scad-gltf 0.3.3 → 0.4.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 +31 -4
- package/bin/gen.js +1 -1
- package/editor/dist/assets/{OutputPass-B6MrFnGE.js → OutputPass-C3DZe46t.js} +2 -2
- package/editor/dist/assets/{index-CgVih1C4.js → index-D-FSzMhd.js} +76 -76
- package/editor/dist/assets/{index-B1KAb97r.css → index-D8In1wnN.css} +1 -1
- package/editor/dist/assets/{openscad-CdBCY4mx.wasm → openscad-DiJCzDqJ.wasm} +0 -0
- package/editor/dist/assets/preview-Br3_yFrj.js +1 -0
- package/editor/dist/assets/preview-Cx3FHqKG.css +1 -0
- package/editor/dist/assets/{prompt-ui-B9QCNLfJ.js → prompt-ui-BjZlMzjn.js} +1 -0
- package/editor/dist/content.js +1 -1
- package/editor/dist/index.html +7 -6
- package/editor/dist/preview.html +20 -15
- package/editor/dist/sw.js +1 -1
- package/package.json +1 -1
- package/src/cli-utils.js +2 -2
- package/src/ext/openscad.js +1 -1
- package/src/ext/openscad.wasm +0 -0
- package/src/project-prompts.js +65 -32
- package/src/prompt.js +1 -0
- package/editor/dist/assets/preview-A6M04CFK.css +0 -1
- package/editor/dist/assets/preview-BbUpKLF4.js +0 -1
|
@@ -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,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 ee,Y as te,Z as ne,_ as w,a as re,at as ie,b as ae,c as oe,ct as se,d as ce,dt as le,et as ue,f as de,ft as fe,g as pe,h as me,ht as he,i as ge,it as _e,j as ve,k as ye,l as be,lt as T,m as xe,mt as Se,n as Ce,nt as we,o as Te,ot as Ee,p as De,pt as Oe,q as ke,r as Ae,rt as je,s as Me,st as Ne,t as Pe,tt as Fe,u as Ie,ut as E,v as Le,w as Re,x as ze,y as Be,z as Ve}from"./OutputPass-C3DZe46t.js";import{i as He,n as Ue,r as We,t as Ge}from"./prompt-ui-BjZlMzjn.js";var Ke=1.25,qe=65535,Je=-65536,Ye=2**-24,Xe=Symbol(`SKIP_GENERATION`),Ze={strategy:0,maxDepth:40,targetLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Xe]:!1};function D(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 Qe(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 $e(e,t){t.set(e)}function et(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 tt(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 nt(e){let t=e[3]-e[0],n=e[4]-e[1],r=e[5]-e[2];return 2*(t*n+n*r+r*t)}function O(e,t){return t[e+15]===qe}function k(e,t){return t[e+6]}function A(e,t){return t[e+14]}function j(e){return e+8}function M(e,t){return e+t[e+6]*8}function rt(e,t){return t[e+7]}function N(e){return e}function it(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,te=S+C;ee<s&&(s=ee),te>u&&(u=te),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 at=32,ot=(e,t)=>e.candidate-t.candidate,st=Array(at).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),ct=new Float32Array(6);function lt(e,t,n,r,i,a){let o=-1,s=0;if(a===0)o=Qe(t),o!==-1&&(s=(t[o]+t[o+3])/2);else if(a===1)o=Qe(e),o!==-1&&(s=ut(n,r,i,o));else if(a===2){let a=nt(e),c=Ke*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)/at;if(i<at/4){let t=[...st];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;tt(i,n,o)}t.sort(ot);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?tt(r,n,a.rightCacheBounds):(tt(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=nt(d)/a);let m=0;u!==0&&(m=nt(f)/a);let h=1+Ke*(p*l+m*u);h<c&&(o=e,c=h,s=r.candidate)}}else{for(let e=0;e<at;e++){let t=st[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>=at&&(i=31);let a=st[i];a.count++,tt(t,n,a.bounds)}let t=st[31];$e(t.bounds,t.rightCacheBounds);for(let e=30;e>=0;e--){let t=st[e],n=st[e+1];et(t.bounds,n.rightCacheBounds,t.rightCacheBounds)}let f=0;for(let t=0;t<31;t++){let n=st[t],r=n.count,l=n.bounds,u=st[t+1].rightCacheBounds;r!==0&&(f===0?$e(l,ct):et(l,ct,ct)),f+=r;let d=0,p=0;f!==0&&(d=nt(ct)/a);let m=i-f;m!==0&&(p=nt(u)/a);let h=1+Ke*(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 ut(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 dt=class{constructor(){this.boundingData=new Float32Array(6)}};function ft(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 pt,mt,ht,gt,_t=2**32;function vt(e){return`count`in e?1:1+vt(e.left)+vt(e.right)}function yt(e,t,n){return pt=new Float32Array(n),mt=new Uint32Array(n),ht=new Uint16Array(n),gt=new Uint8Array(n),bt(e,t)}function bt(e,t){let n=e/4,r=e/2,i=`count`in t,a=t.boundingData;for(let e=0;e<6;e++)pt[n+e]=a[e];if(i)return t.buffer?(gt.set(new Uint8Array(t.buffer),e),e+t.buffer.byteLength):(mt[n+6]=t.offset,ht[r+14]=t.count,ht[r+15]=qe,e+32);{let{left:r,right:i,splitAxis:a}=t,o=bt(e+32,r),s=e/32,c=o/32-s;if(c>_t)throw Error(`MeshBVH: Cannot store relative child node offset greater than 32 bits.`);return mt[n+6]=c,mt[n+7]=a,bt(o,i)}}function xt(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 dt;return it(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=lt(e.boundingData,i,t,n,r,u),y=g.axis===-1?-1:ft(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,Qe(e.boundingData)),y=n+Math.max(1,Math.floor(r/2))}e.splitAxis=g.axis;let b=new dt,x=n,S=y-n;e.left=b,it(t,x,S,b.boundingData,m),v(b,x,S,m,a+1);let C=new dt,ee=y,te=r-S;return e.right=C,it(t,ee,te,C.boundingData,m),v(C,ee,te,m,a+1),e}}function St(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=xt(e,s,r.offset,r.count,t,o),a=vt(i),c=new n(32*a);return yt(0,i,c),c})}var Ct=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)}},P=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())}}},wt,Tt,Et=[],Dt=new Ct(()=>new De);function Ot(e,t,n,r,i,a){wt=Dt.getPrimitive(),Tt=Dt.getPrimitive(),Et.push(wt,Tt),P.setBuffer(e._roots[t]);let o=kt(0,e.geometry,n,r,i,a);P.clearBuffer(),Dt.releasePrimitive(wt),Dt.releasePrimitive(Tt),Et.pop(),Et.pop();let s=Et.length;return s>0&&(Tt=Et[s-1],wt=Et[s-2]),o}function kt(e,t,n,r,i=null,a=0,o=0){let{float32Array:s,uint16Array:c,uint32Array:l}=P,u=e*2;if(O(u,c)){let t=k(e,l),n=A(u,c);return D(N(e),s,wt),r(t,n,!1,o,a+e/8,wt)}{let u=j(e),d=M(e,l),f=u,p=d,m,h,g,_;if(i&&(g=wt,_=Tt,D(N(f),s,g),D(N(p),s,_),m=i(g),h=i(_),h<m)){f=d,p=u;let e=m;m=h,h=e,g=_}g||(g=wt,D(N(f),s,g));let v=O(f*2,c),y=n(g,v,m,o+1,a+f/8),b;if(y===2){let e=ee(f);b=r(e,te(f)-e,!0,o+1,a+f/8,g)}else b=y&&kt(f,t,n,r,i,a,o+1);if(b)return!0;_=Tt,D(N(p),s,_);let x=O(p*2,c),S=n(_,x,h,o+1,a+p/8),C;if(S===2){let e=ee(p);C=r(e,te(p)-e,!0,o+1,a+p/8,_)}else C=S&&kt(p,t,n,r,i,a,o+1);return!!C;function ee(e){let{uint16Array:t,uint32Array:n}=P,r=e*2;for(;!O(r,t);)e=j(e),r=e*2;return k(e,n)}function te(e){let{uint16Array:t,uint32Array:n}=P,r=e*2;for(;!O(r,t);)e=M(e,n),r=e*2;return k(e,n)+A(r,t)}}}var At=new P.constructor,jt=new P.constructor,Mt=new Ct(()=>new De),Nt=new De,Pt=new De,Ft=new De,It=new De,Lt=!1;function Rt(e,t,n,r){if(Lt)throw Error(`MeshBVH: Recursive calls to bvhcast not supported.`);Lt=!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++){At.setBuffer(i[e]),c=0;let t=Mt.getPrimitive();D(N(0),At.float32Array,t),t.applyMatrix4(l);for(let e=0,i=a.length;e<i&&(jt.setBuffer(a[e]),o=zt(0,0,n,l,r,s,c,0,0,t),jt.clearBuffer(),c+=a[e].byteLength/32,!o);e++);if(Mt.releasePrimitive(t),At.clearBuffer(),s+=i[e].byteLength/32,o)break}return Lt=!1,o}function zt(e,t,n,r,i,a=0,o=0,s=0,c=0,l=null,u=!1){let d,f;u?(d=jt,f=At):(d=At,f=jt);let p=d.float32Array,m=d.uint32Array,h=d.uint16Array,g=f.float32Array,_=f.uint32Array,v=f.uint16Array,y=e*2,b=t*2,x=O(y,h),S=O(b,v),C=!1;if(S&&x)C=u?i(k(t,_),A(t*2,v),k(e,m),A(e*2,h),c,o+t/8,s,a+e/8):i(k(e,m),A(e*2,h),k(t,_),A(t*2,v),s,a+e/8,c,o+t/8);else if(S){let l=Mt.getPrimitive();D(N(t),g,l),l.applyMatrix4(n);let d=j(e),f=M(e,m);D(N(d),p,Nt),D(N(f),p,Pt);let h=l.intersectsBox(Nt),_=l.intersectsBox(Pt);C=h&&zt(t,d,r,n,i,o,a,c,s+1,l,!u)||_&&zt(t,f,r,n,i,o,a,c,s+1,l,!u),Mt.releasePrimitive(l)}else{let d=j(t),f=M(t,_);D(N(d),g,Ft),D(N(f),g,It);let h=l.intersectsBox(Ft),v=l.intersectsBox(It);if(h&&v)C=zt(e,d,n,r,i,a,o,s,c+1,l,u)||zt(e,f,n,r,i,a,o,s,c+1,l,u);else if(h){if(x)C=zt(e,d,n,r,i,a,o,s,c+1,l,u);else{let t=Mt.getPrimitive();t.copy(Ft).applyMatrix4(n);let l=j(e),f=M(e,m);D(N(l),p,Nt),D(N(f),p,Pt);let h=t.intersectsBox(Nt),g=t.intersectsBox(Pt);C=h&&zt(d,l,r,n,i,o,a,c,s+1,t,!u)||g&&zt(d,f,r,n,i,o,a,c,s+1,t,!u),Mt.releasePrimitive(t)}}else if(v){if(x)C=zt(e,f,n,r,i,a,o,s,c+1,l,u);else{let t=Mt.getPrimitive();t.copy(It).applyMatrix4(n);let l=j(e),d=M(e,m);D(N(l),p,Nt),D(N(d),p,Pt);let h=t.intersectsBox(Nt),g=t.intersectsBox(Pt);C=h&&zt(f,l,r,n,i,o,a,c,s+1,t,!u)||g&&zt(f,d,r,n,i,o,a,c,s+1,t,!u),Mt.releasePrimitive(t)}}}return C}var Bt=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(;!O(r,n);)e=j(e),r=e*2;return k(e,t)},this.getRangeEnd=e=>{let r=e*2;for(;!O(r,n);)e=M(e,t),r=e*2;return k(e,t)+A(r,n)};let i=(e,r,a)=>{let o=O(r*2,n);if(!e(a,o,r)&&!o){let n=j(r),o=M(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=rt(o,t);return r(i,a,new Float32Array(e,o*4,6),n)}})}}},Vt=new De,Ht=new Float32Array(6),Ut=class{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...Ze,...e},`maxLeafSize`in e&&(console.warn(`BVH: "maxLeafSize" option has been deprecated. Use "targetLeafSize", instead.`),e={...e,targetLeafSize:e.maxLeafSize}),St(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,Ht,0);let[e,t,r,u,d,f]=Ht;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,Ht,0);let[e,t,a,o,s,c]=Ht,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)*Ye,n[h+2]=u,n[h+3]=p+(Math.abs(u)+p)*Ye,n[h+4]=d,n[h+5]=m+(Math.abs(d)+m)*Ye}return n}shiftPrimitiveOffsets(e){let t=this._indirectBuffer;if(t)for(let n=0,r=t.length;n<r;n++)t[n]+=e;else{let t=this._roots;for(let n=0;n<t.length;n++){let r=t[n],i=new Uint32Array(r),a=new Uint16Array(r),o=r.byteLength/32;for(let t=0;t<o;t++){let n=8*t;O(2*n,a)&&(i[n+6]+=e)}}}}traverse(e,t=0){Bt.setBVH(this,t),Bt.traverse(e),Bt.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(O(n,i)){let e=k(t,r),o=A(n,i);this.writePrimitiveRangeBounds(e,o,Ht,0),a.set(Ht,t)}else{let e=j(t),n=M(t,r);for(let r=0;r<3;r++){let i=a[e+r],o=a[e+r+3],s=a[n+r],c=a[n+r+3];a[t+r]=i<s?i:s,a[t+r+3]=o>c?o:c}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{D(0,new Float32Array(t),Vt),e.union(Vt)}),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=Ot(this,e,n,r,t,c),s)break;c+=i.byteLength/32}return s}bvhcast(e,t,n){let{intersectsRanges:r}=n;return Rt(this,e,t,r)}};function Wt(){return typeof SharedArrayBuffer<`u`}function Gt(e){return e.index?e.index.count:e.attributes.position.count}function Kt(e){return Gt(e)/3}function qt(e,t=ArrayBuffer){return e>65535?new Uint32Array(new t(4*e)):new Uint16Array(new t(2*e))}function Jt(e,t){if(!e.index){let n=e.attributes.position.count,r=qt(n,t.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer);e.setIndex(new xe(r,1));for(let e=0;e<n;e++)r[e]=e}}function Yt(e,t,n){let r=Gt(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 Xt(e,t){return e.groups.map(e=>({offset:e.start/t,count:e.count/t}))}function Zt(e,t,n){let r=Yt(e,t,n),i=Xt(e,n);if(!i.length)return[r];let a=[],o=r.offset,s=r.offset+r.count,c=Gt(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 Qt(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 $t=class extends Ut{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&&!Wt())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={...Ze,...t},t[Xe]||this.init(t)}init(e){let{geometry:t,primitiveStride:n}=this;if(e.indirect){let r=Qt(Zt(t,e.range,n),e.useSharedArrayBuffer);this._indirectBuffer=r}else Jt(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new De))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Zt(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw Error(`BVH: raycastObject3D() not implemented`)}},en=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}};en.prototype.setFromBox=(function(){let e=new E;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 tn=(function(){let e=new E,t=new E,n=new E;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}})(),nn=(function(){let e=new T,t=new E,n=new E;return function(r,i,a,o){tn(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}}})(),rn=(function(){let e=new E,t=new E,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}})(),an=[`x`,`y`,`z`],on=1e-15,sn=on*on;function cn(e){return Math.abs(e)<on}var ln=class extends ie{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=[,,,,].fill().map(()=>new E),this.satBounds=[,,,,].fill().map(()=>new en),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 rn(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<on?h<on||g<on?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):h<on?g<on?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):g<on&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}};ln.prototype.closestPointToSegment=(function(){let e=new E,t=new E,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]),nn(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)}})(),ln.prototype.intersectsTriangle=(function(){let e=new ln,t=new en,n=new en,r=new E,i=new E,a=new E,o=new E,s=new p,c=new p,l=new E,u=new T,d=new T;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 cn(o)?cn(s)?f(e,t,n,i):(n&&(n.start.copy(a.start),n.end.copy(a.start)),e.containsPoint(a.start)):cn(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 cn(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)<sn&&(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(cn(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:cn(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)<sn&&(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);cn(g)&&(g=0),cn(_)&&(_=0),cn(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),ee=p.distanceToPoint(t.c);cn(S)&&(S=0),cn(C)&&(C=0),cn(ee)&&(ee=0);let te=S*C,ne=S*ee;if(te>0&&ne>0)return!1;i.copy(p.normal),a.copy(m.normal);let w=i.cross(a),re=0,ie=Math.abs(w.x),ae=Math.abs(w.y);ae>ie&&(ie=ae,re=1),Math.abs(w.z)>ie&&(re=2);let oe=an[re],se=this.a[oe],ce=this.b[oe],le=this.c[oe],ue=t.a[oe],de=t.b[oe],fe=t.c[oe];if(h(this,se,ce,le,b,x,g,_,v,u,s)||h(t,ue,de,fe,te,ne,S,C,ee,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)}})(),ln.prototype.distanceToPoint=(function(){let e=new E;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),ln.prototype.distanceToTriangle=(function(){let e=new E,t=new E,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]),nn(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 F=class{constructor(e,t,n){this.isOrientedBox=!0,this.min=new E,this.max=new E,this.matrix=new f,this.invMatrix=new f,this.points=Array(8).fill().map(()=>new E),this.satAxes=[,,,].fill().map(()=>new E),this.satBounds=[,,,].fill().map(()=>new en),this.alignedSatBounds=[,,,].fill().map(()=>new en),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}};F.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}})(),F.prototype.intersectsBox=(function(){let e=new en;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}})(),F.prototype.intersectsTriangle=(function(){let e=new ln,t=[,,,],n=new en,r=new en,i=new E;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}})(),F.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}})(),F.prototype.distanceToPoint=(function(){let e=new E;return function(t){return this.closestPointToPoint(t,e),t.distanceTo(e)}})(),F.prototype.distanceToBox=(function(){let e=[`x`,`y`,`z`],t=Array(12).fill().map(()=>new p),n=Array(12).fill().map(()=>new p),r=new E,i=new E;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];nn(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 un=new class extends Ct{constructor(){super(()=>new ln)}},dn=new E,fn=new E;function pn(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=>(dn.copy(t).clamp(e.min,e.max),dn.distanceToSquared(t)),intersectsBounds:(e,t,n)=>n<s&&n<o,intersectsTriangle:(e,n)=>{e.closestPointToPoint(t,dn);let r=t.distanceToSquared(dn);return r<s&&(fn.copy(dn),s=r,c=n),r<a}}),s===1/0)return null;let l=Math.sqrt(s);return n.point?n.point.copy(fn):n.point=fn.clone(),n.distance=l,n.faceIndex=c,n}var mn=!0,hn=new E,gn=new E,_n=new E,vn=new T,yn=new T,bn=new T,xn=new E,Sn=new E,Cn=new E,wn=new E;function Tn(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 En(e,t,n,r,i,a,o,s,c,l,u){hn.fromBufferAttribute(t,a),gn.fromBufferAttribute(t,o),_n.fromBufferAttribute(t,s);let d=Tn(e,hn,gn,_n,wn,c,l,u);if(d){if(r){vn.fromBufferAttribute(r,a),yn.fromBufferAttribute(r,o),bn.fromBufferAttribute(r,s),d.uv=new T;let e=ie.getInterpolation(wn,hn,gn,_n,vn,yn,bn,d.uv);mn||(d.uv=e)}if(i){vn.fromBufferAttribute(i,a),yn.fromBufferAttribute(i,o),bn.fromBufferAttribute(i,s),d.uv1=new T;let e=ie.getInterpolation(wn,hn,gn,_n,vn,yn,bn,d.uv1);mn||(d.uv1=e)}if(n){xn.fromBufferAttribute(n,a),Sn.fromBufferAttribute(n,o),Cn.fromBufferAttribute(n,s),d.normal=new E;let t=ie.getInterpolation(wn,hn,gn,_n,xn,Sn,Cn,d.normal);d.normal.dot(e.direction)>0&&d.normal.multiplyScalar(-1),mn||(d.normal=t)}let t={a,b:o,c:s,normal:new E,materialIndex:0};if(ie.getNormal(hn,gn,_n,t.normal),d.face=t,d.faceIndex=a,mn){let e=new E;ie.getBarycoord(wn,hn,gn,_n,e),d.barycoord=e}}return d}function Dn(e){return e&&e.isMaterial?e.side:e}function On(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=Dn(t[v]),s=En(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=Dn(t),s=En(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 I(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 kn(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,l=r+i;e<l;e++)On(c,t,n,e,a,o,s)}function An(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=On(s,t,n,e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function jn(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,I(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Mn(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(e,n,a=!1){let l=e*2;if(O(l,s)){let t=k(e,o),n=A(l,s),a=1/0,u=1/0,d=1/0,f=-1/0,p=-1/0,m=-1/0;for(let e=3*t,o=3*(t+n);e<o;e++){let t=r[e],n=i.getX(t),o=i.getY(t),s=i.getZ(t);n<a&&(a=n),n>f&&(f=n),o<u&&(u=o),o>p&&(p=o),s<d&&(d=s),s>m&&(m=s)}return c[e+0]!==a||c[e+1]!==u||c[e+2]!==d||c[e+3]!==f||c[e+4]!==p||c[e+5]!==m?(c[e+0]=a,c[e+1]=u,c[e+2]=d,c[e+3]=f,c[e+4]=p,c[e+5]=m,!0):!1}{let r=j(e),i=M(e,o),s=a,l=!1,u=!1;if(t){if(!s){let e=r/8+n/32,a=i/8+n/32;l=t.has(e),u=t.has(a),s=!l&&!u}}else l=!0,u=!0;let f=s||l,p=s||u,m=!1;f&&(m=d(r,n,s));let h=!1;p&&(h=d(i,n,s));let g=m||h;if(g)for(let t=0;t<3;t++){let n=r+t,a=i+t,o=c[n],s=c[n+3],l=c[a],u=c[a+3];c[e+t]=o<l?o:l,c[e+t+3]=s>u?s:u}return g}}}function Nn(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 Pn(e,t,n,r,i,a,o,s){let{geometry:c,_indirectBuffer:l}=e;for(let e=r,u=r+i;e<u;e++)On(c,t,n,l?l[e]:e,a,o,s)}function Fn(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=On(s,t,n,c?c[e]:e,null,a,o),r&&r.distance<l&&(u=r,l=r.distance)}return u}function In(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),I(o,e*3,c,l),o.needsUpdate=!0,r(o,e,i,a))return!0}return!1}function Ln(e,t,n,r,i,a,o){P.setBuffer(e._roots[t]),Rn(0,e,n,r,i,a,o),P.clearBuffer()}function Rn(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=P,u=e*2;if(O(u,c))kn(t,n,r,k(e,l),A(u,c),i,a,o);else{let c=j(e);Nn(c,s,r,a,o)&&Rn(c,t,n,r,i,a,o);let u=M(e,l);Nn(u,s,r,a,o)&&Rn(u,t,n,r,i,a,o)}}var zn=[`x`,`y`,`z`];function Bn(e,t,n,r,i,a){P.setBuffer(e._roots[t]);let o=Vn(0,e,n,r,i,a);return P.clearBuffer(),o}function Vn(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=P,l=e*2;if(O(l,s))return An(t,n,r,k(e,c),A(l,s),i,a);{let s=rt(e,c),l=zn[s],u=r.direction[l]>=0,d,f;u?(d=j(e),f=M(e,c)):(d=M(e,c),f=j(e));let p=Nn(d,o,r,i,a)?Vn(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=Nn(f,o,r,i,a)?Vn(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var Hn=new De,Un=new ln,Wn=new ln,Gn=new f,Kn=new F,qn=new F;function Jn(e,t,n,r){P.setBuffer(e._roots[t]);let i=Yn(0,e,n,r);return P.clearBuffer(),i}function Yn(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=P,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),Kn.set(n.boundingBox.min,n.boundingBox.max,r),i=Kn),O(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=k(e,s),m=A(c,o);if(Gn.copy(r).invert(),n.boundsTree)return D(N(e),a,qn),qn.matrix.copy(Gn),qn.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>qn.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(I(Wn,t,l,u),Wn.needsUpdate=!0,e.intersectsTriangle(Wn))return!0;return!1}});{let e=Kt(n);for(let t=p*3,n=(m+p)*3;t<n;t+=3){I(Un,t,l,u),Un.a.applyMatrix4(Gn),Un.b.applyMatrix4(Gn),Un.c.applyMatrix4(Gn),Un.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(I(Wn,t,d,f),Wn.needsUpdate=!0,Un.intersectsTriangle(Wn))return!0}}}else{let o=j(e),c=M(e,s);return D(N(o),a,Hn),!!(i.intersectsBox(Hn)&&Yn(o,t,n,r,i)||(D(N(c),a,Hn),i.intersectsBox(Hn)&&Yn(c,t,n,r,i)))}}var Xn=new f,Zn=new F,Qn=new F,$n=new E,er=new E,tr=new E,nr=new E;function rr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),Zn.set(t.boundingBox.min,t.boundingBox.max,n),Zn.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=un.getPrimitive(),p=un.getPrimitive(),m=$n,h=er,g=null,_=null;i&&(g=tr,_=nr);let v=1/0,y=null,b=null;return Xn.copy(n).invert(),Qn.matrix.copy(Xn),e.shapecast({boundsTraverseOrder:e=>Zn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(Qn.min.copy(e.min),Qn.max.copy(e.max),Qn.needsUpdate=!0),!0),intersectsRange:(e,r)=>{if(t.boundsTree)return t.boundsTree.shapecast({boundsTraverseOrder:e=>Qn.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o,intersectsRange:(t,i)=>{for(let o=t,s=t+i;o<s;o++){I(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++){I(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=Kt(t);for(let t=0,o=i;t<o;t++){I(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++){I(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}}}}}),un.releasePrimitive(f),un.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(Xn),h.applyMatrix4(Xn),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function ir(e,t=null){t&&Array.isArray(t)&&(t=new Set(t));let n=e.geometry,r=n.index?n.index.array:null,i=n.attributes.position,a,o,s,c,l=0,u=e._roots;for(let e=0,t=u.length;e<t;e++)a=u[e],o=new Uint32Array(a),s=new Uint16Array(a),c=new Float32Array(a),d(0,l),l+=a.byteLength;function d(n,a,l=!1){let u=n*2;if(O(u,s)){let t=k(n,o),a=A(u,s),l=1/0,d=1/0,f=1/0,p=-1/0,m=-1/0,h=-1/0;for(let n=t,o=t+a;n<o;n++){let t=3*e.resolveTriangleIndex(n);for(let e=0;e<3;e++){let n=t+e;n=r?r[n]:n;let a=i.getX(n),o=i.getY(n),s=i.getZ(n);a<l&&(l=a),a>p&&(p=a),o<d&&(d=o),o>m&&(m=o),s<f&&(f=s),s>h&&(h=s)}}return c[n+0]!==l||c[n+1]!==d||c[n+2]!==f||c[n+3]!==p||c[n+4]!==m||c[n+5]!==h?(c[n+0]=l,c[n+1]=d,c[n+2]=f,c[n+3]=p,c[n+4]=m,c[n+5]=h,!0):!1}{let e=j(n),r=M(n,o),i=l,s=!1,u=!1;if(t){if(!i){let n=e/8+a/32,o=r/8+a/32;s=t.has(n),u=t.has(o),i=!s&&!u}}else s=!0,u=!0;let f=i||s,p=i||u,m=!1;f&&(m=d(e,a,i));let h=!1;p&&(h=d(r,a,i));let g=m||h;if(g)for(let t=0;t<3;t++){let i=e+t,a=r+t,o=c[i],s=c[i+3],l=c[a],u=c[a+3];c[n+t]=o<l?o:l,c[n+t+3]=s>u?s:u}return g}}}function ar(e,t,n,r,i,a,o){P.setBuffer(e._roots[t]),or(0,e,n,r,i,a,o),P.clearBuffer()}function or(e,t,n,r,i,a,o){let{float32Array:s,uint16Array:c,uint32Array:l}=P,u=e*2;if(O(u,c))Pn(t,n,r,k(e,l),A(u,c),i,a,o);else{let c=j(e);Nn(c,s,r,a,o)&&or(c,t,n,r,i,a,o);let u=M(e,l);Nn(u,s,r,a,o)&&or(u,t,n,r,i,a,o)}}var sr=[`x`,`y`,`z`];function cr(e,t,n,r,i,a){P.setBuffer(e._roots[t]);let o=lr(0,e,n,r,i,a);return P.clearBuffer(),o}function lr(e,t,n,r,i,a){let{float32Array:o,uint16Array:s,uint32Array:c}=P,l=e*2;if(O(l,s))return Fn(t,n,r,k(e,c),A(l,s),i,a);{let s=rt(e,c),l=sr[s],u=r.direction[l]>=0,d,f;u?(d=j(e),f=M(e,c)):(d=M(e,c),f=j(e));let p=Nn(d,o,r,i,a)?lr(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=Nn(f,o,r,i,a)?lr(f,t,n,r,i,a):null;return p&&m?p.distance<=m.distance?p:m:p||m||null}}var ur=new De,dr=new ln,fr=new ln,pr=new f,mr=new F,hr=new F;function gr(e,t,n,r){P.setBuffer(e._roots[t]);let i=_r(0,e,n,r);return P.clearBuffer(),i}function _r(e,t,n,r,i=null){let{float32Array:a,uint16Array:o,uint32Array:s}=P,c=e*2;if(i===null&&(n.boundingBox||n.computeBoundingBox(),mr.set(n.boundingBox.min,n.boundingBox.max,r),i=mr),O(c,o)){let i=t.geometry,l=i.index,u=i.attributes.position,d=n.index,f=n.attributes.position,p=k(e,s),m=A(c,o);if(pr.copy(r).invert(),n.boundsTree)return D(N(e),a,hr),hr.matrix.copy(pr),hr.needsUpdate=!0,n.boundsTree.shapecast({intersectsBounds:e=>hr.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(I(fr,3*t.resolveTriangleIndex(n),l,u),fr.needsUpdate=!0,e.intersectsTriangle(fr))return!0;return!1}});{let e=Kt(n);for(let n=p,r=m+p;n<r;n++){I(dr,3*t.resolveTriangleIndex(n),l,u),dr.a.applyMatrix4(pr),dr.b.applyMatrix4(pr),dr.c.applyMatrix4(pr),dr.needsUpdate=!0;for(let t=0,n=e*3;t<n;t+=3)if(I(fr,t,d,f),fr.needsUpdate=!0,dr.intersectsTriangle(fr))return!0}}}else{let o=j(e),c=M(e,s);return D(N(o),a,ur),!!(i.intersectsBox(ur)&&_r(o,t,n,r,i)||(D(N(c),a,ur),i.intersectsBox(ur)&&_r(c,t,n,r,i)))}}var vr=new f,yr=new F,br=new F,xr=new E,Sr=new E,Cr=new E,wr=new E;function Tr(e,t,n,r={},i={},a=0,o=1/0){t.boundingBox||t.computeBoundingBox(),yr.set(t.boundingBox.min,t.boundingBox.max,n),yr.needsUpdate=!0;let s=e.geometry,c=s.attributes.position,l=s.index,u=t.attributes.position,d=t.index,f=un.getPrimitive(),p=un.getPrimitive(),m=xr,h=Sr,g=null,_=null;i&&(g=Cr,_=wr);let v=1/0,y=null,b=null;return vr.copy(n).invert(),br.matrix.copy(vr),e.shapecast({boundsTraverseOrder:e=>yr.distanceToBox(e),intersectsBounds:(e,t,n)=>n<v&&n<o&&(t&&(br.min.copy(e.min),br.max.copy(e.max),br.needsUpdate=!0),!0),intersectsRange:(r,i)=>{if(t.boundsTree){let s=t.boundsTree;return s.shapecast({boundsTraverseOrder:e=>br.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);I(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);I(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=Kt(t);for(let t=0,s=o;t<s;t++){I(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);I(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}}}}}),un.releasePrimitive(f),un.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(vr),h.applyMatrix4(vr),i.distance=h.sub(i.point).length(),i.faceIndex=b),r)}function Er(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 Dr=new F,Or=new ee,kr=new E,Ar=new f,jr=new E,Mr=[`getX`,`getY`,`getZ`],Nr=class e extends $t{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,[Xe]:!0});if(s._roots=a,s._indirectBuffer=o||null,r.setIndex){let e=n.getIndex();if(e===null){let e=new xe(t.index,1,!1);n.setIndex(e)}else e.array!==i&&(e.array.set(i),e.needsUpdate=!0)}return s;function c(e){for(let t=0;t<e.length;t++){let n=e[t],r=new Uint32Array(n),i=new Uint16Array(n);for(let e=0,t=n.byteLength/32;e<t;e++){let t=8*e;O(2*t,i)||(r[t+6]=r[t+6]/8-e)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn(`MeshBVH: "maxLeafTris" option has been deprecated. Use "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[Mr[e]](c),i=a[Mr[e]](l),o=a[Mr[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)*Ye}}return n}raycastObject3D(e,t,n=[]){let{material:r}=e;if(r===void 0)return;Ar.copy(e.matrixWorld).invert(),Or.copy(t.ray).applyMatrix4(Ar),jr.setFromMatrixScale(e.matrixWorld),kr.copy(Or.direction).multiply(jr);let i=kr.length(),a=t.near/i,o=t.far/i;if(t.firstHitOnly===!0){let i=this.raycastFirst(Or,r,a,o);i=Er(i,e,t),i&&n.push(i)}else{let i=this.raycast(Or,r,a,o);for(let r=0,a=i.length;r<a;r++){let a=Er(i[r],e,t);a&&n.push(a)}}return n}refit(e=null){return(this.indirect?ir:Mn)(this,e)}raycast(e,t=0,n=0,r=1/0){let i=this._roots,a=[],o=this.indirect?ar:Ln;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?cr:Bn;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?gr:Jn;for(let a=0,o=r.length;a<o&&(n=i(this,a,e,t),!n);a++);return n}shapecast(e){let t=un.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?In:jn});return un.releasePrimitive(t),n}bvhcast(t,n,r){let{intersectsRanges:i,intersectsTriangles:a}=r,o=un.getPrimitive(),s=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?e=>{let t=this.resolveTriangleIndex(e);I(o,t*3,s,c)}:e=>{I(o,e*3,s,c)},u=un.getPrimitive(),d=t.geometry.index,f=t.geometry.attributes.position,p=t.indirect?e=>{let n=t.resolveTriangleIndex(e);I(u,n*3,d,f)}:e=>{I(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 Dr.set(e.min,e.max,t),Dr.needsUpdate=!0,this.shapecast({intersectsBounds:e=>Dr.intersectsBox(e),intersectsTriangle:e=>Dr.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?Tr:rr)(this,e,t,n,r,i,a)}closestPointToPoint(e,t={},n=0,r=1/0){return pn(this,e,t,n,r)}};function Pr(e){switch(e){case 1:return`R`;case 2:return`RG`;case 3:return`RGBA`;case 4:return`RGBA`}throw Error()}function Fr(e){switch(e){case 1:return ne;case 2:return u;case 3:return d;case 4:return d}}function Ir(e){switch(e){case 1:return _;case 2:return te;case 3:return ke;case 4:return ke}}var Lr=class extends ze{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=Ne;break;case Int8Array:case Int16Array:case Int32Array:l=ve}let d,f,p,m,h=Pr(i);switch(l){case b:p=1,f=Fr(i),o&&c===1?(m=s,h+=`8`,s===Uint8Array?d=Ee:(d=pe,h+=`_SNORM`)):(m=Float32Array,h+=`32F`,d=b);break;case ve:h+=c*8+`I`,p=o?2**(s.BYTES_PER_ELEMENT*8-1):1,f=Ir(i),c===1?(m=Int8Array,d=pe):c===2?(m=Int16Array,d=we):(m=Int32Array,d=ve);break;case Ne:h+=c*8+`UI`,p=o?2**(s.BYTES_PER_ELEMENT*8-1):1,f=Ir(i),c===1?(m=Uint8Array,d=Ee):c===2?(m=Uint16Array,d=se):(m=Uint32Array,d=Ne)}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}},Rr=class extends Lr{constructor(){super(),this._forcedType=Ne}},zr=class extends Lr{constructor(){super(),this._forcedType=b}},Br=class{constructor(){this.index=new Rr,this.position=new zr,this.bvhBounds=new ze,this.bvhContents=new ze,this._cachedIndexAttr=null,this.index.overrideItemSize=3}updateFrom(e){let{geometry:t}=e;if(Hr(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=qt(Gt(t));this._cachedIndexAttr=new xe(e,1,!1)}}Vr(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 Vr(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 Hr(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=N(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(O(n,a)){let r=A(n,a),i=k(t,o),s=Je|r;p[e*2+0]=s,p[e*2+1]=i}else{let n=o[t+6],r=rt(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=te,n.type=Ne,n.internalFormat=`RG32UI`,n.minFilter=S,n.magFilter=S,n.generateMipmaps=!1,n.needsUpdate=!0,n.dispose()}var Ur=`
|
|
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
|
+
`,Wr=`
|
|
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
|
+
`,Gr=`
|
|
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 Kr(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 qr(e,t=null){let n=e.array.constructor,r=e.normalized,i=e.itemSize,a=t===null?e.count:t;return new xe(new n(i*a),i,r)}function Jr(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 Yr(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 Xr(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getIndex().count;return t}function Zr(e){let t=0;for(let n=0,r=e.length;n<r;n++)t+=e[n].getAttribute(`position`).count;return t}function Qr(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 $r(e,t={},n=new me){let{useGroups:r=!1,forceUpdate:i=!1,skipAssigningAttributes:a=[],overwriteIndex:o=!0}=t;Yr(e);let s=e[0].index!==null,c=s?Xr(e):-1,l=Zr(e);if(Qr(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 xe(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,qr(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 Kr(u,c,s)}s+=u.count}}}function ei(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 xe(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 ti(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 xe(new Float32Array(t*2),2,!1))}if(!e.attributes.uv2&&t&&t.includes(`uv2`)){let t=e.attributes.position.count;e.setAttribute(`uv2`,new xe(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 xe(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 xe(n,4))}}function ni(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 ri(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 ii(e){let t=e.skeleton;return t?(t.boneTexture||t.computeBoneTexture(),`${ni(t.boneTexture.image.data.buffer)}_${t.boneTexture.uuid}`):null}var ai=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=ri(t),this.primitiveCount=n,this.skeletonHash=ii(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===ri(t)&&this.skeletonHash===ii(e)&&this.primitiveCount===n)}},oi=new E,si=new E,ci=new E,li=new le,ui=new E,di=new E,fi=new le,pi=new le,mi=new f,hi=new f;function gi(e,t,n){let r=e.skeleton,i=e.geometry,a=r.bones,o=r.boneInverses;fi.fromBufferAttribute(i.attributes.skinIndex,t),pi.fromBufferAttribute(i.attributes.skinWeight,t),mi.elements.fill(0);for(let e=0;e<4;e++){let t=pi.getComponent(e);if(t!==0){let n=fi.getComponent(e);hi.multiplyMatrices(a[n].matrixWorld,o[n]),vi(mi,hi,t)}}return mi.multiply(e.bindMatrix).premultiply(e.bindMatrixInverse),n.transformDirection(mi),n}function _i(e,t,n,r,i){ui.set(0,0,0);for(let a=0,o=e.length;a<o;a++){let o=t[a],s=e[a];o!==0&&(di.fromBufferAttribute(s,r),n?ui.addScaledVector(di,o):ui.addScaledVector(di.sub(i),o))}i.add(ui)}function vi(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 yi(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 bi(e,t={},n=new me){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`,qr(s.position)),a&&!c.normal&&s.normal&&n.setAttribute(`normal`,qr(s.normal)),o&&!c.tangent&&s.tangent&&n.setAttribute(`tangent`,qr(s.tangent)),Jr(r.index,n.index),Jr(s.position,c.position),a&&Jr(s.normal,c.normal),o&&Jr(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++)oi.fromBufferAttribute(u,t),d&&si.fromBufferAttribute(d,t),f&&(li.fromBufferAttribute(f,t),ci.fromBufferAttribute(f,t)),_&&(p&&_i(p,_,g,t,oi),m&&_i(m,_,g,t,si),h&&_i(h,_,g,t,ci)),e.isSkinnedMesh&&(e.applyBoneTransform(t,oi),d&&gi(e,t,si),f&&gi(e,t,ci)),i&&oi.applyMatrix4(e.matrixWorld),c.position.setXYZ(t,oi.x,oi.y,oi.z),d&&(i&&si.applyNormalMatrix(v),c.normal.setXYZ(t,si.x,si.y,si.z)),f&&(i&&ci.transformDirection(e.matrixWorld),c.tangent.setXYZW(t,ci.x,ci.y,ci.z,li.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,qr(s[r])),Jr(s[r],c[r]),Kr(s[r],c[r]))}return e.matrixWorld.determinant()<0&&yi(n),n}var xi=class extends me{constructor(){super(),this.version=0,this.hash=null,this._diff=new ai}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&&!Jr(i,a))return!1}return!0}updateFrom(e,t){let n=this._diff;return n.didChange(e)?(bi(e,t,this),n.updateFrom(e),this.version++,this.hash=`${this.uuid}_${this.version}`,!0):!1}};function Si(e,t){for(let n=0,r=e.length;n<r;n++)e[n].traverseVisible(e=>{e.isMesh&&t(e)})}function Ci(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 wi(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 xe(new Float32Array,4,!1))}else $r(e,n,t);for(let e in t.attributes)t.attributes[e].needsUpdate=!0}var Ti=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 Ve,t=new me;t.setAttribute(`position`,new xe(new Float32Array(9),3)),this._dummyMesh=new v(t,e)}return this._dummyMesh}_getMeshes(){let e=[];return Si(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 xi,e.set(o,s)),s.updateFrom(a,r)&&this.generateMissingAttributes&&ti(s,this.attributes)}n.forEach(t=>{e.delete(t)})}setObjects(e){this.objects=Array.isArray(e)?[...e]:[e]}generate(e=new me){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)}wi(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:Ci(a),geometry:e}}};function Ei(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 Di(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 Oi=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 me,this.staticGeometryGenerator=new Ti(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=Ei(o),{lights:l,iesTextures:u}=Di(i);if(s&&(ei(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 Nr(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}}},ki=class extends Fe{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}},Ai=class extends ki{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 ji(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 Mi(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 Ni=`
|
|
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
|
+
${ji(1)}
|
|
394
|
+
${ji(2)}
|
|
395
|
+
${ji(3)}
|
|
396
|
+
${ji(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
|
+
`,Pi=`
|
|
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
|
+
`,Fi=`
|
|
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
|
+
${Mi(1)}
|
|
527
|
+
${Mi(2)}
|
|
528
|
+
${Mi(3)}
|
|
529
|
+
${Mi(4)}
|
|
530
530
|
|
|
531
|
-
`,
|
|
531
|
+
`,Ii=class extends ki{constructor(){super({blending:0,uniforms:{resolution:{value:new T}},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
|
-
${Mi}
|
|
543
542
|
${Ni}
|
|
543
|
+
${Pi}
|
|
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
|
+
`})}},Li=class{generate(e,t=256){let n=new Oe(t,t,{type:b,format:d,minFilter:S,magFilter:S,generateMipmaps:!1}),r=e.getRenderTarget();e.setRenderTarget(n);let i=new oe(new Ii);return i.material.resolution.set(t,t),i.render(e),e.setRenderTarget(r),i.dispose(),n}},Ri=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}},zi=class{constructor(){this.bokehSize=0,this.apertureBlades=0,this.apertureRotation=0,this.focusDistance=10,this.anamorphicRatio=1}updateFrom(e){e instanceof Ri?(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 Bi(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 Vi(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 Hi(e,t,n){return .2126*e+.7152*t+.0722*n}function Ui(e,t=ye){let n=e.clone();n.source=new je({...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 Wi=class{constructor(){let t=new ze(Bi(new Float32Array([0,0,0,0])),1,1);t.type=ye,t.format=d,t.minFilter=m,t.magFilter=m,t.wrapS=e,t.wrapT=e,t.generateMipmaps=!1,t.needsUpdate=!0;let n=new ze(Bi(new Float32Array([0,1])),1,2);n.type=ye,n.format=ne,n.minFilter=m,n.magFilter=m,n.generateMipmaps=!1,n.needsUpdate=!0;let r=new ze(Bi(new Float32Array([0,0,1,1])),2,2);r.type=ye,r.format=ne,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=Ui(t);n.wrapS=e,n.wrapT=w;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=Hi(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=Vi(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=Vi(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}},Gi=6,Ki=0,qi=1,Ji=2,Yi=3,Xi=4,Zi=new E,L=new E,Qi=new f,$i=new s,ea=new E,ta=new E,na=new E(0,1,0),ra=class{constructor(){let e=new ze(new Float32Array(4),1,1);e.format=d,e.type=b,e.wrapS=w,e.wrapT=w,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*Gi,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*Gi*4,o=0;for(let e=0;e<24;e++)a[i+e]=0;r.getWorldPosition(L),a[i+o++]=L.x,a[i+o++]=L.y,a[i+o++]=L.z;let s=Ki;if(r.isRectAreaLight&&r.isCircular?s=qi:r.isSpotLight?s=Ji:r.isDirectionalLight?s=Yi:r.isPointLight&&(s=Xi),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($i),r.isRectAreaLight)Zi.set(r.width,0,0).applyQuaternion($i),a[i+o++]=Zi.x,a[i+o++]=Zi.y,a[i+o++]=Zi.z,o++,L.set(0,r.height,0).applyQuaternion($i),a[i+o++]=L.x,a[i+o++]=L.y,a[i+o++]=L.z,a[i+o++]=Zi.cross(L).length()*(r.isCircular?Math.PI/4:1);else if(r.isSpotLight){let e=r.radius||0;ea.setFromMatrixPosition(r.matrixWorld),ta.setFromMatrixPosition(r.target.matrixWorld),Qi.lookAt(ea,ta,na),$i.setFromRotationMatrix(Qi),Zi.set(1,0,0).applyQuaternion($i),a[i+o++]=Zi.x,a[i+o++]=Zi.y,a[i+o++]=Zi.z,o++,L.set(0,1,0).applyQuaternion($i),a[i+o++]=L.x,a[i+o++]=L.y,a[i+o++]=L.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=Zi.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=Zi.setFromMatrixPosition(r.matrixWorld),t=L.setFromMatrixPosition(r.target.matrixWorld);ta.subVectors(e,t).normalize(),a[i+o++]=ta.x,a[i+o++]=ta.y,a[i+o++]=ta.z}}this.count=e.length;let o=ni(a.buffer);return this.hash!==o&&(this.hash=o,n.needsUpdate=!0,!0)}};function ia(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 aa=class extends ae{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),ia(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 zr;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),ia(n.image.data,a,o,4,i)}this.dispose(),this.needsUpdate=!0}},oa=class extends aa{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 sa(e,t){return e.uuid<t.uuid?1:e.uuid>t.uuid?-1:0}function ca(e){return`${e.source.uuid}:${e.colorSpace}`}function la(e){let t=new Set,n=[];for(let r=0,i=e.length;r<i;r++){let i=e[r],a=ca(i);t.has(a)||(t.add(a),n.push(i))}return n}function ua(e){let t=e.map(e=>e.iesMap||null).filter(e=>e),n=new Set(t);return Array.from(n).sort(sa)}function da(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 la(Array.from(t)).sort(sa)}function fa(e){let t=[];return e.traverse(e=>{e.visible&&(e.isRectAreaLight||e.isSpotLight||e.isPointLight||e.isDirectionalLight)&&t.push(e)}),t.sort(sa)}var pa=188,ma=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={}}},ha=class extends ze{constructor(){super(new Float32Array(4),1,1),this.format=d,this.type=b,this.wrapS=w,this.wrapT=w,this.minFilter=S,this.magFilter=S,this.generateMipmaps=!1,this.features=new ma}updateFrom(e,t){function n(e,t,n=-1){if(t in e&&e[t]){let n=ca(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[ca(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<pa;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+=pa;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=ni(d.buffer);return this.hash!==f&&(this.hash=f,this.needsUpdate=!0,!0)}},ga=new Be;function _a(e){return e?`${e.uuid}:${e.version}`:null}function va(e,t){for(let n in t)n in e&&(e[n]=t[n])}var ya=class extends fe{constructor(t,n,r){let i={format:d,type:Ee,minFilter:m,magFilter:m,wrapS:e,wrapT:e,generateMipmaps:!1,...r};super(t,n,1,i),va(this.texture,i),this.texture.setTextures=(...e)=>{this.setTextures(...e)},this.hashes=[null];let a=new oe(new ba);this.fsQuad=a}setTextures(e,t,n=this.width,r=this.height){let i=e.getRenderTarget(),a=e.toneMapping,o=e.getClearAlpha();e.getClearColor(ga);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=_a(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(ga,o),e.setRenderTarget(i),e.toneMapping=a,u}dispose(){super.dispose(),this.fsQuad.dispose()}},ba=class extends Fe{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 xa(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 Sa=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&&(xa(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}}},Ca=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 Sa(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()}}},wa=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)}},Ta=class extends ze{constructor(e=1,t=1,n=8){super(new Float32Array(1),1,1,d,b),this.minFilter=S,this.magFilter=S,this.strata=n,this.sampler=null,this.generator=new wa,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 Ca(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 Ea(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 Da(e,t){e.fill(0);for(let n=0;n<t;n++)e[n]=1}var Oa=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}},ka=class{constructor(){this.random=Math.random,this.sigma=1.5,this.size=64,this.majorityPointsRatio=.1,this.samples=new Oa(1),this.savedSamples=new Oa(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;Da(o,a),Ea(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 Aa(e){return e>=3?4:e}function ja(e){switch(e){case 1:return ne;case 2:return u;default:return d}}var Ma=class extends ze{constructor(e=64,t=1){super(new Float32Array(4),1,1,d,b),this.minFilter=S,this.magFilter=S,this.size=e,this.channels=t,this.update()}update(){let e=this.channels,t=this.size,n=new ka;n.channels=e,n.size=t;let r=Aa(e),i=ja(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}},Na=`
|
|
570
570
|
|
|
571
571
|
struct PhysicalCamera {
|
|
572
572
|
|
|
@@ -578,7 +578,7 @@ struct BVH {
|
|
|
578
578
|
|
|
579
579
|
};
|
|
580
580
|
|
|
581
|
-
`,
|
|
581
|
+
`,Pa=`
|
|
582
582
|
|
|
583
583
|
struct EquirectHdrInfo {
|
|
584
584
|
|
|
@@ -590,7 +590,7 @@ struct BVH {
|
|
|
590
590
|
|
|
591
591
|
};
|
|
592
592
|
|
|
593
|
-
`,
|
|
593
|
+
`,Fa=`
|
|
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
|
+
`,Ia=`
|
|
680
680
|
|
|
681
681
|
struct Material {
|
|
682
682
|
|
|
@@ -885,7 +885,7 @@ struct BVH {
|
|
|
885
885
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
|
-
`,
|
|
888
|
+
`,La=`
|
|
889
889
|
|
|
890
890
|
struct SurfaceRecord {
|
|
891
891
|
|
|
@@ -947,7 +947,7 @@ struct BVH {
|
|
|
947
947
|
vec3 color;
|
|
948
948
|
};
|
|
949
949
|
|
|
950
|
-
`,
|
|
950
|
+
`,Ra=`
|
|
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
|
+
`,za=`
|
|
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
|
+
`,Ba=`
|
|
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
|
+
`,Va=`
|
|
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
|
+
`,Ha=`
|
|
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
|
+
`,Ua=`
|
|
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
|
+
`,Wa=`
|
|
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
|
+
`,Ga=`
|
|
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
|
+
`,Ka=`
|
|
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
|
+
`,qa=`
|
|
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
|
+
`,Ja=`
|
|
1805
1805
|
|
|
1806
1806
|
// diffuse
|
|
1807
1807
|
float diffuseEval( vec3 wo, vec3 wi, vec3 wh, SurfaceRecord surf, inout vec3 color ) {
|
|
@@ -2239,7 +2239,7 @@ struct BVH {
|
|
|
2239
2239
|
|
|
2240
2240
|
}
|
|
2241
2241
|
|
|
2242
|
-
`,
|
|
2242
|
+
`,Ya=`
|
|
2243
2243
|
|
|
2244
2244
|
// returns the hit distance given the material density
|
|
2245
2245
|
float intersectFogVolume( Material material, float u ) {
|
|
@@ -2260,7 +2260,7 @@ struct BVH {
|
|
|
2260
2260
|
|
|
2261
2261
|
}
|
|
2262
2262
|
|
|
2263
|
-
`,
|
|
2263
|
+
`,Xa=`
|
|
2264
2264
|
|
|
2265
2265
|
// The GGX functions provide sampling and distribution information for normals as output so
|
|
2266
2266
|
// in order to get probability of scatter direction the half vector must be computed and provided.
|
|
@@ -2361,7 +2361,7 @@ struct BVH {
|
|
|
2361
2361
|
|
|
2362
2362
|
}
|
|
2363
2363
|
|
|
2364
|
-
`,
|
|
2364
|
+
`,Za=`
|
|
2365
2365
|
|
|
2366
2366
|
// XYZ to sRGB color space
|
|
2367
2367
|
const mat3 XYZ_TO_REC709 = mat3(
|
|
@@ -2495,7 +2495,7 @@ struct BVH {
|
|
|
2495
2495
|
|
|
2496
2496
|
}
|
|
2497
2497
|
|
|
2498
|
-
`,
|
|
2498
|
+
`,Qa=`
|
|
2499
2499
|
|
|
2500
2500
|
// See equation (2) in http://www.aconty.com/pdf/s2017_pbs_imageworks_sheen.pdf
|
|
2501
2501
|
float velvetD( float cosThetaH, float roughness ) {
|
|
@@ -2592,7 +2592,7 @@ struct BVH {
|
|
|
2592
2592
|
|
|
2593
2593
|
}
|
|
2594
2594
|
|
|
2595
|
-
|
|
2595
|
+
`,$a=`
|
|
2596
2596
|
|
|
2597
2597
|
#ifndef FOG_CHECK_ITERATIONS
|
|
2598
2598
|
#define FOG_CHECK_ITERATIONS 30
|
|
@@ -2653,7 +2653,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2653
2653
|
|
|
2654
2654
|
}
|
|
2655
2655
|
|
|
2656
|
-
|
|
2656
|
+
`,eo=`
|
|
2657
2657
|
|
|
2658
2658
|
// step through multiple surface hits and accumulate color attenuation based on transmissive surfaces
|
|
2659
2659
|
// returns true if a solid surface was hit
|
|
@@ -2831,7 +2831,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2831
2831
|
|
|
2832
2832
|
}
|
|
2833
2833
|
|
|
2834
|
-
`,
|
|
2834
|
+
`,to=`
|
|
2835
2835
|
|
|
2836
2836
|
vec3 ndcToRayOrigin( vec2 coord ) {
|
|
2837
2837
|
|
|
@@ -2914,7 +2914,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
2914
2914
|
|
|
2915
2915
|
}
|
|
2916
2916
|
|
|
2917
|
-
`,
|
|
2917
|
+
`,no=`
|
|
2918
2918
|
|
|
2919
2919
|
vec3 directLightContribution( vec3 worldWo, SurfaceRecord surf, RenderState state, vec3 rayOrigin ) {
|
|
2920
2920
|
|
|
@@ -3010,7 +3010,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3010
3010
|
|
|
3011
3011
|
}
|
|
3012
3012
|
|
|
3013
|
-
`,
|
|
3013
|
+
`,ro=`
|
|
3014
3014
|
|
|
3015
3015
|
#define SKIP_SURFACE 0
|
|
3016
3016
|
#define HIT_SURFACE 1
|
|
@@ -3333,7 +3333,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3333
3333
|
return HIT_SURFACE;
|
|
3334
3334
|
|
|
3335
3335
|
}
|
|
3336
|
-
`,
|
|
3336
|
+
`,io=`
|
|
3337
3337
|
|
|
3338
3338
|
struct Ray {
|
|
3339
3339
|
|
|
@@ -3382,7 +3382,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3382
3382
|
|
|
3383
3383
|
}
|
|
3384
3384
|
|
|
3385
|
-
`,
|
|
3385
|
+
`,ao=`
|
|
3386
3386
|
|
|
3387
3387
|
#define NO_HIT 0
|
|
3388
3388
|
#define SURFACE_HIT 1
|
|
@@ -3429,7 +3429,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3429
3429
|
|
|
3430
3430
|
}
|
|
3431
3431
|
|
|
3432
|
-
`,
|
|
3432
|
+
`,oo=class extends ki{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 T},opacity:{value:1},bounces:{value:10},transmissiveBounces:{value:10},filterGlossyFactor:{value:0},physicalCamera:{value:new zi},cameraWorldMatrix:{value:new f},invProjectionMatrix:{value:new f},bvh:{value:new Br},attributesArray:{value:new oa},materialIndexAttribute:{value:new Rr},materials:{value:new ha},textures:{value:new ya().texture},lights:{value:new ra},iesProfiles:{value:new ya(360,180,{type:ye,wrapS:w,wrapT:w}).texture},environmentIntensity:{value:1},environmentRotation:{value:new f},envMapInfo:{value:new Wi},backgroundBlur:{value:0},backgroundMap:{value:null},backgroundAlpha:{value:1},backgroundIntensity:{value:1},backgroundRotation:{value:new f},seed:{value:0},sobolTexture:{value:null},stratifiedTexture:{value:new Ta},stratifiedOffsetTexture:{value:new Ma(64,1)}},vertexShader:`
|
|
3433
3433
|
|
|
3434
3434
|
varying vec2 vUv;
|
|
3435
3435
|
void main() {
|
|
@@ -3453,27 +3453,27 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3453
3453
|
#include <common>
|
|
3454
3454
|
|
|
3455
3455
|
// bvh intersection
|
|
3456
|
-
${Hr}
|
|
3457
|
-
${Wr}
|
|
3458
3456
|
${Ur}
|
|
3457
|
+
${Gr}
|
|
3458
|
+
${Wr}
|
|
3459
3459
|
|
|
3460
3460
|
// uniform structs
|
|
3461
|
-
${Ma}
|
|
3462
|
-
${Pa}
|
|
3463
3461
|
${Na}
|
|
3464
3462
|
${Fa}
|
|
3463
|
+
${Pa}
|
|
3465
3464
|
${Ia}
|
|
3465
|
+
${La}
|
|
3466
3466
|
|
|
3467
3467
|
// random
|
|
3468
3468
|
#if RANDOM_TYPE == 2 // Stratified List
|
|
3469
3469
|
|
|
3470
|
-
${
|
|
3470
|
+
${qa}
|
|
3471
3471
|
|
|
3472
3472
|
#elif RANDOM_TYPE == 1 // Sobol
|
|
3473
3473
|
|
|
3474
|
-
${
|
|
3475
|
-
${
|
|
3476
|
-
${
|
|
3474
|
+
${Ka}
|
|
3475
|
+
${Ni}
|
|
3476
|
+
${Fi}
|
|
3477
3477
|
|
|
3478
3478
|
#define rand(v) sobol(v)
|
|
3479
3479
|
#define rand2(v) sobol2(v)
|
|
@@ -3482,7 +3482,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3482
3482
|
|
|
3483
3483
|
#else // PCG
|
|
3484
3484
|
|
|
3485
|
-
${
|
|
3485
|
+
${Ka}
|
|
3486
3486
|
|
|
3487
3487
|
// Using the sobol functions seems to break the the compiler on MacOS
|
|
3488
3488
|
// - specifically the "sobolReverseBits" function.
|
|
@@ -3498,11 +3498,11 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3498
3498
|
#endif
|
|
3499
3499
|
|
|
3500
3500
|
// common
|
|
3501
|
-
${Ua}
|
|
3502
|
-
${Ba}
|
|
3503
3501
|
${Wa}
|
|
3504
3502
|
${Va}
|
|
3503
|
+
${Ga}
|
|
3505
3504
|
${Ha}
|
|
3505
|
+
${Ua}
|
|
3506
3506
|
|
|
3507
3507
|
// environment
|
|
3508
3508
|
uniform EquirectHdrInfo envMapInfo;
|
|
@@ -3558,16 +3558,16 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3558
3558
|
float lightsDenom;
|
|
3559
3559
|
|
|
3560
3560
|
// sampling
|
|
3561
|
-
${
|
|
3562
|
-
${La}
|
|
3561
|
+
${Ba}
|
|
3563
3562
|
${Ra}
|
|
3563
|
+
${za}
|
|
3564
3564
|
|
|
3565
|
+
${$a}
|
|
3566
|
+
${Xa}
|
|
3565
3567
|
${Qa}
|
|
3566
|
-
${Ya}
|
|
3567
3568
|
${Za}
|
|
3568
|
-
${
|
|
3569
|
+
${Ya}
|
|
3569
3570
|
${Ja}
|
|
3570
|
-
${qa}
|
|
3571
3571
|
|
|
3572
3572
|
float applyFilteredGlossy( float roughness, float accumulatedRoughness ) {
|
|
3573
3573
|
|
|
@@ -3599,12 +3599,12 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3599
3599
|
|
|
3600
3600
|
}
|
|
3601
3601
|
|
|
3602
|
-
${ro}
|
|
3603
|
-
${eo}
|
|
3604
3602
|
${io}
|
|
3605
|
-
${$a}
|
|
3606
3603
|
${to}
|
|
3604
|
+
${ao}
|
|
3605
|
+
${eo}
|
|
3607
3606
|
${no}
|
|
3607
|
+
${ro}
|
|
3608
3608
|
|
|
3609
3609
|
void main() {
|
|
3610
3610
|
|
|
@@ -3896,7 +3896,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3896
3896
|
|
|
3897
3897
|
}
|
|
3898
3898
|
|
|
3899
|
-
`}),this.setValues(e)}};function*
|
|
3899
|
+
`}),this.setValues(e)}};function*so(){let{_renderer:e,_fsQuad:t,_blendQuad:n,_primaryTarget:r,_blendTargets:i,_sobolTarget:a,_subframe:o,alpha:s,material:c}=this,l=new le,u=new le,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*_),te=Math.floor(m*v),ne=Math.ceil(S/y),w=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*ne,te+_*w,Math.min(ne,S-h*ne),Math.min(w,C-_*w)),r.viewport.set(ee,te,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 co=new Be,lo=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 T(3,3),this.stableNoise=!1,this.stableTiles=!0,this.samples=0,this._subframe=new le(0,0,1,1),this._opacityFactor=1,this._renderer=e,this._alpha=!1,this._fsQuad=new oe(new oo),this._blendQuad=new oe(new Ai),this._task=null,this._currentTile=0,this._compilePromise=null,this._sobolTarget=new Li().generate(e),this._primaryTarget=new Oe(1,1,{format:d,type:b,magFilter:S,minFilter:S}),this._blendTargets=[new Oe(1,1,{format:d,type:b,magFilter:S,minFilter:S}),new Oe(1,1,{format:d,type:b,magFilter:S,minFilter:S})],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(co),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(co,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||=so.call(this),this._task.next())}},uo=new T,fo=new T,po=new _e,mo=new Be,ho=class extends ze{constructor(t=512,n=512){super(new Float32Array(t*n*4),t,n,d,b,303,e,w,m,m),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++){fo.set(t,n),uo.set(r/t,i/n),uo.x-=.5,uo.y=1-uo.y,po.theta=uo.x*2*Math.PI,po.phi=uo.y*Math.PI,po.radius=1,this.generationCallback(po,uo,fo,mo);let a=4*(i*t+r);e[a+0]=mo.r,e[a+1]=mo.g,e[a+2]=mo.b,e[a+3]=1}}copy(e){return super.copy(e),this.generationCallback=e.generationCallback,this}},go=new E,_o=class extends ho{constructor(e=512){super(e,e),this.topColor=new Be().set(16777215),this.bottomColor=new Be().set(0),this.exponent=2,this.generationCallback=(e,t,n,r)=>{go.setFromSpherical(e);let i=go.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}},vo=class extends Fe{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
3900
|
varying vec2 vUv;
|
|
3901
3901
|
void main() {
|
|
3902
3902
|
|
|
@@ -3953,7 +3953,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3953
3953
|
#include <premultiplied_alpha_fragment>
|
|
3954
3954
|
|
|
3955
3955
|
}
|
|
3956
|
-
`}),this.setValues(e)}},
|
|
3956
|
+
`}),this.setValues(e)}},yo=class extends Fe{constructor(){super({uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:`
|
|
3957
3957
|
varying vec2 vUv;
|
|
3958
3958
|
void main() {
|
|
3959
3959
|
|
|
@@ -3970,7 +3970,7 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3970
3970
|
#include <common>
|
|
3971
3971
|
#include <cube_uv_reflection_fragment>
|
|
3972
3972
|
|
|
3973
|
-
${
|
|
3973
|
+
${Ga}
|
|
3974
3974
|
|
|
3975
3975
|
void main() {
|
|
3976
3976
|
|
|
@@ -3978,11 +3978,11 @@ bool bvhIntersectFogVolumeHit(
|
|
|
3978
3978
|
rayDirection.x *= flipEnvMap;
|
|
3979
3979
|
gl_FragColor = textureCube( envMap, rayDirection );
|
|
3980
3980
|
|
|
3981
|
-
}`}),this.depthWrite=!1,this.depthTest=!1}},
|
|
3981
|
+
}`}),this.depthWrite=!1,this.depthTest=!1}},bo=class{constructor(e){this._renderer=e,this._quad=new oe(new yo)}generate(t,n=null,i=null){if(!t.isCubeTexture)throw Error(`CubeToEquirectMaterial: Source can only be cube textures.`);let a=t.images[0],o=this._renderer,s=this._quad;n===null&&(n=4*a.height),i===null&&(i=2*a.height);let c=new Oe(n,i,{type:b,colorSpace:a.colorSpace}),l=a.height,u=Math.log2(l)-2,f=1/l,p=1/(3*Math.max(2**u,112));s.material.defines.CUBEUV_MAX_MIP=`${u}.0`,s.material.defines.CUBEUV_TEXEL_WIDTH=p,s.material.defines.CUBEUV_TEXEL_HEIGHT=f,s.material.uniforms.envMap.value=t,s.material.uniforms.flipEnvMap.value=t.isRenderTargetTexture?1:-1,s.material.needsUpdate=!0;let h=o.getRenderTarget(),_=o.autoClear;o.autoClear=!0,o.setRenderTarget(c),s.render(o),o.setRenderTarget(h),o.autoClear=_;let v=new Uint16Array(n*i*4),y=new Float32Array(n*i*4);o.readRenderTargetPixels(c,0,0,n,i,y),c.dispose();for(let e=0,t=y.length;e<t;e++)v[e]=r.toHalfFloat(y[e]);let x=new ze(v,n,i,d,ye);return x.minFilter=g,x.magFilter=m,x.wrapS=e,x.wrapT=e,x.mapping=303,x.needsUpdate=!0,x}dispose(){this._quad.dispose()}};function xo(e){return e.extensions.get(`EXT_float_blend`)}var So=new T,Co=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){this._renderer=e,this._generator=new Oi,this._pathTracer=new lo(e),this._queueReset=!1,this._clock=new Le,this._compilePromise=null,this._lowResPathTracer=new lo(e),this._lowResPathTracer.tiles.set(1,1),this._quad=new oe(new vo({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 T(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 ue,new c)}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=da(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=fa(e),i=ua(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 _o(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 bo(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 bo(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||!xo(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(So);let e=Math.floor(this.renderScale*So.x),t=Math.floor(this.renderScale*So.y);if(this._pathTracer.getSize(So),So.x!==e||So.y!==t){let n=this.lowResScale;this._pathTracer.setSize(e,t),this._lowResPathTracer.setSize(Math.floor(e*n),Math.floor(t*n))}}}},wo=class extends y{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(`
|
|
3982
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))},i=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
3983
|
`;l=n(e),!1!==l;){if(c.string+=l+`
|
|
3984
3984
|
`,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},a=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},s=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},c=function(e,t,n,i){let a=2**(e[t+3]-128)/255;n[i+0]=r.toHalfFloat(Math.min(e[t+0]*a,65504)),n[i+1]=r.toHalfFloat(Math.min(e[t+1]*a,65504)),n[i+2]=r.toHalfFloat(Math.min(e[t+2]*a,65504)),n[i+3]=r.toHalfFloat(1)},l=new Uint8Array(e);l.pos=0;let u=i(l),d=u.width,f=u.height,p=a(l.subarray(l.pos),d,f),h,g,_;switch(this.type){case b:_=p.length/4;let e=new Float32Array(_*4);for(let t=0;t<_;t++)s(p,t*4,e,t*4);h=e,g=b;break;case
|
|
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},a=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},s=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},c=function(e,t,n,i){let a=2**(e[t+3]-128)/255;n[i+0]=r.toHalfFloat(Math.min(e[t+0]*a,65504)),n[i+1]=r.toHalfFloat(Math.min(e[t+1]*a,65504)),n[i+2]=r.toHalfFloat(Math.min(e[t+2]*a,65504)),n[i+3]=r.toHalfFloat(1)},l=new Uint8Array(e);l.pos=0;let u=i(l),d=u.width,f=u.height,p=a(l.subarray(l.pos),d,f),h,g,_;switch(this.type){case b:_=p.length/4;let e=new Float32Array(_*4);for(let t=0;t<_;t++)s(p,t*4,e,t*4);h=e,g=b;break;case ye:_=p.length/4;let t=new Uint16Array(_*4);for(let e=0;e<_;e++)c(p,e*4,t,e*4);h=t,g=ye;break;default:throw Error(`THREE.HDRLoader: Unsupported type: `+this.type)}return{width:d,height:f,data:h,header:u.string,gamma:u.gamma,exposure:u.exposure,type:g,colorSpace:o,minFilter:m,magFilter:m,generateMipmaps:!1,flipY:!0}}setDataType(e){return this.type=e,this}},To=`// Global detail setting
|
|
3986
3986
|
$fn = 64;
|
|
3987
3987
|
|
|
3988
3988
|
// Animation Data Dictionary
|
|
@@ -4108,7 +4108,7 @@ armature(animations=anim_data) {
|
|
|
4108
4108
|
}
|
|
4109
4109
|
}
|
|
4110
4110
|
}
|
|
4111
|
-
`,
|
|
4111
|
+
`,Eo=document.getElementById(`prompt-desc`),Do=document.getElementById(`copy-prompt-btn`),Oo=document.getElementById(`model-name-input`),R=document.getElementById(`editor`),ko=document.getElementById(`render-btn`),Ao=document.getElementById(`load-scad-btn`),jo=document.getElementById(`download-scad-btn`),Mo=document.getElementById(`export-gltf-btn`),No=document.getElementById(`capture-image-btn`),Po=document.getElementById(`share-btn`),Fo=document.getElementById(`auto-render-cb`),Io=document.getElementById(`minify-share-cb`),z=document.getElementById(`viewer`),Lo=document.getElementById(`right-panel`),Ro=document.getElementById(`backend-url`),zo=document.getElementById(`backend-connect-btn`),Bo=document.getElementById(`backend-ui`),Vo=document.getElementById(`backend-select`),Ho=document.getElementById(`backend-single-save-btn`),Uo=document.getElementById(`backend-delete-btn`),Wo=document.getElementById(`anim-controls-section`),Go=document.getElementById(`anim-play-btn`),Ko=document.getElementById(`anim-select`),qo=document.getElementById(`anim-slider`),Jo=document.getElementById(`prompt-ui-container`),Yo=document.getElementById(`show-grid-cb`),Xo=document.getElementById(`wireframe-cb`),Zo=document.getElementById(`fullscreen-btn`),Qo=document.getElementById(`screenshot-btn`),$o=document.getElementById(`camera-select`),es=``,B=null,ts=null,ns=[],rs=!1,is=null,V=null,as=!1,os=!1,ss=null,cs=[],ls=!1,us=!1,ds={isNew:!0,options:{},content:``},H=null,fs=!0,ps=!1,ms=[],U=null;function hs(e,t,n){if(e){if(e.isPerspectiveCamera)e.aspect=t/n,e.updateProjectionMatrix();else if(e.isOrthographicCamera){let r=t/n;e.userData.ymag||(e.userData.ymag=e.top),e.left=-e.userData.ymag*r,e.right=e.userData.ymag*r,e.top=e.userData.ymag,e.bottom=-e.userData.ymag,e.updateProjectionMatrix()}}}function gs(){return us?R.value:R.value||`// Global detail setting
|
|
4112
4112
|
$fn = 64;
|
|
4113
4113
|
|
|
4114
4114
|
// Animation Data Dictionary
|
|
@@ -4234,8 +4234,8 @@ armature(animations=anim_data) {
|
|
|
4234
4234
|
}
|
|
4235
4235
|
}
|
|
4236
4236
|
}
|
|
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||!
|
|
4237
|
+
`}function _s(){return Oo.value.trim()||`model`}Oo.addEventListener(`input`,Ms),Jo&&(Jo.innerHTML=Ge,We(Jo,`scad_editor_prompt_settings`)),Do.onclick=async()=>{let e=Eo.value.trim()||`an object`,t=Ue(Jo),n=He(e,t);try{await navigator.clipboard.writeText(n);let e=Do.innerText;Do.innerText=`✅ Copied!`,setTimeout(()=>{Do.innerText=e},2e3)}catch(e){alert(`Failed to copy clipboard: `+e)}};async function vs(e){let t={};if(!us)return t;let n=new Set;async function r(e){let i=/(?:include|use)\s*([<"])([^>"]+)([>"])/g,a;for(;(a=i.exec(e))!==null;){let e=a[2],i=e.split(/[/\\]/).pop();if(!n.has(e)){n.add(e);try{let n=await fetch(`${Os}/api/scads/${encodeURIComponent(i)}`);if(n.ok){let i=await n.json();t[e]=i.content,await r(i.content)}}catch{console.warn(`Failed to load dependency: ${e}`)}}}}return await r(e),t}async function ys(e){if(typeof e!=`string`)return;if(rs){is=e;return}if(e.trim()===``){Us();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&&Oo.value!==e&&(Oo.value=e,Ms())}rs=!0;try{let t=await vs(e);ts=await Se(e,{wasmUrl:he,additionalFiles:t}),await Gs(ts)}catch(e){console.error(e)}finally{if(rs=!1,is!==null){let e=is;is=null,ys(e)}}}ko.onclick=()=>ys(gs());var bs;R.addEventListener(`input`,()=>{Ms(),clearTimeout(bs),Fo.checked&&(bs=setTimeout(()=>{ys(gs())},800))}),Fo.addEventListener(`change`,()=>{Fo.checked&&ys(gs())}),Ao.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();R.value=t,Ms(),ys(t)}catch(e){alert(`Failed to read file: `+e.message)}},e.click()};function xs(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}jo.onclick=()=>{let e=gs();xs(new Blob([e],{type:`text/plain`}),`${_s()}.scad`)},Mo.onclick=()=>{ts&&xs(new Blob([ts],{type:`application/octet-stream`}),`${_s()}.glb`)};function Ss(){No.innerText=os?`🔴 Rec...`:H&&fs?`🎥 Video`:`📷 Image`}No.onclick=()=>{if(os){ls=!0,ss&&ss.state!==`inactive`&&ss.stop();return}if(H&&fs){if(typeof MediaRecorder<`u`){let e=q!==void 0&&J&&J.checked;H.time=0,V&&V.update(0),hs(U,512,512),K.setSize(512,512,!1),Ps.setSize(512,512),e&&q.updateCamera();let t=K.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;ls=!1,os=!0,Ss();let l=H.getClip().duration,u=Math.round(l*30),d=0,f=[],p=()=>{if(ls||d>=u){if(f.length===0){os=!1,hs(U,z.clientWidth,z.clientHeight),K.setSize(z.clientWidth,z.clientHeight),Ps.setSize(z.clientWidth,z.clientHeight),e&&q!==void 0&&(q.setScene(W,U),q.updateCamera()),Ss();return}ls=!1,ss=new MediaRecorder(i,s),cs=[],ss.ondataavailable=e=>{e.data.size>0&&cs.push(e.data)},ss.onstop=()=>{c&&clearTimeout(c),xs(new Blob(cs,{type:s.mimeType.split(`;`)[0]}),`${_s()}.${o}`),os=!1,hs(U,z.clientWidth,z.clientHeight),K.setSize(z.clientWidth,z.clientHeight),Ps.setSize(z.clientWidth,z.clientHeight),e&&q!==void 0&&(q.setScene(W,U),q.updateCamera()),Ss()},r.drawImage(f[0],0,0,512,512),ss.start();let t=0,n=performance.now(),a=()=>{if(ls){ss.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(()=>ss.stop(),50)};c=setTimeout(a,0);return}if(H.time=d/30,V&&V.update(0),e){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,U);let e=()=>{if(ls){p();return}let n=0;for(;q.samples<100&&n<5;)q.renderSample(),n++;if(q.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=!Yo||Yo.checked;Z!==void 0&&(Z.visible=!0),Y!==void 0&&(Y.visible=!0),Q!==void 0&&(Q.visible=e),$!==void 0&&($.visible=e),Ps.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 as=!0};function Cs(e){let t=e.length%4;return t===2?e+`==`:t===3?e+`=`:e}async function ws(e){try{if(typeof CompressionStream<`u`){let t=new Blob([e]).stream().pipeThrough(new CompressionStream(`deflate-raw`)),n=await new Response(t).arrayBuffer(),r=new Uint8Array(n),i=``;for(let e=0;e<r.length;e++)i+=String.fromCharCode(r[e]);return`c`+btoa(i).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}}catch(e){console.warn(`CompressionStream failed, falling back`,e)}return`u`+btoa(unescape(encodeURIComponent(e))).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}async function Ts(e){if(!e)return null;let t=e.charAt(0),n=e.substring(1);if(n=Cs(n.replace(/-/g,`+`).replace(/_/g,`/`)),t===`c`)try{let e=atob(n),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);let r=new Blob([t]).stream().pipeThrough(new DecompressionStream(`deflate-raw`)),i=await new Response(r).arrayBuffer();return new TextDecoder().decode(i)}catch(e){console.warn(`DecompressionStream failed`,e)}else if(t===`u`)try{return decodeURIComponent(escape(atob(n)))}catch(e){console.warn(`Unescape failed`,e)}else try{return decodeURIComponent(escape(atob(Cs(e.replace(/-/g,`+`).replace(/_/g,`/`)))))}catch{return decodeURIComponent(e)}return null}Po.onclick=async()=>{let e=R.value.trim(),t=e,n=new URL(window.location.href),r=``;if(Io&&Io.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]!==`
|
|
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||!us&&t===`// Global detail setting
|
|
4239
4239
|
$fn = 64;
|
|
4240
4240
|
|
|
4241
4241
|
// Animation Data Dictionary
|
|
@@ -4360,4 +4360,4 @@ armature(animations=anim_data) {
|
|
|
4360
4360
|
}
|
|
4361
4361
|
}
|
|
4362
4362
|
}
|
|
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)})();
|
|
4363
|
+
}`)r=n.origin+n.pathname+n.search;else try{n.hash=await ws(e),r=n.toString()}catch{r=n.origin+n.pathname+n.search}window.history.replaceState(null,``,r);try{if(navigator.share){let e=Oo.value.trim(),t=e?e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase()):`Scadify`;await navigator.share({title:t,url:r});let n=Po.innerText;Po.innerText=`✅ Shared!`,setTimeout(()=>Po.innerText=n,2e3)}else{await navigator.clipboard.writeText(r);let e=Po.innerText;Po.innerText=`✅ Copied Link!`,setTimeout(()=>Po.innerText=e,2e3)}}catch(e){if(e.name!==`AbortError`)try{await navigator.clipboard.writeText(r),Po.innerText=`✅ Copied Link!`,setTimeout(()=>Po.innerText=`🔗 Share`,2e3)}catch{alert(`Failed to share or copy link.`)}}};var Es=document.getElementById(`drag-overlay`);window.addEventListener(`dragenter`,e=>{e.preventDefault(),Es.classList.add(`active`)}),window.addEventListener(`dragover`,e=>{e.preventDefault(),Es.classList.add(`active`)}),Es.addEventListener(`dragleave`,e=>{e.preventDefault(),Es.classList.remove(`active`)}),window.addEventListener(`drop`,async e=>{if(e.preventDefault(),Es.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 wo().load(e,e=>{e.mapping=303,W.environment=e,zs=e,J&&J.checked?(W.background=e,W.backgroundBlurriness=.5,W.backgroundIntensity=.3):(W.background=new Be(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();R.value=e,Ms(),ys(e)}catch(e){alert(`Failed to read file: `+e.message)}else alert(`Please drop a valid .scad or .hdr file.`)}});var Ds=null,Os=``;async function ks(e){let t=await fetch(`${e}/api/scads`);if(!t.ok)throw Error(`Failed to fetch files`);return(await t.json()).files}function As(){Vo.innerHTML=`<option value="">-- Create New Model --</option>`,Array.isArray(Ds)&&Ds.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e,Vo.appendChild(n)}),Vo.value=es,Uo&&(Uo.style.display=es===``?`none`:`flex`)}function js(){let e=Oo.value.trim();return e&&=e.replace(/\.scad$/i,``).split(/[/\\]/).pop()+`.scad`,{filename:e}}function Ms(){if(Ds===null)return;let e=Vo.value===``,{filename:t}=js(),n=R.value,r=!1;e?(t&&t!==`.scad`||n.trim()!==``)&&(r=!0):n!==ds.content&&(r=!0),r?(Ho.style.display=`flex`,Ho.innerText=`Save`):Ho.style.display=`none`}async function Ns(e,t=!1){if(!e)return!1;try{return zo.innerText=`Connecting...`,Ds=await ks(e),Os=e,us=!0,zo.innerText=`Connected`,Bo.classList.add(`active`),R.placeholder=`Enter OpenSCAD code here...`,es=``,As(),ds={isNew:!0,content:``},Ms(),!0}catch(e){return t?console.warn(`Auto-connect failed:`,e.message):alert(`Connection failed: `+e.message),zo.innerText=`Connect`,Bo.classList.remove(`active`),us=!1,R.placeholder=To,!1}}zo.onclick=async()=>{await Ns(Ro.value.trim(),!1)&&ys(gs())},Vo.addEventListener(`change`,async()=>{if(Ho.style.display!==`none`&&!confirm(`You have unsaved changes. Are you sure you want to discard them and load another model?`)){Vo.value=es;return}let e=Vo.value;if(es=e,Uo&&(Uo.style.display=e===``?`none`:`flex`),e===``)Oo.value=``,R.value=``,ys(gs()),ds={isNew:!0,content:``},Ms();else{let t=Ds[e];Oo.value=t.replace(/\.scad$/i,``);try{let e=await fetch(`${Os}/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();R.value=n.content,ys(gs()),ds={isNew:!1,content:n.content},Ms()}catch(e){alert(`Error loading model: `+e.message)}}}),Ho.onclick=async()=>{let{filename:e}=js();if(!e||e===`.scad`){let e=Ho.innerText;Ho.innerText=`⚠️ Name Required!`,Ho.style.borderColor=`#ff4444`,Oo.focus(),setTimeout(()=>{Ho.innerText=e,Ho.style.borderColor=``},2e3);return}if(Vo.value===``&&Ds&&Ds.includes(e)&&!confirm(`A model named "${e}" already exists. Are you sure you want to overwrite it?`))return;let t={filename:e,content:R.value};try{Ho.innerText=`Saving...`;let n=await fetch(`${Os}/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`)}Ds=await ks(Os);let r=Ds.findIndex(t=>t===e);es=r>=0?r.toString():``,As(),ds={isNew:!1,content:R.value},Ms()}catch(e){Ms(),alert(`Error: `+e.message)}},Uo.onclick=async()=>{let e=Vo.value;if(e===``)return;let t=Ds[e];if(confirm(`Are you sure you want to delete "${t}"?`))try{Uo.innerText=`Deleting...`;let e=await fetch(`${Os}/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)}Ds=await ks(Os),es=``,As(),Oo.value=``,R.value=``,ys(gs()),ds={isNew:!0,content:``},Ms(),Uo.innerText=`Delete`}catch(e){alert(`Error: `+e.message),Uo.innerText=`Delete`}};var W=new ue;W.background=new Be(2236962);var G=new c(60,z.clientWidth/z.clientHeight,.1,2e3);G.position.set(50,50,-50),U=G;var K=new Ie({antialias:!0,preserveDrawingBuffer:!0});K.setSize(z.clientWidth,z.clientHeight),K.setPixelRatio(Math.min(window.devicePixelRatio,2)),K.toneMapping=4,K.toneMappingExposure=1,K.shadowMap.enabled=!0,K.shadowMap.type=2,z.appendChild(K.domElement);var Ps=new ge(K),Fs=new Ae(W,U);Ps.addPass(Fs);var Is=new Ce(new T(z.clientWidth,z.clientHeight),.1,.1,2);Ps.addPass(Is);var Ls=new Pe;Ps.addPass(Ls);var q=new Co(K);q.bounces=10,q.transmissiveBounces=10,q.multipleImportanceSampling=!0,q.filterGlossyFactor=.2;var Rs=new Me(G,K.domElement);Rs.addEventListener(`change`,()=>{q!==void 0&&q.updateCamera()});var zs=null;new wo().load(`./aristea_wreck_puresky_2k.hdr`,e=>{e.mapping=303,W.environment=e,zs=e;let t=J&&J.checked,n=!Yo||Yo.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 Be(2236962),W.backgroundBlurriness=0,W.backgroundIntensity=1),q!==void 0&&(q.setScene(W,U),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=!Yo||Yo.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?zs&&(W.background=zs,W.backgroundBlurriness=.5,W.backgroundIntensity=.3):(W.background=new Be(2236962),W.backgroundBlurriness=0,W.backgroundIntensity=1),e&&q!==void 0&&(q.setScene(W,U),q.updateCamera())}),$o&&$o.addEventListener(`change`,e=>{let t=e.target.value;t===``?(U=G,Rs.enabled=!0):(U=ms[parseInt(t)],Rs.enabled=!1);let n=z.clientWidth,r=z.clientHeight;hs(U,n,r),Fs.camera=U,J&&J.checked&&q!==void 0&&(q.setScene(W,U),q.updateCamera())}),Rs.enableDamping=!0,Rs.dampingFactor=.1,Rs.maxDistance=2e3,W.environment=new be(K).fromScene(new re,.04).texture,W.environmentIntensity=.8;var Y=new h;W.add(Y);var X=new Re(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 Bs=new t(16777215,4473924,.6);Bs.position.set(0,20,0),Y.add(Bs);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 de(100);W.add($),Xo&&Xo.addEventListener(`change`,()=>{let e=Xo.checked;B&&B.traverse(t=>{t.isMesh&&t.material&&(Array.isArray(t.material)?t.material.forEach(t=>{t.wireframe=e}):t.material.wireframe=e)})}),Zo&&Lo&&(Zo.addEventListener(`click`,()=>{document.fullscreenElement?document.exitFullscreen():Lo.requestFullscreen().catch(e=>{console.warn(`Error attempting to enable fullscreen: ${e.message}`)})}),document.addEventListener(`fullscreenchange`,()=>{setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100)})),Qo&&Qo.addEventListener(`click`,()=>{as=!0;let e=Qo.innerText;Qo.innerText=`✅`,setTimeout(()=>{Qo.innerText=e},1e3)});function Vs(){H&&(fs=!1,H.paused=!0,Go.innerText=`▶ Play`,Ss())}function Hs(e){if(!V||!ns[e])return;H&&H.stop();let t=ns[e];H=V.clipAction(t),H.play(),H.time=0,V.update(0),fs=!0,H.paused=!1,Go.innerText=`⏸ Pause`,qo.value=0,Ss()}Ko.addEventListener(`change`,e=>{Hs(parseInt(e.target.value))}),Go.addEventListener(`click`,()=>{H&&(fs=!fs,H.paused=!fs,Go.innerText=fs?`⏸ Pause`:`▶ Play`,Ss())}),qo.addEventListener(`mousedown`,()=>{ps=!0,Vs()}),qo.addEventListener(`mouseup`,()=>{ps=!1}),qo.addEventListener(`touchstart`,()=>{ps=!0,Vs()},{passive:!0}),qo.addEventListener(`touchend`,()=>{ps=!1},{passive:!0}),qo.addEventListener(`input`,e=>{if(Vs(),H){let t=H.getClip().duration;H.time=parseFloat(e.target.value)*t,V&&(V.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,U),q.updateCamera()))}});function Us(){os&&ss&&ss.state!==`inactive`&&(ss.stop(),os=!1),B&&=(V&&=(V.stopAllAction(),V.uncacheRoot(V.getRoot()),null),H=null,W.remove(B),B.traverse(e=>{e.isMesh&&(e.geometry.dispose(),Array.isArray(e.material)?e.material.forEach(e=>e.dispose()):e.material&&e.material.dispose())}),null),Ss()}function Ws(e,t){if(!e)return new De;e.updateMatrixWorld(!0);let n=new De().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 ce(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 Gs(e){return new Promise((t,n)=>{let r=null;B&&(V&&H&&(H.time=0,V.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,U),q.updateCamera())),r=Ws(B,ns)),Us();let i=e;e instanceof Uint8Array&&(i=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)),new Te().parse(i,``,e=>{B=e.scene,ns=e.animations||[];let n=Xo?Xo.checked:!1;ms=[],B.traverse(e=>{e.isCamera&&ms.push(e)});let i=!1;$o?ms.length>0?($o.style.display=`inline-block`,$o.innerHTML=`<option value="">Free Camera</option>`,ms.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Camera ${t+1}`,$o.appendChild(n)}),$o.value=`0`,U=ms[0],Rs.enabled=!1,i=!0):($o.style.display=`none`,$o.value=``,U=G,Rs.enabled=!0):(U=G,Rs.enabled=!0);let a=z?z.clientWidth:window.innerWidth,o=z?z.clientHeight:window.innerHeight;hs(U,a,o),Fs.camera=U;let s=document.getElementById(`anim-slider-row`);ns.length?(V=new ce(B),i=!0,Go&&(Go.style.display=``),Ko&&(Ko.style.display=``),s&&(s.style.display=``),Ko.innerHTML=``,ns.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Animation ${t+1}`,Ko.appendChild(n)}),Hs(0)):(Go&&(Go.style.display=`none`),Ko&&(Ko.style.display=`none`),s&&(s.style.display=`none`),H=null,Ss()),Wo&&(Wo.style.display=i?`flex`:`none`),B.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(B);let c=!0;if(r&&!r.isEmpty()){let e=Ws(B,ns);if(!e.isEmpty()){let t=.001;r.min.distanceTo(e.min)<t&&r.max.distanceTo(e.max)<t&&(c=!1)}}if(c)typeof Ks==`function`&&Ks();else{let e=J&&J.checked,t=!Yo||Yo.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,U),q.updateCamera())}t()},n)})}function Ks(){if(!B)return;let e=Ws(B,ns);if(e.isEmpty())return;let t=e.getCenter(new E),n=e.getSize(new E),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(),Rs.maxDistance=G.far,G.position.set(t.x+o*.8,t.y+o*.8,t.z-o*.8),G.lookAt(t),Rs.target.copy(t),Rs.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=!Yo||Yo.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,U),q.updateCamera())}var qs=performance.now();function Js(){requestAnimationFrame(Js);let e=performance.now(),t=(e-qs)/1e3;if(qs=e,V&&(!(J&&J.checked)&&!os&&V.update(t),H&&fs&&!ps)){let e=H.getClip().duration;if(e>0){let t=H.time%e;t<0&&(t+=e),qo.value=t/e}}Rs.update();let n=J&&J.checked,r=!Yo||Yo.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&&!os&&(H&&fs&&q.updateCamera(),q.renderSample())):(Z!==void 0&&(Z.visible=!0),Y!==void 0&&(Y.visible=!0),Q!==void 0&&(Q.visible=r),$!==void 0&&($.visible=r),os||Ps.render()),as&&(as=!1,K.domElement.toBlob(e=>{e&&xs(e,`${_s()}.png`)},`image/png`))}Js(),window.addEventListener(`resize`,()=>{if(!z||os)return;let e=z.clientWidth,t=z.clientHeight;hs(U,e,t),K.setSize(e,t),Ps.setSize(e,t),q!==void 0&&q.updateCamera()}),setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100);var Ys=[`localhost`,`127.0.0.1`,``].includes(window.location.hostname);R.placeholder=Ys?`Enter OpenSCAD code here...`:To,(async function(){if(Ys&&await Ns(Ro.value.trim(),!0),window.location.hash&&window.location.hash.length>1)try{let e=await Ts(window.location.hash.substring(1));e&&(R.value=e)}catch(e){console.error(`Failed to decode hash`,e)}Ms(),setTimeout(()=>ys(gs()),500)})();
|