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
- */var Sn=Object.defineProperty,zr=Object.getOwnPropertyDescriptor,Gr=Object.getOwnPropertyNames,Hr=Object.prototype.hasOwnProperty,Xr=(e,t)=>{for(var i in t)Sn(e,i,{get:t[i],enumerable:!0})},$r=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Gr(t))!Hr.call(e,s)&&s!==i&&Sn(e,s,{get:()=>t[s],enumerable:!(r=zr(t,s))||r.enumerable});return e},jr=e=>$r(Sn({},"__esModule",{value:!0}),e),Ii={};Xr(Ii,{AmbientLight:()=>mt,BoxGeometry:()=>ot,BufferAttribute:()=>be,BufferGeometry:()=>me,Camera:()=>ft,CapsuleGeometry:()=>mn,CatmullRomCurve3:()=>jt,CircleGeometry:()=>hn,Clock:()=>sn,Color:()=>Te,ConeGeometry:()=>Vt,CubicBezierCurve3:()=>$t,Curve3:()=>Ie,CylinderGeometry:()=>at,DataTexture:()=>Kt,DirectionalLight:()=>tn,DodecahedronGeometry:()=>ln,EdgesGeometry:()=>pn,Euler:()=>it,Float32BufferAttribute:()=>Ft,Group:()=>en,HemisphereLight:()=>yt,IcosahedronGeometry:()=>un,InstancedMesh:()=>lt,LatheGeometry:()=>ct,Light:()=>ze,Line:()=>ke,LineBasicMaterial:()=>Ye,LineCurve3:()=>Ht,LineDashedMaterial:()=>fn,LineLoop:()=>bn,LineSegments:()=>gn,MAX_INSTANCES_PER_MESH:()=>ut,Material:()=>Me,MathUtils:()=>Sr,Matrix3:()=>Pt,Matrix4:()=>Fe,Mesh:()=>Re,MeshBasicMaterial:()=>qt,MeshLambertMaterial:()=>Zt,MeshPhongMaterial:()=>Jt,MeshPhysicalMaterial:()=>Qt,MeshStandardMaterial:()=>Ve,Object3D:()=>_e,OctahedronGeometry:()=>cn,PerspectiveCamera:()=>nn,PlaneGeometry:()=>Ot,PointLight:()=>ht,Points:()=>yn,PointsMaterial:()=>gt,PolyhedronFallbackGeometry:()=>Ai,PolyhedronGeometry:()=>Ne,QuadraticBezierCurve3:()=>Xt,Quaternion:()=>st,RawShaderMaterial:()=>kr,RectAreaLight:()=>Br,RingGeometry:()=>bt,Scene:()=>dt,SceneQuotaValidator:()=>Ee,ShaderMaterial:()=>pt,SphereGeometry:()=>Bt,SpotLight:()=>xn,THREE:()=>He,TetrahedronGeometry:()=>an,Texture:()=>We,TextureLoader:()=>Yt,TorusGeometry:()=>zt,TorusKnotGeometry:()=>Gt,TubeGeometry:()=>Wt,Uint16BufferAttribute:()=>kt,Uint32BufferAttribute:()=>Ut,Vector2:()=>Se,Vector3:()=>Z,Vector4:()=>Lt,WebGLRenderer:()=>rn,WireframeGeometry:()=>dn,authorScriptRunner:()=>Lr,buildSandboxWorkerSource:()=>Vn,clearAuthorWarnings:()=>Fr,default:()=>Di,exportSceneToCanvas3D:()=>kn,exportSceneToGLB:()=>Un,exportSceneToUSDZ:()=>Ar,generateUSDZ:()=>Pn,getAllowClientScripts:()=>Cr,getAuthorWarnings:()=>Pr,getSandboxEngineSrc:()=>On,getSandboxIframeSrc:()=>Rr,glbToUSDZ:()=>Rt,isAllowedSandboxEngineUrl:()=>Ke,noopProxy:()=>nt,sceneToCanvas3D:()=>je,sceneToGLB:()=>Qe,sceneToUSDZ:()=>et,setAllowClientScripts:()=>gi,setSandboxEngineSrc:()=>fi,setSandboxIframeSrc:()=>pi,threeAuthorPlugin:()=>rt,threeMicroPlugin:()=>Ci,toTrustedWorkerScriptURL:()=>Er,validateSandboxWorkerMessage:()=>zn,warnUnsupported:()=>Ge}),module.exports=jr(Ii);function Gn(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)}}),O=f("variable/set",{configuration:{variable:P},values:{value:g(W)}}),Y=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[O].flows={out:{node:f("flow/branch",{values:{condition:g(j)},flows:{true:{node:Y},false:{node:U}}})}},A.push(O)}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}}}),O=f("variable/set",{configuration:{variable:T},values:{value:g(W)}}),Y={};for(let U=0;U<d.colors.length;U++){let X=d.colors[U],V=Array.isArray(X)&&X.length>=3?[X[0],X[1],X[2],X[3]??1]:[1,1,1,1];Y[String(U)]={node:S>0?f("pointer/interpolate",{configuration:{pointer:D},values:{value:{value:V},duration:{value:S}}}):f("pointer/set",{configuration:{pointer:D},values:{value:{value:V}}})}}n[O].flows={out:{node:f("flow/switch",{values:{selection:g(P)},flows:Y})}},A.push(O)}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 Hn='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).',Xn="Security Error: client-side scripts require allow-client-scripts opt-in.",vt="__THREE_LIVE_REGISTRY__";function ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[vt]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,vt,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[vt]=t}}return e[vt]}var he=ae().plugins;function $n(e){let t=ae().plugins;t.some(i=>i.name===e.name)||t.push(e),e.onRegister?.()}function jn(){return ae().plugins}function ce(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function Mt(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 Xe(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 de(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 qe(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 Ae(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 Wn(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 Tn(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 Kn(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,O=M*v-x*p,Y=Math.hypot(j,W,O)||1;return b.normal=[j/Y,W/Y,O/Y],!0}return!1}function Yn(e,t){let i=Array.isArray(e?.nodes)?e.nodes.length:0,r=[];for(let c=0;c<i;c++)r.push(ce());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=ce();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];qe(u,M,w,x)}let b=r[c];if(f?de(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 _n(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 qn(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 wt(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 Qn=["neutral","reinhard","none","aces","agx"];function Rn(e){let t=String(e??"").trim().toLowerCase();return Qn.includes(t)?t:"neutral"}function Kr(e){return Qn.indexOf(Rn(e))}function Yr(e){return new TextDecoder().decode(e)}var er=ae().decoders;function qr(e,t){er.set(e.toLowerCase(),t)}function $e(e){return er.get(e.toLowerCase())}function tr(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=Yr(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")&&!$e("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)&&!$e("meshopt"))throw new Error(`Model requires ${y}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(l.includes("KHR_texture_basisu")&&!$e("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 he)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 Je(e){if(Zr(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return tr(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var nr=`#version 300 es
16
+ */var On=Object.defineProperty,ni=Object.getOwnPropertyDescriptor,ri=Object.getOwnPropertyNames,ii=Object.prototype.hasOwnProperty,oi=(t,e)=>{for(var i in e)On(t,i,{get:e[i],enumerable:!0})},si=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ri(e))!ii.call(t,n)&&n!==i&&On(t,n,{get:()=>e[n],enumerable:!(r=ni(e,n))||r.enumerable});return t},ai=t=>si(On({},"__esModule",{value:!0}),t),Ki={};oi(Ki,{AmbientLight:()=>St,BoxGeometry:()=>bt,BufferAttribute:()=>we,BufferGeometry:()=>xe,Camera:()=>_t,CapsuleGeometry:()=>_n,CatmullRomCurve3:()=>sn,CircleGeometry:()=>An,Clock:()=>yn,Color:()=>Pe,ConeGeometry:()=>Qt,CubicBezierCurve3:()=>on,Curve3:()=>ze,CylinderGeometry:()=>gt,DataTexture:()=>cn,DirectionalLight:()=>pn,DodecahedronGeometry:()=>wn,EdgesGeometry:()=>Rn,Euler:()=>pt,Float32BufferAttribute:()=>Kt,Group:()=>fn,HemisphereLight:()=>Lt,IcosahedronGeometry:()=>Sn,InstancedMesh:()=>vt,LatheGeometry:()=>yt,Light:()=>Ge,LightShadow:()=>Mt,Line:()=>Ke,LineBasicMaterial:()=>nt,LineCurve3:()=>nn,LineDashedMaterial:()=>Tn,LineLoop:()=>Ln,LineSegments:()=>Cn,MAX_INSTANCES_PER_MESH:()=>xt,Material:()=>Ce,MathUtils:()=>Br,Matrix3:()=>Xt,Matrix4:()=>We,Mesh:()=>Oe,MeshBasicMaterial:()=>ln,MeshLambertMaterial:()=>mn,MeshPhongMaterial:()=>hn,MeshPhysicalMaterial:()=>dn,MeshStandardMaterial:()=>qe,Object3D:()=>ke,OctahedronGeometry:()=>Mn,PerspectiveCamera:()=>bn,PlaneGeometry:()=>Zt,PointLight:()=>wt,Points:()=>Dn,PointsMaterial:()=>Rt,PolyhedronFallbackGeometry:()=>Hi,PolyhedronGeometry:()=>He,QuadraticBezierCurve3:()=>rn,Quaternion:()=>Qe,RawShaderMaterial:()=>Jr,RectAreaLight:()=>Nn,RingGeometry:()=>Et,Scene:()=>At,SceneQuotaValidator:()=>Ue,ShaderMaterial:()=>Tt,SphereGeometry:()=>Jt,SpotLight:()=>In,THREE:()=>Ze,TetrahedronGeometry:()=>vn,Texture:()=>et,TextureLoader:()=>un,TorusGeometry:()=>en,TorusKnotGeometry:()=>tn,TubeGeometry:()=>an,Uint16BufferAttribute:()=>Yt,Uint32BufferAttribute:()=>qt,Vector2:()=>Ee,Vector3:()=>Q,Vector4:()=>Wt,WebGLRenderer:()=>gn,WireframeGeometry:()=>En,authorScriptRunner:()=>Yr,buildSandboxWorkerSource:()=>or,clearAuthorWarnings:()=>Zr,default:()=>Xi,exportSceneToCanvas3D:()=>tr,exportSceneToGLB:()=>nr,exportSceneToUSDZ:()=>Gr,generateUSDZ:()=>Jn,getAllowClientScripts:()=>$r,getAuthorWarnings:()=>qr,getSandboxEngineSrc:()=>rr,getSandboxIframeSrc:()=>jr,glbToUSDZ:()=>zt,isAllowedSandboxEngineUrl:()=>tt,noopProxy:()=>dt,sceneToCanvas3D:()=>Je,sceneToGLB:()=>lt,sceneToUSDZ:()=>mt,setAllowClientScripts:()=>Pi,setSandboxEngineSrc:()=>Ci,setSandboxIframeSrc:()=>Ii,threeAuthorPlugin:()=>ft,threeMicroPlugin:()=>Wi,toTrustedWorkerScriptURL:()=>Hr,validateSandboxWorkerMessage:()=>sr,warnUnsupported:()=>Xe}),module.exports=ai(Ki);function cr(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 F=R.action||"interpolate",k=typeof R.duration=="number"?R.duration:.35;if(F==="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),I=b("variable/get",{configuration:{variable:c}}),C=b("math/not",{values:{a:d(I)}}),U=b("variable/set",{configuration:{variable:c},values:{value:d(C)}}),j=b("pointer/interpolate",{configuration:{pointer:O},values:{value:{value:Array.isArray(R.to)?R.to:L},duration:{value:k}}}),H=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(I)},flows:{true:{node:j},false:{node:H}}})}},S.push(U)}else if(F==="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(F==="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(F==="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)}}),I=b("variable/set",{configuration:{variable:L},values:{value:d(c)}});s[I].flows={out:{node:b("pointer/set",{configuration:{pointer:`/nodes/${V}/extensions/KHR_node_visibility/visible`},values:{value:d(O)}})}},S.push(I)}else if(F==="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}}),I=b("math/add",{values:{a:d(c),b:{value:1}}}),C=b("math/rem",{values:{a:d(I),b:{value:R.colors.length}}}),U=b("variable/set",{configuration:{variable:O},values:{value:d(C)}}),j={};for(let H=0;H<R.colors.length;H++){let Y=R.colors[H],q=Array.isArray(Y)&&Y.length>=3?[Y[0],Y[1],Y[2],Y[3]??1]:[1,1,1,1];j[String(H)]={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:j})}},S.push(U)}else if(F==="playAnimation")S.push(b("animation/start",{configuration:{animation:R.animation??R.clip??0}}));else if(F==="stopAnimation")S.push(b("animation/stop"));else if(F==="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 ur='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).',lr="Security Error: client-side scripts require allow-client-scripts opt-in.",Dt="__THREE_LIVE_REGISTRY__";function de(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Dt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Dt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Dt]=e}}return t[Dt]}var ge=de().plugins;function mr(t){let e=de().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function hr(){return de().plugins}function ve(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Bn(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 it(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 Me(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 ot(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 Fe(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 dr(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 Vn(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 fr(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,F=S*(A*N+D*P+R*E);if(F<-m||F>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||F+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 I=g*_-p*w,C=p*x-u*_,U=u*w-g*x,j=Math.hypot(I,C,U)||1;return M.normal=[I/j,C/j,U/j],!0}return!1}function zn(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];ot(v,u,m,g)}let M=r[f];if(b?Me(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 Gn(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 F=h[w+S]-R&255;g[S]=F,T+=F<128?F:256-F}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 I=p.indexOf(c);A.push(I>=0?S[I]: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,F=new Uint8Array(R),k=0;for(let c=0;c<N.length;c++){let I=N[c];k=k+3&-4,F.set(A[I],k),u[I].byteOffset=k,u[I].byteLength=A[I].length,k+=A[I].length}for(let c=0;c<x.length;c++){let I=S[p.length+c];k=k+3&-4,F.set(I,k);let C=g[x[c]];delete C.uri,C.mimeType="image/png",C.bufferView=u.length,u.push({buffer:0,byteOffset:k,byteLength:I.length}),k+=I.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(F,28+L),O.length<h.length?O:h})}}}var ci={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Hn(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=ci[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 pr(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 st(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 gr=["neutral","reinhard","none","aces","agx"];function Wn(t){let e=String(t??"").trim().toLowerCase();return gr.includes(e)?e:"neutral"}function ui(t){return gr.indexOf(Wn(t))}function li(t){return new TextDecoder().decode(t)}var yr=de().decoders;function mi(t,e){yr.set(t.toLowerCase(),e)}function Ft(t){return yr.get(t.toLowerCase())}function xr(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=li(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)&&!Ft(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 ge)h.onParseGLB?.(b);return b}function Yn(t,e=zn(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 hi(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 Ut(t){if(hi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return xr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Xn=`#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
+ }`,di=`#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
+ }`,fi=`#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);}`,ei=`#version 300 es
210
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,pi=`#version 300 es
246
211
  precision highp float;
247
212
  uniform vec4 uColorId;
248
213
  out vec4 fragColor;
249
- void main(){fragColor=uColorId;}`;function Cn(e,t,i){let r={};for(let s of i)r[s]=e.getUniformLocation(t,s);return r}var Zn=["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 rr(){let e=ae().xrDepthShader;return{fs:Jr.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...Zn,...e.uniformNames]:Zn}}function ti(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 An(e,t,i,r,s,n,o,a){if(r===void 0||!t.accessors?.[r])return null;let h=_n(t,i,t.accessors[r],n);if(!h)return null;a&&(h=h.slice(),qn(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 En(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ir(e,t,i){let r=rr(),s=nr,n=r.fs,o=!1;for(let h of he)if(h.onResolveShader){let l=h.onResolveShader(t,i,s,n);l&&(s=l.vs,n=l.fs,o=!0)}let a=o?wt(e,s,n):null;return{program:a,uniforms:a?Cn(e,a,r.uniforms):null}}function ni(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 ri(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 Hi=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),sr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function St(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function or(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 ar(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 Jn(e,t,i=sr,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ii(e,t,i,r,s)}catch(n){let o=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;ar(e,o,s.gpuTextures),s.vao&&e.deleteVertexArray(s.vao);for(let a of s.buffers)e.deleteBuffer(a);throw n}}function ii(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=$e("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=Yn(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=ti(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]:ce(),S=new Float32Array(9);Ae(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,O=P.SCALE!==void 0?n.accessors?.[P.SCALE]:null,Y=P._COLOR_0!==void 0?n.accessors?.[P._COLOR_0]:null,U=Number(j?.count??W?.count??O?.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,xt)=>{if(!z||z.bufferView===void 0||!n.bufferViews?.[z.bufferView])return null;let te=z.componentType??5126,ie=ee=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${ee})`),null);if(te!==5120&&te!==5121&&te!==5122&&te!==5123&&te!==5126)return ie(`componentType ${te}`);if(!(Number(z.count)>=U))return ie(`count ${z.count} < ${U}`);let J=null;try{J=_n(n,a,{...z,count:U},xt)}catch{return ie("out of bounds")}return!J||!J.every(Number.isFinite)?ie("non-finite value"):J},V=X(j,3),G=X(W,4),F=X(O,3),H=Y?.type==="VEC4"?4:3,B=X(Y,H),K=new Float32Array(U*16),q=ce();for(let z=0;z<U;z++){let xt=V?[V[z*3],V[z*3+1],V[z*3+2]]:[0,0,0],te=G?[G[z*4],G[z*4+1],G[z*4+2],G[z*4+3]]:[0,0,0,1],ie=F?[F[z*3],F[z*3+1],F[z*3+2]]:[1,1,1];qe(q,te,xt,ie),K.set(q,z*16)}if(D.instanceMatrices=K,B){let z=new Float32Array(U*3);for(let xt=0;xt<U;xt++)z[xt*3]=B[xt*H],z[xt*3+1]=B[xt*H+1],z[xt*3+2]=B[xt*H+2];D.instanceColors=z}}}for(let P of k.primitives||[]){if(P.extensions?.KHR_draco_mesh_compression){let J=$e("draco");J&&J.decodePrimitive(n,P,a)}let j=[],W=e.createVertexArray();s.vao=W,s.buffers=j,e.bindVertexArray(W);let O=ni(e,D,j),Y=n.accessors[P.attributes.POSITION],U=Number(Y?.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,Y?.min&&Y?.max){let J=ee=>{for(let re=0;re<3;re++){let ge=ee[12+re],se=ee[12+re];for(let ne=0;ne<3;ne++){let ue=ee[ne*4+re]*Y.min[ne],le=ee[ne*4+re]*Y.max[ne];ge+=ue<le?ue:le,se+=ue>le?ue:le}ge<M[re]&&(M[re]=ge),se>x[re]&&(x[re]=se)}};if(D.instanceMatrices&&D.instanceMatrices.length>=16){let ee=D.instanceMatrices.length>>4,re=ce();for(let ge=0;ge<ee;ge++){let se=D.instanceMatrices.subarray(ge*16,ge*16+16);de(re,$,se),J(re)}}else J($)}let X=An(e,n,a,P.attributes.POSITION,0,3,j);An(e,n,a,P.attributes.NORMAL,1,3,j),An(e,n,a,P.attributes.TEXCOORD_0,2,2,j,ri(n,P));let V=0,G=5123,F=null;if(P.indices!==void 0){let J=n.accessors[P.indices],ee=(n.bufferViews[J.bufferView].byteOffset||0)+(J.byteOffset||0);if(V=Number(J.count??0),!Number.isFinite(V)||V<0||p+V>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);p+=V,G=J.componentType===5125?5125:5123;let re=e.createBuffer();j.push(re),e.bindBuffer(34963,re),J.componentType===5125?F=new Uint32Array(a,ee,J.count):J.componentType===5121?F=Uint16Array.from(new Uint8Array(a,ee,J.count)):F=ee%2===0?new Uint16Array(a,ee,J.count):new Uint16Array(a.slice(ee,ee+J.count*2)),e.bufferData(34963,F,35044)}else V=Y.count;let H={};for(let J of he)if(J.onBuildPrimitiveVAO){let ee=J.onBuildPrimitiveVAO(e,W,P,n,a);ee&&(H[J.name]=ee)}e.bindVertexArray(null);let B=n.materials&&P.material!==void 0?n.materials[P.material]:null,{program:K,uniforms:q}=ir(e,P,B),z=or(B,w),xt=!!(B?.extensions?.KHR_materials_transmission||H.materials?.isTransmissive),te=P.extensions?.KHR_materials_variants?.mappings,ie=Array.isArray(te)?te.filter(J=>J&&typeof J.material=="number"&&Array.isArray(J.variants)).map(J=>({material:J.material|0,variants:J.variants.map(ee=>Number(ee)|0)})):void 0;D.primitives.push({vao:W,instanced:O,indexCount:V,indexType:G,...z,positions:X,indices:F,buffers:j,materialIndex:P.material,defaultMaterialIndex:P.material,variantMappings:ie,primitiveDef:P,programCache:new Map([[P.material??-1,{program:K,uniforms:q}]]),pluginData:H,customProgram:K,customUniforms:q,isTransmissive:xt})}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 he)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 Ze(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 Tt=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=ce(),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=ce(),this.viewMatrix=ce(),this.activeViewMatrix=null,this.modelMatrix=ce(),this.mvpMatrix=ce(),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:ce(),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=En(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=Rn(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){qr(e,t)}static getDecoder(e){return $e(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=rr();this.renderProg=wt(e,nr,t.fs),this.pickProg=wt(e,Qr,ei),this.uRender=Cn(e,this.renderProg,t.uniforms),this.uPick=Cn(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of he)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}=Jn(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 he)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=En(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(tr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of he)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Je(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let i=Je(e),{meshes:r}=Jn(this.gl,i,sr,()=>this.render());if(t)for(let s of r)s.transform[12]+=t[0],s.transform[13]+=t[1],s.transform[14]+=t[2],Ae(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),Ae(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=En(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=Rn(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of he)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of he)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,or(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=ir(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 he)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=ce();de(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]=Ze(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=ce();de(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),de(this.modelMatrix,this.modelRootMatrix,R.transform);let A=R.instanceMatrices;if(A&&A.length>=16){let E=A.length>>4,C=ce();for(let d of R.primitives){r.bindVertexArray(d.vao);for(let k=0;k<E;k++)de(C,this.modelMatrix,A.subarray(k*16,k*16+16)),de(this.mvpMatrix,o,C),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),St(r,d)}}else{de(this.mvpMatrix,o,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let E of R.primitives)r.bindVertexArray(E.vao),St(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]=Ze(this),M=ce();for(let m of a){de(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?de(this.modelMatrix,M,p.subarray(R*16,R*16+16)):this.modelMatrix.set(M),de(this.mvpMatrix,o,this.modelMatrix);let L=ce();if(!Wn(L,this.mvpMatrix))continue;let I=(h+.5)/s*2-1,N=(l+.5)/n*2-1,_=[0,0,0],A=[0,0,0];Tn(_,I,N,-1,L),Tn(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,O=j.indices,Y=Math.floor(O?O.length/3:W.length/9);for(let U=0;U<Y;U++){let X=O?O[U*3]:U*3,V=O?O[U*3+1]:U*3+1,G=O?O[U*3+2]:U*3+2;Kn(_[0],_[1],_[2],$,S,D,W[X*3],W[X*3+1],W[X*3+2],W[V*3],W[V*3+1],W[V*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],O=this.modelMatrix,Y=O[0]*P+O[4]*j+O[8]*W+O[12],U=O[1]*P+O[5]*j+O[9]*W+O[13],X=O[2]*P+O[6]*j+O[10]*W+O[14],V=Y-u,G=U-b,F=X-w,H=Math.hypot(V,G,F);if(H<f){Ae(this.normalMatrix,this.modelMatrix);let B=this.normalMatrix,K=T.normal[0],q=T.normal[1],z=T.normal[2],xt=B[0]*K+B[3]*q+B[6]*z,te=B[1]*K+B[4]*q+B[7]*z,ie=B[2]*K+B[5]*q+B[8]*z,J=Math.hypot(xt,te,ie)||1;xt/=J,te/=J,ie/=J,xt*V+te*G+ie*F>0&&(xt=-xt,te=-te,ie=-ie),c=m,f=Math.round(H*1e3)/1e3,y=[Math.round(Y*1e3)/1e3,Math.round(U*1e3)/1e3,Math.round(X*1e3)/1e3],g=[Math.round(xt*1e3)/1e3,Math.round(te*1e3)/1e3,Math.round(ie*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 he)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);Mt(this.projMatrix,this.fov,e,.1,t);let i=this.customTarget||this.bounds.center;Xe(this.viewMatrix,Ze(this),i,[0,1,0]),de(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ae(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 he)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 he)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 he)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 he)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,_]=Ze(this),A=Math.cos(this.currTheta),E=-Math.sin(this.currTheta),C=.032,d=ce(),k=ce(),$=[I-A*C,N,_-E*C],S=[L[0]-A*C*.25,L[1],L[2]-E*C*.25];Mt(d,this.fov,p/m,.1,R),Xe(k,$,S,[0,1,0]);let D=ce(),T=ce(),P=[I+A*C,N,_+E*C],j=[L[0]+A*C*.25,L[1],L[2]+E*C*.25];Mt(D,this.fov,v/m,.1,R),Xe(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=ce(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,de(o,e?.projMatrix??this.projMatrix,a);let h=ae().xrDepthShader,l=Kr(this.toneMapping),[c,f,y]=e?e.eyePos:Ze(this);for(let x of he)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):de(this.modelMatrix,this.modelRootMatrix,p.transform),de(this.mvpMatrix,o,this.modelMatrix),Ae(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 he)$.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=ce(),T=new Float32Array(9),P=[A.baseColor[0],A.baseColor[1],A.baseColor[2],A.baseColor[3]];for(let j=0;j<$;j++)de(D,this.modelMatrix,k.subarray(j*16,j*16+16)),de(this.mvpMatrix,o,D),Ae(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)),St(t,A)}else St(t,A)}}};if(M(!1),b){for(let x of he)x.onBeforeTransmissivePass?.(t,this);M(!0)}for(let x of he)x.onAfterRender?.(t,this,o,e?.eye??"none",[i,r,s,n],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ar(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 he)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()}};Tt.registerPlugin=$n,Tt.getRegisteredPlugins=jn;function si(e){return e+3&-4}var Q=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function lr(e,t){let i=t,r=1;for(;e.has(i);)i=`${t}_${r++}`;return e.add(i),i}function mr(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 oi(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 Le=(e,t,i,r)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(i,e)):r;function hr(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:Le(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function je(e,t){return fr(e,t)[0]}function fr(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,O=T.opacity??1,Y={baseColorFactor:[P,j,W,O],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)}Y.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:Y,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 V={};return T.clearcoat&&T.clearcoat>0&&(V.KHR_materials_clearcoat={clearcoatFactor:T.clearcoat,clearcoatRoughnessFactor:T.clearcoatRoughness||0}),T.sheen&&T.sheen>0&&(V.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&&(V.KHR_materials_transmission={transmissionFactor:T.transmission}),T.thickness&&T.thickness>0&&(V.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&&(V.KHR_materials_ior={ior:T.ior}),T.dispersion&&T.dispersion>0&&(V.KHR_materials_dispersion={dispersion:T.dispersion}),T.iridescence&&T.iridescence>0&&(V.KHR_materials_iridescence={iridescenceFactor:T.iridescence,iridescenceIor:T.iridescenceIOR??1.3}),Object.keys(V).length>0&&(X.extensions=V),c.push(X),D}function m(S,D){let T=new Uint8Array(S.buffer,S.byteOffset,S.byteLength),P=si(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,O){let Y=m(S,T),U=n.length,X={bufferView:Y,byteOffset:0,componentType:P,count:j,type:D};return W&&(X.min=W),O&&(X.max=O),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,O=W?.parent?W?.matrixWorld?.elements:void 0,Y=Q(O?O[12]:W?.position?.x,0),U=Q(O?O[13]:W?.position?.y,0),X=Q(O?O[14]:W?.position?.z,0),V=Y-T,G=U-P,F=X-j,H=Math.hypot(V,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?[V/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?.(),ae().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),O=Q(S.position?.z,0),Y=Q(S.quaternion?.x,0),U=Q(S.quaternion?.y,0),X=Q(S.quaternion?.z,0),V=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||O)&&(P.translation=[j,W,O]),(Y||U||X||V!==1)&&(P.rotation=[Y,U,X,V]),(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=oi(S.userData.xr);P.extensions={...P.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},ae().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 xt=[1/0,1/0,1/0],te=[-1/0,-1/0,-1/0];for(let se=0;se<z.count;se++){let ne=z.getX(se),ue=z.getY(se),le=z.getZ(se);ne<xt[0]&&(xt[0]=ne),ne>te[0]&&(te[0]=ne),ue<xt[1]&&(xt[1]=ue),ue>te[1]&&(te[1]=ue),le<xt[2]&&(xt[2]=le),le>te[2]&&(te[2]=le)}let ie={attributes:{POSITION:p(z.array,"VEC3",34962,5126,z.count,xt,te)}};if(q.attributes.normal&&(ie.attributes.NORMAL=p(q.attributes.normal.array,"VEC3",34962,5126,q.attributes.normal.count)),q.attributes.uv&&(ie.attributes.TEXCOORD_0=p(q.attributes.uv.array,"VEC2",34962,5126,q.attributes.uv.count)),q.index){let se=q.index.array instanceof Uint32Array;ie.indices=p(q.index.array,"SCALAR",34963,se?5125:5123,q.index.count)}let J=Array.isArray(S.material)?S.material[0]:S.material;J&&(ie.material=x(J));let ee=S.userData?.variants;if(ee&&typeof ee=="object"){let se=new Map;for(let ne of Object.keys(ee)){if(!ne||ne==="__proto__"||ne==="constructor"||ne==="prototype")continue;let ue=ee[ne];if(!ue||typeof ue!="object")continue;let le=w.indexOf(ne);if(le===-1&&w.length<256&&(le=w.length,w.push(ne)),le===-1)continue;let xe=x(ue),Ue=se.get(xe);Ue||(Ue=[],se.set(xe,Ue)),Ue.push(le)}if(se.size>0){let ne=[];for(let[ue,le]of se.entries())ne.push({material:ue,variants:le});ie.extensions={...ie.extensions||{},KHR_materials_variants:{mappings:ne}},h.add("KHR_materials_variants")}}let re=S;if(re.isInstancedMesh&&typeof re.count=="number"&&re.count>0&&re.instanceMatrix?.array){let se=Math.min(1e4,Math.floor(re.count)),ne=re.instanceMatrix.array,ue=new Float32Array(se*3),le=new Float32Array(se*4),xe=new Float32Array(se*3);for(let fe=0;fe<se;fe++){let{t:Be,r:Oe,s:Pi}=mr(ne,fe*16);ue[fe*3]=Be[0],ue[fe*3+1]=Be[1],ue[fe*3+2]=Be[2],le[fe*4]=Oe[0],le[fe*4+1]=Oe[1],le[fe*4+2]=Oe[2],le[fe*4+3]=Oe[3],xe[fe*3]=Pi[0],xe[fe*3+1]=Pi[1],xe[fe*3+2]=Pi[2]}let Ue={TRANSLATION:p(ue,"VEC3",0,5126,se),ROTATION:p(le,"VEC4",0,5126,se),SCALE:p(xe,"VEC3",0,5126,se)};if(re.instanceColor?.array&&re.instanceColor.array.length>=se*3){let fe=new Float32Array(re.instanceColor.array.subarray(0,se*3));Ue._COLOR_0=p(fe,"VEC3",0,5126,se)}P.extensions={...P.extensions||{},EXT_mesh_gpu_instancing:{attributes:Ue}},h.add("EXT_mesh_gpu_instancing")}let ge=o.length;o.push({primitives:[ie],name:S.name,...P.extras?{extras:P.extras}:{}}),P.mesh=ge}}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)),O=l.map(()=>new Float32Array(T*4)),Y=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),xt=Q(K.quaternion?.z,0),te=Q(K.quaternion?.w,1),ie=Math.hypot(q,z,xt,te)||1;if(q/=ie,z/=ie,xt/=ie,te/=ie,F>0){let J=(F-1)*4,ee=O[B];ee[J]*q+ee[J+1]*z+ee[J+2]*xt+ee[J+3]*te<0&&(q=-q,z=-z,xt=-xt,te=-te)}O[B][F*4]=q,O[B][F*4+1]=z,O[B][F*4+2]=xt,O[B][F*4+3]=te,Y[B][F*3]=Q(K.scale?.x,1),Y[B][F*3+1]=Q(K.scale?.y,1),Y[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),V=[],G=[];for(let F=0;F<l.length;F++){let H=j[F],B=(q,z,xt)=>q.some((te,ie)=>Math.abs(te-H[xt+ie%z])>1e-4),K=(q,z,xt,te)=>{q&&G.push({sampler:V.push({input:X(),interpolation:"LINEAR",output:p(z,xt,0,5126,T)})-1,target:{node:F,path:te}})};K(B(W[F],3,0),W[F],"VEC3","translation"),K(B(O[F],4,3),O[F],"VEC4","rotation"),K(B(Y[F],3,7),Y[F],"VEC3","scale")}G.length>0&&N.push({name:"ProceduralLoop",samplers:V,channels:G})}let _=Gn(a,o,e.userData),A=[],E=[],C=[];for(let S=0;S<a.length;S++){let D=a[S],T=hr(D.extras?.xr);if(!T)continue;let{ae:P,src:j,preset:W,volume:O,loop:Y,isGlobal:U}=T,X=D.name||`Node_${S}`,V=E.length;E.push({name:`${X}_source`,gain:O,loop:Y,autoPlay:typeof P.autoplay=="boolean"?P.autoplay:!0,...j!==void 0?{audio:A.push({uri:j})-1}:{},...W?{extras:{preset:W,pitch:Le(P.pitch,.25,4,1)}}:{}});let G=C.length,F=Le(P.refDistance,.05,100,1),H=Le(P.coneInnerAngle,0,360,360),B=Le(P.coneOuterAngle,H,360,360);C.push({name:`${X}_emitter`,type:U?"global":"positional",gain:O,sources:[V],...U?{}:{positional:{distanceModel:P.distanceModel==="linear"||P.distanceModel==="exponential"?P.distanceModel:"inverse",refDistance:F,maxDistance:Le(P.maxDistance,F,500,Math.max(F,25)),rolloffFactor:Le(P.rolloffFactor,0,10,1),coneInnerAngle:+(H*Math.PI/180).toFixed(6),coneOuterAngle:+(B*Math.PI/180).toFixed(6),coneOuterGain:Le(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 Nn(e){return new TextEncoder().encode(e)}function Qe(e,t){let{gltf:i,bin:r}=je(e,t),s=JSON.stringify(i),n=Nn(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 ai(e,t){let[i,r]=fr(e,t);return Ln(i,r)}function Ln(e,t){let i=[],r=e.gltf,s=ae().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)=>lr(y,At(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:V,buffer:G}=u(d),F=new Float32Array(G,0,V.count*3);C=new Float32Array(F.length);for(let H=0;H<V.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:V,buffer:G}=u($);k=new Float32Array(G,0,V.count*2)}let S;if(I.indices!==void 0){let{acc:V,buffer:G}=u(I.indices);S=V.componentType===5125?new Uint32Array(G,0,V.count):new Uint16Array(G,0,V.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 V=_.count;S=V>65535?new Uint32Array(V):new Uint16Array(V);for(let G=0;G<V;G++)S[G]=G}let D="DefaultMaterial",T=[.8,.8,.8],P=.5,j=0,W=0,O=0,Y=1.5,U=1,X=[0,0,0];if(I.material!==void 0&&l[I.material]){let V=l[I.material];D=g[I.material]||`Material_${I.material}`;let G=V.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=V.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(V.emissiveFactor,[0,0,0]);let K=V.extensions||{};K.KHR_materials_clearcoat&&(W=K.KHR_materials_clearcoat.clearcoatFactor??0,O=K.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof K.KHR_materials_ior?.ior=="number"&&(Y=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:O,ior:Y,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=mr(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),V=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(V,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 O=(U,X,V)=>({name:U,positions:w,indices:M,isXform:!0,xrTraits:W,timeSamples:D,translation:k,rotation:$,scale:S,children:X,...V?{invisible:!0}:{}}),Y=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,Y),V=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(V&&typeof V=="object"&&X.length>0){let G=x(V.TRANSLATION,3),F=x(V.ROTATION,4),H=x(V.SCALE,3),B=x(V._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 xt=p(G,z,[0,0,0]),te=v(F,z,[0,0,0,1]),ie=p(H,z,[1,1,1]);for(let J of X){let ee=J.color||[.8,.8,.8],re=B&&B.length>=(z+1)*3;q.push({...J,name:`${J.name}_${z}`,materialName:re?`${J.materialName}_inst_${z}`:J.materialName,color:re?[ee[0]*B[z*3],ee[1]*B[z*3+1],ee[2]*B[z*3+2]]:J.color,translation:xt,rotation:te,scale:ie})}}A(P,q),C.push(O(U,q,Y));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(O(U,G,Y))}}else{let U=[];A(P,U),C.push(O(d.name||`Group_${E}`,U,Y))}}}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 At(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 Dn(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function pe(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 Ce=(e,t,i)=>`(${pe(e)}, ${pe(t)}, ${pe(i)})`,cr=(e,t,i,r)=>`(${pe(e)}, ${pe(t)}, ${pe(i)}, ${pe(r)})`;function ur(e){let t=e.length/3,i=new Array(t);for(let r=0;r<t;r++)i[r]=Ce(e[r*3],e[r*3+1],e[r*3+2]);return i.join(", ")}function ci(e,t){let i=new Array(t);for(let r=0;r<t;r++)i[r]=`(${pe(e[r*2])}, ${pe(1-e[r*2+1])})`;return i.join(", ")}function ui(e){return Array.from(e).join(", ")}function In(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=At(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 = ${pe(i)}
214
+ void main(){fragColor=uColorId;}`;function kt(t,e,i){let r={};for(let n of i)r[n]=t.getUniformLocation(e,n);return r}var bi="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 Kn(){let t=de(),e=t.xrDepthShader,i=t.shadowMapShader;return{fs:di.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:[...bi,...e?.uniformNames||[],...i?.uniformNames||[]]}}function gi(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 jn(t,e,i,r,n,s,a,o){if(r===void 0||!e.accessors?.[r])return null;let l=Hn(e,i,e.accessors[r],s);if(!l)return null;o&&(l=l.slice(),pr(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 $n(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function vr(t,e,i){let r=Kn(),n=Xn,s=r.fs,a=!1;for(let l of ge)if(l.onResolveShader){let y=l.onResolveShader(e,i,n,s);y&&(n=y.vs,s=y.fs,a=!0)}let o=a?st(t,n,s):null;return{program:o,uniforms:o?kt(t,o,r.uniforms):null}}function yi(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 xi(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 ao=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Mr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function It(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Sr(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 wr(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 br(t,e,i=Mr,r){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return vi(t,e,i,r,n)}catch(s){let a=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;wr(t,a,n.gpuTextures),n.vao&&t.deleteVertexArray(n.vao);for(let o of n.buffers)t.deleteBuffer(o);throw s}}function vi(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=Ft("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=zn(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(...Yn(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[F,k]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])t.texParameteri(3553,F,k);let R=F=>{D.__gpuImageSource=F,t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,F),t.generateMipmap(3553),r?.()};if(A.bufferView!==void 0){let F=s.bufferViews[A.bufferView],k=F.byteOffset||0,V=new Blob([o.slice(k,k+F.byteLength)],{type:A.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(V).then(R).catch(()=>{})}else if(A.uri){let F=gi(A.uri);if(F){let k=new Image;k.crossOrigin="anonymous",k.referrerPolicy="no-referrer",k.onload=()=>R(k),k.src=F}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);Fe(R,D);let F=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 F?.cast=="boolean"?{castShadow:F.cast}:{},...typeof F?.receive=="boolean"?{receiveShadow:F.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,I=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??I?.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 j=(B,X)=>{if(!B||B.bufferView===void 0||!s.bufferViews?.[B.bufferView])return null;let z=B.componentType??5126,ee=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 ee(`componentType ${z}`);if(!(Number(B.count)>=U))return ee(`count ${B.count} < ${U}`);let te=null;try{te=Hn(s,o,{...B,count:U},X)}catch{return ee("out of bounds")}return!te||!te.every(Number.isFinite)?ee("non-finite value"):te},H=j(O,3),Y=j(c,4),q=j(I,3),ne=C?.type==="VEC4"?4:3,ie=j(C,ne),oe=new Float32Array(U*16),he=ve();for(let B=0;B<U;B++){let X=B*3,z=B*4;ot(he,Y?[Y[z],Y[z+1],Y[z+2],Y[z+3]]:[0,0,0,1],H?[H[X],H[X+1],H[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 $=Ft("draco");$&&$.decodePrimitive(s,L,o)}let O=[],c=t.createVertexArray();n.vao=c,n.buffers=O,t.bindVertexArray(c);let I=yi(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 Z=G[12+W],ae=Z;for(let se=0;se<3;se++){let fe=G[se*4+W]*C.min[se],re=G[se*4+W]*C.max[se];Z+=fe<re?fe:re,ae+=fe>re?fe:re}Z<u[W]&&(u[W]=Z),ae>g[W]&&(g[W]=ae)}};if(k.instanceMatrices&&k.instanceMatrices.length>=16){let G=k.instanceMatrices.length>>4,W=ve();for(let Z=0;Z<G;Z++)Me(W,D,k.instanceMatrices.subarray(Z*16,Z*16+16)),$(W)}else $(D)}let j=jn(t,s,o,L.attributes.POSITION,0,3,O),H=jn(t,s,o,L.attributes.NORMAL,1,3,O),Y=jn(t,s,o,L.attributes.TEXCOORD_0,2,2,O,xi(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 ge)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}=vr(t,L,he),z=Sr(he,m),ee=!!(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:I,indexCount:q,indexType:ne,...z,positions:j,normals:H,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:ee})}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 ge)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 Nt(){return typeof performance<"u"?performance.now():Date.now()}function at(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 Pt=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=$n(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=Wn(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){mi(t,e)}static getDecoder(t){return Ft(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=Kn();this.renderProg=st(t,Xn,e.fs),this.pickProg=st(t,fi,pi),this.uRender=kt(t,this.renderProg,e.uniforms),this.uPick=kt(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let t=this.gl,e=Kn();this.renderProg&&t.deleteProgram(this.renderProg),this.renderProg=st(t,Xn,e.fs),this.uRender=kt(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 ge)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}=br(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 ge)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=$n(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(xr(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of ge)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(Ut(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=Ut(t),{meshes:r}=br(this.gl,i,Mr,()=>this.render());if(e)for(let n of r)n.transform[12]+=e[0],n.transform[13]+=e[1],n.transform[14]+=e[2],Fe(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),Fe(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=$n(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=Wn(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){this.environmentSource=t&&typeof t=="object"?t:null;for(let e of ge)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t),this.render();return}this.render()}async setSkyboxImage(t){for(let e of ge)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,Sr(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=vr(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 ge)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();Me(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]=at(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=Nt;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();Me(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),Me(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 F=0;F<A;F++)Me(D,this.modelMatrix,S.subarray(F*16,F*16+16)),Me(this.mvpMatrix,a,D),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),It(r,R)}}else{Me(this.mvpMatrix,a,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let A of _.primitives)r.bindVertexArray(A.vao),It(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]=at(this),u=ve();for(let p of o){Me(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?Me(this.modelMatrix,u,x.subarray(_*16,_*16+16)):this.modelMatrix.set(u),Me(this.mvpMatrix,a,this.modelMatrix);let N=ve();if(!dr(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];Vn(T,P,E,-1,N),Vn(S,P,E,1,N);let A=S[0]-T[0],D=S[1]-T[1],R=S[2]-T[2],F=Math.hypot(A,D,R)||1,k=A/F,V=D/F,L=R/F,O={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let c of p.primitives){if(!c.positions)continue;let I=c.positions,C=c.indices,U=Math.floor(C?C.length/3:I.length/9);for(let j=0;j<U;j++){let H=(C?C[j*3]:j*3)*3,Y=(C?C[j*3+1]:j*3+1)*3,q=(C?C[j*3+2]:j*3+2)*3;fr(T[0],T[1],T[2],k,V,L,I[H],I[H+1],I[H+2],I[Y],I[Y+1],I[Y+2],I[q],I[q+1],I[q+2],O,1e-4)}}if(isFinite(O.distance)){let c=O.point[0],I=O.point[1],C=O.point[2],U=this.modelMatrix,j=U[0]*c+U[4]*I+U[8]*C+U[12],H=U[1]*c+U[5]*I+U[9]*C+U[13],Y=U[2]*c+U[6]*I+U[10]*C+U[14],q=j-v,ne=H-M,ie=Y-m,oe=Math.hypot(q,ne,ie);if(oe<b){Fe(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,B=O.normal[0],X=O.normal[1],z=O.normal[2],ee=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(ee,te,K)||1;ee/=$,te/=$,K/=$,ee*q+te*ne+K*ie>0&&(ee=-ee,te=-te,K=-K);let G=W=>Math.round(W*1e3)/1e3;f=p,b=G(oe),h=[G(j),G(H),G(Y)],d=[G(ee),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 ge)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);Bn(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;it(this.viewMatrix,at(this),i,[0,1,0]),Me(this.mvpMatrix,this.projMatrix,this.viewMatrix),Fe(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 ge)i.onXRSessionEnd?.(this);if(this.lastTime=Nt(),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 ge)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=Nt();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 ge)s.onUpdate?.(this,t);let e=Nt();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let s of ge)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]=at(this),F=Math.cos(this.currTheta),k=-Math.sin(this.currTheta),V=.032;for(let L of[-1,1]){let O=ve(),c=ve(),I=L<0?P:E,C=[A+L*F*V,D,R+L*k*V];Bn(O,this.fov,I/N,.1,T),it(c,C,[S[0]+L*F*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,I,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;Me(a,l,o);let y=de(),f=y.xrDepthShader,b=ui(this.toneMapping),[h,d,v]=t?t.eyePos:at(this);for(let _ of ge)_.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 ge)_.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{Me(this.modelMatrix,this.modelRootMatrix,P.transform);let F=!t&&(P.extras?.xr?.billboard??P.userData?.xr?.billboard);if(F){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=F==="y"||F==="cylindrical"||F==="capsule",I=h-k[12],C=v-k[14],U=Math.hypot(I,C),j=U>1e-5?I/U:0,H=U>1e-5?C/U:1;k.set(c?[H*V,0,-j*V,0,0,L,0,0,j*O,0,H*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])}}Me(this.mvpMatrix,a,this.modelMatrix),Fe(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 F of P.primitives){let k=!!F.isTransmissive;if(!_&&k){g=!0;continue}if(_&&!k)continue;let V=F.customProgram||this.renderProg,L=F.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 ge)c.onBeforeDrawPrimitive?.(e,V,F,P,this.worldMatrices||[],this.gltf);e.uniform4fv(L.uBaseColor,F.baseColor),e.uniform1f(L.uMetallic,F.metallic),e.uniform1f(L.uRoughness,F.roughness),L.uClearcoat&&e.uniform2f(L.uClearcoat,F.clearcoat??0,F.clearcoatRoughness??.04),x(0,F.texture,L.uBaseColorTexture,L.uHasTexture),x(1,F.metallicRoughnessTexture,L.uMetallicRoughnessTexture,L.uHasMetallicRoughnessTexture),x(2,F.normalTexture,L.uNormalTexture,L.uHasNormalTexture),F.normalTexture&&e.uniform1f(L.uNormalScale,F.normalScale),x(3,F.occlusionTexture,L.uOcclusionTexture,L.uHasOcclusionTexture),F.occlusionTexture&&e.uniform1f(L.uOcclusionStrength,F.occlusionStrength),e.uniform3fv(L.uEmissiveFactor,F.emissiveFactor),x(8,F.emissiveTexture,L.uEmissiveTexture,L.uHasEmissiveTexture),e.bindVertexArray(F.vao);let O=P.instanceMatrices;if(F.instanceCount!==void 0)e.drawElementsInstanced(4,F.indexCount,F.indexType,0,F.instanceCount);else if(O&&O.length>=16&&F.instanced&&L.uInstanced&&L.uViewProj){let c=O.length>>4;e.uniform1i(L.uInstanced,1),e.uniformMatrix4fv(L.uViewProj,!1,a),F.indices?e.drawElementsInstanced(4,F.indexCount,F.indexType,0,c):e.drawArraysInstanced(4,0,F.indexCount,c),e.uniform1i(L.uInstanced,0)}else if(O&&O.length>=16){let c=O.length>>4,I=P.instanceColors,C=ve(),U=new Float32Array(9);for(let j=0;j<c;j++){if(Me(C,this.modelMatrix,O.subarray(j*16,j*16+16)),Me(this.mvpMatrix,a,C),Fe(U,C),e.uniformMatrix4fv(L.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(L.uModel,!1,C),e.uniformMatrix3fv(L.uNormalMatrix,!1,U),I){let H=F.baseColor,Y=j*3;e.uniform4fv(L.uBaseColor,[H[0]*I[Y],H[1]*I[Y+1],H[2]*I[Y+2],H[3]])}It(e,F)}}else It(e,F)}}};if(w(!1),g){for(let _ of ge)_.onBeforeTransmissivePass?.(e,this);w(!0)}for(let _ of ge)_.onAfterRender?.(e,this,a,m,[i,r,n,s],l)}disposeMeshListGpuResources(t,e){wr(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 ge)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()}};Pt.registerPlugin=mr,Pt.getRegisteredPlugins=hr;function Mi(t){return t+3&-4}var J=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function qn(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function Ar(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 Tr(t,e=0){let[i,r,n,,s,a,o,,l,y,f,,b,h,d]=Array.from({length:15},(O,c)=>J(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,F=0,k=0,V=1;if(D>0){let O=.5/Math.sqrt(D+1);V=.25/O,R=(E-S)*O,F=(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,F=(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,F=.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,F=(E+S)/O,k=.25*O)}let L=Math.hypot(R,F,k,V);return L>1e-8&&Number.isFinite(L)?(R/=L,F/=L,k/=L,V/=L):(R=0,F=0,k=0,V=1),{t:[b,h,d],r:[R,F,k,V],s:[v,M,m]}}function Si(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 Ie=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Er(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:Ie(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function wi(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 Je(t,e){return Rr(t,e)[0]}function Rr(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 I=b.get(c);if(I!==void 0)return I;I=f.length,b.set(c,I);let C=c,U=C.color?.r??1,j=C.color?.g??1,H=C.color?.b??1,Y=C.opacity??1,q={baseColorFactor:[U,j,H,Y],metallicFactor:C.metalness??0,roughnessFactor:C.roughness??.5},ne={},ie=re=>{if(!re)return;let Ae=(typeof re=="string"?re:typeof re.source=="string"?re.source:typeof re.image=="string"?re.image:"").trim();if(!Ae||/[\x00-\x1f\x7f\\]|\.\./.test(Ae)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(Ae)||!Ae.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(Ae)))return;let le=M.get(Ae);if(le===void 0){let me=h.length;h.push({uri:Ae}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),le=v.length,v.push({sampler:0,source:me}),M.set(Ae,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),ee=C.normalScale,te=oe?.normUri?oe.normScale??1:typeof ee=="number"?Math.max(0,J(ee,1)):ee?Math.max(0,(J(ee.x,1)+J(ee.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,J(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}:{}},Z=Math.max(0,J(C.emissiveIntensity,1)),ae=C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0);(ae||K&&!C._em&&Z>0)&&(W.emissiveFactor=ae?[C.emissive.r*Z,C.emissive.g*Z,C.emissive.b*Z]:[Z,Z,Z]);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),I}function w(c,I){let C=new Uint8Array(c.buffer,c.byteOffset,c.byteLength),U=Mi(C.byteLength),j=new Uint8Array(U);j.set(C),i.push(j);let H=n.length;return n.push({buffer:0,byteOffset:r,byteLength:C.byteLength,target:I}),r+=U,H}function _(c,I,C,U,j,H,Y){let q=w(c,C),ne=s.length,ie={bufferView:q,byteOffset:0,componentType:U,count:j,type:I};return H&&(ie.min=H),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:I}=T.pop();if(!c||typeof c!="object"||E.has(c))continue;E.add(c),c._bakeAuthorGeometry?.(),de().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}`:"")},j=J(c.position?.x,0),H=J(c.position?.y,0),Y=J(c.position?.z,0),q=J(c.quaternion?.x,0),ne=J(c.quaternion?.y,0),ie=J(c.quaternion?.z,0),oe=J(c.quaternion?.w,1),he=J(c.scale?.x,1),B=J(c.scale?.y,1),X=J(c.scale?.z,1);if((j||H||Y)&&(U.translation=[j,H,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 $=Si(c.userData.xr);U.extensions={...U.extensions||{},MOZ_hubs_components:$,ANDROID_xr_scenecore:$},de().xrTraitSerializer?.gltfNode(U,c.userData.xr);let G=wi(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,ee=z.isLight||z.color&&z.intensity!==void 0;if(!ee&&(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)}}),ee){let $=z.matrixWorld?.elements,G=J($?$[12]:c.position?.x,0),W=J($?$[13]:c.position?.y,0),Z=J($?$[14]:c.position?.z,0),ae=z.target,se=ae?.parent?ae?.matrixWorld?.elements:void 0,fe=J(se?se[12]:ae?.position?.x,0),re=J(se?se[13]:ae?.position?.y,0),Ae=J(se?se[14]:ae?.position?.z,0),le=fe-G,me=re-W,ue=Ae-Z,ce=Math.hypot(le,me,ue),Te=Math.max(.01,Math.min(Math.PI/2,J(z.angle,Math.PI/3))),_e=Math.max(0,Math.min(1,J(z.penumbra,0))),pe=Math.max(0,Te*(1-_e)),Le=Math.max(0,J(z.distance,0)),je=c.type==="directional"||c.type==="spot"||c.type==="point",Be;if(c.castShadow&&je){let Ye=z.shadow,Zi=Math.max(256,Math.min(2048,Math.round(J(Ye?.mapSize?.x??Ye?.mapSize?.width,1024))));Be={cast:!0,mapSize:Zi<=384?256:Zi<=768?512:Zi<=1536?1024:2048,bias:Ie(Ye?.bias,-.05,.05,-5e-4),normalBias:Ie(Ye?.normalBias,0,.2,.015),radius:Ie(Ye?.radius,0,8,1.5)},p=!0}let Ct=G-fe,qi=W-re,Yi=Z-Ae,rt=Math.hypot(Ct,qi,Yi);u.push({type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:c.type==="directional"?[Ct,qi,Yi]:[G,W,Z],...c.type==="directional"?{direction:rt>1e-6?[Ct/rt,qi/rt,Yi/rt]:[0,1,0]}:c.type==="spot"?{direction:ce>1e-6?[le/ce,me/ce,ue/ce]:[0,-1,0],outerConeAngle:Te,innerConeAngle:pe,range:Le}:c.type==="point"?{range:Le}:c.type==="hemisphere"&&z.groundColor?{groundColor:[z.groundColor.r,z.groundColor.g,z.groundColor.b]}:{},...Be?{shadow:Be}:{}}),je&&N.push({node:U,obj:c,px:G,py:W,pz:Z,tx:fe,ty:re,tz:Ae,dx:le,dy:me,dz:ue,dLen:ce,outerAngle:Te,innerAngle:pe,range:Le,shadowSpec:Be})}if(c.geometry){let $=c.geometry,G=$.attributes.position;if(G&&G.count>0){let W=[1/0,1/0,1/0],Z=[-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>Z[0]&&(Z[0]=me),ue<W[1]&&(W[1]=ue),ue>Z[1]&&(Z[1]=ue),ce<W[2]&&(W[2]=ce),ce>Z[2]&&(Z[2]=ce)}let ae={attributes:{POSITION:_(G.array,"VEC3",34962,5126,G.count,W,Z)}};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 Te=x(ue),_e=le.get(Te);_e||(_e=[],le.set(Te,_e)),_e.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),Te=new Float32Array(le*3);for(let pe=0;pe<le;pe++){let{t:Le,r:je,s:Be}=Tr(me,pe*16);ue[pe*3]=Le[0],ue[pe*3+1]=Le[1],ue[pe*3+2]=Le[2],ce[pe*4]=je[0],ce[pe*4+1]=je[1],ce[pe*4+2]=je[2],ce[pe*4+3]=je[3],Te[pe*3]=Be[0],Te[pe*3+1]=Be[1],Te[pe*3+2]=Be[2]}let _e={TRANSLATION:_(ue,"VEC3",0,5126,le),ROTATION:_(ce,"VEC4",0,5126,le),SCALE:_(Te,"VEC3",0,5126,le)};if(re.instanceColor?.array&&re.instanceColor.array.length>=le*3){let pe=new Float32Array(re.instanceColor.array.subarray(0,le*3));_e._COLOR_0=_(pe,"VEC3",0,5126,le)}U.extensions={...U.extensions||{},EXT_mesh_gpu_instancing:{attributes:_e}},l.add("EXT_mesh_gpu_instancing")}let Ae=a.length;a.push({primitives:[ae],name:c.name,...U.extras?{extras:U.extras}:{}}),U.mesh=Ae}}let te=o.length;o.push(U),y.push(c),I.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 I=g.length;if(g.push({name:c.obj.name||`Light_${I}`,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:I}},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,j=c.dLen>1e-6?c.dz/c.dLen:0;c.node.rotation=Ar(C,U,j),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 I=o[c];I.children&&I.children.length===0?delete I.children:I.children&&I.children.length>0&&(I.extras?.xr?.lod||I.extensions?.ANDROID_xr_scenecore?.lod||y[c]?.isLOD)&&(I.extensions={...I.extensions||{},MSFT_lod:{ids:[...I.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,I=e?.fps??15,C=Math.max(2,Math.round(c*I)+1),U=new Float32Array(C),j=y.map(B=>[J(B.position?.x,0),J(B.position?.y,0),J(B.position?.z,0),J(B.quaternion?.x,0),J(B.quaternion?.y,0),J(B.quaternion?.z,0),J(B.quaternion?.w,1),J(B.scale?.x,1),J(B.scale?.y,1),J(B.scale?.z,1)]),H=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 ee=y[z];H[z][B*3]=J(ee.position?.x,0),H[z][B*3+1]=J(ee.position?.y,0),H[z][B*3+2]=J(ee.position?.z,0);let te=J(ee.quaternion?.x,0),K=J(ee.quaternion?.y,0),$=J(ee.quaternion?.z,0),G=J(ee.quaternion?.w,1),W=Math.hypot(te,K,$,G)||1;if(te/=W,K/=W,$/=W,G/=W,B>0){let Z=(B-1)*4,ae=Y[z];ae[Z]*te+ae[Z+1]*K+ae[Z+2]*$+ae[Z+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]=J(ee.scale?.x,1),q[z][B*3+1]=J(ee.scale?.y,1),q[z][B*3+2]=J(ee.scale?.z,1)}}for(let B=0;B<y.length;B++){let X=y[B],z=j[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=j[B],z=(te,K,$)=>te.some((G,W)=>Math.abs(G-X[$+W%K])>1e-4),ee=(te,K,$,G)=>{te&&he.push({sampler:oe.push({input:ie(),interpolation:"LINEAR",output:_(K,$,0,5126,C)})-1,target:{node:B,path:G}})};ee(z(H[B],3,0),H[B],"VEC3","translation"),ee(z(Y[B],4,3),Y[B],"VEC4","rotation"),ee(z(q[B],3,7),q[B],"VEC3","scale")}he.length>0&&A.push({name:"ProceduralLoop",samplers:oe,channels:he})}let D=cr(o,a,t.userData),R=[],F=[],k=[];for(let c=0;c<o.length;c++){let I=o[c],C=Er(I.extras?.xr);if(!C)continue;let{ae:U,src:j,preset:H,volume:Y,loop:q,isGlobal:ne}=C,ie=I.name||`Node_${c}`,oe=F.length;F.push({name:`${ie}_source`,gain:Y,loop:q,autoPlay:typeof U.autoplay=="boolean"?U.autoplay:!0,...j!==void 0?{audio:R.push({uri:j})-1}:{},...H?{extras:{preset:H,pitch:Ie(U.pitch,.25,4,1)}}:{}});let he=k.length,B=Ie(U.refDistance,.05,100,1),X=Ie(U.coneInnerAngle,0,360,360),z=Ie(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:Ie(U.maxDistance,B,500,Math.max(B,25)),rolloffFactor:Ie(U.rolloffFactor,0,10,1),coneInnerAngle:+(X*Math.PI/180).toFixed(6),coneOuterAngle:+(z*Math.PI/180).toFixed(6),coneOuterGain:Ie(U.coneOuterGain,0,1,0)}}}),I.extensions={...I.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:F,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 Zn(t){return new TextEncoder().encode(t)}function lt(t,e){let{gltf:i,bin:r}=Je(t,e),n=JSON.stringify(i),s=Zn(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 _i(t,e){let[i,r]=Rr(t,e);return Lr(i,r)}function Lr(t,e){let i=[],r=t.gltf,n=de().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)=>qn(M,ut(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=F=>{let k=T.charCodeAt(F);return k>96?k-71:k>64?k-65:k>47?k+4:k===43?62:k===47?63:0},R=0;for(let F=0;F<T.length;F+=4){let k=D(F)<<18|D(F+1)<<12|D(F+2)<<6|D(F+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,I=O?.byteLength||0;O&&I>0&&c>=0&&c+I<=a.byteLength&&(L=new Uint8Array(a,c,I))}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 F=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(F?.wrapS),wrapT:k(F?.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 F=0;F<R.length;F++){let k=R[F],V=k.attributes?.POSITION;if(V===void 0)continue;let{acc:L,buffer:O}=x(V),c=new Float32Array(O,0,L.count*3),I,C=k.attributes?.NORMAL;if(C!==void 0){let{acc:K,buffer:$}=x(C),G=new Float32Array($,0,K.count*3);I=new Float32Array(G.length);for(let W=0;W<K.count;W++){let Z=G[W*3],ae=G[W*3+1],se=G[W*3+2],fe=Math.hypot(Z,ae,se)||1;I[W*3]=Z/fe,I[W*3+1]=ae/fe,I[W*3+2]=se/fe}}let U,j=k.attributes?.TEXCOORD_0;if(j!==void 0){let{acc:K,buffer:$}=x(j);U=new Float32Array($,0,K.count*2)}let H;if(k.indices!==void 0){let{acc:K,buffer:$}=x(k.indices);H=K.componentType===5125?new Uint32Array($,0,K.count):new Uint16Array($,0,K.count);let G=L.count;for(let W of H)if(W>=G)throw new Error(`SecurityError: Index buffer value (${W}) out of vertex bounds [0, ${G}).`)}else{let K=L.count;H=K>65535?new Uint32Array(K):new Uint16Array(K);for(let $=0;$<K;$++)H[$]=$}let Y="DefaultMaterial",q=[1,1,1],ne=.5,ie=0,oe=0,he=0,B=1.5,X=1,z=[0,0,0],ee,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=(pe,Le)=>Array.isArray(pe)&&pe.length>=3?[pe[0],pe[1],pe[2]]:Le;q=G($.baseColorFactor,[1,1,1]);let W=Array.isArray($.baseColorFactor)&&typeof $.baseColorFactor[3]=="number"?$.baseColorFactor[3]:1,Z=q[0]!==1||q[1]!==1||q[2]!==1||W!==1,ae=p($.baseColorTexture,Z?[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,Ae=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]),Te=typeof K.occlusionTexture?.strength=="number"?K.occlusionTexture.strength:1,_e=Te!==1?p(K.occlusionTexture,[Te,Te,Te,1],[1-Te,1-Te,1-Te,0]):p(K.occlusionTexture);(ae||Ae||ce||me||_e)&&(ee=[ae,Ae,ce,me,_e]),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${F}`:E,positions:c,indices:H,normals:I,uvs:U,materialName:Y,color:q,roughness:ne,metallic:ie,clearcoat:oe,clearcoatRoughness:he,ior:B,opacity:X,emissiveColor:z,...ee?{textures:ee}:{},...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,I)=>{if(c===void 0)return null;let{acc:C,buffer:U}=x(c);return new Float32Array(U,0,C.count*I)},S=(c,I)=>Array.isArray(c)&&c.length>=3?[J(c[0],I),J(c[1],I),J(c[2],I)]:[I,I,I],A=(c,I,C)=>c&&c.length>=(I+1)*3?[c[I*3],c[I*3+1],c[I*3+2]]:C,D=(c,I,C)=>c&&c.length>=(I+1)*4?[c[I*4],c[I*4+1],c[I*4+2],c[I*4+3]]:C,R=new Map,F=r.animations?.[0];if(F&&Array.isArray(F.channels)&&Array.isArray(F.samplers))for(let c of F.channels){let I=F.samplers[c?.sampler],C=c?.target?.node,U=c?.target?.path;if(!I||typeof C!="number"||I.input===void 0)continue;let j=R.get(C);j||(j={input:I.input},R.set(C,j)),U==="translation"?j.t=I.output:U==="rotation"?j.r=I.output:U==="scale"&&(j.s=I.output)}let k=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(k)||k.length===0){let c=new Set;for(let I of b)if(Array.isArray(I?.children))for(let C of I.children)c.add(C);k=[];for(let I=0;I<b.length;I++)c.has(I)||k.push(I);k.length===0&&(k=[0])}let V=new Set,L=[],O=(c,I)=>{if(Array.isArray(c))for(let C=c.length-1;C>=0;C--)L.push({idx:c[C],out:I})};for(O(k,i);L.length>0;){let{idx:c,out:I}=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],j=[0,0,0,1],H=[1,1,1];if(Array.isArray(C.matrix)&&C.matrix.length===16){let X=Tr(C.matrix);U=X.t,j=X.r,H=X.s}else U=S(C.translation,0),Array.isArray(C.rotation)&&C.rotation.length>=4&&(j=[J(C.rotation[0],0),J(C.rotation[1],0),J(C.rotation[2],0),J(C.rotation[3],1)]),H=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),ee=T(q.r,4),te=T(q.s,3),K=Array.from(X),$=[],G=[],W=[];for(let Z=0;Z<X.length;Z++)$.push(A(z,Z,U)),G.push(D(ee,Z,j)),W.push(A(te,Z,H));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,ee)=>({name:X,positions:P,indices:E,isXform:!0,xrTraits:oe,timeSamples:Y,translation:U,rotation:j,scale:H,children:z,...ee?{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),ee=e?.[c],te=!!(ee?._castShdSet||ee?._recvShdSet),K=typeof C.extras?.shadow?.cast=="boolean"?C.extras.shadow.cast:te?!!ee?.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),Z=T($.SCALE,3),ae=T($._COLOR_0,3),se=Math.min(1e3,G?G.length/3:W?W.length/4:Z?Z.length/3:0);if(se>0){let fe=[];for(let re=0;re<se;re++){let Ae=A(G,re,[0,0,0]),le=D(W,re,[0,0,0,1]),me=A(Z,re,[1,1,1]);for(let ue of z){let ce=ue.color||[.8,.8,.8],Te=ae&&ae.length>=(re+1)*3;fe.push({...ue,name:`${ue.name}_${re}`,materialName:Te?`${ue.materialName}_inst_${re}`:ue.materialName,color:Te?[ce[0]*ae[re*3],ce[1]*ae[re*3+1],ce[2]*ae[re*3+2]]:ue.color,translation:Ae,rotation:le,scale:me})}}O(ne,fe),I.push(he(X,fe,B));continue}}if(z.length===1)z[0].translation=U,z[0].rotation=j,z[0].scale=H,z[0].timeSamples=Y,ne.length>0&&(z[0].children=[],O(ne,z[0].children)),I.push(z[0]);else{let G=[...z];O(ne,G),I.push(he(X,G,B))}}else{let X=[];O(ne,X),I.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)??Yn(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 ut(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 Ot(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ye(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 Ne=(t,e,i)=>`(${ye(t)}, ${ye(e)}, ${ye(i)})`,ct=(t,e,i,r)=>`(${ye(t)}, ${ye(e)}, ${ye(i)}, ${ye(r)})`;function _r(t){let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=Ne(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ai(t,e){let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${ye(t[r*2])}, ${ye(1-t[r*2+1])})`;return i.join(", ")}function Ti(t){return Array.from(t).join(", ")}function Ei(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=ut(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 = ${ye(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=(I,C)=>`.connect = <${P}/${I}.outputs:${C}>`,F=E?`color3f inputs:diffuseColor${R("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${Ne(g,p,x)}`,k=T?`float inputs:metallic${R("MetallicRoughnessTexture","b")}
233
+ float inputs:roughness${R("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${ye(u.metallic)}
234
+ float inputs:roughness = ${ye(u.roughness)}`,V="";u.clearcoat>0&&(V+=`float inputs:clearcoat = ${ye(u.clearcoat)}
235
+ `,V+=`float inputs:clearcoatRoughness = ${ye(u.clearcoatRoughness)}
236
+ `),u.ior!==1.5&&(V+=`float inputs:ior = ${ye(u.ior)}
237
+ `),u.opacity<1&&(V+=`float inputs:opacity = ${ye(u.opacity)}
238
+ `),A?V+=`color3f inputs:emissiveColor${R("EmissiveTexture","rgb")}
239
+ `:(w>0||_>0||N>0)&&(V+=`color3f inputs:emissiveColor = ${Ne(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 = ${pe(b.clearcoat)}
268
- `,R+=`float inputs:clearcoatRoughness = ${pe(b.clearcoatRoughness)}
269
- `),b.ior!==1.5&&(R+=`float inputs:ior = ${pe(b.ior)}
270
- `),b.opacity<1&&(R+=`float inputs:opacity = ${pe(b.opacity)}
271
- `),(m>0||p>0||v>0)&&(R+=`color3f inputs:emissiveColor = ${Ce(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 I=(C,U,j,H)=>{if(!U)return;let Y=U.scale?`float4 inputs:scale = ${ct(U.scale[0],U.scale[1],U.scale[2],U.scale[3])}
249
+ `:"",q=U.bias?`float4 inputs:bias = ${ct(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 = @${Ot(U.file)}@
254
+ float2 inputs:st${R("PrimvarReader","result")}
255
+ token inputs:sourceColorSpace = "${j}"
256
+ token inputs:wrapS = "${U.wrapS||"repeat"}"
257
+ token inputs:wrapT = "${U.wrapT||"repeat"}"
258
+ ${Y}${q}${H}}
259
+ `};I("DiffuseTexture",E,"sRGB",`float3 outputs:rgb
260
+ `),I("MetallicRoughnessTexture",T,"raw",`float outputs:g
261
+ float outputs:b
262
+ `),I("NormalTexture",S,"raw",`float3 outputs:rgb
263
+ `),I("EmissiveTexture",A,"sRGB",`float3 outputs:rgb
264
+ `),I("OcclusionTexture",D,"raw",`float outputs:r
265
+ `)}let O=`${F}
266
+ ${k}
267
+ ${V}`,c=u.tslGraph&&de().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 = ${Ce(w,M,x)}
278
- float inputs:metallic = ${pe(b.metallic)}
279
- float inputs:roughness = ${pe(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=ae().xrTraitSerializer?.usdLines(u,Dn)??[];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 ${_} = "${Dn(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=de().xrTraitSerializer;if(m){let A=N?.usdLines(m,Ot)??[];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} = "${Ot(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 = ${pe(N.mass)}
300
- `)}let L=hr(u),I=L?`def SpatialAudio "AudioEmitter"
291
+ `,A?.mass>0&&Number.isFinite(A.mass)&&(E+=`float physics:mass = ${ye(A.mass)}
292
+ `)}let T=Er(m),S=(T?`def SpatialAudio "AudioEmitter"
301
293
  {
302
- ${L.src?`asset inputs:file = @${Dn(L.src)}@
303
- `:""}uniform token inputs:auralMode = "${L.isGlobal?"nonSpatial":"spatial"}"
304
- uniform token inputs:playbackMode = "${L.loop?"loopFromStart":"onceFromStart"}"
305
- double gain = ${pe(L.volume)}
294
+ ${T.src?`asset inputs:file = @${Ot(T.src)}@
295
+ `:""}uniform token inputs:auralMode = "${T.isGlobal?"nonSpatial":"spatial"}"
296
+ uniform token inputs:playbackMode = "${T.loop?"loopFromStart":"onceFromStart"}"
297
+ double gain = ${ye(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)=>`${pe(E)}: ${A(N?.[C]||_)}`).join(", "),R=v(p.translations,[0,0,0],N=>Ce(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 cr(N[3]/_,N[0]/_,N[1]/_,N[2]/_)}),I=v(p.scales,[1,1,1],N=>Ce(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,F)=>`${ye(R)}: ${D(S?.[F]||A)}`).join(", "),P=N(_.translations,[0,0,0],S=>Ne(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 ct(S[3]/A,S[0]/A,S[1]/A,S[2]/A)}),T=N(_.scales,[1,1,1],S=>Ne(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 = ${Ce(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 = ${cr(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 = ${Ce(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=At(u.materialName,"DefaultMaterial"),I=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",N=`float3[] extent = [${Ce(w,M,x)}, ${Ce(m,p,v)}]
316
- int[] faceVertexCounts = [${I}]
317
- int[] faceVertexIndices = [${ui(u.indices)}]
318
- point3f[] points = [${ur(u.positions)}]
319
- `;return u.normals&&u.normals.length===u.positions.length&&(N+=`normal3f[] normals = [${ur(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 = ${Ne(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 = ${ct(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 = ${Ne(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],F=m.positions[A*3+2];D<g&&(g=D),D>w&&(w=D),R<p&&(p=R),R>_&&(_=R),F<x&&(x=F),F>N&&(N=F)}isFinite(g)||(g=p=x=-1,w=_=N=1);let P=Math.floor(m.indices.length/3),E=ut(m.materialName,"DefaultMaterial"),T=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",S=`float3[] extent = [${Ne(g,p,x)}, ${Ne(w,_,N)}]
308
+ int[] faceVertexCounts = [${T}]
309
+ int[] faceVertexIndices = [${Ti(m.indices)}]
310
+ point3f[] points = [${_r(m.positions)}]
311
+ `;return m.normals&&m.normals.length===m.positions.length&&(S+=`normal3f[] normals = [${_r(m.normals)}] (
320
312
  interpolation = "vertex"
321
313
  )
322
- `),u.uvs&&u.uvs.length===b*2&&(N+=`texCoord2f[] primvars:st = [${ci(u.uvs,b)}] (
314
+ `),m.uvs&&m.uvs.length===u*2&&(S+=`texCoord2f[] primvars:st = [${Ai(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=lr(w,At(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=qn(g,ut(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 li(e,t){if(e&&typeof e.traverse=="function"){let s=ai(e,t);return In(s)}let i=Je(e),r=Ln(i);return In(r)}var _t=null;function Et(e){if(!_t){_t=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;_t[i]=r}}let t=4294967295;for(let i=0;i<e.length;i++)t=_t[(t^e[i])&255]^t>>>8;return(t^4294967295)>>>0}function mi(e){let t=[],i=0,r=[];for(let c of e){let f=Nn(c.filename),y=Et(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 dr=e=>mi([{filename:"model.usda",data:Nn(e)}]);function et(e){return dr(li(e))}function Rt(e){return dr(In(Ln(Je(e))))}function Pn(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Rt(e)}var Se=class Ni{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 Ni(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)}},Z=class Li{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 Li(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}},Lt=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}},it=class Fi{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 Fi(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},st=class ki{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 ki(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}},Fe=class Ui{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 Ui;return t.copy(this),t}compose(t,i,r){return qe(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 de(this.elements,t.elements,i.elements),this}lookAt(t,i,r){return Xe(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 Z(0,0,0),r=new Z(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}},Pt=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 Ae(this.elements,e.elements),this}},ve=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Ct=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,pr={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},Te=class zi{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 pr)this.setHex(pr[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=>ve(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=ve(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(ve(o(t+1/3)),ve(o(t)),ve(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=ve((i>>16&255)/255),this.g=ve((i>>8&255)/255),this.b=ve((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=ve(this.r),this.g=ve(this.g),this.b=ve(this.b),this}convertLinearToSRGB(){return this.r=Ct(this.r),this.g=Ct(this.g),this.b=Ct(this.b),this}getHex(){let t=i=>Math.round(Ct(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 zi(this.r,this.g,this.b)}},Sr={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)},be=class Oi{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 Oi(new t(this.array),this.itemSize)}},Ft=class extends be{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},kt=class extends be{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Ut=class extends be{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},me=class Vi{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 be)this.index=t;else if(Array.isArray(t)){let i=0;for(let r of t)r>i&&(i=r);this.index=new be(new(i>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new be(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 Z,n=new Z,o=new Z,a=new Z,h=new Z,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 be(r,3)),this}setFromBuffers(t,i,r,s){this.setAttribute("position",new be(t,3)),this.setAttribute("normal",new be(i,3)),this.setAttribute("uv",new be(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 be(i,3))}computeBoundingBox(){let t=this.attributes.position,i=new Z(1/0,1/0,1/0),r=new Z(-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 Z;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 Vi;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(){}},ot=class extends me{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)}},Ot=class extends me{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)}},Bt=class extends me{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)}},at=class extends me{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)}},Vt=class extends at{constructor(e=1,t=1,i=16){super(0,e,t,i)}},zt=class extends me{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 Tr(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 Z,g=new Z,u=new Z,b=new Z,w=new Z;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 Gt=class extends me{constructor(e=1,t=.4,i=64,r=8,s=2,n=3){super(),i=Math.floor(i),r=Math.floor(r),Tr(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)})}},Ie=class{getPoint(e,t=new Z){return t}getPointAt(e,t=new Z){return this.getPoint(e,t)}getTangent(e,t=new Z){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)}},Ht=class extends Ie{constructor(e=new Z,t=new Z){super(),this.v1=e,this.v2=t}getPoint(e,t=new Z){return t.lerpVectors(this.v1,this.v2,e)}},Xt=class extends Ie{constructor(e=new Z,t=new Z,i=new Z){super(),this.v0=e,this.v1=t,this.v2=i}getPoint(e,t=new Z){return t.lerpVectors(this.v0,this.v1,e).lerp(new Z().lerpVectors(this.v1,this.v2,e),e)}},$t=class extends Ie{constructor(e=new Z,t=new Z,i=new Z,r=new Z){super(),this.v0=e,this.v1=t,this.v2=i,this.v3=r}getPoint(e,t=new Z){let i=new Z().lerpVectors(this.v0,this.v1,e),r=new Z().lerpVectors(this.v1,this.v2,e),s=new Z().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(i.lerp(r,e),r.lerp(s,e),e)}},jt=class extends Ie{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new Z){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))}},ct=class extends me{constructor(e=[new Se(0,-.5),new Se(.5,0),new Se(0,.5)],t=12,i=0,r=Math.PI*2){super();let s=Array.isArray(e)&&e.length>=2?e:[new Se(.2,0),new Se(.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)}},Wt=class extends me{constructor(e,t=64,i=1,r=8,s=!1){super(),Tr(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)})}},Dt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",We=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Se(1,1),this.offset=new Se(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Kt=class extends We{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,Et(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,Et(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:ve(x/L),I?m/L:ve(m/L),I?p/L:ve(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(Dt[A>>18&63]+Dt[A>>12&63]+(_+1<g.length?Dt[A>>6&63]:"=")+(_+2<g.length?Dt[A&63]:"="))}this.source=N.join("")}},Yt=class{load(e,t){let i=new We(e);return t?.(i),i}};function ye(e,t){return e!==void 0?Number(e):t}function Fn(e,t){return e!==void 0?!!e:t}var Me=class{constructor(e={}){this.name=e.name||"",this.color=new Te(e.color!==void 0?e.color:16777215),this.emissive=new Te(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ye(e.emissiveIntensity,1),this.roughness=ye(e.roughness,.5),this.metalness=ye(e.metalness,0),this.opacity=ye(e.opacity,1),this.transparent=Fn(e.transparent,!1),this.wireframe=Fn(e.wireframe,!1),this.side=ye(e.side,2),this.doubleSided=Fn(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=ye(e.clearcoat,0),this.clearcoatRoughness=ye(e.clearcoatRoughness,0),this.sheen=ye(e.sheen,0),this.sheenColor=new Te(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=ye(e.sheenRoughness,0),this.transmission=ye(e.transmission,0),this.thickness=ye(e.thickness,0),this.attenuationColor=new Te(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=ye(e.attenuationDistance,1/0),this.ior=ye(e.ior,1.5),this.dispersion=ye(e.dispersion,0),this.iridescence=ye(e.iridescence,0),this.iridescenceIOR=ye(e.iridescenceIOR,1.3)}dispose(){}},Ve=class extends Me{},qt=class extends Me{},Zt=class extends Me{},Jt=class extends Me{},Qt=class extends Me{},_e=class Bi{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 Z,this.rotation=new it,this.quaternion=new st,this.scale=new Z(1,1,1),this.matrix=new Fe,this.matrixWorld=new Fe,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 Bi&&(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=>{_r(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 Z(t,i,r);this.target instanceof Z?this.target.copy(s):this.target?.position instanceof Z&&this.target.position.copy(s),this.updateMatrixWorld(!0);let n=new Fe;n.lookAt(this.position,s,new Z(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 Fe().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(t){return this.translateOnAxis(new Z(1,0,0),t)}translateY(t){return this.translateOnAxis(new Z(0,1,0),t)}translateZ(t){return this.translateOnAxis(new Z(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 ke?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Re?new Re(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}},en=class extends _e{},Re=class extends _e{constructor(e,t){super(),this.isMesh=!0;let i=Array.isArray(t)?t[0]:t;this.geometry=e instanceof me?e:e?(Ge("unsupported geometry","BoxGeometry"),new ot(.5,.5,.5)):new me,this.material=i instanceof Me?i:i?(Ge("unsupported material","MeshStandardMaterial"),new Ve({color:13421772})):new Ve}};function _r(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=ae().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var ut=1e4,lt=class extends Re{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>ut)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${ut})`);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 be(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 be(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(){}},ze=class extends _e{constructor(e=16777215,t=1){super(),this.color=new Te(e),this.intensity=Number(t),this.type="directional"}},mt=class extends ze{constructor(e,t){super(e,t),this.type="ambient"}},tn=class extends ze{constructor(e,t){super(e,t),this.target=new _e,this.type="directional"}},ht=class extends ze{constructor(e,t,i=0,r=2){super(e,t),this.type="point",this.distance=i,this.decay=r}},ft=class extends _e{},nn=class extends ft{constructor(e=45,t=1,i=.1,r=1e3){super(),this.target=new Z(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(i),this.far=Number(r)}},dt=class extends _e{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ee.validate(this),je(this)}toGLB(){return Ee.validate(this),Qe(this)}toUSDZ(){return Ee.validate(this),et(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(i=>{if(i instanceof Re){let r=new Float32Array(i.matrixWorld.elements);e.set(t,r),i.name&&e.set(i.name,r),t++}}),e}},kn=je,Un=Qe,Ar=et,Ee=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(_r(a),a instanceof Re||a.geometry?.attributes?.position?.count){if(r++,r>1e3&&n("MESHES",1e3,r),a instanceof lt){let l=o("instance",a.count);(l<0||l>ut)&&n("INSTANCES",ut,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))}}},rn=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 Te(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){Ee.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=kn(e),n=Un(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 br(){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 sn=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=br(),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=br();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function hi(){}var nt=new Proxy(hi,{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:nt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>nt,construct:()=>nt}),gr=(()=>{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 vn(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Ke(e,t){if(!e||typeof e!="string")return!1;let i=e.trim();if(!i)return!1;try{let r=new URL(i,vn());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 yr,tt;function Er(e){if(!Ke(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(tt===void 0||yr!==t){yr=t;try{tt=t.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Ke(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{tt=null}}return tt?tt.createScriptURL(e):e}function fi(e){ae().sandboxEngineSrc=e}function On(){let e=ae().sandboxEngineSrc;if(e)return e;if(gr)return gr;try{if(typeof document>"u")return null;let t=vn(),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)&&Ke(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Bn(e,t){if(!Ke(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,vn()).href}function di(){let e=On();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 Bn(e,"sandbox engine")}function pi(e){ae().sandboxIframeSrc=e}function Rr(){let e=ae().sandboxIframeSrc;if(e)return e;let t=On();if(!t||!Ke(t))return null;let i=new URL(t,vn());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function bi(){let e=Rr();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 Bn(e,"sandbox iframe")}function gi(e){ae().allowClientScripts=e}function Cr(){return!!ae().allowClientScripts}function yi(e){return Bn(e,"procedural scene script")}var xi=["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 vi(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=qn(m,ut(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[F,k,V,L]=Ar(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 = ${Ne(E,T,S)}
336
+ `,c.push('"xformOp:translate"')),g.type!=="point"&&(1-Math.abs(L)>1e-7||Math.hypot(F,k,V)>1e-7)&&(O+=`quatf xformOp:orient = ${ct(L,F,k,V)}
337
+ `,c.push('"xformOp:orient"')),c.length>0&&(O+=`uniform token[] xformOpOrder = [${c.join(", ")}]
338
+ `);let I="";if(g.type==="spot"){let C=(g.outerConeAngle??Math.PI/3)*180/Math.PI,U=(g.innerConeAngle??C*.8)*180/Math.PI,j=C>1e-4?Math.max(0,Math.min(1,1-U/C)):0;I=`float inputs:shaping:cone:angle = ${ye(C)}
339
+ float inputs:shaping:cone:softness = ${ye(j)}
340
+ `}y+=`def ${x} "${p}" (
341
+ prepend apiSchemas = ${w}
342
+ )
343
+ {
344
+ color3f inputs:color = ${Ne(_,N,P)}
345
+ float inputs:intensity = ${ye(g.intensity??1)}
346
+ bool inputs:shadow:enable = 1
347
+ ${I}${O}}
348
+ `}y+=`}
349
+ `}return y+=`}
350
+ `,y}var Bt=null;function Vt(t){if(!Bt){Bt=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;Bt[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=Bt[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Ri(t){let e=[],i=0,r=[];for(let f of t){let b=Zn(f.filename),h=Vt(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 Cr(t){let e=[{filename:"model.usda",data:Zn(Ei(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 Ri(e)}function mt(t){return Cr(_i(t))}function zt(t){return Cr(Lr(Ut(t)))}function Jn(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():zt(t)}var Ee=class Ji{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 Ji(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)}},Q=class Qi{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 Qi(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}},Wt=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}},pt=class es{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 es(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Qe=class ts{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 ts(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}},We=class is{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 is;return e.copy(this),e}compose(e,i,r){return ot(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 Me(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return it(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 Q(0,0,0),r=new Q(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}},Xt=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 Fe(this.elements,t.elements),this}},Re=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,Gt=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Dr={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},Pe=class rs{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 Dr)this.setHex(Dr[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=>Re(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=Re(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(Re(a(e+1/3)),Re(a(e)),Re(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(Re((i>>16&255)/255),Re((i>>8&255)/255),Re((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(Re(this.r),Re(this.g),Re(this.b))}convertLinearToSRGB(){return this.setRGB(Gt(this.r),Gt(this.g),Gt(this.b))}getHex(){let e=i=>Math.round(Gt(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 rs(this.r,this.g,this.b)}},Qn=1234567,Br={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&&(Qn=Number.isFinite(t)?t|0:0);let e=Qn=Qn+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}},we=class ss{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 ss(new e(this.array),this.itemSize)}},Kt=class extends we{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},Yt=class extends we{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},qt=class extends we{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},xe=class ns{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 we)this.index=e;else if(Array.isArray(e)){let i=0;for(let r of e)r>i&&(i=r);this.index=new we(new(i>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new we(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 we(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 we(s,3)),this}setFromBuffers(e,i,r,n){this.setAttribute("position",new we(e,3)),this.setAttribute("normal",new we(i,3)),this.setAttribute("uv",new we(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 we(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new Q(1/0,1/0,1/0),r=new Q(-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 Q;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 ns;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(){}},bt=class extends xe{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)}},Zt=class extends xe{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)}},Jt=class extends xe{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)}},gt=class extends xe{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)}},Qt=class extends gt{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)}},en=class extends xe{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 Vr(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 Q,v=new Q,M=new Q;for(let u=0;u<=s;u++){let g=new Q;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 tn=class extends xe{constructor(t=1,e=.4,i=64,r=8,n=2,s=3){super(),i=Math.floor(i),r=Math.floor(r),Vr(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)})}},ze=class{getPoint(t,e=new Q){return e}getPointAt(t,e=new Q){return this.getPoint(t,e)}getTangent(t,e=new Q){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)}},nn=class extends ze{constructor(t=new Q,e=new Q){super(),this.v1=t,this.v2=e}getPoint(t,e=new Q){return e.lerpVectors(this.v1,this.v2,t)}},rn=class extends ze{constructor(t=new Q,e=new Q,i=new Q){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Q){return e.lerpVectors(this.v0,this.v1,t).lerp(new Q().lerpVectors(this.v1,this.v2,t),t)}},on=class extends ze{constructor(t=new Q,e=new Q,i=new Q,r=new Q){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new Q){let i=new Q().lerpVectors(this.v0,this.v1,t),r=new Q().lerpVectors(this.v1,this.v2,t),n=new Q().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(n,t),t)}},sn=class extends ze{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new Q){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))}},yt=class extends xe{constructor(t=[new Ee(0,-.5),new Ee(.5,0),new Ee(0,.5)],e=12,i=0,r=Math.PI*2){super();let n=Array.isArray(t)&&t.length>=2?t:[new Ee(.2,0),new Ee(.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)}},an=class extends xe{constructor(t,e=64,i=1,r=8,n=!1){super(),Vr(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)})}},Ht="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",et=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Ee(1,1),this.offset=new Ee(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},cn=class extends et{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,Vt(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 F=0;F<f;F++){let k=(R*n+(F*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,Vt(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:Re(x/E),T?w/E:Re(w/E),T?_/E:Re(_/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(Ht[D>>18&63]+Ht[D>>12&63]+(A+1<M.length?Ht[D>>6&63]:"=")+(A+2<M.length?Ht[D&63]:"="))}this.source=S.join("")}},un=class{load(t,e){let i=new et(t);return e?.(i),i}};function Se(t,e){return t!==void 0?Number(t):e}function er(t,e){return t!==void 0?!!t:e}var Ce=class{constructor(t={}){this.name=t.name||"",this.color=new Pe(t.color??16777215),this._em=t.emissive!==void 0,this.emissive=new Pe(t.emissive??0),this.emissiveIntensity=Se(t.emissiveIntensity,1),this.roughness=Se(t.roughness,t.roughnessMap?1:.5),this.metalness=Se(t.metalness,t.metalnessMap?1:0),this.opacity=Se(t.opacity,1),this.transparent=er(t.transparent,!1),this.wireframe=er(t.wireframe,!1),this.side=Se(t.side,2),this.doubleSided=er(t.doubleSided,!0),this.map=t.map||null,this.normalMap=t.normalMap||null;let e=t.normalScale;this.normalScale=typeof e=="number"?new Ee(e,e):new Ee(Se(e?.x,1),Se(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=Se(t.aoMapIntensity,1),this.bumpMap=t.bumpMap||null,this.bumpScale=Se(t.bumpScale,1),this.clearcoat=Se(t.clearcoat,0),this.clearcoatRoughness=Se(t.clearcoatRoughness,0),this.sheen=Se(t.sheen,0),this.sheenColor=new Pe(t.sheenColor??0),this.sheenRoughness=Se(t.sheenRoughness,0),this.transmission=Se(t.transmission,0),this.thickness=Se(t.thickness,0),this.attenuationColor=new Pe(t.attenuationColor??16777215),this.attenuationDistance=Se(t.attenuationDistance,1/0),this.ior=Se(t.ior,1.5),this.dispersion=Se(t.dispersion,0),this.iridescence=Se(t.iridescence,0),this.iridescenceIOR=Se(t.iridescenceIOR,1.3)}dispose(){}},qe=class extends Ce{},ln=class extends Ce{},mn=class extends Ce{},hn=class extends Ce{},dn=class extends Ce{},ke=class as{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 Q,this.rotation=new pt,this.quaternion=new Qe,this.scale=new Q(1,1,1),this.matrix=new We,this.matrixWorld=new We,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 as&&(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=>{zr(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 Q(e,i,r);this.target instanceof Q?this.target.copy(n):this.target?.position instanceof Q&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new We;s.lookAt(this.position,n,new Q(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 We().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new Q(1,0,0),e)}translateY(e){return this.translateOnAxis(new Q(0,1,0),e)}translateZ(e){return this.translateOnAxis(new Q(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 Q){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new Q){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 Q){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new Qe){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 Ke?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Oe?new Oe(this.geometry,this.material):new this.constructor;if(this instanceof Ge){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 Lt&&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}},fn=class extends ke{},Oe=class extends ke{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof xe?t:t?(Xe("unsupported geometry","BoxGeometry"),new bt(.5,.5,.5)):new xe,this.material=i instanceof Ce?i:i?(Xe("unsupported material","MeshStandardMaterial"),new qe({color:13421772})):new qe}};function zr(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=de().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var xt=1e4,vt=class extends Oe{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>xt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${xt})`);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 we(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 we(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(){}},Mt=class os{constructor(){this.mapSize=new Ee(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 os().copy(this)}},Ge=class extends ke{constructor(t=16777215,e=1){super(),this.isLight=!0,this.shadow=new Mt,this.color=new Pe(t),this.intensity=Number(e),this.type="directional"}},St=class extends Ge{constructor(t,e){super(t,e),this.type="ambient"}},pn=class extends Ge{constructor(t,e){super(t,e),this.target=new ke,this.type="directional"}},wt=class extends Ge{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},_t=class extends ke{},bn=class extends _t{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new Q(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},At=class extends ke{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Ue.validate(this),Je(this)}toGLB(){return Ue.validate(this),lt(this)}toUSDZ(){return Ue.validate(this),mt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof Oe){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},tr=Je,nr=lt,Gr=mt;de().makePngDeflater=Gn;var Ue=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(zr(o),o instanceof Oe||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&s("MESHES",1e3,r),o instanceof vt){let y=a("instance",o.count);(y<0||y>xt)&&s("INSTANCES",xt,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))}}},gn=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 Pe(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){Ue.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=tr(t),s=nr(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 Ir(){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 yn=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=Ir(),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=Ir();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function Li(){}var dt=new Proxy(Li,{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:dt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>dt,construct:()=>dt}),Nr=(()=>{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 Pn(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function tt(t,e){if(!t||typeof t!="string")return!1;let i=t.trim();if(!i)return!1;try{let r=new URL(i,Pn());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,ht;function Hr(t){if(!tt(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(ht===void 0||Pr!==e){Pr=e;try{ht=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!tt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{ht=null}}return ht?ht.createScriptURL(t):t}function Ci(t){de().sandboxEngineSrc=t}function rr(){let t=de().sandboxEngineSrc;if(t)return t;if(Nr)return Nr;try{if(typeof document>"u")return null;let e=Pn(),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)&&tt(n,{requireSameOrigin:!0}))return n}}catch{}return null}function ir(t,e){if(!tt(t))throw new Error(`SecurityError: Disallowed ${e} URL "${t}" (http:, https:, or blob: required).`);return new URL(t,Pn()).href}function Di(){let t=rr();if(!t)throw new Error("SecurityError: Could not locate Three-Live bundle URL for worker sandbox; set ThreeLiveElement.sandboxEngineSrc explicitly.");return ir(t,"sandbox engine")}function Ii(t){de().sandboxIframeSrc=t}function jr(){let t=de().sandboxIframeSrc;if(t)return t;let e=rr();if(!e||!tt(e))return null;let i=new URL(e,Pn());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function Ni(){let t=jr();if(!t)throw new Error("SecurityError: Could not locate three-live-sandbox.html; set ThreeLiveElement.sandboxIframeSrc explicitly.");return ir(t,"sandbox iframe")}function Pi(t){de().allowClientScripts=t}function $r(){return!!de().allowClientScripts}function ki(t){return ir(t,"procedural scene script")}var Fi="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 Ui(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 F=r.__THREE_LIVE_SCENE__(u,T,S,A);F&&typeof F.toGLB=="function"&&(T=F)}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 Vn(e,t,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,n={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:s,revoked:xi},o=(ae().workerExtensionInstallers??[]).map(a=>`(${a.toString()})`).join(",");return`'use strict';(${vi.toString()})(${JSON.stringify(n)},[${o}]);`}function Dr(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 Pe=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 Mi(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var wi=1024,Si=256;function xr(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 zn(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,wi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!xr(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>Si||a==="__proto__"||a==="constructor"||a==="prototype")return null;let h=o[a];if(!xr(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 Ti(e){let t=Mi(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Nr(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 _i(e,t,i,r){let s=Ir(),n=Vn(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,Pe++;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=zn(w,s);M&&Nr(M,r,y,l)};y=()=>{a||(a=!0,c!==void 0&&clearTimeout(c),Pe=Math.max(0,Pe-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(),Dr(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 vr(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(Pe>=32)return r(`SecurityError: ${Pe} 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=di()}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=bi()}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(_i(e,s,y,i))}catch(g){return Promise.reject(g)}}let n=Ir(),o=Vn(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=Er(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.")}Pe++;let h=!1,l={modelDispatched:!1},c,f=()=>{h||(h=!0,c!==void 0&&clearTimeout(c),Pe=Math.max(0,Pe-1),a.terminate())};return c=setTimeout(()=>{h||(f(),Dr(i))},3e3),a.onmessage=y=>{let g=zn(y.data,n);g&&Nr(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 Mr(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 wr=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=wr(i),n=Mr(t,s);if(n)return n;try{Ti(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??Cr()?vr({kind:"script",script:e},t,i,s):s(Hn,Xn)},executeUrl(e,t,i){let r=wr(i),s=Mr(t,r);if(s)return s;let n;try{n=yi(e)}catch(o){let a=o instanceof Error?o.message:String(o);return r(a,"Security Error: disallowed scene script URL.")}return vr({kind:"url",scriptUrl:n},t,i,r)}},on=new Set;function Ge(e,t){let i=`[three-live] ${e} is unsupported; degraded to ${t}.`;on.has(i)||(on.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Pr(){return Array.from(on)}function Fr(){on.clear()}var pt=class extends Ve{constructor(e={}){Ge("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}},kr=pt,Ne=class extends me{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 Z,y=new Z,g=new Z,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 Z().subVectors(m,x).cross(new Z().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)}},Ai=Ne,an=class extends Ne{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)}},It=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Ur=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],cn=class extends Ne{constructor(e=1,t=0){super(It,Ur,e,t)}},oe=(1+Math.sqrt(5))/2,un=class extends Ne{constructor(e=1,t=0){super([-1,oe,0,1,oe,0,-1,-oe,0,1,-oe,0,0,-1,oe,0,1,oe,0,-1,-oe,0,1,-oe,oe,0,-1,oe,0,1,-oe,0,-1,-oe,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)}},we=1/oe,ln=class extends Ne{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,-we,-oe,0,-we,oe,0,we,-oe,0,we,oe,-we,-oe,0,-we,oe,0,we,-oe,0,we,oe,0,-oe,0,-we,oe,0,-we,-oe,0,we,oe,0,we],[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)}},mn=class extends ct{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 Se(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))))}},bt=class extends me{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)}},hn=class extends bt{constructor(e=1,t=32,i=0,r=Math.PI*2){super(0,e,t,1,i,r)}},gt=class extends Me{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)}},Ye=class extends Me{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)}},fn=class extends Ye{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Or(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 dn=class extends me{constructor(e){super(),this.setAttribute("position",new be(Or(e),3)),this.__isSegmentPairs=!0}},pn=class extends me{constructor(e,t=1){super();let i=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new be(Or(e,i),3)),this.__isSegmentPairs=!0}};function Ei(e,t,i=1){let r=new me;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,O=g.length/3,Y=[[S,D,T],[P,j,W],[-S,-D,-T],[-P,-j,-W]];for(let U=0;U<2;U++){let X=R+U*N,V=L+U*_,G=I+U*A;for(let F=0;F<4;F++){let H=Y[F];g.push(X+H[0]*y,V+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(O+U,O+X,O+4+X,O+U,O+4+X,O+4+U)}}return g.length>0&&r.setFromBuffers(g,u,b,w),r}function Ri(e,t=.05){let i=new me;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=It[x*3],p=It[x*3+1],v=It[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+Ur[x])}return i.setFromBuffers(h,l,c,f),i}var ke=class extends Re{constructor(e,t,i="strip"){let r=t&&typeof t=="object"?t:{},s=t instanceof Me?t:i==="points"?new gt(r):new Ye(r),n=e instanceof me?e:new me;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?Ri(this._sourceGeo,this.material?.size??.05):Ei(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},bn=class extends ke{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},gn=class extends ke{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},yn=class extends ke{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},xn=class extends ht{constructor(e,t,i=0,r=Math.PI/3,s=0,n=2){super(e,t,i,n),this.target=new _e,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}},yt=class extends mt{constructor(e,t,i){Ge("HemisphereLight","AmbientLight"),super(e,i),this.groundColor=new Te(t??4473924)}},Br=yt,Vr={Vector2:Se,Vector3:Z,Vector4:Lt,Euler:it,Quaternion:st,Matrix4:Fe,Matrix3:Pt,Color:Te,MathUtils:Sr,BufferAttribute:be,Float32BufferAttribute:Ft,Uint16BufferAttribute:kt,Uint32BufferAttribute:Ut,BufferGeometry:me,BoxGeometry:ot,PlaneGeometry:Ot,SphereGeometry:Bt,CylinderGeometry:at,ConeGeometry:Vt,TorusGeometry:zt,TorusKnotGeometry:Gt,Curve:Ie,Curve3:Ie,LineCurve3:Ht,QuadraticBezierCurve3:Xt,CubicBezierCurve3:$t,CatmullRomCurve3:jt,LatheGeometry:ct,TubeGeometry:Wt,PolyhedronGeometry:Ne,IcosahedronGeometry:un,OctahedronGeometry:cn,DodecahedronGeometry:ln,TetrahedronGeometry:an,CapsuleGeometry:mn,RingGeometry:bt,CircleGeometry:hn,WireframeGeometry:dn,EdgesGeometry:pn,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:We,DataTexture:Kt,TextureLoader:Yt,Material:Me,MeshStandardMaterial:Ve,MeshBasicMaterial:qt,MeshLambertMaterial:Zt,MeshPhongMaterial:Jt,MeshPhysicalMaterial:Qt,PointsMaterial:gt,LineBasicMaterial:Ye,LineDashedMaterial:fn,ShaderMaterial:pt,RawShaderMaterial:kr,Object3D:_e,Group:en,Mesh:Re,InstancedMesh:lt,Line:ke,LineLoop:bn,LineSegments:gn,Points:yn,Light:ze,AmbientLight:mt,DirectionalLight:tn,PointLight:ht,SpotLight:xn,HemisphereLight:yt,RectAreaLight:Br,Camera:ft,PerspectiveCamera:nn,Scene:dt,WebGLRenderer:rn,Clock:sn,SceneQuotaValidator:Ee,exportSceneToCanvas3D:kn,exportSceneToGLB:Un,exportSceneToUSDZ:Ar,generateUSDZ:Pn,glbToUSDZ:Rt,sceneToCanvas3D:je,sceneToGLB:Qe,sceneToUSDZ:et,authorScriptRunner:Lr,getAuthorWarnings:Pr,clearAuthorWarnings:Fr};Object.freeze(Ee),Object.freeze(Ee.prototype),Object.freeze(dt.prototype),Object.freeze(Vr);var He=new Proxy(Vr,{get:(e,t)=>{if(t in e)return e[t];let i=ae().authorNamespace;return i&&typeof t=="string"&&t in i?i[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Ge(`THREE.${t}`,"no-op proxy"),nt)},has:(e,t)=>{if(t in e)return!0;let i=ae().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")}}),Nt=ae();if(Nt.threeNamespace=He,Nt.workerExtensionInstallers)for(let e of Nt.workerExtensionInstallers)e(He,Nt);var rt={name:"three_author",THREE:He},Ci=rt,De=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof De.THREE>"u"&&(De.THREE=He),typeof De.requestAnimationFrame!="function"&&(De.requestAnimationFrame=e=>(typeof e=="function"&&typeof De.__three_live_raf_cb__!="function"&&(De.__three_live_raf_cb__=e),De.__three_live_in_step__||Ge("requestAnimationFrame","single-frame static evaluation"),0)),typeof De.cancelAnimationFrame!="function"&&(De.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=He,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=rt,e.ThreeLivePlugins.three_author=rt,e.ThreeLivePlugins["three-author"]=rt}var Di=He;
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 or(t,e,i){let r=i?.allowedScriptUrl??null,n=i?.allowClientScripts??r===null,s={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:n,revoked:Fi},a=(de().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${Ui.toString()})(${JSON.stringify(s)},[${a}],(${Gn.toString()}));`}function Wr(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 $e=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 Oi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Bi=1024,Vi=256;function kr(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 sr(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,Bi)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let n of r)if(!kr(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>Vi||o==="__proto__"||o==="constructor"||o==="prototype")return null;let l=a[o];if(!kr(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 zi(t){let e=Oi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Kr(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 Gi(t,e,i,r){let n=Xr(),s=or(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,$e++;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=sr(m,n);u&&Kr(u,r,h,y)};h=()=>{o||(o=!0,f!==void 0&&clearTimeout(f),$e=Math.max(0,$e-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(),Wr(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 Fr(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($e>=32)return r(`SecurityError: ${$e} workers running, meeting SECURITY_3D_MAX_CONCURRENT_TASKS (32).`,"Security Error: too many concurrent sandboxed scripts.");let n;try{n=Di()}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=Ni()}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(Gi(t,n,h,i))}catch(d){return Promise.reject(d)}}let s=Xr(),a=or(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=Hr(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.")}$e++;let l=!1,y={modelDispatched:!1},f,b=()=>{l||(l=!0,f!==void 0&&clearTimeout(f),$e=Math.max(0,$e-1),o.terminate())};return f=setTimeout(()=>{l||(b(),Wr(i))},3e3),o.onmessage=h=>{let d=sr(h.data,s);d&&Kr(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 Ur(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 Or=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},Yr={execute(t,e,i,r){let n=Or(i),s=Ur(e,n);if(s)return s;try{zi(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??$r()?Fr({kind:"script",script:t,texturePack:r?.texturePack},e,i,n):n(ur,lr)},executeUrl(t,e,i,r){let n=Or(i),s=Ur(e,n);if(s)return s;let a;try{a=ki(t)}catch(o){let l=o instanceof Error?o.message:String(o);return n(l,"Security Error: disallowed scene script URL.")}return Fr({kind:"url",scriptUrl:a,texturePack:r?.texturePack},e,i,n)}},xn=new Set;function Xe(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;xn.has(i)||(xn.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function qr(){return Array.from(xn)}function Zr(){xn.clear()}var Tt=class extends qe{constructor(t={}){Xe("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}},Jr=Tt,He=class extends xe{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 Q,h=new Q,d=new Q,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 Q().subVectors(p,g).cross(new Q().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)}},Hi=He,vn=class extends He{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)}},ar=t=>Array.from(t,e=>parseInt(e,36)),jt=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Qr=ar("024043035052125153134142"),Mn=class extends He{constructor(t=1,e=0){super(jt,Qr,t,e)}},be=(1+Math.sqrt(5))/2,Sn=class extends He{constructor(t=1,e=0){super([-1,be,0,1,be,0,-1,-be,0,1,-be,0,0,-1,be,0,1,be,0,-1,-be,0,1,-be,be,0,-1,be,0,1,-be,0,-1,-be,0,1],ar("0b505101707a0ab1595b4ba2a7671839434232636838949524b62a867981"),t,e)}},De=1/be,wn=class extends He{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,-De,-be,0,-De,be,0,De,-be,0,De,be,-De,-be,0,-De,be,0,De,-be,0,De,be,0,-be,0,-De,be,0,-De,-be,0,De,be,0,De],ar("3b737f3fd7jh7h676fh48h8aha680g8g282a0c101i0ig6a262d6df2gi2i323di19i9bib34ec4c0408b95b5jbj7j5eje4j4h1ce1e5159"),t,e)}},_n=class extends yt{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 Ee(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))))}},Et=class extends xe{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)}},An=class extends Et{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},Rt=class extends Ce{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)}},nt=class extends Ce{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)}},Tn=class extends nt{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function ei(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 F=D[R],k=D[(R+1)%3],V=a(F),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(F,k)):(y[O]={va:F,vb:k,nx:E,ny:T,nz:S,m:o?1:0},o&&b(F,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 En=class extends xe{constructor(t){super(),this.setAttribute("position",new we(ei(t),3)),this.__isSegmentPairs=!0}},Rn=class extends xe{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new we(ei(t,i),3)),this.__isSegmentPairs=!0}};function ji(t,e,i=1){let r=new xe;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,F=S/A,k=(Math.abs(R)<.9?Math.hypot(F,D):Math.hypot(F,R))||1,V=Math.abs(R)<.9?F/k:0,L=Math.abs(R)<.9?0:-F/k,O=Math.abs(R)<.9?-D/k:R/k,c=R*O-F*L,I=F*V-D*O,C=D*L-R*V,U=d.length/3,j=[[V,L,O],[c,I,C],[-V,-L,-O],[-c,-I,-C]];for(let H=0;H<2;H++){let Y=_+H*E,q=N+H*T,ne=P+H*S;for(let ie=0;ie<4;ie++){let oe=j[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,H)}}for(let H=0;H<4;H++){let Y=(H+1)%4;m.push(U+H,U+Y,U+4+Y,U+H,U+4+Y,U+4+H)}}return d.length>0&&r.setFromBuffers(d,v,M,m),r}function $i(t,e=.05){let i=new xe;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=jt[g*3],x=jt[g*3+1],w=jt[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+Qr[g])}return i.setFromBuffers(l,y,f,b),i}var Ke=class extends Oe{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},n=e instanceof Ce?e:i==="points"?new Rt(r):new nt(r),s=t instanceof xe?t:new xe;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?$i(this._sourceGeo,this.material?.size??.05):ji(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Ln=class extends Ke{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},Cn=class extends Ke{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Dn=class extends Ke{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},In=class extends wt{constructor(t,e,i=0,r=Math.PI/3,n=0,s=2){super(t,e,i,s),this.target=new ke,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}},Lt=class extends Ge{constructor(t,e,i){super(t,i),this.type="hemisphere",this.groundColor=new Pe(e??4473924),this.position.set(0,1,0)}},Nn=class extends St{constructor(t,e){Xe("RectAreaLight","AmbientLight"),super(t,e)}},ti={Vector2:Ee,Vector3:Q,Vector4:Wt,Euler:pt,Quaternion:Qe,Matrix4:We,Matrix3:Xt,Color:Pe,MathUtils:Br,BufferAttribute:we,Float32BufferAttribute:Kt,Uint16BufferAttribute:Yt,Uint32BufferAttribute:qt,BufferGeometry:xe,BoxGeometry:bt,PlaneGeometry:Zt,SphereGeometry:Jt,CylinderGeometry:gt,ConeGeometry:Qt,TorusGeometry:en,TorusKnotGeometry:tn,Curve:ze,Curve3:ze,LineCurve3:nn,QuadraticBezierCurve3:rn,CubicBezierCurve3:on,CatmullRomCurve3:sn,LatheGeometry:yt,TubeGeometry:an,PolyhedronGeometry:He,IcosahedronGeometry:Sn,OctahedronGeometry:Mn,DodecahedronGeometry:wn,TetrahedronGeometry:vn,CapsuleGeometry:_n,RingGeometry:Et,CircleGeometry:An,WireframeGeometry:En,EdgesGeometry:Rn,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:et,DataTexture:cn,TextureLoader:un,Material:Ce,MeshStandardMaterial:qe,MeshBasicMaterial:ln,MeshLambertMaterial:mn,MeshPhongMaterial:hn,MeshPhysicalMaterial:dn,PointsMaterial:Rt,LineBasicMaterial:nt,LineDashedMaterial:Tn,ShaderMaterial:Tt,RawShaderMaterial:Jr,Object3D:ke,Group:fn,Mesh:Oe,InstancedMesh:vt,Line:Ke,LineLoop:Ln,LineSegments:Cn,Points:Dn,LightShadow:Mt,Light:Ge,AmbientLight:St,DirectionalLight:pn,PointLight:wt,SpotLight:In,HemisphereLight:Lt,RectAreaLight:Nn,Camera:_t,PerspectiveCamera:bn,Scene:At,WebGLRenderer:gn,Clock:yn,SceneQuotaValidator:Ue,exportSceneToCanvas3D:tr,exportSceneToGLB:nr,exportSceneToUSDZ:Gr,generateUSDZ:Jn,glbToUSDZ:zt,sceneToCanvas3D:Je,sceneToGLB:lt,sceneToUSDZ:mt,authorScriptRunner:Yr,warnUnsupported:Xe,getAuthorWarnings:qr,clearAuthorWarnings:Zr};Object.freeze(Ue),Object.freeze(Ue.prototype),Object.freeze(At.prototype),Object.freeze(ti);var Ze=new Proxy(ti,{get:(t,e)=>{if(e in t)return t[e];let i=de().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Xe(`THREE.${e}`,"no-op proxy"),dt)},has:(t,e)=>{if(e in t)return!0;let i=de().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=de();if($t.threeNamespace=Ze,$t.workerExtensionInstallers)for(let t of $t.workerExtensionInstallers)t(Ze,$t);var ft={name:"three_author",THREE:Ze},Wi=ft,Ve=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Ve.THREE>"u"&&(Ve.THREE=Ze),typeof Ve.requestAnimationFrame!="function"&&(Ve.requestAnimationFrame=t=>(typeof t=="function"&&typeof Ve.__three_live_raf_cb__!="function"&&(Ve.__three_live_raf_cb__=t),Ve.__three_live_in_step__||Xe("requestAnimationFrame","single-frame static evaluation"),0)),typeof Ve.cancelAnimationFrame!="function"&&(Ve.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=Ze,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=ft,t.ThreeLivePlugins.three_author=ft,t.ThreeLivePlugins["three-author"]=ft}var Xi=Ze;