three-live 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +4 -1
  2. package/dist/index.d.ts +191 -0
  3. package/dist/three-author-engine.js +179 -144
  4. package/dist/three-author.cjs +153 -144
  5. package/dist/three-author.d.ts +191 -0
  6. package/dist/three-author.js +153 -144
  7. package/dist/three-convert.cjs +150 -141
  8. package/dist/three-convert.d.ts +191 -0
  9. package/dist/three-convert.js +150 -141
  10. package/dist/three-live-ai.cjs +41 -0
  11. package/dist/three-live-ai.d.ts +759 -0
  12. package/dist/three-live-ai.js +41 -0
  13. package/dist/three-live-ai.min.js +41 -0
  14. package/dist/three-live-animation.cjs +6 -6
  15. package/dist/three-live-animation.d.ts +191 -0
  16. package/dist/three-live-animation.js +5 -5
  17. package/dist/three-live-animation.min.js +5 -5
  18. package/dist/three-live-cad.cjs +2 -2
  19. package/dist/three-live-cad.d.ts +191 -0
  20. package/dist/three-live-cad.js +2 -2
  21. package/dist/three-live-cad.min.js +2 -2
  22. package/dist/three-live-element.cjs +50 -85
  23. package/dist/three-live-element.d.ts +191 -0
  24. package/dist/three-live-element.js +50 -85
  25. package/dist/three-live-full.cjs +915 -170
  26. package/dist/three-live-full.js +917 -172
  27. package/dist/three-live-full.min.js +915 -170
  28. package/dist/three-live-procedural.cjs +16 -0
  29. package/dist/three-live-procedural.d.ts +759 -0
  30. package/dist/three-live-procedural.js +16 -0
  31. package/dist/three-live-procedural.min.js +16 -0
  32. package/dist/three-live-sandbox.html +11 -1
  33. package/dist/three-live-studio.cjs +72 -17
  34. package/dist/three-live-studio.d.ts +191 -0
  35. package/dist/three-live-studio.js +72 -17
  36. package/dist/three-live-studio.min.js +73 -18
  37. package/dist/three-live-tsl.cjs +103 -0
  38. package/dist/three-live-tsl.d.ts +759 -0
  39. package/dist/three-live-tsl.js +103 -0
  40. package/dist/three-live-tsl.min.js +103 -0
  41. package/dist/three-live-viewer.cjs +50 -85
  42. package/dist/three-live-viewer.d.ts +191 -0
  43. package/dist/three-live-viewer.js +50 -85
  44. package/dist/three-live-viewer.min.js +50 -85
  45. package/dist/three-live-webgpu.cjs +585 -0
  46. package/dist/three-live-webgpu.d.ts +759 -0
  47. package/dist/three-live-webgpu.js +585 -0
  48. package/dist/three-live-webgpu.min.js +585 -0
  49. package/dist/three-live.cjs +155 -146
  50. package/dist/three-live.js +155 -146
  51. package/dist/three-live.min.js +155 -146
  52. package/dist/three-view.cjs +49 -84
  53. package/dist/three-view.d.ts +191 -0
  54. package/dist/three-view.js +50 -85
  55. package/dist/three-xr.cjs +150 -141
  56. package/dist/three-xr.d.ts +191 -0
  57. package/dist/three-xr.js +150 -141
  58. package/package.json +39 -1
@@ -13,7 +13,7 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */function zr(e,t,i){let r=[],s=new Map,n=[],o=[],a=[],h=new Map,l=m=>{let p=s.get(m);return p===void 0&&(p=r.length,r.push({op:m}),s.set(m,p)),p},c=m=>{let p=h.get(m);return p===void 0&&(p=a.length,a.push({id:m}),h.set(m,p)),p},f=(m,p={})=>n.push({declaration:l(m),...p})-1,y=(m,p,v)=>o.push({id:m,type:p,value:v})-1,g=m=>({node:m,socket:"value"}),u=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(u&&typeof u=="object"){let m=Array.isArray(u.graphs)?u.graphs[u.graph??0]:u;if(m&&Array.isArray(m.nodes)){let p=Array.isArray(m.declarations)?m.declarations:[];for(let v of p)v?.op&&l(v.op);Array.isArray(m.variables)&&o.push(...m.variables);for(let v of m.events||[])v?.id&&c(v.id);for(let v of m.nodes){if(!v||typeof v!="object")continue;let R=v.op||(typeof v.declaration=="number"?p[v.declaration]?.op:"");n.push(R?{...v,declaration:l(R)}:{...v})}}}let b=(m,p,v="translation")=>v==="baseColorFactor"||v==="metallicFactor"||v==="roughnessFactor"?`/materials/${Math.max(0,p)}/pbrMetallicRoughness/${v}`:v==="emissiveFactor"||v==="alphaCutoff"?`/materials/${Math.max(0,p)}/${v}`:v==="visible"?`/nodes/${m}/extensions/KHR_node_visibility/visible`:`/nodes/${m}/${v}`,w=new Map;e.forEach((m,p)=>{typeof m?.name=="string"&&!w.has(m.name)&&w.set(m.name,p)});let M=(m,p)=>typeof m.target=="string"&&w.has(m.target)?w.get(m.target):typeof m.targetNode=="number"?m.targetNode:p,x=m=>{let p=e[m];return(typeof p?.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0};for(let m=0;m<e.length;m++){let p=e[m],v=p?.extras?.interactivity;if(!v||typeof v!="object")continue;let R=(typeof p.mesh=="number"?t[p.mesh]?.primitives?.[0]?.material:0)??0,L=N=>{let _=Array.isArray(N)?N:[N],A=[];for(let C=0;C<_.length;C++){let d=_[C];if(!d||typeof d!="object")continue;let k=d.action||"interpolate",$=typeof d.duration=="number"?d.duration:.35;if(k==="toggleTransform"){let S=d.property==="rotation"||d.property==="scale"?d.property:"translation",D=S==="rotation"?p.rotation||[0,0,0,1]:S==="scale"?p.scale||[1,1,1]:p.translation||[0,0,0],T=`/nodes/${m}/${S}`,P=y(`__toggle_${m}_${C}`,"bool",!1),j=f("variable/get",{configuration:{variable:P}}),W=f("math/not",{values:{a:g(j)}}),V=f("variable/set",{configuration:{variable:P},values:{value:g(W)}}),Z=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.to)?d.to:D},duration:{value:$}}}),U=f("pointer/interpolate",{configuration:{pointer:T},values:{value:{value:Array.isArray(d.from)?d.from:D},duration:{value:$}}});n[V].flows={out:{node:f("flow/branch",{values:{condition:g(j)},flows:{true:{node:Z},false:{node:U}}})}},A.push(V)}else if(k==="interpolate"){let S=d.to??d.value;if(S===void 0)continue;let D={value:{value:S},duration:{value:$}};d.from!==void 0&&(D.from={value:d.from}),A.push(f("pointer/interpolate",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:D}))}else if(k==="setProperty"){if(d.value===void 0)continue;A.push(f("pointer/set",{configuration:{pointer:typeof d.pointer=="string"?d.pointer:b(M(d,m),x(M(d,m)),d.property)},values:{value:{value:d.value}}}))}else if(k==="toggleVisibility"){let S=M(d,m),D=y(`__vis_${S}_${C}`,"bool",!0),T=f("variable/get",{configuration:{variable:D}}),P=f("math/not",{values:{a:g(T)}}),j=f("variable/set",{configuration:{variable:D},values:{value:g(P)}});n[j].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${S}/extensions/KHR_node_visibility/visible`},values:{value:g(T)}})}},A.push(j)}else if(k==="cycleMaterialColor"&&Array.isArray(d.colors)&&d.colors.length>0){let S=typeof d.duration=="number"?d.duration:.25,D=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,T=y(`__color_idx_${m}_${C}`,"int",0),P=f("variable/get",{configuration:{variable:T}}),j=f("math/add",{values:{a:g(P),b:{value:1}}}),W=f("math/rem",{values:{a:g(j),b:{value:d.colors.length}}}),V=f("variable/set",{configuration:{variable:T},values:{value:g(W)}}),Z={};for(let U=0;U<d.colors.length;U++){let X=d.colors[U],O=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];Z[String(U)]={node:S>0?f("pointer/interpolate",{configuration:{pointer:D},values:{value:{value:O},duration:{value:S}}}):f("pointer/set",{configuration:{pointer:D},values:{value:{value:O}}})}}n[V].flows={out:{node:f("flow/switch",{values:{selection:g(P)},flows:Z})}},A.push(V)}else if(k==="playAnimation")A.push(f("animation/start",{configuration:{animation:d.animation??d.clip??0}}));else if(k==="stopAnimation")A.push(f("animation/stop"));else if(k==="sendEvent"){let S={};for(let[D,T]of Object.entries(d.values||{}))S[D]={value:T};A.push(f("event/send",{configuration:{event:c(String(d.event??d.id??"custom"))},values:S}))}}if(!A.length)return null;if(A.length===1)return A[0];let E={};return A.forEach((C,d)=>{E[String(d)]={node:C}}),f("flow/sequence",{flows:E})},I=(N,_,A)=>{let E=L(_);E!==null&&f(N,{...A?{configuration:A}:{},flows:{out:{node:E}}})};if(v.onSelect&&I("pointer/onSelect",v.onSelect,{nodeIndex:m}),v.onHoverIn&&I("pointer/onHoverIn",v.onHoverIn,{nodeIndex:m}),v.onHoverOut&&I("pointer/onHoverOut",v.onHoverOut,{nodeIndex:m}),v.onStart&&I("event/onStart",v.onStart),v.onReceive&&typeof v.onReceive=="object")for(let[N,_]of Object.entries(v.onReceive))I("event/receive",_,{event:c(N)})}return n.length?{graphs:[{declarations:r,nodes:n,variables:o,events:a}],graph:0}:null}var Vr='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',Or="Security Error: client-side scripts require allow-client-scripts opt-in.",Jt="__THREE_LIVE_REGISTRY__";function ut(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Jt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Jt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Jt]=t}}return e[Jt]}var mt=ut().plugins;function Br(e){let t=ut().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function $r(){return ut().plugins}function ht(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ge(e,t,i,r,s){let n=1/Math.tan(t/2);e.fill(0),e[0]=n/i,e[5]=n,e[11]=-1;let o=1/(r-s);return e[10]=(s+r)*o,e[14]=2*s*r*o,e}function Qt(e,t,i,r){let[s,n,o]=t,[a,h,l]=r,[c,f,y]=i,g=s-c,u=n-f,b=o-y,w=Math.hypot(g,u,b);w<=1e-5?(g=0,u=0,b=1):(g/=w,u/=w,b/=w);let M=h*b-l*u,x=l*g-a*b,m=a*u-h*g;w=Math.hypot(M,x,m),w<=1e-5?(M=0,x=0,m=0):(M/=w,x/=w,m/=w);let p=u*m-b*x,v=b*M-g*m,R=g*x-u*M;return w=Math.hypot(p,v,R),w<=1e-5?(p=0,v=0,R=0):(p/=w,v/=w,R/=w),e[0]=M,e[1]=p,e[2]=g,e[3]=0,e[4]=x,e[5]=v,e[6]=u,e[7]=0,e[8]=m,e[9]=R,e[10]=b,e[11]=0,e[12]=-(M*s+x*n+m*o),e[13]=-(p*s+v*n+R*o),e[14]=-(g*s+u*n+b*o),e[15]=1,e}function dt(e,t,i){let r=t[0],s=t[1],n=t[2],o=t[3],a=t[4],h=t[5],l=t[6],c=t[7],f=t[8],y=t[9],g=t[10],u=t[11],b=t[12],w=t[13],M=t[14],x=t[15],m=i[0],p=i[1],v=i[2],R=i[3];return e[0]=m*r+p*a+v*f+R*b,e[1]=m*s+p*h+v*y+R*w,e[2]=m*n+p*l+v*g+R*M,e[3]=m*o+p*c+v*u+R*x,m=i[4],p=i[5],v=i[6],R=i[7],e[4]=m*r+p*a+v*f+R*b,e[5]=m*s+p*h+v*y+R*w,e[6]=m*n+p*l+v*g+R*M,e[7]=m*o+p*c+v*u+R*x,m=i[8],p=i[9],v=i[10],R=i[11],e[8]=m*r+p*a+v*f+R*b,e[9]=m*s+p*h+v*y+R*w,e[10]=m*n+p*l+v*g+R*M,e[11]=m*o+p*c+v*u+R*x,m=i[12],p=i[13],v=i[14],R=i[15],e[12]=m*r+p*a+v*f+R*b,e[13]=m*s+p*h+v*y+R*w,e[14]=m*n+p*l+v*g+R*M,e[15]=m*o+p*c+v*u+R*x,e}function ye(e,t,i,r){let s=t[0],n=t[1],o=t[2],a=t[3],h=s+s,l=n+n,c=o+o,f=s*h,y=s*l,g=s*c,u=n*l,b=n*c,w=o*c,M=a*h,x=a*l,m=a*c,p=r[0],v=r[1],R=r[2];return e[0]=(1-(u+w))*p,e[1]=(y+m)*p,e[2]=(g-x)*p,e[3]=0,e[4]=(y-m)*v,e[5]=(1-(f+w))*v,e[6]=(b+M)*v,e[7]=0,e[8]=(g+x)*R,e[9]=(b-M)*R,e[10]=(1-(f+u))*R,e[11]=0,e[12]=i[0],e[13]=i[1],e[14]=i[2],e[15]=1,e}function Pt(e,t,i=0){let r=t[0],s=t[1],n=t[2],o=t[4],a=t[5],h=t[6],l=t[8],c=t[9],f=t[10],y=f*a-h*c,g=-f*o+h*l,u=c*o-a*l,b=r*y+s*g+n*u;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,e[0]=y*b,e[1]=g*b,e[2]=u*b,e[3]=(-f*s+n*c)*b,e[4]=(f*r-n*l)*b,e[5]=(-c*r+s*l)*b,e[6]=(h*s-n*a)*b,e[7]=(-h*r+n*o)*b,e[8]=(a*r-s*o)*b),e}function Gr(e,t){let i=t[0],r=t[1],s=t[2],n=t[3],o=t[4],a=t[5],h=t[6],l=t[7],c=t[8],f=t[9],y=t[10],g=t[11],u=t[12],b=t[13],w=t[14],M=t[15],x=i*a-r*o,m=i*h-s*o,p=i*l-n*o,v=r*h-s*a,R=r*l-n*a,L=s*l-n*h,I=c*b-f*u,N=c*w-y*u,_=c*M-g*u,A=f*w-y*b,E=f*M-g*b,C=y*M-g*w,d=x*C-m*E+p*A+v*_-R*N+L*I;return d?(d=1/d,e[0]=(a*C-h*E+l*A)*d,e[1]=(s*E-r*C-n*A)*d,e[2]=(b*L-w*R+M*v)*d,e[3]=(y*R-f*L-g*v)*d,e[4]=(h*_-o*C-l*N)*d,e[5]=(i*C-s*_+n*N)*d,e[6]=(w*p-u*L-M*m)*d,e[7]=(c*L-y*p+g*m)*d,e[8]=(o*E-a*_+l*I)*d,e[9]=(r*_-i*E-n*I)*d,e[10]=(u*R-b*p+M*x)*d,e[11]=(f*p-c*R-g*x)*d,e[12]=(a*N-o*A-h*I)*d,e[13]=(i*A-r*N+s*I)*d,e[14]=(b*m-u*v-w*x)*d,e[15]=(c*v-f*m+y*x)*d,e):null}function Ye(e,t,i,r,s){let n=s[0]*t+s[4]*i+s[8]*r+s[12],o=s[1]*t+s[5]*i+s[9]*r+s[13],a=s[2]*t+s[6]*i+s[10]*r+s[14],h=s[3]*t+s[7]*i+s[11]*r+s[15],l=h!==0?1/h:1;e[0]=n*l,e[1]=o*l,e[2]=a*l}function Hr(e,t,i,r,s,n,o,a,h,l,c,f,y,g,u,b,w=0){let M=l-o,x=c-a,m=f-h,p=y-o,v=g-a,R=u-h,L=s*R-n*v,I=n*p-r*R,N=r*v-s*p,_=M*L+x*I+m*N;if(_>-1e-7&&_<1e-7)return!1;let A=1/_,E=e-o,C=t-a,d=i-h,k=A*(E*L+C*I+d*N);if(k<-w||k>1+w)return!1;let $=C*m-d*x,S=d*M-E*m,D=E*x-C*M,T=A*(r*$+s*S+n*D);if(T<-w||k+T>1+w)return!1;let P=A*(p*$+v*S+R*D);if(P>1e-4&&P<b.distance){b.distance=P,b.point=[e+r*P,t+s*P,i+n*P];let j=x*R-m*v,W=m*p-M*R,V=M*v-x*p,Z=Math.hypot(j,W,V)||1;return b.normal=[j/Z,W/Z,V/Z],!0}return!1}function jr(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let c=0;c<i;c++)r.push(ht());if(i===0)return r;let s=new Set;for(let c of e.nodes)if(Array.isArray(c.children))for(let f of c.children)s.add(f);let n=new Set,o=128,a=(c,f,y=0)=>{if(y>o||c<0||c>=i||n.has(c))return;n.add(c);let g=e.nodes[c];if(!g)return;let u=ht();if(t&&t[c])u.set(t[c]);else if(g.matrix&&g.matrix.length===16)u.set(g.matrix);else{let w=g.translation||[0,0,0],M=g.rotation||[0,0,0,1],x=g.scale||[1,1,1];ye(u,M,w,x)}let b=r[c];if(f?dt(b,f,u):b.set(u),Array.isArray(g.children))for(let w of g.children)typeof w=="number"&&a(w,b,y+1)},h=[],l=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(l&&Array.isArray(l.nodes))h.push(...l.nodes);else for(let c=0;c<i;c++)s.has(c)||h.push(c);for(let c of h)a(c,null);for(let c=0;c<i;c++)!s.has(c)&&!h.includes(c)&&a(c,null);return r}var Wr={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Ze(e,t,i,r){if(!i||i.bufferView===void 0)return null;let s=e.bufferViews?.[i.bufferView];if(!s)return null;let n=Number(i.count??0);if(!Number.isInteger(n)||n<=0)return null;let o=i.componentType??5126,a=Wr[o];if(!a)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let h=a*r,l=s.byteStride&&s.byteStride>0?s.byteStride:h,c=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(c)||c<0||l<h||c+(n-1)*l+h>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(o===5126&&l===h&&c%4===0)return new Float32Array(t,c,n*r);let f=new DataView(t),y=i.normalized===!0,g=new Float32Array(n*r);for(let u=0;u<n;u++){let b=c+u*l;for(let w=0;w<r;w++){let M=b+w*a,x;switch(o){case 5126:x=f.getFloat32(M,!0);break;case 5120:x=f.getInt8(M),y&&(x=Math.max(x/127,-1));break;case 5121:x=f.getUint8(M),y&&(x/=255);break;case 5122:x=f.getInt16(M,!0),y&&(x=Math.max(x/32767,-1));break;case 5123:x=f.getUint16(M,!0),y&&(x/=65535);break;default:x=f.getUint32(M,!0),y&&(x/=4294967295)}g[u*r+w]=x}}return g}function Xr(e,t){let i=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,s=Number(t.scale?.[0]??1),n=Number(t.scale?.[1]??1),o=Number(t.rotation??0)||0,a=Math.cos(o),h=Math.sin(o),l=(Number.isFinite(s)?s:1)*a,c=(Number.isFinite(s)?s:1)*h,f=-(Number.isFinite(n)?n:1)*h,y=(Number.isFinite(n)?n:1)*a;for(let g=0;g+1<e.length;g+=2){let u=e[g],b=e[g+1];e[g]=l*u+c*b+i,e[g+1]=f*u+y*b+r}}function be(e,t,i,r=!0){let s=[],n=null;try{for(let[o,a]of[[35633,t],[35632,i]]){let h=e.createShader(o);if(!h){if(r)throw new Error("Shader allocation failed");return null}if(s.push(h),e.shaderSource(h,a),e.compileShader(h),e.getShaderParameter&&!e.getShaderParameter(h,35713)){if(r)throw new Error(`Shader compile error: ${e.getShaderInfoLog(h)}`);return null}}if(n=e.createProgram(),!n){if(r)throw new Error("Program allocation failed");return null}for(let o of s)e.attachShader(n,o);if(e.linkProgram(n),e.getProgramParameter&&!e.getProgramParameter(n,35714)){let o=r?e.getProgramInfoLog(n):null;if(e.deleteProgram?.(n),n=null,r)throw new Error(`Program link error: ${o}`);return null}return n}finally{for(let o of s)n&&e.detachShader?.(n,o),e.deleteShader?.(o)}}var Je=["neutral","reinhard","none","aces","agx"];function xe(e){let t=String(e??"").trim().toLowerCase();return Je.includes(t)?t:"neutral"}function qr(e){return Je.indexOf(xe(e))}function Kr(e){return new TextDecoder().decode(e)}var Qe=ut().decoders;function Yr(e,t){Qe.set(e.toLowerCase(),t)}function Vt(e){return Qe.get(e.toLowerCase())}function ti(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,i=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let y=i.getUint8(0);throw y===123||y===32||y===10||y===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let n=i.getUint32(8,!0),o=12,a=null,h=null;for(;o+8<=n&&o+8<=t.byteLength;){let y=i.getUint32(o,!0),g=i.getUint32(o+4,!0),u=o+8;if(u+y>t.byteLength)throw new Error(`Truncated GLB chunk: required ${u+y} bytes, buffer has ${t.byteLength}`);if(g===1313821514){let b=new Uint8Array(t,u,y),w=Kr(b);a=JSON.parse(w,(M,x)=>M==="__proto__"||M==="constructor"||M==="prototype"?void 0:x)}else g===5130562&&(h=t.slice(u,u+y));o=u+y}if(!a)throw new Error("Missing JSON chunk in GLB");let l=a.extensionsRequired||[];if(l.includes("KHR_draco_mesh_compression")&&!Vt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let y of["EXT_meshopt_compression","KHR_meshopt_compression"])if(l.includes(y)&&!Vt("meshopt"))throw new Error(`Model requires ${y}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!Vt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let c=h||new ArrayBuffer(0),f={gltf:a,bin:c,animations:[]};for(let y of mt)y.onParseGLB?.(f);return f}function Zr(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function te(e){if(Zr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return ti(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ei=`#version 300 es
16
+ */function is(t,e,i){let r=[],n=new Map,s=[],a=[],o=[],l=new Map,y=p=>{let x=n.get(p);return x===void 0&&(x=r.length,r.push({op:p}),n.set(p,x)),x},f=p=>{let x=l.get(p);return x===void 0&&(x=o.length,o.push({id:p}),l.set(p,x)),x},b=(p,x={})=>s.push({declaration:y(p),...x})-1,h=(p,x,w)=>a.push({id:p,type:x,value:w})-1,d=p=>({node:p,socket:"value"}),v=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(v&&typeof v=="object"){let p=Array.isArray(v.graphs)?v.graphs[v.graph??0]:v;if(p&&Array.isArray(p.nodes)){let x=Array.isArray(p.declarations)?p.declarations:[];for(let w of x)w?.op&&y(w.op);Array.isArray(p.variables)&&a.push(...p.variables);for(let w of p.events||[])w?.id&&f(w.id);for(let w of p.nodes){if(!w||typeof w!="object")continue;let _=w.op||(typeof w.declaration=="number"?x[w.declaration]?.op:"");s.push(_?{...w,declaration:y(_)}:{...w})}}}let M=(p,x,w="translation")=>w==="baseColorFactor"||w==="metallicFactor"||w==="roughnessFactor"?`/materials/${Math.max(0,x)}/pbrMetallicRoughness/${w}`:w==="emissiveFactor"||w==="alphaCutoff"?`/materials/${Math.max(0,x)}/${w}`:w==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${w}`,m=new Map;t.forEach((p,x)=>{typeof p?.name=="string"&&!m.has(p.name)&&m.set(p.name,x)});let u=(p,x)=>typeof p.target=="string"&&m.has(p.target)?m.get(p.target):typeof p.targetNode=="number"?p.targetNode:x,g=p=>{let x=t[p];return(typeof x?.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<t.length;p++){let x=t[p],w=x?.extras?.interactivity;if(!w||typeof w!="object")continue;let _=(typeof x.mesh=="number"?e[x.mesh]?.primitives?.[0]?.material:0)??0,N=E=>{let T=Array.isArray(E)?E:[E],S=[];for(let D=0;D<T.length;D++){let R=T[D];if(!R||typeof R!="object")continue;let I=R.action||"interpolate",k=typeof R.duration=="number"?R.duration:.35;if(I==="toggleTransform"){let V=R.property==="rotation"||R.property==="scale"?R.property:"translation",L=V==="rotation"?x.rotation||[0,0,0,1]:V==="scale"?x.scale||[1,1,1]:x.translation||[0,0,0],O=`/nodes/${p}/${V}`,c=h(`__toggle_${p}_${D}`,"bool",!1),F=b("variable/get",{configuration:{variable:c}}),C=b("math/not",{values:{a:d(F)}}),U=b("variable/set",{configuration:{variable:c},values:{value:d(C)}}),H=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.to)?R.to:L},duration:{value:k}}}),j=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.from)?R.from:L},duration:{value:k}}});s[U].flows={out:{node:b("flow/branch",{values:{condition:d(F)},flows:{true:{node:H},false:{node:j}}})}},S.push(U)}else if(I==="interpolate"){let V=R.to??R.value;if(V===void 0)continue;let L={value:{value:V},duration:{value:k}};R.from!==void 0&&(L.from={value:R.from}),S.push(b("pointer/interpolate",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:L}))}else if(I==="setProperty"){if(R.value===void 0)continue;S.push(b("pointer/set",{configuration:{pointer:typeof R.pointer=="string"?R.pointer:M(u(R,p),g(u(R,p)),R.property)},values:{value:{value:R.value}}}))}else if(I==="toggleVisibility"){let V=u(R,p),L=h(`__vis_${V}_${D}`,"bool",!0),O=b("variable/get",{configuration:{variable:L}}),c=b("math/not",{values:{a:d(O)}}),F=b("variable/set",{configuration:{variable:L},values:{value:d(c)}});s[F].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(O)}})}},S.push(F)}else if(I==="cycleMaterialColor"&&Array.isArray(R.colors)&&R.colors.length>0){let V=typeof R.duration=="number"?R.duration:.25,L=`/materials/${Math.max(0,_)}/pbrMetallicRoughness/baseColorFactor`,O=h(`__color_idx_${p}_${D}`,"int",0),c=b("variable/get",{configuration:{variable:O}}),F=b("math/add",{values:{a:d(c),b:{value:1}}}),C=b("math/rem",{values:{a:d(F),b:{value:R.colors.length}}}),U=b("variable/set",{configuration:{variable:O},values:{value:d(C)}}),H={};for(let j=0;j<R.colors.length;j++){let Y=R.colors[j],q=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];H[String(j)]={node:V>0?b("pointer/interpolate",{configuration:{pointer:L},values:{value:{value:q},duration:{value:V}}}):b("pointer/set",{configuration:{pointer:L},values:{value:{value:q}}})}}s[U].flows={out:{node:b("flow/switch",{values:{selection:d(c)},flows:H})}},S.push(U)}else if(I==="playAnimation")S.push(b("animation/start",{configuration:{animation:R.animation??R.clip??0}}));else if(I==="stopAnimation")S.push(b("animation/stop"));else if(I==="sendEvent"){let V={};for(let[L,O]of Object.entries(R.values||{}))V[L]={value:O};S.push(b("event/send",{configuration:{event:f(String(R.event??R.id??"custom"))},values:V}))}}if(!S.length)return null;if(S.length===1)return S[0];let A={};return S.forEach((D,R)=>{A[String(R)]={node:D}}),b("flow/sequence",{flows:A})},P=(E,T,S)=>{let A=N(T);A!==null&&b(E,{...S?{configuration:S}:{},flows:{out:{node:A}}})};if(w.onSelect&&P("pointer/onSelect",w.onSelect,{nodeIndex:p}),w.onHoverIn&&P("pointer/onHoverIn",w.onHoverIn,{nodeIndex:p}),w.onHoverOut&&P("pointer/onHoverOut",w.onHoverOut,{nodeIndex:p}),w.onStart&&P("event/onStart",w.onStart),w.onReceive&&typeof w.onReceive=="object")for(let[E,T]of Object.entries(w.onReceive))P("event/receive",T,{event:f(E)})}return s.length?{graphs:[{declarations:r,nodes:s,variables:a,events:o}],graph:0}:null}var rs='SecurityError: Client-modified script compilation (Use Case 1) is disabled by default to satisfy strict CSP and Trusted Types requirements. Use script-src="..." or loadScriptFromSrc(url) for server-generated scripts (Use Case 2), or explicitly opt in via ThreeLiveElement.allowClientScripts = true (or the allow-client-scripts attribute).',ss="Security Error: client-side scripts require allow-client-scripts opt-in.",lt="__THREE_LIVE_REGISTRY__";function ge(){let t=typeof globalThis<"u"?globalThis:{};if(!t[lt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,lt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[lt]=e}}return t[lt]}var xe=ge().plugins;function ns(t){let e=ge().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function as(){return ge().plugins}function ve(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function mi(t,e,i,r,n){let s=1/Math.tan(e/2);t.fill(0),t[0]=s/i,t[5]=s,t[11]=-1;let a=1/(r-n);return t[10]=(n+r)*a,t[14]=2*n*r*a,t}function Lt(t,e,i,r){let[n,s,a]=e,[o,l,y]=r,[f,b,h]=i,d=n-f,v=s-b,M=a-h,m=Math.hypot(d,v,M);m<=1e-5?(d=0,v=0,M=1):(d/=m,v/=m,M/=m);let u=l*M-y*v,g=y*d-o*M,p=o*v-l*d;m=Math.hypot(u,g,p),m<=1e-5?(u=0,g=0,p=0):(u/=m,g/=m,p/=m);let x=v*p-M*g,w=M*u-d*p,_=d*g-v*u;return m=Math.hypot(x,w,_),m<=1e-5?(x=0,w=0,_=0):(x/=m,w/=m,_/=m),t[0]=u,t[1]=x,t[2]=d,t[3]=0,t[4]=g,t[5]=w,t[6]=v,t[7]=0,t[8]=p,t[9]=_,t[10]=M,t[11]=0,t[12]=-(u*n+g*s+p*a),t[13]=-(x*n+w*s+_*a),t[14]=-(d*n+v*s+M*a),t[15]=1,t}function Te(t,e,i){let r=e[0],n=e[1],s=e[2],a=e[3],o=e[4],l=e[5],y=e[6],f=e[7],b=e[8],h=e[9],d=e[10],v=e[11],M=e[12],m=e[13],u=e[14],g=e[15],p=i[0],x=i[1],w=i[2],_=i[3];return t[0]=p*r+x*o+w*b+_*M,t[1]=p*n+x*l+w*h+_*m,t[2]=p*s+x*y+w*d+_*u,t[3]=p*a+x*f+w*v+_*g,p=i[4],x=i[5],w=i[6],_=i[7],t[4]=p*r+x*o+w*b+_*M,t[5]=p*n+x*l+w*h+_*m,t[6]=p*s+x*y+w*d+_*u,t[7]=p*a+x*f+w*v+_*g,p=i[8],x=i[9],w=i[10],_=i[11],t[8]=p*r+x*o+w*b+_*M,t[9]=p*n+x*l+w*h+_*m,t[10]=p*s+x*y+w*d+_*u,t[11]=p*a+x*f+w*v+_*g,p=i[12],x=i[13],w=i[14],_=i[15],t[12]=p*r+x*o+w*b+_*M,t[13]=p*n+x*l+w*h+_*m,t[14]=p*s+x*y+w*d+_*u,t[15]=p*a+x*f+w*v+_*g,t}function Nt(t,e,i,r){let n=e[0],s=e[1],a=e[2],o=e[3],l=n+n,y=s+s,f=a+a,b=n*l,h=n*y,d=n*f,v=s*y,M=s*f,m=a*f,u=o*l,g=o*y,p=o*f,x=r[0],w=r[1],_=r[2];return t[0]=(1-(v+m))*x,t[1]=(h+p)*x,t[2]=(d-g)*x,t[3]=0,t[4]=(h-p)*w,t[5]=(1-(b+m))*w,t[6]=(M+u)*w,t[7]=0,t[8]=(d+g)*_,t[9]=(M-u)*_,t[10]=(1-(b+v))*_,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function Oe(t,e,i=0){let r=e[0],n=e[1],s=e[2],a=e[4],o=e[5],l=e[6],y=e[8],f=e[9],b=e[10],h=b*o-l*f,d=-b*a+l*y,v=f*a-o*y,M=r*h+n*d+s*v;return!M||i>0&&(!Number.isFinite(M)||Math.abs(M)<=i)||(M=1/M,t[0]=h*M,t[1]=d*M,t[2]=v*M,t[3]=(-b*n+s*f)*M,t[4]=(b*r-s*y)*M,t[5]=(-f*r+n*y)*M,t[6]=(l*n-s*o)*M,t[7]=(-l*r+s*a)*M,t[8]=(o*r-n*a)*M),t}function os(t,e){let i=e[0],r=e[1],n=e[2],s=e[3],a=e[4],o=e[5],l=e[6],y=e[7],f=e[8],b=e[9],h=e[10],d=e[11],v=e[12],M=e[13],m=e[14],u=e[15],g=i*o-r*a,p=i*l-n*a,x=i*y-s*a,w=r*l-n*o,_=r*y-s*o,N=n*y-s*l,P=f*M-b*v,E=f*m-h*v,T=f*u-d*v,S=b*m-h*M,A=b*u-d*M,D=h*u-d*m,R=g*D-p*A+x*S+w*T-_*E+N*P;return R?(R=1/R,t[0]=(o*D-l*A+y*S)*R,t[1]=(n*A-r*D-s*S)*R,t[2]=(M*N-m*_+u*w)*R,t[3]=(h*_-b*N-d*w)*R,t[4]=(l*T-a*D-y*E)*R,t[5]=(i*D-n*T+s*E)*R,t[6]=(m*x-v*N-u*p)*R,t[7]=(f*N-h*x+d*p)*R,t[8]=(a*A-o*T+y*P)*R,t[9]=(r*T-i*A-s*P)*R,t[10]=(v*_-M*x+u*g)*R,t[11]=(b*x-f*_-d*g)*R,t[12]=(o*E-a*S-l*P)*R,t[13]=(i*S-r*E+n*P)*R,t[14]=(M*p-v*w-m*g)*R,t[15]=(f*w-b*p+h*g)*R,t):null}function fi(t,e,i,r,n){let s=n[0]*e+n[4]*i+n[8]*r+n[12],a=n[1]*e+n[5]*i+n[9]*r+n[13],o=n[2]*e+n[6]*i+n[10]*r+n[14],l=n[3]*e+n[7]*i+n[11]*r+n[15],y=l!==0?1/l:1;t[0]=s*y,t[1]=a*y,t[2]=o*y}function ls(t,e,i,r,n,s,a,o,l,y,f,b,h,d,v,M,m=0){let u=y-a,g=f-o,p=b-l,x=h-a,w=d-o,_=v-l,N=n*_-s*w,P=s*x-r*_,E=r*w-n*x,T=u*N+g*P+p*E;if(T>-1e-7&&T<1e-7)return!1;let S=1/T,A=t-a,D=e-o,R=i-l,I=S*(A*N+D*P+R*E);if(I<-m||I>1+m)return!1;let k=D*p-R*g,V=R*u-A*p,L=A*g-D*u,O=S*(r*k+n*V+s*L);if(O<-m||I+O>1+m)return!1;let c=S*(x*k+w*V+_*L);if(c>1e-4&&c<M.distance){M.distance=c,M.point=[t+r*c,e+n*c,i+s*c];let F=g*_-p*w,C=p*x-u*_,U=u*w-g*x,H=Math.hypot(F,C,U)||1;return M.normal=[F/H,C/H,U/H],!0}return!1}function pi(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let f=0;f<i;f++)r.push(ve());if(i===0)return r;let n=new Set;for(let f of t.nodes)if(Array.isArray(f.children))for(let b of f.children)n.add(b);let s=new Set,a=128,o=(f,b,h=0)=>{if(h>a||f<0||f>=i||s.has(f))return;s.add(f);let d=t.nodes[f];if(!d)return;let v=ve();if(e&&e[f])v.set(e[f]);else if(d.matrix&&d.matrix.length===16)v.set(d.matrix);else{let m=d.translation||[0,0,0],u=d.rotation||[0,0,0,1],g=d.scale||[1,1,1];Nt(v,u,m,g)}let M=r[f];if(b?Te(M,b,v):M.set(v),Array.isArray(d.children))for(let m of d.children)typeof m=="number"&&o(m,M,h+1)},l=[],y=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(y&&Array.isArray(y.nodes))l.push(...y.nodes);else for(let f=0;f<i;f++)n.has(f)||l.push(f);for(let f of l)o(f,null);for(let f=0;f<i;f++)!n.has(f)&&!l.includes(f)&&o(f,null);return r}function di(t){if(typeof t!="function")return null;let e=new Uint32Array(256);for(let h=0;h<256;h++){let d=h;for(let v=0;v<8;v++)d=d&1?3988292384^d>>>1:d>>>1;e[h]=d>>>0}let i=(h,d,v)=>{let M=4294967295;for(let m=d;m<v;m++)M=e[(M^h[m])&255]^M>>>8;return(M^4294967295)>>>0},r=(h,d)=>(h[d]<<24|h[d+1]<<16|h[d+2]<<8|h[d+3])>>>0,n=(h,d,v)=>{h[d]=v>>>24,h[d+1]=v>>>16&255,h[d+2]=v>>>8&255,h[d+3]=v&255},s=h=>{let d=new t("deflate"),v=d.writable.getWriter();v.write(h).catch(()=>{}),v.close().catch(()=>{});let M=d.readable.getReader(),m=[],u=0,g=()=>M.read().then(p=>{if(p.done){let x=new Uint8Array(u),w=0;for(let _=0;_<m.length;_++)x.set(m[_],w),w+=m[_].length;return x}return p.value&&(m.push(p.value),u+=p.value.length),g()});return g()},a=h=>{if(h.length<45||r(h,0)!==2303741511||r(h,12)!==1229472850)return null;let d=r(h,16),v=r(h,20);if(h[24]!==8||h[25]!==6||h[28]!==0||!d||!v||d>4096||v>4096)return null;let M=1+d*4,m=new Uint8Array(M*v),u=0,g=33,p=-2,x=0,w=[],_=!1;for(;g+8<=h.length&&!_;){let N=r(h,g),P=r(h,g+4),E=g+8,T=E+N;if(T+4>h.length)return null;if(P===1229209940)for(let S=E;S<T&&!_;){if(p<0)p++,S++;else if(x>0){let A=Math.min(x,T-S);if(u+A>m.length)return null;m.set(h.subarray(S,S+A),u),u+=A,S+=A,x-=A,x===0&&w[0]&1&&(_=!0)}else{if(w.push(h[S++]),w.length===1&&w[0]>>1&3)return null;if(w.length===5){let A=w[1]|w[2]<<8;if((A^(w[3]|w[4]<<8))!==65535)return null;x=A,A===0&&(w[0]&1&&(_=!0),w=[])}}x===0&&w.length===5&&(w=[])}else if(P===1229278788)break;g=T+4}if(u!==m.length)return null;for(let N=0;N<v;N++)if(m[N*M]!==0)return null;return{w:d,h:v,raw:m}},o=(h,d,v)=>{let M=d*4,m=M+1,u=new Uint8Array(h.length),g=new Uint8Array(M),p=new Uint8Array(M);for(let x=0;x<v;x++){let w=x*m+1,_=w-m,N=0,P=1/0;for(let E=0;E<5;E++){if(E===3||(E===2||E===4)&&x===0)continue;let T=0;for(let S=0;S<M;S++){let A=S>=4?h[w+S-4]:0,D=x>0?h[_+S]:0,R=0;if(E===1)R=A;else if(E===2)R=D;else if(E===4){let k=S>=4&&x>0?h[_+S-4]:0,V=A+D-k,L=Math.abs(V-A),O=Math.abs(V-D),c=Math.abs(V-k);R=L<=O&&L<=c?A:O<=c?D:k}let I=h[w+S]-R&255;g[S]=I,T+=I<128?I:256-I}T<P&&(P=T,N=E,p.set(g))}u[x*m]=N,u.set(p,w)}return u},l=h=>{let d=null;try{d=a(h)}catch{d=null}if(!d)return Promise.resolve(h);let{w:v,h:M,raw:m}=d;return s(o(m,v,M)).then(u=>{let g=45+u.length+12;if(g>=h.length)return h;let p=new Uint8Array(g);p.set(h.subarray(0,33),0),n(p,33,u.length),n(p,37,1229209940),p.set(u,41),n(p,41+u.length,i(p,37,41+u.length));let x=45+u.length;return n(p,x,0),n(p,x+4,1229278788),n(p,x+8,2923585666),p},()=>h)},y=new Int16Array(128).fill(-1),f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let h=0;h<64;h++)y[f.charCodeAt(h)]=h;let b=h=>{let d=h.length;for(;d>0&&h.charCodeAt(d-1)===61;)d--;let v=new Uint8Array(Math.floor(d*3/4)),M=0,m=0,u=0;for(let g=0;g<d;g++){let p=h.charCodeAt(g),x=p<128?y[p]:-1;if(x<0)return null;M=(M<<6|x)&16777215,m+=6,m>=8&&(m-=8,v[u++]=M>>m&255)}return u===v.length?v:null};return{png:l,glb:h=>{let d=(S,A)=>(S[A]|S[A+1]<<8|S[A+2]<<16|S[A+3]<<24)>>>0,v=(S,A,D)=>{S[A]=D&255,S[A+1]=D>>>8&255,S[A+2]=D>>>16&255,S[A+3]=D>>>24},M,m=new Uint8Array(0);try{if(h.length<20||d(h,0)!==1179937895)return Promise.resolve(h);let S=Math.min(h.length,d(h,8)),A=d(h,12);if(d(h,16)!==1313821514||20+A>S)return Promise.resolve(h);M=JSON.parse(new TextDecoder().decode(h.subarray(20,20+A)));let D=20+A;if(D+8<=S){let R=d(h,D);if(d(h,D+4)!==5130562||D+8+R>S)return Promise.resolve(h);m=h.subarray(D+8,D+8+R)}}catch{return Promise.resolve(h)}if(!M||typeof M!="object")return Promise.resolve(h);let u=Array.isArray(M.bufferViews)?M.bufferViews:[],g=Array.isArray(M.images)?M.images:[],p=[],x=[],w=[],_="data:image/png;base64,";for(let S=0;S<g.length;S++){let A=g[S];if(!A||typeof A!="object")continue;let D=u[A.bufferView];if(typeof A.uri=="string"&&A.uri.indexOf(_)===0){let R=b(A.uri.slice(_.length));R&&(x.push(S),w.push(R))}else A.mimeType==="image/png"&&D&&(D.buffer||0)===0&&p.indexOf(A.bufferView)<0&&p.push(A.bufferView)}if(!p.length&&!x.length)return Promise.resolve(h);let N=[];for(let S=0;S<u.length;S++)N.push(S);N.sort((S,A)=>(u[S].byteOffset||0)-(u[A].byteOffset||0));let P=0;for(let S=0;S<N.length;S++){let A=u[N[S]],D=A.byteOffset||0;if(typeof A.byteLength!="number"||(A.buffer||0)!==0||D<P||D+A.byteLength>m.length)return Promise.resolve(h);P=D+A.byteLength}let E=S=>{let A=u[S].byteOffset||0;return m.subarray(A,A+u[S].byteLength)},T=[];for(let S=0;S<p.length;S++)T.push(l(E(p[S])));for(let S=0;S<w.length;S++)T.push(l(w[S]));return Promise.all(T).then(S=>{let A=[];for(let c=0;c<u.length;c++){let F=p.indexOf(c);A.push(F>=0?S[F]:E(c))}let D=0;for(let c=0;c<N.length;c++)D=(D+3&-4)+A[N[c]].length;for(let c=0;c<x.length;c++)D=(D+3&-4)+S[p.length+c].length;let R=D+3&-4,I=new Uint8Array(R),k=0;for(let c=0;c<N.length;c++){let F=N[c];k=k+3&-4,I.set(A[F],k),u[F].byteOffset=k,u[F].byteLength=A[F].length,k+=A[F].length}for(let c=0;c<x.length;c++){let F=S[p.length+c];k=k+3&-4,I.set(F,k);let C=g[x[c]];delete C.uri,C.mimeType="image/png",C.bufferView=u.length,u.push({buffer:0,byteOffset:k,byteLength:F.length}),k+=F.length}M.bufferViews=u,!Array.isArray(M.buffers)||!M.buffers.length?M.buffers=[{byteLength:R}]:M.buffers[0].byteLength=R;let V=new TextEncoder().encode(JSON.stringify(M)),L=V.length+3&-4;if(L!==V.length){let c=new Uint8Array(L).fill(32);c.set(V),V=c}let O=new Uint8Array(20+L+8+R);return v(O,0,1179937895),v(O,4,2),v(O,8,O.length),v(O,12,L),v(O,16,1313821514),O.set(V,20),v(O,20+L,R),v(O,24+L,5130562),O.set(I,28+L),O.length<h.length?O:h})}}}var hs={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function gi(t,e,i,r){if(!i||i.bufferView===void 0)return null;let n=t.bufferViews?.[i.bufferView];if(!n)return null;let s=Number(i.count??0);if(!Number.isInteger(s)||s<=0)return null;let a=i.componentType??5126,o=hs[a];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let l=o*r,y=n.byteStride&&n.byteStride>0?n.byteStride:l,f=(n.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(f)||f<0||y<l||f+(s-1)*y+l>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&y===l&&f%4===0)return new Float32Array(e,f,s*r);let b=new DataView(e),h=i.normalized===!0,d=new Float32Array(s*r);for(let v=0;v<s;v++){let M=f+v*y;for(let m=0;m<r;m++){let u=M+m*o,g;switch(a){case 5126:g=b.getFloat32(u,!0);break;case 5120:g=b.getInt8(u),h&&(g=Math.max(g/127,-1));break;case 5121:g=b.getUint8(u),h&&(g/=255);break;case 5122:g=b.getInt16(u,!0),h&&(g=Math.max(g/32767,-1));break;case 5123:g=b.getUint16(u,!0),h&&(g/=65535);break;default:g=b.getUint32(u,!0),h&&(g/=4294967295)}d[v*r+m]=g}}return d}function us(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,n=Number(e.scale?.[0]??1),s=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,o=Math.cos(a),l=Math.sin(a),y=(Number.isFinite(n)?n:1)*o,f=(Number.isFinite(n)?n:1)*l,b=-(Number.isFinite(s)?s:1)*l,h=(Number.isFinite(s)?s:1)*o;for(let d=0;d+1<t.length;d+=2){let v=t[d],M=t[d+1];t[d]=y*v+f*M+i,t[d+1]=b*v+h*M+r}}function ht(t,e,i,r=!0){let n=[],s=null;try{for(let[a,o]of[[35633,e],[35632,i]]){let l=t.createShader(a);if(!l){if(r)throw new Error("Shader allocation failed");return null}if(n.push(l),t.shaderSource(l,o),t.compileShader(l),t.getShaderParameter&&!t.getShaderParameter(l,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(l)}`);return null}}if(s=t.createProgram(),!s){if(r)throw new Error("Program allocation failed");return null}for(let a of n)t.attachShader(s,a);if(t.linkProgram(s),t.getProgramParameter&&!t.getProgramParameter(s,35714)){let a=r?t.getProgramInfoLog(s):null;if(t.deleteProgram?.(s),s=null,r)throw new Error(`Program link error: ${a}`);return null}return s}finally{for(let a of n)s&&t.detachShader?.(s,a),t.deleteShader?.(a)}}var yi=["neutral","reinhard","none","aces","agx"];function Dt(t){let e=String(t??"").trim().toLowerCase();return yi.includes(e)?e:"neutral"}function cs(t){return yi.indexOf(Dt(t))}function ms(t){return new TextDecoder().decode(t)}var bi=ge().decoders;function fs(t,e){bi.set(t.toLowerCase(),e)}function ut(t){return bi.get(t.toLowerCase())}function xi(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let h=i.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let n=i.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=i.getUint32(8,!0),a=12,o=null,l=null;for(;a+8<=s&&a+8<=e.byteLength;){let h=i.getUint32(a,!0),d=i.getUint32(a+4,!0),v=a+8;if(v+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${v+h} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let M=new Uint8Array(e,v,h),m=ms(M);o=JSON.parse(m,(u,g)=>u==="__proto__"||u==="constructor"||u==="prototype"?void 0:g)}else d===5130562&&(l=e.slice(v,v+h));a=v+h}if(!o)throw new Error("Missing JSON chunk in GLB");let y=o.extensionsRequired||[];for(let[h,d]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(y.includes(h)&&!ut(d))throw new Error(`Model requires ${h}. Register a decoder via ThreeLiveElement.registerDecoder('${d}', decoder).`);let f=l||new ArrayBuffer(0),b={gltf:o,bin:f,animations:[],animationsParsed:!1};for(let h of xe)h.onParseGLB?.(b);return b}function vi(t,e=pi(t)){let i=t?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],n=new Set,s=(a,o,l,y)=>{let f=a.type,b=f==="directional"||f==="point"||f==="spot"?f:"ambient",h=o?o[8]:-.5,d=o?o[9]:-1,v=o?o[10]:-.8,M=Math.hypot(h,d,v)||1,m=a.extras?.shadow??l,u=a.name||y,g={type:b,color:a.color||[1,1,1],intensity:a.intensity??1};u&&(g.name=u),o&&(g.position=[o[12],o[13],o[14]]),b==="directional"&&o?g.direction=[h/M,d/M,v/M]:(b==="spot"&&(g.direction=o?[-h/M,-d/M,-v/M]:[0,-1,0],g.innerConeAngle=a.spot?.innerConeAngle??0,g.outerConeAngle=a.spot?.outerConeAngle??Math.PI/4),g.range=a.range),m&&(g.shadow=m),r.push(g)};return(t.nodes||[]).forEach((a,o)=>{let l=a?.extensions?.KHR_lights_punctual?.light;typeof l=="number"&&i[l]&&(n.add(l),s(i[l],e[o],a.extras?.shadow,a.name))}),i.forEach((a,o)=>{n.has(o)||s(a)}),r}function ps(t){return typeof t=="object"&&t!==null&&"gltf"in t&&typeof t.gltf=="object"&&t.gltf!==null&&"bin"in t&&(t.bin instanceof ArrayBuffer||ArrayBuffer.isView(t.bin))}function It(t){if(ps(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return xi(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ft=`#version 300 es
17
17
  layout(location=0) in vec3 aPos;
18
18
  layout(location=3) in vec3 aOff;
19
19
  layout(location=1) in vec3 aNormal;
@@ -48,7 +48,7 @@ vec2 scaleUV=uUvTransform.zw;
48
48
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
49
49
  vUV=aUV*scaleUV+uUvTransform.xy;
50
50
  gl_Position=uMVP*vec4(aPosition,1.0);
51
- }`,Jr=`#version 300 es
51
+ }`,ds=`#version 300 es
52
52
  precision highp float;
53
53
  in vec3 vNormal,vWorldPos;
54
54
  in vec2 vUV;
@@ -57,117 +57,81 @@ in vec4 vInstTint;
57
57
  #define uBaseColor (uBaseColor*vInstTint)
58
58
  uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
59
59
  uniform vec2 uClearcoat;
60
- uniform vec3 uCameraPos,uAmbientColor;
61
- uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap;
62
- uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap;
60
+ uniform vec3 uCameraPos,uAmbientColor,uEmissiveFactor;
61
+ uniform mat3 uHemi;
62
+ uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uEmissiveTexture;
63
+ uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uHasEmissiveTexture;
63
64
  uniform float uNormalScale,uOcclusionStrength;
64
- /*XRD_U*/
65
+ /*XRD_U*//*SHD_U*/
65
66
  uniform vec2 uViewportSize;
66
67
  uniform vec4 uSectionPlane;
67
68
  uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
68
69
  uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
69
70
  uniform vec2 uPointLightSpotCone[2];
70
71
  out vec4 fragColor;
71
-
72
72
  vec2 envBRDF(float r,float n){
73
- vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
74
- vec4 rv=r*c0+c1;
73
+ vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04),rv=r*c0+c1;
75
74
  float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
76
75
  return vec2(-1.04,1.04)*a+rv.zw;
77
76
  }
78
-
79
77
  vec3 F_SchlickRoughness(vec3 F0,float r,float n){
80
78
  return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
81
79
  }
82
-
83
80
  vec3 getStudioRadiance(vec3 R,float r){
84
- vec3 kd=normalize(vec3(0.0,1.0,0.35));
81
+ vec3 kd=normalize(vec3(0.0,1.0,0.35)),fd=normalize(vec3(-0.85,0.45,-0.35));
85
82
  float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
86
- vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
87
83
  float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
88
84
  float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
89
- vec3 ag=mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5);
90
- return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
85
+ return mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5)+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
91
86
  }
92
-
93
- vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D normalMap,float scale){
94
- vec3 mapNormal=texture(normalMap,uv).xyz*2.0-1.0;
95
- mapNormal.xy*=scale;
96
- vec3 dp1=dFdx(vWorldPos);
97
- vec3 dp2=dFdy(vWorldPos);
98
- vec2 duv1=dFdx(uv);
99
- vec2 duv2=dFdy(uv);
100
- vec3 dp2perp=cross(dp2,N);
101
- vec3 dp1perp=cross(N,dp1);
102
- vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
103
- vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
104
- float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
105
- return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
87
+ vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D m,float s){
88
+ vec3 q=texture(m,uv).xyz*2.0-1.0;q.xy*=s;
89
+ vec3 p1=dFdx(vWorldPos),p2=dFdy(vWorldPos),c2=cross(p2,N),c1=cross(N,p1);
90
+ vec2 u1=dFdx(uv),u2=dFdy(uv);
91
+ vec3 T=c2*u1.x+c1*u2.x,B=c2*u1.y+c1*u2.y;
92
+ float k=inversesqrt(max(dot(T,T),dot(B,B)));
93
+ return normalize(mat3(T*k,B*k,N)*normalize(q));
106
94
  }
107
-
108
95
  vec2 equirectangularUV(vec3 dir){
109
96
  vec3 d=normalize(dir);
110
- float u=atan(d.z,d.x)*0.15915494309+0.5;
111
- float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
112
- return vec2(u,1.0-v);
97
+ return vec2(atan(d.z,d.x)*0.15915494309+0.5,0.5-asin(clamp(d.y,-1.0,1.0))*0.31830988618);
113
98
  }
114
-
115
- vec3 neutralToneMapping(vec3 color){
116
- const float startCompression=0.76;
117
- const float desaturation=0.15;
118
- float x=min(color.r,min(color.g,color.b));
119
- float offset=x<0.08?x-6.25*x*x:0.04;
120
- color-=offset;
121
- float peak=max(color.r,max(color.g,color.b));
122
- if(peak<startCompression)return color;
123
- const float d=1.0-startCompression;
124
- float newPeak=1.0-d*d/(peak+d-startCompression);
125
- color*=newPeak/peak;
126
- float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
127
- return mix(color,newPeak*vec3(1.0),g);
99
+ vec3 neutralToneMapping(vec3 c){
100
+ float x=min(c.r,min(c.g,c.b));
101
+ c-=x<0.08?x-6.25*x*x:0.04;
102
+ float p=max(c.r,max(c.g,c.b));
103
+ if(p<0.76)return c;
104
+ float n=1.0-0.0576/(p-0.52);
105
+ c*=n/p;
106
+ return mix(c,vec3(n),1.0-1.0/(0.15*(p-n)+1.0));
128
107
  }
129
-
130
- vec3 acesToneMapping(vec3 color){
131
- color*=0.6;
132
- return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
108
+ vec3 acesToneMapping(vec3 c){
109
+ c*=0.6;return clamp((c*(2.51*c+0.03))/(c*(2.43*c+0.59)+0.14),0.0,1.0);
133
110
  }
134
-
135
- vec3 agxToneMapping(vec3 color){
136
- color=max(color,vec3(0.0));
137
- vec3 inset=vec3(
138
- 0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
139
- 0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
140
- 0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
141
- vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
142
- vec3 x2=ev*ev;
143
- vec3 x4=x2*x2;
144
- vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
145
- vec3 outset=vec3(
146
- 1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
147
- -0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
148
- -0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
149
- return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
111
+ vec3 agxToneMapping(vec3 c){
112
+ c=max(c,vec3(0.0));
113
+ vec3 i=mat3(0.84247906,0.04232824,0.04237565,0.0784336,0.87846864,0.0784336,0.07922375,0.07916613,0.87914297)*c;
114
+ vec3 e=clamp((log2(max(i,vec3(1e-6)))+12.47393)/16.5,0.0,1.0),x2=e*e,x4=x2*x2;
115
+ vec3 s=15.5*x4*x2-40.14*x4*e+31.96*x4-6.868*x2*e+0.4298*x2+0.1191*e-0.00232;
116
+ vec3 o=mat3(1.196879,-0.05289685,-0.05297164,-0.09802088,1.15190313,-0.09804345,-0.09902974,-0.09896118,1.15107367)*s;
117
+ return clamp(pow(max(o,vec3(0.0)),vec3(2.2)),0.0,1.0);
150
118
  }
151
-
152
- vec3 applyToneMapping(vec3 color,int mode){
153
- if(mode==0)return neutralToneMapping(color);
154
- if(mode==1)return color/(color+vec3(1.0));
155
- if(mode==3)return acesToneMapping(color);
156
- if(mode==4)return agxToneMapping(color);
157
- return color;
119
+ vec3 applyToneMapping(vec3 c,int m){
120
+ return m==0?neutralToneMapping(c):m==1?c/(c+vec3(1.0)):m==3?acesToneMapping(c):m==4?agxToneMapping(c):c;
158
121
  }
159
-
160
- vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 base,float specExp,float specWeight){
161
- float NoH=max(dot(N,normalize(L+V)),0.0);
162
- return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
122
+ vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 b,float e,float w){
123
+ float h=max(dot(N,normalize(L+V)),0.0);
124
+ return b*max(dot(N,L),0.0)*0.75+vec3(pow(h,e)*w+uClearcoat.x*pow(h,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
163
125
  }
164
126
 
165
127
  void main(){
166
128
  if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
167
129
  vec4 base=uBaseColor;
168
130
  if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
131
+ if(base.a<0.004)discard;
132
+ vec3 em=uHasEmissiveTexture==1?uEmissiveFactor*texture(uEmissiveTexture,vUV).rgb:uEmissiveFactor;
169
133
  if(length(vNormal)<1e-4&&uHasTexture==1){
170
- vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
134
+ vec3 unlit=base.rgb+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
171
135
  fragColor=vec4(unlit,base.a);
172
136
  return;
173
137
  }
@@ -199,7 +163,7 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
199
163
  vec3 directLight=vec3(0.0);
200
164
  for(int i=0;i<2;i++){
201
165
  if(i>=uNumDirLights)break;
202
- directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i];
166
+ directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]/*SHD_D*/;
203
167
  }
204
168
  for(int i=0;i<2;i++){
205
169
  if(i>=uNumPointLights)break;
@@ -208,7 +172,7 @@ float dist=length(toLight);
208
172
  vec3 L=toLight/max(dist,0.0001);
209
173
  float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
210
174
  spotAtt*=spotAtt;
211
- directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist);
175
+ directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)/*SHD_P*/;
212
176
  }
213
177
 
214
178
  vec3 R=reflect(-V,N);
@@ -228,8 +192,9 @@ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
228
192
  }
229
193
 
230
194
  vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
195
+ directLight+=kD*base.rgb*mix(uHemi[1],uHemi[0],dot(N,uHemi[2])*0.5+0.5)*occ;
231
196
  vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
232
- vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
197
+ vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
233
198
  if(uClearcoat.x>0.0){
234
199
  vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
235
200
  color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
@@ -239,113 +204,157 @@ color=applyToneMapping(color,uToneMapping);
239
204
  float outAlpha=base.a;
240
205
  /*XRD_O*/
241
206
  fragColor=vec4(color,outAlpha);
242
- }`,Qr=`#version 300 es
207
+ }`,gs=`#version 300 es
243
208
  layout(location=0) in vec3 aPosition;
244
209
  uniform mat4 uMVP;
245
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ts=`#version 300 es
210
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ys=`#version 300 es
246
211
  precision highp float;
247
212
  uniform vec4 uColorId;
248
213
  out vec4 fragColor;
249
- void main(){fragColor=uColorId;}`;function ve(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var ii=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function ri(){let e=ut().xrDepthShader;return{fs:Jr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...ii,...e.uniformNames]:ii}}function es(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let i=t.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:i.startsWith("https://")||i.startsWith("blob:")?t:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Me(e,t,i,r,s,n,o,a){if(r===void 0||!t.accessors?.[r])return null;let h=Ze(t,i,t.accessors[r],n);if(!h)return null;a&&(h=h.slice(),Xr(h,a));let l=e.createBuffer();return o.push(l),e.bindBuffer(34962,l),e.bufferData(34962,h,35044),e.enableVertexAttribArray(s),e.vertexAttribPointer(s,n,5126,!1,0,0),h}function we(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function si(e,t,i){let r=ri(),s=ei,n=r.fs,o=!1;for(let h of mt)if(h.onResolveShader){let l=h.onResolveShader(t,i,s,n);l&&(s=l.vs,n=l.fs,o=!0)}let a=o?be(e,s,n):null;return{program:a,uniforms:a?ve(e,a,r.uniforms):null}}function is(e,t,i){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let s=r.length>>4,n=t.instanceColors,o=new Float32Array(s*20);for(let h=0;h<s;h++)o.set(r.subarray(h*16,h*16+16),h*20),o[h*20+16]=n?n[h*3]:1,o[h*20+17]=n?n[h*3+1]:1,o[h*20+18]=n?n[h*3+2]:1,o[h*20+19]=1;let a=e.createBuffer();i.push(a),e.bindBuffer(34962,a),e.bufferData(34962,o,35044);for(let h=0;h<5;h++)e.enableVertexAttribArray(8+h),e.vertexAttribPointer(8+h,4,5126,!1,80,h*16),e.vertexAttribDivisor(8+h,1);return!0}function rs(e,t){let i=e.materials?.[t?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let n=s?.extensions?.KHR_texture_transform;if(n&&typeof n=="object")return n}return null}var Ns=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ni=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ee(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function ai(e,t){let i=e?.pbrMetallicRoughness,r=i?.baseColorFactor,s=e?.extensions?.KHR_materials_clearcoat,n=o=>o!==void 0&&t[o.index]?t[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:n(i?.baseColorTexture),metallicRoughnessTexture:n(i?.metallicRoughnessTexture),normalTexture:n(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:n(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function oi(e,t,i){let r=new Set,s=n=>{n&&!r.has(n)&&(r.add(n),e.deleteTexture(n))};for(let n of t)for(let o of n.primitives){if(o.vao&&e.deleteVertexArray(o.vao),o.buffers)for(let h of o.buffers)e.deleteBuffer(h);s(o.texture),s(o.metallicRoughnessTexture),s(o.normalTexture),s(o.occlusionTexture);let a=new Set;o.customProgram&&a.add(o.customProgram);for(let h of o.programCache?.values()??[])h.program&&a.add(h.program);for(let h of a)e.deleteProgram(h)}if(i)for(let n of i)s(n)}function li(e,t,i=ni,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ss(e,t,i,r,s)}catch(n){let o=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;oi(e,o,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let a of s.buffers)e.deleteBuffer(a);throw n}}function ss(e,t,i,r,s){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:n}=t,o=Vt("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(n,t);let a=t.bin,h=[];s.meshes=h;let l=[],c=n.extensions?.KHR_materials_variants;c&&Array.isArray(c.variants)&&c.variants.forEach((C,d)=>{l.push(typeof C?.name=="string"&&C.name?C.name:`Variant_${d}`)});let f=jr(n),y=[];if(Array.isArray(n.nodes))for(let C=0;C<n.nodes.length;C++){let d=n.nodes[C];d.mesh!==void 0&&n.meshes&&n.meshes[d.mesh]&&y.push({node:d,nodeIdx:C,meshIdx:d.mesh})}let g=y.length>0?y:(n.meshes||[]).map((C,d)=>({node:C,nodeIdx:-1,meshIdx:d})),u=[],b=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(n.asset?.extras?.lights)&&n.asset.extras.lights.length>0?n.asset.extras.lights:null;if(b)for(let C of b)u.push({...C,type:C.type||C.light_type||"point",innerConeAngle:C.innerConeAngle??C.inner_cone_angle,outerConeAngle:C.outerConeAngle??C.outer_cone_angle});else if(n.extensions?.KHR_lights_punctual?.lights){let C=n.extensions.KHR_lights_punctual.lights;for(let d of C){let k=d.type==="directional"?"directional":d.type==="point"?"point":d.type==="spot"?"spot":"ambient";u.push({type:k,color:d.color||[1,1,1],intensity:d.intensity!==void 0?d.intensity:1})}}if(u.length===0&&(u.push({type:"ambient",color:[1,1,1],intensity:.35}),u.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),g.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${g.length}`);let w=[];if(s.gpuTextures=w,n.textures&&n.images){if(n.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${n.textures.length}`);for(let C=0;C<n.textures.length;C++){let d=n.textures[C],k=n.images[d.source];if(k){let $=e.createTexture();e.bindTexture(3553,$),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let S=D=>{e.bindTexture(3553,$),e.texImage2D(3553,0,6408,6408,5121,D),e.generateMipmap(3553),r?.()};if(k.bufferView!==void 0){let D=n.bufferViews[k.bufferView],T=D.byteOffset||0,P=new Blob([a.slice(T,T+D.byteLength)],{type:k.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(P).then(S).catch(()=>{})}else if(k.uri){let D=es(k.uri);if(D){let T=new Image;T.crossOrigin="anonymous",T.referrerPolicy="no-referrer",T.onload=()=>S(T),T.src=D}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",k.uri)}w.push($)}else w.push(null)}}let M=[1/0,1/0,1/0],x=[-1/0,-1/0,-1/0],m=0,p=0;for(let C=0;C<g.length;C++){let d=g[C],k=n.meshes[d.meshIdx],$=d.nodeIdx>=0?f[d.nodeIdx]:ht(),S=new Float32Array(9);Pt(S,$);let D={name:d.node.name||k.name||`Mesh_${d.meshIdx}`,nodeIndex:d.nodeIdx,transform:$,normalMatrix:S,primitives:[],extras:d.node.extras||k.extras,...d.node?.visible===!1||d.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=D;let T=d.node?.extensions?.EXT_mesh_gpu_instancing;if(T&&T.attributes&&typeof T.attributes=="object"){let P=T.attributes,j=P.TRANSLATION!==void 0?n.accessors?.[P.TRANSLATION]:null,W=P.ROTATION!==void 0?n.accessors?.[P.ROTATION]:null,V=P.SCALE!==void 0?n.accessors?.[P.SCALE]:null,Z=P._COLOR_0!==void 0?n.accessors?.[P._COLOR_0]:null,U=Number(j?.count??W?.count??V?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let X=(z,tt)=>{if(!z||z.bufferView===void 0||!n.bufferViews?.[z.bufferView])return null;let et=z.componentType??5126,rt=it=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${it})`),null);if(et!==5120&&et!==5121&&et!==5122&&et!==5123&&et!==5126)return rt(`componentType ${et}`);if(!(Number(z.count)>=U))return rt(`count ${z.count} < ${U}`);let J=null;try{J=Ze(n,a,{...z,count:U},tt)}catch{return rt("out of bounds")}return!J||!J.every(Number.isFinite)?rt("non-finite value"):J},O=X(j,3),G=X(W,4),F=X(V,3),H=Z?.type==="VEC4"?4:3,B=X(Z,H),K=new Float32Array(U*16),q=ht();for(let z=0;z<U;z++){let tt=O?[O[z*3],O[z*3+1],O[z*3+2]]:[0,0,0],et=G?[G[z*4],G[z*4+1],G[z*4+2],G[z*4+3]]:[0,0,0,1],rt=F?[F[z*3],F[z*3+1],F[z*3+2]]:[1,1,1];ye(q,et,tt,rt),K.set(q,z*16)}if(D.instanceMatrices=K,B){let z=new Float32Array(U*3);for(let tt=0;tt<U;tt++)z[tt*3]=B[tt*H],z[tt*3+1]=B[tt*H+1],z[tt*3+2]=B[tt*H+2];D.instanceColors=z}}}for(let P of k.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let J=Vt("draco");J&&J.decodePrimitive(n,P,a)}let j=[],W=e.createVertexArray();s.vao=W,s.buffers=j,e.bindVertexArray(W);let V=is(e,D,j),Z=n.accessors[P.attributes.POSITION],U=Number(Z?.count??0);if(!Number.isFinite(U)||U<0||m+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(m+=U,Z?.min&&Z?.max){let J=it=>{for(let st=0;st<3;st++){let wt=it[12+st],nt=it[12+st];for(let ot=0;ot<3;ot++){let ct=it[ot*4+st]*Z.min[ot],lt=it[ot*4+st]*Z.max[ot];wt+=ct<lt?ct:lt,nt+=ct>lt?ct:lt}wt<M[st]&&(M[st]=wt),nt>x[st]&&(x[st]=nt)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let it=D.instanceMatrices.length>>4,st=ht();for(let wt=0;wt<it;wt++){let nt=D.instanceMatrices.subarray(wt*16,wt*16+16);dt(st,$,nt),J(st)}}else J($)}let X=Me(e,n,a,P.attributes.POSITION,0,3,j);Me(e,n,a,P.attributes.NORMAL,1,3,j),Me(e,n,a,P.attributes.TEXCOORD_0,2,2,j,rs(n,P));let O=0,G=5123,F=null;if(P.indices!==void 0){let J=n.accessors[P.indices],it=(n.bufferViews[J.bufferView].byteOffset||0)+(J.byteOffset||0);if(O=Number(J.count??0),!Number.isFinite(O)||O<0||p+O>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);p+=O,G=J.componentType===5125?5125:5123;let st=e.createBuffer();j.push(st),e.bindBuffer(34963,st),J.componentType===5125?F=new Uint32Array(a,it,J.count):J.componentType===5121?F=Uint16Array.from(new Uint8Array(a,it,J.count)):F=it%2===0?new Uint16Array(a,it,J.count):new Uint16Array(a.slice(it,it+J.count*2)),e.bufferData(34963,F,35044)}else O=Z.count;let H={};for(let J of mt)if(J.onBuildPrimitiveVAO){let it=J.onBuildPrimitiveVAO(e,W,P,n,a);it&&(H[J.name]=it)}e.bindVertexArray(null);let B=n.materials&&P.material!==void 0?n.materials[P.material]:null,{program:K,uniforms:q}=si(e,P,B),z=ai(B,w),tt=!!(B?.extensions?.KHR_materials_transmission||H.materials?.isTransmissive),et=P.extensions?.KHR_materials_variants?.mappings,rt=Array.isArray(et)?et.filter(J=>J&&typeof J.material=="number"&&Array.isArray(J.variants)).map(J=>({material:J.material|0,variants:J.variants.map(it=>Number(it)|0)})):void 0;D.primitives.push({vao:W,instanced:V,indexCount:O,indexType:G,...z,positions:X,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:rt,primitiveDef:P,programCache:new Map([[P.material??-1,{program:K,uniforms:q}]]),pluginData:H,customProgram:K,customUniforms:q,isTransmissive:tt})}h.push(D)}isFinite(M[0])||(M=[-1,-1,-1]),isFinite(x[0])||(x=[1,1,1]);let v=[(M[0]+x[0])/2,(M[1]+x[1])/2,(M[2]+x[2])/2],R=x[0]-M[0],L=x[1]-M[1],I=x[2]-M[2],N=Math.max(Math.hypot(R,L,I)/2,.5),_=[M[0],M[1],M[2]],A=[x[0],x[1],x[2]],E=t.animations;if(!E){for(let C of mt)if(C.onParseGLB?.(t),t.animations){E=t.animations;break}}return E||(E=[]),{meshes:h,bounds:{center:v,radius:N,min:_,max:A},lights:u,animations:E,worldMatrices:f,gpuTextures:w,availableVariants:l}}function Gt(e){let t=e.customTarget||e.bounds.center,i=e.currDistance*Math.cos(e.currPhi);return[t[0]+i*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+i*Math.cos(e.currTheta)]}var hi=class{constructor(e,t,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ht(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ht(),this.viewMatrix=ht(),this.activeViewMatrix=null,this.modelMatrix=ht(),this.mvpMatrix=ht(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ht(),rawValueToMeters:.001,format:0},this.container=e;let r,s;if(t&&typeof t.getContext=="function"?(r=t,s=i):(s=t,r=s?.canvas),!r){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),r=a}this.canvas=r,this.opts=s||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let n=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!n:n&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=we(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=xe(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Yr(e,t)}static getDecoder(e){return Vt(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=ri();this.renderProg=be(e,ei,t.fs),this.pickProg=be(e,Qr,ts),this.uRender=ve(e,this.renderProg,t.uniforms),this.uPick=ve(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of mt)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=i,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,i,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,i),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,e),s=Math.max(1,t);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(e,t){let{meshes:i,bounds:r,lights:s,animations:n,worldMatrices:o,gpuTextures:a,availableVariants:h}=li(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=n||[],this.worldMatrices=o||[],this.gpuTextures=a||[],this.availableVariants=h||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of mt)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let l=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=we(l));let c=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(ti(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of mt)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(te(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=te(e),{meshes:r}=li(this.gl,i,ni,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Pt(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(e,t,i,r=1){this.clearColor=[e,t,i,r]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let i=this.meshes[t],r;e instanceof Map?r=e.get(i.name)??e.get(t):Array.isArray(e)?r=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,i.name)?r=e[i.name]:Object.prototype.hasOwnProperty.call(e,t)&&(r=e[t])),r&&r.length===16&&(i.transform.set(r),Pt(i.normalMatrix,i.transform))}}bindLights(e=this.uRender){let t=this.gl,i=[.28,.28,.28],r=[],s=[],n=[],o=[],a=[],h=[];for(let l of this.lights){let c=l.color||[1,1,1],f=l.intensity!==void 0?l.intensity:1;if(l.type==="ambient")i=[c[0]*f,c[1]*f,c[2]*f];else if(l.type==="directional"&&r.length<6){let y=l.direction||[.5,1,.8];r.push(y[0],y[1],y[2]),s.push(c[0]*f,c[1]*f,c[2]*f)}else if((l.type==="point"||l.type==="spot")&&n.length<6){let y=l.position||[0,0,0];if(n.push(y[0],y[1],y[2]),o.push(c[0]*f,c[1]*f,c[2]*f),l.type==="spot"){let g=l.direction||[0,-1,0],u=Math.max(.01,Math.min(Math.PI/2,l.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(u-1e-4,l.innerConeAngle??0));a.push(g[0],g[1],g[2]),h.push(Math.cos(b),Math.cos(u))}else a.push(0,-1,0),h.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),t.uniform3fv(e.uAmbientColor,i),t.uniform1i(e.uNumDirLights,r.length/3),r.length>0&&(t.uniform3fv(e.uDirLightDir,r),t.uniform3fv(e.uDirLightColor,s)),t.uniform1i(e.uNumPointLights,n.length/3),n.length>0&&(t.uniform3fv(e.uPointLightPos,n),t.uniform3fv(e.uPointLightColor,o),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,a),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,h)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=we(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=xe(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of mt)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of mt)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,i=this.currDistance;return{theta:e,phi:t,radius:i,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,i)=>{let r=this.meshes.flatMap(l=>l.primitives.filter(c=>c.materialIndex===i||e.length===1&&c.materialIndex===void 0)),s=r[0],n=s?[...s.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],o=s?s.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,a=s?s.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,h={baseColorFactor:n,metallicFactor:o,roughnessFactor:a,setBaseColorFactor:l=>{let c=[l[0],l[1],l[2],l[3]??1];h.baseColorFactor=c,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=c);for(let f of r)f.baseColor=c;this.render()},setMetallicFactor:l=>{h.metallicFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=l);for(let c of r)c.metallic=l;this.render()},setRoughnessFactor:l=>{h.roughnessFactor=l,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=l);for(let c of r)c.roughness=l;this.render()}};return{name:t.name||`Material_${i}`,pbrMetallicRoughness:h}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(i=>i.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",i=-1;if(t)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(e),i<0)return!1;this.activeVariantName=e}let r=this.gltf?.materials;if(!Array.isArray(r))return t;for(let s of this.meshes)for(let n of s.primitives){let o=n.defaultMaterialIndex;if(!t&&Array.isArray(n.variantMappings)){for(let h of n.variantMappings)if(Array.isArray(h.variants)&&h.variants.includes(i)){o=h.material;break}}let a=o!==void 0?r[o]:void 0;n.materialIndex=a?o:void 0,Object.assign(n,ai(a,this.gpuTextures)),this.applyPrimitiveProgram(n,n.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,t,i){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let r=t??-1,s=e.programCache.get(r);s||(s=si(this.gl,{...e.primitiveDef,material:t},i),e.programCache.set(r,s)),e.customProgram=s.program,e.customUniforms=s.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of mt)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,i){this.customTarget=[e,t,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(i,e))}setCamera(e,t,i,r){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(e,t,i,r){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let i=ht();dt(i,this.projMatrix,this.viewMatrix);let[r,s,n]=e,o=t?t[0]:0,a=t?t[1]:0,h=t?t[2]:0,l=this.modelRootMatrix;l&&(r=l[0]*e[0]+l[4]*e[1]+l[8]*e[2]+l[12],s=l[1]*e[0]+l[5]*e[1]+l[9]*e[2]+l[13],n=l[2]*e[0]+l[6]*e[1]+l[10]*e[2]+l[14],t&&(o=l[0]*t[0]+l[4]*t[1]+l[8]*t[2],a=l[1]*t[0]+l[5]*t[1]+l[9]*t[2],h=l[2]*t[0]+l[6]*t[1]+l[10]*t[2]));let c=i[0]*r+i[4]*s+i[8]*n+i[12],f=i[1]*r+i[5]*s+i[9]*n+i[13],y=i[2]*r+i[6]*s+i[10]*n+i[14],g=i[3]*r+i[7]*s+i[11]*n+i[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let u=c/g,b=f/g,w=y/g,M=this.canvas.getBoundingClientRect(),x=M.width||this.canvas.clientWidth||this.canvas.width||300,m=M.height||this.canvas.clientHeight||this.canvas.height||150,p=(u*.5+.5)*x,v=(-b*.5+.5)*m,R=u>=-1.1&&u<=1.1&&b>=-1.1&&b<=1.1&&w>=-1&&w<=1;if(R&&t){let[L,I,N]=Gt(this),_=[r-L,s-I,n-N];o*_[0]+a*_[1]+h*_[2]>.05&&(R=!1)}return{x:p,y:v,z:w,visible:R}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,e.setPointerCapture(i.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,n=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,n),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],a=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],h=this.customTarget?[...this.customTarget]:[...this.bounds.center],l=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;h[0]+=(-s*o[0]+n*a[0])*l,h[1]+=(-s*o[1]+n*a[1])*l,h[2]+=(-s*o[2]+n*a[2])*l,this.customTarget=h}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+n*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=t(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=e.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(e.width/Math.max(r.width,1))),n=Math.floor((i.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(s,n,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=t();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),i.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,n=i.height||300,o=r.width>0?Math.floor((e-r.left)*(s/r.width)):Math.floor(e),a=r.height>0?Math.floor((t-r.top)*(n/r.height)):Math.floor(t);return this.performMeshPick(o,a,!1)}performMeshPick(e,t,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),n=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,s);let o=ht();dt(o,this.projMatrix,this.viewMatrix);let a=[],h=Math.max(0,Math.min(s-1,e)),l=Math.max(0,Math.min(n-1,n-1-t));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==n)&&this.resizePickingFbo(s,n),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,n),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let v=0;v<this.meshes.length;v++){let R=this.meshes[v];if(R.visible===!1||R.isPluginMesh)continue;let L=v+1,I=(L&255)/255,N=(L>>8&255)/255,_=(L>>16&255)/255;r.uniform4f(this.uPick.uColorId,I,N,_,1),dt(this.modelMatrix,this.modelRootMatrix,R.transform);let A=R.instanceMatrices;if(A&&A.length>=16){let E=A.length>>4,C=ht();for(let d of R.primitives){r.bindVertexArray(d.vao);for(let k=0;k<E;k++)dt(C,this.modelMatrix,A.subarray(k*16,k*16+16)),dt(this.mvpMatrix,o,C),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),ee(r,d)}}else{dt(this.mvpMatrix,o,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let E of R.primitives)r.bindVertexArray(E.vao),ee(r,E)}}let m=new Uint8Array(4);r.readPixels(h,l,1,1,6408,5121,m),r.bindFramebuffer(36160,null);let p=m[0]+(m[1]<<8)+(m[2]<<16);p>0&&p<=this.meshes.length&&(a=[this.meshes[p-1]])}a.length===0&&(a=this.meshes.filter(m=>m.visible!==!1));let c=null,f=1/0,y=[0,0,0],g=[0,1,0],[u,b,w]=Gt(this),M=ht();for(let m of a){dt(M,this.modelRootMatrix,m.transform);let p=m.instanceMatrices,v=p&&p.length>=16?p.length>>4:1;for(let R=0;R<v;R++){p&&p.length>=16?dt(this.modelMatrix,M,p.subarray(R*16,R*16+16)):this.modelMatrix.set(M),dt(this.mvpMatrix,o,this.modelMatrix);let L=ht();if(!Gr(L,this.mvpMatrix))continue;let I=(h+.5)/s*2-1,N=(l+.5)/n*2-1,_=[0,0,0],A=[0,0,0];Ye(_,I,N,-1,L),Ye(A,I,N,1,L);let E=A[0]-_[0],C=A[1]-_[1],d=A[2]-_[2],k=Math.hypot(E,C,d)||1,$=E/k,S=C/k,D=d/k,T={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((P=>{for(let j of m.primitives){if(!j.positions)continue;let W=j.positions,V=j.indices,Z=Math.floor(V?V.length/3:W.length/9);for(let U=0;U<Z;U++){let X=V?V[U*3]:U*3,O=V?V[U*3+1]:U*3+1,G=V?V[U*3+2]:U*3+2;Hr(_[0],_[1],_[2],$,S,D,W[X*3],W[X*3+1],W[X*3+2],W[O*3],W[O*3+1],W[O*3+2],W[G*3],W[G*3+1],W[G*3+2],T,P)}}})(1e-4),isFinite(T.distance)){let P=T.point[0],j=T.point[1],W=T.point[2],V=this.modelMatrix,Z=V[0]*P+V[4]*j+V[8]*W+V[12],U=V[1]*P+V[5]*j+V[9]*W+V[13],X=V[2]*P+V[6]*j+V[10]*W+V[14],O=Z-u,G=U-b,F=X-w,H=Math.hypot(O,G,F);if(H<f){Pt(this.normalMatrix,this.modelMatrix);let B=this.normalMatrix,K=T.normal[0],q=T.normal[1],z=T.normal[2],tt=B[0]*K+B[3]*q+B[6]*z,et=B[1]*K+B[4]*q+B[7]*z,rt=B[2]*K+B[5]*q+B[8]*z,J=Math.hypot(tt,et,rt)||1;tt/=J,et/=J,rt/=J,tt*O+et*G+rt*F>0&&(tt=-tt,et=-et,rt=-rt),c=m,f=Math.round(H*1e3)/1e3,y=[Math.round(Z*1e3)/1e3,Math.round(U*1e3)/1e3,Math.round(X*1e3)/1e3],g=[Math.round(tt*1e3)/1e3,Math.round(et*1e3)/1e3,Math.round(rt*1e3)/1e3]}}}}if(!c)return null;let x={meshIndex:this.meshes.indexOf(c),meshName:c.name,nodeIndex:c.nodeIndex,distance:f,hitPoint:y,normal:g,screenX:e,screenY:t};if(i){for(let m of mt)m.onMeshSelect?.(this,x);this.opts.onMeshClick&&this.opts.onMeshClick(x),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:x}))}return x}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let i=Math.max(1,Math.floor(t*.5)),r=e>=i,s=r?e-i:e,n=r?Math.max(1,t-i):i,o=(s+.5)/n*2-1;return Math.floor((o*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);ge(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;Qt(this.viewMatrix,Gt(this),i,[0,1,0]),dt(this.mvpMatrix,this.projMatrix,this.viewMatrix),Pt(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(t.width*e)),r=Math.max(1,Math.floor(t.height*e));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let i of mt)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let t of mt)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=e,s[1]=0,s[2]=-t,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=t,s[9]=0,s[10]=e,s[11]=0,s[12]=i-(e*i+t*r),s[13]=0,s[14]=r-(-t*i+e*r),s[15]=1}setVisible(e){this.isVisible=e}update(e){for(let n of mt)n.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let n of mt)n.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let n={theta:i,phi:r,zoom:s,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(n),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:n}))}}renderXRView(e,t,i,r,s=!0,n=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let o=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,h=e?.transform?.position,l=h?[h.x,h.y,h.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):i&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:o,projMatrix:a,eyePos:l,viewport:r,eye:e?.eye||"none",clear:n>0?!1:e?.eye!=="right",isAR:s})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let x=Math.max(2,this.canvas.width||2),m=Math.max(1,this.canvas.height||1),p=Math.max(1,Math.floor(x*.5)),v=Math.max(1,x-p),R=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[I,N,_]=Gt(this),A=Math.cos(this.currTheta),E=-Math.sin(this.currTheta),C=.032,d=ht(),k=ht(),$=[I-A*C,N,_-E*C],S=[L[0]-A*C*.25,L[1],L[2]-E*C*.25];ge(d,this.fov,p/m,.1,R),Qt(k,$,S,[0,1,0]);let D=ht(),T=ht(),P=[I+A*C,N,_+E*C],j=[L[0]+A*C*.25,L[1],L[2]+E*C*.25];ge(D,this.fov,v/m,.1,R),Qt(T,P,j,[0,1,0]),this.render({viewMatrix:k,projMatrix:d,eyePos:$,viewport:[0,0,p,m],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:T,projMatrix:D,eyePos:P,viewport:[p,0,v,m],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,x,m);return}let t=this.gl,i=0,r=0,s=this.canvas.width,n=this.canvas.height;e?.viewport?(i=e.viewport[0],r=e.viewport[1],s=e.viewport[2],n=e.viewport[3],t.viewport(i,r,s,n)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let o=ht(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,dt(o,e?.projMatrix??this.projMatrix,a);let h=ut().xrDepthShader,l=qr(this.toneMapping),[c,f,y]=e?e.eyePos:Gt(this);for(let x of mt)x.onBeforeDrawScene?.(this,t,o,[c,f,y],l);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let u=e?.eye||"none",b=!1,w=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,M=x=>{for(let m=0;m<w.length;m++){let p=w[m];if(p.visible===!1)continue;let v=this.selectedMeshName!==""&&p.name===this.selectedMeshName;m<g||p.worldSpace===!0||p.name==="__xr_reticle__"?this.modelMatrix.set(p.transform):dt(this.modelMatrix,this.modelRootMatrix,p.transform),dt(this.mvpMatrix,o,this.modelMatrix),Pt(p.normalMatrix,this.modelMatrix);let R=p.extras?.xr?.stereo||p.userData?.xr?.stereo,L=0,I=0,N=1,_=1;R==="sbs"?(N=.5,L=u==="right"?.5:0):R==="ou"&&(_=.5,I=u==="right"?.5:0);for(let A of p.primitives){let E=!!A.isTransmissive;if(!x&&E){b=!0;continue}if(x&&!E)continue;let C=A.customProgram||this.renderProg,d=A.customUniforms||this.uRender;t.useProgram(C),t.vertexAttrib3f(3,0,0,0),d.uInstanced&&t.uniform1i(d.uInstanced,0),t.uniform1i(d.uToneMapping,l),t.uniform1f(d.uEnvIntensity,this.envIntensity),d.uExposure&&t.uniform1f(d.uExposure,this.exposure),t.uniform3f(d.uCameraPos,c,f,y),t.uniform1f(d.uEmissive,v?1:0),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(d.uNormalMatrix,!1,p.normalMatrix),d.uUvTransform&&t.uniform4f(d.uUvTransform,L,I,N,_),d.uViewportSize&&t.uniform2f(d.uViewportSize,Math.max(1,s),Math.max(1,n)),h?.bind(t,d,this.xrDepthState,a,[i,r,Math.max(1,s),Math.max(1,n)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(d.uEnvironmentMap,4),t.uniform1i(d.uHasEnvironmentMap,1)):t.uniform1i(d.uHasEnvironmentMap,0),this.bindLights(d),d.uSectionEnabled&&t.uniform1i(d.uSectionEnabled,0);for(let $ of mt)$.onBeforeDrawPrimitive?.(t,C,A,p,this.worldMatrices||[],this.gltf);t.uniform4fv(d.uBaseColor,A.baseColor),t.uniform1f(d.uMetallic,A.metallic),t.uniform1f(d.uRoughness,A.roughness),d.uClearcoat&&t.uniform2f(d.uClearcoat,A.clearcoat??0,A.clearcoatRoughness??.04),A.texture?(t.activeTexture(33984),t.bindTexture(3553,A.texture),t.uniform1i(d.uBaseColorTexture,0),t.uniform1i(d.uHasTexture,1)):t.uniform1i(d.uHasTexture,0),A.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,A.metallicRoughnessTexture),t.uniform1i(d.uMetallicRoughnessTexture,1),t.uniform1i(d.uHasMetallicRoughnessTexture,1)):t.uniform1i(d.uHasMetallicRoughnessTexture,0),A.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,A.normalTexture),t.uniform1i(d.uNormalTexture,2),t.uniform1i(d.uHasNormalTexture,1),t.uniform1f(d.uNormalScale,A.normalScale)):t.uniform1i(d.uHasNormalTexture,0),A.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,A.occlusionTexture),t.uniform1i(d.uOcclusionTexture,3),t.uniform1i(d.uHasOcclusionTexture,1),t.uniform1f(d.uOcclusionStrength,A.occlusionStrength)):t.uniform1i(d.uHasOcclusionTexture,0),t.bindVertexArray(A.vao);let k=p.instanceMatrices;if(A.instanceCount!==void 0)t.drawElementsInstanced(4,A.indexCount,A.indexType,0,A.instanceCount);else if(k&&k.length>=16&&A.instanced&&d.uInstanced&&d.uViewProj){let $=k.length>>4;t.uniform1i(d.uInstanced,1),t.uniformMatrix4fv(d.uViewProj,!1,o),A.indices?t.drawElementsInstanced(4,A.indexCount,A.indexType,0,$):t.drawArraysInstanced(4,0,A.indexCount,$),t.uniform1i(d.uInstanced,0)}else if(k&&k.length>=16){let $=k.length>>4,S=p.instanceColors,D=ht(),T=new Float32Array(9),P=[A.baseColor[0],A.baseColor[1],A.baseColor[2],A.baseColor[3]];for(let j=0;j<$;j++)dt(D,this.modelMatrix,k.subarray(j*16,j*16+16)),dt(this.mvpMatrix,o,D),Pt(T,D),t.uniformMatrix4fv(d.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(d.uModel,!1,D),t.uniformMatrix3fv(d.uNormalMatrix,!1,T),S&&(P[0]=A.baseColor[0]*S[j*3],P[1]=A.baseColor[1]*S[j*3+1],P[2]=A.baseColor[2]*S[j*3+2],P[3]=A.baseColor[3],t.uniform4fv(d.uBaseColor,P)),ee(t,A)}else ee(t,A)}}};if(M(!1),b){for(let x of mt)x.onBeforeTransmissivePass?.(t,this);M(!0)}for(let x of mt)x.onAfterRender?.(t,this,o,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){oi(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of mt)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};hi.registerPlugin=Br,hi.getRegisteredPlugins=$r;function ns(e){return e+3&-4}var Q=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function ui(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function ci(e,t=0){let[i,r,s,,n,o,a,,h,l,c,,f,y,g]=Array.from({length:15},(T,P)=>Q(e[t+P],P%5===0?1:0)),u=Math.hypot(i,r,s),b=Math.hypot(n,o,a),w=Math.hypot(h,l,c);i*(o*c-l*a)-n*(r*c-l*s)+h*(r*a-o*s)<0&&(u=-u);let M=Math.abs(u)>1e-8?1/u:0,x=Math.abs(b)>1e-8?1/b:0,m=Math.abs(w)>1e-8?1/w:0,p=i*M,v=r*M,R=s*M,L=n*x,I=o*x,N=a*x,_=h*m,A=l*m,E=c*m,C=p+I+E,d=0,k=0,$=0,S=1;if(C>0){let T=.5/Math.sqrt(C+1);S=.25/T,d=(N-A)*T,k=(_-R)*T,$=(v-L)*T}else if(p>I&&p>E){let T=2*Math.sqrt(Math.max(0,1+p-I-E));T>1e-8&&(S=(N-A)/T,d=.25*T,k=(L+v)/T,$=(_+R)/T)}else if(I>E){let T=2*Math.sqrt(Math.max(0,1+I-p-E));T>1e-8&&(S=(_-R)/T,d=(L+v)/T,k=.25*T,$=(N+A)/T)}else{let T=2*Math.sqrt(Math.max(0,1+E-p-I));T>1e-8&&(S=(v-L)/T,d=(_+R)/T,k=(N+A)/T,$=.25*T)}let D=Math.hypot(d,k,$,S);return D>1e-8&&Number.isFinite(D)?(d/=D,k/=D,$/=D,S/=D):(d=0,k=0,$=0,S=1),{t:[f,y,g],r:[d,k,$,S],s:[u,b,w]}}function as(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var _t=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function mi(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let i=typeof t=="string"?{preset:t}:t,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:_t(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Ht(e,t){return fi(e,t)[0]}function fi(e,t){e.updateMatrixWorld(!0);let i=[],r=0,s=[],n=[],o=[],a=[],h=new Set,l=[],c=[],f=new Map,y=[],g=[],u=[],b=new Map,w=[],M=[];function x(S){let D=f.get(S);if(D!==void 0)return D;D=c.length,f.set(S,D);let T=S,P=T.color?.r??.8,j=T.color?.g??.8,W=T.color?.b??.8,V=T.opacity??1,Z={baseColorFactor:[P,j,W,V],metallicFactor:T.metalness??0,roughnessFactor:T.roughness??.5},U={};if(T.map){let G="";typeof T.map=="string"?G=T.map:typeof T.map.source=="string"?G=T.map.source:typeof T.map.image=="string"&&(G=T.map.image);let F=G.trim(),H=F&&!/[\x00-\x1f\x7f\\]|\.\./.test(F)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(F)||!F.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(F))?F:null;if(H){let K=b.get(H);if(K===void 0){let q=y.length;y.push({uri:H}),g.length===0&&g.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),K=u.length,u.push({sampler:0,source:q}),b.set(H,K)}Z.baseColorTexture={index:K}}let B=T.map.avgColor;Array.isArray(B)&&B.length>=3&&(U.avgColor=[B[0],B[1],B[2]])}let X={name:T.name||"",pbrMetallicRoughness:Z,doubleSided:T.side===2||!!T.doubleSided,...Object.keys(U).length>0?{extras:U}:{}};if(T.emissive&&(T.emissive.r>0||T.emissive.g>0||T.emissive.b>0)){let G=T.emissiveIntensity??1;X.emissiveFactor=[T.emissive.r*G,T.emissive.g*G,T.emissive.b*G]}let O={};return T.clearcoat&&T.clearcoat>0&&(O.KHR_materials_clearcoat={clearcoatFactor:T.clearcoat,clearcoatRoughnessFactor:T.clearcoatRoughness||0}),T.sheen&&T.sheen>0&&(O.KHR_materials_sheen={sheenColorFactor:T.sheenColor?[T.sheenColor.r,T.sheenColor.g,T.sheenColor.b]:[1,1,1],sheenRoughnessFactor:T.sheenRoughness||0}),T.transmission&&T.transmission>0&&(O.KHR_materials_transmission={transmissionFactor:T.transmission}),T.thickness&&T.thickness>0&&(O.KHR_materials_volume={thicknessFactor:T.thickness,attenuationDistance:T.attenuationDistance??1/0,attenuationColor:T.attenuationColor?[T.attenuationColor.r,T.attenuationColor.g,T.attenuationColor.b]:[1,1,1]}),T.ior!==void 0&&T.ior!==1.5&&(O.KHR_materials_ior={ior:T.ior}),T.dispersion&&T.dispersion>0&&(O.KHR_materials_dispersion={dispersion:T.dispersion}),T.iridescence&&T.iridescence>0&&(O.KHR_materials_iridescence={iridescenceFactor:T.iridescence,iridescenceIor:T.iridescenceIOR??1.3}),Object.keys(O).length>0&&(X.extensions=O),c.push(X),D}function m(S,D){let T=new Uint8Array(S.buffer,S.byteOffset,S.byteLength),P=ns(T.byteLength),j=new Uint8Array(P);j.set(T),i.push(j);let W=s.length;return s.push({buffer:0,byteOffset:r,byteLength:T.byteLength,target:D}),r+=P,W}function p(S,D,T,P,j,W,V){let Z=m(S,T),U=n.length,X={bufferView:Z,byteOffset:0,componentType:P,count:j,type:D};return W&&(X.min=W),V&&(X.max=V),n.push(X),U}e.traverse(S=>{if(S.isLight||S.color&&S.intensity!==void 0){let D=S.matrixWorld?.elements,T=Q(D?D[12]:S.position?.x,0),P=Q(D?D[13]:S.position?.y,0),j=Q(D?D[14]:S.position?.z,0),W=S.target,V=W?.parent?W?.matrixWorld?.elements:void 0,Z=Q(V?V[12]:W?.position?.x,0),U=Q(V?V[13]:W?.position?.y,0),X=Q(V?V[14]:W?.position?.z,0),O=Z-T,G=U-P,F=X-j,H=Math.hypot(O,G,F),B=Math.max(.01,Math.min(Math.PI/2,Q(S.angle,Math.PI/3))),K=Math.max(0,Math.min(1,Q(S.penumbra,0)));M.push({type:S.type,color:[S.color.r,S.color.g,S.color.b],intensity:S.intensity,position:[T,P,j],...S.type==="spot"?{direction:H>1e-6?[O/H,G/H,F/H]:[0,-1,0],outerConeAngle:B,innerConeAngle:Math.max(0,B*(1-K)),range:Math.max(0,Q(S.distance,0))}:S.type==="point"?{range:Math.max(0,Q(S.distance,0))}:{}})}});let v=[],R=new Set([e]),L=[];if(Array.isArray(e.children))for(let S=e.children.length-1;S>=0;S--)L.push({obj:e.children[S],parentKids:v});for(;L.length>0;){let{obj:S,parentKids:D}=L.pop();if(!S||typeof S!="object"||R.has(S))continue;R.add(S),S._bakeAuthorGeometry?.(),ut().materializeDeclarativeGeometry?.(S);let T=!!(S.userData&&(S.userData.xr&&typeof S.userData.xr=="object"&&Object.keys(S.userData.xr).length>0||S.userData.interactivity&&typeof S.userData.interactivity=="object"&&Object.keys(S.userData.interactivity).length>0)),P={name:S.name||(T?`Node_${a.length}`:"")},j=Q(S.position?.x,0),W=Q(S.position?.y,0),V=Q(S.position?.z,0),Z=Q(S.quaternion?.x,0),U=Q(S.quaternion?.y,0),X=Q(S.quaternion?.z,0),O=Q(S.quaternion?.w,1),G=Q(S.scale?.x,1),F=Q(S.scale?.y,1),H=Q(S.scale?.z,1);if((j||W||V)&&(P.translation=[j,W,V]),(Z||U||X||O!==1)&&(P.rotation=[Z,U,X,O]),(G!==1||F!==1||H!==1)&&(P.scale=[G,F,H]),S.visible===!1&&(P.extensions={...P.extensions||{},KHR_node_visibility:{visible:!1}},h.add("KHR_node_visibility")),S.userData&&Object.keys(S.userData).length>0&&(P.extras=JSON.parse(JSON.stringify(S.userData,(q,z)=>{if(!(q==="__proto__"||q==="prototype"||q==="constructor"))return typeof z=="function"?void 0:z})),S.userData.xr)){let q=as(S.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},ut().xrTraitSerializer?.gltfNode(P,S.userData.xr),h.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(S.geometry){let q=S.geometry,z=q.attributes.position;if(z&&z.count>0){let tt=[1/0,1/0,1/0],et=[-1/0,-1/0,-1/0];for(let nt=0;nt<z.count;nt++){let ot=z.getX(nt),ct=z.getY(nt),lt=z.getZ(nt);ot<tt[0]&&(tt[0]=ot),ot>et[0]&&(et[0]=ot),ct<tt[1]&&(tt[1]=ct),ct>et[1]&&(et[1]=ct),lt<tt[2]&&(tt[2]=lt),lt>et[2]&&(et[2]=lt)}let rt={attributes:{POSITION:p(z.array,"VEC3",34962,5126,z.count,tt,et)}};if(q.attributes.normal&&(rt.attributes.NORMAL=p(q.attributes.normal.array,"VEC3",34962,5126,q.attributes.normal.count)),q.attributes.uv&&(rt.attributes.TEXCOORD_0=p(q.attributes.uv.array,"VEC2",34962,5126,q.attributes.uv.count)),q.index){let nt=q.index.array instanceof Uint32Array;rt.indices=p(q.index.array,"SCALAR",34963,nt?5125:5123,q.index.count)}let J=Array.isArray(S.material)?S.material[0]:S.material;J&&(rt.material=x(J));let it=S.userData?.variants;if(it&&typeof it=="object"){let nt=new Map;for(let ot of Object.keys(it)){if(!ot||ot==="__proto__"||ot==="constructor"||ot==="prototype")continue;let ct=it[ot];if(!ct||typeof ct!="object")continue;let lt=w.indexOf(ot);if(lt===-1&&w.length<256&&(lt=w.length,w.push(ot)),lt===-1)continue;let Lt=x(ct),It=nt.get(Lt);It||(It=[],nt.set(Lt,It)),It.push(lt)}if(nt.size>0){let ot=[];for(let[ct,lt]of nt.entries())ot.push({material:ct,variants:lt});rt.extensions={...rt.extensions||{},KHR_materials_variants:{mappings:ot}},h.add("KHR_materials_variants")}}let st=S;if(st.isInstancedMesh&&typeof st.count=="number"&&st.count>0&&st.instanceMatrix?.array){let nt=Math.min(1e4,Math.floor(st.count)),ot=st.instanceMatrix.array,ct=new Float32Array(nt*3),lt=new Float32Array(nt*4),Lt=new Float32Array(nt*3);for(let bt=0;bt<nt;bt++){let{t:pe,r:Zt,s:de}=ci(ot,bt*16);ct[bt*3]=pe[0],ct[bt*3+1]=pe[1],ct[bt*3+2]=pe[2],lt[bt*4]=Zt[0],lt[bt*4+1]=Zt[1],lt[bt*4+2]=Zt[2],lt[bt*4+3]=Zt[3],Lt[bt*3]=de[0],Lt[bt*3+1]=de[1],Lt[bt*3+2]=de[2]}let It={TRANSLATION:p(ct,"VEC3",0,5126,nt),ROTATION:p(lt,"VEC4",0,5126,nt),SCALE:p(Lt,"VEC3",0,5126,nt)};if(st.instanceColor?.array&&st.instanceColor.array.length>=nt*3){let bt=new Float32Array(st.instanceColor.array.subarray(0,nt*3));It._COLOR_0=p(bt,"VEC3",0,5126,nt)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:It}},h.add("EXT_mesh_gpu_instancing")}let wt=o.length;o.push({primitives:[rt],name:S.name,...P.extras?{extras:P.extras}:{}}),P.mesh=wt}}let B=a.length;a.push(P),l.push(S),D.push(B);let K=S.children;if(Array.isArray(K)&&K.length>0){let q=[];P.children=q;for(let z=K.length-1;z>=0;z--)L.push({obj:K[z],parentKids:q})}}for(let S=0;S<a.length;S++){let D=a[S];D.children&&D.children.length===0?delete D.children:D.children&&D.children.length>0&&(D.extras?.xr?.lod||D.extensions?.ANDROID_xr_scenecore?.lod||l[S]?.isLOD)&&(D.extensions={...D.extensions||{},MSFT_lod:{ids:[...D.children]}},h.add("MSFT_lod"))}let I=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),N=[];if(typeof I=="function"&&l.length>0){let S=t?.duration??4,D=t?.fps??15,T=Math.max(2,Math.round(S*D)+1),P=new Float32Array(T),j=l.map(F=>[Q(F.position?.x,0),Q(F.position?.y,0),Q(F.position?.z,0),Q(F.quaternion?.x,0),Q(F.quaternion?.y,0),Q(F.quaternion?.z,0),Q(F.quaternion?.w,1),Q(F.scale?.x,1),Q(F.scale?.y,1),Q(F.scale?.z,1)]),W=l.map(()=>new Float32Array(T*3)),V=l.map(()=>new Float32Array(T*4)),Z=l.map(()=>new Float32Array(T*3));for(let F=0;F<T;F++){let H=F/(T-1)*S;P[F]=H;try{I(H)}catch{}for(let B=0;B<l.length;B++){let K=l[B];W[B][F*3]=Q(K.position?.x,0),W[B][F*3+1]=Q(K.position?.y,0),W[B][F*3+2]=Q(K.position?.z,0);let q=Q(K.quaternion?.x,0),z=Q(K.quaternion?.y,0),tt=Q(K.quaternion?.z,0),et=Q(K.quaternion?.w,1),rt=Math.hypot(q,z,tt,et)||1;if(q/=rt,z/=rt,tt/=rt,et/=rt,F>0){let J=(F-1)*4,it=V[B];it[J]*q+it[J+1]*z+it[J+2]*tt+it[J+3]*et<0&&(q=-q,z=-z,tt=-tt,et=-et)}V[B][F*4]=q,V[B][F*4+1]=z,V[B][F*4+2]=tt,V[B][F*4+3]=et,Z[B][F*3]=Q(K.scale?.x,1),Z[B][F*3+1]=Q(K.scale?.y,1),Z[B][F*3+2]=Q(K.scale?.z,1)}}for(let F=0;F<l.length;F++){let H=l[F],B=j[F];H.position?.set(B[0],B[1],B[2]),H.quaternion?.set(B[3],B[4],B[5],B[6]),H.scale?.set(B[7],B[8],B[9])}e.updateMatrixWorld(!0);let U=null,X=()=>(U===null&&(U=p(P,"SCALAR",0,5126,T,[0],[S])),U),O=[],G=[];for(let F=0;F<l.length;F++){let H=j[F],B=(q,z,tt)=>q.some((et,rt)=>Math.abs(et-H[tt+rt%z])>1e-4),K=(q,z,tt,et)=>{q&&G.push({sampler:O.push({input:X(),interpolation:"LINEAR",output:p(z,tt,0,5126,T)})-1,target:{node:F,path:et}})};K(B(W[F],3,0),W[F],"VEC3","translation"),K(B(V[F],4,3),V[F],"VEC4","rotation"),K(B(Z[F],3,7),Z[F],"VEC3","scale")}G.length>0&&N.push({name:"ProceduralLoop",samplers:O,channels:G})}let _=zr(a,o,e.userData),A=[],E=[],C=[];for(let S=0;S<a.length;S++){let D=a[S],T=mi(D.extras?.xr);if(!T)continue;let{ae:P,src:j,preset:W,volume:V,loop:Z,isGlobal:U}=T,X=D.name||`Node_${S}`,O=E.length;E.push({name:`${X}_source`,gain:V,loop:Z,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:A.push({uri:j})-1}:{},...W?{extras:{preset:W,pitch:_t(P.pitch,.25,4,1)}}:{}});let G=C.length,F=_t(P.refDistance,.05,100,1),H=_t(P.coneInnerAngle,0,360,360),B=_t(P.coneOuterAngle,H,360,360);C.push({name:`${X}_emitter`,type:U?"global":"positional",gain:V,sources:[O],...U?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:_t(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:_t(P.rolloffFactor,0,10,1),coneInnerAngle:+(H*Math.PI/180).toFixed(6),coneOuterAngle:+(B*Math.PI/180).toFixed(6),coneOuterGain:_t(P.coneOuterGain,0,1,0)}}}),D.extensions={...D.extensions||{},KHR_audio_emitter:{emitter:G}},h.add("KHR_audio_emitter")}let d={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:a,meshes:o,materials:c,...y.length>0?{images:y}:{},...g.length>0?{samplers:g}:{},...u.length>0?{textures:u}:{},accessors:n,bufferViews:s,buffers:[{byteLength:r}],...N.length>0?{animations:N}:{},..._||h.size>0?{extensionsUsed:[..._?["KHR_interactivity"]:[],...h]}:{},..._||w.length>0||C.length>0?{extensions:{..._?{KHR_interactivity:_}:{},...w.length>0?{KHR_materials_variants:{variants:w.map(S=>({name:S}))}}:{},...C.length>0?{KHR_audio_emitter:{...A.length>0?{audio:A}:{},sources:E,emitters:C}}:{}}}:{}},k=new Uint8Array(r),$=0;for(let S of i)k.set(S,$),$+=S.byteLength;return[{gltf:d,bin:k.buffer,lights:M,environmentIntensity:e.environmentIntensity},l]}function Te(e){return new TextEncoder().encode(e)}function ie(e,t){let{gltf:i,bin:r}=Ht(e,t),s=JSON.stringify(i),n=Te(s),o=(4-n.byteLength%4)%4,a=n.byteLength+o,h=20+a+8+r.byteLength,l=new Uint8Array(h),c=new DataView(l.buffer);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0),c.setUint32(8,h,!0),c.setUint32(12,a,!0),c.setUint32(16,1313821514,!0),l.set(n,20);for(let y=0;y<o;y++)l[20+n.byteLength+y]=32;let f=20+a;return c.setUint32(f,r.byteLength,!0),c.setUint32(f+4,5130562,!0),l.set(new Uint8Array(r),f+8),l}function os(e,t){let[i,r]=fi(e,t);return Se(i,r)}function Se(e,t){let i=[],r=e.gltf,s=ut().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,e);let n=e.bin,o=n instanceof ArrayBuffer?n:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength),a=r.accessors||[],h=r.bufferViews||[],l=r.materials||[],c=r.meshes||[],f=r.nodes||[],y=new Set,g=l.map((w,M)=>ui(y,re(w?.name,`Material_${M}`)));function u(w){let M=a[w];if(!M)throw new Error(`Accessor ${w} not found`);let x=h[M.bufferView||0],m=(x.byteOffset||0)+(M.byteOffset||0),p=x.byteLength||0;return{acc:M,buffer:o.slice(m,m+p)}}function b(w,M,x,m){let p=[],v=c[w];if(!v)return p;let R=v.primitives||[];for(let L=0;L<R.length;L++){let I=R[L],N=I.attributes?.POSITION;if(N===void 0)continue;let{acc:_,buffer:A}=u(N),E=new Float32Array(A,0,_.count*3),C,d=I.attributes?.NORMAL;if(d!==void 0){let{acc:O,buffer:G}=u(d),F=new Float32Array(G,0,O.count*3);C=new Float32Array(F.length);for(let H=0;H<O.count;H++){let B=F[H*3],K=F[H*3+1],q=F[H*3+2],z=Math.hypot(B,K,q)||1;C[H*3]=B/z,C[H*3+1]=K/z,C[H*3+2]=q/z}}let k,$=I.attributes?.TEXCOORD_0;if($!==void 0){let{acc:O,buffer:G}=u($);k=new Float32Array(G,0,O.count*2)}let S;if(I.indices!==void 0){let{acc:O,buffer:G}=u(I.indices);S=O.componentType===5125?new Uint32Array(G,0,O.count):new Uint16Array(G,0,O.count);let F=_.count;for(let H of S)if(H>=F)throw new Error(`SecurityError: Index buffer value (${H}) out of vertex bounds [0, ${F}).`)}else{let O=_.count;S=O>65535?new Uint32Array(O):new Uint16Array(O);for(let G=0;G<O;G++)S[G]=G}let D="DefaultMaterial",T=[.8,.8,.8],P=.5,j=0,W=0,V=0,Z=1.5,U=1,X=[0,0,0];if(I.material!==void 0&&l[I.material]){let O=l[I.material];D=g[I.material]||`Material_${I.material}`;let G=O.pbrMetallicRoughness||{},F=(q,z)=>Array.isArray(q)&&q.length>=3?[q[0],q[1],q[2]]:z;T=F(G.baseColorFactor,[1,1,1]);let H=O.extras?.avgColor;Array.isArray(H)&&H.length>=3&&(T=[T[0]*H[0],T[1]*H[1],T[2]*H[2]]);let B=Array.isArray(G.baseColorFactor)&&typeof G.baseColorFactor[3]=="number"?G.baseColorFactor[3]:1;typeof G.roughnessFactor=="number"&&(P=G.roughnessFactor),typeof G.metallicFactor=="number"&&(j=G.metallicFactor),X=F(O.emissiveFactor,[0,0,0]);let K=O.extensions||{};K.KHR_materials_clearcoat&&(W=K.KHR_materials_clearcoat.clearcoatFactor??0,V=K.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof K.KHR_materials_ior?.ior=="number"&&(Z=K.KHR_materials_ior.ior),U=B*(1-(K.KHR_materials_transmission?.transmissionFactor??0))}p.push({name:R.length>1?`${M}_p${L}`:M,positions:E,indices:S,normals:C,uvs:k,materialName:D,color:T,roughness:P,metallic:j,clearcoat:W,clearcoatRoughness:V,ior:Z,opacity:U,emissiveColor:X,xrTraits:x||v.extras?.xr,...m?{invisible:!0}:{}})}return p}if(f.length>0){let w=new Float32Array(0),M=new Uint16Array(0),x=(E,C)=>{if(E===void 0)return null;let{acc:d,buffer:k}=u(E);return new Float32Array(k,0,d.count*C)},m=(E,C)=>Array.isArray(E)&&E.length>=3?[Q(E[0],C),Q(E[1],C),Q(E[2],C)]:[C,C,C],p=(E,C,d)=>E&&E.length>=(C+1)*3?[E[C*3],E[C*3+1],E[C*3+2]]:d,v=(E,C,d)=>E&&E.length>=(C+1)*4?[E[C*4],E[C*4+1],E[C*4+2],E[C*4+3]]:d,R=new Map,L=r.animations?.[0];if(L&&Array.isArray(L.channels)&&Array.isArray(L.samplers))for(let E of L.channels){let C=L.samplers[E?.sampler],d=E?.target?.node,k=E?.target?.path;if(!C||typeof d!="number"||C.input===void 0)continue;let $=R.get(d);$||($={input:C.input},R.set(d,$)),k==="translation"?$.t=C.output:k==="rotation"?$.r=C.output:k==="scale"&&($.s=C.output)}let I=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(I)||I.length===0){let E=new Set;for(let C of f)if(Array.isArray(C?.children))for(let d of C.children)E.add(d);I=[];for(let C=0;C<f.length;C++)E.has(C)||I.push(C);I.length===0&&(I=[0])}let N=new Set,_=[],A=(E,C)=>{if(Array.isArray(E))for(let d=E.length-1;d>=0;d--)_.push({idx:E[d],out:C})};for(A(I,i);_.length>0;){let{idx:E,out:C}=_.pop();if(typeof E!="number"||E<0||E>=f.length||N.has(E))continue;N.add(E);let d=f[E];if(!d)continue;let k=[0,0,0],$=[0,0,0,1],S=[1,1,1];if(Array.isArray(d.matrix)&&d.matrix.length===16){let U=ci(d.matrix);k=U.t,$=U.r,S=U.s}else k=m(d.translation,0),Array.isArray(d.rotation)&&d.rotation.length>=4&&($=[Q(d.rotation[0],0),Q(d.rotation[1],0),Q(d.rotation[2],0),Q(d.rotation[3],1)]),S=m(d.scale,1);let D,T=R.get(E);if(T){let U=x(T.input,1);if(U&&U.length>0){let X=x(T.t,3),O=x(T.r,4),G=x(T.s,3),F=Array.from(U),H=[],B=[],K=[];for(let q=0;q<U.length;q++)H.push(p(X,q,k)),B.push(v(O,q,$)),K.push(p(G,q,S));D={times:F,translations:H,rotations:B,scales:K}}}let P=Array.isArray(d.children)?d.children:[],j=typeof d.mesh=="number"&&d.mesh>=0&&d.mesh<c.length,W=t?.[E]?.userData?.xr??d.extras?.xr;if(!j&&P.length===0&&(d.camera!==void 0||d.extensions?.KHR_lights_punctual||!d.name&&!d.extras&&!W&&!D))continue;let V=(U,X,O)=>({name:U,positions:w,indices:M,isXform:!0,xrTraits:W,timeSamples:D,translation:k,rotation:$,scale:S,children:X,...O?{invisible:!0}:{}}),Z=d.visible===!1||d.extensions?.KHR_node_visibility?.visible===!1||t?.[E]?.visible===!1;if(j){let U=d.name||c[d.mesh]?.name||`Mesh_${E}`,X=b(d.mesh,U,W,Z),O=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(O&&typeof O=="object"&&X.length>0){let G=x(O.TRANSLATION,3),F=x(O.ROTATION,4),H=x(O.SCALE,3),B=x(O._COLOR_0,3),K=Math.min(1e3,G?G.length/3:F?F.length/4:H?H.length/3:0);if(K>0){let q=[];for(let z=0;z<K;z++){let tt=p(G,z,[0,0,0]),et=v(F,z,[0,0,0,1]),rt=p(H,z,[1,1,1]);for(let J of X){let it=J.color||[.8,.8,.8],st=B&&B.length>=(z+1)*3;q.push({...J,name:`${J.name}_${z}`,materialName:st?`${J.materialName}_inst_${z}`:J.materialName,color:st?[it[0]*B[z*3],it[1]*B[z*3+1],it[2]*B[z*3+2]]:J.color,translation:tt,rotation:et,scale:rt})}}A(P,q),C.push(V(U,q,Z));continue}}if(X.length===1)X[0].translation=k,X[0].rotation=$,X[0].scale=S,X[0].timeSamples=D,P.length>0&&(X[0].children=[],A(P,X[0].children)),C.push(X[0]);else{let G=[...X];A(P,G),C.push(V(U,G,Z))}}else{let U=[];A(P,U),C.push(V(d.name||`Group_${E}`,U,Z))}}}else for(let w=0;w<c.length;w++){let M=c[w].name||`Mesh_${w}`;i.push(...b(w,M,c[w].extras?.xr))}return i}function re(e,t){if(!e||typeof e!="string")return t;let i=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||t}function Re(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function pt(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var St=(e,t,i)=>`(${pt(e)}, ${pt(t)}, ${pt(i)})`,pi=(e,t,i,r)=>`(${pt(e)}, ${pt(t)}, ${pt(i)}, ${pt(r)})`;function di(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=St(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ls(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${pt(e[r*2])}, ${pt(1-e[r*2+1])})`;return i.join(", ")}function hs(e){return Array.from(e).join(", ")}function Ce(e){let t=new Map,i=0,r=null,s=[...e];for(;s.length>0;){let u=s.pop();if(!u.isXform&&u.positions&&u.positions.length>0){let b=re(u.materialName,"DefaultMaterial");t.has(b)||t.set(b,{color:u.color||[.8,.8,.8],roughness:u.roughness??.5,metallic:u.metallic??0,clearcoat:u.clearcoat??0,clearcoatRoughness:u.clearcoatRoughness??0,ior:u.ior??1.5,opacity:u.opacity??1,emissiveColor:u.emissiveColor||[0,0,0]})}if(u.timeSamples&&u.timeSamples.times.length>0){let b=u.timeSamples.times[u.timeSamples.times.length-1];b>i&&(i=b)}if(u.xrTraits?.anchor&&!r&&(r=u.xrTraits.anchor==="vertical"||u.xrTraits.anchor==="wall"?"vertical":"horizontal"),u.children)for(let b=u.children.length-1;b>=0;b--)s.push(u.children[b])}let n="";i>0&&(n=`startTimeCode = 0
250
- endTimeCode = ${pt(i)}
214
+ void main(){fragColor=uColorId;}`;function ct(t,e,i){let r={};for(let n of i)r[n]=t.getUniformLocation(e,n);return r}var bs="uMVP uModel uInstanced uViewProj uNormalMatrix uUvTransform uBaseColor uMetallic uRoughness uClearcoat uEmissive uCameraPos uBaseColorTexture uHasTexture uMetallicRoughnessTexture uHasMetallicRoughnessTexture uNormalTexture uHasNormalTexture uNormalScale uOcclusionTexture uHasOcclusionTexture uOcclusionStrength uEmissiveFactor uEmissiveTexture uHasEmissiveTexture uToneMapping uEnvironmentMap uHasEnvironmentMap uAmbientColor uHemi uNumDirLights uDirLightDir uDirLightColor uNumPointLights uPointLightPos uPointLightColor uPointLightSpotDir uPointLightSpotCone uEnvIntensity uExposure uViewportSize uSectionPlane uSectionEnabled".split(" ");function kt(){let t=ge(),e=t.xrDepthShader,i=t.shadowMapShader;return{fs:ds.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||"").replace("/*SHD_U*/",i?.uniformsGLSL||"").replace("/*SHD_D*/",i?.dirGLSL||"").replace("/*SHD_P*/",i?.ptGLSL||""),uniforms:[...bs,...e?.uniformNames||[],...i?.uniformNames||[]]}}function xs(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Ut(t,e,i,r,n,s,a,o){if(r===void 0||!e.accessors?.[r])return null;let l=gi(e,i,e.accessors[r],s);if(!l)return null;o&&(l=l.slice(),us(l,o));let y=t.createBuffer();return a.push(y),t.bindBuffer(34962,y),t.bufferData(34962,l,35044),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,s,5126,!1,0,0),l}function Ot(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Mi(t,e,i){let r=kt(),n=Ft,s=r.fs,a=!1;for(let l of xe)if(l.onResolveShader){let y=l.onResolveShader(e,i,n,s);y&&(n=y.vs,s=y.fs,a=!0)}let o=a?ht(t,n,s):null;return{program:o,uniforms:o?ct(t,o,r.uniforms):null}}function vs(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let n=r.length>>4,s=e.instanceColors,a=new Float32Array(n*20);for(let l=0;l<n;l++)a.set(r.subarray(l*16,l*16+16),l*20),a[l*20+16]=s?s[l*3]:1,a[l*20+17]=s?s[l*3+1]:1,a[l*20+18]=s?s[l*3+2]:1,a[l*20+19]=1;let o=t.createBuffer();i.push(o),t.bindBuffer(34962,o),t.bufferData(34962,a,35044);for(let l=0;l<5;l++)t.enableVertexAttribArray(8+l),t.vertexAttribPointer(8+l,4,5126,!1,80,l*16),t.vertexAttribDivisor(8+l,1);return!0}function Ms(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let n of r){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Ys=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),wi=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function mt(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Si(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,n=t?.emissiveFactor,s=t?.extensions?.KHR_materials_clearcoat,a=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:a(i?.baseColorTexture),metallicRoughnessTexture:a(i?.metallicRoughnessTexture),normalTexture:a(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:a(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,emissiveTexture:a(t?.emissiveTexture),emissiveFactor:Array.isArray(n)&&n.length>=3?[n[0],n[1],n[2]]:[0,0,0],isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Ti(t,e,i){let r=new Set,n=s=>{s&&!r.has(s)&&(r.add(s),t.deleteTexture(s))};for(let s of e)for(let a of s.primitives){if(a.vao&&t.deleteVertexArray(a.vao),a.buffers)for(let l of a.buffers)t.deleteBuffer(l);for(let l of[a.texture,a.metallicRoughnessTexture,a.normalTexture,a.occlusionTexture,a.emissiveTexture])n(l);let o=new Set;a.customProgram&&o.add(a.customProgram);for(let l of a.programCache?.values()??[])l.program&&o.add(l.program);for(let l of o)t.deleteProgram(l)}if(i)for(let s of i)n(s)}function Ai(t,e,i=wi,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ws(t,e,i,r,n)}catch(s){let a=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;Ti(t,a,n.gpuTextures),n.vao&&t.deleteVertexArray(n.vao);for(let o of n.buffers)t.deleteBuffer(o);throw s}}function ws(t,e,i,r,n){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=e,a=ut("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(s,e);let o=e.bin,l=[];n.meshes=l;let y=[],f=s.extensions?.KHR_materials_variants;f&&Array.isArray(f.variants)&&f.variants.forEach((T,S)=>{y.push(typeof T?.name=="string"&&T.name?T.name:`Variant_${S}`)});let b=pi(s),h=[];if(Array.isArray(s.nodes))for(let T=0;T<s.nodes.length;T++){let S=s.nodes[T];S.mesh!==void 0&&s.meshes&&s.meshes[S.mesh]&&h.push({node:S,nodeIdx:T,meshIdx:S.mesh})}let d=h.length>0?h:(s.meshes||[]).map((T,S)=>({node:T,nodeIdx:-1,meshIdx:S})),v=[],M=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(M)for(let T of M)v.push({...T,type:T.type||T.light_type||"point",groundColor:T.groundColor??T.ground_color,innerConeAngle:T.innerConeAngle??T.inner_cone_angle,outerConeAngle:T.outerConeAngle??T.outer_cone_angle});else s.extensions?.KHR_lights_punctual?.lights&&v.push(...vi(s,b));if(v.length===0&&(v.push({type:"ambient",color:[1,1,1],intensity:.35}),v.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${d.length}`);let m=[];if(n.gpuTextures=m,s.textures&&s.images){if(s.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${s.textures.length}`);for(let T=0;T<s.textures.length;T++){let S=s.textures[T],A=s.images[S.source];if(A){let D=t.createTexture();t.bindTexture(3553,D),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[I,k]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])t.texParameteri(3553,I,k);let R=I=>{D.__gpuImageSource=I,t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()};if(A.bufferView!==void 0){let I=s.bufferViews[A.bufferView],k=I.byteOffset||0,V=new Blob([o.slice(k,k+I.byteLength)],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(V).then(R).catch(()=>{})}else if(A.uri){let I=xs(A.uri);if(I){let k=new Image;k.crossOrigin="anonymous",k.referrerPolicy="no-referrer",k.onload=()=>R(k),k.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",A.uri)}m.push(D)}else m.push(null)}}let u=[1/0,1/0,1/0],g=[-1/0,-1/0,-1/0],p=0,x=0;for(let T=0;T<d.length;T++){let S=d[T],A=s.meshes[S.meshIdx],D=S.nodeIdx>=0?b[S.nodeIdx]:ve(),R=new Float32Array(9);Oe(R,D);let I=S.node?.extras?.shadow,k={name:S.node.name||A.name||`Mesh_${S.meshIdx}`,nodeIndex:S.nodeIdx,transform:D,normalMatrix:R,primitives:[],extras:S.node.extras||A.extras,...S.node?.visible===!1||S.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{},...typeof I?.cast=="boolean"?{castShadow:I.cast}:{},...typeof I?.receive=="boolean"?{receiveShadow:I.receive}:{}};n.mesh=k;let V=S.node?.extensions?.EXT_mesh_gpu_instancing;if(V&&V.attributes&&typeof V.attributes=="object"){let L=V.attributes,O=L.TRANSLATION!==void 0?s.accessors?.[L.TRANSLATION]:null,c=L.ROTATION!==void 0?s.accessors?.[L.ROTATION]:null,F=L.SCALE!==void 0?s.accessors?.[L.SCALE]:null,C=L._COLOR_0!==void 0?s.accessors?.[L._COLOR_0]:null,U=Number(O?.count??c?.count??F?.count??0);if(!Number.isFinite(U)||U<0||U>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${U}`);if(U>0){let H=(B,X)=>{if(!B||B.bufferView===void 0||!s.bufferViews?.[B.bufferView])return null;let z=B.componentType??5126,Q=K=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${K})`),null);if(z!==5120&&z!==5121&&z!==5122&&z!==5123&&z!==5126)return Q(`componentType ${z}`);if(!(Number(B.count)>=U))return Q(`count ${B.count} < ${U}`);let te=null;try{te=gi(s,o,{...B,count:U},X)}catch{return Q("out of bounds")}return!te||!te.every(Number.isFinite)?Q("non-finite value"):te},j=H(O,3),Y=H(c,4),q=H(F,3),ne=C?.type==="VEC4"?4:3,ie=H(C,ne),oe=new Float32Array(U*16),he=ve();for(let B=0;B<U;B++){let X=B*3,z=B*4;Nt(he,Y?[Y[z],Y[z+1],Y[z+2],Y[z+3]]:[0,0,0,1],j?[j[X],j[X+1],j[X+2]]:[0,0,0],q?[q[X],q[X+1],q[X+2]]:[1,1,1]),oe.set(he,B*16)}if(k.instanceMatrices=oe,ie){let B=new Float32Array(U*3);for(let X=0;X<U;X++)B[X*3]=ie[X*ne],B[X*3+1]=ie[X*ne+1],B[X*3+2]=ie[X*ne+2];k.instanceColors=B}}}for(let L of A.primitives||[]){if(L.extensions?.KHR_draco_mesh_compression){let $=ut("draco");$&&$.decodePrimitive(s,L,o)}let O=[],c=t.createVertexArray();n.vao=c,n.buffers=O,t.bindVertexArray(c);let F=vs(t,k,O),C=s.accessors[L.attributes.POSITION],U=Number(C?.count??0);if(!Number.isFinite(U)||U<0||p+U>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(p+=U,C?.min&&C?.max){let $=G=>{for(let W=0;W<3;W++){let J=G[12+W],ae=J;for(let se=0;se<3;se++){let fe=G[se*4+W]*C.min[se],re=G[se*4+W]*C.max[se];J+=fe<re?fe:re,ae+=fe>re?fe:re}J<u[W]&&(u[W]=J),ae>g[W]&&(g[W]=ae)}};if(k.instanceMatrices&&k.instanceMatrices.length>=16){let G=k.instanceMatrices.length>>4,W=ve();for(let J=0;J<G;J++)Te(W,D,k.instanceMatrices.subarray(J*16,J*16+16)),$(W)}else $(D)}let H=Ut(t,s,o,L.attributes.POSITION,0,3,O),j=Ut(t,s,o,L.attributes.NORMAL,1,3,O),Y=Ut(t,s,o,L.attributes.TEXCOORD_0,2,2,O,Ms(s,L)),q=0,ne=5123,ie=null;if(L.indices!==void 0){let $=s.accessors[L.indices],G=(s.bufferViews[$.bufferView].byteOffset||0)+($.byteOffset||0);if(q=Number($.count??0),!Number.isFinite(q)||q<0||x+q>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);x+=q,ne=$.componentType===5125?5125:5123;let W=t.createBuffer();O.push(W),t.bindBuffer(34963,W),$.componentType===5125?ie=new Uint32Array(o,G,$.count):$.componentType===5121?ie=Uint16Array.from(new Uint8Array(o,G,$.count)):ie=G%2===0?new Uint16Array(o,G,$.count):new Uint16Array(o.slice(G,G+$.count*2)),t.bufferData(34963,ie,35044)}else q=C.count;let oe={};for(let $ of xe)if($.onBuildPrimitiveVAO){let G=$.onBuildPrimitiveVAO(t,c,L,s,o);G&&(oe[$.name]=G)}t.bindVertexArray(null);let he=s.materials&&L.material!==void 0?s.materials[L.material]:null,{program:B,uniforms:X}=Mi(t,L,he),z=Si(he,m),Q=!!(he?.extensions?.KHR_materials_transmission||oe.materials?.isTransmissive),te=L.extensions?.KHR_materials_variants?.mappings,K=Array.isArray(te)?te.filter($=>$&&typeof $.material=="number"&&Array.isArray($.variants)).map($=>({material:$.material|0,variants:$.variants.map(G=>Number(G)|0)})):void 0;k.primitives.push({vao:c,instanced:F,indexCount:q,indexType:ne,...z,positions:H,normals:j,uvs:Y,indices:ie,buffers:O,materialIndex:L.material,defaultMaterialIndex:L.material,variantMappings:K,primitiveDef:L,programCache:new Map([[L.material??-1,{program:B,uniforms:X}]]),pluginData:oe,customProgram:B,customUniforms:X,isTransmissive:Q})}l.push(k)}isFinite(u[0])||(u=[-1,-1,-1]),isFinite(g[0])||(g=[1,1,1]);let w=[(u[0]+g[0])/2,(u[1]+g[1])/2,(u[2]+g[2])/2],_=Math.max(Math.hypot(g[0]-u[0],g[1]-u[1],g[2]-u[2])/2,.5),N=[...u],P=[...g],E=e.animations;if(e.animationsParsed===!1||!E){for(let T of xe)if(T.onParseGLB?.(e),e.animations){E=e.animations;break}}return E||(E=[]),{meshes:l,bounds:{center:w,radius:_,min:N,max:P},lights:v,animations:E,worldMatrices:b,gpuTextures:m,availableVariants:y}}function ft(){return typeof performance<"u"?performance.now():Date.now()}function Je(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var _i=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ve(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.environmentSource=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=ve(),this.viewMatrix=ve(),this.activeViewMatrix=null,this.modelMatrix=ve(),this.mvpMatrix=ve(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshNames=new Set,this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:ve(),rawValueToMeters:.001,format:0},this.container=t;let r,n;if(e&&typeof e.getContext=="function"?(r=e,n=i):(n=e,r=n?.canvas),!r){let l=t.querySelector("canvas");l||(l=document.createElement("canvas"),l.style.cssText="width:100%;height:100%;display:block;touch-action:none",t.prepend(l)),r=l}this.canvas=r;let s=this.opts=n||{};s.clearColor&&(this.clearColor=s.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;s.autoRotate!==void 0?this.autoRotate=s.autoRotate&&!a:a&&(this.autoRotate=!1),s.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=s.autoRotateSpeed),s.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(s.autoRotateDelay)||0)),s.exposure!==void 0&&(this.exposure=Ot(s.exposure)),s.camera&&this.setInitialCamera(s.camera.theta,s.camera.phi,s.camera.distance,s.camera.zoom),(s.shadowIntensity!==void 0||s.shadowSoftness!==void 0)&&this.setShadow(s.shadowIntensity??0,s.shadowSoftness),s.shadowMaps!==void 0&&(this.shadowMaps=s.shadowMaps),s.toneMapping!==void 0&&(this.toneMapping=Dt(s.toneMapping)),s.autoplay!==void 0&&(this.autoplay=s.autoplay),s.animationName!==void 0&&(this.animationName=s.animationName),s.variantName!==void 0&&(this.activeVariantName=s.variantName||null),s.fieldOfView!==void 0&&(this.fov=s.fieldOfView*Math.PI/180),s.distanceMode!==void 0&&(this.distanceMode=s.distanceMode),s.cameraTarget!==void 0&&(this.setTarget(s.cameraTarget[0],s.cameraTarget[1],s.cameraTarget[2]),this.initialCustomTarget=[...s.cameraTarget]),(s.minCameraOrbit||s.maxCameraOrbit)&&this.setOrbitLimits({minTheta:s.minCameraOrbit?.theta,maxTheta:s.maxCameraOrbit?.theta,minPhi:s.minCameraOrbit?.phi,maxPhi:s.maxCameraOrbit?.phi,minDistance:s.minCameraOrbit?.distance,maxDistance:s.maxCameraOrbit?.distance});let o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),s.environmentImage&&this.setEnvironmentImage(s.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&s.autoStart!==!1&&this.start()}static registerDecoder(t,e){fs(t,e)}static getDecoder(t){return ut(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=kt();this.renderProg=ht(t,Ft,e.fs),this.pickProg=ht(t,gs,ys),this.uRender=ct(t,this.renderProg,e.uniforms),this.uPick=ct(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let t=this.gl,e=kt();this.renderProg&&t.deleteProgram(this.renderProg),this.renderProg=ht(t,Ft,e.fs),this.uRender=ct(t,this.renderProg,e.uniforms);for(let i of this.meshes)for(let r of i.primitives)r.customProgram&&(t.deleteProgram(r.customProgram),r.programCache?.clear(),this.applyPrimitiveProgram(r,r.materialIndex,this.gltf?.materials?.[r.materialIndex??-1]??null))}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of xe)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;typeof t.createFramebuffer=="function"&&(this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer(),this.resizePickingFbo(this.canvas.width,this.canvas.height),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null))}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),n=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=n,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,n,0,6408,5121,null),i.texParameteri(3553,10241,9728),i.texParameteri(3553,10240,9728),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,n)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:n,animations:s,worldMatrices:a,gpuTextures:o,availableVariants:l}=Ai(this.gl,t,e,()=>this.render());this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=a||[],this.gpuTextures=o||[],this.availableVariants=l||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(t.gltf?.nodes||[]).map(b=>({t:[b.translation?.[0]??0,b.translation?.[1]??0,b.translation?.[2]??0],r:[b.rotation?.[0]??0,b.rotation?.[1]??0,b.rotation?.[2]??0,b.rotation?.[3]??1],s:[b.scale?.[0]??1,b.scale?.[1]??1,b.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let b of xe)b.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let y=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;y!==void 0&&(this.exposure=Ot(y));let f=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;f!==void 0&&(this.envIntensity=Math.max(0,Number(f)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(xi(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of xe)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(It(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=It(t),{meshes:r}=Ai(this.gl,i,wi,()=>this.render());if(e)for(let n of r)n.transform[12]+=e[0],n.transform[13]+=e[1],n.transform[14]+=e[2],Oe(n.normalMatrix,n.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r=t instanceof Map?t.get(i.name)??t.get(e):Array.isArray(t)?t[e]:t&&typeof t=="object"?Object.prototype.hasOwnProperty.call(t,i.name)?t[i.name]:Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:void 0;r&&r.length===16&&(i.transform.set(r),Oe(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[0,0,0,0,0,0,0,1,0],n=!1,s=[],a=[],o=[],l=[],y=[],f=[];for(let b of this.lights){let h=b.color||[1,1,1],d=b.intensity!==void 0?b.intensity:1;if(b.type==="ambient")i=[h[0]*d,h[1]*d,h[2]*d];else if(b.type==="hemisphere"){n=!0;let v=b.groundColor||[.2,.2,.2],M=d*.65;for(let g=0;g<3;g++)r[g]+=h[g]*M,r[g+3]+=v[g]*M;let m=b.position||[0,1,0],u=Math.hypot(m[0],m[1],m[2]);u>1e-5&&(r[6]=m[0]/u,r[7]=m[1]/u,r[8]=m[2]/u)}else if(b.type==="directional"&&s.length<6){let v=b.direction||[.5,1,.8];s.push(v[0],v[1],v[2]),a.push(h[0]*d,h[1]*d,h[2]*d)}else if((b.type==="point"||b.type==="spot")&&o.length<6){let v=b.position||[0,0,0];if(o.push(v[0],v[1],v[2]),l.push(h[0]*d,h[1]*d,h[2]*d),b.type==="spot"){let M=b.direction||[0,-1,0],m=Math.max(.01,Math.min(Math.PI/2,b.outerConeAngle??Math.PI/3)),u=Math.max(0,Math.min(m-1e-4,b.innerConeAngle??0));y.push(M[0],M[1],M[2]),f.push(Math.cos(u),Math.cos(m))}else y.push(0,-1,0),f.push(-2,-3)}}s.length===0&&!n&&(s.push(.5,1,.8),a.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),t.uHemi&&e.uniformMatrix3fv(t.uHemi,!1,r),e.uniform1i(t.uNumDirLights,s.length/3),s.length>0&&(e.uniform3fv(t.uDirLightDir,s),e.uniform3fv(t.uDirLightColor,a)),e.uniform1i(t.uNumPointLights,o.length/3),o.length>0&&(e.uniform3fv(t.uPointLightPos,o),e.uniform3fv(t.uPointLightColor,l),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,y),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,f)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Ot(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Dt(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){this.environmentSource=t&&typeof t=="object"?t:null;for(let e of xe)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t),this.render();return}this.render()}async setSkyboxImage(t){for(let e of xe)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(f=>f.primitives.filter(b=>b.materialIndex===i||t.length===1&&b.materialIndex===void 0)),n=r[0],s=n?[...n.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],a=n?n.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,l=(f,b,h)=>{y[f]=h,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness[f]=h);for(let d of r)d[b]=h;this.render()},y={baseColorFactor:s,metallicFactor:a,roughnessFactor:o,setBaseColorFactor:f=>l("baseColorFactor","baseColor",[f[0],f[1],f[2],f[3]??1]),setMetallicFactor:f=>l("metallicFactor","metallic",f),setRoughnessFactor:f=>l("roughnessFactor","roughness",f)};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:y}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let n of this.meshes)for(let s of n.primitives){let a=s.defaultMaterialIndex;if(!e&&Array.isArray(s.variantMappings)){for(let l of s.variantMappings)if(Array.isArray(l.variants)&&l.variants.includes(i)){a=l.material;break}}let o=a!==void 0?r[a]:void 0;s.materialIndex=o?a:void 0,Object.assign(s,Si(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,n=t.programCache.get(r);n||(n=Mi(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,n)),t.customProgram=n.program,t.customUniforms=n.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of xe)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){let e=Math.PI/180,i=Math.PI*.48;t.minTheta!==void 0&&(this.minTheta=t.minTheta*e),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*e),t.minPhi!==void 0&&(this.minPhi=Math.max(-i,t.minPhi*e)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(i,t.maxPhi*e)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){let t=180/Math.PI;return{minTheta:isFinite(this.minTheta)?this.minTheta*t:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*t:void 0,minPhi:this.minPhi*t,maxPhi:this.maxPhi*t,minDistance:this.minDistanceLimit??void 0,maxDistance:this.maxDistanceLimit??void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=this.bounds?.radius;return Math.max(this.minDistanceLimit??(e?e*.5:.1),Math.min(this.maxDistanceLimit??(e?e*8:100),t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(t,e,i,r){t!==void 0&&(this.initialTheta=this.targetTheta=this.currTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.initialPhi=this.targetPhi=this.currPhi=this.clampPhi(e*Math.PI/180));let n=i!==void 0&&i>0?i:r!==void 0&&r>0?this.bounds.radius*2.5/r:null;this.customDistance=n!==null,this.initialDistance=this.targetDistance=this.currDistance=this.clampDistance(n??(this.distanceMode==="absolute"?3:this.bounds.radius*2.5)),this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.targetDistance=this.clampDistance(this.initialDistance??this.bounds.radius*2.5),this.customTarget=this.initialCustomTarget?[...this.initialCustomTarget]:null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let i=ve();Te(i,this.projMatrix,this.viewMatrix);let r=(P,E,T=1)=>[P[0]*E[0]+P[4]*E[1]+P[8]*E[2]+P[12]*T,P[1]*E[0]+P[5]*E[1]+P[9]*E[2]+P[13]*T,P[2]*E[0]+P[6]*E[1]+P[10]*E[2]+P[14]*T,P[3]*E[0]+P[7]*E[1]+P[11]*E[2]+P[15]*T],n=this.modelRootMatrix,[s,a,o]=n?r(n,t):t,[l,y,f]=e?n?r(n,e,0):e:[0,0,0],[b,h,d,v]=r(i,[s,a,o]);if(v<=1e-4)return{x:0,y:0,z:1,visible:!1};let M=b/v,m=h/v,u=d/v,g=this.canvas.getBoundingClientRect(),p=g.width||this.canvas.clientWidth||this.canvas.width||300,x=g.height||this.canvas.clientHeight||this.canvas.height||150,w=(M*.5+.5)*p,_=(-m*.5+.5)*x,N=M>=-1.1&&M<=1.1&&m>=-1.1&&m<=1.1&&u>=-1&&u<=1;if(N&&e){let[P,E,T]=Je(this),S=[s-P,a-E,o-T];l*S[0]+y*S[1]+f*S[2]>.05&&(N=!1)}return{x:w,y:_,z:u,visible:N}}setSelectedMesh(t){this.setSelectedMeshes([t])}setSelectedMeshes(t){this.selectedMeshNames=new Set(t.filter(Boolean))}getSelectedMesh(){return[...this.selectedMeshNames][0]||""}setupEvents(){let t=this.canvas,e=ft;this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=i.clientX-r.x,s=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],l=this.customTarget?[...this.customTarget]:[...this.bounds.center],y=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;l[0]+=(-n*a[0]+s*o[0])*y,l[1]+=(-n*a[1]+s*o[1])*y,l[2]+=(-n*a[2]+s*o[2])*y,this.customTarget=l}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),n=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),s=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(n,s,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,n)=>{this[n]&&(i.removeEventListener(r,this[n]),this[n]=null)},e=this.canvas;for(let[i,r]of[["webglcontextlost","boundContextLost"],["webglcontextrestored","boundContextRestored"],["contextmenu","boundContextMenu"],["pointerdown","boundPointerDown"],["pointermove","boundPointerMove"],["pointerup","boundPointerUp"],["wheel","boundWheel"],["keydown","boundKeyDown"]])t(e,i,r);t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),n=i.width||300,s=i.height||300,a=r.width>0?Math.floor((t-r.left)*(n/r.width)):Math.floor(t),o=r.height>0?Math.floor((e-r.top)*(s/r.height)):Math.floor(e);return this.performMeshPick(a,o,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,n);let a=ve();Te(a,this.projMatrix,this.viewMatrix);let o=[],l=Math.max(0,Math.min(n-1,t)),y=Math.max(0,Math.min(s-1,s-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,n,s),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let w=0;w<this.meshes.length;w++){let _=this.meshes[w];if(_.visible===!1||_.isPluginMesh)continue;let N=w+1,P=(N&255)/255,E=(N>>8&255)/255,T=(N>>16&255)/255;r.uniform4f(this.uPick.uColorId,P,E,T,1),Te(this.modelMatrix,this.modelRootMatrix,_.transform);let S=_.instanceMatrices;if(S&&S.length>=16){let A=S.length>>4,D=ve();for(let R of _.primitives){r.bindVertexArray(R.vao);for(let I=0;I<A;I++)Te(D,this.modelMatrix,S.subarray(I*16,I*16+16)),Te(this.mvpMatrix,a,D),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),mt(r,R)}}else{Te(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let A of _.primitives)r.bindVertexArray(A.vao),mt(r,A)}}let p=new Uint8Array(4);r.readPixels(l,y,1,1,6408,5121,p),r.bindFramebuffer(36160,null);let x=p[0]+(p[1]<<8)+(p[2]<<16);x>0&&x<=this.meshes.length&&(o=[this.meshes[x-1]])}o.length===0&&(o=this.meshes.filter(p=>p.visible!==!1));let f=null,b=1/0,h=[0,0,0],d=[0,1,0],[v,M,m]=Je(this),u=ve();for(let p of o){Te(u,this.modelRootMatrix,p.transform);let x=p.instanceMatrices,w=x&&x.length>=16?x.length>>4:1;for(let _=0;_<w;_++){x&&x.length>=16?Te(this.modelMatrix,u,x.subarray(_*16,_*16+16)):this.modelMatrix.set(u),Te(this.mvpMatrix,a,this.modelMatrix);let N=ve();if(!os(N,this.mvpMatrix))continue;let P=(l+.5)/n*2-1,E=(y+.5)/s*2-1,T=[0,0,0],S=[0,0,0];fi(T,P,E,-1,N),fi(S,P,E,1,N);let A=S[0]-T[0],D=S[1]-T[1],R=S[2]-T[2],I=Math.hypot(A,D,R)||1,k=A/I,V=D/I,L=R/I,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let c of p.primitives){if(!c.positions)continue;let F=c.positions,C=c.indices,U=Math.floor(C?C.length/3:F.length/9);for(let H=0;H<U;H++){let j=(C?C[H*3]:H*3)*3,Y=(C?C[H*3+1]:H*3+1)*3,q=(C?C[H*3+2]:H*3+2)*3;ls(T[0],T[1],T[2],k,V,L,F[j],F[j+1],F[j+2],F[Y],F[Y+1],F[Y+2],F[q],F[q+1],F[q+2],O,1e-4)}}if(isFinite(O.distance)){let c=O.point[0],F=O.point[1],C=O.point[2],U=this.modelMatrix,H=U[0]*c+U[4]*F+U[8]*C+U[12],j=U[1]*c+U[5]*F+U[9]*C+U[13],Y=U[2]*c+U[6]*F+U[10]*C+U[14],q=H-v,ne=j-M,ie=Y-m,oe=Math.hypot(q,ne,ie);if(oe<b){Oe(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,B=O.normal[0],X=O.normal[1],z=O.normal[2],Q=he[0]*B+he[3]*X+he[6]*z,te=he[1]*B+he[4]*X+he[7]*z,K=he[2]*B+he[5]*X+he[8]*z,$=Math.hypot(Q,te,K)||1;Q/=$,te/=$,K/=$,Q*q+te*ne+K*ie>0&&(Q=-Q,te=-te,K=-K);let G=W=>Math.round(W*1e3)/1e3;f=p,b=G(oe),h=[G(H),G(j),G(Y)],d=[G(Q),G(te),G(K)]}}}}if(!f)return null;let g={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:b,hitPoint:h,normal:d,screenX:t,screenY:e};if(i){for(let p of xe)p.onMeshSelect?.(this,g);this.opts.onMeshClick&&this.opts.onMeshClick(g),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:g}))}return g}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,n=r?t-i:t,s=r?Math.max(1,e-i):i,a=(n+.5)/s*2-1;return Math.floor((a*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);mi(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;Lt(this.viewMatrix,Je(this),i,[0,1,0]),Te(this.mvpMatrix,this.projMatrix,this.viewMatrix),Oe(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of xe)i.onXRSessionEnd?.(this);if(this.lastTime=ft(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of xe)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=ft();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),[i,,r]=this.bounds.center;this.modelRootMatrix.set([t,0,-e,0,0,1,0,0,e,0,t,0,i-(t*i+e*r),0,r-(-e*i+t*r),1])}setVisible(t){this.isVisible=t}update(t){for(let s of xe)s.onUpdate?.(this,t);let e=ft();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of xe)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=n;let s={theta:i,phi:r,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(t,e,i,r,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let a=t?.transform?.inverse?.matrix||this.viewMatrix,o=t?.projectionMatrix||this.projMatrix,l=t?.transform?.position,y=l?[l.x,l.y,l.z]:[0,1.6,0];e&&this.modelRootMatrix.set(e),this.render({viewMatrix:a,projMatrix:o,eyePos:y,viewport:r,eye:t?.eye||"none",clear:s>0?!1:t?.eye!=="right",isAR:n})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let _=Math.max(2,this.canvas.width||2),N=Math.max(1,this.canvas.height||1),P=Math.max(1,Math.floor(_*.5)),E=Math.max(1,_-P),T=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),S=this.customTarget||this.bounds.center,[A,D,R]=Je(this),I=Math.cos(this.currTheta),k=-Math.sin(this.currTheta),V=.032;for(let L of[-1,1]){let O=ve(),c=ve(),F=L<0?P:E,C=[A+L*I*V,D,R+L*k*V];mi(O,this.fov,F/N,.1,T),Lt(c,C,[S[0]+L*I*V*.25,S[1],S[2]+L*k*V*.25],[0,1,0]),this.render({viewMatrix:c,projMatrix:O,eyePos:C,viewport:[L<0?0:P,0,F,N],eye:L<0?"left":"right",clear:L<0,isAR:!1})}this.gl.viewport(0,0,_,N);return}let e=this.gl,[i,r,n,s]=t?.viewport||[0,0,this.canvas.width,this.canvas.height];if(e.viewport(i,r,n,s),e.enable(2929),!t||t.clear!==!1){let _=t?.isAR?[0,0,0,0]:this.clearColor;e.clearColor(_[0],_[1],_[2],_[3]),e.clear(16640)}let a=ve(),o=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o;let l=t?.projMatrix??this.projMatrix;Te(a,l,o);let y=ge(),f=y.xrDepthShader,b=cs(this.toneMapping),[h,d,v]=t?t.eyePos:Je(this);for(let _ of xe)_.onBeforeDrawScene?.(this,e,a,[h,d,v],b);let M=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&M===0){y.gpuSceneAccelerator?.hideLayer?.(this);return}let m=t?.eye||"none",u=!t||t.clear!==!1;if(!this.xrSessionActive&&y.gpuSceneAccelerator?.renderScene(this,a,l,o,[h,d,v],b,[i,r,n,s],m,u,!!t?.isAR)){u&&!this.skyboxTexture&&(e.clearColor(0,0,0,0),e.clear(16384));for(let _ of xe)_.name.includes("webgpu")&&_.onAfterRender?.(e,this,a,m,[i,r,n,s],l);return}let g=!1,p=M>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=(_,N,P,E)=>{N?(e.activeTexture(33984+_),e.bindTexture(3553,N),e.uniform1i(P,_),e.uniform1i(E,1)):e.uniform1i(E,0)},w=_=>{for(let N=0;N<p.length;N++){let P=p[N];if(P.visible===!1)continue;let E=this.selectedMeshNames.has(P.name);if(N<M||P.worldSpace===!0||P.name==="__xr_reticle__")this.modelMatrix.set(P.transform);else{Te(this.modelMatrix,this.modelRootMatrix,P.transform);let I=!t&&(P.extras?.xr?.billboard??P.userData?.xr?.billboard);if(I){let k=this.modelMatrix,V=Math.hypot(k[0],k[1],k[2])||1,L=Math.hypot(k[4],k[5],k[6])||1,O=Math.hypot(k[8],k[9],k[10])||1,c=I==="y"||I==="cylindrical"||I==="capsule",F=h-k[12],C=v-k[14],U=Math.hypot(F,C),H=U>1e-5?F/U:0,j=U>1e-5?C/U:1;k.set(c?[j*V,0,-H*V,0,0,L,0,0,H*O,0,j*O]:[o[0]*V,o[4]*V,o[8]*V,0,o[1]*L,o[5]*L,o[9]*L,0,o[2]*O,o[6]*O,o[10]*O])}}Te(this.mvpMatrix,a,this.modelMatrix),Oe(P.normalMatrix,this.modelMatrix);let T=P.extras?.xr?.stereo||P.userData?.xr?.stereo,S=0,A=0,D=1,R=1;T==="sbs"?(D=.5,S=m==="right"?.5:0):T==="ou"&&(R=.5,A=m==="right"?.5:0);for(let I of P.primitives){let k=!!I.isTransmissive;if(!_&&k){g=!0;continue}if(_&&!k)continue;let V=I.customProgram||this.renderProg,L=I.customUniforms||this.uRender;e.useProgram(V),e.vertexAttrib3f(3,0,0,0),L.uInstanced&&e.uniform1i(L.uInstanced,0),e.uniform1i(L.uToneMapping,b),e.uniform1f(L.uEnvIntensity,this.envIntensity),L.uExposure&&e.uniform1f(L.uExposure,this.exposure),e.uniform3f(L.uCameraPos,h,d,v),e.uniform1f(L.uEmissive,E?1:0),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(L.uNormalMatrix,!1,P.normalMatrix),L.uUvTransform&&e.uniform4f(L.uUvTransform,S,A,D,R),L.uViewportSize&&e.uniform2f(L.uViewportSize,Math.max(1,n),Math.max(1,s)),f?.bind(e,L,this.xrDepthState,o,[i,r,Math.max(1,n),Math.max(1,s)]),y.shadowMapShader?.bind(e,L,this,P),x(4,this.environmentTexture,L.uEnvironmentMap,L.uHasEnvironmentMap),this.bindLights(L),L.uSectionEnabled&&e.uniform1i(L.uSectionEnabled,0);for(let c of xe)c.onBeforeDrawPrimitive?.(e,V,I,P,this.worldMatrices||[],this.gltf);e.uniform4fv(L.uBaseColor,I.baseColor),e.uniform1f(L.uMetallic,I.metallic),e.uniform1f(L.uRoughness,I.roughness),L.uClearcoat&&e.uniform2f(L.uClearcoat,I.clearcoat??0,I.clearcoatRoughness??.04),x(0,I.texture,L.uBaseColorTexture,L.uHasTexture),x(1,I.metallicRoughnessTexture,L.uMetallicRoughnessTexture,L.uHasMetallicRoughnessTexture),x(2,I.normalTexture,L.uNormalTexture,L.uHasNormalTexture),I.normalTexture&&e.uniform1f(L.uNormalScale,I.normalScale),x(3,I.occlusionTexture,L.uOcclusionTexture,L.uHasOcclusionTexture),I.occlusionTexture&&e.uniform1f(L.uOcclusionStrength,I.occlusionStrength),e.uniform3fv(L.uEmissiveFactor,I.emissiveFactor),x(8,I.emissiveTexture,L.uEmissiveTexture,L.uHasEmissiveTexture),e.bindVertexArray(I.vao);let O=P.instanceMatrices;if(I.instanceCount!==void 0)e.drawElementsInstanced(4,I.indexCount,I.indexType,0,I.instanceCount);else if(O&&O.length>=16&&I.instanced&&L.uInstanced&&L.uViewProj){let c=O.length>>4;e.uniform1i(L.uInstanced,1),e.uniformMatrix4fv(L.uViewProj,!1,a),I.indices?e.drawElementsInstanced(4,I.indexCount,I.indexType,0,c):e.drawArraysInstanced(4,0,I.indexCount,c),e.uniform1i(L.uInstanced,0)}else if(O&&O.length>=16){let c=O.length>>4,F=P.instanceColors,C=ve(),U=new Float32Array(9);for(let H=0;H<c;H++){if(Te(C,this.modelMatrix,O.subarray(H*16,H*16+16)),Te(this.mvpMatrix,a,C),Oe(U,C),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,C),e.uniformMatrix3fv(L.uNormalMatrix,!1,U),F){let j=I.baseColor,Y=H*3;e.uniform4fv(L.uBaseColor,[j[0]*F[Y],j[1]*F[Y+1],j[2]*F[Y+2],j[3]])}mt(e,I)}}else mt(e,I)}}};if(w(!1),g){for(let _ of xe)_.onBeforeTransmissivePass?.(e,this);w(!0)}for(let _ of xe)_.onAfterRender?.(e,this,a,m,[i,r,n,s],l)}disposeMeshListGpuResources(t,e){Ti(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of xe)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};_i.registerPlugin=ns,_i.getRegisteredPlugins=as;function Ss(t){return t+3&-4}var Z=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function $t(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function Pi(t,e,i){let r=Math.hypot(t,e,i)||1,n=t/r,s=e/r,a=-(i/r);if(a<-.999999)return[0,1,0,0];let o=Math.sqrt((1+a)*2);return[s/o,-n/o,0,o*.5]}function Ci(t,e=0){let[i,r,n,,s,a,o,,l,y,f,,b,h,d]=Array.from({length:15},(O,c)=>Z(t[e+c],c%5===0?1:0)),v=Math.hypot(i,r,n),M=Math.hypot(s,a,o),m=Math.hypot(l,y,f);i*(a*f-y*o)-s*(r*f-y*n)+l*(r*o-a*n)<0&&(v=-v);let u=Math.abs(v)>1e-8?1/v:0,g=Math.abs(M)>1e-8?1/M:0,p=Math.abs(m)>1e-8?1/m:0,x=i*u,w=r*u,_=n*u,N=s*g,P=a*g,E=o*g,T=l*p,S=y*p,A=f*p,D=x+P+A,R=0,I=0,k=0,V=1;if(D>0){let O=.5/Math.sqrt(D+1);V=.25/O,R=(E-S)*O,I=(T-_)*O,k=(w-N)*O}else if(x>P&&x>A){let O=2*Math.sqrt(Math.max(0,1+x-P-A));O>1e-8&&(V=(E-S)/O,R=.25*O,I=(N+w)/O,k=(T+_)/O)}else if(P>A){let O=2*Math.sqrt(Math.max(0,1+P-x-A));O>1e-8&&(V=(T-_)/O,R=(N+w)/O,I=.25*O,k=(E+S)/O)}else{let O=2*Math.sqrt(Math.max(0,1+A-x-P));O>1e-8&&(V=(w-N)/O,R=(T+_)/O,I=(E+S)/O,k=.25*O)}let L=Math.hypot(R,I,k,V);return L>1e-8&&Number.isFinite(L)?(R/=L,I/=L,k/=L,V/=L):(R=0,I=0,k=0,V=1),{t:[b,h,d],r:[R,I,k,V],s:[v,M,m]}}function Ts(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var Ee=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Ri(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,n=typeof i.preset=="string"?i.preset:void 0;return!r&&!n?null:{ae:i,src:r,preset:n,volume:Ee(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function As(t){let e=t?.material,i=e?._presetMaps?.map;if(!i||i!==e.map)return null;let r=/^ai_([0-9a-f]{16})_albedo$/.exec(String(i.name??""));return r?r[1]:null}function Qe(t,e){return Ei(t,e)[0]}function Ei(t,e){t.updateMatrixWorld(!0);let i=[],r=0,n=[],s=[],a=[],o=[],l=new Set,y=[],f=[],b=new Map,h=[],d=[],v=[],M=new Map,m=[],u=[],g=[],p=!1;function x(c){let F=b.get(c);if(F!==void 0)return F;F=f.length,b.set(c,F);let C=c,U=C.color?.r??1,H=C.color?.g??1,j=C.color?.b??1,Y=C.opacity??1,q={baseColorFactor:[U,H,j,Y],metallicFactor:C.metalness??0,roughnessFactor:C.roughness??.5},ne={},ie=re=>{if(!re)return;let Se=(typeof re=="string"?re:typeof re.source=="string"?re.source:typeof re.image=="string"?re.image:"").trim();if(!Se||/[\x00-\x1f\x7f\\]|\.\./.test(Se)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(Se)||!Se.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(Se)))return;let le=M.get(Se);if(le===void 0){let me=h.length;h.push({uri:Se}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),le=v.length,v.push({sampler:0,source:me}),M.set(Se,le)}return{index:le}},oe=C._packPbr?.(),he=ie(C.map);he&&(q.baseColorTexture=he);let B=ie(oe?.mrUri||C.roughnessMap||C.metalnessMap);B&&(q.metallicRoughnessTexture=B);let X=C.map?.avgColor;Array.isArray(X)&&X.length>=3&&(ne.avgColor=[X[0],X[1],X[2]]);let z=ie(oe?.normUri||C.normalMap),Q=C.normalScale,te=oe?.normUri?oe.normScale??1:typeof Q=="number"?Math.max(0,Z(Q,1)):Q?Math.max(0,(Z(Q.x,1)+Z(Q.y,1))*.5):1;z&&te!==1&&(z.scale=te);let K=ie(C.emissiveMap),$=ie(C.aoMap),G=Math.max(0,Math.min(1,Z(C.aoMapIntensity,1)));$&&G!==1&&($.strength=G);let W={name:C.name||"",pbrMetallicRoughness:q,doubleSided:C.side===2||!!C.doubleSided,...Y<1||C.transparent?{alphaMode:"BLEND"}:{},...z?{normalTexture:z}:{},...K?{emissiveTexture:K}:{},...$?{occlusionTexture:$}:{},...Object.keys(ne).length>0?{extras:ne}:{}},J=Math.max(0,Z(C.emissiveIntensity,1)),ae=C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0);(ae||K&&!C._em&&J>0)&&(W.emissiveFactor=ae?[C.emissive.r*J,C.emissive.g*J,C.emissive.b*J]:[J,J,J]);let se={};C.clearcoat&&C.clearcoat>0&&(se.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen&&C.sheen>0&&(se.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission&&C.transmission>0&&(se.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness&&C.thickness>0&&(se.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(se.KHR_materials_ior={ior:C.ior}),C.dispersion&&C.dispersion>0&&(se.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence&&C.iridescence>0&&(se.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3});let fe=C._serializeTslGraph?.();return fe&&(se.GOOGLE_material_tsl=fe,l.add("GOOGLE_material_tsl")),Object.keys(se).length>0&&(W.extensions=se),f.push(W),F}function w(c,F){let C=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),U=Ss(C.byteLength),H=new Uint8Array(U);H.set(C),i.push(H);let j=n.length;return n.push({buffer:0,byteOffset:r,byteLength:C.byteLength,target:F}),r+=U,j}function _(c,F,C,U,H,j,Y){let q=w(c,C),ne=s.length,ie={bufferView:q,byteOffset:0,componentType:U,count:H,type:F};return j&&(ie.min=j),Y&&(ie.max=Y),s.push(ie),ne}let N=[],P=[],E=new Set([t]),T=[];if(Array.isArray(t.children))for(let c=t.children.length-1;c>=0;c--)T.push({obj:t.children[c],parentKids:P});for(;T.length>0;){let{obj:c,parentKids:F}=T.pop();if(!c||typeof c!="object"||E.has(c))continue;E.add(c),c._bakeAuthorGeometry?.(),ge().materializeDeclarativeGeometry?.(c);let C=!!(c.userData&&(c.userData.xr&&typeof c.userData.xr=="object"&&Object.keys(c.userData.xr).length>0||c.userData.interactivity&&typeof c.userData.interactivity=="object"&&Object.keys(c.userData.interactivity).length>0)),U={name:c.name||(C?`Node_${o.length}`:"")},H=Z(c.position?.x,0),j=Z(c.position?.y,0),Y=Z(c.position?.z,0),q=Z(c.quaternion?.x,0),ne=Z(c.quaternion?.y,0),ie=Z(c.quaternion?.z,0),oe=Z(c.quaternion?.w,1),he=Z(c.scale?.x,1),B=Z(c.scale?.y,1),X=Z(c.scale?.z,1);if((H||j||Y)&&(U.translation=[H,j,Y]),(q||ne||ie||oe!==1)&&(U.rotation=[q,ne,ie,oe]),(he!==1||B!==1||X!==1)&&(U.scale=[he,B,X]),c.visible===!1&&(U.extensions={...U.extensions||{},KHR_node_visibility:{visible:!1}},l.add("KHR_node_visibility")),c.userData&&Object.keys(c.userData).length>0&&(U.extras=JSON.parse(JSON.stringify(c.userData,($,G)=>{if(!($==="__proto__"||$==="prototype"||$==="constructor"))return typeof G=="function"?void 0:G})),c.userData.xr)){let $=Ts(c.userData.xr);U.extensions={...U.extensions||{},MOZ_hubs_components:$,ANDROID_xr_scenecore:$},ge().xrTraitSerializer?.gltfNode(U,c.userData.xr);let G=As(c),W=U.extras?.xr?.material;G&&W&&typeof W=="object"&&!Array.isArray(W)&&(W.textureKey=G),l.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let z=c,Q=z.isLight||z.color&&z.intensity!==void 0;if(!Q&&(z._castShdSet||z._recvShdSet||c.castShadow||c.receiveShadow)&&(U.extras={...U.extras||{},shadow:{cast:!!c.castShadow,receive:z._recvShdSet?!!c.receiveShadow:!!(c.receiveShadow||c.castShadow)}}),Q){let $=z.matrixWorld?.elements,G=Z($?$[12]:c.position?.x,0),W=Z($?$[13]:c.position?.y,0),J=Z($?$[14]:c.position?.z,0),ae=z.target,se=ae?.parent?ae?.matrixWorld?.elements:void 0,fe=Z(se?se[12]:ae?.position?.x,0),re=Z(se?se[13]:ae?.position?.y,0),Se=Z(se?se[14]:ae?.position?.z,0),le=fe-G,me=re-W,ue=Se-J,ce=Math.hypot(le,me,ue),ye=Math.max(.01,Math.min(Math.PI/2,Z(z.angle,Math.PI/3))),Ce=Math.max(0,Math.min(1,Z(z.penumbra,0))),de=Math.max(0,ye*(1-Ce)),De=Math.max(0,Z(z.distance,0)),Ge=c.type==="directional"||c.type==="spot"||c.type==="point",Ue;if(c.castShadow&&Ge){let Ze=z.shadow,Et=Math.max(256,Math.min(2048,Math.round(Z(Ze?.mapSize?.x??Ze?.mapSize?.width,1024))));Ue={cast:!0,mapSize:Et<=384?256:Et<=768?512:Et<=1536?1024:2048,bias:Ee(Ze?.bias,-.05,.05,-5e-4),normalBias:Ee(Ze?.normalBias,0,.2,.015),radius:Ee(Ze?.radius,0,8,1.5)},p=!0}let Pt=G-fe,Ct=W-re,Rt=J-Se,ot=Math.hypot(Pt,Ct,Rt);u.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:c.type==="directional"?[Pt,Ct,Rt]:[G,W,J],...c.type==="directional"?{direction:ot>1e-6?[Pt/ot,Ct/ot,Rt/ot]:[0,1,0]}:c.type==="spot"?{direction:ce>1e-6?[le/ce,me/ce,ue/ce]:[0,-1,0],outerConeAngle:ye,innerConeAngle:de,range:De}:c.type==="point"?{range:De}:c.type==="hemisphere"&&z.groundColor?{groundColor:[z.groundColor.r,z.groundColor.g,z.groundColor.b]}:{},...Ue?{shadow:Ue}:{}}),Ge&&N.push({node:U,obj:c,px:G,py:W,pz:J,tx:fe,ty:re,tz:Se,dx:le,dy:me,dz:ue,dLen:ce,outerAngle:ye,innerAngle:de,range:De,shadowSpec:Ue})}if(c.geometry){let $=c.geometry,G=$.attributes.position;if(G&&G.count>0){let W=[1/0,1/0,1/0],J=[-1/0,-1/0,-1/0];for(let le=0;le<G.count;le++){let me=G.getX(le),ue=G.getY(le),ce=G.getZ(le);me<W[0]&&(W[0]=me),me>J[0]&&(J[0]=me),ue<W[1]&&(W[1]=ue),ue>J[1]&&(J[1]=ue),ce<W[2]&&(W[2]=ce),ce>J[2]&&(J[2]=ce)}let ae={attributes:{POSITION:_(G.array,"VEC3",34962,5126,G.count,W,J)}};if($.attributes.normal&&(ae.attributes.NORMAL=_($.attributes.normal.array,"VEC3",34962,5126,$.attributes.normal.count)),$.attributes.uv&&(ae.attributes.TEXCOORD_0=_($.attributes.uv.array,"VEC2",34962,5126,$.attributes.uv.count)),$.index){let le=$.index.array instanceof Uint32Array;ae.indices=_($.index.array,"SCALAR",34963,le?5125:5123,$.index.count)}let se=Array.isArray(c.material)?c.material[0]:c.material;se&&(ae.material=x(se));let fe=c.userData?.variants;if(fe&&typeof fe=="object"){let le=new Map;for(let me of Object.keys(fe)){if(!me||me==="__proto__"||me==="constructor"||me==="prototype")continue;let ue=fe[me];if(!ue||typeof ue!="object")continue;let ce=m.indexOf(me);if(ce===-1&&m.length<256&&(ce=m.length,m.push(me)),ce===-1)continue;let ye=x(ue),Ce=le.get(ye);Ce||(Ce=[],le.set(ye,Ce)),Ce.push(ce)}if(le.size>0){let me=[];for(let[ue,ce]of le.entries())me.push({material:ue,variants:ce});ae.extensions={...ae.extensions||{},KHR_materials_variants:{mappings:me}},l.add("KHR_materials_variants")}}let re=c;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let le=Math.min(1e4,Math.floor(re.count)),me=re.instanceMatrix.array,ue=new Float32Array(le*3),ce=new Float32Array(le*4),ye=new Float32Array(le*3);for(let de=0;de<le;de++){let{t:De,r:Ge,s:Ue}=Ci(me,de*16);ue[de*3]=De[0],ue[de*3+1]=De[1],ue[de*3+2]=De[2],ce[de*4]=Ge[0],ce[de*4+1]=Ge[1],ce[de*4+2]=Ge[2],ce[de*4+3]=Ge[3],ye[de*3]=Ue[0],ye[de*3+1]=Ue[1],ye[de*3+2]=Ue[2]}let Ce={TRANSLATION:_(ue,"VEC3",0,5126,le),ROTATION:_(ce,"VEC4",0,5126,le),SCALE:_(ye,"VEC3",0,5126,le)};if(re.instanceColor?.array&&re.instanceColor.array.length>=le*3){let de=new Float32Array(re.instanceColor.array.subarray(0,le*3));Ce._COLOR_0=_(de,"VEC3",0,5126,le)}U.extensions={...U.extensions||{},EXT_mesh_gpu_instancing:{attributes:Ce}},l.add("EXT_mesh_gpu_instancing")}let Se=a.length;a.push({primitives:[ae],name:c.name,...U.extras?{extras:U.extras}:{}}),U.mesh=Se}}let te=o.length;o.push(U),y.push(c),F.push(te);let K=c.children;if(Array.isArray(K)&&K.length>0){let $=[];U.children=$;for(let G=K.length-1;G>=0;G--)T.push({obj:K[G],parentKids:$})}}if(p)for(let c of N){let F=g.length;if(g.push({name:c.obj.name||`Light_${F}`,type:c.obj.type,color:[c.obj.color.r,c.obj.color.g,c.obj.color.b],intensity:c.obj.intensity,...c.range>0&&(c.obj.type==="point"||c.obj.type==="spot")?{range:c.range}:{},...c.obj.type==="spot"?{spot:{innerConeAngle:c.innerAngle,outerConeAngle:c.outerAngle}}:{},...c.shadowSpec?{extras:{shadow:c.shadowSpec}}:{}}),c.node.extensions={...c.node.extensions||{},KHR_lights_punctual:{light:F}},l.add("KHR_lights_punctual"),c.obj.type==="directional"||c.obj.type==="spot"){let C=c.dLen>1e-6?c.dx/c.dLen:0,U=c.dLen>1e-6?c.dy/c.dLen:-1,H=c.dLen>1e-6?c.dz/c.dLen:0;c.node.rotation=Pi(C,U,H),c.obj.type==="directional"&&(c.tx||c.ty||c.tz)&&(c.node.translation=[c.px-c.tx,c.py-c.ty,c.pz-c.tz])}}for(let c=0;c<o.length;c++){let F=o[c];F.children&&F.children.length===0?delete F.children:F.children&&F.children.length>0&&(F.extras?.xr?.lod||F.extensions?.ANDROID_xr_scenecore?.lod||y[c]?.isLOD)&&(F.extensions={...F.extensions||{},MSFT_lod:{ids:[...F.children]}},l.add("MSFT_lod"))}let S=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),A=[];if(typeof S=="function"&&y.length>0){let c=e?.duration??4,F=e?.fps??15,C=Math.max(2,Math.round(c*F)+1),U=new Float32Array(C),H=y.map(B=>[Z(B.position?.x,0),Z(B.position?.y,0),Z(B.position?.z,0),Z(B.quaternion?.x,0),Z(B.quaternion?.y,0),Z(B.quaternion?.z,0),Z(B.quaternion?.w,1),Z(B.scale?.x,1),Z(B.scale?.y,1),Z(B.scale?.z,1)]),j=y.map(()=>new Float32Array(C*3)),Y=y.map(()=>new Float32Array(C*4)),q=y.map(()=>new Float32Array(C*3));for(let B=0;B<C;B++){let X=B/(C-1)*c;U[B]=X;try{S(X)}catch{}for(let z=0;z<y.length;z++){let Q=y[z];j[z][B*3]=Z(Q.position?.x,0),j[z][B*3+1]=Z(Q.position?.y,0),j[z][B*3+2]=Z(Q.position?.z,0);let te=Z(Q.quaternion?.x,0),K=Z(Q.quaternion?.y,0),$=Z(Q.quaternion?.z,0),G=Z(Q.quaternion?.w,1),W=Math.hypot(te,K,$,G)||1;if(te/=W,K/=W,$/=W,G/=W,B>0){let J=(B-1)*4,ae=Y[z];ae[J]*te+ae[J+1]*K+ae[J+2]*$+ae[J+3]*G<0&&(te=-te,K=-K,$=-$,G=-G)}Y[z][B*4]=te,Y[z][B*4+1]=K,Y[z][B*4+2]=$,Y[z][B*4+3]=G,q[z][B*3]=Z(Q.scale?.x,1),q[z][B*3+1]=Z(Q.scale?.y,1),q[z][B*3+2]=Z(Q.scale?.z,1)}}for(let B=0;B<y.length;B++){let X=y[B],z=H[B];X.position?.set(z[0],z[1],z[2]),X.quaternion?.set(z[3],z[4],z[5],z[6]),X.scale?.set(z[7],z[8],z[9])}t.updateMatrixWorld(!0);let ne=null,ie=()=>(ne===null&&(ne=_(U,"SCALAR",0,5126,C,[0],[c])),ne),oe=[],he=[];for(let B=0;B<y.length;B++){let X=H[B],z=(te,K,$)=>te.some((G,W)=>Math.abs(G-X[$+W%K])>1e-4),Q=(te,K,$,G)=>{te&&he.push({sampler:oe.push({input:ie(),interpolation:"LINEAR",output:_(K,$,0,5126,C)})-1,target:{node:B,path:G}})};Q(z(j[B],3,0),j[B],"VEC3","translation"),Q(z(Y[B],4,3),Y[B],"VEC4","rotation"),Q(z(q[B],3,7),q[B],"VEC3","scale")}he.length>0&&A.push({name:"ProceduralLoop",samplers:oe,channels:he})}let D=is(o,a,t.userData),R=[],I=[],k=[];for(let c=0;c<o.length;c++){let F=o[c],C=Ri(F.extras?.xr);if(!C)continue;let{ae:U,src:H,preset:j,volume:Y,loop:q,isGlobal:ne}=C,ie=F.name||`Node_${c}`,oe=I.length;I.push({name:`${ie}_source`,gain:Y,loop:q,autoPlay:typeof U.autoplay=="boolean"?U.autoplay:!0,...H!==void 0?{audio:R.push({uri:H})-1}:{},...j?{extras:{preset:j,pitch:Ee(U.pitch,.25,4,1)}}:{}});let he=k.length,B=Ee(U.refDistance,.05,100,1),X=Ee(U.coneInnerAngle,0,360,360),z=Ee(U.coneOuterAngle,X,360,360);k.push({name:`${ie}_emitter`,type:ne?"global":"positional",gain:Y,sources:[oe],...ne?{}:{positional:{distanceModel:U.distanceModel==="linear"||U.distanceModel==="exponential"?U.distanceModel:"inverse",refDistance:B,maxDistance:Ee(U.maxDistance,B,500,Math.max(B,25)),rolloffFactor:Ee(U.rolloffFactor,0,10,1),coneInnerAngle:+(X*Math.PI/180).toFixed(6),coneOuterAngle:+(z*Math.PI/180).toFixed(6),coneOuterGain:Ee(U.coneOuterGain,0,1,0)}}}),F.extensions={...F.extensions||{},KHR_audio_emitter:{emitter:he}},l.add("KHR_audio_emitter")}let V={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity,...u.length>0?{lights:u}:{}}},scenes:[{nodes:P}],scene:0,nodes:o,meshes:a,materials:f,...h.length>0?{images:h}:{},...d.length>0?{samplers:d}:{},...v.length>0?{textures:v}:{},accessors:s,bufferViews:n,buffers:[{byteLength:r}],...A.length>0?{animations:A}:{},...D||l.size>0?{extensionsUsed:[...D?["KHR_interactivity"]:[],...l]}:{},...D||m.length>0||k.length>0||g.length>0?{extensions:{...D?{KHR_interactivity:D}:{},...m.length>0?{KHR_materials_variants:{variants:m.map(c=>({name:c}))}}:{},...k.length>0?{KHR_audio_emitter:{...R.length>0?{audio:R}:{},sources:I,emitters:k}}:{},...g.length>0?{KHR_lights_punctual:{lights:g}}:{}}}:{}},L=new Uint8Array(r),O=0;for(let c of i)L.set(c,O),O+=c.byteLength;return[{gltf:V,bin:L.buffer,lights:u,environmentIntensity:t.environmentIntensity},y]}function Vt(t){return new TextEncoder().encode(t)}function pt(t,e){let{gltf:i,bin:r}=Qe(t,e),n=JSON.stringify(i),s=Vt(n),a=(4-s.byteLength%4)%4,o=s.byteLength+a,l=20+o+8+r.byteLength,y=new Uint8Array(l),f=new DataView(y.buffer);f.setUint32(0,1179937895,!0),f.setUint32(4,2,!0),f.setUint32(8,l,!0),f.setUint32(12,o,!0),f.setUint32(16,1313821514,!0),y.set(s,20);for(let h=0;h<a;h++)y[20+s.byteLength+h]=32;let b=20+o;return f.setUint32(b,r.byteLength,!0),f.setUint32(b+4,5130562,!0),y.set(new Uint8Array(r),b+8),y}function _s(t,e){let[i,r]=Ei(t,e);return Li(i,r)}function Li(t,e){let i=[],r=t.gltf,n=ge().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(r,t);let s=t.bin,a=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=r.accessors||[],l=r.bufferViews||[],y=r.materials||[],f=r.meshes||[],b=r.nodes||[],h=r.textures||[],d=r.images||[],v=r.samplers||[],M=new Set,m=y.map((P,E)=>$t(M,et(P?.name,`Material_${E}`))),u=new Map;function g(P){let E=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!E)return null;let T=E[2].replace(/\s+/g,""),S=T.endsWith("==")?2:T.endsWith("=")?1:0,A=new Uint8Array((T.length*3>>2)-S),D=I=>{let k=T.charCodeAt(I);return k>96?k-71:k>64?k-65:k>47?k+4:k===43?62:k===47?63:0},R=0;for(let I=0;I<T.length;I+=4){let k=D(I)<<18|D(I+1)<<12|D(I+2)<<6|D(I+3);A[R++]=k>>16&255,R<A.length&&(A[R++]=k>>8&255),R<A.length&&(A[R++]=k&255)}return A}function p(P,E,T){let S=P?.index;if(typeof S!="number")return;let A=h[S],D=A?.source;if(typeof D!="number"||!d[D])return;let R=u.get(D);if(R===void 0){R=null;let V=d[D],L=null;if(typeof V.bufferView=="number"){let O=l[V.bufferView],c=O?.byteOffset||0,F=O?.byteLength||0;O&&F>0&&c>=0&&c+F<=a.byteLength&&(L=new Uint8Array(a,c,F))}else typeof V.uri=="string"&&(L=g(V.uri));if(L&&L.byteLength>0){let O=L[0]===255&&L[1]===216&&L[2]===255||!(L[0]===137&&L[1]===80)&&/jpe?g/i.test(V.mimeType||V.uri||"");R={file:`texture_${D}.${O?"jpg":"png"}`,data:L}}u.set(D,R)}if(!R)return;let I=typeof A.sampler=="number"?v[A.sampler]:void 0,k=V=>V===33071?"clamp":V===33648?"mirror":"repeat";return{file:R.file,data:R.data,wrapS:k(I?.wrapS),wrapT:k(I?.wrapT),...E?{scale:E}:{},...T?{bias:T}:{}}}function x(P){let E=o[P];if(!E)throw new Error(`Accessor ${P} not found`);let T=l[E.bufferView||0],S=(T.byteOffset||0)+(E.byteOffset||0),A=T.byteLength||0;return{acc:E,buffer:a.slice(S,S+A)}}function w(P,E,T,S){let A=[],D=f[P];if(!D)return A;let R=D.primitives||[];for(let I=0;I<R.length;I++){let k=R[I],V=k.attributes?.POSITION;if(V===void 0)continue;let{acc:L,buffer:O}=x(V),c=new Float32Array(O,0,L.count*3),F,C=k.attributes?.NORMAL;if(C!==void 0){let{acc:K,buffer:$}=x(C),G=new Float32Array($,0,K.count*3);F=new Float32Array(G.length);for(let W=0;W<K.count;W++){let J=G[W*3],ae=G[W*3+1],se=G[W*3+2],fe=Math.hypot(J,ae,se)||1;F[W*3]=J/fe,F[W*3+1]=ae/fe,F[W*3+2]=se/fe}}let U,H=k.attributes?.TEXCOORD_0;if(H!==void 0){let{acc:K,buffer:$}=x(H);U=new Float32Array($,0,K.count*2)}let j;if(k.indices!==void 0){let{acc:K,buffer:$}=x(k.indices);j=K.componentType===5125?new Uint32Array($,0,K.count):new Uint16Array($,0,K.count);let G=L.count;for(let W of j)if(W>=G)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${G}).`)}else{let K=L.count;j=K>65535?new Uint32Array(K):new Uint16Array(K);for(let $=0;$<K;$++)j[$]=$}let Y="DefaultMaterial",q=[1,1,1],ne=.5,ie=0,oe=0,he=0,B=1.5,X=1,z=[0,0,0],Q,te={};if(k.material!==void 0&&y[k.material]){let K=y[k.material];Y=m[k.material]||`Material_${k.material}`;let $=K.pbrMetallicRoughness||{},G=(de,De)=>Array.isArray(de)&&de.length>=3?[de[0],de[1],de[2]]:De;q=G($.baseColorFactor,[1,1,1]);let W=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,J=q[0]!==1||q[1]!==1||q[2]!==1||W!==1,ae=p($.baseColorTexture,J?[q[0],q[1],q[2],W]:void 0),se=K.extras?.avgColor;!ae&&Array.isArray(se)&&se.length>=3&&(q=[q[0]*se[0],q[1]*se[1],q[2]*se[2]]),typeof $.roughnessFactor=="number"&&(ne=$.roughnessFactor),typeof $.metallicFactor=="number"&&(ie=$.metallicFactor);let fe=typeof $.roughnessFactor=="number"?$.roughnessFactor:1,re=typeof $.metallicFactor=="number"?$.metallicFactor:1,Se=p($.metallicRoughnessTexture,fe!==1||re!==1?[1,fe,re,1]:void 0);z=G(K.emissiveFactor,[0,0,0]);let le=(z[0]>0||z[1]>0||z[2]>0)&&(z[0]!==1||z[1]!==1||z[2]!==1)?[z[0],z[1],z[2],1]:void 0,me=p(K.emissiveTexture,le),ue=typeof K.normalTexture?.scale=="number"?K.normalTexture.scale:1,ce=p(K.normalTexture,[2*ue,2*ue,2,1],[-ue,-ue,-1,0]),ye=typeof K.occlusionTexture?.strength=="number"?K.occlusionTexture.strength:1,Ce=ye!==1?p(K.occlusionTexture,[ye,ye,ye,1],[1-ye,1-ye,1-ye,0]):p(K.occlusionTexture);(ae||Se||ce||me||Ce)&&(Q=[ae,Se,ce,me,Ce]),te=K.extensions||{},te.KHR_materials_clearcoat&&(oe=te.KHR_materials_clearcoat.clearcoatFactor??0,he=te.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof te.KHR_materials_ior?.ior=="number"&&(B=te.KHR_materials_ior.ior),X=W*(1-(te.KHR_materials_transmission?.transmissionFactor??0))}A.push({name:R.length>1?`${E}_p${I}`:E,positions:c,indices:j,normals:F,uvs:U,materialName:Y,color:q,roughness:ne,metallic:ie,clearcoat:oe,clearcoatRoughness:he,ior:B,opacity:X,emissiveColor:z,...Q?{textures:Q}:{},...te.GOOGLE_material_tsl?{tslGraph:te.GOOGLE_material_tsl}:{},xrTraits:T||D.extras?.xr,...S?{invisible:!0}:{}})}return A}if(b.length>0){let P=new Float32Array(0),E=new Uint16Array(0),T=(c,F)=>{if(c===void 0)return null;let{acc:C,buffer:U}=x(c);return new Float32Array(U,0,C.count*F)},S=(c,F)=>Array.isArray(c)&&c.length>=3?[Z(c[0],F),Z(c[1],F),Z(c[2],F)]:[F,F,F],A=(c,F,C)=>c&&c.length>=(F+1)*3?[c[F*3],c[F*3+1],c[F*3+2]]:C,D=(c,F,C)=>c&&c.length>=(F+1)*4?[c[F*4],c[F*4+1],c[F*4+2],c[F*4+3]]:C,R=new Map,I=r.animations?.[0];if(I&&Array.isArray(I.channels)&&Array.isArray(I.samplers))for(let c of I.channels){let F=I.samplers[c?.sampler],C=c?.target?.node,U=c?.target?.path;if(!F||typeof C!="number"||F.input===void 0)continue;let H=R.get(C);H||(H={input:F.input},R.set(C,H)),U==="translation"?H.t=F.output:U==="rotation"?H.r=F.output:U==="scale"&&(H.s=F.output)}let k=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(k)||k.length===0){let c=new Set;for(let F of b)if(Array.isArray(F?.children))for(let C of F.children)c.add(C);k=[];for(let F=0;F<b.length;F++)c.has(F)||k.push(F);k.length===0&&(k=[0])}let V=new Set,L=[],O=(c,F)=>{if(Array.isArray(c))for(let C=c.length-1;C>=0;C--)L.push({idx:c[C],out:F})};for(O(k,i);L.length>0;){let{idx:c,out:F}=L.pop();if(typeof c!="number"||c<0||c>=b.length||V.has(c))continue;V.add(c);let C=b[c];if(!C)continue;let U=[0,0,0],H=[0,0,0,1],j=[1,1,1];if(Array.isArray(C.matrix)&&C.matrix.length===16){let X=Ci(C.matrix);U=X.t,H=X.r,j=X.s}else U=S(C.translation,0),Array.isArray(C.rotation)&&C.rotation.length>=4&&(H=[Z(C.rotation[0],0),Z(C.rotation[1],0),Z(C.rotation[2],0),Z(C.rotation[3],1)]),j=S(C.scale,1);let Y,q=R.get(c);if(q){let X=T(q.input,1);if(X&&X.length>0){let z=T(q.t,3),Q=T(q.r,4),te=T(q.s,3),K=Array.from(X),$=[],G=[],W=[];for(let J=0;J<X.length;J++)$.push(A(z,J,U)),G.push(D(Q,J,H)),W.push(A(te,J,j));Y={times:K,translations:$,rotations:G,scales:W}}}let ne=Array.isArray(C.children)?C.children:[],ie=typeof C.mesh=="number"&&C.mesh>=0&&C.mesh<f.length,oe=e?.[c]?.userData?.xr??C.extras?.xr;if(!ie&&ne.length===0&&(C.camera!==void 0||C.extensions?.KHR_lights_punctual||!C.name&&!C.extras&&!oe&&!Y))continue;let he=(X,z,Q)=>({name:X,positions:P,indices:E,isXform:!0,xrTraits:oe,timeSamples:Y,translation:U,rotation:H,scale:j,children:z,...Q?{invisible:!0}:{}}),B=C.visible===!1||C.extensions?.KHR_node_visibility?.visible===!1||e?.[c]?.visible===!1;if(ie){let X=C.name||f[C.mesh]?.name||`Mesh_${c}`,z=w(C.mesh,X,oe,B),Q=e?.[c],te=!!(Q?._castShdSet||Q?._recvShdSet),K=typeof C.extras?.shadow?.cast=="boolean"?C.extras.shadow.cast:te?!!Q?.castShadow:void 0;if(K!==void 0)for(let G of z)G.castShadow=K;let $=C.extensions?.EXT_mesh_gpu_instancing?.attributes;if($&&typeof $=="object"&&z.length>0){let G=T($.TRANSLATION,3),W=T($.ROTATION,4),J=T($.SCALE,3),ae=T($._COLOR_0,3),se=Math.min(1e3,G?G.length/3:W?W.length/4:J?J.length/3:0);if(se>0){let fe=[];for(let re=0;re<se;re++){let Se=A(G,re,[0,0,0]),le=D(W,re,[0,0,0,1]),me=A(J,re,[1,1,1]);for(let ue of z){let ce=ue.color||[.8,.8,.8],ye=ae&&ae.length>=(re+1)*3;fe.push({...ue,name:`${ue.name}_${re}`,materialName:ye?`${ue.materialName}_inst_${re}`:ue.materialName,color:ye?[ce[0]*ae[re*3],ce[1]*ae[re*3+1],ce[2]*ae[re*3+2]]:ue.color,translation:Se,rotation:le,scale:me})}}O(ne,fe),F.push(he(X,fe,B));continue}}if(z.length===1)z[0].translation=U,z[0].rotation=H,z[0].scale=j,z[0].timeSamples=Y,ne.length>0&&(z[0].children=[],O(ne,z[0].children)),F.push(z[0]);else{let G=[...z];O(ne,G),F.push(he(X,G,B))}}else{let X=[];O(ne,X),F.push(he(C.name||`Group_${c}`,X,B))}}}else for(let P=0;P<f.length;P++){let E=f[P].name||`Mesh_${P}`;i.push(...w(P,E,f[P].extras?.xr))}let _=(Array.isArray(t.lights)&&t.lights.length>0?t.lights:void 0)??vi(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),N=[];for(let P=0;P<_.length;P++){let E=_[P];E?.shadow?.cast&&(E.type==="directional"||E.type==="spot"||E.type==="point")&&N.push({name:`Light_${P}`,type:E.type,color:E.color,intensity:E.intensity,position:E.position,direction:E.direction,range:E.range,innerConeAngle:E.innerConeAngle,outerConeAngle:E.outerConeAngle,shadow:E.shadow})}return N.length>0&&(i.__usdaShadowLights=N),i}function et(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function dt(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function be(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var Le=(t,e,i)=>`(${be(t)}, ${be(e)}, ${be(i)})`,tt=(t,e,i,r)=>`(${be(t)}, ${be(e)}, ${be(i)}, ${be(r)})`;function Ni(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=Le(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ps(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${be(t[r*2])}, ${be(1-t[r*2+1])})`;return i.join(", ")}function Cs(t){return Array.from(t).join(", ")}function Rs(t,e){let i=(e??t.__usdaShadowLights??[]).filter(m=>m?.shadow?.cast),r=new Map,n=0,s=null,a=[...t];for(;a.length>0;){let m=a.pop();if(!m.isXform&&m.positions&&m.positions.length>0){let u=et(m.materialName,"DefaultMaterial");r.has(u)||r.set(u,{color:m.color||[1,1,1],roughness:m.roughness??.5,metallic:m.metallic??0,clearcoat:m.clearcoat??0,clearcoatRoughness:m.clearcoatRoughness??0,ior:m.ior??1.5,opacity:m.opacity??1,emissiveColor:m.emissiveColor||[0,0,0],textures:m.textures,tslGraph:m.tslGraph})}if(m.timeSamples&&m.timeSamples.times.length>0){let u=m.timeSamples.times[m.timeSamples.times.length-1];u>n&&(n=u)}else m.tslGraph&&n<=0&&JSON.stringify(m.tslGraph).includes('"time"')&&(n=60);if(m.xrTraits?.anchor&&!s&&(s=m.xrTraits.anchor==="vertical"||m.xrTraits.anchor==="wall"?"vertical":"horizontal"),m.children)for(let u=m.children.length-1;u>=0;u--)a.push(m.children[u])}let o="";n>0&&(o=`startTimeCode = 0
215
+ endTimeCode = ${be(n)}
251
216
  timeCodesPerSecond = 1.0
252
- `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
253
- uniform token preliminary:planeAnchoring:alignment = "${r}"
254
- `);let a=`#usda 1.0
217
+ `);let l="";s&&(l=`uniform token preliminary:anchoring:type = "plane"
218
+ uniform token preliminary:planeAnchoring:alignment = "${s}"
219
+ `);let y=`#usda 1.0
255
220
  (
256
221
  defaultPrim = "Root"
257
222
  metersPerUnit = 1.0
258
223
  upAxis = "Y"
259
- ${n})
224
+ ${o})
260
225
 
261
226
  def Xform "Root" (
262
227
  kind = "component"
263
228
  )
264
229
  {
265
- ${o}def Scope "Materials"
230
+ ${l}def Scope "Materials"
231
+ {
232
+ `;for(let[m,u]of r.entries()){let[g,p,x]=u.color,[w,_,N]=u.emissiveColor,P=`/Root/Materials/${m}`,[E,T,S,A,D]=u.textures||[],R=(F,C)=>`.connect = <${P}/${F}.outputs:${C}>`,I=E?`color3f inputs:diffuseColor${R("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Le(g,p,x)}`,k=T?`float inputs:metallic${R("MetallicRoughnessTexture","b")}
233
+ float inputs:roughness${R("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${be(u.metallic)}
234
+ float inputs:roughness = ${be(u.roughness)}`,V="";u.clearcoat>0&&(V+=`float inputs:clearcoat = ${be(u.clearcoat)}
235
+ `,V+=`float inputs:clearcoatRoughness = ${be(u.clearcoatRoughness)}
236
+ `),u.ior!==1.5&&(V+=`float inputs:ior = ${be(u.ior)}
237
+ `),u.opacity<1&&(V+=`float inputs:opacity = ${be(u.opacity)}
238
+ `),A?V+=`color3f inputs:emissiveColor${R("EmissiveTexture","rgb")}
239
+ `:(w>0||_>0||N>0)&&(V+=`color3f inputs:emissiveColor = ${Le(w,_,N)}
240
+ `),S&&(V+=`normal3f inputs:normal${R("NormalTexture","rgb")}
241
+ `),D&&(V+=`float inputs:occlusion${R("OcclusionTexture","r")}
242
+ `);let L="";if(E||T||S||A||D){L+=`def Shader "PrimvarReader"
266
243
  {
267
- `;for(let[u,b]of t.entries()){let[w,M,x]=b.color,[m,p,v]=b.emissiveColor,R="";b.clearcoat>0&&(R+=`float inputs:clearcoat = ${pt(b.clearcoat)}
268
- `,R+=`float inputs:clearcoatRoughness = ${pt(b.clearcoatRoughness)}
269
- `),b.ior!==1.5&&(R+=`float inputs:ior = ${pt(b.ior)}
270
- `),b.opacity<1&&(R+=`float inputs:opacity = ${pt(b.opacity)}
271
- `),(m>0||p>0||v>0)&&(R+=`color3f inputs:emissiveColor = ${St(m,p,v)}
272
- `),a+=`def Material "${u}"
244
+ uniform token info:id = "UsdPrimvarReader_float2"
245
+ string inputs:varname = "st"
246
+ float2 outputs:result
247
+ }
248
+ `;let F=(C,U,H,j)=>{if(!U)return;let Y=U.scale?`float4 inputs:scale = ${tt(U.scale[0],U.scale[1],U.scale[2],U.scale[3])}
249
+ `:"",q=U.bias?`float4 inputs:bias = ${tt(U.bias[0],U.bias[1],U.bias[2],U.bias[3])}
250
+ `:"";L+=`def Shader "${C}"
251
+ {
252
+ uniform token info:id = "UsdUVTexture"
253
+ asset inputs:file = @${dt(U.file)}@
254
+ float2 inputs:st${R("PrimvarReader","result")}
255
+ token inputs:sourceColorSpace = "${H}"
256
+ token inputs:wrapS = "${U.wrapS||"repeat"}"
257
+ token inputs:wrapT = "${U.wrapT||"repeat"}"
258
+ ${Y}${q}${j}}
259
+ `};F("DiffuseTexture",E,"sRGB",`float3 outputs:rgb
260
+ `),F("MetallicRoughnessTexture",T,"raw",`float outputs:g
261
+ float outputs:b
262
+ `),F("NormalTexture",S,"raw",`float3 outputs:rgb
263
+ `),F("EmissiveTexture",A,"sRGB",`float3 outputs:rgb
264
+ `),F("OcclusionTexture",D,"raw",`float outputs:r
265
+ `)}let O=`${I}
266
+ ${k}
267
+ ${V}`,c=u.tslGraph&&ge().tslUsdzSerializer?.(u.tslGraph,m,O);c&&(O=c.surfaceInputsUsda||O,L+=c.nodeGraphUsda),y+=`def Material "${m}"
273
268
  {
274
269
  def Shader "PBRShader"
275
270
  {
276
271
  uniform token info:id = "UsdPreviewSurface"
277
- color3f inputs:diffuseColor = ${St(w,M,x)}
278
- float inputs:metallic = ${pt(b.metallic)}
279
- float inputs:roughness = ${pt(b.roughness)}
280
- ${R}token outputs:surface
281
- }
282
- token outputs:surface.connect = </Root/Materials/${u}/PBRShader.outputs:surface>
272
+ ${O}token outputs:surface
283
273
  }
284
- `}a+=`}
274
+ token outputs:surface${R("PBRShader","surface")}
275
+ ${L}}
276
+ `}y+=`}
285
277
  def Scope "Meshes"
286
278
  {
287
- `;let h=(u,b,w)=>{let M=[];b&&M.push('"MaterialBindingAPI"');let x=!!(u?.rigidBody&&u.rigidBody!=="none"&&(typeof u.rigidBody!="object"||u.rigidBody.enabled!==!1)),m=!!(u?.physics&&u.physics!=="none"||x);m&&M.push(...x?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let p=[];if(M.length>0&&p.push(`prepend apiSchemas = [${M.join(", ")}]`),u){let N=ut().xrTraitSerializer?.usdLines(u,Re)??[];if(!N.length)for(let _ of["grab","billboard","follow","anchor","physics"]){let A=_==="follow"&&typeof u.follow=="object"?u.follow.mode??"head":u[_];A!==void 0&&N.push(`string ${_} = "${Re(A)}"`)}N.length>0&&p.push(`customData = {
279
+ `;let f=(m,u,g)=>{let p=[];u&&p.push('"MaterialBindingAPI"');let x=!!(m?.rigidBody&&m.rigidBody!=="none"&&(typeof m.rigidBody!="object"||m.rigidBody.enabled!==!1)),w=!!(m?.physics&&m.physics!=="none"||x);w&&p.push(...x?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let _=[];p.length>0&&_.push(`prepend apiSchemas = [${p.join(", ")}]`);let N=ge().xrTraitSerializer;if(m){let A=N?.usdLines(m,dt)??[];if(!A.length)for(let D of["grab","billboard","follow","anchor","physics"]){let R=D==="follow"&&typeof m.follow=="object"?m.follow.mode??"head":m[D];R!==void 0&&A.push(`string ${D} = "${dt(R)}"`)}A.length>0&&_.push(`customData = {
288
280
  dictionary xr = {
289
- ${N.join(`
281
+ ${A.join(`
290
282
  `)}
291
283
  }
292
- }`)}let v=p.length>0?` (
293
- ${p.join(`
284
+ }`)}let P=_.length>0?` (
285
+ ${_.join(`
294
286
  `)}
295
- )`:"",R=w?`uniform token visibility = "invisible"
296
- `:"";if(m){let N=u?.rigidBody??u?.physics,_=N?.body??N?.mode??N;R+=`bool physics:rigidBodyEnabled = true
297
- bool physics:kinematicEnabled = ${_==="static"||_==="kinematic"}
287
+ )`:"",E=g?`uniform token visibility = "invisible"
288
+ `:"";if(w){let A=m?.rigidBody??m?.physics,D=A?.body??A?.mode??A;E+=`bool physics:rigidBodyEnabled = true
289
+ bool physics:kinematicEnabled = ${D==="static"||D==="kinematic"}
298
290
  bool physics:collisionEnabled = true
299
- `,N?.mass>0&&Number.isFinite(N.mass)&&(R+=`float physics:mass = ${pt(N.mass)}
300
- `)}let L=mi(u),I=L?`def SpatialAudio "AudioEmitter"
291
+ `,A?.mass>0&&Number.isFinite(A.mass)&&(E+=`float physics:mass = ${be(A.mass)}
292
+ `)}let T=Ri(m),S=(T?`def SpatialAudio "AudioEmitter"
301
293
  {
302
- ${L.src?`asset inputs:file = @${Re(L.src)}@
303
- `:""}uniform token inputs:auralMode = "${L.isGlobal?"nonSpatial":"spatial"}"
304
- uniform token inputs:playbackMode = "${L.loop?"loopFromStart":"onceFromStart"}"
305
- double gain = ${pt(L.volume)}
294
+ ${T.src?`asset inputs:file = @${dt(T.src)}@
295
+ `:""}uniform token inputs:auralMode = "${T.isGlobal?"nonSpatial":"spatial"}"
296
+ uniform token inputs:playbackMode = "${T.loop?"loopFromStart":"onceFromStart"}"
297
+ double gain = ${be(T.volume)}
306
298
  }
307
- `:"";return{header:v,body:R,tail:I}},l=u=>{if(u.timeSamples&&u.timeSamples.times.length>0){let p=u.timeSamples,v=(N,_,A)=>p.times.map((E,C)=>`${pt(E)}: ${A(N?.[C]||_)}`).join(", "),R=v(p.translations,[0,0,0],N=>St(N[0],N[1],N[2])),L=v(p.rotations,[0,0,0,1],N=>{let _=Math.hypot(N[0],N[1],N[2],N[3])||1;return pi(N[3]/_,N[0]/_,N[1]/_,N[2]/_)}),I=v(p.scales,[1,1,1],N=>St(N[0],N[1],N[2]));return`double3 xformOp:translate.timeSamples = { ${R} }
308
- quatf xformOp:orient.timeSamples = { ${L} }
309
- double3 xformOp:scale.timeSamples = { ${I} }
299
+ `:"")+(m?N?.usdPrims?.(m)??"":"");return{header:P,body:E,tail:S}},b=m=>{if(m.timeSamples&&m.timeSamples.times.length>0){let _=m.timeSamples,N=(S,A,D)=>_.times.map((R,I)=>`${be(R)}: ${D(S?.[I]||A)}`).join(", "),P=N(_.translations,[0,0,0],S=>Le(S[0],S[1],S[2])),E=N(_.rotations,[0,0,0,1],S=>{let A=Math.hypot(S[0],S[1],S[2],S[3])||1;return tt(S[3]/A,S[0]/A,S[1]/A,S[2]/A)}),T=N(_.scales,[1,1,1],S=>Le(S[0],S[1],S[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
300
+ quatf xformOp:orient.timeSamples = { ${E} }
301
+ double3 xformOp:scale.timeSamples = { ${T} }
310
302
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
311
- `}let b=[],w="",M=u.translation;M&&(Math.abs(M[0])>1e-7||Math.abs(M[1])>1e-7||Math.abs(M[2])>1e-7)&&(w+=`double3 xformOp:translate = ${St(M[0],M[1],M[2])}
312
- `,b.push('"xformOp:translate"'));let x=u.rotation;if(x){let p=Math.hypot(x[0],x[1],x[2],x[3])||1,v=x[0]/p,R=x[1]/p,L=x[2]/p,I=x[3]/p;(1-Math.abs(I)>1e-7||Math.hypot(v,R,L)>1e-7)&&(w+=`quatf xformOp:orient = ${pi(I,v,R,L)}
313
- `,b.push('"xformOp:orient"'))}let m=u.scale;return m&&(Math.abs(m[0]-1)>1e-7||Math.abs(m[1]-1)>1e-7||Math.abs(m[2]-1)>1e-7)&&(w+=`float3 xformOp:scale = ${St(m[0],m[1],m[2])}
314
- `,b.push('"xformOp:scale"')),b.length>0&&(w+=`uniform token[] xformOpOrder = [${b.join(", ")}]
315
- `),w},c=u=>{let b=u.positions.length/3,w=1/0,M=1/0,x=1/0,m=-1/0,p=-1/0,v=-1/0;for(let _=0;_<b;_++){let A=u.positions[_*3],E=u.positions[_*3+1],C=u.positions[_*3+2];A<w&&(w=A),A>m&&(m=A),E<M&&(M=E),E>p&&(p=E),C<x&&(x=C),C>v&&(v=C)}isFinite(w)||(w=M=x=-1,m=p=v=1);let R=Math.floor(u.indices.length/3),L=re(u.materialName,"DefaultMaterial"),I=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",N=`float3[] extent = [${St(w,M,x)}, ${St(m,p,v)}]
316
- int[] faceVertexCounts = [${I}]
317
- int[] faceVertexIndices = [${hs(u.indices)}]
318
- point3f[] points = [${di(u.positions)}]
319
- `;return u.normals&&u.normals.length===u.positions.length&&(N+=`normal3f[] normals = [${di(u.normals)}] (
303
+ `}let u=[],g="",p=m.translation;p&&(Math.abs(p[0])>1e-7||Math.abs(p[1])>1e-7||Math.abs(p[2])>1e-7)&&(g+=`double3 xformOp:translate = ${Le(p[0],p[1],p[2])}
304
+ `,u.push('"xformOp:translate"'));let x=m.rotation;if(x){let _=Math.hypot(x[0],x[1],x[2],x[3])||1,N=x[0]/_,P=x[1]/_,E=x[2]/_,T=x[3]/_;(1-Math.abs(T)>1e-7||Math.hypot(N,P,E)>1e-7)&&(g+=`quatf xformOp:orient = ${tt(T,N,P,E)}
305
+ `,u.push('"xformOp:orient"'))}let w=m.scale;return w&&(Math.abs(w[0]-1)>1e-7||Math.abs(w[1]-1)>1e-7||Math.abs(w[2]-1)>1e-7)&&(g+=`float3 xformOp:scale = ${Le(w[0],w[1],w[2])}
306
+ `,u.push('"xformOp:scale"')),u.length>0&&(g+=`uniform token[] xformOpOrder = [${u.join(", ")}]
307
+ `),g},h=m=>{let u=m.positions.length/3,g=1/0,p=1/0,x=1/0,w=-1/0,_=-1/0,N=-1/0;for(let A=0;A<u;A++){let D=m.positions[A*3],R=m.positions[A*3+1],I=m.positions[A*3+2];D<g&&(g=D),D>w&&(w=D),R<p&&(p=R),R>_&&(_=R),I<x&&(x=I),I>N&&(N=I)}isFinite(g)||(g=p=x=-1,w=_=N=1);let P=Math.floor(m.indices.length/3),E=et(m.materialName,"DefaultMaterial"),T=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",S=`float3[] extent = [${Le(g,p,x)}, ${Le(w,_,N)}]
308
+ int[] faceVertexCounts = [${T}]
309
+ int[] faceVertexIndices = [${Cs(m.indices)}]
310
+ point3f[] points = [${Ni(m.positions)}]
311
+ `;return m.normals&&m.normals.length===m.positions.length&&(S+=`normal3f[] normals = [${Ni(m.normals)}] (
320
312
  interpolation = "vertex"
321
313
  )
322
- `),u.uvs&&u.uvs.length===b*2&&(N+=`texCoord2f[] primvars:st = [${ls(u.uvs,b)}] (
314
+ `),m.uvs&&m.uvs.length===u*2&&(S+=`texCoord2f[] primvars:st = [${Ps(m.uvs,u)}] (
323
315
  interpolation = "vertex"
324
316
  )
325
- `),N+=`rel material:binding = </Root/Materials/${L}>
326
- `,N},f=new Set,y=[];for(let u=e.length-1;u>=0;u--)y.push({node:e[u],siblings:f});let g=0;for(;y.length>0;){let u=y.pop();if(u.close){a+=`}
327
- `;continue}let{node:b,siblings:w}=u,M=!!(b.isXform||b.positions.length===0),x=ui(w,re(b.name,M?`Group_${g}`:`Mesh_${g}`));g++;let m=b.children||[];if(M){let p=h(b.xrTraits,!1,b.invisible);a+=`def Xform "${x}"${p.header}
317
+ `),S+=`rel material:binding = </Root/Materials/${E}>
318
+ `,m.castShadow===!1&&i.length>0&&(S+=`bool primvars:doNotCastShadows = 1
319
+ `),S},d=new Set,v=[];for(let m=t.length-1;m>=0;m--)v.push({node:t[m],siblings:d});let M=0;for(;v.length>0;){let m=v.pop();if(m.close){y+=`}
320
+ `;continue}let{node:u,siblings:g}=m,p=!!(u.isXform||u.positions.length===0),x=$t(g,et(u.name,p?`Group_${M}`:`Mesh_${M}`));M++;let w=u.children||[];if(p){let _=f(u.xrTraits,!1,u.invisible);y+=`def Xform "${x}"${_.header}
328
321
  {
329
- ${p.body}${l(b)}${p.tail}`,y.push({close:!0});let v=new Set;for(let R=m.length-1;R>=0;R--)y.push({node:m[R],siblings:v})}else if(m.length>0){let p=h(b.xrTraits,!1,b.invisible),v=`${x}_mesh`;a+=`def Xform "${x}"${p.header}
322
+ ${_.body}${b(u)}${_.tail}`,v.push({close:!0});let N=new Set;for(let P=w.length-1;P>=0;P--)v.push({node:w[P],siblings:N})}else if(w.length>0){let _=f(u.xrTraits,!1,u.invisible),N=`${x}_mesh`;y+=`def Xform "${x}"${_.header}
330
323
  {
331
- ${p.body}${l(b)}${p.tail}`,a+=`def Mesh "${v}" (
324
+ ${_.body}${b(u)}${_.tail}`,y+=`def Mesh "${N}" (
332
325
  prepend apiSchemas = ["MaterialBindingAPI"]
333
326
  )
334
327
  {
335
- ${c(b)}}
336
- `,y.push({close:!0});let R=new Set([v]);for(let L=m.length-1;L>=0;L--)y.push({node:m[L],siblings:R})}else{let p=h(b.xrTraits,!0,b.invisible);a+=`def Mesh "${x}"${p.header}
328
+ ${h(u)}}
329
+ `,v.push({close:!0});let P=new Set([N]);for(let E=w.length-1;E>=0;E--)v.push({node:w[E],siblings:P})}else{let _=f(u.xrTraits,!0,u.invisible);y+=`def Mesh "${x}"${_.header}
337
330
  {
338
- ${p.body}${l(b)}${c(b)}${p.tail}}
339
- `}}return a+=`}
340
- }
341
- `,a}function us(e,t){if(e&&typeof e.traverse=="function"){let s=os(e,t);return Ce(s)}let i=te(e),r=Se(i);return Ce(r)}var se=null;function Ae(e){if(!se){se=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;se[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=se[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function cs(e){let t=[],i=0,r=[];for(let c of e){let f=Te(c.filename),y=Ae(c.data),g=c.data.length,u=30+f.length,b=(i+u)%64,w=b!==0?64-b:0,M=new Uint8Array(u+w),x=new DataView(M.buffer);x.setUint32(0,67324752,!0),x.setUint16(4,20,!0),x.setUint32(14,y,!0),x.setUint32(18,g,!0),x.setUint32(22,g,!0),x.setUint16(26,f.length,!0),x.setUint16(28,w,!0),M.set(f,30),t.push({offset:i,size:g,crc:y,filenameBytes:f,entry:c}),r.push(M,c.data),i+=M.length+c.data.length}let s=i;for(let c of t){let f=new Uint8Array(46+c.filenameBytes.length),y=new DataView(f.buffer);y.setUint32(0,33639248,!0),y.setUint16(4,20,!0),y.setUint16(6,20,!0),y.setUint32(16,c.crc,!0),y.setUint32(20,c.size,!0),y.setUint32(24,c.size,!0),y.setUint16(28,c.filenameBytes.length,!0),y.setUint32(42,c.offset,!0),f.set(c.filenameBytes,46),r.push(f),i+=f.length}let n=i-s,o=new Uint8Array(22),a=new DataView(o.buffer);a.setUint32(0,101010256,!0),a.setUint16(8,t.length,!0),a.setUint16(10,t.length,!0),a.setUint32(12,n,!0),a.setUint32(16,s,!0),r.push(o),i+=22;let h=new Uint8Array(i),l=0;for(let c of r)h.set(c,l),l+=c.length;return h}var gi=e=>cs([{filename:"model.usda",data:Te(e)}]);function ne(e){return gi(us(e))}function Pe(e){return gi(Ce(Se(te(e))))}function yi(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Pe(e)}var Tt=class _r{constructor(t=0,i=0){this.x=Number(t),this.y=Number(i)}set(t,i){return this.x=Number(t),this.y=Number(i),this}clone(){return new _r(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},Y=class Er{constructor(t=0,i=0,r=0){this.x=Number(t),this.y=Number(i),this.z=Number(r)}set(t,i,r){return this.x=Number(t),this.y=Number(i),this.z=Number(r),this}clone(){return new Er(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addVectors(t,i){return this.x=t.x+i.x,this.y=t.y+i.y,this.z=t.z+i.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,i){return this.x=t.x-i.x,this.y=t.y-i.y,this.z=t.z-i.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,i){return this.x+=t.x*i,this.y+=t.y*i,this.z+=t.z*i,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5&&(this.x/=t,this.y/=t,this.z/=t),this}cross(t){let i=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,s=this.x*t.y-this.y*t.x;return this.x=i,this.y=r,this.z=s,this}crossVectors(t,i){let r=t.x,s=t.y,n=t.z,o=i.x,a=i.y,h=i.z;return this.x=s*h-n*a,this.y=n*o-r*h,this.z=r*a-s*o,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,i){return this.lerpVectors(this,t,i)}lerpVectors(t,i,r){return this.x=t.x+(i.x-t.x)*r,this.y=t.y+(i.y-t.y)*r,this.z=t.z+(i.z-t.z)*r,this}applyMatrix4(t){let i=this.x,r=this.y,s=this.z,n=t.elements,o=1/(n[3]*i+n[7]*r+n[11]*s+n[15]);return this.x=(n[0]*i+n[4]*r+n[8]*s+n[12])*o,this.y=(n[1]*i+n[5]*r+n[9]*s+n[13])*o,this.z=(n[2]*i+n[6]*r+n[10]*s+n[14])*o,this}},bi=class{constructor(e=0,t=0,i=0,r=1){this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r)}set(e,t,i,r){return this.x=Number(e),this.y=Number(t),this.z=Number(i),this.w=Number(r),this}},_e=class Nr{constructor(t=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,i,r,s=this.order){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this.order=t.order,this._onChangeCallback?.(),this}clone(){return new Nr(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ee=class Dr{constructor(t=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,i,r,s){return this._x=Number(t),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback?.(),this}clone(){return new Dr(this._x,this._y,this._z,this._w)}setFromEuler(t,i=!0){let r=t.x,s=t.y,n=t.z,o=Math.cos(r/2),a=Math.cos(s/2),h=Math.cos(n/2),l=Math.sin(r/2),c=Math.sin(s/2),f=Math.sin(n/2);return this._x=l*a*h+o*c*f,this._y=o*c*h-l*a*f,this._z=o*a*f+l*c*h,this._w=o*a*h-l*c*f,i&&this._onChangeCallback?.(),this}setFromAxisAngle(t,i){let r=i/2,s=Math.sin(r);return this.set(t.x*s,t.y*s,t.z*s,Math.cos(r))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,i){let r=t.dot(i)+1;return r<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*i.z-t.z*i.y,t.z*i.x-t.x*i.z,t.x*i.y-t.y*i.x,r).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,i){let r=t.x,s=t.y,n=t.z,o=t.w,a=i.x,h=i.y,l=i.z,c=i.w;return this._x=r*c+o*a+s*l-n*h,this._y=s*c+o*h+n*a-r*l,this._z=n*c+o*l+r*h-s*a,this._w=o*c-r*a-s*h-n*l,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Ot=class Lr{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new Lr;return t.copy(this),t}compose(t,i,r){return ye(this.elements,[i.x,i.y,i.z,i.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,i){return dt(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return Qt(this.elements,[t.x,t.y,t.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let i=new Y(0,0,0),r=new Y(1,1,1);return this.compose(i,t,r)}makeTranslation(t,i,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(t,i,r){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},xi=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return Pt(this.elements,e.elements),this}},xt=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,ae=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,vi={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Rt=class Ir{constructor(t,i,r){this.r=1,this.g=1,this.b=1,t!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(t,i,r):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let i=t.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in vi)this.setHex(vi[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=n=>xt(Math.max(0,Math.min(1,(parseFloat(n)||0)/(n.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(t,i,r){if(t=((Number(t)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let a=xt(r);return this.setRGB(a,a,a)}let s=r<=.5?r*(1+i):r+i-r*i,n=2*r-s,o=a=>(a<0&&(a+=1),a>1&&(a-=1),a<1/6?n+(s-n)*6*a:a<1/2?s:a<2/3?n+(s-n)*6*(2/3-a):n);return this.setRGB(xt(o(t+1/3)),xt(o(t)),xt(o(t-1/3)))}lerp(t,i){let r=Number(i)||0;return this.r+=(t.r-this.r)*r,this.g+=(t.g-this.g)*r,this.b+=(t.b-this.b)*r,this}lerpColors(t,i,r){let s=Number(r)||0;return this.r=t.r+(i.r-t.r)*s,this.g=t.g+(i.g-t.g)*s,this.b=t.b+(i.b-t.b)*s,this}multiplyScalar(t){let i=Number(t)||0;return this.r*=i,this.g*=i,this.b*=i,this}setScalar(t){let i=Number(t)||0;return this.setRGB(i,i,i)}setHex(t){let i=Math.floor(t);return this.r=xt((i>>16&255)/255),this.g=xt((i>>8&255)/255),this.b=xt((i&255)/255),this}setRGB(t,i,r){return this.r=Number(t),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.r=xt(this.r),this.g=xt(this.g),this.b=xt(this.b),this}convertLinearToSRGB(){return this.r=ae(this.r),this.g=ae(this.g),this.b=ae(this.b),this}getHex(){let t=i=>Math.round(ae(Math.max(0,Math.min(1,i)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new Ir(this.r,this.g,this.b)}},Mi={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,i)=>Math.max(t,Math.min(i,e)),lerp:(e,t,i)=>e+(t-e)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},gt=class Fr{constructor(t,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,i){return this.array[t*this.itemSize]=i,this.needsUpdate=!0,this}setY(t,i){return this.array[t*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(t,i){return this.array[t*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(t,i,r,s){let n=t*this.itemSize;return this.array[n]=i,this.array[n+1]=r,this.array[n+2]=s,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new Fr(new t(this.array),this.itemSize)}},wi=class extends gt{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},Ti=class extends gt{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Si=class extends gt{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},ft=class kr{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,i){return this.attributes[t]=i,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof gt)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new gt(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new gt(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let i=t.count,r=new Float32Array(i*3),s=new Y,n=new Y,o=new Y,a=new Y,h=new Y,l=this.index?.array,c=l?l.length:i;for(let f=0;f<c;f+=3){let y=l?l[f]:f,g=l?l[f+1]:f+1,u=l?l[f+2]:f+2;s.set(t.getX(y),t.getY(y),t.getZ(y)),n.set(t.getX(g),t.getY(g),t.getZ(g)),o.set(t.getX(u),t.getY(u),t.getZ(u)),a.subVectors(o,n),h.subVectors(s,n),a.cross(h).normalize();for(let b of[y,g,u])r[b*3]+=a.x,r[b*3+1]+=a.y,r[b*3+2]+=a.z}for(let f=0;f<i;f++){let y=r[f*3],g=r[f*3+1],u=r[f*3+2],b=Math.hypot(y,g,u)||1;r[f*3]=y/b,r[f*3+1]=g/b,r[f*3+2]=u/b}return this.setAttribute("normal",new gt(r,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new gt(t,3)),this.setAttribute("normal",new gt(i,3)),this.setAttribute("uv",new gt(r,2)),this.setIndex(s)}setFromPoints(t){let i=[];if(Array.isArray(t))for(let r of t)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new gt(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new Y(1/0,1/0,1/0),r=new Y(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let s=0;s<t.count;s++){let n=t.getX(s),o=t.getY(s),a=t.getZ(s);n<i.x&&(i.x=n),o<i.y&&(i.y=o),a<i.z&&(i.z=a),n>r.x&&(r.x=n),o>r.y&&(r.y=o),a>r.z&&(r.z=a)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,i){let r=this.attributes.position;if(r){let s=r.array;for(let n=0;n<s.length;n+=3)t(s,n);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,i=0,r=0){return this._xform((s,n)=>{s[n]+=t,s[n+1]+=i,s[n+2]+=r})}scale(t=1,i=1,r=1){return this._xform((s,n)=>{s[n]*=t,s[n+1]*=i,s[n+2]*=r},!0)}_rot(t,i,r){let s=Math.cos(r),n=Math.sin(r);for(let o of[this.attributes.position,this.attributes.normal]){if(!o)continue;let a=o.array;for(let h=0;h<a.length;h+=3){let l=a[h+t],c=a[h+i];a[h+t]=l*s-c*n,a[h+i]=l*n+c*s}o.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let i=this.attributes.position;if(i&&t?.elements){let r=new Y;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(t),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let t=new kr;t.name=this.name;for(let i of Object.keys(this.attributes))t.attributes[i]=this.attributes[i].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},Ne=class extends ft{constructor(e=1,t=1,i=1){super();let r=e/2,s=t/2,n=i/2,o=[-r,-s,n,r,-s,n,r,s,n,-r,s,n,r,-s,-n,-r,-s,-n,-r,s,-n,r,s,-n,-r,s,n,r,s,n,r,s,-n,-r,s,-n,-r,-s,-n,r,-s,-n,r,-s,n,-r,-s,n,r,-s,n,r,-s,-n,r,s,-n,r,s,n,-r,-s,-n,-r,-s,n,-r,s,n,-r,s,-n],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],h=[],l=[];for(let c=0;c<6;c++){let f=c*4;h.push(0,0,1,0,1,1,0,1),l.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(o,a,h,l)}},Ri=class extends ft{constructor(e=1,t=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let s=[],n=[],o=[],a=[];for(let h=0;h<=r;h++){let l=h/r;for(let c=0;c<=i;c++){let f=c/i;if(s.push((f-.5)*e,(.5-l)*t,0),n.push(0,0,1),o.push(f,1-l),h>0&&c>0){let y=(i+1)*h+c-1,g=y-(i+1);a.push(g,y,g+1,y,y+1,g+1)}}}this.setFromBuffers(s,n,o,a)}},Ci=class extends ft{constructor(e=1,t=16,i=12){super(),t=Math.max(3,Math.floor(t)),i=Math.max(2,Math.floor(i));let r=[],s=[],n=[],o=[];for(let a=0;a<=i;a++){let h=a/i;for(let l=0;l<=t;l++){let c=l/t,f=c*Math.PI*2,y=h*Math.PI,g=-Math.cos(f)*Math.sin(y),u=Math.cos(y),b=Math.sin(f)*Math.sin(y);if(r.push(e*g,e*u,e*b),s.push(g,u,b),n.push(c,1-h),a>0&&l>0){let w=(t+1)*a+l,M=w-(t+1),x=M-1,m=w-1;a!==1&&o.push(M,x,w),a!==i&&o.push(x,m,w)}}}this.setFromBuffers(r,s,n,o)}},De=class extends ft{constructor(e=1,t=1,i=1,r=16){super(),r=Math.max(3,Math.floor(r));let s=[],n=[],o=[],a=[],h=i/2;for(let c=0;c<=1;c++){let f=c,y=c===0?e:t,g=c===0?h:-h;for(let u=0;u<=r;u++){let b=u/r,w=b*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(y*M,g,y*x),n.push(M,0,x),o.push(b,1-f)}}for(let c=0;c<r;c++){let f=c,y=c+r+1,g=c+r+2,u=c+1;a.push(f,y,u,y,g,u)}let l=(c,f)=>{if(c<=0)return;let y=f*h,g=s.length/3;s.push(0,y,0),n.push(0,f,0),o.push(.5,.5);let u=s.length/3;for(let b=0;b<=r;b++){let w=b/r*Math.PI*2,M=Math.sin(w),x=Math.cos(w);s.push(c*M,y,c*x),n.push(0,f,0),o.push(x*.5+.5,.5+f*M*.5)}for(let b=0;b<r;b++)a.push(g,u+b+(f>0?0:1),u+b+(f>0?1:0))};l(e,1),l(t,-1),this.setFromBuffers(s,n,o,a)}},Ai=class extends De{constructor(e=1,t=1,i=16){super(0,e,t,i)}},Pi=class extends ft{constructor(e=1,t=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let n=[],o=[],a=[],h=[];for(let l=0;l<=i;l++){let c=l/i*Math.PI*2,f=Math.cos(c),y=Math.sin(c);for(let g=0;g<=r;g++){let u=g/r*s,b=Math.cos(u),w=Math.sin(u);if(n.push((e+t*f)*b,(e+t*f)*w,t*y),o.push(f*b,f*w,y),a.push(g/r,l/i),l>0&&g>0){let M=(r+1)*l+g-1,x=M-(r+1);h.push(M,x,M+1,x,x+1,M+1)}}}this.setFromBuffers(n,o,a,h)}};function _i(e,t,i,r,s){let n=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),o=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),a=Number(r)||.1,h=[],l=[],c=[],f=[],y=new Y,g=new Y,u=new Y,b=new Y,w=new Y;for(let x=0;x<=n;x++){let m=x/n;s(Math.max(0,m-.001),y),s(Math.min(1,m+.001),g),u.subVectors(g,y).normalize(),x===0&&b.set(Math.abs(u.y)>.9?1:0,Math.abs(u.y)>.9?0:1,0),w.crossVectors(u,b).normalize(),b.crossVectors(w,u).normalize(),s(m,y);for(let p=0;p<=o;p++){let v=p/o*Math.PI*2,R=-a*Math.cos(v),L=a*Math.sin(v),I=R*b.x+L*w.x,N=R*b.y+L*w.y,_=R*b.z+L*w.z;h.push(y.x+I,y.y+N,y.z+_);let A=Math.hypot(I,N,_)||1;l.push(I/A,N/A,_/A),c.push(m,p/o)}}let M=o+1;for(let x=1;x<=n;x++){let m=M*(x-1),p=m+M;for(let v=1;v<=o;v++){let R=m+v-1,L=p+v-1;f.push(R,L,m+v,L,p+v,m+v)}}e.setFromBuffers(h,l,c,f)}var Ei=class extends ft{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),_i(this,i,r,t,(o,a)=>{let h=o*s*Math.PI*2,l=n/s*h,c=e*(2+Math.cos(l))*.5;a.set(c*Math.cos(h),c*Math.sin(h),e*Math.sin(l)*.5)})}},Ft=class{getPoint(e,t=new Y){return t}getPointAt(e,t=new Y){return this.getPoint(e,t)}getTangent(e,t=new Y){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),i=[];for(let r=0;r<=t;r++)i.push(this.getPoint(r/t));return i}getSpacedPoints(e=5){return this.getPoints(e)}},Ni=class extends Ft{constructor(e=new Y,t=new Y){super(),this.v1=e,this.v2=t}getPoint(e,t=new Y){return t.lerpVectors(this.v1,this.v2,e)}},Di=class extends Ft{constructor(e=new Y,t=new Y,i=new Y){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Y){return t.lerpVectors(this.v0,this.v1,e).lerp(new Y().lerpVectors(this.v1,this.v2,e),e)}},Li=class extends Ft{constructor(e=new Y,t=new Y,i=new Y,r=new Y){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new Y){let i=new Y().lerpVectors(this.v0,this.v1,e),r=new Y().lerpVectors(this.v1,this.v2,e),s=new Y().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},Ii=class extends Ft{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new Y){let i=this.points,r=i.length;if(!r)return t.set(0,0,0);if(r===1)return t.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(e)||0)),n=Math.floor(s),o=s-n;!this.closed&&n>=r-1&&(n=r-2,o=1);let a=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],h=a(n-1),l=a(n),c=a(n+1),f=a(n+2),y=o*o,g=y*o,u=(b,w,M,x)=>.5*(2*w+(M-b)*o+(2*b-5*w+4*M-x)*y+(3*w-b-3*M+x)*g);return t.set(u(h.x,l.x,c.x,f.x),u(h.y,l.y,c.y,f.y),u(h.z,l.z,c.z,f.z))}},Le=class extends ft{constructor(e=[new Tt(0,-.5),new Tt(.5,0),new Tt(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Tt(.2,0),new Tt(.2,.5)],n=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),o=[],a=[],h=[],l=[],c=s.length;for(let f=0;f<=n;f++){let y=f/n,g=i+y*r,u=Math.sin(g),b=Math.cos(g);for(let w=0;w<c;w++){let M=s[w],x=Number(M?.x)||0,m=Number(M?.y)||0;o.push(x*u,m,x*b);let p=s[Math.max(0,w-1)],v=s[Math.min(c-1,w+1)],R=(Number(v?.x)||0)-(Number(p?.x)||0),L=(Number(v?.y)||0)-(Number(p?.y)||0),I=Math.hypot(L,R)||1;a.push(L/I*u,-R/I,L/I*b),h.push(y,w/(c-1))}}for(let f=0;f<n;f++){let y=f*c;for(let g=0;g<c-1;g++){let u=y+g,b=y+c+g;l.push(u,b,u+1,b,b+1,u+1)}}this.setFromBuffers(o,a,h,l)}},Fi=class extends ft{constructor(e,t=64,i=1,r=8,s=!1){super(),_i(this,t,r,i,(n,o)=>{let a=e?.getPointAt??e?.getPoint;if(typeof a=="function"){let h=a.call(e,n,o);h&&h!==o&&o.copy(h)}else o.set(0,n,0)})}},oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",le=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Tt(1,1),this.offset=new Tt(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},ki=class extends le{constructor(e=null,t=1,i=1,r=1023,s=1009,n,o=1001,a=1001,h=1003,l=1003,c=1,f=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1;let y=Number(t),g=Number(i),u=e&&typeof e.length=="number"?e:null;this.width=y,this.height=g,this.image={data:u,width:y,height:g},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(o)||1001,this.wrapT=Number(a)||1001,this.magFilter=Number(h)||1003,this.minFilter=Number(l)||1003,this.colorSpace=f||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,i=Number(e?.width??this.width),r=Number(e?.height??this.height);if(!t||!t.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),n=Math.max(1,r|0),o=s*n,a=this.format,h=a===1021||a===1024||a===1028||t.length===o?1:a===1025||a===1030||t.length===o*2?2:a===1022||t.length===o*3?3:4,l=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,c=Math.min(s,96),f=Math.min(n,96),y=f*(1+c*4),g=new Uint8Array(68+y),u=new DataView(g.buffer);u.setUint32(0,2303741511),u.setUint32(4,218765834),u.setUint32(8,13),u.setUint32(12,1229472850),u.setUint32(16,c),u.setUint32(20,f),g[24]=8,g[25]=6,u.setUint32(29,Ae(g.subarray(12,29))),u.setUint32(33,y+11),u.setUint32(37,1229209940),g[41]=120,g[42]=1,g[43]=1,u.setUint16(44,y,!0),u.setUint16(46,~y&65535,!0);let b=48,w=1,M=0,x=0,m=0,p=0,v=0,R=_=>{if(!Number.isFinite(_))return 0;let A=l&&_<=1?_*255:_;return A>0?A<255?A+.5|0:255:0};for(let _=0;_<f;_++){let A=_*n/f|0,E=this.flipY?n-1-A:A;g[b++]=0,M+=w;for(let C=0;C<c;C++){let d=(E*s+(C*s/c|0))*h,k=a===1021?255:R(t[d]??0),$=h>=3||a===1030?R(t[d+1]??0):k,S=h>=3?R(t[d+2]??0):a===1030?0:k,D=h===4?R(t[d+3]??255):a===1021?R(t[d]??255):a===1025?R(t[d+1]??255):255;g[b++]=k,w+=k,M+=w,g[b++]=$,w+=$,M+=w,g[b++]=S,w+=S,M+=w,g[b++]=D,w+=D,M+=w,x+=k,m+=$,p+=S,v+=D}w%=65521,M%=65521}u.setUint32(b,(M<<16|w)>>>0),u.setUint32(b+4,Ae(g.subarray(37,b+4))),u.setUint32(b+12,1229278788),u.setUint32(b+16,2923585666);let L=c*f*255,I=this.colorSpace==="srgb-linear";this.avgColor=[I?x/L:xt(x/L),I?m/L:xt(m/L),I?p/L:xt(p/L),v/L];let N=["data:image/png;base64,"];for(let _=0;_<g.length;_+=3){let A=g[_]<<16|(g[_+1]??0)<<8|(g[_+2]??0);N.push(oe[A>>18&63]+oe[A>>12&63]+(_+1<g.length?oe[A>>6&63]:"=")+(_+2<g.length?oe[A&63]:"="))}this.source=N.join("")}},Ui=class{load(e,t){let i=new le(e);return t?.(i),i}};function yt(e,t){return e!==void 0?Number(e):t}function Ie(e,t){return e!==void 0?!!e:t}var Mt=class{constructor(e={}){this.name=e.name||"",this.color=new Rt(e.color!==void 0?e.color:16777215),this.emissive=new Rt(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=yt(e.emissiveIntensity,1),this.roughness=yt(e.roughness,.5),this.metalness=yt(e.metalness,0),this.opacity=yt(e.opacity,1),this.transparent=Ie(e.transparent,!1),this.wireframe=Ie(e.wireframe,!1),this.side=yt(e.side,2),this.doubleSided=Ie(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=yt(e.clearcoat,0),this.clearcoatRoughness=yt(e.clearcoatRoughness,0),this.sheen=yt(e.sheen,0),this.sheenColor=new Rt(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=yt(e.sheenRoughness,0),this.transmission=yt(e.transmission,0),this.thickness=yt(e.thickness,0),this.attenuationColor=new Rt(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=yt(e.attenuationDistance,1/0),this.ior=yt(e.ior,1.5),this.dispersion=yt(e.dispersion,0),this.iridescence=yt(e.iridescence,0),this.iridescenceIOR=yt(e.iridescenceIOR,1.3)}dispose(){}},jt=class extends Mt{},zi=class extends Mt{},Vi=class extends Mt{},Oi=class extends Mt{},Bi=class extends Mt{},Ct=class Ur{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.parent=null,this.children=[],this.userData={},this.position=new Y,this.rotation=new _e,this.quaternion=new Ee,this.scale=new Y(1,1,1),this.matrix=new Ot,this.matrixWorld=new Ot,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,i=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),s=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(i,r,s)})}add(...t){for(let i of t)i&&i instanceof Ur&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...t){for(let i of t){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(t){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),t(s);let n=s.children;if(Array.isArray(n))for(let o=n.length-1;o>=0;o--)r.push(n[o])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(i=>{Gi(i),(i.matrixAutoUpdate||t)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(t,i,r){let s=typeof t=="object"?t:new Y(t,i,r);this.target instanceof Y?this.target.copy(s):this.target?.position instanceof Y&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Ot;n.lookAt(this.position,s,new Y(0,1,0));let o=n.elements,a=o[0],h=o[4],l=o[8],c=o[1],f=o[5],y=o[9],g=o[2],u=o[6],b=o[10],w=a+f+b;if(w>0){let M=.5/Math.sqrt(w+1);this.quaternion.set((u-y)*M,(l-g)*M,(c-h)*M,.25/M)}}translateOnAxis(t,i){let r=t.clone().applyMatrix4(new Ot().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new Y(1,0,0),t)}translateY(t){return this.translateOnAxis(new Y(0,1,0),t)}translateZ(t){return this.translateOnAxis(new Y(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}clone(t=!0){let i=this instanceof $t?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Et?new Et(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(t)for(let r of this.children)i.add(r.clone(!0));return i}},$i=class extends Ct{},Et=class extends Ct{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof ft?e:e?(kt("unsupported geometry","BoxGeometry"),new Ne(.5,.5,.5)):new ft,this.material=i instanceof Mt?i:i?(kt("unsupported material","MeshStandardMaterial"),new jt({color:13421772})):new jt}};function Gi(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=ut().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var Wt=1e4,Fe=class extends Et{constructor(e,t,i=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>Wt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Wt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let n=0;n<this.count;n++){let o=n*16;s[o]=1,s[o+5]=1,s[o+10]=1,s[o+15]=1}this.instanceMatrix=new gt(s,16)}setMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++){let o=Number(t.elements[n]);r[s+n]=Number.isFinite(o)?o:n%5===0?1:0}}getMatrixAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t||!t.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let n=0;n<16;n++)t.elements[n]=r[s+n]}setColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let n=new Float32Array(this.count*3);n.fill(1),this.instanceColor=new gt(n,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(t.r)?t.r:1,r[s+1]=Number.isFinite(t.g)?t.g:1,r[s+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let i=Math.floor(Number(e));if(!Number.isFinite(i)||i<0||i>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){t.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;t.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Xt=class extends Ct{constructor(e=16777215,t=1){super(),this.color=new Rt(e),this.intensity=Number(t),this.type="directional"}},ke=class extends Xt{constructor(e,t){super(e,t),this.type="ambient"}},Hi=class extends Xt{constructor(e,t){super(e,t),this.target=new Ct,this.type="directional"}},Ue=class extends Xt{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},ze=class extends Ct{},ji=class extends ze{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new Y(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},Ve=class extends Ct{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Nt.validate(this),Ht(this)}toGLB(){return Nt.validate(this),ie(this)}toUSDZ(){return Nt.validate(this),ne(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Et){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},Oe=Ht,Be=ie,Wi=ne,Nt=class{static validate(e){let t=0,i=0,r=0,s=new Set,n=(a,h,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${h}). Found: ${l}`)},o=(a,h)=>{if(!Number.isFinite(h))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(h)}), which cannot be bounds-checked.`);return h};e.traverse(a=>{if(Gi(a),a instanceof Et||a.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),a instanceof Fe){let l=o("instance",a.count);(l<0||l>Wt)&&n("INSTANCES",Wt,l)}let h=a.geometry;if(h){let l=0;if(h.attributes.position&&(l=o("vertex",h.attributes.position.count),t+=l,t>1e5&&n("VERTICES",1e5,t)),h.index){let c=o("index",h.index.count);i+=c,i>3e5&&n("INDICES",3e5,i);let f=h.index.array;if(f&&l>0){let y=Math.min(c,f.length);for(let g=0;g<y;g++){let u=f[g];if(!Number.isFinite(u)||u<0||u>=l)throw new Error(`SecurityError: Index buffer value (${String(u)}) out of vertex bounds [0, ${l}).`)}}}}if(a.material){let l=a.material;l.map&&s.add(l.map),l.normalMap&&s.add(l.normalMap),l.roughnessMap&&s.add(l.roughnessMap)}}}),s.size>16&&n("TEXTURES",16,s.size);for(let a of s){let h=a,l=h.image,c=Number(l?.width??h.width??0)||0,f=Number(l?.height??h.height??0)||0;(!Number.isFinite(c)||!Number.isFinite(f)||c>2048||f>2048)&&n("TEXTURE_DIMENSION",2048,Math.max(c,f))}}},Xi=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let i=new Rt(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){Nt.validate(e);let r=(s,n)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(n&&n.length?self.postMessage(s,n):self.postMessage(s))};if(this.hasInitialModelRendered){let s=e.getMeshTransforms(),n={};for(let[o,a]of s.entries())n[o]=Array.from(a);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:n})}else{this.hasInitialModelRendered=!0;let s=Oe(e),n=Be(e),o=(s.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:n.buffer,dynamicLights:o,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[n.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(e.getMeshTransforms()):(i.loadModel(e.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function qi(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var Ki=class{constructor(e=!0){this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1,this.autoStart=e,e&&this.start()}start(){this.startTime=qi(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=qi();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function ms(){}var qt=new Proxy(ms,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:qt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>qt,construct:()=>qt}),Yi=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function he(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Bt(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,he());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Zi,Kt;function Ji(e){if(!Bt(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(Kt===void 0||Zi!==t){Zi=t;try{Kt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Bt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{Kt=null}}return Kt?Kt.createScriptURL(e):e}function fs(e){ut().sandboxEngineSrc=e}function $e(){let e=ut().sandboxEngineSrc;if(e)return e;if(Yi)return Yi;try{if(typeof document>"u")return null;let t=he(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let n=new URL(s,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(n)&&Bt(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Ge(e,t){if(!Bt(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,he()).href}function ps(){let e=$e();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return Ge(e,"sandbox engine")}function ds(e){ut().sandboxIframeSrc=e}function Qi(){let e=ut().sandboxIframeSrc;if(e)return e;let t=$e();if(!t||!Bt(t))return null;let i=new URL(t,he());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function gs(){let e=Qi();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return Ge(e,"sandbox iframe")}function ys(e){ut().allowClientScripts=e}function tr(){return!!ut().allowClientScripts}function bs(e){return Ge(e,"procedural scene script")}var xs=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function vs(e,t){let i=self,r=e.nonce,s=e.engineSrc,n=e.allowedScriptUrl,o=e.allowClientScripts,a=e.revoked,h=i.postMessage.bind(i);function l(m){h({type:"ERROR",nonce:r,message:String(m)})}let c=typeof i.importScripts=="function"?i.importScripts.bind(i):null,f=n,y=null;try{let m=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let p={createScriptURL:function(R){if(R!==s&&(!n||R!==n))throw new TypeError("Disallowed worker importScripts URL");return R}};o&&(p.createScript=function(R){return String(R)});let v=i.trustedTypes.createPolicy("three-live#worker-boot",p);m=v.createScriptURL(s),n&&(f=v.createScriptURL(n)),o&&typeof v.createScript=="function"&&(y=v.createScript.bind(v))}catch{}c(m)}catch(m){l('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(m&&m.message||m));return}let g=i.THREE;if(!g||typeof g.Scene!="function"){l('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let m=i.__THREE_LIVE_REGISTRY__;for(let p=0;p<t.length;p++)if(typeof t[p]=="function")try{t[p](g,m)}catch{}}function u(m,p,v){let R=i;for(;R&&R!==Object.prototype;){if(!v&&R!==i)try{delete R[m]}catch{}if(!v||R===i||Object.prototype.hasOwnProperty.call(R,m))try{Object.defineProperty(R,m,v?{value:p,writable:!1,configurable:!1}:{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}for(let m=0;m<a.length;m++)u(a[m],void 0);u("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],w=!1;function M(m,p){if(m.type==="3D_MODEL_READY"){if(w)return;w=!0}m.nonce=r,p&&p.length?h(m,p):h(m)}u("postMessage",function(m,p){if(!m||b.indexOf(m.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");M(m,p)},!0);let x=!1;i.onmessage=function(m){let p=m&&m.data;if(!(!p||p.nonce!==r)&&!(p.type!=="EXECUTE"&&p.type!=="EXECUTE_URL")&&!x){x=!0;try{let v=new g.Scene,R=new g.PerspectiveCamera(60,1,.1,1e3),L=new g.WebGLRenderer({isSandboxed:!0});if(p.type==="EXECUTE_URL"){if(!n||p.scriptUrl!==n||typeof c!="function"){l("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let I=f||n,N=c;if(c=null,f=null,i.THREE=g,i.scene=v,i.camera=R,i.renderer=L,N(I),typeof i.__THREE_LIVE_SCENE__=="function"){let _=i.__THREE_LIVE_SCENE__(g,v,R,L);_&&typeof _.toGLB=="function"&&(v=_)}else i.scene&&typeof i.scene.toGLB=="function"&&(v=i.scene)}else{if(!o){l("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let I=y?(0,eval)(y(`(function (THREE, scene, camera, renderer) {
331
+ ${_.body}${b(u)}${h(u)}${_.tail}}
332
+ `}}if(y+=`}
333
+ `,i.length>0){y+=`def Scope "Lights"
334
+ {
335
+ `;let m=new Set;for(let u=0;u<i.length;u++){let g=i[u],p=$t(m,et(g.name,`Light_${u}`)),x=g.type==="directional"?"DistantLight":g.type==="spot"?"DiskLight":"SphereLight",w=g.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[_,N,P]=g.color||[1,1,1],[E,T,S]=g.position||[0,5,5],A=-E,D=-T,R=-S;g.direction&&g.direction.length>=3&&(g.type==="directional"?(A=-g.direction[0],D=-g.direction[1],R=-g.direction[2]):(A=g.direction[0],D=g.direction[1],R=g.direction[2]));let[I,k,V,L]=Pi(A,D,R),O="",c=[];g.type!=="directional"&&(Math.abs(E)>1e-7||Math.abs(T)>1e-7||Math.abs(S)>1e-7)&&(O+=`double3 xformOp:translate = ${Le(E,T,S)}
336
+ `,c.push('"xformOp:translate"')),g.type!=="point"&&(1-Math.abs(L)>1e-7||Math.hypot(I,k,V)>1e-7)&&(O+=`quatf xformOp:orient = ${tt(L,I,k,V)}
337
+ `,c.push('"xformOp:orient"')),c.length>0&&(O+=`uniform token[] xformOpOrder = [${c.join(", ")}]
338
+ `);let F="";if(g.type==="spot"){let C=(g.outerConeAngle??Math.PI/3)*180/Math.PI,U=(g.innerConeAngle??C*.8)*180/Math.PI,H=C>1e-4?Math.max(0,Math.min(1,1-U/C)):0;F=`float inputs:shaping:cone:angle = ${be(C)}
339
+ float inputs:shaping:cone:softness = ${be(H)}
340
+ `}y+=`def ${x} "${p}" (
341
+ prepend apiSchemas = ${w}
342
+ )
343
+ {
344
+ color3f inputs:color = ${Le(_,N,P)}
345
+ float inputs:intensity = ${be(g.intensity??1)}
346
+ bool inputs:shadow:enable = 1
347
+ ${F}${O}}
348
+ `}y+=`}
349
+ `}return y+=`}
350
+ `,y}var gt=null;function zt(t){if(!gt){gt=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let n=0;n<8;n++)r=r&1?3988292384^r>>>1:r>>>1;gt[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=gt[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Es(t){let e=[],i=0,r=[];for(let f of t){let b=Vt(f.filename),h=zt(f.data),d=f.data.length,v=30+b.length,M=(i+v)%64,m=M!==0?64-M:0;m>0&&m<4&&(m+=64);let u=new Uint8Array(v+m),g=new DataView(u.buffer);g.setUint32(0,67324752,!0),g.setUint16(4,20,!0),g.setUint32(14,h,!0),g.setUint32(18,d,!0),g.setUint32(22,d,!0),g.setUint16(26,b.length,!0),g.setUint16(28,m,!0),u.set(b,30),m>=4&&(g.setUint16(v,6534,!0),g.setUint16(v+2,m-4,!0)),e.push({offset:i,size:d,crc:h,filenameBytes:b,entry:f}),r.push(u,f.data),i+=u.length+f.data.length}let n=i;for(let f of e){let b=new Uint8Array(46+f.filenameBytes.length),h=new DataView(b.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint32(16,f.crc,!0),h.setUint32(20,f.size,!0),h.setUint32(24,f.size,!0),h.setUint16(28,f.filenameBytes.length,!0),h.setUint32(42,f.offset,!0),b.set(f.filenameBytes,46),r.push(b),i+=b.length}let s=i-n,a=new Uint8Array(22),o=new DataView(a.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,e.length,!0),o.setUint16(10,e.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),r.push(a),i+=22;let l=new Uint8Array(i),y=0;for(let f of r)l.set(f,y),y+=f.length;return l}function Di(t){let e=[{filename:"model.usda",data:Vt(Rs(t))}],i=new Set(["model.usda"]),r=[...t];for(;r.length>0;){let n=r.pop();for(let s of n.textures||[])s?.file&&s.data?.byteLength&&!i.has(s.file)&&(i.add(s.file),e.push({filename:s.file,data:s.data}));if(n.children)for(let s=n.children.length-1;s>=0;s--)r.push(n.children[s])}return Es(e)}function yt(t){return Di(_s(t))}function Bt(t){return Di(Li(It(t)))}function Ii(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():Bt(t)}var Pe=class Wr{constructor(e=0,i=0){this.x=Number(e),this.y=Number(i)}set(e,i){return this.x=Number(e),this.y=Number(i),this}clone(){return new Wr(this.x,this.y)}copy(e){return this.set(e.x,e.y)}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}get width(){return this.x}set width(e){this.x=Number(e)}get height(){return this.y}set height(e){this.y=Number(e)}},ee=class Xr{constructor(e=0,i=0,r=0){this.x=Number(e),this.y=Number(i),this.z=Number(r)}set(e,i,r){return this.x=Number(e),this.y=Number(i),this.z=Number(r),this}clone(){return new Xr(this.x,this.y,this.z)}copy(e){return this.set(e.x,e.y,e.z)}add(e){return this.addVectors(this,e)}addVectors(e,i){return this.set(e.x+i.x,e.y+i.y,e.z+i.z)}sub(e){return this.subVectors(this,e)}subVectors(e,i){return this.set(e.x-i.x,e.y-i.y,e.z-i.z)}multiplyScalar(e){return this.set(this.x*e,this.y*e,this.z*e)}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.set(this.x+e.x*i,this.y+e.y*i,this.z+e.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5?this.multiplyScalar(1/e):this}cross(e){return this.crossVectors(this,e)}crossVectors(e,i){let r=e.x,n=e.y,s=e.z,a=i.x,o=i.y,l=i.z;return this.set(n*l-s*o,s*a-r*l,r*o-n*a)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,i){return this.lerpVectors(this,e,i)}lerpVectors(e,i,r){return this.x=e.x+(i.x-e.x)*r,this.y=e.y+(i.y-e.y)*r,this.z=e.z+(i.z-e.z)*r,this}applyMatrix4(e){let i=this.x,r=this.y,n=this.z,s=e.elements,a=1/(s[3]*i+s[7]*r+s[11]*n+s[15]);return this.x=(s[0]*i+s[4]*r+s[8]*n+s[12])*a,this.y=(s[1]*i+s[5]*r+s[9]*n+s[13])*a,this.z=(s[2]*i+s[6]*r+s[10]*n+s[14])*a,this}},Fi=class{constructor(t=0,e=0,i=0,r=1){this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r)}set(t,e,i,r){return this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r),this}},Gt=class qr{constructor(e=0,i=0,r=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,i,r,n=this.order){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=n,this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.order)}clone(){return new qr(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},bt=class Kr{constructor(e=0,i=0,r=0,n=1){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,i,r,n){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(n),this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.w)}clone(){return new Kr(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(e,i=!0){let r=e.x,n=e.y,s=e.z,a=Math.cos(r/2),o=Math.cos(n/2),l=Math.cos(s/2),y=Math.sin(r/2),f=Math.sin(n/2),b=Math.sin(s/2);return this._x=y*o*l+a*f*b,this._y=a*f*l-y*o*b,this._z=a*o*b+y*f*l,this._w=a*o*l-y*f*b,i&&this._onChangeCallback?.(),this}setFromAxisAngle(e,i){let r=i/2,n=Math.sin(r);return this.set(e.x*n,e.y*n,e.z*n,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,i){let r=e.dot(i)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,i){let r=e.x,n=e.y,s=e.z,a=e.w,o=i.x,l=i.y,y=i.z,f=i.w;return this._x=r*f+a*o+n*y-s*l,this._y=n*f+a*l+s*o-r*y,this._z=s*f+a*y+r*l-n*o,this._w=a*f-r*o-n*l-s*y,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},qe=class Yr{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new Yr;return e.copy(this),e}compose(e,i,r){return Nt(this.elements,[i.x,i.y,i.z,i.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,i){return Te(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return Lt(this.elements,[e.x,e.y,e.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let i=new ee(0,0,0),r=new ee(1,1,1);return this.compose(i,e,r)}makeTranslation(e,i,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(e,i,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},ki=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[4]=1,t[8]=1,this}getNormalMatrix(t){return Oe(this.elements,t.elements),this}},_e=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,xt=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Ui={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},Ie=class Zr{constructor(e,i,r){this.r=1,this.g=1,this.b=1,e!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(e,i,r):this.set(e))}set(e){return typeof e=="number"?this.setHex(e):typeof e=="string"?this.setStyle(e):(e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b)),this)}setStyle(e){let i=e.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let n=parseInt(r,16);r.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(i in Ui)this.setHex(Ui[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let n=s=>_e(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(r[0]),n(r[1]),n(r[2]))}}return this}setHSL(e,i,r){if(e=((Number(e)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let o=_e(r);return this.setRGB(o,o,o)}let n=r<=.5?r*(1+i):r+i-r*i,s=2*r-n,a=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(_e(a(e+1/3)),_e(a(e)),_e(a(e-1/3)))}lerp(e,i){return this.lerpColors(this,e,i)}lerpColors(e,i,r){let n=Number(r)||0;return this.setRGB(e.r+(i.r-e.r)*n,e.g+(i.g-e.g)*n,e.b+(i.b-e.b)*n)}multiplyScalar(e){let i=Number(e)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.setRGB(_e((i>>16&255)/255),_e((i>>8&255)/255),_e((i&255)/255))}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(_e(this.r),_e(this.g),_e(this.b))}convertLinearToSRGB(){return this.setRGB(xt(this.r),xt(this.g),xt(this.b))}getHex(){let e=i=>Math.round(xt(Math.max(0,Math.min(1,i)))*255);return e(this.r)<<16|e(this.g)<<8|e(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.setRGB(e.r,e.g,e.b)}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new Zr(this.r,this.g,this.b)}},Ht=1234567,Oi={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,i)=>Math.max(e,Math.min(i,t)),lerp:(t,e,i)=>t+(e-t)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randInt:(t,e)=>t+Math.floor(Math.random()*(e-t+1)),randFloat:(t,e)=>t+Math.random()*(e-t),randFloatSpread:t=>t*(.5-Math.random()),seededRandom:t=>{t!==void 0&&(Ht=Number.isFinite(t)?t|0:0);let e=Ht=Ht+1831565813|0;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},Ae=class Jr{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.itemSize>=2?this.array[e*this.itemSize+1]:0}getZ(e){return this.itemSize>=3?this.array[e*this.itemSize+2]:0}setX(e,i){return this.array[e*this.itemSize]=i,this.needsUpdate=!0,this}setY(e,i){return this.array[e*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(e,i){return this.array[e*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(e,i,r,n){let s=e*this.itemSize;return this.array[s]=i,this.array[s+1]=r,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(e){return this}clone(){let e=this.array?.constructor||Float32Array;return new Jr(new e(this.array),this.itemSize)}},$i=class extends Ae{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},Vi=class extends Ae{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},zi=class extends Ae{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},Me=class Qr{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(e,i){return this.attributes[e]=i,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof Ae)this.index=e;else if(Array.isArray(e)){let i=0;for(let r of e)r>i&&(i=r);this.index=new Ae(new(i>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new Ae(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=!1;if(typeof i=="function"){let l=i(e.array,this.index?.array);return this.setAttribute("normal",new Ae(l,3)),this}let r=e.count,n=e.array,s=new Float32Array(r*3),a=this.index?.array,o=a?a.length:r;for(let l=0;l<o;l+=3){let y=(a?a[l]:l)*3,f=(a?a[l+1]:l+1)*3,b=(a?a[l+2]:l+2)*3,h=n[f],d=n[f+1],v=n[f+2],M=n[b]-h,m=n[b+1]-d,u=n[b+2]-v,g=n[y]-h,p=n[y+1]-d,x=n[y+2]-v,w=m*x-u*p,_=u*g-M*x,N=M*p-m*g;s[y]+=w,s[y+1]+=_,s[y+2]+=N,s[f]+=w,s[f+1]+=_,s[f+2]+=N,s[b]+=w,s[b+1]+=_,s[b+2]+=N}for(let l=0;l<r*3;l+=3){let y=s[l],f=s[l+1],b=s[l+2],h=Math.hypot(y,f,b)||1;s[l]=y/h,s[l+1]=f/h,s[l+2]=b/h}return this.setAttribute("normal",new Ae(s,3)),this}setFromBuffers(e,i,r,n){this.setAttribute("position",new Ae(e,3)),this.setAttribute("normal",new Ae(i,3)),this.setAttribute("uv",new Ae(r,2)),this.setIndex(n)}setFromPoints(e){let i=[];if(Array.isArray(e))for(let r of e)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new Ae(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new ee(1/0,1/0,1/0),r=new ee(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let n=0;n<e.count;n++){let s=e.getX(n),a=e.getY(n),o=e.getZ(n);s<i.x&&(i.x=s),a<i.y&&(i.y=a),o<i.z&&(i.z=o),s>r.x&&(r.x=s),a>r.y&&(r.y=a),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return e.max.x<e.min.x?this:this.translate(-(e.min.x+e.max.x)*.5,-(e.min.y+e.max.y)*.5,-(e.min.z+e.max.z)*.5)}_xform(e,i){let r=this.attributes.position;if(r){let n=r.array;for(let s=0;s<n.length;s+=3)e(n,s);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(e=0,i=0,r=0){return this._xform((n,s)=>{n[s]+=e,n[s+1]+=i,n[s+2]+=r})}scale(e=1,i=1,r=1){return this._xform((n,s)=>{n[s]*=e,n[s+1]*=i,n[s+2]*=r},!0)}_rot(e,i,r){let n=Math.cos(r),s=Math.sin(r);for(let a of[this.attributes.position,this.attributes.normal]){if(!a)continue;let o=a.array;for(let l=0;l<o.length;l+=3){let y=o[l+e],f=o[l+i];o[l+e]=y*n-f*s,o[l+i]=y*s+f*n}a.needsUpdate=!0}return this}rotateX(e){return this._rot(1,2,e)}rotateY(e){return this._rot(2,0,e)}rotateZ(e){return this._rot(0,1,e)}applyMatrix4(e){let i=this.attributes.position;if(i&&e?.elements){let r=new ee;for(let n=0;n<i.count;n++)r.set(i.getX(n),i.getY(n),i.getZ(n)).applyMatrix4(e),i.setXYZ(n,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let e=new Qr;e.name=this.name;for(let i of Object.keys(this.attributes))e.attributes[i]=this.attributes[i].clone();return this.index&&(e.index=this.index.clone()),e}dispose(){}},jt=class extends Me{constructor(t=1,e=1,i=1){super();let r=t/2,n=e/2,s=i/2,a=[-r,-n,s,r,-n,s,r,n,s,-r,n,s,r,-n,-s,-r,-n,-s,-r,n,-s,r,n,-s,-r,n,s,r,n,s,r,n,-s,-r,n,-s,-r,-n,-s,r,-n,-s,r,-n,s,-r,-n,s,r,-n,s,r,-n,-s,r,n,-s,r,n,s,-r,-n,-s,-r,-n,s,-r,n,s,-r,n,-s],o=[],l=[],y=[];for(let f=0;f<6;f++){let b=f*4,h=2-(f>>1),d=f&1?-1:1;for(let v=0;v<4;v++)o.push(h===0?d:0,h===1?d:0,h===2?d:0);l.push(0,0,1,0,1,1,0,1),y.push(b,b+1,b+2,b,b+2,b+3)}this.setFromBuffers(a,o,l,y)}},Bi=class extends Me{constructor(t=1,e=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));let n=[],s=[],a=[],o=[];for(let l=0;l<=r;l++){let y=l/r;for(let f=0;f<=i;f++){let b=f/i;if(n.push((b-.5)*t,(.5-y)*e,0),s.push(0,0,1),a.push(b,1-y),l>0&&f>0){let h=(i+1)*l+f-1,d=h-(i+1);o.push(d,h,d+1,h,h+1,d+1)}}}this.setFromBuffers(n,s,a,o)}},Gi=class extends Me{constructor(t=1,e=16,i=12,r=0,n=Math.PI*2,s=0,a=Math.PI){super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));let o=[],l=[],y=[],f=[],b=Math.min(s+a,Math.PI);for(let h=0;h<=i;h++){let d=h/i,v=s+d*a;for(let M=0;M<=e;M++){let m=M/e,u=r+m*n,g=-Math.cos(u)*Math.sin(v),p=Math.cos(v),x=Math.sin(u)*Math.sin(v);if(o.push(t*g,t*p,t*x),l.push(g,p,x),y.push(m,1-d),h>0&&M>0){let w=(e+1)*h+M,_=w-(e+1),N=_-1,P=w-1;(h!==1||s>0)&&f.push(_,N,w),(h!==i||b<Math.PI)&&f.push(N,P,w)}}}this.setFromBuffers(o,l,y,f)}},Wt=class extends Me{constructor(t=1,e=1,i=1,r=16,n=1,s=!1,a=0,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),n=Math.max(1,Math.floor(Number(n)||1));let l=[],y=[],f=[],b=[],h=i/2,d=(e-t)/(i||1),v=r+1;for(let m=0;m<=n;m++){let u=m/n,g=u*(e-t)+t,p=h-u*i;for(let x=0;x<=r;x++){let w=x/r,_=a+w*o,N=Math.sin(_),P=Math.cos(_),E=Math.hypot(N,d,P)||1;if(l.push(g*N,p,g*P),y.push(N/E,d/E,P/E),f.push(w,1-u),m<n&&x<r){let T=m*v+x,S=T+v;b.push(T,S,T+1,S,S+1,T+1)}}}let M=(m,u)=>{if(s||m<=0)return;let g=u*h,p=l.length/3;l.push(0,g,0),y.push(0,u,0),f.push(.5,.5);let x=p+1;for(let w=0;w<=r;w++){let _=a+w/r*o,N=Math.sin(_),P=Math.cos(_);l.push(m*N,g,m*P),y.push(0,u,0),f.push(P*.5+.5,.5+u*N*.5),w<r&&b.push(p,x+w+(u>0?0:1),x+w+(u>0?1:0))}};M(t,1),M(e,-1),this.setFromBuffers(l,y,f,b)}},Hi=class extends Wt{constructor(t=1,e=1,i=16,r=1,n=!1,s=0,a=Math.PI*2){super(0,t,e,i,r,n,s,a)}},ji=class extends Me{constructor(t=1,e=.4,i=12,r=48,n=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));let s=[],a=[],o=[],l=[];for(let y=0;y<=i;y++){let f=y/i*Math.PI*2,b=Math.cos(f),h=Math.sin(f);for(let d=0;d<=r;d++){let v=d/r*n,M=Math.cos(v),m=Math.sin(v);if(s.push((t+e*b)*M,(t+e*b)*m,e*h),a.push(b*M,b*m,h),o.push(d/r,y/i),y>0&&d>0){let u=(r+1)*y+d-1,g=u-(r+1);l.push(u,g,u+1,g,g+1,u+1)}}}this.setFromBuffers(s,a,o,l)}};function Wi(t,e,i,r,n){let s=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),a=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,l=[],y=[],f=[],b=[],h=[],d=new ee,v=new ee,M=new ee;for(let u=0;u<=s;u++){let g=new ee;n(u/s,g),h.push(g)}let m=a+1;for(let u=0;u<=s;u++){let g=u/s,p=h[u];d.subVectors(h[Math.min(s,u+1)],h[Math.max(0,u-1)]).normalize(),u===0&&v.set(Math.abs(d.y)>.9?1:0,Math.abs(d.y)>.9?0:1,0),M.crossVectors(d,v).normalize(),v.crossVectors(M,d).normalize();for(let x=0;x<=a;x++){let w=x/a*Math.PI*2,_=-Math.cos(w),N=Math.sin(w),P=_*v.x+N*M.x,E=_*v.y+N*M.y,T=_*v.z+N*M.z;if(l.push(p.x+o*P,p.y+o*E,p.z+o*T),y.push(P,E,T),f.push(g,x/a),u>0&&x>0){let S=m*(u-1)+x-1,A=S+m;b.push(S,A,S+1,A,A+1,S+1)}}}t.setFromBuffers(l,y,f,b)}var Xi=class extends Me{constructor(t=1,e=.4,i=64,r=8,n=2,s=3){super(),i=Math.floor(i),r=Math.floor(r),Wi(this,i,r,e,(a,o)=>{let l=a*n*Math.PI*2,y=s/n*l,f=t*(2+Math.cos(y))*.5;o.set(f*Math.cos(l),f*Math.sin(l),t*Math.sin(y)*.5)})}},He=class{getPoint(t,e=new ee){return e}getPointAt(t,e=new ee){return this.getPoint(t,e)}getTangent(t,e=new ee){return e.subVectors(this.getPoint(Math.min(1,t+.001)),this.getPoint(Math.max(0,t-.001))).normalize()}getPoints(t=5){let e=Math.max(1,Math.min(512,Math.floor(Number(t)||5))),i=[];for(let r=0;r<=e;r++)i.push(this.getPoint(r/e));return i}getSpacedPoints(t=5){return this.getPoints(t)}},qi=class extends He{constructor(t=new ee,e=new ee){super(),this.v1=t,this.v2=e}getPoint(t,e=new ee){return e.lerpVectors(this.v1,this.v2,t)}},Ki=class extends He{constructor(t=new ee,e=new ee,i=new ee){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new ee){return e.lerpVectors(this.v0,this.v1,t).lerp(new ee().lerpVectors(this.v1,this.v2,t),t)}},Yi=class extends He{constructor(t=new ee,e=new ee,i=new ee,r=new ee){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new ee){let i=new ee().lerpVectors(this.v0,this.v1,t),r=new ee().lerpVectors(this.v1,this.v2,t),n=new ee().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(n,t),t)}},Zi=class extends He{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new ee){let i=this.points,r=i.length;if(!r)return e.set(0,0,0);if(r===1)return e.copy(i[0]);let n=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(t)||0)),s=Math.floor(n),a=n-s;!this.closed&&s>=r-1&&(s=r-2,a=1);let o=M=>i[this.closed?(M%r+r)%r:Math.max(0,Math.min(r-1,M))],l=o(s-1),y=o(s),f=o(s+1),b=o(s+2),h=a*a,d=h*a,v=(M,m,u,g)=>.5*(2*m+(u-M)*a+(2*M-5*m+4*u-g)*h+(3*m-M-3*u+g)*d);return e.set(v(l.x,y.x,f.x,b.x),v(l.y,y.y,f.y,b.y),v(l.z,y.z,f.z,b.z))}},Xt=class extends Me{constructor(t=[new Pe(0,-.5),new Pe(.5,0),new Pe(0,.5)],e=12,i=0,r=Math.PI*2){super();let n=Array.isArray(t)&&t.length>=2?t:[new Pe(.2,0),new Pe(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),a=[],o=[],l=[],y=[],f=n.length;for(let b=0;b<=s;b++){let h=b/s,d=i+h*r,v=Math.sin(d),M=Math.cos(d),m=b*f;for(let u=0;u<f;u++){let g=n[u],p=Number(g?.x)||0,x=Number(g?.y)||0;a.push(p*v,x,p*M);let w=n[Math.max(0,u-1)],_=n[Math.min(f-1,u+1)],N=(Number(_?.x)||0)-(Number(w?.x)||0),P=(Number(_?.y)||0)-(Number(w?.y)||0),E=Math.hypot(P,N)||1;if(o.push(P/E*v,-N/E,P/E*M),l.push(h,u/(f-1)),b<s&&u<f-1){let T=m+u,S=T+f;y.push(T,S,T+1,S,S+1,T+1)}}}this.setFromBuffers(a,o,l,y)}},Ji=class extends Me{constructor(t,e=64,i=1,r=8,n=!1){super(),Wi(this,e,r,i,(s,a)=>{let o=t?.getPointAt??t?.getPoint;if(typeof o=="function"){let l=o.call(t,s,a);l&&l!==a&&a.copy(l)}else a.set(0,s,0)})}},vt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Mt=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Pe(1,1),this.offset=new Pe(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},Qi=class extends Mt{constructor(t=null,e=1,i=1,r=1023,n=1009,s,a=1001,o=1001,l=1003,y=1003,f=1,b=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let h=Number(e),d=Number(i),v=t&&typeof t.length=="number"?t:null;this.width=h,this.height=d,this.image={data:v,width:h,height:d},this.format=Number(r)||1023,this.type=Number(n)||1009,this.wrapS=Number(a)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(l)||1003,this.minFilter=Number(y)||1003,this.colorSpace=b||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(t){t&&this._bake()}_bake(){let t=this.image,e=t?.data,i=Number(t?.width??this.width),r=Number(t?.height??this.height);if(!e||!e.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let n=Math.max(1,i|0),s=Math.max(1,r|0),a=n*s,o=this.format,l=o===1021||o===1024||o===1028||e.length===a?1:o===1025||o===1030||e.length===a*2?2:o===1022||e.length===a*3?3:4,y=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,f=Math.min(n,64),b=Math.min(s,64),h=(this.flipY?257:1)^this.colorSpace.length^e.length,d=Math.max(1,e.length>>6|0);for(let A=0;A<e.length;A+=d)h=Math.imul(h^(e[A]*256|0),16777619)|0;if(h===this._sig&&this.source)return;this._sig=h;let v=b*(1+f*4),M=new Uint8Array(68+v),m=new DataView(M.buffer);m.setUint32(0,2303741511),m.setUint32(4,218765834),m.setUint32(8,13),m.setUint32(12,1229472850),m.setUint32(16,f),m.setUint32(20,b),M[24]=8,M[25]=6,m.setUint32(29,zt(M.subarray(12,29))),m.setUint32(33,v+11),m.setUint32(37,1229209940),M[41]=120,M[42]=1,M[43]=1,m.setUint16(44,v,!0),m.setUint16(46,~v&65535,!0);let u=48,g=1,p=0,x=0,w=0,_=0,N=0,P=A=>{if(!Number.isFinite(A))return 0;let D=y&&A<=1?A*255:A;return D>0?D<255?D+.5|0:255:0};for(let A=0;A<b;A++){let D=A*s/b|0,R=this.flipY?s-1-D:D;M[u++]=0,p+=g;for(let I=0;I<f;I++){let k=(R*n+(I*n/f|0))*l,V=o===1021?255:P(e[k]??0),L=l>=3||o===1030?P(e[k+1]??0):V,O=l>=3?P(e[k+2]??0):o===1030?0:V,c=l===4?P(e[k+3]??255):o===1021?P(e[k]??255):o===1025?P(e[k+1]??255):255;M[u++]=V,g+=V,p+=g,M[u++]=L,g+=L,p+=g,M[u++]=O,g+=O,p+=g,M[u++]=c,g+=c,p+=g,x+=V,w+=L,_+=O,N+=c}g%=65521,p%=65521}m.setUint32(u,(p<<16|g)>>>0),m.setUint32(u+4,zt(M.subarray(37,u+4))),m.setUint32(u+12,1229278788),m.setUint32(u+16,2923585666);let E=f*b*255,T=this.colorSpace==="srgb-linear";this.avgColor=[T?x/E:_e(x/E),T?w/E:_e(w/E),T?_/E:_e(_/E),N/E];let S=["data:image/png;base64,"];for(let A=0;A<M.length;A+=3){let D=M[A]<<16|(M[A+1]??0)<<8|(M[A+2]??0);S.push(vt[D>>18&63]+vt[D>>12&63]+(A+1<M.length?vt[D>>6&63]:"=")+(A+2<M.length?vt[D&63]:"="))}this.source=S.join("")}},er=class{load(t,e){let i=new Mt(t);return e?.(i),i}};function we(t,e){return t!==void 0?Number(t):e}function qt(t,e){return t!==void 0?!!t:e}var Ne=class{constructor(t={}){this.name=t.name||"",this.color=new Ie(t.color??16777215),this._em=t.emissive!==void 0,this.emissive=new Ie(t.emissive??0),this.emissiveIntensity=we(t.emissiveIntensity,1),this.roughness=we(t.roughness,t.roughnessMap?1:.5),this.metalness=we(t.metalness,t.metalnessMap?1:0),this.opacity=we(t.opacity,1),this.transparent=qt(t.transparent,!1),this.wireframe=qt(t.wireframe,!1),this.side=we(t.side,2),this.doubleSided=qt(t.doubleSided,!0),this.map=t.map||null,this.normalMap=t.normalMap||null;let e=t.normalScale;this.normalScale=typeof e=="number"?new Pe(e,e):new Pe(we(e?.x,1),we(e?.y,1)),this.roughnessMap=t.roughnessMap||null,this.metalnessMap=t.metalnessMap||null,this.emissiveMap=t.emissiveMap||null,this.aoMap=t.aoMap||null,this.aoMapIntensity=we(t.aoMapIntensity,1),this.bumpMap=t.bumpMap||null,this.bumpScale=we(t.bumpScale,1),this.clearcoat=we(t.clearcoat,0),this.clearcoatRoughness=we(t.clearcoatRoughness,0),this.sheen=we(t.sheen,0),this.sheenColor=new Ie(t.sheenColor??0),this.sheenRoughness=we(t.sheenRoughness,0),this.transmission=we(t.transmission,0),this.thickness=we(t.thickness,0),this.attenuationColor=new Ie(t.attenuationColor??16777215),this.attenuationDistance=we(t.attenuationDistance,1/0),this.ior=we(t.ior,1.5),this.dispersion=we(t.dispersion,0),this.iridescence=we(t.iridescence,0),this.iridescenceIOR=we(t.iridescenceIOR,1.3)}dispose(){}},it=class extends Ne{},tr=class extends Ne{},ir=class extends Ne{},rr=class extends Ne{},sr=class extends Ne{},Fe=class es{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this._castShd=!1,this._castShdSet=!1,this._recvShd=!1,this._recvShdSet=!1,this.parent=null,this.children=[],this.userData={},this.position=new ee,this.rotation=new Gt,this.quaternion=new bt,this.scale=new ee(1,1,1),this.matrix=new qe,this.matrixWorld=new qe,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,i=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),n=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(i,r,n)})}get castShadow(){return this._castShd}set castShadow(e){this._castShd=!!e,this._castShdSet=!0}get receiveShadow(){return this._recvShd}set receiveShadow(e){this._recvShd=!!e,this._recvShdSet=!0}add(...e){for(let i of e)i&&i instanceof es&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...e){for(let i of e){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(e){let i=new Set,r=[this];for(;r.length>0;){let n=r.pop();if(!n||typeof n!="object"||i.has(n))continue;i.add(n),e(n);let s=n.children;if(Array.isArray(s))for(let a=s.length-1;a>=0;a--)r.push(s[a])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){this.traverse(i=>{ar(i),(i.matrixAutoUpdate||e)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(e,i,r){let n=typeof e=="object"?e:new ee(e,i,r);this.target instanceof ee?this.target.copy(n):this.target?.position instanceof ee&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new qe;s.lookAt(this.position,n,new ee(0,1,0));let a=s.elements,o=a[0],l=a[4],y=a[8],f=a[1],b=a[5],h=a[9],d=a[2],v=a[6],M=a[10],m=o+b+M;if(m>0){let u=.5/Math.sqrt(m+1);this.quaternion.set((v-h)*u,(y-d)*u,(f-l)*u,.25/u)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new qe().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new ee(1,0,0),e)}translateY(e){return this.translateOnAxis(new ee(0,1,0),e)}translateZ(e){return this.translateOnAxis(new ee(0,0,1),e)}rotateX(e){return this.rotation.x+=e,this}rotateY(e){return this.rotation.y+=e,this}rotateZ(e){return this.rotation.z+=e,this}_chain(){let e=[];for(let i=this;i&&e.length<64;i=i.parent)e.push(i);return e}_syncWorld(){let e=this._chain();for(let i=e.length-1;i>=0;i--){let r=e[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(e=new ee){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new ee){let i=this._syncWorld();return e.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(e=new ee){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new bt){let i=this._chain();e.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)e.multiply(i[r].quaternion);return e}clone(e=!0){let i=typeof this._cloneCustom=="function"?this._cloneCustom():this instanceof Ye?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof $e?new $e(this.geometry,this.material):new this.constructor;if(this instanceof je){i.color.copy(this.color),i.intensity=this.intensity,i.shadow.copy(this.shadow);let r=this.target;r?.position&&i.target?.position&&i.target.position.copy(r.position),this instanceof ci&&i.groundColor.copy(this.groundColor)}i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,this._castShdSet&&(i.castShadow=this.castShadow),this._recvShdSet&&(i.receiveShadow=this.receiveShadow);try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(e)for(let r of this.children)i.add(r.clone(!0));return i}},nr=class extends Fe{},$e=class extends Fe{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof Me?t:t?(Be("unsupported geometry","BoxGeometry"),new jt(.5,.5,.5)):new Me,this.material=i instanceof Ne?i:i?(Be("unsupported material","MeshStandardMaterial"),new it({color:13421772})):new it}};function ar(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=ge().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var rt=1e4,Kt=class extends $e{constructor(t,e,i=1){super(t,e),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>rt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${rt})`);this.count=Math.floor(r);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let a=s*16;n[a]=1,n[a+5]=1,n[a+10]=1,n[a+15]=1}this.instanceMatrix=new Ae(n,16)}setMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++){let a=Number(e.elements[s]);r[n+s]=Number.isFinite(a)?a:s%5===0?1:0}}getMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,n=i*16;if(!(n+16>r.length))for(let s=0;s<16;s++)e.elements[s]=r[n+s]}setColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new Ae(s,3)}let r=this.instanceColor.array,n=i*3;r[n]=Number.isFinite(e.r)?e.r:1,r[n+1]=Number.isFinite(e.g)?e.g:1,r[n+2]=Number.isFinite(e.b)?e.b:1}getColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){e.setRGB(1,1,1);return}let r=this.instanceColor.array,n=i*3;e.setRGB(r[n],r[n+1],r[n+2])}dispose(){}},Yt=class ts{constructor(){this.mapSize=new Pe(1024,1024),this.bias=-5e-4,this.normalBias=.015,this.radius=1.5,this.camera={near:.1,far:100,left:-5,right:5,top:5,bottom:-5,fov:50,updateProjectionMatrix:()=>{}}}copy(e){return this.mapSize.copy(e.mapSize),this.bias=Number(e.bias),this.normalBias=Number(e.normalBias),this.radius=Number(e.radius),this}clone(){return new ts().copy(this)}},je=class extends Fe{constructor(t=16777215,e=1){super(),this.isLight=!0,this.shadow=new Yt,this.color=new Ie(t),this.intensity=Number(e),this.type="directional"}},Zt=class extends je{constructor(t,e){super(t,e),this.type="ambient"}},or=class extends je{constructor(t,e){super(t,e),this.target=new Fe,this.type="directional"}},Jt=class extends je{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},Qt=class extends Fe{},lr=class extends Qt{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new ee(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},ei=class extends Fe{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ve.validate(this),Qe(this)}toGLB(){return Ve.validate(this),pt(this)}toUSDZ(){return Ve.validate(this),yt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof $e){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},ti=Qe,ii=pt,hr=yt;ge().makePngDeflater=di;var Ve=class{static validate(t){let e=0,i=0,r=0,n=new Set,s=(o,l,y)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${l}). Found: ${y}`)},a=(o,l)=>{if(!Number.isFinite(l))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(l)}), which cannot be bounds-checked.`);return l};t.traverse(o=>{if(ar(o),o instanceof $e||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&s("MESHES",1e3,r),o instanceof Kt){let y=a("instance",o.count);(y<0||y>rt)&&s("INSTANCES",rt,y)}let l=o.geometry;if(l){let y=0;if(l.attributes.position&&(y=a("vertex",l.attributes.position.count),e+=y,e>1e5&&s("VERTICES",1e5,e)),l.index){let f=a("index",l.index.count);i+=f,i>3e5&&s("INDICES",3e5,i);let b=l.index.array;if(b&&y>0){let h=Math.min(f,b.length);for(let d=0;d<h;d++){let v=b[d];if(!Number.isFinite(v)||v<0||v>=y)throw new Error(`SecurityError: Index buffer value (${String(v)}) out of vertex bounds [0, ${y}).`)}}}}if(o.material){let y=o.material;for(let f of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","bumpMap"])y[f]&&n.add(y[f])}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let l=o,y=l.image,f=Number(y?.width??l.width??0)||0,b=Number(y?.height??l.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(b)||f>2048||b>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(f,b))}}},ur=class{constructor(t={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let e=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||e,this.containerId=t.containerId||""}setSize(t,e){return this}setPixelRatio(t){return this}setClearColor(t,e=1){let i=new Ie(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,e),this}clear(){return this}dispose(){}render(t,e){if(this.isSandboxed){Ve.validate(t);let r=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=t.getMeshTransforms(),s={};for(let[a,o]of n.entries())s[a]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=ti(t),s=ii(t),a=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:a,camera:e?{fov:e.fov||60,position:[e.position.x,e.position.y,e.position.z]}:void 0},[s.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(t.getMeshTransforms()):(i.loadModel(t.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function cr(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var mr=class{constructor(t=!0){this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1,this.autoStart=t,t&&this.start()}start(){this.startTime=cr(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let e=cr();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function Ls(){}var st=new Proxy(Ls,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:st},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>st,construct:()=>st}),fr=(()=>{try{if(typeof document>"u")return null;let t=document.currentScript;return t?.src?t.src:t?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([t.textContent],{type:"text/javascript"})):null}catch{return null}})();function wt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ke(t,e){if(!t||typeof t!="string")return!1;let i=t.trim();if(!i)return!1;try{let r=new URL(i,wt());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||e?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var pr,nt;function dr(t){if(!Ke(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let e=globalThis.trustedTypes;if(!e||typeof e.createPolicy!="function")return t;if(nt===void 0||pr!==e){pr=e;try{nt=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ke(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{nt=null}}return nt?nt.createScriptURL(t):t}function Ns(t){ge().sandboxEngineSrc=t}function ri(){let t=ge().sandboxEngineSrc;if(t)return t;if(fr)return fr;try{if(typeof document>"u")return null;let e=wt(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let n=r.src;if(!n)continue;let s=new URL(n,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Ke(n,{requireSameOrigin:!0}))return n}}catch{}return null}function si(t,e){if(!Ke(t))throw new Error(`SecurityError: Disallowed ${e} URL "${t}" (http:, https:, or blob: required).`);return new URL(t,wt()).href}function Ds(){let t=ri();if(!t)throw new Error("SecurityError: Could not locate Three-Live bundle URL for worker sandbox; set ThreeLiveElement.sandboxEngineSrc explicitly.");return si(t,"sandbox engine")}function Is(t){ge().sandboxIframeSrc=t}function gr(){let t=ge().sandboxIframeSrc;if(t)return t;let e=ri();if(!e||!Ke(e))return null;let i=new URL(e,wt());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function Fs(){let t=gr();if(!t)throw new Error("SecurityError: Could not locate three-live-sandbox.html; set ThreeLiveElement.sandboxIframeSrc explicitly.");return si(t,"sandbox iframe")}function ks(t){ge().allowClientScripts=t}function yr(){return!!ge().allowClientScripts}function Us(t){return si(t,"procedural scene script")}var Os="fetch XMLHttpRequest WebSocket WebSocketStream WebTransport EventSource importScripts Request Response Headers navigator WorkerNavigator WorkerLocation RTCPeerConnection RTCDataChannel FontFace FontFaceSet fonts PerformanceObserver ReportingObserver indexedDB IDBFactory caches CacheStorage Cache cookieStore StorageManager FileSystemHandle Worker SharedWorker ServiceWorker ServiceWorkerContainer ServiceWorkerRegistration registration clients BroadcastChannel MessageChannel MessagePort createImageBitmap OffscreenCanvas WebAssembly WorkerGlobalScope DedicatedWorkerGlobalScope trustedTypes TrustedTypePolicyFactory SharedArrayBuffer Atomics".split(" ");function $s(t,e,i){let r=self,n=t.nonce,s=t.engineSrc,a=t.allowedScriptUrl,o=t.allowClientScripts,l=t.revoked,y=r.postMessage.bind(r),f=null;try{f=i?i(r.CompressionStream):null}catch{}let b=null;function h(N,P){let E=()=>P&&P.length?y(N,P):y(N);b?b=b.then(E,E):E()}function d(N){h({type:"ERROR",nonce:n,message:String(N)})}let v=typeof r.importScripts=="function"?r.importScripts.bind(r):null,M=a,m=null;try{let N=s;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let P={createScriptURL:function(T){if(T!==s&&(!a||T!==a))throw new TypeError("Disallowed worker importScripts URL");return T}};o&&(P.createScript=function(T){return String(T)});let E=r.trustedTypes.createPolicy("three-live#worker-boot",P);N=E.createScriptURL(s),a&&(M=E.createScriptURL(a)),o&&typeof E.createScript=="function"&&(m=E.createScript.bind(E))}catch{}v(N)}catch(N){d('Sandbox failed to load "'+s+'" (must be an IIFE bundle like three-live.min.js): '+(N&&N.message||N));return}let u=r.THREE;if(!u||typeof u.Scene!="function"){d('Sandbox "'+s+'" did not install THREE; point sandboxEngineSrc at three-live.min.js.');return}if(Array.isArray(e)){let N=r.__THREE_LIVE_REGISTRY__;for(let P=0;P<e.length;P++)if(typeof e[P]=="function")try{e[P](u,N)}catch{}}function g(N,P,E){let T=r;for(;T&&T!==Object.prototype;){if(!E&&T!==r)try{delete T[N]}catch{}if(!E||T===r||Object.prototype.hasOwnProperty.call(T,N))try{Object.defineProperty(T,N,E?{value:P,writable:!1,configurable:!1}:{value:P,writable:!1,configurable:!1,enumerable:!1})}catch{}try{T=Object.getPrototypeOf(T)}catch{break}}}for(let N=0;N<l.length;N++)g(l[N],void 0);g("performance",Object.freeze({now:function(){return Date.now()}}));let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function w(N,P){if(N.type==="3D_MODEL_READY"){if(x)return;x=!0}if(N.nonce=n,N.type==="3D_MODEL_READY"&&f&&N.glbBuffer instanceof ArrayBuffer){let E=N.glbBuffer;b=(b||Promise.resolve()).then(()=>f.glb(new Uint8Array(E))).then(T=>{T.buffer!==E&&(N.glbBuffer=T.byteOffset===0&&T.byteLength===T.buffer.byteLength?T.buffer:T.slice().buffer),y(N,[N.glbBuffer])},()=>y(N,[E]));return}P&&P.length?h(N,P):h(N)}g("postMessage",function(N,P){if(!N||p.indexOf(N.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");w(N,P)},!0);let _=!1;r.onmessage=function(N){let P=N&&N.data;if(!P||P.nonce!==n||P.type!=="EXECUTE"&&P.type!=="EXECUTE_URL"||_)return;_=!0;let E=P.texturePack;if(E&&typeof E=="object"){let T=Object.create(null),S=0;for(let A of Object.keys(E)){let D=E[A],R=D&&D.size;S<64&&/^[0-9a-f]{16}$/.test(A)&&(R===256||R===512||R===1024)&&D.rgba instanceof Uint8Array&&D.rgba.length===R*R*4&&(T[A]=Object.freeze({size:R,rgba:D.rgba}),S++)}r.__three_live_texture_pack__=Object.freeze(T)}try{let T=new u.Scene,S=new u.PerspectiveCamera(60,1,.1,1e3),A=new u.WebGLRenderer({isSandboxed:!0});if(P.type==="EXECUTE_URL"){if(!a||P.scriptUrl!==a||typeof v!="function"){d("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let D=M||a,R=v;if(v=null,M=null,r.THREE=u,r.scene=T,r.camera=S,r.renderer=A,R(D),typeof r.__THREE_LIVE_SCENE__=="function"){let I=r.__THREE_LIVE_SCENE__(u,T,S,A);I&&typeof I.toGLB=="function"&&(T=I)}else r.scene&&typeof r.scene.toGLB=="function"&&(T=r.scene)}else{if(!o){d("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let D=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
342
351
  return (function () {
343
- `+p.script+`
352
+ `+P.script+`
344
353
  ;
345
354
  return typeof scene === "object" && scene ? scene : undefined;
346
355
  })();
347
356
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
348
- `+p.script+`
357
+ `+P.script+`
349
358
  ;
350
359
  return typeof scene === "object" && scene ? scene : undefined;
351
- })();`);y=null;let N=I(g,v,R,L);N&&typeof N.toGLB=="function"&&(v=N)}if(!w){g.SceneQuotaValidator&&g.SceneQuotaValidator.validate(v);let I=v.toGLB(),N=I instanceof ArrayBuffer?I:I.buffer.slice(I.byteOffset,I.byteOffset+I.byteLength);M({type:"3D_MODEL_READY",glbBuffer:N},[N])}h({type:"DONE",nonce:r})}catch(v){l(v&&v.message||v)}}},h({type:"READY",nonce:r})}function He(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:xs},o=(ut().workerExtensionInstallers??[]).map(a=>`(${a.toString()})`).join(",");return`'use strict';(${vs.toString()})(${JSON.stringify(n)},[${o}]);`}function er(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Dt=0;function ir(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ms(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var ws=1024,Ts=256;function rr(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let i=e[t];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function je(e,t){if(!e||typeof e!="object")return null;let i=e;if(i.nonce!==t)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,ws)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!rr(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let n=Object.create(null),o=r;for(let a of s){if(a.length>Ts||a==="__proto__"||a==="constructor"||a==="prototype")return null;let h=o[a];if(!rr(h))return null;n[a]=h}return{type:"3D_UPDATE_TRANSFORMS",transforms:n}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Ss(e){let t=Ms(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function sr(e,t,i,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":i();return;case"ERROR":i(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Rs(e,t,i,r){let s=ir(),n=He(t,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=i,Dt++;let a=!1,h=!1,l={modelDispatched:!1},c,f=()=>{if(a||h)return;let b=o.contentWindow;!b||typeof b.postMessage!="function"||(h=!0,b.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:n,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:n,script:e.script},"*"))},y=()=>{},g=b=>{if(a||!o.contentWindow||b.source!==o.contentWindow)return;let w=b.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){f();return}let M=je(w,s);M&&sr(M,r,y,l)};y=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),Dt=Math.max(0,Dt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",g),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},c=setTimeout(()=>{a||(y(),er(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",g),o.onload=()=>{f()},o.onerror=()=>{y(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let u=document.body||document.documentElement;if(!u||typeof u.appendChild!="function"){y();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return u.appendChild(o),{terminate:y}}function nr(e,t,i,r){if(t==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Dt>=32)return r(`SecurityError: ${Dt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let s;try{s=ps()}catch(y){let g=y instanceof Error?y.message:String(y);return r(g,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let y;try{y=gs()}catch(g){let u=g instanceof Error?g.message:String(g);return r(u,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Rs(e,s,y,i))}catch(g){return Promise.reject(g)}}let n=ir(),o=He(s,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a;try{let y=new Blob([o],{type:"application/javascript"}),g=URL.createObjectURL(y);try{let u=Ji(g);a=new Worker(u)}finally{URL.revokeObjectURL(g)}}catch(y){let g=y instanceof Error?y.message:String(y);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${g}`,"Security Error: Failed to start Worker sandbox.")}Dt++;let h=!1,l={modelDispatched:!1},c,f=()=>{h||(h=!0,c!==void 0&&clearTimeout(c),Dt=Math.max(0,Dt-1),a.terminate())};return c=setTimeout(()=>{h||(f(),er(i))},3e3),a.onmessage=y=>{let g=je(y.data,n);g&&sr(g,i,f,l)},a.onerror=y=>{f(),i.onError?.(new Error(`Worker execution error: ${y.message}`))},e.kind==="url"?a.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:n}):a.postMessage({type:"EXECUTE",script:e.script,nonce:n}),Promise.resolve({terminate:f})}function ar(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var or=e=>(t,i)=>{let r=new Error(t);return e.onError?.(r),i&&e.onToast?.(i),Promise.reject(r)},lr={execute(e,t,i,r){let s=or(i),n=ar(t,s);if(n)return n;try{Ss(e)}catch(o){let a=o instanceof Error?o.message:String(o);return s(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??tr()?nr({kind:"script",script:e},t,i,s):s(Vr,Or)},executeUrl(e,t,i){let r=or(i),s=ar(t,r);if(s)return s;let n;try{n=bs(e)}catch(o){let a=o instanceof Error?o.message:String(o);return r(a,"Security Error: disallowed scene script URL.")}return nr({kind:"url",scriptUrl:n},t,i,r)}},ue=new Set;function kt(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;ue.has(i)||(ue.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function hr(){return Array.from(ue)}function ur(){ue.clear()}var We=class extends jt{constructor(e={}){kt("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},i=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:i!==void 0?i:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},cr=We,Ut=class extends ft{constructor(e=[],t=[],i=1,r=0){super();let s=Number(i)||1,n=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),o=n+1,a=[],h=[],l=[],c=[],f=new Y,y=new Y,g=new Y,u=(M,x)=>x.set(e[M*3]||0,e[M*3+1]||0,e[M*3+2]||0),b=(M,x)=>{let m=M.clone().normalize();a.push(m.x*s,m.y*s,m.z*s),h.push(x.x,x.y,x.z),l.push(Math.atan2(m.z,-m.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,m.y)))/Math.PI)},w=(M,x,m)=>{let p=a.length/3,v=n===0?new Y().subVectors(m,x).cross(new Y().subVectors(M,x)).normalize():null;b(M,v||M.clone().normalize()),b(x,v||x.clone().normalize()),b(m,v||m.clone().normalize()),c.push(p,p+1,p+2)};for(let M=0;M<t.length;M+=3){u(t[M],f),u(t[M+1],y),u(t[M+2],g);let x=[];for(let m=0;m<=o;m++){x[m]=[];let p=f.clone().lerp(g,m/o),v=y.clone().lerp(g,m/o),R=o-m;for(let L=0;L<=R;L++)x[m][L]=R===0?p.clone():p.clone().lerp(v,L/R)}for(let m=0;m<o;m++)for(let p=0;p<2*(o-m)-1;p++){let v=p>>1;(p&1)===0?w(x[m][v+1],x[m+1][v],x[m][v]):w(x[m][v+1],x[m+1][v+1],x[m+1][v])}}this.setFromBuffers(a,h,l,c)}},Cs=Ut,mr=class extends Ut{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},ce=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],fr=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],pr=class extends Ut{constructor(e=1,t=0){super(ce,fr,e,t)}},at=(1+Math.sqrt(5))/2,dr=class extends Ut{constructor(e=1,t=0){super([-1,at,0,1,at,0,-1,-at,0,1,-at,0,0,-1,at,0,1,at,0,-1,-at,0,1,-at,at,0,-1,at,0,1,-at,0,-1,-at,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},vt=1/at,gr=class extends Ut{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-vt,-at,0,-vt,at,0,vt,-at,0,vt,at,-vt,-at,0,-vt,at,0,vt,-at,0,vt,at,0,-at,0,-vt,at,0,-vt,-at,0,vt,at,0,vt],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},yr=class extends Le{constructor(e=1,t=1,i=4,r=8){let s=Math.max(1e-4,Number(e)||1),n=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,o=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),a=[];for(let h=-1;h<=1;h+=2)for(let l=0;l<=o;l++){if(h>0&&l===0&&n===0)continue;let c=(h<0?l/o-1:l/o)*(Math.PI/2);a.push(new Tt(Math.max(0,Math.cos(c)*s),h*n+Math.sin(c)*s))}super(a,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},Xe=class extends ft{constructor(e=.5,t=1,i=32,r=1,s=0,n=Math.PI*2){super();let o=Math.max(1e-4,Number(t)||1),a=Number(e),h=Number.isFinite(a)?Math.max(0,a):o*.5,l=Math.max(o,h),c=Math.min(l*.999,Math.min(o,h)),f=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),y=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),g=Number.isFinite(Number(s))?Number(s):0,u=Number.isFinite(Number(n))?Number(n):Math.PI*2,b=[],w=[],M=[],x=[];for(let m=0;m<=y;m++){let p=c+m/y*(l-c);for(let v=0;v<=f;v++){let R=g+v/f*u,L=Math.cos(R),I=Math.sin(R);if(b.push(p*L,p*I,0),w.push(0,0,1),M.push(p/l*L*.5+.5,p/l*I*.5+.5),m<y&&v<f){let N=m*(f+1)+v,_=N+f+1;p>1e-6&&x.push(N,_,N+1),x.push(_,_+1,N+1)}}}this.setFromBuffers(b,w,M,x)}},br=class extends Xe{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},qe=class extends Mt{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},me=class extends Mt{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},xr=class extends me{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function vr(e,t){let i=e?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=e?.index?.array,n=Math.min(8192,Math.floor((s?s.length:i.count)/3)),o=y=>`${Math.round((r[y*3]||0)*1e4)},${Math.round((r[y*3+1]||0)*1e4)},${Math.round((r[y*3+2]||0)*1e4)}`,a=t===void 0,h=a?1:Math.cos(t*Math.PI/180),l={},c=[],f=(y,g)=>c.push(r[y*3]||0,r[y*3+1]||0,r[y*3+2]||0,r[g*3]||0,r[g*3+1]||0,r[g*3+2]||0);for(let y=0;y<n;y++){let g=s?s[y*3]:y*3,u=s?s[y*3+1]:y*3+1,b=s?s[y*3+2]:y*3+2,w=r[g*3]||0,M=r[g*3+1]||0,x=r[g*3+2]||0,m=(r[u*3]||0)-w,p=(r[u*3+1]||0)-M,v=(r[u*3+2]||0)-x,R=(r[b*3]||0)-w,L=(r[b*3+1]||0)-M,I=(r[b*3+2]||0)-x,N=p*I-v*L,_=v*R-m*I,A=m*L-p*R,E=Math.hypot(N,_,A);if(!a&&E<1e-8)continue;E>0&&(N/=E,_/=E,A/=E);let C=[g,u,b];for(let d=0;d<3;d++){let k=C[d],$=C[(d+1)%3],S=o(k),D=o($);if(S===D)continue;let T=S<D?`${S}|${D}`:`${D}|${S}`,P=l[T];P?P.m||(P.m=1,P.nx*N+P.ny*_+P.nz*A<=h&&f(k,$)):(l[T]={va:k,vb:$,nx:N,ny:_,nz:A,m:a?1:0},a&&f(k,$))}}if(!a){let y=Object.keys(l);for(let g=0;g<y.length;g++){let u=l[y[g]];u&&!u.m&&f(u.va,u.vb)}}return new Float32Array(c)}var Mr=class extends ft{constructor(e){super(),this.setAttribute("position",new gt(vr(e),3)),this.__isSegmentPairs=!0}},wr=class extends ft{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new gt(vr(e,i),3)),this.__isSegmentPairs=!0}};function As(e,t,i=1){let r=new ft;r.__baked=!0;let s=e?.attributes?.position;if(!s?.array||s.count<2)return r;let n=s.array,o=e.index?.array,a=e.__isSegmentPairs?"segments":t,h=o?o.length:s.count,l=Math.min(4096,Math.max(0,a==="segments"?Math.floor(h/2):a==="loop"&&h>=3?h:h-1));if(l===0)return r;e.computeBoundingBox();let c=e.boundingBox,f=c&&c.max.distanceTo(c.min)||1,y=Math.max(.0015,Math.min(.025,f*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),g=[],u=[],b=[],w=[];for(let M=0;M<l;M++){let x=a==="segments"?M*2:M,m=a==="segments"?M*2+1:(M+1)%h,p=o?o[x]:x,v=o?o[m]:m,R=n[p*3]||0,L=n[p*3+1]||0,I=n[p*3+2]||0,N=(n[v*3]||0)-R,_=(n[v*3+1]||0)-L,A=(n[v*3+2]||0)-I,E=Math.hypot(N,_,A);if(E<1e-6)continue;let C=N/E,d=_/E,k=A/E,$=(Math.abs(d)<.9?Math.hypot(k,C):Math.hypot(k,d))||1,S=Math.abs(d)<.9?k/$:0,D=Math.abs(d)<.9?0:-k/$,T=Math.abs(d)<.9?-C/$:d/$,P=d*T-k*D,j=k*S-C*T,W=C*D-d*S,V=g.length/3,Z=[[S,D,T],[P,j,W],[-S,-D,-T],[-P,-j,-W]];for(let U=0;U<2;U++){let X=R+U*N,O=L+U*_,G=I+U*A;for(let F=0;F<4;F++){let H=Z[F];g.push(X+H[0]*y,O+H[1]*y,G+H[2]*y),u.push(H[0],H[1],H[2]),b.push(F/4,U)}}for(let U=0;U<4;U++){let X=(U+1)%4;w.push(V+U,V+X,V+4+X,V+U,V+4+X,V+4+U)}}return g.length>0&&r.setFromBuffers(g,u,b,w),r}function Ps(e,t=.05){let i=new ft;i.__baked=!0;let r=e?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,n=r.count,o=Math.min(n,5e3),a=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),h=[],l=[],c=[],f=[];for(let y=0;y<o;y++){let g=n<=5e3?y:Math.floor(y*n/o),u=s[g*3]||0,b=s[g*3+1]||0,w=s[g*3+2]||0,M=y*6;for(let x=0;x<6;x++){let m=ce[x*3],p=ce[x*3+1],v=ce[x*3+2];h.push(u+m*a,b+p*a,w+v*a),l.push(m,p,v),c.push(.5,.5)}for(let x=0;x<24;x++)f.push(M+fr[x])}return i.setFromBuffers(h,l,c,f),i}var $t=class extends Et{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Mt?t:i==="points"?new qe(r):new me(r),n=e instanceof ft?e:new ft;super(n,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=n}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=t.array,r=Math.min(t.count,64),s=0,n=0,o=0;for(let a=0;a<r;a++)s+=i[a*3]||0,n+=i[a*3+1]||0,o+=i[a*3+2]||0;this.material.color.setRGB(s/r,n/r,o/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Ps(this._sourceGeo,this.material?.size??.05):As(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Tr=class extends $t{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},Sr=class extends $t{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Rr=class extends $t{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Cr=class extends Ue{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new Ct,this.type="spot";let o=Number(r);this.angle=Number.isFinite(o)?Math.max(.01,Math.min(Math.PI/2,o)):Math.PI/3;let a=Number(s);this.penumbra=Number.isFinite(a)?Math.max(0,Math.min(1,a)):0}},Ke=class extends ke{constructor(e,t,i){kt("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new Rt(t??4473924)}},Ar=Ke,Pr={Vector2:Tt,Vector3:Y,Vector4:bi,Euler:_e,Quaternion:Ee,Matrix4:Ot,Matrix3:xi,Color:Rt,MathUtils:Mi,BufferAttribute:gt,Float32BufferAttribute:wi,Uint16BufferAttribute:Ti,Uint32BufferAttribute:Si,BufferGeometry:ft,BoxGeometry:Ne,PlaneGeometry:Ri,SphereGeometry:Ci,CylinderGeometry:De,ConeGeometry:Ai,TorusGeometry:Pi,TorusKnotGeometry:Ei,Curve:Ft,Curve3:Ft,LineCurve3:Ni,QuadraticBezierCurve3:Di,CubicBezierCurve3:Li,CatmullRomCurve3:Ii,LatheGeometry:Le,TubeGeometry:Fi,PolyhedronGeometry:Ut,IcosahedronGeometry:dr,OctahedronGeometry:pr,DodecahedronGeometry:gr,TetrahedronGeometry:mr,CapsuleGeometry:yr,RingGeometry:Xe,CircleGeometry:br,WireframeGeometry:Mr,EdgesGeometry:wr,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:le,DataTexture:ki,TextureLoader:Ui,Material:Mt,MeshStandardMaterial:jt,MeshBasicMaterial:zi,MeshLambertMaterial:Vi,MeshPhongMaterial:Oi,MeshPhysicalMaterial:Bi,PointsMaterial:qe,LineBasicMaterial:me,LineDashedMaterial:xr,ShaderMaterial:We,RawShaderMaterial:cr,Object3D:Ct,Group:$i,Mesh:Et,InstancedMesh:Fe,Line:$t,LineLoop:Tr,LineSegments:Sr,Points:Rr,Light:Xt,AmbientLight:ke,DirectionalLight:Hi,PointLight:Ue,SpotLight:Cr,HemisphereLight:Ke,RectAreaLight:Ar,Camera:ze,PerspectiveCamera:ji,Scene:Ve,WebGLRenderer:Xi,Clock:Ki,SceneQuotaValidator:Nt,exportSceneToCanvas3D:Oe,exportSceneToGLB:Be,exportSceneToUSDZ:Wi,generateUSDZ:yi,glbToUSDZ:Pe,sceneToCanvas3D:Ht,sceneToGLB:ie,sceneToUSDZ:ne,authorScriptRunner:lr,getAuthorWarnings:hr,clearAuthorWarnings:ur};Object.freeze(Nt),Object.freeze(Nt.prototype),Object.freeze(Ve.prototype),Object.freeze(Pr);var zt=new Proxy(Pr,{get:(e,t)=>{if(t in e)return e[t];let i=ut().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&kt(`THREE.${t}`,"no-op proxy"),qt)},has:(e,t)=>{if(t in e)return!0;let i=ut().authorNamespace;return!!(i&&typeof t=="string"&&t in i)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),fe=ut();if(fe.threeNamespace=zt,fe.workerExtensionInstallers)for(let e of fe.workerExtensionInstallers)e(zt,fe);var Yt={name:"three_author",THREE:zt},_s=Yt,At=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof At.THREE>"u"&&(At.THREE=zt),typeof At.requestAnimationFrame!="function"&&(At.requestAnimationFrame=e=>(typeof e=="function"&&typeof At.__three_live_raf_cb__!="function"&&(At.__three_live_raf_cb__=e),At.__three_live_in_step__||kt("requestAnimationFrame","single-frame static evaluation"),0)),typeof At.cancelAnimationFrame!="function"&&(At.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=zt,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=Yt,e.ThreeLivePlugins.three_author=Yt,e.ThreeLivePlugins["three-author"]=Yt}var Es=zt;export{ke as AmbientLight,Ne as BoxGeometry,gt as BufferAttribute,ft as BufferGeometry,ze as Camera,yr as CapsuleGeometry,Ii as CatmullRomCurve3,br as CircleGeometry,Ki as Clock,Rt as Color,Ai as ConeGeometry,Li as CubicBezierCurve3,Ft as Curve3,De as CylinderGeometry,ki as DataTexture,Hi as DirectionalLight,gr as DodecahedronGeometry,wr as EdgesGeometry,_e as Euler,wi as Float32BufferAttribute,$i as Group,Ke as HemisphereLight,dr as IcosahedronGeometry,Fe as InstancedMesh,Le as LatheGeometry,Xt as Light,$t as Line,me as LineBasicMaterial,Ni as LineCurve3,xr as LineDashedMaterial,Tr as LineLoop,Sr as LineSegments,Wt as MAX_INSTANCES_PER_MESH,Mt as Material,Mi as MathUtils,xi as Matrix3,Ot as Matrix4,Et as Mesh,zi as MeshBasicMaterial,Vi as MeshLambertMaterial,Oi as MeshPhongMaterial,Bi as MeshPhysicalMaterial,jt as MeshStandardMaterial,Ct as Object3D,pr as OctahedronGeometry,ji as PerspectiveCamera,Ri as PlaneGeometry,Ue as PointLight,Rr as Points,qe as PointsMaterial,Cs as PolyhedronFallbackGeometry,Ut as PolyhedronGeometry,Di as QuadraticBezierCurve3,Ee as Quaternion,cr as RawShaderMaterial,Ar as RectAreaLight,Xe as RingGeometry,Ve as Scene,Nt as SceneQuotaValidator,We as ShaderMaterial,Ci as SphereGeometry,Cr as SpotLight,zt as THREE,mr as TetrahedronGeometry,le as Texture,Ui as TextureLoader,Pi as TorusGeometry,Ei as TorusKnotGeometry,Fi as TubeGeometry,Ti as Uint16BufferAttribute,Si as Uint32BufferAttribute,Tt as Vector2,Y as Vector3,bi as Vector4,Xi as WebGLRenderer,Mr as WireframeGeometry,lr as authorScriptRunner,He as buildSandboxWorkerSource,ur as clearAuthorWarnings,Es as default,Oe as exportSceneToCanvas3D,Be as exportSceneToGLB,Wi as exportSceneToUSDZ,yi as generateUSDZ,tr as getAllowClientScripts,hr as getAuthorWarnings,$e as getSandboxEngineSrc,Qi as getSandboxIframeSrc,Pe as glbToUSDZ,Bt as isAllowedSandboxEngineUrl,qt as noopProxy,Ht as sceneToCanvas3D,ie as sceneToGLB,ne as sceneToUSDZ,ys as setAllowClientScripts,fs as setSandboxEngineSrc,ds as setSandboxIframeSrc,Yt as threeAuthorPlugin,_s as threeMicroPlugin,Ji as toTrustedWorkerScriptURL,je as validateSandboxWorkerMessage,kt as warnUnsupported};
360
+ })();`);m=null;let R=D(u,T,S,A);R&&typeof R.toGLB=="function"&&(T=R)}if(!x){u.SceneQuotaValidator&&u.SceneQuotaValidator.validate(T);let D=T.toGLB(),R=D instanceof ArrayBuffer?D:D.buffer.slice(D.byteOffset,D.byteOffset+D.byteLength);w({type:"3D_MODEL_READY",glbBuffer:R},[R])}h({type:"DONE",nonce:n})}catch(T){d(T&&T.message||T)}},h({type:"READY",nonce:n})}function ni(t,e,i){let r=i?.allowedScriptUrl??null,n=i?.allowClientScripts??r===null,s={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:n,revoked:Os},a=(ge().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${$s.toString()})(${JSON.stringify(s)},[${a}],(${di.toString()}));`}function br(t){t.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),t.onToast?.("Security Error: script timed out and was stopped.")}var ze=0;function xr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Vs(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var zs=1024,Bs=256;function vr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let i=t[e];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function ai(t,e){if(!t||typeof t!="object")return null;let i=t;if(i.nonce!==e)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zs)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let n of r)if(!vr(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let n=Object.keys(r);if(n.length>1e3)return null;let s=Object.create(null),a=r;for(let o of n){if(o.length>Bs||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!vr(l))return null;s[o]=l}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Gs(t){let e=Vs(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Mr(t,e,i,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":i();return;case"ERROR":i(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Hs(t,e,i,r){let n=xr(),s=ni(e,n,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),a=document.createElement("iframe");a.setAttribute("sandbox","allow-scripts"),a.setAttribute("aria-hidden","true"),a.tabIndex=-1,a.style.display="none",a.src=i,ze++;let o=!1,l=!1,y={modelDispatched:!1},f,b=()=>{if(o||l)return;let M=a.contentWindow;!M||typeof M.postMessage!="function"||(l=!0,M.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:t.scriptUrl,texturePack:t.texturePack??null}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:t.script,texturePack:t.texturePack??null},"*"))},h=()=>{},d=M=>{if(o||!a.contentWindow||M.source!==a.contentWindow)return;let m=M.data;if(m&&typeof m=="object"&&m.type==="IFRAME_READY"){b();return}let u=ai(m,n);u&&Mr(u,r,h,y)};h=()=>{o||(o=!0,f!==void 0&&clearTimeout(f),ze=Math.max(0,ze-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},f=setTimeout(()=>{o||(h(),br(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),a.onload=()=>{b()},a.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let v=document.body||document.documentElement;if(!v||typeof v.appendChild!="function"){h();let M=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(M),M}return v.appendChild(a),{terminate:h}}function wr(t,e,i,r){if(e==="worker"&&typeof Worker>"u")return r("SecurityError: Web Workers are unavailable for sandboxed execution.","Security Error: Web Workers unavailable.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("SecurityError: DOM unavailable for iframe sandbox execution.","Security Error: DOM unavailable for iframe sandbox.");if(ze>=32)return r(`SecurityError: ${ze} workers running, meeting SECURITY_3D_MAX_CONCURRENT_TASKS (32).`,"Security Error: too many concurrent sandboxed scripts.");let n;try{n=Ds()}catch(h){let d=h instanceof Error?h.message:String(h);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Fs()}catch(d){let v=d instanceof Error?d.message:String(d);return r(v,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Hs(t,n,h,i))}catch(d){return Promise.reject(d)}}let s=xr(),a=ni(n,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let h=new Blob([a],{type:"application/javascript"}),d=URL.createObjectURL(h);try{let v=dr(d);o=new Worker(v)}finally{URL.revokeObjectURL(d)}}catch(h){let d=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}ze++;let l=!1,y={modelDispatched:!1},f,b=()=>{l||(l=!0,f!==void 0&&clearTimeout(f),ze=Math.max(0,ze-1),o.terminate())};return f=setTimeout(()=>{l||(b(),br(i))},3e3),o.onmessage=h=>{let d=ai(h.data,s);d&&Mr(d,i,b,y)},o.onerror=h=>{b(),i.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:s,texturePack:t.texturePack??null}):o.postMessage({type:"EXECUTE",script:t.script,nonce:s,texturePack:t.texturePack??null}),Promise.resolve({terminate:b})}function Sr(t,e){return t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox="${t}"; require "worker" or "iframe".`,`Security Error: sandbox="${t}" is not permitted.`):null}var Tr=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},Ar={execute(t,e,i,r){let n=Tr(i),s=Sr(e,n);if(s)return s;try{Gs(t)}catch(a){let o=a instanceof Error?a.message:String(a);return n(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??yr()?wr({kind:"script",script:t,texturePack:r?.texturePack},e,i,n):n(rs,ss)},executeUrl(t,e,i,r){let n=Tr(i),s=Sr(e,n);if(s)return s;let a;try{a=Us(t)}catch(o){let l=o instanceof Error?o.message:String(o);return n(l,"Security Error: disallowed scene script URL.")}return wr({kind:"url",scriptUrl:a,texturePack:r?.texturePack},e,i,n)}},St=new Set;function Be(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;St.has(i)||(St.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function _r(){return Array.from(St)}function Pr(){St.clear()}var oi=class extends it{constructor(t={}){Be("ShaderMaterial","MeshStandardMaterial");let e=t.uniforms||{},i=e.color?.value??e.uColor?.value??e.diffuse?.value??t.color;super({color:i!==void 0?i:8421504,opacity:e.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=e}},Cr=oi,We=class extends Me{constructor(t=[],e=[],i=1,r=0){super();let n=Number(i)||1,s=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),a=s+1,o=[],l=[],y=[],f=[],b=new ee,h=new ee,d=new ee,v=(u,g)=>g.set(t[u*3]||0,t[u*3+1]||0,t[u*3+2]||0),M=(u,g)=>{let p=u.clone().normalize();o.push(p.x*n,p.y*n,p.z*n),l.push(g.x,g.y,g.z),y.push(Math.atan2(p.z,-p.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,p.y)))/Math.PI)},m=(u,g,p)=>{let x=o.length/3,w=s===0?new ee().subVectors(p,g).cross(new ee().subVectors(u,g)).normalize():null;M(u,w||u.clone().normalize()),M(g,w||g.clone().normalize()),M(p,w||p.clone().normalize()),f.push(x,x+1,x+2)};for(let u=0;u<e.length;u+=3){v(e[u],b),v(e[u+1],h),v(e[u+2],d);let g=[];for(let p=0;p<=a;p++){g[p]=[];let x=b.clone().lerp(d,p/a),w=h.clone().lerp(d,p/a),_=a-p;for(let N=0;N<=_;N++)g[p][N]=_===0?x.clone():x.clone().lerp(w,N/_)}for(let p=0;p<a;p++)for(let x=0;x<2*(a-p)-1;x++){let w=x>>1;(x&1)===0?m(g[p][w+1],g[p+1][w],g[p][w]):m(g[p][w+1],g[p+1][w+1],g[p+1][w])}}this.setFromBuffers(o,l,y,f)}},js=We,Rr=class extends We{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e)}},li=t=>Array.from(t,e=>parseInt(e,36)),Tt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Er=li("024043035052125153134142"),Lr=class extends We{constructor(t=1,e=0){super(Tt,Er,t,e)}},pe=(1+Math.sqrt(5))/2,Nr=class extends We{constructor(t=1,e=0){super([-1,pe,0,1,pe,0,-1,-pe,0,1,-pe,0,0,-1,pe,0,1,pe,0,-1,-pe,0,1,-pe,pe,0,-1,pe,0,1,-pe,0,-1,-pe,0,1],li("0b505101707a0ab1595b4ba2a7671839434232636838949524b62a867981"),t,e)}},Re=1/pe,Dr=class extends We{constructor(t=1,e=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-Re,-pe,0,-Re,pe,0,Re,-pe,0,Re,pe,-Re,-pe,0,-Re,pe,0,Re,-pe,0,Re,pe,0,-pe,0,-Re,pe,0,-Re,-pe,0,Re,pe,0,Re],li("3b737f3fd7jh7h676fh48h8aha680g8g282a0c101i0ig6a262d6df2gi2i323di19i9bib34ec4c0408b95b5jbj7j5eje4j4h1ce1e5159"),t,e)}},Ir=class extends Xt{constructor(t=1,e=1,i=4,r=8){let n=Math.max(1e-4,Number(t)||1),s=Math.max(0,Number.isFinite(Number(e))?Number(e):1)*.5,a=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let l=-1;l<=1;l+=2)for(let y=0;y<=a;y++){if(l>0&&y===0&&s===0)continue;let f=(l<0?y/a-1:y/a)*(Math.PI/2);o.push(new Pe(Math.max(0,Math.cos(f)*n),l*s+Math.sin(f)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},hi=class extends Me{constructor(t=.5,e=1,i=32,r=1,n=0,s=Math.PI*2){super();let a=Math.max(1e-4,Number(e)||1),o=Number(t),l=Number.isFinite(o)?Math.max(0,o):a*.5,y=Math.max(a,l),f=Math.min(y*.999,Math.min(a,l)),b=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),h=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),d=Number.isFinite(Number(n))?Number(n):0,v=Number.isFinite(Number(s))?Number(s):Math.PI*2,M=[],m=[],u=[],g=[];for(let p=0;p<=h;p++){let x=f+p/h*(y-f);for(let w=0;w<=b;w++){let _=d+w/b*v,N=Math.cos(_),P=Math.sin(_);if(M.push(x*N,x*P,0),m.push(0,0,1),u.push(x/y*N*.5+.5,x/y*P*.5+.5),p<h&&w<b){let E=p*(b+1)+w,T=E+b+1;x>1e-6&&g.push(E,T,E+1),g.push(T,T+1,E+1)}}}this.setFromBuffers(M,m,u,g)}},Fr=class extends hi{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},ui=class extends Ne{constructor(t={}){super({roughness:.35,metalness:.1,side:2,...t});let e=Number(t.size);this.size=Number.isFinite(e)?Math.max(.002,Math.min(2,e)):.05,this.sizeAttenuation=t.sizeAttenuation!==!1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},At=class extends Ne{constructor(t={}){super({roughness:.4,metalness:.1,side:2,...t});let e=Number(t.linewidth);this.linewidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},kr=class extends At{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function Ur(t,e){let i=t?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,n=t?.index?.array,s=Math.min(8192,Math.floor((n?n.length:i.count)/3)),a=h=>`${Math.round((r[h*3]||0)*1e4)},${Math.round((r[h*3+1]||0)*1e4)},${Math.round((r[h*3+2]||0)*1e4)}`,o=e===void 0,l=o?1:Math.cos(e*Math.PI/180),y={},f=[],b=(h,d)=>f.push(r[h*3]||0,r[h*3+1]||0,r[h*3+2]||0,r[d*3]||0,r[d*3+1]||0,r[d*3+2]||0);for(let h=0;h<s;h++){let d=n?n[h*3]:h*3,v=n?n[h*3+1]:h*3+1,M=n?n[h*3+2]:h*3+2,m=r[d*3]||0,u=r[d*3+1]||0,g=r[d*3+2]||0,p=(r[v*3]||0)-m,x=(r[v*3+1]||0)-u,w=(r[v*3+2]||0)-g,_=(r[M*3]||0)-m,N=(r[M*3+1]||0)-u,P=(r[M*3+2]||0)-g,E=x*P-w*N,T=w*_-p*P,S=p*N-x*_,A=Math.hypot(E,T,S);if(!o&&A<1e-8)continue;A>0&&(E/=A,T/=A,S/=A);let D=[d,v,M];for(let R=0;R<3;R++){let I=D[R],k=D[(R+1)%3],V=a(I),L=a(k);if(V===L)continue;let O=V<L?`${V}|${L}`:`${L}|${V}`,c=y[O];c?c.m||(c.m=1,c.nx*E+c.ny*T+c.nz*S<=l&&b(I,k)):(y[O]={va:I,vb:k,nx:E,ny:T,nz:S,m:o?1:0},o&&b(I,k))}}if(!o){let h=Object.keys(y);for(let d=0;d<h.length;d++){let v=y[h[d]];v&&!v.m&&b(v.va,v.vb)}}return new Float32Array(f)}var Or=class extends Me{constructor(t){super(),this.setAttribute("position",new Ae(Ur(t),3)),this.__isSegmentPairs=!0}},$r=class extends Me{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new Ae(Ur(t,i),3)),this.__isSegmentPairs=!0}};function Ws(t,e,i=1){let r=new Me;r.__baked=!0;let n=t?.attributes?.position;if(!n?.array||n.count<2)return r;let s=n.array,a=t.index?.array,o=t.__isSegmentPairs?"segments":e,l=a?a.length:n.count,y=Math.min(4096,Math.max(0,o==="segments"?Math.floor(l/2):o==="loop"&&l>=3?l:l-1));if(y===0)return r;t.computeBoundingBox();let f=t.boundingBox,b=f&&f.max.x>=f.min.x&&f.max.distanceTo(f.min)||1,h=Math.max(.0015,Math.min(.025,b*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),d=[],v=[],M=[],m=[];for(let u=0;u<y;u++){let g=o==="segments"?u*2:u,p=o==="segments"?u*2+1:(u+1)%l,x=a?a[g]:g,w=a?a[p]:p,_=s[x*3]||0,N=s[x*3+1]||0,P=s[x*3+2]||0,E=(s[w*3]||0)-_,T=(s[w*3+1]||0)-N,S=(s[w*3+2]||0)-P,A=Math.hypot(E,T,S);if(A<1e-6)continue;let D=E/A,R=T/A,I=S/A,k=(Math.abs(R)<.9?Math.hypot(I,D):Math.hypot(I,R))||1,V=Math.abs(R)<.9?I/k:0,L=Math.abs(R)<.9?0:-I/k,O=Math.abs(R)<.9?-D/k:R/k,c=R*O-I*L,F=I*V-D*O,C=D*L-R*V,U=d.length/3,H=[[V,L,O],[c,F,C],[-V,-L,-O],[-c,-F,-C]];for(let j=0;j<2;j++){let Y=_+j*E,q=N+j*T,ne=P+j*S;for(let ie=0;ie<4;ie++){let oe=H[ie];d.push(Y+oe[0]*h,q+oe[1]*h,ne+oe[2]*h),v.push(oe[0],oe[1],oe[2]),M.push(ie/4,j)}}for(let j=0;j<4;j++){let Y=(j+1)%4;m.push(U+j,U+Y,U+4+Y,U+j,U+4+Y,U+4+j)}}return d.length>0&&r.setFromBuffers(d,v,M,m),r}function Xs(t,e=.05){let i=new Me;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let n=r.array,s=r.count,a=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),l=[],y=[],f=[],b=[];for(let h=0;h<a;h++){let d=s<=5e3?h:Math.floor(h*s/a),v=n[d*3]||0,M=n[d*3+1]||0,m=n[d*3+2]||0,u=h*6;for(let g=0;g<6;g++){let p=Tt[g*3],x=Tt[g*3+1],w=Tt[g*3+2];l.push(v+p*o,M+x*o,m+w*o),y.push(p,x,w),f.push(.5,.5)}for(let g=0;g<24;g++)b.push(u+Er[g])}return i.setFromBuffers(l,y,f,b),i}var Ye=class extends $e{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},n=e instanceof Ne?e:i==="points"?new ui(r):new At(r),s=t instanceof Me?t:new Me;super(s,n),this.isLine=!0,this._lineMode=i,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let t=this._lineMode==="points";if(t){let e=this._sourceGeo?.attributes?.color;if(e?.array&&e.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=e.array,r=Math.min(e.count,64),n=0,s=0,a=0;for(let o=0;o<r;o++)n+=i[o*3]||0,s+=i[o*3+1]||0,a+=i[o*3+2]||0;this.material.color.setRGB(n/r,s/r,a/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?Xs(this._sourceGeo,this.material?.size??.05):Ws(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Vr=class extends Ye{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},zr=class extends Ye{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Br=class extends Ye{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},Gr=class extends Jt{constructor(t,e,i=0,r=Math.PI/3,n=0,s=2){super(t,e,i,s),this.target=new Fe,this.type="spot";let a=Number(r);this.angle=Number.isFinite(a)?Math.max(.01,Math.min(Math.PI/2,a)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},ci=class extends je{constructor(t,e,i){super(t,i),this.type="hemisphere",this.groundColor=new Ie(e??4473924),this.position.set(0,1,0)}},Hr=class extends Zt{constructor(t,e){Be("RectAreaLight","AmbientLight"),super(t,e)}},jr={Vector2:Pe,Vector3:ee,Vector4:Fi,Euler:Gt,Quaternion:bt,Matrix4:qe,Matrix3:ki,Color:Ie,MathUtils:Oi,BufferAttribute:Ae,Float32BufferAttribute:$i,Uint16BufferAttribute:Vi,Uint32BufferAttribute:zi,BufferGeometry:Me,BoxGeometry:jt,PlaneGeometry:Bi,SphereGeometry:Gi,CylinderGeometry:Wt,ConeGeometry:Hi,TorusGeometry:ji,TorusKnotGeometry:Xi,Curve:He,Curve3:He,LineCurve3:qi,QuadraticBezierCurve3:Ki,CubicBezierCurve3:Yi,CatmullRomCurve3:Zi,LatheGeometry:Xt,TubeGeometry:Ji,PolyhedronGeometry:We,IcosahedronGeometry:Nr,OctahedronGeometry:Lr,DodecahedronGeometry:Dr,TetrahedronGeometry:Rr,CapsuleGeometry:Ir,RingGeometry:hi,CircleGeometry:Fr,WireframeGeometry:Or,EdgesGeometry:$r,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,BasicShadowMap:0,PCFShadowMap:1,PCFSoftShadowMap:2,VSMShadowMap:3,Texture:Mt,DataTexture:Qi,TextureLoader:er,Material:Ne,MeshStandardMaterial:it,MeshBasicMaterial:tr,MeshLambertMaterial:ir,MeshPhongMaterial:rr,MeshPhysicalMaterial:sr,PointsMaterial:ui,LineBasicMaterial:At,LineDashedMaterial:kr,ShaderMaterial:oi,RawShaderMaterial:Cr,Object3D:Fe,Group:nr,Mesh:$e,InstancedMesh:Kt,Line:Ye,LineLoop:Vr,LineSegments:zr,Points:Br,LightShadow:Yt,Light:je,AmbientLight:Zt,DirectionalLight:or,PointLight:Jt,SpotLight:Gr,HemisphereLight:ci,RectAreaLight:Hr,Camera:Qt,PerspectiveCamera:lr,Scene:ei,WebGLRenderer:ur,Clock:mr,SceneQuotaValidator:Ve,exportSceneToCanvas3D:ti,exportSceneToGLB:ii,exportSceneToUSDZ:hr,generateUSDZ:Ii,glbToUSDZ:Bt,sceneToCanvas3D:Qe,sceneToGLB:pt,sceneToUSDZ:yt,authorScriptRunner:Ar,warnUnsupported:Be,getAuthorWarnings:_r,clearAuthorWarnings:Pr};Object.freeze(Ve),Object.freeze(Ve.prototype),Object.freeze(ei.prototype),Object.freeze(jr);var Xe=new Proxy(jr,{get:(t,e)=>{if(e in t)return t[e];let i=ge().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Be(`THREE.${e}`,"no-op proxy"),st)},has:(t,e)=>{if(e in t)return!0;let i=ge().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),_t=ge();if(_t.threeNamespace=Xe,_t.workerExtensionInstallers)for(let t of _t.workerExtensionInstallers)t(Xe,_t);var at={name:"three_author",THREE:Xe},qs=at,ke=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof ke.THREE>"u"&&(ke.THREE=Xe),typeof ke.requestAnimationFrame!="function"&&(ke.requestAnimationFrame=t=>(typeof t=="function"&&typeof ke.__three_live_raf_cb__!="function"&&(ke.__three_live_raf_cb__=t),ke.__three_live_in_step__||Be("requestAnimationFrame","single-frame static evaluation"),0)),typeof ke.cancelAnimationFrame!="function"&&(ke.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=Xe,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=at,t.ThreeLivePlugins.three_author=at,t.ThreeLivePlugins["three-author"]=at}var Ks=Xe;export{Zt as AmbientLight,jt as BoxGeometry,Ae as BufferAttribute,Me as BufferGeometry,Qt as Camera,Ir as CapsuleGeometry,Zi as CatmullRomCurve3,Fr as CircleGeometry,mr as Clock,Ie as Color,Hi as ConeGeometry,Yi as CubicBezierCurve3,He as Curve3,Wt as CylinderGeometry,Qi as DataTexture,or as DirectionalLight,Dr as DodecahedronGeometry,$r as EdgesGeometry,Gt as Euler,$i as Float32BufferAttribute,nr as Group,ci as HemisphereLight,Nr as IcosahedronGeometry,Kt as InstancedMesh,Xt as LatheGeometry,je as Light,Yt as LightShadow,Ye as Line,At as LineBasicMaterial,qi as LineCurve3,kr as LineDashedMaterial,Vr as LineLoop,zr as LineSegments,rt as MAX_INSTANCES_PER_MESH,Ne as Material,Oi as MathUtils,ki as Matrix3,qe as Matrix4,$e as Mesh,tr as MeshBasicMaterial,ir as MeshLambertMaterial,rr as MeshPhongMaterial,sr as MeshPhysicalMaterial,it as MeshStandardMaterial,Fe as Object3D,Lr as OctahedronGeometry,lr as PerspectiveCamera,Bi as PlaneGeometry,Jt as PointLight,Br as Points,ui as PointsMaterial,js as PolyhedronFallbackGeometry,We as PolyhedronGeometry,Ki as QuadraticBezierCurve3,bt as Quaternion,Cr as RawShaderMaterial,Hr as RectAreaLight,hi as RingGeometry,ei as Scene,Ve as SceneQuotaValidator,oi as ShaderMaterial,Gi as SphereGeometry,Gr as SpotLight,Xe as THREE,Rr as TetrahedronGeometry,Mt as Texture,er as TextureLoader,ji as TorusGeometry,Xi as TorusKnotGeometry,Ji as TubeGeometry,Vi as Uint16BufferAttribute,zi as Uint32BufferAttribute,Pe as Vector2,ee as Vector3,Fi as Vector4,ur as WebGLRenderer,Or as WireframeGeometry,Ar as authorScriptRunner,ni as buildSandboxWorkerSource,Pr as clearAuthorWarnings,Ks as default,ti as exportSceneToCanvas3D,ii as exportSceneToGLB,hr as exportSceneToUSDZ,Ii as generateUSDZ,yr as getAllowClientScripts,_r as getAuthorWarnings,ri as getSandboxEngineSrc,gr as getSandboxIframeSrc,Bt as glbToUSDZ,Ke as isAllowedSandboxEngineUrl,st as noopProxy,Qe as sceneToCanvas3D,pt as sceneToGLB,yt as sceneToUSDZ,ks as setAllowClientScripts,Ns as setSandboxEngineSrc,Is as setSandboxIframeSrc,at as threeAuthorPlugin,qs as threeMicroPlugin,dr as toTrustedWorkerScriptURL,ai as validateSandboxWorkerMessage,Be as warnUnsupported};