softbox 4.18.0 → 4.19.0
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-B1WEEKgQ.cjs → ThreePathTracingService-CMw8SvGp.cjs} +51 -51
- package/dist/{ThreePathTracingService-qV8I_V9u.js → ThreePathTracingService-Dze7maGx.js} +415 -415
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/simple-viewer.cjs +3 -3
- package/dist/simple-viewer.es.js +1923 -1904
- package/dist/unwrap-CuSMMFPQ.cjs +2 -0
- package/dist/{ContactShadowBaker-MzqtJ-0h.js → unwrap-DdgS2iXe.js} +244 -209
- package/package.json +7 -3
- package/dist/ContactShadowBaker-lWQW97Cr.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=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,ye,be=[],xe=new ve(()=>new c.Box3);function Se(e,t,n,r,i,a){I=xe.getPrimitive(),ye=xe.getPrimitive(),be.push(I,ye),F.setBuffer(e._roots[t]);let o=Ce(0,e.geometry,n,r,i,a);F.clearBuffer(),xe.releasePrimitive(I),xe.releasePrimitive(ye),be.pop(),be.pop();let s=be.length;return s>0&&(ye=be[s-1],I=be[s-2]),o}function Ce(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=ye,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&&Ce(m,t,n,r,i,a,o+1);if(C)return!0;y=ye,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&&Ce(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 we=new F.constructor,Te=new F.constructor,L=new ve(()=>new c.Box3),R=new c.Box3,z=new c.Box3,Ee=new c.Box3,De=new c.Box3,Oe=!1;function ke(e,t,n,r){if(Oe)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Oe=!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++){we.setBuffer(i[e]),l=0;let t=L.getPrimitive();x(M(0),we.float32Array,t),t.applyMatrix4(u);for(let e=0,i=a.length;e<i&&(Te.setBuffer(a[e]),o=B(0,0,n,u,r,s,l,0,0,t),Te.clearBuffer(),l+=a[e].byteLength/32,!o);e++);if(L.releasePrimitive(t),we.clearBuffer(),s+=i[e].byteLength/32,o)break}return Oe=!1,o}function B(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=Te,f=we):(d=we,f=Te);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=L.getPrimitive();x(M(t),g,l),l.applyMatrix4(n);let d=A(e),f=j(e,m);x(M(d),p,R),x(M(f),p,z);let h=l.intersectsBox(R),_=l.intersectsBox(z);w=h&&B(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&B(t,f,r,n,i,o,a,c,s+1,l,!u),L.releasePrimitive(l)}else{let d=A(t),f=j(t,_);x(M(d),g,Ee),x(M(f),g,De);let h=l.intersectsBox(Ee),v=l.intersectsBox(De);if(h&&v)w=B(e,d,n,r,i,a,o,s,c+1,l,u)||B(e,f,n,r,i,a,o,s,c+1,l,u);else if(h)if(S)w=B(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=L.getPrimitive();t.copy(Ee).applyMatrix4(n);let l=A(e),f=j(e,m);x(M(l),p,R),x(M(f),p,z);let h=t.intersectsBox(R),g=t.intersectsBox(z);w=h&&B(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&B(d,f,r,n,i,o,a,c,s+1,t,!u),L.releasePrimitive(t)}else if(v)if(S)w=B(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=L.getPrimitive();t.copy(De).applyMatrix4(n);let l=A(e),d=j(e,m);x(M(l),p,R),x(M(d),p,z);let h=t.intersectsBox(R),g=t.intersectsBox(z);w=h&&B(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&B(f,d,r,n,i,o,a,c,s+1,t,!u),L.releasePrimitive(t)}}return w}var Ae=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)}})}}},je=new c.Box3,Me=new Float32Array(6),Ne=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,Me,0);let[e,t,r,u,d,f]=Me;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,Me,0);let[e,t,a,o,s,c]=Me,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){Ae.setBVH(this,t),Ae.traverse(e),Ae.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,Me,0),a.set(Me,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),je),e.union(je)}),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=Se(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return ke(this,e,t,r)}};function Pe(){return typeof SharedArrayBuffer<`u`}function Fe(e){return e.index?e.index.count:e.attributes.position.count}function Ie(e){return Fe(e)/3}function Le(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function Re(e,t){if(!e.index){let n=e.attributes.position.count,r=Le(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new c.BufferAttribute(r,1));for(let e=0;e<n;e++)r[e]=e}}function ze(e,t,n){let r=Fe(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 Be(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Ve(e,t,n){let r=ze(e,t,n),i=Be(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Fe(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 He(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 Ue=class extends Ne{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&&!Pe())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=He(Ve(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else Re(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}]:Ve(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},V=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}};V.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 We=(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}})(),Ge=(function(){let e=new c.Vector2,t=new c.Vector3,n=new c.Vector3;return function(r,i,a,o){We(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}}}})(),Ke=(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`],H=1e-15,Je=H*H;function U(e){return Math.abs(e)<H}var W=class extends c.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new c.Vector3),this.satBounds=[,,,,].fill().map(()=>new V),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 Ke(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<H?h<H||g<H?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<H?g<H?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<H&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};W.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]),Ge(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)}})(),W.prototype.intersectsTriangle=(function(){let e=new W,t=new V,n=new V,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 U(o)?U(s)?p(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):U(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 U(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)<Je?(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(U(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:U(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)<Je?(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);U(g)&&(g=0),U(_)&&(_=0),U(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);U(S)&&(S=0),U(C)&&(C=0),U(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=qe[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)}})(),W.prototype.distanceToPoint=(function(){let e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),W.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]),Ge(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 G=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 V),this.alignedSatBounds=[,,,].fill().map(()=>new V),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}};G.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}})(),G.prototype.intersectsBox=(function(){let e=new V;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}})(),G.prototype.intersectsTriangle=(function(){let e=new W,t=[,,,],n=new V,r=new V,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}})(),G.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}})(),G.prototype.distanceToPoint=(function(){let e=new c.Vector3;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),G.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];Ge(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 K=new class extends ve{constructor(){super(()=>new W)}},Ye=new c.Vector3,Xe=new c.Vector3;function Ze(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=>(Ye.copy(t).clamp(e.min,e.max),Ye.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,Ye);let r=t.distanceToSquared(Ye);return r<s&&(Xe.copy(Ye),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(Xe):n.point=Xe.clone(),n.distance=l,n.faceIndex=c,n}var Qe=parseInt(c.REVISION)>=169,$e=parseInt(c.REVISION)<=161,q=new c.Vector3,J=new c.Vector3,Y=new c.Vector3,et=new c.Vector2,tt=new c.Vector2,nt=new c.Vector2,rt=new c.Vector3,it=new c.Vector3,at=new c.Vector3,ot=new c.Vector3;function st(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 ct(e,t,n,r,i,a,o,s,l,u,d){q.fromBufferAttribute(t,a),J.fromBufferAttribute(t,o),Y.fromBufferAttribute(t,s);let f=st(e,q,J,Y,ot,l,u,d);if(f){if(r){et.fromBufferAttribute(r,a),tt.fromBufferAttribute(r,o),nt.fromBufferAttribute(r,s),f.uv=new c.Vector2;let e=c.Triangle.getInterpolation(ot,q,J,Y,et,tt,nt,f.uv);Qe||(f.uv=e)}if(i){et.fromBufferAttribute(i,a),tt.fromBufferAttribute(i,o),nt.fromBufferAttribute(i,s),f.uv1=new c.Vector2;let e=c.Triangle.getInterpolation(ot,q,J,Y,et,tt,nt,f.uv1);Qe||(f.uv1=e),$e&&(f.uv2=f.uv1)}if(n){rt.fromBufferAttribute(n,a),it.fromBufferAttribute(n,o),at.fromBufferAttribute(n,s),f.normal=new c.Vector3;let t=c.Triangle.getInterpolation(ot,q,J,Y,rt,it,at,f.normal);f.normal.dot(e.direction)>0&&f.normal.multiplyScalar(-1),Qe||(f.normal=t)}let t={a,b:o,c:s,normal:new c.Vector3,materialIndex:0};if(c.Triangle.getNormal(q,J,Y,t.normal),f.face=t,f.faceIndex=a,Qe){let e=new c.Vector3;c.Triangle.getBarycoord(ot,q,J,Y,e),f.barycoord=e}}return f}function lt(e){return e&&e.isMaterial?e.side:e}function ut(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=lt(t[v]),s=ct(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=lt(t),s=ct(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 X(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 dt(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)ut(c,t,n,e,a,o,s)}function ft(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=ut(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function pt(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,X(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function mt(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 Z(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 ht(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)ut(c,t,n,l?l[e]:e,a,o,s)}function gt(e,t,n,r,i,a,o){let{geometry:s,_indirectBuffer:c}=e,l=1/0,u=null;for(let e=r,d=r+i;e<d;e++){let r;r=ut(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function _t(e,t,n,r,i,a,o){let{geometry:s}=n,{index:c}=s,l=s.attributes.position;for(let s=e,u=t+e;s<u;s++){let e;if(e=n.resolveTriangleIndex(s),X(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function vt(e,t,n,r,i,a,o){F.setBuffer(e._roots[t]),yt(0,e,n,r,i,a,o),F.clearBuffer()}function yt(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(D(u,c))dt(t,n,r,O(e,l),k(u,c),i,a,o);else{let c=A(e);Z(c,s,r,a,o)&&yt(c,t,n,r,i,a,o);let u=j(e,l);Z(u,s,r,a,o)&&yt(u,t,n,r,i,a,o)}}var bt=[`x`,`y`,`z`];function xt(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=St(0,e,n,r,i,a);return F.clearBuffer(),o}function St(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(D(l,s))return ft(t,n,r,O(e,c),k(l,s),i,a);{let s=ee(e,c),l=bt[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=Z(d,o,r,i,a)?St(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=Z(f,o,r,i,a)?St(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Ct=new c.Box3,Q=new W,wt=new W,Tt=new c.Matrix4,Et=new G,Dt=new G;function Ot(e,t,n,r){F.setBuffer(e._roots[t]);let i=kt(0,e,n,r);return F.clearBuffer(),i}function kt(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Et.set(n.boundingBox.min,n.boundingBox.max,r),i=Et),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(Tt.copy(r).invert(),n.boundsTree)return x(M(e),a,Dt),Dt.matrix.copy(Tt),Dt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Dt.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(X(wt,t,l,u),wt.needsUpdate=!0,e.intersectsTriangle(wt))return!0;return!1}});{let e=Ie(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){X(Q,t,l,u),Q.a.applyMatrix4(Tt),Q.b.applyMatrix4(Tt),Q.c.applyMatrix4(Tt),Q.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(X(wt,t,d,f),wt.needsUpdate=!0,Q.intersectsTriangle(wt))return!0}}}else{let o=A(e),c=j(e,s);return x(M(o),a,Ct),!!(i.intersectsBox(Ct)&&kt(o,t,n,r,i)||(x(M(c),a,Ct),i.intersectsBox(Ct)&&kt(c,t,n,r,i)))}}var At=new c.Matrix4,jt=new G,Mt=new G,Nt=new c.Vector3,Pt=new c.Vector3,Ft=new c.Vector3,It=new c.Vector3;function Lt(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),jt.set(t.boundingBox.min,t.boundingBox.max,n),jt.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=K.getPrimitive(),p=K.getPrimitive(),m=Nt,h=Pt,g=null,_=null;i&&(g=Ft,_=It);let v=1/0,y=null,b=null;return At.copy(n).invert(),Mt.matrix.copy(At),e.shapecast({boundsTraverseOrder:e=>jt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(Mt.min.copy(e.min),Mt.max.copy(e.max),Mt.needsUpdate=!0),!0):!1,intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Mt.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){X(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++){X(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=Ie(t);for(let t=0,o=i;t<o;t++){X(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++){X(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}}}}}),K.releasePrimitive(f),K.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(At),h.applyMatrix4(At),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Rt(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 zt(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))ht(t,n,r,O(e,l),k(u,c),i,a,o);else{let c=A(e);Z(c,s,r,a,o)&&Bt(c,t,n,r,i,a,o);let u=j(e,l);Z(u,s,r,a,o)&&Bt(u,t,n,r,i,a,o)}}var Vt=[`x`,`y`,`z`];function Ht(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=Ut(0,e,n,r,i,a);return F.clearBuffer(),o}function Ut(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(D(l,s))return gt(t,n,r,O(e,c),k(l,s),i,a);{let s=ee(e,c),l=Vt[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=Z(d,o,r,i,a)?Ut(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=Z(f,o,r,i,a)?Ut(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Wt=new c.Box3,Gt=new W,Kt=new W,qt=new c.Matrix4,Jt=new G,Yt=new G;function Xt(e,t,n,r){F.setBuffer(e._roots[t]);let i=Zt(0,e,n,r);return F.clearBuffer(),i}function Zt(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Jt.set(n.boundingBox.min,n.boundingBox.max,r),i=Jt),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(qt.copy(r).invert(),n.boundsTree)return x(M(e),a,Yt),Yt.matrix.copy(qt),Yt.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Yt.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(X(Kt,3*t.resolveTriangleIndex(n),l,u),Kt.needsUpdate=!0,e.intersectsTriangle(Kt))return!0;return!1}});{let e=Ie(n);for(let n=p,r=m+p;n<r;n++){X(Gt,3*t.resolveTriangleIndex(n),l,u),Gt.a.applyMatrix4(qt),Gt.b.applyMatrix4(qt),Gt.c.applyMatrix4(qt),Gt.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(X(Kt,t,d,f),Kt.needsUpdate=!0,Gt.intersectsTriangle(Kt))return!0}}}else{let o=A(e),c=j(e,s);return x(M(o),a,Wt),!!(i.intersectsBox(Wt)&&Zt(o,t,n,r,i)||(x(M(c),a,Wt),i.intersectsBox(Wt)&&Zt(c,t,n,r,i)))}}var Qt=new c.Matrix4,$t=new G,en=new G,tn=new c.Vector3,nn=new c.Vector3,rn=new c.Vector3,an=new c.Vector3;function on(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),$t.set(t.boundingBox.min,t.boundingBox.max,n),$t.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=K.getPrimitive(),p=K.getPrimitive(),m=tn,h=nn,g=null,_=null;i&&(g=rn,_=an);let v=1/0,y=null,b=null;return Qt.copy(n).invert(),en.matrix.copy(Qt),e.shapecast({boundsTraverseOrder:e=>$t.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o?(t&&(en.min.copy(e.min),en.max.copy(e.max),en.needsUpdate=!0),!0):!1,intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>en.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);X(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);X(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=Ie(t);for(let t=0,s=o;t<s;t++){X(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);X(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}}}}}),K.releasePrimitive(f),K.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(Qt),h.applyMatrix4(Qt),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function sn(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 cn=new G,ln=new c.Ray,un=new c.Vector3,dn=new c.Matrix4,fn=new c.Vector3,pn=[`getX`,`getY`,`getZ`],mn=class e extends Ue{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[pn[e]](c),i=a[pn[e]](l),o=a[pn[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;dn.copy(e.matrixWorld).invert(),ln.copy(t.ray).applyMatrix4(dn),fn.setFromMatrixScale(e.matrixWorld),un.copy(ln.direction).multiply(fn);let i=un.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(ln,r,a,o);i=sn(i,e,t),i&&n.push(i)}else{let i=this.raycast(ln,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=sn(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?Rt:mt)(this,e)}raycast(e,t=c.FrontSide,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?zt:vt;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?Ht:xt;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?Xt:Ot;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=K.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?_t:pt});return K.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=K.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);X(o,t*3,s,c)}:e=>{X(o,e*3,s,c)},u=K.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);X(u,n*3,d,f)}:e=>{X(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 cn.set(e.min,e.max,t),cn.needsUpdate=!0,this.shapecast({intersectsBounds:e=>cn.intersectsBox(e),intersectsTriangle:e=>cn.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?on:Lt)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return Ze(this,e,t,n,r)}},hn={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},$=new c.Mesh,gn=[];function _n(e,t){if(this.isBatchedMesh)vn.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=hn.Mesh;else if(this instanceof c.LineSegments)n=hn.LineSegments;else if(this instanceof c.LineLoop)n=hn.LineLoop;else if(this instanceof c.Line)n=hn.Line;else if(this instanceof c.Points)n=hn.Points;else throw Error(`BVH: Fallback raycast function not found.`);n.call(this,e,t)}}}function vn(e,t){if(this.boundsTrees){let n=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,a=this.matrixWorld;$.material=this.material,$.geometry=this.geometry;let o=$.geometry.boundsTree,s=$.geometry.drawRange;$.geometry.boundingSphere===null&&($.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($.geometry.boundsTree=n[s],this.getMatrixAt(o,$.matrixWorld).premultiply(a),!$.geometry.boundsTree){this.getBoundingBoxAt(s,$.geometry.boundingBox),this.getBoundingSphereAt(s,$.geometry.boundingSphere);let e=i[s];$.geometry.setDrawRange(e.start,e.count)}$.raycast(e,gn);for(let e=0,n=gn.length;e<n;e++){let n=gn[e];n.object=this,n.batchId=o,t.push(n)}gn.length=0}$.geometry.boundsTree=o,$.geometry.drawRange=s,$.material=null,$.geometry=null}else hn.BatchedMesh.call(this,e,t)}function yn(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 mn(n),t.raycast=_n)})}function bn(e){e.boundsTree&&=void 0}function xn(e){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()}function Sn(e){e.traverse(e=>{let t=e;t.geometry&&typeof t.geometry.dispose==`function`&&(bn(t.geometry),t.geometry.dispose());let n=t.material;Array.isArray(n)?n.forEach(xn):n&&xn(n);let r=e;r.isLight&&r.shadow?.dispose&&r.shadow.dispose()})}function Cn(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 t of[...e.children])Sn(t),e.remove(t)}var wn=`contact-shadow-baked`,Tn=`contact-shadow-live`,En=`softboxContactShadowHelper`,Dn=`softboxPathTracingFloor`,On=Math.PI*(3-Math.sqrt(5));function kn(e){let t=e.getObjectByName(wn);t&&(e.remove(t),Sn(t))}function An(e){kn(e);let t=e.getObjectByName(Tn);t&&(t.visible=!0)}var jn=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(Tn);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){An(e)}evictBakedMesh(e){kn(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*On;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*On;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=wn,o.userData[En]=!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(Tn);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})}},Mn=(e,t)=>{if(e&&typeof e==`object`){let n=e[t];if(typeof n==`function`)return n.call(e)}return null};function Nn(e){return Mn(e,`getThreeObject`)??(e instanceof c.Object3D?e:null)}function Pn(e){return Mn(e,`getThreeCamera`)??(e instanceof c.Camera?e:null)}function Fn(e){return Mn(e,`getThreeScene`)??(e instanceof c.Scene?e:null)}function In(e){return Mn(e,`getThreeTexture`)??(e instanceof c.Texture?e:null)}function Ln(e){return Mn(e,`getThreeRenderer`)??(e instanceof c.WebGLRenderer?e:null)}function Rn(e){return Mn(e,`getThreeControls`)}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Le}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return En}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Dn}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return mn}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return yn}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Tn}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Cn}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Rn}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return In}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Sn}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return Nn}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return wn}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Pn}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return jn}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return M}});
|