- Track Needle/MenuScene/dist and Needle/SampleScene/dist for container deploys - Dockerfile copies pre-built dist (no npm in image); rebuild with npm run build before commit - Fix Needle .gitignore: /assets/ so dist/assets is not ignored - Git LFS: track *.wasm; relax .dockerignore so dist is sent as build context Made-with: Cursor
1 line
54 KiB
JavaScript
1 line
54 KiB
JavaScript
import{Ar as e,En as t,Ft as n,Gn as r,Mt as i,Pt as a,S as o,Xt as s,Yt as c,Zt as l,_ as u,_n as d,bn as f,jr as p,jt as m,kr as h,lr as g,m as _,x as v,yr as y}from"./three@0.169.19.js";var b=1.25,x=65535;x<<16;var S=2**-24,C=Symbol(`SKIP_GENERATION`),w={strategy:0,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[C]:!1};function T(e,t,n){return n.min.x=t[e],n.min.y=t[e+1],n.min.z=t[e+2],n.max.x=t[e+3],n.max.y=t[e+4],n.max.z=t[e+5],n}function ee(e){let t=-1,n=-1/0;for(let r=0;r<3;r++){let i=e[r+3]-e[r];i>n&&(n=i,t=r)}return t}function te(e,t){t.set(e)}function ne(e,t,n){let r,i;for(let a=0;a<3;a++){let o=a+3;r=e[a],i=t[a],n[a]=r<i?r:i,r=e[o],i=t[o],n[o]=r>i?r:i}}function E(e,t,n){for(let r=0;r<3;r++){let i=t[e+2*r],a=t[e+2*r+1],o=i-a,s=i+a;o<n[r]&&(n[r]=o),s>n[r+3]&&(n[r+3]=s)}}function D(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function O(e,t){return t[e+15]===x}function k(e,t){return t[e+6]}function A(e,t){return t[e+14]}function j(e){return e+8}function M(e,t){return e+t[e+6]*8}function re(e,t){return t[e+7]}function N(e){return e}function ie(e,t,n,r,i){let a=1/0,o=1/0,s=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,p=1/0,m=-1/0,h=-1/0,g=-1/0,_=e.offset||0;for(let r=(t-_)*6,i=(t+n-_)*6;r<i;r+=6){let t=e[r+0],n=e[r+1],i=t-n,_=t+n;i<a&&(a=i),_>c&&(c=_),t<d&&(d=t),t>m&&(m=t);let v=e[r+2],y=e[r+3],b=v-y,x=v+y;b<o&&(o=b),x>l&&(l=x),v<f&&(f=v),v>h&&(h=v);let S=e[r+4],C=e[r+5],w=S-C,T=S+C;w<s&&(s=w),T>u&&(u=T),S<p&&(p=S),S>g&&(g=S)}r[0]=a,r[1]=o,r[2]=s,r[3]=c,r[4]=l,r[5]=u,i[0]=d,i[1]=f,i[2]=p,i[3]=m,i[4]=h,i[5]=g}var P=32,ae=(e,t)=>e.candidate-t.candidate,F=Array(P).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),oe=new Float32Array(6);function se(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=ee(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=ee(e),o!==-1&&(s=ce(n,r,i,o));else if(a===2){let a=D(e),c=b*i,l=n.offset||0,u=(r-l)*6,d=(r+i-l)*6;for(let e=0;e<3;e++){let r=t[e],l=(t[e+3]-r)/P;if(i<P/4){let t=[...F];t.length=i;let r=0;for(let i=u;i<d;i+=6,r++){let a=t[r];a.candidate=n[i+2*e],a.count=0;let{bounds:o,leftCacheBounds:s,rightCacheBounds:c}=a;for(let e=0;e<3;e++)c[e]=1/0,c[e+3]=-1/0,s[e]=1/0,s[e+3]=-1/0,o[e]=1/0,o[e+3]=-1/0;E(i,n,o)}t.sort(ae);let l=i;for(let e=0;e<l;e++){let n=t[e];for(;e+1<l&&t[e+1].candidate===n.candidate;)t.splice(e+1,1),l--}for(let r=u;r<d;r+=6){let i=n[r+2*e];for(let e=0;e<l;e++){let a=t[e];i>=a.candidate?E(r,n,a.rightCacheBounds):(E(r,n,a.leftCacheBounds),a.count++)}}for(let n=0;n<l;n++){let r=t[n],l=r.count,u=i-r.count,d=r.leftCacheBounds,f=r.rightCacheBounds,p=0;l!==0&&(p=D(d)/a);let m=0;u!==0&&(m=D(f)/a);let h=1+b*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<P;e++){let t=F[e];t.count=0,t.candidate=r+l+e*l;let n=t.bounds;for(let e=0;e<3;e++)n[e]=1/0,n[e+3]=-1/0}for(let t=u;t<d;t+=6){let i=~~((n[t+2*e]-r)/l);i>=P&&(i=P-1);let a=F[i];a.count++,E(t,n,a.bounds)}let t=F[P-1];te(t.bounds,t.rightCacheBounds);for(let e=P-2;e>=0;e--){let t=F[e],n=F[e+1];ne(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<P-1;t++){let n=F[t],r=n.count,l=n.bounds,u=F[t+1].rightCacheBounds;r!==0&&(f===0?te(l,oe):ne(l,oe,oe)),f+=r;let d=0,p=0;f!==0&&(d=D(oe)/a);let m=i-f;m!==0&&(p=D(u)/a);let h=1+b*(d*f+p*m);h<c&&(o=e,c=h,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function ce(e,t,n,r){let i=0,a=e.offset;for(let o=t,s=t+n;o<s;o++)i+=e[(o-a)*6+r*2];return i/n}var le=class{constructor(){this.boundingData=new Float32Array(6)}};function ue(e,t,n,r,i,a){let o=r,s=r+i-1,c=a.pos,l=a.axis*2,u=n.offset||0;for(;;){for(;o<=s&&n[(o-u)*6+l]<c;)o++;for(;o<=s&&n[(s-u)*6+l]>=c;)s--;if(o<s){for(let n=0;n<t;n++){let r=e[o*t+n];e[o*t+n]=e[s*t+n],e[s*t+n]=r}for(let e=0;e<6;e++){let t=o-u,r=s-u,i=n[t*6+e];n[t*6+e]=n[r*6+e],n[r*6+e]=i}o++,s--}else return o}}var de,fe,pe,me,he=2**32;function ge(e){return`count`in e?1:1+ge(e.left)+ge(e.right)}function _e(e,t,n){return de=new Float32Array(n),fe=new Uint32Array(n),pe=new Uint16Array(n),me=new Uint8Array(n),ve(e,t)}function ve(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)de[n+e]=a[e];if(i)return t.buffer?(me.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(fe[n+6]=t.offset,pe[r+14]=t.count,pe[r+15]=x,e+32);{let{left:r,right:i,splitAxis:a}=t,o=ve(e+32,r),s=e/32,c=o/32-s;if(c>he)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return fe[n+6]=c,fe[n+7]=a,ve(o,i)}}function ye(e,t,n,r,i){let{maxDepth:a,verbose:o,maxLeafSize:s,strategy:c,onProgress:l}=i,u=e.primitiveBuffer,d=e.primitiveBufferStride,f=new Float32Array(6),p=!1,m=new le;return ie(t,n,r,m.boundingData,f),g(m,n,r,f),m;function h(e){l&&l(e/r)}function g(e,n,r,i=null,l=0){if(!p&&l>=a&&(p=!0,o&&console.warn(`BVH: Max depth of ${a} reached when generating BVH. Consider increasing maxDepth.`)),r<=s||l>=a)return h(n+r),e.offset=n,e.count=r,e;let m=se(e.boundingData,i,t,n,r,c);if(m.axis===-1)return h(n+r),e.offset=n,e.count=r,e;let _=ue(u,d,t,n,r,m);if(_===n||_===n+r)h(n+r),e.offset=n,e.count=r;else{e.splitAxis=m.axis;let i=new le,a=n,o=_-n;e.left=i,ie(t,a,o,i.boundingData,f),g(i,a,o,f,l+1);let s=new le,c=_,u=r-o;e.right=s,ie(t,c,u,s.boundingData,f),g(s,c,u,f,l+1)}return e}}function be(e,t){let n=t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=e.getRootRanges(t.range),i=r[0],a=r[r.length-1],o={offset:i.offset,count:a.offset+a.count-i.offset},s=new Float32Array(6*o.count);s.offset=o.offset,e.computePrimitiveBounds(o.offset,o.count,s),e._roots=r.map(r=>{let i=ye(e,s,r.offset,r.count,t),a=new n(32*ge(i));return _e(0,i,a),a})}var xe=class{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){let e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}},I=new class{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;let e=[],t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}},L,Se,Ce=[],we=new xe(()=>new u);function Te(e,t,n,r,i,a){L=we.getPrimitive(),Se=we.getPrimitive(),Ce.push(L,Se),I.setBuffer(e._roots[t]);let o=Ee(0,e.geometry,n,r,i,a);I.clearBuffer(),we.releasePrimitive(L),we.releasePrimitive(Se),Ce.pop(),Ce.pop();let s=Ce.length;return s>0&&(Se=Ce[s-1],L=Ce[s-2]),o}function Ee(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=I,u=e*2;if(O(u,c)){let t=k(e,l),n=A(u,c);return T(N(e),s,L),r(t,n,!1,o,a+e/8,L)}else{let u=j(e),d=M(e,l),f=u,p=d,m,h,g,_;if(i&&(g=L,_=Se,T(N(f),s,g),T(N(p),s,_),m=i(g),h=i(_),h<m)){f=d,p=u;let e=m;m=h,h=e,g=_}g||(g=L,T(N(f),s,g));let v=O(f*2,c),y=n(g,v,m,o+1,a+f/8),b;if(y===2){let e=w(f);b=r(e,ee(f)-e,!0,o+1,a+f/8,g)}else b=y&&Ee(f,t,n,r,i,a,o+1);if(b)return!0;_=Se,T(N(p),s,_);let x=O(p*2,c),S=n(_,x,h,o+1,a+p/8),C;if(S===2){let e=w(p);C=r(e,ee(p)-e,!0,o+1,a+p/8,_)}else C=S&&Ee(p,t,n,r,i,a,o+1);if(C)return!0;return!1;function w(e){let{uint16Array:t,uint32Array:n}=I,r=e*2;for(;!O(r,t);)e=j(e),r=e*2;return k(e,n)}function ee(e){let{uint16Array:t,uint32Array:n}=I,r=e*2;for(;!O(r,t);)e=M(e,n),r=e*2;return k(e,n)+A(r,t)}}}var De=new I.constructor,Oe=new I.constructor,R=new xe(()=>new u),ke=new u,Ae=new u,je=new u,Me=new u,Ne=!1;function Pe(e,t,n,r){if(Ne)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Ne=!0;let i=e._roots,a=t._roots,o,c=0,l=0,u=new s().copy(n).invert();for(let e=0,t=i.length;e<t;e++){De.setBuffer(i[e]),l=0;let t=R.getPrimitive();T(N(0),De.float32Array,t),t.applyMatrix4(u);for(let e=0,i=a.length;e<i&&(Oe.setBuffer(a[e]),o=z(0,0,n,u,r,c,l,0,0,t),Oe.clearBuffer(),l+=a[e].byteLength/32,!o);e++);if(R.releasePrimitive(t),De.clearBuffer(),c+=i[e].byteLength/32,o)break}return Ne=!1,o}function z(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=Oe,f=De):(d=De,f=Oe);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=O(y,h),S=O(b,v),C=!1;if(S&&x)C=u?i(k(t,_),A(t*2,v),k(e,m),A(e*2,h),c,o+t/8,s,a+e/8):i(k(e,m),A(e*2,h),k(t,_),A(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=R.getPrimitive();T(N(t),g,l),l.applyMatrix4(n);let d=j(e),f=M(e,m);T(N(d),p,ke),T(N(f),p,Ae);let h=l.intersectsBox(ke),_=l.intersectsBox(Ae);C=h&&z(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&z(t,f,r,n,i,o,a,c,s+1,l,!u),R.releasePrimitive(l)}else{let d=j(t),f=M(t,_);T(N(d),g,je),T(N(f),g,Me);let h=l.intersectsBox(je),v=l.intersectsBox(Me);if(h&&v)C=z(e,d,n,r,i,a,o,s,c+1,l,u)||z(e,f,n,r,i,a,o,s,c+1,l,u);else if(h)if(x)C=z(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=R.getPrimitive();t.copy(je).applyMatrix4(n);let l=j(e),f=M(e,m);T(N(l),p,ke),T(N(f),p,Ae);let h=t.intersectsBox(ke),g=t.intersectsBox(Ae);C=h&&z(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&z(d,f,r,n,i,o,a,c,s+1,t,!u),R.releasePrimitive(t)}else if(v)if(x)C=z(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=R.getPrimitive();t.copy(Me).applyMatrix4(n);let l=j(e),d=M(e,m);T(N(l),p,ke),T(N(d),p,Ae);let h=t.intersectsBox(ke),g=t.intersectsBox(Ae);C=h&&z(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&z(f,d,r,n,i,o,a,c,s+1,t,!u),R.releasePrimitive(t)}}return C}var Fe=new u,Ie=new Float32Array(6),Le=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...w,...e},be(this,e)}getRootRanges(){throw Error(`BVH: getRootRanges() not implemented`)}writePrimitiveBounds(){throw Error(`BVH: writePrimitiveBounds() not implemented`)}writePrimitiveRangeBounds(e,t,n,r){let i=1/0,a=1/0,o=1/0,s=-1/0,c=-1/0,l=-1/0;for(let n=e,r=e+t;n<r;n++){this.writePrimitiveBounds(n,Ie,0);let[e,t,r,u,d,f]=Ie;e<i&&(i=e),u>s&&(s=u),t<a&&(a=t),d>c&&(c=d),r<o&&(o=r),f>l&&(l=f)}return n[r+0]=i,n[r+1]=a,n[r+2]=o,n[r+3]=s,n[r+4]=c,n[r+5]=l,n}computePrimitiveBounds(e,t,n){let r=n.offset||0;for(let i=e,a=e+t;i<a;i++){this.writePrimitiveBounds(i,Ie,0);let[e,t,a,o,s,c]=Ie,l=(e+o)/2,u=(t+s)/2,d=(a+c)/2,f=(o-e)/2,p=(s-t)/2,m=(c-a)/2,h=(i-r)*6;n[h+0]=l,n[h+1]=f+(Math.abs(l)+f)*S,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*S,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*S}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;O(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){let n=this._roots[t],r=new Uint32Array(n),i=new Uint16Array(n);a(0);function a(t,o=0){let s=t*2,c=O(s,i);if(c){let a=r[t+6],l=i[s+14];e(o,c,new Float32Array(n,t*4,6),a,l)}else{let i=j(t),s=M(t,r),l=re(t,r);e(o,c,new Float32Array(n,t*4,6),l)||(a(i,o+1),a(s,o+1))}}}refit(){let e=this._roots;for(let t=0,n=e.length;t<n;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n),a=new Float32Array(n),o=n.byteLength/32;for(let e=o-1;e>=0;e--){let t=e*8,n=t*2;if(O(n,i)){let e=k(t,r),o=A(n,i);this.writePrimitiveRangeBounds(e,o,Ie,0),a.set(Ie,t)}else{let e=j(t),n=M(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{T(0,new Float32Array(t),Fe),e.union(Fe)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:r,intersectsPrimitive:i,scratchPrimitive:a,iterate:o}=e;if(r&&i){let e=r;r=(t,n,r,s,c)=>e(t,n,r,s,c)?!0:o(t,n,this,i,r,s,a)}else r||=i?(e,t,n,r)=>o(e,t,this,i,n,r,a):(e,t,n)=>n;let s=!1,c=0,l=this._roots;for(let e=0,i=l.length;e<i;e++){let i=l[e];if(s=Te(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Pe(this,e,t,r)}};function Re(){return typeof SharedArrayBuffer<`u`}function ze(e){return e.index?e.index.count:e.attributes.position.count}function Be(e){return ze(e)/3}function Ve(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function He(e,t){if(!e.index){let n=e.attributes.position.count,r=Ve(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new v(r,1));for(let e=0;e<n;e++)r[e]=e}}function Ue(e,t,n){let r=ze(e)/n,i=t||e.drawRange,a=i.start/n,o=(i.start+i.count)/n,s=Math.max(0,a),c=Math.min(r,o)-s;return{offset:Math.floor(s),count:Math.floor(c)}}function We(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Ge(e,t,n){let r=Ue(e,t,n),i=We(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=ze(e)/n,l=[];for(let e of i){let{offset:t,count:n}=e,r=t,i=t+(isFinite(n)?n:c-t);r<s&&i>o&&(l.push({pos:Math.max(o,r),isStart:!0}),l.push({pos:Math.min(s,i),isStart:!1}))}l.sort((e,t)=>e.pos===t.pos?e.type===`end`?-1:1:e.pos-t.pos);let u=0,d=null;for(let e of l){let t=e.pos;u!==0&&t!==d&&a.push({offset:d,count:t-d}),u+=e.isStart?1:-1,d=t}return a}function Ke(e,t){let n=e[e.length-1],r=n.offset+n.count>2**16,i=e.reduce((e,t)=>e+t.count,0),a=r?4:2,o=t?new SharedArrayBuffer(i*a):new ArrayBuffer(i*a),s=r?new Uint32Array(o):new Uint16Array(o),c=0;for(let t=0;t<e.length;t++){let{offset:n,count:r}=e[t];for(let e=0;e<r;e++)s[c+e]=n+e;c+=r}return s}var qe=class extends Le{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)throw Error(`BVH: Only BufferGeometries are supported.`);if(e.index&&e.index.isInterleavedBufferAttribute)throw Error(`BVH: InterleavedBufferAttribute is not supported for the index attribute.`);if(t.useSharedArrayBuffer&&!Re())throw Error(`BVH: SharedArrayBuffer is not available.`);super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?e=>this._indirectBuffer[e]:e=>e,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...w,...t},t[C]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;e.indirect?this._indirectBuffer=Ke(Ge(t,e.range,n),e.useSharedArrayBuffer):He(t,e),super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new u))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ge(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},B=class{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,r=-1/0;for(let i=0,a=e.length;i<a;i++){let a=e[i][t];n=a<n?a:n,r=a>r?a:r}this.min=n,this.max=r}setFromPoints(e,t){let n=1/0,r=-1/0;for(let i=0,a=t.length;i<a;i++){let a=t[i],o=e.dot(a);n=o<n?o:n,r=o>r?o:r}this.min=n,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}};B.prototype.setFromBox=(function(){let t=new e;return function(e,n){let r=n.min,i=n.max,a=1/0,o=-1/0;for(let n=0;n<=1;n++)for(let s=0;s<=1;s++)for(let c=0;c<=1;c++){t.x=r.x*n+i.x*(1-n),t.y=r.y*s+i.y*(1-s),t.z=r.z*c+i.z*(1-c);let l=e.dot(t);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})(),(function(){let e=new B;return function(t,n){let r=t.points,i=t.satAxes,a=t.satBounds,o=n.points,s=n.satAxes,c=n.satBounds;for(let t=0;t<3;t++){let n=a[t],r=i[t];if(e.setFromPoints(r,o),n.isSeparated(e))return!1}for(let t=0;t<3;t++){let n=c[t],i=s[t];if(e.setFromPoints(i,r),n.isSeparated(e))return!1}}})();var Je=(function(){let t=new e,n=new e,r=new e;return function(e,i,a){let o=e.start,s=t,c=i.start,l=n;r.subVectors(o,c),t.subVectors(e.end,e.start),n.subVectors(i.end,i.start);let u=r.dot(l),d=l.dot(s),f=l.dot(l),p=r.dot(s),m=s.dot(s)*f-d*d,h,g;h=m===0?0:(u*d-p*f)/m,g=(u+h*d)/f,a.x=h,a.y=g}})(),Ye=(function(){let t=new h,n=new e,r=new e;return function(e,i,a,o){Je(e,i,t);let s=t.x,c=t.y;if(s>=0&&s<=1&&c>=0&&c<=1){e.at(s,a),i.at(c,o);return}else if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),e.closestPointToPoint(o,!0,a);return}else if(c>=0&&c<=1){s<0?e.at(0,a):e.at(1,a),i.closestPointToPoint(a,!0,o);return}else{let t;t=s<0?e.start:e.end;let l;l=c<0?i.start:i.end;let u=n,d=r;if(e.closestPointToPoint(l,!0,n),i.closestPointToPoint(t,!0,r),u.distanceToSquared(l)<=d.distanceToSquared(t)){a.copy(u),o.copy(l);return}else{a.copy(t),o.copy(d);return}}}})(),Xe=(function(){let t=new e,n=new e,r=new d,a=new i;return function(e,i){let{radius:o,center:s}=e,{a:c,b:l,c:u}=i;if(a.start=c,a.end=l,a.closestPointToPoint(s,!0,t).distanceTo(s)<=o||(a.start=c,a.end=u,a.closestPointToPoint(s,!0,t).distanceTo(s)<=o)||(a.start=l,a.end=u,a.closestPointToPoint(s,!0,t).distanceTo(s)<=o))return!0;let d=i.getPlane(r);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,n);if(i.containsPoint(e))return!0}return!1}})(),Ze=[`x`,`y`,`z`],V=1e-15,Qe=V*V;function H(e){return Math.abs(e)<V}var U=class extends y{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new e),this.satBounds=[,,,,].fill().map(()=>new B),this.points=[this.a,this.b,this.c],this.plane=new d,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new i,this.needsUpdate=!0}intersectsSphere(e){return Xe(e,this)}update(){let e=this.a,t=this.b,n=this.c,r=this.points,i=this.satAxes,a=this.satBounds,o=i[0],s=a[0];this.getNormal(o),s.setFromPoints(o,r);let c=i[1],l=a[1];c.subVectors(e,t),l.setFromPoints(c,r);let u=i[2],d=a[2];u.subVectors(t,n),d.setFromPoints(u,r);let f=i[3],p=a[3];f.subVectors(n,e),p.setFromPoints(f,r);let m=c.length(),h=u.length(),g=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,m<V?h<V||g<V?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<V?g<V?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<V&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};U.prototype.closestPointToSegment=(function(){let t=new e,n=new e,r=new i;return function(e,i=null,a=null){let{start:o,end:s}=e,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;r.start.copy(c[o]),r.end.copy(c[s]),Ye(r,e,t,n),l=t.distanceToSquared(n),l<u&&(u=l,i&&i.copy(t),a&&a.copy(n))}return this.closestPointToPoint(o,t),l=o.distanceToSquared(t),l<u&&(u=l,i&&i.copy(t),a&&a.copy(o)),this.closestPointToPoint(s,t),l=s.distanceToSquared(t),l<u&&(u=l,i&&i.copy(t),a&&a.copy(s)),Math.sqrt(u)}})(),U.prototype.intersectsTriangle=(function(){let t=new U,n=new B,r=new B,a=new e,o=new e,s=new e,c=new e,l=new i,u=new i,d=new e,f=new h,p=new h;function m(e,t,i,o){let s=a;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?s.copy(e.plane.normal):s.copy(t.plane.normal);let l=e.satBounds,u=e.satAxes;for(let i=1;i<4;i++){let a=l[i],o=u[i];if(n.setFromPoints(o,t.points),a.isSeparated(n)||(c.copy(s).cross(o),n.setFromPoints(c,e.points),r.setFromPoints(c,t.points),n.isSeparated(r)))return!1}let d=t.satBounds,f=t.satAxes;for(let i=1;i<4;i++){let a=d[i],o=f[i];if(n.setFromPoints(o,e.points),a.isSeparated(n)||(c.crossVectors(s,o),n.setFromPoints(c,e.points),r.setFromPoints(c,t.points),n.isSeparated(r)))return!1}return i&&(o||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),i.start.set(0,0,0),i.end.set(0,0,0)),!0}function g(e,t,n,r,i,a,o,s,c,l,u){let d=o/(o-s);l.x=r+(i-r)*d,u.start.subVectors(t,e).multiplyScalar(d).add(e),d=o/(o-c),l.y=r+(a-r)*d,u.end.subVectors(n,e).multiplyScalar(d).add(e)}function _(e,t,n,r,i,a,o,s,c,l,u){if(i>0)g(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)g(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)g(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)g(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)g(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function v(e,t,n,r){let i=t.degenerateSegment,o=e.plane.distanceToPoint(i.start),s=e.plane.distanceToPoint(i.end);return H(o)?H(s)?m(e,t,n,r):(n&&(n.start.copy(i.start),n.end.copy(i.start)),e.containsPoint(i.start)):H(s)?(n&&(n.start.copy(i.end),n.end.copy(i.end)),e.containsPoint(i.end)):e.plane.intersectLine(i,a)==null?!1:(n&&(n.start.copy(a),n.end.copy(a)),e.containsPoint(a))}function y(e,t,n){let r=t.a;return H(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function b(e,t,n){let r=e.degenerateSegment,i=t.a;return r.closestPointToPoint(i,!0,a),i.distanceToSquared(a)<Qe?(n&&(n.start.copy(i),n.end.copy(i)),!0):!1}function x(e,t,n,r){if(e.isDegenerateIntoSegment)if(t.isDegenerateIntoSegment){let r=e.degenerateSegment,i=t.degenerateSegment,c=o,l=s;r.delta(c),i.delta(l);let u=a.subVectors(i.start,r.start),d=c.x*l.y-c.y*l.x;if(H(d))return!1;let f=(u.x*l.y-u.y*l.x)/d,p=-(c.x*u.y-c.y*u.x)/d;return f<0||f>1||p<0||p>1?!1:H(r.start.z+c.z*f-(i.start.z+l.z*p))?(n&&(n.start.copy(r.start).addScaledVector(c,f),n.end.copy(r.start).addScaledVector(c,f)),!0):!1}else if(t.isDegenerateIntoPoint)return b(e,t,n);else return v(t,e,n,r);else if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<Qe?(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):!1:t.isDegenerateIntoSegment?b(t,e,n):y(t,e,n);else if(t.isDegenerateIntoPoint)return y(e,t,n);else if(t.isDegenerateIntoSegment)return v(e,t,n,r)}return function(e,n=null,r=!1){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);let i=x(this,e,n,r);if(i!==void 0)return i;let a=this.plane,c=e.plane,h=c.distanceToPoint(this.a),g=c.distanceToPoint(this.b),v=c.distanceToPoint(this.c);H(h)&&(h=0),H(g)&&(g=0),H(v)&&(v=0);let y=h*g,b=h*v;if(y>0&&b>0)return!1;let S=a.distanceToPoint(e.a),C=a.distanceToPoint(e.b),w=a.distanceToPoint(e.c);H(S)&&(S=0),H(C)&&(C=0),H(w)&&(w=0);let T=S*C,ee=S*w;if(T>0&&ee>0)return!1;o.copy(a.normal),s.copy(c.normal);let te=o.cross(s),ne=0,E=Math.abs(te.x),D=Math.abs(te.y);D>E&&(E=D,ne=1),Math.abs(te.z)>E&&(ne=2);let O=Ze[ne],k=this.a[O],A=this.b[O],j=this.c[O],M=e.a[O],re=e.b[O],N=e.c[O];if(_(this,k,A,j,y,b,h,g,v,f,l)||_(e,M,re,N,T,ee,S,C,w,p,u))return m(this,e,n,r);if(f.y<f.x){let e=f.y;f.y=f.x,f.x=e,d.copy(l.start),l.start.copy(l.end),l.end.copy(d)}if(p.y<p.x){let e=p.y;p.y=p.x,p.x=e,d.copy(u.start),u.start.copy(u.end),u.end.copy(d)}return f.y<p.x||p.y<f.x?!1:(n&&(p.x>f.x?n.start.copy(u.start):n.start.copy(l.start),p.y<f.y?n.end.copy(u.end):n.end.copy(l.end)),!0)}})(),U.prototype.distanceToPoint=(function(){let t=new e;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}})(),U.prototype.distanceToTriangle=(function(){let t=new e,n=new e,r=[`a`,`b`,`c`],a=new i,o=new i;return function(e,i=null,s=null){let c=i||s?a:null;if(this.intersectsTriangle(e,c))return(i||s)&&(i&&c.getCenter(i),s&&c.getCenter(s)),0;let l=1/0;for(let n=0;n<3;n++){let a,o=r[n],c=e[o];this.closestPointToPoint(c,t),a=c.distanceToSquared(t),a<l&&(l=a,i&&i.copy(t),s&&s.copy(c));let u=this[o];e.closestPointToPoint(u,t),a=u.distanceToSquared(t),a<l&&(l=a,i&&i.copy(u),s&&s.copy(t))}for(let c=0;c<3;c++){let u=r[c],d=r[(c+1)%3];a.set(this[u],this[d]);for(let c=0;c<3;c++){let u=r[c],d=r[(c+1)%3];o.set(e[u],e[d]),Ye(a,o,t,n);let f=t.distanceToSquared(n);f<l&&(l=f,i&&i.copy(t),s&&s.copy(n))}}return Math.sqrt(l)}})();var W=class{constructor(t,n,r){this.isOrientedBox=!0,this.min=new e,this.max=new e,this.matrix=new s,this.invMatrix=new s,this.points=Array(8).fill().map(()=>new e),this.satAxes=[,,,].fill().map(()=>new e),this.satBounds=[,,,].fill().map(()=>new B),this.alignedSatBounds=[,,,].fill().map(()=>new B),this.needsUpdate=!1,t&&this.min.copy(t),n&&this.max.copy(n),r&&this.matrix.copy(r)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}};W.prototype.update=(function(){return function(){let e=this.matrix,t=this.min,n=this.max,r=this.points;for(let i=0;i<=1;i++)for(let a=0;a<=1;a++)for(let o=0;o<=1;o++){let s=r[1*i|2*a|4*o];s.x=i?n.x:t.x,s.y=a?n.y:t.y,s.z=o?n.z:t.z,s.applyMatrix4(e)}let i=this.satBounds,a=this.satAxes,o=r[0];for(let e=0;e<3;e++){let t=a[e],n=i[e],s=r[1<<e];t.subVectors(o,s),n.setFromPoints(t,r)}let s=this.alignedSatBounds;s[0].setFromPointsField(r,`x`),s[1].setFromPointsField(r,`y`),s[2].setFromPointsField(r,`z`),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})(),W.prototype.intersectsBox=(function(){let e=new B;return function(t){this.needsUpdate&&this.update();let n=t.min,r=t.max,i=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(e.min=n.x,e.max=r.x,o[0].isSeparated(e)||(e.min=n.y,e.max=r.y,o[1].isSeparated(e))||(e.min=n.z,e.max=r.z,o[2].isSeparated(e)))return!1;for(let n=0;n<3;n++){let r=a[n],o=i[n];if(e.setFromBox(r,t),o.isSeparated(e))return!1}return!0}})(),W.prototype.intersectsTriangle=(function(){let t=new U,n=[,,,],r=new B,i=new B,a=new e;return function(e){this.needsUpdate&&this.update(),e.isExtendedTriangle?e.needsUpdate&&e.update():(t.copy(e),t.update(),e=t);let o=this.satBounds,s=this.satAxes;n[0]=e.a,n[1]=e.b,n[2]=e.c;for(let e=0;e<3;e++){let t=o[e],i=s[e];if(r.setFromPoints(i,n),t.isSeparated(r))return!1}let c=e.satBounds,l=e.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],n=l[e];if(r.setFromPoints(n,u),t.isSeparated(r))return!1}for(let e=0;e<3;e++){let t=s[e];for(let e=0;e<4;e++){let o=l[e];if(a.crossVectors(t,o),r.setFromPoints(a,n),i.setFromPoints(a,u),r.isSeparated(i))return!1}}return!0}})(),W.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}})(),W.prototype.distanceToPoint=(function(){let t=new e;return function(e){return this.closestPointToPoint(e,t),e.distanceTo(t)}})(),W.prototype.distanceToBox=(function(){let t=[`x`,`y`,`z`],n=Array(12).fill().map(()=>new i),r=Array(12).fill().map(()=>new i),a=new e,o=new e;return function(e,i=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(e))return(s||c)&&(e.getCenter(o),this.closestPointToPoint(o,a),e.closestPointToPoint(a,o),s&&s.copy(a),c&&c.copy(o)),0;let l=i*i,u=e.min,d=e.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];o.copy(t).clamp(u,d);let n=t.distanceToSquared(o);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(o),n<l))return Math.sqrt(n)}let m=0;for(let e=0;e<3;e++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(e+1)%3,s=(e+2)%3,c=i<<o|a<<s,l=1<<e|i<<o|a<<s,p=f[c],h=f[l];n[m].set(p,h);let g=t[e],_=t[o],v=t[s],y=r[m],b=y.start,x=y.end;b[g]=u[g],b[_]=i?u[_]:d[_],b[v]=a?u[v]:d[_],x[g]=d[g],x[_]=i?u[_]:d[_],x[v]=a?u[v]:d[_],m++}for(let e=0;e<=1;e++)for(let t=0;t<=1;t++)for(let n=0;n<=1;n++){o.x=e?d.x:u.x,o.y=t?d.y:u.y,o.z=n?d.z:u.z,this.closestPointToPoint(o,a);let r=o.distanceToSquared(a);if(r<p&&(p=r,s&&s.copy(a),c&&c.copy(o),r<l))return Math.sqrt(r)}for(let e=0;e<12;e++){let t=n[e];for(let e=0;e<12;e++){let n=r[e];Ye(t,n,a,o);let i=a.distanceToSquared(o);if(i<p&&(p=i,s&&s.copy(a),c&&c.copy(o),i<l))return Math.sqrt(i)}}return Math.sqrt(p)}})();var G=new class extends xe{constructor(){super(()=>new U)}},$e=new e,et=new e;function tt(e,t,n={},r=0,i=1/0){let a=r*r,o=i*i,s=1/0,c=null;if(e.shapecast({boundsTraverseOrder:e=>($e.copy(t).clamp(e.min,e.max),$e.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,$e);let r=t.distanceToSquared($e);return r<s&&(et.copy($e),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(et):n.point=et.clone(),n.distance=l,n.faceIndex=c,n}var nt=parseInt(t)>=169,rt=parseInt(t)<=161,K=new e,q=new e,J=new e,it=new h,at=new h,ot=new h,st=new e,ct=new e,lt=new e,ut=new e;function dt(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function ft(t,n,r,i,a,o,s,c,l,u,d){K.fromBufferAttribute(n,o),q.fromBufferAttribute(n,s),J.fromBufferAttribute(n,c);let f=dt(t,K,q,J,ut,l,u,d);if(f){if(i){it.fromBufferAttribute(i,o),at.fromBufferAttribute(i,s),ot.fromBufferAttribute(i,c),f.uv=new h;let e=y.getInterpolation(ut,K,q,J,it,at,ot,f.uv);nt||(f.uv=e)}if(a){it.fromBufferAttribute(a,o),at.fromBufferAttribute(a,s),ot.fromBufferAttribute(a,c),f.uv1=new h;let e=y.getInterpolation(ut,K,q,J,it,at,ot,f.uv1);nt||(f.uv1=e),rt&&(f.uv2=f.uv1)}if(r){st.fromBufferAttribute(r,o),ct.fromBufferAttribute(r,s),lt.fromBufferAttribute(r,c),f.normal=new e;let n=y.getInterpolation(ut,K,q,J,st,ct,lt,f.normal);f.normal.dot(t.direction)>0&&f.normal.multiplyScalar(-1),nt||(f.normal=n)}let n={a:o,b:s,c,normal:new e,materialIndex:0};if(y.getNormal(K,q,J,n.normal),f.face=n,f.faceIndex=o,nt){let t=new e;y.getBarycoord(ut,K,q,J,t),f.barycoord=t}}return f}function pt(e){return e&&e.isMaterial?e.side:e}function mt(e,t,n,r,i,a,o){let s=r*3,c=s+0,l=s+1,u=s+2,{index:d,groups:f}=e;e.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));let{position:p,normal:m,uv:h,uv1:g}=e.attributes;if(Array.isArray(t)){let e=r*3;for(let s=0,d=f.length;s<d;s++){let{start:d,count:_,materialIndex:v}=f[s];if(e>=d&&e<d+_){let e=pt(t[v]),s=ft(n,p,m,h,g,c,l,u,e,a,o);if(s)if(s.faceIndex=r,s.face.materialIndex=v,i)i.push(s);else return s}}}else{let e=pt(t),s=ft(n,p,m,h,g,c,l,u,e,a,o);if(s)if(s.faceIndex=r,s.face.materialIndex=0,i)i.push(s);else return s}return null}function Y(e,t,n,r){let i=e.a,a=e.b,o=e.c,s=t,c=t+1,l=t+2;n&&(s=n.getX(s),c=n.getX(c),l=n.getX(l)),i.x=r.getX(s),i.y=r.getY(s),i.z=r.getZ(s),a.x=r.getX(c),a.y=r.getY(c),a.z=r.getZ(c),o.x=r.getX(l),o.y=r.getY(l),o.z=r.getZ(l)}function ht(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)mt(c,t,n,e,a,o,s)}function gt(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,c=r+i;e<c;e++){let r;r=mt(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function _t(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let n=e,s=t+e;n<s;n++){let e;if(e=n,Y(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function vt(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(O(l,s)){let t=k(e,o),n=A(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}else{let r=j(e),i=M(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function X(e,t,n,r,i){let a,o,s,c,l,u,d=1/n.direction.x,f=1/n.direction.y,p=1/n.direction.z,m=n.origin.x,h=n.origin.y,g=n.origin.z,_=t[e],v=t[e+3],y=t[e+1],b=t[e+3+1],x=t[e+2],S=t[e+3+2];return d>=0?(a=(_-m)*d,o=(v-m)*d):(a=(v-m)*d,o=(_-m)*d),f>=0?(s=(y-h)*f,c=(b-h)*f):(s=(b-h)*f,c=(y-h)*f),a>c||s>o||((s>a||isNaN(a))&&(a=s),(c<o||isNaN(o))&&(o=c),p>=0?(l=(x-g)*p,u=(S-g)*p):(l=(S-g)*p,u=(x-g)*p),a>u||l>o)?!1:((l>a||a!==a)&&(a=l),(u<o||o!==o)&&(o=u),a<=i&&o>=r)}function yt(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)mt(c,t,n,l?l[e]:e,a,o,s)}function bt(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=mt(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function xt(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),Y(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function St(e,t,n,r,i,a,o){I.setBuffer(e._roots[t]),Ct(0,e,n,r,i,a,o),I.clearBuffer()}function Ct(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=I,u=e*2;if(O(u,c))ht(t,n,r,k(e,l),A(u,c),i,a,o);else{let c=j(e);X(c,s,r,a,o)&&Ct(c,t,n,r,i,a,o);let u=M(e,l);X(u,s,r,a,o)&&Ct(u,t,n,r,i,a,o)}}var wt=[`x`,`y`,`z`];function Tt(e,t,n,r,i,a){I.setBuffer(e._roots[t]);let o=Et(0,e,n,r,i,a);return I.clearBuffer(),o}function Et(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=I,l=e*2;if(O(l,s))return gt(t,n,r,k(e,c),A(l,s),i,a);{let s=re(e,c),l=wt[s],u=r.direction[l]>=0,d,f;u?(d=j(e),f=M(e,c)):(d=M(e,c),f=j(e));let p=X(d,o,r,i,a)?Et(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=X(f,o,r,i,a)?Et(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Dt=new u,Ot=new U,kt=new U,At=new s,jt=new W,Mt=new W;function Nt(e,t,n,r){I.setBuffer(e._roots[t]);let i=Pt(0,e,n,r);return I.clearBuffer(),i}function Pt(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=I,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),jt.set(n.boundingBox.min,n.boundingBox.max,r),i=jt),O(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=k(e,s),m=A(c,o);if(At.copy(r).invert(),n.boundsTree)return T(N(e),a,Mt),Mt.matrix.copy(At),Mt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Mt.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let t=p*3,n=(m+p)*3;t<n;t+=3)if(Y(kt,t,l,u),kt.needsUpdate=!0,e.intersectsTriangle(kt))return!0;return!1}});{let e=Be(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){Y(Ot,t,l,u),Ot.a.applyMatrix4(At),Ot.b.applyMatrix4(At),Ot.c.applyMatrix4(At),Ot.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Y(kt,t,d,f),kt.needsUpdate=!0,Ot.intersectsTriangle(kt))return!0}}}else{let o=j(e),c=M(e,s);return T(N(o),a,Dt),!!(i.intersectsBox(Dt)&&Pt(o,t,n,r,i)||(T(N(c),a,Dt),i.intersectsBox(Dt)&&Pt(c,t,n,r,i)))}}var Ft=new s,It=new W,Lt=new W,Rt=new e,zt=new e,Bt=new e,Vt=new e;function Ht(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),It.set(t.boundingBox.min,t.boundingBox.max,n),It.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=G.getPrimitive(),p=G.getPrimitive(),m=Rt,h=zt,g=null,_=null;i&&(g=Bt,_=Vt);let v=1/0,y=null,b=null;return Ft.copy(n).invert(),Lt.matrix.copy(Ft),e.shapecast({boundsTraverseOrder:e=>It.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(Lt.min.copy(e.min),Lt.max.copy(e.max),Lt.needsUpdate=!0),!0):!1,intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Lt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){Y(p,3*o,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=e,n=e+r;t<n;t++){Y(f,3*t,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=t,b=o),e<a)return!0}}}});{let i=Be(t);for(let t=0,o=i;t<o;t++){Y(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=e,i=e+r;n<i;n++){Y(f,3*n,l,c),f.needsUpdate=!0;let e=f.distanceToTriangle(p,m,g);if(e<v&&(h.copy(m),_&&_.copy(g),v=e,y=n,b=t),e<a)return!0}}}}}),G.releasePrimitive(f),G.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(Ft),h.applyMatrix4(Ft),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Ut(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(O(u,s)){let t=k(n,o),a=A(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}else{let e=j(n),r=M(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function Wt(e,t,n,r,i,a,o){I.setBuffer(e._roots[t]),Gt(0,e,n,r,i,a,o),I.clearBuffer()}function Gt(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=I,u=e*2;if(O(u,c))yt(t,n,r,k(e,l),A(u,c),i,a,o);else{let c=j(e);X(c,s,r,a,o)&&Gt(c,t,n,r,i,a,o);let u=M(e,l);X(u,s,r,a,o)&&Gt(u,t,n,r,i,a,o)}}var Kt=[`x`,`y`,`z`];function qt(e,t,n,r,i,a){I.setBuffer(e._roots[t]);let o=Jt(0,e,n,r,i,a);return I.clearBuffer(),o}function Jt(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=I,l=e*2;if(O(l,s))return bt(t,n,r,k(e,c),A(l,s),i,a);{let s=re(e,c),l=Kt[s],u=r.direction[l]>=0,d,f;u?(d=j(e),f=M(e,c)):(d=M(e,c),f=j(e));let p=X(d,o,r,i,a)?Jt(d,t,n,r,i,a):null;if(p){let e=p.point[l];if(u?e<=o[f+s]:e>=o[f+s+3])return p}let m=X(f,o,r,i,a)?Jt(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Yt=new u,Xt=new U,Zt=new U,Qt=new s,$t=new W,en=new W;function tn(e,t,n,r){I.setBuffer(e._roots[t]);let i=nn(0,e,n,r);return I.clearBuffer(),i}function nn(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=I,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),$t.set(n.boundingBox.min,n.boundingBox.max,r),i=$t),O(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=k(e,s),m=A(c,o);if(Qt.copy(r).invert(),n.boundsTree)return T(N(e),a,en),en.matrix.copy(Qt),en.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>en.intersectsBox(e),intersectsTriangle:e=>{e.a.applyMatrix4(r),e.b.applyMatrix4(r),e.c.applyMatrix4(r),e.needsUpdate=!0;for(let n=p,r=m+p;n<r;n++)if(Y(Zt,3*t.resolveTriangleIndex(n),l,u),Zt.needsUpdate=!0,e.intersectsTriangle(Zt))return!0;return!1}});{let e=Be(n);for(let n=p,r=m+p;n<r;n++){Y(Xt,3*t.resolveTriangleIndex(n),l,u),Xt.a.applyMatrix4(Qt),Xt.b.applyMatrix4(Qt),Xt.c.applyMatrix4(Qt),Xt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Y(Zt,t,d,f),Zt.needsUpdate=!0,Xt.intersectsTriangle(Zt))return!0}}}else{let o=j(e),c=M(e,s);return T(N(o),a,Yt),!!(i.intersectsBox(Yt)&&nn(o,t,n,r,i)||(T(N(c),a,Yt),i.intersectsBox(Yt)&&nn(c,t,n,r,i)))}}var rn=new s,an=new W,on=new W,sn=new e,cn=new e,ln=new e,un=new e;function dn(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),an.set(t.boundingBox.min,t.boundingBox.max,n),an.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=G.getPrimitive(),p=G.getPrimitive(),m=sn,h=cn,g=null,_=null;i&&(g=ln,_=un);let v=1/0,y=null,b=null;return rn.copy(n).invert(),on.matrix.copy(rn),e.shapecast({boundsTraverseOrder:e=>an.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(on.min.copy(e.min),on.max.copy(e.max),on.needsUpdate=!0),!0):!1,intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>on.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){Y(p,3*s.resolveTriangleIndex(x),d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let t=r,n=r+i;t<n;t++){Y(f,3*e.resolveTriangleIndex(t),l,c),f.needsUpdate=!0;let n=f.distanceToTriangle(p,m,g);if(n<v&&(h.copy(m),_&&_.copy(g),v=n,y=t,b=x),n<a)return!0}}}})}else{let o=Be(t);for(let t=0,s=o;t<s;t++){Y(p,3*t,d,u),p.a.applyMatrix4(n),p.b.applyMatrix4(n),p.c.applyMatrix4(n),p.needsUpdate=!0;for(let n=r,o=r+i;n<o;n++){Y(f,3*e.resolveTriangleIndex(n),l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=n,b=t),r<a)return!0}}}}}),G.releasePrimitive(f),G.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(h):r.point=h.clone(),r.distance=v,r.faceIndex=y,i&&(i.point?i.point.copy(_):i.point=_.clone(),i.point.applyMatrix4(rn),h.applyMatrix4(rn),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function fn(e,t,n){return e===null?null:(e.point.applyMatrix4(t.matrixWorld),e.distance=e.point.distanceTo(n.ray.origin),e.object=t,e)}var pn=new W,mn=new r,hn=new e,gn=new s,_n=new e,vn=[`getX`,`getY`,`getZ`],yn=class e extends qe{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[C]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new v(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;O(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.`),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=(i?i[e]:e)*3,c=s+0,l=s+1,u=s+2;o&&(c=o[c],l=o[l],u=o[u]);for(let e=0;e<3;e++){let r=a[vn[e]](c),i=a[vn[e]](l),o=a[vn[e]](u),s=r;i<s&&(s=i),o<s&&(s=o);let d=r;i>d&&(d=i),o>d&&(d=o),t[n+e]=s,t[n+e+3]=d}return t}computePrimitiveBounds(e,t,n){let r=this.geometry,i=this._indirectBuffer,a=r.attributes.position,o=r.index?r.index.array:null,s=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw Error(`MeshBVH: compute triangle bounds range is invalid.`);let c=a.array,l=a.offset||0,u=3;a.isInterleavedBufferAttribute&&(u=a.data.stride);let d=[`getX`,`getY`,`getZ`],f=n.offset;for(let r=e,p=e+t;r<p;r++){let e=(i?i[r]:r)*3,t=(r-f)*6,p=e+0,m=e+1,h=e+2;o&&(p=o[p],m=o[m],h=o[h]),s||(p=p*u+l,m=m*u+l,h=h*u+l);for(let e=0;e<3;e++){let r,i,o;s?(r=a[d[e]](p),i=a[d[e]](m),o=a[d[e]](h)):(r=c[p+e],i=c[m+e],o=c[h+e]);let l=r;i<l&&(l=i),o<l&&(l=o);let u=r;i>u&&(u=i),o>u&&(u=o);let f=(u-l)/2,g=e*2;n[t+g+0]=l+f,n[t+g+1]=f+(Math.abs(l)+f)*S}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;gn.copy(e.matrixWorld).invert(),mn.copy(t.ray).applyMatrix4(gn),_n.setFromMatrixScale(e.matrixWorld),hn.copy(mn.direction).multiply(_n);let i=hn.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(mn,r,a,o);i=fn(i,e,t),i&&n.push(i)}else{let i=this.raycast(mn,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=fn(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?Ut:vt)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?Wt:St;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?qt:Tt;for(let s=0,c=i.length;s<c;s++){let i=o(this,s,t,e,n,r);i!=null&&(a==null||i.distance<a.distance)&&(a=i)}return a}intersectsGeometry(e,t){let n=!1,r=this._roots,i=this.indirect?tn:Nt;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=G.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?xt:_t});return G.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=G.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{Y(o,this.resolveTriangleIndex(e)*3,s,c)}:e=>{Y(o,e*3,s,c)},u=G.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{Y(u,t.resolveTriangleIndex(e)*3,d,f)}:e=>{Y(u,e*3,d,f)};if(a){if(!(t instanceof e))throw Error(`MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.`);let r=(e,t,r,i,s,c,d,f)=>{for(let m=r,h=r+i;m<h;m++){p(m),u.a.applyMatrix4(n),u.b.applyMatrix4(n),u.c.applyMatrix4(n),u.needsUpdate=!0;for(let n=e,r=e+t;n<r;n++)if(l(n),o.needsUpdate=!0,a(o,u,n,m,s,c,d,f))return!0}return!1};if(i){let e=i;i=function(t,n,i,a,o,s,c,l){return e(t,n,i,a,o,s,c,l)?!0:r(t,n,i,a,o,s,c,l)}}else i=r}return super.bvhcast(t,n,{intersectsRanges:i})}intersectsBox(e,t){return pn.set(e.min,e.max,t),pn.needsUpdate=!0,this.shapecast({intersectsBounds:e=>pn.intersectsBox(e),intersectsTriangle:e=>pn.intersectsTriangle(e)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},r={},i=0,a=1/0){return(this.indirect?dn:Ht)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return tt(this,e,t,n,r)}},bn={Mesh:l.prototype.raycast,Line:m.prototype.raycast,LineSegments:n.prototype.raycast,LineLoop:a.prototype.raycast,Points:f.prototype.raycast,BatchedMesh:_.prototype.raycast},Z=new l,xn=[];function Sn(e,t){if(this.isBatchedMesh)Cn.call(this,e,t);else{let{geometry:r}=this;if(r.boundsTree)r.boundsTree.raycastObject3D(this,e,t);else{let r;if(this instanceof l)r=bn.Mesh;else if(this instanceof n)r=bn.LineSegments;else if(this instanceof a)r=bn.LineLoop;else if(this instanceof m)r=bn.Line;else if(this instanceof f)r=bn.Points;else throw Error(`BVH: Fallback raycast function not found.`);r.call(this,e,t)}}}function Cn(e,t){if(this.boundsTrees){let n=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,a=this.matrixWorld;Z.material=this.material,Z.geometry=this.geometry;let o=Z.geometry.boundsTree,s=Z.geometry.drawRange;Z.geometry.boundingSphere===null&&(Z.geometry.boundingSphere=new g);for(let o=0,s=r.length;o<s;o++){if(!this.getVisibleAt(o))continue;let s=r[o].geometryIndex;if(Z.geometry.boundsTree=n[s],this.getMatrixAt(o,Z.matrixWorld).premultiply(a),!Z.geometry.boundsTree){this.getBoundingBoxAt(s,Z.geometry.boundingBox),this.getBoundingSphereAt(s,Z.geometry.boundingSphere);let e=i[s];Z.geometry.setDrawRange(e.start,e.count)}Z.raycast(e,xn);for(let e=0,n=xn.length;e<n;e++){let n=xn[e];n.object=this,n.batchId=o,t.push(n)}xn.length=0}Z.geometry.boundsTree=o,Z.geometry.drawRange=s,Z.material=null,Z.geometry=null}else bn.BatchedMesh.call(this,e,t)}function wn(e={}){let{type:t=yn}=e;return this.boundsTree=new t(this,e),this.boundsTree}var Q=new e,$=new e,Tn=new e,En=new p,Dn=new e,On=new e,kn=new p,An=new p,jn=new s,Mn=new s;function Nn(e,t){if(!e&&!t)return;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;if(!n||!r||!i||!a)throw Error()}function Pn(e,t=null){let n=e.array.constructor,r=e.normalized,i=e.itemSize;return new v(new n(i*(t===null?e.count:t)),i,r)}function Fn(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function In(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function Ln(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;kn.fromBufferAttribute(i.attributes.skinIndex,t),An.fromBufferAttribute(i.attributes.skinWeight,t),jn.elements.fill(0);for(let e=0;e<4;e++){let t=An.getComponent(e);if(t!==0){let n=kn.getComponent(e);Mn.multiplyMatrices(a[n].matrixWorld,o[n]),In(jn,Mn,t)}}return jn.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(jn),n}function Rn(e,t,n,r,i){Dn.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(On.fromBufferAttribute(s,r),n?Dn.addScaledVector(On,o):Dn.addScaledVector(On.sub(i),o))}i.add(Dn)}function zn(e,t={useGroups:!1,updateIndex:!1,skipAttributes:[]},n=new o){let r=e[0].index!==null,{useGroups:i=!1,updateIndex:a=!1,skipAttributes:s=[]}=t,c=new Set(Object.keys(e[0].attributes)),l={},u=0;n.clearGroups();for(let t=0;t<e.length;++t){let a=e[t],o=0;if(r!==(a.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in a.attributes){if(!c.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);l[e]===void 0&&(l[e]=[]),l[e].push(a.attributes[e]),o++}if(o!==c.size)throw Error(`StaticGeometryGenerator: Make sure all geometries have the same number of attributes.`);if(i){let e;if(r)e=a.index.count;else if(a.attributes.position!==void 0)e=a.attributes.position.count;else throw Error(`StaticGeometryGenerator: The geometry must have either an index or a position attribute`);n.addGroup(u,e,t),u+=e}}if(r){let t=!1;if(!n.index){let r=0;for(let t=0;t<e.length;++t)r+=e[t].index.count;n.setIndex(new v(new Uint32Array(r),1,!1)),t=!0}if(a||t){let t=n.index,r=0,i=0;for(let n=0;n<e.length;++n){let a=e[n],o=a.index;if(s[n]!==!0)for(let e=0;e<o.count;++e)t.setX(r,o.getX(e)+i),r++;i+=a.attributes.position.count}}}for(let e in l){let t=l[e];if(!(e in n.attributes)){let r=0;for(let e in t)r+=t[e].count;n.setAttribute(e,Pn(l[e][0],r))}let r=n.attributes[e],i=0;for(let e=0,n=t.length;e<n;e++){let n=t[e];s[e]!==!0&&Fn(n,r,i),i+=n.count}}return n}function Bn(e,t){if(e===null||t===null)return e===t;if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function Vn(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}var Hn=class{constructor(e){this.matrixWorld=new s,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){let e=this.mesh,t=e.geometry,n=e.skeleton,r=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=r,n){n.boneTexture||n.computeBoneTexture(),n.update();let e=n.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==e.length?this.boneMatrices=e.slice():this.boneMatrices.set(e)}else this.boneMatrices=null}didChange(){let e=this.mesh,t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Bn(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===n)}},Un=class{constructor(e){Array.isArray(e)||(e=[e]);let t=[];e.forEach(e=>{e.traverseVisible(e=>{e.isMesh&&t.push(e)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=[`position`,`normal`,`color`,`tangent`,`uv`,`uv2`],this._intermediateGeometry=Array(t.length).fill().map(()=>new o),this._diffMap=new WeakMap}getMaterials(){let e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new o){let t=[],{meshes:n,useGroups:r,_intermediateGeometry:i,_diffMap:a}=this;for(let e=0,r=n.length;e<r;e++){let r=n[e],o=i[e],s=a.get(r);!s||s.didChange(r)?(this._convertToStaticGeometry(r,o),t.push(!1),s?s.update():a.set(r,new Hn(r))):t.push(!0)}if(i.length===0){e.setIndex(null);let t=e.attributes;for(let n in t)e.deleteAttribute(n);for(let t in this.attributes)e.setAttribute(this.attributes[t],new v(new Float32Array,4,!1))}else zn(i,{useGroups:r,skipAttributes:t},e);for(let t in e.attributes)e.attributes[t].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new o){let n=e.geometry,r=this.applyWorldTransforms,i=this.attributes.includes(`normal`),a=this.attributes.includes(`tangent`),s=n.attributes,l=t.attributes;!t.index&&n.index&&(t.index=n.index.clone()),l.position||t.setAttribute(`position`,Pn(s.position)),i&&!l.normal&&s.normal&&t.setAttribute(`normal`,Pn(s.normal)),a&&!l.tangent&&s.tangent&&t.setAttribute(`tangent`,Pn(s.tangent)),Nn(n.index,t.index),Nn(s.position,l.position),i&&Nn(s.normal,l.normal),a&&Nn(s.tangent,l.tangent);let u=s.position,d=i?s.normal:null,f=a?s.tangent:null,p=n.morphAttributes.position,m=n.morphAttributes.normal,h=n.morphAttributes.tangent,g=n.morphTargetsRelative,_=e.morphTargetInfluences,v=new c;v.getNormalMatrix(e.matrixWorld),n.index&&t.index.array.set(n.index.array);for(let t=0,n=s.position.count;t<n;t++)Q.fromBufferAttribute(u,t),d&&$.fromBufferAttribute(d,t),f&&(En.fromBufferAttribute(f,t),Tn.fromBufferAttribute(f,t)),_&&(p&&Rn(p,_,g,t,Q),m&&Rn(m,_,g,t,$),h&&Rn(h,_,g,t,Tn)),e.isSkinnedMesh&&(e.applyBoneTransform(t,Q),d&&Ln(e,t,$),f&&Ln(e,t,Tn)),r&&Q.applyMatrix4(e.matrixWorld),l.position.setXYZ(t,Q.x,Q.y,Q.z),d&&(r&&$.applyNormalMatrix(v),l.normal.setXYZ(t,$.x,$.y,$.z)),f&&(r&&Tn.transformDirection(e.matrixWorld),l.tangent.setXYZW(t,Tn.x,Tn.y,Tn.z,En.w));for(let e in this.attributes){let n=this.attributes[e];n===`position`||n===`tangent`||n===`normal`||!(n in s)||(l[n]||t.setAttribute(n,Pn(s[n])),Nn(s[n],l[n]),Fn(s[n],l[n]))}return e.matrixWorld.determinant()<0&&Vn(t),t}},Wn=class{constructor(e){this.name=`WorkerBase`,this.running=!1,this.worker=e,this.worker.onerror=e=>{throw e.message?Error(`${this.name}: Could not create Web Worker with error "${e.message}"`):Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw Error(`GenerateMeshBVHWorker: Already running job.`);if(this.worker===null)throw Error(`GenerateMeshBVHWorker: Worker has been disposed.`);this.running=!0;let t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}};export{yn as a,qe as c,C as d,wn as i,Ke as l,Un as n,W as o,Sn as r,U as s,Wn as t,Le as u}; |