scad-gltf 0.3.3 → 0.5.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/README.md +46 -18
- package/bin/gen.js +1 -1
- package/bin/mcp.js +198 -69
- package/editor/dist/assets/{index-B1KAb97r.css → index-D8In1wnN.css} +1 -1
- package/editor/dist/assets/{index-CgVih1C4.js → index-b4iPmEjR.js} +204 -92
- package/editor/dist/assets/{openscad-CdBCY4mx.wasm → openscad-DJJQxKJM.wasm} +0 -0
- package/editor/dist/assets/preview-Cx3FHqKG.css +1 -0
- package/editor/dist/assets/preview-DfaOpP2w.js +1 -0
- package/editor/dist/assets/{prompt-ui-B9QCNLfJ.js → prompt-ui-zw7U8lsl.js} +5 -3
- package/editor/dist/assets/shared-CDFEFgsW.js +4315 -0
- package/editor/dist/content.js +1 -1
- package/editor/dist/index.html +11 -6
- package/editor/dist/preview.html +20 -15
- package/editor/dist/sw.js +1 -1
- package/godot/addons/scad_importer/plugin.cfg +0 -1
- package/godot/addons/scad_importer/scad_importer.gd +3 -153
- package/godot/addons/scad_importer/scad_plugin.gd +0 -3
- package/package.json +4 -4
- package/src/cli-utils.js +406 -376
- package/src/ext/openscad.js +1 -1
- package/src/ext/openscad.wasm +0 -0
- package/src/project-prompts.js +111 -87
- package/src/prompt.js +21 -0
- package/editor/dist/assets/OutputPass-B6MrFnGE.js +0 -4317
- package/editor/dist/assets/preview-A6M04CFK.css +0 -1
- package/editor/dist/assets/preview-BbUpKLF4.js +0 -1
- package/godot/README.md +0 -64
- package/godot/addons/scad_importer/LICENSE +0 -21
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as f,M as p,N as m,O as h,P as g,Q as _,R as v,S as y,T as b,U as x,V as S,W as C,X as w,Y as ee,Z as te,_ as T,a as ne,at as re,b as ie,c as ae,ct as oe,d as se,dt as ce,et as le,f as ue,ft as de,g as fe,h as pe,ht as me,i as he,it as ge,j as _e,k as ve,l as ye,lt as E,m as be,mt as xe,n as Se,nt as Ce,o as we,ot as Te,p as Ee,pt as De,q as Oe,r as ke,rt as Ae,s as je,st as Me,t as Ne,tt as Pe,u as Fe,ut as D,v as Ie,w as Le,x as Re,y as ze,z as Be}from"./OutputPass-B6MrFnGE.js";import{i as Ve,n as He,r as Ue,t as We}from"./prompt-ui-B9QCNLfJ.js";var Ge=1.25,Ke=65535,qe=-65536,Je=2**-24,Ye=Symbol(`SKIP_GENERATION`),Xe={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ye]:!1};function O(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 Ze(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 Qe(e,t){t.set(e)}function $e(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 et(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 tt(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]===Ke}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 nt(e,t){return t[e+7]}function P(e){return e}function rt(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,ee=S+C;w<s&&(s=w),ee>u&&(u=ee),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 it=32,at=(e,t)=>e.candidate-t.candidate,ot=Array(it).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),st=new Float32Array(6);function ct(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Ze(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Ze(e),o!==-1&&(s=lt(n,r,i,o));else if(a===2){let a=tt(e),c=Ge*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)/it;if(i<it/4){let t=[...ot];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;et(i,n,o)}t.sort(at);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?et(r,n,a.rightCacheBounds):(et(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=tt(d)/a);let m=0;u!==0&&(m=tt(f)/a);let h=1+Ge*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<it;e++){let t=ot[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>=it&&(i=31);let a=ot[i];a.count++,et(t,n,a.bounds)}let t=ot[31];Qe(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=ot[e],n=ot[e+1];$e(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=ot[t],r=n.count,l=n.bounds,u=ot[t+1].rightCacheBounds;r!==0&&(f===0?Qe(l,st):$e(l,st,st)),f+=r;let d=0,p=0;f!==0&&(d=tt(st)/a);let m=i-f;m!==0&&(p=tt(u)/a);let h=1+Ge*(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 lt(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 ut=class{constructor(){this.boundingData=new Float32Array(6)}};function dt(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 ft,pt,mt,ht,gt=2**32;function _t(e){return`count`in e?1:1+_t(e.left)+_t(e.right)}function vt(e,t,n){return ft=new Float32Array(n),pt=new Uint32Array(n),mt=new Uint16Array(n),ht=new Uint8Array(n),yt(e,t)}function yt(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)ft[n+e]=a[e];if(i)return t.buffer?(ht.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(pt[n+6]=t.offset,mt[r+14]=t.count,mt[r+15]=Ke,e+32);{let{left:r,right:i,splitAxis:a}=t,o=yt(e+32,r),s=e/32,c=o/32-s;if(c>gt)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return pt[n+6]=c,pt[n+7]=a,yt(o,i)}}function bt(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 ut;return rt(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=ct(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:dt(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,Ze(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new ut,x=n,S=y-n;e.left=b,rt(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new ut,w=y,ee=r-S;return e.right=C,rt(t,w,ee,C.boundingData,m),v(C,w,ee,m,a+1),e}}function xt(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=bt(e,s,r.offset,r.count,t,o),a=_t(i),c=new n(32*a);return vt(0,i,c),c})}var St=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())}}},Ct,wt,Tt=[],Et=new St(()=>new Ee);function Dt(e,t,n,r,i,a){Ct=Et.getPrimitive(),wt=Et.getPrimitive(),Tt.push(Ct,wt),F.setBuffer(e._roots[t]);let o=Ot(0,e.geometry,n,r,i,a);F.clearBuffer(),Et.releasePrimitive(Ct),Et.releasePrimitive(wt),Tt.pop(),Tt.pop();let s=Tt.length;return s>0&&(wt=Tt[s-1],Ct=Tt[s-2]),o}function Ot(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(k(u,c)){let t=A(e,l),n=j(u,c);return O(P(e),s,Ct),r(t,n,!1,o,a+e/8,Ct)}{let u=M(e),d=N(e,l),f=u,p=d,m,h,g,_;if(i&&(g=Ct,_=wt,O(P(f),s,g),O(P(p),s,_),m=i(g),h=i(_),h<m)){f=d,p=u;let e=m;m=h,h=e,g=_}g||(g=Ct,O(P(f),s,g));let v=k(f*2,c),y=n(g,v,m,o+1,a+f/8),b;if(y===2){let e=w(f);b=r(e,ee(f)-e,!0,o+1,a+f/8,g)}else b=y&&Ot(f,t,n,r,i,a,o+1);if(b)return!0;_=wt,O(P(p),s,_);let x=k(p*2,c),S=n(_,x,h,o+1,a+p/8),C;if(S===2){let e=w(p);C=r(e,ee(p)-e,!0,o+1,a+p/8,_)}else C=S&&Ot(p,t,n,r,i,a,o+1);return!!C;function w(e){let{uint16Array:t,uint32Array:n}=F,r=e*2;for(;!k(r,t);)e=M(e),r=e*2;return A(e,n)}function ee(e){let{uint16Array:t,uint32Array:n}=F,r=e*2;for(;!k(r,t);)e=N(e,n),r=e*2;return A(e,n)+j(r,t)}}}var kt=new F.constructor,At=new F.constructor,jt=new St(()=>new Ee),Mt=new Ee,Nt=new Ee,Pt=new Ee,Ft=new Ee,It=!1;function Lt(e,t,n,r){if(It)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);It=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new f().copy(n).invert();for(let e=0,t=i.length;e<t;e++){kt.setBuffer(i[e]),c=0;let t=jt.getPrimitive();O(P(0),kt.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(At.setBuffer(a[e]),o=Rt(0,0,n,l,r,s,c,0,0,t),At.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(jt.releasePrimitive(t),kt.clearBuffer(),s+=i[e].byteLength/32,o)break}return It=!1,o}function Rt(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=At,f=kt):(d=kt,f=At);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=jt.getPrimitive();O(P(t),g,l),l.applyMatrix4(n);let d=M(e),f=N(e,m);O(P(d),p,Mt),O(P(f),p,Nt);let h=l.intersectsBox(Mt),_=l.intersectsBox(Nt);C=h&&Rt(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&Rt(t,f,r,n,i,o,a,c,s+1,l,!u),jt.releasePrimitive(l)}else{let d=M(t),f=N(t,_);O(P(d),g,Pt),O(P(f),g,Ft);let h=l.intersectsBox(Pt),v=l.intersectsBox(Ft);if(h&&v)C=Rt(e,d,n,r,i,a,o,s,c+1,l,u)||Rt(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=Rt(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=jt.getPrimitive();t.copy(Pt).applyMatrix4(n);let l=M(e),f=N(e,m);O(P(l),p,Mt),O(P(f),p,Nt);let h=t.intersectsBox(Mt),g=t.intersectsBox(Nt);C=h&&Rt(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&Rt(d,f,r,n,i,o,a,c,s+1,t,!u),jt.releasePrimitive(t)}}else if(v){if(x)C=Rt(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=jt.getPrimitive();t.copy(Ft).applyMatrix4(n);let l=M(e),d=N(e,m);O(P(l),p,Mt),O(P(d),p,Nt);let h=t.intersectsBox(Mt),g=t.intersectsBox(Nt);C=h&&Rt(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&Rt(f,d,r,n,i,o,a,c,s+1,t,!u),jt.releasePrimitive(t)}}}return C}var zt=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)}{let n=nt(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Bt=new Ee,Vt=new Float32Array(6),Ht=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Xe,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),xt(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,Vt,0);let[e,t,r,u,d,f]=Vt;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,Vt,0);let[e,t,a,o,s,c]=Vt,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)*Je,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*Je,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*Je}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){zt.setBVH(this,t),zt.traverse(e),zt.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,Vt,0),a.set(Vt,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=>{O(0,new Float32Array(t),Bt),e.union(Bt)}),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=Dt(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Lt(this,e,t,r)}};function Ut(){return typeof SharedArrayBuffer<`u`}function Wt(e){return e.index?e.index.count:e.attributes.position.count}function Gt(e){return Wt(e)/3}function Kt(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function qt(e,t){if(!e.index){let n=e.attributes.position.count,r=Kt(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new be(r,1));for(let e=0;e<n;e++)r[e]=e}}function Jt(e,t,n){let r=Wt(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 Yt(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Xt(e,t,n){let r=Jt(e,t,n),i=Yt(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Wt(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 Zt(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 Qt=class extends Ht{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&&!Ut())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={...Xe,...t},t[Ye]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=Zt(Xt(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else qt(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new Ee))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Xt(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},$t=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}};$t.prototype.setFromBox=(function(){let e=new D;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 en=(function(){let e=new D,t=new D,n=new D;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}})(),tn=(function(){let e=new E,t=new D,n=new D;return function(r,i,a,o){en(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}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{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}a.copy(e),o.copy(d);return}}})(),nn=(function(){let e=new D,t=new D,n=new x,r=new p;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}})(),rn=[`x`,`y`,`z`],an=1e-15,on=an*an;function sn(e){return Math.abs(e)<an}var cn=class extends re{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new D),this.satBounds=[,,,,].fill().map(()=>new $t),this.points=[this.a,this.b,this.c],this.plane=new x,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new p,this.needsUpdate=!0}intersectsSphere(e){return nn(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<an?h<an||g<an?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<an?g<an?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<an&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};cn.prototype.closestPointToSegment=(function(){let e=new D,t=new D,n=new p;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]),tn(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)}})(),cn.prototype.intersectsTriangle=(function(){let e=new cn,t=new $t,n=new $t,r=new D,i=new D,a=new D,o=new D,s=new p,c=new p,l=new D,u=new E,d=new E;function f(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 sn(o)?sn(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):sn(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function _(e,t,n){let r=t.a;return sn(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)<on&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}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(sn(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:sn(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}return t.isDegenerateIntoPoint?v(e,t,n):g(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<on&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?v(t,e,n):_(t,e,n);if(t.isDegenerateIntoPoint)return _(e,t,n);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 p=this.plane,m=t.plane,g=m.distanceToPoint(this.a),_=m.distanceToPoint(this.b),v=m.distanceToPoint(this.c);sn(g)&&(g=0),sn(_)&&(_=0),sn(v)&&(v=0);let b=g*_,x=g*v;if(b>0&&x>0)return!1;let S=p.distanceToPoint(t.a),C=p.distanceToPoint(t.b),w=p.distanceToPoint(t.c);sn(S)&&(S=0),sn(C)&&(C=0),sn(w)&&(w=0);let ee=S*C,te=S*w;if(ee>0&&te>0)return!1;i.copy(p.normal),a.copy(m.normal);let T=i.cross(a),ne=0,re=Math.abs(T.x),ie=Math.abs(T.y);ie>re&&(re=ie,ne=1),Math.abs(T.z)>re&&(ne=2);let ae=rn[ne],oe=this.a[ae],se=this.b[ae],ce=this.c[ae],le=t.a[ae],ue=t.b[ae],de=t.c[ae];if(h(this,oe,se,ce,b,x,g,_,v,u,s)||h(t,le,ue,de,ee,te,S,C,w,d,c))return f(this,t,n,r);if(u.y<u.x){let e=u.y;u.y=u.x,u.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(n&&(d.x>u.x?n.start.copy(c.start):n.start.copy(s.start),d.y<u.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),cn.prototype.distanceToPoint=(function(){let e=new D;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),cn.prototype.distanceToTriangle=(function(){let e=new D,t=new D,n=[`a`,`b`,`c`],r=new p,i=new p;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]),tn(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 I=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new D,this.max=new D,this.matrix=new f,this.invMatrix=new f,this.points=Array(8).fill().map(()=>new D),this.satAxes=[,,,].fill().map(()=>new D),this.satBounds=[,,,].fill().map(()=>new $t),this.alignedSatBounds=[,,,].fill().map(()=>new $t),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}};I.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}})(),I.prototype.intersectsBox=(function(){let e=new $t;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}})(),I.prototype.intersectsTriangle=(function(){let e=new cn,t=[,,,],n=new $t,r=new $t,i=new D;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}})(),I.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}})(),I.prototype.distanceToPoint=(function(){let e=new D;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),I.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new p),n=Array(12).fill().map(()=>new p),r=new D,i=new D;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];tn(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 ln=new class extends St{constructor(){super(()=>new cn)}},un=new D,dn=new D;function fn(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=>(un.copy(t).clamp(e.min,e.max),un.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,un);let r=t.distanceToSquared(un);return r<s&&(dn.copy(un),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(dn):n.point=dn.clone(),n.distance=l,n.faceIndex=c,n}var pn=!0,mn=new D,hn=new D,gn=new D,_n=new E,vn=new E,yn=new E,bn=new D,xn=new D,Sn=new D,Cn=new D;function wn(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function Tn(e,t,n,r,i,a,o,s,c,l,u){mn.fromBufferAttribute(t,a),hn.fromBufferAttribute(t,o),gn.fromBufferAttribute(t,s);let d=wn(e,mn,hn,gn,Cn,c,l,u);if(d){if(r){_n.fromBufferAttribute(r,a),vn.fromBufferAttribute(r,o),yn.fromBufferAttribute(r,s),d.uv=new E;let e=re.getInterpolation(Cn,mn,hn,gn,_n,vn,yn,d.uv);pn||(d.uv=e)}if(i){_n.fromBufferAttribute(i,a),vn.fromBufferAttribute(i,o),yn.fromBufferAttribute(i,s),d.uv1=new E;let e=re.getInterpolation(Cn,mn,hn,gn,_n,vn,yn,d.uv1);pn||(d.uv1=e)}if(n){bn.fromBufferAttribute(n,a),xn.fromBufferAttribute(n,o),Sn.fromBufferAttribute(n,s),d.normal=new D;let t=re.getInterpolation(Cn,mn,hn,gn,bn,xn,Sn,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),pn||(d.normal=t)}let t={a,b:o,c:s,normal:new D,materialIndex:0};if(re.getNormal(mn,hn,gn,t.normal),d.face=t,d.faceIndex=a,pn){let e=new D;re.getBarycoord(Cn,mn,hn,gn,e),d.barycoord=e}}return d}function En(e){return e&&e.isMaterial?e.side:e}function Dn(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=En(t[v]),s=Tn(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=En(t),s=Tn(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 L(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 On(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Dn(c,t,n,e,a,o,s)}function kn(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=Dn(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function An(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,L(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function jn(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}{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 Mn(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 Nn(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Dn(c,t,n,l?l[e]:e,a,o,s)}function Pn(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=Dn(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Fn(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),L(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function In(e,t,n,r,i,a,o){F.setBuffer(e._roots[t]),Ln(0,e,n,r,i,a,o),F.clearBuffer()}function Ln(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(k(u,c))On(t,n,r,A(e,l),j(u,c),i,a,o);else{let c=M(e);Mn(c,s,r,a,o)&&Ln(c,t,n,r,i,a,o);let u=N(e,l);Mn(u,s,r,a,o)&&Ln(u,t,n,r,i,a,o)}}var Rn=[`x`,`y`,`z`];function zn(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=Bn(0,e,n,r,i,a);return F.clearBuffer(),o}function Bn(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(k(l,s))return kn(t,n,r,A(e,c),j(l,s),i,a);{let s=nt(e,c),l=Rn[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=Mn(d,o,r,i,a)?Bn(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=Mn(f,o,r,i,a)?Bn(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Vn=new Ee,Hn=new cn,Un=new cn,Wn=new f,Gn=new I,Kn=new I;function qn(e,t,n,r){F.setBuffer(e._roots[t]);let i=Jn(0,e,n,r);return F.clearBuffer(),i}function Jn(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Gn.set(n.boundingBox.min,n.boundingBox.max,r),i=Gn),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(Wn.copy(r).invert(),n.boundsTree)return O(P(e),a,Kn),Kn.matrix.copy(Wn),Kn.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>Kn.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(L(Un,t,l,u),Un.needsUpdate=!0,e.intersectsTriangle(Un))return!0;return!1}});{let e=Gt(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){L(Hn,t,l,u),Hn.a.applyMatrix4(Wn),Hn.b.applyMatrix4(Wn),Hn.c.applyMatrix4(Wn),Hn.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(L(Un,t,d,f),Un.needsUpdate=!0,Hn.intersectsTriangle(Un))return!0}}}else{let o=M(e),c=N(e,s);return O(P(o),a,Vn),!!(i.intersectsBox(Vn)&&Jn(o,t,n,r,i)||(O(P(c),a,Vn),i.intersectsBox(Vn)&&Jn(c,t,n,r,i)))}}var Yn=new f,Xn=new I,Zn=new I,Qn=new D,$n=new D,er=new D,tr=new D;function nr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Xn.set(t.boundingBox.min,t.boundingBox.max,n),Xn.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=ln.getPrimitive(),p=ln.getPrimitive(),m=Qn,h=$n,g=null,_=null;i&&(g=er,_=tr);let v=1/0,y=null,b=null;return Yn.copy(n).invert(),Zn.matrix.copy(Yn),e.shapecast({boundsTraverseOrder:e=>Xn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Zn.min.copy(e.min),Zn.max.copy(e.max),Zn.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Zn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){L(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++){L(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=Gt(t);for(let t=0,o=i;t<o;t++){L(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++){L(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}}}}}),ln.releasePrimitive(f),ln.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(Yn),h.applyMatrix4(Yn),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function rr(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}{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 ir(e,t,n,r,i,a,o){F.setBuffer(e._roots[t]),ar(0,e,n,r,i,a,o),F.clearBuffer()}function ar(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=F,u=e*2;if(k(u,c))Nn(t,n,r,A(e,l),j(u,c),i,a,o);else{let c=M(e);Mn(c,s,r,a,o)&&ar(c,t,n,r,i,a,o);let u=N(e,l);Mn(u,s,r,a,o)&&ar(u,t,n,r,i,a,o)}}var or=[`x`,`y`,`z`];function sr(e,t,n,r,i,a){F.setBuffer(e._roots[t]);let o=cr(0,e,n,r,i,a);return F.clearBuffer(),o}function cr(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=F,l=e*2;if(k(l,s))return Pn(t,n,r,A(e,c),j(l,s),i,a);{let s=nt(e,c),l=or[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=Mn(d,o,r,i,a)?cr(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=Mn(f,o,r,i,a)?cr(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var lr=new Ee,ur=new cn,dr=new cn,fr=new f,pr=new I,mr=new I;function hr(e,t,n,r){F.setBuffer(e._roots[t]);let i=gr(0,e,n,r);return F.clearBuffer(),i}function gr(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=F,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),pr.set(n.boundingBox.min,n.boundingBox.max,r),i=pr),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(fr.copy(r).invert(),n.boundsTree)return O(P(e),a,mr),mr.matrix.copy(fr),mr.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>mr.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(L(dr,3*t.resolveTriangleIndex(n),l,u),dr.needsUpdate=!0,e.intersectsTriangle(dr))return!0;return!1}});{let e=Gt(n);for(let n=p,r=m+p;n<r;n++){L(ur,3*t.resolveTriangleIndex(n),l,u),ur.a.applyMatrix4(fr),ur.b.applyMatrix4(fr),ur.c.applyMatrix4(fr),ur.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(L(dr,t,d,f),dr.needsUpdate=!0,ur.intersectsTriangle(dr))return!0}}}else{let o=M(e),c=N(e,s);return O(P(o),a,lr),!!(i.intersectsBox(lr)&&gr(o,t,n,r,i)||(O(P(c),a,lr),i.intersectsBox(lr)&&gr(c,t,n,r,i)))}}var _r=new f,vr=new I,yr=new I,br=new D,xr=new D,Sr=new D,Cr=new D;function wr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),vr.set(t.boundingBox.min,t.boundingBox.max,n),vr.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=ln.getPrimitive(),p=ln.getPrimitive(),m=br,h=xr,g=null,_=null;i&&(g=Sr,_=Cr);let v=1/0,y=null,b=null;return _r.copy(n).invert(),yr.matrix.copy(_r),e.shapecast({boundsTraverseOrder:e=>vr.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(yr.min.copy(e.min),yr.max.copy(e.max),yr.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>yr.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);L(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);L(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}}}})}{let o=Gt(t);for(let t=0,s=o;t<s;t++){L(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);L(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}}}}}),ln.releasePrimitive(f),ln.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(_r),h.applyMatrix4(_r),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Tr(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 Er=new I,Dr=new w,Or=new D,kr=new f,Ar=new D,jr=[`getX`,`getY`,`getZ`],Mr=class e extends Qt{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[Ye]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new be(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;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[jr[e]](c),i=a[jr[e]](l),o=a[jr[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)*Je}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;kr.copy(e.matrixWorld).invert(),Dr.copy(t.ray).applyMatrix4(kr),Ar.setFromMatrixScale(e.matrixWorld),Or.copy(Dr.direction).multiply(Ar);let i=Or.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(Dr,r,a,o);i=Tr(i,e,t),i&&n.push(i)}else{let i=this.raycast(Dr,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=Tr(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?rr:jn)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?ir:In;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?sr:zn;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?hr:qn;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=ln.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Fn:An});return ln.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=ln.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);L(o,t*3,s,c)}:e=>{L(o,e*3,s,c)},u=ln.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);L(u,n*3,d,f)}:e=>{L(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 Er.set(e.min,e.max,t),Er.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Er.intersectsBox(e),intersectsTriangle:e=>Er.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?wr:nr)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return fn(this,e,t,n,r)}};function Nr(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function Pr(e){switch(e){case 1:return te;case 2:return u;case 3:return d;case 4:return d}}function Fr(e){switch(e){case 1:return _;case 2:return ee;case 3:return Oe;case 4:return Oe}}var Ir=class extends Re{constructor(){super(),this.minFilter=S,this.magFilter=S,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){let t=this.overrideItemSize,n=e.itemSize,r=e.count;if(t!==null){if(n*r%t!==0)throw Error(`VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.`);e.itemSize=t,e.count=r*n/t}let i=e.itemSize,a=e.count,o=e.normalized,s=e.array.constructor,c=s.BYTES_PER_ELEMENT,l=this._forcedType,u=i;if(l===null)switch(s){case Float32Array:l=b;break;case Uint8Array:case Uint16Array:case Uint32Array:l=Me;break;case Int8Array:case Int16Array:case Int32Array:l=_e}let d,f,p,m,h=Nr(i);switch(l){case b:p=1,f=Pr(i),o&&c===1?(m=s,h+=`8`,s===Uint8Array?d=Te:(d=fe,h+=`_SNORM`)):(m=Float32Array,h+=`32F`,d=b);break;case _e:h+=c*8+`I`,p=o?2**(s.BYTES_PER_ELEMENT*8-1):1,f=Fr(i),c===1?(m=Int8Array,d=fe):c===2?(m=Int16Array,d=Ce):(m=Int32Array,d=_e);break;case Me:h+=c*8+`UI`,p=o?2**(s.BYTES_PER_ELEMENT*8-1):1,f=Fr(i),c===1?(m=Uint8Array,d=Te):c===2?(m=Uint16Array,d=oe):(m=Uint32Array,d=Me)}u===3&&(f===1023||f===1033)&&(u=4);let g=Math.ceil(Math.sqrt(a))||1,_=u*g*g,v=new m(_),y=e.normalized;e.normalized=!1;for(let t=0;t<a;t++){let n=u*t;v[n]=e.getX(t)/p,i>=2&&(v[n+1]=e.getY(t)/p),i>=3&&(v[n+2]=e.getZ(t)/p,u===4&&(v[n+3]=1)),i>=4&&(v[n+3]=e.getW(t)/p)}e.normalized=y,this.internalFormat=h,this.format=f,this.type=d,this.image.width=g,this.image.height=g,this.image.data=v,this.needsUpdate=!0,this.dispose(),e.itemSize=n,e.count=r}},Lr=class extends Ir{constructor(){super(),this._forcedType=Me}},Rr=class extends Ir{constructor(){super(),this._forcedType=b}},zr=class{constructor(){this.index=new Lr,this.position=new Rr,this.bvhBounds=new Re,this.bvhContents=new Re,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){let{geometry:t}=e;if(Vr(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){let n=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==n.length){if(t.index)this._cachedIndexAttr=t.index.clone();else{let e=Kt(Wt(t));this._cachedIndexAttr=new be(e,1,!1)}}Br(t,n,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){let{index:e,position:t,bvhBounds:n,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),n&&n.dispose(),r&&r.dispose()}};function Br(e,t,n){let r=n.array,i=e.index?e.index.array:null;for(let e=0,n=t.length;e<n;e++){let n=3*e,a=3*t[e];for(let e=0;e<3;e++)r[n+e]=i?i[a+e]:a+e}}function Vr(e,t,n){let r=e._roots;if(r.length!==1)throw Error(`MeshBVHUniformStruct: Multi-root BVHs not supported.`);let i=r[0],a=new Uint16Array(i),o=new Uint32Array(i),s=new Float32Array(i),c=i.byteLength/32,l=2*Math.ceil(Math.sqrt(c/2)),u=new Float32Array(4*l*l),f=Math.ceil(Math.sqrt(c)),p=new Uint32Array(2*f*f);for(let e=0;e<c;e++){let t=e*32/4,n=t*2,r=P(t);for(let t=0;t<3;t++)u[8*e+0+t]=s[r+0+t],u[8*e+4+t]=s[r+3+t];if(k(n,a)){let r=j(n,a),i=A(t,o),s=qe|r;p[e*2+0]=s,p[e*2+1]=i}else{let n=o[t+6],r=nt(t,o);p[e*2+0]=r,p[e*2+1]=n}}t.image.data=u,t.image.width=l,t.image.height=l,t.format=d,t.type=b,t.internalFormat=`RGBA32F`,t.minFilter=S,t.magFilter=S,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose(),n.image.data=p,n.image.width=f,n.image.height=f,n.format=ee,n.type=Me,n.internalFormat=`RG32UI`,n.minFilter=S,n.magFilter=S,n.generateMipmaps=!1,n.needsUpdate=!0,n.dispose()}var Hr=`
|
|
1
|
+
import{$ as e,A as t,B as n,C as r,Ct as i,D as a,E as o,Et as s,F as c,G as l,H as u,I as d,J as f,K as p,L as m,M as h,N as g,O as _,P as v,Q as y,R as b,S as x,St as S,T as C,Tt as ee,U as w,V as te,W as ne,X as re,Y as ie,Z as T,_ as ae,_t as oe,a as se,at as ce,b as le,bt as E,c as ue,ct as de,d as fe,dt as pe,et as me,f as he,ft as ge,g as _e,gt as ve,h as ye,ht as be,i as xe,it as Se,j as Ce,k as we,l as Te,lt as Ee,m as De,mt as Oe,n as ke,nt as D,o as Ae,ot as je,p as Me,pt as Ne,q as O,r as Pe,rt as Fe,s as Ie,st as Le,t as Re,tt as ze,u as Be,ut as Ve,v as He,vt as Ue,w as We,wt as Ge,x as Ke,xt as k,y as qe,yt as Je,z as Ye}from"./shared-CDFEFgsW.js";import{i as Xe,n as Ze,r as Qe,t as $e}from"./prompt-ui-zw7U8lsl.js";var et=1.25,tt=65535,nt=-65536,rt=2**-24,it=Symbol(`SKIP_GENERATION`),at={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[it]:!1};function A(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 ot(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 st(e,t){t.set(e)}function ct(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 lt(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 ut(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 j(e,t){return t[e+15]===tt}function M(e,t){return t[e+6]}function N(e,t){return t[e+14]}function P(e){return e+8}function F(e,t){return e+t[e+6]*8}function dt(e,t){return t[e+7]}function I(e){return e}function ft(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],ee=S-C,w=S+C;ee<s&&(s=ee),w>u&&(u=w),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 pt=32,mt=(e,t)=>e.candidate-t.candidate,ht=Array(pt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),gt=new Float32Array(6);function _t(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=ot(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=ot(e),o!==-1&&(s=vt(n,r,i,o));else if(a===2){let a=ut(e),c=et*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)/pt;if(i<pt/4){let t=[...ht];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;lt(i,n,o)}t.sort(mt);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?lt(r,n,a.rightCacheBounds):(lt(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=ut(d)/a);let m=0;u!==0&&(m=ut(f)/a);let h=1+et*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<pt;e++){let t=ht[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>=pt&&(i=31);let a=ht[i];a.count++,lt(t,n,a.bounds)}let t=ht[31];st(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=ht[e],n=ht[e+1];ct(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=ht[t],r=n.count,l=n.bounds,u=ht[t+1].rightCacheBounds;r!==0&&(f===0?st(l,gt):ct(l,gt,gt)),f+=r;let d=0,p=0;f!==0&&(d=ut(gt)/a);let m=i-f;m!==0&&(p=ut(u)/a);let h=1+et*(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 vt(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 yt=class{constructor(){this.boundingData=new Float32Array(6)}};function bt(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 xt,St,Ct,wt,Tt=2**32;function Et(e){return`count`in e?1:1+Et(e.left)+Et(e.right)}function Dt(e,t,n){return xt=new Float32Array(n),St=new Uint32Array(n),Ct=new Uint16Array(n),wt=new Uint8Array(n),Ot(e,t)}function Ot(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)xt[n+e]=a[e];if(i)return t.buffer?(wt.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(St[n+6]=t.offset,Ct[r+14]=t.count,Ct[r+15]=tt,e+32);{let{left:r,right:i,splitAxis:a}=t,o=Ot(e+32,r),s=e/32,c=o/32-s;if(c>Tt)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return St[n+6]=c,St[n+7]=a,Ot(o,i)}}function kt(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 yt;return ft(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=_t(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:bt(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,ot(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new yt,x=n,S=y-n;e.left=b,ft(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new yt,ee=y,w=r-S;return e.right=C,ft(t,ee,w,C.boundingData,m),v(C,ee,w,m,a+1),e}}function At(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=kt(e,s,r.offset,r.count,t,o),a=Et(i),c=new n(32*a);return Dt(0,i,c),c})}var jt=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())}}},Mt,Nt,Pt=[],Ft=new jt(()=>new We);function It(e,t,n,r,i,a){Mt=Ft.getPrimitive(),Nt=Ft.getPrimitive(),Pt.push(Mt,Nt),L.setBuffer(e._roots[t]);let o=Lt(0,e.geometry,n,r,i,a);L.clearBuffer(),Ft.releasePrimitive(Mt),Ft.releasePrimitive(Nt),Pt.pop(),Pt.pop();let s=Pt.length;return s>0&&(Nt=Pt[s-1],Mt=Pt[s-2]),o}function Lt(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(j(u,c)){let t=M(e,l),n=N(u,c);return A(I(e),s,Mt),r(t,n,!1,o,a+e/8,Mt)}{let u=P(e),d=F(e,l),f=u,p=d,m,h,g,_;if(i&&(g=Mt,_=Nt,A(I(f),s,g),A(I(p),s,_),m=i(g),h=i(_),h<m)){f=d,p=u;let e=m;m=h,h=e,g=_}g||(g=Mt,A(I(f),s,g));let v=j(f*2,c),y=n(g,v,m,o+1,a+f/8),b;if(y===2){let e=ee(f);b=r(e,w(f)-e,!0,o+1,a+f/8,g)}else b=y&&Lt(f,t,n,r,i,a,o+1);if(b)return!0;_=Nt,A(I(p),s,_);let x=j(p*2,c),S=n(_,x,h,o+1,a+p/8),C;if(S===2){let e=ee(p);C=r(e,w(p)-e,!0,o+1,a+p/8,_)}else C=S&&Lt(p,t,n,r,i,a,o+1);return!!C;function ee(e){let{uint16Array:t,uint32Array:n}=L,r=e*2;for(;!j(r,t);)e=P(e),r=e*2;return M(e,n)}function w(e){let{uint16Array:t,uint32Array:n}=L,r=e*2;for(;!j(r,t);)e=F(e,n),r=e*2;return M(e,n)+N(r,t)}}}var Rt=new L.constructor,zt=new L.constructor,Bt=new jt(()=>new We),Vt=new We,Ht=new We,Ut=new We,Wt=new We,Gt=!1;function Kt(e,t,n,r){if(Gt)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Gt=!0;let i=e._roots,a=t._roots,o,s=0,c=0,l=new O().copy(n).invert();for(let e=0,t=i.length;e<t;e++){Rt.setBuffer(i[e]),c=0;let t=Bt.getPrimitive();A(I(0),Rt.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(zt.setBuffer(a[e]),o=qt(0,0,n,l,r,s,c,0,0,t),zt.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(Bt.releasePrimitive(t),Rt.clearBuffer(),s+=i[e].byteLength/32,o)break}return Gt=!1,o}function qt(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=zt,f=Rt):(d=Rt,f=zt);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=j(y,h),S=j(b,v),C=!1;if(S&&x)C=u?i(M(t,_),N(t*2,v),M(e,m),N(e*2,h),c,o+t/8,s,a+e/8):i(M(e,m),N(e*2,h),M(t,_),N(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=Bt.getPrimitive();A(I(t),g,l),l.applyMatrix4(n);let d=P(e),f=F(e,m);A(I(d),p,Vt),A(I(f),p,Ht);let h=l.intersectsBox(Vt),_=l.intersectsBox(Ht);C=h&&qt(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&qt(t,f,r,n,i,o,a,c,s+1,l,!u),Bt.releasePrimitive(l)}else{let d=P(t),f=F(t,_);A(I(d),g,Ut),A(I(f),g,Wt);let h=l.intersectsBox(Ut),v=l.intersectsBox(Wt);if(h&&v)C=qt(e,d,n,r,i,a,o,s,c+1,l,u)||qt(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=qt(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=Bt.getPrimitive();t.copy(Ut).applyMatrix4(n);let l=P(e),f=F(e,m);A(I(l),p,Vt),A(I(f),p,Ht);let h=t.intersectsBox(Vt),g=t.intersectsBox(Ht);C=h&&qt(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&qt(d,f,r,n,i,o,a,c,s+1,t,!u),Bt.releasePrimitive(t)}}else if(v){if(x)C=qt(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=Bt.getPrimitive();t.copy(Wt).applyMatrix4(n);let l=P(e),d=F(e,m);A(I(l),p,Vt),A(I(d),p,Ht);let h=t.intersectsBox(Vt),g=t.intersectsBox(Ht);C=h&&qt(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&qt(f,d,r,n,i,o,a,c,s+1,t,!u),Bt.releasePrimitive(t)}}}return C}var Jt=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(;!j(r,n);)e=P(e),r=e*2;return M(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!j(r,n);)e=F(e,t),r=e*2;return M(e,t)+N(r,n)};let i=(e,r,a)=>{let o=j(r*2,n);if(!e(a,o,r)&&!o){let n=P(r),o=F(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)}{let n=dt(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Yt=new We,Xt=new Float32Array(6),Zt=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...at,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),At(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,Xt,0);let[e,t,r,u,d,f]=Xt;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,Xt,0);let[e,t,a,o,s,c]=Xt,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)*rt,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*rt,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*rt}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;j(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Jt.setBVH(this,t),Jt.traverse(e),Jt.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(j(n,i)){let e=M(t,r),o=N(n,i);this.writePrimitiveRangeBounds(e,o,Xt,0),a.set(Xt,t)}else{let e=P(t),n=F(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=>{A(0,new Float32Array(t),Yt),e.union(Yt)}),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=It(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Kt(this,e,t,r)}};function Qt(){return typeof SharedArrayBuffer<`u`}function $t(e){return e.index?e.index.count:e.attributes.position.count}function en(e){return $t(e)/3}function tn(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function nn(e,t){if(!e.index){let n=e.attributes.position.count,r=tn(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new C(r,1));for(let e=0;e<n;e++)r[e]=e}}function rn(e,t,n){let r=$t(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 an(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function on(e,t,n){let r=rn(e,t,n),i=an(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=$t(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 sn(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 cn=class extends Zt{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&&!Qt())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={...at,...t},t[it]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=sn(on(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else nn(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new We))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:on(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},ln=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}};ln.prototype.setFromBox=(function(){let e=new k;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 un=(function(){let e=new k,t=new k,n=new k;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}})(),dn=(function(){let e=new E,t=new k,n=new k;return function(r,i,a,o){un(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}if(s>=0&&s<=1){c<0?i.at(0,o):i.at(1,o),r.closestPointToPoint(o,!0,a);return}if(c>=0&&c<=1){s<0?r.at(0,a):r.at(1,a),i.closestPointToPoint(a,!0,o);return}{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}a.copy(e),o.copy(d);return}}})(),fn=(function(){let t=new k,n=new k,r=new e,i=new u;return function(e,a){let{radius:o,center:s}=e,{a:c,b:l,c:u}=a;if(i.start=c,i.end=l,i.closestPointToPoint(s,!0,t).distanceTo(s)<=o||(i.start=c,i.end=u,i.closestPointToPoint(s,!0,t).distanceTo(s)<=o)||(i.start=l,i.end=u,i.closestPointToPoint(s,!0,t).distanceTo(s)<=o))return!0;let d=a.getPlane(r);if(Math.abs(d.distanceToPoint(s))<=o){let e=d.projectPoint(s,n);if(a.containsPoint(e))return!0}return!1}})(),pn=[`x`,`y`,`z`],mn=1e-15,hn=mn*mn;function gn(e){return Math.abs(e)<mn}var _n=class extends be{constructor(...t){super(...t),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new k),this.satBounds=[,,,,].fill().map(()=>new ln),this.points=[this.a,this.b,this.c],this.plane=new e,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new u,this.needsUpdate=!0}intersectsSphere(e){return fn(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<mn?h<mn||g<mn?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<mn?g<mn?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<mn&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};_n.prototype.closestPointToSegment=(function(){let e=new k,t=new k,n=new u;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]),dn(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)}})(),_n.prototype.intersectsTriangle=(function(){let e=new _n,t=new ln,n=new ln,r=new k,i=new k,a=new k,o=new k,s=new u,c=new u,l=new k,d=new E,f=new E;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 gn(o)?gn(s)?p(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):gn(s)?(n&&(n.start.copy(a.end),n.end.copy(a.end)),e.containsPoint(a.end)):e.plane.intersectLine(a,r)!=null&&(n&&(n.start.copy(r),n.end.copy(r)),e.containsPoint(r))}function _(e,t,n){let r=t.a;return gn(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)<hn&&(n&&(n.start.copy(a),n.end.copy(a)),!0)}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(gn(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:gn(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}return t.isDegenerateIntoPoint?v(e,t,n):g(t,e,n,o)}if(e.isDegenerateIntoPoint)return t.isDegenerateIntoPoint?t.a.distanceToSquared(e.a)<hn&&(n&&(n.start.copy(e.a),n.end.copy(e.a)),!0):t.isDegenerateIntoSegment?v(t,e,n):_(t,e,n);if(t.isDegenerateIntoPoint)return _(e,t,n);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 u=this.plane,m=t.plane,g=m.distanceToPoint(this.a),_=m.distanceToPoint(this.b),v=m.distanceToPoint(this.c);gn(g)&&(g=0),gn(_)&&(_=0),gn(v)&&(v=0);let b=g*_,x=g*v;if(b>0&&x>0)return!1;let S=u.distanceToPoint(t.a),C=u.distanceToPoint(t.b),ee=u.distanceToPoint(t.c);gn(S)&&(S=0),gn(C)&&(C=0),gn(ee)&&(ee=0);let w=S*C,te=S*ee;if(w>0&&te>0)return!1;i.copy(u.normal),a.copy(m.normal);let ne=i.cross(a),re=0,ie=Math.abs(ne.x),T=Math.abs(ne.y);T>ie&&(ie=T,re=1),Math.abs(ne.z)>ie&&(re=2);let ae=pn[re],oe=this.a[ae],se=this.b[ae],ce=this.c[ae],le=t.a[ae],E=t.b[ae],ue=t.c[ae];if(h(this,oe,se,ce,b,x,g,_,v,d,s)||h(t,le,E,ue,w,te,S,C,ee,f,c))return p(this,t,n,r);if(d.y<d.x){let e=d.y;d.y=d.x,d.x=e,l.copy(s.start),s.start.copy(s.end),s.end.copy(l)}if(f.y<f.x){let e=f.y;f.y=f.x,f.x=e,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return d.y<f.x||f.y<d.x?!1:(n&&(f.x>d.x?n.start.copy(c.start):n.start.copy(s.start),f.y<d.y?n.end.copy(c.end):n.end.copy(s.end)),!0)}})(),_n.prototype.distanceToPoint=(function(){let e=new k;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),_n.prototype.distanceToTriangle=(function(){let e=new k,t=new k,n=[`a`,`b`,`c`],r=new u,i=new u;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]),dn(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 vn=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new k,this.max=new k,this.matrix=new O,this.invMatrix=new O,this.points=Array(8).fill().map(()=>new k),this.satAxes=[,,,].fill().map(()=>new k),this.satBounds=[,,,].fill().map(()=>new ln),this.alignedSatBounds=[,,,].fill().map(()=>new ln),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}};vn.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}})(),vn.prototype.intersectsBox=(function(){let e=new ln;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}})(),vn.prototype.intersectsTriangle=(function(){let e=new _n,t=[,,,],n=new ln,r=new ln,i=new k;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}})(),vn.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}})(),vn.prototype.distanceToPoint=(function(){let e=new k;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),vn.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new u),n=Array(12).fill().map(()=>new u),r=new k,i=new k;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];dn(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 yn=new class extends jt{constructor(){super(()=>new _n)}},bn=new k,xn=new k;function Sn(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=>(bn.copy(t).clamp(e.min,e.max),bn.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,bn);let r=t.distanceToSquared(bn);return r<s&&(xn.copy(bn),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(xn):n.point=xn.clone(),n.distance=l,n.faceIndex=c,n}var Cn=!0,wn=new k,Tn=new k,En=new k,Dn=new E,On=new E,kn=new E,An=new k,jn=new k,Mn=new k,Nn=new k;function Pn(e,t,n,r,i,a,o,s){let c;if(c=a===1?e.intersectTriangle(r,n,t,!0,i):e.intersectTriangle(t,n,r,a!==2,i),c===null)return null;let l=e.origin.distanceTo(i);return l<o||l>s?null:{distance:l,point:i.clone()}}function Fn(e,t,n,r,i,a,o,s,c,l,u){wn.fromBufferAttribute(t,a),Tn.fromBufferAttribute(t,o),En.fromBufferAttribute(t,s);let d=Pn(e,wn,Tn,En,Nn,c,l,u);if(d){if(r){Dn.fromBufferAttribute(r,a),On.fromBufferAttribute(r,o),kn.fromBufferAttribute(r,s),d.uv=new E;let e=be.getInterpolation(Nn,wn,Tn,En,Dn,On,kn,d.uv);Cn||(d.uv=e)}if(i){Dn.fromBufferAttribute(i,a),On.fromBufferAttribute(i,o),kn.fromBufferAttribute(i,s),d.uv1=new E;let e=be.getInterpolation(Nn,wn,Tn,En,Dn,On,kn,d.uv1);Cn||(d.uv1=e)}if(n){An.fromBufferAttribute(n,a),jn.fromBufferAttribute(n,o),Mn.fromBufferAttribute(n,s),d.normal=new k;let t=be.getInterpolation(Nn,wn,Tn,En,An,jn,Mn,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),Cn||(d.normal=t)}let t={a,b:o,c:s,normal:new k,materialIndex:0};if(be.getNormal(wn,Tn,En,t.normal),d.face=t,d.faceIndex=a,Cn){let e=new k;be.getBarycoord(Nn,wn,Tn,En,e),d.barycoord=e}}return d}function In(e){return e&&e.isMaterial?e.side:e}function Ln(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=In(t[v]),s=Fn(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=In(t),s=Fn(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 R(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 Rn(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)Ln(c,t,n,e,a,o,s)}function zn(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=Ln(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Bn(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,R(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Vn(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(j(l,s)){let t=M(e,o),n=N(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}{let r=P(e),i=F(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 Hn(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 Un(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)Ln(c,t,n,l?l[e]:e,a,o,s)}function Wn(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=Ln(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function Gn(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),R(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Kn(e,t,n,r,i,a,o){L.setBuffer(e._roots[t]),qn(0,e,n,r,i,a,o),L.clearBuffer()}function qn(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(j(u,c))Rn(t,n,r,M(e,l),N(u,c),i,a,o);else{let c=P(e);Hn(c,s,r,a,o)&&qn(c,t,n,r,i,a,o);let u=F(e,l);Hn(u,s,r,a,o)&&qn(u,t,n,r,i,a,o)}}var Jn=[`x`,`y`,`z`];function Yn(e,t,n,r,i,a){L.setBuffer(e._roots[t]);let o=Xn(0,e,n,r,i,a);return L.clearBuffer(),o}function Xn(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=L,l=e*2;if(j(l,s))return zn(t,n,r,M(e,c),N(l,s),i,a);{let s=dt(e,c),l=Jn[s],u=r.direction[l]>=0,d,f;u?(d=P(e),f=F(e,c)):(d=F(e,c),f=P(e));let p=Hn(d,o,r,i,a)?Xn(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=Hn(f,o,r,i,a)?Xn(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Zn=new We,Qn=new _n,$n=new _n,er=new O,tr=new vn,nr=new vn;function rr(e,t,n,r){L.setBuffer(e._roots[t]);let i=ir(0,e,n,r);return L.clearBuffer(),i}function ir(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=L,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),tr.set(n.boundingBox.min,n.boundingBox.max,r),i=tr),j(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=M(e,s),m=N(c,o);if(er.copy(r).invert(),n.boundsTree)return A(I(e),a,nr),nr.matrix.copy(er),nr.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>nr.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(R($n,t,l,u),$n.needsUpdate=!0,e.intersectsTriangle($n))return!0;return!1}});{let e=en(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){R(Qn,t,l,u),Qn.a.applyMatrix4(er),Qn.b.applyMatrix4(er),Qn.c.applyMatrix4(er),Qn.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(R($n,t,d,f),$n.needsUpdate=!0,Qn.intersectsTriangle($n))return!0}}}else{let o=P(e),c=F(e,s);return A(I(o),a,Zn),!!(i.intersectsBox(Zn)&&ir(o,t,n,r,i)||(A(I(c),a,Zn),i.intersectsBox(Zn)&&ir(c,t,n,r,i)))}}var ar=new O,or=new vn,sr=new vn,cr=new k,lr=new k,ur=new k,dr=new k;function fr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),or.set(t.boundingBox.min,t.boundingBox.max,n),or.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=yn.getPrimitive(),p=yn.getPrimitive(),m=cr,h=lr,g=null,_=null;i&&(g=ur,_=dr);let v=1/0,y=null,b=null;return ar.copy(n).invert(),sr.matrix.copy(ar),e.shapecast({boundsTraverseOrder:e=>or.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(sr.min.copy(e.min),sr.max.copy(e.max),sr.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>sr.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){R(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++){R(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=en(t);for(let t=0,o=i;t<o;t++){R(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++){R(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}}}}}),yn.releasePrimitive(f),yn.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(ar),h.applyMatrix4(ar),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function pr(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(j(u,s)){let t=M(n,o),a=N(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}{let e=P(n),r=F(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 mr(e,t,n,r,i,a,o){L.setBuffer(e._roots[t]),hr(0,e,n,r,i,a,o),L.clearBuffer()}function hr(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=L,u=e*2;if(j(u,c))Un(t,n,r,M(e,l),N(u,c),i,a,o);else{let c=P(e);Hn(c,s,r,a,o)&&hr(c,t,n,r,i,a,o);let u=F(e,l);Hn(u,s,r,a,o)&&hr(u,t,n,r,i,a,o)}}var gr=[`x`,`y`,`z`];function _r(e,t,n,r,i,a){L.setBuffer(e._roots[t]);let o=vr(0,e,n,r,i,a);return L.clearBuffer(),o}function vr(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=L,l=e*2;if(j(l,s))return Wn(t,n,r,M(e,c),N(l,s),i,a);{let s=dt(e,c),l=gr[s],u=r.direction[l]>=0,d,f;u?(d=P(e),f=F(e,c)):(d=F(e,c),f=P(e));let p=Hn(d,o,r,i,a)?vr(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=Hn(f,o,r,i,a)?vr(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var yr=new We,br=new _n,xr=new _n,Sr=new O,Cr=new vn,wr=new vn;function Tr(e,t,n,r){L.setBuffer(e._roots[t]);let i=Er(0,e,n,r);return L.clearBuffer(),i}function Er(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=L,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Cr.set(n.boundingBox.min,n.boundingBox.max,r),i=Cr),j(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=M(e,s),m=N(c,o);if(Sr.copy(r).invert(),n.boundsTree)return A(I(e),a,wr),wr.matrix.copy(Sr),wr.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>wr.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(R(xr,3*t.resolveTriangleIndex(n),l,u),xr.needsUpdate=!0,e.intersectsTriangle(xr))return!0;return!1}});{let e=en(n);for(let n=p,r=m+p;n<r;n++){R(br,3*t.resolveTriangleIndex(n),l,u),br.a.applyMatrix4(Sr),br.b.applyMatrix4(Sr),br.c.applyMatrix4(Sr),br.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(R(xr,t,d,f),xr.needsUpdate=!0,br.intersectsTriangle(xr))return!0}}}else{let o=P(e),c=F(e,s);return A(I(o),a,yr),!!(i.intersectsBox(yr)&&Er(o,t,n,r,i)||(A(I(c),a,yr),i.intersectsBox(yr)&&Er(c,t,n,r,i)))}}var Dr=new O,Or=new vn,kr=new vn,Ar=new k,jr=new k,Mr=new k,Nr=new k;function Pr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Or.set(t.boundingBox.min,t.boundingBox.max,n),Or.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=yn.getPrimitive(),p=yn.getPrimitive(),m=Ar,h=jr,g=null,_=null;i&&(g=Mr,_=Nr);let v=1/0,y=null,b=null;return Dr.copy(n).invert(),kr.matrix.copy(Dr),e.shapecast({boundsTraverseOrder:e=>Or.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(kr.min.copy(e.min),kr.max.copy(e.max),kr.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>kr.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);R(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);R(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}}}})}{let o=en(t);for(let t=0,s=o;t<s;t++){R(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);R(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}}}}}),yn.releasePrimitive(f),yn.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(Dr),h.applyMatrix4(Dr),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Fr(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 Ir=new vn,Lr=new je,Rr=new k,zr=new O,Br=new k,Vr=[`getX`,`getY`,`getZ`],Hr=class e extends cn{static serialize(e,t={}){t={cloneBuffers:!0,...t};let n=e.geometry,r=e._roots,i=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=r.map(e=>e.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=i?i.slice():null):(o.roots=r,o.index=a?a.array:null,o.indirectBuffer=i),o}static deserialize(t,n,r={}){r={setIndex:!0,indirect:!!t.indirectBuffer,...r};let{index:i,roots:a,indirectBuffer:o}=t;t.version||(console.warn(`MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data.`),c(a));let s=new e(n,{...r,[it]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new C(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;j(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[Vr[e]](c),i=a[Vr[e]](l),o=a[Vr[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)*rt}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;zr.copy(e.matrixWorld).invert(),Lr.copy(t.ray).applyMatrix4(zr),Br.setFromMatrixScale(e.matrixWorld),Rr.copy(Lr.direction).multiply(Br);let i=Rr.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(Lr,r,a,o);i=Fr(i,e,t),i&&n.push(i)}else{let i=this.raycast(Lr,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=Fr(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?pr:Vn)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?mr:Kn;for(let s=0,c=i.length;s<c;s++)o(this,s,t,e,a,n,r);return a}raycastFirst(e,t=0,n=0,r=1/0){let i=this._roots,a=null,o=this.indirect?_r:Yn;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?Tr:rr;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=yn.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?Gn:Bn});return yn.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=yn.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);R(o,t*3,s,c)}:e=>{R(o,e*3,s,c)},u=yn.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);R(u,n*3,d,f)}:e=>{R(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 Ir.set(e.min,e.max,t),Ir.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Ir.intersectsBox(e),intersectsTriangle:e=>Ir.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?Pr:fr)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return Sn(this,e,t,n,r)}};function Ur(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function Wr(e){switch(e){case 1:return Le;case 2:return Se;case 3:return D;case 4:return D}}function Gr(e){switch(e){case 1:return de;case 2:return ce;case 3:return Fe;case 4:return Fe}}var Kr=class extends h{constructor(){super(),this.minFilter=T,this.magFilter=T,this.generateMipmaps=!1,this.overrideItemSize=null,this._forcedType=null}updateFrom(e){let t=this.overrideItemSize,n=e.itemSize,r=e.count;if(t!==null){if(n*r%t!==0)throw Error(`VertexAttributeTexture: overrideItemSize must divide evenly into buffer length.`);e.itemSize=t,e.count=r*n/t}let i=e.itemSize,o=e.count,s=e.normalized,c=e.array.constructor,l=c.BYTES_PER_ELEMENT,u=this._forcedType,f=i;if(u===null)switch(c){case Float32Array:u=d;break;case Uint8Array:case Uint16Array:case Uint32Array:u=Ue;break;case Int8Array:case Int16Array:case Int32Array:u=te}let p,m,h,g,_=Ur(i);switch(u){case d:h=1,m=Wr(i),s&&l===1?(g=c,_+=`8`,c===Uint8Array?p=oe:(p=a,_+=`_SNORM`)):(g=Float32Array,_+=`32F`,p=d);break;case te:_+=l*8+`I`,h=s?2**(c.BYTES_PER_ELEMENT*8-1):1,m=Gr(i),l===1?(g=Int8Array,p=a):l===2?(g=Int16Array,p=ge):(g=Int32Array,p=te);break;case Ue:_+=l*8+`UI`,h=s?2**(c.BYTES_PER_ELEMENT*8-1):1,m=Gr(i),l===1?(g=Uint8Array,p=oe):l===2?(g=Uint16Array,p=Je):(g=Uint32Array,p=Ue)}f===3&&(m===1023||m===1033)&&(f=4);let v=Math.ceil(Math.sqrt(o))||1,y=f*v*v,b=new g(y),x=e.normalized;e.normalized=!1;for(let t=0;t<o;t++){let n=f*t;b[n]=e.getX(t)/h,i>=2&&(b[n+1]=e.getY(t)/h),i>=3&&(b[n+2]=e.getZ(t)/h,f===4&&(b[n+3]=1)),i>=4&&(b[n+3]=e.getW(t)/h)}e.normalized=x,this.internalFormat=_,this.format=m,this.type=p,this.image.width=v,this.image.height=v,this.image.data=b,this.needsUpdate=!0,this.dispose(),e.itemSize=n,e.count=r}},qr=class extends Kr{constructor(){super(),this._forcedType=Ue}},Jr=class extends Kr{constructor(){super(),this._forcedType=d}},Yr=class{constructor(){this.index=new qr,this.position=new Jr,this.bvhBounds=new h,this.bvhContents=new h,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){let{geometry:t}=e;if(Zr(e,this.bvhBounds,this.bvhContents),this.position.updateFrom(t.attributes.position),e.indirect){let n=e._indirectBuffer;if(this._cachedIndexAttr===null||this._cachedIndexAttr.count!==n.length){if(t.index)this._cachedIndexAttr=t.index.clone();else{let e=tn($t(t));this._cachedIndexAttr=new C(e,1,!1)}}Xr(t,n,this._cachedIndexAttr),this.index.updateFrom(this._cachedIndexAttr)}else this.index.updateFrom(t.index)}dispose(){let{index:e,position:t,bvhBounds:n,bvhContents:r}=this;e&&e.dispose(),t&&t.dispose(),n&&n.dispose(),r&&r.dispose()}};function Xr(e,t,n){let r=n.array,i=e.index?e.index.array:null;for(let e=0,n=t.length;e<n;e++){let n=3*e,a=3*t[e];for(let e=0;e<3;e++)r[n+e]=i?i[a+e]:a+e}}function Zr(e,t,n){let r=e._roots;if(r.length!==1)throw Error(`MeshBVHUniformStruct: Multi-root BVHs not supported.`);let i=r[0],a=new Uint16Array(i),o=new Uint32Array(i),s=new Float32Array(i),c=i.byteLength/32,l=2*Math.ceil(Math.sqrt(c/2)),u=new Float32Array(4*l*l),f=Math.ceil(Math.sqrt(c)),p=new Uint32Array(2*f*f);for(let e=0;e<c;e++){let t=e*32/4,n=t*2,r=I(t);for(let t=0;t<3;t++)u[8*e+0+t]=s[r+0+t],u[8*e+4+t]=s[r+3+t];if(j(n,a)){let r=N(n,a),i=M(t,o),s=nt|r;p[e*2+0]=s,p[e*2+1]=i}else{let n=o[t+6],r=dt(t,o);p[e*2+0]=r,p[e*2+1]=n}}t.image.data=u,t.image.width=l,t.image.height=l,t.format=D,t.type=d,t.internalFormat=`RGBA32F`,t.minFilter=T,t.magFilter=T,t.generateMipmaps=!1,t.needsUpdate=!0,t.dispose(),n.image.data=p,n.image.width=f,n.image.height=f,n.format=ce,n.type=Ue,n.internalFormat=`RG32UI`,n.minFilter=T,n.magFilter=T,n.generateMipmaps=!1,n.needsUpdate=!0,n.dispose()}var Qr=`
|
|
2
2
|
|
|
3
3
|
// A stack of uint32 indices can can store the indices for
|
|
4
4
|
// a perfectly balanced tree with a depth up to 31. Lower stack
|
|
@@ -80,7 +80,7 @@ void ndcToCameraRay(
|
|
|
80
80
|
rayDirection = direction.xyz;
|
|
81
81
|
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
`,$r=`
|
|
84
84
|
|
|
85
85
|
#ifndef TRI_INTERSECT_EPSILON
|
|
86
86
|
#define TRI_INTERSECT_EPSILON 1e-5
|
|
@@ -284,7 +284,7 @@ bool _bvhIntersectFirstHit(
|
|
|
284
284
|
return found;
|
|
285
285
|
|
|
286
286
|
}
|
|
287
|
-
`,
|
|
287
|
+
`,ei=`
|
|
288
288
|
struct BVH {
|
|
289
289
|
|
|
290
290
|
usampler2D index;
|
|
@@ -294,7 +294,7 @@ struct BVH {
|
|
|
294
294
|
usampler2D bvhContents;
|
|
295
295
|
|
|
296
296
|
};
|
|
297
|
-
`;function Gr(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function Kr(e,t=null){let n=e.array.constructor,r=e.normalized,i=e.itemSize,a=t===null?e.count:t;return new be(new n(i*a),i,r)}function qr(e,t){if(!e&&!t)return!0;if(!!e!=!!t)return!1;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;return!(!n||!r||!i||!a)}function Jr(e){let t=e[0].index!==null,n=new Set(Object.keys(e[0].attributes));if(!e[0].getAttribute(`position`))throw Error(`StaticGeometryGenerator: position attribute is required.`);for(let r=0;r<e.length;++r){let i=e[r],a=0;if(t!==(i.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in i.attributes){if(!n.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);a++}if(a!==n.size)throw Error(`StaticGeometryGenerator: All geometries must have the same number of attributes.`)}}function Yr(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function Xr(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function Zr(e,t,n){e.index&&e.index.count!==t&&e.setIndex(null);let r=e.attributes;for(let t in r)r[t].count!==n&&e.deleteAttribute(t)}function Qr(e,t={},n=new pe){let{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:a=[],overwriteIndex:o=!0}=t;Jr(e);let s=e[0].index!==null,c=s?Yr(e):-1,l=Xr(e);if(Zr(n,c,l),r){let t=0;for(let r=0,i=e.length;r<i;r++){let i=e[r],a;a=s?i.getIndex().count:i.getAttribute(`position`).count,n.addGroup(t,a,r),t+=a}}if(s){let t=!1;if(n.index||(n.setIndex(new be(new Uint32Array(c),1,!1)),t=!0),t||o){let r=0,o=0,s=n.getIndex();for(let n=0,c=e.length;n<c;n++){let c=e[n],l=c.getIndex();if(i||t||!a[n])for(let e=0;e<l.count;++e)s.setX(r+e,l.getX(e)+o);r+=l.count,o+=c.getAttribute(`position`).count}}}let u=Object.keys(e[0].attributes);for(let t=0,r=u.length;t<r;t++){let r=!1,o=u[t];if(!n.getAttribute(o)){let t=e[0].getAttribute(o);n.setAttribute(o,Kr(t,l)),r=!0}let s=0,c=n.getAttribute(o);for(let t=0,n=e.length;t<n;t++){let n=e[t],l=!i&&!r&&a[t],u=n.getAttribute(o);if(!l){if(o===`color`&&c.itemSize!==u.itemSize)for(let e=s,t=u.count;e<t;e++)u.setXYZW(e,c.getX(e),c.getY(e),c.getZ(e),1);else Gr(u,c,s)}s+=u.count}}}function $r(e,t,n){let r=e.index,i=e.attributes.position.count,a=r?r.count:i,o=e.groups;o.length===0&&(o=[{count:a,start:0,materialIndex:0}]);let s=e.getAttribute(`materialIndex`);if(!s||s.count!==i){let t;t=n.length<=255?new Uint8Array(i):new Uint16Array(i),s=new be(t,1,!1),e.deleteAttribute(`materialIndex`),e.setAttribute(`materialIndex`,s)}let c=s.array;for(let e=0;e<o.length;e++){let i=o[e],s=i.start,l=i.count,u=Math.min(l,a-s),d=Array.isArray(t)?t[i.materialIndex]:t,f=n.indexOf(d);for(let e=0;e<u;e++){let t=s+e;r&&(t=r.getX(t)),c[t]=f}}}function ei(e,t){if(!e.index){let t=e.attributes.position.count,n=Array(t);for(let e=0;e<t;e++)n[e]=e;e.setIndex(n)}if(!e.attributes.normal&&t&&t.includes(`normal`)&&e.computeVertexNormals(),!e.attributes.uv&&t&&t.includes(`uv`)){let t=e.attributes.position.count;e.setAttribute(`uv`,new be(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new be(new Float32Array(t*2),2,!1))}if(!e.attributes.tangent&&t&&t.includes(`tangent`)){if(e.attributes.uv&&e.attributes.normal)e.computeTangents();else{let t=e.attributes.position.count;e.setAttribute(`tangent`,new be(new Float32Array(t*4),4,!1))}}if(!e.attributes.color&&t&&t.includes(`color`)){let t=e.attributes.position.count,n=new Float32Array(t*4);n.fill(1),e.setAttribute(`color`,new be(n,4))}}function ti(e){let t=0;if(e.byteLength!==0){let n=new Uint8Array(e);for(let r=0;r<e.byteLength;r++){let e=n[r];t=(t<<5)-t+e,t|=0}}return t}function ni(e){let t=e.uuid,n=Object.values(e.attributes);e.index&&(n.push(e.index),t+=`index|${e.index.version}`);let r=Object.keys(n).sort();for(let e of r){let r=n[e];t+=`${e}_${r.version}|`}return t}function ri(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${ti(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var ii=class{constructor(e=null){this.matrixWorld=new f,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=ni(t),this.primitiveCount=n,this.skeletonHash=ri(e)}didChange(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===ni(t)&&this.skeletonHash===ri(e)&&this.primitiveCount===n)}},ai=new D,oi=new D,si=new D,ci=new ce,li=new D,ui=new D,di=new ce,fi=new ce,pi=new f,mi=new f;function hi(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;di.fromBufferAttribute(i.attributes.skinIndex,t),fi.fromBufferAttribute(i.attributes.skinWeight,t),pi.elements.fill(0);for(let e=0;e<4;e++){let t=fi.getComponent(e);if(t!==0){let n=di.getComponent(e);mi.multiplyMatrices(a[n].matrixWorld,o[n]),_i(pi,mi,t)}}return pi.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(pi),n}function gi(e,t,n,r,i){li.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(ui.fromBufferAttribute(s,r),n?li.addScaledVector(ui,o):li.addScaledVector(ui.sub(i),o))}i.add(li)}function _i(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function vi(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}function yi(e,t={},n=new pe){t={applyWorldTransforms:!0,attributes:[],...t};let r=e.geometry,i=t.applyWorldTransforms,a=t.attributes.includes(`normal`),o=t.attributes.includes(`tangent`),s=r.attributes,c=n.attributes;for(let e in n.attributes)(!t.attributes.includes(e)||!(e in r.attributes))&&n.deleteAttribute(e);!n.index&&r.index&&(n.index=r.index.clone()),c.position||n.setAttribute(`position`,Kr(s.position)),a&&!c.normal&&s.normal&&n.setAttribute(`normal`,Kr(s.normal)),o&&!c.tangent&&s.tangent&&n.setAttribute(`tangent`,Kr(s.tangent)),qr(r.index,n.index),qr(s.position,c.position),a&&qr(s.normal,c.normal),o&&qr(s.tangent,c.tangent);let u=s.position,d=a?s.normal:null,f=o?s.tangent:null,p=r.morphAttributes.position,m=r.morphAttributes.normal,h=r.morphAttributes.tangent,g=r.morphTargetsRelative,_=e.morphTargetInfluences,v=new l;v.getNormalMatrix(e.matrixWorld),r.index&&n.index.array.set(r.index.array);for(let t=0,n=s.position.count;t<n;t++)ai.fromBufferAttribute(u,t),d&&oi.fromBufferAttribute(d,t),f&&(ci.fromBufferAttribute(f,t),si.fromBufferAttribute(f,t)),_&&(p&&gi(p,_,g,t,ai),m&&gi(m,_,g,t,oi),h&&gi(h,_,g,t,si)),e.isSkinnedMesh&&(e.applyBoneTransform(t,ai),d&&hi(e,t,oi),f&&hi(e,t,si)),i&&ai.applyMatrix4(e.matrixWorld),c.position.setXYZ(t,ai.x,ai.y,ai.z),d&&(i&&oi.applyNormalMatrix(v),c.normal.setXYZ(t,oi.x,oi.y,oi.z)),f&&(i&&si.transformDirection(e.matrixWorld),c.tangent.setXYZW(t,si.x,si.y,si.z,ci.w));for(let e in t.attributes){let r=t.attributes[e];r!==`position`&&r!==`tangent`&&r!==`normal`&&r in s&&(c[r]||n.setAttribute(r,Kr(s[r])),qr(s[r],c[r]),Gr(s[r],c[r]))}return e.matrixWorld.determinant()<0&&vi(n),n}var bi=class extends pe{constructor(){super(),this.version=0,this.hash=null,this._diff=new ii}isCompatible(e,t){let n=e.geometry;for(let e=0;e<t.length;e++){let r=t[e],i=n.attributes[r],a=this.attributes[r];if(i&&!qr(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(yi(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function xi(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function Si(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];Array.isArray(r.material)?t.push(...r.material):t.push(r.material)}return t}function Ci(e,t,n){if(e.length===0){t.setIndex(null);let e=t.attributes;for(let n in e)t.deleteAttribute(n);for(let e in n.attributes)t.setAttribute(n.attributes[e],new be(new Float32Array,4,!1))}else Qr(e,n,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var wi=class{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=[`position`,`normal`,`color`,`tangent`,`uv`,`uv2`],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){let e=new Be,t=new pe;t.setAttribute(`position`,new be(new Float32Array(9),3)),this._dummyMesh=new v(t,e)}return this._dummyMesh}_getMeshes(){let e=[];return xi(this.objects,t=>{e.push(t)}),e.sort((e,t)=>e.uuid>t.uuid?1:e.uuid<t.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){let{_intermediateGeometry:e}=this,t=this._getMeshes(),n=new Set(e.keys()),r={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let i=0,a=t.length;i<a;i++){let a=t[i],o=a.uuid;n.delete(o);let s=e.get(o);(!s||!s.isCompatible(a,this.attributes))&&(s&&s.dispose(),s=new bi,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&ei(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){this.objects=Array.isArray(e)?[...e]:[e]}generate(e=new pe){let{useGroups:t,overwriteIndex:n,_intermediateGeometry:r,_geometryMergeSets:i}=this,a=this._getMeshes(),o=[],s=[],c=i.get(e)||[];this._updateIntermediateGeometries();let l=!1;a.length!==c.length&&(l=!0);for(let e=0,t=a.length;e<t;e++){let t=a[e],n=r.get(t.uuid);s.push(n);let i=c[e];!i||i.uuid!==n.uuid?(o.push(!1),l=!0):i.version===n.version?o.push(!0):o.push(!1)}Ci(s,e,{useGroups:t,forceUpdate:l,skipAssigningAttributes:o,overwriteIndex:n}),l&&e.dispose(),i.set(e,s.map(e=>({version:e.version,uuid:e.uuid})));let u=0;return l?u=2:o.includes(!1)&&(u=1),{changeType:u,materials:Si(a),geometry:e}}};function Ti(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Array.from(t)}function Ei(e){let t=[],n=new Set;for(let r=0,i=e.length;r<i;r++)e[r].traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&(t.push(e),e.iesMap&&n.add(e.iesMap))});return{lights:t,iesTextures:Array.from(n).sort((e,t)=>e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0)}}var Di=class{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=[`position`,`normal`,`tangent`,`color`,`uv`,`uv2`],this.generateBVH=!0,this.bvh=null,this.geometry=new pe,this.staticGeometryGenerator=new wi(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1,this._materialUuids=null}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw Error(`PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.`);if(this.bvh instanceof Promise)return this._pendingGenerate||=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e))),this._pendingGenerate;{this._buildAsync=!0;let t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){let{staticGeometryGenerator:t,geometry:n,attributes:r}=this,i=t.objects;t.attributes=r,i.forEach(e=>{e.traverse(e=>{e.isSkinnedMesh&&e.skeleton&&e.skeleton.update()})});let a=t.generate(n),o=a.materials,s=a.changeType!==0||this._materialUuids===null||this._materialUuids.length!==length;if(!s){for(let e=0,t=o.length;e<t;e++)if(o[e].uuid!==this._materialUuids[e]){s=!0;break}}let c=Ti(o),{lights:l,iesTextures:u}=Ei(i);if(s&&($r(n,o,o),this._materialUuids=o.map(e=>e.uuid)),this.generateBVH){if(this.bvh instanceof Promise)throw Error(`PathTracingSceneGenerator: BVH is already building asynchronously.`);if(a.changeType===2){let t={strategy:2,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this.bvh=this._buildAsync?this._bvhWorker.generate(n,t):new Mr(n,t)}else a.changeType===1&&this.bvh.refit()}return{bvhChanged:a.changeType!==0,bvh:this.bvh,needsMaterialIndexUpdate:s,lights:l,iesTextures:u,geometry:n,materials:o,textures:c,objects:i}}},Oi=class extends Pe{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:`recompilation`})}constructor(e){super(e);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(t){this.uniforms[e].value=t}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}},ki=class extends Oi{constructor(e){super({blending:0,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
297
|
+
`;function ti(e,t,n=0){if(e.isInterleavedBufferAttribute){let r=e.itemSize;for(let i=0,a=e.count;i<a;i++){let a=i+n;t.setX(a,e.getX(i)),r>=2&&t.setY(a,e.getY(i)),r>=3&&t.setZ(a,e.getZ(i)),r>=4&&t.setW(a,e.getW(i))}}else{let r=t.array,i=r.constructor,a=r.BYTES_PER_ELEMENT*e.itemSize*n;new i(r.buffer,a,e.array.length).set(e.array)}}function ni(e,t=null){let n=e.array.constructor,r=e.normalized,i=e.itemSize,a=t===null?e.count:t;return new C(new n(i*a),i,r)}function ri(e,t){if(!e&&!t)return!0;if(!!e!=!!t)return!1;let n=e.count===t.count,r=e.normalized===t.normalized,i=e.array.constructor===t.array.constructor,a=e.itemSize===t.itemSize;return!(!n||!r||!i||!a)}function ii(e){let t=e[0].index!==null,n=new Set(Object.keys(e[0].attributes));if(!e[0].getAttribute(`position`))throw Error(`StaticGeometryGenerator: position attribute is required.`);for(let r=0;r<e.length;++r){let i=e[r],a=0;if(t!==(i.index!==null))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.`);for(let e in i.attributes){if(!n.has(e))throw Error(`StaticGeometryGenerator: All geometries must have compatible attributes; make sure "`+e+`" attribute exists among all geometries, or in none of them.`);a++}if(a!==n.size)throw Error(`StaticGeometryGenerator: All geometries must have the same number of attributes.`)}}function ai(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function oi(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function si(e,t,n){e.index&&e.index.count!==t&&e.setIndex(null);let r=e.attributes;for(let t in r)r[t].count!==n&&e.deleteAttribute(t)}function ci(e,t={},n=new o){let{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:a=[],overwriteIndex:s=!0}=t;ii(e);let c=e[0].index!==null,l=c?ai(e):-1,u=oi(e);if(si(n,l,u),r){let t=0;for(let r=0,i=e.length;r<i;r++){let i=e[r],a;a=c?i.getIndex().count:i.getAttribute(`position`).count,n.addGroup(t,a,r),t+=a}}if(c){let t=!1;if(n.index||(n.setIndex(new C(new Uint32Array(l),1,!1)),t=!0),t||s){let r=0,o=0,s=n.getIndex();for(let n=0,c=e.length;n<c;n++){let c=e[n],l=c.getIndex();if(i||t||!a[n])for(let e=0;e<l.count;++e)s.setX(r+e,l.getX(e)+o);r+=l.count,o+=c.getAttribute(`position`).count}}}let d=Object.keys(e[0].attributes);for(let t=0,r=d.length;t<r;t++){let r=!1,o=d[t];if(!n.getAttribute(o)){let t=e[0].getAttribute(o);n.setAttribute(o,ni(t,u)),r=!0}let s=0,c=n.getAttribute(o);for(let t=0,n=e.length;t<n;t++){let n=e[t],l=!i&&!r&&a[t],u=n.getAttribute(o);if(!l){if(o===`color`&&c.itemSize!==u.itemSize)for(let e=s,t=u.count;e<t;e++)u.setXYZW(e,c.getX(e),c.getY(e),c.getZ(e),1);else ti(u,c,s)}s+=u.count}}}function li(e,t,n){let r=e.index,i=e.attributes.position.count,a=r?r.count:i,o=e.groups;o.length===0&&(o=[{count:a,start:0,materialIndex:0}]);let s=e.getAttribute(`materialIndex`);if(!s||s.count!==i){let t;t=n.length<=255?new Uint8Array(i):new Uint16Array(i),s=new C(t,1,!1),e.deleteAttribute(`materialIndex`),e.setAttribute(`materialIndex`,s)}let c=s.array;for(let e=0;e<o.length;e++){let i=o[e],s=i.start,l=i.count,u=Math.min(l,a-s),d=Array.isArray(t)?t[i.materialIndex]:t,f=n.indexOf(d);for(let e=0;e<u;e++){let t=s+e;r&&(t=r.getX(t)),c[t]=f}}}function ui(e,t){if(!e.index){let t=e.attributes.position.count,n=Array(t);for(let e=0;e<t;e++)n[e]=e;e.setIndex(n)}if(!e.attributes.normal&&t&&t.includes(`normal`)&&e.computeVertexNormals(),!e.attributes.uv&&t&&t.includes(`uv`)){let t=e.attributes.position.count;e.setAttribute(`uv`,new C(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new C(new Float32Array(t*2),2,!1))}if(!e.attributes.tangent&&t&&t.includes(`tangent`)){if(e.attributes.uv&&e.attributes.normal)e.computeTangents();else{let t=e.attributes.position.count;e.setAttribute(`tangent`,new C(new Float32Array(t*4),4,!1))}}if(!e.attributes.color&&t&&t.includes(`color`)){let t=e.attributes.position.count,n=new Float32Array(t*4);n.fill(1),e.setAttribute(`color`,new C(n,4))}}function di(e){let t=0;if(e.byteLength!==0){let n=new Uint8Array(e);for(let r=0;r<e.byteLength;r++){let e=n[r];t=(t<<5)-t+e,t|=0}}return t}function fi(e){let t=e.uuid,n=Object.values(e.attributes);e.index&&(n.push(e.index),t+=`index|${e.index.version}`);let r=Object.keys(n).sort();for(let e of r){let r=n[e];t+=`${e}_${r.version}|`}return t}function pi(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${di(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var mi=class{constructor(e=null){this.matrixWorld=new O,this.geometryHash=null,this.skeletonHash=null,this.primitiveCount=-1,e!==null&&this.updateFrom(e)}updateFrom(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;this.matrixWorld.copy(e.matrixWorld),this.geometryHash=fi(t),this.primitiveCount=n,this.skeletonHash=pi(e)}didChange(e){let t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===fi(t)&&this.skeletonHash===pi(e)&&this.primitiveCount===n)}},hi=new k,gi=new k,_i=new k,vi=new S,yi=new k,bi=new k,xi=new S,Si=new S,Ci=new O,wi=new O;function Ti(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;xi.fromBufferAttribute(i.attributes.skinIndex,t),Si.fromBufferAttribute(i.attributes.skinWeight,t),Ci.elements.fill(0);for(let e=0;e<4;e++){let t=Si.getComponent(e);if(t!==0){let n=xi.getComponent(e);wi.multiplyMatrices(a[n].matrixWorld,o[n]),Di(Ci,wi,t)}}return Ci.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(Ci),n}function Ei(e,t,n,r,i){yi.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(bi.fromBufferAttribute(s,r),n?yi.addScaledVector(bi,o):yi.addScaledVector(bi.sub(i),o))}i.add(yi)}function Di(e,t,n){let r=e.elements,i=t.elements;for(let e=0,t=i.length;e<t;e++)r[e]+=i[e]*n}function Oi(e){let{index:t,attributes:n}=e;if(t)for(let e=0,n=t.count;e<n;e+=3){let n=t.getX(e),r=t.getX(e+2);t.setX(e,r),t.setX(e+2,n)}else for(let e in n){let t=n[e],r=t.itemSize;for(let e=0,n=t.count;e<n;e+=3)for(let n=0;n<r;n++){let r=t.getComponent(e,n),i=t.getComponent(e+2,n);t.setComponent(e,n,i),t.setComponent(e+2,n,r)}}return e}function ki(e,t={},n=new o){t={applyWorldTransforms:!0,attributes:[],...t};let r=e.geometry,i=t.applyWorldTransforms,a=t.attributes.includes(`normal`),s=t.attributes.includes(`tangent`),c=r.attributes,l=n.attributes;for(let e in n.attributes)(!t.attributes.includes(e)||!(e in r.attributes))&&n.deleteAttribute(e);!n.index&&r.index&&(n.index=r.index.clone()),l.position||n.setAttribute(`position`,ni(c.position)),a&&!l.normal&&c.normal&&n.setAttribute(`normal`,ni(c.normal)),s&&!l.tangent&&c.tangent&&n.setAttribute(`tangent`,ni(c.tangent)),ri(r.index,n.index),ri(c.position,l.position),a&&ri(c.normal,l.normal),s&&ri(c.tangent,l.tangent);let u=c.position,d=a?c.normal:null,f=s?c.tangent:null,m=r.morphAttributes.position,h=r.morphAttributes.normal,g=r.morphAttributes.tangent,_=r.morphTargetsRelative,v=e.morphTargetInfluences,y=new p;y.getNormalMatrix(e.matrixWorld),r.index&&n.index.array.set(r.index.array);for(let t=0,n=c.position.count;t<n;t++)hi.fromBufferAttribute(u,t),d&&gi.fromBufferAttribute(d,t),f&&(vi.fromBufferAttribute(f,t),_i.fromBufferAttribute(f,t)),v&&(m&&Ei(m,v,_,t,hi),h&&Ei(h,v,_,t,gi),g&&Ei(g,v,_,t,_i)),e.isSkinnedMesh&&(e.applyBoneTransform(t,hi),d&&Ti(e,t,gi),f&&Ti(e,t,_i)),i&&hi.applyMatrix4(e.matrixWorld),l.position.setXYZ(t,hi.x,hi.y,hi.z),d&&(i&&gi.applyNormalMatrix(y),l.normal.setXYZ(t,gi.x,gi.y,gi.z)),f&&(i&&_i.transformDirection(e.matrixWorld),l.tangent.setXYZW(t,_i.x,_i.y,_i.z,vi.w));for(let e in t.attributes){let r=t.attributes[e];r!==`position`&&r!==`tangent`&&r!==`normal`&&r in c&&(l[r]||n.setAttribute(r,ni(c[r])),ri(c[r],l[r]),ti(c[r],l[r]))}return e.matrixWorld.determinant()<0&&Oi(n),n}var Ai=class extends o{constructor(){super(),this.version=0,this.hash=null,this._diff=new mi}isCompatible(e,t){let n=e.geometry;for(let e=0;e<t.length;e++){let r=t[e],i=n.attributes[r],a=this.attributes[r];if(i&&!ri(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(ki(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function ji(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function Mi(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];Array.isArray(r.material)?t.push(...r.material):t.push(r.material)}return t}function Ni(e,t,n){if(e.length===0){t.setIndex(null);let e=t.attributes;for(let n in e)t.deleteAttribute(n);for(let e in n.attributes)t.setAttribute(n.attributes[e],new C(new Float32Array,4,!1))}else ci(e,n,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var Pi=class{constructor(e){this.objects=null,this.useGroups=!0,this.applyWorldTransforms=!0,this.generateMissingAttributes=!0,this.overwriteIndex=!0,this.attributes=[`position`,`normal`,`color`,`tangent`,`uv`,`uv2`],this._intermediateGeometry=new Map,this._geometryMergeSets=new WeakMap,this._mergeOrder=[],this._dummyMesh=null,this.setObjects(e||[])}_getDummyMesh(){if(!this._dummyMesh){let e=new ie,t=new o;t.setAttribute(`position`,new C(new Float32Array(9),3)),this._dummyMesh=new f(t,e)}return this._dummyMesh}_getMeshes(){let e=[];return ji(this.objects,t=>{e.push(t)}),e.sort((e,t)=>e.uuid>t.uuid?1:e.uuid<t.uuid?-1:0),e.length===0&&e.push(this._getDummyMesh()),e}_updateIntermediateGeometries(){let{_intermediateGeometry:e}=this,t=this._getMeshes(),n=new Set(e.keys()),r={attributes:this.attributes,applyWorldTransforms:this.applyWorldTransforms};for(let i=0,a=t.length;i<a;i++){let a=t[i],o=a.uuid;n.delete(o);let s=e.get(o);(!s||!s.isCompatible(a,this.attributes))&&(s&&s.dispose(),s=new Ai,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&ui(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){this.objects=Array.isArray(e)?[...e]:[e]}generate(e=new o){let{useGroups:t,overwriteIndex:n,_intermediateGeometry:r,_geometryMergeSets:i}=this,a=this._getMeshes(),s=[],c=[],l=i.get(e)||[];this._updateIntermediateGeometries();let u=!1;a.length!==l.length&&(u=!0);for(let e=0,t=a.length;e<t;e++){let t=a[e],n=r.get(t.uuid);c.push(n);let i=l[e];!i||i.uuid!==n.uuid?(s.push(!1),u=!0):i.version===n.version?s.push(!0):s.push(!1)}Ni(c,e,{useGroups:t,forceUpdate:u,skipAssigningAttributes:s,overwriteIndex:n}),u&&e.dispose(),i.set(e,c.map(e=>({version:e.version,uuid:e.uuid})));let d=0;return u?d=2:s.includes(!1)&&(d=1),{changeType:d,materials:Mi(a),geometry:e}}};function Fi(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return Array.from(t)}function Ii(e){let t=[],n=new Set;for(let r=0,i=e.length;r<i;r++)e[r].traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&(t.push(e),e.iesMap&&n.add(e.iesMap))});return{lights:t,iesTextures:Array.from(n).sort((e,t)=>e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0)}}var Li=class{get initialized(){return!!this.bvh}constructor(e){this.bvhOptions={},this.attributes=[`position`,`normal`,`tangent`,`color`,`uv`,`uv2`],this.generateBVH=!0,this.bvh=null,this.geometry=new o,this.staticGeometryGenerator=new Pi(e),this._bvhWorker=null,this._pendingGenerate=null,this._buildAsync=!1,this._materialUuids=null}setObjects(e){this.staticGeometryGenerator.setObjects(e)}setBVHWorker(e){this._bvhWorker=e}async generateAsync(e=null){if(!this._bvhWorker)throw Error(`PathTracingSceneGenerator: "setBVHWorker" must be called before "generateAsync" can be called.`);if(this.bvh instanceof Promise)return this._pendingGenerate||=new Promise(async()=>(await this.bvh,this._pendingGenerate=null,this.generateAsync(e))),this._pendingGenerate;{this._buildAsync=!0;let t=this.generate(e);return this._buildAsync=!1,t.bvh=this.bvh=await t.bvh,t}}generate(e=null){let{staticGeometryGenerator:t,geometry:n,attributes:r}=this,i=t.objects;t.attributes=r,i.forEach(e=>{e.traverse(e=>{e.isSkinnedMesh&&e.skeleton&&e.skeleton.update()})});let a=t.generate(n),o=a.materials,s=a.changeType!==0||this._materialUuids===null||this._materialUuids.length!==length;if(!s){for(let e=0,t=o.length;e<t;e++)if(o[e].uuid!==this._materialUuids[e]){s=!0;break}}let c=Fi(o),{lights:l,iesTextures:u}=Ii(i);if(s&&(li(n,o,o),this._materialUuids=o.map(e=>e.uuid)),this.generateBVH){if(this.bvh instanceof Promise)throw Error(`PathTracingSceneGenerator: BVH is already building asynchronously.`);if(a.changeType===2){let t={strategy:2,maxLeafTris:1,indirect:!0,onProgress:e,...this.bvhOptions};this.bvh=this._buildAsync?this._bvhWorker.generate(n,t):new Hr(n,t)}else a.changeType===1&&this.bvh.refit()}return{bvhChanged:a.changeType!==0,bvh:this.bvh,needsMaterialIndexUpdate:s,lights:l,iesTextures:u,geometry:n,materials:o,textures:c,objects:i}}},Ri=class extends pe{set needsUpdate(e){super.needsUpdate=!0,this.dispatchEvent({type:`recompilation`})}constructor(e){super(e);for(let e in this.uniforms)Object.defineProperty(this,e,{get(){return this.uniforms[e].value},set(t){this.uniforms[e].value=t}})}setDefine(e,t=void 0){if(t==null){if(e in this.defines)return delete this.defines[e],this.needsUpdate=!0,!0}else if(this.defines[e]!==t)return this.defines[e]=t,this.needsUpdate=!0,!0;return!1}},zi=class extends Ri{constructor(e){super({blending:0,uniforms:{target1:{value:null},target2:{value:null},opacity:{value:1}},vertexShader:`
|
|
298
298
|
|
|
299
299
|
varying vec2 vUv;
|
|
300
300
|
|
|
@@ -331,7 +331,7 @@ struct BVH {
|
|
|
331
331
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
}`}),this.setValues(e)}};function
|
|
334
|
+
}`}),this.setValues(e)}};function Bi(e=1){let t=`uint`;return e>1&&(t=`uvec`+e),`
|
|
335
335
|
${t} sobolReverseBits( ${t} x ) {
|
|
336
336
|
|
|
337
337
|
x = ( ( ( x & 0xaaaaaaaau ) >> 1 ) | ( ( x & 0x55555555u ) << 1 ) );
|
|
@@ -366,7 +366,7 @@ struct BVH {
|
|
|
366
366
|
return x;
|
|
367
367
|
|
|
368
368
|
}
|
|
369
|
-
`}function
|
|
369
|
+
`}function Vi(e=1){let t=`uint`,n=`float`,r=``,i=`.r`,a=`1u`;return e>1&&(t=`uvec`+e,n=`vec`+e,r=e+``,e===2?(i=`.rg`,a=`uvec2( 1u, 2u )`):e===3?(i=`.rgb`,a=`uvec3( 1u, 2u, 3u )`):(i=``,a=`uvec4( 1u, 2u, 3u, 4u )`)),`
|
|
370
370
|
|
|
371
371
|
${n} sobol${r}( int effect ) {
|
|
372
372
|
|
|
@@ -384,16 +384,16 @@ struct BVH {
|
|
|
384
384
|
return SOBOL_FACTOR * ${n}( result >> 8 );
|
|
385
385
|
|
|
386
386
|
}
|
|
387
|
-
`}var
|
|
387
|
+
`}var Hi=`
|
|
388
388
|
|
|
389
389
|
// Utils
|
|
390
390
|
const float SOBOL_FACTOR = 1.0 / 16777216.0;
|
|
391
391
|
const uint SOBOL_MAX_POINTS = 256u * 256u;
|
|
392
392
|
|
|
393
|
-
${
|
|
394
|
-
${
|
|
395
|
-
${
|
|
396
|
-
${
|
|
393
|
+
${Bi(1)}
|
|
394
|
+
${Bi(2)}
|
|
395
|
+
${Bi(3)}
|
|
396
|
+
${Bi(4)}
|
|
397
397
|
|
|
398
398
|
uint sobolHash( uint x ) {
|
|
399
399
|
|
|
@@ -407,7 +407,7 @@ struct BVH {
|
|
|
407
407
|
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
`,
|
|
410
|
+
`,Ui=`
|
|
411
411
|
|
|
412
412
|
const uint SOBOL_DIRECTIONS_1[ 32 ] = uint[ 32 ](
|
|
413
413
|
0x80000000u, 0xc0000000u, 0xa0000000u, 0xf0000000u,
|
|
@@ -485,7 +485,7 @@ struct BVH {
|
|
|
485
485
|
|
|
486
486
|
}
|
|
487
487
|
|
|
488
|
-
`,
|
|
488
|
+
`,Wi=`
|
|
489
489
|
|
|
490
490
|
// Seeds
|
|
491
491
|
uniform sampler2D sobolTexture;
|
|
@@ -523,12 +523,12 @@ struct BVH {
|
|
|
523
523
|
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
${
|
|
527
|
-
${
|
|
528
|
-
${
|
|
529
|
-
${
|
|
526
|
+
${Vi(1)}
|
|
527
|
+
${Vi(2)}
|
|
528
|
+
${Vi(3)}
|
|
529
|
+
${Vi(4)}
|
|
530
530
|
|
|
531
|
-
`,
|
|
531
|
+
`,Gi=class extends Ri{constructor(){super({blending:0,uniforms:{resolution:{value:new E}},vertexShader:`
|
|
532
532
|
|
|
533
533
|
varying vec2 vUv;
|
|
534
534
|
void main() {
|
|
@@ -539,8 +539,8 @@ struct BVH {
|
|
|
539
539
|
}
|
|
540
540
|
`,fragmentShader:`
|
|
541
541
|
|
|
542
|
-
${
|
|
543
|
-
${
|
|
542
|
+
${Hi}
|
|
543
|
+
${Ui}
|
|
544
544
|
|
|
545
545
|
varying vec2 vUv;
|
|
546
546
|
uniform vec2 resolution;
|
|
@@ -550,7 +550,7 @@ struct BVH {
|
|
|
550
550
|
gl_FragColor = generateSobolPoint( index );
|
|
551
551
|
|
|
552
552
|
}
|
|
553
|
-
`})}},Ii=class{generate(e,t=256){let n=new De(t,t,{type:b,format:d,minFilter:S,magFilter:S,generateMipmaps:!1}),r=e.getRenderTarget();e.setRenderTarget(n);let i=new ae(new Fi);return i.material.resolution.set(t,t),i.render(e),e.setRenderTarget(r),i.dispose(),n}},Li=class extends c{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}},Ri=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Li?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}};function zi(e){let t=new Uint16Array(e.length);for(let n=0,i=e.length;n<i;++n)t[n]=r.toHalfFloat(e[n]);return t}function Bi(e,t,n=0,r=e.length){let i=n,a=n+r-1;for(;i<a;){let n=i+a>>1;e[n]<t?i=n+1:a=n}return i-n}function Vi(e,t,n){return .2126*e+.7152*t+.0722*n}function Hi(e,t=ve){let n=e.clone();n.source=new Ae({...n.image});let{width:i,height:a,data:o}=n.image,s=o;if(n.type!==t){s=t===1016?new Uint16Array(o.length):new Float32Array(o.length);let e;e=o instanceof Int8Array||o instanceof Int16Array||o instanceof Int32Array?2**(8*o.BYTES_PER_ELEMENT-1)-1:2**(8*o.BYTES_PER_ELEMENT)-1;for(let i=0,a=o.length;i<a;i++){let a=o[i];n.type===1016&&(a=r.fromHalfFloat(o[i])),n.type!==1015&&n.type!==1016&&(a/=e),t===1016&&(s[i]=r.toHalfFloat(a))}n.image.data=s,n.type=t}if(n.flipY){let e=s;s=s.slice();for(let t=0;t<a;t++)for(let n=0;n<i;n++){let r=a-t-1,o=4*(t*i+n),c=4*(r*i+n);s[c+0]=e[o+0],s[c+1]=e[o+1],s[c+2]=e[o+2],s[c+3]=e[o+3]}n.flipY=!1,n.image.data=s}return n}var Ui=class{constructor(){let t=new Re(zi(new Float32Array([0,0,0,0])),1,1);t.type=ve,t.format=d,t.minFilter=m,t.magFilter=m,t.wrapS=e,t.wrapT=e,t.generateMipmaps=!1,t.needsUpdate=!0;let n=new Re(zi(new Float32Array([0,1])),1,2);n.type=ve,n.format=te,n.minFilter=m,n.magFilter=m,n.generateMipmaps=!1,n.needsUpdate=!0;let r=new Re(zi(new Float32Array([0,0,1,1])),2,2);r.type=ve,r.format=te,r.minFilter=m,r.magFilter=m,r.generateMipmaps=!1,r.needsUpdate=!0,this.map=t,this.marginalWeights=n,this.conditionalWeights=r,this.totalSum=0}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(t){let n=Hi(t);n.wrapS=e,n.wrapT=T;let{width:i,height:a,data:o}=n.image,s=new Float32Array(i*a),c=new Float32Array(i*a),l=new Float32Array(a),u=new Float32Array(a),d=0,f=0;for(let e=0;e<a;e++){let t=0;for(let n=0;n<i;n++){let a=e*i+n,l=Vi(r.fromHalfFloat(o[4*a+0]),r.fromHalfFloat(o[4*a+1]),r.fromHalfFloat(o[4*a+2]));t+=l,d+=l,s[a]=l,c[a]=t}if(t!==0)for(let n=e*i,r=e*i+i;n<r;n++)s[n]/=t,c[n]/=t;f+=t,l[e]=t,u[e]=f}if(f!==0)for(let e=0,t=l.length;e<t;e++)l[e]/=f,u[e]/=f;let p=new Uint16Array(a),m=new Uint16Array(i*a);for(let e=0;e<a;e++){let t=Bi(u,(e+1)/a);p[e]=r.toHalfFloat((t+.5)/a)}for(let e=0;e<a;e++)for(let t=0;t<i;t++){let n=e*i+t,a=Bi(c,(t+1)/i,e*i,i);m[n]=r.toHalfFloat((a+.5)/i)}this.dispose();let{marginalWeights:h,conditionalWeights:g}=this;h.image={width:a,height:1,data:p},h.needsUpdate=!0,g.image={width:i,height:a,data:m},g.needsUpdate=!0,this.totalSum=d,this.map=n}},Wi=6,Gi=0,Ki=1,qi=2,Ji=3,Yi=4,Xi=new D,R=new D,Zi=new f,Qi=new s,$i=new D,ea=new D,ta=new D(0,1,0),na=class{constructor(){let e=new Re(new Float32Array(4),1,1);e.format=d,e.type=b,e.wrapS=T,e.wrapT=T,e.generateMipmaps=!1,e.minFilter=S,e.magFilter=S,this.tex=e,this.count=0}updateFrom(e,t=[]){let n=this.tex,r=Math.max(e.length*Wi,1),i=Math.ceil(Math.sqrt(r));n.image.width!==i&&(n.dispose(),n.image.data=new Float32Array(i*i*4),n.image.width=i,n.image.height=i);let a=n.image.data;for(let n=0,r=e.length;n<r;n++){let r=e[n],i=n*Wi*4,o=0;for(let e=0;e<24;e++)a[i+e]=0;r.getWorldPosition(R),a[i+o++]=R.x,a[i+o++]=R.y,a[i+o++]=R.z;let s=Gi;if(r.isRectAreaLight&&r.isCircular?s=Ki:r.isSpotLight?s=qi:r.isDirectionalLight?s=Ji:r.isPointLight&&(s=Yi),a[i+o++]=s,a[i+o++]=r.color.r,a[i+o++]=r.color.g,a[i+o++]=r.color.b,a[i+o++]=r.intensity,r.getWorldQuaternion(Qi),r.isRectAreaLight)Xi.set(r.width,0,0).applyQuaternion(Qi),a[i+o++]=Xi.x,a[i+o++]=Xi.y,a[i+o++]=Xi.z,o++,R.set(0,r.height,0).applyQuaternion(Qi),a[i+o++]=R.x,a[i+o++]=R.y,a[i+o++]=R.z,a[i+o++]=Xi.cross(R).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;$i.setFromMatrixPosition(r.matrixWorld),ea.setFromMatrixPosition(r.target.matrixWorld),Zi.lookAt($i,ea,ta),Qi.setFromRotationMatrix(Zi),Xi.set(1,0,0).applyQuaternion(Qi),a[i+o++]=Xi.x,a[i+o++]=Xi.y,a[i+o++]=Xi.z,o++,R.set(0,1,0).applyQuaternion(Qi),a[i+o++]=R.x,a[i+o++]=R.y,a[i+o++]=R.z,a[i+o++]=Math.PI*e*e,a[i+o++]=e,a[i+o++]=r.decay,a[i+o++]=r.distance,a[i+o++]=Math.cos(r.angle),a[i+o++]=Math.cos(r.angle*(1-r.penumbra)),a[i+o++]=r.iesMap?t.indexOf(r.iesMap):-1}else if(r.isPointLight){let e=Xi.setFromMatrixPosition(r.matrixWorld);a[i+o++]=e.x,a[i+o++]=e.y,a[i+o++]=e.z,o++,o+=4,o+=1,a[i+o++]=r.decay,a[i+o++]=r.distance}else if(r.isDirectionalLight){let e=Xi.setFromMatrixPosition(r.matrixWorld),t=R.setFromMatrixPosition(r.target.matrixWorld);ea.subVectors(e,t).normalize(),a[i+o++]=ea.x,a[i+o++]=ea.y,a[i+o++]=ea.z}}this.count=e.length;let o=ti(a.buffer);return this.hash!==o&&(this.hash=o,n.needsUpdate=!0,!0)}};function ra(e,t,n,r,i){if(t>r)throw Error();let a=e.length/t,o=e.constructor.BYTES_PER_ELEMENT*8,s=1;switch(e.constructor){case Uint8Array:case Uint16Array:case Uint32Array:s=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:s=2**(o-1)-1}for(let o=0;o<a;o++){let a=4*o,c=t*o;for(let o=0;o<r;o++)n[i+a+o]=t>=o+1?e[c+o]/s:0}}var ia=class extends ie{constructor(){super(),this._textures=[],this.type=b,this.format=d,this.internalFormat=`RGBA32F`}updateAttribute(e,t){let n=this._textures[e];n.updateFrom(t);let r=n.image,i=this.image;if(r.width!==i.width||r.height!==i.height)throw Error(`FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.`);let{width:a,height:o,data:s}=i,c=a*o*4*e,l=t.itemSize;l===3&&(l=4),ra(n.image.data,l,s,4,c),this.dispose(),this.needsUpdate=!0}setAttributes(e){let t=e[0].count,n=e.length;for(let r=0,i=n;r<i;r++)if(e[r].count!==t)throw Error(`FloatAttributeTextureArray: All attributes must have the same item count.`);let r=this._textures;for(;r.length<n;){let e=new Rr;r.push(e)}for(;r.length>n;)r.pop();for(let t=0,i=n;t<i;t++)r[t].updateFrom(e[t]);let i=r[0].image,a=this.image;(i.width!==a.width||i.height!==a.height||i.depth!==n)&&(a.width=i.width,a.height=i.height,a.depth=n,a.data=new Float32Array(a.width*a.height*a.depth*4));let{data:o,width:s,height:c}=a;for(let t=0,i=n;t<i;t++){let n=r[t],i=s*c*4*t,a=e[t].itemSize;a===3&&(a=4),ra(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},aa=class extends ia{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,n,r){this.setAttributes([e,t,n,r])}};function oa(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function sa(e){return`${e.source.uuid}:${e.colorSpace}`}function ca(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=sa(i);t.has(a)||(t.add(a),n.push(i))}return n}function la(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(oa)}function ua(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return ca(Array.from(t)).sort(oa)}function da(e){let t=[];return e.traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(oa)}var fa=188,pa=class{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}},ma=class extends Re{constructor(){super(new Float32Array(4),1,1),this.format=d,this.type=b,this.wrapS=T,this.wrapT=T,this.minFilter=S,this.magFilter=S,this.generateMipmaps=!1,this.features=new pa}updateFrom(e,t){function n(e,t,n=-1){if(t in e&&e[t]){let n=sa(e[t]);return u[n]}return n}function r(e,t,n){return t in e?e[t]:n}function i(e,t,n,r){let i=e[t]&&e[t].isTexture?e[t]:null;if(i){i.matrixAutoUpdate&&i.updateMatrix();let e=i.matrix.elements,t=0;n[r+t++]=e[0],n[r+t++]=e[3],n[r+t++]=e[6],t++,n[r+t++]=e[1],n[r+t++]=e[4],n[r+t++]=e[7],t++}return 8}let a=0,o=e.length*47,s=Math.ceil(Math.sqrt(o))||1,{image:c,features:l}=this,u={};for(let e=0,n=t.length;e<n;e++)u[sa(t[e])]=e;c.width!==s&&(this.dispose(),c.data=new Float32Array(s*s*4),c.width=s,c.height=s);let d=c.data;l.reset();for(let t=0,o=e.length;t<o;t++){let o=e[t];if(o.isFogVolumeMaterial){l.setUsed(`FOG`);for(let e=0;e<fa;e++)d[a+e]=0;d[a+0+0]=o.color.r,d[a+0+1]=o.color.g,d[a+0+2]=o.color.b,d[a+8+3]=r(o,`emissiveIntensity`,0),d[a+12+0]=o.emissive.r,d[a+12+1]=o.emissive.g,d[a+12+2]=o.emissive.b,d[a+52+1]=o.density,d[a+52+3]=0,d[a+56+2]=4,a+=fa;continue}d[a++]=o.color.r,d[a++]=o.color.g,d[a++]=o.color.b,d[a++]=n(o,`map`),d[a++]=r(o,`metalness`,0),d[a++]=n(o,`metalnessMap`),d[a++]=r(o,`roughness`,0),d[a++]=n(o,`roughnessMap`),d[a++]=r(o,`ior`,1.5),d[a++]=r(o,`transmission`,0),d[a++]=n(o,`transmissionMap`),d[a++]=r(o,`emissiveIntensity`,0),`emissive`in o?(d[a++]=o.emissive.r,d[a++]=o.emissive.g,d[a++]=o.emissive.b):(d[a++]=0,d[a++]=0,d[a++]=0),d[a++]=n(o,`emissiveMap`),d[a++]=n(o,`normalMap`),`normalScale`in o?(d[a++]=o.normalScale.x,d[a++]=o.normalScale.y):(d[a++]=1,d[a++]=1),d[a++]=r(o,`clearcoat`,0),d[a++]=n(o,`clearcoatMap`),d[a++]=r(o,`clearcoatRoughness`,0),d[a++]=n(o,`clearcoatRoughnessMap`),d[a++]=n(o,`clearcoatNormalMap`),`clearcoatNormalScale`in o?(d[a++]=o.clearcoatNormalScale.x,d[a++]=o.clearcoatNormalScale.y):(d[a++]=1,d[a++]=1),a++,d[a++]=r(o,`sheen`,0),`sheenColor`in o?(d[a++]=o.sheenColor.r,d[a++]=o.sheenColor.g,d[a++]=o.sheenColor.b):(d[a++]=0,d[a++]=0,d[a++]=0),d[a++]=n(o,`sheenColorMap`),d[a++]=r(o,`sheenRoughness`,0),d[a++]=n(o,`sheenRoughnessMap`),d[a++]=n(o,`iridescenceMap`),d[a++]=n(o,`iridescenceThicknessMap`),d[a++]=r(o,`iridescence`,0),d[a++]=r(o,`iridescenceIOR`,1.3);let s=r(o,`iridescenceThicknessRange`,[100,400]);d[a++]=s[0],d[a++]=s[1],`specularColor`in o?(d[a++]=o.specularColor.r,d[a++]=o.specularColor.g,d[a++]=o.specularColor.b):(d[a++]=1,d[a++]=1,d[a++]=1),d[a++]=n(o,`specularColorMap`),d[a++]=r(o,`specularIntensity`,1),d[a++]=n(o,`specularIntensityMap`);let c=r(o,`thickness`,0)===0&&r(o,`attenuationDistance`,1/0)===1/0;if(d[a++]=Number(c),a++,`attenuationColor`in o?(d[a++]=o.attenuationColor.r,d[a++]=o.attenuationColor.g,d[a++]=o.attenuationColor.b):(d[a++]=1,d[a++]=1,d[a++]=1),d[a++]=r(o,`attenuationDistance`,1/0),d[a++]=n(o,`alphaMap`),d[a++]=o.opacity,d[a++]=o.alphaTest,!c&&o.transmission>0)d[a++]=0;else switch(o.side){case 0:d[a++]=1;break;case 1:d[a++]=-1;break;case 2:d[a++]=0}d[a++]=Number(r(o,`matte`,!1)),d[a++]=Number(r(o,`castShadow`,!0)),d[a++]=Number(o.vertexColors)|Number(o.flatShading)<<1,d[a++]=Number(o.transparent),a+=i(o,`map`,d,a),a+=i(o,`metalnessMap`,d,a),a+=i(o,`roughnessMap`,d,a),a+=i(o,`transmissionMap`,d,a),a+=i(o,`emissiveMap`,d,a),a+=i(o,`normalMap`,d,a),a+=i(o,`clearcoatMap`,d,a),a+=i(o,`clearcoatNormalMap`,d,a),a+=i(o,`clearcoatRoughnessMap`,d,a),a+=i(o,`sheenColorMap`,d,a),a+=i(o,`sheenRoughnessMap`,d,a),a+=i(o,`iridescenceMap`,d,a),a+=i(o,`iridescenceThicknessMap`,d,a),a+=i(o,`specularColorMap`,d,a),a+=i(o,`specularIntensityMap`,d,a),a+=i(o,`alphaMap`,d,a)}let f=ti(d.buffer);return this.hash!==f&&(this.hash=f,this.needsUpdate=!0,!0)}},ha=new ze;function ga(e){return e?`${e.uuid}:${e.version}`:null}function _a(e,t){for(let n in t)n in e&&(e[n]=t[n])}var va=class extends de{constructor(t,n,r){let i={format:d,type:Te,minFilter:m,magFilter:m,wrapS:e,wrapT:e,generateMipmaps:!1,...r};super(t,n,1,i),_a(this.texture,i),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let a=new ae(new ya);this.fsQuad=a}setTextures(e,t,n=this.width,r=this.height){let i=e.getRenderTarget(),a=e.toneMapping,o=e.getClearAlpha();e.getClearColor(ha);let s=t.length||1;(n!==this.width||r!==this.height||this.depth!==s)&&(this.setSize(n,r,s),this.hashes=Array(s).fill(null)),e.setClearColor(0,0),e.toneMapping=0;let c=this.fsQuad,l=this.hashes,u=!1;for(let n=0,r=s;n<r;n++){let r=t[n],i=ga(r);r&&(l[n]!==i||r.isWebGLRenderTarget)&&(r.matrixAutoUpdate=!1,r.matrix.identity(),c.material.map=r,e.setRenderTarget(this,n),c.render(e),r.updateMatrix(),r.matrixAutoUpdate=!0,l[n]=i,u=!0)}return c.material.map=null,e.setClearColor(ha,o),e.setRenderTarget(i),e.toneMapping=a,u}dispose(){super.dispose(),this.fsQuad.dispose()}},ya=class extends Pe{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
553
|
+
`})}},Ki=class{generate(e,t=256){let n=new Ge(t,t,{type:d,format:D,minFilter:T,magFilter:T,generateMipmaps:!1}),r=e.getRenderTarget();e.setRenderTarget(n);let i=new He(new Gi);return i.material.resolution.set(t,t),i.render(e),e.setRenderTarget(r),i.dispose(),n}},qi=class extends y{set bokehSize(e){this.fStop=this.getFocalLength()/e}get bokehSize(){return this.getFocalLength()/this.fStop}constructor(...e){super(...e),this.fStop=1.4,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=25,this.anamorphicRatio=1}copy(e,t){return super.copy(e,t),this.fStop=e.fStop,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio,this}},Ji=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof qi?(this.bokehSize=e.bokehSize,this.apertureBlades=e.apertureBlades,this.apertureRotation=e.apertureRotation,this.focusDistance=e.focusDistance,this.anamorphicRatio=e.anamorphicRatio):(this.bokehSize=0,this.apertureRotation=0,this.apertureBlades=0,this.focusDistance=10,this.anamorphicRatio=1)}};function Yi(e){let t=new Uint16Array(e.length);for(let n=0,r=e.length;n<r;++n)t[n]=v.toHalfFloat(e[n]);return t}function Xi(e,t,n=0,r=e.length){let i=n,a=n+r-1;for(;i<a;){let n=i+a>>1;e[n]<t?i=n+1:a=n}return i-n}function Zi(e,t,n){return .2126*e+.7152*t+.0722*n}function Qi(e,t=Ye){let n=e.clone();n.source=new Ne({...n.image});let{width:r,height:i,data:a}=n.image,o=a;if(n.type!==t){o=t===1016?new Uint16Array(a.length):new Float32Array(a.length);let e;e=a instanceof Int8Array||a instanceof Int16Array||a instanceof Int32Array?2**(8*a.BYTES_PER_ELEMENT-1)-1:2**(8*a.BYTES_PER_ELEMENT)-1;for(let r=0,i=a.length;r<i;r++){let i=a[r];n.type===1016&&(i=v.fromHalfFloat(a[r])),n.type!==1015&&n.type!==1016&&(i/=e),t===1016&&(o[r]=v.toHalfFloat(i))}n.image.data=o,n.type=t}if(n.flipY){let e=o;o=o.slice();for(let t=0;t<i;t++)for(let n=0;n<r;n++){let a=i-t-1,s=4*(t*r+n),c=4*(a*r+n);o[c+0]=e[s+0],o[c+1]=e[s+1],o[c+2]=e[s+2],o[c+3]=e[s+3]}n.flipY=!1,n.image.data=o}return n}var $i=class{constructor(){let e=new h(Yi(new Float32Array([0,0,0,0])),1,1);e.type=Ye,e.format=D,e.minFilter=w,e.magFilter=w,e.wrapS=Ee,e.wrapT=Ee,e.generateMipmaps=!1,e.needsUpdate=!0;let t=new h(Yi(new Float32Array([0,1])),1,2);t.type=Ye,t.format=Le,t.minFilter=w,t.magFilter=w,t.generateMipmaps=!1,t.needsUpdate=!0;let n=new h(Yi(new Float32Array([0,0,1,1])),2,2);n.type=Ye,n.format=Le,n.minFilter=w,n.magFilter=w,n.generateMipmaps=!1,n.needsUpdate=!0,this.map=e,this.marginalWeights=t,this.conditionalWeights=n,this.totalSum=0}getPixelWeight(e,t,n){return Zi(e,t,n)}dispose(){this.marginalWeights.dispose(),this.conditionalWeights.dispose(),this.map.dispose()}updateFrom(e){let t=Qi(e);t.wrapS=Ee,t.wrapT=_;let{width:n,height:r,data:i}=t.image,a=new Float32Array(n*r),o=new Float32Array(n*r),s=new Float32Array(r),c=new Float32Array(r),l=0,u=0;for(let e=0;e<r;e++){let t=0;for(let s=0;s<n;s++){let c=e*n+s,u=v.fromHalfFloat(i[4*c+0]),d=v.fromHalfFloat(i[4*c+1]),f=v.fromHalfFloat(i[4*c+2]),p=this.getPixelWeight(u,d,f,e,r);t+=p,l+=p,a[c]=p,o[c]=t}if(t!==0)for(let r=e*n,i=e*n+n;r<i;r++)a[r]/=t,o[r]/=t;u+=t,s[e]=t,c[e]=u}if(u!==0)for(let e=0,t=s.length;e<t;e++)s[e]/=u,c[e]/=u;let d=new Uint16Array(r),f=new Uint16Array(n*r);for(let e=0;e<r;e++){let t=Xi(c,(e+1)/r);d[e]=v.toHalfFloat((t+.5)/r)}for(let e=0;e<r;e++)for(let t=0;t<n;t++){let r=e*n+t,i=Xi(o,(t+1)/n,e*n,n);f[r]=v.toHalfFloat((i+.5)/n)}this.dispose();let{marginalWeights:p,conditionalWeights:m}=this;p.image={width:r,height:1,data:d},p.needsUpdate=!0,m.image={width:n,height:r,data:f},m.needsUpdate=!0,this.totalSum=l,this.map=t}},ea=6,ta=0,na=1,ra=2,ia=3,aa=4,oa=new k,sa=new k,ca=new O,la=new ze,ua=new k,da=new k,fa=new k(0,1,0),pa=class{constructor(){let e=new h(new Float32Array(4),1,1);e.format=D,e.type=d,e.wrapS=_,e.wrapT=_,e.generateMipmaps=!1,e.minFilter=T,e.magFilter=T,this.tex=e,this.count=0}updateFrom(e,t=[]){let n=this.tex,r=Math.max(e.length*ea,1),i=Math.ceil(Math.sqrt(r));n.image.width!==i&&(n.dispose(),n.image.data=new Float32Array(i*i*4),n.image.width=i,n.image.height=i);let a=n.image.data;for(let n=0,r=e.length;n<r;n++){let r=e[n],i=n*ea*4,o=0;for(let e=0;e<24;e++)a[i+e]=0;r.getWorldPosition(sa),a[i+o++]=sa.x,a[i+o++]=sa.y,a[i+o++]=sa.z;let s=ta;if(r.isRectAreaLight&&r.isCircular?s=na:r.isSpotLight?s=ra:r.isDirectionalLight?s=ia:r.isPointLight&&(s=aa),a[i+o++]=s,a[i+o++]=r.color.r,a[i+o++]=r.color.g,a[i+o++]=r.color.b,a[i+o++]=r.intensity,r.getWorldQuaternion(la),r.isRectAreaLight)oa.set(r.width,0,0).applyQuaternion(la),a[i+o++]=oa.x,a[i+o++]=oa.y,a[i+o++]=oa.z,o++,sa.set(0,r.height,0).applyQuaternion(la),a[i+o++]=sa.x,a[i+o++]=sa.y,a[i+o++]=sa.z,a[i+o++]=oa.cross(sa).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;ua.setFromMatrixPosition(r.matrixWorld),da.setFromMatrixPosition(r.target.matrixWorld),ca.lookAt(ua,da,fa),la.setFromRotationMatrix(ca),oa.set(1,0,0).applyQuaternion(la),a[i+o++]=oa.x,a[i+o++]=oa.y,a[i+o++]=oa.z,o++,sa.set(0,1,0).applyQuaternion(la),a[i+o++]=sa.x,a[i+o++]=sa.y,a[i+o++]=sa.z,a[i+o++]=Math.PI*e*e,a[i+o++]=e,a[i+o++]=r.decay,a[i+o++]=r.distance,a[i+o++]=Math.cos(r.angle),a[i+o++]=Math.cos(r.angle*(1-r.penumbra)),a[i+o++]=r.iesMap?t.indexOf(r.iesMap):-1}else if(r.isPointLight){let e=oa.setFromMatrixPosition(r.matrixWorld);a[i+o++]=e.x,a[i+o++]=e.y,a[i+o++]=e.z,o++,o+=4,o+=1,a[i+o++]=r.decay,a[i+o++]=r.distance}else if(r.isDirectionalLight){let e=oa.setFromMatrixPosition(r.matrixWorld),t=sa.setFromMatrixPosition(r.target.matrixWorld);da.subVectors(e,t).normalize(),a[i+o++]=da.x,a[i+o++]=da.y,a[i+o++]=da.z}}this.count=e.length;let o=di(a.buffer);return this.hash!==o&&(this.hash=o,n.needsUpdate=!0,!0)}};function ma(e,t,n,r,i){if(t>r)throw Error();let a=e.length/t,o=e.constructor.BYTES_PER_ELEMENT*8,s=1;switch(e.constructor){case Uint8Array:case Uint16Array:case Uint32Array:s=2**o-1;break;case Int8Array:case Int16Array:case Int32Array:s=2**(o-1)-1}for(let o=0;o<a;o++){let a=4*o,c=t*o;for(let o=0;o<r;o++)n[i+a+o]=t>=o+1?e[c+o]/s:0}}var ha=class extends Ce{constructor(){super(),this._textures=[],this.type=d,this.format=D,this.internalFormat=`RGBA32F`}updateAttribute(e,t){let n=this._textures[e];n.updateFrom(t);let r=n.image,i=this.image;if(r.width!==i.width||r.height!==i.height)throw Error(`FloatAttributeTextureArray: Attribute must be the same dimensions when updating single layer.`);let{width:a,height:o,data:s}=i,c=a*o*4*e,l=t.itemSize;l===3&&(l=4),ma(n.image.data,l,s,4,c),this.dispose(),this.needsUpdate=!0}setAttributes(e){let t=e[0].count,n=e.length;for(let r=0,i=n;r<i;r++)if(e[r].count!==t)throw Error(`FloatAttributeTextureArray: All attributes must have the same item count.`);let r=this._textures;for(;r.length<n;){let e=new Jr;r.push(e)}for(;r.length>n;)r.pop();for(let t=0,i=n;t<i;t++)r[t].updateFrom(e[t]);let i=r[0].image,a=this.image;(i.width!==a.width||i.height!==a.height||i.depth!==n)&&(a.width=i.width,a.height=i.height,a.depth=n,a.data=new Float32Array(a.width*a.height*a.depth*4));let{data:o,width:s,height:c}=a;for(let t=0,i=n;t<i;t++){let n=r[t],i=s*c*4*t,a=e[t].itemSize;a===3&&(a=4),ma(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},ga=class extends ha{updateNormalAttribute(e){this.updateAttribute(0,e)}updateTangentAttribute(e){this.updateAttribute(1,e)}updateUvAttribute(e){this.updateAttribute(2,e)}updateColorAttribute(e){this.updateAttribute(3,e)}updateFrom(e,t,n,r){this.setAttributes([e,t,n,r])}};function _a(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function va(e){return`${e.source.uuid}:${e.colorSpace}`}function ya(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=va(i);t.has(a)||(t.add(a),n.push(i))}return n}function ba(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(_a)}function xa(e){let t=new Set;for(let n=0,r=e.length;n<r;n++){let r=e[n];for(let e in r){let n=r[e];n&&n.isTexture&&t.add(n)}}return ya(Array.from(t)).sort(_a)}function Sa(e){let t=[];return e.traverseVisible(e=>{(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(_a)}var Ca=188,wa=class{constructor(){this._features={}}isUsed(e){return e in this._features}setUsed(e,t=!0){t===!1?delete this._features[e]:this._features[e]=!0}reset(){this._features={}}},Ta=class extends h{constructor(){super(new Float32Array(4),1,1),this.format=D,this.type=d,this.wrapS=_,this.wrapT=_,this.minFilter=T,this.magFilter=T,this.generateMipmaps=!1,this.features=new wa}updateFrom(e,t){function n(e,t,n=-1){if(t in e&&e[t]){let n=va(e[t]);return u[n]}return n}function r(e,t,n){return t in e?e[t]:n}function i(e,t,n,r){let i=e[t]&&e[t].isTexture?e[t]:null;if(i){i.matrixAutoUpdate&&i.updateMatrix();let e=i.matrix.elements,t=0;n[r+t++]=e[0],n[r+t++]=e[3],n[r+t++]=e[6],t++,n[r+t++]=e[1],n[r+t++]=e[4],n[r+t++]=e[7],t++}return 8}let a=0,o=e.length*47,s=Math.ceil(Math.sqrt(o))||1,{image:c,features:l}=this,u={};for(let e=0,n=t.length;e<n;e++)u[va(t[e])]=e;c.width!==s&&(this.dispose(),c.data=new Float32Array(s*s*4),c.width=s,c.height=s);let d=c.data;l.reset();for(let t=0,o=e.length;t<o;t++){let o=e[t];if(o.isFogVolumeMaterial){l.setUsed(`FOG`);for(let e=0;e<Ca;e++)d[a+e]=0;d[a+0+0]=o.color.r,d[a+0+1]=o.color.g,d[a+0+2]=o.color.b,d[a+8+3]=r(o,`emissiveIntensity`,0),d[a+12+0]=o.emissive.r,d[a+12+1]=o.emissive.g,d[a+12+2]=o.emissive.b,d[a+52+1]=o.density,d[a+52+3]=0,d[a+56+2]=4,a+=Ca;continue}d[a++]=o.color.r,d[a++]=o.color.g,d[a++]=o.color.b,d[a++]=n(o,`map`),d[a++]=r(o,`metalness`,0),d[a++]=n(o,`metalnessMap`),d[a++]=r(o,`roughness`,0),d[a++]=n(o,`roughnessMap`),d[a++]=r(o,`ior`,1.5),d[a++]=r(o,`transmission`,0),d[a++]=n(o,`transmissionMap`),d[a++]=r(o,`emissiveIntensity`,0),`emissive`in o?(d[a++]=o.emissive.r,d[a++]=o.emissive.g,d[a++]=o.emissive.b):(d[a++]=0,d[a++]=0,d[a++]=0),d[a++]=n(o,`emissiveMap`),d[a++]=n(o,`normalMap`),`normalScale`in o?(d[a++]=o.normalScale.x,d[a++]=o.normalScale.y):(d[a++]=1,d[a++]=1),d[a++]=r(o,`clearcoat`,0),d[a++]=n(o,`clearcoatMap`),d[a++]=r(o,`clearcoatRoughness`,0),d[a++]=n(o,`clearcoatRoughnessMap`),d[a++]=n(o,`clearcoatNormalMap`),`clearcoatNormalScale`in o?(d[a++]=o.clearcoatNormalScale.x,d[a++]=o.clearcoatNormalScale.y):(d[a++]=1,d[a++]=1),a++,d[a++]=r(o,`sheen`,0),`sheenColor`in o?(d[a++]=o.sheenColor.r,d[a++]=o.sheenColor.g,d[a++]=o.sheenColor.b):(d[a++]=0,d[a++]=0,d[a++]=0),d[a++]=n(o,`sheenColorMap`),d[a++]=r(o,`sheenRoughness`,0),d[a++]=n(o,`sheenRoughnessMap`),d[a++]=n(o,`iridescenceMap`),d[a++]=n(o,`iridescenceThicknessMap`),d[a++]=r(o,`iridescence`,0),d[a++]=r(o,`iridescenceIOR`,1.3);let s=r(o,`iridescenceThicknessRange`,[100,400]);d[a++]=s[0],d[a++]=s[1],`specularColor`in o?(d[a++]=o.specularColor.r,d[a++]=o.specularColor.g,d[a++]=o.specularColor.b):(d[a++]=1,d[a++]=1,d[a++]=1),d[a++]=n(o,`specularColorMap`),d[a++]=r(o,`specularIntensity`,1),d[a++]=n(o,`specularIntensityMap`);let c=r(o,`thickness`,0)===0&&r(o,`attenuationDistance`,1/0)===1/0;if(d[a++]=Number(c),a++,`attenuationColor`in o?(d[a++]=o.attenuationColor.r,d[a++]=o.attenuationColor.g,d[a++]=o.attenuationColor.b):(d[a++]=1,d[a++]=1,d[a++]=1),d[a++]=r(o,`attenuationDistance`,1/0),d[a++]=n(o,`alphaMap`),d[a++]=o.opacity,d[a++]=o.alphaTest,!c&&o.transmission>0)d[a++]=0;else switch(o.side){case 0:d[a++]=1;break;case 1:d[a++]=-1;break;case 2:d[a++]=0}d[a++]=Number(r(o,`matte`,!1)),d[a++]=Number(r(o,`castShadow`,!0)),d[a++]=Number(o.vertexColors)|Number(o.flatShading)<<1,d[a++]=Number(o.transparent),a+=i(o,`map`,d,a),a+=i(o,`metalnessMap`,d,a),a+=i(o,`roughnessMap`,d,a),a+=i(o,`transmissionMap`,d,a),a+=i(o,`emissiveMap`,d,a),a+=i(o,`normalMap`,d,a),a+=i(o,`clearcoatMap`,d,a),a+=i(o,`clearcoatNormalMap`,d,a),a+=i(o,`clearcoatRoughnessMap`,d,a),a+=i(o,`sheenColorMap`,d,a),a+=i(o,`sheenRoughnessMap`,d,a),a+=i(o,`iridescenceMap`,d,a),a+=i(o,`iridescenceThicknessMap`,d,a),a+=i(o,`specularColorMap`,d,a),a+=i(o,`specularIntensityMap`,d,a),a+=i(o,`alphaMap`,d,a)}let f=di(d.buffer);return this.hash!==f&&(this.hash=f,this.needsUpdate=!0,!0)}},Ea=new t;function Da(e){return e?`${e.uuid}:${e.version}`:null}function Oa(e,t){for(let n in t)n in e&&(e[n]=t[n])}var ka=class extends i{constructor(e,t,n){let r={format:D,type:oe,minFilter:w,magFilter:w,wrapS:Ee,wrapT:Ee,generateMipmaps:!1,...n};super(e,t,1,r),Oa(this.texture,r),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let i=new He(new Aa);this.fsQuad=i}setTextures(e,t,n=this.width,r=this.height){let i=e.getRenderTarget(),a=e.toneMapping,o=e.getClearAlpha();e.getClearColor(Ea);let s=t.length||1;(n!==this.width||r!==this.height||this.depth!==s)&&(this.setSize(n,r,s),this.hashes=Array(s).fill(null)),e.setClearColor(0,0),e.toneMapping=0;let c=this.fsQuad,l=this.hashes,u=!1;for(let n=0,r=s;n<r;n++){let r=t[n],i=Da(r);r&&(l[n]!==i||r.isWebGLRenderTarget)&&(r.matrixAutoUpdate=!1,r.matrix.identity(),c.material.map=r,e.setRenderTarget(this,n),c.render(e),r.updateMatrix(),r.matrixAutoUpdate=!0,l[n]=i,u=!0)}return c.material.map=null,e.setClearColor(Ea,o),e.setRenderTarget(i),e.toneMapping=a,u}dispose(){super.dispose(),this.fsQuad.dispose()}},Aa=class extends pe{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}constructor(){super({uniforms:{map:{value:null}},vertexShader:`
|
|
554
554
|
varying vec2 vUv;
|
|
555
555
|
void main() {
|
|
556
556
|
|
|
@@ -566,7 +566,7 @@ struct BVH {
|
|
|
566
566
|
gl_FragColor = texture2D( map, vUv );
|
|
567
567
|
|
|
568
568
|
}
|
|
569
|
-
`})}};function
|
|
569
|
+
`})}};function ja(e,t=Math.random()){for(let n=e.length-1;n>0;n--){let r=Math.floor(t()*(n+1)),i=e[n];e[n]=e[r],e[r]=i}return e}var Ma=class{constructor(e,t,n=Math.random){let r=e**t,i=new Uint16Array(r),a=r;for(let e=0;e<r;e++)i[e]=e;this.samples=new Float32Array(t),this.strataCount=e,this.reset=function(){for(let e=0;e<r;e++)i[e]=e;a=0},this.reshuffle=function(){a=0},this.next=function(){let{samples:r}=this;a>=i.length&&(ja(i,n),this.reshuffle());let o=i[a++];for(let i=0;i<t;i++)r[i]=(o%e+n())/e,o=Math.floor(o/e);return r}}},Na=class{constructor(e,t,n=Math.random){let r=0;for(let e of t)r+=e;let i=new Float32Array(r),a=[],o=0;for(let r of t){let t=new Ma(e,r,n);t.samples=new Float32Array(i.buffer,o,t.samples.length),o+=t.samples.length*4,a.push(t)}this.samples=i,this.strataCount=e,this.next=function(){for(let e of a)e.next();return i},this.reshuffle=function(){for(let e of a)e.reshuffle()},this.reset=function(){for(let e of a)e.reset()}}},Pa=class{constructor(e=0){this.m=2147483648,this.a=1103515245,this.c=12345,this.seed=e}nextInt(){return this.seed=(this.a*this.seed+this.c)%this.m,this.seed}nextFloat(){return this.nextInt()/(this.m-1)}},Fa=class extends h{constructor(e=1,t=1,n=8){super(new Float32Array(1),1,1,D,d),this.minFilter=T,this.magFilter=T,this.strata=n,this.sampler=null,this.generator=new Pa,this.stableNoise=!1,this.random=()=>this.stableNoise?this.generator.nextFloat():Math.random(),this.init(e,t,n)}init(e=this.image.height,t=this.image.width,n=this.strata){let{image:r}=this;if(r.width===t&&r.height===e&&this.sampler!==null)return;let i=new Na(n,Array(e*t).fill(4),this.random);r.width=t,r.height=e,r.data=i.samples,this.sampler=i,this.dispose(),this.next()}next(){this.sampler.next(),this.needsUpdate=!0}reset(){this.sampler.reset(),this.generator.seed=0}};function Ia(e,t=Math.random){for(let n=e.length-1;n>0;n--){let r=~~((t()-1e-6)*n),i=e[n];e[n]=e[r],e[r]=i}}function La(e,t){e.fill(0);for(let n=0;n<t;n++)e[n]=1}var Ra=class{constructor(e){this.count=0,this.size=-1,this.sigma=-1,this.radius=-1,this.lookupTable=null,this.score=null,this.binaryPattern=null,this.resize(e),this.setSigma(1.5)}findVoid(){let{score:e,binaryPattern:t}=this,n=1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==0)continue;let a=e[i];a<n&&(n=a,r=i)}return r}findCluster(){let{score:e,binaryPattern:t}=this,n=-1/0,r=-1;for(let i=0,a=t.length;i<a;i++){if(t[i]!==1)continue;let a=e[i];a>n&&(n=a,r=i)}return r}setSigma(e){if(e===this.sigma)return;let t=~~(Math.sqrt(20*e**2)+1),n=2*t+1,r=new Float32Array(n*n),i=e*e;for(let e=-t;e<=t;e++)for(let a=-t;a<=t;a++){let o=(t+a)*n+e+t,s=e*e+a*a;r[o]=Math.E**(-s/(2*i))}this.lookupTable=r,this.sigma=e,this.radius=t}resize(e){this.size!==e&&(this.size=e,this.score=new Float32Array(e*e),this.binaryPattern=new Uint8Array(e*e))}invert(){let{binaryPattern:e,score:t,size:n}=this;t.fill(0);for(let t=0,r=e.length;t<r;t++)if(e[t]===0){let r=~~(t/n),i=t-r*n;this.updateScore(i,r,1),e[t]=1}else e[t]=0}updateScore(e,t,n){let{size:r,score:i,lookupTable:a}=this,o=this.radius,s=2*o+1;for(let c=-o;c<=o;c++)for(let l=-o;l<=o;l++){let u=a[(o+l)*s+c+o],d=e+c;d=d<0?r+d:d%r;let f=t+l;f=f<0?r+f:f%r;let p=f*r+d;i[p]+=n*u}}addPointIndex(e){this.binaryPattern[e]=1;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,1),this.count++}removePointIndex(e){this.binaryPattern[e]=0;let t=this.size,n=~~(e/t),r=e-n*t;this.updateScore(r,n,-1),this.count--}copy(e){this.resize(e.size),this.score.set(e.score),this.binaryPattern.set(e.binaryPattern),this.setSigma(e.sigma),this.count=e.count}},za=class{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Ra(1),this.savedSamples=new Ra(1)}generate(){let{samples:e,savedSamples:t,sigma:n,majorityPointsRatio:r,size:i}=this;e.resize(i),e.setSigma(n);let a=Math.floor(i*i*r),o=e.binaryPattern;La(o,a),Ia(o,this.random);for(let t=0,n=o.length;t<n;t++)o[t]===1&&e.addPointIndex(t);for(;;){let t=e.findCluster();e.removePointIndex(t);let n=e.findVoid();if(t===n){e.addPointIndex(t);break}e.addPointIndex(n)}let s=new Uint32Array(i*i);t.copy(e);let c;for(c=e.count-1;c>=0;){let t=e.findCluster();e.removePointIndex(t),s[t]=c,c--}let l=i*i;for(c=t.count;c<l/2;){let e=t.findVoid();t.addPointIndex(e),s[e]=c,c++}for(t.invert();c<l;){let e=t.findCluster();t.removePointIndex(e),s[e]=c,c++}return{data:s,maxValue:l}}};function Ba(e){return e>=3?4:e}function Va(e){switch(e){case 1:return Le;case 2:return Se;default:return D}}var Ha=class extends h{constructor(e=64,t=1){super(new Float32Array(4),1,1,D,d),this.minFilter=T,this.magFilter=T,this.size=e,this.channels=t,this.update()}update(){let e=this.channels,t=this.size,n=new za;n.channels=e,n.size=t;let r=Ba(e),i=Va(r);(this.image.width!==t||i!==this.format)&&(this.image.width=t,this.image.height=t,this.image.data=new Float32Array(t**2*r),this.format=i,this.dispose());let a=this.image.data;for(let t=0,i=e;t<i;t++){let e=n.generate(),i=e.data,o=e.maxValue;for(let e=0,n=i.length;e<n;e++){let n=i[e]/o;a[e*r+t]=n}}this.needsUpdate=!0}},Ua=`
|
|
570
570
|
|
|
571
571
|
struct PhysicalCamera {
|
|
572
572
|
|
|
@@ -578,7 +578,7 @@ struct BVH {
|
|
|
578
578
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
|
-
`,
|
|
581
|
+
`,Wa=`
|
|
582
582
|
|
|
583
583
|
struct EquirectHdrInfo {
|
|
584
584
|
|
|
@@ -590,7 +590,7 @@ struct BVH {
|
|
|
590
590
|
|
|
591
591
|
};
|
|
592
592
|
|
|
593
|
-
`,
|
|
593
|
+
`,Ga=`
|
|
594
594
|
|
|
595
595
|
#define RECT_AREA_LIGHT_TYPE 0
|
|
596
596
|
#define CIRC_AREA_LIGHT_TYPE 1
|
|
@@ -676,7 +676,7 @@ struct BVH {
|
|
|
676
676
|
|
|
677
677
|
}
|
|
678
678
|
|
|
679
|
-
`,
|
|
679
|
+
`,Ka=`
|
|
680
680
|
|
|
681
681
|
struct Material {
|
|
682
682
|
|
|
@@ -885,7 +885,7 @@ struct BVH {
|
|
|
885
885
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
|
-
`,
|
|
888
|
+
`,qa=`
|
|
889
889
|
|
|
890
890
|
struct SurfaceRecord {
|
|
891
891
|
|
|
@@ -947,7 +947,7 @@ struct BVH {
|
|
|
947
947
|
vec3 color;
|
|
948
948
|
};
|
|
949
949
|
|
|
950
|
-
`,
|
|
950
|
+
`,Ja=`
|
|
951
951
|
|
|
952
952
|
// samples the the given environment map in the given direction
|
|
953
953
|
vec3 sampleEquirectColor( sampler2D envMap, vec3 direction ) {
|
|
@@ -1014,7 +1014,7 @@ struct BVH {
|
|
|
1014
1014
|
return float( resolution.x * resolution.y ) * pdf * equirectDirectionPdf( direction );
|
|
1015
1015
|
|
|
1016
1016
|
}
|
|
1017
|
-
`,
|
|
1017
|
+
`,Ya=`
|
|
1018
1018
|
|
|
1019
1019
|
float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
|
|
1020
1020
|
|
|
@@ -1229,7 +1229,7 @@ struct BVH {
|
|
|
1229
1229
|
|
|
1230
1230
|
}
|
|
1231
1231
|
|
|
1232
|
-
`,
|
|
1232
|
+
`,Xa=`
|
|
1233
1233
|
|
|
1234
1234
|
vec3 sampleHemisphere( vec3 n, vec2 uv ) {
|
|
1235
1235
|
|
|
@@ -1314,7 +1314,7 @@ struct BVH {
|
|
|
1314
1314
|
}
|
|
1315
1315
|
|
|
1316
1316
|
|
|
1317
|
-
`,
|
|
1317
|
+
`,Za=`
|
|
1318
1318
|
|
|
1319
1319
|
bool totalInternalReflection( float cosTheta, float eta ) {
|
|
1320
1320
|
|
|
@@ -1417,7 +1417,7 @@ struct BVH {
|
|
|
1417
1417
|
|
|
1418
1418
|
}
|
|
1419
1419
|
|
|
1420
|
-
`,
|
|
1420
|
+
`,Qa=`
|
|
1421
1421
|
|
|
1422
1422
|
// Fast arccos approximation used to remove banding artifacts caused by numerical errors in acos.
|
|
1423
1423
|
// This is a cubic Lagrange interpolating polynomial for x = [-1, -1/2, 0, 1/2, 1].
|
|
@@ -1497,7 +1497,7 @@ struct BVH {
|
|
|
1497
1497
|
|
|
1498
1498
|
}
|
|
1499
1499
|
|
|
1500
|
-
|
|
1500
|
+
`,$a=`
|
|
1501
1501
|
|
|
1502
1502
|
// Finds the point where the ray intersects the plane defined by u and v and checks if this point
|
|
1503
1503
|
// falls in the bounds of the rectangle on that same plane.
|
|
@@ -1558,7 +1558,7 @@ struct BVH {
|
|
|
1558
1558
|
|
|
1559
1559
|
}
|
|
1560
1560
|
|
|
1561
|
-
`,
|
|
1561
|
+
`,eo=`
|
|
1562
1562
|
|
|
1563
1563
|
// add texel fetch functions for texture arrays
|
|
1564
1564
|
vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
|
|
@@ -1581,7 +1581,7 @@ struct BVH {
|
|
|
1581
1581
|
|
|
1582
1582
|
}
|
|
1583
1583
|
|
|
1584
|
-
`,
|
|
1584
|
+
`,to=`
|
|
1585
1585
|
|
|
1586
1586
|
// TODO: possibly this should be renamed something related to material or path tracing logic
|
|
1587
1587
|
|
|
@@ -1696,7 +1696,7 @@ struct BVH {
|
|
|
1696
1696
|
return x < 0.5 ? sqrt( 2.0 * x ) - 1.0 : 1.0 - sqrt( 2.0 - ( 2.0 * x ) );
|
|
1697
1697
|
|
|
1698
1698
|
}
|
|
1699
|
-
`,
|
|
1699
|
+
`,no=`
|
|
1700
1700
|
|
|
1701
1701
|
// https://www.shadertoy.com/view/wltcRS
|
|
1702
1702
|
uvec4 WHITE_NOISE_SEED;
|
|
@@ -1752,7 +1752,7 @@ struct BVH {
|
|
|
1752
1752
|
return vec4( WHITE_NOISE_SEED ) / float( 0xffffffffu );
|
|
1753
1753
|
|
|
1754
1754
|
}
|
|
1755
|
-
`,
|
|
1755
|
+
`,ro=`
|
|
1756
1756
|
|
|
1757
1757
|
uniform sampler2D stratifiedTexture;
|
|
1758
1758
|
uniform sampler2D stratifiedOffsetTexture;
|
|
@@ -1801,7 +1801,7 @@ struct BVH {
|
|
|
1801
1801
|
|
|
1802
1802
|
}
|
|
1803
1803
|
|
|
1804
|
-
`,
|
|
1804
|
+
`,io=`
|
|
1805
1805
|
|
|
1806
1806
|
// diffuse
|
|
1807
1807
|
float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
|
|
@@ -2025,7 +2025,6 @@ struct BVH {
|
|
|
2025
2025
|
// See equation (1) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
2026
2026
|
vec3 color = surf.sheenColor;
|
|
2027
2027
|
color *= D * G / ( 4.0 * abs( cosThetaO * cosThetaI ) );
|
|
2028
|
-
color *= wi.z;
|
|
2029
2028
|
|
|
2030
2029
|
return color;
|
|
2031
2030
|
|
|
@@ -2239,7 +2238,7 @@ struct BVH {
|
|
|
2239
2238
|
|
|
2240
2239
|
}
|
|
2241
2240
|
|
|
2242
|
-
`,
|
|
2241
|
+
`,ao=`
|
|
2243
2242
|
|
|
2244
2243
|
// returns the hit distance given the material density
|
|
2245
2244
|
float intersectFogVolume( Material material, float u ) {
|
|
@@ -2260,7 +2259,7 @@ struct BVH {
|
|
|
2260
2259
|
|
|
2261
2260
|
}
|
|
2262
2261
|
|
|
2263
|
-
`,
|
|
2262
|
+
`,oo=`
|
|
2264
2263
|
|
|
2265
2264
|
// The GGX functions provide sampling and distribution information for normals as output so
|
|
2266
2265
|
// in order to get probability of scatter direction the half vector must be computed and provided.
|
|
@@ -2361,7 +2360,7 @@ struct BVH {
|
|
|
2361
2360
|
|
|
2362
2361
|
}
|
|
2363
2362
|
|
|
2364
|
-
`,
|
|
2363
|
+
`,so=`
|
|
2365
2364
|
|
|
2366
2365
|
// XYZ to sRGB color space
|
|
2367
2366
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
@@ -2495,7 +2494,7 @@ struct BVH {
|
|
|
2495
2494
|
|
|
2496
2495
|
}
|
|
2497
2496
|
|
|
2498
|
-
`,
|
|
2497
|
+
`,co=`
|
|
2499
2498
|
|
|
2500
2499
|
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
2501
2500
|
float velvetD( float cosThetaH, float roughness ) {
|
|
@@ -2592,7 +2591,7 @@ struct BVH {
|
|
|
2592
2591
|
|
|
2593
2592
|
}
|
|
2594
2593
|
|
|
2595
|
-
`,
|
|
2594
|
+
`,lo=`
|
|
2596
2595
|
|
|
2597
2596
|
#ifndef FOG_CHECK_ITERATIONS
|
|
2598
2597
|
#define FOG_CHECK_ITERATIONS 30
|
|
@@ -2653,7 +2652,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2653
2652
|
|
|
2654
2653
|
}
|
|
2655
2654
|
|
|
2656
|
-
|
|
2655
|
+
`,uo=`
|
|
2657
2656
|
|
|
2658
2657
|
// step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
|
|
2659
2658
|
// returns true if a solid surface was hit
|
|
@@ -2831,7 +2830,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2831
2830
|
|
|
2832
2831
|
}
|
|
2833
2832
|
|
|
2834
|
-
`,
|
|
2833
|
+
`,fo=`
|
|
2835
2834
|
|
|
2836
2835
|
vec3 ndcToRayOrigin( vec2 coord ) {
|
|
2837
2836
|
|
|
@@ -2914,7 +2913,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2914
2913
|
|
|
2915
2914
|
}
|
|
2916
2915
|
|
|
2917
|
-
`,
|
|
2916
|
+
`,po=`
|
|
2918
2917
|
|
|
2919
2918
|
vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
|
|
2920
2919
|
|
|
@@ -3010,7 +3009,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3010
3009
|
|
|
3011
3010
|
}
|
|
3012
3011
|
|
|
3013
|
-
`,
|
|
3012
|
+
`,mo=`
|
|
3014
3013
|
|
|
3015
3014
|
#define SKIP_SURFACE 0
|
|
3016
3015
|
#define HIT_SURFACE 1
|
|
@@ -3333,7 +3332,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3333
3332
|
return HIT_SURFACE;
|
|
3334
3333
|
|
|
3335
3334
|
}
|
|
3336
|
-
`,
|
|
3335
|
+
`,ho=`
|
|
3337
3336
|
|
|
3338
3337
|
struct Ray {
|
|
3339
3338
|
|
|
@@ -3382,7 +3381,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3382
3381
|
|
|
3383
3382
|
}
|
|
3384
3383
|
|
|
3385
|
-
`,
|
|
3384
|
+
`,go=`
|
|
3386
3385
|
|
|
3387
3386
|
#define NO_HIT 0
|
|
3388
3387
|
#define SURFACE_HIT 1
|
|
@@ -3429,7 +3428,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3429
3428
|
|
|
3430
3429
|
}
|
|
3431
3430
|
|
|
3432
|
-
`,
|
|
3431
|
+
`,_o=class extends Ri{onBeforeRender(){this.setDefine(`FEATURE_DOF`,this.physicalCamera.bokehSize===0?0:1),this.setDefine(`FEATURE_BACKGROUND_MAP`,+!!this.backgroundMap),this.setDefine(`FEATURE_FOG`,+!!this.materials.features.isUsed(`FOG`))}constructor(e){super({transparent:!0,depthWrite:!1,defines:{FEATURE_MIS:1,FEATURE_RUSSIAN_ROULETTE:1,FEATURE_DOF:1,FEATURE_BACKGROUND_MAP:0,FEATURE_FOG:1,RANDOM_TYPE:2,CAMERA_TYPE:0,DEBUG_MODE:0,ATTR_NORMAL:0,ATTR_TANGENT:1,ATTR_UV:2,ATTR_COLOR:3,MATERIAL_PIXELS:47},uniforms:{resolution:{value:new E},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new Ji},cameraWorldMatrix:{value:new O},invProjectionMatrix:{value:new O},bvh:{value:new Yr},attributesArray:{value:new ga},materialIndexAttribute:{value:new qr},materials:{value:new Ta},textures:{value:new ka().texture},lights:{value:new pa},iesProfiles:{value:new ka(360,180,{type:Ye,wrapS:_,wrapT:_}).texture},environmentIntensity:{value:1},environmentRotation:{value:new O},envMapInfo:{value:new $i},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new O},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new Fa},stratifiedOffsetTexture:{value:new Ha(64,1)}},vertexShader:`
|
|
3433
3432
|
|
|
3434
3433
|
varying vec2 vUv;
|
|
3435
3434
|
void main() {
|
|
@@ -3453,27 +3452,27 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3453
3452
|
#include <common>
|
|
3454
3453
|
|
|
3455
3454
|
// bvh intersection
|
|
3456
|
-
${
|
|
3457
|
-
${
|
|
3458
|
-
${
|
|
3455
|
+
${Qr}
|
|
3456
|
+
${ei}
|
|
3457
|
+
${$r}
|
|
3459
3458
|
|
|
3460
3459
|
// uniform structs
|
|
3461
|
-
${
|
|
3462
|
-
${
|
|
3463
|
-
${
|
|
3464
|
-
${
|
|
3465
|
-
${
|
|
3460
|
+
${Ua}
|
|
3461
|
+
${Ga}
|
|
3462
|
+
${Wa}
|
|
3463
|
+
${Ka}
|
|
3464
|
+
${qa}
|
|
3466
3465
|
|
|
3467
3466
|
// random
|
|
3468
3467
|
#if RANDOM_TYPE == 2 // Stratified List
|
|
3469
3468
|
|
|
3470
|
-
${
|
|
3469
|
+
${ro}
|
|
3471
3470
|
|
|
3472
3471
|
#elif RANDOM_TYPE == 1 // Sobol
|
|
3473
3472
|
|
|
3474
|
-
${
|
|
3475
|
-
${
|
|
3476
|
-
${
|
|
3473
|
+
${no}
|
|
3474
|
+
${Hi}
|
|
3475
|
+
${Wi}
|
|
3477
3476
|
|
|
3478
3477
|
#define rand(v) sobol(v)
|
|
3479
3478
|
#define rand2(v) sobol2(v)
|
|
@@ -3482,7 +3481,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3482
3481
|
|
|
3483
3482
|
#else // PCG
|
|
3484
3483
|
|
|
3485
|
-
${
|
|
3484
|
+
${no}
|
|
3486
3485
|
|
|
3487
3486
|
// Using the sobol functions seems to break the the compiler on MacOS
|
|
3488
3487
|
// - specifically the "sobolReverseBits" function.
|
|
@@ -3498,11 +3497,11 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3498
3497
|
#endif
|
|
3499
3498
|
|
|
3500
3499
|
// common
|
|
3501
|
-
${
|
|
3502
|
-
${
|
|
3503
|
-
${
|
|
3504
|
-
${
|
|
3505
|
-
${
|
|
3500
|
+
${eo}
|
|
3501
|
+
${Za}
|
|
3502
|
+
${to}
|
|
3503
|
+
${Qa}
|
|
3504
|
+
${$a}
|
|
3506
3505
|
|
|
3507
3506
|
// environment
|
|
3508
3507
|
uniform EquirectHdrInfo envMapInfo;
|
|
@@ -3558,16 +3557,16 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3558
3557
|
float lightsDenom;
|
|
3559
3558
|
|
|
3560
3559
|
// sampling
|
|
3561
|
-
${za}
|
|
3562
|
-
${La}
|
|
3563
|
-
${Ra}
|
|
3564
|
-
|
|
3565
|
-
${Qa}
|
|
3566
|
-
${Ya}
|
|
3567
|
-
${Za}
|
|
3568
3560
|
${Xa}
|
|
3569
3561
|
${Ja}
|
|
3570
|
-
${
|
|
3562
|
+
${Ya}
|
|
3563
|
+
|
|
3564
|
+
${lo}
|
|
3565
|
+
${oo}
|
|
3566
|
+
${co}
|
|
3567
|
+
${so}
|
|
3568
|
+
${ao}
|
|
3569
|
+
${io}
|
|
3571
3570
|
|
|
3572
3571
|
float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
|
|
3573
3572
|
|
|
@@ -3599,12 +3598,12 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3599
3598
|
|
|
3600
3599
|
}
|
|
3601
3600
|
|
|
3602
|
-
${
|
|
3603
|
-
${
|
|
3604
|
-
${
|
|
3605
|
-
${
|
|
3606
|
-
${
|
|
3607
|
-
${
|
|
3601
|
+
${ho}
|
|
3602
|
+
${fo}
|
|
3603
|
+
${go}
|
|
3604
|
+
${uo}
|
|
3605
|
+
${po}
|
|
3606
|
+
${mo}
|
|
3608
3607
|
|
|
3609
3608
|
void main() {
|
|
3610
3609
|
|
|
@@ -3896,7 +3895,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3896
3895
|
|
|
3897
3896
|
}
|
|
3898
3897
|
|
|
3899
|
-
`}),this.setValues(e)}};function*
|
|
3898
|
+
`}),this.setValues(e)}};function*vo(){let{_renderer:e,_fsQuad:t,_blendQuad:n,_primaryTarget:r,_blendTargets:i,_sobolTarget:a,_subframe:o,alpha:s,material:c}=this,l=new S,u=new S,d=n.material,[f,p]=i;for(;;){s?(d.opacity=this._opacityFactor/(this.samples+1),c.blending=0,c.opacity=1):(c.opacity=this._opacityFactor/(this.samples+1),c.blending=1);let[i,m,h,g]=o,_=r.width,v=r.height;c.resolution.set(_*h,v*g),c.sobolTexture=a.texture,c.stratifiedTexture.init(20,c.bounces+c.transmissiveBounces+5),c.stratifiedTexture.next(),c.seed++;let y=this.tiles.x||1,b=this.tiles.y||1,x=y*b,S=Math.ceil(_*h),C=Math.ceil(v*g),ee=Math.floor(i*_),w=Math.floor(m*v),te=Math.ceil(S/y),ne=Math.ceil(C/b);for(let i=0;i<b;i++)for(let a=0;a<y;a++){let o=e.getRenderTarget(),c=e.autoClear,m=e.getScissorTest();e.getScissor(l),e.getViewport(u);let h=a,g=i;if(!this.stableTiles){let e=this._currentTile%(y*b);h=e%y,g=~~(e/y),this._currentTile=e+1}let _=b-g-1;r.scissor.set(ee+h*te,w+_*ne,Math.min(te,S-h*te),Math.min(ne,C-_*ne)),r.viewport.set(ee,w,S,C),e.setRenderTarget(r),e.setScissorTest(!0),e.autoClear=!1,t.render(e),e.setViewport(u),e.setScissor(l),e.setScissorTest(m),e.setRenderTarget(o),e.autoClear=c,s&&(d.target1=f.texture,d.target2=r.texture,e.setRenderTarget(p),n.render(e),e.setRenderTarget(o)),this.samples+=1/x,a===y-1&&i===b-1&&(this.samples=Math.round(this.samples)),yield}[f,p]=[p,f]}}var yo=new t,bo=class{get material(){return this._fsQuad.material}set material(e){this._fsQuad.material.removeEventListener(`recompilation`,this._compileFunction),e.addEventListener(`recompilation`,this._compileFunction),this._fsQuad.material=e}get target(){return this._alpha?this._blendTargets[1]:this._primaryTarget}set alpha(e){this._alpha!==e&&(e||(this._blendTargets[0].dispose(),this._blendTargets[1].dispose()),this._alpha=e,this.reset())}get alpha(){return this._alpha}get isCompiling(){return!!this._compilePromise}constructor(e){this.camera=null,this.tiles=new E(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new S(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new He(new _o),this._blendQuad=new He(new zi),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Ki().generate(e),this._primaryTarget=new Ge(1,1,{format:D,type:d,magFilter:T,minFilter:T}),this._blendTargets=[new Ge(1,1,{format:D,type:d,magFilter:T,minFilter:T}),new Ge(1,1,{format:D,type:d,magFilter:T,minFilter:T})],this._compileFunction=()=>{let e=this.compileMaterial(this._fsQuad._mesh);e.then(()=>{this._compilePromise===e&&(this._compilePromise=null)}),this._compilePromise=e},this.material.addEventListener(`recompilation`,this._compileFunction)}compileMaterial(){return this._renderer.compileAsync(this._fsQuad._mesh)}setCamera(e){let{material:t}=this;t.cameraWorldMatrix.copy(e.matrixWorld),t.invProjectionMatrix.copy(e.projectionMatrixInverse),t.physicalCamera.updateFrom(e);let n=0;e.projectionMatrix.elements[15]>0&&(n=1),e.isEquirectCamera&&(n=2),t.setDefine(`CAMERA_TYPE`,n),this.camera=e}setSize(e,t){e=Math.ceil(e),t=Math.ceil(t),(this._primaryTarget.width!==e||this._primaryTarget.height!==t)&&(this._primaryTarget.setSize(e,t),this._blendTargets[0].setSize(e,t),this._blendTargets[1].setSize(e,t),this.reset())}getSize(e){e.x=this._primaryTarget.width,e.y=this._primaryTarget.height}dispose(){this._primaryTarget.dispose(),this._blendTargets[0].dispose(),this._blendTargets[1].dispose(),this._sobolTarget.dispose(),this._fsQuad.dispose(),this._blendQuad.dispose(),this._task=null}reset(){let{_renderer:e,_primaryTarget:t,_blendTargets:n}=this,r=e.getRenderTarget(),i=e.getClearAlpha();e.getClearColor(yo),e.setRenderTarget(t),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[0]),e.setClearColor(0,0),e.clearColor(),e.setRenderTarget(n[1]),e.setClearColor(0,0),e.clearColor(),e.setClearColor(yo,i),e.setRenderTarget(r),this.samples=0,this._task=null,this.material.stratifiedTexture.stableNoise=this.stableNoise,this.stableNoise&&(this.material.seed=0,this.material.stratifiedTexture.reset())}update(){this.material.onBeforeRender(),!this.isCompiling&&(this._task||=vo.call(this),this._task.next())}},xo=new E,So=new E,Co=new Oe,wo=new t,To=class extends h{constructor(e=512,t=512){super(new Uint16Array(e*t*4),e,t,D,Ye,303,Ee,_,w,w),this.generationCallback=null}update(){this.dispose(),this.needsUpdate=!0;let{data:e,width:t,height:n}=this.image;for(let r=0;r<t;r++)for(let i=0;i<n;i++){So.set(t,n),xo.set(r/t,i/n),xo.x-=.5,xo.y=1-xo.y,Co.theta=xo.x*2*Math.PI,Co.phi=xo.y*Math.PI,Co.radius=1,this.generationCallback(Co,xo,So,wo);let a=4*(i*t+r);e[a+0]=v.toHalfFloat(wo.r),e[a+1]=v.toHalfFloat(wo.g),e[a+2]=v.toHalfFloat(wo.b),e[a+3]=v.toHalfFloat(1)}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}},Eo=new k,Do=class extends To{constructor(e=512){super(e,e),this.topColor=new t().set(16777215),this.bottomColor=new t().set(0),this.exponent=2,this.generationCallback=(e,t,n,r)=>{Eo.setFromSpherical(e);let i=Eo.y*.5+.5;r.lerpColors(this.bottomColor,this.topColor,i**this.exponent)}}copy(e){return super.copy(e),this.topColor.copy(e.topColor),this.bottomColor.copy(e.bottomColor),this}},Oo=class extends pe{get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}constructor(e){super({uniforms:{map:{value:null},opacity:{value:1}},vertexShader:`
|
|
3900
3899
|
varying vec2 vUv;
|
|
3901
3900
|
void main() {
|
|
3902
3901
|
|
|
@@ -3953,7 +3952,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3953
3952
|
#include <premultiplied_alpha_fragment>
|
|
3954
3953
|
|
|
3955
3954
|
}
|
|
3956
|
-
`}),this.setValues(e)}},
|
|
3955
|
+
`}),this.setValues(e)}},ko=class extends pe{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
|
|
3957
3956
|
varying vec2 vUv;
|
|
3958
3957
|
void main() {
|
|
3959
3958
|
|
|
@@ -3970,7 +3969,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3970
3969
|
#include <common>
|
|
3971
3970
|
#include <cube_uv_reflection_fragment>
|
|
3972
3971
|
|
|
3973
|
-
${
|
|
3972
|
+
${to}
|
|
3974
3973
|
|
|
3975
3974
|
void main() {
|
|
3976
3975
|
|
|
@@ -3978,11 +3977,124 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3978
3977
|
rayDirection.x *= flipEnvMap;
|
|
3979
3978
|
gl_FragColor = textureCube( envMap, rayDirection );
|
|
3980
3979
|
|
|
3981
|
-
}`}),this.depthWrite=!1,this.depthTest=!1}},
|
|
3982
|
-
`))&&a<t&&r<e.byteLength;)o+=s,a+=s.length,r+=128,s=String.fromCharCode.apply(null,new Uint16Array(e.subarray(r,r+128)));return-1<i&&(!1!==n&&(e.pos+=a+i+1),o+s.slice(0,i))},
|
|
3980
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}},Ao=class{constructor(e){this._renderer=e,this._quad=new He(new ko)}generate(e,t=null,n=null){if(!e.isCubeTexture)throw Error(`CubeToEquirectMaterial: Source can only be cube textures.`);let r=e.images[0],i=this._renderer,a=this._quad;t===null&&(t=4*r.height),n===null&&(n=2*r.height);let o=new Ge(t,n,{type:d,colorSpace:r.colorSpace}),s=r.height,c=Math.log2(s)-2,l=1/s,u=1/(3*Math.max(2**c,112));a.material.defines.CUBEUV_MAX_MIP=`${c}.0`,a.material.defines.CUBEUV_TEXEL_WIDTH=u,a.material.defines.CUBEUV_TEXEL_HEIGHT=l,a.material.uniforms.envMap.value=e,a.material.uniforms.flipEnvMap.value=e.isRenderTargetTexture?1:-1,a.material.needsUpdate=!0;let f=i.getRenderTarget(),p=i.autoClear;i.autoClear=!0,i.setRenderTarget(o),a.render(i),i.setRenderTarget(f),i.autoClear=p;let m=new Uint16Array(t*n*4),g=new Float32Array(t*n*4);i.readRenderTargetPixels(o,0,0,t,n,g),o.dispose();for(let e=0,t=g.length;e<t;e++)m[e]=v.toHalfFloat(g[e]);let _=new h(m,t,n,D,Ye);return _.minFilter=ne,_.magFilter=w,_.wrapS=Ee,_.wrapT=Ee,_.mapping=303,_.needsUpdate=!0,_}dispose(){this._quad.dispose()}};function jo(e){return e.extensions.get(`EXT_float_blend`)}var Mo=new E,No=class{get multipleImportanceSampling(){return!!this._pathTracer.material.defines.FEATURE_MIS}set multipleImportanceSampling(e){this._pathTracer.material.setDefine(`FEATURE_MIS`,+!!e)}get transmissiveBounces(){return this._pathTracer.material.transmissiveBounces}set transmissiveBounces(e){this._pathTracer.material.transmissiveBounces=e}get bounces(){return this._pathTracer.material.bounces}set bounces(e){this._pathTracer.material.bounces=e}get filterGlossyFactor(){return this._pathTracer.material.filterGlossyFactor}set filterGlossyFactor(e){this._pathTracer.material.filterGlossyFactor=e}get samples(){return this._pathTracer.samples}get target(){return this._pathTracer.target}get tiles(){return this._pathTracer.tiles}get stableNoise(){return this._pathTracer.stableNoise}set stableNoise(e){this._pathTracer.stableNoise=e}get isCompiling(){return!!this._pathTracer.isCompiling}constructor(e){console.warn(`WebGLPathTracer: This class has been deprecated and will be removed in a future release. Use "WebGPUPathTracer" instead.`),this._renderer=e,this._generator=new Li,this._pathTracer=new bo(e),this._queueReset=!1,this._clock=new we,this._compilePromise=null,this._lowResPathTracer=new bo(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new He(new Oo({map:null,transparent:!0,blending:0,premultipliedAlpha:e.getContextAttributes().premultipliedAlpha})),this._materials=null,this._previousEnvironment=null,this._previousBackground=null,this._internalBackground=null,this.renderDelay=100,this.minSamples=5,this.fadeDuration=500,this.enablePathTracing=!0,this.pausePathTracing=!1,this.dynamicLowRes=!1,this.lowResScale=.25,this.renderScale=1,this.synchronizeRenderSize=!0,this.rasterizeScene=!0,this.renderToCanvas=!0,this.textureSize=new E(1024,1024),this.rasterizeSceneCallback=(e,t)=>{this._renderer.render(e,t)},this.renderToCanvasCallback=(e,t,n)=>{let r=t.autoClear;t.autoClear=!1,n.render(t),t.autoClear=r},this.setScene(new Ve,new y)}setBVHWorker(e){this._generator.setBVHWorker(e)}setScene(e,t,n={}){e.updateMatrixWorld(!0),t.updateMatrixWorld();let r=this._generator;if(r.setObjects(e),this._buildAsync)return r.generateAsync(n.onProgress).then(n=>this._updateFromResults(e,t,n));{let n=r.generate();return this._updateFromResults(e,t,n)}}setSceneAsync(...e){this._buildAsync=!0;let t=this.setScene(...e);return this._buildAsync=!1,t}setCamera(e){this.camera=e,this.updateCamera()}updateCamera(){let e=this.camera;e.updateMatrixWorld(),this._pathTracer.setCamera(e),this._lowResPathTracer.setCamera(e),this.reset()}updateMaterials(){let e=this._pathTracer.material,t=this._renderer,n=this._materials,r=this.textureSize,i=xa(n);e.textures.setTextures(t,i,r.x,r.y),e.materials.updateFrom(n,i),this.reset()}updateLights(){let e=this.scene,t=this._renderer,n=this._pathTracer.material,r=Sa(e),i=ba(r);n.lights.updateFrom(r,i),n.iesProfiles.setTextures(t,i),this.reset()}updateEnvironment(){let e=this.scene,t=this._pathTracer.material;if(this._internalBackground&&=(this._internalBackground.dispose(),null),t.backgroundBlur=e.backgroundBlurriness,t.backgroundIntensity=e.backgroundIntensity??1,t.backgroundRotation.makeRotationFromEuler(e.backgroundRotation).invert(),e.background===null)t.backgroundMap=null,t.backgroundAlpha=0;else if(e.background.isColor){this._colorBackground=this._colorBackground||new Do(16);let n=this._colorBackground;n.topColor.equals(e.background)||(n.topColor.set(e.background),n.bottomColor.set(e.background),n.update()),t.backgroundMap=n,t.backgroundAlpha=1}else if(e.background.isCubeTexture){if(e.background!==this._previousBackground){let n=new Ao(this._renderer).generate(e.background);this._internalBackground=n,t.backgroundMap=n,t.backgroundAlpha=1}}else t.backgroundMap=e.background,t.backgroundAlpha=1;if(t.environmentIntensity=e.environment===null?0:e.environmentIntensity??1,t.environmentRotation.makeRotationFromEuler(e.environmentRotation).invert(),this._previousEnvironment!==e.environment&&e.environment!==null){if(e.environment.isCubeTexture){let n=new Ao(this._renderer).generate(e.environment);t.envMapInfo.updateFrom(n)}else t.envMapInfo.updateFrom(e.environment)}this._previousEnvironment=e.environment,this._previousBackground=e.background,this.reset()}_updateFromResults(e,t,n){let{materials:r,geometry:i,bvh:a,bvhChanged:o,needsMaterialIndexUpdate:s}=n;this._materials=r;let c=this._pathTracer.material;return o&&(c.bvh.updateFrom(a),c.attributesArray.updateFrom(i.attributes.normal,i.attributes.tangent,i.attributes.uv,i.attributes.color)),s&&c.materialIndexAttribute.updateFrom(i.attributes.materialIndex),this._previousScene=e,this.scene=e,this.camera=t,this.updateCamera(),this.updateMaterials(),this.updateEnvironment(),this.updateLights(),n}renderSample(){let e=this._lowResPathTracer,t=this._pathTracer,n=this._renderer,r=this._clock,i=this._quad;this._updateScale(),this._queueReset&&(t.reset(),e.reset(),this._queueReset=!1,i.material.opacity=0,r.start());let a=r.getDelta()*1e3,o=r.getElapsedTime()*1e3;if(!this.pausePathTracing&&this.enablePathTracing&&this.renderDelay<=o&&!this.isCompiling&&t.update(),t.alpha=t.material.backgroundAlpha!==1||!jo(n),e.alpha=t.alpha,this.renderToCanvas){let n=this._renderer,r=this.minSamples;if(o>=this.renderDelay&&this.samples>=this.minSamples&&(this.fadeDuration===0?i.material.opacity=1:i.material.opacity=Math.min(i.material.opacity+a/this.fadeDuration,1)),!this.enablePathTracing||this.samples<r||i.material.opacity<1){if(this.dynamicLowRes&&!this.isCompiling){e.samples<1&&(e.material=t.material,e.update());let r=i.material.opacity;i.material.opacity=1-i.material.opacity,i.material.map=e.target.texture,i.render(n),i.material.opacity=r}(!this.dynamicLowRes&&this.rasterizeScene||this.dynamicLowRes&&this.isCompiling)&&this.rasterizeSceneCallback(this.scene,this.camera)}this.enablePathTracing&&i.material.opacity>0&&(i.material.opacity<1&&(i.material.blending=this.dynamicLowRes?2:1),i.material.map=t.target.texture,this.renderToCanvasCallback(t.target,n,i),i.material.blending=0)}}reset(){this._queueReset=!0,this._pathTracer.samples=0}dispose(){this._quad.dispose(),this._quad.material.dispose(),this._pathTracer.dispose()}_updateScale(){if(this.synchronizeRenderSize){this._renderer.getDrawingBufferSize(Mo);let e=Math.floor(this.renderScale*Mo.x),t=Math.floor(this.renderScale*Mo.y);if(this._pathTracer.getSize(Mo),Mo.x!==e||Mo.y!==t){let n=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*n),Math.floor(t*n))}}}getRenderTime(){return this._clock.getElapsedTime()*1e3}},Po=class extends g{constructor(e){super(e),this.type=Ye}parse(e){let t=function(e,t){switch(e){case 1:throw Error(`THREE.HDRLoader: Read Error: `+(t||``));case 2:throw Error(`THREE.HDRLoader: Write Error: `+(t||``));case 3:throw Error(`THREE.HDRLoader: Bad File Format: `+(t||``));default:case 4:throw Error(`THREE.HDRLoader: Memory Error: `+(t||``))}},n=function(e,t,n){t||=1024;let r=e.pos,i=-1,a=0,o=``,s=String.fromCharCode.apply(null,new Uint16Array(e.subarray(r,r+128)));for(;0>(i=s.indexOf(`
|
|
3981
|
+
`))&&a<t&&r<e.byteLength;)o+=s,a+=s.length,r+=128,s=String.fromCharCode.apply(null,new Uint16Array(e.subarray(r,r+128)));return-1<i&&(!1!==n&&(e.pos+=a+i+1),o+s.slice(0,i))},r=function(e){let r=/^#\?(\S+)/,i=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,a=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,o=/^\s*FORMAT=(\S+)\s*$/,s=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,c={valid:0,string:``,comments:``,programtype:`RGBE`,format:``,gamma:1,exposure:1,width:0,height:0},l,u;for((e.pos>=e.byteLength||!(l=n(e)))&&t(1,`no header found`),(u=l.match(r))||t(3,`bad initial token`),c.valid|=1,c.programtype=u[1],c.string+=l+`
|
|
3983
3982
|
`;l=n(e),!1!==l;){if(c.string+=l+`
|
|
3984
3983
|
`,l.charAt(0)===`#`){c.comments+=l+`
|
|
3985
|
-
`;continue}if((u=l.match(i))&&(c.gamma=parseFloat(u[1])),(u=l.match(a))&&(c.exposure=parseFloat(u[1])),(u=l.match(o))&&(c.valid|=2,c.format=u[1]),(u=l.match(s))&&(c.valid|=4,c.height=parseInt(u[1],10),c.width=parseInt(u[2],10)),c.valid&2&&c.valid&4)break}return c.valid&2||t(3,`missing format specifier`),c.valid&4||t(3,`missing image size specifier`),c},
|
|
3984
|
+
`;continue}if((u=l.match(i))&&(c.gamma=parseFloat(u[1])),(u=l.match(a))&&(c.exposure=parseFloat(u[1])),(u=l.match(o))&&(c.valid|=2,c.format=u[1]),(u=l.match(s))&&(c.valid|=4,c.height=parseInt(u[1],10),c.width=parseInt(u[2],10)),c.valid&2&&c.valid&4)break}return c.valid&2||t(3,`missing format specifier`),c.valid&4||t(3,`missing image size specifier`),c},i=function(e,n,r){let i=n;if(i<8||i>32767||e[0]!==2||e[1]!==2||e[2]&128)return new Uint8Array(e);i!==(e[2]<<8|e[3])&&t(3,`wrong scanline width`);let a=new Uint8Array(4*n*r);a.length||t(4,`unable to allocate buffer space`);let o=0,s=0,c=4*i,l=new Uint8Array(4),u=new Uint8Array(c),d=r;for(;d>0&&s<e.byteLength;){s+4>e.byteLength&&t(1),l[0]=e[s++],l[1]=e[s++],l[2]=e[s++],l[3]=e[s++],(l[0]!=2||l[1]!=2||(l[2]<<8|l[3])!=i)&&t(3,`bad rgbe scanline format`);let n=0,r;for(;n<c&&s<e.byteLength;){r=e[s++];let i=r>128;if(i&&(r-=128),(r===0||n+r>c)&&t(3,`bad scanline data`),i){let t=e[s++];for(let e=0;e<r;e++)u[n++]=t}else u.set(e.subarray(s,s+r),n),n+=r,s+=r}let f=i;for(let e=0;e<f;e++){let t=0;a[o]=u[e+t],t+=i,a[o+1]=u[e+t],t+=i,a[o+2]=u[e+t],t+=i,a[o+3]=u[e+t],o+=4}d--}return a},a=function(e,t,n,r){let i=2**(e[t+3]-128)/255;n[r+0]=e[t+0]*i,n[r+1]=e[t+1]*i,n[r+2]=e[t+2]*i,n[r+3]=1},o=function(e,t,n,r){let i=2**(e[t+3]-128)/255;n[r+0]=v.toHalfFloat(Math.min(e[t+0]*i,65504)),n[r+1]=v.toHalfFloat(Math.min(e[t+1]*i,65504)),n[r+2]=v.toHalfFloat(Math.min(e[t+2]*i,65504)),n[r+3]=v.toHalfFloat(1)},s=new Uint8Array(e);s.pos=0;let c=r(s),u=c.width,f=c.height,p=i(s.subarray(s.pos),u,f),m,h,g;switch(this.type){case d:g=p.length/4;let e=new Float32Array(g*4);for(let t=0;t<g;t++)a(p,t*4,e,t*4);m=e,h=d;break;case Ye:g=p.length/4;let t=new Uint16Array(g*4);for(let e=0;e<g;e++)o(p,e*4,t,e*4);m=t,h=Ye;break;default:throw Error(`THREE.HDRLoader: Unsupported type: `+this.type)}return{width:u,height:f,data:m,header:c.string,gamma:c.gamma,exposure:c.exposure,type:h,colorSpace:l,minFilter:w,magFilter:w,generateMipmaps:!1,flipY:!0}}setDataType(e){return this.type=e,this}},Fo={name:`LuminosityHighPassShader`,uniforms:{tDiffuse:{value:null},luminosityThreshold:{value:1},smoothWidth:{value:1},defaultColor:{value:new t(0)},defaultOpacity:{value:0}},vertexShader:`
|
|
3985
|
+
|
|
3986
|
+
varying vec2 vUv;
|
|
3987
|
+
|
|
3988
|
+
void main() {
|
|
3989
|
+
|
|
3990
|
+
vUv = uv;
|
|
3991
|
+
|
|
3992
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
3993
|
+
|
|
3994
|
+
}`,fragmentShader:`
|
|
3995
|
+
|
|
3996
|
+
uniform sampler2D tDiffuse;
|
|
3997
|
+
uniform vec3 defaultColor;
|
|
3998
|
+
uniform float defaultOpacity;
|
|
3999
|
+
uniform float luminosityThreshold;
|
|
4000
|
+
uniform float smoothWidth;
|
|
4001
|
+
|
|
4002
|
+
varying vec2 vUv;
|
|
4003
|
+
|
|
4004
|
+
void main() {
|
|
4005
|
+
|
|
4006
|
+
vec4 texel = texture2D( tDiffuse, vUv );
|
|
4007
|
+
|
|
4008
|
+
float v = luminance( texel.xyz );
|
|
4009
|
+
|
|
4010
|
+
vec4 outputColor = vec4( defaultColor.rgb, defaultOpacity );
|
|
4011
|
+
|
|
4012
|
+
float alpha = smoothstep( luminosityThreshold, luminosityThreshold + smoothWidth, v );
|
|
4013
|
+
|
|
4014
|
+
gl_FragColor = mix( outputColor, texel, alpha );
|
|
4015
|
+
|
|
4016
|
+
}`},Io=class e extends qe{constructor(e,n=1,r,i){super(),this.strength=n,this.radius=r,this.threshold=i,this.resolution=e===void 0?new E(256,256):new E(e.x,e.y),this.clearColor=new t(0,0,0),this.needsSwap=!1,this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.nMips=5;let a=Math.round(this.resolution.x/2),o=Math.round(this.resolution.y/2);this.renderTargetBright=new Ge(a,o,{type:Ye,depthBuffer:!1}),this.renderTargetBright.texture.name=`UnrealBloomPass.bright`,this.renderTargetBright.texture.generateMipmaps=!1;for(let e=0;e<this.nMips;e++){let t=new Ge(a,o,{type:Ye,depthBuffer:!1});t.texture.name=`UnrealBloomPass.h`+e,t.texture.generateMipmaps=!1,this.renderTargetsHorizontal.push(t);let n=new Ge(a,o,{type:Ye,depthBuffer:!1});n.texture.name=`UnrealBloomPass.v`+e,n.texture.generateMipmaps=!1,this.renderTargetsVertical.push(n),a=Math.round(a/2),o=Math.round(o/2)}let s=Fo;this.highPassUniforms=ve.clone(s.uniforms),this.highPassUniforms.luminosityThreshold.value=i,this.highPassUniforms.smoothWidth.value=.01,this.materialHighPassFilter=new pe({uniforms:this.highPassUniforms,vertexShader:s.vertexShader,fragmentShader:s.fragmentShader}),this.separableBlurMaterials=[];let c=[6,10,14,18,22];a=Math.round(this.resolution.x/2),o=Math.round(this.resolution.y/2);for(let e=0;e<this.nMips;e++)this.separableBlurMaterials.push(this._getSeparableBlurMaterial(c[e])),this.separableBlurMaterials[e].uniforms.invSize.value=new E(1/a,1/o),a=Math.round(a/2),o=Math.round(o/2);this.compositeMaterial=this._getCompositeMaterial(this.nMips),this.compositeMaterial.uniforms.blurTexture1.value=this.renderTargetsVertical[0].texture,this.compositeMaterial.uniforms.blurTexture2.value=this.renderTargetsVertical[1].texture,this.compositeMaterial.uniforms.blurTexture3.value=this.renderTargetsVertical[2].texture,this.compositeMaterial.uniforms.blurTexture4.value=this.renderTargetsVertical[3].texture,this.compositeMaterial.uniforms.blurTexture5.value=this.renderTargetsVertical[4].texture,this.compositeMaterial.uniforms.bloomStrength.value=n,this.compositeMaterial.uniforms.bloomRadius.value=.1;let l=[1,.8,.6,.4,.2];this.compositeMaterial.uniforms.bloomFactors.value=l,this.bloomTintColors=[new k(1,1,1),new k(1,1,1),new k(1,1,1),new k(1,1,1),new k(1,1,1)],this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,this.copyUniforms=ve.clone(De.uniforms),this.blendMaterial=new pe({uniforms:this.copyUniforms,vertexShader:De.vertexShader,fragmentShader:De.fragmentShader,premultipliedAlpha:!0,blending:2,depthTest:!1,depthWrite:!1,transparent:!0}),this._oldClearColor=new t,this._oldClearAlpha=1,this._basic=new ie,this._fsQuad=new He(null)}dispose(){for(let e=0;e<this.renderTargetsHorizontal.length;e++)this.renderTargetsHorizontal[e].dispose();for(let e=0;e<this.renderTargetsVertical.length;e++)this.renderTargetsVertical[e].dispose();this.renderTargetBright.dispose();for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].dispose();this.compositeMaterial.dispose(),this.blendMaterial.dispose(),this._basic.dispose(),this._fsQuad.dispose()}setSize(e,t){let n=Math.round(e/2),r=Math.round(t/2);this.renderTargetBright.setSize(n,r);for(let e=0;e<this.nMips;e++)this.renderTargetsHorizontal[e].setSize(n,r),this.renderTargetsVertical[e].setSize(n,r),this.separableBlurMaterials[e].uniforms.invSize.value=new E(1/n,1/r),n=Math.round(n/2),r=Math.round(r/2)}render(t,n,r,i,a){t.getClearColor(this._oldClearColor),this._oldClearAlpha=t.getClearAlpha();let o=t.autoClear;t.autoClear=!1,t.setClearColor(this.clearColor,0),a&&t.state.buffers.stencil.setTest(!1),this.renderToScreen&&(this._fsQuad.material=this._basic,this._basic.map=r.texture,t.setRenderTarget(null),t.clear(),this._fsQuad.render(t)),this.highPassUniforms.tDiffuse.value=r.texture,this.highPassUniforms.luminosityThreshold.value=this.threshold,this._fsQuad.material=this.materialHighPassFilter,t.setRenderTarget(this.renderTargetBright),t.clear(),this._fsQuad.render(t);let s=this.renderTargetBright;for(let n=0;n<this.nMips;n++)this._fsQuad.material=this.separableBlurMaterials[n],this.separableBlurMaterials[n].uniforms.colorTexture.value=s.texture,this.separableBlurMaterials[n].uniforms.direction.value=e.BlurDirectionX,t.setRenderTarget(this.renderTargetsHorizontal[n]),t.clear(),this._fsQuad.render(t),this.separableBlurMaterials[n].uniforms.colorTexture.value=this.renderTargetsHorizontal[n].texture,this.separableBlurMaterials[n].uniforms.direction.value=e.BlurDirectionY,t.setRenderTarget(this.renderTargetsVertical[n]),t.clear(),this._fsQuad.render(t),s=this.renderTargetsVertical[n];this._fsQuad.material=this.compositeMaterial,this.compositeMaterial.uniforms.bloomStrength.value=this.strength,this.compositeMaterial.uniforms.bloomRadius.value=this.radius,this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,t.setRenderTarget(this.renderTargetsHorizontal[0]),t.clear(),this._fsQuad.render(t),this._fsQuad.material=this.blendMaterial,this.copyUniforms.tDiffuse.value=this.renderTargetsHorizontal[0].texture,a&&t.state.buffers.stencil.setTest(!0),this.renderToScreen?(t.setRenderTarget(null),this._fsQuad.render(t)):(t.setRenderTarget(r),this._fsQuad.render(t)),t.setClearColor(this._oldClearColor,this._oldClearAlpha),t.autoClear=o}_getSeparableBlurMaterial(e){let t=[],n=e/3;for(let r=0;r<e;r++)t.push(.39894*Math.exp(-.5*r*r/(n*n))/n);let r=[],i=[];for(let n=1;n<e;n+=2){let a=t[n],o=n+1<e?t[n+1]:0,s=a+o;r.push((n*a+(n+1)*o)/s),i.push(s)}return new pe({defines:{KERNEL_PAIRS:r.length},uniforms:{colorTexture:{value:null},invSize:{value:new E(.5,.5)},direction:{value:new E(.5,.5)},centerWeight:{value:t[0]},gaussianOffsets:{value:r},gaussianWeights:{value:i}},vertexShader:`
|
|
4017
|
+
|
|
4018
|
+
varying vec2 vUv;
|
|
4019
|
+
|
|
4020
|
+
void main() {
|
|
4021
|
+
|
|
4022
|
+
vUv = uv;
|
|
4023
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
4024
|
+
|
|
4025
|
+
}`,fragmentShader:`
|
|
4026
|
+
|
|
4027
|
+
#include <common>
|
|
4028
|
+
|
|
4029
|
+
varying vec2 vUv;
|
|
4030
|
+
|
|
4031
|
+
uniform sampler2D colorTexture;
|
|
4032
|
+
uniform vec2 invSize;
|
|
4033
|
+
uniform vec2 direction;
|
|
4034
|
+
uniform float centerWeight;
|
|
4035
|
+
uniform float gaussianOffsets[KERNEL_PAIRS];
|
|
4036
|
+
uniform float gaussianWeights[KERNEL_PAIRS];
|
|
4037
|
+
|
|
4038
|
+
void main() {
|
|
4039
|
+
|
|
4040
|
+
vec3 diffuseSum = texture2D( colorTexture, vUv ).rgb * centerWeight;
|
|
4041
|
+
|
|
4042
|
+
for ( int i = 0; i < KERNEL_PAIRS; i ++ ) {
|
|
4043
|
+
|
|
4044
|
+
vec2 uvOffset = direction * invSize * gaussianOffsets[ i ];
|
|
4045
|
+
vec3 sample1 = texture2D( colorTexture, vUv + uvOffset ).rgb;
|
|
4046
|
+
vec3 sample2 = texture2D( colorTexture, vUv - uvOffset ).rgb;
|
|
4047
|
+
diffuseSum += ( sample1 + sample2 ) * gaussianWeights[ i ];
|
|
4048
|
+
|
|
4049
|
+
}
|
|
4050
|
+
|
|
4051
|
+
gl_FragColor = vec4( diffuseSum, 1.0 );
|
|
4052
|
+
|
|
4053
|
+
}`})}_getCompositeMaterial(e){return new pe({defines:{NUM_MIPS:e},uniforms:{blurTexture1:{value:null},blurTexture2:{value:null},blurTexture3:{value:null},blurTexture4:{value:null},blurTexture5:{value:null},bloomStrength:{value:1},bloomFactors:{value:null},bloomTintColors:{value:null},bloomRadius:{value:0}},vertexShader:`
|
|
4054
|
+
|
|
4055
|
+
varying vec2 vUv;
|
|
4056
|
+
|
|
4057
|
+
void main() {
|
|
4058
|
+
|
|
4059
|
+
vUv = uv;
|
|
4060
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
4061
|
+
|
|
4062
|
+
}`,fragmentShader:`
|
|
4063
|
+
|
|
4064
|
+
varying vec2 vUv;
|
|
4065
|
+
|
|
4066
|
+
uniform sampler2D blurTexture1;
|
|
4067
|
+
uniform sampler2D blurTexture2;
|
|
4068
|
+
uniform sampler2D blurTexture3;
|
|
4069
|
+
uniform sampler2D blurTexture4;
|
|
4070
|
+
uniform sampler2D blurTexture5;
|
|
4071
|
+
uniform float bloomStrength;
|
|
4072
|
+
uniform float bloomRadius;
|
|
4073
|
+
uniform float bloomFactors[NUM_MIPS];
|
|
4074
|
+
uniform vec3 bloomTintColors[NUM_MIPS];
|
|
4075
|
+
|
|
4076
|
+
float lerpBloomFactor( const in float factor ) {
|
|
4077
|
+
|
|
4078
|
+
float mirrorFactor = 1.2 - factor;
|
|
4079
|
+
return mix( factor, mirrorFactor, bloomRadius );
|
|
4080
|
+
|
|
4081
|
+
}
|
|
4082
|
+
|
|
4083
|
+
void main() {
|
|
4084
|
+
|
|
4085
|
+
// 3.0 for backwards compatibility with previous alpha-based intensity
|
|
4086
|
+
vec3 bloom = 3.0 * bloomStrength * (
|
|
4087
|
+
lerpBloomFactor( bloomFactors[ 0 ] ) * bloomTintColors[ 0 ] * texture2D( blurTexture1, vUv ).rgb +
|
|
4088
|
+
lerpBloomFactor( bloomFactors[ 1 ] ) * bloomTintColors[ 1 ] * texture2D( blurTexture2, vUv ).rgb +
|
|
4089
|
+
lerpBloomFactor( bloomFactors[ 2 ] ) * bloomTintColors[ 2 ] * texture2D( blurTexture3, vUv ).rgb +
|
|
4090
|
+
lerpBloomFactor( bloomFactors[ 3 ] ) * bloomTintColors[ 3 ] * texture2D( blurTexture4, vUv ).rgb +
|
|
4091
|
+
lerpBloomFactor( bloomFactors[ 4 ] ) * bloomTintColors[ 4 ] * texture2D( blurTexture5, vUv ).rgb
|
|
4092
|
+
);
|
|
4093
|
+
|
|
4094
|
+
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
|
4095
|
+
gl_FragColor = vec4( bloom, bloomAlpha );
|
|
4096
|
+
|
|
4097
|
+
}`})}};Io.BlurDirectionX=new E(1,0),Io.BlurDirectionY=new E(0,1);var Lo=`// Global detail setting
|
|
3986
4098
|
$fn = 64;
|
|
3987
4099
|
|
|
3988
4100
|
// Animation Data Dictionary
|
|
@@ -4108,7 +4220,7 @@ armature(animations=anim_data) {
|
|
|
4108
4220
|
}
|
|
4109
4221
|
}
|
|
4110
4222
|
}
|
|
4111
|
-
`,
|
|
4223
|
+
`,Ro=document.getElementById(`prompt-desc`),zo=document.getElementById(`copy-prompt-btn`),Bo=document.getElementById(`model-name-input`),z=document.getElementById(`editor`),Vo=document.getElementById(`render-btn`),Ho=document.getElementById(`load-scad-btn`),Uo=document.getElementById(`download-scad-btn`),Wo=document.getElementById(`export-gltf-btn`),Go=document.getElementById(`capture-image-btn`),Ko=document.getElementById(`share-btn`),qo=document.getElementById(`auto-render-cb`),Jo=document.getElementById(`minify-share-cb`),B=document.getElementById(`viewer`),Yo=document.getElementById(`right-panel`),Xo=document.getElementById(`backend-url`),Zo=document.getElementById(`backend-connect-btn`),Qo=document.getElementById(`backend-ui`),$o=document.getElementById(`backend-select`),es=document.getElementById(`backend-single-save-btn`),ts=document.getElementById(`backend-delete-btn`),ns=document.getElementById(`anim-controls-section`),rs=document.getElementById(`anim-play-btn`),is=document.getElementById(`anim-select`),as=document.getElementById(`anim-slider`),os=document.getElementById(`prompt-ui-container`),ss=document.getElementById(`show-grid-cb`),cs=document.getElementById(`wireframe-cb`),ls=document.getElementById(`bloom-cb`),V=document.getElementById(`lights-cb`),us=document.getElementById(`fullscreen-btn`),ds=document.getElementById(`screenshot-btn`),fs=document.getElementById(`camera-select`),ps=``,H=null,ms=null,hs=[],gs=!1,_s=null,U=null,vs=!1,ys=!1,bs=null,xs=[],Ss=!1,Cs=!1,ws={isNew:!0,options:{},content:``},W=null,Ts=!0,Es=!1,Ds=[],Os=[],G=null,ks=!1,As=1;function js(){return Cs?z.value:z.value||`// Global detail setting
|
|
4112
4224
|
$fn = 64;
|
|
4113
4225
|
|
|
4114
4226
|
// Animation Data Dictionary
|
|
@@ -4234,8 +4346,8 @@ armature(animations=anim_data) {
|
|
|
4234
4346
|
}
|
|
4235
4347
|
}
|
|
4236
4348
|
}
|
|
4237
|
-
`}function
|
|
4238
|
-
`;)r++;else if(e[r]===`/`&&e[r+1]===`*`){for(r+=2;r<e.length&&(e[r]!==`*`||e[r+1]!==`/`);)r++;r+=2}else/\s/.test(e[r])?(t.length>0&&!/\s/.test(t[t.length-1])&&(t+=` `),r++):(t+=e[r],r++);e=t.trim()}if(!e||!
|
|
4349
|
+
`}function Ms(){return Bo.value.trim()||`model`}Bo.addEventListener(`input`,Us),os&&(os.innerHTML=$e,Qe(os,`scad_editor_prompt_settings`)),zo.onclick=async()=>{let e=Ro.value.trim()||`an object`,t=Ze(os),n=Xe(e,t);try{await navigator.clipboard.writeText(n);let e=zo.innerText;zo.innerText=`✅ Copied!`,setTimeout(()=>{zo.innerText=e},2e3)}catch(e){alert(`Failed to copy clipboard: `+e)}};async function Ns(e){return Cs?Ie(e,zs,null):{}}async function Ps(e){if(typeof e!=`string`)return;if(gs){_s=e;return}if(e.trim()===``){nc();return}let t=e.match(/\/\*\s*Model Name:\s*(.*?)\s*\*\//i);if(t&&t[1]){let e=t[1].trim().replace(/\s+/g,`_`).replace(/[^a-zA-Z0-9_-]/g,``);e&&Bo.value!==e&&(Bo.value=e,Us())}gs=!0;try{let t=await Ns(e);ms=await ee(e,{wasmUrl:s,additionalFiles:t}),await rc(ms)}catch(e){console.error(e)}finally{if(gs=!1,_s!==null){let e=_s;_s=null,Ps(e)}}}Vo.onclick=()=>Ps(js());var Fs;z.addEventListener(`input`,()=>{Us(),clearTimeout(Fs),qo.checked&&(Fs=setTimeout(()=>{Ps(js())},800))}),qo.addEventListener(`change`,()=>{qo.checked&&Ps(js())}),Ho.onclick=()=>{let e=document.createElement(`input`);e.type=`file`,e.accept=`.scad`,e.onchange=async e=>{if(e.target.files&&e.target.files.length>0)try{let t=await e.target.files[0].text();z.value=t,Us(),Ps(t)}catch(e){alert(`Failed to read file: `+e.message)}},e.click()},Uo.onclick=()=>{let e=js();xe(new Blob([e],{type:`text/plain`}),`${Ms()}.scad`)},Wo.onclick=()=>{ms&&xe(new Blob([ms],{type:`application/octet-stream`}),`${Ms()}.glb`)};function Is(){Go.innerText=ys?`🔴 Rec...`:W&&Ts?`🎥 Video`:`📷 Image`}Go.onclick=()=>{if(ys){Ss=!0,bs&&bs.state!==`inactive`&&bs.stop();return}if(W&&Ts){if(typeof MediaRecorder<`u`){let e=J!==void 0&&Y&&Y.checked;W.time=0,U&&U.update(0),Be(G,512,512),q.setSize(512,512,!1),Ks.setSize(512,512),e&&J.updateCamera();let t=q.domElement,n=document.createElement(`canvas`);n.width=512,n.height=512;let r=n.getContext(`2d`),i=n.captureStream(30),a=25e5,o=`mp4`,s={mimeType:`video/mp4;codecs=avc1`,videoBitsPerSecond:a};MediaRecorder.isTypeSupported(s.mimeType)||(s={mimeType:`video/mp4`,videoBitsPerSecond:a},MediaRecorder.isTypeSupported(s.mimeType)||(o=`webm`,s={mimeType:`video/webm;codecs=vp9`,videoBitsPerSecond:a},MediaRecorder.isTypeSupported(s.mimeType)||(s={mimeType:`video/webm;codecs=vp8`,videoBitsPerSecond:a},MediaRecorder.isTypeSupported(s.mimeType)||(s={mimeType:`video/webm`,videoBitsPerSecond:a}))));let c=null;Ss=!1,ys=!0,Is();let l=W.getClip().duration,u=Math.round(l*30),d=0,f=[],p=()=>{if(Ss||d>=u){if(f.length===0){ys=!1,Be(G,B.clientWidth,B.clientHeight),q.setSize(B.clientWidth,B.clientHeight),Ks.setSize(B.clientWidth,B.clientHeight),e&&J!==void 0&&(J.setScene(K,G),J.updateCamera()),Is();return}Ss=!1,bs=new MediaRecorder(i,s),xs=[],bs.ondataavailable=e=>{e.data.size>0&&xs.push(e.data)},bs.onstop=()=>{c&&clearTimeout(c);let t=new Blob(xs,{type:s.mimeType.split(`;`)[0]});xe(t,`${Ms()}.${o}`),ys=!1,Be(G,B.clientWidth,B.clientHeight),q.setSize(B.clientWidth,B.clientHeight),Ks.setSize(B.clientWidth,B.clientHeight),e&&J!==void 0&&(J.setScene(K,G),J.updateCamera()),Is()},r.drawImage(f[0],0,0,512,512),bs.start();let t=0,n=performance.now(),a=()=>{if(Ss){bs.stop();return}if(t<f.length){r.drawImage(f[t],0,0,512,512),t++;let e=n+1e3/30*t,i=Math.max(0,e-performance.now());c=setTimeout(a,i)}else c=setTimeout(()=>bs.stop(),50)};c=setTimeout(a,0);return}if(W.time=d/30,U&&U.update(0),e){Z!==void 0&&(Z.visible=!1),X!==void 0&&(X.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),J.setScene(K,G);let e=()=>{if(Ss){p();return}let n=0;for(;J.samples<100&&n<5;)J.renderSample(),n++;if(J.samples>=100){let e=document.createElement(`canvas`);e.width=512,e.height=512,e.getContext(`2d`).drawImage(t,0,0,512,512),f.push(e),d++,setTimeout(p,0)}else requestAnimationFrame(e)};e()}else{let e=!ss||ss.checked;Z!==void 0&&(Z.visible=!0),X!==void 0&&(X.visible=!ks||V&&!V.checked),Q!==void 0&&(Q.visible=e),$!==void 0&&($.visible=e),Ks.render();let n=document.createElement(`canvas`);n.width=512,n.height=512,n.getContext(`2d`).drawImage(t,0,0,512,512),f.push(n),d++,setTimeout(p,0)}};p()}else alert(`Video recording is not supported in this browser.`)}else vs=!0},Ko.onclick=async()=>{let e=z.value.trim(),t=e,n=new URL(window.location.href),r=``;if(Jo&&Jo.checked){let t=``,n=!1,r=0;for(;r<e.length;)if(n)t+=e[r],e[r]===`"`&&e[r-1]!==`\\`&&(n=!1),r++;else if(e[r]===`"`)n=!0,t+=e[r],r++;else if(e[r]===`/`&&e[r+1]===`/`)for(r+=2;r<e.length&&e[r]!==`
|
|
4350
|
+
`;)r++;else if(e[r]===`/`&&e[r+1]===`*`){for(r+=2;r<e.length&&(e[r]!==`*`||e[r+1]!==`/`);)r++;r+=2}else/\s/.test(e[r])?(t.length>0&&!/\s/.test(t[t.length-1])&&(t+=` `),r++):(t+=e[r],r++);e=t.trim()}if(!e||!Cs&&t===`// Global detail setting
|
|
4239
4351
|
$fn = 64;
|
|
4240
4352
|
|
|
4241
4353
|
// Animation Data Dictionary
|
|
@@ -4360,4 +4472,4 @@ armature(animations=anim_data) {
|
|
|
4360
4472
|
}
|
|
4361
4473
|
}
|
|
4362
4474
|
}
|
|
4363
|
-
}`)r=n.origin+n.pathname+n.search;else try{n.hash=await bs(e),r=n.toString()}catch{r=n.origin+n.pathname+n.search}window.history.replaceState(null,``,r);try{if(navigator.share){let e=Do.value.trim(),t=e?e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):`Scadify`;await navigator.share({title:t,url:r});let n=No.innerText;No.innerText=`✅ Shared!`,setTimeout(()=>No.innerText=n,2e3)}else{await navigator.clipboard.writeText(r);let e=No.innerText;No.innerText=`✅ Copied Link!`,setTimeout(()=>No.innerText=e,2e3)}}catch(e){if(e.name!==`AbortError`)try{await navigator.clipboard.writeText(r),No.innerText=`✅ Copied Link!`,setTimeout(()=>No.innerText=`🔗 Share`,2e3)}catch{alert(`Failed to share or copy link.`)}}};var Ss=document.getElementById(`drag-overlay`);window.addEventListener(`dragenter`,e=>{e.preventDefault(),Ss.classList.add(`active`)}),window.addEventListener(`dragover`,e=>{e.preventDefault(),Ss.classList.add(`active`)}),Ss.addEventListener(`dragleave`,e=>{e.preventDefault(),Ss.classList.remove(`active`)}),window.addEventListener(`drop`,async e=>{if(e.preventDefault(),Ss.classList.remove(`active`),e.dataTransfer.files&&e.dataTransfer.files.length>0){let t=e.dataTransfer.files[0],n=t.name.toLowerCase();if(n.endsWith(`.hdr`)){let e=URL.createObjectURL(t);new Co().load(e,e=>{e.mapping=303,W.environment=e,Fs=e,J&&J.checked?(W.background=e,W.backgroundBlurriness=.5,W.backgroundIntensity=.3):(W.background=new ze(2236962),W.backgroundBlurriness=0,W.backgroundIntensity=1),q!==void 0&&(q.setScene(W,G),q.updateCamera())},void 0,e=>{console.warn(`Error loading HDR:`,e),alert(`Failed to load HDR file.`)})}else if(n.endsWith(`.scad`)||!t.type||t.type.includes(`text`))try{let e=await t.text();z.value=e,Os(),hs(e)}catch(e){alert(`Failed to read file: `+e.message)}else alert(`Please drop a valid .scad or .hdr file.`)}});var Cs=null,ws=``;async function Ts(e){let t=await fetch(`${e}/api/scads`);if(!t.ok)throw Error(`Failed to fetch files`);return(await t.json()).files}function Es(){Bo.innerHTML=`<option value="">-- Create New Model --</option>`,Array.isArray(Cs)&&Cs.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e,Bo.appendChild(n)}),Bo.value=Qo,Ho&&(Ho.style.display=Qo===``?`none`:`flex`)}function Ds(){let e=Do.value.trim();return e&&=e.replace(/\.scad$/i,``).split(/[/\\]/).pop()+`.scad`,{filename:e}}function Os(){if(Cs===null)return;let e=Bo.value===``,{filename:t}=Ds(),n=z.value,r=!1;e?(t&&t!==`.scad`||n.trim()!==``)&&(r=!0):n!==ls.content&&(r=!0),r?(Vo.style.display=`flex`,Vo.innerText=`Save`):Vo.style.display=`none`}async function ks(e,t=!1){if(!e)return!1;try{return Ro.innerText=`Connecting...`,Cs=await Ts(e),ws=e,cs=!0,Ro.innerText=`Connected`,zo.classList.add(`active`),z.placeholder=`Enter OpenSCAD code here...`,Qo=``,Es(),ls={isNew:!0,content:``},Os(),!0}catch(e){return t?console.warn(`Auto-connect failed:`,e.message):alert(`Connection failed: `+e.message),Ro.innerText=`Connect`,zo.classList.remove(`active`),cs=!1,z.placeholder=wo,!1}}Ro.onclick=async()=>{await ks(Lo.value.trim(),!1)&&hs(fs())},Bo.addEventListener(`change`,async()=>{if(Vo.style.display!==`none`&&!confirm(`You have unsaved changes. Are you sure you want to discard them and load another model?`)){Bo.value=Qo;return}let e=Bo.value;if(Qo=e,Ho&&(Ho.style.display=e===``?`none`:`flex`),e===``)Do.value=``,z.value=``,hs(fs()),ls={isNew:!0,content:``},Os();else{let t=Cs[e];Do.value=t.replace(/\.scad$/i,``);try{let e=await fetch(`${ws}/api/scads/${encodeURIComponent(t)}`);if(!e.ok){let t=await e.json();throw Error(t.error||`Failed to load model`)}let n=await e.json();z.value=n.content,hs(fs()),ls={isNew:!1,content:n.content},Os()}catch(e){alert(`Error loading model: `+e.message)}}}),Vo.onclick=async()=>{let{filename:e}=Ds();if(!e||e===`.scad`){let e=Vo.innerText;Vo.innerText=`⚠️ Name Required!`,Vo.style.borderColor=`#ff4444`,Do.focus(),setTimeout(()=>{Vo.innerText=e,Vo.style.borderColor=``},2e3);return}if(Bo.value===``&&Cs&&Cs.includes(e)&&!confirm(`A model named "${e}" already exists. Are you sure you want to overwrite it?`))return;let t={filename:e,content:z.value};try{Vo.innerText=`Saving...`;let n=await fetch(`${ws}/api/scads`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json();throw Error(e.error||`Save failed`)}Cs=await Ts(ws);let r=Cs.findIndex(t=>t===e);Qo=r>=0?r.toString():``,Es(),ls={isNew:!1,content:z.value},Os()}catch(e){Os(),alert(`Error: `+e.message)}},Ho.onclick=async()=>{let e=Bo.value;if(e===``)return;let t=Cs[e];if(confirm(`Are you sure you want to delete "${t}"?`))try{Ho.innerText=`Deleting...`;let e=await fetch(`${ws}/api/scads/${encodeURIComponent(t)}`,{method:`DELETE`});if(!e.ok){let t=`Delete failed`;try{let n=await e.json();n.error&&(t=n.error)}catch{}throw Error(t)}Cs=await Ts(ws),Qo=``,Es(),Do.value=``,z.value=``,hs(fs()),ls={isNew:!0,content:``},Os(),Ho.innerText=`Delete`}catch(e){alert(`Error: `+e.message),Ho.innerText=`Delete`}};var W=new le;W.background=new ze(2236962);var G=new c(60,B.clientWidth/B.clientHeight,.1,2e3);G.position.set(50,50,-50);var K=new Fe({antialias:!0,preserveDrawingBuffer:!0});K.setSize(B.clientWidth,B.clientHeight),K.setPixelRatio(Math.min(window.devicePixelRatio,2)),K.toneMapping=4,K.toneMappingExposure=1,K.shadowMap.enabled=!0,K.shadowMap.type=2,B.appendChild(K.domElement);var As=new he(K),js=new ke(W,G);As.addPass(js);var Ms=new Se(new E(B.clientWidth,B.clientHeight),.1,.1,2);As.addPass(Ms);var Ns=new Ne;As.addPass(Ns);var q=new So(K);q.bounces=10,q.transmissiveBounces=10,q.multipleImportanceSampling=!0,q.filterGlossyFactor=.2;var Ps=new je(G,K.domElement);Ps.addEventListener(`change`,()=>{q!==void 0&&q.updateCamera()});var Fs=null;new Co().load(`./aristea_wreck_puresky_2k.hdr`,e=>{e.mapping=303,W.environment=e,Fs=e;let t=J&&J.checked,n=!Jo||Jo.checked;Z!==void 0&&(Z.visible=!t),Y!==void 0&&(Y.visible=!t),Q!==void 0&&(Q.visible=!t&&n),$!==void 0&&($.visible=!t&&n),t?(W.background=e,W.backgroundBlurriness=.5,W.backgroundIntensity=.3):(W.background=new ze(2236962),W.backgroundBlurriness=0,W.backgroundIntensity=1),q!==void 0&&(q.setScene(W,G),q.updateCamera())},void 0,e=>console.warn(`Error loading HDR:`,e));var J=document.getElementById(`path-tracing-cb`);J&&J.addEventListener(`change`,()=>{let e=J.checked,t=!Jo||Jo.checked;Z!==void 0&&(Z.visible=!e),Y!==void 0&&(Y.visible=!e),Q!==void 0&&(Q.visible=!e&&t),$!==void 0&&($.visible=!e&&t),e?Fs&&(W.background=Fs,W.backgroundBlurriness=.5,W.backgroundIntensity=.3):(W.background=new ze(2236962),W.backgroundBlurriness=0,W.backgroundIntensity=1),e&&q!==void 0&&q.setScene(W,G)}),Ps.enableDamping=!0,Ps.dampingFactor=.1,Ps.maxDistance=2e3,W.environment=new ye(K).fromScene(new ne,.04).texture,W.environmentIntensity=.8;var Y=new h;W.add(Y);var X=new Le(16777215,1.5);X.castShadow=!0,X.shadow.mapSize.width=2048,X.shadow.mapSize.height=2048,X.shadow.bias=-5e-4,Y.add(X),Y.add(X.target);var Is=new t(16777215,4473924,.6);Is.position.set(0,20,0),Y.add(Is);var Z=new v(new C(2e3,2e3),new n({color:2236962,roughness:.8,metalness:.1}));Z.rotation.x=-Math.PI/2,Z.receiveShadow=!0,W.add(Z);var Q=new i(2e3,100,5592405,3355443);Q.material.transparent=!0,Q.material.opacity=.5,W.add(Q);var $=new ue(100);W.add($),Yo&&Yo.addEventListener(`change`,()=>{let e=Yo.checked;V&&V.traverse(t=>{t.isMesh&&t.material&&(Array.isArray(t.material)?t.material.forEach(t=>{t.wireframe=e}):t.material.wireframe=e)})}),Xo&&Io&&(Xo.addEventListener(`click`,()=>{document.fullscreenElement?document.exitFullscreen():Io.requestFullscreen().catch(e=>{console.warn(`Error attempting to enable fullscreen: ${e.message}`)})}),document.addEventListener(`fullscreenchange`,()=>{setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100)})),Zo&&Zo.addEventListener(`click`,()=>{rs=!0;let e=Zo.innerText;Zo.innerText=`✅`,setTimeout(()=>{Zo.innerText=e},1e3)});function Ls(){U&&(us=!1,U.paused=!0,Wo.innerText=`▶ Play`,vs())}function Rs(e){if(!H||!es[e])return;U&&U.stop();let t=es[e];U=H.clipAction(t),U.play(),U.time=0,H.update(0),us=!0,U.paused=!1,Wo.innerText=`⏸ Pause`,Ko.value=0,vs()}Go.addEventListener(`change`,e=>{Rs(parseInt(e.target.value))}),Wo.addEventListener(`click`,()=>{U&&(us=!us,U.paused=!us,Wo.innerText=us?`⏸ Pause`:`▶ Play`,vs())}),Ko.addEventListener(`mousedown`,()=>{ds=!0,Ls()}),Ko.addEventListener(`mouseup`,()=>{ds=!1}),Ko.addEventListener(`touchstart`,()=>{ds=!0,Ls()},{passive:!0}),Ko.addEventListener(`touchend`,()=>{ds=!1},{passive:!0}),Ko.addEventListener(`input`,e=>{if(Ls(),U){let t=U.getClip().duration;U.time=parseFloat(e.target.value)*t,H&&(H.update(0),J&&J.checked&&q!==void 0&&(Z!==void 0&&(Z.visible=!1),Y!==void 0&&(Y.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),q.setScene(W,G)))}});function zs(){is&&as&&as.state!==`inactive`&&(as.stop(),is=!1),V&&=(H&&=(H.stopAllAction(),H.uncacheRoot(H.getRoot()),null),U=null,W.remove(V),V.traverse(e=>{e.isMesh&&(e.geometry.dispose(),Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material&&e.material.dispose())}),null),vs()}function Bs(e,t){if(!e)return new Ee;e.updateMatrixWorld(!0);let n=new Ee().setFromObject(e);if(!t||t.length===0)return n;let r=new Map;e.traverse(e=>{r.set(e,{position:e.position.clone(),quaternion:e.quaternion.clone(),scale:e.scale.clone()})});let i=new se(e);for(let r of t){let t=i.clipAction(r);t.play();let a=new Set([0,r.duration]);if(r.tracks){for(let e of r.tracks)if(e.times)for(let t=0;t<e.times.length;t++)a.add(e.times[t])}if(r.duration>0)for(let e=0;e<=20;e++)a.add(e/20*r.duration);let o=Array.from(a).sort((e,t)=>e-t);if(o.length>60){let e=[],t=(o.length-1)/59;for(let n=0;n<60;n++)e.push(o[Math.round(n*t)]);o=e}for(let r of o)t.time=r,i.update(0),e.updateMatrixWorld(!0),n.expandByObject(e);t.stop()}return i.stopAllAction(),i.uncacheRoot(e),r.forEach((e,t)=>{t.position.copy(e.position),t.quaternion.copy(e.quaternion),t.scale.copy(e.scale)}),e.updateMatrixWorld(!0),n}function Vs(e){return new Promise((t,n)=>{let r=null;V&&(H&&U&&(U.time=0,H.update(0),J&&J.checked&&q!==void 0&&(Z!==void 0&&(Z.visible=!1),Y!==void 0&&(Y.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),q.setScene(W,G))),r=Bs(V,es)),zs();let i=e;e instanceof Uint8Array&&(i=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)),new we().parse(i,``,e=>{V=e.scene,es=e.animations||[];let n=Yo?Yo.checked:!1;es.length?(H=new se(V),Uo.style.display=`flex`,Go.innerHTML=``,es.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Animation ${t+1}`,Go.appendChild(n)}),Rs(0)):(Uo.style.display=`none`,U=null,vs()),V.traverse(e=>{e.isMesh&&(e.castShadow=!0,e.receiveShadow=!0,e.frustumCulled=!1,e.material&&(Array.isArray(e.material)?e.material.forEach(e=>{e.wireframe=n}):e.material.wireframe=n))}),W.add(V);let i=!0;if(r&&!r.isEmpty()){let e=Bs(V,es);if(!e.isEmpty()){let t=.001;r.min.distanceTo(e.min)<t&&r.max.distanceTo(e.max)<t&&(i=!1)}}if(i)typeof Hs==`function`&&Hs();else{let e=J&&J.checked,t=!Jo||Jo.checked;Z!==void 0&&(Z.visible=!e),Y!==void 0&&(Y.visible=!e),Q!==void 0&&(Q.visible=!e&&t),$!==void 0&&($.visible=!e&&t),q!==void 0&&q.setScene(W,G)}t()},n)})}function Hs(){if(!V)return;let e=Bs(V,es);if(e.isEmpty())return;let t=e.getCenter(new D),n=e.getSize(new D),r=Math.max(n.x,n.y,n.z)||10;Z.position.y=e.min.y-.01,Q.position.y=Z.position.y+.001,$.position.y=Z.position.y+.002;let i=G.fov*(Math.PI/180),o=r/(2*Math.tan(i/2));G.aspect<1&&(o/=G.aspect),o*=1.5,G.near=Math.max(.01,r*.01),G.far=Math.max(2e3,o*10),G.updateProjectionMatrix(),Ps.maxDistance=G.far,G.position.set(t.x+o*.8,t.y+o*.8,t.z-o*.8),G.lookAt(t),Ps.target.copy(t),Ps.update(),X.position.set(t.x+r,t.y+r*1.5,t.z-r),X.target.position.copy(t),X.target.updateMatrixWorld();let s=r*1.5;X.shadow.camera.left=-s,X.shadow.camera.right=s,X.shadow.camera.top=s,X.shadow.camera.bottom=-s,X.shadow.camera.near=.1,X.shadow.camera.far=r*5,X.shadow.camera.updateProjectionMatrix(),W.fog=new a(2236962,o*1.5,o*5);let c=J&&J.checked,l=!Jo||Jo.checked;Z!==void 0&&(Z.visible=!c),Y!==void 0&&(Y.visible=!c),Q!==void 0&&(Q.visible=!c&&l),$!==void 0&&($.visible=!c&&l),q!==void 0&&q.setScene(W,G)}var Us=performance.now();function Ws(){requestAnimationFrame(Ws);let e=performance.now(),t=(e-Us)/1e3;if(Us=e,H&&(!(J&&J.checked)&&!is&&H.update(t),U&&us&&!ds)){let e=U.getClip().duration;if(e>0){let t=U.time%e;t<0&&(t+=e),Ko.value=t/e}}Ps.update();let n=J&&J.checked,r=!Jo||Jo.checked;n?(Z!==void 0&&(Z.visible=!1),Y!==void 0&&(Y.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),q!==void 0&&!is&&q.renderSample()):(Z!==void 0&&(Z.visible=!0),Y!==void 0&&(Y.visible=!0),Q!==void 0&&(Q.visible=r),$!==void 0&&($.visible=r),is||As.render()),rs&&(rs=!1,K.domElement.toBlob(e=>{e&&_s(e,`${ps()}.png`)},`image/png`))}Ws(),window.addEventListener(`resize`,()=>{if(!B||is)return;let e=B.clientWidth,t=B.clientHeight;G.aspect=e/t,G.updateProjectionMatrix(),K.setSize(e,t),As.setSize(e,t),q!==void 0&&q.updateCamera()}),setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100);var Gs=[`localhost`,`127.0.0.1`,``].includes(window.location.hostname);z.placeholder=Gs?`Enter OpenSCAD code here...`:wo,(async function(){if(Gs&&await ks(Lo.value.trim(),!0),window.location.hash&&window.location.hash.length>1)try{let e=await xs(window.location.hash.substring(1));e&&(z.value=e)}catch(e){console.error(`Failed to decode hash`,e)}Os(),setTimeout(()=>hs(fs()),500)})();
|
|
4475
|
+
}`)r=n.origin+n.pathname+n.search;else try{n.hash=await se(e),r=n.toString()}catch{r=n.origin+n.pathname+n.search}window.history.replaceState(null,``,r);try{if(navigator.share){let e=Bo.value.trim(),t=e?e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):`Scadify`;await navigator.share({title:t,url:r});let n=Ko.innerText;Ko.innerText=`✅ Shared!`,setTimeout(()=>Ko.innerText=n,2e3)}else{await navigator.clipboard.writeText(r);let e=Ko.innerText;Ko.innerText=`✅ Copied Link!`,setTimeout(()=>Ko.innerText=e,2e3)}}catch(e){if(e.name!==`AbortError`)try{await navigator.clipboard.writeText(r),Ko.innerText=`✅ Copied Link!`,setTimeout(()=>Ko.innerText=`🔗 Share`,2e3)}catch{alert(`Failed to share or copy link.`)}}};var Ls=document.getElementById(`drag-overlay`);window.addEventListener(`dragenter`,e=>{e.preventDefault(),Ls.classList.add(`active`)}),window.addEventListener(`dragover`,e=>{e.preventDefault(),Ls.classList.add(`active`)}),Ls.addEventListener(`dragleave`,e=>{e.preventDefault(),Ls.classList.remove(`active`)}),window.addEventListener(`drop`,async e=>{if(e.preventDefault(),Ls.classList.remove(`active`),e.dataTransfer.files&&e.dataTransfer.files.length>0){let n=e.dataTransfer.files[0],r=n.name.toLowerCase();if(r.endsWith(`.hdr`)){let e=URL.createObjectURL(n);new Po().load(e,e=>{e.mapping=303,K.environment=e,Zs=e,Y&&Y.checked?(K.background=e,K.backgroundBlurriness=.5,K.backgroundIntensity=.3):(K.background=new t(2236962),K.backgroundBlurriness=0,K.backgroundIntensity=1),J!==void 0&&(J.setScene(K,G),J.updateCamera())},void 0,e=>{console.warn(`Error loading HDR:`,e),alert(`Failed to load HDR file.`)})}else if(r.endsWith(`.scad`)||!n.type||n.type.includes(`text`))try{let e=await n.text();z.value=e,Us(),Ps(e)}catch(e){alert(`Failed to read file: `+e.message)}else alert(`Please drop a valid .scad or .hdr file.`)}});var Rs=null,zs=``;async function Bs(e){let t=await fetch(`${e}/api/scads`);if(!t.ok)throw Error(`Failed to fetch files`);return(await t.json()).files}function Vs(){$o.innerHTML=`<option value="">-- Create New Model --</option>`,Array.isArray(Rs)&&Rs.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e,$o.appendChild(n)}),$o.value=ps,ts&&(ts.style.display=ps===``?`none`:`flex`)}function Hs(){let e=Bo.value.trim();return e&&=e.replace(/\.scad$/i,``).split(/[/\\]/).pop()+`.scad`,{filename:e}}function Us(){if(Rs===null)return;let e=$o.value===``,{filename:t}=Hs(),n=z.value,r=!1;e?(t&&t!==`.scad`||n.trim()!==``)&&(r=!0):n!==ws.content&&(r=!0),r?(es.style.display=`flex`,es.innerText=`Save`):es.style.display=`none`}async function Ws(e,t=!1){if(!e)return!1;try{return Zo.innerText=`Connecting...`,Rs=await Bs(e),zs=e,Cs=!0,Zo.innerText=`Connected`,Qo.classList.add(`active`),z.placeholder=`Enter OpenSCAD code here...`,ps=``,Vs(),ws={isNew:!0,content:``},Us(),!0}catch(e){return t?console.warn(`Auto-connect failed:`,e.message):alert(`Connection failed: `+e.message),Zo.innerText=`Connect`,Qo.classList.remove(`active`),Cs=!1,z.placeholder=Lo,!1}}Zo.onclick=async()=>{await Ws(Xo.value.trim(),!1)&&Ps(js())},$o.addEventListener(`change`,async()=>{if(es.style.display!==`none`&&!confirm(`You have unsaved changes. Are you sure you want to discard them and load another model?`)){$o.value=ps;return}let e=$o.value;if(ps=e,ts&&(ts.style.display=e===``?`none`:`flex`),e===``)Bo.value=``,z.value=``,Ps(js()),ws={isNew:!0,content:``},Us();else{let t=Rs[e];Bo.value=t.replace(/\.scad$/i,``);try{let e=await fetch(`${zs}/api/scads/${encodeURIComponent(t)}`);if(!e.ok){let t=await e.json();throw Error(t.error||`Failed to load model`)}let n=await e.json();z.value=n.content,Ps(js()),ws={isNew:!1,content:n.content},Us()}catch(e){alert(`Error loading model: `+e.message)}}}),es.onclick=async()=>{let{filename:e}=Hs();if(!e||e===`.scad`){let e=es.innerText;es.innerText=`⚠️ Name Required!`,es.style.borderColor=`#ff4444`,Bo.focus(),setTimeout(()=>{es.innerText=e,es.style.borderColor=``},2e3);return}if($o.value===``&&Rs&&Rs.includes(e)&&!confirm(`A model named "${e}" already exists. Are you sure you want to overwrite it?`))return;let t={filename:e,content:z.value};try{es.innerText=`Saving...`;let n=await fetch(`${zs}/api/scads`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(!n.ok){let e=await n.json();throw Error(e.error||`Save failed`)}Rs=await Bs(zs);let r=Rs.findIndex(t=>t===e);ps=r>=0?r.toString():``,Vs(),ws={isNew:!1,content:z.value},Us()}catch(e){Us(),alert(`Error: `+e.message)}},ts.onclick=async()=>{let e=$o.value;if(e===``)return;let t=Rs[e];if(confirm(`Are you sure you want to delete "${t}"?`))try{ts.innerText=`Deleting...`;let e=await fetch(`${zs}/api/scads/${encodeURIComponent(t)}`,{method:`DELETE`});if(!e.ok){let t=`Delete failed`;try{let n=await e.json();n.error&&(t=n.error)}catch{}throw Error(t)}Rs=await Bs(zs),ps=``,Vs(),Bo.value=``,z.value=``,Ps(js()),ws={isNew:!0,content:``},Us(),ts.innerText=`Delete`}catch(e){alert(`Error: `+e.message),ts.innerText=`Delete`}};var K=new Ve;K.background=new t(2236962);var Gs=new y(60,B.clientWidth/B.clientHeight,.1,2e3);Gs.position.set(50,50,-50),G=Gs;var q=new Ke({antialias:!0,preserveDrawingBuffer:!0});q.setSize(B.clientWidth,B.clientHeight),q.setPixelRatio(Math.min(window.devicePixelRatio,2)),q.toneMapping=4,q.toneMappingExposure=1,q.shadowMap.enabled=!0,q.shadowMap.type=2,B.appendChild(q.domElement);var Ks=new Me(q),qs=new he(K,G);Ks.addPass(qs);var Js=new Io(new E(B.clientWidth,B.clientHeight),.1,.1,2);Js.enabled=!1,Ks.addPass(Js);var Ys=new fe;Ks.addPass(Ys);var J=new No(q);J.bounces=10,J.transmissiveBounces=10,J.multipleImportanceSampling=!0,J.filterGlossyFactor=.2;var Xs=new ae(Gs,q.domElement);Xs.addEventListener(`change`,()=>{J!==void 0&&J.updateCamera()});var Zs=null;new Po().load(`./aristea_wreck_puresky_2k.hdr`,e=>{e.mapping=303,K.environment=e,Zs=e;let n=Y&&Y.checked,r=!ss||ss.checked;Z!==void 0&&(Z.visible=!n),X!==void 0&&(X.visible=!n&&(!ks||V&&!V.checked)),Q!==void 0&&(Q.visible=!n&&r),$!==void 0&&($.visible=!n&&r),n?(K.background=e,K.backgroundBlurriness=.5,K.backgroundIntensity=.3):(K.background=new t(2236962),K.backgroundBlurriness=0,K.backgroundIntensity=1),J!==void 0&&(J.setScene(K,G),J.updateCamera())},void 0,e=>console.warn(`Error loading HDR:`,e));var Y=document.getElementById(`path-tracing-cb`);Y&&Y.addEventListener(`change`,()=>{let e=Y.checked,n=!ss||ss.checked;Z!==void 0&&(Z.visible=!e),X!==void 0&&(X.visible=!e&&(!ks||V&&!V.checked)),Q!==void 0&&(Q.visible=!e&&n),$!==void 0&&($.visible=!e&&n),e?Zs&&(K.background=Zs,K.backgroundBlurriness=.5,K.backgroundIntensity=.3):(K.background=new t(2236962),K.backgroundBlurriness=0,K.backgroundIntensity=1),e&&J!==void 0&&(J.setScene(K,G),J.updateCamera())}),fs&&fs.addEventListener(`change`,e=>{let t=e.target.value;t===``?(G=Gs,Xs.enabled=!0):(G=Ds[parseInt(t)],Xs.enabled=!1);let n=B.clientWidth,r=B.clientHeight;Be(G,n,r),qs.camera=G,Y&&Y.checked&&J!==void 0&&(J.setScene(K,G),J.updateCamera())}),Xs.enableDamping=!0,Xs.dampingFactor=.1,Xs.maxDistance=2e3,K.environment=new le(q).fromScene(new ye,.04).texture,K.environmentIntensity=.8;var X=new b;K.add(X);var Qs=new c(16777215,1.5);Qs.castShadow=!0,Qs.shadow.mapSize.width=2048,Qs.shadow.mapSize.height=2048,Qs.shadow.bias=-5e-4,X.add(Qs),X.add(Qs.target);var $s=new n(16777215,4473924,.6);$s.position.set(0,20,0),X.add($s);var Z=new f(new me(2e3,2e3),new re({color:2236962,roughness:.8,metalness:.1}));Z.rotation.x=-Math.PI/2,Z.receiveShadow=!0,K.add(Z);var Q=new m(2e3,100,5592405,3355443);Q.material.transparent=!0,Q.material.opacity=.5,K.add(Q);var $=new r(100);K.add($),cs&&cs.addEventListener(`change`,()=>{let e=cs.checked;Js.enabled=(ls?ls.checked:!1)&&!e,H&&Te(H,e)}),ls&&ls.addEventListener(`change`,()=>{let e=ls.checked,t=cs?cs.checked:!1;Js.enabled=e&&!t}),V&&V.addEventListener(`change`,()=>{let e=Y&&Y.checked,t=V.checked;Os.forEach(e=>e.visible=t),K.environmentIntensity=ks&&t?0:.8,q.toneMappingExposure=ks&&t?As:1,X!==void 0&&(X.visible=!e&&(!ks||!t)),e&&J!==void 0&&(J.setScene(K,G),J.updateCamera())}),us&&Yo&&(us.addEventListener(`click`,()=>{document.fullscreenElement?document.exitFullscreen():Yo.requestFullscreen().catch(e=>{console.warn(`Error attempting to enable fullscreen: ${e.message}`)})}),document.addEventListener(`fullscreenchange`,()=>{setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100)})),ds&&ds.addEventListener(`click`,()=>{vs=!0;let e=ds.innerText;ds.innerText=`✅`,setTimeout(()=>{ds.innerText=e},1e3)});function ec(){W&&(Ts=!1,W.paused=!0,rs.innerText=`▶ Play`,Is())}function tc(e){if(!U||!hs[e])return;W&&W.stop();let t=hs[e];W=U.clipAction(t),W.play(),W.time=0,U.update(0),Ts=!0,W.paused=!1,rs.innerText=`⏸ Pause`,as.value=0,Is()}is.addEventListener(`change`,e=>{tc(parseInt(e.target.value))}),rs.addEventListener(`click`,()=>{W&&(Ts=!Ts,W.paused=!Ts,rs.innerText=Ts?`⏸ Pause`:`▶ Play`,Is())}),as.addEventListener(`mousedown`,()=>{Es=!0,ec()}),as.addEventListener(`mouseup`,()=>{Es=!1}),as.addEventListener(`touchstart`,()=>{Es=!0,ec()},{passive:!0}),as.addEventListener(`touchend`,()=>{Es=!1},{passive:!0}),as.addEventListener(`input`,e=>{if(ec(),W){let t=W.getClip().duration;W.time=parseFloat(e.target.value)*t,U&&(U.update(0),Y&&Y.checked&&J!==void 0&&(Z!==void 0&&(Z.visible=!1),X!==void 0&&(X.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),J.setScene(K,G),J.updateCamera()))}});function nc(){ys&&bs&&bs.state!==`inactive`&&(bs.stop(),ys=!1),H&&=(U&&=(U.stopAllAction(),U.uncacheRoot(U.getRoot()),null),W=null,K.remove(H),H.traverse(e=>{e.isMesh&&(e.geometry.dispose(),Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material&&e.material.dispose())}),null),Is()}function rc(e){return new Promise((t,n)=>{let r=null;H&&(U&&W&&(W.time=0,U.update(0),Y&&Y.checked&&J!==void 0&&(Z!==void 0&&(Z.visible=!1),X!==void 0&&(X.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),J.setScene(K,G),J.updateCamera())),r=ke(H,hs)),nc();let i=e;e instanceof Uint8Array&&(i=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)),new _e().parse(i,``,e=>{H=e.scene,hs=e.animations||[];let n=cs?cs.checked:!1;Js.enabled=(ls?ls.checked:!1)&&!n;let i=Ae(H);Ds=i.gltfCameras,Os=i.gltfLights,ks=i.sceneHasLights,As=i.optimalExposure||1;let a=document.getElementById(`lights-cb-label`);a&&(a.style.display=ks?`flex`:`none`);let o=!V||V.checked;Os.forEach(e=>e.visible=o),K.environmentIntensity=ks&&o?0:.8,q.toneMappingExposure=ks&&o?As:1;let s=!1;fs?Ds.length>0?(fs.style.display=`inline-block`,fs.innerHTML=`<option value="">Free Camera</option>`,Ds.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Camera ${t+1}`,fs.appendChild(n)}),fs.value=`0`,G=Ds[0],Xs.enabled=!1,s=!0):(fs.style.display=`none`,fs.value=``,G=Gs,Xs.enabled=!0):(G=Gs,Xs.enabled=!0);let c=B?B.clientWidth:window.innerWidth,l=B?B.clientHeight:window.innerHeight;Be(G,c,l),qs.camera=G;let u=document.getElementById(`anim-slider-row`);hs.length?(U=new x(H),s=!0,rs&&(rs.style.display=``),is&&(is.style.display=``),u&&(u.style.display=``),is.innerHTML=``,hs.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Animation ${t+1}`,is.appendChild(n)}),tc(0)):(rs&&(rs.style.display=`none`),is&&(is.style.display=`none`),u&&(u.style.display=`none`),W=null,Is()),ns&&(ns.style.display=s?`flex`:`none`),Te(H,n),K.add(H);let d=!0,f=null;if(r&&!r.isEmpty()&&(f=ke(H,hs),!f.isEmpty())){let e=.001;r.min.distanceTo(f.min)<e&&r.max.distanceTo(f.max)<e&&(d=!1)}if(d)typeof ic==`function`&&ic();else{if(f){let e=f.getSize(new k),t=Math.max(e.x,e.y,e.z)||10;Re(H,t*1.5)}let e=Y&&Y.checked,t=!ss||ss.checked;Z!==void 0&&(Z.visible=!e),X!==void 0&&(X.visible=!e&&(!ks||V&&!V.checked)),Q!==void 0&&(Q.visible=!e&&t),$!==void 0&&($.visible=!e&&t),J!==void 0&&(J.setScene(K,G),J.updateCamera())}t()},n)})}function ic(){if(!H)return;let e=ke(H,hs);if(e.isEmpty())return;Z.position.y=e.min.y-.01,Q.position.y=Z.position.y+.001,$.position.y=Z.position.y+.002;let{maxDim:t}=ue(Gs,Xs,Qs,K,e);Re(H,t*1.5);let n=Y&&Y.checked,r=!ss||ss.checked;Z!==void 0&&(Z.visible=!n),X!==void 0&&(X.visible=!n&&(!ks||V&&!V.checked)),Q!==void 0&&(Q.visible=!n&&r),$!==void 0&&($.visible=!n&&r),J!==void 0&&(J.setScene(K,G),J.updateCamera())}var ac=performance.now();function oc(){requestAnimationFrame(oc);let e=performance.now(),t=(e-ac)/1e3;if(ac=e,U&&(!(Y&&Y.checked)&&!ys&&U.update(t),W&&Ts&&!Es)){let e=W.getClip().duration;if(e>0){let t=W.time%e;t<0&&(t+=e),as.value=t/e}}Xs.update();let n=Y&&Y.checked,r=!ss||ss.checked;n?(Z!==void 0&&(Z.visible=!1),X!==void 0&&(X.visible=!1),Q!==void 0&&(Q.visible=!1),$!==void 0&&($.visible=!1),J!==void 0&&!ys&&J.renderSample()):(Z!==void 0&&(Z.visible=!0),X!==void 0&&(X.visible=X.visible=!ks||V&&!V.checked),Q!==void 0&&(Q.visible=r),$!==void 0&&($.visible=r),ys||Ks.render()),vs&&(vs=!1,q.domElement.toBlob(e=>{e&&xe(e,`${Ms()}.png`)},`image/png`))}oc(),window.addEventListener(`resize`,()=>{if(!B||ys)return;let e=B.clientWidth,t=B.clientHeight;Be(G,e,t),q.setSize(e,t),Ks.setSize(e,t),J!==void 0&&J.updateCamera()}),setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100);var sc=[`localhost`,`127.0.0.1`,``].includes(window.location.hostname);z.placeholder=sc?`Enter OpenSCAD code here...`:Lo,(async function(){if(sc&&await Ws(Xo.value.trim(),!0),window.location.hash&&window.location.hash.length>1)try{let e=window.location.hash.substring(1),t=await Pe(e);t&&(z.value=t)}catch(e){console.error(`Failed to decode hash`,e)}Us(),setTimeout(()=>Ps(js()),500)})();
|