scad-gltf 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/scad-godot.js +15 -7
- package/bin/scad-web.js +6 -9
- package/editor/dist/assets/{index-V9cEH4KX.js → index-CXqDtloH.js} +2 -2
- package/editor/dist/assets/{prompt-ui-8EFRz0ju.js → prompt-ui-mDTjxcQO.js} +7 -4
- package/editor/dist/content.js +1 -1
- package/editor/dist/index.html +2 -2
- package/editor/dist/sw.js +1 -1
- package/package.json +1 -1
- package/src/prompt.js +8 -4
package/bin/scad-godot.js
CHANGED
|
@@ -180,7 +180,12 @@ ${promptRules}
|
|
|
180
180
|
const files = fs.readdirSync(addonDir);
|
|
181
181
|
for (const file of files) {
|
|
182
182
|
const fullPath = path.join(addonDir, file);
|
|
183
|
-
|
|
183
|
+
// Ensure we only read text files to prevent binary/hidden files
|
|
184
|
+
// from introducing control characters that crash browser UIs.
|
|
185
|
+
if (
|
|
186
|
+
fs.statSync(fullPath).isFile() &&
|
|
187
|
+
(file.endsWith(".gd") || file.endsWith(".cfg"))
|
|
188
|
+
) {
|
|
184
189
|
addonFiles.push(fullPath);
|
|
185
190
|
}
|
|
186
191
|
}
|
|
@@ -190,16 +195,19 @@ ${promptRules}
|
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
// 6. Format the unified system instructions clipboard output
|
|
193
|
-
let systemClipboardOutput =
|
|
194
|
-
|
|
195
|
-
systemClipboardOutput += `### SYSTEM_PROMPT\n---\n\`\`\`\n${systemPrompt}\n\`\`\`\n\n`;
|
|
198
|
+
let systemClipboardOutput = `${systemPrompt}\n\n`;
|
|
196
199
|
|
|
197
200
|
for (const file of addonFiles) {
|
|
198
201
|
try {
|
|
199
|
-
|
|
202
|
+
// Normalize line endings to avoid mixed line-ending layout loops in web editors
|
|
203
|
+
const content = fs.readFileSync(file, "utf-8").replace(/\r\n/g, "\n");
|
|
200
204
|
// Format to use relative paths and force forward slashes for LLM clarity
|
|
201
205
|
const relativePath = path.relative(DIR, file).replace(/\\/g, "/");
|
|
202
|
-
|
|
206
|
+
|
|
207
|
+
// Add explicit language tags to prevent catastrophic regex backtracking
|
|
208
|
+
// during the Markdown parser's language auto-detection step.
|
|
209
|
+
const lang = file.endsWith(".gd") ? "gdscript" : "text";
|
|
210
|
+
systemClipboardOutput += `### ${relativePath}\n---\n\`\`\`${lang}\n${content}\n\`\`\`\n\n`;
|
|
203
211
|
} catch (e) {
|
|
204
212
|
console.error(`Warning: Skipping '${file}'. It is not a readable file.`);
|
|
205
213
|
}
|
|
@@ -208,7 +216,7 @@ ${promptRules}
|
|
|
208
216
|
systemClipboardOutput = systemClipboardOutput.trimEnd() + "\n";
|
|
209
217
|
|
|
210
218
|
// 7. Format the input request output
|
|
211
|
-
const inputRequestOutput = `
|
|
219
|
+
const inputRequestOutput = `Design and implement a Godot 4 project for the following game concept: "${task}"`;
|
|
212
220
|
|
|
213
221
|
// 8. Write to System Clipboard (Part 1: System Instructions)
|
|
214
222
|
try {
|
package/bin/scad-web.js
CHANGED
|
@@ -163,15 +163,12 @@ ${promptRules}
|
|
|
163
163
|
- Your generated Vite web project files.
|
|
164
164
|
- Ensure all string file contents inside the Node.js script are properly escaped.`;
|
|
165
165
|
|
|
166
|
-
// 5. Format the
|
|
167
|
-
|
|
166
|
+
// 5. Format the input request output
|
|
167
|
+
const inputRequestOutput = `Design and implement a web-based 3D glTF app using Vite for the following concept: "${task}"`;
|
|
168
168
|
|
|
169
|
-
// 6.
|
|
170
|
-
const inputRequestOutput = `Input Task:\nDesign and implement a web-based 3D glTF app using Vite for the following concept: "${task}"`;
|
|
171
|
-
|
|
172
|
-
// 7. Write to System Clipboard (Part 1: System Instructions)
|
|
169
|
+
// 6. Write to System Clipboard (Part 1: System Instructions)
|
|
173
170
|
try {
|
|
174
|
-
await writeToClipboard(
|
|
171
|
+
await writeToClipboard(systemPrompt);
|
|
175
172
|
console.log("✔️ System instructions have been copied to the clipboard.");
|
|
176
173
|
} catch (err) {
|
|
177
174
|
console.error(
|
|
@@ -181,12 +178,12 @@ ${promptRules}
|
|
|
181
178
|
process.exit(1);
|
|
182
179
|
}
|
|
183
180
|
|
|
184
|
-
//
|
|
181
|
+
// 7. Await user confirmation
|
|
185
182
|
await waitForEnter(
|
|
186
183
|
"Please paste the system instructions into your LLM, then press ENTER to copy your input request...",
|
|
187
184
|
);
|
|
188
185
|
|
|
189
|
-
//
|
|
186
|
+
// 8. Write to System Clipboard (Part 2: Input Request)
|
|
190
187
|
try {
|
|
191
188
|
await writeToClipboard(inputRequestOutput);
|
|
192
189
|
console.log(
|
|
@@ -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
|
|
|
@@ -19,8 +19,7 @@ Important PBR & Shading rules:`,n.basic&&(r+=`
|
|
|
19
19
|
- Sheen Roughness: Controls the roughness of the sheen layer. (Default: 0.0)`),n.emissive&&(r+=`
|
|
20
20
|
- Emissive & Emissive Intensity: Makes the material glow. Emissive is an RGB color vector, intensity is a float multiplier. (Defaults: [0.0, 0.0, 0.0] and 1.0)`),n.specular&&(r+=`
|
|
21
21
|
- Specular Color & Intensity: Overrides the default specular reflection. (Defaults: [1.0, 1.0, 1.0] and 1.0)`),n.iridescence&&(r+=`
|
|
22
|
-
- Iridescence & Iridescence IOR: Simulates thin-film interference like soap bubbles, oil spills, or pearlescent surfaces. (Defaults: 0.0 and 1.3)`),n.autoSmoothAngle&&(r+=`
|
|
23
|
-
- Auto Smooth Angle: Generates smooth vertex normals for adjoining faces with an angle difference less than this value (in degrees). Use > 0 (e.g., 30 or 45) for curved/smooth surfaces, 0.0 for flat shading. Can be set globally using the special variable $asa (e.g., $asa=30;), or overridden per-material via the $asa parameter INSIDE the color() module. IMPORTANT: $asa ONLY affects surface shading (normals). It DOES NOT alter the actual geometry or polygon count. You must still use standard variables like $fn to increase geometric resolution. DO NOT pass $asa directly to geometry modules like sphere() or cylinder(). (Default: 0.0)`);let e=[];n.basic&&e.push(`metalness=1.0`,`roughness=0.3`),n.transmission&&e.push(`transmission=0.8`,`ior=1.5`),n.clearcoat&&e.push(`clearcoat=1.0`),n.sheen&&e.push(`sheen=1.0`),n.iridescence&&e.push(`iridescence=1.0`),n.emissive&&e.push(`emissive=[0.0, 0.5, 1.0]`,`emissiveIntensity=2.0`),n.specular&&e.push(`specularIntensity=1.0`),n.autoSmoothAngle&&e.push(`$asa=45.0`);let t=e.length>0?`, `+e.join(`, `):``;r+=`\n\nExample Material Usage:\n// Syntax: color(c=color_value, alpha=1.0, [named PBR parameters...])\ncolor([0.2, 0.2, 0.2], alpha=1.0${t})\n cube([10, 10, 10]);`}if(n.lazyUnion&&(r+=`
|
|
22
|
+
- Iridescence & Iridescence IOR: Simulates thin-film interference like soap bubbles, oil spills, or pearlescent surfaces. (Defaults: 0.0 and 1.3)`),n.autoSmoothAngle&&(r+="\n- Auto Smooth Angle: Generates smooth vertex normals for adjoining faces with an angle difference less than this value (in degrees). Use > 0 (e.g., 30 or 45) for curved/smooth surfaces, 0.0 for flat shading. Can be set globally using the special variable `$asa` (e.g., `$asa=30;`), or overridden per-material via the `$asa` parameter INSIDE the color() module. IMPORTANT: `$asa` ONLY affects surface shading (normals). It DOES NOT alter the actual geometry or polygon count. You must still use standard variables like `$fn` to increase geometric resolution. DO NOT pass `$asa` directly to geometry modules like sphere() or cylinder(). (Default: 0.0)");let e=[];n.basic&&e.push(`metalness=1.0`,`roughness=0.3`),n.transmission&&e.push(`transmission=0.8`,`ior=1.5`),n.clearcoat&&e.push(`clearcoat=1.0`),n.sheen&&e.push(`sheen=1.0`),n.iridescence&&e.push(`iridescence=1.0`),n.emissive&&e.push(`emissive=[0.0, 0.5, 1.0]`,`emissiveIntensity=2.0`),n.specular&&e.push(`specularIntensity=1.0`),n.autoSmoothAngle&&e.push(`$asa=45.0`);let t=e.length>0?`, `+e.join(`, `):``;r+=`\n\nExample Material Usage:\n\`\`\`openscad\n// Syntax: color(c=color_value, alpha=1.0, [named PBR parameters...])\ncolor([0.2, 0.2, 0.2], alpha=1.0${t})\n cube([10, 10, 10]);\n\`\`\``}if(n.lazyUnion&&(r+=`
|
|
24
23
|
|
|
25
24
|
Important Geometry rules:
|
|
26
25
|
- The compiler runs with "lazy-union" enabled. This means top-level objects, module children, and items inside loops ('for') or conditionals ('if') are NOT implicitly boolean-unioned together. They are evaluated and exported as separate discrete meshes.`),n.animation&&(r+=`
|
|
@@ -43,6 +42,7 @@ Important Animation rules:
|
|
|
43
42
|
- Translational & Rotational Keyframes: Keyframe translations and rotations are ABSOLUTE in local space. They completely replace the bone's resting 't' and 'r' attributes during the animation. If a bone's resting translation is [0, 0, 2] and it needs to move 10 units up, the keyframe translation must be [0, 0, 12]. If translation is omitted, it defaults to the resting position.
|
|
44
43
|
|
|
45
44
|
Example Animation Usage:
|
|
45
|
+
\`\`\`openscad
|
|
46
46
|
anim_data = [
|
|
47
47
|
["Action 1", [
|
|
48
48
|
["BaseSpinner", [
|
|
@@ -72,7 +72,8 @@ armature(animations=anim_data) {
|
|
|
72
72
|
color([0.8, 0.2, 0.2]) cylinder(h=5, r=2);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
|
76
|
+
\`\`\``),n.bakeColors||n.bakeNormals||n.bakeOrm||n.bakeUvs){let e=[],t=[];n.bakeColors&&(e.push(`colors=true`),t.push(`- Set 'colors=true' (default false) to project and bake the high-poly's solid colors onto the low-poly mesh.`)),n.bakeNormals&&(e.push(`normals=true`),t.push(`- Set 'normals=true' (default false) to project and bake the high-poly's physical geometric details as a tangent-space normal map onto the low-poly mesh.`)),n.bakeOrm&&(e.push(`orm=true`),t.push(`- Set 'orm=true' (default false) to project and bake the high-poly's Roughness, and Metallic values onto the low-poly mesh.`)),n.bakeUvs&&(e.push(`uvs=true`),t.push(`- Set 'uvs=true' (default false) when you only want to generate UV coordinates and Tangent vectors without baking any image textures. Note that UVs and Tangents are automatically generated whenever 'colors', 'normals', or 'orm' are enabled, so 'uvs=true' is only explicitly needed for textureless UV-only exports.`)),t.push(`- You can customize the baking process using 'distance' (max ray length, default: 2.0), 'bias' (ray origin offset, default: 1e-4), 'dilation' (pixel padding around UV islands, default: 2), 'resolution' (texture dimensions, default: 512), 'msaa' (super-sampling anti-aliasing level, default: 2), 'index' (atlas group identifier, default: 0), and 'rotate_uvs' (allow UV islands to be rotated for better packing, default: true).`),t.push(`- The 'index' parameter enables multi-atlas texture baking. Low-poly meshes configured with the same 'index' will be packed together into a shared texture atlas, while meshes with distinct indices will be split into separate output image maps.`),e.push(`resolution=1024`);let i=e.length>0?`bake(${e.join(`, `)})`:`bake()`,a=t.length>0?t.join(`
|
|
76
77
|
`):`- You can toggle what gets baked using the 'colors', 'normals', 'orm', and 'uvs' boolean parameters (all default to false).`;r+=`\n\nImportant Texture Baking rules:
|
|
77
78
|
- Baking: Use the 'bake()' module to project details from a high-resolution mesh onto a low-resolution mesh.
|
|
78
79
|
- UV Unwrapping: The engine automatically generates UV coordinates and bakes the textures for the low-poly child mesh; you do not need to manually map textures.
|
|
@@ -80,6 +81,7 @@ armature(animations=anim_data) {
|
|
|
80
81
|
${a}
|
|
81
82
|
|
|
82
83
|
Example Baking Usage:
|
|
84
|
+
\`\`\`openscad
|
|
83
85
|
// Bake the selected details of a high-resolution sphere onto a low-resolution one
|
|
84
86
|
${i} {
|
|
85
87
|
color("white") sphere(r=10, $fn=100); // Child 1: High Poly
|
|
@@ -89,7 +91,8 @@ ${i} {
|
|
|
89
91
|
// Alternatively, generate UVs/Tangents for a mesh WITHOUT a high-poly source by providing only 1 child
|
|
90
92
|
bake(uvs=true) {
|
|
91
93
|
color("white") cube([10, 10, 10]);
|
|
92
|
-
}
|
|
94
|
+
}
|
|
95
|
+
\`\`\``}return r}var t=`
|
|
93
96
|
<div class="scad-prompt-toggles">
|
|
94
97
|
<label><input type="checkbox" id="opt-pbr-basic" checked /> Basic PBR</label>
|
|
95
98
|
<label><input type="checkbox" id="opt-pbr-autosmooth" checked /> Auto Smooth</label>
|
package/editor/dist/content.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e,n as t,r as n,t as r}from"./assets/prompt-ui-
|
|
1
|
+
import{i as e,n as t,r as n,t as r}from"./assets/prompt-ui-mDTjxcQO.js";console.log(`🚀 SCAD Preview Extension loaded!`),window.addEventListener(`message`,e=>{if(e.data){if(e.data.type===`CLOSE_PREVIEW`){let e=document.getElementById(`scad-preview-iframe`);e&&e.remove()}else e.data.type===`ADD_IMAGE_TO_CHAT`&&i(e.data.dataUrl)}});async function i(e){try{let t=await(await fetch(e)).blob(),n=new File([t],`preview.png`,{type:`image/png`}),r=document.querySelector(`ms-prompt-box textarea[formcontrolname="promptText"]`)||document.querySelector(`ms-prompt-box textarea`)||document.querySelector(`textarea`);if(r){r.focus();let e=new DataTransfer;e.items.add(n);let t=new ClipboardEvent(`paste`,{clipboardData:e,bubbles:!0,cancelable:!0});r.dispatchEvent(t)}else console.warn(`Could not find chat input to paste the image.`)}catch(e){console.error(`Error adding image to chat:`,e)}}new MutationObserver(()=>{a(),o(),document.querySelectorAll(`ms-code-block[data-test-language="openscad" i], ms-code-block[data-test-language="scad" i]`).forEach(e=>{if(e.querySelector(`.scad-preview-btn`))return;let t=document.createElement(`button`);t.className=`scad-preview-btn`,t.title=`Preview 3D`,t.setAttribute(`aria-label`,`Preview 3D`),t.innerHTML=`
|
|
2
2
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3
3
|
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path>
|
|
4
4
|
<polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline>
|
package/editor/dist/index.html
CHANGED
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
content="https://iliagrigorevdev.github.io/scad-gltf/icon.png"
|
|
45
45
|
/>
|
|
46
46
|
|
|
47
|
-
<script type="module" crossorigin src="./assets/index-
|
|
47
|
+
<script type="module" crossorigin src="./assets/index-CXqDtloH.js"></script>
|
|
48
48
|
<link rel="modulepreload" crossorigin href="./assets/OutputPass-Bvl6NigM.js">
|
|
49
|
-
<link rel="modulepreload" crossorigin href="./assets/prompt-ui-
|
|
49
|
+
<link rel="modulepreload" crossorigin href="./assets/prompt-ui-mDTjxcQO.js">
|
|
50
50
|
<link rel="stylesheet" crossorigin href="./assets/index-t9MYrExo.css">
|
|
51
51
|
<link rel="manifest" href="./manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="./registerSW.js"></script></head>
|
|
52
52
|
<body>
|
package/editor/dist/sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
if(!self.define){let e,s={};const i=(i,r)=>(i=new URL(i+".js",r).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(r,n)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let l={};const o=e=>i(e,t),
|
|
1
|
+
if(!self.define){let e,s={};const i=(i,r)=>(i=new URL(i+".js",r).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(r,n)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let l={};const o=e=>i(e,t),c={module:{uri:t},exports:l,require:o};s[t]=Promise.all(r.map(e=>c[e]||o(e))).then(e=>(n(...e),l))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"402b66900e731ca748771b6fc5e7a068"},{url:"preview.html",revision:"c90d9c25847a398e770ccae0a6dad222"},{url:"index.html",revision:"3bb2e87bf61bcfac35db086f0fbc4c89"},{url:"icon.png",revision:"20a5bd64b0ab560837e6333f5afd2bf2"},{url:"content.js",revision:"fe4d9df0d512444e8fd3e28dce98b2ad"},{url:"content.css",revision:"8a04232febb2faba7b10edc60e2974dd"},{url:"content-loader.js",revision:"d94f1755552d49c1fe3a6da123e8a346"},{url:"aristea_wreck_puresky_2k.hdr",revision:"e764c66f871ab0987f3fac422edc841d"},{url:"assets/prompt-ui-mDTjxcQO.js",revision:null},{url:"assets/preview-fQfL_FJ-.css",revision:null},{url:"assets/preview-C1zc24MJ.js",revision:null},{url:"assets/openscad-CdBCY4mx.wasm",revision:null},{url:"assets/index-t9MYrExo.css",revision:null},{url:"assets/index-CXqDtloH.js",revision:null},{url:"assets/OutputPass-Bvl6NigM.js",revision:null},{url:"icon.png",revision:"20a5bd64b0ab560837e6333f5afd2bf2"},{url:"manifest.webmanifest",revision:"81dc3433323859b43ec568f4f95cd344"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});
|
package/package.json
CHANGED
package/src/prompt.js
CHANGED
|
@@ -89,7 +89,7 @@ export function generatePrompt(description, options = {}) {
|
|
|
89
89
|
prompt += `\n- Iridescence & Iridescence IOR: Simulates thin-film interference like soap bubbles, oil spills, or pearlescent surfaces. (Defaults: 0.0 and 1.3)`;
|
|
90
90
|
}
|
|
91
91
|
if (opts.autoSmoothAngle) {
|
|
92
|
-
prompt += `\n- Auto Smooth Angle: Generates smooth vertex normals for adjoining faces with an angle difference less than this value (in degrees). Use > 0 (e.g., 30 or 45) for curved/smooth surfaces, 0.0 for flat shading. Can be set globally using the special variable
|
|
92
|
+
prompt += `\n- Auto Smooth Angle: Generates smooth vertex normals for adjoining faces with an angle difference less than this value (in degrees). Use > 0 (e.g., 30 or 45) for curved/smooth surfaces, 0.0 for flat shading. Can be set globally using the special variable \`$asa\` (e.g., \`$asa=30;\`), or overridden per-material via the \`$asa\` parameter INSIDE the color() module. IMPORTANT: \`$asa\` ONLY affects surface shading (normals). It DOES NOT alter the actual geometry or polygon count. You must still use standard variables like \`$fn\` to increase geometric resolution. DO NOT pass \`$asa\` directly to geometry modules like sphere() or cylinder(). (Default: 0.0)`;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
let exampleParams = [];
|
|
@@ -106,7 +106,7 @@ export function generatePrompt(description, options = {}) {
|
|
|
106
106
|
let exampleStr =
|
|
107
107
|
exampleParams.length > 0 ? ", " + exampleParams.join(", ") : "";
|
|
108
108
|
|
|
109
|
-
prompt += `\n\nExample Material Usage:\n// Syntax: color(c=color_value, alpha=1.0, [named PBR parameters...])\ncolor([0.2, 0.2, 0.2], alpha=1.0${exampleStr})\n cube([10, 10, 10])
|
|
109
|
+
prompt += `\n\nExample Material Usage:\n\`\`\`openscad\n// Syntax: color(c=color_value, alpha=1.0, [named PBR parameters...])\ncolor([0.2, 0.2, 0.2], alpha=1.0${exampleStr})\n cube([10, 10, 10]);\n\`\`\``;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
if (opts.lazyUnion) {
|
|
@@ -132,6 +132,7 @@ export function generatePrompt(description, options = {}) {
|
|
|
132
132
|
- Translational & Rotational Keyframes: Keyframe translations and rotations are ABSOLUTE in local space. They completely replace the bone's resting 't' and 'r' attributes during the animation. If a bone's resting translation is [0, 0, 2] and it needs to move 10 units up, the keyframe translation must be [0, 0, 12]. If translation is omitted, it defaults to the resting position.
|
|
133
133
|
|
|
134
134
|
Example Animation Usage:
|
|
135
|
+
\`\`\`openscad
|
|
135
136
|
anim_data = [
|
|
136
137
|
["Action 1", [
|
|
137
138
|
["BaseSpinner", [
|
|
@@ -161,7 +162,8 @@ armature(animations=anim_data) {
|
|
|
161
162
|
color([0.8, 0.2, 0.2]) cylinder(h=5, r=2);
|
|
162
163
|
}
|
|
163
164
|
}
|
|
164
|
-
}
|
|
165
|
+
}
|
|
166
|
+
\`\`\``;
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
if (opts.bakeColors || opts.bakeNormals || opts.bakeOrm || opts.bakeUvs) {
|
|
@@ -213,6 +215,7 @@ armature(animations=anim_data) {
|
|
|
213
215
|
${explanationText}
|
|
214
216
|
|
|
215
217
|
Example Baking Usage:
|
|
218
|
+
\`\`\`openscad
|
|
216
219
|
// Bake the selected details of a high-resolution sphere onto a low-resolution one
|
|
217
220
|
${bakeSig} {
|
|
218
221
|
color("white") sphere(r=10, $fn=100); // Child 1: High Poly
|
|
@@ -222,7 +225,8 @@ ${bakeSig} {
|
|
|
222
225
|
// Alternatively, generate UVs/Tangents for a mesh WITHOUT a high-poly source by providing only 1 child
|
|
223
226
|
bake(uvs=true) {
|
|
224
227
|
color("white") cube([10, 10, 10]);
|
|
225
|
-
}
|
|
228
|
+
}
|
|
229
|
+
\`\`\``;
|
|
226
230
|
}
|
|
227
231
|
|
|
228
232
|
return prompt;
|