@solid-labs/fab-one-widget 0.1.0-alpha.2 → 0.1.0-alpha.3
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/fab-one-widget.js +1 -1
- package/package.json +1 -1
package/dist/fab-one-widget.js
CHANGED
|
@@ -4728,5 +4728,5 @@ No matching component was found for:
|
|
|
4728
4728
|
`)),e.indexOf(`\\
|
|
4729
4729
|
`)!==-1&&(e=e.replace(/\\\n/g,""));const a=e.split(`
|
|
4730
4730
|
`);let l=[];for(let m=0,b=a.length;m<b;m++){const S=a[m].trimStart();if(S.length===0)continue;const x=S.charAt(0);if(x!=="#")if(x==="v"){const C=S.split(qL);switch(C[0]){case"v":t.vertices.push(parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3])),C.length>=7?(HM.setRGB(parseFloat(C[4]),parseFloat(C[5]),parseFloat(C[6]),od),t.colors.push(HM.r,HM.g,HM.b)):t.colors.push(void 0,void 0,void 0);break;case"vn":t.normals.push(parseFloat(C[1]),parseFloat(C[2]),parseFloat(C[3]));break;case"vt":t.uvs.push(parseFloat(C[1]),parseFloat(C[2]));break}}else if(x==="f"){const C=S.slice(1).trim().split(qL),E=[];for(let A=0,O=C.length;A<O;A++){const B=C[A];if(B.length>0){const z=B.split("/");E.push(z)}}const k=E[0];for(let A=1,O=E.length-1;A<O;A++){const B=E[A],z=E[A+1];t.addFace(k[0],B[0],z[0],k[1],B[1],z[1],k[2],B[2],z[2])}}else if(x==="l"){const C=S.substring(1).trim().split(" ");let E=[];const k=[];if(S.indexOf("/")===-1)E=C;else for(let A=0,O=C.length;A<O;A++){const B=C[A].split("/");B[0]!==""&&E.push(B[0]),B[1]!==""&&k.push(B[1])}t.addLineGeometry(E,k)}else if(x==="p"){const C=S.slice(1).trim().split(" ");t.addPointGeometry(C)}else if((l=MW.exec(S))!==null){const C=(" "+l[0].slice(1).trim()).slice(1);t.startObject(C)}else if(kW.test(S))t.object.startMaterial(S.substring(7).trim(),t.materialLibraries);else if(CW.test(S))t.materialLibraries.push(S.substring(7).trim());else if(AW.test(S))console.warn('THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.');else if(x==="s"){if(l=S.split(" "),l.length>1){const E=l[1].trim().toLowerCase();t.object.smooth=E!=="0"&&E!=="off"}else t.object.smooth=!0;const C=t.object.currentMaterial();C&&(C.smooth=t.object.smooth)}else{if(S==="\0")continue;console.warn('THREE.OBJLoader: Unexpected line: "'+S+'"')}}t.finalize();const f=new _S;if(f.materialLibraries=[].concat(t.materialLibraries),!(t.objects.length===1&&t.objects[0].geometry.vertices.length===0))for(let m=0,b=t.objects.length;m<b;m++){const S=t.objects[m],x=S.geometry,C=S.materials,E=x.type==="Line",k=x.type==="Points";let A=!1;if(x.vertices.length===0)continue;const O=new Nr;O.setAttribute("position",new Sn(x.vertices,3)),x.normals.length>0&&O.setAttribute("normal",new Sn(x.normals,3)),x.colors.length>0&&(A=!0,O.setAttribute("color",new Sn(x.colors,3))),x.hasUVIndices===!0&&O.setAttribute("uv",new Sn(x.uvs,2));const B=[];for(let N=0,H=C.length;N<H;N++){const V=C[N],W=V.name+"_"+V.smooth+"_"+A;let X=t.materials[W];if(this.materials!==null){if(X=this.materials.create(V.name),E&&X&&!(X instanceof wc)){const Y=new wc;xc.prototype.copy.call(Y,X),Y.color.copy(X.color),X=Y}else if(k&&X&&!(X instanceof MS)){const Y=new MS({size:10,sizeAttenuation:!1});xc.prototype.copy.call(Y,X),Y.color.copy(X.color),Y.map=X.map,X=Y}}X===void 0&&(E?X=new wc:k?X=new MS({size:1,sizeAttenuation:!1}):X=new xA,X.name=V.name,X.flatShading=!V.smooth,X.vertexColors=A,t.materials[W]=X),B.push(X)}let z;if(B.length>1){for(let N=0,H=C.length;N<H;N++){const V=C[N];O.addGroup(V.groupStart,V.groupCount,N)}E?z=new gg(O,B):k?z=new Bw(O,B):z=new ss(O,B)}else E?z=new gg(O,B[0]):k?z=new Bw(O,B[0]):z=new ss(O,B[0]);z.name=S.name,f.add(z)}else if(t.vertices.length>0){const m=new MS({size:1,sizeAttenuation:!1}),b=new Nr;b.setAttribute("position",new Sn(t.vertices,3)),t.colors.length>0&&t.colors[0]!==void 0&&(b.setAttribute("color",new Sn(t.colors,3)),m.vertexColors=!0);const S=new Bw(b,m);f.add(S)}return f}}const XL=0,NW=1,DW=2,YL=2,LP=1.25,JL=1,nf=32,Gu=nf/4,$L=65535,WM=Math.pow(2,-24),OP=Symbol("SKIP_GENERATION"),eO={strategy:XL,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[OP]:!1};function al(u,e,t){return t.min.x=e[u],t.min.y=e[u+1],t.min.z=e[u+2],t.max.x=e[u+3],t.max.y=e[u+4],t.max.z=e[u+5],t}function tO(u){let e=-1,t=-1/0;for(let a=0;a<3;a++){const l=u[a+3]-u[a];l>t&&(t=l,e=a)}return e}function nO(u,e){e.set(u)}function rO(u,e,t){let a,l;for(let f=0;f<3;f++){const m=f+3;a=u[f],l=e[f],t[f]=a<l?a:l,a=u[m],l=e[m],t[m]=a>l?a:l}}function GM(u,e,t){for(let a=0;a<3;a++){const l=e[u+2*a],f=e[u+2*a+1],m=l-f,b=l+f;m<t[a]&&(t[a]=m),b>t[a+3]&&(t[a+3]=b)}}function cT(u){const e=u[3]-u[0],t=u[4]-u[1],a=u[5]-u[2];return 2*(e*t+t*a+a*e)}function qu(u,e){return e[u+15]===$L}function rf(u,e){return e[u+6]}function th(u,e){return e[u+14]}function Tc(u){return u+Gu}function Ec(u,e){const t=e[u+6];return u+t*Gu}function zP(u,e){return e[u+7]}function FP(u,e,t,a,l){let f=1/0,m=1/0,b=1/0,S=-1/0,x=-1/0,C=-1/0,E=1/0,k=1/0,A=1/0,O=-1/0,B=-1/0,z=-1/0;const N=u.offset||0;for(let H=(e-N)*6,V=(e+t-N)*6;H<V;H+=6){const W=u[H+0],X=u[H+1],Y=W-X,$=W+X;Y<f&&(f=Y),$>S&&(S=$),W<E&&(E=W),W>O&&(O=W);const te=u[H+2],Z=u[H+3],Q=te-Z,ie=te+Z;Q<m&&(m=Q),ie>x&&(x=ie),te<k&&(k=te),te>B&&(B=te);const ue=u[H+4],he=u[H+5],Se=ue-he,Me=ue+he;Se<b&&(b=Se),Me>C&&(C=Me),ue<A&&(A=ue),ue>z&&(z=ue)}a[0]=f,a[1]=m,a[2]=b,a[3]=S,a[4]=x,a[5]=C,l[0]=E,l[1]=k,l[2]=A,l[3]=O,l[4]=B,l[5]=z}const ob=32,IW=(u,e)=>u.candidate-e.candidate,b1=new Array(ob).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),qM=new Float32Array(6);function LW(u,e,t,a,l,f){let m=-1,b=0;if(f===XL)m=tO(e),m!==-1&&(b=(e[m]+e[m+3])/2);else if(f===NW)m=tO(u),m!==-1&&(b=OW(t,a,l,m));else if(f===DW){const S=cT(u);let x=LP*l;const C=t.offset||0,E=(a-C)*6,k=(a+l-C)*6;for(let A=0;A<3;A++){const O=e[A],B=(e[A+3]-O)/ob;if(l<ob/4){const z=[...b1];z.length=l;let N=0;for(let V=E;V<k;V+=6,N++){const W=z[N];W.candidate=t[V+2*A],W.count=0;const{bounds:X,leftCacheBounds:Y,rightCacheBounds:$}=W;for(let te=0;te<3;te++)$[te]=1/0,$[te+3]=-1/0,Y[te]=1/0,Y[te+3]=-1/0,X[te]=1/0,X[te+3]=-1/0;GM(V,t,X)}z.sort(IW);let H=l;for(let V=0;V<H;V++){const W=z[V];for(;V+1<H&&z[V+1].candidate===W.candidate;)z.splice(V+1,1),H--}for(let V=E;V<k;V+=6){const W=t[V+2*A];for(let X=0;X<H;X++){const Y=z[X];W>=Y.candidate?GM(V,t,Y.rightCacheBounds):(GM(V,t,Y.leftCacheBounds),Y.count++)}}for(let V=0;V<H;V++){const W=z[V],X=W.count,Y=l-W.count,$=W.leftCacheBounds,te=W.rightCacheBounds;let Z=0;X!==0&&(Z=cT($)/S);let Q=0;Y!==0&&(Q=cT(te)/S);const ie=JL+LP*(Z*X+Q*Y);ie<x&&(m=A,x=ie,b=W.candidate)}}else{for(let H=0;H<ob;H++){const V=b1[H];V.count=0,V.candidate=O+B+H*B;const W=V.bounds;for(let X=0;X<3;X++)W[X]=1/0,W[X+3]=-1/0}for(let H=E;H<k;H+=6){let V=~~((t[H+2*A]-O)/B);V>=ob&&(V=ob-1);const W=b1[V];W.count++,GM(H,t,W.bounds)}const z=b1[ob-1];nO(z.bounds,z.rightCacheBounds);for(let H=ob-2;H>=0;H--){const V=b1[H],W=b1[H+1];rO(V.bounds,W.rightCacheBounds,V.rightCacheBounds)}let N=0;for(let H=0;H<ob-1;H++){const V=b1[H],W=V.count,X=V.bounds,Y=b1[H+1].rightCacheBounds;W!==0&&(N===0?nO(X,qM):rO(X,qM,qM)),N+=W;let $=0,te=0;N!==0&&($=cT(qM)/S);const Z=l-N;Z!==0&&(te=cT(Y)/S);const Q=JL+LP*($*N+te*Z);Q<x&&(m=A,x=Q,b=V.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${f} used.`);return{axis:m,pos:b}}function OW(u,e,t,a){let l=0;const f=u.offset;for(let m=e,b=e+t;m<b;m++)l+=u[(m-f)*6+a*2];return l/t}class UP{constructor(){this.boundingData=new Float32Array(6)}}function zW(u,e,t,a,l,f){let m=a,b=a+l-1;const S=f.pos,x=f.axis*2,C=t.offset||0;for(;;){for(;m<=b&&t[(m-C)*6+x]<S;)m++;for(;m<=b&&t[(b-C)*6+x]>=S;)b--;if(m<b){for(let E=0;E<e;E++){let k=u[m*e+E];u[m*e+E]=u[b*e+E],u[b*e+E]=k}for(let E=0;E<6;E++){const k=m-C,A=b-C,O=t[k*6+E];t[k*6+E]=t[A*6+E],t[A*6+E]=O}m++,b--}else return m}}let aO,QM,BP,iO;const FW=Math.pow(2,32);function VP(u){return"count"in u?1:1+VP(u.left)+VP(u.right)}function UW(u,e,t){return aO=new Float32Array(t),QM=new Uint32Array(t),BP=new Uint16Array(t),iO=new Uint8Array(t),jP(u,e)}function jP(u,e){const t=u/4,a=u/2,l="count"in e,f=e.boundingData;for(let m=0;m<6;m++)aO[t+m]=f[m];if(l)return e.buffer?(iO.set(new Uint8Array(e.buffer),u),u+e.buffer.byteLength):(QM[t+6]=e.offset,BP[a+14]=e.count,BP[a+15]=$L,u+nf);{const{left:m,right:b,splitAxis:S}=e,x=u+nf;let C=jP(x,m);const E=u/nf,k=C/nf-E;if(k>FW)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return QM[t+6]=k,QM[t+7]=S,jP(C,b)}}function BW(u,e,t,a,l,f){const{maxDepth:m,verbose:b,maxLeafSize:S,strategy:x,onProgress:C}=l,E=u.primitiveBuffer,k=u.primitiveBufferStride,A=new Float32Array(6);let O=!1;const B=new UP;return FP(e,t,a,B.boundingData,A),N(B,t,a,A),B;function z(H){C&&C((H-f.offset)/f.count)}function N(H,V,W,X=null,Y=0){if(!O&&Y>=m&&(O=!0,b&&console.warn(`BVH: Max depth of ${m} reached when generating BVH. Consider increasing maxDepth.`)),W<=S||Y>=m)return z(V+W),H.offset=V,H.count=W,H;const $=LW(H.boundingData,X,e,V,W,x);if($.axis===-1)return z(V+W),H.offset=V,H.count=W,H;const te=zW(E,k,e,V,W,$);if(te===V||te===V+W)z(V+W),H.offset=V,H.count=W;else{H.splitAxis=$.axis;const Z=new UP,Q=V,ie=te-V;H.left=Z,FP(e,Q,ie,Z.boundingData,A),N(Z,Q,ie,A,Y+1);const ue=new UP,he=te,Se=W-ie;H.right=ue,FP(e,he,Se,ue.boundingData,A),N(ue,he,Se,A,Y+1)}return H}}function VW(u,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,a=u.getRootRanges(e.range),l=a[0],f=a[a.length-1],m={offset:l.offset,count:f.offset+f.count-l.offset},b=new Float32Array(6*m.count);b.offset=m.offset,u.computePrimitiveBounds(m.offset,m.count,b),u._roots=a.map(S=>{const x=BW(u,b,S.offset,S.count,e,m),C=VP(x),E=new t(nf*C);return UW(0,x,E),E})}class HP{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class jW{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=a=>{t&&e.push(t),t=a,this.float32Array=new Float32Array(a),this.uint16Array=new Uint16Array(a),this.uint32Array=new Uint32Array(a)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const Jo=new jW;let S1,b_;const S_=[],KM=new HP(()=>new Ni);function HW(u,e,t,a,l,f){S1=KM.getPrimitive(),b_=KM.getPrimitive(),S_.push(S1,b_),Jo.setBuffer(u._roots[e]);const m=WP(0,u.geometry,t,a,l,f);Jo.clearBuffer(),KM.releasePrimitive(S1),KM.releasePrimitive(b_),S_.pop(),S_.pop();const b=S_.length;return b>0&&(b_=S_[b-1],S1=S_[b-2]),m}function WP(u,e,t,a,l=null,f=0,m=0){const{float32Array:b,uint16Array:S,uint32Array:x}=Jo;let C=u*2;if(qu(C,S)){const E=rf(u,x),k=th(C,S);return al(u,b,S1),a(E,k,!1,m,f+u/Gu,S1)}else{let E=function(ie){const{uint16Array:ue,uint32Array:he}=Jo;let Se=ie*2;for(;!qu(Se,ue);)ie=Tc(ie),Se=ie*2;return rf(ie,he)},k=function(ie){const{uint16Array:ue,uint32Array:he}=Jo;let Se=ie*2;for(;!qu(Se,ue);)ie=Ec(ie,he),Se=ie*2;return rf(ie,he)+th(Se,ue)};const A=Tc(u),O=Ec(u,x);let B=A,z=O,N,H,V,W;if(l&&(V=S1,W=b_,al(B,b,V),al(z,b,W),N=l(V),H=l(W),H<N)){B=O,z=A;const ie=N;N=H,H=ie,V=W}V||(V=S1,al(B,b,V));const X=qu(B*2,S),Y=t(V,X,N,m+1,f+B/Gu);let $;if(Y===YL){const ie=E(B),ue=k(B)-ie;$=a(ie,ue,!0,m+1,f+B/Gu,V)}else $=Y&&WP(B,e,t,a,l,f,m+1);if($)return!0;W=b_,al(z,b,W);const te=qu(z*2,S),Z=t(W,te,H,m+1,f+z/Gu);let Q;if(Z===YL){const ie=E(z),ue=k(z)-ie;Q=a(ie,ue,!0,m+1,f+z/Gu,W)}else Q=Z&&WP(z,e,t,a,l,f,m+1);return!!Q}}const dT=new Jo.constructor,ZM=new Jo.constructor,x1=new HP(()=>new Ni),x_=new Ni,__=new Ni,GP=new Ni,qP=new Ni;let QP=!1;function WW(u,e,t,a){if(QP)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");QP=!0;const l=u._roots,f=e._roots;let m,b=0,S=0;const x=new Wn().copy(t).invert();for(let C=0,E=l.length;C<E;C++){dT.setBuffer(l[C]),S=0;const k=x1.getPrimitive();al(0,dT.float32Array,k),k.applyMatrix4(x);for(let A=0,O=f.length;A<O&&(ZM.setBuffer(f[A]),m=H0(0,0,t,x,a,b,S,0,0,k),ZM.clearBuffer(),S+=f[A].byteLength/nf,!m);A++);if(x1.releasePrimitive(k),dT.clearBuffer(),b+=l[C].byteLength/nf,m)break}return QP=!1,m}function H0(u,e,t,a,l,f=0,m=0,b=0,S=0,x=null,C=!1){let E,k;C?(E=ZM,k=dT):(E=dT,k=ZM);const A=E.float32Array,O=E.uint32Array,B=E.uint16Array,z=k.float32Array,N=k.uint32Array,H=k.uint16Array,V=u*2,W=e*2,X=qu(V,B),Y=qu(W,H);let $=!1;if(Y&&X)C?$=l(rf(e,N),th(e*2,H),rf(u,O),th(u*2,B),S,m+e/Gu,b,f+u/Gu):$=l(rf(u,O),th(u*2,B),rf(e,N),th(e*2,H),b,f+u/Gu,S,m+e/Gu);else if(Y){const te=x1.getPrimitive();al(e,z,te),te.applyMatrix4(t);const Z=Tc(u),Q=Ec(u,O);al(Z,A,x_),al(Q,A,__);const ie=te.intersectsBox(x_),ue=te.intersectsBox(__);$=ie&&H0(e,Z,a,t,l,m,f,S,b+1,te,!C)||ue&&H0(e,Q,a,t,l,m,f,S,b+1,te,!C),x1.releasePrimitive(te)}else{const te=Tc(e),Z=Ec(e,N);al(te,z,GP),al(Z,z,qP);const Q=x.intersectsBox(GP),ie=x.intersectsBox(qP);if(Q&&ie)$=H0(u,te,t,a,l,f,m,b,S+1,x,C)||H0(u,Z,t,a,l,f,m,b,S+1,x,C);else if(Q)if(X)$=H0(u,te,t,a,l,f,m,b,S+1,x,C);else{const ue=x1.getPrimitive();ue.copy(GP).applyMatrix4(t);const he=Tc(u),Se=Ec(u,O);al(he,A,x_),al(Se,A,__);const Me=ue.intersectsBox(x_),ce=ue.intersectsBox(__);$=Me&&H0(te,he,a,t,l,m,f,S,b+1,ue,!C)||ce&&H0(te,Se,a,t,l,m,f,S,b+1,ue,!C),x1.releasePrimitive(ue)}else if(ie)if(X)$=H0(u,Z,t,a,l,f,m,b,S+1,x,C);else{const ue=x1.getPrimitive();ue.copy(qP).applyMatrix4(t);const he=Tc(u),Se=Ec(u,O);al(he,A,x_),al(Se,A,__);const Me=ue.intersectsBox(x_),ce=ue.intersectsBox(__);$=Me&&H0(Z,he,a,t,l,m,f,S,b+1,ue,!C)||ce&&H0(Z,Se,a,t,l,m,f,S,b+1,ue,!C),x1.releasePrimitive(ue)}}return $}const oO=new Ni,w_=new Float32Array(6);class GW{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...eO,...e},VW(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,a,l){let f=1/0,m=1/0,b=1/0,S=-1/0,x=-1/0,C=-1/0;for(let E=e,k=e+t;E<k;E++){this.writePrimitiveBounds(E,w_,0);const[A,O,B,z,N,H]=w_;A<f&&(f=A),z>S&&(S=z),O<m&&(m=O),N>x&&(x=N),B<b&&(b=B),H>C&&(C=H)}return a[l+0]=f,a[l+1]=m,a[l+2]=b,a[l+3]=S,a[l+4]=x,a[l+5]=C,a}computePrimitiveBounds(e,t,a){const l=a.offset||0;for(let f=e,m=e+t;f<m;f++){this.writePrimitiveBounds(f,w_,0);const[b,S,x,C,E,k]=w_,A=(b+C)/2,O=(S+E)/2,B=(x+k)/2,z=(C-b)/2,N=(E-S)/2,H=(k-x)/2,V=(f-l)*6;a[V+0]=A,a[V+1]=z+(Math.abs(A)+z)*WM,a[V+2]=O,a[V+3]=N+(Math.abs(O)+N)*WM,a[V+4]=B,a[V+5]=H+(Math.abs(B)+H)*WM}return a}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let a=0,l=t.length;a<l;a++)t[a]+=e;else{const a=this._roots;for(let l=0;l<a.length;l++){const f=a[l],m=new Uint32Array(f),b=new Uint16Array(f),S=f.byteLength/nf;for(let x=0;x<S;x++){const C=Gu*x,E=2*C;qu(E,b)&&(m[C+6]+=e)}}}}traverse(e,t=0){const a=this._roots[t],l=new Uint32Array(a),f=new Uint16Array(a);m(0);function m(b,S=0){const x=b*2,C=qu(x,f);if(C){const E=l[b+6],k=f[x+14];e(S,C,new Float32Array(a,b*4,6),E,k)}else{const E=Tc(b),k=Ec(b,l),A=zP(b,l);e(S,C,new Float32Array(a,b*4,6),A)||(m(E,S+1),m(k,S+1))}}}refit(){const e=this._roots;for(let t=0,a=e.length;t<a;t++){const l=e[t],f=new Uint32Array(l),m=new Uint16Array(l),b=new Float32Array(l),S=l.byteLength/nf;for(let x=S-1;x>=0;x--){const C=x*Gu,E=C*2;if(qu(E,m)){const k=rf(C,f),A=th(E,m);this.writePrimitiveRangeBounds(k,A,w_,0),b.set(w_,C)}else{const k=Tc(C),A=Ec(C,f);for(let O=0;O<3;O++){const B=b[k+O],z=b[k+O+3],N=b[A+O],H=b[A+O+3];b[C+O]=B<N?B:N,b[C+O+3]=z>H?z:H}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{al(0,new Float32Array(t),oO),e.union(oO)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:a,intersectsRange:l,intersectsPrimitive:f,scratchPrimitive:m,iterate:b}=e;if(l&&f){const E=l;l=(k,A,O,B,z)=>E(k,A,O,B,z)?!0:b(k,A,this,f,O,B,m)}else l||(f?l=(E,k,A,O)=>b(E,k,this,f,A,O,m):l=(E,k,A)=>A);let S=!1,x=0;const C=this._roots;for(let E=0,k=C.length;E<k;E++){const A=C[E];if(S=HW(this,E,a,l,t,x),S)break;x+=A.byteLength/nf}return S}bvhcast(e,t,a){let{intersectsRanges:l}=a;return WW(this,e,t,l)}}function qW(){return typeof SharedArrayBuffer<"u"}function KP(u){return u.index?u.index.count:u.attributes.position.count}function XM(u){return KP(u)/3}function QW(u,e=ArrayBuffer){return u>65535?new Uint32Array(new e(4*u)):new Uint16Array(new e(2*u))}function KW(u,e){if(!u.index){const t=u.attributes.position.count,a=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,l=QW(t,a);u.setIndex(new Di(l,1));for(let f=0;f<t;f++)l[f]=f}}function ZW(u,e,t){const a=KP(u)/t,l=e||u.drawRange,f=l.start/t,m=(l.start+l.count)/t,b=Math.max(0,f),S=Math.min(a,m)-b;return{offset:Math.floor(b),count:Math.floor(S)}}function XW(u,e){return u.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function sO(u,e,t){const a=ZW(u,e,t),l=XW(u,t);if(!l.length)return[a];const f=[],m=a.offset,b=a.offset+a.count,S=KP(u)/t,x=[];for(const k of l){const{offset:A,count:O}=k,B=A,z=isFinite(O)?O:S-A,N=A+z;B<b&&N>m&&(x.push({pos:Math.max(m,B),isStart:!0}),x.push({pos:Math.min(b,N),isStart:!1}))}x.sort((k,A)=>k.pos!==A.pos?k.pos-A.pos:k.type==="end"?-1:1);let C=0,E=null;for(const k of x){const A=k.pos;C!==0&&A!==E&&f.push({offset:E,count:A-E}),C+=k.isStart?1:-1,E=A}return f}function YW(u,e){const t=u[u.length-1],a=t.offset+t.count>2**16,l=u.reduce((x,C)=>x+C.count,0),f=a?4:2,m=e?new SharedArrayBuffer(l*f):new ArrayBuffer(l*f),b=a?new Uint32Array(m):new Uint16Array(m);let S=0;for(let x=0;x<u.length;x++){const{offset:C,count:E}=u[x];for(let k=0;k<E;k++)b[S+k]=C+k;S+=E}return b}class JW extends GW{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!qW())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?a=>this._indirectBuffer[a]:a=>a,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...eO,...t},t[OP]||this.init(t)}init(e){const{geometry:t,primitiveStride:a}=this;if(e.indirect){const l=sO(t,e.range,a),f=YW(l,e.useSharedArrayBuffer);this._indirectBuffer=f}else KW(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Ni))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:sO(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class sb{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let a=1/0,l=-1/0;for(let f=0,m=e.length;f<m;f++){const b=e[f][t];a=b<a?b:a,l=b>l?b:l}this.min=a,this.max=l}setFromPoints(e,t){let a=1/0,l=-1/0;for(let f=0,m=t.length;f<m;f++){const b=t[f],S=e.dot(b);a=S<a?S:a,l=S>l?S:l}this.min=a,this.max=l}isSeparated(e){return this.min>e.max||e.min>this.max}}sb.prototype.setFromBox=(function(){const u=new ae;return function(e,t){const a=t.min,l=t.max;let f=1/0,m=-1/0;for(let b=0;b<=1;b++)for(let S=0;S<=1;S++)for(let x=0;x<=1;x++){u.x=a.x*b+l.x*(1-b),u.y=a.y*S+l.y*(1-S),u.z=a.z*x+l.z*(1-x);const C=e.dot(u);f=Math.min(C,f),m=Math.max(C,m)}this.min=f,this.max=m}})();const $W=(function(){const u=new ae,e=new ae,t=new ae;return function(a,l,f){const m=a.start,b=u,S=l.start,x=e;t.subVectors(m,S),u.subVectors(a.end,a.start),e.subVectors(l.end,l.start);const C=t.dot(x),E=x.dot(b),k=x.dot(x),A=t.dot(b),O=b.dot(b)*k-E*E;let B,z;O!==0?B=(C*E-A*k)/O:B=0,z=(C+B*E)/k,f.x=B,f.y=z}})(),ZP=(function(){const u=new Ot,e=new ae,t=new ae;return function(a,l,f,m){$W(a,l,u);let b=u.x,S=u.y;if(b>=0&&b<=1&&S>=0&&S<=1){a.at(b,f),l.at(S,m);return}else if(b>=0&&b<=1){S<0?l.at(0,m):l.at(1,m),a.closestPointToPoint(m,!0,f);return}else if(S>=0&&S<=1){b<0?a.at(0,f):a.at(1,f),l.closestPointToPoint(f,!0,m);return}else{let x;b<0?x=a.start:x=a.end;let C;S<0?C=l.start:C=l.end;const E=e,k=t;if(a.closestPointToPoint(C,!0,e),l.closestPointToPoint(x,!0,t),E.distanceToSquared(C)<=k.distanceToSquared(x)){f.copy(E),m.copy(C);return}else{f.copy(x),m.copy(k);return}}}})(),e9=(function(){const u=new ae,e=new ae,t=new $h,a=new rm;return function(l,f){const{radius:m,center:b}=l,{a:S,b:x,c:C}=f;if(a.start=S,a.end=x,a.closestPointToPoint(b,!0,u).distanceTo(b)<=m||(a.start=S,a.end=C,a.closestPointToPoint(b,!0,u).distanceTo(b)<=m)||(a.start=x,a.end=C,a.closestPointToPoint(b,!0,u).distanceTo(b)<=m))return!0;const E=f.getPlane(t);if(Math.abs(E.distanceToPoint(b))<=m){const k=E.projectPoint(b,e);if(f.containsPoint(k))return!0}return!1}})(),t9=["x","y","z"],lb=1e-15,lO=lb*lb;function Sg(u){return Math.abs(u)<lb}class W0 extends ou{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new ae),this.satBounds=new Array(4).fill().map(()=>new sb),this.points=[this.a,this.b,this.c],this.plane=new $h,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new rm,this.needsUpdate=!0}intersectsSphere(e){return e9(e,this)}update(){const e=this.a,t=this.b,a=this.c,l=this.points,f=this.satAxes,m=this.satBounds,b=f[0],S=m[0];this.getNormal(b),S.setFromPoints(b,l);const x=f[1],C=m[1];x.subVectors(e,t),C.setFromPoints(x,l);const E=f[2],k=m[2];E.subVectors(t,a),k.setFromPoints(E,l);const A=f[3],O=m[3];A.subVectors(a,e),O.setFromPoints(A,l);const B=x.length(),z=E.length(),N=A.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,B<lb?z<lb||N<lb?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(a)):z<lb?N<lb?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):N<lb&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(a),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(b,e),this.needsUpdate=!1}}W0.prototype.closestPointToSegment=(function(){const u=new ae,e=new ae,t=new rm;return function(a,l=null,f=null){const{start:m,end:b}=a,S=this.points;let x,C=1/0;for(let E=0;E<3;E++){const k=(E+1)%3;t.start.copy(S[E]),t.end.copy(S[k]),ZP(t,a,u,e),x=u.distanceToSquared(e),x<C&&(C=x,l&&l.copy(u),f&&f.copy(e))}return this.closestPointToPoint(m,u),x=m.distanceToSquared(u),x<C&&(C=x,l&&l.copy(u),f&&f.copy(m)),this.closestPointToPoint(b,u),x=b.distanceToSquared(u),x<C&&(C=x,l&&l.copy(u),f&&f.copy(b)),Math.sqrt(C)}})(),W0.prototype.intersectsTriangle=(function(){const u=new W0,e=new sb,t=new sb,a=new ae,l=new ae,f=new ae,m=new ae,b=new rm,S=new rm,x=new ae,C=new Ot,E=new Ot;function k(V,W,X,Y){const $=a;!V.isDegenerateIntoPoint&&!V.isDegenerateIntoSegment?$.copy(V.plane.normal):$.copy(W.plane.normal);const te=V.satBounds,Z=V.satAxes;for(let ue=1;ue<4;ue++){const he=te[ue],Se=Z[ue];if(e.setFromPoints(Se,W.points),he.isSeparated(e)||(m.copy($).cross(Se),e.setFromPoints(m,V.points),t.setFromPoints(m,W.points),e.isSeparated(t)))return!1}const Q=W.satBounds,ie=W.satAxes;for(let ue=1;ue<4;ue++){const he=Q[ue],Se=ie[ue];if(e.setFromPoints(Se,V.points),he.isSeparated(e)||(m.crossVectors($,Se),e.setFromPoints(m,V.points),t.setFromPoints(m,W.points),e.isSeparated(t)))return!1}return X&&(Y||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),X.start.set(0,0,0),X.end.set(0,0,0)),!0}function A(V,W,X,Y,$,te,Z,Q,ie,ue,he){let Se=Z/(Z-Q);ue.x=Y+($-Y)*Se,he.start.subVectors(W,V).multiplyScalar(Se).add(V),Se=Z/(Z-ie),ue.y=Y+(te-Y)*Se,he.end.subVectors(X,V).multiplyScalar(Se).add(V)}function O(V,W,X,Y,$,te,Z,Q,ie,ue,he){if($>0)A(V.c,V.a,V.b,Y,W,X,ie,Z,Q,ue,he);else if(te>0)A(V.b,V.a,V.c,X,W,Y,Q,Z,ie,ue,he);else if(Q*ie>0||Z!=0)A(V.a,V.b,V.c,W,X,Y,Z,Q,ie,ue,he);else if(Q!=0)A(V.b,V.a,V.c,X,W,Y,Q,Z,ie,ue,he);else if(ie!=0)A(V.c,V.a,V.b,Y,W,X,ie,Z,Q,ue,he);else return!0;return!1}function B(V,W,X,Y){const $=W.degenerateSegment,te=V.plane.distanceToPoint($.start),Z=V.plane.distanceToPoint($.end);return Sg(te)?Sg(Z)?k(V,W,X,Y):(X&&(X.start.copy($.start),X.end.copy($.start)),V.containsPoint($.start)):Sg(Z)?(X&&(X.start.copy($.end),X.end.copy($.end)),V.containsPoint($.end)):V.plane.intersectLine($,a)!=null?(X&&(X.start.copy(a),X.end.copy(a)),V.containsPoint(a)):!1}function z(V,W,X){const Y=W.a;return Sg(V.plane.distanceToPoint(Y))&&V.containsPoint(Y)?(X&&(X.start.copy(Y),X.end.copy(Y)),!0):!1}function N(V,W,X){const Y=V.degenerateSegment,$=W.a;return Y.closestPointToPoint($,!0,a),$.distanceToSquared(a)<lO?(X&&(X.start.copy($),X.end.copy($)),!0):!1}function H(V,W,X,Y){if(V.isDegenerateIntoSegment)if(W.isDegenerateIntoSegment){const $=V.degenerateSegment,te=W.degenerateSegment,Z=l,Q=f;$.delta(Z),te.delta(Q);const ie=a.subVectors(te.start,$.start),ue=Z.x*Q.y-Z.y*Q.x;if(Sg(ue))return!1;const he=(ie.x*Q.y-ie.y*Q.x)/ue,Se=-(Z.x*ie.y-Z.y*ie.x)/ue;if(he<0||he>1||Se<0||Se>1)return!1;const Me=$.start.z+Z.z*he,ce=te.start.z+Q.z*Se;return Sg(Me-ce)?(X&&(X.start.copy($.start).addScaledVector(Z,he),X.end.copy($.start).addScaledVector(Z,he)),!0):!1}else return W.isDegenerateIntoPoint?N(V,W,X):B(W,V,X,Y);else{if(V.isDegenerateIntoPoint)return W.isDegenerateIntoPoint?W.a.distanceToSquared(V.a)<lO?(X&&(X.start.copy(V.a),X.end.copy(V.a)),!0):!1:W.isDegenerateIntoSegment?N(W,V,X):z(W,V,X);if(W.isDegenerateIntoPoint)return z(V,W,X);if(W.isDegenerateIntoSegment)return B(V,W,X,Y)}}return function(V,W=null,X=!1){this.needsUpdate&&this.update(),V.isExtendedTriangle?V.needsUpdate&&V.update():(u.copy(V),u.update(),V=u);const Y=H(this,V,W,X);if(Y!==void 0)return Y;const $=this.plane,te=V.plane;let Z=te.distanceToPoint(this.a),Q=te.distanceToPoint(this.b),ie=te.distanceToPoint(this.c);Sg(Z)&&(Z=0),Sg(Q)&&(Q=0),Sg(ie)&&(ie=0);const ue=Z*Q,he=Z*ie;if(ue>0&&he>0)return!1;let Se=$.distanceToPoint(V.a),Me=$.distanceToPoint(V.b),ce=$.distanceToPoint(V.c);Sg(Se)&&(Se=0),Sg(Me)&&(Me=0),Sg(ce)&&(ce=0);const xe=Se*Me,_e=Se*ce;if(xe>0&&_e>0)return!1;l.copy($.normal),f.copy(te.normal);const Qe=l.cross(f);let it=0,se=Math.abs(Qe.x);const ye=Math.abs(Qe.y);ye>se&&(se=ye,it=1),Math.abs(Qe.z)>se&&(it=2);const Ce=t9[it],Le=this.a[Ce],Pt=this.b[Ce],Ke=this.c[Ce],Je=V.a[Ce],zt=V.b[Ce],Qt=V.c[Ce];if(O(this,Le,Pt,Ke,ue,he,Z,Q,ie,C,b))return k(this,V,W,X);if(O(V,Je,zt,Qt,xe,_e,Se,Me,ce,E,S))return k(this,V,W,X);if(C.y<C.x){const Kt=C.y;C.y=C.x,C.x=Kt,x.copy(b.start),b.start.copy(b.end),b.end.copy(x)}if(E.y<E.x){const Kt=E.y;E.y=E.x,E.x=Kt,x.copy(S.start),S.start.copy(S.end),S.end.copy(x)}return C.y<E.x||E.y<C.x?!1:(W&&(E.x>C.x?W.start.copy(S.start):W.start.copy(b.start),E.y<C.y?W.end.copy(S.end):W.end.copy(b.end)),!0)}})(),W0.prototype.distanceToPoint=(function(){const u=new ae;return function(e){return this.closestPointToPoint(e,u),e.distanceTo(u)}})(),W0.prototype.distanceToTriangle=(function(){const u=new ae,e=new ae,t=["a","b","c"],a=new rm,l=new rm;return function(f,m=null,b=null){const S=m||b?a:null;if(this.intersectsTriangle(f,S))return(m||b)&&(m&&S.getCenter(m),b&&S.getCenter(b)),0;let x=1/0;for(let C=0;C<3;C++){let E;const k=t[C],A=f[k];this.closestPointToPoint(A,u),E=A.distanceToSquared(u),E<x&&(x=E,m&&m.copy(u),b&&b.copy(A));const O=this[k];f.closestPointToPoint(O,u),E=O.distanceToSquared(u),E<x&&(x=E,m&&m.copy(O),b&&b.copy(u))}for(let C=0;C<3;C++){const E=t[C],k=t[(C+1)%3];a.set(this[E],this[k]);for(let A=0;A<3;A++){const O=t[A],B=t[(A+1)%3];l.set(f[O],f[B]),ZP(a,l,u,e);const z=u.distanceToSquared(e);z<x&&(x=z,m&&m.copy(u),b&&b.copy(e))}}return Math.sqrt(x)}})();class nh{constructor(e,t,a){this.isOrientedBox=!0,this.min=new ae,this.max=new ae,this.matrix=new Wn,this.invMatrix=new Wn,this.points=new Array(8).fill().map(()=>new ae),this.satAxes=new Array(3).fill().map(()=>new ae),this.satBounds=new Array(3).fill().map(()=>new sb),this.alignedSatBounds=new Array(3).fill().map(()=>new sb),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),a&&this.matrix.copy(a)}set(e,t,a){this.min.copy(e),this.max.copy(t),this.matrix.copy(a),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}nh.prototype.update=(function(){return function(){const u=this.matrix,e=this.min,t=this.max,a=this.points;for(let S=0;S<=1;S++)for(let x=0;x<=1;x++)for(let C=0;C<=1;C++){const E=1*S|2*x|4*C,k=a[E];k.x=S?t.x:e.x,k.y=x?t.y:e.y,k.z=C?t.z:e.z,k.applyMatrix4(u)}const l=this.satBounds,f=this.satAxes,m=a[0];for(let S=0;S<3;S++){const x=f[S],C=l[S],E=1<<S,k=a[E];x.subVectors(m,k),C.setFromPoints(x,a)}const b=this.alignedSatBounds;b[0].setFromPointsField(a,"x"),b[1].setFromPointsField(a,"y"),b[2].setFromPointsField(a,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),nh.prototype.intersectsBox=(function(){const u=new sb;return function(e){this.needsUpdate&&this.update();const t=e.min,a=e.max,l=this.satBounds,f=this.satAxes,m=this.alignedSatBounds;if(u.min=t.x,u.max=a.x,m[0].isSeparated(u)||(u.min=t.y,u.max=a.y,m[1].isSeparated(u))||(u.min=t.z,u.max=a.z,m[2].isSeparated(u)))return!1;for(let b=0;b<3;b++){const S=f[b],x=l[b];if(u.setFromBox(S,e),x.isSeparated(u))return!1}return!0}})(),nh.prototype.intersectsTriangle=(function(){const u=new W0,e=new Array(3),t=new sb,a=new sb,l=new ae;return function(f){this.needsUpdate&&this.update(),f.isExtendedTriangle?f.needsUpdate&&f.update():(u.copy(f),u.update(),f=u);const m=this.satBounds,b=this.satAxes;e[0]=f.a,e[1]=f.b,e[2]=f.c;for(let E=0;E<3;E++){const k=m[E],A=b[E];if(t.setFromPoints(A,e),k.isSeparated(t))return!1}const S=f.satBounds,x=f.satAxes,C=this.points;for(let E=0;E<3;E++){const k=S[E],A=x[E];if(t.setFromPoints(A,C),k.isSeparated(t))return!1}for(let E=0;E<3;E++){const k=b[E];for(let A=0;A<4;A++){const O=x[A];if(l.crossVectors(k,O),t.setFromPoints(l,e),a.setFromPoints(l,C),t.isSeparated(a))return!1}}return!0}})(),nh.prototype.closestPointToPoint=(function(){return function(u,e){return this.needsUpdate&&this.update(),e.copy(u).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}})(),nh.prototype.distanceToPoint=(function(){const u=new ae;return function(e){return this.closestPointToPoint(e,u),e.distanceTo(u)}})(),nh.prototype.distanceToBox=(function(){const u=["x","y","z"],e=new Array(12).fill().map(()=>new rm),t=new Array(12).fill().map(()=>new rm),a=new ae,l=new ae;return function(f,m=0,b=null,S=null){if(this.needsUpdate&&this.update(),this.intersectsBox(f))return(b||S)&&(f.getCenter(l),this.closestPointToPoint(l,a),f.closestPointToPoint(a,l),b&&b.copy(a),S&&S.copy(l)),0;const x=m*m,C=f.min,E=f.max,k=this.points;let A=1/0;for(let B=0;B<8;B++){const z=k[B];l.copy(z).clamp(C,E);const N=z.distanceToSquared(l);if(N<A&&(A=N,b&&b.copy(z),S&&S.copy(l),N<x))return Math.sqrt(N)}let O=0;for(let B=0;B<3;B++)for(let z=0;z<=1;z++)for(let N=0;N<=1;N++){const H=(B+1)%3,V=(B+2)%3,W=z<<H|N<<V,X=1<<B|z<<H|N<<V,Y=k[W],$=k[X];e[O].set(Y,$);const te=u[B],Z=u[H],Q=u[V],ie=t[O],ue=ie.start,he=ie.end;ue[te]=C[te],ue[Z]=z?C[Z]:E[Z],ue[Q]=N?C[Q]:E[Z],he[te]=E[te],he[Z]=z?C[Z]:E[Z],he[Q]=N?C[Q]:E[Z],O++}for(let B=0;B<=1;B++)for(let z=0;z<=1;z++)for(let N=0;N<=1;N++){l.x=B?E.x:C.x,l.y=z?E.y:C.y,l.z=N?E.z:C.z,this.closestPointToPoint(l,a);const H=l.distanceToSquared(a);if(H<A&&(A=H,b&&b.copy(a),S&&S.copy(l),H<x))return Math.sqrt(H)}for(let B=0;B<12;B++){const z=e[B];for(let N=0;N<12;N++){const H=t[N];ZP(z,H,a,l);const V=a.distanceToSquared(l);if(V<A&&(A=V,b&&b.copy(a),S&&S.copy(l),V<x))return Math.sqrt(V)}}return Math.sqrt(A)}})();class n9 extends HP{constructor(){super(()=>new W0)}}const xg=new n9,fT=new ae,XP=new ae;function r9(u,e,t={},a=0,l=1/0){const f=a*a,m=l*l;let b=1/0,S=null;if(u.shapecast({boundsTraverseOrder:C=>(fT.copy(e).clamp(C.min,C.max),fT.distanceToSquared(e)),intersectsBounds:(C,E,k)=>k<b&&k<m,intersectsTriangle:(C,E)=>{C.closestPointToPoint(e,fT);const k=e.distanceToSquared(fT);return k<b&&(XP.copy(fT),b=k,S=E),k<f}}),b===1/0)return null;const x=Math.sqrt(b);return t.point?t.point.copy(XP):t.point=XP.clone(),t.distance=x,t.faceIndex=S,t}const YM=parseInt(uS)>=169,a9=parseInt(uS)<=161,WS=new ae,GS=new ae,qS=new ae,JM=new Ot,$M=new Ot,eC=new Ot,uO=new ae,cO=new ae,dO=new ae,hT=new ae;function i9(u,e,t,a,l,f,m,b){let S;if(f===Yd?S=u.intersectTriangle(a,t,e,!0,l):S=u.intersectTriangle(e,t,a,f!==Xh,l),S===null)return null;const x=u.origin.distanceTo(l);return x<m||x>b?null:{distance:x,point:l.clone()}}function fO(u,e,t,a,l,f,m,b,S,x,C){WS.fromBufferAttribute(e,f),GS.fromBufferAttribute(e,m),qS.fromBufferAttribute(e,b);const E=i9(u,WS,GS,qS,hT,S,x,C);if(E){if(a){JM.fromBufferAttribute(a,f),$M.fromBufferAttribute(a,m),eC.fromBufferAttribute(a,b),E.uv=new Ot;const A=ou.getInterpolation(hT,WS,GS,qS,JM,$M,eC,E.uv);YM||(E.uv=A)}if(l){JM.fromBufferAttribute(l,f),$M.fromBufferAttribute(l,m),eC.fromBufferAttribute(l,b),E.uv1=new Ot;const A=ou.getInterpolation(hT,WS,GS,qS,JM,$M,eC,E.uv1);YM||(E.uv1=A),a9&&(E.uv2=E.uv1)}if(t){uO.fromBufferAttribute(t,f),cO.fromBufferAttribute(t,m),dO.fromBufferAttribute(t,b),E.normal=new ae;const A=ou.getInterpolation(hT,WS,GS,qS,uO,cO,dO,E.normal);E.normal.dot(u.direction)>0&&E.normal.multiplyScalar(-1),YM||(E.normal=A)}const k={a:f,b:m,c:b,normal:new ae,materialIndex:0};if(ou.getNormal(WS,GS,qS,k.normal),E.face=k,E.faceIndex=f,YM){const A=new ae;ou.getBarycoord(hT,WS,GS,qS,A),E.barycoord=A}}return E}function hO(u){return u&&u.isMaterial?u.side:u}function tC(u,e,t,a,l,f,m){const b=a*3;let S=b+0,x=b+1,C=b+2;const{index:E,groups:k}=u;u.index&&(S=E.getX(S),x=E.getX(x),C=E.getX(C));const{position:A,normal:O,uv:B,uv1:z}=u.attributes;if(Array.isArray(e)){const N=a*3;for(let H=0,V=k.length;H<V;H++){const{start:W,count:X,materialIndex:Y}=k[H];if(N>=W&&N<W+X){const $=hO(e[Y]),te=fO(t,A,O,B,z,S,x,C,$,f,m);if(te)if(te.faceIndex=a,te.face.materialIndex=Y,l)l.push(te);else return te}}}else{const N=hO(e),H=fO(t,A,O,B,z,S,x,C,N,f,m);if(H)if(H.faceIndex=a,H.face.materialIndex=0,l)l.push(H);else return H}return null}function lu(u,e,t,a){const l=u.a,f=u.b,m=u.c;let b=e,S=e+1,x=e+2;t&&(b=t.getX(b),S=t.getX(S),x=t.getX(x)),l.x=a.getX(b),l.y=a.getY(b),l.z=a.getZ(b),f.x=a.getX(S),f.y=a.getY(S),f.z=a.getZ(S),m.x=a.getX(x),m.y=a.getY(x),m.z=a.getZ(x)}function o9(u,e,t,a,l,f,m,b){const{geometry:S,_indirectBuffer:x}=u;for(let C=a,E=a+l;C<E;C++)tC(S,e,t,C,f,m,b)}function s9(u,e,t,a,l,f,m){const{geometry:b,_indirectBuffer:S}=u;let x=1/0,C=null;for(let E=a,k=a+l;E<k;E++){let A;A=tC(b,e,t,E,null,f,m),A&&A.distance<x&&(C=A,x=A.distance)}return C}function l9(u,e,t,a,l,f,m){const{geometry:b}=t,{index:S}=b,x=b.attributes.position;for(let C=u,E=e+u;C<E;C++){let k;if(k=C,lu(m,k*3,S,x),m.needsUpdate=!0,a(m,k,l,f))return!0}return!1}function u9(u,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=u.geometry,a=t.index?t.index.array:null,l=t.attributes.position;let f,m,b,S,x=0;const C=u._roots;for(let k=0,A=C.length;k<A;k++)f=C[k],m=new Uint32Array(f),b=new Uint16Array(f),S=new Float32Array(f),E(0,x),x+=f.byteLength;function E(k,A,O=!1){const B=k*2;if(qu(B,b)){const z=rf(k,m),N=th(B,b);let H=1/0,V=1/0,W=1/0,X=-1/0,Y=-1/0,$=-1/0;for(let te=3*z,Z=3*(z+N);te<Z;te++){let Q=a[te];const ie=l.getX(Q),ue=l.getY(Q),he=l.getZ(Q);ie<H&&(H=ie),ie>X&&(X=ie),ue<V&&(V=ue),ue>Y&&(Y=ue),he<W&&(W=he),he>$&&($=he)}return S[k+0]!==H||S[k+1]!==V||S[k+2]!==W||S[k+3]!==X||S[k+4]!==Y||S[k+5]!==$?(S[k+0]=H,S[k+1]=V,S[k+2]=W,S[k+3]=X,S[k+4]=Y,S[k+5]=$,!0):!1}else{const z=Tc(k),N=Ec(k,m);let H=O,V=!1,W=!1;if(e){if(!H){const Q=z/Gu+A/nf,ie=N/Gu+A/nf;V=e.has(Q),W=e.has(ie),H=!V&&!W}}else V=!0,W=!0;const X=H||V,Y=H||W;let $=!1;X&&($=E(z,A,H));let te=!1;Y&&(te=E(N,A,H));const Z=$||te;if(Z)for(let Q=0;Q<3;Q++){const ie=z+Q,ue=N+Q,he=S[ie],Se=S[ie+3],Me=S[ue],ce=S[ue+3];S[k+Q]=he<Me?he:Me,S[k+Q+3]=Se>ce?Se:ce}return Z}}}function _1(u,e,t,a,l){let f,m,b,S,x,C;const E=1/t.direction.x,k=1/t.direction.y,A=1/t.direction.z,O=t.origin.x,B=t.origin.y,z=t.origin.z;let N=e[u],H=e[u+3],V=e[u+1],W=e[u+3+1],X=e[u+2],Y=e[u+3+2];return E>=0?(f=(N-O)*E,m=(H-O)*E):(f=(H-O)*E,m=(N-O)*E),k>=0?(b=(V-B)*k,S=(W-B)*k):(b=(W-B)*k,S=(V-B)*k),f>S||b>m||((b>f||isNaN(f))&&(f=b),(S<m||isNaN(m))&&(m=S),A>=0?(x=(X-z)*A,C=(Y-z)*A):(x=(Y-z)*A,C=(X-z)*A),f>C||x>m)?!1:((x>f||f!==f)&&(f=x),(C<m||m!==m)&&(m=C),f<=l&&m>=a)}function c9(u,e,t,a,l,f,m,b){const{geometry:S,_indirectBuffer:x}=u;for(let C=a,E=a+l;C<E;C++){let k=x?x[C]:C;tC(S,e,t,k,f,m,b)}}function d9(u,e,t,a,l,f,m){const{geometry:b,_indirectBuffer:S}=u;let x=1/0,C=null;for(let E=a,k=a+l;E<k;E++){let A;A=tC(b,e,t,S?S[E]:E,null,f,m),A&&A.distance<x&&(C=A,x=A.distance)}return C}function f9(u,e,t,a,l,f,m){const{geometry:b}=t,{index:S}=b,x=b.attributes.position;for(let C=u,E=e+u;C<E;C++){let k;if(k=t.resolveTriangleIndex(C),lu(m,k*3,S,x),m.needsUpdate=!0,a(m,k,l,f))return!0}return!1}function h9(u,e,t,a,l,f,m){Jo.setBuffer(u._roots[e]),YP(0,u,t,a,l,f,m),Jo.clearBuffer()}function YP(u,e,t,a,l,f,m){const{float32Array:b,uint16Array:S,uint32Array:x}=Jo,C=u*2;if(qu(C,S)){const E=rf(u,x),k=th(C,S);o9(e,t,a,E,k,l,f,m)}else{const E=Tc(u);_1(E,b,a,f,m)&&YP(E,e,t,a,l,f,m);const k=Ec(u,x);_1(k,b,a,f,m)&&YP(k,e,t,a,l,f,m)}}const p9=["x","y","z"];function m9(u,e,t,a,l,f){Jo.setBuffer(u._roots[e]);const m=JP(0,u,t,a,l,f);return Jo.clearBuffer(),m}function JP(u,e,t,a,l,f){const{float32Array:m,uint16Array:b,uint32Array:S}=Jo;let x=u*2;if(qu(x,b)){const C=rf(u,S),E=th(x,b);return s9(e,t,a,C,E,l,f)}else{const C=zP(u,S),E=p9[C],k=a.direction[E]>=0;let A,O;k?(A=Tc(u),O=Ec(u,S)):(A=Ec(u,S),O=Tc(u));const B=_1(A,m,a,l,f)?JP(A,e,t,a,l,f):null;if(B){const N=B.point[E];if(k?N<=m[O+C]:N>=m[O+C+3])return B}const z=_1(O,m,a,l,f)?JP(O,e,t,a,l,f):null;return B&&z?B.distance<=z.distance?B:z:B||z||null}}const nC=new Ni,T_=new W0,E_=new W0,pT=new Wn,pO=new nh,rC=new nh;function g9(u,e,t,a){Jo.setBuffer(u._roots[e]);const l=$P(0,u,t,a);return Jo.clearBuffer(),l}function $P(u,e,t,a,l=null){const{float32Array:f,uint16Array:m,uint32Array:b}=Jo;let S=u*2;if(l===null&&(t.boundingBox||t.computeBoundingBox(),pO.set(t.boundingBox.min,t.boundingBox.max,a),l=pO),qu(S,m)){const x=e.geometry,C=x.index,E=x.attributes.position,k=t.index,A=t.attributes.position,O=rf(u,b),B=th(S,m);if(pT.copy(a).invert(),t.boundsTree)return al(u,f,rC),rC.matrix.copy(pT),rC.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:z=>rC.intersectsBox(z),intersectsTriangle:z=>{z.a.applyMatrix4(a),z.b.applyMatrix4(a),z.c.applyMatrix4(a),z.needsUpdate=!0;for(let N=O*3,H=(B+O)*3;N<H;N+=3)if(lu(E_,N,C,E),E_.needsUpdate=!0,z.intersectsTriangle(E_))return!0;return!1}});{const z=XM(t);for(let N=O*3,H=(B+O)*3;N<H;N+=3){lu(T_,N,C,E),T_.a.applyMatrix4(pT),T_.b.applyMatrix4(pT),T_.c.applyMatrix4(pT),T_.needsUpdate=!0;for(let V=0,W=z*3;V<W;V+=3)if(lu(E_,V,k,A),E_.needsUpdate=!0,T_.intersectsTriangle(E_))return!0}}}else{const x=Tc(u),C=Ec(u,b);return al(x,f,nC),!!(l.intersectsBox(nC)&&$P(x,e,t,a,l)||(al(C,f,nC),l.intersectsBox(nC)&&$P(C,e,t,a,l)))}}const aC=new Wn,e3=new nh,mT=new nh,v9=new ae,y9=new ae,b9=new ae,S9=new ae;function x9(u,e,t,a={},l={},f=0,m=1/0){e.boundingBox||e.computeBoundingBox(),e3.set(e.boundingBox.min,e.boundingBox.max,t),e3.needsUpdate=!0;const b=u.geometry,S=b.attributes.position,x=b.index,C=e.attributes.position,E=e.index,k=xg.getPrimitive(),A=xg.getPrimitive();let O=v9,B=y9,z=null,N=null;l&&(z=b9,N=S9);let H=1/0,V=null,W=null;return aC.copy(t).invert(),mT.matrix.copy(aC),u.shapecast({boundsTraverseOrder:X=>e3.distanceToBox(X),intersectsBounds:(X,Y,$)=>$<H&&$<m?(Y&&(mT.min.copy(X.min),mT.max.copy(X.max),mT.needsUpdate=!0),!0):!1,intersectsRange:(X,Y)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:$=>mT.distanceToBox($),intersectsBounds:($,te,Z)=>Z<H&&Z<m,intersectsRange:($,te)=>{for(let Z=$,Q=$+te;Z<Q;Z++){lu(A,3*Z,E,C),A.a.applyMatrix4(t),A.b.applyMatrix4(t),A.c.applyMatrix4(t),A.needsUpdate=!0;for(let ie=X,ue=X+Y;ie<ue;ie++){lu(k,3*ie,x,S),k.needsUpdate=!0;const he=k.distanceToTriangle(A,O,z);if(he<H&&(B.copy(O),N&&N.copy(z),H=he,V=ie,W=Z),he<f)return!0}}}});{const $=XM(e);for(let te=0,Z=$;te<Z;te++){lu(A,3*te,E,C),A.a.applyMatrix4(t),A.b.applyMatrix4(t),A.c.applyMatrix4(t),A.needsUpdate=!0;for(let Q=X,ie=X+Y;Q<ie;Q++){lu(k,3*Q,x,S),k.needsUpdate=!0;const ue=k.distanceToTriangle(A,O,z);if(ue<H&&(B.copy(O),N&&N.copy(z),H=ue,V=Q,W=te),ue<f)return!0}}}}}),xg.releasePrimitive(k),xg.releasePrimitive(A),H===1/0?null:(a.point?a.point.copy(B):a.point=B.clone(),a.distance=H,a.faceIndex=V,l&&(l.point?l.point.copy(N):l.point=N.clone(),l.point.applyMatrix4(aC),B.applyMatrix4(aC),l.distance=B.sub(l.point).length(),l.faceIndex=W),a)}function _9(u,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=u.geometry,a=t.index?t.index.array:null,l=t.attributes.position;let f,m,b,S,x=0;const C=u._roots;for(let k=0,A=C.length;k<A;k++)f=C[k],m=new Uint32Array(f),b=new Uint16Array(f),S=new Float32Array(f),E(0,x),x+=f.byteLength;function E(k,A,O=!1){const B=k*2;if(qu(B,b)){const z=rf(k,m),N=th(B,b);let H=1/0,V=1/0,W=1/0,X=-1/0,Y=-1/0,$=-1/0;for(let te=z,Z=z+N;te<Z;te++){const Q=3*u.resolveTriangleIndex(te);for(let ie=0;ie<3;ie++){let ue=Q+ie;ue=a?a[ue]:ue;const he=l.getX(ue),Se=l.getY(ue),Me=l.getZ(ue);he<H&&(H=he),he>X&&(X=he),Se<V&&(V=Se),Se>Y&&(Y=Se),Me<W&&(W=Me),Me>$&&($=Me)}}return S[k+0]!==H||S[k+1]!==V||S[k+2]!==W||S[k+3]!==X||S[k+4]!==Y||S[k+5]!==$?(S[k+0]=H,S[k+1]=V,S[k+2]=W,S[k+3]=X,S[k+4]=Y,S[k+5]=$,!0):!1}else{const z=Tc(k),N=Ec(k,m);let H=O,V=!1,W=!1;if(e){if(!H){const Q=z/Gu+A/nf,ie=N/Gu+A/nf;V=e.has(Q),W=e.has(ie),H=!V&&!W}}else V=!0,W=!0;const X=H||V,Y=H||W;let $=!1;X&&($=E(z,A,H));let te=!1;Y&&(te=E(N,A,H));const Z=$||te;if(Z)for(let Q=0;Q<3;Q++){const ie=z+Q,ue=N+Q,he=S[ie],Se=S[ie+3],Me=S[ue],ce=S[ue+3];S[k+Q]=he<Me?he:Me,S[k+Q+3]=Se>ce?Se:ce}return Z}}}function w9(u,e,t,a,l,f,m){Jo.setBuffer(u._roots[e]),t3(0,u,t,a,l,f,m),Jo.clearBuffer()}function t3(u,e,t,a,l,f,m){const{float32Array:b,uint16Array:S,uint32Array:x}=Jo,C=u*2;if(qu(C,S)){const E=rf(u,x),k=th(C,S);c9(e,t,a,E,k,l,f,m)}else{const E=Tc(u);_1(E,b,a,f,m)&&t3(E,e,t,a,l,f,m);const k=Ec(u,x);_1(k,b,a,f,m)&&t3(k,e,t,a,l,f,m)}}const T9=["x","y","z"];function E9(u,e,t,a,l,f){Jo.setBuffer(u._roots[e]);const m=n3(0,u,t,a,l,f);return Jo.clearBuffer(),m}function n3(u,e,t,a,l,f){const{float32Array:m,uint16Array:b,uint32Array:S}=Jo;let x=u*2;if(qu(x,b)){const C=rf(u,S),E=th(x,b);return d9(e,t,a,C,E,l,f)}else{const C=zP(u,S),E=T9[C],k=a.direction[E]>=0;let A,O;k?(A=Tc(u),O=Ec(u,S)):(A=Ec(u,S),O=Tc(u));const B=_1(A,m,a,l,f)?n3(A,e,t,a,l,f):null;if(B){const N=B.point[E];if(k?N<=m[O+C]:N>=m[O+C+3])return B}const z=_1(O,m,a,l,f)?n3(O,e,t,a,l,f):null;return B&&z?B.distance<=z.distance?B:z:B||z||null}}const iC=new Ni,M_=new W0,C_=new W0,gT=new Wn,mO=new nh,oC=new nh;function M9(u,e,t,a){Jo.setBuffer(u._roots[e]);const l=r3(0,u,t,a);return Jo.clearBuffer(),l}function r3(u,e,t,a,l=null){const{float32Array:f,uint16Array:m,uint32Array:b}=Jo;let S=u*2;if(l===null&&(t.boundingBox||t.computeBoundingBox(),mO.set(t.boundingBox.min,t.boundingBox.max,a),l=mO),qu(S,m)){const x=e.geometry,C=x.index,E=x.attributes.position,k=t.index,A=t.attributes.position,O=rf(u,b),B=th(S,m);if(gT.copy(a).invert(),t.boundsTree)return al(u,f,oC),oC.matrix.copy(gT),oC.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:z=>oC.intersectsBox(z),intersectsTriangle:z=>{z.a.applyMatrix4(a),z.b.applyMatrix4(a),z.c.applyMatrix4(a),z.needsUpdate=!0;for(let N=O,H=B+O;N<H;N++)if(lu(C_,3*e.resolveTriangleIndex(N),C,E),C_.needsUpdate=!0,z.intersectsTriangle(C_))return!0;return!1}});{const z=XM(t);for(let N=O,H=B+O;N<H;N++){const V=e.resolveTriangleIndex(N);lu(M_,3*V,C,E),M_.a.applyMatrix4(gT),M_.b.applyMatrix4(gT),M_.c.applyMatrix4(gT),M_.needsUpdate=!0;for(let W=0,X=z*3;W<X;W+=3)if(lu(C_,W,k,A),C_.needsUpdate=!0,M_.intersectsTriangle(C_))return!0}}}else{const x=Tc(u),C=Ec(u,b);return al(x,f,iC),!!(l.intersectsBox(iC)&&r3(x,e,t,a,l)||(al(C,f,iC),l.intersectsBox(iC)&&r3(C,e,t,a,l)))}}const sC=new Wn,a3=new nh,vT=new nh,C9=new ae,k9=new ae,A9=new ae,P9=new ae;function R9(u,e,t,a={},l={},f=0,m=1/0){e.boundingBox||e.computeBoundingBox(),a3.set(e.boundingBox.min,e.boundingBox.max,t),a3.needsUpdate=!0;const b=u.geometry,S=b.attributes.position,x=b.index,C=e.attributes.position,E=e.index,k=xg.getPrimitive(),A=xg.getPrimitive();let O=C9,B=k9,z=null,N=null;l&&(z=A9,N=P9);let H=1/0,V=null,W=null;return sC.copy(t).invert(),vT.matrix.copy(sC),u.shapecast({boundsTraverseOrder:X=>a3.distanceToBox(X),intersectsBounds:(X,Y,$)=>$<H&&$<m?(Y&&(vT.min.copy(X.min),vT.max.copy(X.max),vT.needsUpdate=!0),!0):!1,intersectsRange:(X,Y)=>{if(e.boundsTree){const $=e.boundsTree;return $.shapecast({boundsTraverseOrder:te=>vT.distanceToBox(te),intersectsBounds:(te,Z,Q)=>Q<H&&Q<m,intersectsRange:(te,Z)=>{for(let Q=te,ie=te+Z;Q<ie;Q++){const ue=$.resolveTriangleIndex(Q);lu(A,3*ue,E,C),A.a.applyMatrix4(t),A.b.applyMatrix4(t),A.c.applyMatrix4(t),A.needsUpdate=!0;for(let he=X,Se=X+Y;he<Se;he++){const Me=u.resolveTriangleIndex(he);lu(k,3*Me,x,S),k.needsUpdate=!0;const ce=k.distanceToTriangle(A,O,z);if(ce<H&&(B.copy(O),N&&N.copy(z),H=ce,V=he,W=Q),ce<f)return!0}}}})}else{const $=XM(e);for(let te=0,Z=$;te<Z;te++){lu(A,3*te,E,C),A.a.applyMatrix4(t),A.b.applyMatrix4(t),A.c.applyMatrix4(t),A.needsUpdate=!0;for(let Q=X,ie=X+Y;Q<ie;Q++){const ue=u.resolveTriangleIndex(Q);lu(k,3*ue,x,S),k.needsUpdate=!0;const he=k.distanceToTriangle(A,O,z);if(he<H&&(B.copy(O),N&&N.copy(z),H=he,V=Q,W=te),he<f)return!0}}}}}),xg.releasePrimitive(k),xg.releasePrimitive(A),H===1/0?null:(a.point?a.point.copy(B):a.point=B.clone(),a.distance=H,a.faceIndex=V,l&&(l.point?l.point.copy(N):l.point=N.clone(),l.point.applyMatrix4(sC),B.applyMatrix4(sC),l.distance=B.sub(l.point).length(),l.faceIndex=W),a)}function gO(u,e,t){return u===null?null:(u.point.applyMatrix4(e.matrixWorld),u.distance=u.point.distanceTo(t.ray.origin),u.object=e,u)}const lC=new nh,uC=new u1,vO=new ae,yO=new Wn,bO=new ae,i3=["getX","getY","getZ"];class w1 extends JW{static serialize(e,t={}){t={cloneBuffers:!0,...t};const a=e.geometry,l=e._roots,f=e._indirectBuffer,m=a.getIndex(),b={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(b.roots=l.map(S=>S.slice()),b.index=m?m.array.slice():null,b.indirectBuffer=f?f.slice():null):(b.roots=l,b.index=m?m.array:null,b.indirectBuffer=f),b}static deserialize(e,t,a={}){a={setIndex:!0,indirect:!!e.indirectBuffer,...a};const{index:l,roots:f,indirectBuffer:m}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),S(f));const b=new w1(t,{...a,[OP]:!0});if(b._roots=f,b._indirectBuffer=m||null,a.setIndex){const x=t.getIndex();if(x===null){const C=new Di(e.index,1,!1);t.setIndex(C)}else x.array!==l&&(x.array.set(l),x.needsUpdate=!0)}return b;function S(x){for(let C=0;C<x.length;C++){const E=x[C],k=new Uint32Array(E),A=new Uint16Array(E);for(let O=0,B=E.byteLength/nf;O<B;O++){const z=Gu*O,N=2*z;qu(N,A)||(k[z+6]=k[z+6]/Gu-O)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,a){const l=this.geometry,f=this._indirectBuffer,m=l.attributes.position,b=l.index?l.index.array:null,S=(f?f[e]:e)*3;let x=S+0,C=S+1,E=S+2;b&&(x=b[x],C=b[C],E=b[E]);for(let k=0;k<3;k++){const A=m[i3[k]](x),O=m[i3[k]](C),B=m[i3[k]](E);let z=A;O<z&&(z=O),B<z&&(z=B);let N=A;O>N&&(N=O),B>N&&(N=B),t[a+k]=z,t[a+k+3]=N}return t}computePrimitiveBounds(e,t,a){const l=this.geometry,f=this._indirectBuffer,m=l.attributes.position,b=l.index?l.index.array:null,S=m.normalized;if(e<0||t+e-a.offset>a.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const x=m.array,C=m.offset||0;let E=3;m.isInterleavedBufferAttribute&&(E=m.data.stride);const k=["getX","getY","getZ"],A=a.offset;for(let O=e,B=e+t;O<B;O++){const z=(f?f[O]:O)*3,N=(O-A)*6;let H=z+0,V=z+1,W=z+2;b&&(H=b[H],V=b[V],W=b[W]),S||(H=H*E+C,V=V*E+C,W=W*E+C);for(let X=0;X<3;X++){let Y,$,te;S?(Y=m[k[X]](H),$=m[k[X]](V),te=m[k[X]](W)):(Y=x[H+X],$=x[V+X],te=x[W+X]);let Z=Y;$<Z&&(Z=$),te<Z&&(Z=te);let Q=Y;$>Q&&(Q=$),te>Q&&(Q=te);const ie=(Q-Z)/2,ue=X*2;a[N+ue+0]=Z+ie,a[N+ue+1]=ie+(Math.abs(Z)+ie)*WM}}return a}raycastObject3D(e,t,a=[]){const{material:l}=e;if(l===void 0)return;yO.copy(e.matrixWorld).invert(),uC.copy(t.ray).applyMatrix4(yO),bO.setFromMatrixScale(e.matrixWorld),vO.copy(uC.direction).multiply(bO);const f=vO.length(),m=t.near/f,b=t.far/f;if(t.firstHitOnly===!0){let S=this.raycastFirst(uC,l,m,b);S=gO(S,e,t),S&&a.push(S)}else{const S=this.raycast(uC,l,m,b);for(let x=0,C=S.length;x<C;x++){const E=gO(S[x],e,t);E&&a.push(E)}}return a}refit(e=null){return(this.indirect?_9:u9)(this,e)}raycast(e,t=L0,a=0,l=1/0){const f=this._roots,m=[],b=this.indirect?w9:h9;for(let S=0,x=f.length;S<x;S++)b(this,S,t,e,m,a,l);return m}raycastFirst(e,t=L0,a=0,l=1/0){const f=this._roots;let m=null;const b=this.indirect?E9:m9;for(let S=0,x=f.length;S<x;S++){const C=b(this,S,t,e,a,l);C!=null&&(m==null||C.distance<m.distance)&&(m=C)}return m}intersectsGeometry(e,t){let a=!1;const l=this._roots,f=this.indirect?M9:g9;for(let m=0,b=l.length;m<b&&(a=f(this,m,e,t),!a);m++);return a}shapecast(e){const t=xg.getPrimitive(),a=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?f9:l9});return xg.releasePrimitive(t),a}bvhcast(e,t,a){let{intersectsRanges:l,intersectsTriangles:f}=a;const m=xg.getPrimitive(),b=this.geometry.index,S=this.geometry.attributes.position,x=this.indirect?O=>{const B=this.resolveTriangleIndex(O);lu(m,B*3,b,S)}:O=>{lu(m,O*3,b,S)},C=xg.getPrimitive(),E=e.geometry.index,k=e.geometry.attributes.position,A=e.indirect?O=>{const B=e.resolveTriangleIndex(O);lu(C,B*3,E,k)}:O=>{lu(C,O*3,E,k)};if(f){if(!(e instanceof w1))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const O=(B,z,N,H,V,W,X,Y)=>{for(let $=N,te=N+H;$<te;$++){A($),C.a.applyMatrix4(t),C.b.applyMatrix4(t),C.c.applyMatrix4(t),C.needsUpdate=!0;for(let Z=B,Q=B+z;Z<Q;Z++)if(x(Z),m.needsUpdate=!0,f(m,C,Z,$,V,W,X,Y))return!0}return!1};if(l){const B=l;l=function(z,N,H,V,W,X,Y,$){return B(z,N,H,V,W,X,Y,$)?!0:O(z,N,H,V,W,X,Y,$)}}else l=O}return super.bvhcast(e,t,{intersectsRanges:l})}intersectsBox(e,t){return lC.set(e.min,e.max,t),lC.needsUpdate=!0,this.shapecast({intersectsBounds:a=>lC.intersectsBox(a),intersectsTriangle:a=>lC.intersectsTriangle(a)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,a={},l={},f=0,m=1/0){return(this.indirect?R9:x9)(this,e,t,a,l,f,m)}closestPointToPoint(e,t={},a=0,l=1/0){return r9(this,e,t,a,l)}}const o3=hW((u,e)=>({landmarkPoints:[],isAligned:!1,isCut:!1,addLandmarkPoint:t=>u(a=>a.landmarkPoints.length>=3?a:{landmarkPoints:[...a.landmarkPoints,t]}),removeLandmarkPoint:t=>u(a=>({landmarkPoints:a.landmarkPoints.filter((l,f)=>f!==t)})),clearLandmarkPoints:()=>u({landmarkPoints:[],isAligned:!1,isCut:!1}),updateLandmarkPositions:t=>u(a=>({landmarkPoints:a.landmarkPoints.map((l,f)=>({...l,position:t[f]??l.position}))})),setAligned:t=>u({isAligned:t}),setCut:t=>u({isCut:t}),isSelectionComplete:()=>e().landmarkPoints.length===3})),N9=.45,cC=3,D9=.001,yT=25.4,I9=5;function L9(u){const e=u.split(`
|
|
4731
|
-
`),t=[],a=[];let l=!1;for(const f of e)if(f.startsWith("v ")){const m=f.trim().split(/\s+/);if(m.length>=7){t.push(parseFloat(m[1]),parseFloat(m[2]),parseFloat(m[3]));let b=parseFloat(m[4]),S=parseFloat(m[5]),x=parseFloat(m[6]);(b>1||S>1||x>1)&&(b/=255,S/=255,x/=255),a.push(b,S,x),l=!0}else m.length>=4&&(t.push(parseFloat(m[1]),parseFloat(m[2]),parseFloat(m[3])),a.push(0,0,0))}return l?{positions:new Float32Array(t),colors:new Float32Array(a)}:null}function O9(u,e,t,a){const l=u.getAttribute("position"),f=l.count,m=new Float32Array(f*3),b=e.length/3;let S=1/0,x=1/0,C=1/0,E=-1/0,k=-1/0,A=-1/0;for(let V=0;V<b;V++){const W=e[V*3]*a,X=e[V*3+1]*a,Y=e[V*3+2]*a;W<S&&(S=W),W>E&&(E=W),X<x&&(x=X),X>k&&(k=X),Y<C&&(C=Y),Y>A&&(A=Y)}const O=Math.min(128,Math.max(16,Math.round(Math.cbrt(b)))),B=(E-S+1e-6)/O,z=(k-x+1e-6)/O,N=(A-C+1e-6)/O,H=new Map;for(let V=0;V<b;V++){const W=Math.min(O-1,Math.floor((e[V*3]*a-S)/B)),X=Math.min(O-1,Math.floor((e[V*3+1]*a-x)/z)),Y=Math.min(O-1,Math.floor((e[V*3+2]*a-C)/N)),$=W*O*O+X*O+Y;let te=H.get($);te||(te=[],H.set($,te)),te.push(V)}for(let V=0;V<f;V++){const W=l.getX(V),X=l.getY(V),Y=l.getZ(V),$=Math.min(O-1,Math.max(0,Math.floor((W-S)/B))),te=Math.min(O-1,Math.max(0,Math.floor((X-x)/z))),Z=Math.min(O-1,Math.max(0,Math.floor((Y-C)/N)));let Q=1/0,ie=0;for(let ue=0;ue<=O&&Q>0;ue++){for(let he=-ue;he<=ue;he++)for(let Se=-ue;Se<=ue;Se++)for(let Me=-ue;Me<=ue;Me++){if(ue>0&&Math.abs(he)<ue&&Math.abs(Se)<ue&&Math.abs(Me)<ue)continue;const ce=$+he,xe=te+Se,_e=Z+Me;if(ce<0||ce>=O||xe<0||xe>=O||_e<0||_e>=O)continue;const Qe=H.get(ce*O*O+xe*O+_e);if(Qe)for(const it of Qe){const se=e[it*3]*a,ye=e[it*3+1]*a,Ce=e[it*3+2]*a,Le=(W-se)**2+(X-ye)**2+(Y-Ce)**2;Le<Q&&(Q=Le,ie=it)}}if(Q<1/0)break}m[V*3]=t[ie*3],m[V*3+1]=t[ie*3+1],m[V*3+2]=t[ie*3+2]}u.setAttribute("color",new Sn(m,3))}const z9=({message:u,onDismiss:e})=>rn.jsxs("div",{style:{position:"absolute",top:16,right:16,padding:"12px 16px",backgroundColor:"rgba(220, 53, 69, 0.95)",borderRadius:8,color:"#fff",fontSize:14,maxWidth:300,zIndex:100,display:"flex",alignItems:"flex-start",gap:12},children:[rn.jsxs("div",{style:{flex:1},children:[rn.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:"Error"}),rn.jsx("div",{style:{fontSize:12,opacity:.9},children:u})]}),rn.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"#fff",cursor:"pointer",fontSize:18,padding:0,lineHeight:1,opacity:.7},children:"\xD7"})]}),SO=({message:u})=>rn.jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.7)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:100},children:[rn.jsx("div",{style:{width:48,height:48,border:"4px solid rgba(255, 255, 255, 0.2)",borderTopColor:"#4a90d9",borderRadius:"50%",animation:"spin 1s linear infinite"}}),u&&rn.jsx("div",{style:{marginTop:16,color:"#fff",fontSize:14},children:u}),rn.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]});function xO(u,e){const t=1/e;return`${Math.round(u.x*t)}_${Math.round(u.y*t)}_${Math.round(u.z*t)}`}function F9(u,e=.001){if(!u.length)return[];const t=new Map,a=m=>{const b=xO(m,e);let S=t.get(b);return S||(S=m.clone(),t.set(b,S)),S},l=u.map(m=>({a:a(m.a),b:a(m.b)})),f=[];for(;l.length;){const m=l.pop(),b=[m.a,m.b];let S=!0;for(;S;){S=!1;for(let C=l.length-1;C>=0;C--){const{a:E,b:k}=l[C];if(E.equals(b[b.length-1]))b.push(k);else if(k.equals(b[b.length-1]))b.push(E);else if(E.equals(b[0]))b.unshift(k);else if(k.equals(b[0]))b.unshift(E);else continue;l.splice(C,1),S=!0}}const x=_O(b,e);x.length>1&&f.push(x)}return f.length?(f.sort((m,b)=>dC(b)-dC(m)),f[0]??[]):[]}function _O(u,e){if(!u.length)return[];const t=[];for(const a of u)(t.length===0||t[t.length-1].distanceTo(a)>e)&&t.push(a.clone());return t.length>2&&t[0].distanceTo(t[t.length-1])>e&&t.push(t[0].clone()),t}function dC(u){let e=0;for(let t=0;t<u.length-1;t++)e+=u[t].distanceTo(u[t+1]);return e}function bT(u,e,t){const a=new $h(new ae(0,1,0),-t),l=[],f=new Ni;if(f.setFromBufferAttribute(e.getAttribute("position")),!a.intersectsBox(f))return{linePoints:[],lineLength:0,rightmostPoint:new ae(0,t,0)};const m=new rm,b=new ae;u.shapecast({intersectsBounds:k=>a.intersectsBox(k),intersectsTriangle:k=>{const A=[];m.set(k.a,k.b),a.intersectLine(m,b)&&A.push(b.clone()),m.set(k.b,k.c),a.intersectLine(m,b)&&A.push(b.clone()),m.set(k.c,k.a),a.intersectLine(m,b)&&A.push(b.clone()),A.length===2&&l.push({a:A[0],b:A[1]})}});const S=F9(l,D9),x=dC(S);if(S.length<2)return{linePoints:[],lineLength:0,rightmostPoint:new ae(0,t,0)};let C=-1/0,E=new ae(0,t,0);for(const k of S)k.x>C&&(C=k.x,E=k.clone());return{linePoints:S,lineLength:x,rightmostPoint:E}}function wO(u){return It.useMemo(()=>u?new w1(u,{maxLeafSize:cC}):null,[u])}function TO(u,e,t){const a=u instanceof w1?u:new w1(u,{maxLeafSize:cC}),l=new $h().setFromNormalAndCoplanarPoint(t.clone().normalize(),e),f=[],m=new rm,b=new ae;return a.shapecast({intersectsBounds:S=>l.intersectsBox(S),intersectsTriangle:S=>{const x=[];m.set(S.a,S.b),l.intersectLine(m,b)&&x.push(b.clone()),m.set(S.b,S.c),l.intersectLine(m,b)&&x.push(b.clone()),m.set(S.c,S.a),l.intersectLine(m,b)&&x.push(b.clone()),x.length===2&&f.push({a:x[0],b:x[1]})}}),f}function EO(u,e,t=.001){if(!u.length)return[];const a=new Map,l=x=>{const C=xO(x,t);let E=a.get(C);return E||(E=x.clone(),a.set(C,E)),E},f=u.map(x=>({a:l(x.a),b:l(x.b)})),m=[];for(;f.length;){const x=f.pop(),C=[x.a,x.b];let E=!0;for(;E;){E=!1;for(let A=f.length-1;A>=0;A--){const{a:O,b:B}=f[A];if(O.equals(C[C.length-1]))C.push(B);else if(B.equals(C[C.length-1]))C.push(O);else if(O.equals(C[0]))C.unshift(B);else if(B.equals(C[0]))C.unshift(O);else continue;f.splice(A,1),E=!0}}const k=_O(C,t);k.length>1&&m.push(k)}if(!m.length)return[];let b=[],S=1/0;for(const x of m){if(x.length<3||!(x[0].distanceTo(x[x.length-1])<2))continue;const C=new ae;for(const k of x)C.add(k);C.divideScalar(x.length);const E=C.distanceTo(e);E<S&&(S=E,b=x)}if(b.length===0)for(const x of m){if(x.length<3)continue;const C=new ae;for(const k of x)C.add(k);C.divideScalar(x.length);const E=C.distanceTo(e);E<S&&(S=E,b=x)}return b}function U9(u){const e=new ae;for(const t of u)e.add(t);return e.divideScalar(u.length)}function B9(u,e,t){const a=new w1(u,{maxLeafSize:cC}),l=new ae().subVectors(e,t).normalize(),f=e.distanceTo(t)*.05;let m=l.clone();const b=z=>{const N=[];for(let Q=-10;Q<=0;Q++){const ie=e.clone().addScaledVector(z,Q*f),ue=TO(a,ie,z),he=EO(ue,ie,1);he.length>=3&&he[0].distanceTo(he[he.length-1])<1&&N.push(U9(he))}if(N.length<3)return null;const H=new ae;for(const Q of N)H.add(Q);H.divideScalar(N.length);let V=0,W=0,X=0,Y=0,$=0,te=0;for(const Q of N){const ie=Q.x-H.x,ue=Q.y-H.y,he=Q.z-H.z;V+=ie*ie,W+=ie*ue,X+=ie*he,Y+=ue*ue,$+=ue*he,te+=he*he}let Z=z.clone();for(let Q=0;Q<30;Q++){const ie=V*Z.x+W*Z.y+X*Z.z,ue=W*Z.x+Y*Z.y+$*Z.z,he=X*Z.x+$*Z.y+te*Z.z,Se=new ae(ie,ue,he),Me=Se.length();if(Me<1e-10||(Se.divideScalar(Me),Z.distanceTo(Se)<1e-8))break;Z=Se}return Z.dot(l)<0&&Z.negate(),Z};for(let z=0;z<3;z++){const N=b(m);if(!N)break;const H=m.angleTo(N);if(m=N,H<.001)break}const S=new ae;Math.abs(m.x)<.9?S.set(1,0,0):S.set(0,1,0),S.crossVectors(m,S).normalize();const x=new ae().crossVectors(m,S).normalize(),C=z=>{const N=TO(a,e,z),H=EO(N,e,1);if(H.length<3)return{circumference:1/0,closed:!1};const V=H[0].distanceTo(H[H.length-1])<1;return{circumference:dC(H),closed:V}};let E=m.clone(),k=1/0;for(let z=-3;z<=3;z+=1)for(let N=-3;N<=3;N+=1){const H=z*Math.PI/180,V=N*Math.PI/180,W=m.clone().applyQuaternion(new tl().setFromAxisAngle(S,H)).applyQuaternion(new tl().setFromAxisAngle(x,V)).normalize(),X=C(W);X.closed&&X.circumference<k&&(k=X.circumference,E=W)}const A=E.clone(),O=new ae;Math.abs(A.x)<.9?O.set(1,0,0):O.set(0,1,0),O.crossVectors(A,O).normalize();const B=new ae().crossVectors(A,O).normalize();for(let z=-5;z<=5;z+=1)for(let N=-5;N<=5;N+=1){const H=z*.1*Math.PI/180,V=N*.1*Math.PI/180,W=A.clone().applyQuaternion(new tl().setFromAxisAngle(O,H)).applyQuaternion(new tl().setFromAxisAngle(B,V)).normalize(),X=C(W);X.closed&&X.circumference<k&&(k=X.circumference,E=W)}return k===1/0&&(k=C(m).circumference,E=m),{normal:E,circumference:k}}function MO(u,e,t,a){const l=t.clone().normalize(),f=u.getAttribute("position"),m=u.getIndex();if(!m)throw new Error("No index buffer");const b=new ae().subVectors(a,e).dot(l),S=Math.abs(b)<1e-6?1:Math.sign(b),x=f.array,C=m.array,E=u.getAttribute("color"),k=E?E.array:null,A=[],O=[],B=[],z=(ye,Ce,Le)=>{const Pt=A.length/3;return A.push(ye,Ce,Le),Pt},N=ye=>new ae(x[ye*3],x[ye*3+1],x[ye*3+2]),H=(ye,Ce)=>{const Le=new ae().subVectors(ye,e).dot(l),Pt=new ae().subVectors(Ce,e).dot(l),Ke=Le/(Le-Pt);return new ae().lerpVectors(ye,Ce,Ke)},V=new Map,W=new Map,X=ye=>{if(V.has(ye))return V.get(ye);const Ce=N(ye),Le=z(Ce.x,Ce.y,Ce.z);return k&&O.push(k[ye*3],k[ye*3+1],k[ye*3+2]),V.set(ye,Le),Le},Y=new Map,$=ye=>{let Ce=Y.get(ye);return Ce===void 0&&(Ce=new ae().subVectors(N(ye),e).dot(l),Y.set(ye,Ce)),Ce},te=(ye,Ce)=>{const Le=ye<Ce?`${ye}_${Ce}`:`${Ce}_${ye}`;if(W.has(Le))return W.get(Le);const Pt=H(N(ye),N(Ce)),Ke=z(Pt.x,Pt.y,Pt.z);if(k){const Je=$(ye),zt=$(Ce),Qt=Je/(Je-zt);O.push(k[ye*3]+Qt*(k[Ce*3]-k[ye*3]),k[ye*3+1]+Qt*(k[Ce*3+1]-k[ye*3+1]),k[ye*3+2]+Qt*(k[Ce*3+2]-k[ye*3+2]))}return W.set(Le,Ke),Ke},Z=ye=>{const Ce=$(ye);return Math.sign(Ce)===S||Math.abs(Ce)<1e-6};for(let ye=0;ye<C.length;ye+=3){const Ce=C[ye],Le=C[ye+1],Pt=C[ye+2],Ke=Z(Ce),Je=Z(Le),zt=Z(Pt),Qt=(Ke?1:0)+(Je?1:0)+(zt?1:0);if(Qt!==0)if(Qt===3)B.push(X(Ce),X(Le),X(Pt));else if(Qt===1){let Kt,We,vn;Ke?(Kt=Ce,We=Le,vn=Pt):Je?(Kt=Le,We=Pt,vn=Ce):(Kt=Pt,We=Ce,vn=Le),B.push(X(Kt),te(Kt,We),te(Kt,vn))}else{let Kt,We,vn;Ke?Je?(Kt=Pt,We=Ce,vn=Le):(Kt=Le,We=Pt,vn=Ce):(Kt=Ce,We=Le,vn=Pt);const ve=X(We),Nt=X(vn),Ge=te(We,Kt),tt=te(vn,Kt);B.push(ve,Ge,Nt),B.push(Nt,Ge,tt)}}const Q=B.length/3,ie=new Map;for(let ye=0;ye<Q;ye++)for(let Ce=0;Ce<3;Ce++){const Le=B[ye*3+Ce];ie.has(Le)||ie.set(Le,[]),ie.get(Le).push(ye)}const ue=new Set,he=[];for(let ye=0;ye<Q;ye++){if(ue.has(ye))continue;const Ce=[],Le=[ye];for(ue.add(ye);Le.length>0;){const Pt=Le.shift();Ce.push(Pt);for(let Ke=0;Ke<3;Ke++){const Je=B[Pt*3+Ke];for(const zt of ie.get(Je))ue.has(zt)||(ue.add(zt),Le.push(zt))}}he.push(Ce)}let Se=he[0]||[],Me=1/0;for(const ye of he){let Ce=1/0;for(const Le of ye){for(let Pt=0;Pt<3;Pt++){const Ke=B[Le*3+Pt],Je=A[Ke*3]-a.x,zt=A[Ke*3+1]-a.y,Qt=A[Ke*3+2]-a.z,Kt=Je*Je+zt*zt+Qt*Qt;Kt<Ce&&(Ce=Kt)}if(Ce<Me)break}Ce<Me&&(Me=Ce,Se=ye)}const ce=new Map,xe=[],_e=[],Qe=[];let it=0;for(const ye of Se)for(let Ce=0;Ce<3;Ce++){const Le=B[ye*3+Ce];ce.has(Le)||(xe.push(A[Le*3],A[Le*3+1],A[Le*3+2]),k&&_e.push(O[Le*3],O[Le*3+1],O[Le*3+2]),ce.set(Le,it++)),Qe.push(ce.get(Le))}const se=new Nr;return se.setAttribute("position",new Sn(xe,3)),k&&_e.length>0&&se.setAttribute("color",new Sn(_e,3)),se.setIndex(Qe),se.computeVertexNormals(),se.computeBoundingBox(),se}function V9(u,e,t,a){const l=new ae().subVectors(t,e),f=new ae().subVectors(a,e),m=new ae().subVectors(u,e),b=l.dot(l),S=l.dot(f),x=l.dot(m),C=f.dot(f),E=f.dot(m),k=1/(b*C-S*S),A=(C*x-S*E)*k,O=(b*E-S*x)*k;return{u:1-A-O,v:A,w:O}}let CO,kO,AO,PO,RO,NO,DO,s3,IO,LO;CO=({mesh:u,maxPoints:e=2,meshColor:t="#c8c8c8",meshOpacity:a=1})=>{const{addLandmarkPoint:l,landmarkPoints:f}=o3(),m=It.useCallback(x=>{if(f.length>=e)return;x.stopPropagation();const C=x.intersections[0],E=C?.faceIndex;if(!C||E==null)return;const k=u.geometry,A=k.index;let O;A?O=[A.getX(E*3),A.getX(E*3+1),A.getX(E*3+2)]:O=[E*3,E*3+1,E*3+2];const B=k.getAttribute("position"),z=new ae().fromBufferAttribute(B,O[0]),N=new ae().fromBufferAttribute(B,O[1]),H=new ae().fromBufferAttribute(B,O[2]);z.applyMatrix4(u.matrixWorld),N.applyMatrix4(u.matrixWorld),H.applyMatrix4(u.matrixWorld);const V=C.point,W=V9(V,z,N,H),X={faceIndex:E,vertexIndices:O,position:{x:V.x,y:V.y,z:V.z},barycentricCoords:W};l(X)},[u,l,f.length,e]),b=It.useMemo(()=>!!u.geometry.getAttribute("color"),[u]),S=It.useMemo(()=>new Yw({color:b?"#ffffff":t,side:Xh,roughness:.6,metalness:.1,transparent:a<1,opacity:a,vertexColors:b}),[t,a,b]);return rn.jsx("primitive",{object:u,onClick:m,material:S})},kO=({modelSize:u})=>{const{landmarkPoints:e}=o3(),t=u*.02,a=["#ff4444","#44ff44","#4444ff"];return rn.jsx(rn.Fragment,{children:e.map((l,f)=>rn.jsxs("mesh",{position:[l.position.x,l.position.y,l.position.z],children:[rn.jsx("sphereGeometry",{args:[t,16,16]}),rn.jsx("meshBasicMaterial",{color:a[f]})]},f))})},AO=({mesh:u,greenY:e,modelSize:t})=>{const a=u.geometry;a.computeBoundingBox();const l=a.boundingBox?.min.y??0,f=e-l,m=-t*.4,b=t*.03,S=new ae(m,e,0),x=new ae(m,l,0),C=new ae(m,(e+l)/2,0),E=new ae(m-b,e,0),k=new ae(m+b,e,0),A=new ae(m-b,l,0),O=new ae(m+b,l,0);return rn.jsxs("group",{children:[rn.jsx(y_,{points:[S,x],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx(y_,{points:[E,k],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx(y_,{points:[A,O],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx("mesh",{position:C,children:rn.jsx(kP,{center:!0,children:rn.jsxs("div",{style:{padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.7)",borderRadius:4,color:"#fff",fontSize:16,fontFamily:"monospace",whiteSpace:"nowrap",transform:"rotate(-90deg)",transformOrigin:"center center"},children:[f.toFixed(1)," mm"]})})})]})},PO=({position:u,value:e})=>rn.jsx("mesh",{position:u,children:rn.jsx(kP,{center:!0,children:rn.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.7)",borderRadius:4,marginLeft:10},children:[rn.jsx("span",{style:{fontSize:16,color:"#fff",fontFamily:"monospace",minWidth:60,textAlign:"right"},children:e.toFixed(1)}),rn.jsx("span",{style:{fontSize:16,color:"#fff",fontFamily:"monospace"},children:"mm"})]})})}),RO=({bvh:u,geometry:e,yPosition:t,color:a="#00ff00",labelX:l,onDataChange:f})=>{const m=It.useMemo(()=>bT(u,e,t),[u,e,t]),{linePoints:b,lineLength:S,rightmostPoint:x}=m;if(It.useEffect(()=>{S>0&&f?.({yPosition:t,originalValue:S,modifiedValue:null})},[S,t,f]),b.length<2)return null;const C=new ae(l,t,0);return rn.jsxs("group",{children:[rn.jsx(y_,{points:[x,C],color:"#666",lineWidth:1,depthTest:!1,depthWrite:!1,transparent:!0}),rn.jsx(PO,{position:C,value:S}),rn.jsx(y_,{points:b,color:a,lineWidth:3,depthTest:!1,depthWrite:!1,transparent:!0})]})},NO=It.memo(RO),DO=({mesh:u,startY:e,endY:t,spacing:a,modelSize:l,onMeasurementsChange:f,reverseOrder:m=!1})=>{const b=It.useRef(new Map),S=u.geometry,x=wO(S),C=It.useMemo(()=>{const O=[];if(m)for(let B=t;B>=e;B-=a)O.push(B);else for(let B=e;B<=t;B+=a)O.push(B);return O},[e,t,a,m]);It.useEffect(()=>{b.current.clear()},[C]);const E=["#00ff00","#ffff00","#ff00ff","#00ffff","#ff8800","#88ff00"],k=l*N9,A=It.useCallback(O=>{b.current.set(O.yPosition,O);const B=Array.from(b.current.values()).sort((z,N)=>m?N.yPosition-z.yPosition:z.yPosition-N.yPosition);f?.(B)},[f,m]);return x?rn.jsx(rn.Fragment,{children:C.map((O,B)=>rn.jsx(NO,{bvh:x,geometry:S,yPosition:O,color:E[B%E.length],labelX:k,onDataChange:A},O))}):null},s3=({mesh:u,yPosition:e,onYChange:t,minY:a,maxY:l,modelSize:f,color:m,hoverColor:b,dragColor:S,label:x})=>{const[C,E]=It.useState(!1),[k,A]=It.useState(!1),{camera:O,gl:B}=yg(),z=It.useRef(0),N=u.geometry,H=wO(N),V=It.useMemo(()=>H?bT(H,N,e):{linePoints:[],lineLength:0,rightmostPoint:new ae},[H,N,e]),W=It.useCallback((Z,Q)=>{const ie=B.domElement.getBoundingClientRect(),ue=(Z-ie.left)/ie.width*2-1,he=-((Q-ie.top)/ie.height)*2+1,Se=new VA;Se.setFromCamera(new Ot(ue,he),O);const Me=new $h(new ae(0,0,1),0),ce=new ae;return Se.ray.intersectPlane(Me,ce),ce?ce.y:e},[O,B,e]),X=It.useCallback(Z=>{Z.stopPropagation(),E(!0),B.domElement.style.cursor="ns-resize",z.current=e-W(Z.clientX,Z.clientY),Z.target.setPointerCapture(Z.pointerId)},[e,B,W]),Y=It.useCallback(Z=>{if(!C)return;let Q=W(Z.clientX,Z.clientY)+z.current;Q=Math.max(a,Math.min(l,Q)),t(Q)},[C,W,t,a,l]),$=It.useCallback(Z=>{E(!1),B.domElement.style.cursor="auto",Z.target.releasePointerCapture(Z.pointerId)},[B]);if(V.linePoints.length<2)return null;const te=C?S:k?b:m;return rn.jsxs("group",{children:[rn.jsx(y_,{points:V.linePoints,color:te,lineWidth:C?6:k?5:4,depthTest:!1,depthWrite:!1,transparent:!0,onPointerDown:X,onPointerMove:Y,onPointerUp:$,onPointerEnter:()=>{A(!0),B.domElement.style.cursor="ns-resize"},onPointerLeave:()=>{C||(A(!1),B.domElement.style.cursor="auto")}}),(k||C)&&rn.jsx("mesh",{position:[V.rightmostPoint.x+f*.15,e,0],children:rn.jsx(kP,{center:!0,children:rn.jsx("div",{style:{padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.8)",borderRadius:4,color:te,fontSize:11,whiteSpace:"nowrap",pointerEvents:"none"},children:C?"Dragging...":x})})})]})},IO=({modelSize:u,isAligned:e,isCut:t,mesh:a})=>{const{set:l,size:f,camera:m}=yg(),b=It.useRef(!1),S=It.useRef(e),x=It.useRef(t),C=It.useRef(new ae);return It.useEffect(()=>{if(u>0&&!b.current&&!e){b.current=!0;const E=new ls(50,f.width/f.height,.1,u*10);E.position.set(u*.3,u*.2,u*1.5),E.lookAt(0,0,0),l({camera:E})}},[u,f,l,e]),It.useEffect(()=>{if(!(S.current===e&&x.current===t)&&(S.current=e,x.current=t,e&&a&&u>0)){const E=a.geometry;E.computeBoundingBox();const k=E.boundingBox,A=new ae;k.getCenter(A);const O=new ae;k.getSize(O),C.current.copy(O);const B=f.width/f.height,z=Math.max(O.y,O.x/B)*1.2,N=z*B,H=new V0(-N/2,N/2,z/2,-z/2,.1,u*10);H.position.set(0,A.y,u*2),H.lookAt(0,A.y,0),l({camera:H})}},[e,t,a,u,l,f]),It.useEffect(()=>{if(e&&m&&m.isOrthographicCamera){const E=m,k=C.current,A=f.width/f.height,O=Math.max(k.y,k.x/A)*1.2,B=O*A;E.left=-B/2,E.right=B/2,E.top=O/2,E.bottom=-O/2,E.updateProjectionMatrix()}},[f.width,f.height,e,m]),null},LO=({objUrl:u,spacingType:e="BK"})=>{const[t,a]=It.useState(null),[l,f]=It.useState(0),[m,b]=It.useState(!1),[S,x]=It.useState(""),[C,E]=It.useState(!1),[k,A]=It.useState("mm"),[O,B]=It.useState(!1),[z,N]=It.useState(""),[H,V]=It.useState([]),[W,X]=It.useState(null),[Y,$]=It.useState(null),[te,Z]=It.useState(null),[Q,ie]=It.useState(null),[ue,he]=It.useState(!1),Se=It.useRef(null),Me=It.useRef(null),{landmarkPoints:ce,clearLandmarkPoints:xe,addLandmarkPoint:_e,removeLandmarkPoint:Qe,updateLandmarkPositions:it,setAligned:se,isAligned:ye,setCut:Ce,isCut:Le}=o3(),Pt=(e==="AK"?2:1)*yT;It.useEffect(()=>{if(H.length===0)return;const Ge=Me.current?.closest("fab-one-widget");Ge&&Ge.dispatchEvent(new CustomEvent("measurements",{detail:H,bubbles:!0,composed:!0}))},[H]),It.useEffect(()=>{(async()=>{try{const Ge=await import("./protosthetics_geo-C8ArKwiO.js");await Ge.default(),Se.current=Ge}catch(Ge){console.warn("WASM module not available:",Ge)}finally{he(!0)}})()},[]);const Ke=async Ge=>{const tt=Se.current;if(!tt)return null;let Be=null;try{const Ft=L9(Ge);x("Loading mesh..."),Be=new tt.WasmMeshSet,Be.loadObjString(Ge),x("Detecting units...");const ft=Be.autoScaleToMm(I9);x("Merging close vertices..."),Be.applyMergeCloseVertices(1e-4),x("Removing floating artifacts..."),Be.splitAndKeepLargest(),x("Closing holes..."),Be.applyCloseHoles(30),Be.applyMergeCloseVertices(1e-4),x("Extracting geometry...");const Ze=Be.getVertices(),Ht=Be.getFaces();if(Ze.length===0)return null;const Xt=new Nr;if(Xt.setAttribute("position",new Sn(Ze,3)),Xt.setIndex(Array.from(Ht)),Xt.computeVertexNormals(),Ft){const ge=ft?1e3:1;O9(Xt,Ft.positions,Ft.colors,ge)}return{geometry:Xt,wasScaled:ft}}catch(Ft){return console.error("WASM processing failed:",Ft),null}finally{if(Be)try{Be.free()}catch{}}},Je=Ge=>{const tt=new RW().parse(Ge);let Be=null;return tt.traverse(Ft=>{Ft.isMesh&&!Be&&(Be=Ft.geometry)}),Be},zt=It.useCallback((Ge,tt)=>{Ge.computeBoundingBox();const Be=Ge.boundingBox,Ft=new ae;Be.getCenter(Ft),Ge.translate(-Ft.x,-Ft.y,-Ft.z),Ge.computeBoundingBox();const ft=Ge.boundingBox,Ze=new ae;ft.getSize(Ze),f(Math.max(Ze.x,Ze.y,Ze.z));const Ht=new ss(Ge,new Yw({color:8947848,side:Xh}));a(Ht)},[]);It.useEffect(()=>{u&&(async()=>{b(!0),x("Fetching OBJ..."),ie(null),xe();try{const Ge=await fetch(u);if(!Ge.ok)throw new Error(`HTTP ${Ge.status}`);const tt=await Ge.text(),Be=await Ke(tt);if(Be)zt(Be.geometry,Be.wasScaled);else{x("Using fallback loader...");const Ft=Je(tt);Ft?zt(Ft,!1):ie("Failed to parse the mesh.")}}catch(Ge){ie(Ge instanceof Error?Ge.message:"Failed to fetch OBJ.")}finally{b(!1),x("")}})()},[u]);const Qt=(Ge,tt,Be)=>{const Ft=Ge.getAttribute("position"),ft=Be-tt;if(ft<1)return null;const Ze=30,Ht=ft/Ze,Xt=[];for(let ln=0;ln<Ze;ln++){const Jt=tt+ln*Ht,At=tt+(ln+1)*Ht;let Dt=0,we=0,at=0,St=0;for(let ne=0;ne<Ft.count;ne++){const le=Ft.getY(ne);le>=Jt&&le<At&&(Dt+=Ft.getX(ne),we+=le,at+=Ft.getZ(ne),St++)}St>20&&Xt.push(new ae(Dt/St,we/St,at/St))}if(Xt.length<5)return null;const ge=new ae;for(const ln of Xt)ge.add(ln);ge.divideScalar(Xt.length);let oe=0,Oe=0,dt=0,pt=0,xt=0,cn=0;for(const ln of Xt){const Jt=ln.x-ge.x,At=ln.y-ge.y,Dt=ln.z-ge.z;oe+=Jt*Jt,Oe+=Jt*At,dt+=Jt*Dt,pt+=At*At,xt+=At*Dt,cn+=Dt*Dt}let Bt=new ae(.01,1,.01).normalize();for(let ln=0;ln<30;ln++){const Jt=oe*Bt.x+Oe*Bt.y+dt*Bt.z,At=Oe*Bt.x+pt*Bt.y+xt*Bt.z,Dt=dt*Bt.x+xt*Bt.y+cn*Bt.z,we=new ae(Jt,At,Dt),at=we.length();if(at<1e-10||(we.divideScalar(at),Bt.distanceTo(we)<1e-8))break;Bt=we}return Bt.y<0&&Bt.negate(),Bt},Kt=(Ge,tt,Be,Ft)=>{const ft=tt-Be;if(ft<4)return{valid:!1,reason:`Height too small (${ft.toFixed(1)}mm < 4mm)`};if(ft>1e3)return{valid:!1,reason:`Height too large (${ft.toFixed(1)}mm > 1000mm)`};const Ze=new w1(Ge,{maxLeafSize:cC}),Ht=bT(Ze,Ge,tt),Xt=tt-Ft;if(Xt<=Be)return{valid:!0,reason:""};const ge=bT(Ze,Ge,Xt);if(Ht.lineLength>0&&ge.lineLength>0){const Oe=Ht.lineLength/ge.lineLength;if(Oe<.5)return{valid:!1,reason:`First circumference is too small relative to second (ratio ${Oe.toFixed(2)} < 0.5) \u2014 possible trimmed angle`}}const oe=tt-Ft*2;if(oe>Be){const Oe=bT(Ze,Ge,oe);if(ge.lineLength>0&&Oe.lineLength>0){const dt=ge.lineLength/Oe.lineLength;if(dt<.5)return{valid:!1,reason:`Second circumference is too small relative to third (ratio ${dt.toFixed(2)} < 0.5) \u2014 possible trimmed angle`}}}return{valid:!0,reason:""}},We=It.useCallback(()=>{if(!t||ce.length<2)return;B(!0),N("Finding optimal cut plane...");const Ge=3,tt=t.geometry.clone(),Be=ce.map(Ft=>({...Ft}));setTimeout(()=>{let Ft="";for(let ft=0;ft<Ge;ft++)try{ft>0&&(N(`Retry ${ft}/${Ge-1} \u2014 nudging green point \u2014 ${Ft}`),t.geometry.dispose(),t.geometry=tt.clone(),Qe(2),se(!1),Ce(!1));let Ze=t.geometry,Ht=Be.map(Et=>new ae(Et.position.x,Et.position.y,Et.position.z));if(ft>0){const Et=2*ft,_n=ft*Math.PI*2/3,dn=new ae().subVectors(Ht[1],Ht[0]).normalize(),Mr=new ae;Math.abs(dn.x)<.9?Mr.crossVectors(dn,new ae(1,0,0)).normalize():Mr.crossVectors(dn,new ae(0,0,1)).normalize(),Mr.applyAxisAngle(dn,_n),Ht[1].addScaledVector(Mr,Et);const nr=Ze.getAttribute("position");let Ya=1/0,Oa=0;for(let za=0;za<nr.count;za++){const ui=nr.getX(za)-Ht[1].x,$o=nr.getY(za)-Ht[1].y,Mi=nr.getZ(za)-Ht[1].z,on=ui*ui+$o*$o+Mi*Mi;on<Ya&&(Ya=on,Oa=za)}Ht[1].set(nr.getX(Oa),nr.getY(Oa),nr.getZ(Oa))}const Xt=new ae(0,1,0),ge=(Et,_n)=>{const dn=new tl().setFromAxisAngle(Et,_n);Ze.applyMatrix4(new Wn().makeRotationFromQuaternion(dn)),Ht=Ht.map(Mr=>Mr.clone().applyQuaternion(dn))},oe=Ht[0],Oe=Ht[1],{normal:dt}=B9(Ze,Oe,oe);N(ft>0?`Retry ${ft}: Slicing mesh...`:"Slicing mesh at cut plane...");const pt=new ae().subVectors(Oe,oe).normalize(),xt=Math.sign(pt.dot(dt)),cn=Oe.clone().addScaledVector(dt,xt*3*yT),Bt=MO(Ze,cn,dt,oe);Ze.dispose(),Ze=Bt,t.geometry=Ze,N(ft>0?`Retry ${ft}: Rough alignment...`:"Rough alignment...");const ln=new ae().subVectors(Ht[1],Ht[0]).normalize();let Jt=ln.dot(Xt),At=new ae().crossVectors(ln,Xt);At.length()>1e-4&&(At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))))),Ht[0].y>Ht[1].y&&ge(new ae(1,0,0),Math.PI),Ze.computeVertexNormals(),N(ft>0?`Retry ${ft}: Translating...`:"Translating to origin...");const Dt=Ht[0].clone();Ze.translate(-Dt.x,-Dt.y,-Dt.z),Ht=Ht.map(Et=>new ae(Et.x-Dt.x,Et.y-Dt.y,Et.z-Dt.z)),N(ft>0?`Retry ${ft}: PCA alignment...`:"Iterative PCA alignment...");const we=10,at=80,St=Ht[0].y,ne=Ht[1].y;let le=ne-we;for(let Et=0;Et<at;Et++){const _n=Math.min(le,ne),dn=Math.max(le,ne),Mr=Qt(Ze,_n,dn);if(Mr&&(Jt=Mr.dot(Xt),Math.acos(Math.min(1,Math.abs(Jt)))*180/Math.PI>.1&&(At=new ae().crossVectors(Mr,Xt),At.length()>1e-4))){At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))));const nr=Ht[0].clone();Ze.translate(-nr.x,-nr.y,-nr.z),Ht=Ht.map(Ya=>new ae(Ya.x-nr.x,Ya.y-nr.y,Ya.z-nr.z))}if(le-=we,le<=St)break}Ze.computeVertexNormals(),N(ft>0?`Retry ${ft}: Setting blue point...`:"Setting blue point...");const Ne=new ae(Ht[0].x,Ht[0].y,Ht[0].z);Ht.push(Ne),_e({faceIndex:-1,vertexIndices:[0,1,2],position:{x:Ne.x,y:Ne.y,z:Ne.z},barycentricCoords:{u:.33,v:.33,w:.34}}),N(ft>0?`Retry ${ft}: Final PCA...`:"Final PCA refinement...");for(let Et=0;Et<3;Et++){const _n=Qt(Ze,0,Ht[1].y);if(_n){if(Jt=_n.dot(Xt),Math.acos(Math.min(1,Math.abs(Jt)))*180/Math.PI<.1)break;if(At=new ae().crossVectors(_n,Xt),At.length()>1e-4){At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))));const dn=Ht[0].clone();Ze.translate(-dn.x,-dn.y,-dn.z),Ht=Ht.map(Mr=>new ae(Mr.x-dn.x,Mr.y-dn.y,Mr.z-dn.z))}}}if(Ht[1].y<Ht[0].y){ge(new ae(1,0,0),Math.PI);const Et=Ht[0].clone();Ze.translate(-Et.x,-Et.y,-Et.z),Ht=Ht.map(_n=>new ae(_n.x-Et.x,_n.y-Et.y,_n.z-Et.z))}Ze.computeVertexNormals(),Ze.computeBoundingBox();const $e=Ht.map(Et=>({x:Et.x,y:Et.y,z:Et.z}));it($e),se(!0),N(ft>0?`Retry ${ft}: Cutting mesh...`:"Cutting mesh above green..."),vn(t,Ht,Ze),N("Validating results...");const Rt=t.geometry,lt=Ht[1].y,Xe=Ht[0].y,Wt=Kt(Rt,lt,Xe,Pt);if(Wt.valid)break;Ft=Wt.reason,ft===Ge-1&&(ie(`Processing produced unusual results after ${Ge} attempts: ${Wt.reason}`),t.geometry.dispose(),t.geometry=tt.clone(),Qe(2),se(!1),Ce(!1))}catch(Ze){console.error("Processing failed:",Ze),ie(Ze instanceof Error?Ze.message:"Failed to process mesh.");break}tt.dispose(),B(!1)},50)},[t,ce,it,se,_e,Qe,Ce,Pt]),vn=(Ge,tt,Be)=>{const Ft=Be.getAttribute("position"),ft=Be.getIndex();if(!ft){B(!1);return}const Ze=tt[1].y+3*yT,Ht=Ft.array,Xt=ft.array,ge=Be.getAttribute("color"),oe=ge?ge.array:null,Oe=[],dt=[],pt=[],xt=(on,yn,un)=>{const Qn=Oe.length/3;return Oe.push(on,yn,un),Qn},cn=on=>[Ht[on*3],Ht[on*3+1],Ht[on*3+2]],Bt=(on,yn)=>{const un=(Ze-on[1])/(yn[1]-on[1]);return[on[0]+un*(yn[0]-on[0]),Ze,on[2]+un*(yn[2]-on[2])]},ln=new Map,Jt=new Map,At=on=>{if(ln.has(on))return ln.get(on);const[yn,un,Qn]=cn(on),fa=xt(yn,un,Qn);return oe&&dt.push(oe[on*3],oe[on*3+1],oe[on*3+2]),ln.set(on,fa),fa},Dt=(on,yn)=>{const un=on<yn?`${on}_${yn}`:`${yn}_${on}`;if(Jt.has(un))return Jt.get(un);const Qn=cn(on),fa=cn(yn),[Ja,ci,Xi]=Bt(Qn,fa),No=xt(Ja,ci,Xi);if(oe){const di=(Ze-Qn[1])/(fa[1]-Qn[1]);dt.push(oe[on*3]+di*(oe[yn*3]-oe[on*3]),oe[on*3+1]+di*(oe[yn*3+1]-oe[on*3+1]),oe[on*3+2]+di*(oe[yn*3+2]-oe[on*3+2]))}return Jt.set(un,No),No};for(let on=0;on<Xt.length;on+=3){const yn=Xt[on],un=Xt[on+1],Qn=Xt[on+2],fa=cn(yn),Ja=cn(un),ci=cn(Qn),Xi=fa[1]<Ze,No=Ja[1]<Ze,di=ci[1]<Ze,me=(Xi?1:0)+(No?1:0)+(di?1:0);if(me!==0)if(me===3)pt.push(At(yn),At(un),At(Qn));else if(me===1){let He,ot,Pe;Xi?(He=yn,ot=un,Pe=Qn):No?(He=un,ot=Qn,Pe=yn):(He=Qn,ot=yn,Pe=un),pt.push(At(He),Dt(He,ot),Dt(He,Pe))}else{let He,ot,Pe;Xi?No?(He=Qn,ot=yn,Pe=un):(He=un,ot=Qn,Pe=yn):(He=yn,ot=un,Pe=Qn);const ze=At(ot),wt=At(Pe),an=Dt(ot,He),en=Dt(Pe,He);pt.push(ze,an,wt),pt.push(wt,an,en)}}const we=pt.length/3,at=new Map;for(let on=0;on<we;on++)for(let yn=0;yn<3;yn++){const un=pt[on*3+yn];at.has(un)||at.set(un,[]),at.get(un).push(on)}const St=new Map;for(let on=0;on<we;on++)St.set(on,new Set);for(const[,on]of at)for(const yn of on)for(const un of on)yn!==un&&St.get(yn).add(un);const ne=new Set,le=[];for(let on=0;on<we;on++){if(ne.has(on))continue;const yn=[],un=[on];for(ne.add(on);un.length>0;){const Qn=un.shift();yn.push(Qn);for(const fa of St.get(Qn))ne.has(fa)||(ne.add(fa),un.push(fa))}le.push(yn)}const Ne=tt[0];let $e=le[0]||[],Rt=1/0;for(const on of le){let yn=1/0;for(const un of on){for(let Qn=0;Qn<3;Qn++){const fa=pt[un*3+Qn],Ja=Oe[fa*3]-Ne.x,ci=Oe[fa*3+1]-Ne.y,Xi=Oe[fa*3+2]-Ne.z,No=Ja*Ja+ci*ci+Xi*Xi;No<yn&&(yn=No)}if(yn<Rt)break}yn<Rt&&(Rt=yn,$e=on)}const lt=new Map,Xe=[],Wt=[],Et=[];let _n=0;for(const on of $e)for(let yn=0;yn<3;yn++){const un=pt[on*3+yn];lt.has(un)||(Xe.push(Oe[un*3],Oe[un*3+1],Oe[un*3+2]),oe&&Wt.push(dt[un*3],dt[un*3+1],dt[un*3+2]),lt.set(un,_n++)),Et.push(lt.get(un))}const dn=new Nr;dn.setAttribute("position",new Sn(Xe,3)),oe&&Wt.length>0&&dn.setAttribute("color",new Sn(Wt,3)),dn.setIndex(Et),dn.computeVertexNormals(),dn.computeBoundingBox(),Ge.geometry.dispose(),Ge.geometry=dn,N("Refining alignment...");const Mr=new ae(0,1,0),nr=(on,yn)=>{const un=new tl().setFromAxisAngle(on,yn);dn.applyMatrix4(new Wn().makeRotationFromQuaternion(un)),tt=tt.map(Qn=>Qn.clone().applyQuaternion(un))};for(let on=0;on<5;on++){const yn=dn.getAttribute("position"),un=Math.min(tt[0].y,tt[1].y),Qn=Math.max(tt[0].y,tt[1].y)-un;if(Qn<1)break;const fa=30,Ja=Qn/fa,ci=[];for(let en=0;en<fa;en++){const sn=un+en*Ja,pn=un+(en+1)*Ja;let mn=0,wn=0,Tn=0,rr=0;for(let Cr=0;Cr<yn.count;Cr++){const Jr=yn.getY(Cr);Jr>=sn&&Jr<pn&&(mn+=yn.getX(Cr),wn+=Jr,Tn+=yn.getZ(Cr),rr++)}rr>20&&ci.push(new ae(mn/rr,wn/rr,Tn/rr))}if(ci.length<5)break;const Xi=new ae;for(const en of ci)Xi.add(en);Xi.divideScalar(ci.length);let No=0,di=0,me=0,He=0,ot=0,Pe=0;for(const en of ci){const sn=en.x-Xi.x,pn=en.y-Xi.y,mn=en.z-Xi.z;No+=sn*sn,di+=sn*pn,me+=sn*mn,He+=pn*pn,ot+=pn*mn,Pe+=mn*mn}let ze=new ae(.01,1,.01).normalize();for(let en=0;en<30;en++){const sn=No*ze.x+di*ze.y+me*ze.z,pn=di*ze.x+He*ze.y+ot*ze.z,mn=me*ze.x+ot*ze.y+Pe*ze.z,wn=new ae(sn,pn,mn),Tn=wn.length();if(Tn<1e-10||(wn.divideScalar(Tn),ze.distanceTo(wn)<1e-8))break;ze=wn}ze.y<0&&ze.negate();const wt=ze.dot(Mr);if(Math.acos(Math.min(1,Math.abs(wt)))*180/Math.PI<.1)break;const an=new ae().crossVectors(ze,Mr);an.length()>1e-4&&(an.normalize(),nr(an,Math.acos(Math.min(1,Math.max(-1,wt)))))}tt[0].y>tt[1].y&&nr(new ae(1,0,0),Math.PI);const Ya=tt[0];dn.translate(-Ya.x,-Ya.y,-Ya.z),tt=tt.map(on=>new ae(on.x-Ya.x,on.y-Ya.y,on.z-Ya.z));const Oa=tt[1].y+3*yT,za=MO(dn,new ae(0,Oa,0),new ae(0,1,0),tt[0]);Ge.geometry.dispose(),Ge.geometry=za,za.computeVertexNormals(),za.computeBoundingBox();const ui=tt.map(on=>({x:on.x,y:on.y,z:on.z}));it(ui);const $o=za.boundingBox,Mi=new ae;$o.getSize(Mi),f(Math.max(Mi.x,Mi.y,Mi.z)),Ce(!0),X(null),$(null),Z(tt[1].y)},ve=It.useCallback(Ge=>k==="inch"?Ge/yT:Ge,[k]),Nt=It.useCallback(()=>{if(H.length===0)return;const Ge=ce.length>=2?ce[1].position.y:H[0].yPosition,tt=k==="inch"?"in":"mm",Be=k==="inch"?3:2,Ft=[`Position (${tt})`,`Original Circumference (${tt})`,`Modified Circumference (${tt})`,`Difference (${tt})`],ft=H.map(oe=>{const Oe=oe.yPosition-Ge,dt=oe.modifiedValue??oe.originalValue,pt=oe.modifiedValue!==null?oe.modifiedValue-oe.originalValue:0;return[ve(Oe).toFixed(Be),ve(oe.originalValue).toFixed(Be),ve(dt).toFixed(Be),ve(pt).toFixed(Be)].join(",")}),Ze=[Ft.join(","),...ft].join(`
|
|
4731
|
+
`),t=[],a=[];let l=!1;for(const f of e)if(f.startsWith("v ")){const m=f.trim().split(/\s+/);if(m.length>=7){t.push(parseFloat(m[1]),parseFloat(m[2]),parseFloat(m[3]));let b=parseFloat(m[4]),S=parseFloat(m[5]),x=parseFloat(m[6]);(b>1||S>1||x>1)&&(b/=255,S/=255,x/=255),a.push(b,S,x),l=!0}else m.length>=4&&(t.push(parseFloat(m[1]),parseFloat(m[2]),parseFloat(m[3])),a.push(0,0,0))}return l?{positions:new Float32Array(t),colors:new Float32Array(a)}:null}function O9(u,e,t,a){const l=u.getAttribute("position"),f=l.count,m=new Float32Array(f*3),b=e.length/3;let S=1/0,x=1/0,C=1/0,E=-1/0,k=-1/0,A=-1/0;for(let V=0;V<b;V++){const W=e[V*3]*a,X=e[V*3+1]*a,Y=e[V*3+2]*a;W<S&&(S=W),W>E&&(E=W),X<x&&(x=X),X>k&&(k=X),Y<C&&(C=Y),Y>A&&(A=Y)}const O=Math.min(128,Math.max(16,Math.round(Math.cbrt(b)))),B=(E-S+1e-6)/O,z=(k-x+1e-6)/O,N=(A-C+1e-6)/O,H=new Map;for(let V=0;V<b;V++){const W=Math.min(O-1,Math.floor((e[V*3]*a-S)/B)),X=Math.min(O-1,Math.floor((e[V*3+1]*a-x)/z)),Y=Math.min(O-1,Math.floor((e[V*3+2]*a-C)/N)),$=W*O*O+X*O+Y;let te=H.get($);te||(te=[],H.set($,te)),te.push(V)}for(let V=0;V<f;V++){const W=l.getX(V),X=l.getY(V),Y=l.getZ(V),$=Math.min(O-1,Math.max(0,Math.floor((W-S)/B))),te=Math.min(O-1,Math.max(0,Math.floor((X-x)/z))),Z=Math.min(O-1,Math.max(0,Math.floor((Y-C)/N)));let Q=1/0,ie=0;for(let ue=0;ue<=O&&Q>0;ue++){for(let he=-ue;he<=ue;he++)for(let Se=-ue;Se<=ue;Se++)for(let Me=-ue;Me<=ue;Me++){if(ue>0&&Math.abs(he)<ue&&Math.abs(Se)<ue&&Math.abs(Me)<ue)continue;const ce=$+he,xe=te+Se,_e=Z+Me;if(ce<0||ce>=O||xe<0||xe>=O||_e<0||_e>=O)continue;const Qe=H.get(ce*O*O+xe*O+_e);if(Qe)for(const it of Qe){const se=e[it*3]*a,ye=e[it*3+1]*a,Ce=e[it*3+2]*a,Le=(W-se)**2+(X-ye)**2+(Y-Ce)**2;Le<Q&&(Q=Le,ie=it)}}if(Q<1/0)break}m[V*3]=t[ie*3],m[V*3+1]=t[ie*3+1],m[V*3+2]=t[ie*3+2]}u.setAttribute("color",new Sn(m,3))}const z9=({message:u,onDismiss:e})=>rn.jsxs("div",{style:{position:"absolute",top:16,right:16,padding:"12px 16px",backgroundColor:"rgba(220, 53, 69, 0.95)",borderRadius:8,color:"#fff",fontSize:14,maxWidth:300,zIndex:100,display:"flex",alignItems:"flex-start",gap:12},children:[rn.jsxs("div",{style:{flex:1},children:[rn.jsx("div",{style:{fontWeight:"bold",marginBottom:4},children:"Error"}),rn.jsx("div",{style:{fontSize:12,opacity:.9},children:u})]}),rn.jsx("button",{onClick:e,style:{background:"none",border:"none",color:"#fff",cursor:"pointer",fontSize:18,padding:0,lineHeight:1,opacity:.7},children:"\xD7"})]}),SO=({message:u})=>rn.jsxs("div",{style:{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:"rgba(0, 0, 0, 0.7)",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",zIndex:100},children:[rn.jsx("div",{style:{width:48,height:48,border:"4px solid rgba(255, 255, 255, 0.2)",borderTopColor:"#4a90d9",borderRadius:"50%",animation:"spin 1s linear infinite"}}),u&&rn.jsx("div",{style:{marginTop:16,color:"#fff",fontSize:14},children:u}),rn.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]});function xO(u,e){const t=1/e;return`${Math.round(u.x*t)}_${Math.round(u.y*t)}_${Math.round(u.z*t)}`}function F9(u,e=.001){if(!u.length)return[];const t=new Map,a=m=>{const b=xO(m,e);let S=t.get(b);return S||(S=m.clone(),t.set(b,S)),S},l=u.map(m=>({a:a(m.a),b:a(m.b)})),f=[];for(;l.length;){const m=l.pop(),b=[m.a,m.b];let S=!0;for(;S;){S=!1;for(let C=l.length-1;C>=0;C--){const{a:E,b:k}=l[C];if(E.equals(b[b.length-1]))b.push(k);else if(k.equals(b[b.length-1]))b.push(E);else if(E.equals(b[0]))b.unshift(k);else if(k.equals(b[0]))b.unshift(E);else continue;l.splice(C,1),S=!0}}const x=_O(b,e);x.length>1&&f.push(x)}return f.length?(f.sort((m,b)=>dC(b)-dC(m)),f[0]??[]):[]}function _O(u,e){if(!u.length)return[];const t=[];for(const a of u)(t.length===0||t[t.length-1].distanceTo(a)>e)&&t.push(a.clone());return t.length>2&&t[0].distanceTo(t[t.length-1])>e&&t.push(t[0].clone()),t}function dC(u){let e=0;for(let t=0;t<u.length-1;t++)e+=u[t].distanceTo(u[t+1]);return e}function bT(u,e,t){const a=new $h(new ae(0,1,0),-t),l=[],f=new Ni;if(f.setFromBufferAttribute(e.getAttribute("position")),!a.intersectsBox(f))return{linePoints:[],lineLength:0,rightmostPoint:new ae(0,t,0)};const m=new rm,b=new ae;u.shapecast({intersectsBounds:k=>a.intersectsBox(k),intersectsTriangle:k=>{const A=[];m.set(k.a,k.b),a.intersectLine(m,b)&&A.push(b.clone()),m.set(k.b,k.c),a.intersectLine(m,b)&&A.push(b.clone()),m.set(k.c,k.a),a.intersectLine(m,b)&&A.push(b.clone()),A.length===2&&l.push({a:A[0],b:A[1]})}});const S=F9(l,D9),x=dC(S);if(S.length<2)return{linePoints:[],lineLength:0,rightmostPoint:new ae(0,t,0)};let C=-1/0,E=new ae(0,t,0);for(const k of S)k.x>C&&(C=k.x,E=k.clone());return{linePoints:S,lineLength:x,rightmostPoint:E}}function wO(u){return It.useMemo(()=>u?new w1(u,{maxLeafSize:cC}):null,[u])}function TO(u,e,t){const a=u instanceof w1?u:new w1(u,{maxLeafSize:cC}),l=new $h().setFromNormalAndCoplanarPoint(t.clone().normalize(),e),f=[],m=new rm,b=new ae;return a.shapecast({intersectsBounds:S=>l.intersectsBox(S),intersectsTriangle:S=>{const x=[];m.set(S.a,S.b),l.intersectLine(m,b)&&x.push(b.clone()),m.set(S.b,S.c),l.intersectLine(m,b)&&x.push(b.clone()),m.set(S.c,S.a),l.intersectLine(m,b)&&x.push(b.clone()),x.length===2&&f.push({a:x[0],b:x[1]})}}),f}function EO(u,e,t=.001){if(!u.length)return[];const a=new Map,l=x=>{const C=xO(x,t);let E=a.get(C);return E||(E=x.clone(),a.set(C,E)),E},f=u.map(x=>({a:l(x.a),b:l(x.b)})),m=[];for(;f.length;){const x=f.pop(),C=[x.a,x.b];let E=!0;for(;E;){E=!1;for(let A=f.length-1;A>=0;A--){const{a:O,b:B}=f[A];if(O.equals(C[C.length-1]))C.push(B);else if(B.equals(C[C.length-1]))C.push(O);else if(O.equals(C[0]))C.unshift(B);else if(B.equals(C[0]))C.unshift(O);else continue;f.splice(A,1),E=!0}}const k=_O(C,t);k.length>1&&m.push(k)}if(!m.length)return[];let b=[],S=1/0;for(const x of m){if(x.length<3||!(x[0].distanceTo(x[x.length-1])<2))continue;const C=new ae;for(const k of x)C.add(k);C.divideScalar(x.length);const E=C.distanceTo(e);E<S&&(S=E,b=x)}if(b.length===0)for(const x of m){if(x.length<3)continue;const C=new ae;for(const k of x)C.add(k);C.divideScalar(x.length);const E=C.distanceTo(e);E<S&&(S=E,b=x)}return b}function U9(u){const e=new ae;for(const t of u)e.add(t);return e.divideScalar(u.length)}function B9(u,e,t){const a=new w1(u,{maxLeafSize:cC}),l=new ae().subVectors(e,t).normalize(),f=e.distanceTo(t)*.05;let m=l.clone();const b=z=>{const N=[];for(let Q=-10;Q<=0;Q++){const ie=e.clone().addScaledVector(z,Q*f),ue=TO(a,ie,z),he=EO(ue,ie,1);he.length>=3&&he[0].distanceTo(he[he.length-1])<1&&N.push(U9(he))}if(N.length<3)return null;const H=new ae;for(const Q of N)H.add(Q);H.divideScalar(N.length);let V=0,W=0,X=0,Y=0,$=0,te=0;for(const Q of N){const ie=Q.x-H.x,ue=Q.y-H.y,he=Q.z-H.z;V+=ie*ie,W+=ie*ue,X+=ie*he,Y+=ue*ue,$+=ue*he,te+=he*he}let Z=z.clone();for(let Q=0;Q<30;Q++){const ie=V*Z.x+W*Z.y+X*Z.z,ue=W*Z.x+Y*Z.y+$*Z.z,he=X*Z.x+$*Z.y+te*Z.z,Se=new ae(ie,ue,he),Me=Se.length();if(Me<1e-10||(Se.divideScalar(Me),Z.distanceTo(Se)<1e-8))break;Z=Se}return Z.dot(l)<0&&Z.negate(),Z};for(let z=0;z<3;z++){const N=b(m);if(!N)break;const H=m.angleTo(N);if(m=N,H<.001)break}const S=new ae;Math.abs(m.x)<.9?S.set(1,0,0):S.set(0,1,0),S.crossVectors(m,S).normalize();const x=new ae().crossVectors(m,S).normalize(),C=z=>{const N=TO(a,e,z),H=EO(N,e,1);if(H.length<3)return{circumference:1/0,closed:!1};const V=H[0].distanceTo(H[H.length-1])<1;return{circumference:dC(H),closed:V}};let E=m.clone(),k=1/0;for(let z=-3;z<=3;z+=1)for(let N=-3;N<=3;N+=1){const H=z*Math.PI/180,V=N*Math.PI/180,W=m.clone().applyQuaternion(new tl().setFromAxisAngle(S,H)).applyQuaternion(new tl().setFromAxisAngle(x,V)).normalize(),X=C(W);X.closed&&X.circumference<k&&(k=X.circumference,E=W)}const A=E.clone(),O=new ae;Math.abs(A.x)<.9?O.set(1,0,0):O.set(0,1,0),O.crossVectors(A,O).normalize();const B=new ae().crossVectors(A,O).normalize();for(let z=-5;z<=5;z+=1)for(let N=-5;N<=5;N+=1){const H=z*.1*Math.PI/180,V=N*.1*Math.PI/180,W=A.clone().applyQuaternion(new tl().setFromAxisAngle(O,H)).applyQuaternion(new tl().setFromAxisAngle(B,V)).normalize(),X=C(W);X.closed&&X.circumference<k&&(k=X.circumference,E=W)}return k===1/0&&(k=C(m).circumference,E=m),{normal:E,circumference:k}}function MO(u,e,t,a){const l=t.clone().normalize(),f=u.getAttribute("position"),m=u.getIndex();if(!m)throw new Error("No index buffer");const b=new ae().subVectors(a,e).dot(l),S=Math.abs(b)<1e-6?1:Math.sign(b),x=f.array,C=m.array,E=u.getAttribute("color"),k=E?E.array:null,A=[],O=[],B=[],z=(ye,Ce,Le)=>{const Pt=A.length/3;return A.push(ye,Ce,Le),Pt},N=ye=>new ae(x[ye*3],x[ye*3+1],x[ye*3+2]),H=(ye,Ce)=>{const Le=new ae().subVectors(ye,e).dot(l),Pt=new ae().subVectors(Ce,e).dot(l),Ke=Le/(Le-Pt);return new ae().lerpVectors(ye,Ce,Ke)},V=new Map,W=new Map,X=ye=>{if(V.has(ye))return V.get(ye);const Ce=N(ye),Le=z(Ce.x,Ce.y,Ce.z);return k&&O.push(k[ye*3],k[ye*3+1],k[ye*3+2]),V.set(ye,Le),Le},Y=new Map,$=ye=>{let Ce=Y.get(ye);return Ce===void 0&&(Ce=new ae().subVectors(N(ye),e).dot(l),Y.set(ye,Ce)),Ce},te=(ye,Ce)=>{const Le=ye<Ce?`${ye}_${Ce}`:`${Ce}_${ye}`;if(W.has(Le))return W.get(Le);const Pt=H(N(ye),N(Ce)),Ke=z(Pt.x,Pt.y,Pt.z);if(k){const Je=$(ye),zt=$(Ce),Qt=Je/(Je-zt);O.push(k[ye*3]+Qt*(k[Ce*3]-k[ye*3]),k[ye*3+1]+Qt*(k[Ce*3+1]-k[ye*3+1]),k[ye*3+2]+Qt*(k[Ce*3+2]-k[ye*3+2]))}return W.set(Le,Ke),Ke},Z=ye=>{const Ce=$(ye);return Math.sign(Ce)===S||Math.abs(Ce)<1e-6};for(let ye=0;ye<C.length;ye+=3){const Ce=C[ye],Le=C[ye+1],Pt=C[ye+2],Ke=Z(Ce),Je=Z(Le),zt=Z(Pt),Qt=(Ke?1:0)+(Je?1:0)+(zt?1:0);if(Qt!==0)if(Qt===3)B.push(X(Ce),X(Le),X(Pt));else if(Qt===1){let Kt,We,vn;Ke?(Kt=Ce,We=Le,vn=Pt):Je?(Kt=Le,We=Pt,vn=Ce):(Kt=Pt,We=Ce,vn=Le),B.push(X(Kt),te(Kt,We),te(Kt,vn))}else{let Kt,We,vn;Ke?Je?(Kt=Pt,We=Ce,vn=Le):(Kt=Le,We=Pt,vn=Ce):(Kt=Ce,We=Le,vn=Pt);const ve=X(We),Nt=X(vn),Ge=te(We,Kt),tt=te(vn,Kt);B.push(ve,Ge,Nt),B.push(Nt,Ge,tt)}}const Q=B.length/3,ie=new Map;for(let ye=0;ye<Q;ye++)for(let Ce=0;Ce<3;Ce++){const Le=B[ye*3+Ce];ie.has(Le)||ie.set(Le,[]),ie.get(Le).push(ye)}const ue=new Set,he=[];for(let ye=0;ye<Q;ye++){if(ue.has(ye))continue;const Ce=[],Le=[ye];for(ue.add(ye);Le.length>0;){const Pt=Le.shift();Ce.push(Pt);for(let Ke=0;Ke<3;Ke++){const Je=B[Pt*3+Ke];for(const zt of ie.get(Je))ue.has(zt)||(ue.add(zt),Le.push(zt))}}he.push(Ce)}let Se=he[0]||[],Me=1/0;for(const ye of he){let Ce=1/0;for(const Le of ye){for(let Pt=0;Pt<3;Pt++){const Ke=B[Le*3+Pt],Je=A[Ke*3]-a.x,zt=A[Ke*3+1]-a.y,Qt=A[Ke*3+2]-a.z,Kt=Je*Je+zt*zt+Qt*Qt;Kt<Ce&&(Ce=Kt)}if(Ce<Me)break}Ce<Me&&(Me=Ce,Se=ye)}const ce=new Map,xe=[],_e=[],Qe=[];let it=0;for(const ye of Se)for(let Ce=0;Ce<3;Ce++){const Le=B[ye*3+Ce];ce.has(Le)||(xe.push(A[Le*3],A[Le*3+1],A[Le*3+2]),k&&_e.push(O[Le*3],O[Le*3+1],O[Le*3+2]),ce.set(Le,it++)),Qe.push(ce.get(Le))}const se=new Nr;return se.setAttribute("position",new Sn(xe,3)),k&&_e.length>0&&se.setAttribute("color",new Sn(_e,3)),se.setIndex(Qe),se.computeVertexNormals(),se.computeBoundingBox(),se}function V9(u,e,t,a){const l=new ae().subVectors(t,e),f=new ae().subVectors(a,e),m=new ae().subVectors(u,e),b=l.dot(l),S=l.dot(f),x=l.dot(m),C=f.dot(f),E=f.dot(m),k=1/(b*C-S*S),A=(C*x-S*E)*k,O=(b*E-S*x)*k;return{u:1-A-O,v:A,w:O}}let CO,kO,AO,PO,RO,NO,DO,s3,IO,LO;CO=({mesh:u,maxPoints:e=2,meshColor:t="#c8c8c8",meshOpacity:a=1})=>{const{addLandmarkPoint:l,landmarkPoints:f}=o3(),m=It.useCallback(x=>{if(f.length>=e)return;x.stopPropagation();const C=x.intersections[0],E=C?.faceIndex;if(!C||E==null)return;const k=u.geometry,A=k.index;let O;A?O=[A.getX(E*3),A.getX(E*3+1),A.getX(E*3+2)]:O=[E*3,E*3+1,E*3+2];const B=k.getAttribute("position"),z=new ae().fromBufferAttribute(B,O[0]),N=new ae().fromBufferAttribute(B,O[1]),H=new ae().fromBufferAttribute(B,O[2]);z.applyMatrix4(u.matrixWorld),N.applyMatrix4(u.matrixWorld),H.applyMatrix4(u.matrixWorld);const V=C.point,W=V9(V,z,N,H),X={faceIndex:E,vertexIndices:O,position:{x:V.x,y:V.y,z:V.z},barycentricCoords:W};l(X)},[u,l,f.length,e]),b=It.useMemo(()=>!!u.geometry.getAttribute("color"),[u]),S=It.useMemo(()=>new Yw({color:b?"#ffffff":t,side:Xh,roughness:.6,metalness:.1,transparent:a<1,opacity:a,vertexColors:b}),[t,a,b]);return rn.jsx("primitive",{object:u,onClick:m,material:S})},kO=({modelSize:u})=>{const{landmarkPoints:e}=o3(),t=u*.02,a=["#ff4444","#44ff44","#4444ff"];return rn.jsx(rn.Fragment,{children:e.map((l,f)=>rn.jsxs("mesh",{position:[l.position.x,l.position.y,l.position.z],children:[rn.jsx("sphereGeometry",{args:[t,16,16]}),rn.jsx("meshBasicMaterial",{color:a[f]})]},f))})},AO=({mesh:u,greenY:e,modelSize:t})=>{const a=u.geometry;a.computeBoundingBox();const l=a.boundingBox?.min.y??0,f=e-l,m=-t*.4,b=t*.03,S=new ae(m,e,0),x=new ae(m,l,0),C=new ae(m,(e+l)/2,0),E=new ae(m-b,e,0),k=new ae(m+b,e,0),A=new ae(m-b,l,0),O=new ae(m+b,l,0);return rn.jsxs("group",{children:[rn.jsx(y_,{points:[S,x],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx(y_,{points:[E,k],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx(y_,{points:[A,O],color:"#888888",lineWidth:1.5,depthTest:!1}),rn.jsx("mesh",{position:C,children:rn.jsx(kP,{center:!0,children:rn.jsxs("div",{style:{padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.7)",borderRadius:4,color:"#fff",fontSize:16,fontFamily:"monospace",whiteSpace:"nowrap",transform:"rotate(-90deg)",transformOrigin:"center center"},children:[f.toFixed(1)," mm"]})})})]})},PO=({position:u,value:e})=>rn.jsx("mesh",{position:u,children:rn.jsx(kP,{center:!0,children:rn.jsxs("div",{style:{display:"flex",alignItems:"center",gap:4,padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.7)",borderRadius:4,marginLeft:10},children:[rn.jsx("span",{style:{fontSize:16,color:"#fff",fontFamily:"monospace",minWidth:60,textAlign:"right"},children:e.toFixed(1)}),rn.jsx("span",{style:{fontSize:16,color:"#fff",fontFamily:"monospace"},children:"mm"})]})})}),RO=({bvh:u,geometry:e,yPosition:t,color:a="#00ff00",labelX:l,onDataChange:f})=>{const m=It.useMemo(()=>bT(u,e,t),[u,e,t]),{linePoints:b,lineLength:S,rightmostPoint:x}=m;if(It.useEffect(()=>{S>0&&f?.({yPosition:t,originalValue:S,modifiedValue:null})},[S,t,f]),b.length<2)return null;const C=new ae(l,t,0);return rn.jsxs("group",{children:[rn.jsx(y_,{points:[x,C],color:"#666",lineWidth:1,depthTest:!1,depthWrite:!1,transparent:!0}),rn.jsx(PO,{position:C,value:S}),rn.jsx(y_,{points:b,color:a,lineWidth:3,depthTest:!1,depthWrite:!1,transparent:!0})]})},NO=It.memo(RO),DO=({mesh:u,startY:e,endY:t,spacing:a,modelSize:l,onMeasurementsChange:f,reverseOrder:m=!1})=>{const b=It.useRef(new Map),S=u.geometry,x=wO(S),C=It.useMemo(()=>{const O=[];if(m)for(let B=t;B>=e;B-=a)O.push(B);else for(let B=e;B<=t;B+=a)O.push(B);return O},[e,t,a,m]);It.useEffect(()=>{b.current.clear()},[C]);const E=["#00ff00","#ffff00","#ff00ff","#00ffff","#ff8800","#88ff00"],k=l*N9,A=It.useCallback(O=>{b.current.set(O.yPosition,O);const B=Array.from(b.current.values()).sort((z,N)=>m?N.yPosition-z.yPosition:z.yPosition-N.yPosition);f?.(B)},[f,m]);return x?rn.jsx(rn.Fragment,{children:C.map((O,B)=>rn.jsx(NO,{bvh:x,geometry:S,yPosition:O,color:E[B%E.length],labelX:k,onDataChange:A},O))}):null},s3=({mesh:u,yPosition:e,onYChange:t,minY:a,maxY:l,modelSize:f,color:m,hoverColor:b,dragColor:S,label:x})=>{const[C,E]=It.useState(!1),[k,A]=It.useState(!1),{camera:O,gl:B}=yg(),z=It.useRef(0),N=u.geometry,H=wO(N),V=It.useMemo(()=>H?bT(H,N,e):{linePoints:[],lineLength:0,rightmostPoint:new ae},[H,N,e]),W=It.useCallback((Z,Q)=>{const ie=B.domElement.getBoundingClientRect(),ue=(Z-ie.left)/ie.width*2-1,he=-((Q-ie.top)/ie.height)*2+1,Se=new VA;Se.setFromCamera(new Ot(ue,he),O);const Me=new $h(new ae(0,0,1),0),ce=new ae;return Se.ray.intersectPlane(Me,ce),ce?ce.y:e},[O,B,e]),X=It.useCallback(Z=>{Z.stopPropagation(),E(!0),B.domElement.style.cursor="ns-resize",z.current=e-W(Z.clientX,Z.clientY),Z.target.setPointerCapture(Z.pointerId)},[e,B,W]),Y=It.useCallback(Z=>{if(!C)return;let Q=W(Z.clientX,Z.clientY)+z.current;Q=Math.max(a,Math.min(l,Q)),t(Q)},[C,W,t,a,l]),$=It.useCallback(Z=>{E(!1),B.domElement.style.cursor="auto",Z.target.releasePointerCapture(Z.pointerId)},[B]);if(V.linePoints.length<2)return null;const te=C?S:k?b:m;return rn.jsxs("group",{children:[rn.jsx(y_,{points:V.linePoints,color:te,lineWidth:C?6:k?5:4,depthTest:!1,depthWrite:!1,transparent:!0,onPointerDown:X,onPointerMove:Y,onPointerUp:$,onPointerEnter:()=>{A(!0),B.domElement.style.cursor="ns-resize"},onPointerLeave:()=>{C||(A(!1),B.domElement.style.cursor="auto")}}),(k||C)&&rn.jsx("mesh",{position:[V.rightmostPoint.x+f*.15,e,0],children:rn.jsx(kP,{center:!0,children:rn.jsx("div",{style:{padding:"4px 8px",backgroundColor:"rgba(0, 0, 0, 0.8)",borderRadius:4,color:te,fontSize:11,whiteSpace:"nowrap",pointerEvents:"none"},children:C?"Dragging...":x})})})]})},IO=({modelSize:u,isAligned:e,isCut:t,mesh:a})=>{const{set:l,size:f,camera:m}=yg(),b=It.useRef(!1),S=It.useRef(e),x=It.useRef(t),C=It.useRef(new ae);return It.useEffect(()=>{if(u>0&&!b.current&&!e){b.current=!0;const E=new ls(50,f.width/f.height,.1,u*10);E.position.set(u*.3,u*.2,u*1.5),E.lookAt(0,0,0),l({camera:E})}},[u,f,l,e]),It.useEffect(()=>{if(!(S.current===e&&x.current===t)&&(S.current=e,x.current=t,e&&a&&u>0)){const E=a.geometry;E.computeBoundingBox();const k=E.boundingBox,A=new ae;k.getCenter(A);const O=new ae;k.getSize(O),C.current.copy(O);const B=f.width/f.height,z=Math.max(O.y,O.x/B)*1.2,N=z*B,H=new V0(-N/2,N/2,z/2,-z/2,.1,u*10);H.position.set(0,A.y,u*2),H.lookAt(0,A.y,0),l({camera:H})}},[e,t,a,u,l,f]),It.useEffect(()=>{if(e&&m&&m.isOrthographicCamera){const E=m,k=C.current,A=f.width/f.height,O=Math.max(k.y,k.x/A)*1.2,B=O*A;E.left=-B/2,E.right=B/2,E.top=O/2,E.bottom=-O/2,E.updateProjectionMatrix()}},[f.width,f.height,e,m]),null},LO=({objUrl:u,spacingType:e="BK"})=>{const[t,a]=It.useState(null),[l,f]=It.useState(0),[m,b]=It.useState(!1),[S,x]=It.useState(""),[C,E]=It.useState(!1),[k,A]=It.useState("mm"),[O,B]=It.useState(!1),[z,N]=It.useState(""),[H,V]=It.useState([]),[W,X]=It.useState(null),[Y,$]=It.useState(null),[te,Z]=It.useState(null),[Q,ie]=It.useState(null),[ue,he]=It.useState(!1),Se=It.useRef(null),Me=It.useRef(null),{landmarkPoints:ce,clearLandmarkPoints:xe,addLandmarkPoint:_e,removeLandmarkPoint:Qe,updateLandmarkPositions:it,setAligned:se,isAligned:ye,setCut:Ce,isCut:Le}=o3(),Pt=(e==="AK"?2:1)*yT;It.useEffect(()=>{if(H.length===0)return;const Ge=Me.current?.closest("fab-one-widget");Ge&&Ge.dispatchEvent(new CustomEvent("measurements",{detail:H,bubbles:!0,composed:!0}))},[H]),It.useEffect(()=>{(async()=>{try{const Ge=await import("./protosthetics_geo-C8ArKwiO.js");await Ge.default(),Se.current=Ge}catch(Ge){console.warn("WASM module not available:",Ge)}finally{he(!0)}})()},[]);const Ke=async Ge=>{const tt=Se.current;if(!tt)return null;let Be=null;try{const Ft=L9(Ge);x("Loading mesh..."),Be=new tt.WasmMeshSet,Be.loadObjString(Ge),x("Detecting units...");const ft=Be.autoScaleToMm(I9);x("Merging close vertices..."),Be.applyMergeCloseVertices(1e-4),x("Removing floating artifacts..."),Be.splitAndKeepLargest(),x("Closing holes..."),Be.applyCloseHoles(30),Be.applyMergeCloseVertices(1e-4),x("Extracting geometry...");const Ze=Be.getVertices(),Ht=Be.getFaces();if(Ze.length===0)return null;const Xt=new Nr;if(Xt.setAttribute("position",new Sn(Ze,3)),Xt.setIndex(Array.from(Ht)),Xt.computeVertexNormals(),Ft){const ge=ft?1e3:1;O9(Xt,Ft.positions,Ft.colors,ge)}return{geometry:Xt,wasScaled:ft}}catch(Ft){return console.error("WASM processing failed:",Ft),null}finally{if(Be)try{Be.free()}catch{}}},Je=Ge=>{const tt=new RW().parse(Ge);let Be=null;return tt.traverse(Ft=>{Ft.isMesh&&!Be&&(Be=Ft.geometry)}),Be},zt=It.useCallback((Ge,tt)=>{Ge.computeBoundingBox();const Be=Ge.boundingBox,Ft=new ae;Be.getCenter(Ft),Ge.translate(-Ft.x,-Ft.y,-Ft.z),Ge.computeBoundingBox();const ft=Ge.boundingBox,Ze=new ae;ft.getSize(Ze),f(Math.max(Ze.x,Ze.y,Ze.z));const Ht=new ss(Ge,new Yw({color:8947848,side:Xh}));a(Ht)},[]);It.useEffect(()=>{!u||!ue||(async()=>{b(!0),x("Fetching OBJ..."),ie(null),xe();try{const Ge=await fetch(u);if(!Ge.ok)throw new Error(`HTTP ${Ge.status}`);const tt=await Ge.text(),Be=await Ke(tt);if(Be)zt(Be.geometry,Be.wasScaled);else{x("Using fallback loader...");const Ft=Je(tt);Ft?zt(Ft,!1):ie("Failed to parse the mesh.")}}catch(Ge){ie(Ge instanceof Error?Ge.message:"Failed to fetch OBJ.")}finally{b(!1),x("")}})()},[u,ue]);const Qt=(Ge,tt,Be)=>{const Ft=Ge.getAttribute("position"),ft=Be-tt;if(ft<1)return null;const Ze=30,Ht=ft/Ze,Xt=[];for(let ln=0;ln<Ze;ln++){const Jt=tt+ln*Ht,At=tt+(ln+1)*Ht;let Dt=0,we=0,at=0,St=0;for(let ne=0;ne<Ft.count;ne++){const le=Ft.getY(ne);le>=Jt&&le<At&&(Dt+=Ft.getX(ne),we+=le,at+=Ft.getZ(ne),St++)}St>20&&Xt.push(new ae(Dt/St,we/St,at/St))}if(Xt.length<5)return null;const ge=new ae;for(const ln of Xt)ge.add(ln);ge.divideScalar(Xt.length);let oe=0,Oe=0,dt=0,pt=0,xt=0,cn=0;for(const ln of Xt){const Jt=ln.x-ge.x,At=ln.y-ge.y,Dt=ln.z-ge.z;oe+=Jt*Jt,Oe+=Jt*At,dt+=Jt*Dt,pt+=At*At,xt+=At*Dt,cn+=Dt*Dt}let Bt=new ae(.01,1,.01).normalize();for(let ln=0;ln<30;ln++){const Jt=oe*Bt.x+Oe*Bt.y+dt*Bt.z,At=Oe*Bt.x+pt*Bt.y+xt*Bt.z,Dt=dt*Bt.x+xt*Bt.y+cn*Bt.z,we=new ae(Jt,At,Dt),at=we.length();if(at<1e-10||(we.divideScalar(at),Bt.distanceTo(we)<1e-8))break;Bt=we}return Bt.y<0&&Bt.negate(),Bt},Kt=(Ge,tt,Be,Ft)=>{const ft=tt-Be;if(ft<4)return{valid:!1,reason:`Height too small (${ft.toFixed(1)}mm < 4mm)`};if(ft>1e3)return{valid:!1,reason:`Height too large (${ft.toFixed(1)}mm > 1000mm)`};const Ze=new w1(Ge,{maxLeafSize:cC}),Ht=bT(Ze,Ge,tt),Xt=tt-Ft;if(Xt<=Be)return{valid:!0,reason:""};const ge=bT(Ze,Ge,Xt);if(Ht.lineLength>0&&ge.lineLength>0){const Oe=Ht.lineLength/ge.lineLength;if(Oe<.5)return{valid:!1,reason:`First circumference is too small relative to second (ratio ${Oe.toFixed(2)} < 0.5) \u2014 possible trimmed angle`}}const oe=tt-Ft*2;if(oe>Be){const Oe=bT(Ze,Ge,oe);if(ge.lineLength>0&&Oe.lineLength>0){const dt=ge.lineLength/Oe.lineLength;if(dt<.5)return{valid:!1,reason:`Second circumference is too small relative to third (ratio ${dt.toFixed(2)} < 0.5) \u2014 possible trimmed angle`}}}return{valid:!0,reason:""}},We=It.useCallback(()=>{if(!t||ce.length<2)return;B(!0),N("Finding optimal cut plane...");const Ge=3,tt=t.geometry.clone(),Be=ce.map(Ft=>({...Ft}));setTimeout(()=>{let Ft="";for(let ft=0;ft<Ge;ft++)try{ft>0&&(N(`Retry ${ft}/${Ge-1} \u2014 nudging green point \u2014 ${Ft}`),t.geometry.dispose(),t.geometry=tt.clone(),Qe(2),se(!1),Ce(!1));let Ze=t.geometry,Ht=Be.map(Et=>new ae(Et.position.x,Et.position.y,Et.position.z));if(ft>0){const Et=2*ft,_n=ft*Math.PI*2/3,dn=new ae().subVectors(Ht[1],Ht[0]).normalize(),Mr=new ae;Math.abs(dn.x)<.9?Mr.crossVectors(dn,new ae(1,0,0)).normalize():Mr.crossVectors(dn,new ae(0,0,1)).normalize(),Mr.applyAxisAngle(dn,_n),Ht[1].addScaledVector(Mr,Et);const nr=Ze.getAttribute("position");let Ya=1/0,Oa=0;for(let za=0;za<nr.count;za++){const ui=nr.getX(za)-Ht[1].x,$o=nr.getY(za)-Ht[1].y,Mi=nr.getZ(za)-Ht[1].z,on=ui*ui+$o*$o+Mi*Mi;on<Ya&&(Ya=on,Oa=za)}Ht[1].set(nr.getX(Oa),nr.getY(Oa),nr.getZ(Oa))}const Xt=new ae(0,1,0),ge=(Et,_n)=>{const dn=new tl().setFromAxisAngle(Et,_n);Ze.applyMatrix4(new Wn().makeRotationFromQuaternion(dn)),Ht=Ht.map(Mr=>Mr.clone().applyQuaternion(dn))},oe=Ht[0],Oe=Ht[1],{normal:dt}=B9(Ze,Oe,oe);N(ft>0?`Retry ${ft}: Slicing mesh...`:"Slicing mesh at cut plane...");const pt=new ae().subVectors(Oe,oe).normalize(),xt=Math.sign(pt.dot(dt)),cn=Oe.clone().addScaledVector(dt,xt*3*yT),Bt=MO(Ze,cn,dt,oe);Ze.dispose(),Ze=Bt,t.geometry=Ze,N(ft>0?`Retry ${ft}: Rough alignment...`:"Rough alignment...");const ln=new ae().subVectors(Ht[1],Ht[0]).normalize();let Jt=ln.dot(Xt),At=new ae().crossVectors(ln,Xt);At.length()>1e-4&&(At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))))),Ht[0].y>Ht[1].y&&ge(new ae(1,0,0),Math.PI),Ze.computeVertexNormals(),N(ft>0?`Retry ${ft}: Translating...`:"Translating to origin...");const Dt=Ht[0].clone();Ze.translate(-Dt.x,-Dt.y,-Dt.z),Ht=Ht.map(Et=>new ae(Et.x-Dt.x,Et.y-Dt.y,Et.z-Dt.z)),N(ft>0?`Retry ${ft}: PCA alignment...`:"Iterative PCA alignment...");const we=10,at=80,St=Ht[0].y,ne=Ht[1].y;let le=ne-we;for(let Et=0;Et<at;Et++){const _n=Math.min(le,ne),dn=Math.max(le,ne),Mr=Qt(Ze,_n,dn);if(Mr&&(Jt=Mr.dot(Xt),Math.acos(Math.min(1,Math.abs(Jt)))*180/Math.PI>.1&&(At=new ae().crossVectors(Mr,Xt),At.length()>1e-4))){At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))));const nr=Ht[0].clone();Ze.translate(-nr.x,-nr.y,-nr.z),Ht=Ht.map(Ya=>new ae(Ya.x-nr.x,Ya.y-nr.y,Ya.z-nr.z))}if(le-=we,le<=St)break}Ze.computeVertexNormals(),N(ft>0?`Retry ${ft}: Setting blue point...`:"Setting blue point...");const Ne=new ae(Ht[0].x,Ht[0].y,Ht[0].z);Ht.push(Ne),_e({faceIndex:-1,vertexIndices:[0,1,2],position:{x:Ne.x,y:Ne.y,z:Ne.z},barycentricCoords:{u:.33,v:.33,w:.34}}),N(ft>0?`Retry ${ft}: Final PCA...`:"Final PCA refinement...");for(let Et=0;Et<3;Et++){const _n=Qt(Ze,0,Ht[1].y);if(_n){if(Jt=_n.dot(Xt),Math.acos(Math.min(1,Math.abs(Jt)))*180/Math.PI<.1)break;if(At=new ae().crossVectors(_n,Xt),At.length()>1e-4){At.normalize(),ge(At,Math.acos(Math.min(1,Math.max(-1,Jt))));const dn=Ht[0].clone();Ze.translate(-dn.x,-dn.y,-dn.z),Ht=Ht.map(Mr=>new ae(Mr.x-dn.x,Mr.y-dn.y,Mr.z-dn.z))}}}if(Ht[1].y<Ht[0].y){ge(new ae(1,0,0),Math.PI);const Et=Ht[0].clone();Ze.translate(-Et.x,-Et.y,-Et.z),Ht=Ht.map(_n=>new ae(_n.x-Et.x,_n.y-Et.y,_n.z-Et.z))}Ze.computeVertexNormals(),Ze.computeBoundingBox();const $e=Ht.map(Et=>({x:Et.x,y:Et.y,z:Et.z}));it($e),se(!0),N(ft>0?`Retry ${ft}: Cutting mesh...`:"Cutting mesh above green..."),vn(t,Ht,Ze),N("Validating results...");const Rt=t.geometry,lt=Ht[1].y,Xe=Ht[0].y,Wt=Kt(Rt,lt,Xe,Pt);if(Wt.valid)break;Ft=Wt.reason,ft===Ge-1&&(ie(`Processing produced unusual results after ${Ge} attempts: ${Wt.reason}`),t.geometry.dispose(),t.geometry=tt.clone(),Qe(2),se(!1),Ce(!1))}catch(Ze){console.error("Processing failed:",Ze),ie(Ze instanceof Error?Ze.message:"Failed to process mesh.");break}tt.dispose(),B(!1)},50)},[t,ce,it,se,_e,Qe,Ce,Pt]),vn=(Ge,tt,Be)=>{const Ft=Be.getAttribute("position"),ft=Be.getIndex();if(!ft){B(!1);return}const Ze=tt[1].y+3*yT,Ht=Ft.array,Xt=ft.array,ge=Be.getAttribute("color"),oe=ge?ge.array:null,Oe=[],dt=[],pt=[],xt=(on,yn,un)=>{const Qn=Oe.length/3;return Oe.push(on,yn,un),Qn},cn=on=>[Ht[on*3],Ht[on*3+1],Ht[on*3+2]],Bt=(on,yn)=>{const un=(Ze-on[1])/(yn[1]-on[1]);return[on[0]+un*(yn[0]-on[0]),Ze,on[2]+un*(yn[2]-on[2])]},ln=new Map,Jt=new Map,At=on=>{if(ln.has(on))return ln.get(on);const[yn,un,Qn]=cn(on),fa=xt(yn,un,Qn);return oe&&dt.push(oe[on*3],oe[on*3+1],oe[on*3+2]),ln.set(on,fa),fa},Dt=(on,yn)=>{const un=on<yn?`${on}_${yn}`:`${yn}_${on}`;if(Jt.has(un))return Jt.get(un);const Qn=cn(on),fa=cn(yn),[Ja,ci,Xi]=Bt(Qn,fa),No=xt(Ja,ci,Xi);if(oe){const di=(Ze-Qn[1])/(fa[1]-Qn[1]);dt.push(oe[on*3]+di*(oe[yn*3]-oe[on*3]),oe[on*3+1]+di*(oe[yn*3+1]-oe[on*3+1]),oe[on*3+2]+di*(oe[yn*3+2]-oe[on*3+2]))}return Jt.set(un,No),No};for(let on=0;on<Xt.length;on+=3){const yn=Xt[on],un=Xt[on+1],Qn=Xt[on+2],fa=cn(yn),Ja=cn(un),ci=cn(Qn),Xi=fa[1]<Ze,No=Ja[1]<Ze,di=ci[1]<Ze,me=(Xi?1:0)+(No?1:0)+(di?1:0);if(me!==0)if(me===3)pt.push(At(yn),At(un),At(Qn));else if(me===1){let He,ot,Pe;Xi?(He=yn,ot=un,Pe=Qn):No?(He=un,ot=Qn,Pe=yn):(He=Qn,ot=yn,Pe=un),pt.push(At(He),Dt(He,ot),Dt(He,Pe))}else{let He,ot,Pe;Xi?No?(He=Qn,ot=yn,Pe=un):(He=un,ot=Qn,Pe=yn):(He=yn,ot=un,Pe=Qn);const ze=At(ot),wt=At(Pe),an=Dt(ot,He),en=Dt(Pe,He);pt.push(ze,an,wt),pt.push(wt,an,en)}}const we=pt.length/3,at=new Map;for(let on=0;on<we;on++)for(let yn=0;yn<3;yn++){const un=pt[on*3+yn];at.has(un)||at.set(un,[]),at.get(un).push(on)}const St=new Map;for(let on=0;on<we;on++)St.set(on,new Set);for(const[,on]of at)for(const yn of on)for(const un of on)yn!==un&&St.get(yn).add(un);const ne=new Set,le=[];for(let on=0;on<we;on++){if(ne.has(on))continue;const yn=[],un=[on];for(ne.add(on);un.length>0;){const Qn=un.shift();yn.push(Qn);for(const fa of St.get(Qn))ne.has(fa)||(ne.add(fa),un.push(fa))}le.push(yn)}const Ne=tt[0];let $e=le[0]||[],Rt=1/0;for(const on of le){let yn=1/0;for(const un of on){for(let Qn=0;Qn<3;Qn++){const fa=pt[un*3+Qn],Ja=Oe[fa*3]-Ne.x,ci=Oe[fa*3+1]-Ne.y,Xi=Oe[fa*3+2]-Ne.z,No=Ja*Ja+ci*ci+Xi*Xi;No<yn&&(yn=No)}if(yn<Rt)break}yn<Rt&&(Rt=yn,$e=on)}const lt=new Map,Xe=[],Wt=[],Et=[];let _n=0;for(const on of $e)for(let yn=0;yn<3;yn++){const un=pt[on*3+yn];lt.has(un)||(Xe.push(Oe[un*3],Oe[un*3+1],Oe[un*3+2]),oe&&Wt.push(dt[un*3],dt[un*3+1],dt[un*3+2]),lt.set(un,_n++)),Et.push(lt.get(un))}const dn=new Nr;dn.setAttribute("position",new Sn(Xe,3)),oe&&Wt.length>0&&dn.setAttribute("color",new Sn(Wt,3)),dn.setIndex(Et),dn.computeVertexNormals(),dn.computeBoundingBox(),Ge.geometry.dispose(),Ge.geometry=dn,N("Refining alignment...");const Mr=new ae(0,1,0),nr=(on,yn)=>{const un=new tl().setFromAxisAngle(on,yn);dn.applyMatrix4(new Wn().makeRotationFromQuaternion(un)),tt=tt.map(Qn=>Qn.clone().applyQuaternion(un))};for(let on=0;on<5;on++){const yn=dn.getAttribute("position"),un=Math.min(tt[0].y,tt[1].y),Qn=Math.max(tt[0].y,tt[1].y)-un;if(Qn<1)break;const fa=30,Ja=Qn/fa,ci=[];for(let en=0;en<fa;en++){const sn=un+en*Ja,pn=un+(en+1)*Ja;let mn=0,wn=0,Tn=0,rr=0;for(let Cr=0;Cr<yn.count;Cr++){const Jr=yn.getY(Cr);Jr>=sn&&Jr<pn&&(mn+=yn.getX(Cr),wn+=Jr,Tn+=yn.getZ(Cr),rr++)}rr>20&&ci.push(new ae(mn/rr,wn/rr,Tn/rr))}if(ci.length<5)break;const Xi=new ae;for(const en of ci)Xi.add(en);Xi.divideScalar(ci.length);let No=0,di=0,me=0,He=0,ot=0,Pe=0;for(const en of ci){const sn=en.x-Xi.x,pn=en.y-Xi.y,mn=en.z-Xi.z;No+=sn*sn,di+=sn*pn,me+=sn*mn,He+=pn*pn,ot+=pn*mn,Pe+=mn*mn}let ze=new ae(.01,1,.01).normalize();for(let en=0;en<30;en++){const sn=No*ze.x+di*ze.y+me*ze.z,pn=di*ze.x+He*ze.y+ot*ze.z,mn=me*ze.x+ot*ze.y+Pe*ze.z,wn=new ae(sn,pn,mn),Tn=wn.length();if(Tn<1e-10||(wn.divideScalar(Tn),ze.distanceTo(wn)<1e-8))break;ze=wn}ze.y<0&&ze.negate();const wt=ze.dot(Mr);if(Math.acos(Math.min(1,Math.abs(wt)))*180/Math.PI<.1)break;const an=new ae().crossVectors(ze,Mr);an.length()>1e-4&&(an.normalize(),nr(an,Math.acos(Math.min(1,Math.max(-1,wt)))))}tt[0].y>tt[1].y&&nr(new ae(1,0,0),Math.PI);const Ya=tt[0];dn.translate(-Ya.x,-Ya.y,-Ya.z),tt=tt.map(on=>new ae(on.x-Ya.x,on.y-Ya.y,on.z-Ya.z));const Oa=tt[1].y+3*yT,za=MO(dn,new ae(0,Oa,0),new ae(0,1,0),tt[0]);Ge.geometry.dispose(),Ge.geometry=za,za.computeVertexNormals(),za.computeBoundingBox();const ui=tt.map(on=>({x:on.x,y:on.y,z:on.z}));it(ui);const $o=za.boundingBox,Mi=new ae;$o.getSize(Mi),f(Math.max(Mi.x,Mi.y,Mi.z)),Ce(!0),X(null),$(null),Z(tt[1].y)},ve=It.useCallback(Ge=>k==="inch"?Ge/yT:Ge,[k]),Nt=It.useCallback(()=>{if(H.length===0)return;const Ge=ce.length>=2?ce[1].position.y:H[0].yPosition,tt=k==="inch"?"in":"mm",Be=k==="inch"?3:2,Ft=[`Position (${tt})`,`Original Circumference (${tt})`,`Modified Circumference (${tt})`,`Difference (${tt})`],ft=H.map(oe=>{const Oe=oe.yPosition-Ge,dt=oe.modifiedValue??oe.originalValue,pt=oe.modifiedValue!==null?oe.modifiedValue-oe.originalValue:0;return[ve(Oe).toFixed(Be),ve(oe.originalValue).toFixed(Be),ve(dt).toFixed(Be),ve(pt).toFixed(Be)].join(",")}),Ze=[Ft.join(","),...ft].join(`
|
|
4732
4732
|
`),Ht=new Blob([Ze],{type:"text/csv;charset=utf-8;"}),Xt=URL.createObjectURL(Ht),ge=document.createElement("a");ge.setAttribute("href",Xt),ge.setAttribute("download",`measurements_${k}_${new Date().toISOString().slice(0,10)}.csv`),document.body.appendChild(ge),ge.click(),document.body.removeChild(ge),URL.revokeObjectURL(Xt)},[H,ce,k,ve]);return rn.jsxs("div",{ref:Me,style:{width:"100%",height:"100%",position:"relative",display:"flex",flexDirection:"column"},children:[rn.jsxs("div",{style:{flex:1,position:"relative",minHeight:0,overflow:"hidden"},children:[!t&&!m&&rn.jsx("div",{style:{position:"absolute",inset:16,border:"3px dashed #ccc",borderRadius:4,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:ue?u?null:rn.jsx("div",{style:{fontSize:18,color:"#aaa",fontWeight:400,fontFamily:"system-ui, sans-serif"},children:"No OBJ URL provided"}):rn.jsxs("div",{style:{textAlign:"center"},children:[rn.jsx("div",{style:{width:32,height:32,border:"3px solid rgba(0,0,0,0.1)",borderTopColor:"#4a90d9",borderRadius:"50%",animation:"spin 1s linear infinite",margin:"0 auto 12px"}}),rn.jsx("div",{style:{fontSize:16,color:"#999",fontFamily:"system-ui, sans-serif"},children:"Loading WASM module..."}),rn.jsx("style",{children:"@keyframes spin { to { transform: rotate(360deg); } }"})]})}),t&&!ye&&ce.length===0&&rn.jsxs("div",{style:{position:"absolute",top:16,left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:8,padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.6)",borderRadius:8,color:"#fff",fontSize:13,pointerEvents:"none",zIndex:5,fontFamily:"system-ui, sans-serif"},children:[rn.jsx("div",{style:{width:10,height:10,borderRadius:"50%",backgroundColor:"#ff4444",flexShrink:0}}),"Click mesh to set Origin"]}),t&&!ye&&ce.length===1&&rn.jsxs("div",{style:{position:"absolute",top:16,left:"50%",transform:"translateX(-50%)",display:"flex",alignItems:"center",gap:8,padding:"8px 16px",backgroundColor:"rgba(0, 0, 0, 0.6)",borderRadius:8,color:"#fff",fontSize:13,pointerEvents:"none",zIndex:5,fontFamily:"system-ui, sans-serif"},children:[rn.jsx("div",{style:{width:10,height:10,borderRadius:"50%",backgroundColor:"#44ff44",flexShrink:0}}),"Click mesh to set ",e==="AK"?"IT/Perineum":"MPT"]}),m&&rn.jsx(SO,{message:S||"Processing mesh..."}),O&&rn.jsx(SO,{message:z}),Q&&rn.jsx(z9,{message:Q,onDismiss:()=>ie(null)}),rn.jsxs(tW,{camera:{position:[0,0,5]},style:{display:t?"block":"none"},children:[rn.jsx("ambientLight",{intensity:.4}),rn.jsx("directionalLight",{position:[10,10,5],intensity:1.2}),rn.jsx("directionalLight",{position:[-5,5,-5],intensity:.4}),rn.jsx("directionalLight",{position:[0,-10,0],intensity:.2}),t&&rn.jsx(CO,{mesh:t,maxPoints:2,meshColor:"#c8c8c8",meshOpacity:1}),t&&rn.jsx(kO,{modelSize:l}),t&&rn.jsx("primitive",{object:new cI(l||1)}),rn.jsx(IO,{modelSize:l,isAligned:ye,isCut:Le,mesh:t}),(!ye||C)&&rn.jsx(EW,{enableDamping:!1}),t&&ye&&ce.length>=3&&(()=>{const Ge=ce[2],tt=ce[1],Be=W??Ge.position.y,Ft=Y??tt.position.y;return rn.jsxs(rn.Fragment,{children:[rn.jsx(s3,{mesh:t,yPosition:Be,onYChange:X,minY:ce[0].position.y,maxY:Ft-l*.05,modelSize:l,color:"#4444ff",hoverColor:"#8888ff",dragColor:"#ffff00",label:"Drag to adjust end (bottom)"}),rn.jsx(s3,{mesh:t,yPosition:Ft,onYChange:$,minY:Be+l*.05,maxY:te??tt.position.y,modelSize:l,color:"#00ff00",hoverColor:"#88ff88",dragColor:"#ffff00",label:"Drag to adjust start (top)"}),rn.jsx(DO,{mesh:t,startY:Be,endY:Ft,spacing:Pt,modelSize:l,onMeasurementsChange:V,reverseOrder:!0}),rn.jsx(AO,{mesh:t,greenY:Ft,modelSize:l})]})})()]}),ye&&H.length>0&&rn.jsxs("div",{style:{position:"absolute",top:16,right:16,width:240,backgroundColor:"rgba(255, 255, 255, 0.92)",borderRadius:12,boxShadow:"0 4px 24px rgba(0, 0, 0, 0.12)",zIndex:10,maxHeight:"calc(100% - 32px)",overflow:"auto",padding:16,backdropFilter:"blur(8px)"},children:[rn.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#333",marginBottom:12,fontFamily:"system-ui, sans-serif"},children:"Measurements"}),(()=>{const Ge=["#00ff00","#ffff00","#ff00ff","#00ffff","#ff8800","#88ff00"];return H.map((tt,Be)=>rn.jsxs("div",{style:{display:"flex",alignItems:"center",padding:"5px 0",fontSize:11,borderBottom:Be<H.length-1?"1px solid #eee":"none"},children:[rn.jsx("div",{style:{width:6,height:6,borderRadius:"50%",backgroundColor:Ge[Be%Ge.length],marginRight:8,flexShrink:0}}),rn.jsx("span",{style:{color:"#888",fontSize:10},children:Be+1}),rn.jsx("span",{style:{marginLeft:"auto",fontWeight:500,color:"#333"},children:k==="mm"?`${tt.originalValue.toFixed(1)}mm`:`${(tt.originalValue/25.4).toFixed(2)}"`})]},Be))})()]})]}),rn.jsxs("div",{style:{padding:"12px 24px",backgroundColor:"#fff",borderTop:"1px solid #e0e0e0",display:"flex",alignItems:"center",justifyContent:"flex-end",gap:8,flexShrink:0},children:[t&&!ye&&ce.length>=2&&rn.jsx("button",{onClick:We,style:{padding:"6px 16px",borderRadius:4,fontSize:14,fontWeight:500,backgroundColor:"rgb(12, 67, 173)",border:"none",color:"#fff",cursor:"pointer",fontFamily:"system-ui, sans-serif",letterSpacing:"0.4px",lineHeight:"36px"},children:"Next \xBB"}),t&&!ye&&ce.length>=1&&rn.jsx("button",{onClick:xe,style:{padding:"6px 16px",borderRadius:4,fontSize:14,fontWeight:500,backgroundColor:"#fff",border:"1px solid #bdbdbd",color:"#333",cursor:"pointer",fontFamily:"system-ui, sans-serif",letterSpacing:"0.4px",lineHeight:"36px"},children:"Reset Points"}),ye&&rn.jsxs(rn.Fragment,{children:[rn.jsx("button",{onClick:Nt,disabled:H.length===0,style:{padding:"6px 16px",borderRadius:4,fontSize:14,fontWeight:500,backgroundColor:H.length>0?"rgb(12, 67, 173)":"#e0e0e0",border:"none",color:H.length>0?"#fff":"#9e9e9e",cursor:H.length>0?"pointer":"not-allowed",fontFamily:"system-ui, sans-serif",letterSpacing:"0.4px",lineHeight:"36px"},children:"Export CSV \xBB"}),rn.jsx("div",{style:{display:"flex",gap:4},children:["mm","inch"].map(Ge=>rn.jsx("button",{onClick:()=>A(Ge),style:{padding:"4px 12px",borderRadius:4,fontSize:12,fontWeight:500,backgroundColor:k===Ge?"rgba(12, 67, 173, 0.08)":"#fff",border:`1px solid ${k===Ge?"rgb(12, 67, 173)":"#bdbdbd"}`,color:k===Ge?"rgb(12, 67, 173)":"#666",cursor:"pointer",fontFamily:"system-ui, sans-serif",lineHeight:"24px"},children:Ge},Ge))})]})]})]})},Q3=MF(LO,{props:{objUrl:"string",spacingType:"string"}}),customElements.get("fab-one-widget")||customElements.define("fab-one-widget",Q3)})();export{Q3 as FabOneWidgetWC,f7 as __tla};
|
package/package.json
CHANGED