clipoox-render 0.4.4 → 0.4.6
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/package.json +1 -1
- package/scripts/render-local.mjs +1512 -1292
- package/web/assets/{FxEmbed-DbfuM8Yo.js → FxEmbed-ROS6C_HI.js} +1 -1
- package/web/assets/{MotionEmbed-CBQ-8Tzh.js → MotionEmbed-E2hCysi-.js} +1 -1
- package/web/assets/{PluginStore-OOEx0lP5.js → PluginStore-CwUSpwPp.js} +1 -1
- package/web/assets/{ShotComposer-Cng515xa.js → ShotComposer-DLxWpdYH.js} +8 -8
- package/web/assets/{TemplateEmbed-hjwM2b0o.js → TemplateEmbed-qG1AXdtf.js} +1 -1
- package/web/assets/{TimelinePlugins-D-NakABP.js → TimelinePlugins-CB1b6-Cb.js} +3 -3
- package/web/assets/{TimelineShotFx-D3kGhHN3.js → TimelineShotFx-CyHTgJHj.js} +2 -2
- package/web/assets/{TransitionEmbed-DR26yI3a.js → TransitionEmbed-Dym9P7--.js} +1 -1
- package/web/assets/{Whiteboard-BhxY0D0Z.js → Whiteboard-BdGjJZXW.js} +1 -1
- package/web/assets/{aerial-BisYSXzG.js → aerial-yLD_gDzw.js} +2 -2
- package/web/assets/{agentTools-CPFQeiDP.js → agentTools-B7g6tXTR.js} +2 -2
- package/web/assets/{aiInbetween-AOOM1e6p.js → aiInbetween-6eKDYbYS.js} +2 -2
- package/web/assets/{analyzerRun-Dtp2o7gT.js → analyzerRun-Cr-_79RH.js} +1 -1
- package/web/assets/{analyzerSandbox-BG_3Cea1.js → analyzerSandbox-N92T6amg.js} +1 -1
- package/web/assets/{api-BFN7blbw.js → api-Dnl2uaKO.js} +3 -3
- package/web/assets/auraTrack-C8eAEIWQ.js +1 -0
- package/web/assets/{breakthrough-0qFpZW-V.js → breakthrough-DSiuVwEX.js} +2 -2
- package/web/assets/{cameraPresets-eK3mP7qb.js → cameraPresets-Cfn7qhXK.js} +1 -1
- package/web/assets/{cameraTracker-BAQHuTV-.js → cameraTracker-DHdF8Zqx.js} +5 -5
- package/web/assets/{captionLayout-CWPcbid-.js → captionLayout-cckQ7p-t.js} +1 -1
- package/web/assets/{clientExport-DvpTTndR.js → clientExport-pkLbOmEF.js} +1 -1
- package/web/assets/{clientJobs-CIrYTMpn.js → clientJobs-CcsLDqFM.js} +2 -2
- package/web/assets/{depthEstimate-B7D7cGCl.js → depthEstimate-Cav4MmQ1.js} +1 -1
- package/web/assets/{directorTools-CJD4Huqk.js → directorTools-DMsatulF.js} +1 -1
- package/web/assets/{distortFrames-BLt1icUb.js → distortFrames-D_v-aSVO.js} +2 -2
- package/web/assets/{distortGL-BA5molk-.js → distortGL-vhnBRB59.js} +1 -1
- package/web/assets/domino-DBrinEUu.js +1 -0
- package/web/assets/{editTools-NKLsWZD1.js → editTools-BNnAvCw-.js} +1 -1
- package/web/assets/{engine-DioUF2mX.js → engine-Co-ivzlQ.js} +1 -1
- package/web/assets/{exportGlb-BOdI9cVS.js → exportGlb-D3PrWUvi.js} +1 -1
- package/web/assets/{faceTracker-D7CbF-qX.js → faceTracker-ClR-lS6Y.js} +1 -1
- package/web/assets/fightDirector-BlpVAURl.js +1 -0
- package/web/assets/{fightDrama-DIPcRKnc.js → fightDrama-BK0QidpM.js} +2 -2
- package/web/assets/{focusTool-vfabPqQ5.js → focusTool-sVOb2GGS.js} +1 -1
- package/web/assets/{frameSink-DYs2gTzq.js → frameSink-CSRqCnwI.js} +3 -3
- package/web/assets/{glTransitionSources.generated-DM5sRMX2.js → glTransitionSources.generated-q0H-ZbnZ.js} +2 -2
- package/web/assets/{gpuCompose-DbnZuelB.js → gpuCompose-B5bgbHdQ.js} +1 -1
- package/web/assets/{gpuExport-CQ7ZhpsX.js → gpuExport-oA2mUsdm.js} +7 -7
- package/web/assets/{handMatte-DIbMuqCu.js → handMatte-Dj2taFoC.js} +1 -1
- package/web/assets/handTracker-c6_rvuwA.js +2 -0
- package/web/assets/i18n-C9zFX25m.js +3 -0
- package/web/assets/{index-BfrDwjDI.js → index-Ds_8isyf.js} +1 -1
- package/web/assets/layer-worker-ClVZG6ZW.js +5 -0
- package/web/assets/library-BK0QVG4O.js +1 -0
- package/web/assets/{lottieLayer-C2YbiXhK.js → lottieLayer-Cv8ub9f6.js} +1 -1
- package/web/assets/{main-B27kf5aL.css → main-B_MAOvi6.css} +1 -1
- package/web/assets/{main-BKatDoGw.js → main-CwrkBJ63.js} +104 -104
- package/web/assets/{mapBake-C-G7WpFM.js → mapBake-DtQboFIX.js} +1 -1
- package/web/assets/{maskTrack-LMrwm5ub.js → maskTrack-D4QZfMWc.js} +1 -1
- package/web/assets/{matteFixRun-B38CbeEt.js → matteFixRun-CytaeRzS.js} +1 -1
- package/web/assets/{objectLocate-CKi3OTnL.js → objectLocate-XuAcemlO.js} +1 -1
- package/web/assets/{objectSegmenter-CziPuM61.js → objectSegmenter-D66spD7o.js} +1 -1
- package/web/assets/{objectTrack.worker-b7DJ-ub6.js → objectTrack.worker-BZS6WZ6l.js} +547 -327
- package/web/assets/{pathTracer-bqau16sX.js → pathTracer-DykgPkkh.js} +2 -2
- package/web/assets/{pendingMatte-CQb7jPg1.js → pendingMatte-BWBIWajI.js} +2 -2
- package/web/assets/{personAi-CQntGDqK.js → personAi-EhBknW6X.js} +2 -2
- package/web/assets/{personHq-B1c0QVJT.js → personHq-Ca351o06.js} +2 -2
- package/web/assets/{plateCamera-D7iLiNBy.js → plateCamera-BcdXD1uI.js} +1 -1
- package/web/assets/{plateCameraMatch-BM88dx-a.js → plateCameraMatch-GPZl1fQQ.js} +2 -2
- package/web/assets/{plateFollow-4iGUDTu1.js → plateFollow-CJUilsNV.js} +2 -2
- package/web/assets/{plateMatte-zTyuHHqh.js → plateMatte-CoEoVjxZ.js} +2 -2
- package/web/assets/{pluginAutomation-DSg-sYLF.js → pluginAutomation-DAPHWZPN.js} +1 -1
- package/web/assets/{poseTracker-DZl8l2qS.js → poseTracker-CzEKvJph.js} +1 -1
- package/web/assets/{productTools-B-jh8ukh.js → productTools-ce-zyZO0.js} +2 -2
- package/web/assets/remote-8XzEAnAJ.js +974 -0
- package/web/assets/{rigTrack-XaMj1yaH.js → rigTrack-DMyqb0pb.js} +1 -1
- package/web/assets/{rotoMaskStore-DdpmT9C3.js → rotoMaskStore-pE1AIt3I.js} +1 -1
- package/web/assets/{rotoMatte-i-cJTYmK.js → rotoMatte-7b7Ow64f.js} +1 -1
- package/web/assets/{rotoscope-DqRSWmHR.js → rotoscope-BUqNTKLd.js} +1 -1
- package/web/assets/{sceneTrack-DIPzBmMK.js → sceneTrack-CA21MCOP.js} +1 -1
- package/web/assets/{sceneTrack-Bbov7zET.js → sceneTrack-DlAH5s74.js} +1 -1
- package/web/assets/{sceneTrack.worker-Bav9h0pv.js → sceneTrack.worker-COlhlHRe.js} +547 -327
- package/web/assets/{shot-worker-m-q77W9f.js → shot-worker-DL1ZoIym.js} +1 -1
- package/web/assets/{shotFxAgent-DIMS7BGA.js → shotFxAgent-DqngnGFb.js} +1 -1
- package/web/assets/{skin-DrUzJE1u.js → skin-xFScwS3T.js} +1 -1
- package/web/assets/{spark.module-Y1SEI8Xz.js → spark.module-DjaIF6J1.js} +1 -1
- package/web/assets/{spellDuel-DNnyQDVr.js → spellDuel-BYNtnE8f.js} +2 -2
- package/web/assets/{store-GFMJzaWS.js → store-CpqHUcA2.js} +1 -1
- package/web/assets/{surfaceLight-C--moyc9.js → surfaceLight-C7YI9SV8.js} +1 -1
- package/web/assets/{surfacePin-B4-1UqXD.js → surfacePin-CzpUj1Cw.js} +2 -2
- package/web/assets/{textAnimators-BVXTl8bU.js → textAnimators-B9vO_hbP.js} +1 -1
- package/web/assets/{thumb-CTfDJgLp.js → thumb-BTFsBS1u.js} +1 -1
- package/web/assets/{timeline3d-Dn7PqmEe.js → timeline3d-DrFaMPPB.js} +2 -2
- package/web/assets/{timeline3dExport-DCOr6ARB.js → timeline3dExport-Uo0S0CR0.js} +1 -1
- package/web/assets/{timelineComp-Dx_kED5V.js → timelineComp-i-zdaoB2.js} +1 -1
- package/web/assets/timelineOps-DSSaDsU2.js +525 -0
- package/web/assets/{timelineProps-eYgO6gs5.js → timelineProps-0v-s69pw.js} +1 -1
- package/web/assets/{timelineText-RKyRP988.js → timelineText-DurRhyuh.js} +1 -1
- package/web/assets/{titleArt-CUtA0C3I.js → titleArt-CnC0A7x7.js} +3 -3
- package/web/assets/{titleFrameBudget-X7HLSDre.js → titleFrameBudget-DsM0V482.js} +801 -581
- package/web/assets/{titleFrames-aMG7HdVe.js → titleFrames-C8kvflgT.js} +1 -1
- package/web/assets/{tool-DpFjybaq.js → tool-D1FpErrX.js} +1 -1
- package/web/assets/{tools-CeOU0p13.js → tools-DIvrRu-5.js} +1 -1
- package/web/assets/toonTools-D9MNdRty.js +2 -0
- package/web/assets/{trackAnchor-hAOtEhKO.js → trackAnchor-XvUuvkWP.js} +1 -1
- package/web/assets/{userFonts-1kuRjWOo.js → userFonts-Djka6RJX.js} +1 -1
- package/web/assets/{vfxAlpha-DxS5-QwY.js → vfxAlpha-B-JzzRI1.js} +1 -1
- package/web/assets/vfxBackground-b053ziDK.js +2 -0
- package/web/assets/{videoExport-Cg4B2Nyh.js → videoExport-NN-QijHd.js} +1 -1
- package/web/assets/{views-CUXyRb9x.js → views-RQBs4zva.js} +1 -1
- package/web/assets/{weaponDuel-nFECu9nk.js → weaponDuel-DKAEYJjO.js} +1 -1
- package/web/assets/{windowFrames-1wAkkWnv.js → windowFrames-DhhJLIs-.js} +1 -1
- package/web/layer-worker.html +3 -3
- package/web/shot-worker.html +23 -23
- package/web/assets/auraTrack-D_gxHNVe.js +0 -1
- package/web/assets/fightDirector-CYP8jxo8.js +0 -1
- package/web/assets/handTracker-DY_g5Xmg.js +0 -2
- package/web/assets/i18n-BJppIrtF.js +0 -3
- package/web/assets/layer-worker-DLSnp1D-.js +0 -5
- package/web/assets/library-B6KsZUKq.js +0 -1
- package/web/assets/remote-DJd9xWjn.js +0 -963
- package/web/assets/timelineOps-afzSo188.js +0 -525
- package/web/assets/toonTools-DLmo37Z_.js +0 -2
- package/web/assets/vfxBackground-CYpaQaTa.js +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Box3 as de,Matrix4 as $,BufferAttribute as te,Vector3 as C,Line3 as ge,Plane as br,Vector2 as Y,Triangle as Ye,BackSide as Tr,DoubleSide as wr,REVISION as Sr,Ray as Kr,FrontSide as oi,UnsignedIntType as lt,FloatType as G,DataTexture as Z,NearestFilter as N,IntType as qt,UnsignedByteType as ci,UnsignedShortType as Zr,ByteType as Di,ShortType as Jr,RGBAFormat as L,RGBAIntegerFormat as li,RGIntegerFormat as _r,RedIntegerFormat as en,RGFormat as Ar,RedFormat as Et,BufferGeometry as Ke,Matrix3 as tn,Vector4 as Ze,MeshBasicMaterial as rn,Mesh as nn,ShaderMaterial as Nt,NoBlending as Je,WebGLRenderTarget as Qe,PerspectiveCamera as Mr,DataUtils as K,HalfFloatType as ee,LinearFilter as oe,RepeatWrapping as we,ClampToEdgeWrapping as Se,Source as sn,Quaternion as an,DataArrayTexture as on,WebGLArrayRenderTarget as cn,Color as et,NoToneMapping as ln,NormalBlending as Ir,EquirectangularReflectionMapping as Ti,Spherical as un,LinearMipMapLinearFilter as fn,Clock as hn,Scene as dn,AdditiveBlending as mn,Camera as pn,SpotLight as gn,RectAreaLight as vn,PMREMGenerator as xn,MeshStandardMaterial as yn,TangentSpaceNormalMap as Ei}from"./three.module-Bx43vjkH.js";import{eK as De}from"./remote-DJd9xWjn.js";import"./index-CKtv7gGE.js";import"./i18n-BJppIrtF.js";import"./api-BFN7blbw.js";import"./titleFrameBudget-X7HLSDre.js";import"./gltfLoader-U0Eebg7v.js";import"./store-GFMJzaWS.js";import"./rotoMaskStore-DdpmT9C3.js";import"./sceneTrack-Bbov7zET.js";import"./timelineOps-afzSo188.js";import"./cameraTracker-BAQHuTV-.js";import"./textAnimators-BVXTl8bU.js";import"./timelineComp-Dx_kED5V.js";import"./rigTrack-XaMj1yaH.js";import"./clientJobs-CuuUyhEy.js";const Pr=0,bn=1,Rr=2,Bi=2,Gt=1.25,zi=1,j=32,O=j/4,wi=65535,Tn=wi<<16,Dt=Math.pow(2,-24),Si=Symbol("SKIP_GENERATION"),Fr={strategy:Pr,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Si]:!1};function z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function ui(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=n[i+3]-n[i];s>t&&(t=s,e=i)}return e}function Ni(n,e,t){for(let i=0;i<3;i++){const s=e[n+2*i],a=e[n+2*i+1],r=s-a,c=s+a;r<t[i]&&(t[i]=r),c>t[i+3]&&(t[i+3]=c)}}function $t(n){const e=n[3]-n[0],t=n[4]-n[1],i=n[5]-n[2];return 2*(e*t+t*i+i*e)}function k(n,e){return e[n+15]===wi}function H(n,e){return e[n+6]}function q(n,e){return e[n+14]}function W(n){return n+O}function V(n,e){const t=e[n+6];return n+t*O}function kt(n,e){return e[n+7]}function Yt(n,e,t,i,s){let a=1/0,r=1/0,c=1/0,l=-1/0,h=-1/0,f=-1/0,u=1/0,o=1/0,m=1/0,g=-1/0,x=-1/0,d=-1/0;const b=n.offset||0;for(let p=(e-b)*6,v=(e+t-b)*6;p<v;p+=6){const y=n[p+0],T=n[p+1],A=y-T,w=y+T;A<a&&(a=A),w>l&&(l=w),y<u&&(u=y),y>g&&(g=y);const M=n[p+2],I=n[p+3],_=M-I,P=M+I;_<r&&(r=_),P>h&&(h=P),M<o&&(o=M),M>x&&(x=M);const S=n[p+4],R=n[p+5],F=S-R,D=S+R;F<c&&(c=F),D>f&&(f=D),S<m&&(m=S),S>d&&(d=S)}i[0]=a,i[1]=r,i[2]=c,i[3]=l,i[4]=h,i[5]=f,s[0]=u,s[1]=o,s[2]=m,s[3]=g,s[4]=x,s[5]=d}const he=8,_i=8,jt=new Int32Array(he),ue=new Float32Array(he*6),ze=new Float32Array(he*6),ne=new Float32Array(6),ft=new Float32Array(6),ye=new Int32Array(_i),ki=new Float32Array(_i*6);function wn(n,e,t,i){for(let s=0;s<3;s++){const a=e[n+2*s],r=e[n+2*s+1],c=a-r,l=a+r;c<t[i+s]&&(t[i+s]=c),l>t[i+s+3]&&(t[i+s+3]=l)}}function Oi(n,e){const t=n[e+3]-n[e],i=n[e+4]-n[e+1],s=n[e+5]-n[e+2];return 2*(t*i+i*s+s*t)}function Sn(n,e,t,i,s,a){let r=-1,c=0;if(a===Pr)r=ui(e),r!==-1&&(c=(e[r]+e[r+3])/2);else if(a===bn)r=ui(n),r!==-1&&(c=_n(t,i,s,r));else if(a===Rr){const l=$t(n);let h=Gt*s;const f=t.offset||0,u=(i-f)*6,o=(i+s-f)*6;for(let m=0;m<3;m++){const g=e[m],b=(e[m+3]-g)/he;if(s<_i){for(let p=0;p<s;p++){const v=u+p*6,y=t[v+2*m];let T=p;for(;T>0&&t[ye[T-1]+2*m]>y;)ye[T]=ye[T-1],T--;ye[T]=v}for(let p=0;p<3;p++)ne[p]=1/0,ne[p+3]=-1/0,ft[p]=1/0,ft[p+3]=-1/0;for(let p=s-1;p>=0;p--)Ni(ye[p],t,ft),ki.set(ft,p*6);for(let p=0;p<s-1;p++){Ni(ye[p],t,ne);const v=t[ye[p+1]+2*m];if(t[ye[p]+2*m]===v)continue;const y=p+1,T=s-y,A=$t(ne)/l,w=Oi(ki,y*6)/l,M=zi+Gt*(A*y+w*T);M<h&&(r=m,h=M,c=v)}}else{for(let y=0;y<he;y++){jt[y]=0;for(let T=0;T<3;T++)ue[y*6+T]=1/0,ue[y*6+T+3]=-1/0}for(let y=u;y<o;y+=6){let w=~~((t[y+2*m]-g)/b);w>=he&&(w=he-1),jt[w]++,wn(y,t,ue,w*6)}const p=(he-1)*6;for(let y=0;y<6;y++)ze[p+y]=ue[p+y];for(let y=he-2;y>=0;y--){const T=y*6,A=T+6;for(let w=0;w<3;w++)ze[T+w]=Math.min(ue[T+w],ze[A+w]),ze[T+w+3]=Math.max(ue[T+w+3],ze[A+w+3])}let v=0;for(let y=0;y<he-1;y++){const T=y*6,A=jt[y];if(A!==0)for(let P=0;P<3;P++)v===0?(ne[P]=ue[T+P],ne[P+3]=ue[T+P+3]):(ne[P]=Math.min(ne[P],ue[T+P]),ne[P+3]=Math.max(ne[P+3],ue[T+P+3]));v+=A;let w=0,M=0;v!==0&&(w=$t(ne)/l);const I=s-v;I!==0&&(M=Oi(ze,T+6)/l);const _=zi+Gt*(w*v+M*I);_<h&&(r=m,h=_,c=g+b+y*b)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:r,pos:c}}function _n(n,e,t,i){let s=0;const a=n.offset;for(let r=e,c=e+t;r<c;r++)s+=n[(r-a)*6+i*2];return s/t}function An(n,e,t,i,s,a){let r=i,c=i+s-1;const l=a.pos,h=a.axis*2,f=t.offset||0;for(;;){for(;r<=c&&t[(r-f)*6+h]<l;)r++;for(;r<=c&&t[(c-f)*6+h]>=l;)c--;if(r<c){for(let u=0;u<e;u++){let o=n[r*e+u];n[r*e+u]=n[c*e+u],n[c*e+u]=o}for(let u=0;u<6;u++){const o=r-f,m=c-f,g=t[o*6+u];t[o*6+u]=t[m*6+u],t[m*6+u]=g}r++,c--}else return r}}const Mn=Math.pow(2,32),Ne=new Float32Array(6),ht=new Float32Array(6);function In(n,e,t,i,s,a){const{maxDepth:r,verbose:c,targetLeafSize:l,_strictLeafSize:h=1/0,strategy:f,onProgress:u,useSharedArrayBuffer:o=!1}=s,m=n.primitiveBuffer,g=n.primitiveBufferStride,x=o?SharedArrayBuffer:ArrayBuffer,d=new x(j*Math.max(1,2*Math.ceil(i)-1)),b=new Float32Array(d),p=new Uint32Array(d),v=new Uint16Array(d);let y=0,T=!1;return Yt(e,t,i,Ne,ht),M(t,i,0),d.slice(0,y*j);function A(I){u&&u((I-a.offset)/a.count)}function w(I,_,P){const S=I*2;p[I+6]=_,v[S+14]=P,v[S+15]=wi,A(_+P)}function M(I,_,P){const S=y++,R=S*O;b.set(Ne,R),!T&&P>=r&&(T=!0,c&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const F=_>h;if(_<=l&&!F||P>=r){w(R,I,_);return}const D=Sn(Ne,ht,e,I,_,f);let E=D.axis===-1?-1:An(m,g,e,I,_,D);if(D.axis===-1||E===I||E===I+_){if(!F){w(R,I,_);return}D.axis=Math.max(0,ui(Ne)),E=I+Math.max(1,Math.floor(_/2))}p[R+7]=D.axis;const le=E-I;Yt(e,I,le,Ne,ht),M(I,le,P+1);const me=y-S;if(me>Mn)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");p[R+6]=me;const xe=_-le;Yt(e,E,xe,Ne,ht),M(E,xe,P+1)}}function Pn(n,e){const t=n.getRootRanges(e.range),i=t[0],s=t[t.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},r=new Float32Array(6*a.count);r.offset=a.offset,n.computePrimitiveBounds(a.offset,a.count,r),n._roots=t.map(c=>In(n,r,c.offset,c.count,e,a))}class Ai{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 Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const B=new Rn;let Te,Xe;const ke=[],dt=new Ai(()=>new de);function Fn(n,e,t,i,s,a){Te=dt.getPrimitive(),Xe=dt.getPrimitive(),ke.push(Te,Xe),B.setBuffer(n._roots[e]);const r=fi(0,n.geometry,t,i,s,a);B.clearBuffer(),dt.releasePrimitive(Te),dt.releasePrimitive(Xe),ke.pop(),ke.pop();const c=ke.length;return c>0&&(Xe=ke[c-1],Te=ke[c-2]),r}function fi(n,e,t,i,s=null,a=0,r=0){const{float32Array:c,uint16Array:l,uint32Array:h}=B;let f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);return z(n,c,Te),i(o,m,!1,r,a+n/O,Te)}else{let _=function(S){const{uint16Array:R,uint32Array:F}=B;let D=S*2;for(;!k(D,R);)S=W(S),D=S*2;return H(S,F)},P=function(S){const{uint16Array:R,uint32Array:F}=B;let D=S*2;for(;!k(D,R);)S=V(S,F),D=S*2;return H(S,F)+q(D,R)};const o=W(n),m=V(n,h);let g=o,x=m,d,b,p,v;if(s&&(p=Te,v=Xe,z(g,c,p),z(x,c,v),d=s(p),b=s(v),b<d)){g=m,x=o;const S=d;d=b,b=S,p=v}p||(p=Te,z(g,c,p));const y=k(g*2,l),T=t(p,y,d,r+1,a+g/O);let A;if(T===Bi){const S=_(g),F=P(g)-S;A=i(S,F,!0,r+1,a+g/O,p)}else A=T&&fi(g,e,t,i,s,a,r+1);if(A)return!0;v=Xe,z(x,c,v);const w=k(x*2,l),M=t(v,w,b,r+1,a+x/O);let I;if(M===Bi){const S=_(x),F=P(x)-S;I=i(S,F,!0,r+1,a+x/O,v)}else I=M&&fi(x,e,t,i,s,a,r+1);return!!I}}const ut=new B.constructor,Bt=new B.constructor,be=new Ai(()=>new de),Oe=new de,Ue=new de,Xt=new de,Qt=new de;let Kt=!1;function Cn(n,e,t,i){if(Kt)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Kt=!0;const s=n._roots,a=e._roots;let r,c=0,l=0;const h=new $().copy(t).invert();for(let f=0,u=s.length;f<u;f++){ut.setBuffer(s[f]),l=0;const o=be.getPrimitive();z(0,ut.float32Array,o),o.applyMatrix4(h);for(let m=0,g=a.length;m<g&&(Bt.setBuffer(a[m]),r=ae(0,0,t,h,i,c,l,0,0,o),Bt.clearBuffer(),l+=a[m].byteLength/j,!r);m++);if(be.releasePrimitive(o),ut.clearBuffer(),c+=s[f].byteLength/j,r)break}return Kt=!1,r}function ae(n,e,t,i,s,a=0,r=0,c=0,l=0,h=null,f=!1){let u,o;f?(u=Bt,o=ut):(u=ut,o=Bt);const m=u.float32Array,g=u.uint32Array,x=u.uint16Array,d=o.float32Array,b=o.uint32Array,p=o.uint16Array,v=n*2,y=e*2,T=k(v,x),A=k(y,p);let w=!1;if(A&&T)f?w=s(H(e,b),q(e*2,p),H(n,g),q(n*2,x),l,r+e/O,c,a+n/O):w=s(H(n,g),q(n*2,x),H(e,b),q(e*2,p),c,a+n/O,l,r+e/O);else if(A){const M=be.getPrimitive();z(e,d,M),M.applyMatrix4(t);const I=W(n),_=V(n,g);z(I,m,Oe),z(_,m,Ue);const P=M.intersectsBox(Oe),S=M.intersectsBox(Ue);w=P&&ae(e,I,i,t,s,r,a,l,c+1,M,!f)||S&&ae(e,_,i,t,s,r,a,l,c+1,M,!f),be.releasePrimitive(M)}else{const M=W(e),I=V(e,b);z(M,d,Xt),z(I,d,Qt);const _=h.intersectsBox(Xt),P=h.intersectsBox(Qt);if(_&&P)w=ae(n,M,t,i,s,a,r,c,l+1,h,f)||ae(n,I,t,i,s,a,r,c,l+1,h,f);else if(_)if(T)w=ae(n,M,t,i,s,a,r,c,l+1,h,f);else{const S=be.getPrimitive();S.copy(Xt).applyMatrix4(t);const R=W(n),F=V(n,g);z(R,m,Oe),z(F,m,Ue);const D=S.intersectsBox(Oe),E=S.intersectsBox(Ue);w=D&&ae(M,R,i,t,s,r,a,l,c+1,S,!f)||E&&ae(M,F,i,t,s,r,a,l,c+1,S,!f),be.releasePrimitive(S)}else if(P)if(T)w=ae(n,I,t,i,s,a,r,c,l+1,h,f);else{const S=be.getPrimitive();S.copy(Qt).applyMatrix4(t);const R=W(n),F=V(n,g);z(R,m,Oe),z(F,m,Ue);const D=S.intersectsBox(Oe),E=S.intersectsBox(Ue);w=D&&ae(I,R,i,t,s,r,a,l,c+1,S,!f)||E&&ae(I,F,i,t,s,r,a,l,c+1,S,!f),be.releasePrimitive(S)}}return w}const Zt=new class{constructor(){let n=null,e=null,t=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(a,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=n=a._roots[r],this.uint16Array=t=new Uint16Array(n),this.uint32Array=e=new Uint32Array(n)},this.reset=()=>{this.root=null,this.buffer=n=null,this.uint16Array=t=null,this.uint32Array=e=null},this.getRangeStart=a=>{let r=a*2;for(;!k(r,t);)a=W(a),r=a*2;return H(a,e)},this.getRangeEnd=a=>{let r=a*2;for(;!k(r,t);)a=V(a,e),r=a*2;return H(a,e)+q(r,t)};const s=(a,r,c)=>{const l=r*2,h=k(l,t);if(!a(c,h,r)&&!h){const u=W(r),o=V(r,e);s(a,u,c+1),s(a,o,c+1)}};this.traverseBuffer=a=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(a,0,0)}finally{i=!1}},this.traverse=a=>{this.traverseBuffer((r,c,l)=>{if(c){const h=l*2,f=e[l+6],u=t[h+14];return a(r,c,new Float32Array(n,l*4,6),f,u)}else{const h=kt(l,e);return a(r,c,new Float32Array(n,l*4,6),h)}})}}},Ui=new de,Le=new Float32Array(6);class Dn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Fr,...e},"maxLeafSize"in e&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafSize}),Pn(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,i,s){let a=1/0,r=1/0,c=1/0,l=-1/0,h=-1/0,f=-1/0;for(let u=e,o=e+t;u<o;u++){this.writePrimitiveBounds(u,Le,0);const[m,g,x,d,b,p]=Le;m<a&&(a=m),d>l&&(l=d),g<r&&(r=g),b>h&&(h=b),x<c&&(c=x),p>f&&(f=p)}return i[s+0]=a,i[s+1]=r,i[s+2]=c,i[s+3]=l,i[s+4]=h,i[s+5]=f,i}computePrimitiveBounds(e,t,i){const s=i.offset||0;for(let a=e,r=e+t;a<r;a++){this.writePrimitiveBounds(a,Le,0);const[c,l,h,f,u,o]=Le,m=(c+f)/2,g=(l+u)/2,x=(h+o)/2,d=(f-c)/2,b=(u-l)/2,p=(o-h)/2,v=(a-s)*6;i[v+0]=m,i[v+1]=d+(Math.abs(m)+d)*Dt,i[v+2]=g,i[v+3]=b+(Math.abs(g)+b)*Dt,i[v+4]=x,i[v+5]=p+(Math.abs(x)+p)*Dt}return i}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let i=0,s=t.length;i<s;i++)t[i]+=e;else{const i=this._roots;for(let s=0;s<i.length;s++){const a=i[s],r=new Uint32Array(a),c=new Uint16Array(a),l=a.byteLength/j;for(let h=0;h<l;h++){const f=O*h,u=2*f;k(u,c)&&(r[f+6]+=e)}}}}traverse(e,t=0){Zt.setBVH(this,t),Zt.traverse(e),Zt.reset()}refit(){const e=this._roots;for(let t=0,i=e.length;t<i;t++){const s=e[t],a=new Uint32Array(s),r=new Uint16Array(s),c=new Float32Array(s),l=s.byteLength/j;for(let h=l-1;h>=0;h--){const f=h*O,u=f*2;if(k(u,r)){const m=H(f,a),g=q(u,r);this.writePrimitiveRangeBounds(m,g,Le,0),c.set(Le,f)}else{const m=W(f),g=V(f,a);for(let x=0;x<3;x++){const d=c[m+x],b=c[m+x+3],p=c[g+x],v=c[g+x+3];c[f+x]=d<p?d:p,c[f+x+3]=b>v?b:v}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{z(0,new Float32Array(i),Ui),e.union(Ui)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:a,scratchPrimitive:r,iterate:c}=e;if(s&&a){const u=s;s=(o,m,g,x,d)=>u(o,m,g,x,d)?!0:c(o,m,this,a,g,x,r)}else s||(a?s=(u,o,m,g)=>c(u,o,this,a,m,g,r):s=(u,o,m)=>m);let l=!1,h=0;const f=this._roots;for(let u=0,o=f.length;u<o;u++){const m=f[u];if(l=Fn(this,u,i,s,t,h),l)break;h+=m.byteLength/j}return l}bvhcast(e,t,i){let{intersectsRanges:s}=i;return Cn(this,e,t,s)}}function En(){return typeof SharedArrayBuffer<"u"}function Ot(n){return n.index?n.index.count:n.attributes.position.count}function Ut(n){return Ot(n)/3}function Cr(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Bn(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Cr(t,i);n.setIndex(new te(s,1));for(let a=0;a<t;a++)s[a]=a}}function zn(n,e,t){const i=Ot(n)/t,s=e||n.drawRange,a=s.start/t,r=(s.start+s.count)/t,c=Math.max(0,a),l=Math.min(i,r)-c;return{offset:Math.floor(c),count:Math.floor(l)}}function Nn(n,e){return n.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function Li(n,e,t){const i=zn(n,e,t),s=Nn(n,t);if(!s.length)return[i];const a=[],r=i.offset,c=i.offset+i.count,l=Ot(n)/t,h=[];for(const o of s){const{offset:m,count:g}=o,x=m,d=isFinite(g)?g:l-m,b=m+d;x<c&&b>r&&(h.push({pos:Math.max(r,x),isStart:!0}),h.push({pos:Math.min(c,b),isStart:!1}))}h.sort((o,m)=>o.pos!==m.pos?o.pos-m.pos:o.type==="end"?-1:1);let f=0,u=null;for(const o of h){const m=o.pos;f!==0&&m!==u&&a.push({offset:u,count:m-u}),f+=o.isStart?1:-1,u=m}return a}function kn(n,e){const t=n[n.length-1],i=t.offset+t.count>2**16,s=n.reduce((h,f)=>h+f.count,0),a=i?4:2,r=e?new SharedArrayBuffer(s*a):new ArrayBuffer(s*a),c=i?new Uint32Array(r):new Uint16Array(r);let l=0;for(let h=0;h<n.length;h++){const{offset:f,count:u}=n[h];for(let o=0;o<u;o++)c[l+o]=f+o;l+=u}return c}class On extends Dn{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&&!En())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Fr,...t},t[Si]||this.init(t)}init(e){const{geometry:t,primitiveStride:i}=this;if(e.indirect){const s=Li(t,e.range,i),a=kn(s,e.useSharedArrayBuffer);this._indirectBuffer=a}else Bn(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new de))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Li(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class ve{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let a=0,r=e.length;a<r;a++){const l=e[a][t];i=l<i?l:i,s=l>s?l:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let a=0,r=t.length;a<r;a++){const c=t[a],l=e.dot(c);i=l<i?l:i,s=l>s?l:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}ve.prototype.setFromBox=(function(){const n=new C;return function(t,i){const s=i.min,a=i.max;let r=1/0,c=-1/0;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let f=0;f<=1;f++){n.x=s.x*l+a.x*(1-l),n.y=s.y*h+a.y*(1-h),n.z=s.z*f+a.z*(1-f);const u=t.dot(n);r=Math.min(u,r),c=Math.max(u,c)}this.min=r,this.max=c}})();const Un=(function(){const n=new C,e=new C,t=new C;return function(s,a,r){const c=s.start,l=n,h=a.start,f=e;t.subVectors(c,h),n.subVectors(s.end,s.start),e.subVectors(a.end,a.start);const u=t.dot(f),o=f.dot(l),m=f.dot(f),g=t.dot(l),d=l.dot(l)*m-o*o;let b,p;d!==0?b=(u*o-g*m)/d:b=0,p=(u+b*o)/m,r.x=b,r.y=p}})(),Mi=(function(){const n=new Y,e=new C,t=new C;return function(s,a,r,c){Un(s,a,n);let l=n.x,h=n.y;if(l>=0&&l<=1&&h>=0&&h<=1){s.at(l,r),a.at(h,c);return}else if(l>=0&&l<=1){h<0?a.at(0,c):a.at(1,c),s.closestPointToPoint(c,!0,r);return}else if(h>=0&&h<=1){l<0?s.at(0,r):s.at(1,r),a.closestPointToPoint(r,!0,c);return}else{let f;l<0?f=s.start:f=s.end;let u;h<0?u=a.start:u=a.end;const o=e,m=t;if(s.closestPointToPoint(u,!0,e),a.closestPointToPoint(f,!0,t),o.distanceToSquared(u)<=m.distanceToSquared(f)){r.copy(o),c.copy(u);return}else{r.copy(f),c.copy(m);return}}}})(),Ln=(function(){const n=new C,e=new C,t=new br,i=new ge;return function(a,r){const{radius:c,center:l}=a,{a:h,b:f,c:u}=r;if(i.start=h,i.end=f,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c||(i.start=h,i.end=u,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c)||(i.start=f,i.end=u,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c))return!0;const x=r.getPlane(t);if(Math.abs(x.distanceToPoint(l))<=c){const b=x.projectPoint(l,e);if(r.containsPoint(b))return!0}return!1}})(),Hn=["x","y","z"],pe=1e-15,Hi=pe*pe;function J(n){return Math.abs(n)<pe}class ce extends Ye{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new C),this.satBounds=new Array(4).fill().map(()=>new ve),this.points=[this.a,this.b,this.c],this.plane=new br,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new ge,this.needsUpdate=!0}intersectsSphere(e){return Ln(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,a=this.satAxes,r=this.satBounds,c=a[0],l=r[0];this.getNormal(c),l.setFromPoints(c,s);const h=a[1],f=r[1];h.subVectors(e,t),f.setFromPoints(h,s);const u=a[2],o=r[2];u.subVectors(t,i),o.setFromPoints(u,s);const m=a[3],g=r[3];m.subVectors(i,e),g.setFromPoints(m,s);const x=h.length(),d=u.length(),b=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,x<pe?d<pe||b<pe?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(i)):d<pe?b<pe?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):b<pe&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}ce.prototype.closestPointToSegment=(function(){const n=new C,e=new C,t=new ge;return function(s,a=null,r=null){this.needsUpdate&&this.update();const{start:c,end:l}=s,h=this.points;let f,u=1/0;const o=this.plane.distanceToPoint(c),m=this.plane.distanceToPoint(l);if(o*m<0&&this.plane.intersectLine(s,n)!==null&&this.containsPoint(n))return a&&a.copy(n),r&&r.copy(n),0;for(let g=0;g<3;g++){const x=(g+1)%3;t.start.copy(h[g]),t.end.copy(h[x]),Mi(t,s,n,e),f=n.distanceToSquared(e),f<u&&(u=f,a&&a.copy(n),r&&r.copy(e))}return this.closestPointToPoint(c,n),f=c.distanceToSquared(n),f<u&&(u=f,a&&a.copy(n),r&&r.copy(c)),this.closestPointToPoint(l,n),f=l.distanceToSquared(n),f<u&&(u=f,a&&a.copy(n),r&&r.copy(l)),Math.sqrt(u)}})();ce.prototype.intersectsTriangle=(function(){const n=new ce,e=new ve,t=new ve,i=new C,s=new C,a=new C,r=new C,c=new ge,l=new ge,h=new C,f=new Y,u=new Y;function o(v,y,T,A){const w=i;!v.isDegenerateIntoPoint&&!v.isDegenerateIntoSegment?w.copy(v.plane.normal):w.copy(y.plane.normal);const M=v.satBounds,I=v.satAxes;for(let S=1;S<4;S++){const R=M[S],F=I[S];if(e.setFromPoints(F,y.points),R.isSeparated(e)||(r.copy(w).cross(F),e.setFromPoints(r,v.points),t.setFromPoints(r,y.points),e.isSeparated(t)))return!1}const _=y.satBounds,P=y.satAxes;for(let S=1;S<4;S++){const R=_[S],F=P[S];if(e.setFromPoints(F,v.points),R.isSeparated(e)||(r.crossVectors(w,F),e.setFromPoints(r,v.points),t.setFromPoints(r,y.points),e.isSeparated(t)))return!1}return T&&(A||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),T.start.set(0,0,0),T.end.set(0,0,0)),!0}function m(v,y,T,A,w,M,I,_,P,S,R){let F=I/(I-_);S.x=A+(w-A)*F,R.start.subVectors(y,v).multiplyScalar(F).add(v),F=I/(I-P),S.y=A+(M-A)*F,R.end.subVectors(T,v).multiplyScalar(F).add(v)}function g(v,y,T,A,w,M,I,_,P,S,R){if(w>0)m(v.c,v.a,v.b,A,y,T,P,I,_,S,R);else if(M>0)m(v.b,v.a,v.c,T,y,A,_,I,P,S,R);else if(_*P>0||I!=0)m(v.a,v.b,v.c,y,T,A,I,_,P,S,R);else if(_!=0)m(v.b,v.a,v.c,T,y,A,_,I,P,S,R);else if(P!=0)m(v.c,v.a,v.b,A,y,T,P,I,_,S,R);else return!0;return!1}function x(v,y,T,A){const w=y.degenerateSegment,M=v.plane.distanceToPoint(w.start),I=v.plane.distanceToPoint(w.end);return J(M)?J(I)?o(v,y,T,A):(T&&(T.start.copy(w.start),T.end.copy(w.start)),v.containsPoint(w.start)):J(I)?(T&&(T.start.copy(w.end),T.end.copy(w.end)),v.containsPoint(w.end)):v.plane.intersectLine(w,i)!=null?(T&&(T.start.copy(i),T.end.copy(i)),v.containsPoint(i)):!1}function d(v,y,T){const A=y.a;return J(v.plane.distanceToPoint(A))&&v.containsPoint(A)?(T&&(T.start.copy(A),T.end.copy(A)),!0):!1}function b(v,y,T){const A=v.degenerateSegment,w=y.a;return A.closestPointToPoint(w,!0,i),w.distanceToSquared(i)<Hi?(T&&(T.start.copy(w),T.end.copy(w)),!0):!1}function p(v,y,T,A){if(v.isDegenerateIntoSegment)if(y.isDegenerateIntoSegment){const w=v.degenerateSegment,M=y.degenerateSegment,I=s,_=a;w.delta(I),M.delta(_);const P=i.subVectors(M.start,w.start),S=I.x*_.y-I.y*_.x;if(J(S))return!1;const R=(P.x*_.y-P.y*_.x)/S,F=-(I.x*P.y-I.y*P.x)/S;if(R<0||R>1||F<0||F>1)return!1;const D=w.start.z+I.z*R,E=M.start.z+_.z*F;return J(D-E)?(T&&(T.start.copy(w.start).addScaledVector(I,R),T.end.copy(w.start).addScaledVector(I,R)),!0):!1}else return y.isDegenerateIntoPoint?b(v,y,T):x(y,v,T,A);else{if(v.isDegenerateIntoPoint)return y.isDegenerateIntoPoint?y.a.distanceToSquared(v.a)<Hi?(T&&(T.start.copy(v.a),T.end.copy(v.a)),!0):!1:y.isDegenerateIntoSegment?b(y,v,T):d(y,v,T);if(y.isDegenerateIntoPoint)return d(v,y,T);if(y.isDegenerateIntoSegment)return x(v,y,T,A)}}return function(y,T=null,A=!1){this.needsUpdate&&this.update(),y.isExtendedTriangle?y.needsUpdate&&y.update():(n.copy(y),n.update(),y=n);const w=p(this,y,T,A);if(w!==void 0)return w;const M=this.plane,I=y.plane;let _=I.distanceToPoint(this.a),P=I.distanceToPoint(this.b),S=I.distanceToPoint(this.c);J(_)&&(_=0),J(P)&&(P=0),J(S)&&(S=0);const R=_*P,F=_*S;if(R>0&&F>0)return!1;let D=M.distanceToPoint(y.a),E=M.distanceToPoint(y.b),le=M.distanceToPoint(y.c);J(D)&&(D=0),J(E)&&(E=0),J(le)&&(le=0);const me=D*E,xe=D*le;if(me>0&&xe>0)return!1;s.copy(M.normal),a.copy(I.normal);const Ee=s.cross(a);let _e=0,Wt=Math.abs(Ee.x);const Ci=Math.abs(Ee.y);Ci>Wt&&(Wt=Ci,_e=1),Math.abs(Ee.z)>Wt&&(_e=2);const Be=Hn[_e],Gr=this.a[Be],$r=this.b[Be],Yr=this.c[Be],jr=y.a[Be],Xr=y.b[Be],Qr=y.c[Be];if(g(this,Gr,$r,Yr,R,F,_,P,S,f,c))return o(this,y,T,A);if(g(y,jr,Xr,Qr,me,xe,D,E,le,u,l))return o(this,y,T,A);if(f.y<f.x){const Vt=f.y;f.y=f.x,f.x=Vt,h.copy(c.start),c.start.copy(c.end),c.end.copy(h)}if(u.y<u.x){const Vt=u.y;u.y=u.x,u.x=Vt,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}return f.y<u.x||u.y<f.x?!1:(T&&(u.x>f.x?T.start.copy(l.start):T.start.copy(c.start),u.y<f.y?T.end.copy(l.end):T.end.copy(c.end)),!0)}})();ce.prototype.distanceToPoint=(function(){const n=new C;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();ce.prototype.distanceToTriangle=(function(){const n=new C,e=new C,t=["a","b","c"],i=new ge,s=new ge;return function(r,c=null,l=null){const h=c||l?i:null;if(this.intersectsTriangle(r,h,!0))return(c||l)&&(c&&h.getCenter(c),l&&h.getCenter(l)),0;let f=1/0;for(let u=0;u<3;u++){let o;const m=t[u],g=r[m];this.closestPointToPoint(g,n),o=g.distanceToSquared(n),o<f&&(f=o,c&&c.copy(n),l&&l.copy(g));const x=this[m];r.closestPointToPoint(x,n),o=x.distanceToSquared(n),o<f&&(f=o,c&&c.copy(x),l&&l.copy(n))}for(let u=0;u<3;u++){const o=t[u],m=t[(u+1)%3];i.set(this[o],this[m]);for(let g=0;g<3;g++){const x=t[g],d=t[(g+1)%3];s.set(r[x],r[d]),Mi(i,s,n,e);const b=n.distanceToSquared(e);b<f&&(f=b,c&&c.copy(n),l&&l.copy(e))}}return Math.sqrt(f)}})();class X{constructor(e,t,i){this.isOrientedBox=!0,this.min=new C,this.max=new C,this.matrix=new $,this.invMatrix=new $,this.points=new Array(8).fill().map(()=>new C),this.satAxes=new Array(3).fill().map(()=>new C),this.satBounds=new Array(3).fill().map(()=>new ve),this.alignedSatBounds=new Array(3).fill().map(()=>new ve),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}X.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let h=0;h<=1;h++)for(let f=0;f<=1;f++)for(let u=0;u<=1;u++){const o=1*h|2*f|4*u,m=s[o];m.x=h?i.x:t.x,m.y=f?i.y:t.y,m.z=u?i.z:t.z,m.applyMatrix4(e)}const a=this.satBounds,r=this.satAxes,c=s[0];for(let h=0;h<3;h++){const f=r[h],u=a[h],o=1<<h,m=s[o];f.subVectors(c,m),u.setFromPoints(f,s)}const l=this.alignedSatBounds;l[0].setFromPointsField(s,"x"),l[1].setFromPointsField(s,"y"),l[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();X.prototype.intersectsBox=(function(){const n=new ve;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,a=this.satBounds,r=this.satAxes,c=this.alignedSatBounds;if(n.min=i.x,n.max=s.x,c[0].isSeparated(n)||(n.min=i.y,n.max=s.y,c[1].isSeparated(n))||(n.min=i.z,n.max=s.z,c[2].isSeparated(n)))return!1;for(let l=0;l<3;l++){const h=r[l],f=a[l];if(n.setFromBox(h,t),f.isSeparated(n))return!1}return!0}})();X.prototype.intersectsTriangle=(function(){const n=new ce,e=new Array(3),t=new ve,i=new ve,s=new C;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(n.copy(r),n.update(),r=n);const c=this.satBounds,l=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let o=0;o<3;o++){const m=c[o],g=l[o];if(t.setFromPoints(g,e),m.isSeparated(t))return!1}const h=r.satBounds,f=r.satAxes,u=this.points;for(let o=0;o<3;o++){const m=h[o],g=f[o];if(t.setFromPoints(g,u),m.isSeparated(t))return!1}for(let o=0;o<3;o++){const m=l[o];for(let g=0;g<4;g++){const x=f[g];if(s.crossVectors(m,x),t.setFromPoints(s,e),i.setFromPoints(s,u),t.isSeparated(i))return!1}}return!0}})();X.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();X.prototype.distanceToPoint=(function(){const n=new C;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();X.prototype.distanceToBox=(function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ge),t=new Array(12).fill().map(()=>new ge),i=new C,s=new C;return function(r,c=0,l=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(l||h)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),l&&l.copy(i),h&&h.copy(s)),0;const f=c*c,u=r.min,o=r.max,m=this.points;let g=1/0;for(let d=0;d<8;d++){const b=m[d];s.copy(b).clamp(u,o);const p=b.distanceToSquared(s);if(p<g&&(g=p,l&&l.copy(b),h&&h.copy(s),p<f))return Math.sqrt(p)}let x=0;for(let d=0;d<3;d++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const v=(d+1)%3,y=(d+2)%3,T=b<<v|p<<y,A=1<<d|b<<v|p<<y,w=m[T],M=m[A];e[x].set(w,M);const _=n[d],P=n[v],S=n[y],R=t[x],F=R.start,D=R.end;F[_]=u[_],F[P]=b?u[P]:o[P],F[S]=p?u[S]:o[S],D[_]=o[_],D[P]=b?u[P]:o[P],D[S]=p?u[S]:o[S],x++}for(let d=0;d<=1;d++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=d?o.x:u.x,s.y=b?o.y:u.y,s.z=p?o.z:u.z,this.closestPointToPoint(s,i);const v=s.distanceToSquared(i);if(v<g&&(g=v,l&&l.copy(i),h&&h.copy(s),v<f))return Math.sqrt(v)}for(let d=0;d<12;d++){const b=e[d];for(let p=0;p<12;p++){const v=t[p];Mi(b,v,i,s);const y=i.distanceToSquared(s);if(y<g&&(g=y,l&&l.copy(i),h&&h.copy(s),y<f))return Math.sqrt(y)}}return Math.sqrt(g)}})();class Wn extends Ai{constructor(){super(()=>new ce)}}const ie=new Wn,it=new C,Jt=new C;function Vn(n,e,t={},i=0,s=1/0){const a=i*i,r=s*s;let c=1/0,l=null;if(n.shapecast({boundsTraverseOrder:f=>(it.copy(e).clamp(f.min,f.max),it.distanceToSquared(e)),intersectsBounds:(f,u,o)=>o<c&&o<r,intersectsTriangle:(f,u)=>{f.closestPointToPoint(e,it);const o=e.distanceToSquared(it);return o<c&&(Jt.copy(it),c=o,l=u),o<a}}),c===1/0)return null;const h=Math.sqrt(c);return t.point?t.point.copy(Jt):t.point=Jt.clone(),t.distance=h,t.faceIndex=l,t}const mt=parseInt(Sr)>=169,qn=parseInt(Sr)<=161,Ae=new C,Me=new C,Ie=new C,pt=new Y,gt=new Y,vt=new Y,Wi=new C,Vi=new C,qi=new C,rt=new C;function Gn(n,e,t,i,s,a,r,c){let l;if(a===Tr?l=n.intersectTriangle(i,t,e,!0,s):l=n.intersectTriangle(e,t,i,a!==wr,s),l===null)return null;const h=n.origin.distanceTo(s);return h<r||h>c?null:{distance:h,point:s.clone()}}function Gi(n,e,t,i,s,a,r,c,l,h,f){Ae.fromBufferAttribute(e,a),Me.fromBufferAttribute(e,r),Ie.fromBufferAttribute(e,c);const u=Gn(n,Ae,Me,Ie,rt,l,h,f);if(u){if(i){pt.fromBufferAttribute(i,a),gt.fromBufferAttribute(i,r),vt.fromBufferAttribute(i,c),u.uv=new Y;const m=Ye.getInterpolation(rt,Ae,Me,Ie,pt,gt,vt,u.uv);mt||(u.uv=m)}if(s){pt.fromBufferAttribute(s,a),gt.fromBufferAttribute(s,r),vt.fromBufferAttribute(s,c),u.uv1=new Y;const m=Ye.getInterpolation(rt,Ae,Me,Ie,pt,gt,vt,u.uv1);mt||(u.uv1=m),qn&&(u.uv2=u.uv1)}if(t){Wi.fromBufferAttribute(t,a),Vi.fromBufferAttribute(t,r),qi.fromBufferAttribute(t,c),u.normal=new C;const m=Ye.getInterpolation(rt,Ae,Me,Ie,Wi,Vi,qi,u.normal);u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1),mt||(u.normal=m)}const o={a,b:r,c,normal:new C,materialIndex:0};if(Ye.getNormal(Ae,Me,Ie,o.normal),u.face=o,u.faceIndex=a,mt){const m=new C;Ye.getBarycoord(rt,Ae,Me,Ie,m),u.barycoord=m}}return u}function $i(n){return n&&n.isMaterial?n.side:n}function Lt(n,e,t,i,s,a,r){const c=i*3;let l=c+0,h=c+1,f=c+2;const{index:u,groups:o}=n;n.index&&(l=u.getX(l),h=u.getX(h),f=u.getX(f));const{position:m,normal:g,uv:x,uv1:d}=n.attributes;if(Array.isArray(e)){const b=i*3;for(let p=0,v=o.length;p<v;p++){const{start:y,count:T,materialIndex:A}=o[p];if(b>=y&&b<y+T){const w=$i(e[A]),M=Gi(t,m,g,x,d,l,h,f,w,a,r);if(M)if(M.faceIndex=i,M.face.materialIndex=A,s)s.push(M);else return M}}}else{const b=$i(e),p=Gi(t,m,g,x,d,l,h,f,b,a,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function U(n,e,t,i){const s=n.a,a=n.b,r=n.c;let c=e,l=e+1,h=e+2;t&&(c=t.getX(c),l=t.getX(l),h=t.getX(h)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l),r.x=i.getX(h),r.y=i.getY(h),r.z=i.getZ(h)}function $n(n,e,t,i,s,a,r,c){const{geometry:l,_indirectBuffer:h}=n;for(let f=i,u=i+s;f<u;f++)Lt(l,e,t,f,a,r,c)}function Yn(n,e,t,i,s,a,r){const{geometry:c,_indirectBuffer:l}=n;let h=1/0,f=null;for(let u=i,o=i+s;u<o;u++){let m;m=Lt(c,e,t,u,null,a,r),m&&m.distance<h&&(f=m,h=m.distance)}return f}function jn(n,e,t,i,s,a,r){const{geometry:c}=t,{index:l}=c,h=c.attributes.position;for(let f=n,u=e+n;f<u;f++){let o;if(o=f,U(r,o*3,l,h),r.needsUpdate=!0,i(r,o,s,a))return!0}return!1}function Xn(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,r,c,l,h=0;const f=n._roots;for(let o=0,m=f.length;o<m;o++)a=f[o],r=new Uint32Array(a),c=new Uint16Array(a),l=new Float32Array(a),u(0,h),h+=a.byteLength;function u(o,m,g=!1){const x=o*2;if(k(x,c)){const d=H(o,r),b=q(x,c);let p=1/0,v=1/0,y=1/0,T=-1/0,A=-1/0,w=-1/0;for(let M=3*d,I=3*(d+b);M<I;M++){let _=i[M];const P=s.getX(_),S=s.getY(_),R=s.getZ(_);P<p&&(p=P),P>T&&(T=P),S<v&&(v=S),S>A&&(A=S),R<y&&(y=R),R>w&&(w=R)}return l[o+0]!==p||l[o+1]!==v||l[o+2]!==y||l[o+3]!==T||l[o+4]!==A||l[o+5]!==w?(l[o+0]=p,l[o+1]=v,l[o+2]=y,l[o+3]=T,l[o+4]=A,l[o+5]=w,!0):!1}else{const d=W(o),b=V(o,r);let p=g,v=!1,y=!1;if(e){if(!p){const _=d/O+m/j,P=b/O+m/j;v=e.has(_),y=e.has(P),p=!v&&!y}}else v=!0,y=!0;const T=p||v,A=p||y;let w=!1;T&&(w=u(d,m,p));let M=!1;A&&(M=u(b,m,p));const I=w||M;if(I)for(let _=0;_<3;_++){const P=d+_,S=b+_,R=l[P],F=l[P+3],D=l[S],E=l[S+3];l[o+_]=R<D?R:D,l[o+_+3]=F>E?F:E}return I}}}function re(n,e,t,i,s){let a,r,c,l,h,f;const u=1/t.direction.x,o=1/t.direction.y,m=1/t.direction.z,g=t.origin.x,x=t.origin.y,d=t.origin.z;let b=e[n],p=e[n+3],v=e[n+1],y=e[n+3+1],T=e[n+2],A=e[n+3+2];return u>=0?(a=(b-g)*u,r=(p-g)*u):(a=(p-g)*u,r=(b-g)*u),o>=0?(c=(v-x)*o,l=(y-x)*o):(c=(y-x)*o,l=(v-x)*o),a>l||c>r||((c>a||isNaN(a))&&(a=c),(l<r||isNaN(r))&&(r=l),m>=0?(h=(T-d)*m,f=(A-d)*m):(h=(A-d)*m,f=(T-d)*m),a>f||h>r)?!1:((h>a||a!==a)&&(a=h),(f<r||r!==r)&&(r=f),a<=s&&r>=i)}function Qn(n,e,t,i,s,a,r,c){const{geometry:l,_indirectBuffer:h}=n;for(let f=i,u=i+s;f<u;f++){let o=h?h[f]:f;Lt(l,e,t,o,a,r,c)}}function Kn(n,e,t,i,s,a,r){const{geometry:c,_indirectBuffer:l}=n;let h=1/0,f=null;for(let u=i,o=i+s;u<o;u++){let m;m=Lt(c,e,t,l?l[u]:u,null,a,r),m&&m.distance<h&&(f=m,h=m.distance)}return f}function Zn(n,e,t,i,s,a,r){const{geometry:c}=t,{index:l}=c,h=c.attributes.position;for(let f=n,u=e+n;f<u;f++){let o;if(o=t.resolveTriangleIndex(f),U(r,o*3,l,h),r.needsUpdate=!0,i(r,o,s,a))return!0}return!1}function Jn(n,e,t,i,s,a,r){B.setBuffer(n._roots[e]),re(0,B.float32Array,i,a,r)&&hi(0,n,t,i,s,a,r),B.clearBuffer()}function hi(n,e,t,i,s,a,r){const{float32Array:c,uint16Array:l,uint32Array:h}=B,f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);$n(e,t,i,o,m,s,a,r)}else{const o=W(n);re(o,c,i,a,r)&&hi(o,e,t,i,s,a,r);const m=V(n,h);re(m,c,i,a,r)&&hi(m,e,t,i,s,a,r)}}const es=["x","y","z"];function ts(n,e,t,i,s,a){B.setBuffer(n._roots[e]);let r=null;return re(0,B.float32Array,i,s,a)&&(r=di(0,n,t,i,s,a)),B.clearBuffer(),r}function di(n,e,t,i,s,a){const{float32Array:r,uint16Array:c,uint32Array:l}=B;let h=n*2;if(k(h,c)){const u=H(n,l),o=q(h,c);return Yn(e,t,i,u,o,s,a)}else{const u=kt(n,l),o=es[u],g=i.direction[o]>=0;let x,d;g?(x=W(n),d=V(n,l)):(x=V(n,l),d=W(n));const p=re(x,r,i,s,a)?di(x,e,t,i,s,a):null;if(p){const T=p.point[o];if(g?T<=r[d+u]:T>=r[d+u+3])return p}const y=re(d,r,i,s,a)?di(d,e,t,i,s,a):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const xt=new de,He=new ce,We=new ce,nt=new $,Yi=new X,yt=new X;function is(n,e,t,i){B.setBuffer(n._roots[e]);const s=mi(0,n,t,i);return B.clearBuffer(),s}function mi(n,e,t,i,s=null){const{float32Array:a,uint16Array:r,uint32Array:c}=B;let l=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Yi.set(t.boundingBox.min,t.boundingBox.max,i),s=Yi),k(l,r)){const f=e.geometry,u=f.index,o=f.attributes.position,m=t.index,g=t.attributes.position,x=H(n,c),d=q(l,r);if(nt.copy(i).invert(),t.boundsTree)return z(n,a,yt),yt.matrix.copy(nt),yt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:p=>yt.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let v=x*3,y=(d+x)*3;v<y;v+=3)if(U(We,v,u,o),We.needsUpdate=!0,p.intersectsTriangle(We))return!0;return!1}});{const b=Ut(t);for(let p=x*3,v=(d+x)*3;p<v;p+=3){U(He,p,u,o),He.a.applyMatrix4(nt),He.b.applyMatrix4(nt),He.c.applyMatrix4(nt),He.needsUpdate=!0;for(let y=0,T=b*3;y<T;y+=3)if(U(We,y,m,g),We.needsUpdate=!0,He.intersectsTriangle(We))return!0}}}else{const f=W(n),u=V(n,c);return z(f,a,xt),!!(s.intersectsBox(xt)&&mi(f,e,t,i,s)||(z(u,a,xt),s.intersectsBox(xt)&&mi(u,e,t,i,s)))}}const bt=new $,ei=new X,st=new X,rs=new C,ns=new C,ss=new C,as=new C;function os(n,e,t,i={},s={},a=0,r=1/0){e.boundingBox||e.computeBoundingBox(),ei.set(e.boundingBox.min,e.boundingBox.max,t),ei.needsUpdate=!0;const c=n.geometry,l=c.attributes.position,h=c.index,f=e.attributes.position,u=e.index,o=ie.getPrimitive(),m=ie.getPrimitive();let g=rs,x=ns,d=null,b=null;s&&(d=ss,b=as);let p=1/0,v=null,y=null;return bt.copy(t).invert(),st.matrix.copy(bt),n.shapecast({boundsTraverseOrder:T=>ei.distanceToBox(T),intersectsBounds:(T,A,w)=>w<p&&w<r?(A&&(st.min.copy(T.min),st.max.copy(T.max),st.needsUpdate=!0),!0):!1,intersectsRange:(T,A)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:M=>st.distanceToBox(M),intersectsBounds:(M,I,_)=>_<p&&_<r,intersectsRange:(M,I)=>{for(let _=M,P=M+I;_<P;_++){U(m,3*_,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let S=T,R=T+A;S<R;S++){U(o,3*S,h,l),o.needsUpdate=!0;const F=o.distanceToTriangle(m,g,d);if(F<p&&(x.copy(g),b&&b.copy(d),p=F,v=S,y=_),F<a)return!0}}}});{const w=Ut(e);for(let M=0,I=w;M<I;M++){U(m,3*M,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let _=T,P=T+A;_<P;_++){U(o,3*_,h,l),o.needsUpdate=!0;const S=o.distanceToTriangle(m,g,d);if(S<p&&(x.copy(g),b&&b.copy(d),p=S,v=_,y=M),S<a)return!0}}}}}),ie.releasePrimitive(o),ie.releasePrimitive(m),p===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=p,i.faceIndex=v,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(bt),x.applyMatrix4(bt),s.distance=x.sub(s.point).length(),s.faceIndex=y),i)}function cs(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,r,c,l,h=0;const f=n._roots;for(let o=0,m=f.length;o<m;o++)a=f[o],r=new Uint32Array(a),c=new Uint16Array(a),l=new Float32Array(a),u(0,h),h+=a.byteLength;function u(o,m,g=!1){const x=o*2;if(k(x,c)){const d=H(o,r),b=q(x,c);let p=1/0,v=1/0,y=1/0,T=-1/0,A=-1/0,w=-1/0;for(let M=d,I=d+b;M<I;M++){const _=3*n.resolveTriangleIndex(M);for(let P=0;P<3;P++){let S=_+P;S=i?i[S]:S;const R=s.getX(S),F=s.getY(S),D=s.getZ(S);R<p&&(p=R),R>T&&(T=R),F<v&&(v=F),F>A&&(A=F),D<y&&(y=D),D>w&&(w=D)}}return l[o+0]!==p||l[o+1]!==v||l[o+2]!==y||l[o+3]!==T||l[o+4]!==A||l[o+5]!==w?(l[o+0]=p,l[o+1]=v,l[o+2]=y,l[o+3]=T,l[o+4]=A,l[o+5]=w,!0):!1}else{const d=W(o),b=V(o,r);let p=g,v=!1,y=!1;if(e){if(!p){const _=d/O+m/j,P=b/O+m/j;v=e.has(_),y=e.has(P),p=!v&&!y}}else v=!0,y=!0;const T=p||v,A=p||y;let w=!1;T&&(w=u(d,m,p));let M=!1;A&&(M=u(b,m,p));const I=w||M;if(I)for(let _=0;_<3;_++){const P=d+_,S=b+_,R=l[P],F=l[P+3],D=l[S],E=l[S+3];l[o+_]=R<D?R:D,l[o+_+3]=F>E?F:E}return I}}}function ls(n,e,t,i,s,a,r){B.setBuffer(n._roots[e]),re(0,B.float32Array,i,a,r)&&pi(0,n,t,i,s,a,r),B.clearBuffer()}function pi(n,e,t,i,s,a,r){const{float32Array:c,uint16Array:l,uint32Array:h}=B,f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);Qn(e,t,i,o,m,s,a,r)}else{const o=W(n);re(o,c,i,a,r)&&pi(o,e,t,i,s,a,r);const m=V(n,h);re(m,c,i,a,r)&&pi(m,e,t,i,s,a,r)}}const us=["x","y","z"];function fs(n,e,t,i,s,a){B.setBuffer(n._roots[e]);let r=null;return re(0,B.float32Array,i,s,a)&&(r=gi(0,n,t,i,s,a)),B.clearBuffer(),r}function gi(n,e,t,i,s,a){const{float32Array:r,uint16Array:c,uint32Array:l}=B;let h=n*2;if(k(h,c)){const u=H(n,l),o=q(h,c);return Kn(e,t,i,u,o,s,a)}else{const u=kt(n,l),o=us[u],g=i.direction[o]>=0;let x,d;g?(x=W(n),d=V(n,l)):(x=V(n,l),d=W(n));const p=re(x,r,i,s,a)?gi(x,e,t,i,s,a):null;if(p){const T=p.point[o];if(g?T<=r[d+u]:T>=r[d+u+3])return p}const y=re(d,r,i,s,a)?gi(d,e,t,i,s,a):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const Tt=new de,Ve=new ce,qe=new ce,at=new $,ji=new X,wt=new X;function hs(n,e,t,i){B.setBuffer(n._roots[e]);const s=vi(0,n,t,i);return B.clearBuffer(),s}function vi(n,e,t,i,s=null){const{float32Array:a,uint16Array:r,uint32Array:c}=B;let l=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),ji.set(t.boundingBox.min,t.boundingBox.max,i),s=ji),k(l,r)){const f=e.geometry,u=f.index,o=f.attributes.position,m=t.index,g=t.attributes.position,x=H(n,c),d=q(l,r);if(at.copy(i).invert(),t.boundsTree)return z(n,a,wt),wt.matrix.copy(at),wt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:p=>wt.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let v=x,y=d+x;v<y;v++)if(U(qe,3*e.resolveTriangleIndex(v),u,o),qe.needsUpdate=!0,p.intersectsTriangle(qe))return!0;return!1}});{const b=Ut(t);for(let p=x,v=d+x;p<v;p++){const y=e.resolveTriangleIndex(p);U(Ve,3*y,u,o),Ve.a.applyMatrix4(at),Ve.b.applyMatrix4(at),Ve.c.applyMatrix4(at),Ve.needsUpdate=!0;for(let T=0,A=b*3;T<A;T+=3)if(U(qe,T,m,g),qe.needsUpdate=!0,Ve.intersectsTriangle(qe))return!0}}}else{const f=W(n),u=V(n,c);return z(f,a,Tt),!!(s.intersectsBox(Tt)&&vi(f,e,t,i,s)||(z(u,a,Tt),s.intersectsBox(Tt)&&vi(u,e,t,i,s)))}}const St=new $,ti=new X,ot=new X,ds=new C,ms=new C,ps=new C,gs=new C;function vs(n,e,t,i={},s={},a=0,r=1/0){e.boundingBox||e.computeBoundingBox(),ti.set(e.boundingBox.min,e.boundingBox.max,t),ti.needsUpdate=!0;const c=n.geometry,l=c.attributes.position,h=c.index,f=e.attributes.position,u=e.index,o=ie.getPrimitive(),m=ie.getPrimitive();let g=ds,x=ms,d=null,b=null;s&&(d=ps,b=gs);let p=1/0,v=null,y=null;return St.copy(t).invert(),ot.matrix.copy(St),n.shapecast({boundsTraverseOrder:T=>ti.distanceToBox(T),intersectsBounds:(T,A,w)=>w<p&&w<r?(A&&(ot.min.copy(T.min),ot.max.copy(T.max),ot.needsUpdate=!0),!0):!1,intersectsRange:(T,A)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:M=>ot.distanceToBox(M),intersectsBounds:(M,I,_)=>_<p&&_<r,intersectsRange:(M,I)=>{for(let _=M,P=M+I;_<P;_++){const S=w.resolveTriangleIndex(_);U(m,3*S,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=T,F=T+A;R<F;R++){const D=n.resolveTriangleIndex(R);U(o,3*D,h,l),o.needsUpdate=!0;const E=o.distanceToTriangle(m,g,d);if(E<p&&(x.copy(g),b&&b.copy(d),p=E,v=R,y=_),E<a)return!0}}}})}else{const w=Ut(e);for(let M=0,I=w;M<I;M++){U(m,3*M,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let _=T,P=T+A;_<P;_++){const S=n.resolveTriangleIndex(_);U(o,3*S,h,l),o.needsUpdate=!0;const R=o.distanceToTriangle(m,g,d);if(R<p&&(x.copy(g),b&&b.copy(d),p=R,v=_,y=M),R<a)return!0}}}}}),ie.releasePrimitive(o),ie.releasePrimitive(m),p===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=p,i.faceIndex=v,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(St),x.applyMatrix4(St),s.distance=x.sub(s.point).length(),s.faceIndex=y),i)}function Xi(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const _t=new X,At=new Kr,Qi=new C,Ki=new $,Zi=new C,ii=["getX","getY","getZ"];class zt extends On{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,a=e._indirectBuffer,r=i.getIndex(),c={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(c.roots=s.map(l=>l.slice()),c.index=r?r.array.slice():null,c.indirectBuffer=a?a.slice():null):(c.roots=s,c.index=r?r.array:null,c.indirectBuffer=a),c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:a,indirectBuffer:r}=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."),l(a));const c=new zt(t,{...i,[Si]:!0});if(c._roots=a,c._indirectBuffer=r||null,i.setIndex){const h=t.getIndex();if(h===null){const f=new te(e.index,1,!1);t.setIndex(f)}else h.array!==s&&(h.array.set(s),h.needsUpdate=!0)}return c;function l(h){for(let f=0;f<h.length;f++){const u=h[f],o=new Uint32Array(u),m=new Uint16Array(u);for(let g=0,x=u.byteLength/j;g<x;g++){const d=O*g,b=2*d;k(b,m)||(o[d+6]=o[d+6]/O-g)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,i){const s=this.geometry,a=this._indirectBuffer,r=s.attributes.position,c=s.index?s.index.array:null,h=(a?a[e]:e)*3;let f=h+0,u=h+1,o=h+2;c&&(f=c[f],u=c[u],o=c[o]);for(let m=0;m<3;m++){const g=r[ii[m]](f),x=r[ii[m]](u),d=r[ii[m]](o);let b=g;x<b&&(b=x),d<b&&(b=d);let p=g;x>p&&(p=x),d>p&&(p=d),t[i+m]=b,t[i+m+3]=p}return t}computePrimitiveBounds(e,t,i){const s=this.geometry,a=this._indirectBuffer,r=s.attributes.position,c=s.index?s.index.array:null,l=r.normalized;if(e<0||t+e-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const h=r.array,f=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const o=["getX","getY","getZ"],m=i.offset;for(let g=e,x=e+t;g<x;g++){const b=(a?a[g]:g)*3,p=(g-m)*6;let v=b+0,y=b+1,T=b+2;c&&(v=c[v],y=c[y],T=c[T]),l||(v=v*u+f,y=y*u+f,T=T*u+f);for(let A=0;A<3;A++){let w,M,I;l?(w=r[o[A]](v),M=r[o[A]](y),I=r[o[A]](T)):(w=h[v+A],M=h[y+A],I=h[T+A]);let _=w;M<_&&(_=M),I<_&&(_=I);let P=w;M>P&&(P=M),I>P&&(P=I);const S=(P-_)/2,R=A*2;i[p+R+0]=_+S,i[p+R+1]=S+(Math.abs(_)+S)*Dt}}return i}raycastObject3D(e,t,i=[]){const{material:s}=e;if(s===void 0)return;Ki.copy(e.matrixWorld).invert(),At.copy(t.ray).applyMatrix4(Ki),Zi.setFromMatrixScale(e.matrixWorld),Qi.copy(At.direction).multiply(Zi);const a=Qi.length(),r=t.near/a,c=t.far/a;if(t.firstHitOnly===!0){let l=this.raycastFirst(At,s,r,c);l=Xi(l,e,t),l&&i.push(l)}else{const l=this.raycast(At,s,r,c);for(let h=0,f=l.length;h<f;h++){const u=Xi(l[h],e,t);u&&i.push(u)}}return i}refit(e=null){return(this.indirect?cs:Xn)(this,e)}raycast(e,t=oi,i=0,s=1/0){const a=this._roots,r=[],c=this.indirect?ls:Jn;for(let l=0,h=a.length;l<h;l++)c(this,l,t,e,r,i,s);return r}raycastFirst(e,t=oi,i=0,s=1/0){const a=this._roots;let r=null;const c=this.indirect?fs:ts;for(let l=0,h=a.length;l<h;l++){const f=c(this,l,t,e,i,s);f!=null&&(r==null||f.distance<r.distance)&&(r=f)}return r}intersectsGeometry(e,t){let i=!1;const s=this._roots,a=this.indirect?hs:is;for(let r=0,c=s.length;r<c&&(i=a(this,r,e,t),!i);r++);return i}shapecast(e){const t=ie.getPrimitive(),i=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Zn:jn});return ie.releasePrimitive(t),i}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:a}=i;const r=ie.getPrimitive(),c=this.geometry.index,l=this.geometry.attributes.position,h=this.indirect?g=>{const x=this.resolveTriangleIndex(g);U(r,x*3,c,l)}:g=>{U(r,g*3,c,l)},f=ie.getPrimitive(),u=e.geometry.index,o=e.geometry.attributes.position,m=e.indirect?g=>{const x=e.resolveTriangleIndex(g);U(f,x*3,u,o)}:g=>{U(f,g*3,u,o)};if(a){if(!(e instanceof zt))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const g=(x,d,b,p,v,y,T,A)=>{for(let w=b,M=b+p;w<M;w++){m(w),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let I=x,_=x+d;I<_;I++)if(h(I),r.needsUpdate=!0,a(r,f,I,w,v,y,T,A))return!0}return!1};if(s){const x=s;s=function(d,b,p,v,y,T,A,w){return x(d,b,p,v,y,T,A,w)?!0:g(d,b,p,v,y,T,A,w)}}else s=g}return super.bvhcast(e,t,{intersectsRanges:s})}intersectsBox(e,t){return _t.set(e.min,e.max,t),_t.needsUpdate=!0,this.shapecast({intersectsBounds:i=>_t.intersectsBox(i),intersectsTriangle:i=>_t.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},a=0,r=1/0){return(this.indirect?vs:os)(this,e,t,i,s,a,r)}closestPointToPoint(e,t={},i=0,s=1/0){return Vn(this,e,t,i,s)}}function xs(n){switch(n){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function ys(n){switch(n){case 1:return Et;case 2:return Ar;case 3:return L;case 4:return L}}function Ji(n){switch(n){case 1:return en;case 2:return _r;case 3:return li;case 4:return li}}class Dr extends Z{constructor(){super(),this.minFilter=N,this.magFilter=N,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,i=e.itemSize,s=e.count;if(t!==null){if(i*s%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=s*i/t}const a=e.itemSize,r=e.count,c=e.normalized,l=e.array.constructor,h=l.BYTES_PER_ELEMENT;let f=this._forcedType,u=a;if(f===null)switch(l){case Float32Array:f=G;break;case Uint8Array:case Uint16Array:case Uint32Array:f=lt;break;case Int8Array:case Int16Array:case Int32Array:f=qt;break}let o,m,g,x,d=xs(a);switch(f){case G:g=1,m=ys(a),c&&h===1?(x=l,d+="8",l===Uint8Array?o=ci:(o=Di,d+="_SNORM")):(x=Float32Array,d+="32F",o=G);break;case qt:d+=h*8+"I",g=c?Math.pow(2,l.BYTES_PER_ELEMENT*8-1):1,m=Ji(a),h===1?(x=Int8Array,o=Di):h===2?(x=Int16Array,o=Jr):(x=Int32Array,o=qt);break;case lt:d+=h*8+"UI",g=c?Math.pow(2,l.BYTES_PER_ELEMENT*8-1):1,m=Ji(a),h===1?(x=Uint8Array,o=ci):h===2?(x=Uint16Array,o=Zr):(x=Uint32Array,o=lt);break}u===3&&(m===L||m===li)&&(u=4);const b=Math.ceil(Math.sqrt(r))||1,p=u*b*b,v=new x(p),y=e.normalized;e.normalized=!1;for(let T=0;T<r;T++){const A=u*T;v[A]=e.getX(T)/g,a>=2&&(v[A+1]=e.getY(T)/g),a>=3&&(v[A+2]=e.getZ(T)/g,u===4&&(v[A+3]=1)),a>=4&&(v[A+3]=e.getW(T)/g)}e.normalized=y,this.internalFormat=d,this.format=m,this.type=o,this.image.width=b,this.image.height=b,this.image.data=v,this.needsUpdate=!0,this.dispose(),e.itemSize=i,e.count=s}}class Er extends Dr{constructor(){super(),this._forcedType=lt}}class Br extends Dr{constructor(){super(),this._forcedType=G}}class zr{constructor(){this.index=new Er,this.position=new Br,this.bvhBounds=new Z,this.bvhContents=new Z,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(Ts(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const i=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const s=Cr(Ot(t));this._cachedIndexAttr=new te(s,1,!1)}bs(t,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:i,bvhContents:s}=this;e&&e.dispose(),t&&t.dispose(),i&&i.dispose(),s&&s.dispose()}}function bs(n,e,t){const i=t.array,s=n.index?n.index.array:null;for(let a=0,r=e.length;a<r;a++){const c=3*a,l=3*e[a];for(let h=0;h<3;h++)i[c+h]=s?s[l+h]:l+h}}function Ts(n,e,t){const i=n._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const s=i[0],a=new Uint16Array(s),r=new Uint32Array(s),c=new Float32Array(s),l=s.byteLength/j,h=2*Math.ceil(Math.sqrt(l/2)),f=new Float32Array(4*h*h),u=Math.ceil(Math.sqrt(l)),o=new Uint32Array(2*u*u);for(let m=0;m<l;m++){const g=m*j/4,x=g*2,d=g;for(let b=0;b<3;b++)f[8*m+0+b]=c[d+0+b],f[8*m+4+b]=c[d+3+b];if(k(x,a)){const b=q(x,a),p=H(g,r),v=Tn|b;o[m*2+0]=v,o[m*2+1]=p}else{const b=r[g+6],p=kt(g,r);o[m*2+0]=p,o[m*2+1]=b}}e.image.data=f,e.image.width=h,e.image.height=h,e.format=L,e.type=G,e.internalFormat="RGBA32F",e.minFilter=N,e.magFilter=N,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=o,t.image.width=u,t.image.height=u,t.format=_r,t.type=lt,t.internalFormat="RG32UI",t.minFilter=N,t.magFilter=N,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const Nr=`
|
|
1
|
+
import{Box3 as de,Matrix4 as $,BufferAttribute as te,Vector3 as C,Line3 as ge,Plane as br,Vector2 as Y,Triangle as Ye,BackSide as Tr,DoubleSide as wr,REVISION as Sr,Ray as Kr,FrontSide as oi,UnsignedIntType as lt,FloatType as G,DataTexture as Z,NearestFilter as N,IntType as qt,UnsignedByteType as ci,UnsignedShortType as Zr,ByteType as Di,ShortType as Jr,RGBAFormat as L,RGBAIntegerFormat as li,RGIntegerFormat as _r,RedIntegerFormat as en,RGFormat as Ar,RedFormat as Et,BufferGeometry as Ke,Matrix3 as tn,Vector4 as Ze,MeshBasicMaterial as rn,Mesh as nn,ShaderMaterial as Nt,NoBlending as Je,WebGLRenderTarget as Qe,PerspectiveCamera as Mr,DataUtils as K,HalfFloatType as ee,LinearFilter as oe,RepeatWrapping as we,ClampToEdgeWrapping as Se,Source as sn,Quaternion as an,DataArrayTexture as on,WebGLArrayRenderTarget as cn,Color as et,NoToneMapping as ln,NormalBlending as Ir,EquirectangularReflectionMapping as Ti,Spherical as un,LinearMipMapLinearFilter as fn,Clock as hn,Scene as dn,AdditiveBlending as mn,Camera as pn,SpotLight as gn,RectAreaLight as vn,PMREMGenerator as xn,MeshStandardMaterial as yn,TangentSpaceNormalMap as Ei}from"./three.module-Bx43vjkH.js";import{eK as De}from"./remote-8XzEAnAJ.js";import"./index-CKtv7gGE.js";import"./i18n-C9zFX25m.js";import"./api-Dnl2uaKO.js";import"./titleFrameBudget-DsM0V482.js";import"./gltfLoader-U0Eebg7v.js";import"./store-CpqHUcA2.js";import"./rotoMaskStore-pE1AIt3I.js";import"./sceneTrack-DlAH5s74.js";import"./timelineOps-DSSaDsU2.js";import"./cameraTracker-DHdF8Zqx.js";import"./textAnimators-B9vO_hbP.js";import"./timelineComp-i-zdaoB2.js";import"./rigTrack-DMyqb0pb.js";import"./clientJobs-CuuUyhEy.js";const Pr=0,bn=1,Rr=2,Bi=2,Gt=1.25,zi=1,j=32,O=j/4,wi=65535,Tn=wi<<16,Dt=Math.pow(2,-24),Si=Symbol("SKIP_GENERATION"),Fr={strategy:Pr,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Si]:!1};function z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function ui(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const s=n[i+3]-n[i];s>t&&(t=s,e=i)}return e}function Ni(n,e,t){for(let i=0;i<3;i++){const s=e[n+2*i],a=e[n+2*i+1],r=s-a,c=s+a;r<t[i]&&(t[i]=r),c>t[i+3]&&(t[i+3]=c)}}function $t(n){const e=n[3]-n[0],t=n[4]-n[1],i=n[5]-n[2];return 2*(e*t+t*i+i*e)}function k(n,e){return e[n+15]===wi}function H(n,e){return e[n+6]}function q(n,e){return e[n+14]}function W(n){return n+O}function V(n,e){const t=e[n+6];return n+t*O}function kt(n,e){return e[n+7]}function Yt(n,e,t,i,s){let a=1/0,r=1/0,c=1/0,l=-1/0,h=-1/0,f=-1/0,u=1/0,o=1/0,m=1/0,g=-1/0,x=-1/0,d=-1/0;const b=n.offset||0;for(let p=(e-b)*6,v=(e+t-b)*6;p<v;p+=6){const y=n[p+0],T=n[p+1],A=y-T,w=y+T;A<a&&(a=A),w>l&&(l=w),y<u&&(u=y),y>g&&(g=y);const M=n[p+2],I=n[p+3],_=M-I,P=M+I;_<r&&(r=_),P>h&&(h=P),M<o&&(o=M),M>x&&(x=M);const S=n[p+4],R=n[p+5],F=S-R,D=S+R;F<c&&(c=F),D>f&&(f=D),S<m&&(m=S),S>d&&(d=S)}i[0]=a,i[1]=r,i[2]=c,i[3]=l,i[4]=h,i[5]=f,s[0]=u,s[1]=o,s[2]=m,s[3]=g,s[4]=x,s[5]=d}const he=8,_i=8,jt=new Int32Array(he),ue=new Float32Array(he*6),ze=new Float32Array(he*6),ne=new Float32Array(6),ft=new Float32Array(6),ye=new Int32Array(_i),ki=new Float32Array(_i*6);function wn(n,e,t,i){for(let s=0;s<3;s++){const a=e[n+2*s],r=e[n+2*s+1],c=a-r,l=a+r;c<t[i+s]&&(t[i+s]=c),l>t[i+s+3]&&(t[i+s+3]=l)}}function Oi(n,e){const t=n[e+3]-n[e],i=n[e+4]-n[e+1],s=n[e+5]-n[e+2];return 2*(t*i+i*s+s*t)}function Sn(n,e,t,i,s,a){let r=-1,c=0;if(a===Pr)r=ui(e),r!==-1&&(c=(e[r]+e[r+3])/2);else if(a===bn)r=ui(n),r!==-1&&(c=_n(t,i,s,r));else if(a===Rr){const l=$t(n);let h=Gt*s;const f=t.offset||0,u=(i-f)*6,o=(i+s-f)*6;for(let m=0;m<3;m++){const g=e[m],b=(e[m+3]-g)/he;if(s<_i){for(let p=0;p<s;p++){const v=u+p*6,y=t[v+2*m];let T=p;for(;T>0&&t[ye[T-1]+2*m]>y;)ye[T]=ye[T-1],T--;ye[T]=v}for(let p=0;p<3;p++)ne[p]=1/0,ne[p+3]=-1/0,ft[p]=1/0,ft[p+3]=-1/0;for(let p=s-1;p>=0;p--)Ni(ye[p],t,ft),ki.set(ft,p*6);for(let p=0;p<s-1;p++){Ni(ye[p],t,ne);const v=t[ye[p+1]+2*m];if(t[ye[p]+2*m]===v)continue;const y=p+1,T=s-y,A=$t(ne)/l,w=Oi(ki,y*6)/l,M=zi+Gt*(A*y+w*T);M<h&&(r=m,h=M,c=v)}}else{for(let y=0;y<he;y++){jt[y]=0;for(let T=0;T<3;T++)ue[y*6+T]=1/0,ue[y*6+T+3]=-1/0}for(let y=u;y<o;y+=6){let w=~~((t[y+2*m]-g)/b);w>=he&&(w=he-1),jt[w]++,wn(y,t,ue,w*6)}const p=(he-1)*6;for(let y=0;y<6;y++)ze[p+y]=ue[p+y];for(let y=he-2;y>=0;y--){const T=y*6,A=T+6;for(let w=0;w<3;w++)ze[T+w]=Math.min(ue[T+w],ze[A+w]),ze[T+w+3]=Math.max(ue[T+w+3],ze[A+w+3])}let v=0;for(let y=0;y<he-1;y++){const T=y*6,A=jt[y];if(A!==0)for(let P=0;P<3;P++)v===0?(ne[P]=ue[T+P],ne[P+3]=ue[T+P+3]):(ne[P]=Math.min(ne[P],ue[T+P]),ne[P+3]=Math.max(ne[P+3],ue[T+P+3]));v+=A;let w=0,M=0;v!==0&&(w=$t(ne)/l);const I=s-v;I!==0&&(M=Oi(ze,T+6)/l);const _=zi+Gt*(w*v+M*I);_<h&&(r=m,h=_,c=g+b+y*b)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:r,pos:c}}function _n(n,e,t,i){let s=0;const a=n.offset;for(let r=e,c=e+t;r<c;r++)s+=n[(r-a)*6+i*2];return s/t}function An(n,e,t,i,s,a){let r=i,c=i+s-1;const l=a.pos,h=a.axis*2,f=t.offset||0;for(;;){for(;r<=c&&t[(r-f)*6+h]<l;)r++;for(;r<=c&&t[(c-f)*6+h]>=l;)c--;if(r<c){for(let u=0;u<e;u++){let o=n[r*e+u];n[r*e+u]=n[c*e+u],n[c*e+u]=o}for(let u=0;u<6;u++){const o=r-f,m=c-f,g=t[o*6+u];t[o*6+u]=t[m*6+u],t[m*6+u]=g}r++,c--}else return r}}const Mn=Math.pow(2,32),Ne=new Float32Array(6),ht=new Float32Array(6);function In(n,e,t,i,s,a){const{maxDepth:r,verbose:c,targetLeafSize:l,_strictLeafSize:h=1/0,strategy:f,onProgress:u,useSharedArrayBuffer:o=!1}=s,m=n.primitiveBuffer,g=n.primitiveBufferStride,x=o?SharedArrayBuffer:ArrayBuffer,d=new x(j*Math.max(1,2*Math.ceil(i)-1)),b=new Float32Array(d),p=new Uint32Array(d),v=new Uint16Array(d);let y=0,T=!1;return Yt(e,t,i,Ne,ht),M(t,i,0),d.slice(0,y*j);function A(I){u&&u((I-a.offset)/a.count)}function w(I,_,P){const S=I*2;p[I+6]=_,v[S+14]=P,v[S+15]=wi,A(_+P)}function M(I,_,P){const S=y++,R=S*O;b.set(Ne,R),!T&&P>=r&&(T=!0,c&&console.warn(`BVH: Max depth of ${r} reached when generating BVH. Consider increasing maxDepth.`));const F=_>h;if(_<=l&&!F||P>=r){w(R,I,_);return}const D=Sn(Ne,ht,e,I,_,f);let E=D.axis===-1?-1:An(m,g,e,I,_,D);if(D.axis===-1||E===I||E===I+_){if(!F){w(R,I,_);return}D.axis=Math.max(0,ui(Ne)),E=I+Math.max(1,Math.floor(_/2))}p[R+7]=D.axis;const le=E-I;Yt(e,I,le,Ne,ht),M(I,le,P+1);const me=y-S;if(me>Mn)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");p[R+6]=me;const xe=_-le;Yt(e,E,xe,Ne,ht),M(E,xe,P+1)}}function Pn(n,e){const t=n.getRootRanges(e.range),i=t[0],s=t[t.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},r=new Float32Array(6*a.count);r.offset=a.offset,n.computePrimitiveBounds(a.offset,a.count,r),n._roots=t.map(c=>In(n,r,c.offset,c.count,e,a))}class Ai{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 Rn{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const B=new Rn;let Te,Xe;const ke=[],dt=new Ai(()=>new de);function Fn(n,e,t,i,s,a){Te=dt.getPrimitive(),Xe=dt.getPrimitive(),ke.push(Te,Xe),B.setBuffer(n._roots[e]);const r=fi(0,n.geometry,t,i,s,a);B.clearBuffer(),dt.releasePrimitive(Te),dt.releasePrimitive(Xe),ke.pop(),ke.pop();const c=ke.length;return c>0&&(Xe=ke[c-1],Te=ke[c-2]),r}function fi(n,e,t,i,s=null,a=0,r=0){const{float32Array:c,uint16Array:l,uint32Array:h}=B;let f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);return z(n,c,Te),i(o,m,!1,r,a+n/O,Te)}else{let _=function(S){const{uint16Array:R,uint32Array:F}=B;let D=S*2;for(;!k(D,R);)S=W(S),D=S*2;return H(S,F)},P=function(S){const{uint16Array:R,uint32Array:F}=B;let D=S*2;for(;!k(D,R);)S=V(S,F),D=S*2;return H(S,F)+q(D,R)};const o=W(n),m=V(n,h);let g=o,x=m,d,b,p,v;if(s&&(p=Te,v=Xe,z(g,c,p),z(x,c,v),d=s(p),b=s(v),b<d)){g=m,x=o;const S=d;d=b,b=S,p=v}p||(p=Te,z(g,c,p));const y=k(g*2,l),T=t(p,y,d,r+1,a+g/O);let A;if(T===Bi){const S=_(g),F=P(g)-S;A=i(S,F,!0,r+1,a+g/O,p)}else A=T&&fi(g,e,t,i,s,a,r+1);if(A)return!0;v=Xe,z(x,c,v);const w=k(x*2,l),M=t(v,w,b,r+1,a+x/O);let I;if(M===Bi){const S=_(x),F=P(x)-S;I=i(S,F,!0,r+1,a+x/O,v)}else I=M&&fi(x,e,t,i,s,a,r+1);return!!I}}const ut=new B.constructor,Bt=new B.constructor,be=new Ai(()=>new de),Oe=new de,Ue=new de,Xt=new de,Qt=new de;let Kt=!1;function Cn(n,e,t,i){if(Kt)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Kt=!0;const s=n._roots,a=e._roots;let r,c=0,l=0;const h=new $().copy(t).invert();for(let f=0,u=s.length;f<u;f++){ut.setBuffer(s[f]),l=0;const o=be.getPrimitive();z(0,ut.float32Array,o),o.applyMatrix4(h);for(let m=0,g=a.length;m<g&&(Bt.setBuffer(a[m]),r=ae(0,0,t,h,i,c,l,0,0,o),Bt.clearBuffer(),l+=a[m].byteLength/j,!r);m++);if(be.releasePrimitive(o),ut.clearBuffer(),c+=s[f].byteLength/j,r)break}return Kt=!1,r}function ae(n,e,t,i,s,a=0,r=0,c=0,l=0,h=null,f=!1){let u,o;f?(u=Bt,o=ut):(u=ut,o=Bt);const m=u.float32Array,g=u.uint32Array,x=u.uint16Array,d=o.float32Array,b=o.uint32Array,p=o.uint16Array,v=n*2,y=e*2,T=k(v,x),A=k(y,p);let w=!1;if(A&&T)f?w=s(H(e,b),q(e*2,p),H(n,g),q(n*2,x),l,r+e/O,c,a+n/O):w=s(H(n,g),q(n*2,x),H(e,b),q(e*2,p),c,a+n/O,l,r+e/O);else if(A){const M=be.getPrimitive();z(e,d,M),M.applyMatrix4(t);const I=W(n),_=V(n,g);z(I,m,Oe),z(_,m,Ue);const P=M.intersectsBox(Oe),S=M.intersectsBox(Ue);w=P&&ae(e,I,i,t,s,r,a,l,c+1,M,!f)||S&&ae(e,_,i,t,s,r,a,l,c+1,M,!f),be.releasePrimitive(M)}else{const M=W(e),I=V(e,b);z(M,d,Xt),z(I,d,Qt);const _=h.intersectsBox(Xt),P=h.intersectsBox(Qt);if(_&&P)w=ae(n,M,t,i,s,a,r,c,l+1,h,f)||ae(n,I,t,i,s,a,r,c,l+1,h,f);else if(_)if(T)w=ae(n,M,t,i,s,a,r,c,l+1,h,f);else{const S=be.getPrimitive();S.copy(Xt).applyMatrix4(t);const R=W(n),F=V(n,g);z(R,m,Oe),z(F,m,Ue);const D=S.intersectsBox(Oe),E=S.intersectsBox(Ue);w=D&&ae(M,R,i,t,s,r,a,l,c+1,S,!f)||E&&ae(M,F,i,t,s,r,a,l,c+1,S,!f),be.releasePrimitive(S)}else if(P)if(T)w=ae(n,I,t,i,s,a,r,c,l+1,h,f);else{const S=be.getPrimitive();S.copy(Qt).applyMatrix4(t);const R=W(n),F=V(n,g);z(R,m,Oe),z(F,m,Ue);const D=S.intersectsBox(Oe),E=S.intersectsBox(Ue);w=D&&ae(I,R,i,t,s,r,a,l,c+1,S,!f)||E&&ae(I,F,i,t,s,r,a,l,c+1,S,!f),be.releasePrimitive(S)}}return w}const Zt=new class{constructor(){let n=null,e=null,t=null,i=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(a,r)=>{if(i)throw new Error("BVHTraversalHelper: cannot call setBVH during an active traversal.");this.root=r,this.buffer=n=a._roots[r],this.uint16Array=t=new Uint16Array(n),this.uint32Array=e=new Uint32Array(n)},this.reset=()=>{this.root=null,this.buffer=n=null,this.uint16Array=t=null,this.uint32Array=e=null},this.getRangeStart=a=>{let r=a*2;for(;!k(r,t);)a=W(a),r=a*2;return H(a,e)},this.getRangeEnd=a=>{let r=a*2;for(;!k(r,t);)a=V(a,e),r=a*2;return H(a,e)+q(r,t)};const s=(a,r,c)=>{const l=r*2,h=k(l,t);if(!a(c,h,r)&&!h){const u=W(r),o=V(r,e);s(a,u,c+1),s(a,o,c+1)}};this.traverseBuffer=a=>{if(i)throw new Error("BVHTraversalHelper: cannot start a traversal during an active traversal.");i=!0;try{s(a,0,0)}finally{i=!1}},this.traverse=a=>{this.traverseBuffer((r,c,l)=>{if(c){const h=l*2,f=e[l+6],u=t[h+14];return a(r,c,new Float32Array(n,l*4,6),f,u)}else{const h=kt(l,e);return a(r,c,new Float32Array(n,l*4,6),h)}})}}},Ui=new de,Le=new Float32Array(6);class Dn{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Fr,...e},"maxLeafSize"in e&&(console.warn('BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.'),e={...e,targetLeafSize:e.maxLeafSize}),Pn(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,i,s){let a=1/0,r=1/0,c=1/0,l=-1/0,h=-1/0,f=-1/0;for(let u=e,o=e+t;u<o;u++){this.writePrimitiveBounds(u,Le,0);const[m,g,x,d,b,p]=Le;m<a&&(a=m),d>l&&(l=d),g<r&&(r=g),b>h&&(h=b),x<c&&(c=x),p>f&&(f=p)}return i[s+0]=a,i[s+1]=r,i[s+2]=c,i[s+3]=l,i[s+4]=h,i[s+5]=f,i}computePrimitiveBounds(e,t,i){const s=i.offset||0;for(let a=e,r=e+t;a<r;a++){this.writePrimitiveBounds(a,Le,0);const[c,l,h,f,u,o]=Le,m=(c+f)/2,g=(l+u)/2,x=(h+o)/2,d=(f-c)/2,b=(u-l)/2,p=(o-h)/2,v=(a-s)*6;i[v+0]=m,i[v+1]=d+(Math.abs(m)+d)*Dt,i[v+2]=g,i[v+3]=b+(Math.abs(g)+b)*Dt,i[v+4]=x,i[v+5]=p+(Math.abs(x)+p)*Dt}return i}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let i=0,s=t.length;i<s;i++)t[i]+=e;else{const i=this._roots;for(let s=0;s<i.length;s++){const a=i[s],r=new Uint32Array(a),c=new Uint16Array(a),l=a.byteLength/j;for(let h=0;h<l;h++){const f=O*h,u=2*f;k(u,c)&&(r[f+6]+=e)}}}}traverse(e,t=0){Zt.setBVH(this,t),Zt.traverse(e),Zt.reset()}refit(){const e=this._roots;for(let t=0,i=e.length;t<i;t++){const s=e[t],a=new Uint32Array(s),r=new Uint16Array(s),c=new Float32Array(s),l=s.byteLength/j;for(let h=l-1;h>=0;h--){const f=h*O,u=f*2;if(k(u,r)){const m=H(f,a),g=q(u,r);this.writePrimitiveRangeBounds(m,g,Le,0),c.set(Le,f)}else{const m=W(f),g=V(f,a);for(let x=0;x<3;x++){const d=c[m+x],b=c[m+x+3],p=c[g+x],v=c[g+x+3];c[f+x]=d<p?d:p,c[f+x+3]=b>v?b:v}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{z(0,new Float32Array(i),Ui),e.union(Ui)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:i,intersectsRange:s,intersectsPrimitive:a,scratchPrimitive:r,iterate:c}=e;if(s&&a){const u=s;s=(o,m,g,x,d)=>u(o,m,g,x,d)?!0:c(o,m,this,a,g,x,r)}else s||(a?s=(u,o,m,g)=>c(u,o,this,a,m,g,r):s=(u,o,m)=>m);let l=!1,h=0;const f=this._roots;for(let u=0,o=f.length;u<o;u++){const m=f[u];if(l=Fn(this,u,i,s,t,h),l)break;h+=m.byteLength/j}return l}bvhcast(e,t,i){let{intersectsRanges:s}=i;return Cn(this,e,t,s)}}function En(){return typeof SharedArrayBuffer<"u"}function Ot(n){return n.index?n.index.count:n.attributes.position.count}function Ut(n){return Ot(n)/3}function Cr(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Bn(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,s=Cr(t,i);n.setIndex(new te(s,1));for(let a=0;a<t;a++)s[a]=a}}function zn(n,e,t){const i=Ot(n)/t,s=e||n.drawRange,a=s.start/t,r=(s.start+s.count)/t,c=Math.max(0,a),l=Math.min(i,r)-c;return{offset:Math.floor(c),count:Math.floor(l)}}function Nn(n,e){return n.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function Li(n,e,t){const i=zn(n,e,t),s=Nn(n,t);if(!s.length)return[i];const a=[],r=i.offset,c=i.offset+i.count,l=Ot(n)/t,h=[];for(const o of s){const{offset:m,count:g}=o,x=m,d=isFinite(g)?g:l-m,b=m+d;x<c&&b>r&&(h.push({pos:Math.max(r,x),isStart:!0}),h.push({pos:Math.min(c,b),isStart:!1}))}h.sort((o,m)=>o.pos!==m.pos?o.pos-m.pos:o.type==="end"?-1:1);let f=0,u=null;for(const o of h){const m=o.pos;f!==0&&m!==u&&a.push({offset:u,count:m-u}),f+=o.isStart?1:-1,u=m}return a}function kn(n,e){const t=n[n.length-1],i=t.offset+t.count>2**16,s=n.reduce((h,f)=>h+f.count,0),a=i?4:2,r=e?new SharedArrayBuffer(s*a):new ArrayBuffer(s*a),c=i?new Uint32Array(r):new Uint16Array(r);let l=0;for(let h=0;h<n.length;h++){const{offset:f,count:u}=n[h];for(let o=0;o<u;o++)c[l+o]=f+o;l+=u}return c}class On extends Dn{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&&!En())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...Fr,...t},t[Si]||this.init(t)}init(e){const{geometry:t,primitiveStride:i}=this;if(e.indirect){const s=Li(t,e.range,i),a=kn(s,e.useSharedArrayBuffer);this._indirectBuffer=a}else Bn(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new de))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Li(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class ve{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,s=-1/0;for(let a=0,r=e.length;a<r;a++){const l=e[a][t];i=l<i?l:i,s=l>s?l:s}this.min=i,this.max=s}setFromPoints(e,t){let i=1/0,s=-1/0;for(let a=0,r=t.length;a<r;a++){const c=t[a],l=e.dot(c);i=l<i?l:i,s=l>s?l:s}this.min=i,this.max=s}isSeparated(e){return this.min>e.max||e.min>this.max}}ve.prototype.setFromBox=(function(){const n=new C;return function(t,i){const s=i.min,a=i.max;let r=1/0,c=-1/0;for(let l=0;l<=1;l++)for(let h=0;h<=1;h++)for(let f=0;f<=1;f++){n.x=s.x*l+a.x*(1-l),n.y=s.y*h+a.y*(1-h),n.z=s.z*f+a.z*(1-f);const u=t.dot(n);r=Math.min(u,r),c=Math.max(u,c)}this.min=r,this.max=c}})();const Un=(function(){const n=new C,e=new C,t=new C;return function(s,a,r){const c=s.start,l=n,h=a.start,f=e;t.subVectors(c,h),n.subVectors(s.end,s.start),e.subVectors(a.end,a.start);const u=t.dot(f),o=f.dot(l),m=f.dot(f),g=t.dot(l),d=l.dot(l)*m-o*o;let b,p;d!==0?b=(u*o-g*m)/d:b=0,p=(u+b*o)/m,r.x=b,r.y=p}})(),Mi=(function(){const n=new Y,e=new C,t=new C;return function(s,a,r,c){Un(s,a,n);let l=n.x,h=n.y;if(l>=0&&l<=1&&h>=0&&h<=1){s.at(l,r),a.at(h,c);return}else if(l>=0&&l<=1){h<0?a.at(0,c):a.at(1,c),s.closestPointToPoint(c,!0,r);return}else if(h>=0&&h<=1){l<0?s.at(0,r):s.at(1,r),a.closestPointToPoint(r,!0,c);return}else{let f;l<0?f=s.start:f=s.end;let u;h<0?u=a.start:u=a.end;const o=e,m=t;if(s.closestPointToPoint(u,!0,e),a.closestPointToPoint(f,!0,t),o.distanceToSquared(u)<=m.distanceToSquared(f)){r.copy(o),c.copy(u);return}else{r.copy(f),c.copy(m);return}}}})(),Ln=(function(){const n=new C,e=new C,t=new br,i=new ge;return function(a,r){const{radius:c,center:l}=a,{a:h,b:f,c:u}=r;if(i.start=h,i.end=f,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c||(i.start=h,i.end=u,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c)||(i.start=f,i.end=u,i.closestPointToPoint(l,!0,n).distanceTo(l)<=c))return!0;const x=r.getPlane(t);if(Math.abs(x.distanceToPoint(l))<=c){const b=x.projectPoint(l,e);if(r.containsPoint(b))return!0}return!1}})(),Hn=["x","y","z"],pe=1e-15,Hi=pe*pe;function J(n){return Math.abs(n)<pe}class ce extends Ye{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new C),this.satBounds=new Array(4).fill().map(()=>new ve),this.points=[this.a,this.b,this.c],this.plane=new br,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new ge,this.needsUpdate=!0}intersectsSphere(e){return Ln(e,this)}update(){const e=this.a,t=this.b,i=this.c,s=this.points,a=this.satAxes,r=this.satBounds,c=a[0],l=r[0];this.getNormal(c),l.setFromPoints(c,s);const h=a[1],f=r[1];h.subVectors(e,t),f.setFromPoints(h,s);const u=a[2],o=r[2];u.subVectors(t,i),o.setFromPoints(u,s);const m=a[3],g=r[3];m.subVectors(i,e),g.setFromPoints(m,s);const x=h.length(),d=u.length(),b=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,x<pe?d<pe||b<pe?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(i)):d<pe?b<pe?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):b<pe&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(i),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(c,e),this.needsUpdate=!1}}ce.prototype.closestPointToSegment=(function(){const n=new C,e=new C,t=new ge;return function(s,a=null,r=null){this.needsUpdate&&this.update();const{start:c,end:l}=s,h=this.points;let f,u=1/0;const o=this.plane.distanceToPoint(c),m=this.plane.distanceToPoint(l);if(o*m<0&&this.plane.intersectLine(s,n)!==null&&this.containsPoint(n))return a&&a.copy(n),r&&r.copy(n),0;for(let g=0;g<3;g++){const x=(g+1)%3;t.start.copy(h[g]),t.end.copy(h[x]),Mi(t,s,n,e),f=n.distanceToSquared(e),f<u&&(u=f,a&&a.copy(n),r&&r.copy(e))}return this.closestPointToPoint(c,n),f=c.distanceToSquared(n),f<u&&(u=f,a&&a.copy(n),r&&r.copy(c)),this.closestPointToPoint(l,n),f=l.distanceToSquared(n),f<u&&(u=f,a&&a.copy(n),r&&r.copy(l)),Math.sqrt(u)}})();ce.prototype.intersectsTriangle=(function(){const n=new ce,e=new ve,t=new ve,i=new C,s=new C,a=new C,r=new C,c=new ge,l=new ge,h=new C,f=new Y,u=new Y;function o(v,y,T,A){const w=i;!v.isDegenerateIntoPoint&&!v.isDegenerateIntoSegment?w.copy(v.plane.normal):w.copy(y.plane.normal);const M=v.satBounds,I=v.satAxes;for(let S=1;S<4;S++){const R=M[S],F=I[S];if(e.setFromPoints(F,y.points),R.isSeparated(e)||(r.copy(w).cross(F),e.setFromPoints(r,v.points),t.setFromPoints(r,y.points),e.isSeparated(t)))return!1}const _=y.satBounds,P=y.satAxes;for(let S=1;S<4;S++){const R=_[S],F=P[S];if(e.setFromPoints(F,v.points),R.isSeparated(e)||(r.crossVectors(w,F),e.setFromPoints(r,v.points),t.setFromPoints(r,y.points),e.isSeparated(t)))return!1}return T&&(A||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),T.start.set(0,0,0),T.end.set(0,0,0)),!0}function m(v,y,T,A,w,M,I,_,P,S,R){let F=I/(I-_);S.x=A+(w-A)*F,R.start.subVectors(y,v).multiplyScalar(F).add(v),F=I/(I-P),S.y=A+(M-A)*F,R.end.subVectors(T,v).multiplyScalar(F).add(v)}function g(v,y,T,A,w,M,I,_,P,S,R){if(w>0)m(v.c,v.a,v.b,A,y,T,P,I,_,S,R);else if(M>0)m(v.b,v.a,v.c,T,y,A,_,I,P,S,R);else if(_*P>0||I!=0)m(v.a,v.b,v.c,y,T,A,I,_,P,S,R);else if(_!=0)m(v.b,v.a,v.c,T,y,A,_,I,P,S,R);else if(P!=0)m(v.c,v.a,v.b,A,y,T,P,I,_,S,R);else return!0;return!1}function x(v,y,T,A){const w=y.degenerateSegment,M=v.plane.distanceToPoint(w.start),I=v.plane.distanceToPoint(w.end);return J(M)?J(I)?o(v,y,T,A):(T&&(T.start.copy(w.start),T.end.copy(w.start)),v.containsPoint(w.start)):J(I)?(T&&(T.start.copy(w.end),T.end.copy(w.end)),v.containsPoint(w.end)):v.plane.intersectLine(w,i)!=null?(T&&(T.start.copy(i),T.end.copy(i)),v.containsPoint(i)):!1}function d(v,y,T){const A=y.a;return J(v.plane.distanceToPoint(A))&&v.containsPoint(A)?(T&&(T.start.copy(A),T.end.copy(A)),!0):!1}function b(v,y,T){const A=v.degenerateSegment,w=y.a;return A.closestPointToPoint(w,!0,i),w.distanceToSquared(i)<Hi?(T&&(T.start.copy(w),T.end.copy(w)),!0):!1}function p(v,y,T,A){if(v.isDegenerateIntoSegment)if(y.isDegenerateIntoSegment){const w=v.degenerateSegment,M=y.degenerateSegment,I=s,_=a;w.delta(I),M.delta(_);const P=i.subVectors(M.start,w.start),S=I.x*_.y-I.y*_.x;if(J(S))return!1;const R=(P.x*_.y-P.y*_.x)/S,F=-(I.x*P.y-I.y*P.x)/S;if(R<0||R>1||F<0||F>1)return!1;const D=w.start.z+I.z*R,E=M.start.z+_.z*F;return J(D-E)?(T&&(T.start.copy(w.start).addScaledVector(I,R),T.end.copy(w.start).addScaledVector(I,R)),!0):!1}else return y.isDegenerateIntoPoint?b(v,y,T):x(y,v,T,A);else{if(v.isDegenerateIntoPoint)return y.isDegenerateIntoPoint?y.a.distanceToSquared(v.a)<Hi?(T&&(T.start.copy(v.a),T.end.copy(v.a)),!0):!1:y.isDegenerateIntoSegment?b(y,v,T):d(y,v,T);if(y.isDegenerateIntoPoint)return d(v,y,T);if(y.isDegenerateIntoSegment)return x(v,y,T,A)}}return function(y,T=null,A=!1){this.needsUpdate&&this.update(),y.isExtendedTriangle?y.needsUpdate&&y.update():(n.copy(y),n.update(),y=n);const w=p(this,y,T,A);if(w!==void 0)return w;const M=this.plane,I=y.plane;let _=I.distanceToPoint(this.a),P=I.distanceToPoint(this.b),S=I.distanceToPoint(this.c);J(_)&&(_=0),J(P)&&(P=0),J(S)&&(S=0);const R=_*P,F=_*S;if(R>0&&F>0)return!1;let D=M.distanceToPoint(y.a),E=M.distanceToPoint(y.b),le=M.distanceToPoint(y.c);J(D)&&(D=0),J(E)&&(E=0),J(le)&&(le=0);const me=D*E,xe=D*le;if(me>0&&xe>0)return!1;s.copy(M.normal),a.copy(I.normal);const Ee=s.cross(a);let _e=0,Wt=Math.abs(Ee.x);const Ci=Math.abs(Ee.y);Ci>Wt&&(Wt=Ci,_e=1),Math.abs(Ee.z)>Wt&&(_e=2);const Be=Hn[_e],Gr=this.a[Be],$r=this.b[Be],Yr=this.c[Be],jr=y.a[Be],Xr=y.b[Be],Qr=y.c[Be];if(g(this,Gr,$r,Yr,R,F,_,P,S,f,c))return o(this,y,T,A);if(g(y,jr,Xr,Qr,me,xe,D,E,le,u,l))return o(this,y,T,A);if(f.y<f.x){const Vt=f.y;f.y=f.x,f.x=Vt,h.copy(c.start),c.start.copy(c.end),c.end.copy(h)}if(u.y<u.x){const Vt=u.y;u.y=u.x,u.x=Vt,h.copy(l.start),l.start.copy(l.end),l.end.copy(h)}return f.y<u.x||u.y<f.x?!1:(T&&(u.x>f.x?T.start.copy(l.start):T.start.copy(c.start),u.y<f.y?T.end.copy(l.end):T.end.copy(c.end)),!0)}})();ce.prototype.distanceToPoint=(function(){const n=new C;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();ce.prototype.distanceToTriangle=(function(){const n=new C,e=new C,t=["a","b","c"],i=new ge,s=new ge;return function(r,c=null,l=null){const h=c||l?i:null;if(this.intersectsTriangle(r,h,!0))return(c||l)&&(c&&h.getCenter(c),l&&h.getCenter(l)),0;let f=1/0;for(let u=0;u<3;u++){let o;const m=t[u],g=r[m];this.closestPointToPoint(g,n),o=g.distanceToSquared(n),o<f&&(f=o,c&&c.copy(n),l&&l.copy(g));const x=this[m];r.closestPointToPoint(x,n),o=x.distanceToSquared(n),o<f&&(f=o,c&&c.copy(x),l&&l.copy(n))}for(let u=0;u<3;u++){const o=t[u],m=t[(u+1)%3];i.set(this[o],this[m]);for(let g=0;g<3;g++){const x=t[g],d=t[(g+1)%3];s.set(r[x],r[d]),Mi(i,s,n,e);const b=n.distanceToSquared(e);b<f&&(f=b,c&&c.copy(n),l&&l.copy(e))}}return Math.sqrt(f)}})();class X{constructor(e,t,i){this.isOrientedBox=!0,this.min=new C,this.max=new C,this.matrix=new $,this.invMatrix=new $,this.points=new Array(8).fill().map(()=>new C),this.satAxes=new Array(3).fill().map(()=>new C),this.satBounds=new Array(3).fill().map(()=>new ve),this.alignedSatBounds=new Array(3).fill().map(()=>new ve),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}X.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,i=this.max,s=this.points;for(let h=0;h<=1;h++)for(let f=0;f<=1;f++)for(let u=0;u<=1;u++){const o=1*h|2*f|4*u,m=s[o];m.x=h?i.x:t.x,m.y=f?i.y:t.y,m.z=u?i.z:t.z,m.applyMatrix4(e)}const a=this.satBounds,r=this.satAxes,c=s[0];for(let h=0;h<3;h++){const f=r[h],u=a[h],o=1<<h,m=s[o];f.subVectors(c,m),u.setFromPoints(f,s)}const l=this.alignedSatBounds;l[0].setFromPointsField(s,"x"),l[1].setFromPointsField(s,"y"),l[2].setFromPointsField(s,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();X.prototype.intersectsBox=(function(){const n=new ve;return function(t){this.needsUpdate&&this.update();const i=t.min,s=t.max,a=this.satBounds,r=this.satAxes,c=this.alignedSatBounds;if(n.min=i.x,n.max=s.x,c[0].isSeparated(n)||(n.min=i.y,n.max=s.y,c[1].isSeparated(n))||(n.min=i.z,n.max=s.z,c[2].isSeparated(n)))return!1;for(let l=0;l<3;l++){const h=r[l],f=a[l];if(n.setFromBox(h,t),f.isSeparated(n))return!1}return!0}})();X.prototype.intersectsTriangle=(function(){const n=new ce,e=new Array(3),t=new ve,i=new ve,s=new C;return function(r){this.needsUpdate&&this.update(),r.isExtendedTriangle?r.needsUpdate&&r.update():(n.copy(r),n.update(),r=n);const c=this.satBounds,l=this.satAxes;e[0]=r.a,e[1]=r.b,e[2]=r.c;for(let o=0;o<3;o++){const m=c[o],g=l[o];if(t.setFromPoints(g,e),m.isSeparated(t))return!1}const h=r.satBounds,f=r.satAxes,u=this.points;for(let o=0;o<3;o++){const m=h[o],g=f[o];if(t.setFromPoints(g,u),m.isSeparated(t))return!1}for(let o=0;o<3;o++){const m=l[o];for(let g=0;g<4;g++){const x=f[g];if(s.crossVectors(m,x),t.setFromPoints(s,e),i.setFromPoints(s,u),t.isSeparated(i))return!1}}return!0}})();X.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();X.prototype.distanceToPoint=(function(){const n=new C;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();X.prototype.distanceToBox=(function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ge),t=new Array(12).fill().map(()=>new ge),i=new C,s=new C;return function(r,c=0,l=null,h=null){if(this.needsUpdate&&this.update(),this.intersectsBox(r))return(l||h)&&(r.getCenter(s),this.closestPointToPoint(s,i),r.closestPointToPoint(i,s),l&&l.copy(i),h&&h.copy(s)),0;const f=c*c,u=r.min,o=r.max,m=this.points;let g=1/0;for(let d=0;d<8;d++){const b=m[d];s.copy(b).clamp(u,o);const p=b.distanceToSquared(s);if(p<g&&(g=p,l&&l.copy(b),h&&h.copy(s),p<f))return Math.sqrt(p)}let x=0;for(let d=0;d<3;d++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){const v=(d+1)%3,y=(d+2)%3,T=b<<v|p<<y,A=1<<d|b<<v|p<<y,w=m[T],M=m[A];e[x].set(w,M);const _=n[d],P=n[v],S=n[y],R=t[x],F=R.start,D=R.end;F[_]=u[_],F[P]=b?u[P]:o[P],F[S]=p?u[S]:o[S],D[_]=o[_],D[P]=b?u[P]:o[P],D[S]=p?u[S]:o[S],x++}for(let d=0;d<=1;d++)for(let b=0;b<=1;b++)for(let p=0;p<=1;p++){s.x=d?o.x:u.x,s.y=b?o.y:u.y,s.z=p?o.z:u.z,this.closestPointToPoint(s,i);const v=s.distanceToSquared(i);if(v<g&&(g=v,l&&l.copy(i),h&&h.copy(s),v<f))return Math.sqrt(v)}for(let d=0;d<12;d++){const b=e[d];for(let p=0;p<12;p++){const v=t[p];Mi(b,v,i,s);const y=i.distanceToSquared(s);if(y<g&&(g=y,l&&l.copy(i),h&&h.copy(s),y<f))return Math.sqrt(y)}}return Math.sqrt(g)}})();class Wn extends Ai{constructor(){super(()=>new ce)}}const ie=new Wn,it=new C,Jt=new C;function Vn(n,e,t={},i=0,s=1/0){const a=i*i,r=s*s;let c=1/0,l=null;if(n.shapecast({boundsTraverseOrder:f=>(it.copy(e).clamp(f.min,f.max),it.distanceToSquared(e)),intersectsBounds:(f,u,o)=>o<c&&o<r,intersectsTriangle:(f,u)=>{f.closestPointToPoint(e,it);const o=e.distanceToSquared(it);return o<c&&(Jt.copy(it),c=o,l=u),o<a}}),c===1/0)return null;const h=Math.sqrt(c);return t.point?t.point.copy(Jt):t.point=Jt.clone(),t.distance=h,t.faceIndex=l,t}const mt=parseInt(Sr)>=169,qn=parseInt(Sr)<=161,Ae=new C,Me=new C,Ie=new C,pt=new Y,gt=new Y,vt=new Y,Wi=new C,Vi=new C,qi=new C,rt=new C;function Gn(n,e,t,i,s,a,r,c){let l;if(a===Tr?l=n.intersectTriangle(i,t,e,!0,s):l=n.intersectTriangle(e,t,i,a!==wr,s),l===null)return null;const h=n.origin.distanceTo(s);return h<r||h>c?null:{distance:h,point:s.clone()}}function Gi(n,e,t,i,s,a,r,c,l,h,f){Ae.fromBufferAttribute(e,a),Me.fromBufferAttribute(e,r),Ie.fromBufferAttribute(e,c);const u=Gn(n,Ae,Me,Ie,rt,l,h,f);if(u){if(i){pt.fromBufferAttribute(i,a),gt.fromBufferAttribute(i,r),vt.fromBufferAttribute(i,c),u.uv=new Y;const m=Ye.getInterpolation(rt,Ae,Me,Ie,pt,gt,vt,u.uv);mt||(u.uv=m)}if(s){pt.fromBufferAttribute(s,a),gt.fromBufferAttribute(s,r),vt.fromBufferAttribute(s,c),u.uv1=new Y;const m=Ye.getInterpolation(rt,Ae,Me,Ie,pt,gt,vt,u.uv1);mt||(u.uv1=m),qn&&(u.uv2=u.uv1)}if(t){Wi.fromBufferAttribute(t,a),Vi.fromBufferAttribute(t,r),qi.fromBufferAttribute(t,c),u.normal=new C;const m=Ye.getInterpolation(rt,Ae,Me,Ie,Wi,Vi,qi,u.normal);u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1),mt||(u.normal=m)}const o={a,b:r,c,normal:new C,materialIndex:0};if(Ye.getNormal(Ae,Me,Ie,o.normal),u.face=o,u.faceIndex=a,mt){const m=new C;Ye.getBarycoord(rt,Ae,Me,Ie,m),u.barycoord=m}}return u}function $i(n){return n&&n.isMaterial?n.side:n}function Lt(n,e,t,i,s,a,r){const c=i*3;let l=c+0,h=c+1,f=c+2;const{index:u,groups:o}=n;n.index&&(l=u.getX(l),h=u.getX(h),f=u.getX(f));const{position:m,normal:g,uv:x,uv1:d}=n.attributes;if(Array.isArray(e)){const b=i*3;for(let p=0,v=o.length;p<v;p++){const{start:y,count:T,materialIndex:A}=o[p];if(b>=y&&b<y+T){const w=$i(e[A]),M=Gi(t,m,g,x,d,l,h,f,w,a,r);if(M)if(M.faceIndex=i,M.face.materialIndex=A,s)s.push(M);else return M}}}else{const b=$i(e),p=Gi(t,m,g,x,d,l,h,f,b,a,r);if(p)if(p.faceIndex=i,p.face.materialIndex=0,s)s.push(p);else return p}return null}function U(n,e,t,i){const s=n.a,a=n.b,r=n.c;let c=e,l=e+1,h=e+2;t&&(c=t.getX(c),l=t.getX(l),h=t.getX(h)),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l),r.x=i.getX(h),r.y=i.getY(h),r.z=i.getZ(h)}function $n(n,e,t,i,s,a,r,c){const{geometry:l,_indirectBuffer:h}=n;for(let f=i,u=i+s;f<u;f++)Lt(l,e,t,f,a,r,c)}function Yn(n,e,t,i,s,a,r){const{geometry:c,_indirectBuffer:l}=n;let h=1/0,f=null;for(let u=i,o=i+s;u<o;u++){let m;m=Lt(c,e,t,u,null,a,r),m&&m.distance<h&&(f=m,h=m.distance)}return f}function jn(n,e,t,i,s,a,r){const{geometry:c}=t,{index:l}=c,h=c.attributes.position;for(let f=n,u=e+n;f<u;f++){let o;if(o=f,U(r,o*3,l,h),r.needsUpdate=!0,i(r,o,s,a))return!0}return!1}function Xn(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,r,c,l,h=0;const f=n._roots;for(let o=0,m=f.length;o<m;o++)a=f[o],r=new Uint32Array(a),c=new Uint16Array(a),l=new Float32Array(a),u(0,h),h+=a.byteLength;function u(o,m,g=!1){const x=o*2;if(k(x,c)){const d=H(o,r),b=q(x,c);let p=1/0,v=1/0,y=1/0,T=-1/0,A=-1/0,w=-1/0;for(let M=3*d,I=3*(d+b);M<I;M++){let _=i[M];const P=s.getX(_),S=s.getY(_),R=s.getZ(_);P<p&&(p=P),P>T&&(T=P),S<v&&(v=S),S>A&&(A=S),R<y&&(y=R),R>w&&(w=R)}return l[o+0]!==p||l[o+1]!==v||l[o+2]!==y||l[o+3]!==T||l[o+4]!==A||l[o+5]!==w?(l[o+0]=p,l[o+1]=v,l[o+2]=y,l[o+3]=T,l[o+4]=A,l[o+5]=w,!0):!1}else{const d=W(o),b=V(o,r);let p=g,v=!1,y=!1;if(e){if(!p){const _=d/O+m/j,P=b/O+m/j;v=e.has(_),y=e.has(P),p=!v&&!y}}else v=!0,y=!0;const T=p||v,A=p||y;let w=!1;T&&(w=u(d,m,p));let M=!1;A&&(M=u(b,m,p));const I=w||M;if(I)for(let _=0;_<3;_++){const P=d+_,S=b+_,R=l[P],F=l[P+3],D=l[S],E=l[S+3];l[o+_]=R<D?R:D,l[o+_+3]=F>E?F:E}return I}}}function re(n,e,t,i,s){let a,r,c,l,h,f;const u=1/t.direction.x,o=1/t.direction.y,m=1/t.direction.z,g=t.origin.x,x=t.origin.y,d=t.origin.z;let b=e[n],p=e[n+3],v=e[n+1],y=e[n+3+1],T=e[n+2],A=e[n+3+2];return u>=0?(a=(b-g)*u,r=(p-g)*u):(a=(p-g)*u,r=(b-g)*u),o>=0?(c=(v-x)*o,l=(y-x)*o):(c=(y-x)*o,l=(v-x)*o),a>l||c>r||((c>a||isNaN(a))&&(a=c),(l<r||isNaN(r))&&(r=l),m>=0?(h=(T-d)*m,f=(A-d)*m):(h=(A-d)*m,f=(T-d)*m),a>f||h>r)?!1:((h>a||a!==a)&&(a=h),(f<r||r!==r)&&(r=f),a<=s&&r>=i)}function Qn(n,e,t,i,s,a,r,c){const{geometry:l,_indirectBuffer:h}=n;for(let f=i,u=i+s;f<u;f++){let o=h?h[f]:f;Lt(l,e,t,o,a,r,c)}}function Kn(n,e,t,i,s,a,r){const{geometry:c,_indirectBuffer:l}=n;let h=1/0,f=null;for(let u=i,o=i+s;u<o;u++){let m;m=Lt(c,e,t,l?l[u]:u,null,a,r),m&&m.distance<h&&(f=m,h=m.distance)}return f}function Zn(n,e,t,i,s,a,r){const{geometry:c}=t,{index:l}=c,h=c.attributes.position;for(let f=n,u=e+n;f<u;f++){let o;if(o=t.resolveTriangleIndex(f),U(r,o*3,l,h),r.needsUpdate=!0,i(r,o,s,a))return!0}return!1}function Jn(n,e,t,i,s,a,r){B.setBuffer(n._roots[e]),re(0,B.float32Array,i,a,r)&&hi(0,n,t,i,s,a,r),B.clearBuffer()}function hi(n,e,t,i,s,a,r){const{float32Array:c,uint16Array:l,uint32Array:h}=B,f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);$n(e,t,i,o,m,s,a,r)}else{const o=W(n);re(o,c,i,a,r)&&hi(o,e,t,i,s,a,r);const m=V(n,h);re(m,c,i,a,r)&&hi(m,e,t,i,s,a,r)}}const es=["x","y","z"];function ts(n,e,t,i,s,a){B.setBuffer(n._roots[e]);let r=null;return re(0,B.float32Array,i,s,a)&&(r=di(0,n,t,i,s,a)),B.clearBuffer(),r}function di(n,e,t,i,s,a){const{float32Array:r,uint16Array:c,uint32Array:l}=B;let h=n*2;if(k(h,c)){const u=H(n,l),o=q(h,c);return Yn(e,t,i,u,o,s,a)}else{const u=kt(n,l),o=es[u],g=i.direction[o]>=0;let x,d;g?(x=W(n),d=V(n,l)):(x=V(n,l),d=W(n));const p=re(x,r,i,s,a)?di(x,e,t,i,s,a):null;if(p){const T=p.point[o];if(g?T<=r[d+u]:T>=r[d+u+3])return p}const y=re(d,r,i,s,a)?di(d,e,t,i,s,a):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const xt=new de,He=new ce,We=new ce,nt=new $,Yi=new X,yt=new X;function is(n,e,t,i){B.setBuffer(n._roots[e]);const s=mi(0,n,t,i);return B.clearBuffer(),s}function mi(n,e,t,i,s=null){const{float32Array:a,uint16Array:r,uint32Array:c}=B;let l=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),Yi.set(t.boundingBox.min,t.boundingBox.max,i),s=Yi),k(l,r)){const f=e.geometry,u=f.index,o=f.attributes.position,m=t.index,g=t.attributes.position,x=H(n,c),d=q(l,r);if(nt.copy(i).invert(),t.boundsTree)return z(n,a,yt),yt.matrix.copy(nt),yt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:p=>yt.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let v=x*3,y=(d+x)*3;v<y;v+=3)if(U(We,v,u,o),We.needsUpdate=!0,p.intersectsTriangle(We))return!0;return!1}});{const b=Ut(t);for(let p=x*3,v=(d+x)*3;p<v;p+=3){U(He,p,u,o),He.a.applyMatrix4(nt),He.b.applyMatrix4(nt),He.c.applyMatrix4(nt),He.needsUpdate=!0;for(let y=0,T=b*3;y<T;y+=3)if(U(We,y,m,g),We.needsUpdate=!0,He.intersectsTriangle(We))return!0}}}else{const f=W(n),u=V(n,c);return z(f,a,xt),!!(s.intersectsBox(xt)&&mi(f,e,t,i,s)||(z(u,a,xt),s.intersectsBox(xt)&&mi(u,e,t,i,s)))}}const bt=new $,ei=new X,st=new X,rs=new C,ns=new C,ss=new C,as=new C;function os(n,e,t,i={},s={},a=0,r=1/0){e.boundingBox||e.computeBoundingBox(),ei.set(e.boundingBox.min,e.boundingBox.max,t),ei.needsUpdate=!0;const c=n.geometry,l=c.attributes.position,h=c.index,f=e.attributes.position,u=e.index,o=ie.getPrimitive(),m=ie.getPrimitive();let g=rs,x=ns,d=null,b=null;s&&(d=ss,b=as);let p=1/0,v=null,y=null;return bt.copy(t).invert(),st.matrix.copy(bt),n.shapecast({boundsTraverseOrder:T=>ei.distanceToBox(T),intersectsBounds:(T,A,w)=>w<p&&w<r?(A&&(st.min.copy(T.min),st.max.copy(T.max),st.needsUpdate=!0),!0):!1,intersectsRange:(T,A)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:M=>st.distanceToBox(M),intersectsBounds:(M,I,_)=>_<p&&_<r,intersectsRange:(M,I)=>{for(let _=M,P=M+I;_<P;_++){U(m,3*_,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let S=T,R=T+A;S<R;S++){U(o,3*S,h,l),o.needsUpdate=!0;const F=o.distanceToTriangle(m,g,d);if(F<p&&(x.copy(g),b&&b.copy(d),p=F,v=S,y=_),F<a)return!0}}}});{const w=Ut(e);for(let M=0,I=w;M<I;M++){U(m,3*M,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let _=T,P=T+A;_<P;_++){U(o,3*_,h,l),o.needsUpdate=!0;const S=o.distanceToTriangle(m,g,d);if(S<p&&(x.copy(g),b&&b.copy(d),p=S,v=_,y=M),S<a)return!0}}}}}),ie.releasePrimitive(o),ie.releasePrimitive(m),p===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=p,i.faceIndex=v,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(bt),x.applyMatrix4(bt),s.distance=x.sub(s.point).length(),s.faceIndex=y),i)}function cs(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,s=t.attributes.position;let a,r,c,l,h=0;const f=n._roots;for(let o=0,m=f.length;o<m;o++)a=f[o],r=new Uint32Array(a),c=new Uint16Array(a),l=new Float32Array(a),u(0,h),h+=a.byteLength;function u(o,m,g=!1){const x=o*2;if(k(x,c)){const d=H(o,r),b=q(x,c);let p=1/0,v=1/0,y=1/0,T=-1/0,A=-1/0,w=-1/0;for(let M=d,I=d+b;M<I;M++){const _=3*n.resolveTriangleIndex(M);for(let P=0;P<3;P++){let S=_+P;S=i?i[S]:S;const R=s.getX(S),F=s.getY(S),D=s.getZ(S);R<p&&(p=R),R>T&&(T=R),F<v&&(v=F),F>A&&(A=F),D<y&&(y=D),D>w&&(w=D)}}return l[o+0]!==p||l[o+1]!==v||l[o+2]!==y||l[o+3]!==T||l[o+4]!==A||l[o+5]!==w?(l[o+0]=p,l[o+1]=v,l[o+2]=y,l[o+3]=T,l[o+4]=A,l[o+5]=w,!0):!1}else{const d=W(o),b=V(o,r);let p=g,v=!1,y=!1;if(e){if(!p){const _=d/O+m/j,P=b/O+m/j;v=e.has(_),y=e.has(P),p=!v&&!y}}else v=!0,y=!0;const T=p||v,A=p||y;let w=!1;T&&(w=u(d,m,p));let M=!1;A&&(M=u(b,m,p));const I=w||M;if(I)for(let _=0;_<3;_++){const P=d+_,S=b+_,R=l[P],F=l[P+3],D=l[S],E=l[S+3];l[o+_]=R<D?R:D,l[o+_+3]=F>E?F:E}return I}}}function ls(n,e,t,i,s,a,r){B.setBuffer(n._roots[e]),re(0,B.float32Array,i,a,r)&&pi(0,n,t,i,s,a,r),B.clearBuffer()}function pi(n,e,t,i,s,a,r){const{float32Array:c,uint16Array:l,uint32Array:h}=B,f=n*2;if(k(f,l)){const o=H(n,h),m=q(f,l);Qn(e,t,i,o,m,s,a,r)}else{const o=W(n);re(o,c,i,a,r)&&pi(o,e,t,i,s,a,r);const m=V(n,h);re(m,c,i,a,r)&&pi(m,e,t,i,s,a,r)}}const us=["x","y","z"];function fs(n,e,t,i,s,a){B.setBuffer(n._roots[e]);let r=null;return re(0,B.float32Array,i,s,a)&&(r=gi(0,n,t,i,s,a)),B.clearBuffer(),r}function gi(n,e,t,i,s,a){const{float32Array:r,uint16Array:c,uint32Array:l}=B;let h=n*2;if(k(h,c)){const u=H(n,l),o=q(h,c);return Kn(e,t,i,u,o,s,a)}else{const u=kt(n,l),o=us[u],g=i.direction[o]>=0;let x,d;g?(x=W(n),d=V(n,l)):(x=V(n,l),d=W(n));const p=re(x,r,i,s,a)?gi(x,e,t,i,s,a):null;if(p){const T=p.point[o];if(g?T<=r[d+u]:T>=r[d+u+3])return p}const y=re(d,r,i,s,a)?gi(d,e,t,i,s,a):null;return p&&y?p.distance<=y.distance?p:y:p||y||null}}const Tt=new de,Ve=new ce,qe=new ce,at=new $,ji=new X,wt=new X;function hs(n,e,t,i){B.setBuffer(n._roots[e]);const s=vi(0,n,t,i);return B.clearBuffer(),s}function vi(n,e,t,i,s=null){const{float32Array:a,uint16Array:r,uint32Array:c}=B;let l=n*2;if(s===null&&(t.boundingBox||t.computeBoundingBox(),ji.set(t.boundingBox.min,t.boundingBox.max,i),s=ji),k(l,r)){const f=e.geometry,u=f.index,o=f.attributes.position,m=t.index,g=t.attributes.position,x=H(n,c),d=q(l,r);if(at.copy(i).invert(),t.boundsTree)return z(n,a,wt),wt.matrix.copy(at),wt.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:p=>wt.intersectsBox(p),intersectsTriangle:p=>{p.a.applyMatrix4(i),p.b.applyMatrix4(i),p.c.applyMatrix4(i),p.needsUpdate=!0;for(let v=x,y=d+x;v<y;v++)if(U(qe,3*e.resolveTriangleIndex(v),u,o),qe.needsUpdate=!0,p.intersectsTriangle(qe))return!0;return!1}});{const b=Ut(t);for(let p=x,v=d+x;p<v;p++){const y=e.resolveTriangleIndex(p);U(Ve,3*y,u,o),Ve.a.applyMatrix4(at),Ve.b.applyMatrix4(at),Ve.c.applyMatrix4(at),Ve.needsUpdate=!0;for(let T=0,A=b*3;T<A;T+=3)if(U(qe,T,m,g),qe.needsUpdate=!0,Ve.intersectsTriangle(qe))return!0}}}else{const f=W(n),u=V(n,c);return z(f,a,Tt),!!(s.intersectsBox(Tt)&&vi(f,e,t,i,s)||(z(u,a,Tt),s.intersectsBox(Tt)&&vi(u,e,t,i,s)))}}const St=new $,ti=new X,ot=new X,ds=new C,ms=new C,ps=new C,gs=new C;function vs(n,e,t,i={},s={},a=0,r=1/0){e.boundingBox||e.computeBoundingBox(),ti.set(e.boundingBox.min,e.boundingBox.max,t),ti.needsUpdate=!0;const c=n.geometry,l=c.attributes.position,h=c.index,f=e.attributes.position,u=e.index,o=ie.getPrimitive(),m=ie.getPrimitive();let g=ds,x=ms,d=null,b=null;s&&(d=ps,b=gs);let p=1/0,v=null,y=null;return St.copy(t).invert(),ot.matrix.copy(St),n.shapecast({boundsTraverseOrder:T=>ti.distanceToBox(T),intersectsBounds:(T,A,w)=>w<p&&w<r?(A&&(ot.min.copy(T.min),ot.max.copy(T.max),ot.needsUpdate=!0),!0):!1,intersectsRange:(T,A)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:M=>ot.distanceToBox(M),intersectsBounds:(M,I,_)=>_<p&&_<r,intersectsRange:(M,I)=>{for(let _=M,P=M+I;_<P;_++){const S=w.resolveTriangleIndex(_);U(m,3*S,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=T,F=T+A;R<F;R++){const D=n.resolveTriangleIndex(R);U(o,3*D,h,l),o.needsUpdate=!0;const E=o.distanceToTriangle(m,g,d);if(E<p&&(x.copy(g),b&&b.copy(d),p=E,v=R,y=_),E<a)return!0}}}})}else{const w=Ut(e);for(let M=0,I=w;M<I;M++){U(m,3*M,u,f),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let _=T,P=T+A;_<P;_++){const S=n.resolveTriangleIndex(_);U(o,3*S,h,l),o.needsUpdate=!0;const R=o.distanceToTriangle(m,g,d);if(R<p&&(x.copy(g),b&&b.copy(d),p=R,v=_,y=M),R<a)return!0}}}}}),ie.releasePrimitive(o),ie.releasePrimitive(m),p===1/0?null:(i.point?i.point.copy(x):i.point=x.clone(),i.distance=p,i.faceIndex=v,s&&(s.point?s.point.copy(b):s.point=b.clone(),s.point.applyMatrix4(St),x.applyMatrix4(St),s.distance=x.sub(s.point).length(),s.faceIndex=y),i)}function Xi(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const _t=new X,At=new Kr,Qi=new C,Ki=new $,Zi=new C,ii=["getX","getY","getZ"];class zt extends On{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,s=e._roots,a=e._indirectBuffer,r=i.getIndex(),c={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(c.roots=s.map(l=>l.slice()),c.index=r?r.array.slice():null,c.indirectBuffer=a?a.slice():null):(c.roots=s,c.index=r?r.array:null,c.indirectBuffer=a),c}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:s,roots:a,indirectBuffer:r}=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."),l(a));const c=new zt(t,{...i,[Si]:!0});if(c._roots=a,c._indirectBuffer=r||null,i.setIndex){const h=t.getIndex();if(h===null){const f=new te(e.index,1,!1);t.setIndex(f)}else h.array!==s&&(h.array.set(s),h.needsUpdate=!0)}return c;function l(h){for(let f=0;f<h.length;f++){const u=h[f],o=new Uint32Array(u),m=new Uint16Array(u);for(let g=0,x=u.byteLength/j;g<x;g++){const d=O*g,b=2*d;k(b,m)||(o[d+6]=o[d+6]/O-g)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use "targetLeafSize", instead.'),t={...t,targetLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,i){const s=this.geometry,a=this._indirectBuffer,r=s.attributes.position,c=s.index?s.index.array:null,h=(a?a[e]:e)*3;let f=h+0,u=h+1,o=h+2;c&&(f=c[f],u=c[u],o=c[o]);for(let m=0;m<3;m++){const g=r[ii[m]](f),x=r[ii[m]](u),d=r[ii[m]](o);let b=g;x<b&&(b=x),d<b&&(b=d);let p=g;x>p&&(p=x),d>p&&(p=d),t[i+m]=b,t[i+m+3]=p}return t}computePrimitiveBounds(e,t,i){const s=this.geometry,a=this._indirectBuffer,r=s.attributes.position,c=s.index?s.index.array:null,l=r.normalized;if(e<0||t+e-i.offset>i.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const h=r.array,f=r.offset||0;let u=3;r.isInterleavedBufferAttribute&&(u=r.data.stride);const o=["getX","getY","getZ"],m=i.offset;for(let g=e,x=e+t;g<x;g++){const b=(a?a[g]:g)*3,p=(g-m)*6;let v=b+0,y=b+1,T=b+2;c&&(v=c[v],y=c[y],T=c[T]),l||(v=v*u+f,y=y*u+f,T=T*u+f);for(let A=0;A<3;A++){let w,M,I;l?(w=r[o[A]](v),M=r[o[A]](y),I=r[o[A]](T)):(w=h[v+A],M=h[y+A],I=h[T+A]);let _=w;M<_&&(_=M),I<_&&(_=I);let P=w;M>P&&(P=M),I>P&&(P=I);const S=(P-_)/2,R=A*2;i[p+R+0]=_+S,i[p+R+1]=S+(Math.abs(_)+S)*Dt}}return i}raycastObject3D(e,t,i=[]){const{material:s}=e;if(s===void 0)return;Ki.copy(e.matrixWorld).invert(),At.copy(t.ray).applyMatrix4(Ki),Zi.setFromMatrixScale(e.matrixWorld),Qi.copy(At.direction).multiply(Zi);const a=Qi.length(),r=t.near/a,c=t.far/a;if(t.firstHitOnly===!0){let l=this.raycastFirst(At,s,r,c);l=Xi(l,e,t),l&&i.push(l)}else{const l=this.raycast(At,s,r,c);for(let h=0,f=l.length;h<f;h++){const u=Xi(l[h],e,t);u&&i.push(u)}}return i}refit(e=null){return(this.indirect?cs:Xn)(this,e)}raycast(e,t=oi,i=0,s=1/0){const a=this._roots,r=[],c=this.indirect?ls:Jn;for(let l=0,h=a.length;l<h;l++)c(this,l,t,e,r,i,s);return r}raycastFirst(e,t=oi,i=0,s=1/0){const a=this._roots;let r=null;const c=this.indirect?fs:ts;for(let l=0,h=a.length;l<h;l++){const f=c(this,l,t,e,i,s);f!=null&&(r==null||f.distance<r.distance)&&(r=f)}return r}intersectsGeometry(e,t){let i=!1;const s=this._roots,a=this.indirect?hs:is;for(let r=0,c=s.length;r<c&&(i=a(this,r,e,t),!i);r++);return i}shapecast(e){const t=ie.getPrimitive(),i=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Zn:jn});return ie.releasePrimitive(t),i}bvhcast(e,t,i){let{intersectsRanges:s,intersectsTriangles:a}=i;const r=ie.getPrimitive(),c=this.geometry.index,l=this.geometry.attributes.position,h=this.indirect?g=>{const x=this.resolveTriangleIndex(g);U(r,x*3,c,l)}:g=>{U(r,g*3,c,l)},f=ie.getPrimitive(),u=e.geometry.index,o=e.geometry.attributes.position,m=e.indirect?g=>{const x=e.resolveTriangleIndex(g);U(f,x*3,u,o)}:g=>{U(f,g*3,u,o)};if(a){if(!(e instanceof zt))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const g=(x,d,b,p,v,y,T,A)=>{for(let w=b,M=b+p;w<M;w++){m(w),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let I=x,_=x+d;I<_;I++)if(h(I),r.needsUpdate=!0,a(r,f,I,w,v,y,T,A))return!0}return!1};if(s){const x=s;s=function(d,b,p,v,y,T,A,w){return x(d,b,p,v,y,T,A,w)?!0:g(d,b,p,v,y,T,A,w)}}else s=g}return super.bvhcast(e,t,{intersectsRanges:s})}intersectsBox(e,t){return _t.set(e.min,e.max,t),_t.needsUpdate=!0,this.shapecast({intersectsBounds:i=>_t.intersectsBox(i),intersectsTriangle:i=>_t.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},s={},a=0,r=1/0){return(this.indirect?vs:os)(this,e,t,i,s,a,r)}closestPointToPoint(e,t={},i=0,s=1/0){return Vn(this,e,t,i,s)}}function xs(n){switch(n){case 1:return"R";case 2:return"RG";case 3:return"RGBA";case 4:return"RGBA"}throw new Error}function ys(n){switch(n){case 1:return Et;case 2:return Ar;case 3:return L;case 4:return L}}function Ji(n){switch(n){case 1:return en;case 2:return _r;case 3:return li;case 4:return li}}class Dr extends Z{constructor(){super(),this.minFilter=N,this.magFilter=N,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){const t=this.overrideItemSize,i=e.itemSize,s=e.count;if(t!==null){if(i*s%t!==0)throw new Error("VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.");e.itemSize=t,e.count=s*i/t}const a=e.itemSize,r=e.count,c=e.normalized,l=e.array.constructor,h=l.BYTES_PER_ELEMENT;let f=this._forcedType,u=a;if(f===null)switch(l){case Float32Array:f=G;break;case Uint8Array:case Uint16Array:case Uint32Array:f=lt;break;case Int8Array:case Int16Array:case Int32Array:f=qt;break}let o,m,g,x,d=xs(a);switch(f){case G:g=1,m=ys(a),c&&h===1?(x=l,d+="8",l===Uint8Array?o=ci:(o=Di,d+="_SNORM")):(x=Float32Array,d+="32F",o=G);break;case qt:d+=h*8+"I",g=c?Math.pow(2,l.BYTES_PER_ELEMENT*8-1):1,m=Ji(a),h===1?(x=Int8Array,o=Di):h===2?(x=Int16Array,o=Jr):(x=Int32Array,o=qt);break;case lt:d+=h*8+"UI",g=c?Math.pow(2,l.BYTES_PER_ELEMENT*8-1):1,m=Ji(a),h===1?(x=Uint8Array,o=ci):h===2?(x=Uint16Array,o=Zr):(x=Uint32Array,o=lt);break}u===3&&(m===L||m===li)&&(u=4);const b=Math.ceil(Math.sqrt(r))||1,p=u*b*b,v=new x(p),y=e.normalized;e.normalized=!1;for(let T=0;T<r;T++){const A=u*T;v[A]=e.getX(T)/g,a>=2&&(v[A+1]=e.getY(T)/g),a>=3&&(v[A+2]=e.getZ(T)/g,u===4&&(v[A+3]=1)),a>=4&&(v[A+3]=e.getW(T)/g)}e.normalized=y,this.internalFormat=d,this.format=m,this.type=o,this.image.width=b,this.image.height=b,this.image.data=v,this.needsUpdate=!0,this.dispose(),e.itemSize=i,e.count=s}}class Er extends Dr{constructor(){super(),this._forcedType=lt}}class Br extends Dr{constructor(){super(),this._forcedType=G}}class zr{constructor(){this.index=new Er,this.position=new Br,this.bvhBounds=new Z,this.bvhContents=new Z,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){const{geometry:t}=e;if(Ts(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){const i=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==i.length)if(t.index)this._cachedIndexAttr=t.index.clone();else{const s=Cr(Ot(t));this._cachedIndexAttr=new te(s,1,!1)}bs(t,i,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){const{index:e,position:t,bvhBounds:i,bvhContents:s}=this;e&&e.dispose(),t&&t.dispose(),i&&i.dispose(),s&&s.dispose()}}function bs(n,e,t){const i=t.array,s=n.index?n.index.array:null;for(let a=0,r=e.length;a<r;a++){const c=3*a,l=3*e[a];for(let h=0;h<3;h++)i[c+h]=s?s[l+h]:l+h}}function Ts(n,e,t){const i=n._roots;if(i.length!==1)throw new Error("MeshBVHUniformStruct: Multi-root BVHs not supported.");const s=i[0],a=new Uint16Array(s),r=new Uint32Array(s),c=new Float32Array(s),l=s.byteLength/j,h=2*Math.ceil(Math.sqrt(l/2)),f=new Float32Array(4*h*h),u=Math.ceil(Math.sqrt(l)),o=new Uint32Array(2*u*u);for(let m=0;m<l;m++){const g=m*j/4,x=g*2,d=g;for(let b=0;b<3;b++)f[8*m+0+b]=c[d+0+b],f[8*m+4+b]=c[d+3+b];if(k(x,a)){const b=q(x,a),p=H(g,r),v=Tn|b;o[m*2+0]=v,o[m*2+1]=p}else{const b=r[g+6],p=kt(g,r);o[m*2+0]=p,o[m*2+1]=b}}e.image.data=f,e.image.width=h,e.image.height=h,e.format=L,e.type=G,e.internalFormat="RGBA32F",e.minFilter=N,e.magFilter=N,e.generateMipmaps=!1,e.needsUpdate=!0,e.dispose(),t.image.data=o,t.image.width=u,t.image.height=u,t.format=_r,t.type=lt,t.internalFormat="RG32UI",t.minFilter=N,t.magFilter=N,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose()}const Nr=`
|
|
2
2
|
|
|
3
3
|
// A stack of uint32 indices can can store the indices for
|
|
4
4
|
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/rotoMaskStore-pE1AIt3I.js","assets/titleFrameBudget-DsM0V482.js","assets/sceneTrack-DlAH5s74.js","assets/api-Dnl2uaKO.js","assets/i18n-C9zFX25m.js","assets/index-CKtv7gGE.js","assets/timeline3dExport-Uo0S0CR0.js","assets/timeline3d-DrFaMPPB.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/frameSink-CSRqCnwI.js","assets/titleFrames-C8kvflgT.js","assets/titleArt-CnC0A7x7.js","assets/textAnimators-B9vO_hbP.js","assets/lottieLayer-Cv8ub9f6.js","assets/rigTrack-DMyqb0pb.js","assets/rotoMatte-7b7Ow64f.js","assets/store-CpqHUcA2.js","assets/windowFrames-DhhJLIs-.js","assets/gpuExport-oA2mUsdm.js","assets/glTransitionSources.generated-q0H-ZbnZ.js","assets/timelineComp-i-zdaoB2.js","assets/gpuCompose-B5bgbHdQ.js","assets/motionBlur-uAm030t9.js","assets/distortGL-vhnBRB59.js","assets/id3-arvEpAg7.js","assets/output-p-Q7qous.js","assets/clientExport-pkLbOmEF.js","assets/distortFrames-D_v-aSVO.js","assets/engine-Co-ivzlQ.js","assets/store-Cug4GGcP.js","assets/conversion-4rhF3xRJ.js","assets/pendingMatte-BWBIWajI.js","assets/timelineOps-DSSaDsU2.js","assets/cameraTracker-DHdF8Zqx.js","assets/clientJobs-CuuUyhEy.js","assets/personHq-Ca351o06.js","assets/matteQuality-9X-jgJrH.js","assets/surfacePin-CzpUj1Cw.js","assets/sceneTrack-CA21MCOP.js","assets/surfaceLight-C7YI9SV8.js","assets/clientJobs-CcsLDqFM.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as w,b_ as I,iF as O}from"./titleFrameBudget-DsM0V482.js";import{FrameSink as R,SKIPPED_FRAME as F}from"./frameSink-CSRqCnwI.js";class $ extends R{want;next=new Map;last=new Map;out={};constructor(c){super({put:async()=>{throw Error("a pick sink keeps its frames")}}),this.want=new Map;for(const[u,a]of Object.entries(c))for(const[s,r]of Object.entries(a||{}))this.want.set(`${u}
|
|
3
|
+
${s}`,new Set(r));this.wants=(u,a,s)=>{const r=this.want.get(`${u}
|
|
4
|
+
${a}`);return!!r&&(s===void 0||r.has(s))}}async push(c,u,a){const s=`${c}
|
|
5
|
+
${u}`,r=this.next.get(s)??0;if(this.next.set(s,r+1),a===F)return;const n=a==="="?this.last.get(s):a;n!==void 0&&(this.last.set(s,n),this.want.get(s)?.has(r)&&(((this.out[c]??={})[u]??={})[r]=n))}picked(){return this.out}}const b=(o,c)=>Object.keys(o[c]||{}).length>0,D={async frames({clips:o,format:c,camera:u=null,want:a}){const{unpackMasks:s}=await w(async()=>{const{unpackMasks:e}=await import("./rotoMaskStore-pE1AIt3I.js");return{unpackMasks:e}},__vite__mapDeps([0,1,2,3,4,5])),r=await s(o);o=r.clips;const n=new $(a),_={},k=I(c).fps,l=n.wants,p=async(e,m,h)=>{for(const y of m){n.wants=(E,v,d)=>E===e&&v===y&&l(E,v,d);try{await h()}catch(E){_[y]=String(E?.message||E).slice(0,200)}finally{n.wants=l}}},t=e=>Object.keys(a[e]||{});if(b(a,"modelFrames")){const{render3DFrames:e}=await w(async()=>{const{render3DFrames:m}=await import("./timeline3dExport-Uo0S0CR0.js");return{render3DFrames:m}},__vite__mapDeps([6,1,7,8,9,3,4,5,10,11]));await p("modelFrames",t("modelFrames"),()=>e(o,c,n,void 0,u))}if(b(a,"titleFrames")){const{renderTitleFrames:e}=await w(async()=>{const{renderTitleFrames:h}=await import("./titleFrames-C8kvflgT.js");return{renderTitleFrames:h}},__vite__mapDeps([12,1,13,14,15,16,4,5,3,11])),m=[...o,...O(o)];await p("titleFrames",t("titleFrames"),()=>e(m,c,n,void 0,u))}if(b(a,"matteFrames")){const e=await w(()=>import("./rotoMatte-7b7Ow64f.js").then(h=>h.r),__vite__mapDeps([17,1,3,4,5,18])),m=[...o,...e.maskedCopies(o)];await p("matteFrames",t("matteFrames"),()=>e.renderMatteFrames(m,k,n))}if(b(a,"windowFrames")){const e=await w(()=>import("./windowFrames-DhhJLIs-.js"),__vite__mapDeps([19,1,17,3,4,5,18]));await p("windowFrames",t("windowFrames"),()=>e.renderWindowFrames(o,k,n))}return{frames:n.picked(),failed:_,missingMasks:r.missing}},async gpuExport({clips:o,format:c,tracks:u={},camera:a=null,encode:s=null,range:r,only:n,name:_="film.mp4",softwareEncoder:k=!1}){const{unpackMasks:l}=await w(async()=>{const{unpackMasks:i}=await import("./rotoMaskStore-pE1AIt3I.js");return{unpackMasks:i}},__vite__mapDeps([0,1,2,3,4,5])),p=await l(o);if(p.missing)throw Object.assign(new Error(`${p.missing} stored Roto mask(s) / track(s) could not be read`),{name:"MissingMasks"});o=p.clips;const t=await w(()=>import("./gpuExport-oA2mUsdm.js"),__vite__mapDeps([20,1,21,3,4,5,22,23,24,25,26,27]));if(k){if(n!=="video"||!await t.canEncodeH264(c))throw Object.assign(new Error("no H.264 encoder in this browser"),{name:"NoEncoder"})}else if(!await t.gpuExportSupported(c,s))throw Object.assign(new Error("no hardware video encoder in this browser"),{name:"NoEncoder"});const{softwareRetry:e}=await w(async()=>{const{softwareRetry:i}=await import("./clientExport-pkLbOmEF.js");return{softwareRetry:i}},__vite__mapDeps([28,1,22])),m=i=>{try{window.__clipooxProgress?.(i)}catch{}};let h=k;const y=`/__clipoox/out/${encodeURIComponent(_)}`,E=()=>new WritableStream({async write(i){const g=await fetch(`${y}?at=${i.position}`,{method:"PATCH",body:i.data});if(!g.ok)throw new Error(`the film could not be handed over (${g.status})`)}}),v=i=>t.exportOnGpu(o,{format:c,encode:s,tracks:u,camera:a,onProgress:m,software:i,liveMotion:!0,range:r,only:n,sink:E()}),d=i=>{const g=i instanceof Error?`${i.name}: ${i.message}`:String(i);return new Error(`${t.gpuExportStage()||"start"}${r?` (frames ${r.from}–${r.to})`:""}: ${g}`)},f=await v(k).catch(i=>{if(!e(i,t.gpuExportStage(),s))throw d(i);return h=!0,v(!0).catch(g=>{throw d(g)})});let P="";try{const i=document.createElement("canvas").getContext("webgl2"),g=i?.getExtension("WEBGL_debug_renderer_info");P=String(g&&i?i.getParameter(g.UNMASKED_RENDERER_WEBGL):"").slice(0,120)}catch{}return{ms:f.ms,software:h,gpu:P}},async distort({clips:o,format:c,tracks:u={}}){const{unpackMasks:a}=await w(async()=>{const{unpackMasks:t}=await import("./rotoMaskStore-pE1AIt3I.js");return{unpackMasks:t}},__vite__mapDeps([0,1,2,3,4,5])),s=await a(o);if(s.missing)throw Object.assign(new Error(`${s.missing} stored Roto mask(s) / track(s) could not be read`),{name:"MissingMasks"});let r=0;const n=async t=>{const e=`chunk-${r++}.json`,m=await fetch(`/__clipoox/chunk/${e}`,{method:"POST",body:JSON.stringify(t)});if(!m.ok)throw new Error(`the frames could not be handed over (${m.status})`);return e},{FrameSink:_}=await w(async()=>{const{FrameSink:t}=await import("./frameSink-CSRqCnwI.js");return{FrameSink:t}},__vite__mapDeps([11,1])),{distortForServer:k}=await w(async()=>{const{distortForServer:t}=await import("./distortFrames-D_v-aSVO.js");return{distortForServer:t}},__vite__mapDeps([29,1,25,26])),l=new _({put:n,inlineLimit:0}),p=await k(s.clips,c,l,void 0,u);return{clips:p.clips,tracks:p.tracks,frames:await l.finish()}},async upscale({url:o,kind:c,scale:u=2,model:a="photo",name:s="upscaled.bin"}){const r=await w(()=>import("./engine-Co-ivzlQ.js"),__vite__mapDeps([30,1,31,26,27,32])),n=t=>{try{window.__clipooxProgress?.(t.fraction)}catch{}},_=c==="video"?await r.upscaleVideo(o,{model:a,onProgress:n}):await r.upscaleImage(o,{scale:u,model:a,onProgress:n}),k=`/__clipoox/out/${encodeURIComponent(s)}`,l=new Uint8Array(await _.blob.arrayBuffer()),p=8<<20;for(let t=0;t<l.length;t+=p){const e=await fetch(`${k}?at=${t}`,{method:"PATCH",body:l.subarray(t,Math.min(l.length,t+p))});if(!e.ok)throw new Error(`the file could not be handed over (${e.status})`)}return{width:_.width,height:_.height,duration:_.duration??null,type:_.blob.type,bytes:l.length,backend:_.backend,seconds:_.seconds,soundDropped:!!_.soundDropped}},async runClientJobs({clips:o,format:c,tracks:u={},camera:a=null,only:s}){const[{useStore:r},{unpackMasks:n,packMasks:_},{runPendingMattes:k},{runSurfacePins:l},{runPendingClientJobs:p}]=await Promise.all([w(()=>import("./store-CpqHUcA2.js").then(d=>d.d),__vite__mapDeps([18,1,5])),w(()=>import("./rotoMaskStore-pE1AIt3I.js"),__vite__mapDeps([0,1,2,3,4,5])),w(()=>import("./pendingMatte-BWBIWajI.js"),__vite__mapDeps([33,1,34,2,35,14,22,3,4,5,18,16,36,37,38])),w(()=>import("./surfacePin-CzpUj1Cw.js"),__vite__mapDeps([39,1,40,2,4,5,35,14,38,41,18])),w(()=>import("./clientJobs-CcsLDqFM.js"),__vite__mapDeps([42,1,5,18,4,3,36]))]),t=await n(o);r.setState({clips:t.clips,timelineFormat:c,timelineTracks:u,timelineCamera:a??void 0});const e=d=>!s?.length||s.includes(d),m=[],h=d=>{try{window.__clipooxProgress?.(d)}catch{}};if(h(.05),e("person-matte")||e("object-matte")||e("person-matte-hq")){const d=await k();for(const f of d)m.push({kind:"person-matte",clipId:f.clipId,ok:f.ok,message:f.message})}if(h(.4),e("surface-track")){const d=await l();for(const f of d)m.push({kind:"surface-track",clipId:f.clipId,ok:f.ok,message:f.message})}h(.7);const y=await p({only:s});for(const d of y)m.push({kind:d.kind,clipId:d.clipId,ok:d.ok,message:d.error||"done"});h(.95);const E=r.getState(),v=await _(E.clips);return h(1),{clips:v,timelineTracks:E.timelineTracks,timelineCamera:E.timelineCamera??null,results:m}}};window.__layerWorker=D;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{d6 as f}from"./remote-8XzEAnAJ.js";import{eM as h,e9 as k,eN as q,eO as v}from"./remote-8XzEAnAJ.js";import{e as l}from"./skin-xFScwS3T.js";import"./index-CKtv7gGE.js";import"./i18n-C9zFX25m.js";import"./api-Dnl2uaKO.js";import"./titleFrameBudget-DsM0V482.js";import"./three.module-Bx43vjkH.js";import"./gltfLoader-U0Eebg7v.js";import"./store-CpqHUcA2.js";import"./rotoMaskStore-pE1AIt3I.js";import"./sceneTrack-DlAH5s74.js";import"./timelineOps-DSSaDsU2.js";import"./cameraTracker-DHdF8Zqx.js";import"./textAnimators-B9vO_hbP.js";import"./timelineComp-i-zdaoB2.js";import"./rigTrack-DMyqb0pb.js";import"./clientJobs-CuuUyhEy.js";async function P(o,m,s,n=2e4){let i;for(const e=Date.now()+n;!i&&Date.now()<e;){const r=o.getStage().items.find(t=>t.id===m);if(!r||r.rig!==s)return!1;i=o.engine()?.objects?.children.find(t=>t.userData.id===m)?.children[0],i||await new Promise(t=>setTimeout(t,150))}if(!i)return!1;const p=f(s,{positions:l(i).positions});let a=!1;return o.setStage(e=>({...e,items:e.items.map(r=>r.id===m&&r.rig===s?(a=!0,{...r,rig:p}):r)})),a}export{P as fitLibraryFingers,h as libraryModelFields,k as libraryModelItem,q as libraryRig,v as wantsFingers};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DxdDhmLR.js","assets/index-CKtv7gGE.js","assets/opentype.module-DcKU8U04.js","assets/gltfLoader-U0Eebg7v.js","assets/three.module-Bx43vjkH.js","assets/lottie_light_canvas-DX9Wf-DS.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{ht as Dt,jp as Bt,jq as Nt,jr as pn,js as Ft,jt as mn,ju as gn,N as yn,jv as wn,jw as bn,jx as Mn,_ as U,jy as _n,hs as kn,jz as Sn,jA as An,jB as En,jC as ft,jD as xn,fL as tt,gk as Tn,fN as nt,gl as vn,fl as V,ge as ct,gm as On,ct as Ce,jE as Ln,g9 as rt,jF as Pn,ga as Gt,gn as jn,jG as $n,jH as Cn,jI as Rn,jJ as In,jK as Dn,jL as Bn,jM as Nn,jN as Ht,jO as Fn,jP as Gn,jQ as Hn,bt as zn,bD as Wn,jR as qn,jS as fe,jT as Un,jU as Kn,jV as Vn,jW as Jn,jX as Yn,jY as ce,jZ as Re,j_ as ht,j$ as Xn,k0 as Zn,bz as Qn,k1 as er,k2 as ut,k3 as tr,k4 as nr,gc as rr,cD as sr,f8 as or,gb as zt,b$ as ar,gN as ir,dX as oe,ih as lr,eB as fr,f6 as cr,cw as we,dY as Ie,dZ as dt,k5 as hr,k6 as W,hr as ur,k7 as dr}from"./titleFrameBudget-
|
|
2
|
+
import{ht as Dt,jp as Bt,jq as Nt,jr as pn,js as Ft,jt as mn,ju as gn,N as yn,jv as wn,jw as bn,jx as Mn,_ as U,jy as _n,hs as kn,jz as Sn,jA as An,jB as En,jC as ft,jD as xn,fL as tt,gk as Tn,fN as nt,gl as vn,fl as V,ge as ct,gm as On,ct as Ce,jE as Ln,g9 as rt,jF as Pn,ga as Gt,gn as jn,jG as $n,jH as Cn,jI as Rn,jJ as In,jK as Dn,jL as Bn,jM as Nn,jN as Ht,jO as Fn,jP as Gn,jQ as Hn,bt as zn,bD as Wn,jR as qn,jS as fe,jT as Un,jU as Kn,jV as Vn,jW as Jn,jX as Yn,jY as ce,jZ as Re,j_ as ht,j$ as Xn,k0 as Zn,bz as Qn,k1 as er,k2 as ut,k3 as tr,k4 as nr,gc as rr,cD as sr,f8 as or,gb as zt,b$ as ar,gN as ir,dX as oe,ih as lr,eB as fr,f6 as cr,cw as we,dY as Ie,dZ as dt,k5 as hr,k6 as W,hr as ur,k7 as dr}from"./titleFrameBudget-DsM0V482.js";import{g as pr,l as mr,r as gr}from"./rigTrack-DMyqb0pb.js";import{t as le}from"./i18n-C9zFX25m.js";import{bK as yr,ap as wr,s as br}from"./api-Dnl2uaKO.js";function De(e){if(typeof e!="string")return null;const t=(o,a=!1)=>o.split(",").map(i=>i.trim()).filter(Boolean).map(i=>{const[l,f]=i.split(/\s+as\s+/);return a?f?`${f}:${l}`:l:f?`${l}:${f}`:l}).join(",");let n=e.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]three['"];?/m,(o,a)=>`const {${t(a)}}=THREE;`);if(n=n.replace(/^import\s*\{([^}]*)\}\s*from\s*['"]\.\.\/utils\/([A-Za-z]+)\.js['"];?/mg,(o,a,i)=>`const {${t(a)}}=__deps.${i};`),/^\s*import\s/m.test(n))return null;const r=/^export\s*\{([^}]*)\};?[ \t]*$/m,s=r.exec(n);return!s||(n=n.replace(r,`return {${t(s[1],!0)}};`),/^export\s/m.test(n))?null:'"use strict";'+n}const Wt=`async(THREE,items,LOADERS,flip)=>{
|
|
3
3
|
const out=new Map()
|
|
4
4
|
const bmp=(data)=>createImageBitmap(new Blob([data]),flip?{imageOrientation:'flipY',premultiplyAlpha:'none'}:{})
|
|
5
5
|
for(const it of items){
|