scad-gltf 0.1.0 → 0.1.2
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/LICENSE +339 -0
- package/README.md +1 -2
- package/bin/scad-godot.js +33 -9
- package/bin/scad-web.js +6 -9
- package/editor/dist/assets/{index-t9MYrExo.css → index-B1KAb97r.css} +1 -1
- package/editor/dist/assets/{index-V9cEH4KX.js → index-Cy6q5gqL.js} +66 -21
- package/editor/dist/assets/{prompt-ui-8EFRz0ju.js → prompt-ui-mDTjxcQO.js} +7 -4
- package/editor/dist/content.js +1 -1
- package/editor/dist/icon.png +0 -0
- package/editor/dist/index.html +4 -3
- package/editor/dist/sw.js +1 -1
- package/godot/addons/scad_importer/LICENSE +21 -0
- package/godot/addons/scad_importer/plugin.cfg +1 -0
- package/godot/addons/scad_importer/scad_importer.gd +3 -0
- package/godot/addons/scad_importer/scad_plugin.gd +3 -0
- package/godot/examples/LICENSE +21 -0
- package/godot/examples/README.md +4 -0
- package/godot/examples/horde_survivor_3d.js +2694 -0
- package/godot/examples/naval_battle_3d.js +1691 -0
- package/package.json +1 -1
- package/src/prompt.js +8 -4
|
@@ -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-Bvl6NigM.js";import{i as Ve,n as He,r as Ue,t as We}from"./prompt-ui-8EFRz0ju.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);if(C)return!0;return!1;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 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-Bvl6NigM.js";import{i as Ve,n as He,r as Ue,t as We}from"./prompt-ui-mDTjxcQO.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);if(C)return!0;return!1;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=`
|
|
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
|
|
@@ -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 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:`
|
|
298
298
|
|
|
299
299
|
varying vec2 vUv;
|
|
300
300
|
|
|
@@ -4081,19 +4081,34 @@ armature(animations=anim_data) {
|
|
|
4081
4081
|
|
|
4082
4082
|
// Deep Volumetric Sapphire
|
|
4083
4083
|
// Showcasing: $asa=0.0 (Preserves faceted "cut" look of the crystal)
|
|
4084
|
-
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=
|
|
4084
|
+
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=6.0, $asa=30) {
|
|
4085
|
+
|
|
4086
|
+
// Use difference() to carve out an inner cavity so the shell is hollow,
|
|
4087
|
+
// allowing physically correct index-of-refraction depth sorting.
|
|
4088
|
+
difference() {
|
|
4089
|
+
// Octagonal faceted crystal shape
|
|
4090
|
+
union() {
|
|
4091
|
+
cylinder(h=5, r1=4, r2=0, $fn=8);
|
|
4092
|
+
translate([0,0,-5]) cylinder(h=5, r1=0, r2=4, $fn=8);
|
|
4093
|
+
}
|
|
4094
|
+
|
|
4095
|
+
// Hollow cavity
|
|
4096
|
+
sphere(r=0.9, $fn=32);
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
4085
4099
|
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4100
|
+
// 4. Glowing Core (Child of Gem Shell)
|
|
4101
|
+
// Placed inside its own bone to prevent auto-unioning with the transparent gem
|
|
4102
|
+
bone(name="Core", t=[0,0,0]) {
|
|
4103
|
+
color([0.0, 0.0, 0.0, 1.0], emissive=[0.5, 0.8, 1.0], emissiveIntensity=20.0, $asa=45) {
|
|
4104
|
+
sphere(r=0.6, $fn=32);
|
|
4090
4105
|
}
|
|
4091
4106
|
}
|
|
4092
4107
|
}
|
|
4093
4108
|
}
|
|
4094
4109
|
}
|
|
4095
4110
|
}
|
|
4096
|
-
`,To=document.getElementById(`prompt-desc`),Eo=document.getElementById(`copy-prompt-btn`),Do=document.getElementById(`model-name-input`),z=document.getElementById(`editor`),Oo=document.getElementById(`render-btn`),ko=document.getElementById(`load-scad-btn`),Ao=document.getElementById(`download-scad-btn`),jo=document.getElementById(`export-gltf-btn`),Mo=document.getElementById(`capture-image-btn`),No=document.getElementById(`share-btn`),Po=document.getElementById(`auto-render-cb`),Fo=document.getElementById(`minify-share-cb`),B=document.getElementById(`viewer`),Io=document.getElementById(`right-panel`),Lo=document.getElementById(`backend-url`),Ro=document.getElementById(`backend-connect-btn`),zo=document.getElementById(`backend-ui`),Bo=document.getElementById(`backend-select`),Vo=document.getElementById(`backend-single-save-btn`),Ho=document.getElementById(`backend-delete-btn`),Uo=document.getElementById(`anim-controls-section`),Wo=document.getElementById(`anim-play-btn`),Go=document.getElementById(`anim-select`),Ko=document.getElementById(`anim-slider`),qo=document.getElementById(`prompt-ui-container`),Jo=document.getElementById(`show-grid-cb`),Yo=document.getElementById(`wireframe-cb`),Xo=document.getElementById(`fullscreen-btn`),Zo
|
|
4111
|
+
`,To=document.getElementById(`prompt-desc`),Eo=document.getElementById(`copy-prompt-btn`),Do=document.getElementById(`model-name-input`),z=document.getElementById(`editor`),Oo=document.getElementById(`render-btn`),ko=document.getElementById(`load-scad-btn`),Ao=document.getElementById(`download-scad-btn`),jo=document.getElementById(`export-gltf-btn`),Mo=document.getElementById(`capture-image-btn`),No=document.getElementById(`share-btn`),Po=document.getElementById(`auto-render-cb`),Fo=document.getElementById(`minify-share-cb`),B=document.getElementById(`viewer`),Io=document.getElementById(`right-panel`),Lo=document.getElementById(`backend-url`),Ro=document.getElementById(`backend-connect-btn`),zo=document.getElementById(`backend-ui`),Bo=document.getElementById(`backend-select`),Vo=document.getElementById(`backend-single-save-btn`),Ho=document.getElementById(`backend-delete-btn`),Uo=document.getElementById(`anim-controls-section`),Wo=document.getElementById(`anim-play-btn`),Go=document.getElementById(`anim-select`),Ko=document.getElementById(`anim-slider`),qo=document.getElementById(`prompt-ui-container`),Jo=document.getElementById(`show-grid-cb`),Yo=document.getElementById(`wireframe-cb`),Xo=document.getElementById(`fullscreen-btn`),Zo=document.getElementById(`screenshot-btn`),Qo=``,V=null,$o=null,es=[],ts=!1,ns=null,H=null,rs=!1,is=!1,as=null,os=[],ss=!1,cs=!1,ls={isNew:!0,options:{},content:``},U=null,us=!0,ds=!1;function fs(){return cs?z.value:z.value||`// Global detail setting
|
|
4097
4112
|
$fn = 64;
|
|
4098
4113
|
|
|
4099
4114
|
// Animation Data Dictionary
|
|
@@ -4192,20 +4207,35 @@ armature(animations=anim_data) {
|
|
|
4192
4207
|
|
|
4193
4208
|
// Deep Volumetric Sapphire
|
|
4194
4209
|
// Showcasing: $asa=0.0 (Preserves faceted "cut" look of the crystal)
|
|
4195
|
-
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=
|
|
4210
|
+
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=6.0, $asa=30) {
|
|
4211
|
+
|
|
4212
|
+
// Use difference() to carve out an inner cavity so the shell is hollow,
|
|
4213
|
+
// allowing physically correct index-of-refraction depth sorting.
|
|
4214
|
+
difference() {
|
|
4215
|
+
// Octagonal faceted crystal shape
|
|
4216
|
+
union() {
|
|
4217
|
+
cylinder(h=5, r1=4, r2=0, $fn=8);
|
|
4218
|
+
translate([0,0,-5]) cylinder(h=5, r1=0, r2=4, $fn=8);
|
|
4219
|
+
}
|
|
4220
|
+
|
|
4221
|
+
// Hollow cavity
|
|
4222
|
+
sphere(r=0.9, $fn=32);
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
4196
4225
|
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4226
|
+
// 4. Glowing Core (Child of Gem Shell)
|
|
4227
|
+
// Placed inside its own bone to prevent auto-unioning with the transparent gem
|
|
4228
|
+
bone(name="Core", t=[0,0,0]) {
|
|
4229
|
+
color([0.0, 0.0, 0.0, 1.0], emissive=[0.5, 0.8, 1.0], emissiveIntensity=20.0, $asa=45) {
|
|
4230
|
+
sphere(r=0.6, $fn=32);
|
|
4201
4231
|
}
|
|
4202
4232
|
}
|
|
4203
4233
|
}
|
|
4204
4234
|
}
|
|
4205
4235
|
}
|
|
4206
4236
|
}
|
|
4207
|
-
`}function
|
|
4208
|
-
`;)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 ps(){return Do.value.trim()||`model`}Do.addEventListener(`input`,Os),qo&&(qo.innerHTML=We,Ue(qo,`scad_editor_prompt_settings`)),Eo.onclick=async()=>{let e=To.value.trim()||`an object`,t=He(qo),n=Ve(e,t);try{await navigator.clipboard.writeText(n);let e=Eo.innerText;Eo.innerText=`✅ Copied!`,setTimeout(()=>{Eo.innerText=e},2e3)}catch(e){alert(`Failed to copy clipboard: `+e)}};async function ms(e){let t={};if(!cs)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(`${ws}/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 hs(e){if(typeof e!=`string`)return;if(ts){ns=e;return}if(e.trim()===``){zs();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&&Do.value!==e&&(Do.value=e,Os())}ts=!0;try{let t=await ms(e);$o=await xe(e,{wasmUrl:me,additionalFiles:t}),await Vs($o)}catch(e){console.error(e)}finally{if(ts=!1,ns!==null){let e=ns;ns=null,hs(e)}}}Oo.onclick=()=>hs(fs());var gs;z.addEventListener(`input`,()=>{Os(),clearTimeout(gs),Po.checked&&(gs=setTimeout(()=>{hs(fs())},800))}),Po.addEventListener(`change`,()=>{Po.checked&&hs(fs())}),ko.onclick=()=>{let e=document.createElement(`input`);e.type=`file`,e.accept=`.scad`,e.onchange=async e=>{if(e.target.files&&e.target.files.length>0)try{let t=await e.target.files[0].text();z.value=t,Os(),hs(t)}catch(e){alert(`Failed to read file: `+e.message)}},e.click()};function _s(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)}Ao.onclick=()=>{let e=fs();_s(new Blob([e],{type:`text/plain`}),`${ps()}.scad`)},jo.onclick=()=>{$o&&_s(new Blob([$o],{type:`application/octet-stream`}),`${ps()}.glb`)};function vs(){Mo.innerText=is?`🔴 Rec...`:U&&us?`🎥 Video`:`📷 Image`}Mo.onclick=()=>{if(is){ss=!0,as&&as.state!==`inactive`&&as.stop();return}if(U&&us){if(typeof MediaRecorder<`u`){let e=q!==void 0&&J&&J.checked;U.time=0,H&&H.update(0),G.aspect=1,G.updateProjectionMatrix(),K.setSize(512,512,!1),As.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;ss=!1,is=!0,vs();let l=U.getClip().duration,u=Math.round(l*30),d=0,f=[],p=()=>{if(ss||d>=u){if(f.length===0){is=!1,G.aspect=B.clientWidth/B.clientHeight,G.updateProjectionMatrix(),K.setSize(B.clientWidth,B.clientHeight),As.setSize(B.clientWidth,B.clientHeight),e&&q!==void 0&&q.updateCamera(),vs();return}ss=!1,as=new MediaRecorder(i,s),os=[],as.ondataavailable=e=>{e.data.size>0&&os.push(e.data)},as.onstop=()=>{c&&clearTimeout(c),_s(new Blob(os,{type:s.mimeType.split(`;`)[0]}),`${ps()}.${o}`),is=!1,G.aspect=B.clientWidth/B.clientHeight,G.updateProjectionMatrix(),K.setSize(B.clientWidth,B.clientHeight),As.setSize(B.clientWidth,B.clientHeight),e&&q!==void 0&&q.updateCamera(),vs()},r.drawImage(f[0],0,0,512,512),as.start();let t=0,n=performance.now(),a=()=>{if(ss){as.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(()=>as.stop(),50)};c=setTimeout(a,0);return}if(U.time=d/30,H&&H.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,G);let e=()=>{if(ss){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=!Jo||Jo.checked;Z!==void 0&&(Z.visible=!0),Y!==void 0&&(Y.visible=!0),Q!==void 0&&(Q.visible=e),$!==void 0&&($.visible=e),As.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 rs=!0};function ys(e){let t=e.length%4;return t===2?e+`==`:t===3?e+`=`:e}async function bs(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 xs(e){if(!e)return null;let t=e.charAt(0),n=e.substring(1);if(n=ys(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(ys(e.replace(/-/g,`+`).replace(/_/g,`/`)))))}catch{return decodeURIComponent(e)}return null}No.onclick=async()=>{let e=z.value.trim(),t=e,n=new URL(window.location.href),r=``;if(Fo&&Fo.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||!cs&&t===`// Global detail setting
|
|
4209
4239
|
$fn = 64;
|
|
4210
4240
|
|
|
4211
4241
|
// Animation Data Dictionary
|
|
@@ -4304,15 +4334,30 @@ armature(animations=anim_data) {
|
|
|
4304
4334
|
|
|
4305
4335
|
// Deep Volumetric Sapphire
|
|
4306
4336
|
// Showcasing: $asa=0.0 (Preserves faceted "cut" look of the crystal)
|
|
4307
|
-
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=
|
|
4337
|
+
color([1.0, 1.0, 1.0, 1.0], transmission=1.0, roughness=0.0, thickness=8.0, ior=1.76, attenuationColor=[0.1, 0.3, 0.9], attenuationDistance=6.0, $asa=30) {
|
|
4338
|
+
|
|
4339
|
+
// Use difference() to carve out an inner cavity so the shell is hollow,
|
|
4340
|
+
// allowing physically correct index-of-refraction depth sorting.
|
|
4341
|
+
difference() {
|
|
4342
|
+
// Octagonal faceted crystal shape
|
|
4343
|
+
union() {
|
|
4344
|
+
cylinder(h=5, r1=4, r2=0, $fn=8);
|
|
4345
|
+
translate([0,0,-5]) cylinder(h=5, r1=0, r2=4, $fn=8);
|
|
4346
|
+
}
|
|
4347
|
+
|
|
4348
|
+
// Hollow cavity
|
|
4349
|
+
sphere(r=0.9, $fn=32);
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4308
4352
|
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4353
|
+
// 4. Glowing Core (Child of Gem Shell)
|
|
4354
|
+
// Placed inside its own bone to prevent auto-unioning with the transparent gem
|
|
4355
|
+
bone(name="Core", t=[0,0,0]) {
|
|
4356
|
+
color([0.0, 0.0, 0.0, 1.0], emissive=[0.5, 0.8, 1.0], emissiveIntensity=20.0, $asa=45) {
|
|
4357
|
+
sphere(r=0.6, $fn=32);
|
|
4313
4358
|
}
|
|
4314
4359
|
}
|
|
4315
4360
|
}
|
|
4316
4361
|
}
|
|
4317
4362
|
}
|
|
4318
|
-
}`)r=n.origin+n.pathname+n.search;else try{n.hash=await ys(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 xs=document.getElementById(`drag-overlay`);window.addEventListener(`dragenter`,e=>{e.preventDefault(),xs.classList.add(`active`)}),window.addEventListener(`dragover`,e=>{e.preventDefault(),xs.classList.add(`active`)}),xs.addEventListener(`dragleave`,e=>{e.preventDefault(),xs.classList.remove(`active`)}),window.addEventListener(`drop`,async e=>{if(e.preventDefault(),xs.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,Ps=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,Ds(),ms(e)}catch(e){alert(`Failed to read file: `+e.message)}else alert(`Please drop a valid .scad or .hdr file.`)}});var Ss=null,Cs=``;async function ws(e){let t=await fetch(`${e}/api/scads`);if(!t.ok)throw Error(`Failed to fetch files`);return(await t.json()).files}function Ts(){Bo.innerHTML=`<option value="">-- Create New Model --</option>`,Array.isArray(Ss)&&Ss.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e,Bo.appendChild(n)}),Bo.value=Zo,Ho&&(Ho.style.display=Zo===``?`none`:`flex`)}function Es(){let e=Do.value.trim();return e&&=e.replace(/\.scad$/i,``).split(/[/\\]/).pop()+`.scad`,{filename:e}}function Ds(){if(Ss===null)return;let e=Bo.value===``,{filename:t}=Es(),n=z.value,r=!1;e?(t&&t!==`.scad`||n.trim()!==``)&&(r=!0):n!==cs.content&&(r=!0),r?(Vo.style.display=`flex`,Vo.innerText=`Save`):Vo.style.display=`none`}async function Os(e,t=!1){if(!e)return!1;try{return Ro.innerText=`Connecting...`,Ss=await ws(e),Cs=e,ss=!0,Ro.innerText=`Connected`,zo.classList.add(`active`),z.placeholder=`Enter OpenSCAD code here...`,Zo=``,Ts(),cs={isNew:!0,content:``},Ds(),!0}catch(e){return t?console.warn(`Auto-connect failed:`,e.message):alert(`Connection failed: `+e.message),Ro.innerText=`Connect`,zo.classList.remove(`active`),ss=!1,z.placeholder=wo,!1}}Ro.onclick=async()=>{await Os(Lo.value.trim(),!1)&&ms(ds())},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=Zo;return}let e=Bo.value;if(Zo=e,Ho&&(Ho.style.display=e===``?`none`:`flex`),e===``)Do.value=``,z.value=``,ms(ds()),cs={isNew:!0,content:``},Ds();else{let t=Ss[e];Do.value=t.replace(/\.scad$/i,``);try{let e=await fetch(`${Cs}/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,ms(ds()),cs={isNew:!1,content:n.content},Ds()}catch(e){alert(`Error loading model: `+e.message)}}}),Vo.onclick=async()=>{let{filename:e}=Es();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===``&&Ss&&Ss.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(`${Cs}/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`)}Ss=await ws(Cs);let r=Ss.findIndex(t=>t===e);Zo=r>=0?r.toString():``,Ts(),cs={isNew:!1,content:z.value},Ds()}catch(e){Ds(),alert(`Error: `+e.message)}},Ho.onclick=async()=>{let e=Bo.value;if(e===``)return;let t=Ss[e];if(confirm(`Are you sure you want to delete "${t}"?`))try{Ho.innerText=`Deleting...`;let e=await fetch(`${Cs}/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)}Ss=await ws(Cs),Zo=``,Ts(),Do.value=``,z.value=``,ms(ds()),cs={isNew:!0,content:``},Ds(),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 ks=new he(K),As=new ke(W,G);ks.addPass(As);var js=new Se(new E(B.clientWidth,B.clientHeight),.1,.1,2);ks.addPass(js);var Ms=new Ne;ks.addPass(Ms);var q=new So(K);q.bounces=10,q.transmissiveBounces=10,q.multipleImportanceSampling=!0,q.filterGlossyFactor=.2;var Ns=new je(G,K.domElement);Ns.addEventListener(`change`,()=>{q!==void 0&&q.updateCamera()});var Ps=null;new Co().load(`./aristea_wreck_puresky_2k.hdr`,e=>{e.mapping=303,W.environment=e,Ps=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?Ps&&(W.background=Ps,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)}),Ns.enableDamping=!0,Ns.dampingFactor=.1,Ns.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 Fs=new t(16777215,4473924,.6);Fs.position.set(0,20,0),Y.add(Fs);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)}));function Is(){U&&(ls=!1,U.paused=!0,Wo.innerText=`▶ Play`,_s())}function Ls(e){if(!H||!$o[e])return;U&&U.stop();let t=$o[e];U=H.clipAction(t),U.play(),U.time=0,H.update(0),ls=!0,U.paused=!1,Wo.innerText=`⏸ Pause`,Ko.value=0,_s()}Go.addEventListener(`change`,e=>{Ls(parseInt(e.target.value))}),Wo.addEventListener(`click`,()=>{U&&(ls=!ls,U.paused=!ls,Wo.innerText=ls?`⏸ Pause`:`▶ Play`,_s())}),Ko.addEventListener(`mousedown`,()=>{us=!0,Is()}),Ko.addEventListener(`mouseup`,()=>{us=!1}),Ko.addEventListener(`touchstart`,()=>{us=!0,Is()},{passive:!0}),Ko.addEventListener(`touchend`,()=>{us=!1},{passive:!0}),Ko.addEventListener(`input`,e=>{if(Is(),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 Rs(){rs&&is&&is.state!==`inactive`&&(is.stop(),rs=!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),_s()}function zs(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 Bs(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=zs(V,$o)),Rs();let i=e;e instanceof Uint8Array&&(i=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)),new we().parse(i,``,e=>{V=e.scene,$o=e.animations||[];let n=Yo?Yo.checked:!1;$o.length?(H=new se(V),Uo.style.display=`flex`,Go.innerHTML=``,$o.forEach((e,t)=>{let n=document.createElement(`option`);n.value=t,n.innerText=e.name||`Animation ${t+1}`,Go.appendChild(n)}),Ls(0)):(Uo.style.display=`none`,U=null,_s()),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=zs(V,$o);if(!e.isEmpty()){let t=.001;r.min.distanceTo(e.min)<t&&r.max.distanceTo(e.max)<t&&(i=!1)}}if(i)typeof Vs==`function`&&Vs();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 Vs(){if(!V)return;let e=zs(V,$o);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(),Ns.maxDistance=G.far,G.position.set(t.x+o*.8,t.y+o*.8,t.z-o*.8),G.lookAt(t),Ns.target.copy(t),Ns.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 Hs=performance.now();function Us(){requestAnimationFrame(Us);let e=performance.now(),t=(e-Hs)/1e3;if(Hs=e,H&&(!(J&&J.checked)&&!rs&&H.update(t),U&&ls&&!us)){let e=U.getClip().duration;if(e>0){let t=U.time%e;t<0&&(t+=e),Ko.value=t/e}}Ns.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&&!rs&&q.renderSample()):(Z!==void 0&&(Z.visible=!0),Y!==void 0&&(Y.visible=!0),Q!==void 0&&(Q.visible=r),$!==void 0&&($.visible=r),rs||ks.render()),ns&&(ns=!1,K.domElement.toBlob(e=>{e&&gs(e,`${fs()}.png`)},`image/png`))}Us(),window.addEventListener(`resize`,()=>{if(!B||rs)return;let e=B.clientWidth,t=B.clientHeight;G.aspect=e/t,G.updateProjectionMatrix(),K.setSize(e,t),ks.setSize(e,t)}),setTimeout(()=>window.dispatchEvent(new Event(`resize`)),100);var Ws=[`localhost`,`127.0.0.1`,``].includes(window.location.hostname);z.placeholder=Ws?`Enter OpenSCAD code here...`:wo,(async function(){if(Ws&&await Os(Lo.value.trim(),!0),window.location.hash&&window.location.hash.length>1)try{let e=await bs(window.location.hash.substring(1));e&&(z.value=e)}catch(e){console.error(`Failed to decode hash`,e)}Ds(),setTimeout(()=>ms(ds()),500)})();
|
|
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)})();
|