softbox 4.26.0 → 4.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ThreePathTracingService-BF9N0xLz.js → ThreePathTracingService-WxrUCt06.js} +446 -456
- package/dist/{ThreePathTracingService-Cfn0abhM.cjs → ThreePathTracingService-vIumWBEY.cjs} +4 -4
- package/dist/index.d.cts +0 -564
- package/dist/index.d.ts +0 -564
- package/dist/simple-viewer.cjs +7 -17
- package/dist/simple-viewer.es.js +3515 -4154
- package/dist/{smoothstep-gC155W8-.js → smoothstep-DJLgqxNL.js} +272 -362
- package/dist/smoothstep-DoPxvpnb.cjs +2 -0
- package/package.json +1 -1
- package/dist/smoothstep-BsyRnZAu.cjs +0 -2
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("three");c=s(c,1);var l=class e extends Error{constructor(t,n,r){super(t),this.code=n,this.context=r,this.name=`ThreeViewerError`,this.timestamp=new Date,Error.captureStackTrace&&Error.captureStackTrace(this,e)}static fromError(t,n,r){if(t instanceof e)return t;let i=t instanceof Error?t.message:String(t),a={...r,originalError:t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:t};return new e(i,n,a)}},u=function(e){return e.SCENE_INIT_FAILED=`SCENE_INIT_FAILED`,e.RENDERER_INIT_FAILED=`RENDERER_INIT_FAILED`,e.RENDERER_NOT_INITIALIZED=`RENDERER_NOT_INITIALIZED`,e.CAMERA_INIT_FAILED=`CAMERA_INIT_FAILED`,e.WEBGL_NOT_SUPPORTED=`WEBGL_NOT_SUPPORTED`,e.INITIALIZATION_FAILED=`INITIALIZATION_FAILED`,e.PATH_TRACING_INIT_FAILED=`PATH_TRACING_INIT_FAILED`,e.MODEL_LOAD_FAILED=`MODEL_LOAD_FAILED`,e.TEXTURE_LOAD_FAILED=`TEXTURE_LOAD_FAILED`,e.RESOURCE_NOT_FOUND=`RESOURCE_NOT_FOUND`,e.UNSUPPORTED_FORMAT=`UNSUPPORTED_FORMAT`,e.INVALID_CONFIGURATION=`INVALID_CONFIGURATION`,e.RENDER_ERROR=`RENDER_ERROR`,e.RENDER_FAILED=`RENDER_FAILED`,e.SCENE_OPERATION_FAILED=`SCENE_OPERATION_FAILED`,e.COMPONENT_NOT_MOUNTED=`COMPONENT_NOT_MOUNTED`,e.INVALID_STATE=`INVALID_STATE`,e.INVALID_PARAMETER=`INVALID_PARAMETER`,e.OPERATION_FAILED=`OPERATION_FAILED`,e.POST_PROCESSING_FAILED=`POST_PROCESSING_FAILED`,e.UNKNOWN=`UNKNOWN`,e}({}),d={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}},wrap(e){try{return d.ok(e())}catch(e){return d.err(e instanceof l?e:new l(String(e),u.UNKNOWN,{originalError:e}))}}},f=class{constructor(){this.listeners=new Map}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set);let n=this.listeners.get(e);return n&&n.add(t),()=>{this.listeners.get(e)?.delete(t)}}emit(e,t){this.listeners.get(e)?.forEach(n=>{try{n(t)}catch(t){console.error(`Error in event listener for ${String(e)}:`,t)}})}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}removeAllListeners(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){return this.listeners.get(e)?.size||0}off(e,t){this.listeners.get(e)?.delete(t)}removeListener(e,t){this.off(e,t)}},p={meters:1,centimeters:.01,millimeters:.001,feet:.3048,inches:.0254},m=`softbox-units-scale`,h=`softboxExternallyOwnedTextures`,g=`softboxBackgroundNode`,_=`softboxStashedMaterials`;function v(e){if(!e.userData.softboxDisposed){if(!e.userData?.softboxExternallyOwnedTextures){let t=e;for(let e of Object.keys(t)){let n=t[e];n instanceof c.Texture&&n.dispose()}let n=e;if(n.isShaderMaterial&&n.uniforms)for(let e of Object.values(n.uniforms))e?.value instanceof c.Texture&&e.value.dispose()}e.dispose(),e.userData.softboxDisposed=!0}}function y(e){e.boundsTree&&=void 0}function b(e){e.traverse(e=>{let t=e;t.geometry&&typeof t.geometry.dispose==`function`&&(y(t.geometry),t.geometry.dispose());let n=t.material;Array.isArray(n)?n.forEach(v):n&&v(n),(e.userData?.[_])?.forEach(v);let r=e;r.isLight&&r.shadow?.dispose&&r.shadow.dispose()})}function x(e,t){if(!t?.keepBackgrounds){e.background instanceof c.Texture&&(e.background.dispose(),e.background=null),e.environment instanceof c.Texture&&(e.environment.dispose(),e.environment=null);let t=e;t.__originalEnvironmentTexture&&=void 0}for(let n of[...e.children])t?.keepBackgrounds&&n.userData?.softboxBackgroundNode||(b(n),e.remove(n))}var S=1.25,C=65535,w=C<<16,T=2**-24,ee=Symbol(`SKIP_GENERATION`),te={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[ee]:!1};function E(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 ne(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 re(e,t){t.set(e)}function D(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 ie(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 O(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 k(e,t){return t[e+15]===C}function A(e,t){return t[e+6]}function j(e,t){return t[e+14]}function M(e){return e+8}function N(e,t){return e+t[e+6]*8}function ae(e,t){return t[e+7]}function P(e){return e}function oe(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 F=32,se=(e,t)=>e.candidate-t.candidate,I=Array(F).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ce=new Float32Array(6);function le(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=ne(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=ne(e),o!==-1&&(s=ue(n,r,i,o));else if(a===2){let a=O(e),c=S*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)/F;if(i<F/4){let t=[...I];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;ie(i,n,o)}t.sort(se);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?ie(r,n,a.rightCacheBounds):(ie(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=O(d)/a);let m=0;u!==0&&(m=O(f)/a);let h=1+S*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<F;e++){let t=I[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>=F&&(i=F-1);let a=I[i];a.count++,ie(t,n,a.bounds)}let t=I[F-1];re(t.bounds,t.rightCacheBounds);for(let e=F-2;e>=0;e--){let t=I[e],n=I[e+1];D(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<F-1;t++){let n=I[t],r=n.count,l=n.bounds,u=I[t+1].rightCacheBounds;r!==0&&(f===0?re(l,ce):D(l,ce,ce)),f+=r;let d=0,p=0;f!==0&&(d=O(ce)/a);let m=i-f;m!==0&&(p=O(u)/a);let h=1+S*(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 ue(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 de=class{constructor(){this.boundingData=new Float32Array(6)}};function fe(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 pe,me,he,ge,_e=2**32;function ve(e){return`count`in e?1:1+ve(e.left)+ve(e.right)}function ye(e,t,n){return pe=new Float32Array(n),me=new Uint32Array(n),he=new Uint16Array(n),ge=new Uint8Array(n),be(e,t)}function be(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)pe[n+e]=a[e];if(i)return t.buffer?(ge.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(me[n+6]=t.offset,he[r+14]=t.count,he[r+15]=C,e+32);{let{left:r,right:i,splitAxis:a}=t,o=be(e+32,r),s=e/32,c=o/32-s;if(c>_e)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return me[n+6]=c,me[n+7]=a,be(o,i)}}function xe(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new de;return oe(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=le(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:fe(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,ne(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new de,x=n,S=y-n;e.left=b,oe(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new de,w=y,T=r-S;return e.right=C,oe(t,w,T,C.boundingData,m),v(C,w,T,m,a+1),e}}function Se(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=xe(e,s,r.offset,r.count,t,o),a=ve(i),c=new n(32*a);return ye(0,i,c),c})}var Ce=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)}},L=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())}}},R,z,B=[],we=new Ce(()=>new c.Box3);function Te(e,t,n,r,i,a){R=we.getPrimitive(),z=we.getPrimitive(),B.push(R,z),L.setBuffer(e._roots[t]);let o=Ee(0,e.geometry,n,r,i,a);L.clearBuffer(),we.releasePrimitive(R),we.releasePrimitive(z),B.pop(),B.pop();let s=B.length;return s>0&&(z=B[s-1],R=B[s-2]),o}function Ee(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(k(u,c)){let t=A(e,l),n=j(u,c);return E(P(e),s,R),r(t,n,!1,o,a+e/8,R)}else{let u=M(e),p=N(e,l),m=u,h=p,g,_,v,y;if(i&&(v=R,y=z,E(P(m),s,v),E(P(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=R,E(P(m),s,v));let b=k(m*2,c),x=n(v,b,g,o+1,a+m/8),S;if(x===2){let e=d(m);S=r(e,f(m)-e,!0,o+1,a+m/8,v)}else S=x&&Ee(m,t,n,r,i,a,o+1);if(S)return!0;y=z,E(P(h),s,y);let C=k(h*2,c),w=n(y,C,_,o+1,a+h/8),T;if(w===2){let e=d(h);T=r(e,f(h)-e,!0,o+1,a+h/8,y)}else T=w&&Ee(h,t,n,r,i,a,o+1);if(T)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=L,r=e*2;for(;!k(r,t);)e=M(e),r=e*2;return A(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=L,r=e*2;for(;!k(r,t);)e=N(e,n),r=e*2;return A(e,n)+j(r,t)}}}var De=new L.constructor,Oe=new L.constructor,V=new Ce(()=>new c.Box3),ke=new c.Box3,Ae=new c.Box3,je=new c.Box3,Me=new c.Box3,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,s=0,l=0,u=new c.Matrix4().copy(n).invert();for(let e=0,t=i.length;e<t;e++){De.setBuffer(i[e]),l=0;let t=V.getPrimitive();E(P(0),De.float32Array,t),t.applyMatrix4(u);for(let e=0,i=a.length;e<i&&(Oe.setBuffer(a[e]),o=H(0,0,n,u,r,s,l,0,0,t),Oe.clearBuffer(),l+=a[e].byteLength/32,!o);e++);if(V.releasePrimitive(t),De.clearBuffer(),s+=i[e].byteLength/32,o)break}return Ne=!1,o}function H(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=k(y,h),S=k(b,v),C=!1;if(S&&x)C=u?i(A(t,_),j(t*2,v),A(e,m),j(e*2,h),c,o+t/8,s,a+e/8):i(A(e,m),j(e*2,h),A(t,_),j(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=V.getPrimitive();E(P(t),g,l),l.applyMatrix4(n);let d=M(e),f=N(e,m);E(P(d),p,ke),E(P(f),p,Ae);let h=l.intersectsBox(ke),_=l.intersectsBox(Ae);C=h&&H(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&H(t,f,r,n,i,o,a,c,s+1,l,!u),V.releasePrimitive(l)}else{let d=M(t),f=N(t,_);E(P(d),g,je),E(P(f),g,Me);let h=l.intersectsBox(je),v=l.intersectsBox(Me);if(h&&v)C=H(e,d,n,r,i,a,o,s,c+1,l,u)||H(e,f,n,r,i,a,o,s,c+1,l,u);else if(h)if(x)C=H(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=V.getPrimitive();t.copy(je).applyMatrix4(n);let l=M(e),f=N(e,m);E(P(l),p,ke),E(P(f),p,Ae);let h=t.intersectsBox(ke),g=t.intersectsBox(Ae);C=h&&H(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&H(d,f,r,n,i,o,a,c,s+1,t,!u),V.releasePrimitive(t)}else if(v)if(x)C=H(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=V.getPrimitive();t.copy(Me).applyMatrix4(n);let l=M(e),d=N(e,m);E(P(l),p,ke),E(P(d),p,Ae);let h=t.intersectsBox(ke),g=t.intersectsBox(Ae);C=h&&H(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&H(f,d,r,n,i,o,a,c,s+1,t,!u),V.releasePrimitive(t)}}return C}var Fe=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!k(r,n);)e=M(e),r=e*2;return A(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!k(r,n);)e=N(e,t),r=e*2;return A(e,t)+j(r,n)};let i=(e,r,a)=>{let o=k(r*2,n);if(!e(a,o,r)&&!o){let n=M(r),o=N(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}else{let n=ae(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Ie=new c.Box3,Le=new Float32Array(6),Re=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...te,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),Se(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,Le,0);let[e,t,r,u,d,f]=Le;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,Le,0);let[e,t,a,o,s,c]=Le,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)*T,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*T,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*T}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;k(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Fe.setBVH(this,t),Fe.traverse(e),Fe.reset()}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(k(n,i)){let e=A(t,r),o=j(n,i);this.writePrimitiveRangeBounds(e,o,Le,0),a.set(Le,t)}else{let e=M(t),n=N(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=>{E(0,new Float32Array(t),Ie),e.union(Ie)}),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 ze(){return typeof SharedArrayBuffer<`u`}function Be(e){return e.index?e.index.count:e.attributes.position.count}function Ve(e){return Be(e)/3}function He(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function Ue(e,t){if(!e.index){let n=e.attributes.position.count,r=He(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new c.BufferAttribute(r,1));for(let e=0;e<n;e++)r[e]=e}}function We(e,t,n){let r=Be(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 Ge(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Ke(e,t,n){let r=We(e,t,n),i=Ge(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Be(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 qe(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 Je=class extends Re{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&&!ze())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={...te,...t},t[ee]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=qe(Ke(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else Ue(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new c.Box3))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ke(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},U=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}};U.prototype.setFromBox=(function(){let e=new c.Vector3;return function(t,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++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var Ye=(function(){let e=new c.Vector3,t=new c.Vector3,n=new c.Vector3;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.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}})(),Xe=(function(){let e=new c.Vector2,t=new c.Vector3,n=new c.Vector3;return function(r,i,a,o){Ye(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}else if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}else if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}else{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}else{a.copy(e),o.copy(d);return}}}})(),Ze=(function(){let e=new c.Vector3,t=new c.Vector3,n=new c.Plane,r=new c.Line3;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),Qe=[`x`,`y`,`z`],W=1e-15,$e=W*W;function G(e){return Math.abs(e)<W}var K=class extends c.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new c.Vector3),this.satBounds=[,,,,].fill().map(()=>new U),this.points=[this.a,this.b,this.c],this.plane=new c.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new c.Line3,this.needsUpdate=!0}intersectsSphere(e){return Ze(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<W?h<W||g<W?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<W?g<W?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<W&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};K.prototype.closestPointToSegment=(function(){let e=new c.Vector3,t=new c.Vector3,n=new c.Line3;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),Xe(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),K.prototype.intersectsTriangle=(function(){let e=new K,t=new U,n=new U,r=new c.Vector3,i=new c.Vector3,a=new c.Vector3,o=new c.Vector3,s=new c.Line3,l=new c.Line3,u=new c.Vector3,d=new c.Vector2,f=new c.Vector2;function p(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function m(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 h(e,t,n,r,i,a,o,s,c,l,u){if(i>0)m(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)m(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)m(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)m(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)m(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function g(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return G(o)?G(s)?p(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):G(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)==null?!1:(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function _(e,t,n){let r=t.a;return G(e.plane.distanceToPoint(r))&&e.containsPoint(r)?(n&&(n.start.copy(r),n.end.copy(r)),!0):!1}function v(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<$e?(n&&(n.start.copy(a),n.end.copy(a)),!0):!1}function y(e,t,n,o){if(e.isDegenerateIntoSegment)if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.start),d=c.x*l.y-c.y*l.x;if(G(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:G(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}else if(t.isDegenerateIntoPoint)return v(e,t,n);else return g(t,e,n,o);else if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<$e?(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):!1:t.isDegenerateIntoSegment?v(t,e,n):_(t,e,n);else if(t.isDegenerateIntoPoint)return _(e,t,n);else if(t.isDegenerateIntoSegment)return g(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=y(this,t,n,r);if(o!==void 0)return o;let c=this.plane,m=t.plane,g=m.distanceToPoint(this.a),_=m.distanceToPoint(this.b),v=m.distanceToPoint(this.c);G(g)&&(g=0),G(_)&&(_=0),G(v)&&(v=0);let b=g*_,x=g*v;if(b>0&&x>0)return!1;let S=c.distanceToPoint(t.a),C=c.distanceToPoint(t.b),w=c.distanceToPoint(t.c);G(S)&&(S=0),G(C)&&(C=0),G(w)&&(w=0);let T=S*C,ee=S*w;if(T>0&&ee>0)return!1;i.copy(c.normal),a.copy(m.normal);let te=i.cross(a),E=0,ne=Math.abs(te.x),re=Math.abs(te.y);re>ne&&(ne=re,E=1),Math.abs(te.z)>ne&&(E=2);let D=Qe[E],ie=this.a[D],O=this.b[D],k=this.c[D],A=t.a[D],j=t.b[D],M=t.c[D];if(h(this,ie,O,k,b,x,g,_,v,d,s)||h(t,A,j,M,T,ee,S,C,w,f,l))return p(this,t,n,r);if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,u.copy(s.start),s.start.copy(s.end),s.end.copy(u)}if(f.y<f.x){let e=f.y;f.y=f.x,f.x=e,u.copy(l.start),l.start.copy(l.end),l.end.copy(u)}return d.y<f.x||f.y<d.x?!1:(n&&(f.x>d.x?n.start.copy(l.start):n.start.copy(s.start),f.y<d.y?n.end.copy(l.end):n.end.copy(s.end)),!0)}})(),K.prototype.distanceToPoint=(function(){let e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),K.prototype.distanceToTriangle=(function(){let e=new c.Vector3,t=new c.Vector3,n=[`a`,`b`,`c`],r=new c.Line3,i=new c.Line3;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),Xe(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var q=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new c.Vector3,this.max=new c.Vector3,this.matrix=new c.Matrix4,this.invMatrix=new c.Matrix4,this.points=Array(8).fill().map(()=>new c.Vector3),this.satAxes=[,,,].fill().map(()=>new c.Vector3),this.satBounds=[,,,].fill().map(()=>new U),this.alignedSatBounds=[,,,].fill().map(()=>new U),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}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}};q.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}})(),q.prototype.intersectsBox=(function(){let e=new U;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}})(),q.prototype.intersectsTriangle=(function(){let e=new K,t=[,,,],n=new U,r=new U,i=new c.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))return!1}}return!0}})(),q.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}})(),q.prototype.distanceToPoint=(function(){let e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),q.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new c.Line3),n=Array(12).fill().map(()=>new c.Line3),r=new c.Vector3,i=new c.Vector3;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[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++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];Xe(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var J=new class extends Ce{constructor(){super(()=>new K)}},et=new c.Vector3,tt=new c.Vector3;function nt(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=>(et.copy(t).clamp(e.min,e.max),et.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,et);let r=t.distanceToSquared(et);return r<s&&(tt.copy(et),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(tt):n.point=tt.clone(),n.distance=l,n.faceIndex=c,n}var rt=parseInt(c.REVISION)>=169,it=parseInt(c.REVISION)<=161,Y=new c.Vector3,X=new c.Vector3,Z=new c.Vector3,at=new c.Vector2,ot=new c.Vector2,st=new c.Vector2,ct=new c.Vector3,lt=new c.Vector3,ut=new c.Vector3,dt=new c.Vector3;function ft(e,t,n,r,i,a,o,s){let l;if(l=a===c.BackSide?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==c.DoubleSide,i),l===null)return null;let u=e.origin.distanceTo(i);return u<o||u>s?null:{distance:u,point:i.clone()}}function pt(e,t,n,r,i,a,o,s,l,u,d){Y.fromBufferAttribute(t,a),X.fromBufferAttribute(t,o),Z.fromBufferAttribute(t,s);let f=ft(e,Y,X,Z,dt,l,u,d);if(f){if(r){at.fromBufferAttribute(r,a),ot.fromBufferAttribute(r,o),st.fromBufferAttribute(r,s),f.uv=new c.Vector2;let e=c.Triangle.getInterpolation(dt,Y,X,Z,at,ot,st,f.uv);rt||(f.uv=e)}if(i){at.fromBufferAttribute(i,a),ot.fromBufferAttribute(i,o),st.fromBufferAttribute(i,s),f.uv1=new c.Vector2;let e=c.Triangle.getInterpolation(dt,Y,X,Z,at,ot,st,f.uv1);rt||(f.uv1=e),it&&(f.uv2=f.uv1)}if(n){ct.fromBufferAttribute(n,a),lt.fromBufferAttribute(n,o),ut.fromBufferAttribute(n,s),f.normal=new c.Vector3;let t=c.Triangle.getInterpolation(dt,Y,X,Z,ct,lt,ut,f.normal);f.normal.dot(e.direction)>0&&f.normal.multiplyScalar(-1),rt||(f.normal=t)}let t={a,b:o,c:s,normal:new c.Vector3,materialIndex:0};if(c.Triangle.getNormal(Y,X,Z,t.normal),f.face=t,f.faceIndex=a,rt){let e=new c.Vector3;c.Triangle.getBarycoord(dt,Y,X,Z,e),f.barycoord=e}}return f}function mt(e){return e&&e.isMaterial?e.side:e}function ht(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=mt(t[v]),s=pt(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=mt(t),s=pt(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 Q(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 gt(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)ht(c,t,n,e,a,o,s)}function _t(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=ht(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function vt(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,Q(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function yt(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(k(l,s)){let t=A(e,o),n=j(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=M(e),i=N(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 $(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 bt(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)ht(c,t,n,l?l[e]:e,a,o,s)}function xt(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=ht(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function St(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),Q(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ct(e,t,n,r,i,a,o){L.setBuffer(e._roots[t]),wt(0,e,n,r,i,a,o),L.clearBuffer()}function wt(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(k(u,c))gt(t,n,r,A(e,l),j(u,c),i,a,o);else{let c=M(e);$(c,s,r,a,o)&&wt(c,t,n,r,i,a,o);let u=N(e,l);$(u,s,r,a,o)&&wt(u,t,n,r,i,a,o)}}var Tt=[`x`,`y`,`z`];function Et(e,t,n,r,i,a){L.setBuffer(e._roots[t]);let o=Dt(0,e,n,r,i,a);return L.clearBuffer(),o}function Dt(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=L,l=e*2;if(k(l,s))return _t(t,n,r,A(e,c),j(l,s),i,a);{let s=ae(e,c),l=Tt[s],u=r.direction[l]>=0,d,f;u?(d=M(e),f=N(e,c)):(d=N(e,c),f=M(e));let p=$(d,o,r,i,a)?Dt(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=$(f,o,r,i,a)?Dt(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Ot=new c.Box3,kt=new K,At=new K,jt=new c.Matrix4,Mt=new q,Nt=new q;function Pt(e,t,n,r){L.setBuffer(e._roots[t]);let i=Ft(0,e,n,r);return L.clearBuffer(),i}function Ft(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=L,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Mt.set(n.boundingBox.min,n.boundingBox.max,r),i=Mt),k(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=A(e,s),m=j(c,o);if(jt.copy(r).invert(),n.boundsTree)return E(P(e),a,Nt),Nt.matrix.copy(jt),Nt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Nt.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(Q(At,t,l,u),At.needsUpdate=!0,e.intersectsTriangle(At))return!0;return!1}});{let e=Ve(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){Q(kt,t,l,u),kt.a.applyMatrix4(jt),kt.b.applyMatrix4(jt),kt.c.applyMatrix4(jt),kt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Q(At,t,d,f),At.needsUpdate=!0,kt.intersectsTriangle(At))return!0}}}else{let o=M(e),c=N(e,s);return E(P(o),a,Ot),!!(i.intersectsBox(Ot)&&Ft(o,t,n,r,i)||(E(P(c),a,Ot),i.intersectsBox(Ot)&&Ft(c,t,n,r,i)))}}var It=new c.Matrix4,Lt=new q,Rt=new q,zt=new c.Vector3,Bt=new c.Vector3,Vt=new c.Vector3,Ht=new c.Vector3;function Ut(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Lt.set(t.boundingBox.min,t.boundingBox.max,n),Lt.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=J.getPrimitive(),p=J.getPrimitive(),m=zt,h=Bt,g=null,_=null;i&&(g=Vt,_=Ht);let v=1/0,y=null,b=null;return It.copy(n).invert(),Rt.matrix.copy(It),e.shapecast({boundsTraverseOrder:e=>Lt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(Rt.min.copy(e.min),Rt.max.copy(e.max),Rt.needsUpdate=!0),!0):!1,intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Rt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){Q(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++){Q(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=Ve(t);for(let t=0,o=i;t<o;t++){Q(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++){Q(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}}}}}),J.releasePrimitive(f),J.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(It),h.applyMatrix4(It),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Wt(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(k(u,s)){let t=A(n,o),a=j(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=M(n),r=N(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 Gt(e,t,n,r,i,a,o){L.setBuffer(e._roots[t]),Kt(0,e,n,r,i,a,o),L.clearBuffer()}function Kt(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(k(u,c))bt(t,n,r,A(e,l),j(u,c),i,a,o);else{let c=M(e);$(c,s,r,a,o)&&Kt(c,t,n,r,i,a,o);let u=N(e,l);$(u,s,r,a,o)&&Kt(u,t,n,r,i,a,o)}}var qt=[`x`,`y`,`z`];function Jt(e,t,n,r,i,a){L.setBuffer(e._roots[t]);let o=Yt(0,e,n,r,i,a);return L.clearBuffer(),o}function Yt(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=L,l=e*2;if(k(l,s))return xt(t,n,r,A(e,c),j(l,s),i,a);{let s=ae(e,c),l=qt[s],u=r.direction[l]>=0,d,f;u?(d=M(e),f=N(e,c)):(d=N(e,c),f=M(e));let p=$(d,o,r,i,a)?Yt(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=$(f,o,r,i,a)?Yt(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Xt=new c.Box3,Zt=new K,Qt=new K,$t=new c.Matrix4,en=new q,tn=new q;function nn(e,t,n,r){L.setBuffer(e._roots[t]);let i=rn(0,e,n,r);return L.clearBuffer(),i}function rn(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=L,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),en.set(n.boundingBox.min,n.boundingBox.max,r),i=en),k(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=A(e,s),m=j(c,o);if($t.copy(r).invert(),n.boundsTree)return E(P(e),a,tn),tn.matrix.copy($t),tn.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>tn.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(Q(Qt,3*t.resolveTriangleIndex(n),l,u),Qt.needsUpdate=!0,e.intersectsTriangle(Qt))return!0;return!1}});{let e=Ve(n);for(let n=p,r=m+p;n<r;n++){Q(Zt,3*t.resolveTriangleIndex(n),l,u),Zt.a.applyMatrix4($t),Zt.b.applyMatrix4($t),Zt.c.applyMatrix4($t),Zt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Q(Qt,t,d,f),Qt.needsUpdate=!0,Zt.intersectsTriangle(Qt))return!0}}}else{let o=M(e),c=N(e,s);return E(P(o),a,Xt),!!(i.intersectsBox(Xt)&&rn(o,t,n,r,i)||(E(P(c),a,Xt),i.intersectsBox(Xt)&&rn(c,t,n,r,i)))}}var an=new c.Matrix4,on=new q,sn=new q,cn=new c.Vector3,ln=new c.Vector3,un=new c.Vector3,dn=new c.Vector3;function fn(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),on.set(t.boundingBox.min,t.boundingBox.max,n),on.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=J.getPrimitive(),p=J.getPrimitive(),m=cn,h=ln,g=null,_=null;i&&(g=un,_=dn);let v=1/0,y=null,b=null;return an.copy(n).invert(),sn.matrix.copy(an),e.shapecast({boundsTraverseOrder:e=>on.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(sn.min.copy(e.min),sn.max.copy(e.max),sn.needsUpdate=!0),!0):!1,intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>sn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);Q(p,3*t,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++){let n=e.resolveTriangleIndex(t);Q(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}else{let o=Ve(t);for(let t=0,s=o;t<s;t++){Q(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++){let r=e.resolveTriangleIndex(n);Q(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<a)return!0}}}}}),J.releasePrimitive(f),J.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(an),h.applyMatrix4(an),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function pn(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 mn=new q,hn=new c.Ray,gn=new c.Vector3,_n=new c.Matrix4,vn=new c.Vector3,yn=[`getX`,`getY`,`getZ`],bn=class e extends Je{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.`),l(a));let s=new e(n,{...r,[ee]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new c.BufferAttribute(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function l(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;k(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 "targetLeafSize", instead.`),t={...t,targetLeafSize: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[yn[e]](c),i=a[yn[e]](l),o=a[yn[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)*T}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;_n.copy(e.matrixWorld).invert(),hn.copy(t.ray).applyMatrix4(_n),vn.setFromMatrixScale(e.matrixWorld),gn.copy(hn.direction).multiply(vn);let i=gn.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(hn,r,a,o);i=pn(i,e,t),i&&n.push(i)}else{let i=this.raycast(hn,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=pn(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?Wt:yt)(this,e)}raycast(e,t=c.FrontSide,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?Gt:Ct;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=c.FrontSide,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?Jt:Et;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?nn:Pt;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=J.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?St:vt});return J.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=J.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);Q(o,t*3,s,c)}:e=>{Q(o,e*3,s,c)},u=J.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);Q(u,n*3,d,f)}:e=>{Q(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 mn.set(e.min,e.max,t),mn.needsUpdate=!0,this.shapecast({intersectsBounds:e=>mn.intersectsBox(e),intersectsTriangle:e=>mn.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?fn:Ut)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return nt(this,e,t,n,r)}},xn=`contact-shadow-baked`,Sn=`contact-shadow-live`,Cn=`softboxContactShadowHelper`,wn=`softboxPathTracingFloor`,Tn=Math.PI*(3-Math.sqrt(5));function En(e){let t=e.getObjectByName(xn);t&&(e.remove(t),b(t))}function Dn(e){En(e);let t=e.getObjectByName(Sn);t&&(t.visible=!0)}var On=class e{static{this.AMBIENT_RATIO=.62}static{this.LIGHT_APERTURE_DEGREES=13}static{this.DEPTH_PADDING_FACTOR=1.5}static{this.AMBIENT_MAX_ELEVATION_SIN=.98}static{this.AMBIENT_MIN_ELEVATION_DEGREES=55}static{this.ACCUMULATION_TEXTURE_SIZE=1024}static{this.BAKE_SHADOW_MAP_SIZE=1024}static{this.SHADOW_STRENGTH=.55}static{this.DISC_FOOTPRINT_MARGIN=1.4}static{this.DISC_HEIGHT_STRETCH=.45}static{this.DISC_MIN_HALF_EXTENT=.05}static{this.FLOOR_LIFT_PER_HEIGHT=.0025}static{this.FLOOR_LIFT_MIN=2e-4}static{this.FLOOR_LIFT_MAX=.01}static{this.BAKE_BUDGET_MS=100}static{this.MIN_PASSES=24}static{this.MAX_PASSES=96}constructor(e){this.explicitPasses=e?.passes}bake(t){let{renderer:n,scene:r,object:i,light:a}=t;if(n.getContext().isContextLost()){this.leaveLiveCatcherInCharge(r);return}let o=this.measureBakeRegion(i);if(!o)return;let s=r.getObjectByName(Sn);s?.geometry instanceof c.CircleGeometry&&(o.halfExtent=Math.min(o.halfExtent,s.geometry.parameters.radius));let l=new c.WebGLRenderTarget(e.ACCUMULATION_TEXTURE_SIZE,e.ACCUMULATION_TEXTURE_SIZE,{type:n.capabilities.isWebGL2?c.HalfFloatType:c.UnsignedByteType,depthBuffer:!1,stencilBuffer:!1}),u=new c.CircleGeometry(o.halfExtent,64);try{this.accumulateShadowPasses(n,i,a,o,l,u)}catch(e){throw l.dispose(),u.dispose(),e}if(n.getContext().isContextLost()){l.dispose(),u.dispose(),this.leaveLiveCatcherInCharge(r),console.warn(`Contact-shadow bake aborted: WebGL context was lost mid-bake`);return}this.installBakedMesh(r,o,l,u)}leaveLiveCatcherInCharge(e){Dn(e)}evictBakedMesh(e){En(e)}measureBakeRegion(t){let n=new c.Box3().setFromObject(t);if(n.isEmpty()||!Number.isFinite(n.min.x)||!Number.isFinite(n.max.x))return null;let r=n.getSize(new c.Vector3),i=n.getCenter(new c.Vector3),a=Math.max(r.x,r.z);return{center:i,halfExtent:Math.max(a*e.DISC_FOOTPRINT_MARGIN+r.y*e.DISC_HEIGHT_STRETCH,e.DISC_MIN_HALF_EXTENT),objectHeight:r.y,boundingRadius:r.length()/2}}accumulateShadowPasses(e,t,n,r,i,a){let o=new c.Scene,s=t.parent;o.add(t);let l=this.disableColorWrite(t),u=this.createBakeLight(n);o.add(u),o.add(u.target),u.target.position.copy(n.target.parent?n.target.getWorldPosition(new c.Vector3):n.target.position);let d=new c.ShadowMaterial({transparent:!0,opacity:0,depthWrite:!1});d.blending=c.CustomBlending,d.blendEquation=c.AddEquation,d.blendSrc=c.OneFactor,d.blendDst=c.OneFactor;let f=new c.Mesh(a,d);f.rotation.x=-Math.PI/2,f.position.set(r.center.x,0,r.center.z),f.receiveShadow=!0,o.add(f);let p=this.createBakeCamera(r);o.add(p);let m=e.getRenderTarget(),h=e.autoClear,g=e.getClearColor(new c.Color),_=e.getClearAlpha(),v=e.shadowMap.autoUpdate;try{e.shadowMap.autoUpdate=!0,e.setRenderTarget(i),e.setClearColor(0,0),e.clear(!0,!1,!1),e.autoClear=!1;let t=this.explicitPasses??this.measureAffordablePasses(e,o,p,n,u,i);d.opacity=1/t;for(let i of this.sampleLightPositions(n,t))u.position.copy(i),this.fitBakeDepthRange(u,r),e.render(o,p)}finally{e.autoClear=h,e.setClearColor(g,_),e.setRenderTarget(m),e.shadowMap.autoUpdate=v,this.restoreColorWrite(l),s?s.add(t):o.remove(t),u.dispose(),d.dispose()}}measureAffordablePasses(t,n,r,i,a,o){a.position.copy(i.position),t.render(n,r),this.awaitGpuIdle(t,o);let s=performance.now();t.render(n,r),this.awaitGpuIdle(t,o);let l=Math.max(performance.now()-s,.01);return c.MathUtils.clamp(Math.round(e.BAKE_BUDGET_MS/l),e.MIN_PASSES,e.MAX_PASSES)}awaitGpuIdle(e,t){if(!e.capabilities.textureTypeReadable(t.texture.type))return;let n=t.texture.type===c.HalfFloatType?new Uint16Array(4):new Uint8Array(4);e.readRenderTargetPixels(t,0,0,1,1,n)}createBakeLight(t){let n=new c.DirectionalLight(16777215,1);n.castShadow=!0,n.shadow.mapSize.set(e.BAKE_SHADOW_MAP_SIZE,e.BAKE_SHADOW_MAP_SIZE),n.shadow.bias=0,n.shadow.normalBias=0,n.shadow.radius=6;let r=t.shadow.camera,i=n.shadow.camera;return i.left=r.left,i.right=r.right,i.top=r.top,i.bottom=r.bottom,i.updateProjectionMatrix(),n}fitBakeDepthRange(t,n){let r=t.target.position.clone().sub(t.position).normalize(),i=n.center.clone().sub(t.position).dot(r),a=n.boundingRadius*e.DEPTH_PADDING_FACTOR+n.halfExtent,o=t.shadow.camera;o.near=Math.max(i-a,i*.01),o.far=i+a,o.updateProjectionMatrix()}createBakeCamera(e){let t=new c.OrthographicCamera(-e.halfExtent,e.halfExtent,e.halfExtent,-e.halfExtent,.1,Math.max(e.objectHeight,1)*4);return t.position.set(e.center.x,Math.max(e.objectHeight,1)*2,e.center.z),t.up.set(0,0,-1),t.lookAt(e.center.x,0,e.center.z),t.updateProjectionMatrix(),t.updateMatrixWorld(!0),t}sampleLightPositions(t,n){let r=t.position.clone(),i=t.target.parent?t.target.getWorldPosition(new c.Vector3):t.target.position.clone(),a=i.clone().sub(r),o=a.length(),s=a.normalize(),l=new c.Vector3().crossVectors(s,new c.Vector3(0,1,0));l.lengthSq()<1e-6&&l.set(1,0,0),l.normalize();let u=new c.Vector3().crossVectors(s,l),d=Math.round(n*e.AMBIENT_RATIO),f=n-d,p=c.MathUtils.degToRad(e.LIGHT_APERTURE_DEGREES),m=Math.tan(p/2)*o,h=[];for(let e=0;e<f;e++){let t=m*Math.sqrt((e+.5)/f),n=e*Tn;h.push(r.clone().addScaledVector(l,t*Math.cos(n)).addScaledVector(u,t*Math.sin(n)))}let g=Math.sin(c.MathUtils.degToRad(e.AMBIENT_MIN_ELEVATION_DEGREES)),_=e.AMBIENT_MAX_ELEVATION_SIN;for(let e=0;e<d;e++){let t=Math.sqrt((e+.5)/d),n=g+(_-g)*t,r=Math.sqrt(1-n*n),a=e*Tn;h.push(new c.Vector3(r*Math.cos(a),n,r*Math.sin(a)).multiplyScalar(o).add(i))}return h}installBakedMesh(t,n,r,i){this.evictBakedMesh(t);let a=new c.MeshBasicMaterial({map:r.texture,transparent:!0,opacity:e.SHADOW_STRENGTH,depthWrite:!1,toneMapped:!1});a.onBeforeCompile=e=>{e.fragmentShader=e.fragmentShader.replace(`#include <map_fragment>`,`#include <map_fragment>
|
|
2
|
+
diffuseColor.a = pow(diffuseColor.a, 0.75);`)},a.customProgramCacheKey=()=>`contact-shadow-alpha-gamma`,a.addEventListener(`dispose`,()=>r.dispose());let o=new c.Mesh(i,a);o.name=xn,o.userData[Cn]=!0,o.rotation.x=-Math.PI/2;let s=c.MathUtils.clamp(n.objectHeight*e.FLOOR_LIFT_PER_HEIGHT,e.FLOOR_LIFT_MIN,e.FLOOR_LIFT_MAX);o.position.set(n.center.x,s,n.center.z),o.userData.renderTarget=r,t.add(o);let l=t.getObjectByName(Sn);l&&(l.visible=!1)}disableColorWrite(e){let t=new Map;return e.traverse(e=>{let n=e;if(!n.isMesh)return;let r=Array.isArray(n.material)?n.material:[n.material];for(let e of r)e&&!t.has(e)&&(t.set(e,e.colorWrite),e.colorWrite=!1)}),t}restoreColorWrite(e){e.forEach((e,t)=>{t.colorWrite=e})}},kn=e=>e*e*(3-2*e);Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return On}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return bn}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Sn}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return He}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return xn}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return wn}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Cn}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Dn}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return kn}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Be}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return _}});
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("three");c=s(c,1);var l=class e extends Error{constructor(t,n,r){super(t),this.code=n,this.context=r,this.name=`ThreeViewerError`,this.timestamp=new Date,Error.captureStackTrace&&Error.captureStackTrace(this,e)}static fromError(t,n,r){if(t instanceof e)return t;let i=t instanceof Error?t.message:String(t),a={...r,originalError:t instanceof Error?{name:t.name,message:t.message,stack:t.stack}:t};return new e(i,n,a)}},u=function(e){return e.SCENE_INIT_FAILED=`SCENE_INIT_FAILED`,e.RENDERER_INIT_FAILED=`RENDERER_INIT_FAILED`,e.RENDERER_NOT_INITIALIZED=`RENDERER_NOT_INITIALIZED`,e.CAMERA_INIT_FAILED=`CAMERA_INIT_FAILED`,e.WEBGL_NOT_SUPPORTED=`WEBGL_NOT_SUPPORTED`,e.INITIALIZATION_FAILED=`INITIALIZATION_FAILED`,e.PATH_TRACING_INIT_FAILED=`PATH_TRACING_INIT_FAILED`,e.MODEL_LOAD_FAILED=`MODEL_LOAD_FAILED`,e.TEXTURE_LOAD_FAILED=`TEXTURE_LOAD_FAILED`,e.RESOURCE_NOT_FOUND=`RESOURCE_NOT_FOUND`,e.UNSUPPORTED_FORMAT=`UNSUPPORTED_FORMAT`,e.INVALID_CONFIGURATION=`INVALID_CONFIGURATION`,e.RENDER_ERROR=`RENDER_ERROR`,e.RENDER_FAILED=`RENDER_FAILED`,e.SCENE_OPERATION_FAILED=`SCENE_OPERATION_FAILED`,e.COMPONENT_NOT_MOUNTED=`COMPONENT_NOT_MOUNTED`,e.INVALID_STATE=`INVALID_STATE`,e.INVALID_PARAMETER=`INVALID_PARAMETER`,e.OPERATION_FAILED=`OPERATION_FAILED`,e.POST_PROCESSING_FAILED=`POST_PROCESSING_FAILED`,e.UNKNOWN=`UNKNOWN`,e}({}),d={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}},wrap(e){try{return d.ok(e())}catch(e){return d.err(e instanceof l?e:new l(String(e),u.UNKNOWN,{originalError:e}))}}},f=class{constructor(){this.listeners=new Map}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set);let n=this.listeners.get(e);return n&&n.add(t),()=>{this.listeners.get(e)?.delete(t)}}emit(e,t){this.listeners.get(e)?.forEach(n=>{try{n(t)}catch(t){console.error(`Error in event listener for ${String(e)}:`,t)}})}once(e,t){let n=this.on(e,e=>{n(),t(e)});return n}removeAllListeners(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){return this.listeners.get(e)?.size||0}off(e,t){this.listeners.get(e)?.delete(t)}removeListener(e,t){this.off(e,t)}},p={meters:1,centimeters:.01,millimeters:.001,feet:.3048,inches:.0254},m=`softbox-units-scale`,h=1.25,g=65535,_=g<<16,v=2**-24,y=Symbol(`SKIP_GENERATION`),b={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[y]:!1};function x(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 S(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 C(e,t){t.set(e)}function w(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 T(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 E(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 D(e,t){return t[e+15]===g}function O(e,t){return t[e+6]}function k(e,t){return t[e+14]}function A(e){return e+8}function j(e,t){return e+t[e+6]*8}function ee(e,t){return t[e+7]}function M(e){return e}function te(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 N=32,ne=(e,t)=>e.candidate-t.candidate,P=Array(N).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),re=new Float32Array(6);function ie(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=S(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=S(e),o!==-1&&(s=ae(n,r,i,o));else if(a===2){let a=E(e),c=h*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)/N;if(i<N/4){let t=[...P];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;T(i,n,o)}t.sort(ne);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?T(r,n,a.rightCacheBounds):(T(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=E(d)/a);let m=0;u!==0&&(m=E(f)/a);let g=1+h*(p*l+m*u);g<c&&(o=e,c=g,s=r.candidate)}}else{for(let e=0;e<N;e++){let t=P[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>=N&&(i=N-1);let a=P[i];a.count++,T(t,n,a.bounds)}let t=P[N-1];C(t.bounds,t.rightCacheBounds);for(let e=N-2;e>=0;e--){let t=P[e],n=P[e+1];w(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<N-1;t++){let n=P[t],r=n.count,l=n.bounds,u=P[t+1].rightCacheBounds;r!==0&&(f===0?C(l,re):w(l,re,re)),f+=r;let d=0,p=0;f!==0&&(d=E(re)/a);let m=i-f;m!==0&&(p=E(u)/a);let g=1+h*(d*f+p*m);g<c&&(o=e,c=g,s=n.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${a} used.`);return{axis:o,pos:s}}function ae(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 oe=class{constructor(){this.boundingData=new Float32Array(6)}};function se(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 ce,le,ue,de,fe=2**32;function pe(e){return`count`in e?1:1+pe(e.left)+pe(e.right)}function me(e,t,n){return ce=new Float32Array(n),le=new Uint32Array(n),ue=new Uint16Array(n),de=new Uint8Array(n),he(e,t)}function he(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)ce[n+e]=a[e];if(i)return t.buffer?(de.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(le[n+6]=t.offset,ue[r+14]=t.count,ue[r+15]=g,e+32);{let{left:r,right:i,splitAxis:a}=t,o=he(e+32,r),s=e/32,c=o/32-s;if(c>fe)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return le[n+6]=c,le[n+7]=a,he(o,i)}}function ge(e,t,n,r,i,a){let{maxDepth:o,verbose:s,targetLeafSize:c,_strictLeafSize:l=1/0,strategy:u,onProgress:d}=i,f=e.primitiveBuffer,p=e.primitiveBufferStride,m=new Float32Array(6),h=!1,g=new oe;return te(t,n,r,g.boundingData,m),v(g,n,r,m),g;function _(e){d&&d((e-a.offset)/a.count)}function v(e,n,r,i=null,a=0){!h&&a>=o&&(h=!0,s&&console.warn(`BVH: Max depth of ${o} reached when generating BVH. Consider increasing maxDepth.`));let d=r>l;if(r<=c&&!d||a>=o)return _(n+r),e.offset=n,e.count=r,e;let g=ie(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:se(f,p,t,n,r,g);if(g.axis===-1||y===n||y===n+r){if(!d)return _(n+r),e.offset=n,e.count=r,e;g.axis=Math.max(0,S(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new oe,x=n,C=y-n;e.left=b,te(t,x,C,b.boundingData,m),v(b,x,C,m,a+1);let w=new oe,T=y,E=r-C;return e.right=w,te(t,T,E,w.boundingData,m),v(w,T,E,m,a+1),e}}function _e(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=ge(e,s,r.offset,r.count,t,o),a=pe(i),c=new n(32*a);return me(0,i,c),c})}var ve=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)}},F=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())}}},I,L,ye=[],be=new ve(()=>new c.Box3);function xe(e,t,n,r,i,a){I=be.getPrimitive(),L=be.getPrimitive(),ye.push(I,L),F.setBuffer(e._roots[t]);let o=Se(0,e.geometry,n,r,i,a);F.clearBuffer(),be.releasePrimitive(I),be.releasePrimitive(L),ye.pop(),ye.pop();let s=ye.length;return s>0&&(L=ye[s-1],I=ye[s-2]),o}function Se(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(D(u,c)){let t=O(e,l),n=k(u,c);return x(M(e),s,I),r(t,n,!1,o,a+e/8,I)}else{let u=A(e),p=j(e,l),m=u,h=p,g,_,v,y;if(i&&(v=I,y=L,x(M(m),s,v),x(M(h),s,y),g=i(v),_=i(y),_<g)){m=p,h=u;let e=g;g=_,_=e,v=y}v||(v=I,x(M(m),s,v));let b=D(m*2,c),S=n(v,b,g,o+1,a+m/8),C;if(S===2){let e=d(m);C=r(e,f(m)-e,!0,o+1,a+m/8,v)}else C=S&&Se(m,t,n,r,i,a,o+1);if(C)return!0;y=L,x(M(h),s,y);let w=D(h*2,c),T=n(y,w,_,o+1,a+h/8),E;if(T===2){let e=d(h);E=r(e,f(h)-e,!0,o+1,a+h/8,y)}else E=T&&Se(h,t,n,r,i,a,o+1);if(E)return!0;return!1;function d(e){let{uint16Array:t,uint32Array:n}=F,r=e*2;for(;!D(r,t);)e=A(e),r=e*2;return O(e,n)}function f(e){let{uint16Array:t,uint32Array:n}=F,r=e*2;for(;!D(r,t);)e=j(e,n),r=e*2;return O(e,n)+k(r,t)}}}var Ce=new F.constructor,we=new F.constructor,R=new ve(()=>new c.Box3),Te=new c.Box3,Ee=new c.Box3,De=new c.Box3,Oe=new c.Box3,ke=!1;function Ae(e,t,n,r){if(ke)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);ke=!0;let i=e._roots,a=t._roots,o,s=0,l=0,u=new c.Matrix4().copy(n).invert();for(let e=0,t=i.length;e<t;e++){Ce.setBuffer(i[e]),l=0;let t=R.getPrimitive();x(M(0),Ce.float32Array,t),t.applyMatrix4(u);for(let e=0,i=a.length;e<i&&(we.setBuffer(a[e]),o=z(0,0,n,u,r,s,l,0,0,t),we.clearBuffer(),l+=a[e].byteLength/32,!o);e++);if(R.releasePrimitive(t),Ce.clearBuffer(),s+=i[e].byteLength/32,o)break}return ke=!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=we,f=Ce):(d=Ce,f=we);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,S=D(y,h),C=D(b,v),w=!1;if(C&&S)w=u?i(O(t,_),k(t*2,v),O(e,m),k(e*2,h),c,o+t/8,s,a+e/8):i(O(e,m),k(e*2,h),O(t,_),k(t*2,v),s,a+e/8,c,o+t/8);else if(C){let l=R.getPrimitive();x(M(t),g,l),l.applyMatrix4(n);let d=A(e),f=j(e,m);x(M(d),p,Te),x(M(f),p,Ee);let h=l.intersectsBox(Te),_=l.intersectsBox(Ee);w=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=A(t),f=j(t,_);x(M(d),g,De),x(M(f),g,Oe);let h=l.intersectsBox(De),v=l.intersectsBox(Oe);if(h&&v)w=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(S)w=z(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=R.getPrimitive();t.copy(De).applyMatrix4(n);let l=A(e),f=j(e,m);x(M(l),p,Te),x(M(f),p,Ee);let h=t.intersectsBox(Te),g=t.intersectsBox(Ee);w=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(S)w=z(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=R.getPrimitive();t.copy(Oe).applyMatrix4(n);let l=A(e),d=j(e,m);x(M(l),p,Te),x(M(d),p,Ee);let h=t.intersectsBox(Te),g=t.intersectsBox(Ee);w=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 w}var je=new class{constructor(){let e=null,t=null,n=null,r=!1;this.root=null,this.buffer=null,this.uint32Array=null,this.uint16Array=null,this.setBVH=(i,a)=>{if(r)throw Error(`BVHTraversalHelper: cannot call setBVH during an active traversal.`);this.root=a,this.buffer=e=i._roots[a],this.uint16Array=n=new Uint16Array(e),this.uint32Array=t=new Uint32Array(e)},this.reset=()=>{this.root=null,this.buffer=e=null,this.uint16Array=n=null,this.uint32Array=t=null},this.getRangeStart=e=>{let r=e*2;for(;!D(r,n);)e=A(e),r=e*2;return O(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!D(r,n);)e=j(e,t),r=e*2;return O(e,t)+k(r,n)};let i=(e,r,a)=>{let o=D(r*2,n);if(!e(a,o,r)&&!o){let n=A(r),o=j(r,t);i(e,n,a+1),i(e,o,a+1)}};this.traverseBuffer=e=>{if(r)throw Error(`BVHTraversalHelper: cannot start a traversal during an active traversal.`);r=!0;try{i(e,0,0)}finally{r=!1}},this.traverse=r=>{this.traverseBuffer((i,a,o)=>{if(a){let s=o*2,c=t[o+6],l=n[s+14];return r(i,a,new Float32Array(e,o*4,6),c,l)}else{let n=ee(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Me=new c.Box3,Ne=new Float32Array(6),Pe=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...b,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),_e(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,Ne,0);let[e,t,r,u,d,f]=Ne;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,Ne,0);let[e,t,a,o,s,c]=Ne,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)*v,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*v,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*v}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;D(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){je.setBVH(this,t),je.traverse(e),je.reset()}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(D(n,i)){let e=O(t,r),o=k(n,i);this.writePrimitiveRangeBounds(e,o,Ne,0),a.set(Ne,t)}else{let e=A(t),n=j(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=>{x(0,new Float32Array(t),Me),e.union(Me)}),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=xe(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Ae(this,e,t,r)}};function Fe(){return typeof SharedArrayBuffer<`u`}function Ie(e){return e.index?e.index.count:e.attributes.position.count}function Le(e){return Ie(e)/3}function Re(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function ze(e,t){if(!e.index){let n=e.attributes.position.count,r=Re(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new c.BufferAttribute(r,1));for(let e=0;e<n;e++)r[e]=e}}function Be(e,t,n){let r=Ie(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 Ve(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function He(e,t,n){let r=Be(e,t,n),i=Ve(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Ie(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 Ue(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 We=class extends Pe{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&&!Fe())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={...b,...t},t[y]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=Ue(He(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else ze(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new c.Box3))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:He(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 e=new c.Vector3;return function(t,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++){e.x=r.x*n+i.x*(1-n),e.y=r.y*s+i.y*(1-s),e.z=r.z*c+i.z*(1-c);let l=t.dot(e);a=Math.min(l,a),o=Math.max(l,o)}this.min=a,this.max=o}})();var Ge=(function(){let e=new c.Vector3,t=new c.Vector3,n=new c.Vector3;return function(r,i,a){let o=r.start,s=e,c=i.start,l=t;n.subVectors(o,c),e.subVectors(r.end,r.start),t.subVectors(i.end,i.start);let u=n.dot(l),d=l.dot(s),f=l.dot(l),p=n.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}})(),Ke=(function(){let e=new c.Vector2,t=new c.Vector3,n=new c.Vector3;return function(r,i,a,o){Ge(r,i,e);let s=e.x,c=e.y;if(s>=0&&s<=1&&c>=0&&c<=1){r.at(s,a),i.at(c,o);return}else if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}else if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}else{let e;e=s<0?r.start:r.end;let l;l=c<0?i.start:i.end;let u=t,d=n;if(r.closestPointToPoint(l,!0,t),i.closestPointToPoint(e,!0,n),u.distanceToSquared(l)<=d.distanceToSquared(e)){a.copy(u),o.copy(l);return}else{a.copy(e),o.copy(d);return}}}})(),qe=(function(){let e=new c.Vector3,t=new c.Vector3,n=new c.Plane,r=new c.Line3;return function(i,a){let{radius:o,center:s}=i,{a:c,b:l,c:u}=a;if(r.start=c,r.end=l,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o||(r.start=c,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o)||(r.start=l,r.end=u,r.closestPointToPoint(s,!0,e).distanceTo(s)<=o))return!0;let d=a.getPlane(n);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,t);if(a.containsPoint(e))return!0}return!1}})(),Je=[`x`,`y`,`z`],V=1e-15,Ye=V*V;function H(e){return Math.abs(e)<V}var U=class extends c.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new c.Vector3),this.satBounds=[,,,,].fill().map(()=>new B),this.points=[this.a,this.b,this.c],this.plane=new c.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new c.Line3,this.needsUpdate=!0}intersectsSphere(e){return qe(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 e=new c.Vector3,t=new c.Vector3,n=new c.Line3;return function(r,i=null,a=null){let{start:o,end:s}=r,c=this.points,l,u=1/0;for(let o=0;o<3;o++){let s=(o+1)%3;n.start.copy(c[o]),n.end.copy(c[s]),Ke(n,r,e,t),l=e.distanceToSquared(t),l<u&&(u=l,i&&i.copy(e),a&&a.copy(t))}return this.closestPointToPoint(o,e),l=o.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(o)),this.closestPointToPoint(s,e),l=s.distanceToSquared(e),l<u&&(u=l,i&&i.copy(e),a&&a.copy(s)),Math.sqrt(u)}})(),U.prototype.intersectsTriangle=(function(){let e=new U,t=new B,n=new B,r=new c.Vector3,i=new c.Vector3,a=new c.Vector3,o=new c.Vector3,s=new c.Line3,l=new c.Line3,u=new c.Vector3,d=new c.Vector2,f=new c.Vector2;function p(e,i,a,s){let c=r;!e.isDegenerateIntoPoint&&!e.isDegenerateIntoSegment?c.copy(e.plane.normal):c.copy(i.plane.normal);let l=e.satBounds,u=e.satAxes;for(let r=1;r<4;r++){let a=l[r],s=u[r];if(t.setFromPoints(s,i.points),a.isSeparated(t)||(o.copy(c).cross(s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}let d=i.satBounds,f=i.satAxes;for(let r=1;r<4;r++){let a=d[r],s=f[r];if(t.setFromPoints(s,e.points),a.isSeparated(t)||(o.crossVectors(c,s),t.setFromPoints(o,e.points),n.setFromPoints(o,i.points),t.isSeparated(n)))return!1}return a&&(s||console.warn(`ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0.`),a.start.set(0,0,0),a.end.set(0,0,0)),!0}function m(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 h(e,t,n,r,i,a,o,s,c,l,u){if(i>0)m(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else if(a>0)m(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(s*c>0||o!=0)m(e.a,e.b,e.c,t,n,r,o,s,c,l,u);else if(s!=0)m(e.b,e.a,e.c,n,t,r,s,o,c,l,u);else if(c!=0)m(e.c,e.a,e.b,r,t,n,c,o,s,l,u);else return!0;return!1}function g(e,t,n,i){let a=t.degenerateSegment,o=e.plane.distanceToPoint(a.start),s=e.plane.distanceToPoint(a.end);return H(o)?H(s)?p(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):H(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)==null?!1:(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function _(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 v(e,t,n){let i=e.degenerateSegment,a=t.a;return i.closestPointToPoint(a,!0,r),a.distanceToSquared(r)<Ye?(n&&(n.start.copy(a),n.end.copy(a)),!0):!1}function y(e,t,n,o){if(e.isDegenerateIntoSegment)if(t.isDegenerateIntoSegment){let o=e.degenerateSegment,s=t.degenerateSegment,c=i,l=a;o.delta(c),s.delta(l);let u=r.subVectors(s.start,o.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(o.start.z+c.z*f-(s.start.z+l.z*p))?(n&&(n.start.copy(o.start).addScaledVector(c,f),n.end.copy(o.start).addScaledVector(c,f)),!0):!1}else if(t.isDegenerateIntoPoint)return v(e,t,n);else return g(t,e,n,o);else if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<Ye?(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):!1:t.isDegenerateIntoSegment?v(t,e,n):_(t,e,n);else if(t.isDegenerateIntoPoint)return _(e,t,n);else if(t.isDegenerateIntoSegment)return g(e,t,n,o)}return function(t,n=null,r=!1){this.needsUpdate&&this.update(),t.isExtendedTriangle?t.needsUpdate&&t.update():(e.copy(t),e.update(),t=e);let o=y(this,t,n,r);if(o!==void 0)return o;let c=this.plane,m=t.plane,g=m.distanceToPoint(this.a),_=m.distanceToPoint(this.b),v=m.distanceToPoint(this.c);H(g)&&(g=0),H(_)&&(_=0),H(v)&&(v=0);let b=g*_,x=g*v;if(b>0&&x>0)return!1;let S=c.distanceToPoint(t.a),C=c.distanceToPoint(t.b),w=c.distanceToPoint(t.c);H(S)&&(S=0),H(C)&&(C=0),H(w)&&(w=0);let T=S*C,E=S*w;if(T>0&&E>0)return!1;i.copy(c.normal),a.copy(m.normal);let D=i.cross(a),O=0,k=Math.abs(D.x),A=Math.abs(D.y);A>k&&(k=A,O=1),Math.abs(D.z)>k&&(O=2);let j=Je[O],ee=this.a[j],M=this.b[j],te=this.c[j],N=t.a[j],ne=t.b[j],P=t.c[j];if(h(this,ee,M,te,b,x,g,_,v,d,s)||h(t,N,ne,P,T,E,S,C,w,f,l))return p(this,t,n,r);if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,u.copy(s.start),s.start.copy(s.end),s.end.copy(u)}if(f.y<f.x){let e=f.y;f.y=f.x,f.x=e,u.copy(l.start),l.start.copy(l.end),l.end.copy(u)}return d.y<f.x||f.y<d.x?!1:(n&&(f.x>d.x?n.start.copy(l.start):n.start.copy(s.start),f.y<d.y?n.end.copy(l.end):n.end.copy(s.end)),!0)}})(),U.prototype.distanceToPoint=(function(){let e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),U.prototype.distanceToTriangle=(function(){let e=new c.Vector3,t=new c.Vector3,n=[`a`,`b`,`c`],r=new c.Line3,i=new c.Line3;return function(a,o=null,s=null){let c=o||s?r:null;if(this.intersectsTriangle(a,c,!0))return(o||s)&&(o&&c.getCenter(o),s&&c.getCenter(s)),0;let l=1/0;for(let t=0;t<3;t++){let r,i=n[t],c=a[i];this.closestPointToPoint(c,e),r=c.distanceToSquared(e),r<l&&(l=r,o&&o.copy(e),s&&s.copy(c));let u=this[i];a.closestPointToPoint(u,e),r=u.distanceToSquared(e),r<l&&(l=r,o&&o.copy(u),s&&s.copy(e))}for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];r.set(this[u],this[d]);for(let c=0;c<3;c++){let u=n[c],d=n[(c+1)%3];i.set(a[u],a[d]),Ke(r,i,e,t);let f=e.distanceToSquared(t);f<l&&(l=f,o&&o.copy(e),s&&s.copy(t))}}return Math.sqrt(l)}})();var W=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new c.Vector3,this.max=new c.Vector3,this.matrix=new c.Matrix4,this.invMatrix=new c.Matrix4,this.points=Array(8).fill().map(()=>new c.Vector3),this.satAxes=[,,,].fill().map(()=>new c.Vector3),this.satBounds=[,,,].fill().map(()=>new B),this.alignedSatBounds=[,,,].fill().map(()=>new B),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}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 e=new U,t=[,,,],n=new B,r=new B,i=new c.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(e.copy(a),e.update(),a=e);let o=this.satBounds,s=this.satAxes;t[0]=a.a,t[1]=a.b,t[2]=a.c;for(let e=0;e<3;e++){let r=o[e],i=s[e];if(n.setFromPoints(i,t),r.isSeparated(n))return!1}let c=a.satBounds,l=a.satAxes,u=this.points;for(let e=0;e<3;e++){let t=c[e],r=l[e];if(n.setFromPoints(r,u),t.isSeparated(n))return!1}for(let e=0;e<3;e++){let a=s[e];for(let e=0;e<4;e++){let o=l[e];if(i.crossVectors(a,o),n.setFromPoints(i,t),r.setFromPoints(i,u),n.isSeparated(r))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 e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),W.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new c.Line3),n=Array(12).fill().map(()=>new c.Line3),r=new c.Vector3,i=new c.Vector3;return function(a,o=0,s=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(s||c)&&(a.getCenter(i),this.closestPointToPoint(i,r),a.closestPointToPoint(r,i),s&&s.copy(r),c&&c.copy(i)),0;let l=o*o,u=a.min,d=a.max,f=this.points,p=1/0;for(let e=0;e<8;e++){let t=f[e];i.copy(t).clamp(u,d);let n=t.distanceToSquared(i);if(n<p&&(p=n,s&&s.copy(t),c&&c.copy(i),n<l))return Math.sqrt(n)}let m=0;for(let r=0;r<3;r++)for(let i=0;i<=1;i++)for(let a=0;a<=1;a++){let o=(r+1)%3,s=(r+2)%3,c=i<<o|a<<s,l=1<<r|i<<o|a<<s,p=f[c],h=f[l];t[m].set(p,h);let g=e[r],_=e[o],v=e[s],y=n[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++){i.x=e?d.x:u.x,i.y=t?d.y:u.y,i.z=n?d.z:u.z,this.closestPointToPoint(i,r);let a=i.distanceToSquared(r);if(a<p&&(p=a,s&&s.copy(r),c&&c.copy(i),a<l))return Math.sqrt(a)}for(let e=0;e<12;e++){let a=t[e];for(let e=0;e<12;e++){let t=n[e];Ke(a,t,r,i);let o=r.distanceToSquared(i);if(o<p&&(p=o,s&&s.copy(r),c&&c.copy(i),o<l))return Math.sqrt(o)}}return Math.sqrt(p)}})();var G=new class extends ve{constructor(){super(()=>new U)}},Xe=new c.Vector3,Ze=new c.Vector3;function Qe(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=>(Xe.copy(t).clamp(e.min,e.max),Xe.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,Xe);let r=t.distanceToSquared(Xe);return r<s&&(Ze.copy(Xe),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(Ze):n.point=Ze.clone(),n.distance=l,n.faceIndex=c,n}var $e=parseInt(c.REVISION)>=169,et=parseInt(c.REVISION)<=161,K=new c.Vector3,q=new c.Vector3,J=new c.Vector3,tt=new c.Vector2,nt=new c.Vector2,rt=new c.Vector2,it=new c.Vector3,at=new c.Vector3,ot=new c.Vector3,st=new c.Vector3;function ct(e,t,n,r,i,a,o,s){let l;if(l=a===c.BackSide?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==c.DoubleSide,i),l===null)return null;let u=e.origin.distanceTo(i);return u<o||u>s?null:{distance:u,point:i.clone()}}function lt(e,t,n,r,i,a,o,s,l,u,d){K.fromBufferAttribute(t,a),q.fromBufferAttribute(t,o),J.fromBufferAttribute(t,s);let f=ct(e,K,q,J,st,l,u,d);if(f){if(r){tt.fromBufferAttribute(r,a),nt.fromBufferAttribute(r,o),rt.fromBufferAttribute(r,s),f.uv=new c.Vector2;let e=c.Triangle.getInterpolation(st,K,q,J,tt,nt,rt,f.uv);$e||(f.uv=e)}if(i){tt.fromBufferAttribute(i,a),nt.fromBufferAttribute(i,o),rt.fromBufferAttribute(i,s),f.uv1=new c.Vector2;let e=c.Triangle.getInterpolation(st,K,q,J,tt,nt,rt,f.uv1);$e||(f.uv1=e),et&&(f.uv2=f.uv1)}if(n){it.fromBufferAttribute(n,a),at.fromBufferAttribute(n,o),ot.fromBufferAttribute(n,s),f.normal=new c.Vector3;let t=c.Triangle.getInterpolation(st,K,q,J,it,at,ot,f.normal);f.normal.dot(e.direction)>0&&f.normal.multiplyScalar(-1),$e||(f.normal=t)}let t={a,b:o,c:s,normal:new c.Vector3,materialIndex:0};if(c.Triangle.getNormal(K,q,J,t.normal),f.face=t,f.faceIndex=a,$e){let e=new c.Vector3;c.Triangle.getBarycoord(st,K,q,J,e),f.barycoord=e}}return f}function ut(e){return e&&e.isMaterial?e.side:e}function dt(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=ut(t[v]),s=lt(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=ut(t),s=lt(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 ft(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)dt(c,t,n,e,a,o,s)}function pt(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=dt(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function mt(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 ht(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(D(l,s)){let t=O(e,o),n=k(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=A(e),i=j(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 gt(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)dt(c,t,n,l?l[e]:e,a,o,s)}function _t(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=dt(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function vt(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 yt(e,t,n,r,i,a,o){F.setBuffer(e._roots[t]),bt(0,e,n,r,i,a,o),F.clearBuffer()}function bt(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(D(u,c))ft(t,n,r,O(e,l),k(u,c),i,a,o);else{let c=A(e);X(c,s,r,a,o)&&bt(c,t,n,r,i,a,o);let u=j(e,l);X(u,s,r,a,o)&&bt(u,t,n,r,i,a,o)}}var xt=[`x`,`y`,`z`];function St(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=Ct(0,e,n,r,i,a);return F.clearBuffer(),o}function Ct(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(D(l,s))return pt(t,n,r,O(e,c),k(l,s),i,a);{let s=ee(e,c),l=xt[s],u=r.direction[l]>=0,d,f;u?(d=A(e),f=j(e,c)):(d=j(e,c),f=A(e));let p=X(d,o,r,i,a)?Ct(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)?Ct(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var wt=new c.Box3,Tt=new U,Et=new U,Dt=new c.Matrix4,Ot=new W,kt=new W;function At(e,t,n,r){F.setBuffer(e._roots[t]);let i=jt(0,e,n,r);return F.clearBuffer(),i}function jt(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Ot.set(n.boundingBox.min,n.boundingBox.max,r),i=Ot),D(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=O(e,s),m=k(c,o);if(Dt.copy(r).invert(),n.boundsTree)return x(M(e),a,kt),kt.matrix.copy(Dt),kt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>kt.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(Et,t,l,u),Et.needsUpdate=!0,e.intersectsTriangle(Et))return!0;return!1}});{let e=Le(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){Y(Tt,t,l,u),Tt.a.applyMatrix4(Dt),Tt.b.applyMatrix4(Dt),Tt.c.applyMatrix4(Dt),Tt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Y(Et,t,d,f),Et.needsUpdate=!0,Tt.intersectsTriangle(Et))return!0}}}else{let o=A(e),c=j(e,s);return x(M(o),a,wt),!!(i.intersectsBox(wt)&&jt(o,t,n,r,i)||(x(M(c),a,wt),i.intersectsBox(wt)&&jt(c,t,n,r,i)))}}var Mt=new c.Matrix4,Nt=new W,Pt=new W,Ft=new c.Vector3,It=new c.Vector3,Lt=new c.Vector3,Rt=new c.Vector3;function zt(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Nt.set(t.boundingBox.min,t.boundingBox.max,n),Nt.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=Ft,h=It,g=null,_=null;i&&(g=Lt,_=Rt);let v=1/0,y=null,b=null;return Mt.copy(n).invert(),Pt.matrix.copy(Mt),e.shapecast({boundsTraverseOrder:e=>Nt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(Pt.min.copy(e.min),Pt.max.copy(e.max),Pt.needsUpdate=!0),!0):!1,intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Pt.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=Le(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(Mt),h.applyMatrix4(Mt),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Bt(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(D(u,s)){let t=O(n,o),a=k(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=A(n),r=j(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 Vt(e,t,n,r,i,a,o){F.setBuffer(e._roots[t]),Ht(0,e,n,r,i,a,o),F.clearBuffer()}function Ht(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(D(u,c))gt(t,n,r,O(e,l),k(u,c),i,a,o);else{let c=A(e);X(c,s,r,a,o)&&Ht(c,t,n,r,i,a,o);let u=j(e,l);X(u,s,r,a,o)&&Ht(u,t,n,r,i,a,o)}}var Ut=[`x`,`y`,`z`];function Wt(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=Gt(0,e,n,r,i,a);return F.clearBuffer(),o}function Gt(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(D(l,s))return _t(t,n,r,O(e,c),k(l,s),i,a);{let s=ee(e,c),l=Ut[s],u=r.direction[l]>=0,d,f;u?(d=A(e),f=j(e,c)):(d=j(e,c),f=A(e));let p=X(d,o,r,i,a)?Gt(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)?Gt(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Kt=new c.Box3,qt=new U,Jt=new U,Yt=new c.Matrix4,Xt=new W,Zt=new W;function Qt(e,t,n,r){F.setBuffer(e._roots[t]);let i=$t(0,e,n,r);return F.clearBuffer(),i}function $t(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Xt.set(n.boundingBox.min,n.boundingBox.max,r),i=Xt),D(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=O(e,s),m=k(c,o);if(Yt.copy(r).invert(),n.boundsTree)return x(M(e),a,Zt),Zt.matrix.copy(Yt),Zt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Zt.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(Jt,3*t.resolveTriangleIndex(n),l,u),Jt.needsUpdate=!0,e.intersectsTriangle(Jt))return!0;return!1}});{let e=Le(n);for(let n=p,r=m+p;n<r;n++){Y(qt,3*t.resolveTriangleIndex(n),l,u),qt.a.applyMatrix4(Yt),qt.b.applyMatrix4(Yt),qt.c.applyMatrix4(Yt),qt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(Y(Jt,t,d,f),Jt.needsUpdate=!0,qt.intersectsTriangle(Jt))return!0}}}else{let o=A(e),c=j(e,s);return x(M(o),a,Kt),!!(i.intersectsBox(Kt)&&$t(o,t,n,r,i)||(x(M(c),a,Kt),i.intersectsBox(Kt)&&$t(c,t,n,r,i)))}}var en=new c.Matrix4,tn=new W,nn=new W,rn=new c.Vector3,an=new c.Vector3,on=new c.Vector3,sn=new c.Vector3;function cn(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),tn.set(t.boundingBox.min,t.boundingBox.max,n),tn.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=rn,h=an,g=null,_=null;i&&(g=on,_=sn);let v=1/0,y=null,b=null;return en.copy(n).invert(),nn.matrix.copy(en),e.shapecast({boundsTraverseOrder:e=>tn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(nn.min.copy(e.min),nn.max.copy(e.max),nn.needsUpdate=!0),!0):!1,intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>nn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,o)=>{for(let x=t,S=t+o;x<S;x++){let t=s.resolveTriangleIndex(x);Y(p,3*t,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++){let n=e.resolveTriangleIndex(t);Y(f,3*n,l,c),f.needsUpdate=!0;let r=f.distanceToTriangle(p,m,g);if(r<v&&(h.copy(m),_&&_.copy(g),v=r,y=t,b=x),r<a)return!0}}}})}else{let o=Le(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++){let r=e.resolveTriangleIndex(n);Y(f,3*r,l,c),f.needsUpdate=!0;let i=f.distanceToTriangle(p,m,g);if(i<v&&(h.copy(m),_&&_.copy(g),v=i,y=n,b=t),i<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(en),h.applyMatrix4(en),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function ln(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 un=new W,dn=new c.Ray,fn=new c.Vector3,pn=new c.Matrix4,mn=new c.Vector3,hn=[`getX`,`getY`,`getZ`],gn=class e extends We{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.`),l(a));let s=new e(n,{...r,[y]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new c.BufferAttribute(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function l(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;D(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 "targetLeafSize", instead.`),t={...t,targetLeafSize: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[hn[e]](c),i=a[hn[e]](l),o=a[hn[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)*v}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;pn.copy(e.matrixWorld).invert(),dn.copy(t.ray).applyMatrix4(pn),mn.setFromMatrixScale(e.matrixWorld),fn.copy(dn.direction).multiply(mn);let i=fn.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(dn,r,a,o);i=ln(i,e,t),i&&n.push(i)}else{let i=this.raycast(dn,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=ln(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?Bt:ht)(this,e)}raycast(e,t=c.FrontSide,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?Vt:yt;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=c.FrontSide,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?Wt:St;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?Qt:At;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?vt:mt});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=>{let t=this.resolveTriangleIndex(e);Y(o,t*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=>{let n=t.resolveTriangleIndex(e);Y(u,n*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 un.set(e.min,e.max,t),un.needsUpdate=!0,this.shapecast({intersectsBounds:e=>un.intersectsBox(e),intersectsTriangle:e=>un.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?cn:zt)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return Qe(this,e,t,n,r)}},Z={Mesh:c.Mesh.prototype.raycast,Line:c.Line.prototype.raycast,LineSegments:c.LineSegments.prototype.raycast,LineLoop:c.LineLoop.prototype.raycast,Points:c.Points.prototype.raycast,BatchedMesh:c.BatchedMesh.prototype.raycast},Q=new c.Mesh,_n=[];function vn(e,t){if(this.isBatchedMesh)yn.call(this,e,t);else{let{geometry:n}=this;if(n.boundsTree)n.boundsTree.raycastObject3D(this,e,t);else{let n;if(this instanceof c.Mesh)n=Z.Mesh;else if(this instanceof c.LineSegments)n=Z.LineSegments;else if(this instanceof c.LineLoop)n=Z.LineLoop;else if(this instanceof c.Line)n=Z.Line;else if(this instanceof c.Points)n=Z.Points;else throw Error(`BVH: Fallback raycast function not found.`);n.call(this,e,t)}}}function yn(e,t){if(this.boundsTrees){let n=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,a=this.matrixWorld;Q.material=this.material,Q.geometry=this.geometry;let o=Q.geometry.boundsTree,s=Q.geometry.drawRange;Q.geometry.boundingSphere===null&&(Q.geometry.boundingSphere=new c.Sphere);for(let o=0,s=r.length;o<s;o++){if(!this.getVisibleAt(o))continue;let s=r[o].geometryIndex;if(Q.geometry.boundsTree=n[s],this.getMatrixAt(o,Q.matrixWorld).premultiply(a),!Q.geometry.boundsTree){this.getBoundingBoxAt(s,Q.geometry.boundingBox),this.getBoundingSphereAt(s,Q.geometry.boundingSphere);let e=i[s];Q.geometry.setDrawRange(e.start,e.count)}Q.raycast(e,_n);for(let e=0,n=_n.length;e<n;e++){let n=_n[e];n.object=this,n.batchId=o,t.push(n)}_n.length=0}Q.geometry.boundsTree=o,Q.geometry.drawRange=s,Q.material=null,Q.geometry=null}else Z.BatchedMesh.call(this,e,t)}function bn(e){e.traverse(e=>{let t=e;if(!t.isMesh||t.isSkinnedMesh||t.isInstancedMesh||t.isBatchedMesh)return;let n=t.geometry;!n?.attributes?.position||n.morphAttributes?.position?.length||(n.boundsTree||=new gn(n),t.raycast=vn)})}function xn(e){e.boundsTree&&=void 0}var Sn=`softboxExternallyOwnedTextures`,Cn=`softboxBackgroundNode`,wn=`softboxStashedMaterials`;function Tn(e){if(!e.userData.softboxDisposed){if(!e.userData?.softboxExternallyOwnedTextures){let t=e;for(let e of Object.keys(t)){let n=t[e];n instanceof c.Texture&&n.dispose()}let n=e;if(n.isShaderMaterial&&n.uniforms)for(let e of Object.values(n.uniforms))e?.value instanceof c.Texture&&e.value.dispose()}e.dispose(),e.userData.softboxDisposed=!0}}function En(e){e.traverse(e=>{let t=e;t.geometry&&typeof t.geometry.dispose==`function`&&(xn(t.geometry),t.geometry.dispose());let n=t.material;Array.isArray(n)?n.forEach(Tn):n&&Tn(n),(e.userData?.[wn])?.forEach(Tn);let r=e;r.isLight&&r.shadow?.dispose&&r.shadow.dispose()})}function Dn(e,t){if(!t?.keepBackgrounds){e.background instanceof c.Texture&&(e.background.dispose(),e.background=null),e.environment instanceof c.Texture&&(e.environment.dispose(),e.environment=null);let t=e;t.__originalEnvironmentTexture&&=void 0}for(let n of[...e.children])t?.keepBackgrounds&&n.userData?.softboxBackgroundNode||(En(n),e.remove(n))}var On=`contact-shadow-baked`,kn=`contact-shadow-live`,An=`softboxContactShadowHelper`,jn=`softboxPathTracingFloor`,Mn=Math.PI*(3-Math.sqrt(5));function Nn(e){let t=e.getObjectByName(On);t&&(e.remove(t),En(t))}function Pn(e){Nn(e);let t=e.getObjectByName(kn);t&&(t.visible=!0)}var Fn=class e{static{this.AMBIENT_RATIO=.62}static{this.LIGHT_APERTURE_DEGREES=13}static{this.DEPTH_PADDING_FACTOR=1.5}static{this.AMBIENT_MAX_ELEVATION_SIN=.98}static{this.AMBIENT_MIN_ELEVATION_DEGREES=55}static{this.ACCUMULATION_TEXTURE_SIZE=1024}static{this.BAKE_SHADOW_MAP_SIZE=1024}static{this.SHADOW_STRENGTH=.55}static{this.DISC_FOOTPRINT_MARGIN=1.4}static{this.DISC_HEIGHT_STRETCH=.45}static{this.DISC_MIN_HALF_EXTENT=.05}static{this.FLOOR_LIFT_PER_HEIGHT=.0025}static{this.FLOOR_LIFT_MIN=2e-4}static{this.FLOOR_LIFT_MAX=.01}static{this.BAKE_BUDGET_MS=100}static{this.MIN_PASSES=24}static{this.MAX_PASSES=96}constructor(e){this.explicitPasses=e?.passes}bake(t){let{renderer:n,scene:r,object:i,light:a}=t;if(n.getContext().isContextLost()){this.leaveLiveCatcherInCharge(r);return}let o=this.measureBakeRegion(i);if(!o)return;let s=r.getObjectByName(kn);s?.geometry instanceof c.CircleGeometry&&(o.halfExtent=Math.min(o.halfExtent,s.geometry.parameters.radius));let l=new c.WebGLRenderTarget(e.ACCUMULATION_TEXTURE_SIZE,e.ACCUMULATION_TEXTURE_SIZE,{type:n.capabilities.isWebGL2?c.HalfFloatType:c.UnsignedByteType,depthBuffer:!1,stencilBuffer:!1}),u=new c.CircleGeometry(o.halfExtent,64);try{this.accumulateShadowPasses(n,i,a,o,l,u)}catch(e){throw l.dispose(),u.dispose(),e}if(n.getContext().isContextLost()){l.dispose(),u.dispose(),this.leaveLiveCatcherInCharge(r),console.warn(`Contact-shadow bake aborted: WebGL context was lost mid-bake`);return}this.installBakedMesh(r,o,l,u)}leaveLiveCatcherInCharge(e){Pn(e)}evictBakedMesh(e){Nn(e)}measureBakeRegion(t){let n=new c.Box3().setFromObject(t);if(n.isEmpty()||!Number.isFinite(n.min.x)||!Number.isFinite(n.max.x))return null;let r=n.getSize(new c.Vector3),i=n.getCenter(new c.Vector3),a=Math.max(r.x,r.z);return{center:i,halfExtent:Math.max(a*e.DISC_FOOTPRINT_MARGIN+r.y*e.DISC_HEIGHT_STRETCH,e.DISC_MIN_HALF_EXTENT),objectHeight:r.y,boundingRadius:r.length()/2}}accumulateShadowPasses(e,t,n,r,i,a){let o=new c.Scene,s=t.parent;o.add(t);let l=this.disableColorWrite(t),u=this.createBakeLight(n);o.add(u),o.add(u.target),u.target.position.copy(n.target.parent?n.target.getWorldPosition(new c.Vector3):n.target.position);let d=new c.ShadowMaterial({transparent:!0,opacity:0,depthWrite:!1});d.blending=c.CustomBlending,d.blendEquation=c.AddEquation,d.blendSrc=c.OneFactor,d.blendDst=c.OneFactor;let f=new c.Mesh(a,d);f.rotation.x=-Math.PI/2,f.position.set(r.center.x,0,r.center.z),f.receiveShadow=!0,o.add(f);let p=this.createBakeCamera(r);o.add(p);let m=e.getRenderTarget(),h=e.autoClear,g=e.getClearColor(new c.Color),_=e.getClearAlpha(),v=e.shadowMap.autoUpdate;try{e.shadowMap.autoUpdate=!0,e.setRenderTarget(i),e.setClearColor(0,0),e.clear(!0,!1,!1),e.autoClear=!1;let t=this.explicitPasses??this.measureAffordablePasses(e,o,p,n,u,i);d.opacity=1/t;for(let i of this.sampleLightPositions(n,t))u.position.copy(i),this.fitBakeDepthRange(u,r),e.render(o,p)}finally{e.autoClear=h,e.setClearColor(g,_),e.setRenderTarget(m),e.shadowMap.autoUpdate=v,this.restoreColorWrite(l),s?s.add(t):o.remove(t),u.dispose(),d.dispose()}}measureAffordablePasses(t,n,r,i,a,o){a.position.copy(i.position),t.render(n,r),this.awaitGpuIdle(t,o);let s=performance.now();t.render(n,r),this.awaitGpuIdle(t,o);let l=Math.max(performance.now()-s,.01);return c.MathUtils.clamp(Math.round(e.BAKE_BUDGET_MS/l),e.MIN_PASSES,e.MAX_PASSES)}awaitGpuIdle(e,t){if(!e.capabilities.textureTypeReadable(t.texture.type))return;let n=t.texture.type===c.HalfFloatType?new Uint16Array(4):new Uint8Array(4);e.readRenderTargetPixels(t,0,0,1,1,n)}createBakeLight(t){let n=new c.DirectionalLight(16777215,1);n.castShadow=!0,n.shadow.mapSize.set(e.BAKE_SHADOW_MAP_SIZE,e.BAKE_SHADOW_MAP_SIZE),n.shadow.bias=0,n.shadow.normalBias=0,n.shadow.radius=6;let r=t.shadow.camera,i=n.shadow.camera;return i.left=r.left,i.right=r.right,i.top=r.top,i.bottom=r.bottom,i.updateProjectionMatrix(),n}fitBakeDepthRange(t,n){let r=t.target.position.clone().sub(t.position).normalize(),i=n.center.clone().sub(t.position).dot(r),a=n.boundingRadius*e.DEPTH_PADDING_FACTOR+n.halfExtent,o=t.shadow.camera;o.near=Math.max(i-a,i*.01),o.far=i+a,o.updateProjectionMatrix()}createBakeCamera(e){let t=new c.OrthographicCamera(-e.halfExtent,e.halfExtent,e.halfExtent,-e.halfExtent,.1,Math.max(e.objectHeight,1)*4);return t.position.set(e.center.x,Math.max(e.objectHeight,1)*2,e.center.z),t.up.set(0,0,-1),t.lookAt(e.center.x,0,e.center.z),t.updateProjectionMatrix(),t.updateMatrixWorld(!0),t}sampleLightPositions(t,n){let r=t.position.clone(),i=t.target.parent?t.target.getWorldPosition(new c.Vector3):t.target.position.clone(),a=i.clone().sub(r),o=a.length(),s=a.normalize(),l=new c.Vector3().crossVectors(s,new c.Vector3(0,1,0));l.lengthSq()<1e-6&&l.set(1,0,0),l.normalize();let u=new c.Vector3().crossVectors(s,l),d=Math.round(n*e.AMBIENT_RATIO),f=n-d,p=c.MathUtils.degToRad(e.LIGHT_APERTURE_DEGREES),m=Math.tan(p/2)*o,h=[];for(let e=0;e<f;e++){let t=m*Math.sqrt((e+.5)/f),n=e*Mn;h.push(r.clone().addScaledVector(l,t*Math.cos(n)).addScaledVector(u,t*Math.sin(n)))}let g=Math.sin(c.MathUtils.degToRad(e.AMBIENT_MIN_ELEVATION_DEGREES)),_=e.AMBIENT_MAX_ELEVATION_SIN;for(let e=0;e<d;e++){let t=Math.sqrt((e+.5)/d),n=g+(_-g)*t,r=Math.sqrt(1-n*n),a=e*Mn;h.push(new c.Vector3(r*Math.cos(a),n,r*Math.sin(a)).multiplyScalar(o).add(i))}return h}installBakedMesh(t,n,r,i){this.evictBakedMesh(t);let a=new c.MeshBasicMaterial({map:r.texture,transparent:!0,opacity:e.SHADOW_STRENGTH,depthWrite:!1,toneMapped:!1});a.onBeforeCompile=e=>{e.fragmentShader=e.fragmentShader.replace(`#include <map_fragment>`,`#include <map_fragment>
|
|
2
|
-
diffuseColor.a = pow(diffuseColor.a, 0.75);`)},a.customProgramCacheKey=()=>`contact-shadow-alpha-gamma`,a.addEventListener(`dispose`,()=>r.dispose());let o=new c.Mesh(i,a);o.name=On,o.userData[An]=!0,o.rotation.x=-Math.PI/2;let s=c.MathUtils.clamp(n.objectHeight*e.FLOOR_LIFT_PER_HEIGHT,e.FLOOR_LIFT_MIN,e.FLOOR_LIFT_MAX);o.position.set(n.center.x,s,n.center.z),o.userData.renderTarget=r,t.add(o);let l=t.getObjectByName(kn);l&&(l.visible=!1)}disableColorWrite(e){let t=new Map;return e.traverse(e=>{let n=e;if(!n.isMesh)return;let r=Array.isArray(n.material)?n.material:[n.material];for(let e of r)e&&!t.has(e)&&(t.set(e,e.colorWrite),e.colorWrite=!1)}),t}restoreColorWrite(e){e.forEach((e,t)=>{t.colorWrite=e})}},$=(e,t)=>{if(e&&typeof e==`object`){let n=e[t];if(typeof n==`function`)return n.call(e)}return null};function In(e){return $(e,`getThreeObject`)??(e instanceof c.Object3D?e:null)}function Ln(e){return $(e,`getThreeCamera`)??(e instanceof c.Camera?e:null)}function Rn(e){return $(e,`getThreeScene`)??(e instanceof c.Scene?e:null)}function zn(e){return $(e,`getThreeTexture`)??(e instanceof c.Texture?e:null)}function Bn(e){return $(e,`getThreeRenderer`)??(e instanceof c.WebGLRenderer?e:null)}function Vn(e){return $(e,`getThreeControls`)}var Hn=e=>e*e*(3-2*e);Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Ie}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Tn}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Bn}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return bn}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return On}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return jn}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return wn}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Sn}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return In}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Cn}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Rn}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Pn}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Vn}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return zn}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return kn}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return En}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return gn}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return Dn}});
|