three-live 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +6 -1
  2. package/dist/index.d.ts +182 -6
  3. package/dist/three-author-engine.js +66 -41
  4. package/dist/three-author.cjs +63 -39
  5. package/dist/three-author.d.ts +182 -6
  6. package/dist/three-author.js +63 -39
  7. package/dist/three-convert.cjs +61 -37
  8. package/dist/three-convert.d.ts +182 -6
  9. package/dist/three-convert.js +61 -37
  10. package/dist/three-live-animation.cjs +7 -7
  11. package/dist/three-live-animation.d.ts +182 -6
  12. package/dist/three-live-animation.js +7 -7
  13. package/dist/three-live-animation.min.js +7 -7
  14. package/dist/three-live-cad.cjs +18 -0
  15. package/dist/{three-live-extras.d.ts → three-live-cad.d.ts} +182 -6
  16. package/dist/three-live-cad.js +18 -0
  17. package/dist/three-live-cad.min.js +18 -0
  18. package/dist/three-live-element.cjs +29 -5
  19. package/dist/three-live-element.d.ts +182 -6
  20. package/dist/three-live-element.js +29 -5
  21. package/dist/three-live-full.cjs +159 -56
  22. package/dist/three-live-full.js +159 -56
  23. package/dist/three-live-full.min.js +159 -56
  24. package/dist/three-live-studio.cjs +120 -0
  25. package/dist/three-live-studio.d.ts +509 -0
  26. package/dist/three-live-studio.js +120 -0
  27. package/dist/three-live-studio.min.js +120 -0
  28. package/dist/three-live-viewer.cjs +29 -5
  29. package/dist/three-live-viewer.d.ts +182 -6
  30. package/dist/three-live-viewer.js +29 -5
  31. package/dist/three-live-viewer.min.js +29 -5
  32. package/dist/three-live.cjs +66 -42
  33. package/dist/three-live.js +66 -42
  34. package/dist/three-live.min.js +66 -42
  35. package/dist/three-view.cjs +29 -5
  36. package/dist/three-view.d.ts +182 -6
  37. package/dist/three-view.js +29 -5
  38. package/dist/three-xr.cjs +65 -41
  39. package/dist/three-xr.d.ts +182 -6
  40. package/dist/three-xr.js +65 -41
  41. package/package.json +10 -5
  42. package/dist/three-live-extras.cjs +0 -42
  43. package/dist/three-live-extras.js +0 -42
  44. package/dist/three-live-extras.min.js +0 -42
@@ -14,7 +14,8 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- "use strict";var _n=Object.defineProperty;var pi=Object.getOwnPropertyDescriptor;var bi=Object.getOwnPropertyNames;var yi=Object.prototype.hasOwnProperty;var gi=(t,e)=>{for(var n in e)_n(t,n,{get:e[n],enumerable:!0})},xi=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of bi(e))!yi.call(t,i)&&i!==n&&_n(t,i,{get:()=>e[i],enumerable:!(r=pi(e,i))||r.enumerable});return t};var vi=t=>xi(_n({},"__esModule",{value:!0}),t);var dr={};gi(dr,{AmbientLight:()=>bt,BoxGeometry:()=>dt,BufferAttribute:()=>re,BufferGeometry:()=>we,Camera:()=>gt,CapsuleGeometry:()=>mn,CircleGeometry:()=>dn,Clock:()=>on,Color:()=>Re,ConeGeometry:()=>$t,CylinderGeometry:()=>Oe,DirectionalLight:()=>tn,DodecahedronGeometry:()=>un,Euler:()=>mt,Float32BufferAttribute:()=>Ht,Group:()=>en,HemisphereLight:()=>wt,IcosahedronGeometry:()=>an,InteractivityVM:()=>Tt,Light:()=>Xe,Material:()=>Ce,MathUtils:()=>Ur,Matrix3:()=>zt,Matrix4:()=>ze,Mesh:()=>Je,MeshBasicMaterial:()=>Kt,MeshLambertMaterial:()=>Zt,MeshPhongMaterial:()=>Jt,MeshPhysicalMaterial:()=>Qt,MeshStandardMaterial:()=>He,Object3D:()=>Te,OctahedronGeometry:()=>cn,PerspectiveCamera:()=>nn,PlaneGeometry:()=>Gt,PointLight:()=>yt,PolyhedronFallbackGeometry:()=>We,Quaternion:()=>ht,RawShaderMaterial:()=>qr,RectAreaLight:()=>Yr,RingGeometry:()=>hn,Scene:()=>xt,SceneQuotaValidator:()=>_e,ShaderMaterial:()=>vt,SphereGeometry:()=>ft,SpotLight:()=>fn,THREE:()=>At,TetrahedronGeometry:()=>ln,Texture:()=>pt,TextureLoader:()=>jt,ThreeLiveElement:()=>Pe,ThreeView:()=>fe,TorusGeometry:()=>qt,TorusKnotGeometry:()=>Yt,Uint16BufferAttribute:()=>Xt,Uint32BufferAttribute:()=>Wt,Vector2:()=>Bt,Vector3:()=>le,Vector4:()=>Vt,WebGLRenderer:()=>rn,activateAR:()=>En,authorScriptRunner:()=>tt,buildSandboxWorkerSource:()=>Vn,clearAuthorWarnings:()=>$r,contactShadowPlugin:()=>Et,createUSDZBlob:()=>Ze,crossFadeTo:()=>Wn,environmentMapPlugin:()=>Kn,exportSceneToCanvas3D:()=>Un,exportSceneToGLB:()=>On,exportSceneToUSDZ:()=>Or,generateUSDZ:()=>at,getARCapabilities:()=>Mn,getAllowClientScripts:()=>zr,getAuthorWarnings:()=>Gr,getBestARMode:()=>fi,getEnvironmentSH:()=>ti,getInteractivityVM:()=>Sn,getSandboxEngineSrc:()=>Bn,getSandboxIframeSrc:()=>Vr,glbToUSDZ:()=>st,hotspotPlugin:()=>Qn,interactivityPlugin:()=>rr,isAllowedSandboxEngineUrl:()=>Be,isQuickLookSupported:()=>lr,isSceneViewerSupported:()=>mr,isWebXRSupported:()=>hr,keyframeAnimationPlugin:()=>Gn,materialsPlugin:()=>or,morphPlugin:()=>$n,noopProxy:()=>ut,parseAnimations:()=>Xn,parseSafeGltfPointer:()=>Rt,registerMaterialShader:()=>ui,sampleChannel:()=>nt,sceneToCanvas3D:()=>je,sceneToGLB:()=>ot,sceneToUSDZ:()=>Ke,sendInteractivityEvent:()=>nr,setAllowClientScripts:()=>Vi,setEnvironmentSH:()=>gn,setMorphTargetWeight:()=>Zr,setSandboxEngineSrc:()=>Ni,setSandboxIframeSrc:()=>Oi,skinningPlugin:()=>Yn,threeAuthorPlugin:()=>lt,threeMicroPlugin:()=>ji,toGLBData:()=>ke,toTrustedWorkerScriptURL:()=>Br,validateSandboxWorkerMessage:()=>zn,warnUnsupported:()=>Ae,webxrPlugin:()=>cr});module.exports=vi(dr);function fr(t,e,n){let r=[],i=new Map,o=[],a=[],l=[],c=new Map,s=y=>{let v=i.get(y);return v===void 0&&(v=r.length,r.push({op:y}),i.set(y,v)),v},u=y=>{let v=c.get(y);return v===void 0&&(v=l.length,l.push({id:y}),c.set(y,v)),v},m=(y,v={})=>o.push({declaration:s(y),...v})-1,h=(y,v,g)=>a.push({id:y,type:v,value:g})-1,f=y=>({node:y,socket:"value"}),d=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(d&&typeof d=="object"){let y=Array.isArray(d.graphs)?d.graphs[d.graph??0]:d;if(y&&Array.isArray(y.nodes)){let v=Array.isArray(y.declarations)?y.declarations:[];for(let g of v)g?.op&&s(g.op);Array.isArray(y.variables)&&a.push(...y.variables);for(let g of y.events||[])g?.id&&u(g.id);for(let g of y.nodes){if(!g||typeof g!="object")continue;let L=g.op||(typeof g.declaration=="number"?v[g.declaration]?.op:"");o.push(L?{...g,declaration:s(L)}:{...g})}}}let p=(y,v,g="translation")=>g==="baseColorFactor"||g==="metallicFactor"||g==="roughnessFactor"?`/materials/${Math.max(0,v)}/pbrMetallicRoughness/${g}`:g==="emissiveFactor"||g==="alphaCutoff"?`/materials/${Math.max(0,v)}/${g}`:g==="visible"?`/nodes/${y}/extensions/KHR_node_visibility/visible`:`/nodes/${y}/${g}`,x=new Map;t.forEach((y,v)=>{typeof y?.name=="string"&&!x.has(y.name)&&x.set(y.name,v)});let P=(y,v)=>typeof y.target=="string"&&x.has(y.target)?x.get(y.target):typeof y.targetNode=="number"?y.targetNode:v,E=y=>{let v=t[y];return(typeof v?.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0};for(let y=0;y<t.length;y++){let v=t[y],g=v?.extras?.interactivity;if(!g||typeof g!="object")continue;let L=(typeof v.mesh=="number"?e[v.mesh]?.primitives?.[0]?.material:0)??0,b=R=>{let _=Array.isArray(R)?R:[R],B=[];for(let I=0;I<_.length;I++){let C=_[I];if(!C||typeof C!="object")continue;let G=C.action||"interpolate",V=typeof C.duration=="number"?C.duration:.35;if(G==="toggleTransform"){let J=C.property==="rotation"||C.property==="scale"?C.property:"translation",j=J==="rotation"?v.rotation||[0,0,0,1]:J==="scale"?v.scale||[1,1,1]:v.translation||[0,0,0],H=`/nodes/${y}/${J}`,X=h(`__toggle_${y}_${I}`,"bool",!1),N=m("variable/get",{configuration:{variable:X}}),$=m("math/not",{values:{a:f(N)}}),Y=m("variable/set",{configuration:{variable:X},values:{value:f($)}}),T=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(C.to)?C.to:j},duration:{value:V}}}),A=m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:Array.isArray(C.from)?C.from:j},duration:{value:V}}});o[Y].flows={out:{node:m("flow/branch",{values:{condition:f(N)},flows:{true:{node:T},false:{node:A}}})}},B.push(Y)}else if(G==="interpolate"){let J=C.to??C.value;if(J===void 0)continue;let j={value:{value:J},duration:{value:V}};C.from!==void 0&&(j.from={value:C.from}),B.push(m("pointer/interpolate",{configuration:{pointer:typeof C.pointer=="string"?C.pointer:p(P(C,y),E(P(C,y)),C.property)},values:j}))}else if(G==="setProperty"){if(C.value===void 0)continue;B.push(m("pointer/set",{configuration:{pointer:typeof C.pointer=="string"?C.pointer:p(P(C,y),E(P(C,y)),C.property)},values:{value:{value:C.value}}}))}else if(G==="toggleVisibility"){let J=P(C,y),j=h(`__vis_${J}_${I}`,"bool",!0),H=m("variable/get",{configuration:{variable:j}}),X=m("math/not",{values:{a:f(H)}}),N=m("variable/set",{configuration:{variable:j},values:{value:f(X)}});o[N].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${J}/extensions/KHR_node_visibility/visible`},values:{value:f(H)}})}},B.push(N)}else if(G==="cycleMaterialColor"&&Array.isArray(C.colors)&&C.colors.length>0){let J=typeof C.duration=="number"?C.duration:.25,j=`/materials/${Math.max(0,L)}/pbrMetallicRoughness/baseColorFactor`,H=h(`__color_idx_${y}_${I}`,"int",0),X=m("variable/get",{configuration:{variable:H}}),N=m("math/add",{values:{a:f(X),b:{value:1}}}),$=m("math/rem",{values:{a:f(N),b:{value:C.colors.length}}}),Y=m("variable/set",{configuration:{variable:H},values:{value:f($)}}),T={};for(let A=0;A<C.colors.length;A++){let S=C.colors[A],k=Array.isArray(S)&&S.length>=3?[S[0],S[1],S[2],S[3]??1]:[1,1,1,1];T[String(A)]={node:J>0?m("pointer/interpolate",{configuration:{pointer:j},values:{value:{value:k},duration:{value:J}}}):m("pointer/set",{configuration:{pointer:j},values:{value:{value:k}}})}}o[Y].flows={out:{node:m("flow/switch",{values:{selection:f(X)},flows:T})}},B.push(Y)}else if(G==="playAnimation")B.push(m("animation/start",{configuration:{animation:C.animation??C.clip??0}}));else if(G==="stopAnimation")B.push(m("animation/stop"));else if(G==="sendEvent"){let J={};for(let[j,H]of Object.entries(C.values||{}))J[j]={value:H};B.push(m("event/send",{configuration:{event:u(String(C.event??C.id??"custom"))},values:J}))}}if(!B.length)return null;if(B.length===1)return B[0];let z={};return B.forEach((I,C)=>{z[String(C)]={node:I}}),m("flow/sequence",{flows:z})},w=(R,_,B)=>{let z=b(_);z!==null&&m(R,{...B?{configuration:B}:{},flows:{out:{node:z}}})};if(g.onSelect&&w("pointer/onSelect",g.onSelect,{nodeIndex:y}),g.onHoverIn&&w("pointer/onHoverIn",g.onHoverIn,{nodeIndex:y}),g.onHoverOut&&w("pointer/onHoverOut",g.onHoverOut,{nodeIndex:y}),g.onStart&&w("event/onStart",g.onStart),g.onReceive&&typeof g.onReceive=="object")for(let[R,_]of Object.entries(g.onReceive))w("event/receive",_,{event:u(R)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:a,events:l}],graph:0}:null}var Pt='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).',Lt="Security Error: client-side scripts require allow-client-scripts opt-in.";var Dt="__THREE_LIVE_REGISTRY__";function ie(){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 ue=ie().plugins;function ge(t){let e=ie().plugins;e.some(n=>n.name===t.name)||e.push(t)}function It(){return ie().plugins}function se(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Ft(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let a=1/(r-i);return t[10]=(i+r)*a,t[14]=2*i*r*a,t}function qe(t,e,n,r){let[i,o,a]=e,[l,c,s]=r,[u,m,h]=n,f=i-u,d=o-m,p=a-h,x=Math.hypot(f,d,p);x<=1e-5?(f=0,d=0,p=1):(f/=x,d/=x,p/=x);let P=c*p-s*d,E=s*f-l*p,y=l*d-c*f;x=Math.hypot(P,E,y),x<=1e-5?(P=0,E=0,y=0):(P/=x,E/=x,y/=x);let v=d*y-p*E,g=p*P-f*y,L=f*E-d*P;return x=Math.hypot(v,g,L),x<=1e-5?(v=0,g=0,L=0):(v/=x,g/=x,L/=x),t[0]=P,t[1]=v,t[2]=f,t[3]=0,t[4]=E,t[5]=g,t[6]=d,t[7]=0,t[8]=y,t[9]=L,t[10]=p,t[11]=0,t[12]=-(P*i+E*o+y*a),t[13]=-(v*i+g*o+L*a),t[14]=-(f*i+d*o+p*a),t[15]=1,t}function be(t,e,n){let r=e[0],i=e[1],o=e[2],a=e[3],l=e[4],c=e[5],s=e[6],u=e[7],m=e[8],h=e[9],f=e[10],d=e[11],p=e[12],x=e[13],P=e[14],E=e[15],y=n[0],v=n[1],g=n[2],L=n[3];return t[0]=y*r+v*l+g*m+L*p,t[1]=y*i+v*c+g*h+L*x,t[2]=y*o+v*s+g*f+L*P,t[3]=y*a+v*u+g*d+L*E,y=n[4],v=n[5],g=n[6],L=n[7],t[4]=y*r+v*l+g*m+L*p,t[5]=y*i+v*c+g*h+L*x,t[6]=y*o+v*s+g*f+L*P,t[7]=y*a+v*u+g*d+L*E,y=n[8],v=n[9],g=n[10],L=n[11],t[8]=y*r+v*l+g*m+L*p,t[9]=y*i+v*c+g*h+L*x,t[10]=y*o+v*s+g*f+L*P,t[11]=y*a+v*u+g*d+L*E,y=n[12],v=n[13],g=n[14],L=n[15],t[12]=y*r+v*l+g*m+L*p,t[13]=y*i+v*c+g*h+L*x,t[14]=y*o+v*s+g*f+L*P,t[15]=y*a+v*u+g*d+L*E,t}function Ye(t,e,n,r){let i=e[0],o=e[1],a=e[2],l=e[3],c=i+i,s=o+o,u=a+a,m=i*c,h=i*s,f=i*u,d=o*s,p=o*u,x=a*u,P=l*c,E=l*s,y=l*u,v=r[0],g=r[1],L=r[2];return t[0]=(1-(d+x))*v,t[1]=(h+y)*v,t[2]=(f-E)*v,t[3]=0,t[4]=(h-y)*g,t[5]=(1-(m+x))*g,t[6]=(p+P)*g,t[7]=0,t[8]=(f+E)*L,t[9]=(p-P)*L,t[10]=(1-(m+d))*L,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function de(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],a=e[5],l=e[6],c=e[8],s=e[9],u=e[10],m=u*a-l*s,h=-u*o+l*c,f=s*o-a*c,d=n*m+r*h+i*f;return d&&(d=1/d,t[0]=m*d,t[1]=(-u*r+i*s)*d,t[2]=(l*r-i*a)*d,t[3]=h*d,t[4]=(u*n-i*c)*d,t[5]=(-l*n+i*o)*d,t[6]=f*d,t[7]=(-s*n+r*c)*d,t[8]=(a*n-r*o)*d),t}function kt(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],a=e[4],l=e[5],c=e[6],s=e[7],u=e[8],m=e[9],h=e[10],f=e[11],d=e[12],p=e[13],x=e[14],P=e[15],E=n*l-r*a,y=n*c-i*a,v=n*s-o*a,g=r*c-i*l,L=r*s-o*l,b=i*s-o*c,w=u*p-m*d,R=u*x-h*d,_=u*P-f*d,B=m*x-h*p,z=m*P-f*p,I=h*P-f*x,C=E*I-y*z+v*B+g*_-L*R+b*w;return C?(C=1/C,t[0]=(l*I-c*z+s*B)*C,t[1]=(i*z-r*I-o*B)*C,t[2]=(p*b-x*L+P*g)*C,t[3]=(h*L-m*b-f*g)*C,t[4]=(c*_-a*I-s*R)*C,t[5]=(n*I-i*_+o*R)*C,t[6]=(x*v-d*b-P*y)*C,t[7]=(u*b-h*v+f*y)*C,t[8]=(a*z-l*_+s*w)*C,t[9]=(r*_-n*z-o*w)*C,t[10]=(d*L-p*v+P*E)*C,t[11]=(m*v-u*L-f*E)*C,t[12]=(l*R-a*B-c*w)*C,t[13]=(n*B-r*R+i*w)*C,t[14]=(p*y-d*g-x*E)*C,t[15]=(u*g-m*y+h*E)*C,t):null}function Cn(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],a=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],c=i[3]*e+i[7]*n+i[11]*r+i[15],s=c!==0?1/c:1;t[0]=o*s,t[1]=a*s,t[2]=l*s}function pr(t,e,n,r,i,o,a,l,c,s,u,m,h,f,d,p,x=0){let P=s-a,E=u-l,y=m-c,v=h-a,g=f-l,L=d-c,b=i*L-o*g,w=o*v-r*L,R=r*g-i*v,_=P*b+E*w+y*R;if(_>-1e-7&&_<1e-7)return!1;let B=1/_,z=t-a,I=e-l,C=n-c,G=B*(z*b+I*w+C*R);if(G<-x||G>1+x)return!1;let V=I*y-C*E,J=C*P-z*y,j=z*E-I*P,H=B*(r*V+i*J+o*j);if(H<-x||G+H>1+x)return!1;let X=B*(v*V+g*J+L*j);if(X>1e-4&&X<p.distance){p.distance=X,p.point=[t+r*X,e+i*X,n+o*X];let N=E*L-y*g,$=y*v-P*L,Y=P*g-E*v,T=Math.hypot(N,$,Y)||1;return p.normal=[N/T,$/T,Y/T],!0}return!1}function Fe(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(se());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let m of u.children)i.add(m);let o=new Set,a=128,l=(u,m,h=0)=>{if(h>a||u<0||u>=n||o.has(u))return;o.add(u);let f=t.nodes[u];if(!f)return;let d=se();if(e&&e[u])d.set(e[u]);else if(f.matrix&&f.matrix.length===16)d.set(f.matrix);else{let x=f.translation||[0,0,0],P=f.rotation||[0,0,0,1],E=f.scale||[1,1,1];Ye(d,P,x,E)}let p=r[u];if(m?be(p,m,d):p.set(d),Array.isArray(f.children))for(let x of f.children)typeof x=="number"&&l(x,p,h+1)},c=[],s=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(s&&Array.isArray(s.nodes))c.push(...s.nodes);else for(let u=0;u<n;u++)i.has(u)||c.push(u);for(let u of c)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!c.includes(u)&&l(u,null);return r}function wi(t){return new TextDecoder().decode(t)}var xr=ie().decoders;function Ai(t,e){xr.set(t.toLowerCase(),e)}function it(t){return xr.get(t.toLowerCase())}function vr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let h=n.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 i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),a=12,l=null,c=null;for(;a+8<=o&&a+8<=e.byteLength;){let h=n.getUint32(a,!0),f=n.getUint32(a+4,!0),d=a+8;if(d+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${d+h} bytes, buffer has ${e.byteLength}`);if(f===1313821514){let p=new Uint8Array(e,d,h),x=wi(p);l=JSON.parse(x,(P,E)=>P==="__proto__"||P==="constructor"||P==="prototype"?void 0:E)}else f===5130562&&(c=e.slice(d,d+h));a=d+h}if(!l)throw new Error("Missing JSON chunk in GLB");let s=l.extensionsRequired||[];if(s.includes("KHR_draco_mesh_compression")&&!it("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(s.includes("EXT_meshopt_compression")&&!it("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(s.includes("KHR_texture_basisu")&&!it("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=c||new ArrayBuffer(0),m={gltf:l,bin:u,animations:[]};for(let h of ue)h.onParseGLB?.(m);return m}function Si(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 ke(t){if(Si(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return vr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var wr=`#version 300 es
17
+ "use strict";var Mr=Object.defineProperty;var ss=Object.getOwnPropertyDescriptor;var as=Object.getOwnPropertyNames;var cs=Object.prototype.hasOwnProperty;var us=(t,e)=>{for(var n in e)Mr(t,n,{get:e[n],enumerable:!0})},ls=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of as(e))!cs.call(t,i)&&i!==n&&Mr(t,i,{get:()=>e[i],enumerable:!(r=ss(e,i))||r.enumerable});return t};var ms=t=>ls(Mr({},"__esModule",{value:!0}),t);var Ei={};us(Ei,{AmbientLight:()=>on,BoxGeometry:()=>Jt,BufferAttribute:()=>Me,BufferGeometry:()=>Xe,Camera:()=>an,CapsuleGeometry:()=>tr,CircleGeometry:()=>rr,Clock:()=>jn,Color:()=>$e,ConeGeometry:()=>Un,CylinderGeometry:()=>yt,DirectionalLight:()=>$n,DodecahedronGeometry:()=>Jn,Euler:()=>Zt,Float32BufferAttribute:()=>Dn,Group:()=>Wn,HemisphereLight:()=>ln,IKSolver:()=>Hi,IcosahedronGeometry:()=>Zn,InstancedMesh:()=>rn,InteractivityVM:()=>dn,Light:()=>Mt,MAX_BSP_DEPTH:()=>zi,MAX_CSG_TRIANGLES:()=>Bi,MAX_INSTANCES_PER_MESH:()=>nn,MAX_TEXT_GEOMETRY_CHARS:()=>Gi,Material:()=>Qe,MathUtils:()=>po,Matrix3:()=>Pn,Matrix4:()=>vt,Mesh:()=>wt,MeshBasicMaterial:()=>zn,MeshLambertMaterial:()=>Gn,MeshPhongMaterial:()=>Xn,MeshPhysicalMaterial:()=>Hn,MeshStandardMaterial:()=>Tt,Object3D:()=>qe,OctahedronGeometry:()=>Qn,PerspectiveCamera:()=>qn,PlaneGeometry:()=>Fn,PointLight:()=>sn,PolyhedronFallbackGeometry:()=>At,Quaternion:()=>Qt,RawShaderMaterial:()=>Eo,RectAreaLight:()=>Ro,RingGeometry:()=>nr,Scene:()=>cn,SceneQuotaValidator:()=>Ze,ShaderMaterial:()=>un,SphereGeometry:()=>en,SpotLight:()=>ir,THREE:()=>St,TetrahedronGeometry:()=>er,Texture:()=>tn,TextureLoader:()=>Bn,ThreeLiveElement:()=>Je,ThreeView:()=>Fe,TorusGeometry:()=>On,TorusKnotGeometry:()=>Vn,Uint16BufferAttribute:()=>kn,Uint32BufferAttribute:()=>Nn,Vector2:()=>In,Vector3:()=>Ce,Vector4:()=>Ln,WebGLRenderer:()=>Yn,activateAR:()=>mr,applyMeshoptFilter:()=>gr,authorScriptRunner:()=>Gt,buildSandboxWorkerSource:()=>Wr,cadPlugin:()=>Ar,clearAuthorWarnings:()=>So,computeOutlineClipOffset:()=>es,contactShadowPlugin:()=>fn,createUSDZBlob:()=>Vt,crossFadeTo:()=>jr,decodeMeshoptBuffer:()=>gi,decodeMeshoptGLB:()=>bn,encodeMeshoptBuffer:()=>Ko,environmentMapPlugin:()=>ai,evaluateKawaseBloom:()=>Jo,evaluateToneMapping:()=>Qi,exportSceneToCanvas3D:()=>Gr,exportSceneToGLB:()=>Xr,exportSceneToUSDZ:()=>yo,extractMaterialVariants:()=>Mi,extractPrimitiveVariantMappings:()=>ts,generateUSDZ:()=>qt,getARCapabilities:()=>lr,getAllowClientScripts:()=>vo,getAuthorWarnings:()=>Ao,getBestARMode:()=>ko,getEnvironmentSH:()=>Oo,getInteractivityVM:()=>yr,getSandboxEngineSrc:()=>Hr,getSandboxIframeSrc:()=>xo,glbToUSDZ:()=>$t,hotspotPlugin:()=>li,ikPlugin:()=>Lr,installCadExtension:()=>wn,interactivityPlugin:()=>di,isAllowedSandboxEngineUrl:()=>gt,isQuickLookSupported:()=>ri,isSceneViewerSupported:()=>ii,isWebXRSupported:()=>oi,keyframeAnimationPlugin:()=>Kr,materialsPlugin:()=>bi,meshoptDecoder:()=>xr,meshoptPlugin:()=>xi,morphPlugin:()=>Zr,noopProxy:()=>jt,parseAnimations:()=>Yr,parseHexRgb:()=>Ti,parseSafeGltfPointer:()=>hn,postprocessingPlugin:()=>wi,quatFromUnitVectors:()=>Xi,registerMaterialShader:()=>$o,sampleChannel:()=>Xt,sceneToCanvas3D:()=>Ut,sceneToGLB:()=>Wt,sceneToUSDZ:()=>Ot,selectMaterialVariant:()=>ns,sendInteractivityEvent:()=>hi,setAllowClientScripts:()=>Fs,setEnvironmentSH:()=>fr,setMorphTargetWeight:()=>Io,setSandboxEngineSrc:()=>Ps,setSandboxIframeSrc:()=>ks,skinningPlugin:()=>Jr,solveFABRIK:()=>Ir,solveTwoBoneIK:()=>Cr,threeAuthorPlugin:()=>Kt,threeMicroPlugin:()=>Ws,toGLBData:()=>ot,toTrustedWorkerScriptURL:()=>go,validateSandboxWorkerMessage:()=>$r,variantsPlugin:()=>Ai,warnUnsupported:()=>He,webxrPlugin:()=>Si});module.exports=ms(Ei);function Vi(t,e,n){let r=[],i=new Map,o=[],s=[],c=[],a=new Map,u=x=>{let R=i.get(x);return R===void 0&&(R=r.length,r.push({op:x}),i.set(x,R)),R},l=x=>{let R=a.get(x);return R===void 0&&(R=c.length,c.push({id:x}),a.set(x,R)),R},m=(x,R={})=>o.push({declaration:u(x),...R})-1,f=(x,R,I)=>s.push({id:x,type:R,value:I})-1,h=x=>({node:x,socket:"value"}),b=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(b&&typeof b=="object"){let x=Array.isArray(b.graphs)?b.graphs[b.graph??0]:b;if(x&&Array.isArray(x.nodes)){let R=Array.isArray(x.declarations)?x.declarations:[];for(let I of R)I?.op&&u(I.op);Array.isArray(x.variables)&&s.push(...x.variables);for(let I of x.events||[])I?.id&&l(I.id);for(let I of x.nodes){if(!I||typeof I!="object")continue;let P=I.op||(typeof I.declaration=="number"?R[I.declaration]?.op:"");o.push(P?{...I,declaration:u(P)}:{...I})}}}let d=(x,R,I="translation")=>I==="baseColorFactor"||I==="metallicFactor"||I==="roughnessFactor"?`/materials/${Math.max(0,R)}/pbrMetallicRoughness/${I}`:I==="emissiveFactor"||I==="alphaCutoff"?`/materials/${Math.max(0,R)}/${I}`:I==="visible"?`/nodes/${x}/extensions/KHR_node_visibility/visible`:`/nodes/${x}/${I}`,p=new Map;t.forEach((x,R)=>{typeof x?.name=="string"&&!p.has(x.name)&&p.set(x.name,R)});let E=(x,R)=>typeof x.target=="string"&&p.has(x.target)?p.get(x.target):typeof x.targetNode=="number"?x.targetNode:R,A=x=>{let R=t[x];return(typeof R?.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0};for(let x=0;x<t.length;x++){let R=t[x],I=R?.extras?.interactivity;if(!I||typeof I!="object")continue;let P=(typeof R.mesh=="number"?e[R.mesh]?.primitives?.[0]?.material:0)??0,k=S=>{let _=Array.isArray(S)?S:[S],v=[];for(let L=0;L<_.length;L++){let U=_[L];if(!U||typeof U!="object")continue;let q=U.action||"interpolate",W=typeof U.duration=="number"?U.duration:.35;if(q==="toggleTransform"){let K=U.property==="rotation"||U.property==="scale"?U.property:"translation",Y=K==="rotation"?R.rotation||[0,0,0,1]:K==="scale"?R.scale||[1,1,1]:R.translation||[0,0,0],te=`/nodes/${x}/${K}`,ie=f(`__toggle_${x}_${L}`,"bool",!1),$=m("variable/get",{configuration:{variable:ie}}),ne=m("math/not",{values:{a:h($)}}),re=m("variable/set",{configuration:{variable:ie},values:{value:h(ne)}}),O=m("pointer/interpolate",{configuration:{pointer:te},values:{value:{value:Array.isArray(U.to)?U.to:Y},duration:{value:W}}}),X=m("pointer/interpolate",{configuration:{pointer:te},values:{value:{value:Array.isArray(U.from)?U.from:Y},duration:{value:W}}});o[re].flows={out:{node:m("flow/branch",{values:{condition:h($)},flows:{true:{node:O},false:{node:X}}})}},v.push(re)}else if(q==="interpolate"){let K=U.to??U.value;if(K===void 0)continue;let Y={value:{value:K},duration:{value:W}};U.from!==void 0&&(Y.from={value:U.from}),v.push(m("pointer/interpolate",{configuration:{pointer:typeof U.pointer=="string"?U.pointer:d(E(U,x),A(E(U,x)),U.property)},values:Y}))}else if(q==="setProperty"){if(U.value===void 0)continue;v.push(m("pointer/set",{configuration:{pointer:typeof U.pointer=="string"?U.pointer:d(E(U,x),A(E(U,x)),U.property)},values:{value:{value:U.value}}}))}else if(q==="toggleVisibility"){let K=E(U,x),Y=f(`__vis_${K}_${L}`,"bool",!0),te=m("variable/get",{configuration:{variable:Y}}),ie=m("math/not",{values:{a:h(te)}}),$=m("variable/set",{configuration:{variable:Y},values:{value:h(ie)}});o[$].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${K}/extensions/KHR_node_visibility/visible`},values:{value:h(te)}})}},v.push($)}else if(q==="cycleMaterialColor"&&Array.isArray(U.colors)&&U.colors.length>0){let K=typeof U.duration=="number"?U.duration:.25,Y=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,te=f(`__color_idx_${x}_${L}`,"int",0),ie=m("variable/get",{configuration:{variable:te}}),$=m("math/add",{values:{a:h(ie),b:{value:1}}}),ne=m("math/rem",{values:{a:h($),b:{value:U.colors.length}}}),re=m("variable/set",{configuration:{variable:te},values:{value:h(ne)}}),O={};for(let X=0;X<U.colors.length;X++){let M=U.colors[X],N=Array.isArray(M)&&M.length>=3?[M[0],M[1],M[2],M[3]??1]:[1,1,1,1];O[String(X)]={node:K>0?m("pointer/interpolate",{configuration:{pointer:Y},values:{value:{value:N},duration:{value:K}}}):m("pointer/set",{configuration:{pointer:Y},values:{value:{value:N}}})}}o[re].flows={out:{node:m("flow/switch",{values:{selection:h(ie)},flows:O})}},v.push(re)}else if(q==="playAnimation")v.push(m("animation/start",{configuration:{animation:U.animation??U.clip??0}}));else if(q==="stopAnimation")v.push(m("animation/stop"));else if(q==="sendEvent"){let K={};for(let[Y,te]of Object.entries(U.values||{}))K[Y]={value:te};v.push(m("event/send",{configuration:{event:l(String(U.event??U.id??"custom"))},values:K}))}}if(!v.length)return null;if(v.length===1)return v[0];let G={};return v.forEach((L,U)=>{G[String(U)]={node:L}}),m("flow/sequence",{flows:G})},D=(S,_,v)=>{let G=k(_);G!==null&&m(S,{...v?{configuration:v}:{},flows:{out:{node:G}}})};if(I.onSelect&&D("pointer/onSelect",I.onSelect,{nodeIndex:x}),I.onHoverIn&&D("pointer/onHoverIn",I.onHoverIn,{nodeIndex:x}),I.onHoverOut&&D("pointer/onHoverOut",I.onHoverOut,{nodeIndex:x}),I.onStart&&D("event/onStart",I.onStart),I.onReceive&&typeof I.onReceive=="object")for(let[S,_]of Object.entries(I.onReceive))D("event/receive",_,{event:l(S)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:s,events:c}],graph:0}:null}var yn='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).',gn="Security Error: client-side scripts require allow-client-scripts opt-in.";var xn="__THREE_LIVE_REGISTRY__";function pe(){let t=typeof globalThis<"u"?globalThis:{};if(!t[xn]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,xn,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[xn]=e}}return t[xn]}var Ie=pe().plugins;function vn(t){let e=pe();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function Pe(t){let e=pe().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function Tn(){return pe().plugins}var Bi=8192,zi=512,Gi=128;function wn(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,s=t.Color,c=t.BufferAttribute,a=t.BufferGeometry,u=t.Material,l=t.MeshStandardMaterial,m=t.Mesh,f=8192,h=512,b=128;class d{constructor(g){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(g)&&g.length>0&&this.fromPoints(g)}fromPoints(g){if(!g.length)return this;this.moveTo(g[0].x,g[0].y);for(let T=1;T<g.length;T++)this.lineTo(g[T].x,g[T].y);return this}moveTo(g,T){let C=Number(g)||0,B=Number(T)||0;return this.currentPoint.set(C,B),this.segments.push({type:"move",pts:[C,B]}),this}lineTo(g,T){let C=Number(g)||0,B=Number(T)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(C,B),this.segments.push({type:"line",pts:[C,B]}),this}quadraticCurveTo(g,T,C,B){let w=this.currentPoint.x,F=this.currentPoint.y,H=Number(g)||0,J=Number(T)||0,Z=Number(C)||0,ee=Number(B)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[w,F]}),this.currentPoint.set(Z,ee),this.segments.push({type:"quad",pts:[w,F,H,J,Z,ee]}),this}bezierCurveTo(g,T,C,B,w,F){let H=this.currentPoint.x,J=this.currentPoint.y,Z=Number(g)||0,ee=Number(T)||0,j=Number(C)||0,Q=Number(B)||0,se=Number(w)||0,oe=Number(F)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[H,J]}),this.currentPoint.set(se,oe),this.segments.push({type:"cubic",pts:[H,J,Z,ee,j,Q,se,oe]}),this}absarc(g,T,C,B,w,F=!1){return this.absellipse(g,T,C,C,B,w,F,0)}arc(g,T,C,B,w,F=!1){return this.absarc(this.currentPoint.x+(Number(g)||0),this.currentPoint.y+(Number(T)||0),C,B,w,F)}absellipse(g,T,C,B,w,F,H=!1,J=0){let Z=Number(g)||0,ee=Number(T)||0,j=Math.max(0,Number(C)||0),Q=Math.max(0,Number(B)||0),se=Number(w)||0,oe=Number(F)||0,ce=H?1:0,ue=Number(J)||0;this.segments.push({type:"arc",pts:[Z,ee,j,Q,se,oe,ce,ue]});let le=Math.cos(ue),de=Math.sin(ue),be=j*Math.cos(oe),he=Q*Math.sin(oe);return this.currentPoint.set(Z+be*le-he*de,ee+be*de+he*le),this}ellipse(g,T,C,B,w,F,H=!1,J=0){return this.absellipse(this.currentPoint.x+(Number(g)||0),this.currentPoint.y+(Number(T)||0),C,B,w,F,H,J)}closePath(){if(this.segments.length>0){let g=this.segments[0],T=0,C=0;if(g.type==="arc"){let B=g.pts[0],w=g.pts[1],F=g.pts[2],H=g.pts[3],J=g.pts[4],Z=g.pts[7],ee=Math.cos(Z),j=Math.sin(Z),Q=F*Math.cos(J),se=H*Math.sin(J);T=B+Q*ee-se*j,C=w+Q*j+se*ee}else T=g.pts[0],C=g.pts[1];Math.hypot(this.currentPoint.x-T,this.currentPoint.y-C)>1e-6&&this.lineTo(T,C)}return this}getPoints(g=12){let T=Math.max(1,Math.min(128,Math.floor(Number(g)||12))),C=[],B=(w,F)=>{if(C.length>0){let H=C[C.length-1];if(Math.hypot(H.x-w,H.y-F)<1e-6)return}C.push(new n(w,F))};for(let w of this.segments){let F=w.pts;if(w.type==="move"||w.type==="line")B(F[0],F[1]);else if(w.type==="quad"){let H=F[0],J=F[1],Z=F[2],ee=F[3],j=F[4],Q=F[5];B(H,J);for(let se=1;se<=T;se++){let oe=se/T,ce=1-oe;B(ce*ce*H+2*ce*oe*Z+oe*oe*j,ce*ce*J+2*ce*oe*ee+oe*oe*Q)}}else if(w.type==="cubic"){let H=F[0],J=F[1],Z=F[2],ee=F[3],j=F[4],Q=F[5],se=F[6],oe=F[7];B(H,J);for(let ce=1;ce<=T;ce++){let ue=ce/T,le=1-ue,de=le*le,be=ue*ue;B(de*le*H+3*de*ue*Z+3*le*be*j+be*ue*se,de*le*J+3*de*ue*ee+3*le*be*Q+be*ue*oe)}}else if(w.type==="arc"){let H=F[0],J=F[1],Z=F[2],ee=F[3],j=F[4],Q=F[5],se=F[6]!==0,oe=F[7],ce=Math.PI*2,ue=Q-j,le=Math.abs(ue)<1e-9;for(;ue<0;)ue+=ce;for(;ue>ce;)ue-=ce;ue<1e-9&&(ue=le?0:ce),se&&!le&&(ue=ue===ce?-ce:ue-ce);let de=Math.cos(oe),be=Math.sin(oe),he=Math.max(2,T);for(let me=0;me<=he;me++){let ge=me/he,Te=j+ge*ue,ye=Z*Math.cos(Te),ve=ee*Math.sin(Te);B(H+ye*de-ve*be,J+ye*be+ve*de)}}}if(C.length>2){let w=C[0],F=C[C.length-1];Math.hypot(w.x-F.x,w.y-F.y)<1e-6&&C.pop()}return C}getSpacedPoints(g=12){return this.getPoints(g)}}class p extends d{constructor(g){super(g),this.holes=[]}extractPoints(g=12){return{shape:this.getPoints(g),holes:this.holes.map(T=>T.getPoints(g))}}}function E(y){let g=0,T=y.length;for(let C=0,B=T-1;C<T;B=C++)g+=y[B].x*y[C].y-y[C].x*y[B].y;return g*.5}function A(y,g,T,C,B,w,F,H){let J=F-T,Z=H-C,ee=B-T,j=w-C,Q=y-T,se=g-C,oe=J*J+Z*Z,ce=J*ee+Z*j,ue=J*Q+Z*se,le=ee*ee+j*j,de=ee*Q+j*se,be=oe*le-ce*ce;if(Math.abs(be)<1e-12)return!1;let he=1/be,me=(le*ue-ce*de)*he,ge=(oe*de-ce*ue)*he;return me>=-1e-7&&ge>=-1e-7&&me+ge<=1+1e-7}function x(y,g){let T=y.slice();E(T)<0&&T.reverse();let C=T.map(F=>new n(F.x,F.y)),B=T.map((F,H)=>H),w=[];for(let F of g){if(!F||F.length<3)continue;let H=F.slice();E(H)>0&&H.reverse();let J=[],Z=-1/0,ee=0;for(let j=0;j<H.length;j++){let Q=H[j],se=C.length;C.push(new n(Q.x,Q.y)),J.push(se),Q.x>Z&&(Z=Q.x,ee=j)}w.push({pts:H,indices:J,maxX:Z,maxIdx:ee})}w.sort((F,H)=>H.maxX-F.maxX);for(let F of w){let H=F.pts[F.maxIdx].x,J=F.pts[F.maxIdx].y,Z=0,ee=1/0;for(let Q=0;Q<B.length;Q++){let se=C[B[Q]],oe=Math.hypot(se.x-H,se.y-J)+(se.x>=H?0:1e3);oe<ee&&(ee=oe,Z=Q)}let j=[];for(let Q=0;Q<=Z;Q++)j.push(B[Q]);for(let Q=0;Q<=F.indices.length;Q++){let se=F.indices[(F.maxIdx+Q)%F.indices.length];j.push(se)}for(let Q=Z;Q<B.length;Q++)j.push(B[Q]);B=j}return{merged:B.map(F=>C[F]),mergedIndices:B,allVertices:C}}function R(y,g){let T=[],C=y.slice();if(C.length<3)return T;let B=C.length*C.length+64,w=0;for(;C.length>2&&B-- >0;){let F=C.length,H=C[(w+F-1)%F],J=C[w%F],Z=C[(w+1)%F],ee=g[H],j=g[J],Q=g[Z];if((j.x-ee.x)*(Q.y-ee.y)-(j.y-ee.y)*(Q.x-ee.x)>1e-9){let oe=!0;for(let ce=0;ce<F;ce++){let ue=C[ce];if(ue===H||ue===J||ue===Z)continue;let le=g[ue];if(!(Math.hypot(le.x-ee.x,le.y-ee.y)<1e-6||Math.hypot(le.x-j.x,le.y-j.y)<1e-6||Math.hypot(le.x-Q.x,le.y-Q.y)<1e-6)&&A(le.x,le.y,ee.x,ee.y,j.x,j.y,Q.x,Q.y)){oe=!1;break}}if(oe){T.push([H,J,Z]),C.splice(w%F,1),w=0;continue}}w++,w>=F*2&&(T.push([H,J,Z]),C.splice(w%F,1),w=0)}return T}class I extends a{constructor(g=new p,T=12){super();let C=Array.isArray(g)?g:[g],B=[],w=[],F=[],H=[];for(let J of C){if(!(J instanceof d))continue;let Z=J instanceof p?J.extractPoints(T):{shape:J.getPoints(T),holes:[]};if(Z.shape.length<3)continue;let{mergedIndices:ee,allVertices:j}=x(Z.shape,Z.holes),Q=R(ee,j),se=B.length/3,oe=1/0,ce=1/0,ue=-1/0,le=-1/0;for(let he of j)he.x<oe&&(oe=he.x),he.y<ce&&(ce=he.y),he.x>ue&&(ue=he.x),he.y>le&&(le=he.y);let de=Math.max(1e-6,ue-oe),be=Math.max(1e-6,le-ce);for(let he of j)B.push(he.x,he.y,0),w.push(0,0,1),F.push((he.x-oe)/de,(he.y-ce)/be);for(let[he,me,ge]of Q)H.push(se+he,se+me,se+ge)}this.setAttribute("position",new c(new Float32Array(B),3)),this.setAttribute("normal",new c(new Float32Array(w),3)),this.setAttribute("uv",new c(new Float32Array(F),2)),this.setIndex(H)}}function P(y){let g=y.length,T=[];for(let C=0;C<g;C++){let B=y[(C+g-1)%g],w=y[C],F=y[(C+1)%g],H=w.x-B.x,J=w.y-B.y,Z=Math.hypot(H,J)||1;H/=Z,J/=Z;let ee=F.x-w.x,j=F.y-w.y,Q=Math.hypot(ee,j)||1;ee/=Q,j/=Q;let se=J,oe=-H,ce=j,ue=-ee,le=se+ce,de=oe+ue,be=Math.hypot(le,de);if(be>1e-6){le/=be,de/=be;let he=Math.max(.35,le*se+de*oe);T.push(new n(le/he,de/he))}else T.push(new n(se,oe))}return T}class k extends a{constructor(g=new p,T={}){super();let C=Array.isArray(g)?g:[g],B=Math.max(1,Math.min(64,Math.floor(Number(T.curveSegments??12)))),w=Number.isFinite(Number(T.depth??T.amount))?Number(T.depth??T.amount):1,F=Math.max(1,Math.min(32,Math.floor(Number(T.steps??1)))),H=!!(T.bevelEnabled??!1),J=H?Math.max(0,Number(T.bevelThickness??.06)):0,Z=H?Math.max(0,Number(T.bevelSize??J*.8)):0,ee=H?Number(T.bevelOffset??0):0,j=H?Math.max(1,Math.min(8,Math.floor(Number(T.bevelSegments??2)))):0,Q=[],se=[],oe=[],ce=[];for(let ue of C){if(!(ue instanceof d))continue;let le=ue instanceof p?ue.extractPoints(B):{shape:ue.getPoints(B),holes:[]};if(le.shape.length<3)continue;let de=le.shape.slice();E(de)<0&&de.reverse();let be=[];for(let fe of le.holes){if(fe.length<3)continue;let Ae=fe.slice();E(Ae)>0&&Ae.reverse(),be.push(Ae)}let{mergedIndices:he,allVertices:me}=x(de,be),ge=R(he,me),Te=[de,...be],ye=[];for(let fe of Te){let Ae=P(fe);for(let Se of Ae)ye.push(Se)}let ve=1/0,_e=1/0,Ue=-1/0,Ve=-1/0;for(let fe of me)fe.x<ve&&(ve=fe.x),fe.y<_e&&(_e=fe.y),fe.x>Ue&&(Ue=fe.x),fe.y>Ve&&(Ve=fe.y);let Ge=Math.max(1e-6,Ue-ve),je=Math.max(1e-6,Ve-_e),_t=-J,Ct=w+J,ct=Q.length/3;for(let fe=0;fe<me.length;fe++){let Ae=me[fe],Se=ye[fe]??new n(0,0),De=Ae.x+Se.x*ee,ke=Ae.y+Se.y*ee;Q.push(De,ke,_t),se.push(0,0,-1),oe.push((De-ve)/Ge,(ke-_e)/je)}for(let[fe,Ae,Se]of ge)ce.push(ct+fe,ct+Se,ct+Ae);let ut=Q.length/3;for(let fe=0;fe<me.length;fe++){let Ae=me[fe],Se=ye[fe]??new n(0,0),De=Ae.x+Se.x*ee,ke=Ae.y+Se.y*ee;Q.push(De,ke,Ct),se.push(0,0,1),oe.push((De-ve)/Ge,(ke-_e)/je)}for(let[fe,Ae,Se]of ge)ce.push(ut+fe,ut+Ae,ut+Se);let Be=[];if(H&&j>0)for(let fe=0;fe<j;fe++){let Se=fe/j*Math.PI/2;Be.push({z:-J*Math.cos(Se),expand:ee+Z*Math.sin(Se)})}for(let fe=0;fe<=F;fe++){let Ae=fe/F;Be.push({z:Ae*w,expand:ee+Z})}if(H&&j>0)for(let fe=1;fe<=j;fe++){let Se=fe/j*Math.PI/2;Be.push({z:w+J*Math.sin(Se),expand:ee+Z*Math.cos(Se)})}let Ke=0;for(let fe of Te){let Ae=fe.length;for(let Se=0;Se<Be.length-1;Se++){let De=Be[Se],ke=Be[Se+1];for(let ze=0;ze<Ae;ze++){let tt=(ze+1)%Ae,lt=fe[ze],mt=fe[tt],ft=ye[Ke+ze],ht=ye[Ke+tt],dt=lt.x+ft.x*De.expand,pt=lt.y+ft.y*De.expand,xt=mt.x+ht.x*De.expand,nt=mt.y+ht.y*De.expand,is=mt.x+ht.x*ke.expand,os=mt.y+ht.y*ke.expand,Ri=lt.x+ft.x*ke.expand,_i=lt.y+ft.y*ke.expand,Ci=xt-dt,Ii=nt-pt,Li=0,Pi=Ri-dt,Di=_i-pt,ki=ke.z-De.z,It=Ii*ki-Li*Di,Lt=Li*Pi-Ci*ki,Pt=Ci*Di-Ii*Pi,wr=Math.hypot(It,Lt,Pt)||1;It/=wr,Lt/=wr,Pt/=wr;let Dt=Q.length/3;Q.push(dt,pt,De.z,xt,nt,De.z,is,os,ke.z,Ri,_i,ke.z),se.push(It,Lt,Pt,It,Lt,Pt,It,Lt,Pt,It,Lt,Pt);let Ni=ze/Ae,Fi=(ze+1)/Ae,Ui=Se/(Be.length-1),Oi=(Se+1)/(Be.length-1);oe.push(Ni,Ui,Fi,Ui,Fi,Oi,Ni,Oi),ce.push(Dt,Dt+1,Dt+2,Dt,Dt+2,Dt+3)}}Ke+=Ae}}this.setAttribute("position",new c(new Float32Array(Q),3)),this.setAttribute("normal",new c(new Float32Array(se),3)),this.setAttribute("uv",new c(new Float32Array(oe),2)),this.setIndex(ce)}}function D(y){return{x:y.x,y:y.y,z:y.z,nx:y.nx,ny:y.ny,nz:y.nz,u:y.u,v:y.v}}function S(y){return{x:y.x,y:y.y,z:y.z,nx:-y.nx,ny:-y.ny,nz:-y.nz,u:y.u,v:y.v}}function _(y,g,T){let C=y.nx+(g.nx-y.nx)*T,B=y.ny+(g.ny-y.ny)*T,w=y.nz+(g.nz-y.nz)*T,F=Math.hypot(C,B,w)||1;return{x:y.x+(g.x-y.x)*T,y:y.y+(g.y-y.y)*T,z:y.z+(g.z-y.z)*T,nx:C/F,ny:B/F,nz:w/F,u:y.u+(g.u-y.u)*T,v:y.v+(g.v-y.v)*T}}function v(y){if(y.length<3)return null;let g=y[0],T=y[1],C=y[2],B=T.x-g.x,w=T.y-g.y,F=T.z-g.z,H=C.x-g.x,J=C.y-g.y,Z=C.z-g.z,ee=w*Z-F*J,j=F*H-B*Z,Q=B*J-w*H,se=Math.hypot(ee,j,Q);if(se<1e-9)return null;ee/=se,j/=se,Q/=se;let oe=ee*g.x+j*g.y+Q*g.z;return{vertices:y,nx:ee,ny:j,nz:Q,w:oe}}function G(y){y.vertices.reverse();for(let g=0;g<y.vertices.length;g++)y.vertices[g]=S(y.vertices[g]);y.nx=-y.nx,y.ny=-y.ny,y.nz=-y.nz,y.w=-y.w}let L=1e-5,U=0,q=1,W=2,K=3;function Y(y,g,T,C,B,w,F,H,J){let Z=0,ee=[];for(let j=0;j<B.vertices.length;j++){let Q=B.vertices[j],se=y*Q.x+g*Q.y+T*Q.z-C,oe=se<-L?W:se>L?q:U;Z|=oe,ee.push(oe)}switch(Z){case U:{y*B.nx+g*B.ny+T*B.nz>0?w.push(B):F.push(B);break}case q:H.push(B);break;case W:J.push(B);break;case K:{let j=[],Q=[],se=B.vertices.length;for(let oe=0;oe<se;oe++){let ce=(oe+1)%se,ue=ee[oe],le=ee[ce],de=B.vertices[oe],be=B.vertices[ce];if(ue!==W&&j.push(de),ue!==q&&Q.push(ue!==W?D(de):de),(ue|le)===K){let he=be.x-de.x,me=be.y-de.y,ge=be.z-de.z,Te=y*he+g*me+T*ge,ye=Math.abs(Te)>1e-12?(C-(y*de.x+g*de.y+T*de.z))/Te:.5,ve=_(de,be,Math.max(0,Math.min(1,ye)));j.push(ve),Q.push(D(ve))}}if(j.length>=3){let oe=v(j);oe&&H.push(oe)}if(Q.length>=3){let oe=v(Q);oe&&J.push(oe)}break}default:break}}class te{constructor(g,T=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,g&&g.length>0&&this.build(g,T)}invert(){for(let T=0;T<this.polygons.length;T++)G(this.polygons[T]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let g=this.front;this.front=this.back,this.back=g}clipPolygons(g,T=0){if(!this.hasPlane||g.length===0||T>=h)return g.slice();let C=[],B=[];for(let w=0;w<g.length;w++)Y(this.nx,this.ny,this.nz,this.w,g[w],C,B,C,B);return this.front&&C.length>0&&(C=this.front.clipPolygons(C,T+1)),this.back?B=B.length>0?this.back.clipPolygons(B,T+1):[]:B=[],C.concat(B)}clipTo(g,T=0){this.polygons.length>0&&(this.polygons=g.clipPolygons(this.polygons,0)),T<h&&(this.front&&this.front.clipTo(g,T+1),this.back&&this.back.clipTo(g,T+1))}allPolygons(g=[]){for(let T=0;T<this.polygons.length;T++)g.push(this.polygons[T]);return this.front&&this.front.allPolygons(g),this.back&&this.back.allPolygons(g),g}build(g,T=0){if(!g.length)return;if(!this.hasPlane){let w=g[0];this.nx=w.nx,this.ny=w.ny,this.nz=w.nz,this.w=w.w,this.hasPlane=!0}if(T>=h){for(let w=0;w<g.length;w++)this.polygons.push(g[w]);return}let C=[],B=[];for(let w=0;w<g.length;w++)Y(this.nx,this.ny,this.nz,this.w,g[w],this.polygons,this.polygons,C,B);C.length>0&&(this.front||(this.front=new te),this.front.build(C,T+1)),B.length>0&&(this.back||(this.back=new te),this.back.build(B,T+1))}}function ie(y,g){let T=y.attributes.position;if(!T||T.count===0)return[];let C=y.attributes.normal,B=y.attributes.uv,w=y.index?y.index.array:null,F=Math.floor(w?w.length/3:T.count/3);if(F>f)throw new RangeError(`SecurityError: CSG input triangle count (${F}) exceeds MAX_CSG_TRIANGLES (${f})`);let H=g?g.elements:null,J=H?H[0]*(H[5]*H[10]-H[9]*H[6])-H[4]*(H[1]*H[10]-H[9]*H[2])+H[8]*(H[1]*H[6]-H[5]*H[2])<0:!1,Z=j=>{let Q=T.getX(j),se=T.getY(j),oe=T.getZ(j),ce=C?C.getX(j):0,ue=C?C.getY(j):0,le=C?C.getZ(j):1;if(H){let he=H[0]*Q+H[4]*se+H[8]*oe+H[12],me=H[1]*Q+H[5]*se+H[9]*oe+H[13],ge=H[2]*Q+H[6]*se+H[10]*oe+H[14];Q=he,se=me,oe=ge;let Te=H[0]*ce+H[4]*ue+H[8]*le,ye=H[1]*ce+H[5]*ue+H[9]*le,ve=H[2]*ce+H[6]*ue+H[10]*le,_e=Math.hypot(Te,ye,ve)||1;ce=Te/_e,ue=ye/_e,le=ve/_e}let de=B?B.getX(j):0,be=B?B.getY(j):0;return{x:Q,y:se,z:oe,nx:ce,ny:ue,nz:le,u:de,v:be}},ee=[];for(let j=0;j<F;j++){let Q=w?w[j*3]:j*3,se=w?w[j*3+1]:j*3+1,oe=w?w[j*3+2]:j*3+2,ce=v(J?[Z(Q),Z(oe),Z(se)]:[Z(Q),Z(se),Z(oe)]);ce&&ee.push(ce)}return ee}function $(y){let g=[],T=[],C=[],B=[];for(let F of y){let H=F.vertices;if(H.length<3)continue;let J=g.length/3;for(let Z of H)g.push(Z.x,Z.y,Z.z),T.push(F.nx,F.ny,F.nz),C.push(Z.u,Z.v);for(let Z=1;Z<H.length-1;Z++)B.push(J,J+Z,J+Z+1)}let w=new a;return w.setAttribute("position",new c(new Float32Array(g),3)),w.setAttribute("normal",new c(new Float32Array(T),3)),w.setAttribute("uv",new c(new Float32Array(C),2)),w.setIndex(B),w}function ne(y,g,T){if(y.length+g.length>f)throw new RangeError(`SecurityError: Combined CSG triangle count (${y.length+g.length}) exceeds MAX_CSG_TRIANGLES (${f})`);if(y.length===0)return T==="union"?g:[];if(g.length===0)return T==="intersect"?[]:y;let C=new te(y),B=new te(g);return T==="union"?(C.clipTo(B),B.clipTo(C),B.invert(),B.clipTo(C),B.invert(),C.build(B.allPolygons()),C.allPolygons()):T==="subtract"?(C.invert(),C.clipTo(B),B.clipTo(C),B.invert(),B.clipTo(C),B.invert(),C.build(B.allPolygons()),C.invert(),C.allPolygons()):(C.invert(),B.clipTo(C),B.invert(),C.clipTo(B),B.clipTo(C),C.build(B.allPolygons()),C.invert(),C.allPolygons())}function re(y,g,T,C=null,B=null){let w=ie(y,C),F=ie(g,B);return $(ne(w,F,T))}function O(y,g,T){let C=y instanceof m||!!y?.isMesh,B=g instanceof m||!!g?.isMesh,w=C?y.geometry:y,F=B?g.geometry:g,H=null;if(B)if(g.updateMatrix(),C){y.updateMatrix();let j=new o().makeScale(1/(y.scale.x||1),1/(y.scale.y||1),1/(y.scale.z||1)),Q=Math.hypot(y.quaternion.x,y.quaternion.y,y.quaternion.z,y.quaternion.w)||1,se=new o().compose(new r(0,0,0),new i(-y.quaternion.x/Q,-y.quaternion.y/Q,-y.quaternion.z/Q,y.quaternion.w/Q),new r(1,1,1)),oe=new o().makeTranslation(-y.position.x,-y.position.y,-y.position.z);H=j.multiply(se).multiply(oe).multiply(g.matrix)}else H=g.matrix;let J=re(w,F,T,null,H),Z=C?y.material:new l,ee=new m(J,Z);return C&&(ee.position.copy(y.position),ee.quaternion.copy(y.quaternion),ee.scale.copy(y.scale),ee.name=y.name),ee}let X={toGeometry:re,subtract(y,g){return O(y,g,"subtract")},union(y,g){return O(y,g,"union")},intersect(y,g){return O(y,g,"intersect")}},M={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class N extends a{constructor(g="",T={}){super();let C=String(g??"").slice(0,b),B=Math.max(.005,Math.min(100,Number(T.size??.2))),w=!!(T.bevelEnabled??!1),F=w?Math.max(0,Math.min(2,Number(T.bevelThickness??B*.04))):0,H=w?Math.max(0,Math.min(2,Number(T.bevelSize??B*.03))):0,J=Math.max(.001,Math.min(20,Number(T.depth??T.height??B*.2)))+F*2,Z=B*.085+H,ee=B*.68,j=B*.82,Q=[],se=[],oe=[],ce=[],ue=(be,he,me,ge,Te,ye,ve)=>{let _e=me-be,Ue=ge-he,Ve=Math.hypot(_e,Ue),Ge=1,je=0;Ve>1e-6&&(Ge=_e/Ve,je=Ue/Ve);let _t=-je*Te,Ct=Ge*Te,ct=Ge*Te*.6,ut=je*Te*.6,Be=be-ct+_t,Ke=he-ut+Ct,fe=be-ct-_t,Ae=he-ut-Ct,Se=me+ct-_t,De=ge+ut-Ct,ke=me+ct+_t,ze=ge+ut+Ct,tt=(lt,mt,ft,ht,dt,pt,xt)=>{let nt=Q.length/3;Q.push(lt[0],lt[1],lt[2],mt[0],mt[1],mt[2],ft[0],ft[1],ft[2],ht[0],ht[1],ht[2]),se.push(dt,pt,xt,dt,pt,xt,dt,pt,xt,dt,pt,xt),oe.push(0,0,1,0,1,1,0,1),ce.push(nt,nt+1,nt+2,nt,nt+2,nt+3)};tt([Be,Ke,ve],[fe,Ae,ve],[Se,De,ve],[ke,ze,ve],0,0,1),tt([fe,Ae,ye],[Be,Ke,ye],[ke,ze,ye],[Se,De,ye],0,0,-1),tt([Be,Ke,ye],[fe,Ae,ye],[fe,Ae,ve],[Be,Ke,ve],-Ge,-je,0),tt([Se,De,ye],[ke,ze,ye],[ke,ze,ve],[Se,De,ve],Ge,je,0),tt([fe,Ae,ye],[Se,De,ye],[Se,De,ve],[fe,Ae,ve],-je,Ge,0),tt([ke,ze,ye],[Be,Ke,ye],[Be,Ke,ve],[ke,ze,ve],je,-Ge,0)},le=0,de=0;for(let be=0;be<C.length;be++){let he=C[be];if(he===`
18
+ `){le=0,de-=B*1.35;continue}if(he===" "){le+=j*.75;continue}let me=he.toUpperCase(),ge=he!==me&&he>="a"&&he<="z",Te=M[me]??M["?"],ye=ge?B*.76:B,ve=ge?ee*.88:ee;for(let _e of Te)for(let Ue=0;Ue<_e.length-1;Ue++){let Ve=_e[Ue],Ge=_e[Ue+1];ue(le+Ve[0]*ve,de+Ve[1]*ye,le+Ge[0]*ve,de+Ge[1]*ye,Z,-J*.5,J*.5)}le+=ge?j*.88:j}this.setAttribute("position",new c(new Float32Array(Q),3)),this.setAttribute("normal",new c(new Float32Array(se),3)),this.setAttribute("uv",new c(new Float32Array(oe),2)),this.setIndex(ce),T.center!==!1?this.center():this.computeBoundingBox()}}function z(y){if(!y)return;let g=y,T=y.userData?.xr?.text;if(T!=null&&T!==!1){let B=g.geometry?.attributes?.position;if(!B||B.count===0){let w="",F=.08,H=.015,J;if(typeof T=="string"||typeof T=="number")w=String(T);else if(typeof T=="object"){let Z=T;w=String(Z.text??Z.value??""),Z.size!==void 0&&(F=Number(Z.size)||.08),(Z.depth!==void 0||Z.height!==void 0)&&(H=Number(Z.depth??Z.height)||F*.2),(typeof Z.color=="string"||typeof Z.color=="number")&&(J=Z.color)}w.trim().length>0&&(g.geometry=new N(w,{size:F,depth:H}),g.material instanceof u?J!==void 0&&y.userData._autoTextColorApplied!==!0&&(g.material.color=new s(J),y.userData._autoTextColorApplied=!0):g.material=new l({color:J??16317180}))}}let C=y.userData?.csg;if(C&&typeof C=="object"&&y.userData._csgApplied!==!0&&g.geometry instanceof a&&g.geometry.attributes.position?.count>0){y.userData._csgApplied=!0;let B=Array.isArray(C)?C:[C];for(let w of B){if(!w||typeof w!="object")continue;let F=w,H=String(F.op??F.operation??"subtract"),J=H==="union"||H==="intersect"?H:"subtract",Z=F.target??F.mesh??F.geometry;if(Z instanceof m||Z instanceof a){let ee=J==="union"?X.union(g,Z):J==="intersect"?X.intersect(g,Z):X.subtract(g,Z);g.geometry=ee.geometry}}}}let V={Path:d,Shape:p,ShapeGeometry:I,ExtrudeGeometry:k,TextGeometry:N,CSG:X,MAX_CSG_TRIANGLES:f,MAX_BSP_DEPTH:h,MAX_TEXT_GEOMETRY_CHARS:b,materializeDeclarativeGeometry:z};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,V),e.materializeDeclarativeGeometry=z),V}var Ar={name:"cad",onRegister(){vn(wn);let t=pe(),e=t.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);e&&wn(e,t)}};function Rr(t,e){function n(a,u,l,m){let f=typeof a=="number"?a:Number(a);return Number.isFinite(f)?Math.max(u,Math.min(l,f)):m}function r(a,u){let m=a[0]*u[0]+a[1]*u[1]+a[2]*u[2]+1;if(m<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let E=Math.hypot(a[1],a[0])||1;return[-a[1]/E,a[0]/E,0,0]}let p=Math.hypot(a[2],a[1])||1;return[0,-a[2]/p,a[1]/p,0]}let f=a[1]*u[2]-a[2]*u[1],h=a[2]*u[0]-a[0]*u[2],b=a[0]*u[1]-a[1]*u[0],d=Math.hypot(f,h,b,m)||1;return[f/d,h/d,b/d,m/d]}function i(a,u,l,m,f){let h=u[0]-a[0],b=u[1]-a[1],d=u[2]-a[2],p=Math.hypot(h,b,d),E=l[0]-u[0],A=l[1]-u[1],x=l[2]-u[2],R=Math.hypot(E,A,x);if(p<1e-6||R<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[u[0],u[1],u[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let I=[h/p,b/p,d/p],P=[E/R,A/R,x/R],k=m[0]-a[0],D=m[1]-a[1],S=m[2]-a[2],_=Math.hypot(k,D,S),v=_>1e-6?[k/_,D/_,S/_]:I,G=Math.abs(p-R)+1e-5,L=Math.max(G,p+R-1e-5),U=Math.max(G,Math.min(L,_>1e-6?_:G)),q=n((p*p+U*U-R*R)/(2*p*U),-1,1,1),W=Math.sqrt(Math.max(0,1-q*q)),K=f?f[0]-a[0]:h,Y=f?f[1]-a[1]:b,te=f?f[2]-a[2]:d,ie=K*v[0]+Y*v[1]+te*v[2],$=K-v[0]*ie,ne=Y-v[1]*ie,re=te-v[2]*ie,O=Math.hypot($,ne,re);if(O<=1e-6){let w=Math.abs(v[1])<.99?0:1,F=Math.abs(v[1])<.99?1:0,H=0;$=v[1]*H-v[2]*F,ne=v[2]*w-v[0]*H,re=v[0]*F-v[1]*w,O=Math.hypot($,ne,re)||1}let X=[$/O,ne/O,re/O],M=[a[0]+v[0]*(p*q)+X[0]*(p*W),a[1]+v[1]*(p*q)+X[1]*(p*W),a[2]+v[2]*(p*q)+X[2]*(p*W)],N=[a[0]+v[0]*U,a[1]+v[1]*U,a[2]+v[2]*U],z=N[0]-M[0],V=N[1]-M[1],y=N[2]-M[2],g=Math.hypot(z,V,y),T=g>1e-6?[z/g,V/g,y/g]:v,C=[M[0]+T[0]*R,M[1]+T[1]*R,M[2]+T[2]*R],B=[(M[0]-a[0])/p,(M[1]-a[1])/p,(M[2]-a[2])/p];return{rootPos:[a[0],a[1],a[2]],midPos:M,effectorPos:C,rootRotation:r(I,B),midRotation:r(P,T)}}function o(a,u,l=8,m=.001){let f=a.length;if(f<2)return{positions:a.map(_=>[_[0],_[1],_[2]]),rotations:[],iterations:0};let h=a.map(_=>[_[0],_[1],_[2]]),b=[],d=[],p=0;for(let _=0;_<f-1;_++){let v=h[_+1][0]-h[_][0],G=h[_+1][1]-h[_][1],L=h[_+1][2]-h[_][2],U=Math.hypot(v,G,L);b.push(U),p+=U,d.push(U>1e-6?[v/U,G/U,L/U]:[0,1,0])}let E=[h[0][0],h[0][1],h[0][2]],A=Math.round(n(l,1,32,8)),x=n(m,1e-5,.1,.001),R=u[0]-E[0],I=u[1]-E[1],P=u[2]-E[2],k=Math.hypot(R,I,P),D=0;if(k>=p&&p>1e-6){let _=k>1e-6?[R/k,I/k,P/k]:d[0];h[0]=[E[0],E[1],E[2]];for(let v=0;v<f-1;v++){let G=b[v];h[v+1]=[h[v][0]+_[0]*G,h[v][1]+_[1]*G,h[v][2]+_[2]*G]}D=1}else for(let _=1;_<=A;_++){let v=h[f-1];if(Math.hypot(v[0]-u[0],v[1]-u[1],v[2]-u[2])<=x)break;D=_,h[f-1]=[u[0],u[1],u[2]];for(let L=f-2;L>=0;L--){let U=h[L][0]-h[L+1][0],q=h[L][1]-h[L+1][1],W=h[L][2]-h[L+1][2],K=Math.hypot(U,q,W),Y=b[L];if(K>1e-6){let te=Y/K;h[L]=[h[L+1][0]+U*te,h[L+1][1]+q*te,h[L+1][2]+W*te]}else{let te=d[L];h[L]=[h[L+1][0]-te[0]*Y,h[L+1][1]-te[1]*Y,h[L+1][2]-te[2]*Y]}}h[0]=[E[0],E[1],E[2]];for(let L=0;L<f-1;L++){let U=h[L+1][0]-h[L][0],q=h[L+1][1]-h[L][1],W=h[L+1][2]-h[L][2],K=Math.hypot(U,q,W),Y=b[L];if(K>1e-6){let te=Y/K;h[L+1]=[h[L][0]+U*te,h[L][1]+q*te,h[L][2]+W*te]}else{let te=d[L];h[L+1]=[h[L][0]+te[0]*Y,h[L][1]+te[1]*Y,h[L][2]+te[2]*Y]}}}let S=[];for(let _=0;_<f-1;_++){let v=h[_+1][0]-h[_][0],G=h[_+1][1]-h[_][1],L=h[_+1][2]-h[_][2],U=Math.hypot(v,G,L),q=U>1e-6?[v/U,G/U,L/U]:d[_];S.push(r(d[_],q))}return{positions:h,rotations:S,iterations:D}}function s(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let u=a;if(u.enabled===!1)return null;let l=R=>{if(typeof R!="string")return;let I=R.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(I)?I:void 0},m=R=>Array.isArray(R)&&R.length===3&&typeof R[0]=="number"&&Number.isFinite(R[0])&&typeof R[1]=="number"&&Number.isFinite(R[1])&&typeof R[2]=="number"&&Number.isFinite(R[2]),f=l(u.root),h=l(u.effector);if(!f||!h)return null;let b=l(u.mid),d=u.target,p;if(m(d))p=[n(d[0],-1e3,1e3,0),n(d[1],-1e3,1e3,0),n(d[2],-1e3,1e3,0)];else{let R=l(d);if(!R)return null;p=R}let E=u.pole,A=m(E)?[n(E[0],-1e3,1e3,0),n(E[1],-1e3,1e3,0),n(E[2],-1e3,1e3,0)]:void 0,x=u.solver==="fabrik"?"fabrik":u.solver==="two-bone"||b?"two-bone":"fabrik";return{root:f,...b?{mid:b}:{},effector:h,target:p,...A?{pole:A}:{},solver:x,iterations:Math.round(n(u.iterations,1,32,8)),tolerance:n(u.tolerance,1e-5,.1,.001),weight:n(u.weight,0,1,1)}}let c=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:s});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=c),{clampNum:n,parseIKTrait:s,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:c}}var kt=Rr(),fs=kt.clampNum,hs=kt.parseIKTrait,Xi=kt.quatFromUnitVectors,Cr=kt.solveTwoBoneIK,Ir=kt.solveFABRIK,Hi=kt.IKSolver;function _r(t){let e=t?.transform??t?.modelMatrix;return e&&e.length>=16?[e[12]||0,e[13]||0,e[14]||0]:[0,0,0]}function Sr(t,e){let n=t?.transform??t?.modelMatrix;!n||n.length<16||(n[12]=e[0],n[13]=e[1],n[14]=e[2])}function Er(t,e,n,r,i){let o=fs(i,0,1,1),s=e[0]+(n[0]-e[0])*o,c=e[1]+(n[1]-e[1])*o,a=e[2]+(n[2]-e[2])*o,u=s-t[0],l=c-t[1],m=a-t[2],f=Math.hypot(u,l,m);if(f>1e-6&&r>1e-6){let h=r/f;return[t[0]+u*h,t[1]+l*h,t[2]+m*h]}return[s,c,a]}function ds(t,e,n){if(Array.isArray(t))return[t[0],t[1],t[2]];let r=e.get(t);if(r)return _r(r);if(t==="head"){let i=n?.headPose?.position??n?.headPose??n?.cameraPosition;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}else if(t==="hand-left"){let i=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}else if(t==="hand-right"){let i=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right;if(Array.isArray(i)&&i.length>=3)return[i[0],i[1],i[2]]}return null}var Lr={name:"ik",onRegister(){let t=pe();vn(Rr),Rr(t.threeNamespace,t)},onUpdate(t){let e=t?.meshes;if(!Array.isArray(e)||e.length===0)return;let n=null;for(let r of e){let i=r?.userData?.xr?.ik??r?.extras?.xr?.ik??r?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let o=hs(i);if(!o||o.weight<=0)continue;if(!n){n=new Map;for(let p of e)p&&typeof p.name=="string"&&p.name&&n.set(p.name,p)}let s=n.get(o.root),c=n.get(o.effector);if(!s||!c)continue;let a=ds(o.target,n,t);if(!a)continue;let u=o.mid?n.get(o.mid):void 0,l=u?[s,u,c]:[s,c],m=l.map(p=>p.name||"").join(">");if(!r.__ikRestOffsets||r.__ikRestKey!==m){let p=l.map(_r),E=[];for(let A=0;A<p.length-1;A++)E.push([p[A+1][0]-p[A][0],p[A+1][1]-p[A][1],p[A+1][2]-p[A][2]]);r.__ikRestOffsets=E,r.__ikRestKey=m}let f=r.__ikRestOffsets,b=[_r(s)],d=[];for(let p=0;p<f.length;p++){let E=b[p],A=f[p];b.push([E[0]+A[0],E[1]+A[1],E[2]+A[2]]),d.push(Math.hypot(A[0],A[1],A[2]))}if(o.solver==="two-bone"&&u&&b.length===3){let p=Cr(b[0],b[1],b[2],a,o.pole),E=Er(b[0],b[1],p.midPos,d[0],o.weight),A=[E[0]+f[1][0],E[1]+f[1][1],E[2]+f[1][2]],x=[E[0]+(p.effectorPos[0]-p.midPos[0]),E[1]+(p.effectorPos[1]-p.midPos[1]),E[2]+(p.effectorPos[2]-p.midPos[2])],R=Er(E,A,x,d[1],o.weight);Sr(u,E),Sr(c,R)}else{let p=Ir(b,a,o.iterations,o.tolerance),E=b[0];for(let A=1;A<l.length;A++){let x=f[A-1],R=[E[0]+x[0],E[1]+x[1],E[2]+x[2]],I=[E[0]+(p.positions[A][0]-p.positions[A-1][0]),E[1]+(p.positions[A][1]-p.positions[A-1][1]),E[2]+(p.positions[A][2]-p.positions[A-1][2])],P=Er(E,R,I,d[A-1],o.weight);Sr(l[A],P),E=P}}}}};function we(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Mn(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let s=1/(r-i);return t[10]=(i+r)*s,t[14]=2*i*r*s,t}function Nt(t,e,n,r){let[i,o,s]=e,[c,a,u]=r,[l,m,f]=n,h=i-l,b=o-m,d=s-f,p=Math.hypot(h,b,d);p<=1e-5?(h=0,b=0,d=1):(h/=p,b/=p,d/=p);let E=a*d-u*b,A=u*h-c*d,x=c*b-a*h;p=Math.hypot(E,A,x),p<=1e-5?(E=0,A=0,x=0):(E/=p,A/=p,x/=p);let R=b*x-d*A,I=d*E-h*x,P=h*A-b*E;return p=Math.hypot(R,I,P),p<=1e-5?(R=0,I=0,P=0):(R/=p,I/=p,P/=p),t[0]=E,t[1]=R,t[2]=h,t[3]=0,t[4]=A,t[5]=I,t[6]=b,t[7]=0,t[8]=x,t[9]=P,t[10]=d,t[11]=0,t[12]=-(E*i+A*o+x*s),t[13]=-(R*i+I*o+P*s),t[14]=-(h*i+b*o+d*s),t[15]=1,t}function Ee(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],c=e[4],a=e[5],u=e[6],l=e[7],m=e[8],f=e[9],h=e[10],b=e[11],d=e[12],p=e[13],E=e[14],A=e[15],x=n[0],R=n[1],I=n[2],P=n[3];return t[0]=x*r+R*c+I*m+P*d,t[1]=x*i+R*a+I*f+P*p,t[2]=x*o+R*u+I*h+P*E,t[3]=x*s+R*l+I*b+P*A,x=n[4],R=n[5],I=n[6],P=n[7],t[4]=x*r+R*c+I*m+P*d,t[5]=x*i+R*a+I*f+P*p,t[6]=x*o+R*u+I*h+P*E,t[7]=x*s+R*l+I*b+P*A,x=n[8],R=n[9],I=n[10],P=n[11],t[8]=x*r+R*c+I*m+P*d,t[9]=x*i+R*a+I*f+P*p,t[10]=x*o+R*u+I*h+P*E,t[11]=x*s+R*l+I*b+P*A,x=n[12],R=n[13],I=n[14],P=n[15],t[12]=x*r+R*c+I*m+P*d,t[13]=x*i+R*a+I*f+P*p,t[14]=x*o+R*u+I*h+P*E,t[15]=x*s+R*l+I*b+P*A,t}function rt(t,e,n,r){let i=e[0],o=e[1],s=e[2],c=e[3],a=i+i,u=o+o,l=s+s,m=i*a,f=i*u,h=i*l,b=o*u,d=o*l,p=s*l,E=c*a,A=c*u,x=c*l,R=r[0],I=r[1],P=r[2];return t[0]=(1-(b+p))*R,t[1]=(f+x)*R,t[2]=(h-A)*R,t[3]=0,t[4]=(f-x)*I,t[5]=(1-(m+p))*I,t[6]=(d+E)*I,t[7]=0,t[8]=(h+A)*P,t[9]=(d-E)*P,t[10]=(1-(m+b))*P,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function Le(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],c=e[6],a=e[8],u=e[9],l=e[10],m=l*s-c*u,f=-l*o+c*a,h=u*o-s*a,b=n*m+r*f+i*h;return b&&(b=1/b,t[0]=m*b,t[1]=f*b,t[2]=h*b,t[3]=(-l*r+i*u)*b,t[4]=(l*n-i*a)*b,t[5]=(-u*n+r*a)*b,t[6]=(c*r-i*s)*b,t[7]=(-c*n+i*o)*b,t[8]=(s*n-r*o)*b),t}function An(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],c=e[5],a=e[6],u=e[7],l=e[8],m=e[9],f=e[10],h=e[11],b=e[12],d=e[13],p=e[14],E=e[15],A=n*c-r*s,x=n*a-i*s,R=n*u-o*s,I=r*a-i*c,P=r*u-o*c,k=i*u-o*a,D=l*d-m*b,S=l*p-f*b,_=l*E-h*b,v=m*p-f*d,G=m*E-h*d,L=f*E-h*p,U=A*L-x*G+R*v+I*_-P*S+k*D;return U?(U=1/U,t[0]=(c*L-a*G+u*v)*U,t[1]=(i*G-r*L-o*v)*U,t[2]=(d*k-p*P+E*I)*U,t[3]=(f*P-m*k-h*I)*U,t[4]=(a*_-s*L-u*S)*U,t[5]=(n*L-i*_+o*S)*U,t[6]=(p*R-b*k-E*x)*U,t[7]=(l*k-f*R+h*x)*U,t[8]=(s*G-c*_+u*D)*U,t[9]=(r*_-n*G-o*D)*U,t[10]=(b*P-d*R+E*A)*U,t[11]=(m*R-l*P-h*A)*U,t[12]=(c*S-s*v-a*D)*U,t[13]=(n*v-r*S+i*D)*U,t[14]=(d*x-b*I-p*A)*U,t[15]=(l*I-m*x+f*A)*U,t):null}function Pr(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],s=i[1]*e+i[5]*n+i[9]*r+i[13],c=i[2]*e+i[6]*n+i[10]*r+i[14],a=i[3]*e+i[7]*n+i[11]*r+i[15],u=a!==0?1/a:1;t[0]=o*u,t[1]=s*u,t[2]=c*u}function Wi(t,e,n,r,i,o,s,c,a,u,l,m,f,h,b,d,p=0){let E=u-s,A=l-c,x=m-a,R=f-s,I=h-c,P=b-a,k=i*P-o*I,D=o*R-r*P,S=r*I-i*R,_=E*k+A*D+x*S;if(_>-1e-7&&_<1e-7)return!1;let v=1/_,G=t-s,L=e-c,U=n-a,q=v*(G*k+L*D+U*S);if(q<-p||q>1+p)return!1;let W=L*x-U*A,K=U*E-G*x,Y=G*A-L*E,te=v*(r*W+i*K+o*Y);if(te<-p||q+te>1+p)return!1;let ie=v*(R*W+I*K+P*Y);if(ie>1e-4&&ie<d.distance){d.distance=ie,d.point=[t+r*ie,e+i*ie,n+o*ie];let $=A*P-x*I,ne=x*R-E*P,re=E*I-A*R,O=Math.hypot($,ne,re)||1;return d.normal=[$/O,ne/O,re/O],!0}return!1}function it(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let l=0;l<n;l++)r.push(we());if(n===0)return r;let i=new Set;for(let l of t.nodes)if(Array.isArray(l.children))for(let m of l.children)i.add(m);let o=new Set,s=128,c=(l,m,f=0)=>{if(f>s||l<0||l>=n||o.has(l))return;o.add(l);let h=t.nodes[l];if(!h)return;let b=we();if(e&&e[l])b.set(e[l]);else if(h.matrix&&h.matrix.length===16)b.set(h.matrix);else{let p=h.translation||[0,0,0],E=h.rotation||[0,0,0,1],A=h.scale||[1,1,1];rt(b,E,p,A)}let d=r[l];if(m?Ee(d,m,b):d.set(b),Array.isArray(h.children))for(let p of h.children)typeof p=="number"&&c(p,d,f+1)},a=[],u=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let l=0;l<n;l++)i.has(l)||a.push(l);for(let l of a)c(l,null);for(let l=0;l<n;l++)!i.has(l)&&!a.includes(l)&&c(l,null);return r}function ps(t){return new TextDecoder().decode(t)}var ji=pe().decoders;function bs(t,e){ji.set(t.toLowerCase(),e)}function Ft(t){return ji.get(t.toLowerCase())}function Ki(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let f=n.getUint8(0);throw f===123||f===32||f===10||f===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 i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),s=12,c=null,a=null;for(;s+8<=o&&s+8<=e.byteLength;){let f=n.getUint32(s,!0),h=n.getUint32(s+4,!0),b=s+8;if(b+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${b+f} bytes, buffer has ${e.byteLength}`);if(h===1313821514){let d=new Uint8Array(e,b,f),p=ps(d);c=JSON.parse(p,(E,A)=>E==="__proto__"||E==="constructor"||E==="prototype"?void 0:A)}else h===5130562&&(a=e.slice(b,b+f));s=b+f}if(!c)throw new Error("Missing JSON chunk in GLB");let u=c.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!Ft("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");if(u.includes("EXT_meshopt_compression")&&!Ft("meshopt"))throw new Error("Model requires EXT_meshopt_compression. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).");if(u.includes("KHR_texture_basisu")&&!Ft("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let l=a||new ArrayBuffer(0),m={gltf:c,bin:l,animations:[]};for(let f of Ie)f.onParseGLB?.(m);return m}function ys(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function gs(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 ot(t){if(gs(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Ki(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Zi=`#version 300 es
18
19
  layout(location=0) in vec3 aPosition;
19
20
  layout(location=1) in vec3 aNormal;
20
21
  layout(location=2) in vec2 aUV;
@@ -32,7 +33,7 @@ vec2 scaleUV=uUvTransform.zw;
32
33
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
33
34
  vUV=aUV*scaleUV+uUvTransform.xy;
34
35
  gl_Position=uMVP*vec4(aPosition,1.0);
35
- }`,Ri=`#version 300 es
36
+ }`,xs=`#version 300 es
36
37
  precision highp float;
37
38
  in vec3 vNormal,vWorldPos;
38
39
  in vec2 vUV;
@@ -108,9 +109,33 @@ float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
108
109
  return mix(color,newPeak*vec3(1.0),g);
109
110
  }
110
111
 
112
+ vec3 acesToneMapping(vec3 color){
113
+ color*=0.6;
114
+ return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
115
+ }
116
+
117
+ vec3 agxToneMapping(vec3 color){
118
+ color=max(color,vec3(0.0));
119
+ vec3 inset=vec3(
120
+ 0.84247906*color.r+0.0784336*color.g+0.07922375*color.b,
121
+ 0.04232824*color.r+0.87846864*color.g+0.07916613*color.b,
122
+ 0.04237565*color.r+0.0784336*color.g+0.87914297*color.b);
123
+ vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
124
+ vec3 x2=ev*ev;
125
+ vec3 x4=x2*x2;
126
+ 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;
127
+ vec3 outset=vec3(
128
+ 1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
129
+ -0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
130
+ -0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
131
+ return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
132
+ }
133
+
111
134
  vec3 applyToneMapping(vec3 color,int mode){
112
135
  if(mode==0)return neutralToneMapping(color);
113
136
  if(mode==1)return color/(color+vec3(1.0));
137
+ if(mode==3)return acesToneMapping(color);
138
+ if(mode==4)return agxToneMapping(color);
114
139
  return color;
115
140
  }
116
141
 
@@ -198,19 +223,19 @@ color=applyToneMapping(color,uToneMapping);
198
223
  float outAlpha=base.a;
199
224
  /*XRD_O*/
200
225
  fragColor=vec4(color,outAlpha);
201
- }`,Ti=`#version 300 es
226
+ }`;function Qi(t,e,n=1){let r=Number.isFinite(n)?Math.max(0,n):1,i=Math.max(0,(Number(t[0])||0)*r),o=Math.max(0,(Number(t[1])||0)*r),s=Math.max(0,(Number(t[2])||0)*r),c=E=>Math.max(0,Math.min(1,E));if(e==="none")return[c(i),c(o),c(s)];if(e==="reinhard")return[i/(i+1),o/(o+1),s/(s+1)];if(e==="aces"){let E=A=>{let x=A*.6;return c(x*(2.51*x+.03)/(x*(2.43*x+.59)+.14))};return[E(i),E(o),E(s)]}if(e==="agx"){let E=.84247906*i+.0784336*o+.07922375*s,A=.04232824*i+.87846864*o+.07916613*s,x=.04237565*i+.0784336*o+.87914297*s,R=v=>{let G=c((Math.log2(Math.max(v,1e-6))+12.47393)/16.5),L=G*G,U=L*L;return 15.5*U*L-40.14*U*G+31.96*U-6.868*L*G+.4298*L+.1191*G-.00232},I=R(E),P=R(A),k=R(x),D=1.196879*I-.09802088*P-.09902974*k,S=-.05289685*I+1.15190313*P-.09896118*k,_=-.05297164*I-.09804345*P+1.15107367*k;return[c(Math.pow(Math.max(D,0),2.2)),c(Math.pow(Math.max(S,0),2.2)),c(Math.max(0,Math.pow(Math.max(_,0),2.2)))]}let a=.76,u=.15,l=Math.min(i,o,s),m=l<.08?l-6.25*l*l:.04;i-=m,o-=m,s-=m;let f=Math.max(i,o,s);if(f<a)return[c(i),c(o),c(s)];let h=1-a,b=1-h*h/(f+h-a),d=b/f;i*=d,o*=d,s*=d;let p=1-1/(u*(f-b)+1);return[c(i+(b-i)*p),c(o+(b-o)*p),c(s+(b-s)*p)]}var vs=`#version 300 es
202
227
  layout(location=0) in vec3 aPosition;
203
228
  uniform mat4 uMVP;
204
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Mi=`#version 300 es
229
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Ts=`#version 300 es
205
230
  precision highp float;
206
231
  uniform vec4 uColorId;
207
232
  out vec4 fragColor;
208
- void main(){fragColor=uColorId;}`;function br(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Ln(t,e,n){let r=br(t,35633,e),i=br(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let a=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${a}`)}return o}function Dn(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var yr=["uMVP","uModel","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","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function Ar(){let t=ie().xrDepthShader;return{fs:Ri.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...yr,...t.uniformNames]:yr}}function Ei(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Pn(t,e,n,r,i,o,a){if(r===void 0||!e.accessors?.[r])return null;let l=e.accessors[r],c=e.bufferViews[l.bufferView],s=(c.byteOffset||0)+(l.byteOffset||0),u=c.byteStride&&c.byteStride>o*4?c.byteStride>>2:o,m;if(u===o)m=new Float32Array(n,s,l.count*o);else{m=new Float32Array(l.count*o);let f=new Float32Array(n,c.byteOffset||0,Math.floor(c.byteLength/4)),d=(l.byteOffset||0)>>2;for(let p=0;p<l.count;p++){let x=d+p*u;for(let P=0;P<o;P++)m[p*o+P]=f[x+P]}}let h=t.createBuffer();return a.push(h),t.bindBuffer(34962,h),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var Sr=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Rr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function gr(t,e,n=Rr,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i,bin:o}=e,a=[],l=Fe(i),c=[];if(Array.isArray(i.nodes))for(let w=0;w<i.nodes.length;w++){let R=i.nodes[w];R.mesh!==void 0&&i.meshes&&i.meshes[R.mesh]&&c.push({node:R,nodeIdx:w,meshIdx:R.mesh})}let s=c.length>0?c:(i.meshes||[]).map((w,R)=>({node:w,nodeIdx:-1,meshIdx:R})),u=[];if(Array.isArray(e.lights)&&e.lights.length>0)u.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let w=i.extensions.KHR_lights_punctual.lights;for(let R of w){let _=R.type==="directional"?"directional":R.type==="point"?"point":"ambient";u.push({type:_,color:R.color||[1,1,1],intensity:R.intensity!==void 0?R.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]})),s.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${s.length}`);let m=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let w=0;w<i.textures.length;w++){let R=i.textures[w],_=i.images[R.source];if(_){let B=t.createTexture();if(t.bindTexture(3553,B),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),_.bufferView!==void 0){let z=i.bufferViews[_.bufferView],I=o.slice(z.byteOffset||0,(z.byteOffset||0)+z.byteLength),C=new Blob([I],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(C).then(G=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,G),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let z=Ei(_.uri);if(z){let I=new Image;I.crossOrigin="anonymous",I.referrerPolicy="no-referrer",I.onload=()=>{t.bindTexture(3553,B),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()},I.src=z}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}m.push(B)}else m.push(null)}}let h=[1/0,1/0,1/0],f=[-1/0,-1/0,-1/0],d=0,p=0;for(let w=0;w<s.length;w++){let R=s[w],_=i.meshes[R.meshIdx],B=R.nodeIdx>=0?l[R.nodeIdx]:se(),z=new Float32Array(9);de(z,B);let I={name:R.node.name||_.name||`Mesh_${R.meshIdx}`,nodeIndex:R.nodeIdx,transform:B,normalMatrix:z,primitives:[],extras:R.node.extras||_.extras};for(let C of _.primitives||[]){if(C.extensions?.KHR_draco_mesh_compression){let te=it("draco");te&&te.decodePrimitive(i,C,o)}let G=[],V=t.createVertexArray();t.bindVertexArray(V);let J=i.accessors[C.attributes.POSITION],j=Number(J?.count??0);if(!Number.isFinite(j)||j<0||d+j>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(d+=j,J?.min&&J?.max)for(let te=0;te<3;te++){let he=B[12+te],Ee=B[12+te];for(let Ie=0;Ie<3;Ie++){let _t=B[Ie*4+te]*J.min[Ie],Ct=B[Ie*4+te]*J.max[Ie];he+=_t<Ct?_t:Ct,Ee+=_t>Ct?_t:Ct}he<h[te]&&(h[te]=he),Ee>f[te]&&(f[te]=Ee)}let H=Pn(t,i,o,C.attributes.POSITION,0,3,G);Pn(t,i,o,C.attributes.NORMAL,1,3,G),Pn(t,i,o,C.attributes.TEXCOORD_0,2,2,G);let X=0,N=5123,$=null;if(C.indices!==void 0){let te=i.accessors[C.indices],Ee=(i.bufferViews[te.bufferView].byteOffset||0)+(te.byteOffset||0);if(X=Number(te.count??0),!Number.isFinite(X)||X<0||p+X>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);p+=X,N=te.componentType===5125?5125||5125:5123||5123;let Ie=t.createBuffer();G.push(Ie),t.bindBuffer(34963,Ie),te.componentType===5125?($=new Uint32Array(o,Ee,te.count),t.bufferData(34963,$,35044)):($=new Uint16Array(o,Ee,te.count),t.bufferData(34963,$,35044))}else X=J.count;let Y={};for(let te of ue)if(te.onBuildPrimitiveVAO){let he=te.onBuildPrimitiveVAO(t,V,C,i,o);he&&(Y[te.name]=he)}t.bindVertexArray(null);let T=i.materials&&C.material!==void 0?i.materials[C.material]:null,A=Ar(),S=wr,k=A.fs,M=!1;for(let te of ue)if(te.onResolveShader){let he=te.onResolveShader(C,T,S,k);he&&(S=he.vs,k=he.fs,M=!0)}let D=M?Ln(t,S,k):null,F=D?Dn(t,D,A.uniforms):null,U=T?.pbrMetallicRoughness,K=U?.baseColorFactor||[.8,.8,.8,1],Z=U?.metallicFactor??.1,Q=U?.roughnessFactor??.5,O=T?.extensions?.KHR_materials_clearcoat,q=O?O.clearcoatFactor??1:0,ee=Math.max(.04,O?.clearcoatRoughnessFactor??.04),ae=U?.baseColorTexture!==void 0&&m[U.baseColorTexture.index]?m[U.baseColorTexture.index]:null,Ve=U?.metallicRoughnessTexture!==void 0&&m[U.metallicRoughnessTexture.index]?m[U.metallicRoughnessTexture.index]:null,pe=T?.normalTexture!==void 0&&m[T.normalTexture.index]?m[T.normalTexture.index]:null,ce=T?.normalTexture?.scale??1,De=T?.occlusionTexture!==void 0&&m[T.occlusionTexture.index]?m[T.occlusionTexture.index]:null,xe=T?.occlusionTexture?.strength??1,ve=!!(T?.extensions?.KHR_materials_transmission||Y.materials?.isTransmissive);I.primitives.push({vao:V,indexCount:X,indexType:N,baseColor:K,metallic:Z,roughness:Q,clearcoat:q,clearcoatRoughness:ee,positions:H,indices:$,texture:ae,metallicRoughnessTexture:Ve,normalTexture:pe,occlusionTexture:De,normalScale:ce,occlusionStrength:xe,buffers:G,materialIndex:C.material,pluginData:Y,customProgram:D,customUniforms:F,isTransmissive:ve})}a.push(I)}isFinite(h[0])||(h=[-1,-1,-1]),isFinite(f[0])||(f=[1,1,1]);let x=[(h[0]+f[0])/2,(h[1]+f[1])/2,(h[2]+f[2])/2],P=f[0]-h[0],E=f[1]-h[1],y=f[2]-h[2],v=Math.max(Math.hypot(P,E,y)/2,.5),g=[h[0],h[1],h[2]],L=[f[0],f[1],f[2]],b=e.animations;if(!b){for(let w of ue)if(w.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:a,bounds:{center:x,radius:v,min:g,max:L},lights:u,animations:b,worldMatrices:l}}var fe=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=se();this.clearColor=[0,0,0,0];this.envIntensity=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.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=se();this.viewMatrix=se();this.modelMatrix=se();this.mvpMatrix=se();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.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:se(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let s=e.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",e.prepend(s)),i=s}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let a=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!a:a&&(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.envIntensity=Math.max(0,Number(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=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.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 l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l;let c=Ar();this.renderProg=Ln(l,wr,c.fs),this.pickProg=Ln(l,Ti,Mi),this.uRender=Dn(l,this.renderProg,c.uniforms),this.uPick=Dn(l,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){Ai(e,n)}static getDecoder(e){return it(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),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,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:a,worldMatrices:l}=gr(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=a||[],this.worldMatrices=l||[],this.gltf=e.gltf,this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let s of e.gltf.nodes)this.initialNodeTransforms.push({t:s.translation?[s.translation[0],s.translation[1],s.translation[2]]:[0,0,0],r:s.rotation?[s.rotation[0],s.rotation[1],s.rotation[2],s.rotation[3]]:[0,0,0,1],s:s.scale?[s.scale[0],s.scale[1],s.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let s of ue)s.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let c=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;c!==void 0&&(this.envIntensity=Math.max(0,Number(c))),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(vr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(ke(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=ke(e),{meshes:i}=gr(this.gl,r,Rr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],de(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),de(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],a=[],l=[];for(let c of this.lights){let s=c.color||[1,1,1],u=c.intensity!==void 0?c.intensity:1;if(c.type==="ambient")r=[s[0]*u,s[1]*u,s[2]*u];else if(c.type==="directional"&&i.length<6){let m=c.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(s[0]*u,s[1]*u,s[2]*u)}else if(c.type==="point"&&a.length<6){let m=c.position||[0,0,0];a.push(m[0],m[1],m[2]),l.push(s[0]*u,s[1]*u,s[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,a.length/3),a.length>0&&(n.uniform3fv(e.uPointLightPos,a),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of ue)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of ue)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.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((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],a=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,c=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,s={baseColorFactor:a,metallicFactor:l,roughnessFactor:c,setBaseColorFactor:u=>{let m=[u[0],u[1],u[2],u[3]??1];s.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let h of i)h.baseColor=m;this.render()},setMetallicFactor:u=>{s.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let m of i)m.metallic=u;this.render()},setRoughnessFactor:u=>{s.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let m of i)m.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:s}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}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 n of ue)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],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 n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let r=se();be(r,this.projMatrix,this.viewMatrix);let[i,o,a]=e,l=n?n[0]:0,c=n?n[1]:0,s=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],a=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(l=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],c=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],s=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*a+r[12],h=r[1]*i+r[5]*o+r[9]*a+r[13],f=r[2]*i+r[6]*o+r[10]*a+r[14],d=r[3]*i+r[7]*o+r[11]*a+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let p=m/d,x=h/d,P=f/d,E=this.canvas.getBoundingClientRect(),y=E.width||this.canvas.clientWidth||this.canvas.width||300,v=E.height||this.canvas.clientHeight||this.canvas.height||150,g=(p*.5+.5)*y,L=(-x*.5+.5)*v,b=p>=-1.1&&p<=1.1&&x>=-1.1&&x<=1.1&&P>=-1&&P<=1;if(b&&n){let w=this.customTarget||this.bounds.center,R=w[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=w[1]+this.currDistance*Math.sin(this.currPhi),B=w[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),z=[i-R,o-_,a-B];l*z[0]+c*z[1]+s*z[2]>.05&&(b=!1)}return{x:g,y:L,z:P,visible:b}}setSelectedMesh(e){this.selectedMeshName=e||""}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],s=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;c[0]+=(-i*a[0]+o*l[0])*s,c[1]+=(-i*a[1]+o*l[1])*s,c[2]+=(-i*a[2]+o*l[2])*s,this.customTarget=c}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.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=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,a=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),c=i.height>0?Math.floor((n-i.top)*(a/i.height)):Math.floor(n);return this.performMeshPick(l,c,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=se();be(l,this.projMatrix,this.viewMatrix);let c=[],s=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(a-1,a-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==a)&&this.resizePickingFbo(o,a),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,a),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let b=0;b<this.meshes.length;b++){let w=this.meshes[b];if(w.visible===!1||w.isPluginMesh)continue;let R=b+1,_=(R&255)/255,B=(R>>8&255)/255,z=(R>>16&255)/255;i.uniform4f(this.uPick.uColorId,_,B,z,1),be(this.modelMatrix,this.modelRootMatrix,w.transform),be(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let I of w.primitives)i.bindVertexArray(I.vao),i.drawElements(4,I.indexCount,I.indexType,0)}let g=new Uint8Array(4);i.readPixels(s,u,1,1,6408,5121,g),i.bindFramebuffer(36160,null);let L=g[0]+(g[1]<<8)+(g[2]<<16);L>0&&L<=this.meshes.length&&(c=[this.meshes[L-1]])}c.length===0&&(c=this.meshes.filter(g=>g.visible!==!1));let m=null,h=1/0,f=[0,0,0],d=[0,1,0],p=this.customTarget||this.bounds.center,x=p[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),P=p[1]+this.currDistance*Math.sin(this.currPhi),E=p[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let g of c){be(this.modelMatrix,this.modelRootMatrix,g.transform),be(this.mvpMatrix,l,this.modelMatrix);let L=se();if(!kt(L,this.mvpMatrix))continue;let b=(s+.5)/o*2-1,w=(u+.5)/a*2-1,R=[0,0,0],_=[0,0,0];Cn(R,b,w,-1,L),Cn(_,b,w,1,L);let B=_[0]-R[0],z=_[1]-R[1],I=_[2]-R[2],C=Math.hypot(B,z,I)||1,G=B/C,V=z/C,J=I/C,j={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((X=>{for(let N of g.primitives){if(!N.positions)continue;let $=N.positions,Y=N.indices,T=Math.floor(Y?Y.length/3:$.length/9);for(let A=0;A<T;A++){let S=Y?Y[A*3]:A*3,k=Y?Y[A*3+1]:A*3+1,M=Y?Y[A*3+2]:A*3+2;pr(R[0],R[1],R[2],G,V,J,$[S*3],$[S*3+1],$[S*3+2],$[k*3],$[k*3+1],$[k*3+2],$[M*3],$[M*3+1],$[M*3+2],j,X)}}})(1e-4),isFinite(j.distance)){let X=j.point[0],N=j.point[1],$=j.point[2],Y=this.modelMatrix,T=Y[0]*X+Y[4]*N+Y[8]*$+Y[12],A=Y[1]*X+Y[5]*N+Y[9]*$+Y[13],S=Y[2]*X+Y[6]*N+Y[10]*$+Y[14],k=T-x,M=A-P,D=S-E,F=Math.hypot(k,M,D);if(F<h){de(this.normalMatrix,this.modelMatrix);let U=this.normalMatrix,K=j.normal[0],Z=j.normal[1],Q=j.normal[2],O=U[0]*K+U[3]*Z+U[6]*Q,q=U[1]*K+U[4]*Z+U[7]*Q,ee=U[2]*K+U[5]*Z+U[8]*Q,ae=Math.hypot(O,q,ee)||1;O/=ae,q/=ae,ee/=ae,O*k+q*M+ee*D>0&&(O=-O,q=-q,ee=-ee),m=g,h=Math.round(F*1e3)/1e3,f=[Math.round(T*1e3)/1e3,Math.round(A*1e3)/1e3,Math.round(S*1e3)/1e3],d=[Math.round(O*1e3)/1e3,Math.round(q*1e3)/1e3,Math.round(ee*1e3)/1e3]}}}if(!m)return null;let v={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:h,hitPoint:f,normal:d,screenX:e,screenY:n};if(r){for(let g of ue)g.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,a=i?Math.max(1,n-r):r,l=(o+.5)/a*2-1;return Math.floor((l*.5+1)*.5*n)}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),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Ft(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),a=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);qe(this.viewMatrix,[i,o,a],r,[0,1,0]),be(this.mvpMatrix,this.projMatrix,this.viewMatrix),de(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of ue)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of ue)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}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),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let a of ue)a.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let a of ue)a.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 r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let a={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(e,n,r,i,o=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,c=e?.projectionMatrix||this.projMatrix,s=e?.transform?.position,u=s?[s.x,s.y,s.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:l,projMatrix:c,eyePos:u,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),g=Math.max(1,this.canvas.height||1),L=Math.max(1,Math.floor(v*.5)),b=Math.max(1,v-L),w=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),R=this.customTarget||this.bounds.center,_=R[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),B=R[1]+this.currDistance*Math.sin(this.currPhi),z=R[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),I=Math.cos(this.currTheta),C=-Math.sin(this.currTheta),G=.032,V=se(),J=se(),j=[_-I*G,B,z-C*G],H=[R[0]-I*G*.25,R[1],R[2]-C*G*.25];Ft(V,this.fov,L/g,.1,w),qe(J,j,H,[0,1,0]);let X=se(),N=se(),$=[_+I*G,B,z+C*G],Y=[R[0]+I*G*.25,R[1],R[2]+C*G*.25];Ft(X,this.fov,b/g,.1,w),qe(N,$,Y,[0,1,0]),this.render({viewMatrix:J,projMatrix:V,eyePos:j,viewport:[0,0,L,g],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:N,projMatrix:X,eyePos:$,viewport:[L,0,b,g],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,g);return}let n=this.gl,r=0,i=0,o=this.canvas.width,a=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],a=e.viewport[3],n.viewport(r,i,o,a)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let l=se(),c=e?.viewMatrix??this.viewMatrix;be(l,e?.projMatrix??this.projMatrix,c);let s=ie().xrDepthShader,u=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:0,m=this.customTarget||this.bounds.center,h=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),f=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),d=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let v of ue)v.onBeforeDrawScene?.(this,n,l,[h,f,d],u);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let x=e?.eye||"none",P=!1,E=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,y=v=>{for(let g=0;g<E.length;g++){let L=E[g];if(L.visible===!1)continue;let b=this.selectedMeshName!==""&&L.name===this.selectedMeshName;g<p||L.worldSpace===!0||L.name==="__xr_reticle__"?this.modelMatrix.set(L.transform):be(this.modelMatrix,this.modelRootMatrix,L.transform),be(this.mvpMatrix,l,this.modelMatrix),de(L.normalMatrix,this.modelMatrix);let w=L.extras?.xr?.stereo||L.userData?.xr?.stereo,R=0,_=0,B=1,z=1;w==="sbs"?(B=.5,R=x==="right"?.5:0):w==="ou"&&(z=.5,_=x==="right"?.5:0);for(let I of L.primitives){let C=!!I.isTransmissive;if(!v&&C){P=!0;continue}if(v&&!C)continue;let G=I.customProgram||this.renderProg,V=I.customUniforms||this.uRender;n.useProgram(G),n.uniform1i(V.uToneMapping,u),n.uniform1f(V.uEnvIntensity,this.envIntensity),n.uniform3f(V.uCameraPos,h,f,d),n.uniform1f(V.uEmissive,b?1:0),n.uniformMatrix4fv(V.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(V.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(V.uNormalMatrix,!1,L.normalMatrix),V.uUvTransform&&n.uniform4f(V.uUvTransform,R,_,B,z),V.uViewportSize&&n.uniform2f(V.uViewportSize,Math.max(1,o),Math.max(1,a)),s?.bind(n,V,this.xrDepthState,c,[r,i,Math.max(1,o),Math.max(1,a)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(V.uEnvironmentMap,4),n.uniform1i(V.uHasEnvironmentMap,1)):n.uniform1i(V.uHasEnvironmentMap,0),this.bindLights(V),V.uSectionEnabled&&n.uniform1i(V.uSectionEnabled,0);for(let J of ue)J.onBeforeDrawPrimitive?.(n,G,I,L,this.worldMatrices||[],this.gltf);n.uniform4fv(V.uBaseColor,I.baseColor),n.uniform1f(V.uMetallic,I.metallic),n.uniform1f(V.uRoughness,I.roughness),V.uClearcoat&&n.uniform2f(V.uClearcoat,I.clearcoat??0,I.clearcoatRoughness??.04),I.texture?(n.activeTexture(33984),n.bindTexture(3553,I.texture),n.uniform1i(V.uBaseColorTexture,0),n.uniform1i(V.uHasTexture,1)):n.uniform1i(V.uHasTexture,0),I.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,I.metallicRoughnessTexture),n.uniform1i(V.uMetallicRoughnessTexture,1),n.uniform1i(V.uHasMetallicRoughnessTexture,1)):n.uniform1i(V.uHasMetallicRoughnessTexture,0),I.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,I.normalTexture),n.uniform1i(V.uNormalTexture,2),n.uniform1i(V.uHasNormalTexture,1),n.uniform1f(V.uNormalScale,I.normalScale)):n.uniform1i(V.uHasNormalTexture,0),I.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,I.occlusionTexture),n.uniform1i(V.uOcclusionTexture,3),n.uniform1i(V.uHasOcclusionTexture,1),n.uniform1f(V.uOcclusionStrength,I.occlusionStrength)):n.uniform1i(V.uHasOcclusionTexture,0),n.bindVertexArray(I.vao),n.drawElements(4,I.indexCount,I.indexType,0)}}};if(y(!1),P){for(let v of ue)v.onBeforeTransmissivePass?.(n,this);y(!0)}for(let v of ue)v.onAfterRender?.(n,this,l)}disposeMeshListGpuResources(e){let n=this.gl;for(let r of e)for(let i of r.primitives){if(i.vao&&n.deleteVertexArray(i.vao),i.buffers)for(let o of i.buffers)n.deleteBuffer(o);i.texture&&n.deleteTexture(i.texture),i.metallicRoughnessTexture&&n.deleteTexture(i.metallicRoughnessTexture),i.normalTexture&&n.deleteTexture(i.normalTexture),i.occlusionTexture&&n.deleteTexture(i.occlusionTexture),i.customProgram&&n.deleteProgram(i.customProgram)}}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes),this.meshes=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of ue)n.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()}};fe.registerPlugin=ge,fe.getRegisteredPlugins=It;function _i(t){return t+3&-4}function Ci(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}function je(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],a=[],l=[],c=new Set,s=[],u=[],m=new Map,h=[];function f(b,w){let R=new Uint8Array(b.buffer,b.byteOffset,b.byteLength),_=_i(R.byteLength),B=new Uint8Array(_);B.set(R),n.push(B);let z=i.length;return i.push({buffer:0,byteOffset:r,byteLength:R.byteLength,target:w}),r+=_,z}function d(b,w,R,_,B,z,I){let C=f(b,R),G=o.length,V={bufferView:C,byteOffset:0,componentType:_,count:B,type:w};return z&&(V.min=z),I&&(V.max=I),o.push(V),G}t.traverse(b=>{(b.isLight||b.color&&b.intensity!==void 0)&&h.push({type:b.type,color:[b.color.r,b.color.g,b.color.b],intensity:b.intensity,position:[b.position.x,b.position.y,b.position.z]})});let p=[];function x(b){let w={name:b.name||""},R=b.position,_=b.quaternion,B=b.scale;if((R.x||R.y||R.z)&&(w.translation=[R.x,R.y,R.z]),(_.x||_.y||_.z||_.w!==1)&&(w.rotation=[_.x,_.y,_.z,_.w]),(B.x!==1||B.y!==1||B.z!==1)&&(w.scale=[B.x,B.y,B.z]),b.userData&&Object.keys(b.userData).length>0&&(w.extras=JSON.parse(JSON.stringify(b.userData,(I,C)=>{if(!(I==="__proto__"||I==="prototype"||I==="constructor"))return typeof C=="function"?void 0:C})),b.userData.xr)){let I=Ci(b.userData.xr);w.extensions={...w.extensions||{},MOZ_hubs_components:I,ANDROID_xr_scenecore:I},ie().xrTraitSerializer?.gltfNode(w,b.userData.xr),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(b.geometry){let I=b.geometry,C=I.attributes.position;if(C&&C.count>0){let G=[1/0,1/0,1/0],V=[-1/0,-1/0,-1/0];for(let X=0;X<C.count;X++){let N=C.getX(X),$=C.getY(X),Y=C.getZ(X);N<G[0]&&(G[0]=N),N>V[0]&&(V[0]=N),$<G[1]&&(G[1]=$),$>V[1]&&(V[1]=$),Y<G[2]&&(G[2]=Y),Y>V[2]&&(V[2]=Y)}let j={attributes:{POSITION:d(C.array,"VEC3",34962,5126,C.count,G,V)}};if(I.attributes.normal&&(j.attributes.NORMAL=d(I.attributes.normal.array,"VEC3",34962,5126,I.attributes.normal.count)),I.attributes.uv&&(j.attributes.TEXCOORD_0=d(I.attributes.uv.array,"VEC2",34962,5126,I.attributes.uv.count)),I.index){let X=I.index.array instanceof Uint32Array;j.indices=d(I.index.array,"SCALAR",34963,X?5125:5123,I.index.count)}if(b.material){let X=m.get(b.material);if(X===void 0){X=u.length,m.set(b.material,X);let N=b.material,$={name:N.name||"",pbrMetallicRoughness:{baseColorFactor:[N.color.r,N.color.g,N.color.b,N.opacity],metallicFactor:N.metalness,roughnessFactor:N.roughness},doubleSided:N.side===2||N.doubleSided};if(N.emissive&&(N.emissive.r>0||N.emissive.g>0||N.emissive.b>0)){let T=N.emissiveIntensity??1;$.emissiveFactor=[N.emissive.r*T,N.emissive.g*T,N.emissive.b*T]}let Y={};N.clearcoat>0&&(Y.KHR_materials_clearcoat={clearcoatFactor:N.clearcoat,clearcoatRoughnessFactor:N.clearcoatRoughness||0}),N.sheen>0&&(Y.KHR_materials_sheen={sheenColorFactor:N.sheenColor?[N.sheenColor.r,N.sheenColor.g,N.sheenColor.b]:[1,1,1],sheenRoughnessFactor:N.sheenRoughness||0}),N.transmission>0&&(Y.KHR_materials_transmission={transmissionFactor:N.transmission}),N.thickness>0&&(Y.KHR_materials_volume={thicknessFactor:N.thickness,attenuationDistance:N.attenuationDistance??1/0,attenuationColor:N.attenuationColor?[N.attenuationColor.r,N.attenuationColor.g,N.attenuationColor.b]:[1,1,1]}),N.ior!==void 0&&N.ior!==1.5&&(Y.KHR_materials_ior={ior:N.ior}),N.dispersion>0&&(Y.KHR_materials_dispersion={dispersion:N.dispersion}),N.iridescence>0&&(Y.KHR_materials_iridescence={iridescenceFactor:N.iridescence,iridescenceIor:N.iridescenceIOR??1.3}),Object.keys(Y).length>0&&($.extensions=Y),u.push($)}j.material=X}let H=a.length;a.push({primitives:[j],name:b.name,...w.extras?{extras:w.extras}:{}}),w.mesh=H}}let z=l.length;if(l.push(w),s.push(b),b.children.length>0){w.children=[];for(let I of b.children)w.children.push(x(I))}return z}for(let b of t.children)p.push(x(b));let P=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),E=[];if(typeof P=="function"&&s.length>0){let b=e?.duration??4,w=e?.fps??15,R=Math.max(2,Math.round(b*w)+1),_=new Float32Array(R),B=s.map(H=>({px:H.position.x,py:H.position.y,pz:H.position.z,qx:H.quaternion.x,qy:H.quaternion.y,qz:H.quaternion.z,qw:H.quaternion.w,sx:H.scale.x,sy:H.scale.y,sz:H.scale.z})),z=s.map(()=>new Float32Array(R*3)),I=s.map(()=>new Float32Array(R*4)),C=s.map(()=>new Float32Array(R*3));for(let H=0;H<R;H++){let X=H/(R-1)*b;_[H]=X;try{P(X)}catch{}for(let N=0;N<s.length;N++){let $=s[N];z[N][H*3]=$.position.x,z[N][H*3+1]=$.position.y,z[N][H*3+2]=$.position.z,I[N][H*4]=$.quaternion.x,I[N][H*4+1]=$.quaternion.y,I[N][H*4+2]=$.quaternion.z,I[N][H*4+3]=$.quaternion.w,C[N][H*3]=$.scale.x,C[N][H*3+1]=$.scale.y,C[N][H*3+2]=$.scale.z}}for(let H=0;H<s.length;H++){let X=s[H],N=B[H];X.position.set(N.px,N.py,N.pz),X.quaternion.set(N.qx,N.qy,N.qz,N.qw),X.scale.set(N.sx,N.sy,N.sz)}t.updateMatrixWorld(!0);let G=null,V=()=>(G===null&&(G=d(_,"SCALAR",0,5126,R,[0],[b])),G),J=[],j=[];for(let H=0;H<s.length;H++){let X=B[H],N=!1,$=!1,Y=!1;for(let T=0;T<R;T++)(Math.abs(z[H][T*3]-X.px)>1e-4||Math.abs(z[H][T*3+1]-X.py)>1e-4||Math.abs(z[H][T*3+2]-X.pz)>1e-4)&&(N=!0),(Math.abs(I[H][T*4]-X.qx)>1e-4||Math.abs(I[H][T*4+1]-X.qy)>1e-4||Math.abs(I[H][T*4+2]-X.qz)>1e-4||Math.abs(I[H][T*4+3]-X.qw)>1e-4)&&($=!0),(Math.abs(C[H][T*3]-X.sx)>1e-4||Math.abs(C[H][T*3+1]-X.sy)>1e-4||Math.abs(C[H][T*3+2]-X.sz)>1e-4)&&(Y=!0);if(N){let T=d(z[H],"VEC3",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"translation"}})}if($){let T=d(I[H],"VEC4",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"rotation"}})}if(Y){let T=d(C[H],"VEC3",0,5126,R),A=J.length;J.push({input:V(),interpolation:"LINEAR",output:T}),j.push({sampler:A,target:{node:H,path:"scale"}})}}j.length>0&&E.push({name:"ProceduralLoop",samplers:J,channels:j})}let y=fr(l,a,t.userData),v={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:p}],scene:0,nodes:l,meshes:a,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},...y||c.size>0?{extensionsUsed:[...y?["KHR_interactivity"]:[],...c]}:{},...y?{extensions:{KHR_interactivity:y}}:{}},g=new Uint8Array(r),L=0;for(let b of n)g.set(b,L),L+=b.byteLength;return{gltf:v,bin:g.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function Ut(t){return new TextEncoder().encode(t)}function ot(t,e){let{gltf:n,bin:r}=je(t,e),i=JSON.stringify(n),o=Ut(i),a=(4-o.byteLength%4)%4,l=o.byteLength+a,c=20+l+8+r.byteLength,s=new Uint8Array(c),u=new DataView(s.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,c,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),s.set(o,20);for(let h=0;h<a;h++)s[20+o.byteLength+h]=32;let m=20+l;return u.setUint32(m,r.byteLength,!0),u.setUint32(m+4,5130562,!0),s.set(new Uint8Array(r),m+8),s}function Pi(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let a=o.count,l=new Float32Array(a*3),c=r.matrixWorld.elements;for(let b=0;b<a;b++){let w=o.getX(b),R=o.getY(b),_=o.getZ(b);l[b*3]=c[0]*w+c[4]*R+c[8]*_+c[12],l[b*3+1]=c[1]*w+c[5]*R+c[9]*_+c[13],l[b*3+2]=c[2]*w+c[6]*R+c[10]*_+c[14]}let s;if(i.attributes.normal){let b=i.attributes.normal;s=new Float32Array(a*3);let w=new Float32Array(9);de(w,c);for(let R=0;R<a;R++){let _=b.getX(R),B=b.getY(R),z=b.getZ(R),I=w[0]*_+w[3]*B+w[6]*z,C=w[1]*_+w[4]*B+w[7]*z,G=w[2]*_+w[5]*B+w[8]*z,V=Math.hypot(I,C,G)||1;s[R*3]=I/V,s[R*3+1]=C/V,s[R*3+2]=G/V}}let u;if(i.attributes.uv){let b=i.attributes.uv;u=new Float32Array(a*2);for(let w=0;w<a;w++)u[w*2]=b.getX(w),u[w*2+1]=b.getY(w)}let m;if(i.index)m=i.index.array;else{m=a>65535?new Uint32Array(a):new Uint16Array(a);for(let b=0;b<a;b++)m[b]=b}let h="DefaultMaterial",f=[.8,.8,.8],d=.5,p=.1,x=0,P=0,E=1.5,y=1,v=[0,0,0];if(r.material){let b=r.material;h=b.name||`Material_${n.length}`,b.color&&(f=[b.color.r,b.color.g,b.color.b]),typeof b.roughness=="number"&&(d=b.roughness),typeof b.metalness=="number"&&(p=b.metalness),typeof b.clearcoat=="number"&&(x=b.clearcoat),typeof b.clearcoatRoughness=="number"&&(P=b.clearcoatRoughness),typeof b.ior=="number"&&(E=b.ior);let w=typeof b.opacity=="number"?b.opacity:1,R=typeof b.transmission=="number"?b.transmission:0;if(y=w*(1-R),b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let _=b.emissiveIntensity??1;v=[b.emissive.r*_,b.emissive.g*_,b.emissive.b*_]}}let g,L=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);if(typeof L=="function"){let b=e?.duration??4,w=e?.fps??4,R=Math.max(2,Math.round(b*w)+1),_=[],B=[],z=[],I=[],C=[r.position.x,r.position.y,r.position.z],G=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],V=[r.scale.x,r.scale.y,r.scale.z],J=!1;for(let j=0;j<R;j++){let H=j/(R-1)*b;_.push(H);try{L(H)}catch{}B.push([r.position.x,r.position.y,r.position.z]),z.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),I.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-C[0])>1e-4||Math.abs(r.position.y-C[1])>1e-4||Math.abs(r.position.z-C[2])>1e-4||Math.abs(r.quaternion.x-G[0])>1e-4||Math.abs(r.quaternion.y-G[1])>1e-4||Math.abs(r.quaternion.z-G[2])>1e-4||Math.abs(r.quaternion.w-G[3])>1e-4||Math.abs(r.scale.x-V[0])>1e-4)&&(J=!0)}r.position.set(C[0],C[1],C[2]),r.quaternion.set(G[0],G[1],G[2],G[3]),r.scale.set(V[0],V[1],V[2]),J&&(g={times:_,translations:B,rotations:z,scales:I})}n.push({name:r.name||`Mesh_${n.length}`,positions:l,indices:m,normals:s,uvs:u,materialName:h,color:f,roughness:d,metallic:p,clearcoat:x,clearcoatRoughness:P,ior:E,opacity:y,emissiveColor:v,xrTraits:r.userData?.xr,timeSamples:g})}}),n}function Er(t){let e=[],n=t.gltf,r=t.bin,i=r instanceof ArrayBuffer?r:r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength),o=n.accessors||[],a=n.bufferViews||[],l=n.materials||[],c=n.meshes||[],s=n.nodes||[];function u(f){let d=o[f];if(!d)throw new Error(`Accessor ${f} not found`);let p=a[d.bufferView||0],x=(p.byteOffset||0)+(d.byteOffset||0),P=p.byteLength||0,E=i.slice(x,x+P);return{acc:d,buffer:E}}let m=new Map;if(s.length>0){let f=Fe(n);for(let d=0;d<f.length;d++)m.set(d,f[d])}function h(f,d,p,x){let P=c[f];if(!P)return;let E=new Float32Array(9);de(E,d);for(let y=0;y<(P.primitives||[]).length;y++){let v=P.primitives[y],g=v.attributes?.POSITION;if(g===void 0)continue;let{acc:L,buffer:b}=u(g),w=new Float32Array(b,0,L.count*3),R=new Float32Array(w.length);for(let A=0;A<L.count;A++){let S=w[A*3],k=w[A*3+1],M=w[A*3+2];R[A*3]=d[0]*S+d[4]*k+d[8]*M+d[12],R[A*3+1]=d[1]*S+d[5]*k+d[9]*M+d[13],R[A*3+2]=d[2]*S+d[6]*k+d[10]*M+d[14]}let _,B=v.attributes?.NORMAL;if(B!==void 0){let{acc:A,buffer:S}=u(B),k=new Float32Array(S,0,A.count*3);_=new Float32Array(k.length);for(let M=0;M<A.count;M++){let D=k[M*3],F=k[M*3+1],U=k[M*3+2],K=E[0]*D+E[3]*F+E[6]*U,Z=E[1]*D+E[4]*F+E[7]*U,Q=E[2]*D+E[5]*F+E[8]*U,O=Math.hypot(K,Z,Q)||1;_[M*3]=K/O,_[M*3+1]=Z/O,_[M*3+2]=Q/O}}let z,I=v.attributes?.TEXCOORD_0;if(I!==void 0){let{acc:A,buffer:S}=u(I);z=new Float32Array(S,0,A.count*2)}let C;if(v.indices!==void 0){let{acc:A,buffer:S}=u(v.indices);A.componentType===5125?C=new Uint32Array(S,0,A.count):C=new Uint16Array(S,0,A.count);let k=L.count;for(let M of C)if(M>=k)throw new Error(`SecurityError: Index buffer value (${M}) out of vertex bounds [0, ${k}).`)}else{let A=L.count;C=A>65535?new Uint32Array(A):new Uint16Array(A);for(let S=0;S<A;S++)C[S]=S}let G="DefaultMaterial",V=[.8,.8,.8],J=.5,j=.1,H=0,X=0,N=1.5,$=1,Y=[0,0,0];if(v.material!==void 0&&l[v.material]){let A=l[v.material];G=A.name||`Material_${v.material}`;let S=A.pbrMetallicRoughness||{},k=1;Array.isArray(S.baseColorFactor)&&(V=[S.baseColorFactor[0],S.baseColorFactor[1],S.baseColorFactor[2]],typeof S.baseColorFactor[3]=="number"&&(k=S.baseColorFactor[3])),typeof S.roughnessFactor=="number"&&(J=S.roughnessFactor),typeof S.metallicFactor=="number"&&(j=S.metallicFactor),Array.isArray(A.emissiveFactor)&&A.emissiveFactor.length>=3&&(Y=[A.emissiveFactor[0],A.emissiveFactor[1],A.emissiveFactor[2]]);let M=A.extensions||{};M.KHR_materials_clearcoat&&(H=M.KHR_materials_clearcoat.clearcoatFactor??0,X=M.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),M.KHR_materials_ior&&typeof M.KHR_materials_ior.ior=="number"&&(N=M.KHR_materials_ior.ior);let D=M.KHR_materials_transmission?.transmissionFactor??0;$=k*(1-D)}let T=(P.primitives||[]).length>1?`${p}_p${y}`:p;e.push({name:T,positions:R,indices:C,normals:_,uvs:z,materialName:G,color:V,roughness:J,metallic:j,clearcoat:H,clearcoatRoughness:X,ior:N,opacity:$,emissiveColor:Y,xrTraits:x?.xr||P.extras?.xr})}}if(s.length>0)for(let f=0;f<s.length;f++){let d=s[f];if(d.mesh!==void 0&&d.mesh<c.length){let p=m.get(f)||se(),x=d.name||c[d.mesh].name||`Node_${f}`;h(d.mesh,p,x,d.extras)}}else{let f=se();for(let d=0;d<c.length;d++){let p=c[d].name||`Mesh_${d}`;h(d,f,p,c[d].extras)}}return e}function In(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function Tr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ne(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}function Mr(t){let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ne(t[r*3])}, ${ne(t[r*3+1])}, ${ne(t[r*3+2])})`;return n.join(", ")}function Li(t,e){let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${ne(t[r*2])}, ${ne(1-t[r*2+1])})`;return n.join(", ")}function Di(t){return Array.from(t).join(", ")}function Fn(t){let e=new Map;for(let c of t){let s=In(c.materialName,"DefaultMaterial");e.has(s)||e.set(s,{color:c.color||[.8,.8,.8],roughness:c.roughness??.5,metallic:c.metallic??0,clearcoat:c.clearcoat??0,clearcoatRoughness:c.clearcoatRoughness??0,ior:c.ior??1.5,opacity:c.opacity??1,emissiveColor:c.emissiveColor||[0,0,0]})}let n=0,r=null;for(let c of t){if(c.timeSamples&&c.timeSamples.times.length>0){let s=c.timeSamples.times[c.timeSamples.times.length-1];s>n&&(n=s)}c.xrTraits?.anchor&&!r&&(r=c.xrTraits.anchor==="vertical"||c.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
209
- endTimeCode = ${ne(n)}
233
+ void main(){fragColor=uColorId;}`;function $i(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function kr(t,e,n){let r=$i(t,35633,e),i=$i(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let s=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${s}`)}return o}function Nr(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var qi=["uMVP","uModel","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","uEnvIntensity","uViewportSize","uSectionPlane","uSectionEnabled"];function Ji(){let t=pe().xrDepthShader;return{fs:xs.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...qi,...t.uniformNames]:qi}}function ws(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Dr(t,e,n,r,i,o,s){if(r===void 0||!e.accessors?.[r])return null;let c=e.accessors[r],a=e.bufferViews[c.bufferView],u=(a.byteOffset||0)+(c.byteOffset||0),l=a.byteStride&&a.byteStride>o*4?a.byteStride>>2:o,m;if(l===o)m=new Float32Array(n,u,c.count*o);else{m=new Float32Array(c.count*o);let h=new Float32Array(n,a.byteOffset||0,Math.floor(a.byteLength/4)),b=(c.byteOffset||0)>>2;for(let d=0;d<c.count;d++){let p=b+d*l;for(let E=0;E<o;E++)m[d*o+E]=h[p+E]}}let f=t.createBuffer();return s.push(f),t.bindBuffer(34962,f),t.bufferData(34962,m,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),m}var eo=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),to=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Yi(t,e,n=to,r){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:i}=e,o=Ft("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(i,e);let s=e.bin,c=[],a=[],u=i.extensions?.KHR_materials_variants;if(u&&Array.isArray(u.variants))for(let v of u.variants)v&&typeof v.name=="string"&&a.push(v.name);let l=it(i),m=[];if(Array.isArray(i.nodes))for(let v=0;v<i.nodes.length;v++){let G=i.nodes[v];G.mesh!==void 0&&i.meshes&&i.meshes[G.mesh]&&m.push({node:G,nodeIdx:v,meshIdx:G.mesh})}let f=m.length>0?m:(i.meshes||[]).map((v,G)=>({node:v,nodeIdx:-1,meshIdx:G})),h=[];if(Array.isArray(e.lights)&&e.lights.length>0)h.push(...e.lights);else if(i.extensions?.KHR_lights_punctual?.lights){let v=i.extensions.KHR_lights_punctual.lights;for(let G of v){let L=G.type==="directional"?"directional":G.type==="point"?"point":"ambient";h.push({type:L,color:G.color||[1,1,1],intensity:G.intensity!==void 0?G.intensity:1})}}if(h.length===0&&(h.push({type:"ambient",color:[1,1,1],intensity:.35}),h.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),f.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${f.length}`);let b=[];if(i.textures&&i.images){if(i.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${i.textures.length}`);for(let v=0;v<i.textures.length;v++){let G=i.textures[v],L=i.images[G.source];if(L){let U=t.createTexture();if(t.bindTexture(3553,U),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),t.texParameteri(3553,10242,10497),t.texParameteri(3553,10243,10497),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),L.bufferView!==void 0){let q=i.bufferViews[L.bufferView],W=s.slice(q.byteOffset||0,(q.byteOffset||0)+q.byteLength),K=new Blob([W],{type:L.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(K).then(Y=>{t.bindTexture(3553,U),t.texImage2D(3553,0,6408,6408,5121,Y),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(L.uri){let q=ws(L.uri);if(q){let W=new Image;W.crossOrigin="anonymous",W.referrerPolicy="no-referrer",W.onload=()=>{t.bindTexture(3553,U),t.texImage2D(3553,0,6408,6408,5121,W),t.generateMipmap(3553),r?.()},W.src=q}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",L.uri)}b.push(U)}else b.push(null)}}let d=[1/0,1/0,1/0],p=[-1/0,-1/0,-1/0],E=0,A=0;for(let v=0;v<f.length;v++){let G=f[v],L=i.meshes[G.meshIdx],U=G.nodeIdx>=0?l[G.nodeIdx]:we(),q=new Float32Array(9);Le(q,U);let W={name:G.node.name||L.name||`Mesh_${G.meshIdx}`,nodeIndex:G.nodeIdx,transform:U,normalMatrix:q,primitives:[],extras:G.node.extras||L.extras},K=G.node?.extensions?.EXT_mesh_gpu_instancing;if(K&&K.attributes&&typeof K.attributes=="object"){let Y=K.attributes,te=Y.TRANSLATION!==void 0?i.accessors?.[Y.TRANSLATION]:null,ie=Y.ROTATION!==void 0?i.accessors?.[Y.ROTATION]:null,$=Y.SCALE!==void 0?i.accessors?.[Y.SCALE]:null,ne=Y._COLOR_0!==void 0?i.accessors?.[Y._COLOR_0]:null,re=Number(te?.count??ie?.count??$?.count??0);if(!Number.isFinite(re)||re<0||re>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${re}`);if(re>0){let O=(T,C)=>{if(!T||T.bufferView===void 0||!i.bufferViews?.[T.bufferView])return null;let w=(i.bufferViews[T.bufferView].byteOffset||0)+(T.byteOffset||0);return ys(s,w,re*C)},X=O(te,3),M=O(ie,4),N=O($,3),z=ne?.type==="VEC4"?4:3,V=O(ne,z),y=new Float32Array(re*16),g=we();for(let T=0;T<re;T++){let C=X?[X[T*3],X[T*3+1],X[T*3+2]]:[0,0,0],B=M?[M[T*4],M[T*4+1],M[T*4+2],M[T*4+3]]:[0,0,0,1],w=N?[N[T*3],N[T*3+1],N[T*3+2]]:[1,1,1];rt(g,B,C,w),y.set(g,T*16)}if(W.instanceMatrices=y,V){let T=new Float32Array(re*3);for(let C=0;C<re;C++)T[C*3]=V[C*z],T[C*3+1]=V[C*z+1],T[C*3+2]=V[C*z+2];W.instanceColors=T}}}for(let Y of L.primitives||[]){if(Y.extensions?.KHR_draco_mesh_compression){let me=Ft("draco");me&&me.decodePrimitive(i,Y,s)}let te=[],ie=t.createVertexArray();t.bindVertexArray(ie);let $=i.accessors[Y.attributes.POSITION],ne=Number($?.count??0);if(!Number.isFinite(ne)||ne<0||E+ne>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(E+=ne,$?.min&&$?.max){let me=ge=>{for(let Te=0;Te<3;Te++){let ye=ge[12+Te],ve=ge[12+Te];for(let _e=0;_e<3;_e++){let Ue=ge[_e*4+Te]*$.min[_e],Ve=ge[_e*4+Te]*$.max[_e];ye+=Ue<Ve?Ue:Ve,ve+=Ue>Ve?Ue:Ve}ye<d[Te]&&(d[Te]=ye),ve>p[Te]&&(p[Te]=ve)}};if(W.instanceMatrices&&W.instanceMatrices.length>=16){let ge=W.instanceMatrices.length>>4,Te=we();for(let ye=0;ye<ge;ye++){let ve=W.instanceMatrices.subarray(ye*16,ye*16+16);Ee(Te,U,ve),me(Te)}}else me(U)}let re=Dr(t,i,s,Y.attributes.POSITION,0,3,te);Dr(t,i,s,Y.attributes.NORMAL,1,3,te),Dr(t,i,s,Y.attributes.TEXCOORD_0,2,2,te);let O=0,X=5123,M=null;if(Y.indices!==void 0){let me=i.accessors[Y.indices],Te=(i.bufferViews[me.bufferView].byteOffset||0)+(me.byteOffset||0);if(O=Number(me.count??0),!Number.isFinite(O)||O<0||A+O>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);A+=O,X=me.componentType===5125?5125||5125:5123||5123;let ye=t.createBuffer();te.push(ye),t.bindBuffer(34963,ye),me.componentType===5125?(M=new Uint32Array(s,Te,me.count),t.bufferData(34963,M,35044)):(M=new Uint16Array(s,Te,me.count),t.bufferData(34963,M,35044))}else O=$.count;let N={};for(let me of Ie)if(me.onBuildPrimitiveVAO){let ge=me.onBuildPrimitiveVAO(t,ie,Y,i,s);ge&&(N[me.name]=ge)}t.bindVertexArray(null);let z=i.materials&&Y.material!==void 0?i.materials[Y.material]:null,V=Ji(),y=Zi,g=V.fs,T=!1;for(let me of Ie)if(me.onResolveShader){let ge=me.onResolveShader(Y,z,y,g);ge&&(y=ge.vs,g=ge.fs,T=!0)}let C=T?kr(t,y,g):null,B=C?Nr(t,C,V.uniforms):null,w=z?.pbrMetallicRoughness,F=w?.baseColorFactor||[.8,.8,.8,1],H=w?.metallicFactor??.1,J=w?.roughnessFactor??.5,Z=z?.extensions?.KHR_materials_clearcoat,ee=Z?Z.clearcoatFactor??1:0,j=Math.max(.04,Z?.clearcoatRoughnessFactor??.04),Q=w?.baseColorTexture!==void 0&&b[w.baseColorTexture.index]?b[w.baseColorTexture.index]:null,se=w?.metallicRoughnessTexture!==void 0&&b[w.metallicRoughnessTexture.index]?b[w.metallicRoughnessTexture.index]:null,oe=z?.normalTexture!==void 0&&b[z.normalTexture.index]?b[z.normalTexture.index]:null,ce=z?.normalTexture?.scale??1,ue=z?.occlusionTexture!==void 0&&b[z.occlusionTexture.index]?b[z.occlusionTexture.index]:null,le=z?.occlusionTexture?.strength??1,de=!!(z?.extensions?.KHR_materials_transmission||N.materials?.isTransmissive),be=Y.extensions?.KHR_materials_variants?.mappings,he=Array.isArray(be)?be.filter(me=>me&&typeof me.material=="number"&&Array.isArray(me.variants)).map(me=>({material:me.material|0,variants:me.variants.map(ge=>Number(ge)|0)})):void 0;W.primitives.push({vao:ie,indexCount:O,indexType:X,baseColor:F,metallic:H,roughness:J,clearcoat:ee,clearcoatRoughness:j,positions:re,indices:M,texture:Q,metallicRoughnessTexture:se,normalTexture:oe,occlusionTexture:ue,normalScale:ce,occlusionStrength:le,buffers:te,materialIndex:Y.material,defaultMaterialIndex:Y.material,variantMappings:he,pluginData:N,customProgram:C,customUniforms:B,isTransmissive:de})}c.push(W)}isFinite(d[0])||(d=[-1,-1,-1]),isFinite(p[0])||(p=[1,1,1]);let x=[(d[0]+p[0])/2,(d[1]+p[1])/2,(d[2]+p[2])/2],R=p[0]-d[0],I=p[1]-d[1],P=p[2]-d[2],k=Math.max(Math.hypot(R,I,P)/2,.5),D=[d[0],d[1],d[2]],S=[p[0],p[1],p[2]],_=e.animations;if(!_){for(let v of Ie)if(v.onParseGLB?.(e),e.animations){_=e.animations;break}}return _||(_=[]),{meshes:c,bounds:{center:x,radius:k,min:D,max:S},lights:h,animations:_,worldMatrices:l,gpuTextures:b,availableVariants:a}}var Fe=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=we();this.clearColor=[0,0,0,0];this.envIntensity=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=we();this.viewMatrix=we();this.modelMatrix=we();this.mvpMatrix=we();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.stereoSBS=!1;this.renderErrorReported=!1;this.xrDepthState={enabled:!1,texture:null,uvTransform:we(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let u=e.querySelector("canvas");u||(u=document.createElement("canvas"),u.style.width="100%",u.style.height="100%",u.style.display="block",u.style.touchAction="none",e.prepend(u)),i=u}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(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.envIntensity=Math.max(0,Number(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=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 c=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!c)throw new Error("WebGL2 not supported");this.gl=c;let a=Ji();this.renderProg=kr(c,Zi,a.fs),this.pickProg=kr(c,vs,Ts),this.uRender=Nr(c,this.renderProg,a.uniforms),this.uPick=Nr(c,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo(),this.setupEvents(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){bs(e,n)}static getDecoder(e){return Ft(e)}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),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,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){let{meshes:r,bounds:i,lights:o,animations:s,worldMatrices:c,gpuTextures:a,availableVariants:u}=Yi(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=s||[],this.worldMatrices=c||[],this.gpuTextures=a||[],this.availableVariants=u||[],this.gltf=e.gltf,this.activeVariantName&&this.applyVariantMaterial(this.activeVariantName),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of Ie)m.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let l=e.exposure??e.environmentIntensity??e.gltf?.extras?.exposure??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.exposure??e.gltf?.asset?.extras?.environmentIntensity;l!==void 0&&(this.envIntensity=Math.max(0,Number(l))),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(Ki(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(ot(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=ot(e),{meshes:i}=Yi(this.gl,r,to,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],Le(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),Le(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],s=[],c=[];for(let a of this.lights){let u=a.color||[1,1,1],l=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[u[0]*l,u[1]*l,u[2]*l];else if(a.type==="directional"&&i.length<6){let m=a.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(u[0]*l,u[1]*l,u[2]*l)}else if(a.type==="point"&&s.length<6){let m=a.position||[0,0,0];s.push(m[0],m[1],m[2]),c.push(u[0]*l,u[1]*l,u[2]*l)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(n.uniform3fv(e.uPointLightPos,s),n.uniform3fv(e.uPointLightColor,c)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.envIntensity=Math.max(0,Number(e))}getExposure(){return this.envIntensity}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=e}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of Ie)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of Ie)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.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((n,r)=>{let i=this.meshes.flatMap(l=>l.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],s=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],c=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:s,metallicFactor:c,roughnessFactor:a,setBaseColorFactor:l=>{let m=[l[0],l[1],l[2],l[3]??1];u.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let f of i)f.baseColor=m;this.render()},setMetallicFactor:l=>{u.metallicFactor=l,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=l);for(let m of i)m.metallic=l;this.render()},setRoughnessFactor:l=>{u.roughnessFactor=l,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=l);for(let m of i)m.roughness=l;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:u}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}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 n=this.applyVariantMaterial(e);return n&&this.gl&&this.render(),n}applyVariantMaterial(e){let n=e===null||e===""||e==="default",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let s of o.primitives){let c=s.defaultMaterialIndex;if(!n&&Array.isArray(s.variantMappings)){for(let m of s.variantMappings)if(Array.isArray(m.variants)&&m.variants.includes(r)){c=m.material;break}}if(c===void 0||!i[c]){s.materialIndex=void 0,s.baseColor=[.8,.8,.8,1],s.metallic=.1,s.roughness=.5,s.clearcoat=0,s.clearcoatRoughness=.04,s.texture=null,s.metallicRoughnessTexture=null,s.normalTexture=null,s.normalScale=1,s.occlusionTexture=null,s.occlusionStrength=1,s.isTransmissive=!1;continue}let a=i[c];s.materialIndex=c;let u=a.pbrMetallicRoughness;s.baseColor=u?.baseColorFactor?[u.baseColorFactor[0],u.baseColorFactor[1],u.baseColorFactor[2],u.baseColorFactor[3]??1]:[.8,.8,.8,1],s.metallic=u?.metallicFactor??.1,s.roughness=u?.roughnessFactor??.5;let l=a.extensions?.KHR_materials_clearcoat;s.clearcoat=l?l.clearcoatFactor??1:0,s.clearcoatRoughness=Math.max(.04,l?.clearcoatRoughnessFactor??.04),s.texture=u?.baseColorTexture!==void 0&&this.gpuTextures[u.baseColorTexture.index]?this.gpuTextures[u.baseColorTexture.index]:null,s.metallicRoughnessTexture=u?.metallicRoughnessTexture!==void 0&&this.gpuTextures[u.metallicRoughnessTexture.index]?this.gpuTextures[u.metallicRoughnessTexture.index]:null,s.normalTexture=a.normalTexture!==void 0&&this.gpuTextures[a.normalTexture.index]?this.gpuTextures[a.normalTexture.index]:null,s.normalScale=a.normalTexture?.scale??1,s.occlusionTexture=a.occlusionTexture!==void 0&&this.gpuTextures[a.occlusionTexture.index]?this.gpuTextures[a.occlusionTexture.index]:null,s.occlusionStrength=a.occlusionTexture?.strength??1,s.isTransmissive=!!(a.extensions?.KHR_materials_transmission||s.pluginData?.materials?.isTransmissive)}return!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 n of Ie)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],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 n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,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 n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}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,n){let r=we();Ee(r,this.projMatrix,this.viewMatrix);let[i,o,s]=e,c=n?n[0]:0,a=n?n[1]:0,u=n?n[2]:0,l=this.modelRootMatrix;l&&(i=l[0]*e[0]+l[4]*e[1]+l[8]*e[2]+l[12],o=l[1]*e[0]+l[5]*e[1]+l[9]*e[2]+l[13],s=l[2]*e[0]+l[6]*e[1]+l[10]*e[2]+l[14],n&&(c=l[0]*n[0]+l[4]*n[1]+l[8]*n[2],a=l[1]*n[0]+l[5]*n[1]+l[9]*n[2],u=l[2]*n[0]+l[6]*n[1]+l[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*s+r[12],f=r[1]*i+r[5]*o+r[9]*s+r[13],h=r[2]*i+r[6]*o+r[10]*s+r[14],b=r[3]*i+r[7]*o+r[11]*s+r[15];if(b<=1e-4)return{x:0,y:0,z:1,visible:!1};let d=m/b,p=f/b,E=h/b,A=this.canvas.getBoundingClientRect(),x=A.width||this.canvas.clientWidth||this.canvas.width||300,R=A.height||this.canvas.clientHeight||this.canvas.height||150,I=(d*.5+.5)*x,P=(-p*.5+.5)*R,k=d>=-1.1&&d<=1.1&&p>=-1.1&&p<=1.1&&E>=-1&&E<=1;if(k&&n){let D=this.customTarget||this.bounds.center,S=D[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),_=D[1]+this.currDistance*Math.sin(this.currPhi),v=D[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),G=[i-S,o-_,s-v];c*G[0]+a*G[1]+u*G[2]>.05&&(k=!1)}return{x:I,y:P,z:E,visible:k}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let s=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],c=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*s[0]+o*c[0])*u,a[1]+=(-i*s[1]+o*c[1])*u,a[2]+=(-i*s[2]+o*c[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.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=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,s=r.height||300,c=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),a=i.height>0?Math.floor((n-i.top)*(s/i.height)):Math.floor(n);return this.performMeshPick(c,a,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let c=we();Ee(c,this.projMatrix,this.viewMatrix);let a=[],u=Math.max(0,Math.min(o-1,e)),l=Math.max(0,Math.min(s-1,s-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==s)&&this.resizePickingFbo(o,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let D=0;D<this.meshes.length;D++){let S=this.meshes[D];if(S.visible===!1||S.isPluginMesh)continue;let _=D+1,v=(_&255)/255,G=(_>>8&255)/255,L=(_>>16&255)/255;i.uniform4f(this.uPick.uColorId,v,G,L,1),Ee(this.modelMatrix,this.modelRootMatrix,S.transform);let U=S.instanceMatrices;if(U&&U.length>=16){let q=U.length>>4,W=we();for(let K of S.primitives){i.bindVertexArray(K.vao);for(let Y=0;Y<q;Y++)Ee(W,this.modelMatrix,U.subarray(Y*16,Y*16+16)),Ee(this.mvpMatrix,c,W),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),K.indices?i.drawElements(4,K.indexCount,K.indexType,0):i.drawArrays(4,0,K.indexCount)}}else{Ee(this.mvpMatrix,c,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let q of S.primitives)i.bindVertexArray(q.vao),q.indices?i.drawElements(4,q.indexCount,q.indexType,0):i.drawArrays(4,0,q.indexCount)}}let P=new Uint8Array(4);i.readPixels(u,l,1,1,6408,5121,P),i.bindFramebuffer(36160,null);let k=P[0]+(P[1]<<8)+(P[2]<<16);k>0&&k<=this.meshes.length&&(a=[this.meshes[k-1]])}a.length===0&&(a=this.meshes.filter(P=>P.visible!==!1));let m=null,f=1/0,h=[0,0,0],b=[0,1,0],d=this.customTarget||this.bounds.center,p=d[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),E=d[1]+this.currDistance*Math.sin(this.currPhi),A=d[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),x=we();for(let P of a){Ee(x,this.modelRootMatrix,P.transform);let k=P.instanceMatrices,D=k&&k.length>=16?k.length>>4:1;for(let S=0;S<D;S++){k&&k.length>=16?Ee(this.modelMatrix,x,k.subarray(S*16,S*16+16)):this.modelMatrix.set(x),Ee(this.mvpMatrix,c,this.modelMatrix);let _=we();if(!An(_,this.mvpMatrix))continue;let v=(u+.5)/o*2-1,G=(l+.5)/s*2-1,L=[0,0,0],U=[0,0,0];Pr(L,v,G,-1,_),Pr(U,v,G,1,_);let q=U[0]-L[0],W=U[1]-L[1],K=U[2]-L[2],Y=Math.hypot(q,W,K)||1,te=q/Y,ie=W/Y,$=K/Y,ne={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((O=>{for(let X of P.primitives){if(!X.positions)continue;let M=X.positions,N=X.indices,z=Math.floor(N?N.length/3:M.length/9);for(let V=0;V<z;V++){let y=N?N[V*3]:V*3,g=N?N[V*3+1]:V*3+1,T=N?N[V*3+2]:V*3+2;Wi(L[0],L[1],L[2],te,ie,$,M[y*3],M[y*3+1],M[y*3+2],M[g*3],M[g*3+1],M[g*3+2],M[T*3],M[T*3+1],M[T*3+2],ne,O)}}})(1e-4),isFinite(ne.distance)){let O=ne.point[0],X=ne.point[1],M=ne.point[2],N=this.modelMatrix,z=N[0]*O+N[4]*X+N[8]*M+N[12],V=N[1]*O+N[5]*X+N[9]*M+N[13],y=N[2]*O+N[6]*X+N[10]*M+N[14],g=z-p,T=V-E,C=y-A,B=Math.hypot(g,T,C);if(B<f){Le(this.normalMatrix,this.modelMatrix);let w=this.normalMatrix,F=ne.normal[0],H=ne.normal[1],J=ne.normal[2],Z=w[0]*F+w[3]*H+w[6]*J,ee=w[1]*F+w[4]*H+w[7]*J,j=w[2]*F+w[5]*H+w[8]*J,Q=Math.hypot(Z,ee,j)||1;Z/=Q,ee/=Q,j/=Q,Z*g+ee*T+j*C>0&&(Z=-Z,ee=-ee,j=-j),m=P,f=Math.round(B*1e3)/1e3,h=[Math.round(z*1e3)/1e3,Math.round(V*1e3)/1e3,Math.round(y*1e3)/1e3],b=[Math.round(Z*1e3)/1e3,Math.round(ee*1e3)/1e3,Math.round(j*1e3)/1e3]}}}}if(!m)return null;let I={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:f,hitPoint:h,normal:b,screenX:e,screenY:n};if(r){for(let P of Ie)P.onMeshSelect?.(this,I);this.opts.onMeshClick&&this.opts.onMeshClick(I),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:I}))}return I}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,s=i?Math.max(1,n-r):r,c=(o+.5)/s*2-1;return Math.floor((c*.5+1)*.5*n)}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),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Mn(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center,i=r[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),o=r[1]+this.currDistance*Math.sin(this.currPhi),s=r[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);Nt(this.viewMatrix,[i,o,s],r,[0,1,0]),Ee(this.mvpMatrix,this.projMatrix,this.viewMatrix),Le(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of Ie)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of Ie)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}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),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Ie)s.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of Ie)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 r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let s={theta:r,phi:i,zoom:o,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(e,n,r,i,o=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let c=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,u=e?.transform?.position,l=u?[u.x,u.y,u.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:c,projMatrix:a,eyePos:l,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:o})}render(e){if(!e&&this.stereoSBS){let R=Math.max(2,this.canvas.width||2),I=Math.max(1,this.canvas.height||1),P=Math.max(1,Math.floor(R*.5)),k=Math.max(1,R-P),D=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),S=this.customTarget||this.bounds.center,_=S[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),v=S[1]+this.currDistance*Math.sin(this.currPhi),G=S[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta),L=Math.cos(this.currTheta),U=-Math.sin(this.currTheta),q=.032,W=we(),K=we(),Y=[_-L*q,v,G-U*q],te=[S[0]-L*q*.25,S[1],S[2]-U*q*.25];Mn(W,this.fov,P/I,.1,D),Nt(K,Y,te,[0,1,0]);let ie=we(),$=we(),ne=[_+L*q,v,G+U*q],re=[S[0]+L*q*.25,S[1],S[2]+U*q*.25];Mn(ie,this.fov,k/I,.1,D),Nt($,ne,re,[0,1,0]),this.render({viewMatrix:K,projMatrix:W,eyePos:Y,viewport:[0,0,P,I],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:$,projMatrix:ie,eyePos:ne,viewport:[P,0,k,I],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,R,I);return}let n=this.gl,r=0,i=0,o=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],s=e.viewport[3],n.viewport(r,i,o,s)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let c=we(),a=e?.viewMatrix??this.viewMatrix;Ee(c,e?.projMatrix??this.projMatrix,a);let u=pe().xrDepthShader,l=this.toneMapping==="reinhard"?1:this.toneMapping==="none"?2:this.toneMapping==="aces"?3:this.toneMapping==="agx"?4:0,m=this.customTarget||this.bounds.center,f=e?e.eyePos[0]:m[0]+this.currDistance*Math.cos(this.currPhi)*Math.sin(this.currTheta),h=e?e.eyePos[1]:m[1]+this.currDistance*Math.sin(this.currPhi),b=e?e.eyePos[2]:m[2]+this.currDistance*Math.cos(this.currPhi)*Math.cos(this.currTheta);for(let R of Ie)R.onBeforeDrawScene?.(this,n,c,[f,h,b],l);let d=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&d===0)return;let p=e?.eye||"none",E=!1,A=d>0?[...this.backdropMeshes,...this.meshes]:this.meshes,x=R=>{for(let I=0;I<A.length;I++){let P=A[I];if(P.visible===!1)continue;let k=this.selectedMeshName!==""&&P.name===this.selectedMeshName;I<d||P.worldSpace===!0||P.name==="__xr_reticle__"?this.modelMatrix.set(P.transform):Ee(this.modelMatrix,this.modelRootMatrix,P.transform),Ee(this.mvpMatrix,c,this.modelMatrix),Le(P.normalMatrix,this.modelMatrix);let D=P.extras?.xr?.stereo||P.userData?.xr?.stereo,S=0,_=0,v=1,G=1;D==="sbs"?(v=.5,S=p==="right"?.5:0):D==="ou"&&(G=.5,_=p==="right"?.5:0);for(let L of P.primitives){let U=!!L.isTransmissive;if(!R&&U){E=!0;continue}if(R&&!U)continue;let q=L.customProgram||this.renderProg,W=L.customUniforms||this.uRender;n.useProgram(q),n.uniform1i(W.uToneMapping,l),n.uniform1f(W.uEnvIntensity,this.envIntensity),n.uniform3f(W.uCameraPos,f,h,b),n.uniform1f(W.uEmissive,k?1:0),n.uniformMatrix4fv(W.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(W.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(W.uNormalMatrix,!1,P.normalMatrix),W.uUvTransform&&n.uniform4f(W.uUvTransform,S,_,v,G),W.uViewportSize&&n.uniform2f(W.uViewportSize,Math.max(1,o),Math.max(1,s)),u?.bind(n,W,this.xrDepthState,a,[r,i,Math.max(1,o),Math.max(1,s)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(W.uEnvironmentMap,4),n.uniform1i(W.uHasEnvironmentMap,1)):n.uniform1i(W.uHasEnvironmentMap,0),this.bindLights(W),W.uSectionEnabled&&n.uniform1i(W.uSectionEnabled,0);for(let Y of Ie)Y.onBeforeDrawPrimitive?.(n,q,L,P,this.worldMatrices||[],this.gltf);n.uniform4fv(W.uBaseColor,L.baseColor),n.uniform1f(W.uMetallic,L.metallic),n.uniform1f(W.uRoughness,L.roughness),W.uClearcoat&&n.uniform2f(W.uClearcoat,L.clearcoat??0,L.clearcoatRoughness??.04),L.texture?(n.activeTexture(33984),n.bindTexture(3553,L.texture),n.uniform1i(W.uBaseColorTexture,0),n.uniform1i(W.uHasTexture,1)):n.uniform1i(W.uHasTexture,0),L.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,L.metallicRoughnessTexture),n.uniform1i(W.uMetallicRoughnessTexture,1),n.uniform1i(W.uHasMetallicRoughnessTexture,1)):n.uniform1i(W.uHasMetallicRoughnessTexture,0),L.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,L.normalTexture),n.uniform1i(W.uNormalTexture,2),n.uniform1i(W.uHasNormalTexture,1),n.uniform1f(W.uNormalScale,L.normalScale)):n.uniform1i(W.uHasNormalTexture,0),L.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,L.occlusionTexture),n.uniform1i(W.uOcclusionTexture,3),n.uniform1i(W.uHasOcclusionTexture,1),n.uniform1f(W.uOcclusionStrength,L.occlusionStrength)):n.uniform1i(W.uHasOcclusionTexture,0),n.bindVertexArray(L.vao);let K=P.instanceMatrices;if(K&&K.length>=16){let Y=K.length>>4,te=P.instanceColors,ie=we(),$=new Float32Array(9),ne=[L.baseColor[0],L.baseColor[1],L.baseColor[2],L.baseColor[3]];for(let re=0;re<Y;re++)Ee(ie,this.modelMatrix,K.subarray(re*16,re*16+16)),Ee(this.mvpMatrix,c,ie),Le($,ie),n.uniformMatrix4fv(W.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(W.uModel,!1,ie),n.uniformMatrix3fv(W.uNormalMatrix,!1,$),te&&(ne[0]=L.baseColor[0]*te[re*3],ne[1]=L.baseColor[1]*te[re*3+1],ne[2]=L.baseColor[2]*te[re*3+2],ne[3]=L.baseColor[3],n.uniform4fv(W.uBaseColor,ne)),L.indices?n.drawElements(4,L.indexCount,L.indexType,0):n.drawArrays(4,0,L.indexCount)}else L.indices?n.drawElements(4,L.indexCount,L.indexType,0):n.drawArrays(4,0,L.indexCount)}}};if(x(!1),E){for(let R of Ie)R.onBeforeTransmissivePass?.(n,this);x(!0)}for(let R of Ie)R.onAfterRender?.(n,this,c)}disposeMeshListGpuResources(e,n){let r=this.gl,i=new Set,o=s=>{s&&!i.has(s)&&(i.add(s),r.deleteTexture(s))};for(let s of e)for(let c of s.primitives){if(c.vao&&r.deleteVertexArray(c.vao),c.buffers)for(let a of c.buffers)r.deleteBuffer(a);o(c.texture),o(c.metallicRoughnessTexture),o(c.normalTexture),o(c.occlusionTexture),c.customProgram&&r.deleteProgram(c.customProgram)}if(n)for(let s of n)o(s)}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 n of Ie)n.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()}};Fe.registerPlugin=Pe,Fe.getRegisteredPlugins=Tn;function Ms(t){return t+3&-4}function As(t,e=0){let n=($,ne)=>typeof $=="number"&&Number.isFinite($)?$:ne,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),s=n(t[e+0],1),c=n(t[e+1],0),a=n(t[e+2],0),u=n(t[e+4],0),l=n(t[e+5],1),m=n(t[e+6],0),f=n(t[e+8],0),h=n(t[e+9],0),b=n(t[e+10],1),d=Math.hypot(s,c,a),p=Math.hypot(u,l,m),E=Math.hypot(f,h,b);s*(l*b-h*m)-u*(c*b-h*a)+f*(c*m-l*a)<0&&(d=-d);let x=Math.abs(d)>1e-8?1/d:0,R=Math.abs(p)>1e-8?1/p:0,I=Math.abs(E)>1e-8?1/E:0,P=s*x,k=c*x,D=a*x,S=u*R,_=l*R,v=m*R,G=f*I,L=h*I,U=b*I,q=P+_+U,W=0,K=0,Y=0,te=1;if(q>0){let $=.5/Math.sqrt(q+1);te=.25/$,W=(v-L)*$,K=(G-D)*$,Y=(k-S)*$}else if(P>_&&P>U){let $=2*Math.sqrt(Math.max(0,1+P-_-U));$>1e-8&&(te=(v-L)/$,W=.25*$,K=(S+k)/$,Y=(G+D)/$)}else if(_>U){let $=2*Math.sqrt(Math.max(0,1+_-P-U));$>1e-8&&(te=(G-D)/$,W=(S+k)/$,K=.25*$,Y=(v+L)/$)}else{let $=2*Math.sqrt(Math.max(0,1+U-P-_));$>1e-8&&(te=(k-S)/$,W=(G+D)/$,K=(v+L)/$,Y=.25*$)}let ie=Math.hypot(W,K,Y,te);return ie>1e-8&&Number.isFinite(ie)?(W/=ie,K/=ie,Y/=ie,te/=ie):(W=0,K=0,Y=0,te=1),{t:[r,i,o],r:[W,K,Y,te],s:[d,p,E]}}function Ss(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}function Ut(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],s=[],c=[],a=new Set,u=[],l=[],m=new Map,f=[],h=[];function b(S){let _=m.get(S);if(_!==void 0)return _;_=l.length,m.set(S,_);let v=S,G=v.color?.r??.8,L=v.color?.g??.8,U=v.color?.b??.8,q=v.opacity??1,W={name:v.name||"",pbrMetallicRoughness:{baseColorFactor:[G,L,U,q],metallicFactor:v.metalness??.1,roughnessFactor:v.roughness??.5},doubleSided:v.side===2||!!v.doubleSided};if(v.emissive&&(v.emissive.r>0||v.emissive.g>0||v.emissive.b>0)){let Y=v.emissiveIntensity??1;W.emissiveFactor=[v.emissive.r*Y,v.emissive.g*Y,v.emissive.b*Y]}let K={};return v.clearcoat&&v.clearcoat>0&&(K.KHR_materials_clearcoat={clearcoatFactor:v.clearcoat,clearcoatRoughnessFactor:v.clearcoatRoughness||0}),v.sheen&&v.sheen>0&&(K.KHR_materials_sheen={sheenColorFactor:v.sheenColor?[v.sheenColor.r,v.sheenColor.g,v.sheenColor.b]:[1,1,1],sheenRoughnessFactor:v.sheenRoughness||0}),v.transmission&&v.transmission>0&&(K.KHR_materials_transmission={transmissionFactor:v.transmission}),v.thickness&&v.thickness>0&&(K.KHR_materials_volume={thicknessFactor:v.thickness,attenuationDistance:v.attenuationDistance??1/0,attenuationColor:v.attenuationColor?[v.attenuationColor.r,v.attenuationColor.g,v.attenuationColor.b]:[1,1,1]}),v.ior!==void 0&&v.ior!==1.5&&(K.KHR_materials_ior={ior:v.ior}),v.dispersion&&v.dispersion>0&&(K.KHR_materials_dispersion={dispersion:v.dispersion}),v.iridescence&&v.iridescence>0&&(K.KHR_materials_iridescence={iridescenceFactor:v.iridescence,iridescenceIor:v.iridescenceIOR??1.3}),Object.keys(K).length>0&&(W.extensions=K),l.push(W),_}function d(S,_){let v=new Uint8Array(S.buffer,S.byteOffset,S.byteLength),G=Ms(v.byteLength),L=new Uint8Array(G);L.set(v),n.push(L);let U=i.length;return i.push({buffer:0,byteOffset:r,byteLength:v.byteLength,target:_}),r+=G,U}function p(S,_,v,G,L,U,q){let W=d(S,v),K=o.length,Y={bufferView:W,byteOffset:0,componentType:G,count:L,type:_};return U&&(Y.min=U),q&&(Y.max=q),o.push(Y),K}t.traverse(S=>{(S.isLight||S.color&&S.intensity!==void 0)&&h.push({type:S.type,color:[S.color.r,S.color.g,S.color.b],intensity:S.intensity,position:[S.position.x,S.position.y,S.position.z]})});let E=[];function A(S){let _={name:S.name||""},v=S.position,G=S.quaternion,L=S.scale;if((v.x||v.y||v.z)&&(_.translation=[v.x,v.y,v.z]),(G.x||G.y||G.z||G.w!==1)&&(_.rotation=[G.x,G.y,G.z,G.w]),(L.x!==1||L.y!==1||L.z!==1)&&(_.scale=[L.x,L.y,L.z]),S.userData&&Object.keys(S.userData).length>0&&(_.extras=JSON.parse(JSON.stringify(S.userData,(q,W)=>{if(!(q==="__proto__"||q==="prototype"||q==="constructor"))return typeof W=="function"?void 0:W})),S.userData.xr)){let q=Ss(S.userData.xr);_.extensions={..._.extensions||{},MOZ_hubs_components:q,ANDROID_xr_scenecore:q},pe().xrTraitSerializer?.gltfNode(_,S.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(S.geometry){let q=S.geometry,W=q.attributes.position;if(W&&W.count>0){let K=[1/0,1/0,1/0],Y=[-1/0,-1/0,-1/0];for(let O=0;O<W.count;O++){let X=W.getX(O),M=W.getY(O),N=W.getZ(O);X<K[0]&&(K[0]=X),X>Y[0]&&(Y[0]=X),M<K[1]&&(K[1]=M),M>Y[1]&&(Y[1]=M),N<K[2]&&(K[2]=N),N>Y[2]&&(Y[2]=N)}let ie={attributes:{POSITION:p(W.array,"VEC3",34962,5126,W.count,K,Y)}};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 O=q.index.array instanceof Uint32Array;ie.indices=p(q.index.array,"SCALAR",34963,O?5125:5123,q.index.count)}S.material&&(ie.material=b(S.material));let $=S.userData?.variants;if($&&typeof $=="object"){let O=new Map;for(let X of Object.keys($)){if(!X||X==="__proto__"||X==="constructor"||X==="prototype")continue;let M=$[X];if(!M||typeof M!="object")continue;let N=f.indexOf(X);if(N===-1&&f.length<256&&(N=f.length,f.push(X)),N===-1)continue;let z=b(M),V=O.get(z);V||(V=[],O.set(z,V)),V.push(N)}if(O.size>0){let X=[];for(let[M,N]of O.entries())X.push({material:M,variants:N});ie.extensions={...ie.extensions||{},KHR_materials_variants:{mappings:X}},a.add("KHR_materials_variants")}}let ne=S;if(ne.isInstancedMesh&&typeof ne.count=="number"&&ne.count>0&&ne.instanceMatrix?.array){let O=Math.min(1e4,Math.floor(ne.count)),X=ne.instanceMatrix.array,M=new Float32Array(O*3),N=new Float32Array(O*4),z=new Float32Array(O*3);for(let y=0;y<O;y++){let{t:g,r:T,s:C}=As(X,y*16);M[y*3]=g[0],M[y*3+1]=g[1],M[y*3+2]=g[2],N[y*4]=T[0],N[y*4+1]=T[1],N[y*4+2]=T[2],N[y*4+3]=T[3],z[y*3]=C[0],z[y*3+1]=C[1],z[y*3+2]=C[2]}let V={TRANSLATION:p(M,"VEC3",0,5126,O),ROTATION:p(N,"VEC4",0,5126,O),SCALE:p(z,"VEC3",0,5126,O)};if(ne.instanceColor?.array&&ne.instanceColor.array.length>=O*3){let y=new Float32Array(ne.instanceColor.array.subarray(0,O*3));V._COLOR_0=p(y,"VEC3",0,5126,O)}_.extensions={..._.extensions||{},EXT_mesh_gpu_instancing:{attributes:V}},a.add("EXT_mesh_gpu_instancing")}let re=s.length;s.push({primitives:[ie],name:S.name,..._.extras?{extras:_.extras}:{}}),_.mesh=re}}let U=c.length;if(c.push(_),u.push(S),S.children.length>0){_.children=[];for(let q of S.children)_.children.push(A(q))}return U}for(let S of t.children)E.push(A(S));let x=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),R=[];if(typeof x=="function"&&u.length>0){let S=e?.duration??4,_=e?.fps??15,v=Math.max(2,Math.round(S*_)+1),G=new Float32Array(v),L=u.map($=>({px:$.position.x,py:$.position.y,pz:$.position.z,qx:$.quaternion.x,qy:$.quaternion.y,qz:$.quaternion.z,qw:$.quaternion.w,sx:$.scale.x,sy:$.scale.y,sz:$.scale.z})),U=u.map(()=>new Float32Array(v*3)),q=u.map(()=>new Float32Array(v*4)),W=u.map(()=>new Float32Array(v*3));for(let $=0;$<v;$++){let ne=$/(v-1)*S;G[$]=ne;try{x(ne)}catch{}for(let re=0;re<u.length;re++){let O=u[re];U[re][$*3]=O.position.x,U[re][$*3+1]=O.position.y,U[re][$*3+2]=O.position.z,q[re][$*4]=O.quaternion.x,q[re][$*4+1]=O.quaternion.y,q[re][$*4+2]=O.quaternion.z,q[re][$*4+3]=O.quaternion.w,W[re][$*3]=O.scale.x,W[re][$*3+1]=O.scale.y,W[re][$*3+2]=O.scale.z}}for(let $=0;$<u.length;$++){let ne=u[$],re=L[$];ne.position.set(re.px,re.py,re.pz),ne.quaternion.set(re.qx,re.qy,re.qz,re.qw),ne.scale.set(re.sx,re.sy,re.sz)}t.updateMatrixWorld(!0);let K=null,Y=()=>(K===null&&(K=p(G,"SCALAR",0,5126,v,[0],[S])),K),te=[],ie=[];for(let $=0;$<u.length;$++){let ne=L[$],re=!1,O=!1,X=!1;for(let M=0;M<v;M++)(Math.abs(U[$][M*3]-ne.px)>1e-4||Math.abs(U[$][M*3+1]-ne.py)>1e-4||Math.abs(U[$][M*3+2]-ne.pz)>1e-4)&&(re=!0),(Math.abs(q[$][M*4]-ne.qx)>1e-4||Math.abs(q[$][M*4+1]-ne.qy)>1e-4||Math.abs(q[$][M*4+2]-ne.qz)>1e-4||Math.abs(q[$][M*4+3]-ne.qw)>1e-4)&&(O=!0),(Math.abs(W[$][M*3]-ne.sx)>1e-4||Math.abs(W[$][M*3+1]-ne.sy)>1e-4||Math.abs(W[$][M*3+2]-ne.sz)>1e-4)&&(X=!0);if(re){let M=p(U[$],"VEC3",0,5126,v),N=te.length;te.push({input:Y(),interpolation:"LINEAR",output:M}),ie.push({sampler:N,target:{node:$,path:"translation"}})}if(O){let M=p(q[$],"VEC4",0,5126,v),N=te.length;te.push({input:Y(),interpolation:"LINEAR",output:M}),ie.push({sampler:N,target:{node:$,path:"rotation"}})}if(X){let M=p(W[$],"VEC3",0,5126,v),N=te.length;te.push({input:Y(),interpolation:"LINEAR",output:M}),ie.push({sampler:N,target:{node:$,path:"scale"}})}}ie.length>0&&R.push({name:"ProceduralLoop",samplers:te,channels:ie})}let I=Vi(c,s,t.userData),P={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:E}],scene:0,nodes:c,meshes:s,materials:l,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...R.length>0?{animations:R}:{},...I||a.size>0?{extensionsUsed:[...I?["KHR_interactivity"]:[],...a]}:{},...I||f.length>0?{extensions:{...I?{KHR_interactivity:I}:{},...f.length>0?{KHR_materials_variants:{variants:f.map(S=>({name:S}))}}:{}}}:{}},k=new Uint8Array(r),D=0;for(let S of n)k.set(S,D),D+=S.byteLength;return{gltf:P,bin:k.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function En(t){return new TextEncoder().encode(t)}function Wt(t,e){let{gltf:n,bin:r}=Ut(t,e),i=JSON.stringify(n),o=En(i),s=(4-o.byteLength%4)%4,c=o.byteLength+s,a=20+c+8+r.byteLength,u=new Uint8Array(a),l=new DataView(u.buffer);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0),l.setUint32(8,a,!0),l.setUint32(12,c,!0),l.setUint32(16,1313821514,!0),u.set(o,20);for(let f=0;f<s;f++)u[20+o.byteLength+f]=32;let m=20+c;return l.setUint32(m,r.byteLength,!0),l.setUint32(m+4,5130562,!0),u.set(new Uint8Array(r),m+8),u}function Es(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let s=o.count,c=new Float32Array(s*3),a=r.matrixWorld.elements;for(let D=0;D<s;D++){let S=o.getX(D),_=o.getY(D),v=o.getZ(D);c[D*3]=a[0]*S+a[4]*_+a[8]*v+a[12],c[D*3+1]=a[1]*S+a[5]*_+a[9]*v+a[13],c[D*3+2]=a[2]*S+a[6]*_+a[10]*v+a[14]}let u;if(i.attributes.normal){let D=i.attributes.normal;u=new Float32Array(s*3);let S=new Float32Array(9);Le(S,a);for(let _=0;_<s;_++){let v=D.getX(_),G=D.getY(_),L=D.getZ(_),U=S[0]*v+S[3]*G+S[6]*L,q=S[1]*v+S[4]*G+S[7]*L,W=S[2]*v+S[5]*G+S[8]*L,K=Math.hypot(U,q,W)||1;u[_*3]=U/K,u[_*3+1]=q/K,u[_*3+2]=W/K}}let l;if(i.attributes.uv){let D=i.attributes.uv;l=new Float32Array(s*2);for(let S=0;S<s;S++)l[S*2]=D.getX(S),l[S*2+1]=D.getY(S)}let m;if(i.index)m=i.index.array;else{m=s>65535?new Uint32Array(s):new Uint16Array(s);for(let D=0;D<s;D++)m[D]=D}let f="DefaultMaterial",h=[.8,.8,.8],b=.5,d=.1,p=0,E=0,A=1.5,x=1,R=[0,0,0];if(r.material){let D=r.material;f=D.name||`Material_${n.length}`,D.color&&(h=[D.color.r,D.color.g,D.color.b]),typeof D.roughness=="number"&&(b=D.roughness),typeof D.metalness=="number"&&(d=D.metalness),typeof D.clearcoat=="number"&&(p=D.clearcoat),typeof D.clearcoatRoughness=="number"&&(E=D.clearcoatRoughness),typeof D.ior=="number"&&(A=D.ior);let S=typeof D.opacity=="number"?D.opacity:1,_=typeof D.transmission=="number"?D.transmission:0;if(x=S*(1-_),D.emissive&&(D.emissive.r>0||D.emissive.g>0||D.emissive.b>0)){let v=D.emissiveIntensity??1;R=[D.emissive.r*v,D.emissive.g*v,D.emissive.b*v]}}let I,P=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);if(typeof P=="function"){let D=e?.duration??4,S=e?.fps??4,_=Math.max(2,Math.round(D*S)+1),v=[],G=[],L=[],U=[],q=[r.position.x,r.position.y,r.position.z],W=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],K=[r.scale.x,r.scale.y,r.scale.z],Y=!1;for(let te=0;te<_;te++){let ie=te/(_-1)*D;v.push(ie);try{P(ie)}catch{}G.push([r.position.x,r.position.y,r.position.z]),L.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),U.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-q[0])>1e-4||Math.abs(r.position.y-q[1])>1e-4||Math.abs(r.position.z-q[2])>1e-4||Math.abs(r.quaternion.x-W[0])>1e-4||Math.abs(r.quaternion.y-W[1])>1e-4||Math.abs(r.quaternion.z-W[2])>1e-4||Math.abs(r.quaternion.w-W[3])>1e-4||Math.abs(r.scale.x-K[0])>1e-4)&&(Y=!0)}r.position.set(q[0],q[1],q[2]),r.quaternion.set(W[0],W[1],W[2],W[3]),r.scale.set(K[0],K[1],K[2]),Y&&(I={times:v,translations:G,rotations:L,scales:U})}let k=r;if(k.isInstancedMesh&&typeof k.count=="number"&&k.count>0&&k.instanceMatrix?.array){let D=Math.min(1e3,Math.floor(k.count)),S=k.instanceMatrix.array,_=k.instanceColor?.array,v=r.name||`Mesh_${n.length}`,G=new Float32Array(16),L=new Float32Array(9);for(let U=0;U<D;U++){let q=S.subarray(U*16,(U+1)*16);Ee(G,a,q);let W=new Float32Array(s*3);for(let ie=0;ie<s;ie++){let $=o.getX(ie),ne=o.getY(ie),re=o.getZ(ie);W[ie*3]=G[0]*$+G[4]*ne+G[8]*re+G[12],W[ie*3+1]=G[1]*$+G[5]*ne+G[9]*re+G[13],W[ie*3+2]=G[2]*$+G[6]*ne+G[10]*re+G[14]}let K;if(i.attributes.normal){let ie=i.attributes.normal;K=new Float32Array(s*3),Le(L,G);for(let $=0;$<s;$++){let ne=ie.getX($),re=ie.getY($),O=ie.getZ($),X=L[0]*ne+L[3]*re+L[6]*O,M=L[1]*ne+L[4]*re+L[7]*O,N=L[2]*ne+L[5]*re+L[8]*O,z=Math.hypot(X,M,N)||1;K[$*3]=X/z,K[$*3+1]=M/z,K[$*3+2]=N/z}}let Y=h,te=f;_&&_.length>=(U+1)*3&&(Y=[h[0]*_[U*3],h[1]*_[U*3+1],h[2]*_[U*3+2]],te=`${f}_inst_${U}`),n.push({name:`${v}_${U}`,positions:W,indices:m,normals:K,uvs:l,materialName:te,color:Y,roughness:b,metallic:d,clearcoat:p,clearcoatRoughness:E,ior:A,opacity:x,emissiveColor:R,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:c,indices:m,normals:u,uvs:l,materialName:f,color:h,roughness:b,metallic:d,clearcoat:p,clearcoatRoughness:E,ior:A,opacity:x,emissiveColor:R,xrTraits:r.userData?.xr,timeSamples:I})}}),n}function io(t){let e=[],n=t.gltf,r=pe().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,t);let i=t.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=n.accessors||[],c=n.bufferViews||[],a=n.materials||[],u=n.meshes||[],l=n.nodes||[];function m(b){let d=s[b];if(!d)throw new Error(`Accessor ${b} not found`);let p=c[d.bufferView||0],E=(p.byteOffset||0)+(d.byteOffset||0),A=p.byteLength||0,x=o.slice(E,E+A);return{acc:d,buffer:x}}let f=new Map;if(l.length>0){let b=it(n);for(let d=0;d<b.length;d++)f.set(d,b[d])}function h(b,d,p,E){let A=u[b];if(!A)return;let x=new Float32Array(9);Le(x,d);for(let R=0;R<(A.primitives||[]).length;R++){let I=A.primitives[R],P=I.attributes?.POSITION;if(P===void 0)continue;let{acc:k,buffer:D}=m(P),S=new Float32Array(D,0,k.count*3),_=new Float32Array(S.length);for(let M=0;M<k.count;M++){let N=S[M*3],z=S[M*3+1],V=S[M*3+2];_[M*3]=d[0]*N+d[4]*z+d[8]*V+d[12],_[M*3+1]=d[1]*N+d[5]*z+d[9]*V+d[13],_[M*3+2]=d[2]*N+d[6]*z+d[10]*V+d[14]}let v,G=I.attributes?.NORMAL;if(G!==void 0){let{acc:M,buffer:N}=m(G),z=new Float32Array(N,0,M.count*3);v=new Float32Array(z.length);for(let V=0;V<M.count;V++){let y=z[V*3],g=z[V*3+1],T=z[V*3+2],C=x[0]*y+x[3]*g+x[6]*T,B=x[1]*y+x[4]*g+x[7]*T,w=x[2]*y+x[5]*g+x[8]*T,F=Math.hypot(C,B,w)||1;v[V*3]=C/F,v[V*3+1]=B/F,v[V*3+2]=w/F}}let L,U=I.attributes?.TEXCOORD_0;if(U!==void 0){let{acc:M,buffer:N}=m(U);L=new Float32Array(N,0,M.count*2)}let q;if(I.indices!==void 0){let{acc:M,buffer:N}=m(I.indices);M.componentType===5125?q=new Uint32Array(N,0,M.count):q=new Uint16Array(N,0,M.count);let z=k.count;for(let V of q)if(V>=z)throw new Error(`SecurityError: Index buffer value (${V}) out of vertex bounds [0, ${z}).`)}else{let M=k.count;q=M>65535?new Uint32Array(M):new Uint16Array(M);for(let N=0;N<M;N++)q[N]=N}let W="DefaultMaterial",K=[.8,.8,.8],Y=.5,te=.1,ie=0,$=0,ne=1.5,re=1,O=[0,0,0];if(I.material!==void 0&&a[I.material]){let M=a[I.material];W=M.name||`Material_${I.material}`;let N=M.pbrMetallicRoughness||{},z=1;Array.isArray(N.baseColorFactor)&&(K=[N.baseColorFactor[0],N.baseColorFactor[1],N.baseColorFactor[2]],typeof N.baseColorFactor[3]=="number"&&(z=N.baseColorFactor[3])),typeof N.roughnessFactor=="number"&&(Y=N.roughnessFactor),typeof N.metallicFactor=="number"&&(te=N.metallicFactor),Array.isArray(M.emissiveFactor)&&M.emissiveFactor.length>=3&&(O=[M.emissiveFactor[0],M.emissiveFactor[1],M.emissiveFactor[2]]);let V=M.extensions||{};V.KHR_materials_clearcoat&&(ie=V.KHR_materials_clearcoat.clearcoatFactor??0,$=V.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),V.KHR_materials_ior&&typeof V.KHR_materials_ior.ior=="number"&&(ne=V.KHR_materials_ior.ior);let y=V.KHR_materials_transmission?.transmissionFactor??0;re=z*(1-y)}let X=(A.primitives||[]).length>1?`${p}_p${R}`:p;e.push({name:X,positions:_,indices:q,normals:v,uvs:L,materialName:W,color:K,roughness:Y,metallic:te,clearcoat:ie,clearcoatRoughness:$,ior:ne,opacity:re,emissiveColor:O,xrTraits:E?.xr||A.extras?.xr})}}if(l.length>0)for(let b=0;b<l.length;b++){let d=l[b];if(d.mesh!==void 0&&d.mesh<u.length){let p=f.get(b)||we(),E=d.name||u[d.mesh].name||`Node_${b}`,A=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(A&&typeof A=="object"){let x=A.TRANSLATION,R=A.ROTATION,I=A.SCALE,P=x!==void 0?(()=>{let{acc:_,buffer:v}=m(x);return new Float32Array(v,0,_.count*3)})():null,k=R!==void 0?(()=>{let{acc:_,buffer:v}=m(R);return new Float32Array(v,0,_.count*4)})():null,D=I!==void 0?(()=>{let{acc:_,buffer:v}=m(I);return new Float32Array(v,0,_.count*3)})():null,S=Math.min(1e3,P?P.length/3:k?k.length/4:D?D.length/3:0);if(S>0){let _=new Float32Array(16),v=new Float32Array(16);for(let G=0;G<S;G++){let L=P?[P[G*3],P[G*3+1],P[G*3+2]]:[0,0,0],U=k?[k[G*4],k[G*4+1],k[G*4+2],k[G*4+3]]:[0,0,0,1],q=D?[D[G*3],D[G*3+1],D[G*3+2]]:[1,1,1];rt(_,U,L,q),Ee(v,p,_),h(d.mesh,v,`${E}_${G}`,d.extras)}continue}}h(d.mesh,p,E,d.extras)}}else{let b=we();for(let d=0;d<u.length;d++){let p=u[d].name||`Mesh_${d}`;h(d,b,p,u[d].extras)}}return e}function Fr(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function no(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function xe(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}function ro(t){let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${xe(t[r*3])}, ${xe(t[r*3+1])}, ${xe(t[r*3+2])})`;return n.join(", ")}function Rs(t,e){let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${xe(t[r*2])}, ${xe(1-t[r*2+1])})`;return n.join(", ")}function _s(t){return Array.from(t).join(", ")}function Ur(t){let e=new Map;for(let a of t){let u=Fr(a.materialName,"DefaultMaterial");e.has(u)||e.set(u,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,r=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let u=a.timeSamples.times[a.timeSamples.times.length-1];u>n&&(n=u)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
234
+ endTimeCode = ${xe(n)}
210
235
  timeCodesPerSecond = 1.0
211
236
  `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
212
237
  uniform token preliminary:planeAnchoring:alignment = "${r}"
213
- `);let a=`#usda 1.0
238
+ `);let s=`#usda 1.0
214
239
  (
215
240
  defaultPrim = "Root"
216
241
  metersPerUnit = 1.0
@@ -223,85 +248,87 @@ kind = "component"
223
248
  {
224
249
  ${o}def Scope "Materials"
225
250
  {
226
- `;for(let[c,s]of e.entries()){let[u,m,h]=s.color,[f,d,p]=s.emissiveColor,x="";s.clearcoat>0&&(x+=`float inputs:clearcoat = ${ne(s.clearcoat)}
227
- `,x+=`float inputs:clearcoatRoughness = ${ne(s.clearcoatRoughness)}
228
- `),s.ior!==1.5&&(x+=`float inputs:ior = ${ne(s.ior)}
229
- `),s.opacity<1&&(x+=`float inputs:opacity = ${ne(s.opacity)}
230
- `),(f>0||d>0||p>0)&&(x+=`color3f inputs:emissiveColor = (${ne(f)}, ${ne(d)}, ${ne(p)})
231
- `),a+=`def Material "${c}"
251
+ `;for(let[a,u]of e.entries()){let[l,m,f]=u.color,[h,b,d]=u.emissiveColor,p="";u.clearcoat>0&&(p+=`float inputs:clearcoat = ${xe(u.clearcoat)}
252
+ `,p+=`float inputs:clearcoatRoughness = ${xe(u.clearcoatRoughness)}
253
+ `),u.ior!==1.5&&(p+=`float inputs:ior = ${xe(u.ior)}
254
+ `),u.opacity<1&&(p+=`float inputs:opacity = ${xe(u.opacity)}
255
+ `),(h>0||b>0||d>0)&&(p+=`color3f inputs:emissiveColor = (${xe(h)}, ${xe(b)}, ${xe(d)})
256
+ `),s+=`def Material "${a}"
232
257
  {
233
258
  def Shader "PBRShader"
234
259
  {
235
260
  uniform token info:id = "UsdPreviewSurface"
236
- color3f inputs:diffuseColor = (${ne(u)}, ${ne(m)}, ${ne(h)})
237
- float inputs:metallic = ${ne(s.metallic)}
238
- float inputs:roughness = ${ne(s.roughness)}
239
- ${x}token outputs:surface
261
+ color3f inputs:diffuseColor = (${xe(l)}, ${xe(m)}, ${xe(f)})
262
+ float inputs:metallic = ${xe(u.metallic)}
263
+ float inputs:roughness = ${xe(u.roughness)}
264
+ ${p}token outputs:surface
240
265
  }
241
- token outputs:surface.connect = </Root/Materials/${c}/PBRShader.outputs:surface>
266
+ token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
242
267
  }
243
- `}a+=`}
268
+ `}s+=`}
244
269
  def Scope "Meshes"
245
270
  {
246
- `;let l=new Set;for(let c=0;c<t.length;c++){let s=t[c],u=s.positions.length/3,m=1/0,h=1/0,f=1/0,d=-1/0,p=-1/0,x=-1/0;for(let b=0;b<u;b++){let w=s.positions[b*3],R=s.positions[b*3+1],_=s.positions[b*3+2];w<m&&(m=w),w>d&&(d=w),R<h&&(h=R),R>p&&(p=R),_<f&&(f=_),_>x&&(x=_)}isFinite(m)||(m=h=f=-1,d=p=x=1);let P=Math.floor(s.indices.length/3),E=In(s.materialName,"DefaultMaterial"),y=In(s.name,`Mesh_${c}`);l.has(y)&&(y=`${y}_${c}`),l.add(y);let v=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",g=s.xrTraits,L="";if(g){let b=[];g.physics&&g.physics!=="none"&&b.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let w=ie().xrTraitSerializer?.usdLines(g,Tr)??[];if(!w.length)for(let R of["grab","billboard","follow","anchor","physics"]){let _=R==="follow"&&typeof g.follow=="object"?g.follow.mode??"head":g[R];_!==void 0&&w.push(`string ${R} = "${Tr(_)}"`)}w.length>0&&b.push(`customData = {
271
+ `;let c=new Set;for(let a=0;a<t.length;a++){let u=t[a],l=u.positions.length/3,m=1/0,f=1/0,h=1/0,b=-1/0,d=-1/0,p=-1/0;for(let k=0;k<l;k++){let D=u.positions[k*3],S=u.positions[k*3+1],_=u.positions[k*3+2];D<m&&(m=D),D>b&&(b=D),S<f&&(f=S),S>d&&(d=S),_<h&&(h=_),_>p&&(p=_)}isFinite(m)||(m=f=h=-1,b=d=p=1);let E=Math.floor(u.indices.length/3),A=Fr(u.materialName,"DefaultMaterial"),x=Fr(u.name,`Mesh_${a}`);c.has(x)&&(x=`${x}_${a}`),c.add(x);let R=E>0?E===1?"3":"3, ".repeat(E-1)+"3":"",I=u.xrTraits,P="";if(I){let k=[];I.physics&&I.physics!=="none"&&k.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let D=pe().xrTraitSerializer?.usdLines(I,no)??[];if(!D.length)for(let S of["grab","billboard","follow","anchor","physics"]){let _=S==="follow"&&typeof I.follow=="object"?I.follow.mode??"head":I[S];_!==void 0&&D.push(`string ${S} = "${no(_)}"`)}D.length>0&&k.push(`customData = {
247
272
  dictionary xr = {
248
- ${w.join(`
273
+ ${D.join(`
249
274
  `)}
250
275
  }
251
- }`),b.length>0&&(L=` (
252
- ${b.join(`
276
+ }`),k.length>0&&(P=` (
277
+ ${k.join(`
253
278
  `)}
254
- )`)}if(a+=`def Mesh "${y}"${L}
279
+ )`)}if(s+=`def Mesh "${x}"${P}
255
280
  {
256
- `,g?.physics&&g.physics!=="none"){let b=g.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
257
- bool physics:kinematicEnabled = ${b}
281
+ `,I?.physics&&I.physics!=="none"){let k=I.physics==="static"?"true":"false";s+=`bool physics:rigidBodyEnabled = true
282
+ bool physics:kinematicEnabled = ${k}
258
283
  bool physics:collisionEnabled = true
259
- `}if(s.timeSamples&&s.timeSamples.times.length>0){let b=s.timeSamples,w=b.times.map((B,z)=>{let I=b.translations?.[z]||[0,0,0];return`${ne(B)}: (${ne(I[0])}, ${ne(I[1])}, ${ne(I[2])})`}).join(", "),R=b.times.map((B,z)=>{let I=b.rotations?.[z]||[0,0,0,1];return`${ne(B)}: (${ne(I[3])}, ${ne(I[0])}, ${ne(I[1])}, ${ne(I[2])})`}).join(", "),_=b.times.map((B,z)=>{let I=b.scales?.[z]||[1,1,1];return`${ne(B)}: (${ne(I[0])}, ${ne(I[1])}, ${ne(I[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${w} }
260
- quatf xformOp:orient.timeSamples = { ${R} }
284
+ `}if(u.timeSamples&&u.timeSamples.times.length>0){let k=u.timeSamples,D=k.times.map((v,G)=>{let L=k.translations?.[G]||[0,0,0];return`${xe(v)}: (${xe(L[0])}, ${xe(L[1])}, ${xe(L[2])})`}).join(", "),S=k.times.map((v,G)=>{let L=k.rotations?.[G]||[0,0,0,1];return`${xe(v)}: (${xe(L[3])}, ${xe(L[0])}, ${xe(L[1])}, ${xe(L[2])})`}).join(", "),_=k.times.map((v,G)=>{let L=k.scales?.[G]||[1,1,1];return`${xe(v)}: (${xe(L[0])}, ${xe(L[1])}, ${xe(L[2])})`}).join(", ");s+=`double3 xformOp:translate.timeSamples = { ${D} }
285
+ quatf xformOp:orient.timeSamples = { ${S} }
261
286
  double3 xformOp:scale.timeSamples = { ${_} }
262
287
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
263
- `}a+=`float3[] extent = [(${ne(m)}, ${ne(h)}, ${ne(f)}), (${ne(d)}, ${ne(p)}, ${ne(x)})]
264
- int[] faceVertexCounts = [${v}]
265
- int[] faceVertexIndices = [${Di(s.indices)}]
266
- point3f[] points = [${Mr(s.positions)}]
267
- `,s.normals&&s.normals.length===s.positions.length&&(a+=`normal3f[] normals = [${Mr(s.normals)}] (
288
+ `}s+=`float3[] extent = [(${xe(m)}, ${xe(f)}, ${xe(h)}), (${xe(b)}, ${xe(d)}, ${xe(p)})]
289
+ int[] faceVertexCounts = [${R}]
290
+ int[] faceVertexIndices = [${_s(u.indices)}]
291
+ point3f[] points = [${ro(u.positions)}]
292
+ `,u.normals&&u.normals.length===u.positions.length&&(s+=`normal3f[] normals = [${ro(u.normals)}] (
268
293
  interpolation = "vertex"
269
294
  )
270
- `),s.uvs&&s.uvs.length===u*2&&(a+=`texCoord2f[] primvars:st = [${Li(s.uvs,u)}] (
295
+ `),u.uvs&&u.uvs.length===l*2&&(s+=`texCoord2f[] primvars:st = [${Rs(u.uvs,l)}] (
271
296
  interpolation = "vertex"
272
297
  )
273
- `),a+=`rel material:binding = </Root/Materials/${E}>
298
+ `),s+=`rel material:binding = </Root/Materials/${A}>
274
299
  }
275
- `}return a+=`}
300
+ `}return s+=`}
276
301
  }
277
- `,a}function _r(t,e){if(t&&typeof t.traverse=="function"){let i=Pi(t,e);return Fn(i)}let n=ke(t),r=Er(n);return Fn(r)}var Nt=null;function Cr(t){if(!Nt){Nt=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;Nt[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=Nt[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function kn(t){let e=[],n=0,r=[];for(let u of t){let m=Ut(u.filename),h=Cr(u.data),f=u.data.length,d=30+m.length,p=n+d,x=0,P=p%64;P!==0&&(x=64-P);let E=new Uint8Array(d+x),y=new DataView(E.buffer);y.setUint32(0,67324752,!0),y.setUint16(4,20,!0),y.setUint16(6,0,!0),y.setUint16(8,0,!0),y.setUint16(10,0,!0),y.setUint16(12,0,!0),y.setUint32(14,h,!0),y.setUint32(18,f,!0),y.setUint32(22,f,!0),y.setUint16(26,m.length,!0),y.setUint16(28,x,!0),E.set(m,30),x>0&&E.fill(0,30+m.length),e.push({offset:n,size:f,crc:h,filenameBytes:m,entry:u}),r.push(E),r.push(u.data),n+=E.length+u.data.length}let i=n;for(let u of e){let m=new Uint8Array(46+u.filenameBytes.length),h=new DataView(m.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint16(14,0,!0),h.setUint32(16,u.crc,!0),h.setUint32(20,u.size,!0),h.setUint32(24,u.size,!0),h.setUint16(28,u.filenameBytes.length,!0),h.setUint16(30,0,!0),h.setUint16(32,0,!0),h.setUint16(34,0,!0),h.setUint16(36,0,!0),h.setUint32(38,0,!0),h.setUint32(42,u.offset,!0),m.set(u.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,a=new Uint8Array(22),l=new DataView(a.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(a),n+=22;let c=new Uint8Array(n),s=0;for(let u of r)c.set(u,s),s+=u.length;return c}function Ke(t){let e=_r(t),n=Ut(e);return kn([{filename:"model.usda",data:n}])}function st(t){let e=ke(t),n=Er(e),r=Fn(n),i=Ut(r);return kn([{filename:"model.usda",data:i}])}function at(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ke(t):st(t)}function Ze(t){let e=at(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function Ot(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ii(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Fi(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Pr(t){let e=Fi(t);if(!e)return null;let n=e.target;return{target:Ii(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Ot(e.radius,.01,50,.5),speed:Ot(e.speed,-20,20,.5),height:Ot(e.height,-10,10,0),phase:Ot(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}var Bt=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}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}},le=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,a=n.x,l=n.y,c=n.z;return this.x=i*c-o*l,this.y=o*a-r*c,this.z=r*l-i*a,this}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)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,a=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*a,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*a,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*a,this}},Vt=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},mt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}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,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},ht=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}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,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,a=Math.cos(r/2),l=Math.cos(i/2),c=Math.cos(o/2),s=Math.sin(r/2),u=Math.sin(i/2),m=Math.sin(o/2);return this._x=s*l*c+a*u*m,this._y=a*u*c-s*l*m,this._z=a*l*m+s*u*c,this._w=a*l*c-s*u*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,a=e.w,l=n.x,c=n.y,s=n.z,u=n.w;return this._x=r*u+a*l+i*s-o*c,this._y=i*u+a*c+o*l-r*s,this._z=o*u+a*s+r*c-i*l,this._w=a*u-r*l-i*c-o*s,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},ze=class t{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 t;return e.copy(this),e}compose(e,n,r){return Ye(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return be(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return qe(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new le(0,0,0),r=new le(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},zt=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 de(this.elements,e.elements),this}},Re=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},Ur={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},re=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;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/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},Ht=class extends re{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Xt=class extends re{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Wt=class extends re{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},we=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof re)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new re(r,1)}else e&&e.buffer&&(this.index=new re(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new le,o=new le,a=new le,l=new le,c=new le;if(this.index){let s=this.index.array;for(let u=0;u<s.length;u+=3){let m=s[u],h=s[u+1],f=s[u+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(h),e.getY(h),e.getZ(h)),a.set(e.getX(f),e.getY(f),e.getZ(f)),l.subVectors(a,o),c.subVectors(i,o),l.cross(c).normalize();for(let d of[m,h,f])r[d*3]+=l.x,r[d*3+1]+=l.y,r[d*3+2]+=l.z}}else for(let s=0;s<n;s+=3){i.set(e.getX(s),e.getY(s),e.getZ(s)),o.set(e.getX(s+1),e.getY(s+1),e.getZ(s+1)),a.set(e.getX(s+2),e.getY(s+2),e.getZ(s+2)),l.subVectors(a,o),c.subVectors(i,o),l.cross(c).normalize();for(let u=0;u<3;u++)r[(s+u)*3]=l.x,r[(s+u)*3+1]=l.y,r[(s+u)*3+2]=l.z}for(let s=0;s<n;s++){let u=r[s*3],m=r[s*3+1],h=r[s*3+2],f=Math.hypot(u,m,h)||1;r[s*3]=u/f,r[s*3+1]=m/f,r[s*3+2]=h/f}return this.setAttribute("normal",new re(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new re(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new re(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new re(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}dispose(){}},dt=class extends we{constructor(e=1,n=1,r=1){super();let i=e/2,o=n/2,a=r/2,l=[-i,-o,a,i,-o,a,i,o,a,-i,o,a,i,-o,-a,-i,-o,-a,-i,o,-a,i,o,-a,-i,o,a,i,o,a,i,o,-a,-i,o,-a,-i,-o,-a,i,-o,-a,i,-o,a,-i,-o,a,i,-o,a,i,-o,-a,i,o,-a,i,o,a,-i,-o,-a,-i,-o,a,-i,o,a,-i,o,-a],c=[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],s=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],u=[];for(let m=0;m<6;m++){let h=m*4;u.push(h,h+1,h+2,h,h+2,h+3)}this.setAttribute("position",new re(new Float32Array(l),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},Gt=class extends we{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],a=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],c=[0,2,1,2,3,1];this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},ft=class extends we{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));let i=[],o=[],a=[],l=[],c=[];for(let s=0;s<=r;s++){let u=[],m=s/r;for(let h=0;h<=n;h++){let f=h/n,d=f*Math.PI*2,p=m*Math.PI,x=-e*Math.cos(d)*Math.sin(p),P=e*Math.cos(p),E=e*Math.sin(d)*Math.sin(p);i.push(x,P,E);let y=Math.hypot(x,P,E)||1;o.push(x/y,P/y,E/y),a.push(f,1-m),u.push(i.length/3-1)}c.push(u)}for(let s=0;s<r;s++)for(let u=0;u<n;u++){let m=c[s][u+1],h=c[s][u],f=c[s+1][u],d=c[s+1][u+1];s!==0&&l.push(m,h,d),s!==r-1&&l.push(h,f,d)}this.setAttribute("position",new re(new Float32Array(i),3)),this.setAttribute("normal",new re(new Float32Array(o),3)),this.setAttribute("uv",new re(new Float32Array(a),2)),this.setIndex(l)}},Oe=class extends we{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],a=[],l=[],c=[],s=r/2;for(let u=0;u<=1;u++){let m=u,h=u===0?e:n,f=u===0?s:-s;for(let d=0;d<=i;d++){let p=d/i,x=p*Math.PI*2,P=Math.sin(x),E=Math.cos(x);o.push(h*P,f,h*E),a.push(P,0,E),l.push(p,1-m)}}for(let u=0;u<i;u++){let m=u,h=u+i+1,f=u+i+2,d=u+1;c.push(m,h,d,h,f,d)}if(e>0){let u=o.length/3;o.push(0,s,0),a.push(0,1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=i;h++){let f=h/i*Math.PI*2,d=Math.sin(f),p=Math.cos(f);o.push(e*d,s,e*p),a.push(0,1,0),l.push(p*.5+.5,d*.5+.5)}for(let h=0;h<i;h++)c.push(u,m+h,m+h+1)}if(n>0){let u=o.length/3;o.push(0,-s,0),a.push(0,-1,0),l.push(.5,.5);let m=o.length/3;for(let h=0;h<=i;h++){let f=h/i*Math.PI*2,d=Math.sin(f),p=Math.cos(f);o.push(n*d,-s,n*p),a.push(0,-1,0),l.push(p*.5+.5,1-(d*.5+.5))}for(let h=0;h<i;h++)c.push(u,m+h+1,m+h)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},$t=class extends Oe{constructor(e=1,n=1,r=16){super(0,e,n,r)}},qt=class extends we{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],a=[],l=[],c=[];for(let s=0;s<=r;s++){let u=s/r*Math.PI*2;for(let m=0;m<=i;m++){let h=m/i*Math.PI*2,f=(e+n*Math.cos(u))*Math.cos(h),d=(e+n*Math.cos(u))*Math.sin(h),p=n*Math.sin(u);o.push(f,d,p);let x=e*Math.cos(h),P=e*Math.sin(h),E=f-x,y=d-P,v=p,g=Math.hypot(E,y,v)||1;a.push(E/g,y/g,v/g),l.push(m/i,s/r)}}for(let s=1;s<=r;s++)for(let u=1;u<=i;u++){let m=(i+1)*s+u-1,h=(i+1)*(s-1)+u-1,f=(i+1)*(s-1)+u,d=(i+1)*s+u;c.push(m,h,d,h,f,d)}this.setAttribute("position",new re(new Float32Array(o),3)),this.setAttribute("normal",new re(new Float32Array(a),3)),this.setAttribute("uv",new re(new Float32Array(l),2)),this.setIndex(c)}},Yt=class extends we{constructor(e=1,n=.4,r=64,i=8,o=2,a=3){super(),r=Math.floor(r),i=Math.floor(i);let l=[],c=[],s=[],u=[],m=new le,h=new le,f=new le,d=new le,p=new le;function x(y,v){let g=Math.cos(v),L=Math.sin(v),b=a/o*v,w=e*(2+Math.cos(b))*.5;y.set(w*g,w*L,e*Math.sin(b)*.5)}let P=[];for(let y=0;y<=i;++y){let v=y/i*Math.PI*2;P.push(-n*Math.cos(v),n*Math.sin(v),y/i)}for(let y=0;y<=r;++y){let v=y/r,g=v*o*Math.PI*2;x(m,g),x(h,g+.01),f.subVectors(h,m).normalize(),d.addVectors(m,h).normalize(),p.crossVectors(f,d).normalize(),d.crossVectors(p,f).normalize();for(let L=0;L<=i;++L){let b=L*3,w=P[b],R=P[b+1],_=P[b+2],B=w*d.x+R*p.x,z=w*d.y+R*p.y,I=w*d.z+R*p.z;l.push(m.x+B,m.y+z,m.z+I);let C=Math.hypot(B,z,I)||1;c.push(B/C,z/C,I/C),s.push(v,_)}}let E=i+1;for(let y=1;y<=r;y++){let v=E*(y-1),g=v+E;for(let L=1;L<=i;L++){let b=v+(L-1),w=g+(L-1),R=g+L,_=v+L;u.push(b,w,_,w,R,_)}}this.setAttribute("position",new re(new Float32Array(l),3)),this.setAttribute("normal",new re(new Float32Array(c),3)),this.setAttribute("uv",new re(new Float32Array(s),2)),this.setIndex(u)}},pt=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},jt=class{load(e,n){let r=new pt(e);return n?.(r),r}};function ye(t,e){return t!==void 0?Number(t):e}function Nn(t,e){return t!==void 0?!!t:e}var Ce=class{constructor(e={}){this.name=e.name||"",this.color=new Re(e.color!==void 0?e.color:16777215),this.emissive=new Re(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=ye(e.emissiveIntensity,1),this.roughness=ye(e.roughness,.5),this.metalness=ye(e.metalness,.1),this.opacity=ye(e.opacity,1),this.transparent=Nn(e.transparent,!1),this.wireframe=Nn(e.wireframe,!1),this.side=ye(e.side,2),this.doubleSided=Nn(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 Re(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 Re(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(){}},He=class extends Ce{},Kt=class extends Ce{},Zt=class extends Ce{},Jt=class extends Ce{},Qt=class extends Ce{},Te=class t{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 le,this.rotation=new mt,this.quaternion=new ht,this.scale=new le(1,1,1),this.matrix=new ze,this.matrixWorld=new ze,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=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)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new le(e,n,r);this.updateMatrixWorld(!0);let o=new ze;o.lookAt(this.position,i,new le(0,1,0));let a=o.elements,l=a[0],c=a[4],s=a[8],u=a[1],m=a[5],h=a[9],f=a[2],d=a[6],p=a[10],x=l+m+p;if(x>0){let P=.5/Math.sqrt(x+1);this.quaternion.set((d-h)*P,(s-f)*P,(u-c)*P,.25/P)}}},en=class extends Te{},Je=class extends Te{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof we?n:n?(Ae("unsupported geometry","BoxGeometry"),new dt(.5,.5,.5)):new we,this.material=i instanceof Ce?i:i?(Ae("unsupported material","MeshStandardMaterial"),new He({color:13421772})):new He}},Xe=class extends Te{constructor(e=16777215,n=1){super(),this.color=new Re(e),this.intensity=Number(n),this.type="directional"}},bt=class extends Xe{constructor(e,n){super(e,n),this.type="ambient"}},tn=class extends Xe{constructor(n,r){super(n,r);this.target=new Te;this.type="directional"}},yt=class extends Xe{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},gt=class extends Te{},nn=class extends gt{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new le(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},xt=class extends Te{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return _e.validate(this),je(this)}toGLB(){return _e.validate(this),ot(this)}toUSDZ(){return _e.validate(this),Ke(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Je){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},Un=je,On=ot,Or=Ke;var _e=class{static validate(e){let n=0,r=0,i=0,o=new Set,a=(c,s,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${c} (${s}). Found: ${u}`)},l=(c,s)=>{if(!Number.isFinite(s))throw new Error(`SecurityError: Scene reports a non-finite ${c} count (${String(s)}), which cannot be bounds-checked.`);return s};e.traverse(c=>{if(c instanceof Je){i++,i>1e3&&a("MESHES",1e3,i);let s=c.geometry;if(s){let u=0;if(s.attributes.position&&(u=l("vertex",s.attributes.position.count),n+=u,n>1e5&&a("VERTICES",1e5,n)),s.index){let m=l("index",s.index.count);r+=m,r>3e5&&a("INDICES",3e5,r);let h=s.index.array;if(h&&u>0){let f=Math.min(m,h.length);for(let d=0;d<f;d++){let p=h[d];if(!Number.isFinite(p)||p<0||p>=u)throw new Error(`SecurityError: Index buffer value (${String(p)}) out of vertex bounds [0, ${u}).`)}}}}if(c.material){let u=c.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&a("TEXTURES",16,o.size);for(let c of o){let s=c,u=s.image,m=Number(u?.width??s.width??0)||0,h=Number(u?.height??s.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(h)||m>2048||h>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(m,h))}}},rn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";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 n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new Re(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){_e.validate(e);let i=(o,a)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(a&&a.length?self.postMessage(o,a):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),a={};for(let[l,c]of o.entries())a[l]=Array.from(c);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let o=Un(e),a=On(e),l=(o.lights||[]).map(c=>({type:c.type,color:c.color,intensity:c.intensity,position:c.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[a.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Lr(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var on=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=Lr(),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 n=Lr();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function ki(){}var ut=new Proxy(ki,{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:ut},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>ut,construct:()=>ut}),Dr=(()=>{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 et(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Be(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,et());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 Ir,ct;function Br(t){if(!Be(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(ct===void 0||Ir!==n){Ir=n;try{ct=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Be(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{ct=null}}return ct?ct.createScriptURL(t):t}function Ni(t){ie().sandboxEngineSrc=t}function Bn(){let t=ie().sandboxEngineSrc;if(t)return t;if(Dr)return Dr;try{if(typeof document>"u")return null;let e=et(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&Be(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ui(){let t=Bn();if(!t)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.");if(!Be(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,et()).href}function Oi(t){ie().sandboxIframeSrc=t}function Vr(){let t=ie().sandboxIframeSrc;if(t)return t;let e=Bn();if(!e||!Be(e))return null;let n=new URL(e,et());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Bi(){let t=Vr();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!Be(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,et()).href}function Vi(t){ie().allowClientScripts=t}function zr(){return!!ie().allowClientScripts}function zi(t){if(!Be(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,et()).href}var Hi=["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 Xi(t){let e=self,n=t.nonce,r=t.engineSrc,i=t.allowedScriptUrl,o=t.allowClientScripts,a=t.revoked,l=e.postMessage.bind(e);function c(g){l({type:"ERROR",nonce:n,message:String(g)})}let s=typeof e.importScripts=="function"?e.importScripts.bind(e):null,u=i,m=null;try{let g=r;if(typeof e.trustedTypes<"u"&&e.trustedTypes&&typeof e.trustedTypes.createPolicy=="function")try{let L={createScriptURL:function(w){if(w!==r&&(!i||w!==i))throw new TypeError("Disallowed worker importScripts URL");return w}};o&&(L.createScript=function(w){return String(w)});let b=e.trustedTypes.createPolicy("three-live#worker-boot",L);g=b.createScriptURL(r),i&&(u=b.createScriptURL(i)),o&&typeof b.createScript=="function"&&(m=b.createScript.bind(b))}catch{}s(g)}catch(g){c('Sandbox failed to load the Three-Live engine from "'+r+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(g&&g.message||g));return}let h=e.THREE;if(!h||typeof h.Scene!="function"){c('Sandbox loaded "'+r+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}for(let g=0;g<a.length;g++){let L=a[g],b=e;for(;b&&b!==Object.prototype;){if(b!==e)try{delete b[L]}catch{}try{Object.defineProperty(b,L,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{b=Object.getPrototypeOf(b)}catch{break}}}let f=Object.freeze({now:function(){return Date.now()}}),d=e;for(;d&&d!==Object.prototype;){if(d!==e)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:f,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function P(g,L){if(g.type==="3D_MODEL_READY"){if(x)return;x=!0}g.nonce=n,L&&L.length?l(g,L):l(g)}let E=function(g,L){if(!g||p.indexOf(g.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");P(g,L)},y=e;for(;y&&y!==Object.prototype;){if(y===e||Object.prototype.hasOwnProperty.call(y,"postMessage"))try{Object.defineProperty(y,"postMessage",{value:E,writable:!1,configurable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let v=!1;e.onmessage=function(g){let L=g&&g.data;if(!(!L||L.nonce!==n)&&!(L.type!=="EXECUTE"&&L.type!=="EXECUTE_URL")&&!v){v=!0;try{let b=new h.Scene,w=new h.PerspectiveCamera(60,1,.1,1e3),R=new h.WebGLRenderer({isSandboxed:!0});if(L.type==="EXECUTE_URL"){if(!i||L.scriptUrl!==i||typeof s!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let _=u||i,B=s;if(s=null,u=null,e.THREE=h,e.scene=b,e.camera=w,e.renderer=R,B(_),typeof e.__THREE_LIVE_SCENE__=="function"){let z=e.__THREE_LIVE_SCENE__(h,b,w,R);z&&typeof z.toGLB=="function"&&(b=z)}else e.scene&&typeof e.scene.toGLB=="function"&&(b=e.scene)}else{if(!o){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let _=m?(0,eval)(m(`(function (THREE, scene, camera, renderer) {
302
+ `,s}function oo(t,e){if(t&&typeof t.traverse=="function"){let i=Es(t,e);return Ur(i)}let n=ot(t),r=io(n);return Ur(r)}var Sn=null;function so(t){if(!Sn){Sn=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;Sn[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=Sn[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function Or(t){let e=[],n=0,r=[];for(let l of t){let m=En(l.filename),f=so(l.data),h=l.data.length,b=30+m.length,d=n+b,p=0,E=d%64;E!==0&&(p=64-E);let A=new Uint8Array(b+p),x=new DataView(A.buffer);x.setUint32(0,67324752,!0),x.setUint16(4,20,!0),x.setUint16(6,0,!0),x.setUint16(8,0,!0),x.setUint16(10,0,!0),x.setUint16(12,0,!0),x.setUint32(14,f,!0),x.setUint32(18,h,!0),x.setUint32(22,h,!0),x.setUint16(26,m.length,!0),x.setUint16(28,p,!0),A.set(m,30),p>0&&A.fill(0,30+m.length),e.push({offset:n,size:h,crc:f,filenameBytes:m,entry:l}),r.push(A),r.push(l.data),n+=A.length+l.data.length}let i=n;for(let l of e){let m=new Uint8Array(46+l.filenameBytes.length),f=new DataView(m.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint16(14,0,!0),f.setUint32(16,l.crc,!0),f.setUint32(20,l.size,!0),f.setUint32(24,l.size,!0),f.setUint16(28,l.filenameBytes.length,!0),f.setUint16(30,0,!0),f.setUint16(32,0,!0),f.setUint16(34,0,!0),f.setUint16(36,0,!0),f.setUint32(38,0,!0),f.setUint32(42,l.offset,!0),m.set(l.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,s=new Uint8Array(22),c=new DataView(s.buffer);c.setUint32(0,101010256,!0),c.setUint16(4,0,!0),c.setUint16(6,0,!0),c.setUint16(8,e.length,!0),c.setUint16(10,e.length,!0),c.setUint32(12,o,!0),c.setUint32(16,i,!0),c.setUint16(20,0,!0),r.push(s),n+=22;let a=new Uint8Array(n),u=0;for(let l of r)a.set(l,u),u+=l.length;return a}function Ot(t){let e=oo(t),n=En(e);return Or([{filename:"model.usda",data:n}])}function $t(t){let e=ot(t),n=io(e),r=Ur(n),i=En(r);return Or([{filename:"model.usda",data:i}])}function qt(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ot(t):$t(t)}function Vt(t){let e=qt(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function st(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Cs(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Vr(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Is(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function ao(t){let e=Vr(t);if(!e)return null;let n=e.target;return{target:Cs(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:st(e.radius,.01,50,.5),speed:st(e.speed,-20,20,.5),height:st(e.height,-10,10,0),phase:st(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Rn(t,e){let n=Is(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}function Br(t){if(t===!1||t===null||t===void 0)return null;if(typeof t=="number")return!Number.isFinite(t)||t<=0?null:{enabled:!0,strength:st(t,0,5,.35),threshold:.8,radius:.5};if(t===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let e=Vr(t);if(!e||e.enabled===!1)return null;let n=st(e.strength??e.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:st(e.threshold,0,4,.8),radius:st(e.radius,0,2,.5)}}function _n(t){if(!t)return null;if(typeof t=="string")return{enabled:!0,color:Rn(t,"#38bdf8"),thickness:3,pulse:!1};if(t===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let e=Vr(t);return!e||e.enabled===!1?null:{enabled:!0,color:Rn(e.color,"#38bdf8"),thickness:st(e.thickness??e.width,.5,20,3),pulse:e.pulse===!0}}var In=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}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}},Ce=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,s=n.x,c=n.y,a=n.z;return this.x=i*a-o*c,this.y=o*s-r*a,this.z=r*c-i*s,this}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)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,s=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*s,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*s,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*s,this}},Ln=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},Zt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}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,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Qt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}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,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,s=Math.cos(r/2),c=Math.cos(i/2),a=Math.cos(o/2),u=Math.sin(r/2),l=Math.sin(i/2),m=Math.sin(o/2);return this._x=u*c*a+s*l*m,this._y=s*l*a-u*c*m,this._z=s*c*m+u*l*a,this._w=s*c*a-u*l*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,s=e.w,c=n.x,a=n.y,u=n.z,l=n.w;return this._x=r*l+s*c+i*u-o*a,this._y=i*l+s*a+o*c-r*u,this._z=o*l+s*u+r*a-i*c,this._w=s*l-r*c-i*a-o*u,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},vt=class t{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 t;return e.copy(this),e}compose(e,n,r){return rt(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return Ee(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return Nt(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new Ce(0,0,0),r=new Ce(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},Pn=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 Le(this.elements,e.elements),this}},$e=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},po={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},Me=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;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/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},Dn=class extends Me{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},kn=class extends Me{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Nn=class extends Me{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Xe=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof Me)this.index=e;else if(Array.isArray(e)){let n=0;for(let i=0;i<e.length;i++)e[i]>n&&(n=e[i]);let r=n>65535?new Uint32Array(e):new Uint16Array(e);this.index=new Me(r,1)}else e&&e.buffer&&(this.index=new Me(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new Ce,o=new Ce,s=new Ce,c=new Ce,a=new Ce;if(this.index){let u=this.index.array;for(let l=0;l<u.length;l+=3){let m=u[l],f=u[l+1],h=u[l+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(f),e.getY(f),e.getZ(f)),s.set(e.getX(h),e.getY(h),e.getZ(h)),c.subVectors(s,o),a.subVectors(i,o),c.cross(a).normalize();for(let b of[m,f,h])r[b*3]+=c.x,r[b*3+1]+=c.y,r[b*3+2]+=c.z}}else for(let u=0;u<n;u+=3){i.set(e.getX(u),e.getY(u),e.getZ(u)),o.set(e.getX(u+1),e.getY(u+1),e.getZ(u+1)),s.set(e.getX(u+2),e.getY(u+2),e.getZ(u+2)),c.subVectors(s,o),a.subVectors(i,o),c.cross(a).normalize();for(let l=0;l<3;l++)r[(u+l)*3]=c.x,r[(u+l)*3+1]=c.y,r[(u+l)*3+2]=c.z}for(let u=0;u<n;u++){let l=r[u*3],m=r[u*3+1],f=r[u*3+2],h=Math.hypot(l,m,f)||1;r[u*3]=l/h,r[u*3+1]=m/h,r[u*3+2]=f/h}return this.setAttribute("normal",new Me(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new Me(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new Me(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new Me(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new Ce(1/0,1/0,1/0),r=new Ce(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),s=e.getY(i),c=e.getZ(i);o<n.x&&(n.x=o),s<n.y&&(n.y=s),c<n.z&&(n.z=c),o>r.x&&(r.x=o),s>r.y&&(r.y=s),c>r.z&&(r.z=c)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),n=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let s=0;s<o.count;s++)o.setXYZ(s,o.getX(s)-n,o.getY(s)-r,o.getZ(s)-i);this.computeBoundingBox()}return this}dispose(){}},Jt=class extends Xe{constructor(e=1,n=1,r=1){super();let i=e/2,o=n/2,s=r/2,c=[-i,-o,s,i,-o,s,i,o,s,-i,o,s,i,-o,-s,-i,-o,-s,-i,o,-s,i,o,-s,-i,o,s,i,o,s,i,o,-s,-i,o,-s,-i,-o,-s,i,-o,-s,i,-o,s,-i,-o,s,i,-o,s,i,-o,-s,i,o,-s,i,o,s,-i,-o,-s,-i,-o,s,-i,o,s,-i,o,-s],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],u=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],l=[];for(let m=0;m<6;m++){let f=m*4;l.push(f,f+1,f+2,f,f+2,f+3)}this.setAttribute("position",new Me(new Float32Array(c),3)),this.setAttribute("normal",new Me(new Float32Array(a),3)),this.setAttribute("uv",new Me(new Float32Array(u),2)),this.setIndex(l)}},Fn=class extends Xe{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],s=[0,0,1,0,0,1,0,0,1,0,0,1],c=[0,1,1,1,0,0,1,0],a=[0,2,1,2,3,1];this.setAttribute("position",new Me(new Float32Array(o),3)),this.setAttribute("normal",new Me(new Float32Array(s),3)),this.setAttribute("uv",new Me(new Float32Array(c),2)),this.setIndex(a)}},en=class extends Xe{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));let i=[],o=[],s=[],c=[],a=[];for(let u=0;u<=r;u++){let l=[],m=u/r;for(let f=0;f<=n;f++){let h=f/n,b=h*Math.PI*2,d=m*Math.PI,p=-e*Math.cos(b)*Math.sin(d),E=e*Math.cos(d),A=e*Math.sin(b)*Math.sin(d);i.push(p,E,A);let x=Math.hypot(p,E,A)||1;o.push(p/x,E/x,A/x),s.push(h,1-m),l.push(i.length/3-1)}a.push(l)}for(let u=0;u<r;u++)for(let l=0;l<n;l++){let m=a[u][l+1],f=a[u][l],h=a[u+1][l],b=a[u+1][l+1];u!==0&&c.push(m,f,b),u!==r-1&&c.push(f,h,b)}this.setAttribute("position",new Me(new Float32Array(i),3)),this.setAttribute("normal",new Me(new Float32Array(o),3)),this.setAttribute("uv",new Me(new Float32Array(s),2)),this.setIndex(c)}},yt=class extends Xe{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],s=[],c=[],a=[],u=r/2;for(let l=0;l<=1;l++){let m=l,f=l===0?e:n,h=l===0?u:-u;for(let b=0;b<=i;b++){let d=b/i,p=d*Math.PI*2,E=Math.sin(p),A=Math.cos(p);o.push(f*E,h,f*A),s.push(E,0,A),c.push(d,1-m)}}for(let l=0;l<i;l++){let m=l,f=l+i+1,h=l+i+2,b=l+1;a.push(m,f,b,f,h,b)}if(e>0){let l=o.length/3;o.push(0,u,0),s.push(0,1,0),c.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let h=f/i*Math.PI*2,b=Math.sin(h),d=Math.cos(h);o.push(e*b,u,e*d),s.push(0,1,0),c.push(d*.5+.5,b*.5+.5)}for(let f=0;f<i;f++)a.push(l,m+f,m+f+1)}if(n>0){let l=o.length/3;o.push(0,-u,0),s.push(0,-1,0),c.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let h=f/i*Math.PI*2,b=Math.sin(h),d=Math.cos(h);o.push(n*b,-u,n*d),s.push(0,-1,0),c.push(d*.5+.5,1-(b*.5+.5))}for(let f=0;f<i;f++)a.push(l,m+f+1,m+f)}this.setAttribute("position",new Me(new Float32Array(o),3)),this.setAttribute("normal",new Me(new Float32Array(s),3)),this.setAttribute("uv",new Me(new Float32Array(c),2)),this.setIndex(a)}},Un=class extends yt{constructor(e=1,n=1,r=16){super(0,e,n,r)}},On=class extends Xe{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],s=[],c=[],a=[];for(let u=0;u<=r;u++){let l=u/r*Math.PI*2;for(let m=0;m<=i;m++){let f=m/i*Math.PI*2,h=(e+n*Math.cos(l))*Math.cos(f),b=(e+n*Math.cos(l))*Math.sin(f),d=n*Math.sin(l);o.push(h,b,d);let p=e*Math.cos(f),E=e*Math.sin(f),A=h-p,x=b-E,R=d,I=Math.hypot(A,x,R)||1;s.push(A/I,x/I,R/I),c.push(m/i,u/r)}}for(let u=1;u<=r;u++)for(let l=1;l<=i;l++){let m=(i+1)*u+l-1,f=(i+1)*(u-1)+l-1,h=(i+1)*(u-1)+l,b=(i+1)*u+l;a.push(m,f,b,f,h,b)}this.setAttribute("position",new Me(new Float32Array(o),3)),this.setAttribute("normal",new Me(new Float32Array(s),3)),this.setAttribute("uv",new Me(new Float32Array(c),2)),this.setIndex(a)}},Vn=class extends Xe{constructor(e=1,n=.4,r=64,i=8,o=2,s=3){super(),r=Math.floor(r),i=Math.floor(i);let c=[],a=[],u=[],l=[],m=new Ce,f=new Ce,h=new Ce,b=new Ce,d=new Ce;function p(x,R){let I=Math.cos(R),P=Math.sin(R),k=s/o*R,D=e*(2+Math.cos(k))*.5;x.set(D*I,D*P,e*Math.sin(k)*.5)}let E=[];for(let x=0;x<=i;++x){let R=x/i*Math.PI*2;E.push(-n*Math.cos(R),n*Math.sin(R),x/i)}for(let x=0;x<=r;++x){let R=x/r,I=R*o*Math.PI*2;p(m,I),p(f,I+.01),h.subVectors(f,m).normalize(),b.addVectors(m,f).normalize(),d.crossVectors(h,b).normalize(),b.crossVectors(d,h).normalize();for(let P=0;P<=i;++P){let k=P*3,D=E[k],S=E[k+1],_=E[k+2],v=D*b.x+S*d.x,G=D*b.y+S*d.y,L=D*b.z+S*d.z;c.push(m.x+v,m.y+G,m.z+L);let U=Math.hypot(v,G,L)||1;a.push(v/U,G/U,L/U),u.push(R,_)}}let A=i+1;for(let x=1;x<=r;x++){let R=A*(x-1),I=R+A;for(let P=1;P<=i;P++){let k=R+(P-1),D=I+(P-1),S=I+P,_=R+P;l.push(k,D,_,D,S,_)}}this.setAttribute("position",new Me(new Float32Array(c),3)),this.setAttribute("normal",new Me(new Float32Array(a),3)),this.setAttribute("uv",new Me(new Float32Array(u),2)),this.setIndex(l)}},tn=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Bn=class{load(e,n){let r=new tn(e);return n?.(r),r}};function Oe(t,e){return t!==void 0?Number(t):e}function zr(t,e){return t!==void 0?!!t:e}var Qe=class{constructor(e={}){this.name=e.name||"",this.color=new $e(e.color!==void 0?e.color:16777215),this.emissive=new $e(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Oe(e.emissiveIntensity,1),this.roughness=Oe(e.roughness,.5),this.metalness=Oe(e.metalness,.1),this.opacity=Oe(e.opacity,1),this.transparent=zr(e.transparent,!1),this.wireframe=zr(e.wireframe,!1),this.side=Oe(e.side,2),this.doubleSided=zr(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Oe(e.clearcoat,0),this.clearcoatRoughness=Oe(e.clearcoatRoughness,0),this.sheen=Oe(e.sheen,0),this.sheenColor=new $e(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Oe(e.sheenRoughness,0),this.transmission=Oe(e.transmission,0),this.thickness=Oe(e.thickness,0),this.attenuationColor=new $e(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Oe(e.attenuationDistance,1/0),this.ior=Oe(e.ior,1.5),this.dispersion=Oe(e.dispersion,0),this.iridescence=Oe(e.iridescence,0),this.iridescenceIOR=Oe(e.iridescenceIOR,1.3)}dispose(){}},Tt=class extends Qe{},zn=class extends Qe{},Gn=class extends Qe{},Xn=class extends Qe{},Hn=class extends Qe{},qe=class t{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 Ce,this.rotation=new Zt,this.quaternion=new Qt,this.scale=new Ce(1,1,1),this.matrix=new vt,this.matrixWorld=new vt,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=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)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){bo(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new Ce(e,n,r);this.updateMatrixWorld(!0);let o=new vt;o.lookAt(this.position,i,new Ce(0,1,0));let s=o.elements,c=s[0],a=s[4],u=s[8],l=s[1],m=s[5],f=s[9],h=s[2],b=s[6],d=s[10],p=c+m+d;if(p>0){let E=.5/Math.sqrt(p+1);this.quaternion.set((b-f)*E,(u-h)*E,(l-a)*E,.25/E)}}},Wn=class extends qe{},wt=class extends qe{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Xe?n:n?(He("unsupported geometry","BoxGeometry"),new Jt(.5,.5,.5)):new Xe,this.material=i instanceof Qe?i:i?(He("unsupported material","MeshStandardMaterial"),new Tt({color:13421772})):new Tt}};function bo(t){let e=pe().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var nn=1e4,rn=class extends wt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>nn)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${nn})`);this.count=Math.floor(o);let s=new Float32Array(this.count*16);for(let c=0;c<this.count;c++){let a=c*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new Me(s,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let c=0;c<16;c++){let a=Number(r.elements[c]);o[s+c]=Number.isFinite(a)?a:c%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let c=0;c<16;c++)r.elements[c]=o[s+c]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let c=new Float32Array(this.count*3);c.fill(1),this.instanceColor=new Me(c,3)}let o=this.instanceColor.array,s=i*3;o[s]=Number.isFinite(r.r)?r.r:1,o[s+1]=Number.isFinite(r.g)?r.g:1,o[s+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,s=i*3;r.setRGB(o[s],o[s+1],o[s+2])}dispose(){}},Mt=class extends qe{constructor(e=16777215,n=1){super(),this.color=new $e(e),this.intensity=Number(n),this.type="directional"}},on=class extends Mt{constructor(e,n){super(e,n),this.type="ambient"}},$n=class extends Mt{constructor(n,r){super(n,r);this.target=new qe;this.type="directional"}},sn=class extends Mt{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},an=class extends qe{},qn=class extends an{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Ce(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},cn=class extends qe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return Ze.validate(this),Ut(this)}toGLB(){return Ze.validate(this),Wt(this)}toUSDZ(){return Ze.validate(this),Ot(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof wt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},Gr=Ut,Xr=Wt,yo=Ot;var Ze=class{static validate(e){let n=0,r=0,i=0,o=new Set,s=(a,u,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${u}). Found: ${l}`)},c=(a,u)=>{if(!Number.isFinite(u))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(u)}), which cannot be bounds-checked.`);return u};e.traverse(a=>{if(bo(a),a instanceof wt||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),a instanceof rn){let l=c("instance",a.count);(l<0||l>nn)&&s("INSTANCES",nn,l)}let u=a.geometry;if(u){let l=0;if(u.attributes.position&&(l=c("vertex",u.attributes.position.count),n+=l,n>1e5&&s("VERTICES",1e5,n)),u.index){let m=c("index",u.index.count);r+=m,r>3e5&&s("INDICES",3e5,r);let f=u.index.array;if(f&&l>0){let h=Math.min(m,f.length);for(let b=0;b<h;b++){let d=f[b];if(!Number.isFinite(d)||d<0||d>=l)throw new Error(`SecurityError: Index buffer value (${String(d)}) out of vertex bounds [0, ${l}).`)}}}}if(a.material){let l=a.material;l.map&&o.add(l.map),l.normalMap&&o.add(l.normalMap),l.roughnessMap&&o.add(l.roughnessMap)}}}),o.size>16&&s("TEXTURES",16,o.size);for(let a of o){let u=a,l=u.image,m=Number(l?.width??u.width??0)||0,f=Number(l?.height??u.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(f)||m>2048||f>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(m,f))}}},Yn=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";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 n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new $e(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){Ze.validate(e);let i=(o,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(o,s):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),s={};for(let[c,a]of o.entries())s[c]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let o=Gr(e),s=Xr(e),c=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:c,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function co(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var jn=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=co(),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 n=co();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Ls(){}var jt=new Proxy(Ls,{get:(t,e)=>{if(e==="isProxy")return!0;if(!(e==="constructor"||e==="__proto__"||e==="prototype"))return e==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:e==="shadowMap"?{enabled:!1,type:0}:e==="capabilities"?{isWebGL2:!0,maxTextures:16}:e===Symbol.toPrimitive?()=>0:jt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>jt,construct:()=>jt}),uo=(()=>{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 zt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function gt(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,zt());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 lo,Yt;function go(t){if(!gt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Yt===void 0||lo!==n){lo=n;try{Yt=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!gt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Yt=null}}return Yt?Yt.createScriptURL(t):t}function Ps(t){pe().sandboxEngineSrc=t}function Hr(){let t=pe().sandboxEngineSrc;if(t)return t;if(uo)return uo;try{if(typeof document>"u")return null;let e=zt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&gt(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ds(){let t=Hr();if(!t)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.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}function ks(t){pe().sandboxIframeSrc=t}function xo(){let t=pe().sandboxIframeSrc;if(t)return t;let e=Hr();if(!e||!gt(e))return null;let n=new URL(e,zt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Ns(){let t=xo();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}function Fs(t){pe().allowClientScripts=t}function vo(){return!!pe().allowClientScripts}function Us(t){if(!gt(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,zt()).href}var Os=["fetch","XMLHttpRequest","WebSocket","WebSocketStream","WebTransport","EventSource","importScripts","Request","Response","Headers","navigator","WorkerNavigator","WorkerLocation","RTCPeerConnection","RTCDataChannel","FontFace","FontFaceSet","fonts","PerformanceObserver","ReportingObserver","indexedDB","IDBFactory","caches","CacheStorage","Cache","cookieStore","StorageManager","FileSystemHandle","Worker","SharedWorker","ServiceWorker","ServiceWorkerContainer","ServiceWorkerRegistration","registration","clients","BroadcastChannel","MessageChannel","MessagePort","createImageBitmap","OffscreenCanvas","WebAssembly","WorkerGlobalScope","DedicatedWorkerGlobalScope","trustedTypes","TrustedTypePolicyFactory","SharedArrayBuffer","Atomics"];function Vs(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,s=t.allowClientScripts,c=t.revoked,a=n.postMessage.bind(n);function u(P){a({type:"ERROR",nonce:r,message:String(P)})}let l=typeof n.importScripts=="function"?n.importScripts.bind(n):null,m=o,f=null;try{let P=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let k={createScriptURL:function(S){if(S!==i&&(!o||S!==o))throw new TypeError("Disallowed worker importScripts URL");return S}};s&&(k.createScript=function(S){return String(S)});let D=n.trustedTypes.createPolicy("three-live#worker-boot",k);P=D.createScriptURL(i),o&&(m=D.createScriptURL(o)),s&&typeof D.createScript=="function"&&(f=D.createScript.bind(D))}catch{}l(P)}catch(P){u('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(P&&P.message||P));return}let h=n.THREE;if(!h||typeof h.Scene!="function"){u('Sandbox loaded "'+i+'" 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(e)){let P=n.__THREE_LIVE_REGISTRY__;for(let k=0;k<e.length;k++)if(typeof e[k]=="function")try{e[k](h,P)}catch{}}for(let P=0;P<c.length;P++){let k=c[P],D=n;for(;D&&D!==Object.prototype;){if(D!==n)try{delete D[k]}catch{}try{Object.defineProperty(D,k,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{D=Object.getPrototypeOf(D)}catch{break}}}let b=Object.freeze({now:function(){return Date.now()}}),d=n;for(;d&&d!==Object.prototype;){if(d!==n)try{delete d.performance}catch{}try{Object.defineProperty(d,"performance",{value:b,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let p=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],E=!1;function A(P,k){if(P.type==="3D_MODEL_READY"){if(E)return;E=!0}P.nonce=r,k&&k.length?a(P,k):a(P)}let x=function(P,k){if(!P||p.indexOf(P.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+p.join(", ")+").");A(P,k)},R=n;for(;R&&R!==Object.prototype;){if(R===n||Object.prototype.hasOwnProperty.call(R,"postMessage"))try{Object.defineProperty(R,"postMessage",{value:x,writable:!1,configurable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}let I=!1;n.onmessage=function(P){let k=P&&P.data;if(!(!k||k.nonce!==r)&&!(k.type!=="EXECUTE"&&k.type!=="EXECUTE_URL")&&!I){I=!0;try{let D=new h.Scene,S=new h.PerspectiveCamera(60,1,.1,1e3),_=new h.WebGLRenderer({isSandboxed:!0});if(k.type==="EXECUTE_URL"){if(!o||k.scriptUrl!==o||typeof l!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let v=m||o,G=l;if(l=null,m=null,n.THREE=h,n.scene=D,n.camera=S,n.renderer=_,G(v),typeof n.__THREE_LIVE_SCENE__=="function"){let L=n.__THREE_LIVE_SCENE__(h,D,S,_);L&&typeof L.toGLB=="function"&&(D=L)}else n.scene&&typeof n.scene.toGLB=="function"&&(D=n.scene)}else{if(!s){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let v=f?(0,eval)(f(`(function (THREE, scene, camera, renderer) {
278
303
  return (function () {
279
- `+L.script+`
304
+ `+k.script+`
280
305
  })();
281
306
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
282
- `+L.script+`
283
- })();`);m=null;let B=_(h,b,w,R);B&&typeof B.toGLB=="function"&&(b=B)}if(!x){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(b);let _=b.toGLB(),B=_ instanceof ArrayBuffer?_:_.buffer.slice(_.byteOffset,_.byteOffset+_.byteLength);P({type:"3D_MODEL_READY",glbBuffer:B},[B])}l({type:"DONE",nonce:n})}catch(b){c(b&&b.message||b)}}},l({type:"READY",nonce:n})}function Vn(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Hi};return`'use strict';(${Xi.toString()})(${JSON.stringify(o)});`}function Hr(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 Ue=0;function Xr(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Wi(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Gi=1024,$i=256;function Fr(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function zn(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Gi)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Fr(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let a=Object.create(null),l=i;for(let c of o){if(c.length>$i||c==="__proto__"||c==="constructor"||c==="prototype")return null;let s=l[c];if(!Fr(s))return null;a[c]=s}return{type:"3D_UPDATE_TRANSFORMS",transforms:a}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function qi(t){let e=Wi(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Wr(t,e,n,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":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Yi(t,e,n,r){let i=Xr(),o=Vn(e,i,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=n,Ue++;let l=!1,c=!1,s={modelDispatched:!1},u,m=()=>{if(l||c)return;let p=a.contentWindow;!p||typeof p.postMessage!="function"||(c=!0,p.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},h=()=>{},f=p=>{if(l||!a.contentWindow||p.source!==a.contentWindow)return;let x=p.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){m();return}let P=zn(x,i);P&&Wr(P,r,h,s)};h=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),Ue=Math.max(0,Ue-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",f),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},u=setTimeout(()=>{l||(h(),Hr(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",f),a.onload=()=>{m()},a.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let d=document.body||document.documentElement;if(!d||typeof d.appendChild!="function"){h();let p=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(p),p}return d.appendChild(a),{terminate:h}}function kr(t,e,n,r){if(e==="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(e==="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(Ue>=32)return r(`SecurityError: ${Ue} 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 i;try{i=Ui()}catch(h){let f=h instanceof Error?h.message:String(h);return r(f,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Bi()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Yi(t,i,h,n))}catch(f){return Promise.reject(f)}}let o=Xr(),a=Vn(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([a],{type:"application/javascript"}),f=URL.createObjectURL(h);try{let d=Br(f);l=new Worker(d)}finally{URL.revokeObjectURL(f)}}catch(h){let f=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${f}`,"Security Error: Failed to start Worker sandbox.")}Ue++;let c=!1,s={modelDispatched:!1},u,m=()=>{c||(c=!0,u!==void 0&&clearTimeout(u),Ue=Math.max(0,Ue-1),l.terminate())};return u=setTimeout(()=>{c||(m(),Hr(n))},3e3),l.onmessage=h=>{let f=zn(h.data,o);f&&Wr(f,n,m,s)},l.onerror=h=>{m(),n.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function Nr(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var tt={execute(t,e,n,r){let i=(l,c)=>{let s=new Error(l);return n.onError?.(s),c&&n.onToast?.(c),Promise.reject(s)},o=Nr(e,i);if(o)return o;try{qi(t)}catch(l){let c=l instanceof Error?l.message:String(l);return i(c,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??zr()?kr({kind:"script",script:t},e,n,i):i(Pt,Lt)},executeUrl(t,e,n){let r=(a,l)=>{let c=new Error(a);return n.onError?.(c),l&&n.onToast?.(l),Promise.reject(c)},i=Nr(e,r);if(i)return i;let o;try{o=zi(t)}catch(a){let l=a instanceof Error?a.message:String(a);return r(l,"Security Error: disallowed scene script URL.")}return kr({kind:"url",scriptUrl:o},e,n,r)}},sn=new Set;function Ae(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;sn.has(n)||(sn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Gr(){return Array.from(sn)}function $r(){sn.clear()}var vt=class extends He{constructor(e={}){Ae("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},qr=vt,We=class extends ft{constructor(e=1,n=0,r="PolyhedronGeometry"){Ae(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},an=class extends We{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},cn=class extends We{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},un=class extends We{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},ln=class extends We{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},mn=class extends Oe{constructor(e=1,n=1,r=4,i=8){Ae("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},hn=class extends Oe{constructor(e=.5,n=1,r=16){Ae("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},dn=class extends Oe{constructor(e=1,n=16){Ae("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},fn=class extends yt{constructor(n,r,i=0,o=Math.PI/3,a=0,l=2){Ae("SpotLight","PointLight");super(n,r,i,l);this.target=new Te;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=a}},wt=class extends bt{constructor(e,n,r){Ae("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new Re(n??4473924)}},Yr=wt,jr={Vector2:Bt,Vector3:le,Vector4:Vt,Euler:mt,Quaternion:ht,Matrix4:ze,Matrix3:zt,Color:Re,MathUtils:Ur,BufferAttribute:re,Float32BufferAttribute:Ht,Uint16BufferAttribute:Xt,Uint32BufferAttribute:Wt,BufferGeometry:we,BoxGeometry:dt,PlaneGeometry:Gt,SphereGeometry:ft,CylinderGeometry:Oe,ConeGeometry:$t,TorusGeometry:qt,TorusKnotGeometry:Yt,IcosahedronGeometry:an,OctahedronGeometry:cn,DodecahedronGeometry:un,TetrahedronGeometry:ln,CapsuleGeometry:mn,RingGeometry:hn,CircleGeometry:dn,Texture:pt,TextureLoader:jt,Material:Ce,MeshStandardMaterial:He,MeshBasicMaterial:Kt,MeshLambertMaterial:Zt,MeshPhongMaterial:Jt,MeshPhysicalMaterial:Qt,ShaderMaterial:vt,RawShaderMaterial:qr,Object3D:Te,Group:en,Mesh:Je,Light:Xe,AmbientLight:bt,DirectionalLight:tn,PointLight:yt,SpotLight:fn,HemisphereLight:wt,RectAreaLight:Yr,Camera:gt,PerspectiveCamera:nn,Scene:xt,WebGLRenderer:rn,Clock:on,SceneQuotaValidator:_e,exportSceneToCanvas3D:Un,exportSceneToGLB:On,exportSceneToUSDZ:Or,generateUSDZ:at,glbToUSDZ:st,sceneToCanvas3D:je,sceneToGLB:ot,sceneToUSDZ:Ke,authorScriptRunner:tt,getAuthorWarnings:Gr,clearAuthorWarnings:$r};Object.freeze(_e);Object.freeze(_e.prototype);Object.freeze(xt.prototype);Object.freeze(jr);var At=new Proxy(jr,{get:(t,e)=>e in t?t[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Ae(`THREE.${e}`,"no-op proxy"),ut),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")}}),lt={name:"three_author",THREE:At},ji=lt,Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Qe.THREE>"u"&&(Qe.THREE=At);typeof Qe.requestAnimationFrame!="function"&&(Qe.requestAnimationFrame=()=>(Ae("requestAnimationFrame","single-frame static evaluation"),0));typeof Qe.cancelAnimationFrame!="function"&&(Qe.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=At,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=lt,t.ThreeLivePlugins.three_author=lt,t.ThreeLivePlugins["three-author"]=lt}var Ki=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(t,e){super(t,e),this.detail=e?.detail??null}});var me=class me extends Ki{constructor(){super(...arguments);this.viewer=null;this.canvas=null;this.posterEl=null;this.arButton=null;this.currentModel=null;this.activeXRSession=null;this.toastTimer=null;this.currentModelLimits=void 0;this.isModelLoaded=!1;this.scriptHandle=null;this.resizeObserver=null;this.mutationObserver=null}static get arProvider(){return ie().arProvider}static set arProvider(n){ie().arProvider=n}static get scriptRunner(){return ie().scriptRunner}static set scriptRunner(n){ie().scriptRunner=n}static get sandboxEngineSrc(){return ie().sandboxEngineSrc??null}static set sandboxEngineSrc(n){ie().sandboxEngineSrc=n}static get sandboxIframeSrc(){return ie().sandboxIframeSrc??null}static set sandboxIframeSrc(n){ie().sandboxIframeSrc=n}static get allowClientScripts(){return!!ie().allowClientScripts}static set allowClientScripts(n){ie().allowClientScripts=n}static registerScriptRunner(n){me.scriptRunner=n}static registerDecoder(n,r){fe.registerDecoder(n,r)}static getDecoder(n){return fe.getDecoder(n)}static registerAR(n){typeof n=="function"?me.arProvider={activateAR:n}:me.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof me&&i.updateARButtonVisibility()})}static isARSupported(){return!!me.arProvider}getLoadedModel(){return this.currentModel}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let n=this.getAttribute("src"),r=this.getAttribute("script-src");if(n)this.loadModelFromSrc(n).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of fe.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of fe.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.activeXRSession&&(this.activeXRSession.stop?.().catch?.(()=>{}),this.activeXRSession=null),this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(n,r,i){if(r!==i){switch(n){case"src":i&&this.loadModelFromSrc(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let o=parseFloat(i);isNaN(o)||this.viewer.setExposure(o)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer&&i&&this.viewer.setToneMapping(i);break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let o=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(o),this.canvas&&(this.canvas.style.touchAction=o?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let o of fe.getRegisteredPlugins())o.onAttributeChanged?.(this,n,r,i)}}getAttr(n){return this.getAttribute(n)}setAttr(n,r){r!==null?this.setAttribute(n,r):this.removeAttribute(n)}getBoolAttr(n){return this.hasAttribute(n)&&this.getAttribute(n)!=="false"}setBoolAttr(n,r){r?this.setAttribute(n,""):this.removeAttribute(n)}getFloatAttr(n,r){let i=this.getAttribute(n);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(n){this.setAttr("src",n)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(n){this.setBoolAttr("camera-controls",n)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(n){this.setAttr("camera-orbit",n)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(n){this.setAttr("camera-target",n)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(n){this.setAttr("min-camera-orbit",n)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(n){this.setAttr("max-camera-orbit",n)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(n){this.setAttr("field-of-view",n)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(n){this.setAttr("ios-src",n)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(n){this.setAttr("script-src",n)}get sandbox(){return this.getAttribute("sandbox")||(ie().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||me.allowClientScripts}set allowClientScripts(n){this.setBoolAttr("allow-client-scripts",n)}get poster(){return this.getAttr("poster")}set poster(n){this.setAttr("poster",n)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(n){this.setAttr("selected-mesh",n)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(n){this.setAttribute("exposure",String(n))}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(n){this.setBoolAttr("auto-rotate",n)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(n){this.setAttribute("auto-rotate-delay",String(n))}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(n){this.setAttr("rotation-per-second",n)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(n){this.setBoolAttr("ar",n)}get arScale(){return this.getAttribute("ar-scale")||"auto"}set arScale(n){this.setAttribute("ar-scale",n)}get arPlacement(){return this.getAttribute("ar-placement")||"floor"}set arPlacement(n){this.setAttribute("ar-placement",n)}get canActivateAR(){return me.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(n){this.setAttribute("shadow-intensity",String(n))}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(n){this.setAttribute("shadow-softness",String(n))}get toneMapping(){return this.getAttribute("tone-mapping")||"neutral"}set toneMapping(n){this.setAttribute("tone-mapping",n)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(n){this.setAttr("environment-image",n)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(n){this.setAttr("skybox-image",n)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(n){this.setBoolAttr("autoplay",n)}get animationName(){return this.getAttr("animation-name")}set animationName(n){this.setAttr("animation-name",n)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get model(){let n=this.viewer?this.viewer.getModelMaterials():[];return{materials:n,getMaterialByName(r){return n.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(n=0){this.viewer?.resetTurntableRotation(n)}setCamera(n,r,i,o){this.viewer&&this.viewer.setCamera(n,r,i,o)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,r){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(n,r):""}toBlob(n){return this.viewer&&this.viewer.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(o=>{o?r(o):i(new Error("Failed to capture canvas blob."))},n?.mimeType,n?.qualityArgument)})}positionAndNormalFromPoint(n,r){if(!this.viewer)return null;let i=this.viewer.raycastFromScreenPoint(n,r);if(!i)return null;let[o,a,l]=i.hitPoint||i.point,[c,s,u]=i.normal;return{position:{x:o,y:a,z:l,toString(){return`${o}m ${a}m ${l}m`}},normal:{x:c,y:s,z:u,toString(){return`${c}m ${s}m ${u}m`}}}}async loadModel(n){return this.loadModelWithLimits(n)}async loadModelWithLimits(n,r){if(!this.viewer){this.currentModel=n,this.currentModelLimits=r;return}try{let i;if(typeof n=="string"){this.isModelLoaded=!1,this.viewer?.clearScene?.();let l=await fetch(n);if(!l.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${l.status}`);i=await l.arrayBuffer()}else i=n;let o=ke(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let a=this.getAttribute("selected-mesh");a&&this.viewer.setSelectedMesh(a),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:o}}))}catch(i){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),i}}showToast(n,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=n,this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")}):(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)"),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){if(this.activeXRSession&&typeof this.activeXRSession.isSessionActive=="function"&&this.activeXRSession.isSessionActive()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null),!this.currentModel){let i=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}if(!me.arProvider){let i=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}let n=this.getAttribute("ios-src"),r=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let i=await me.arProvider.activateAR({model:n||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:r.length>0?r:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:o=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:o}})),this.showToast(`AR error: ${o.message}`,6e3)}}});if(i.success)i.session&&(this.activeXRSession=i.session),i.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):i.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):i.mode==="webxr"&&this.showToast("WebXR AR session started.");else{let o=typeof navigator<"u"&&navigator.userAgent||"",a=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),l=/Android|iPhone|iPad|iPod/i.test(o);if(a&&!l&&typeof document<"u"&&this.currentModel&&me.arProvider.createUSDZBlob)try{let c=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:me.arProvider.createUSDZBlob(this.currentModel),s=URL.createObjectURL(c),u=document.createElement("a");u.href=s,u.download="three_live_model.usdz",document.body.appendChild(u),u.click(),document.body.removeChild(u),setTimeout(()=>URL.revokeObjectURL(s),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3)}else this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3);i.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i.error}}))}return i}catch(i){throw this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(`AR error: ${i.message||String(i)}`,6e3),i}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction=this.cameraControls?"none":"auto",n.style.outline="none",this.appendChild(n)),this.canvas=n;let r=this.getAttribute("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let n=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),o=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),a=this.parseCameraTarget(this.getAttribute("camera-target")),l=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new fe(this,this.canvas,{autoRotate:n,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttribute("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,fieldOfView:l,cameraTarget:a,minCameraOrbit:i,maxCameraOrbit:o,onMeshClick:s=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:s}))},onCameraChange:s=>{this.updateHotspots();for(let u of fe.getRegisteredPlugins())u.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail:s}))}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let c=this.getAttribute("camera-orbit");c&&this.applyCameraOrbit(c),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(n){if(!(typeof document>"u")){if(!n){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.setAttribute("alt","3D Scene Preview"),this.posterEl.style.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("aria-label","View in Augmented Reality"),n.className="three-live-ar-button",n.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let o=document.createElementNS(r,"svg");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.style.marginRight="6px";let a=document.createElementNS(r,"path");a.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let l=document.createElementNS(r,"polyline");l.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let c=document.createElementNS(r,"line");c.setAttribute("x1","12"),c.setAttribute("y1","22.08"),c.setAttribute("x2","12"),c.setAttribute("y2","12"),o.appendChild(a),o.appendChild(l),o.appendChild(c),n.appendChild(o)}let i=document.createElement("span");i.textContent="View in AR",n.appendChild(i),n.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",n.addEventListener("mouseenter",()=>{n.style.backgroundColor="rgba(30, 41, 59, 0.95)",n.style.transform="scale(1.04)"}),n.addEventListener("mouseleave",()=>{n.style.backgroundColor="rgba(15, 23, 42, 0.85)",n.style.transform="scale(1)"}),n.addEventListener("click",o=>{o.stopPropagation(),this.activateAR()}),this.arButton=n,this.appendChild(n)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let n=this.hasAttribute("ar")&&!!me.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=n?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=n?"flex":"none")}applyCameraOrbit(n){if(!(!n||!this.viewer))try{let r=JSON.parse(n);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=n.trim().split(/\s+/);if(r.length>=2){let i=c=>c.endsWith("rad")?parseFloat(c)*180/Math.PI:parseFloat(c.replace(/deg$/,"")),o=r[0]==="auto"?void 0:i(r[0]),a=r[1]==="auto"?void 0:i(r[1]),l;r.length>=3&&r[2]!=="auto"&&(l=parseFloat(r[2].replace(/m$/,""))),(o!==void 0&&!isNaN(o)||a!==void 0&&!isNaN(a))&&this.viewer.setInitialCamera(o!==void 0&&!isNaN(o)?o:void 0,a!==void 0&&!isNaN(a)?a:void 0,l!==void 0&&!isNaN(l)?l:void 0)}}}parseOrbitLimit(n){if(!n)return{};let r=n.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let o=r[0].endsWith("rad")?parseFloat(r[0])*180/Math.PI:parseFloat(r[0].replace(/deg$/,""));isNaN(o)||(i.theta=o)}if(r.length>1&&r[1]!=="auto"){let o=r[1].endsWith("rad")?parseFloat(r[1])*180/Math.PI:parseFloat(r[1].replace(/deg$/,""));isNaN(o)||(i.phi=o)}if(r.length>2&&r[2]!=="auto"){let o=parseFloat(r[2].replace(/m$/,""));isNaN(o)||(i.distance=o)}return i}applyOrbitLimits(){if(!this.viewer)return;let n=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:n.theta,maxTheta:r.theta,minPhi:n.phi,maxPhi:r.phi,minDistance:n.distance,maxDistance:r.distance})}parseCameraTarget(n){if(!n)return;let r=n.trim().split(/\s+/).map(i=>parseFloat(i.replace(/m$/,"")));return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(n){if(!n)return;let r=n.endsWith("rad")?parseFloat(n)*180/Math.PI:parseFloat(n.replace(/deg$/,""));return isNaN(r)?void 0:r}parseRotationPerSecond(n){if(!n)return Math.PI/6;let r=n.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(n){let r=this.parseCameraTarget(n);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(n){let r=this.parseFieldOfView(n);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(n){let r=this.querySelector(`[slot="${n.name}"]`);r&&(n.position!==void 0&&r.setAttribute("data-position",n.position),n.normal!==void 0&&r.setAttribute("data-normal",n.normal)),this.updateHotspots()}updateHotspots(){for(let n of fe.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}async loadModelFromSrc(n){await this.loadModel(n)}runWithScriptRunner(n){let r=me.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.isModelLoaded=!1,this.viewer?.clearScene?.(),new Promise((i,o)=>{let a=!1;n(r,{onModelReady:c=>{this.loadModelWithLimits(c,Sr).then(()=>{a||(a=!0,i(c))},s=>{let u=s instanceof Error?s.message:String(s);this.showToast(u),a||(a=!0,o(s))})},onUpdateTransforms:c=>this.viewer?.updateMeshTransforms(c),onError:c=>{this.showToast(c.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:c}})),a||(a=!0,o(c))},onToast:c=>this.showToast(c)}).then(c=>{c&&(this.scriptHandle=c)},c=>{c instanceof Error&&c.message&&this.showToast(c.message),a||(a=!0,o(c))})})}loadScriptFromSrc(n){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let o=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(o),Promise.reject(o)}return r.executeUrl(n,this.sandbox,i)})}executeScript(n){if(!me.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Pt);return this.showToast(Lt),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(n,this.sandbox,i,{allowClientScripts:!0}))}};me.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","environment-image","skybox-image","autoplay","animation-name","auto-rotate","auto-rotate-delay","rotation-per-second"],me.registerPlugin=fe.registerPlugin,me.getRegisteredPlugins=fe.getRegisteredPlugins;var Pe=me;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",Pe);function pn(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function yn(t,e,n,r){let i=e[0],o=e[1],a=e[2],l=e[3],c=n[0],s=n[1],u=n[2],m=n[3],h=i*c+o*s+a*u+l*m;if(h<0&&(c=-c,s=-s,u=-u,m=-m,h=-h),Math.abs(h)>=1)return t[0]=i,t[1]=o,t[2]=a,t[3]=l,t;let f=Math.acos(h),d=Math.sqrt(1-h*h);if(Math.abs(d)<.001)return t[0]=.5*(i+c),t[1]=.5*(o+s),t[2]=.5*(a+u),t[3]=.5*(l+m),t;let p=Math.sin((1-r)*f)/d,x=Math.sin(r*f)/d;return t[0]=i*p+c*x,t[1]=o*p+s*x,t[2]=a*p+u*x,t[3]=l*p+m*x,t}function Kr(t,e,n,r){return t[0]=e[0]+r*(n[0]-e[0]),t[1]=e[1]+r*(n[1]-e[1]),t[2]=e[2]+r*(n[2]-e[2]),t}function Xn(t,e){if(!Array.isArray(t?.animations))return[];let n=[];for(let r=0;r<t.animations.length;r++){let i=t.animations[r],o=i.name||`Animation_${r}`,a=[],l=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let c of i.channels){if(!c.target||c.target.node===void 0||!c.target.path)continue;let s=i.samplers[c.sampler];if(!s)continue;let u=t.accessors?.[s.input],m=t.accessors?.[s.output];if(!u||!m)continue;let h=t.bufferViews?.[u.bufferView],f=t.bufferViews?.[m.bufferView];if(!h||!f)continue;let d=(h.byteOffset||0)+(u.byteOffset||0),p=(f.byteOffset||0)+(m.byteOffset||0),x=pn(e,d,u.count);x.length>0&&x[x.length-1]>l&&(l=x[x.length-1]);let P=c.target.path==="rotation"?4:c.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,u.count))):3,E=pn(e,p,m.count*(c.target.path==="weights"?1:P)),y=s.interpolation==="STEP"?"STEP":"LINEAR";a.push({nodeIndex:c.target.node,path:c.target.path,times:x,values:E,interpolation:y})}a.length>0&&n.push({name:o,duration:l,channels:a})}return n}function nt(t,e,n){let{times:r,values:i,path:o,interpolation:a}=t,l=r.length;if(l===0)return;let c=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/l)):3;if(e<=r[0]){for(let E=0;E<c;E++)n[E]=i[E];return}if(e>=r[l-1]){let E=(l-1)*c;for(let y=0;y<c;y++)n[y]=i[E+y];return}let s=0,u=l-1;for(;s<=u;){let E=s+u>>1;r[E]<=e?s=E+1:u=E-1}let m=Math.max(0,u),h=Math.min(l-1,m+1);if(a==="STEP"||m===h){let E=m*c;for(let y=0;y<c;y++)n[y]=i[E+y];return}let f=r[m],d=r[h],p=(e-f)/Math.max(1e-5,d-f),x=m*c,P=h*c;if(o==="rotation"){let E=[i[x],i[x+1],i[x+2],i[x+3]],y=[i[P],i[P+1],i[P+2],i[P+3]];yn(n,E,y,p)}else for(let E=0;E<c;E++)n[E]=i[x+E]+p*(i[P+E]-i[x+E])}var bn=new WeakMap;function Wn(t,e,n=.3){if(!t?.animations)return;let r=t.animations.find(l=>l.name===e);if(!r)return;let i=bn.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),bn.set(t,i));let o=n>0?1/n:1e3;for(let l of i)l.clip.name!==e&&(l.fadeSpeed=-o);let a=i.find(l=>l.clip.name===e);a?a.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),t.currentClip=r,t.isPlayingAnimation=!0}function Hn(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=bn.get(t);if(!n||n.length===0){if(!t.currentClip)return;n=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let r=t.gltf.nodes.length,i=[];for(let m=0;m<r;m++){let h=t.initialNodeTransforms[m];h?i.push({t:[h.t[0],h.t[1],h.t[2]],r:[h.r[0],h.r[1],h.r[2],h.r[3]],s:[h.s[0],h.s[1],h.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let o=[0,0,0],a=[0,0,0,1],l=[1,1,1],c=new Float32Array(64);for(let m of n){let h=Math.max(0,Math.min(1,m.weight));if(!(h<=1e-4))for(let f of m.clip.channels){if(f.nodeIndex<0||f.nodeIndex>=r)continue;let d=i[f.nodeIndex];if(f.path==="translation")nt(f,m.time,o),Kr(d.t,d.t,o,h);else if(f.path==="rotation")nt(f,m.time,a),yn(d.r,d.r,a,h);else if(f.path==="scale")nt(f,m.time,l),Kr(d.s,d.s,l,h);else if(f.path==="weights"&&(nt(f,m.time,c),t.meshes)){for(let p of t.meshes)if(p.nodeIndex===f.nodeIndex){for(let x of p.primitives)if(x.pluginData?.morph?.weights){let P=x.pluginData.morph.weights,E=x.pluginData.morph.numTargets||P.length;for(let y=0;y<E;y++)P[y]=P[y]*(1-h)+c[y]*h}}}}}let s=[];for(let m=0;m<r;m++){let h=se(),{t:f,r:d,s:p}=i[m];Ye(h,d,f,p),s.push(h)}let u=Fe(t.gltf,s);t.worldMatrices=u;for(let m of t.meshes)m.nodeIndex>=0&&m.nodeIndex<u.length&&(m.transform.set(u[m.nodeIndex]),de(m.normalMatrix,m.transform))}var Gn={name:"keyframes",evaluateAnimation:Hn,crossFadeTo:Wn,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=Xn(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=bn.get(t);if(n&&n.length>0){for(let r=n.length-1;r>=0;r--){let i=n[r];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){n.splice(r,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(t.animationTime=n[n.length-1].time),Hn(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),Hn(t,t.animationTime))}};var St=64;function Zr(t,e,n){if(!(!t?.meshes||e<0||e>=St))for(let r of t.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var $n={name:"morph",onResolveShader(t,e,n,r){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
307
+ `+k.script+`
308
+ })();`);f=null;let G=v(h,D,S,_);G&&typeof G.toGLB=="function"&&(D=G)}if(!E){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(D);let v=D.toGLB(),G=v instanceof ArrayBuffer?v:v.buffer.slice(v.byteOffset,v.byteOffset+v.byteLength);A({type:"3D_MODEL_READY",glbBuffer:G},[G])}a({type:"DONE",nonce:r})}catch(D){u(D&&D.message||D)}}},a({type:"READY",nonce:r})}function Wr(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Os},s=(pe().workerExtensionInstallers??[]).map(c=>`(${c.toString()})`).join(",");return`'use strict';(${Vs.toString()})(${JSON.stringify(o)},[${s}]);`}function To(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 bt=0;function wo(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Bs(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var zs=1024,Gs=256;function mo(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function $r(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,zs)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!mo(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let s=Object.create(null),c=i;for(let a of o){if(a.length>Gs||a==="__proto__"||a==="constructor"||a==="prototype")return null;let u=c[a];if(!mo(u))return null;s[a]=u}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Xs(t){let e=Bs(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Mo(t,e,n,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":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Hs(t,e,n,r){let i=wo(),o=Wr(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.display="none",s.src=n,bt++;let c=!1,a=!1,u={modelDispatched:!1},l,m=()=>{if(c||a)return;let d=s.contentWindow;!d||typeof d.postMessage!="function"||(a=!0,d.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},f=()=>{},h=d=>{if(c||!s.contentWindow||d.source!==s.contentWindow)return;let p=d.data;if(p&&typeof p=="object"&&p.type==="IFRAME_READY"){m();return}let E=$r(p,i);E&&Mo(E,r,f,u)};f=()=>{c||(c=!0,l!==void 0&&clearTimeout(l),bt=Math.max(0,bt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",h),typeof s.remove=="function"?s.remove():s.parentNode&&s.parentNode.removeChild(s))},l=setTimeout(()=>{c||(f(),To(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",h),s.onload=()=>{m()},s.onerror=()=>{f(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let b=document.body||document.documentElement;if(!b||typeof b.appendChild!="function"){f();let d=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(d),d}return b.appendChild(s),{terminate:f}}function fo(t,e,n,r){if(e==="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(e==="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(bt>=32)return r(`SecurityError: ${bt} 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 i;try{i=Ds()}catch(f){let h=f instanceof Error?f.message:String(f);return r(h,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let f;try{f=Ns()}catch(h){let b=h instanceof Error?h.message:String(h);return r(b,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Hs(t,i,f,n))}catch(h){return Promise.reject(h)}}let o=wo(),s=Wr(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c;try{let f=new Blob([s],{type:"application/javascript"}),h=URL.createObjectURL(f);try{let b=go(h);c=new Worker(b)}finally{URL.revokeObjectURL(h)}}catch(f){let h=f instanceof Error?f.message:String(f);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${h}`,"Security Error: Failed to start Worker sandbox.")}bt++;let a=!1,u={modelDispatched:!1},l,m=()=>{a||(a=!0,l!==void 0&&clearTimeout(l),bt=Math.max(0,bt-1),c.terminate())};return l=setTimeout(()=>{a||(m(),To(n))},3e3),c.onmessage=f=>{let h=$r(f.data,o);h&&Mo(h,n,m,u)},c.onerror=f=>{m(),n.onError?.(new Error(`Worker execution error: ${f.message}`))},t.kind==="url"?c.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):c.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function ho(t,e){return t==="none"||t==="unsafe-host-realm"?e(`SecurityError: sandbox="${t}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${t}" is not permitted.`):t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox mode "${t}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Gt={execute(t,e,n,r){let i=(c,a)=>{let u=new Error(c);return n.onError?.(u),a&&n.onToast?.(a),Promise.reject(u)},o=ho(e,i);if(o)return o;try{Xs(t)}catch(c){let a=c instanceof Error?c.message:String(c);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??vo()?fo({kind:"script",script:t},e,n,i):i(yn,gn)},executeUrl(t,e,n){let r=(s,c)=>{let a=new Error(s);return n.onError?.(a),c&&n.onToast?.(c),Promise.reject(a)},i=ho(e,r);if(i)return i;let o;try{o=Us(t)}catch(s){let c=s instanceof Error?s.message:String(s);return r(c,"Security Error: disallowed scene script URL.")}return fo({kind:"url",scriptUrl:o},e,n,r)}},Kn=new Set;function He(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;Kn.has(n)||(Kn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Ao(){return Array.from(Kn)}function So(){Kn.clear()}var un=class extends Tt{constructor(e={}){He("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},Eo=un,At=class extends en{constructor(e=1,n=0,r="PolyhedronGeometry"){He(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Zn=class extends At{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Qn=class extends At{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},Jn=class extends At{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},er=class extends At{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},tr=class extends yt{constructor(e=1,n=1,r=4,i=8){He("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},nr=class extends yt{constructor(e=.5,n=1,r=16){He("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},rr=class extends yt{constructor(e=1,n=16){He("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},ir=class extends sn{constructor(n,r,i=0,o=Math.PI/3,s=0,c=2){He("SpotLight","PointLight");super(n,r,i,c);this.target=new qe;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=s}},ln=class extends on{constructor(e,n,r){He("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new $e(n??4473924)}},Ro=ln,_o={Vector2:In,Vector3:Ce,Vector4:Ln,Euler:Zt,Quaternion:Qt,Matrix4:vt,Matrix3:Pn,Color:$e,MathUtils:po,BufferAttribute:Me,Float32BufferAttribute:Dn,Uint16BufferAttribute:kn,Uint32BufferAttribute:Nn,BufferGeometry:Xe,BoxGeometry:Jt,PlaneGeometry:Fn,SphereGeometry:en,CylinderGeometry:yt,ConeGeometry:Un,TorusGeometry:On,TorusKnotGeometry:Vn,IcosahedronGeometry:Zn,OctahedronGeometry:Qn,DodecahedronGeometry:Jn,TetrahedronGeometry:er,CapsuleGeometry:tr,RingGeometry:nr,CircleGeometry:rr,Texture:tn,TextureLoader:Bn,Material:Qe,MeshStandardMaterial:Tt,MeshBasicMaterial:zn,MeshLambertMaterial:Gn,MeshPhongMaterial:Xn,MeshPhysicalMaterial:Hn,ShaderMaterial:un,RawShaderMaterial:Eo,Object3D:qe,Group:Wn,Mesh:wt,InstancedMesh:rn,Light:Mt,AmbientLight:on,DirectionalLight:$n,PointLight:sn,SpotLight:ir,HemisphereLight:ln,RectAreaLight:Ro,Camera:an,PerspectiveCamera:qn,Scene:cn,WebGLRenderer:Yn,Clock:jn,SceneQuotaValidator:Ze,exportSceneToCanvas3D:Gr,exportSceneToGLB:Xr,exportSceneToUSDZ:yo,generateUSDZ:qt,glbToUSDZ:$t,sceneToCanvas3D:Ut,sceneToGLB:Wt,sceneToUSDZ:Ot,authorScriptRunner:Gt,getAuthorWarnings:Ao,clearAuthorWarnings:So};Object.freeze(Ze);Object.freeze(Ze.prototype);Object.freeze(cn.prototype);Object.freeze(_o);var St=new Proxy(_o,{get:(t,e)=>{if(e in t)return t[e];let n=pe().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&He(`THREE.${e}`,"no-op proxy"),jt)},has:(t,e)=>{if(e in t)return!0;let n=pe().authorNamespace;return!!(n&&typeof e=="string"&&e in n)},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")}}),Cn=pe();Cn.threeNamespace=St;if(Cn.workerExtensionInstallers)for(let t of Cn.workerExtensionInstallers)t(St,Cn);var Kt={name:"three_author",THREE:St},Ws=Kt,Bt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Bt.THREE>"u"&&(Bt.THREE=St);typeof Bt.requestAnimationFrame!="function"&&(Bt.requestAnimationFrame=()=>(He("requestAnimationFrame","single-frame static evaluation"),0));typeof Bt.cancelAnimationFrame!="function"&&(Bt.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=St,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=Kt,t.ThreeLivePlugins.three_author=Kt,t.ThreeLivePlugins["three-author"]=Kt}var $s=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(t,e){super(t,e),this.detail=e?.detail??null}});var Ne=class Ne extends $s{constructor(){super(...arguments);this.viewer=null;this.canvas=null;this.posterEl=null;this.arButton=null;this.currentModel=null;this.activeXRSession=null;this.toastTimer=null;this.currentModelLimits=void 0;this.isModelLoaded=!1;this.scriptHandle=null;this.resizeObserver=null;this.mutationObserver=null}static get arProvider(){return pe().arProvider}static set arProvider(n){pe().arProvider=n}static get scriptRunner(){return pe().scriptRunner}static set scriptRunner(n){pe().scriptRunner=n}static get sandboxEngineSrc(){return pe().sandboxEngineSrc??null}static set sandboxEngineSrc(n){pe().sandboxEngineSrc=n}static get sandboxIframeSrc(){return pe().sandboxIframeSrc??null}static set sandboxIframeSrc(n){pe().sandboxIframeSrc=n}static get allowClientScripts(){return!!pe().allowClientScripts}static set allowClientScripts(n){pe().allowClientScripts=n}static registerScriptRunner(n){Ne.scriptRunner=n}static registerDecoder(n,r){Fe.registerDecoder(n,r)}static getDecoder(n){return Fe.getDecoder(n)}static registerAR(n){typeof n=="function"?Ne.arProvider={activateAR:n}:Ne.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof Ne&&i.updateARButtonVisibility()})}static isARSupported(){return!!Ne.arProvider}getLoadedModel(){return this.currentModel}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let n=this.getAttribute("src"),r=this.getAttribute("script-src");if(n)this.loadModelFromSrc(n).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of Fe.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of Fe.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.activeXRSession&&(this.activeXRSession.stop?.().catch?.(()=>{}),this.activeXRSession=null),this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(n,r,i){if(r!==i){switch(n){case"src":i&&this.loadModelFromSrc(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let o=parseFloat(i);isNaN(o)||this.viewer.setExposure(o)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer&&i&&this.viewer.setToneMapping(i);break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let o=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(o),this.canvas&&(this.canvas.style.touchAction=o?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"variant-name":this.viewer&&this.selectVariant(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let o of Fe.getRegisteredPlugins())o.onAttributeChanged?.(this,n,r,i)}}getAttr(n){return this.getAttribute(n)}setAttr(n,r){r!==null?this.setAttribute(n,r):this.removeAttribute(n)}getBoolAttr(n){return this.hasAttribute(n)&&this.getAttribute(n)!=="false"}setBoolAttr(n,r){r?this.setAttribute(n,""):this.removeAttribute(n)}getFloatAttr(n,r){let i=this.getAttribute(n);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(n){this.setAttr("src",n)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(n){this.setBoolAttr("camera-controls",n)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(n){this.setAttr("camera-orbit",n)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(n){this.setAttr("camera-target",n)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(n){this.setAttr("min-camera-orbit",n)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(n){this.setAttr("max-camera-orbit",n)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(n){this.setAttr("field-of-view",n)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(n){this.setAttr("ios-src",n)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(n){this.setAttr("script-src",n)}get sandbox(){return this.getAttribute("sandbox")||(pe().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||Ne.allowClientScripts}set allowClientScripts(n){this.setBoolAttr("allow-client-scripts",n)}get poster(){return this.getAttr("poster")}set poster(n){this.setAttr("poster",n)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(n){this.setAttr("selected-mesh",n)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(n){this.setAttribute("exposure",String(n))}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(n){this.setBoolAttr("auto-rotate",n)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(n){this.setAttribute("auto-rotate-delay",String(n))}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(n){this.setAttr("rotation-per-second",n)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(n){this.setBoolAttr("ar",n)}get arScale(){return this.getAttribute("ar-scale")||"auto"}set arScale(n){this.setAttribute("ar-scale",n)}get arPlacement(){return this.getAttribute("ar-placement")||"floor"}set arPlacement(n){this.setAttribute("ar-placement",n)}get canActivateAR(){return Ne.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(n){this.setAttribute("shadow-intensity",String(n))}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(n){this.setAttribute("shadow-softness",String(n))}get toneMapping(){return this.getAttribute("tone-mapping")||"neutral"}set toneMapping(n){this.setAttribute("tone-mapping",n)}get bloom(){return this.getFloatAttr("bloom",0)}set bloom(n){this.setAttribute("bloom",String(n))}get bloomThreshold(){return this.getFloatAttr("bloom-threshold",.8)}set bloomThreshold(n){this.setAttribute("bloom-threshold",String(n))}get bloomRadius(){return this.getFloatAttr("bloom-radius",.5)}set bloomRadius(n){this.setAttribute("bloom-radius",String(n))}get outlineSelected(){return this.getBoolAttr("outline-selected")}set outlineSelected(n){this.setBoolAttr("outline-selected",n)}get outlineColor(){return this.getAttr("outline-color")||"#38bdf8"}set outlineColor(n){this.setAttr("outline-color",n)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(n){this.setAttr("environment-image",n)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(n){this.setAttr("skybox-image",n)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(n){this.setBoolAttr("autoplay",n)}get animationName(){return this.getAttr("animation-name")}set animationName(n){this.setAttr("animation-name",n)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get variantName(){return this.viewer?this.viewer.getVariantName():this.getAttr("variant-name")}set variantName(n){this.setAttr("variant-name",n)}get availableVariants(){return this.viewer?this.viewer.getAvailableVariants():[]}selectVariant(n){if(!this.viewer)return!1;let r=this.viewer.selectVariant(n);return r&&this.dispatchEvent(new CustomEvent("variant-applied",{bubbles:!0,composed:!0,detail:{variantName:this.viewer.getVariantName()}})),r}get model(){let n=this.viewer?this.viewer.getModelMaterials():[];return{materials:n,getMaterialByName(r){return n.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(n=0){this.viewer?.resetTurntableRotation(n)}setCamera(n,r,i,o){this.viewer&&this.viewer.setCamera(n,r,i,o)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,r){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(n,r):""}toBlob(n){return this.viewer&&this.viewer.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(o=>{o?r(o):i(new Error("Failed to capture canvas blob."))},n?.mimeType,n?.qualityArgument)})}positionAndNormalFromPoint(n,r){if(!this.viewer)return null;let i=this.viewer.raycastFromScreenPoint(n,r);if(!i)return null;let[o,s,c]=i.hitPoint||i.point,[a,u,l]=i.normal;return{position:{x:o,y:s,z:c,toString(){return`${o}m ${s}m ${c}m`}},normal:{x:a,y:u,z:l,toString(){return`${a}m ${u}m ${l}m`}}}}async loadModel(n){return this.loadModelWithLimits(n)}async loadModelWithLimits(n,r){if(!this.viewer){this.currentModel=n,this.currentModelLimits=r;return}try{let i;if(typeof n=="string"){this.isModelLoaded=!1,this.viewer?.clearScene?.();let a=await fetch(n);if(!a.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${a.status}`);i=await a.arrayBuffer()}else i=n;let o=ot(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.updateHotspots();let s=this.getAttribute("selected-mesh");s&&this.viewer.setSelectedMesh(s);let c=this.getAttribute("variant-name");c&&this.selectVariant(c),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:o}}))}catch(i){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),i}}showToast(n,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=n,this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")}):(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)"),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){if(this.activeXRSession&&typeof this.activeXRSession.isSessionActive=="function"&&this.activeXRSession.isSessionActive()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null),!this.currentModel){let i=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}if(!Ne.arProvider){let i=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}let n=this.getAttribute("ios-src"),r=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let i=await Ne.arProvider.activateAR({model:n||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:r.length>0?r:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:o=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:o}})),this.showToast(`AR error: ${o.message}`,6e3)}}});if(i.success)i.session&&(this.activeXRSession=i.session),i.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):i.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):i.mode==="webxr"&&this.showToast("WebXR AR session started.");else{let o=typeof navigator<"u"&&navigator.userAgent||"",s=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),c=/Android|iPhone|iPad|iPod/i.test(o);if(s&&!c&&typeof document<"u"&&this.currentModel&&Ne.arProvider.createUSDZBlob)try{let a=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:Ne.arProvider.createUSDZBlob(this.currentModel),u=URL.createObjectURL(a),l=document.createElement("a");l.href=u,l.download="three_live_model.usdz",document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(u),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3)}else this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3);i.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i.error}}))}return i}catch(i){throw this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(`AR error: ${i.message||String(i)}`,6e3),i}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction=this.cameraControls?"none":"auto",n.style.outline="none",this.appendChild(n)),this.canvas=n;let r=this.getAttribute("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let n=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),o=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),s=this.parseCameraTarget(this.getAttribute("camera-target")),c=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new Fe(this,this.canvas,{autoRotate:n,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttribute("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,variantName:this.getAttribute("variant-name")||void 0,fieldOfView:c,cameraTarget:s,minCameraOrbit:i,maxCameraOrbit:o,onMeshClick:u=>{this.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:u}))},onCameraChange:u=>{this.updateHotspots();for(let l of Fe.getRegisteredPlugins())l.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail:u}))}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let a=this.getAttribute("camera-orbit");a&&this.applyCameraOrbit(a),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(n){if(!(typeof document>"u")){if(!n){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.setAttribute("alt","3D Scene Preview"),this.posterEl.style.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("aria-label","View in Augmented Reality"),n.className="three-live-ar-button",n.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let o=document.createElementNS(r,"svg");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.style.marginRight="6px";let s=document.createElementNS(r,"path");s.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let c=document.createElementNS(r,"polyline");c.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let a=document.createElementNS(r,"line");a.setAttribute("x1","12"),a.setAttribute("y1","22.08"),a.setAttribute("x2","12"),a.setAttribute("y2","12"),o.appendChild(s),o.appendChild(c),o.appendChild(a),n.appendChild(o)}let i=document.createElement("span");i.textContent="View in AR",n.appendChild(i),n.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",n.addEventListener("mouseenter",()=>{n.style.backgroundColor="rgba(30, 41, 59, 0.95)",n.style.transform="scale(1.04)"}),n.addEventListener("mouseleave",()=>{n.style.backgroundColor="rgba(15, 23, 42, 0.85)",n.style.transform="scale(1)"}),n.addEventListener("click",o=>{o.stopPropagation(),this.activateAR()}),this.arButton=n,this.appendChild(n)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let n=this.hasAttribute("ar")&&!!Ne.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=n?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=n?"flex":"none")}applyCameraOrbit(n){if(!(!n||!this.viewer))try{let r=JSON.parse(n);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=n.trim().split(/\s+/);if(r.length>=2){let i=a=>a.endsWith("rad")?parseFloat(a)*180/Math.PI:parseFloat(a.replace(/deg$/,"")),o=r[0]==="auto"?void 0:i(r[0]),s=r[1]==="auto"?void 0:i(r[1]),c;r.length>=3&&r[2]!=="auto"&&(c=parseFloat(r[2].replace(/m$/,""))),(o!==void 0&&!isNaN(o)||s!==void 0&&!isNaN(s))&&this.viewer.setInitialCamera(o!==void 0&&!isNaN(o)?o:void 0,s!==void 0&&!isNaN(s)?s:void 0,c!==void 0&&!isNaN(c)?c:void 0)}}}parseOrbitLimit(n){if(!n)return{};let r=n.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let o=r[0].endsWith("rad")?parseFloat(r[0])*180/Math.PI:parseFloat(r[0].replace(/deg$/,""));isNaN(o)||(i.theta=o)}if(r.length>1&&r[1]!=="auto"){let o=r[1].endsWith("rad")?parseFloat(r[1])*180/Math.PI:parseFloat(r[1].replace(/deg$/,""));isNaN(o)||(i.phi=o)}if(r.length>2&&r[2]!=="auto"){let o=parseFloat(r[2].replace(/m$/,""));isNaN(o)||(i.distance=o)}return i}applyOrbitLimits(){if(!this.viewer)return;let n=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:n.theta,maxTheta:r.theta,minPhi:n.phi,maxPhi:r.phi,minDistance:n.distance,maxDistance:r.distance})}parseCameraTarget(n){if(!n)return;let r=n.trim().split(/\s+/).map(i=>parseFloat(i.replace(/m$/,"")));return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(n){if(!n)return;let r=n.endsWith("rad")?parseFloat(n)*180/Math.PI:parseFloat(n.replace(/deg$/,""));return isNaN(r)?void 0:r}parseRotationPerSecond(n){if(!n)return Math.PI/6;let r=n.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(n){let r=this.parseCameraTarget(n);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(n){let r=this.parseFieldOfView(n);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(n){let r=this.querySelector(`[slot="${n.name}"]`);r&&(n.position!==void 0&&r.setAttribute("data-position",n.position),n.normal!==void 0&&r.setAttribute("data-normal",n.normal)),this.updateHotspots()}updateHotspots(){for(let n of Fe.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}async loadModelFromSrc(n){await this.loadModel(n)}runWithScriptRunner(n){let r=Ne.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.isModelLoaded=!1,this.viewer?.clearScene?.(),new Promise((i,o)=>{let s=!1;n(r,{onModelReady:a=>{this.loadModelWithLimits(a,eo).then(()=>{s||(s=!0,i(a))},u=>{let l=u instanceof Error?u.message:String(u);this.showToast(l),s||(s=!0,o(u))})},onUpdateTransforms:a=>this.viewer?.updateMeshTransforms(a),onError:a=>{this.showToast(a.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:a}})),s||(s=!0,o(a))},onToast:a=>this.showToast(a)}).then(a=>{a&&(this.scriptHandle=a)},a=>{a instanceof Error&&a.message&&this.showToast(a.message),s||(s=!0,o(a))})})}loadScriptFromSrc(n){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let o=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(o),Promise.reject(o)}return r.executeUrl(n,this.sandbox,i)})}executeScript(n){if(!Ne.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(yn);return this.showToast(gn),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(n,this.sandbox,i,{allowClientScripts:!0}))}};Ne.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","bloom","bloom-threshold","bloom-radius","outline","outline-selected","outline-color","environment-image","skybox-image","autoplay","animation-name","variant-name","auto-rotate","auto-rotate-delay","rotation-per-second"],Ne.registerPlugin=Fe.registerPlugin,Ne.getRegisteredPlugins=Fe.getRegisteredPlugins;var Je=Ne;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",Je);function or(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function ar(t,e,n,r){let i=e[0],o=e[1],s=e[2],c=e[3],a=n[0],u=n[1],l=n[2],m=n[3],f=i*a+o*u+s*l+c*m;if(f<0&&(a=-a,u=-u,l=-l,m=-m,f=-f),Math.abs(f)>=1)return t[0]=i,t[1]=o,t[2]=s,t[3]=c,t;let h=Math.acos(f),b=Math.sqrt(1-f*f);if(Math.abs(b)<.001)return t[0]=.5*(i+a),t[1]=.5*(o+u),t[2]=.5*(s+l),t[3]=.5*(c+m),t;let d=Math.sin((1-r)*h)/b,p=Math.sin(r*h)/b;return t[0]=i*d+a*p,t[1]=o*d+u*p,t[2]=s*d+l*p,t[3]=c*d+m*p,t}function Co(t,e,n,r){return t[0]=e[0]+r*(n[0]-e[0]),t[1]=e[1]+r*(n[1]-e[1]),t[2]=e[2]+r*(n[2]-e[2]),t}function Yr(t,e){if(!Array.isArray(t?.animations))return[];let n=[];for(let r=0;r<t.animations.length;r++){let i=t.animations[r],o=i.name||`Animation_${r}`,s=[],c=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let a of i.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let u=i.samplers[a.sampler];if(!u)continue;let l=t.accessors?.[u.input],m=t.accessors?.[u.output];if(!l||!m)continue;let f=t.bufferViews?.[l.bufferView],h=t.bufferViews?.[m.bufferView];if(!f||!h)continue;let b=(f.byteOffset||0)+(l.byteOffset||0),d=(h.byteOffset||0)+(m.byteOffset||0),p=or(e,b,l.count);p.length>0&&p[p.length-1]>c&&(c=p[p.length-1]);let E=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,l.count))):3,A=or(e,d,m.count*(a.target.path==="weights"?1:E)),x=u.interpolation==="STEP"?"STEP":"LINEAR";s.push({nodeIndex:a.target.node,path:a.target.path,times:p,values:A,interpolation:x})}s.length>0&&n.push({name:o,duration:c,channels:s})}return n}function Xt(t,e,n){let{times:r,values:i,path:o,interpolation:s}=t,c=r.length;if(c===0)return;let a=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/c)):3;if(e<=r[0]){for(let A=0;A<a;A++)n[A]=i[A];return}if(e>=r[c-1]){let A=(c-1)*a;for(let x=0;x<a;x++)n[x]=i[A+x];return}let u=0,l=c-1;for(;u<=l;){let A=u+l>>1;r[A]<=e?u=A+1:l=A-1}let m=Math.max(0,l),f=Math.min(c-1,m+1);if(s==="STEP"||m===f){let A=m*a;for(let x=0;x<a;x++)n[x]=i[A+x];return}let h=r[m],b=r[f],d=(e-h)/Math.max(1e-5,b-h),p=m*a,E=f*a;if(o==="rotation"){let A=[i[p],i[p+1],i[p+2],i[p+3]],x=[i[E],i[E+1],i[E+2],i[E+3]];ar(n,A,x,d)}else for(let A=0;A<a;A++)n[A]=i[p+A]+d*(i[E+A]-i[p+A])}var sr=new WeakMap;function jr(t,e,n=.3){if(!t?.animations)return;let r=t.animations.find(c=>c.name===e);if(!r)return;let i=sr.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),sr.set(t,i));let o=n>0?1/n:1e3;for(let c of i)c.clip.name!==e&&(c.fadeSpeed=-o);let s=i.find(c=>c.clip.name===e);s?s.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),t.currentClip=r,t.isPlayingAnimation=!0}function qr(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=sr.get(t);if(!n||n.length===0){if(!t.currentClip)return;n=[{clip:t.currentClip,time:e,weight:1,fadeSpeed:0}]}let r=t.gltf.nodes.length,i=[];for(let m=0;m<r;m++){let f=t.initialNodeTransforms[m];f?i.push({t:[f.t[0],f.t[1],f.t[2]],r:[f.r[0],f.r[1],f.r[2],f.r[3]],s:[f.s[0],f.s[1],f.s[2]]}):i.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let o=[0,0,0],s=[0,0,0,1],c=[1,1,1],a=new Float32Array(64);for(let m of n){let f=Math.max(0,Math.min(1,m.weight));if(!(f<=1e-4))for(let h of m.clip.channels){if(h.nodeIndex<0||h.nodeIndex>=r)continue;let b=i[h.nodeIndex];if(h.path==="translation")Xt(h,m.time,o),Co(b.t,b.t,o,f);else if(h.path==="rotation")Xt(h,m.time,s),ar(b.r,b.r,s,f);else if(h.path==="scale")Xt(h,m.time,c),Co(b.s,b.s,c,f);else if(h.path==="weights"&&(Xt(h,m.time,a),t.meshes)){for(let d of t.meshes)if(d.nodeIndex===h.nodeIndex){for(let p of d.primitives)if(p.pluginData?.morph?.weights){let E=p.pluginData.morph.weights,A=p.pluginData.morph.numTargets||E.length;for(let x=0;x<A;x++)E[x]=E[x]*(1-f)+a[x]*f}}}}}let u=[];for(let m=0;m<r;m++){let f=we(),{t:h,r:b,s:d}=i[m];rt(f,b,h,d),u.push(f)}let l=it(t.gltf,u);t.worldMatrices=l;for(let m of t.meshes)m.nodeIndex>=0&&m.nodeIndex<l.length&&(m.transform.set(l[m.nodeIndex]),Le(m.normalMatrix,m.transform))}var Kr={name:"keyframes",evaluateAnimation:qr,crossFadeTo:jr,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=Yr(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=sr.get(t);if(n&&n.length>0){for(let r=n.length-1;r>=0;r--){let i=n[r];if(i.time+=e,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*e,i.weight<=0){n.splice(r,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(t.animationTime=n[n.length-1].time),qr(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),qr(t,t.animationTime))}};var mn=64;function Io(t,e,n){if(!(!t?.meshes||e<0||e>=mn))for(let r of t.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var Zr={name:"morph",onResolveShader(t,e,n,r){if(!Array.isArray(t?.targets)||t.targets.length===0)return null;let i=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
284
309
  uniform sampler2D uMorphDeltasTex;
285
- uniform float uMorphWeights[${St}];
310
+ uniform float uMorphWeights[${mn}];
286
311
  uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
287
- for (int m = 0; m < ${St}; m++) {
312
+ for (int m = 0; m < ${mn}; m++) {
288
313
  if (m >= uNumMorphTargets) break;
289
314
  float w = uMorphWeights[m];
290
315
  if (abs(w) > 0.0001) {
291
316
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
292
317
  }
293
318
  }
294
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.targets;if(!Array.isArray(o)||o.length===0)return null;let a=n.attributes?.POSITION,l=r?.accessors?.[a];if(!l)return null;let c=l.count,s=Math.min(o.length,St),u=new Float32Array(c*s*4);for(let f=0;f<s;f++){let d=o[f].POSITION;if(d===void 0)continue;let p=r.accessors?.[d],x=r.bufferViews?.[p?.bufferView];if(!p||!x)continue;let P=(x.byteOffset||0)+(p.byteOffset||0),E=pn(i,P,c*3),y=f*c*4;for(let v=0;v<c;v++)u[y+v*4]=E[v*3],u[y+v*4+1]=E[v*3+1],u[y+v*4+2]=E[v*3+2],u[y+v*4+3]=0}let m=t.createTexture();t.bindTexture(3553,m),t.texImage2D(3553,0,34836,c,s,0,6408,5126,u),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let h=new Float32Array(St);return{hasMorph:!0,morphTex:m,numTargets:s,vertexCount:c,weights:h}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=n.pluginData?.morph;if(!a?.hasMorph||!a.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,a.morphTex);let l=t.getUniformLocation(e,"uMorphDeltasTex");l&&t.uniform1i(l,5);let c=t.getUniformLocation(e,"uNumMorphTargets");c&&t.uniform1i(c,a.numTargets);let s=t.getUniformLocation(e,"uMorphWeights[0]");s&&t.uniform1fv(s,a.weights)}};var qn=64,Yn={name:"skinning",onResolveShader(t,e,n,r){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=n.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
319
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.targets;if(!Array.isArray(o)||o.length===0)return null;let s=n.attributes?.POSITION,c=r?.accessors?.[s];if(!c)return null;let a=c.count,u=Math.min(o.length,mn),l=new Float32Array(a*u*4);for(let h=0;h<u;h++){let b=o[h].POSITION;if(b===void 0)continue;let d=r.accessors?.[b],p=r.bufferViews?.[d?.bufferView];if(!d||!p)continue;let E=(p.byteOffset||0)+(d.byteOffset||0),A=or(i,E,a*3),x=h*a*4;for(let R=0;R<a;R++)l[x+R*4]=A[R*3],l[x+R*4+1]=A[R*3+1],l[x+R*4+2]=A[R*3+2],l[x+R*4+3]=0}let m=t.createTexture();t.bindTexture(3553,m),t.texImage2D(3553,0,34836,a,u,0,6408,5126,l),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728);let f=new Float32Array(mn);return{hasMorph:!0,morphTex:m,numTargets:u,vertexCount:a,weights:f}},onBeforeDrawPrimitive(t,e,n,r,i,o){let s=n.pluginData?.morph;if(!s?.hasMorph||!s.morphTex)return;t.activeTexture(33989),t.bindTexture(3553,s.morphTex);let c=t.getUniformLocation(e,"uMorphDeltasTex");c&&t.uniform1i(c,5);let a=t.getUniformLocation(e,"uNumMorphTargets");a&&t.uniform1i(a,s.numTargets);let u=t.getUniformLocation(e,"uMorphWeights[0]");u&&t.uniform1fv(u,s.weights)}};var Qr=64,Jr={name:"skinning",onResolveShader(t,e,n,r){if(t?.attributes?.JOINTS_0===void 0||t?.attributes?.WEIGHTS_0===void 0)return null;let i=n.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
295
320
  layout(location=4) in uvec4 aJoints;
296
321
  layout(location=5) in vec4 aWeights;
297
- uniform mat4 uJointMatrix[${qn}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
322
+ uniform mat4 uJointMatrix[${Qr}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
298
323
  aWeights.x * uJointMatrix[int(aJoints.x)] +
299
324
  aWeights.y * uJointMatrix[int(aJoints.y)] +
300
325
  aWeights.z * uJointMatrix[int(aJoints.z)] +
301
326
  aWeights.w * uJointMatrix[int(aJoints.w)];
302
- vec4 world=uModel*(skinMatrix*vec4(${o},1.0));`).replace(`gl_Position=uMVP*vec4(${o},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${o},1.0));`),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.attributes;if(!o||o.JOINTS_0===void 0||o.WEIGHTS_0===void 0)return null;let a=r.accessors[o.JOINTS_0],l=r.accessors[o.WEIGHTS_0];if(!a||!l)return null;let c=r.bufferViews[a.bufferView],s=r.bufferViews[l.bufferView];if(!c||!s)return null;let u=(c.byteOffset||0)+(a.byteOffset||0),m=(s.byteOffset||0)+(l.byteOffset||0),h=t.createBuffer();t.bindBuffer(34962,h);let f=a.componentType===5121?5121:5123,d=f===5121?new Uint8Array(i,u,a.count*4):new Uint16Array(i,u,a.count*4);t.bufferData(34962,d,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,f,0,0);let p=t.createBuffer();t.bindBuffer(34962,p);let x=new Float32Array(i,m,l.count*4);return t.bufferData(34962,x,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[h,p]}},onBeforeDrawPrimitive(t,e,n,r,i,o){if(!n.pluginData?.skinning?.hasSkin)return;let a=o?.nodes?.[r.nodeIndex]?.skin;if(a===void 0||!o.skins||!o.skins[a])return;let c=o.skins[a].joints||[],s=new Float32Array(qn*16);for(let m=0;m<c.length&&m<qn;m++){let h=c[m],f=i[h]||se();s.subarray(m*16,(m+1)*16).set(f)}let u=t.getUniformLocation(e,"uJointMatrix[0]");u&&t.uniformMatrix4fv(u,!1,s)}};ge($n);ge(Gn);ge(Yn);var jn=new WeakMap;function gn(t,e){let n=e instanceof Float32Array?e:new Float32Array(e);jn.set(t,n)}function ti(t){return jn.get(t)}async function Zi(t,e){if(!e)return null;let n;if(typeof e=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let o=await(await fetch(e)).blob();n=await createImageBitmap(o)}else if(typeof Image<"u")n=await new Promise((i,o)=>{let a=new Image;a.crossOrigin="anonymous",a.onload=()=>i(a),a.onerror=o,a.src=e});else return null;else n=e;let r=t.createTexture();return t.bindTexture(3553,r),t.texImage2D(3553,0,6408,6408,5121,n),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553),r}var Jr=new WeakMap,Qr=new Float32Array(16);async function ei(t,e,n){let r=n?await Zi(t.gl,n):null;t[e]&&t.gl.deleteTexture(t[e]),t[e]=r}var Kn={name:"environment-map",setEnvironmentImage(t,e){return ei(t,"environmentTexture",e)},setSkyboxImage(t,e){return ei(t,"skyboxTexture",e)},onBeforeDrawScene(t,e,n,r,i){if(!t.skyboxTexture||typeof e.createProgram!="function")return;let o=Jr.get(e);if(!o){let m=(d,p)=>{let x=e.createShader(d);return e.shaderSource(x,p),e.compileShader(x),x},h=e.createProgram();e.attachShader(h,m(35633,`#version 300 es
303
- out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),e.attachShader(h,m(35632,`#version 300 es
304
- precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),e.linkProgram(h);let f=typeof e.createVertexArray=="function"?e.createVertexArray():null;o={program:h,vao:f},Jr.set(e,o)}let a=kt(Qr,n)||Qr;e.depthMask(!1),e.useProgram(o.program),o.vao&&e.bindVertexArray(o.vao),e.activeTexture(33984),e.bindTexture(3553,t.skyboxTexture);let l=e.getUniformLocation(o.program,"uSkyboxMap");l&&e.uniform1i(l,0);let c=e.getUniformLocation(o.program,"uInvVP");c&&e.uniformMatrix4fv(c,!1,a);let s=e.getUniformLocation(o.program,"uCameraPos");s&&e.uniform3f(s,r[0],r[1],r[2]);let u=e.getUniformLocation(o.program,"uExposure");u&&e.uniform1f(u,t.exposure??1),e.drawArrays(4,0,3),e.depthMask(!0)},onResolveShader(t,e,n,r){if(r.includes("evalSHIrradiance"))return null;let i=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
327
+ vec4 world=uModel*(skinMatrix*vec4(${o},1.0));`).replace(`gl_Position=uMVP*vec4(${o},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${o},1.0));`),{vs:i,fs:r}},onBuildPrimitiveVAO(t,e,n,r,i){let o=n?.attributes;if(!o||o.JOINTS_0===void 0||o.WEIGHTS_0===void 0)return null;let s=r.accessors[o.JOINTS_0],c=r.accessors[o.WEIGHTS_0];if(!s||!c)return null;let a=r.bufferViews[s.bufferView],u=r.bufferViews[c.bufferView];if(!a||!u)return null;let l=(a.byteOffset||0)+(s.byteOffset||0),m=(u.byteOffset||0)+(c.byteOffset||0),f=t.createBuffer();t.bindBuffer(34962,f);let h=s.componentType===5121?5121:5123,b=h===5121?new Uint8Array(i,l,s.count*4):new Uint16Array(i,l,s.count*4);t.bufferData(34962,b,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,h,0,0);let d=t.createBuffer();t.bindBuffer(34962,d);let p=new Float32Array(i,m,c.count*4);return t.bufferData(34962,p,35044),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[f,d]}},onBeforeDrawPrimitive(t,e,n,r,i,o){if(!n.pluginData?.skinning?.hasSkin)return;let s=o?.nodes?.[r.nodeIndex]?.skin;if(s===void 0||!o.skins||!o.skins[s])return;let a=o.skins[s].joints||[],u=new Float32Array(Qr*16);for(let m=0;m<a.length&&m<Qr;m++){let f=a[m],h=i[f]||we();u.subarray(m*16,(m+1)*16).set(h)}let l=t.getUniformLocation(e,"uJointMatrix[0]");l&&t.uniformMatrix4fv(l,!1,u)}};Pe(Zr);Pe(Kr);Pe(Jr);Pe(Lr);Pe(Ar);var qs=`#version 300 es
328
+ layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,Ys=`#version 300 es
329
+ precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,cr=new WeakMap,Lo=new Float32Array(20);function ei(t,e){let[n,r,i,o,s,c]=e;return[t[0]*n+t[4]*r+t[8]*i+t[12],t[1]*n+t[5]*r+t[9]*i+t[13],t[2]*n+t[6]*r+t[10]*i+t[14],Math.abs(t[0])*o+Math.abs(t[4])*s+Math.abs(t[8])*c,Math.abs(t[1])*o+Math.abs(t[5])*s+Math.abs(t[9])*c,Math.abs(t[2])*o+Math.abs(t[6])*s+Math.abs(t[10])*c]}function js(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,s=-1e9;for(let c of t.primitives||[]){let a=c.positions;if(a)for(let u=0;u<a.length;u+=3)a[u]<e&&(e=a[u]),a[u+1]<n&&(n=a[u+1]),a[u+2]<r&&(r=a[u+2]),a[u]>i&&(i=a[u]),a[u+1]>o&&(o=a[u+1]),a[u+2]>s&&(s=a[u+2])}return t._lb=e<=i?[(e+i)*.5,(n+o)*.5,(r+s)*.5,(i-e)*.5,(o-n)*.5,(s-r)*.5]:null}function Ks(t){let e=cr.get(t);if(e)return e;let n=(c,a)=>{let u=t.createShader(c);return t.shaderSource(u,a),t.compileShader(u),u},r=t.createProgram();t.attachShader(r,n(35633,qs)),t.attachShader(r,n(35632,Ys)),t.linkProgram(r);let i=t.createVertexArray(),o=t.createBuffer(),s=t.createBuffer();return t.bindVertexArray(i),t.bindBuffer(34962,o),t.bufferData(34962,80,35048),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,5126,!1,20,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,5126,!1,20,12),t.bindBuffer(34963,s),t.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),t.bindVertexArray(null),e={prog:r,vao:i,vbo:o,ibo:s,uMVP:t.getUniformLocation(r,"uMVP"),uIntensity:t.getUniformLocation(r,"uShadowIntensity"),uSoftness:t.getUniformLocation(r,"uShadowSoftness")},cr.set(t,e),e}var fn={name:"contact-shadow",onAfterRender(t,e,n){let r=e.shadowIntensity;if(r<=0||!e.bounds)return;let i=Ks(t),o=!e.xrSessionActive&&(e.backdropMeshes?.length??0)>0,s=[],c=[];for(let d of e.meshes||[]){if(!d||d.visible===!1||d.isPluginMesh||d.name==="__xr_reticle__"||d.name?.startsWith("__xr_slot_"))continue;let p=js(d);if(!p)continue;d.transform&&(p=ei(d.transform,p)),e.modelRootMatrix&&(p=ei(e.modelRootMatrix,p));let[E,A,x,R,I,P]=p,k=[E,x,R,P,A-I,A+I];/floor|table|pedestal|ground|base|plane/i.test(d.name||"")||I<.14&&Math.min(R,P)>.45?c.push(k):s.push(k)}let a=[],u=e.bounds.center||[0,0,0],l=Math.max(.05,Number(e.bounds.radius)||.5),m=e.bounds.min,f=m?[u[0],u[1],u[2],l,Math.max(.01,u[1]-m[1]),l]:[u[0],u[1],u[2],l,l,l];e.modelRootMatrix&&(f=ei(e.modelRootMatrix,f));let b=e.xrSessionActive&&c.length===0&&String(e.container?.tagName||"").toLowerCase()==="xr-live"?(e.modelRootMatrix?e.modelRootMatrix[5]*-.25+e.modelRootMatrix[13]:-.25)+.002:f[1]-f[4]+.002;for(let[d,p,E,A,x]of s){let R=-1/0;for(let[P,k,D,S,,_]of c)x>=_-.08&&Math.abs(d-P)<=D&&Math.abs(p-k)<=S&&_+.002>R&&(R=_+.002);o&&(R=Math.max(R,d>=.04&&d<=.36&&p>=-.34&&p<=-.04&&x>=.01?.036:Math.hypot(d,p)<=.66&&x>=-.06?.003:-.477)),isFinite(R)||(R=b);let I=a.find(P=>Math.hypot(d-P[0],p-P[1])<.06&&Math.abs(R-P[5])<.05);I?(I[2]=Math.max(I[2],E*.78),I[3]=Math.max(I[3],A*.78),I[4]=Math.min(I[4],x)):a.push([d,p,E,A,x,R])}if(a.length===0){let d=Math.max(.1,f[3]*1.5)/1.45;a.push([f[0],f[2],d,d,b,b])}t.useProgram(i.prog),t.uniformMatrix4fv(i.uMVP,!1,n),t.enable(3042),(t.blendFuncSeparate||t.blendFunc).call(t,770,771,1,771),t.depthMask(!1),t.bindVertexArray(i.vao),t.bindBuffer(34962,i.vbo);for(let[d,p,E,A,x,R]of a){let I=Math.max(0,x-R),P=r/(1+I*2);if(P<.02)continue;let k=1+Math.min(.75,I*.85),D=Math.max(.045,E*1.45*k),S=Math.max(.045,A*1.45*k);Lo.set([d-D,R,p-S,0,0,d+D,R,p-S,1,0,d+D,R,p+S,1,1,d-D,R,p+S,0,1]),t.bufferSubData(34962,0,Lo),t.uniform1f(i.uIntensity,P),t.uniform1f(i.uSoftness,Math.min(1,e.shadowSoftness+Math.min(.45,I*.6))),t.drawElements(4,6,5123,0)}t.bindVertexArray(null),t.depthMask(!0),t.disable(3042)},onDestroy(t){let e=cr.get(t);e&&(t.deleteVertexArray(e.vao),t.deleteBuffer(e.vbo),t.deleteBuffer(e.ibo),t.deleteProgram(e.prog),cr.delete(t))}};function ri(){if(typeof window>"u"||typeof navigator>"u")return!1;let t=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(t)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function ii(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function oi(){if(typeof navigator>"u")return!1;let t=navigator;if(!t.xr||typeof t.xr.isSessionSupported!="function")return!1;try{return await t.xr.isSessionSupported("immersive-ar")?!0:await t.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function ko(){return(await lr()).bestMode}async function lr(){let[t,e,n]=await Promise.all([oi(),Promise.resolve(ri()),Promise.resolve(ii())]),r=[];e&&r.push("quick-look"),t&&r.push("webxr"),n&&r.push("scene-viewer");let i=null;return e?i="quick-look":t?i="webxr":n&&(i="scene-viewer"),{webxr:t,quickLook:e,sceneViewer:n,availableModes:r,bestMode:i}}function Po(t,e={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,r=!1;if(typeof t=="string"){if(n=Zs(t),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(t),r=!0;let i=[];if(e.allowScale===!1&&i.push("allowsContentScaling=0"),e.canonicalWebPageUrl){let c=ur(e.canonicalWebPageUrl,!1);c&&i.push(`canonicalWebPageURL=${encodeURIComponent(c)}`)}e.checkoutTitle&&i.push(`checkoutTitle=${encodeURIComponent(e.checkoutTitle)}`),e.checkoutSubtitle&&i.push(`checkoutSubtitle=${encodeURIComponent(e.checkoutSubtitle)}`),e.price&&i.push(`price=${encodeURIComponent(e.price)}`),i.length>0&&(n+=`#${i.join("&")}`);let o=document.createElement("a");o.setAttribute("rel","ar"),o.setAttribute("href",n);let s=document.createElement("img");s.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),s.style.display="none",o.appendChild(s),document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),r&&URL.revokeObjectURL(n.split("#")[0])},3e3)}function ur(t,e=!1){if(typeof t!="string")return"";let n=t.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!n)return"";if(/^[\\/]{2}/.test(n))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${n.slice(0,32)}`);let r=n.toLowerCase();if(r.startsWith("https://")||r.startsWith("http://")||e&&r.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(n))return n;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${n.slice(0,32)}`)}function Zs(t){try{return ur(t,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(t||"").trim().slice(0,32)}`)}}function Qs(t,e={}){let n=ur(t,!0),r=e.mode||"ar_preferred",i=new URLSearchParams({file:n,mode:r,resizable:e.resizable!==!1?"true":"false",enable_vertical_placement:e.enableVerticalPlacement?"true":"false"});return e.title&&i.set("title",e.title),e.link&&i.set("link",ur(e.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${i.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function Js(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=Qs(t,e);window.location.href=n}var Et=null;function ea(t,e){let r=new Float32Array(144),i=new Float32Array(24*6),o=new Float32Array(24*4),s=new Uint16Array(24*6);for(let m=0;m<24;m++){let f=m/24*Math.PI*2,h=Math.cos(f),b=Math.sin(f),d=m*2,p=d+1,E=(m+1)%24*2;r[d*3]=h*.11,r[d*3+1]=.002,r[d*3+2]=b*.11,r[p*3]=h*.145,r[p*3+1]=.002,r[p*3+2]=b*.145,i[d*3+1]=i[p*3+1]=1,s.set([d,E,p,p,E,E+1],m*6)}let c=t.createVertexArray();t.bindVertexArray(c);let a=(m,f,h)=>{let b=t.createBuffer();return t.bindBuffer(34962,b),t.bufferData(34962,m,35044),t.enableVertexAttribArray(f),t.vertexAttribPointer(f,h,5126,!1,0,0),b},u=[a(r,0,3),a(i,1,3),a(o,2,2)],l=t.createBuffer();return u.push(l),t.bindBuffer(34963,l),t.bufferData(34963,s,35044),t.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:c,indexCount:s.length,indexType:5123,baseColor:e&&e.length>=3?[e[0],e[1],e[2],e[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:s,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:u}]}}function Do(t,e,n,r,i){let o=Math.cos(r),s=Math.sin(r),c=Math.max(.01,i);t.fill(0),t[0]=c*o,t[2]=-c*s,t[5]=c,t[8]=c*s,t[10]=c*o,t[12]=e[0]-c*(o*n[0]+s*n[2]),t[13]=e[1]-c*n[1],t[14]=e[2]-c*(-s*n[0]+o*n[2]),t[15]=1}var ni=class{constructor(e={}){this.s=null;this.placed=!1;this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.cleanFn=null;this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,n){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");Et&&Et!==this&&Et.isSessionActive()&&await Et.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||e?.container,s=String(o?.tagName||"").toLowerCase()==="xr-live",c=e?.bounds,a=Number(c?.radius)||1,u=Array.isArray(c?.center)?c.center:[0,0,0],l=Array.isArray(c?.min)?c.min:[-.5,-.5,-.5],m=typeof navigator<"u"&&navigator.userAgent||"",f=/Android|iPhone|iPad|iPod/i.test(m)&&!/Quest|Oculus|Pico|Vision/i.test(m),h=s?i.arScale==="fixed"?1:f?.55:1:i.arScale==="fixed"?1:a>.45?.3/a:a<.05?.12/Math.max(a,.001):1,b=s?[0,-.25,0]:[u[0]||0,i.arPlacement==="wall"?u[1]:l[1]??0,u[2]||0],d="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(d="immersive-vr")}catch{d="immersive-vr"}let p=o?.querySelector?.('[slot="ar-overlay"]')||null,E=!1,A=null,x=()=>{E&&p?.parentNode&&p.parentNode.removeChild(p),p=null,A=null,E=!1};if(d==="immersive-ar"){if(p)p.addEventListener?.("beforexrselect",M=>M.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let M=document.createElement("div");M.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let N=document.createElement("button");N.type="button",N.textContent="\u2715 Exit AR",N.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",N.addEventListener("beforexrselect",z=>z.preventDefault()),N.addEventListener("click",z=>{z.stopPropagation(),this.stop().catch(()=>{})}),A=document.createElement("div"),A.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",A.textContent="Move phone to detect a surface \u2022 Tap to place",M.appendChild(N),M.appendChild(A),document.body.appendChild(M),p=M,E=!0}}let R=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),I={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(R)};p&&(R.add("dom-overlay"),I.optionalFeatures=Array.from(R),I.domOverlay={root:p});for(let M of Ie)M.onConfigureXRSessionInit?.(o,I);Array.isArray(I.optionalFeatures)&&I.optionalFeatures.includes("dom-overlay")&&!I.domOverlay?.root&&(I.optionalFeatures=I.optionalFeatures.filter(M=>M!=="dom-overlay"));let P=M=>{let N=String(M?.name||"");return N==="NotAllowedError"||N==="SecurityError"};try{this.s=await r.requestSession(d,I)}catch(M){if(x(),P(M))throw i.onError?.(M),M;try{this.s=await r.requestSession(d,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(N){if(P(N))throw i.onError?.(N),N;try{this.s=await r.requestSession(d)}catch(z){throw i.onError?.(z),z}}}let k=this.s;Et=this,this.placed=!1;let D=null,S=null,_=null,v=null,G=null,L=[0,-.25,-1.2],U=[0,-.25,-1.2],q=new Float32Array(16),W=new Float32Array(16),K=!1,Y=1,te=0,ie=!1,$=null,ne=null,re=0,O=null,X=()=>{Et===this&&(Et=null),O?.(),O=null;try{S?.cancel?.()}catch{}if(S=null,_){let M=e?.meshes;if(Array.isArray(M)){let z=M.indexOf(_);z!==-1&&M.splice(z,1)}let N=e.getGLContext?.()||e?.gl;if(N)for(let z of _.primitives||[]){N.deleteVertexArray?.(z.vao);for(let V of z.buffers||[])N.deleteBuffer?.(V)}_=null}e?.setXRSessionActive?.(!1),x(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=X,k.addEventListener("end",()=>{X(),i.onExit?.()}),k.addEventListener("select",()=>{if(!this.placed){let M=G||L;U=[M[0],M[1],M[2]],Do(this.placedMat,U,b,te,h*Y),this.placed=!0,_&&(_.visible=!1),A&&(A.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let M=e.getGLContext?.()||e?.gl;M&&typeof M.makeXRCompatible=="function"&&await M.makeXRCompatible();let N=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;M&&typeof N=="function"&&typeof k.updateRenderState=="function"&&k.updateRenderState({baseLayer:new N(k,M,{alpha:!0})});try{D=await k.requestReferenceSpace("local")}catch{try{D=await k.requestReferenceSpace("local-floor")}catch{D=await k.requestReferenceSpace("viewer")}}let z=await k.requestReferenceSpace("viewer").catch(()=>D);if(typeof k.requestHitTestSource=="function"&&z&&(S=await k.requestHitTestSource({space:z}).catch(()=>null)),d==="immersive-ar"&&M&&typeof M.createVertexArray=="function"&&Array.isArray(e.meshes)&&(_=ea(M,i.reticleColor),e.meshes.push(_)),typeof window<"u"&&typeof window.addEventListener=="function"){let y=w=>Math.hypot(w.touches[1].clientX-w.touches[0].clientX,w.touches[1].clientY-w.touches[0].clientY),g=w=>Math.atan2(w.touches[1].clientY-w.touches[0].clientY,w.touches[1].clientX-w.touches[0].clientX),T=w=>{this.s&&(w.touches.length===1&&this.placed?ie=!0:w.touches.length>=2&&(ie=!1,$=y(w),ne=g(w)))},C=w=>{if(!this.s||w.touches.length<2)return;let F=y(w),H=g(w);if($&&$>4&&i.arScale!=="fixed"&&(Y=Math.max(.15,Math.min(6,Y*(F/$)))),ne!==null){let J=H-ne;J>Math.PI&&(J-=Math.PI*2),J<-Math.PI&&(J+=Math.PI*2),te-=J}$=F,ne=H},B=w=>{(!w.touches||w.touches.length===0)&&(ie=!1),(!w.touches||w.touches.length<2)&&($=null,ne=null)};window.addEventListener("touchstart",T,{passive:!0}),window.addEventListener("touchmove",C,{passive:!0}),window.addEventListener("touchend",B,{passive:!0}),window.addEventListener("touchcancel",B,{passive:!0}),O=()=>{window.removeEventListener("touchstart",T),window.removeEventListener("touchmove",C),window.removeEventListener("touchend",B),window.removeEventListener("touchcancel",B)}}e.setXRSessionActive?.(!0);let V=(y,g)=>{if(this.s!==k)return;k.requestAnimationFrame(V);let T=re>0?Math.min(Math.max((y-re)/1e3,0),.1):1/60;re=y,e?.stepXRUpdate?.(T);let C=g.getViewerPose(D);if(!C)return;let B=C.views?.[0];if(!K&&B?.transform){let ee=B.transform.position,j=B.transform.matrix,Q=ee?.x??(j?j[12]:0),se=ee?.y??(j?j[13]:0),oe=ee?.z??(j?j[14]:0),ce=j?-j[8]:0,ue=j?-j[10]:-1,le=Math.hypot(ce,ue);le>1e-4?(ce/=le,ue/=le):(ce=0,ue=-1),L=[Q+ce*1.2,se-.25,oe+ue*1.2],te=Math.atan2(-ce,-ue),K=!0}if(S&&typeof g.getHitTestResults=="function"&&(!this.placed||ie)){let ee=g.getHitTestResults(S)||[],j=!1;for(let Q of ee){let se=Q.getPose(D);if(se?.transform?.matrix){let oe=se.transform.matrix,ce=oe[5];if(i.arPlacement==="wall"&&Math.abs(ce)>.35||i.arPlacement==="floor"&&Math.abs(ce)<.65)continue;v||(v=new Float32Array(16)),v.set(oe),G=[oe[12],oe[13],oe[14]],this.placed&&ie&&(U=[oe[12],oe[13],oe[14]]),_&&(_.visible=!this.placed||ie,_.transform.set(oe)),!this.placed&&A&&(A.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(v),j=!0;break}}!j&&_&&(_.visible=!1)}Do(q,this.placed?U:G||L,b,te,h*Y),this.placed&&this.placedMat.set(q);let w=e.xrRigMatrix;w instanceof Float32Array&&w.length===16?Ee(W,w,q):W.set(q),e.modelRootMatrix&&e.modelRootMatrix.set(W);for(let ee of Ie)ee.onXRFrame?.(e,k,g,D);let F=e.getGLContext?.()||e?.gl,H=k.renderState?.baseLayer;F&&H&&H.framebuffer!==void 0&&F.bindFramebuffer(36160,H.framebuffer);let J=d==="immersive-ar",Z=C.views||[];for(let ee=0;ee<Z.length;ee++){let j=Z[ee];if(typeof e.renderXRView=="function"){let Q;if(H&&typeof H.getViewport=="function"){let se=H.getViewport(j);se&&se.width>0&&se.height>0&&(Q=[se.x,se.y,se.width,se.height])}else H?.framebufferWidth>0&&H?.framebufferHeight>0&&(Q=[0,0,H.framebufferWidth,H.framebufferHeight]);e.renderXRView(j,W,this.placed,Q,J,ee)}}F&&H&&H.framebuffer&&F.bindFramebuffer(36160,null)};k.requestAnimationFrame(V)}catch(M){throw typeof k.end=="function"&&await k.end().catch(()=>{}),X(),i.onError?.(M),M}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function mr(t){let e=await lr(),n=t.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let c of n)if(e.availableModes.includes(c)){r=c;break}if(r||(r=e.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let i={...t.quickLookOptions,allowScale:t.arScale==="fixed"?!1:t.quickLookOptions?.allowScale},o={...t.sceneViewerOptions,resizable:t.arScale==="fixed"?!1:t.sceneViewerOptions?.resizable,enableVerticalPlacement:t.arPlacement==="wall"?!0:t.sceneViewerOptions?.enableVerticalPlacement},s={...t.webXROptions,arScale:t.arScale||t.webXROptions?.arScale,arPlacement:t.arPlacement||t.webXROptions?.arPlacement};try{if(r==="quick-look"){let c;if(t.model instanceof Blob&&t.model.type==="model/vnd.usdz+zip")c=t.model;else{if(typeof t.model=="string")return Po(t.model,i),{mode:"quick-look",success:!0};c=Vt(t.model)}return Po(c,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let c=t.glbUrl||(typeof t.model=="string"?t.model:null);if(!c)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Js(c,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!t.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let c=new ni(s);return await c.start(t.view,t.element),{mode:"webxr",success:!0,session:c}}}catch(c){return{mode:r,success:!1,error:c}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}Je.registerAR({activateAR:mr,createUSDZBlob:Vt});Je.registerScriptRunner(Gt);Pe(fn);var si=new WeakMap;function fr(t,e){let n=e instanceof Float32Array?e:new Float32Array(e);si.set(t,n)}function Oo(t){return si.get(t)}async function ta(t,e){if(!e)return null;let n;if(typeof e=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let o=await(await fetch(e)).blob();n=await createImageBitmap(o)}else if(typeof Image<"u")n=await new Promise((i,o)=>{let s=new Image;s.crossOrigin="anonymous",s.onload=()=>i(s),s.onerror=o,s.src=e});else return null;else n=e;let r=t.createTexture();return t.bindTexture(3553,r),t.texImage2D(3553,0,6408,6408,5121,n),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553),r}var No=new WeakMap,Fo=new Float32Array(16);async function Uo(t,e,n){let r=n?await ta(t.gl,n):null;t[e]&&t.gl.deleteTexture(t[e]),t[e]=r}var ai={name:"environment-map",setEnvironmentImage(t,e){return Uo(t,"environmentTexture",e)},setSkyboxImage(t,e){return Uo(t,"skyboxTexture",e)},onBeforeDrawScene(t,e,n,r,i){if(!t.skyboxTexture||typeof e.createProgram!="function")return;let o=No.get(e);if(!o){let m=(b,d)=>{let p=e.createShader(b);return e.shaderSource(p,d),e.compileShader(p),p},f=e.createProgram();e.attachShader(f,m(35633,`#version 300 es
330
+ out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),e.attachShader(f,m(35632,`#version 300 es
331
+ precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),e.linkProgram(f);let h=typeof e.createVertexArray=="function"?e.createVertexArray():null;o={program:f,vao:h},No.set(e,o)}let s=An(Fo,n)||Fo;e.depthMask(!1),e.useProgram(o.program),o.vao&&e.bindVertexArray(o.vao),e.activeTexture(33984),e.bindTexture(3553,t.skyboxTexture);let c=e.getUniformLocation(o.program,"uSkyboxMap");c&&e.uniform1i(c,0);let a=e.getUniformLocation(o.program,"uInvVP");a&&e.uniformMatrix4fv(a,!1,s);let u=e.getUniformLocation(o.program,"uCameraPos");u&&e.uniform3f(u,r[0],r[1],r[2]);let l=e.getUniformLocation(o.program,"uExposure");l&&e.uniform1f(l,t.exposure??1),e.drawArrays(4,0,3),e.depthMask(!0)},onResolveShader(t,e,n,r){if(r.includes("evalSHIrradiance"))return null;let i=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
305
332
  uniform int uHasSH;
306
333
  out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
307
334
  vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
@@ -314,14 +341,90 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
314
341
  }else if(uHasSH==1){
315
342
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
316
343
  envDiffuse=evalSHIrradiance(N);
317
- }`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=jn.get(t),l=t.getUniformLocation(e,"uHasSH");if(a&&a.length>=27){l&&t.uniform1i(l,1);let c=t.getUniformLocation(e,"uSH");c&&t.uniform3fv(c,a)}else l&&t.uniform1i(l,0)},onAttributeChanged(t,e,n,r){e==="environment-image"&&t.viewer?this.setEnvironmentImage?.(t.viewer,r):e==="skybox-image"&&t.viewer&&this.setSkyboxImage?.(t.viewer,r)}};var Zn=new WeakMap;function Jn(t,e){let n=e||t.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=t.mockHotspots||t.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let i=0;i<r.length;i++){let o=r[i],a=o.getAttribute("data-position");if(!a)continue;let l=a.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(l.length<3||l.some(isNaN))continue;let c=o.getAttribute("data-normal"),s;if(c){let m=c.trim().split(/\s+/).map(h=>parseFloat(h));m.length>=3&&!m.some(isNaN)&&(s=[m[0],m[1],m[2]])}let u=n.projectPointToScreen([l[0],l[1],l[2]],s);o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.transform=`translate(-50%, -50%) translate3d(${u.x}px, ${u.y}px, 0)`,o.style.zIndex="3",u.visible?(o.style.opacity="1",o.style.pointerEvents="auto",o.removeAttribute("data-occluded")):(o.style.opacity="0",o.style.pointerEvents="none",o.setAttribute("data-occluded",""))}}var Qn={name:"hotspots",updateHotspotsForElement:Jn,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{Jn(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Zn.set(t,e)},onCameraChange(t,e){e&&Jn(e,t)},onElementDisconnected(t){let e=Zn.get(t);e&&(e.disconnect(),Zn.delete(t))}};var ni=1024,er=256,xn=2048,Ji=128,Qi=64,eo=16,to=1e4,no=8,Ne=new Set(["__proto__","constructor","prototype"]),ri={neg:t=>-t,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:t=>t-Math.floor(t),sqrt:t=>Math.sqrt(Math.max(0,t)),cbrt:Math.cbrt,exp:Math.exp,log:t=>t>0?Math.log(t):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:t=>Math.asin(Math.max(-1,Math.min(1,t))),acos:t=>Math.acos(Math.max(-1,Math.min(1,t))),atan:Math.atan,rad:t=>t*Math.PI/180,deg:t=>t*180/Math.PI,saturate:t=>Math.max(0,Math.min(1,t))},ii={add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>Math.abs(e)<1e-12?0:t/e,rem:(t,e)=>Math.abs(e)<1e-12?0:t%e,mod:(t,e)=>Math.abs(e)<1e-12?0:t%e,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},vn={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},wn=(t,e)=>t!==null&&typeof t=="object"&&!Ne.has(e)&&Object.prototype.hasOwnProperty.call(t,e),Se=t=>Array.isArray(t)?[...t]:t,ci=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&wn(t,"value")?t.value:t,oe=(t,e)=>wn(t.configuration,e)?ci(t.configuration[e]):void 0,W=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Ge=t=>Math.max(0,Math.min(1,t)),Me=t=>typeof t=="boolean"?t:typeof t=="number"?t!==0&&!Number.isNaN(t):typeof t=="string"?t.length>0&&t!=="false":!!t;function Rt(t){if(typeof t!="string"||!t.startsWith("/"))return null;let e=[];for(let n of t.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||Ne.has(r)||Ne.has(n))return null;e.push(r)}return{segments:e}}var rt=(t,e)=>{if(t===void 0||!/^\d+$/.test(t))return-1;let n=Number(t);return Number.isSafeInteger(n)&&n>=0&&n<e?n:-1},oi=t=>{let e=W(t[0]),n=W(t[1]),r=W(t[2]),i=W(t[3],1),o=Math.hypot(e,n,r,i);return o>1e-8?[e/o,n/o,r/o,i/o]:[0,0,0,1]},si=(t,e,n,r)=>{if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(Array.isArray(t)&&Array.isArray(e)){if(r&&t.length===4&&e.length===4){let i=[0,0,0,1];return yn(i,oi(t),oi(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},tr=(t,e,n)=>Array.isArray(t)&&Array.isArray(e)?t.slice(0,e.length).map((r,i)=>n(W(r),W(e[i]))):Array.isArray(t)?t.map(r=>n(W(r),W(e))):Array.isArray(e)?e.map(r=>n(W(t),W(r))):n(W(t),W(e)),ro=(t,e)=>Array.isArray(t)?t.map(n=>e(W(n))):e(W(t)),ai=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((n,r)=>Math.abs(n-e[r])<=1e-6):t===e,Tt=class{constructor(e,n,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>ni)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ni})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>er)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${er})`);let a=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],c=new Map,s=new Map,u=new Map,m=new Map,h=new Map,f=new Map,d=[],p=[],x=new Map,P=1,E=0,y=0,v=0,g=0,L=!1,b=!1,w=!1;o.forEach((T,A)=>{if(!T||typeof T!="object")return;let S=Se(ci(T.value));c.set(A,S);let k=T.id??T.name;typeof k=="string"&&k&&!Ne.has(k)&&c.set(k,S)}),(n?.nodes||[]).forEach((T,A)=>{for(let S of T?.children||[])typeof S=="number"&&x.set(S,A)});let R=T=>T.op||typeof T.declaration=="number"&&a[T.declaration]?.op||"",_=(T,A,S)=>{if(Ne.has(A))return;let k=s.get(T);k||s.set(T,k=Object.create(null)),k[A]=S},B=(T,A)=>{if(typeof T!="number"&&typeof T!="string"||typeof T=="string"&&Ne.has(T)||!c.has(T)&&c.size>=er*2)return;let S=Se(A);if(c.set(T,S),typeof T=="number"){let k=o[T]?.id??o[T]?.name;typeof k=="string"&&!Ne.has(k)&&c.set(k,S)}},z=T=>typeof T=="number"?l[T]?.id??String(T):typeof T=="string"?/^\d+$/.test(T)&&l[Number(T)]?.id?l[Number(T)].id:T:"",I=(T,A)=>{for(let S=T,k=0;S!==void 0&&S>=0&&k<128;S=x.get(S),k++)if(S===A)return!0;return!1},C=T=>{for(let A=d.length-1;A>=0;A--)d[A].key===T&&d.splice(A,1)},G=T=>{C(T.key),d.length>=Ji&&d.shift(),d.push(T)},V=T=>{let A=Rt(T)?.segments;if(A){if(A[0]==="nodes"&&Array.isArray(n?.nodes)){let S=n.nodes[rt(A[1],n.nodes.length)];if(!S)return;let k=A[2];if(k in vn){let M=vn[k],D=S[k]||M;return M.map((F,U)=>W(D[U],F))}if(k==="weights"){let M=Array.isArray(S.weights)?S.weights:[0],D=A.length===4?rt(A[3],64):-2;return D===-2?M.map(F=>W(F)):D>=0?W(M[D]):void 0}if(k==="visible"||k==="extensions"&&A[3]==="KHR_node_visibility"&&A[4]==="visible")return S.extensions?.KHR_node_visibility?.visible??S.visible??!0}else if(A[0]==="materials"&&Array.isArray(n?.materials)){let S=n.materials[rt(A[1],n.materials.length)];if(!S)return;let k=S.pbrMetallicRoughness||{};if(A[2]==="pbrMetallicRoughness"){if(A[3]==="baseColorFactor"){let M=k.baseColorFactor||[1,1,1,1];return[W(M[0],1),W(M[1],1),W(M[2],1),W(M[3],1)]}if(A[3]==="metallicFactor"||A[3]==="roughnessFactor")return W(k[A[3]],1)}if(A[2]==="emissiveFactor"){let M=S.emissiveFactor||[0,0,0];return[W(M[0]),W(M[1]),W(M[2])]}if(A[2]==="alphaCutoff")return W(S.alphaCutoff,.5)}}},J=(T,A)=>{let S=Rt(T)?.segments;if(!S)return!1;if(S[0]==="nodes"&&Array.isArray(n?.nodes)){let k=rt(S[1],n.nodes.length),M=n.nodes[k];if(!M)return!1;let D=S[2];if(D in vn&&Array.isArray(A)){let F=vn[D];if(A.length<F.length)return!1;let U=F.map((Z,Q)=>W(A[Q],Z));if(D==="rotation"){let Z=Math.hypot(...U);U=Z>1e-8?U.map(Q=>Q/Z):[0,0,0,1]}M[D]=U,delete M.matrix;let K=e?.initialNodeTransforms?.[k];return K&&(K[D[0]]=[...U]),L=!0,!0}if(D==="weights"){Array.isArray(M.weights)||(M.weights=[]);let F=(U,K)=>{for(let Z of e?.meshes||[])if(Z.nodeIndex===k)for(let Q of Z.primitives||[])Q.pluginData?.morph?.weights&&(Q.pluginData.morph.weights[U]=K)};if(S.length===4){let U=rt(S[3],64);if(U<0)return!1;F(U,M.weights[U]=W(A))}else if(Array.isArray(A))M.weights=A.slice(0,64).map(U=>W(U)),M.weights.forEach((U,K)=>F(K,U));else return!1;return w=!0,!0}if(D==="visible"||D==="extensions"&&S[3]==="KHR_node_visibility"&&S[4]==="visible"){let F=Me(A);return M.visible=F,(!M.extensions||typeof M.extensions!="object")&&(M.extensions={}),M.extensions.KHR_node_visibility={visible:F},b=!0,!0}}else if(S[0]==="materials"&&Array.isArray(n?.materials)){let k=rt(S[1],n.materials.length),M=n.materials[k];if(!M)return!1;let D=M.pbrMetallicRoughness||(M.pbrMetallicRoughness={}),F=U=>{for(let K of e?.meshes||[])for(let Z of K.primitives||[])(Z.materialIndex??0)===k&&U(Z)};if(S[2]==="pbrMetallicRoughness"){if(S[3]==="baseColorFactor"&&Array.isArray(A)&&A.length>=3){let U=[Ge(W(A[0],1)),Ge(W(A[1],1)),Ge(W(A[2],1)),A[3]!==void 0?Ge(W(A[3],1)):D.baseColorFactor?.[3]??1];return D.baseColorFactor=U,F(K=>K.baseColor=[...U]),w=!0}if(S[3]==="metallicFactor"||S[3]==="roughnessFactor"){let U=S[3]==="metallicFactor",K=Ge(W(A,U?0:.5));return D[S[3]]=K,F(Z=>Z[U?"metallic":"roughness"]=K),w=!0}}if(S[2]==="emissiveFactor"&&Array.isArray(A)&&A.length>=3)return M.emissiveFactor=[0,1,2].map(U=>Math.max(0,W(A[U]))),w=!0;if(S[2]==="alphaCutoff")return M.alphaCutoff=Ge(W(A,.5)),w=!0}return!1},j=(T,A,S=new Set)=>{let k=oe(A,"pointer");if(typeof k!="string"||!k.startsWith("/"))return null;let M=k.replace(/\{([a-zA-Z0-9_]+)\}/g,(D,F)=>{let U=Math.trunc(Number(H(T,F,void 0,S)??oe(A,F)));return Number.isSafeInteger(U)&&U>=0?String(U):"-1"});return Rt(M)?M:null},H=(T,A,S,k)=>{let M=i[T]?.values;if(!wn(M,A))return S;let D=M[A];if(D==null)return S;if(typeof D!="object"||Array.isArray(D))return Se(D);let F=D;return typeof F.node=="number"?X(F.node,F.socket||"value",k):wn(F,"value")?Se(F.value):S},X=(T,A,S)=>{if(T<0||T>=i.length||S.has(T)||S.size>128||++v>to)return;let k=i[T],M=R(k);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(M))return Se(s.get(T)?.[A]);S.add(T);try{let D=(F,U=0)=>H(T,F,U,S);if(M==="variable/get"){let F=oe(k,"variable")??oe(k,"id");return typeof F=="number"||typeof F=="string"?Se(c.get(F)):void 0}if(M==="pointer/get"){let F=j(T,k,S);return F?V(F):void 0}if(M.startsWith("math/")){let F=M.slice(5);if(F in ri)return ro(D("a"),ri[F]);if(F in ii){let U=/^(mul|div|rem|mod|pow)$/.test(F)?1:0;return tr(D("a",F==="mul"?1:0),D("b",U),ii[F])}if(F==="pi")return Math.PI;if(F==="e")return Math.E;if(F==="random")return Math.random();if(F==="clamp")return tr(tr(D("a"),D("b",D("min",0)),Math.max),D("c",D("max",1)),Math.min);if(F==="mix"||F==="quatSlerp")return si(D("a",0),D("b",1),W(D("c",D("t",.5)),.5),F==="quatSlerp");if(F==="dot"){let U=D("a"),K=D("b");return Array.isArray(U)&&Array.isArray(K)?U.reduce((Z,Q,O)=>Z+(Q||0)*(K[O]||0),0):W(U)*W(K)}if(F==="cross"){let U=D("a",[0,0,0]),K=D("b",[0,0,0]);return Array.isArray(U)&&Array.isArray(K)?[(U[1]||0)*(K[2]||0)-(U[2]||0)*(K[1]||0),(U[2]||0)*(K[0]||0)-(U[0]||0)*(K[2]||0),(U[0]||0)*(K[1]||0)-(U[1]||0)*(K[0]||0)]:[0,0,0]}if(F==="length"){let U=D("a");return Array.isArray(U)?Math.hypot(...U):Math.abs(W(U))}if(F==="distance"){let U=D("a"),K=D("b");return Array.isArray(U)&&Array.isArray(K)?Math.hypot(...U.map((Z,Q)=>(Z||0)-(K[Q]||0))):Math.abs(W(U)-W(K))}if(F==="normalize"){let U=D("a");if(!Array.isArray(U))return W(U)>=0?1:-1;let K=Math.hypot(...U);return K>1e-8?U.map(Z=>Z/K):U.map(()=>0)}if(F.startsWith("combine"))return["a","b","c","d"].slice(0,Number(F[7])||2).map(U=>W(D(U)));if(F.startsWith("extract")){let U=D("a");return Array.isArray(U)?U[A==="0"||A==="x"?0:A==="1"||A==="y"?1:A==="2"||A==="z"?2:3]??0:0}if(F==="eq")return ai(D("a"),D("b"));if(F==="ne")return!ai(D("a"),D("b"));if(F==="lt")return W(D("a"))<W(D("b"));if(F==="le")return W(D("a"))<=W(D("b"));if(F==="gt")return W(D("a"))>W(D("b"));if(F==="ge")return W(D("a"))>=W(D("b"));if(F==="isNaN")return Number.isNaN(Number(D("a")));if(F==="isInf"){let U=Number(D("a"));return!Number.isFinite(U)&&!Number.isNaN(U)}return F==="and"?Me(D("a",!1))&&Me(D("b",!1)):F==="or"?Me(D("a",!1))||Me(D("b",!1)):F==="xor"?Me(D("a",!1))!==Me(D("b",!1)):F==="not"?!Me(D("a",!1)):F==="select"?Se(Me(D("condition",!1))?D("a"):D("b")):void 0}return M==="type/boolToInt"||M==="type/boolToFloat"?Me(D("a",!1))?1:0:M==="type/intToBool"||M==="type/floatToBool"?W(D("a",0))!==0:M==="type/intToFloat"?W(D("a",0)):M==="type/floatToInt"?Math.trunc(W(D("a",0))):void 0}finally{S.delete(T)}},N=()=>{if(L){L=!1,w=!0;let T=Fe(n);if(e){e.worldMatrices=T;for(let A of e.meshes||[])A.nodeIndex>=0&&A.nodeIndex<T.length&&(A.transform.set(T[A.nodeIndex]),de(A.normalMatrix,A.transform))}}if(b){b=!1,w=!0;let T=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(T))for(let A of e.meshes){let S=!0;for(let k=A.nodeIndex,M=0;k!==void 0&&k>=0&&M<128;k=x.get(k),M++){let D=T[k];if(D?.visible===!1||D?.extensions?.KHR_node_visibility?.visible===!1){S=!1;break}}A.visible=S}}w&&(w=!1,e?.render?.())},$=(T,A={steps:0})=>{if(!T||typeof T.node!="number")return;A.steps===0&&(v=0);let S=[T],k=M=>{S.length+A.steps<xn&&S.push(M)};for(;S.length>0&&A.steps<xn;){A.steps++;let M=S.shift();if(!M||M.node<0||M.node>=i.length)continue;let D=M.node,F=i[D];if(!F)continue;let U=M.socket||"in",K=R(F),Z=(O,q=void 0)=>H(D,O,q,new Set),Q=(O="out")=>{let q=F.flows?.[O];q&&k(q)};switch(K){case"flow/branch":Q(Me(Z("condition",!1))?"true":"false");break;case"flow/sequence":for(let O of Object.keys(F.flows||{}).sort((q,ee)=>Number(q)-Number(ee)||q.localeCompare(ee)))Q(O);break;case"flow/switch":{let O=F.flows?.[String(Z("selection",Z("value",0)))]??F.flows?.default;O&&k(O);break}case"flow/for":{let O=Math.trunc(W(Z("startIndex",0))),q=Math.trunc(W(Z("endIndex",0))),ee=Math.max(1,Math.trunc(W(Z("step",1),1))),ae=F.flows?.body;if(ae&&q>O&&g<no){let pe=Math.min(Math.ceil((q-O)/ee),xn);g++;try{for(let ce=0;ce<pe&&A.steps<xn;ce++)_(D,"index",O+ce*ee),$(ae,A)}finally{g--}}let Ve=F.flows?.completed??F.flows?.out;Ve&&k(Ve);break}case"flow/doN":{let O=U==="reset"?0:(u.get(D)||0)+1;if(u.set(D,O),_(D,"currentCount",O),_(D,"count",O),U!=="reset"){let q=Math.trunc(W(Z("n",oe(F,"stopIterations")??oe(F,"n")??1),1));O<=q&&Q()}break}case"flow/multiGate":{if(U==="reset"){f.set(D,0);break}let O=Object.keys(F.flows||{}).sort();if(!O.length)break;let q=oe(F,"isRandom")?Math.floor(Math.random()*O.length):f.get(D)||0;q<O.length&&(Q(O[q]),f.set(D,oe(F,"isLoop")!==!1?(q+1)%O.length:q+1));break}case"flow/waitAll":{if(U==="reset"){m.delete(D);break}let O=m.get(D);O||m.set(D,O=new Set),O.add(U),O.size>=Math.max(1,Math.trunc(Number(oe(F,"inputFlows")??2)||2))&&(O.clear(),Q("out"),Q("completed"));break}case"flow/throttle":{if(U==="reset"){h.delete(D);break}let O=Math.max(0,W(Z("duration",0))),q=h.get(D);q===void 0||E-q>=O?(h.set(D,E),_(D,"lastRemainingTime",0),Q()):_(D,"lastRemainingTime",Math.max(0,O-(E-q)));break}case"flow/delay":case"flow/setDelay":{if(U==="cancel"){for(let ae=p.length-1;ae>=0;ae--)p[ae].nodeIdx===D&&p.splice(ae,1);_(D,"lastDelayIndex",-1);break}let O=Math.max(0,W(Z("duration",oe(F,"duration")??0))),q=F.flows?.done??F.flows?.out;if(O<=0){_(D,"lastDelayIndex",-1),q&&k(q);break}p.length>=Qi&&p.shift();let ee=P++;_(D,"lastDelayIndex",ee),p.push({id:ee,nodeIdx:D,rem:O,done:q}),K==="flow/setDelay"&&F.flows?.out&&F.flows?.done&&Q("out");break}case"flow/cancelDelay":{let O=Math.trunc(W(Z("delayIndex",-1),-1));if(O<0)p.length=0;else for(let q=p.length-1;q>=0;q--)p[q].id===O&&p.splice(q,1);Q();break}case"variable/set":B(oe(F,"variable")??oe(F,"id"),Z("value")),Q();break;case"variable/interpolate":{let O=oe(F,"variable")??oe(F,"id"),q=Z("value",Z("target")),ee=Math.max(0,W(Z("duration",oe(F,"duration")??.3),.3));O!==void 0&&q!==void 0&&G({key:`var:${String(O)}`,varKey:O,from:Se(Z("from")??c.get(O)??0),to:Se(q),dur:ee,elapsed:0,quat:!1,linear:oe(F,"easing")==="linear",done:F.flows?.done}),Q();break}case"pointer/set":{let O=j(D,F),q=Z("value");O&&q!==void 0&&(C(`ptr:${O}`),J(O,q)),Q();break}case"pointer/interpolate":{let O=j(D,F),q=Z("value",Z("target")),ee=Math.max(0,W(Z("duration",oe(F,"duration")??.3),.3));if(O&&q!==void 0){let ae=Z("from")??V(O);ae!==void 0&&(ee<=0?(J(O,q),Q("done")):G({key:`ptr:${O}`,ptr:O,from:Se(ae),to:Se(q),dur:ee,elapsed:0,quat:O.endsWith("/rotation"),linear:oe(F,"easing")==="linear",done:F.flows?.done}))}Q();break}case"animation/start":{let O=Z("animation")??oe(F,"animation")??oe(F,"clipName"),q=typeof O=="number"?e?.animations?.[O]?.name??n?.animations?.[O]?.name:typeof O=="string"?O:void 0;e?.playAnimation?.(q),w=!0,Q();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),K==="animation/resetAt"&&e?.evaluateAnimation?.(W(Z("time",0))),w=!0,Q();break;case"event/send":case"customEvent/send":{let O=z(oe(F,"event")??oe(F,"id")),q={};for(let ee of Object.keys(F.values||{}))Ne.has(ee)||(q[ee]=Z(ee));O&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:O,values:q}})),Y(O,q,A)),Q();break}default:Q();break}}};this.readScenePointer=V,this.writeScenePointer=J,this.fireOnStart=()=>{i.forEach(T=>{R(T)==="event/onStart"&&$(T.flows?.out)}),N()},this.fireOnSelect=T=>{if(!T)return;let A=typeof T.meshIndex=="number"?T.meshIndex:-1,S=typeof T.nodeIndex=="number"?T.nodeIndex:e?.meshes?.[A]?.nodeIndex??-1;i.forEach((k,M)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(R(k)))return;let D=oe(k,"nodeIndex")??oe(k,"node")??H(M,"nodeIndex",void 0,new Set),F=oe(k,"meshName");if(typeof F=="string"&&F?T.meshName===F:D==null||Number(D)<0||Number.isNaN(Number(D))||I(S,Math.trunc(Number(D)))){if(_(M,"nodeIndex",S),_(M,"meshIndex",A),Array.isArray(T.hitPoint)){let K=[W(T.hitPoint[0]),W(T.hitPoint[1]),W(T.hitPoint[2])];_(M,"hitPoint",K),_(M,"point",K),_(M,"intersectionPoint",K)}if(Array.isArray(T.normal)){let K=[W(T.normal[0]),W(T.normal[1],1),W(T.normal[2])];_(M,"normal",K),_(M,"hitNormal",K)}typeof T.distance=="number"&&_(M,"distance",T.distance),$(k.flows?.out)}}),N()},this.receiveCustomEvent=(T,A={})=>Y(T,A,{steps:0});function Y(T,A,S){if(!(y>=eo)){y++;try{let k=z(T);i.forEach((M,D)=>{if(!/^(customE|e)vent\/receive$/.test(R(M)))return;let F=oe(M,"event")??oe(M,"id");if(!(z(F)!==k&&String(F)!==String(T))){for(let[U,K]of Object.entries(A))Ne.has(U)||_(D,U,Se(K));$(M.flows?.out,S)}}),N()}finally{y--}}}this.tick=T=>{if(!Number.isFinite(T)||T<0)return;let A=Math.min(T,.25);E+=A,i.forEach((k,M)=>{R(k)==="event/onTick"&&(_(M,"timeDelta",A),_(M,"dt",A),_(M,"timeElapsed",E),$(k.flows?.out))});let S=[];for(let k=d.length-1;k>=0;k--){let M=d[k];M.elapsed+=A;let D=M.dur>1e-6?Ge(M.elapsed/M.dur):1,F=M.linear?D:D*D*(3-2*D),U=si(M.from,M.to,F,M.quat);M.ptr?J(M.ptr,U):M.varKey!==void 0&&B(M.varKey,U),D>=1&&(d.splice(k,1),M.done&&S.push(M.done))}for(let k=p.length-1;k>=0;k--){let M=p[k];M.rem-=A,M.rem<=0&&(p.splice(k,1),M.done&&S.push(M.done))}for(let k of S)$(k);N()},this.dispose=()=>{d.length=0,p.length=0,c.clear(),s.clear(),u.clear(),m.clear(),h.clear(),f.clear()}}},Le=new WeakMap,An=new WeakMap;function io(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||It().some(l=>l.name==="xr-live-head-follow"))return;let n=t.gltf,r=n?.nodes;if(!Array.isArray(r)||r.length===0)return;let i=Math.min(e,.1),o=(An.get(t)||0)+i,a=!1;for(let l=0;l<r.length;l++){let c=r[l],s=Pr(c?.extras?.xr?.orbit);if(!s)continue;let u=0,m=0,h=0;if(Array.isArray(s.target))u=s.target[0],m=s.target[1],h=s.target[2];else if(typeof s.target=="string"&&s.target!=="head"){let P=r.find(E=>E?.name===s.target);Array.isArray(P?.translation)&&(u=W(P.translation[0]),m=W(P.translation[1]),h=W(P.translation[2]))}let f=s.phase+s.speed*o,d=u+Math.cos(f)*s.radius,p=m+s.height,x=h+Math.sin(f)*s.radius;if(c.translation=[d,p,x],s.faceCenter){let P=Math.atan2(u-d,h-x);c.rotation=[0,Math.sin(P*.5),0,Math.cos(P*.5)]}a=!0}if(a){An.set(t,o);let l=Fe(n);t.worldMatrices=l;for(let c of t.meshes||[])c.nodeIndex>=0&&c.nodeIndex<l.length&&(c.transform.set(l[c.nodeIndex]),de(c.normalMatrix,c.transform))}}function Sn(t){if(!(!t||typeof t!="object"))return Le.get(t)||Le.get(t.viewer)||Le.get(t._view)}function nr(t,e,n){let r=Sn(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var rr={name:"khr-interactivity",sendInteractivityEvent:nr,getInteractivityVM:Sn,onLoadModel(t,e){if(!t||typeof t!="object")return;Le.get(t)?.dispose(),Le.delete(t),An.delete(t);let n=e?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let i=new Tt(t,e,r);Le.set(t,i),i.fireOnStart()},onMeshSelect(t,e){Le.get(t)?.fireOnSelect(e)},onUpdate(t,e){Le.get(t)?.tick(e),io(t,e)},onDestroy(t,e){Le.get(e)?.dispose(),Le.delete(e),An.delete(e)}};var Mt=new Map,ir=new WeakMap;function ui(t,e){Mt.set(t,e)}var or={name:"materials",onBuildPrimitiveVAO(t,e,n,r,i){return(((r?.materials&&n.material!==void 0?r.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(t,e){let n=ir.get(t);n||(n=t.createTexture(),ir.set(t,n));let r=Math.max(1,e.canvas.width),i=Math.max(1,e.canvas.height);t.activeTexture(33990),t.bindTexture(3553,n),t.copyTexImage2D(3553,0,6408,0,0,r,i,0),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553)},onResolveShader(t,e,n,r){if(!e)return null;if(e.name&&Mt.has(e.name)){let d=Mt.get(e.name);return{vs:d.vs||n,fs:d.fs||r}}let i=e.extensions||{},o=i.KHR_materials_clearcoat,a=i.KHR_materials_sheen,l=!!i.KHR_materials_transmission,c=!!i.KHR_materials_ior,s=i.KHR_materials_iridescence;if(!o&&!a&&!i.KHR_materials_unlit&&!l&&!i.KHR_materials_volume&&!c&&!i.KHR_materials_dispersion&&!s)return null;if(i.KHR_materials_unlit)return{vs:n,fs:r.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let u=r;if(l){let d=u.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
318
- `;u=u.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
319
- ${d}out vec4 fragColor;`)}let m=(d,p,x=0,P=1e6,E=3)=>{let y=Number(d);return(Number.isFinite(y)?Math.min(P,Math.max(x,y)):p).toFixed(E)},h=Number(i.KHR_materials_ior?.ior??1.5),f=Number.isFinite(h)?Math.min(10,Math.max(1,h)):1.5;if(c){let d=Math.pow((f-1)/(f+1),2);u=u.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(d,.04,0,1,4)}),base.rgb,metallic);`)}if(s){let d=m(s.iridescenceFactor,1,0,1),p=m(s.iridescenceIor,1.3,1,10);u=u.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${p}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${d}*pow(1.-NoV,2.));`)}if(l){let d=m(i.KHR_materials_transmission?.transmissionFactor,1,0,1),p=i.KHR_materials_volume||{},x=m(p.thicknessFactor,.5,0,1e4),P=m(p.attenuationDistance,1,.001,1e6),E=Array.isArray(p.attenuationColor)?p.attenuationColor:[1,1,1],y=m(i.KHR_materials_dispersion?.dispersion,0,0,10);u=u.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
320
- vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(f,1.5,1,10)},dV=${y},tV=${x},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
344
+ }`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let s=si.get(t),c=t.getUniformLocation(e,"uHasSH");if(s&&s.length>=27){c&&t.uniform1i(c,1);let a=t.getUniformLocation(e,"uSH");a&&t.uniform3fv(a,s)}else c&&t.uniform1i(c,0)},onAttributeChanged(t,e,n,r){e==="environment-image"&&t.viewer?this.setEnvironmentImage?.(t.viewer,r):e==="skybox-image"&&t.viewer&&this.setSkyboxImage?.(t.viewer,r)}};var ci=new WeakMap;function ui(t,e){let n=e||t.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=t.mockHotspots||t.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let i=0;i<r.length;i++){let o=r[i],s=o.getAttribute("data-position");if(!s)continue;let c=s.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(c.length<3||c.some(isNaN))continue;let a=o.getAttribute("data-normal"),u;if(a){let m=a.trim().split(/\s+/).map(f=>parseFloat(f));m.length>=3&&!m.some(isNaN)&&(u=[m[0],m[1],m[2]])}let l=n.projectPointToScreen([c[0],c[1],c[2]],u);o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.transform=`translate(-50%, -50%) translate3d(${l.x}px, ${l.y}px, 0)`,o.style.zIndex="3",l.visible?(o.style.opacity="1",o.style.pointerEvents="auto",o.removeAttribute("data-occluded")):(o.style.opacity="0",o.style.pointerEvents="none",o.setAttribute("data-occluded",""))}}var li={name:"hotspots",updateHotspotsForElement:ui,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{ui(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),ci.set(t,e)},onCameraChange(t,e){e&&ui(e,t)},onElementDisconnected(t){let e=ci.get(t);e&&(e.disconnect(),ci.delete(t))}};var Vo=1024,mi=256,hr=2048,na=128,ra=64,ia=16,oa=1e4,sa=8,at=new Set(["__proto__","constructor","prototype"]),Bo={neg:t=>-t,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:t=>t-Math.floor(t),sqrt:t=>Math.sqrt(Math.max(0,t)),cbrt:Math.cbrt,exp:Math.exp,log:t=>t>0?Math.log(t):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:t=>Math.asin(Math.max(-1,Math.min(1,t))),acos:t=>Math.acos(Math.max(-1,Math.min(1,t))),atan:Math.atan,rad:t=>t*Math.PI/180,deg:t=>t*180/Math.PI,saturate:t=>Math.max(0,Math.min(1,t))},zo={add:(t,e)=>t+e,sub:(t,e)=>t-e,mul:(t,e)=>t*e,div:(t,e)=>Math.abs(e)<1e-12?0:t/e,rem:(t,e)=>Math.abs(e)<1e-12?0:t%e,mod:(t,e)=>Math.abs(e)<1e-12?0:t%e,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},dr={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},pr=(t,e)=>t!==null&&typeof t=="object"&&!at.has(e)&&Object.prototype.hasOwnProperty.call(t,e),We=t=>Array.isArray(t)?[...t]:t,Wo=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&pr(t,"value")?t.value:t,Re=(t,e)=>pr(t.configuration,e)?Wo(t.configuration[e]):void 0,ae=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Rt=t=>Math.max(0,Math.min(1,t)),Ye=t=>typeof t=="boolean"?t:typeof t=="number"?t!==0&&!Number.isNaN(t):typeof t=="string"?t.length>0&&t!=="false":!!t;function hn(t){if(typeof t!="string"||!t.startsWith("/"))return null;let e=[];for(let n of t.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||at.has(r)||at.has(n))return null;e.push(r)}return{segments:e}}var Ht=(t,e)=>{if(t===void 0||!/^\d+$/.test(t))return-1;let n=Number(t);return Number.isSafeInteger(n)&&n>=0&&n<e?n:-1},Go=t=>{let e=ae(t[0]),n=ae(t[1]),r=ae(t[2]),i=ae(t[3],1),o=Math.hypot(e,n,r,i);return o>1e-8?[e/o,n/o,r/o,i/o]:[0,0,0,1]},Xo=(t,e,n,r)=>{if(typeof t=="number"&&typeof e=="number")return t+(e-t)*n;if(Array.isArray(t)&&Array.isArray(e)){if(r&&t.length===4&&e.length===4){let i=[0,0,0,1];return ar(i,Go(t),Go(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},fi=(t,e,n)=>Array.isArray(t)&&Array.isArray(e)?t.slice(0,e.length).map((r,i)=>n(ae(r),ae(e[i]))):Array.isArray(t)?t.map(r=>n(ae(r),ae(e))):Array.isArray(e)?e.map(r=>n(ae(t),ae(r))):n(ae(t),ae(e)),aa=(t,e)=>Array.isArray(t)?t.map(n=>e(ae(n))):e(ae(t)),Ho=(t,e)=>Array.isArray(t)&&Array.isArray(e)?t.length===e.length&&t.every((n,r)=>Math.abs(n-e[r])<=1e-6):t===e,dn=class{constructor(e,n,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>Vo)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${Vo})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>mi)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${mi})`);let s=Array.isArray(r.declarations)?r.declarations:[],c=Array.isArray(r.events)?r.events:[],a=new Map,u=new Map,l=new Map,m=new Map,f=new Map,h=new Map,b=[],d=[],p=new Map,E=1,A=0,x=0,R=0,I=0,P=!1,k=!1,D=!1;o.forEach((O,X)=>{if(!O||typeof O!="object")return;let M=We(Wo(O.value));a.set(X,M);let N=O.id??O.name;typeof N=="string"&&N&&!at.has(N)&&a.set(N,M)}),(n?.nodes||[]).forEach((O,X)=>{for(let M of O?.children||[])typeof M=="number"&&p.set(M,X)});let S=O=>O.op||typeof O.declaration=="number"&&s[O.declaration]?.op||"",_=(O,X,M)=>{if(at.has(X))return;let N=u.get(O);N||u.set(O,N=Object.create(null)),N[X]=M},v=(O,X)=>{if(typeof O!="number"&&typeof O!="string"||typeof O=="string"&&at.has(O)||!a.has(O)&&a.size>=mi*2)return;let M=We(X);if(a.set(O,M),typeof O=="number"){let N=o[O]?.id??o[O]?.name;typeof N=="string"&&!at.has(N)&&a.set(N,M)}},G=O=>typeof O=="number"?c[O]?.id??String(O):typeof O=="string"?/^\d+$/.test(O)&&c[Number(O)]?.id?c[Number(O)].id:O:"",L=(O,X)=>{for(let M=O,N=0;M!==void 0&&M>=0&&N<128;M=p.get(M),N++)if(M===X)return!0;return!1},U=O=>{for(let X=b.length-1;X>=0;X--)b[X].key===O&&b.splice(X,1)},q=O=>{U(O.key),b.length>=na&&b.shift(),b.push(O)},W=O=>{let X=hn(O)?.segments;if(X){if(X[0]==="nodes"&&Array.isArray(n?.nodes)){let M=n.nodes[Ht(X[1],n.nodes.length)];if(!M)return;let N=X[2];if(N in dr){let z=dr[N],V=M[N]||z;return z.map((y,g)=>ae(V[g],y))}if(N==="weights"){let z=Array.isArray(M.weights)?M.weights:[0],V=X.length===4?Ht(X[3],64):-2;return V===-2?z.map(y=>ae(y)):V>=0?ae(z[V]):void 0}if(N==="visible"||N==="extensions"&&X[3]==="KHR_node_visibility"&&X[4]==="visible")return M.extensions?.KHR_node_visibility?.visible??M.visible??!0}else if(X[0]==="materials"&&Array.isArray(n?.materials)){let M=n.materials[Ht(X[1],n.materials.length)];if(!M)return;let N=M.pbrMetallicRoughness||{};if(X[2]==="pbrMetallicRoughness"){if(X[3]==="baseColorFactor"){let z=N.baseColorFactor||[1,1,1,1];return[ae(z[0],1),ae(z[1],1),ae(z[2],1),ae(z[3],1)]}if(X[3]==="metallicFactor"||X[3]==="roughnessFactor")return ae(N[X[3]],1)}if(X[2]==="emissiveFactor"){let z=M.emissiveFactor||[0,0,0];return[ae(z[0]),ae(z[1]),ae(z[2])]}if(X[2]==="alphaCutoff")return ae(M.alphaCutoff,.5)}}},K=(O,X)=>{let M=hn(O)?.segments;if(!M)return!1;if(M[0]==="nodes"&&Array.isArray(n?.nodes)){let N=Ht(M[1],n.nodes.length),z=n.nodes[N];if(!z)return!1;let V=M[2];if(V in dr&&Array.isArray(X)){let y=dr[V];if(X.length<y.length)return!1;let g=y.map((C,B)=>ae(X[B],C));if(V==="rotation"){let C=Math.hypot(...g);g=C>1e-8?g.map(B=>B/C):[0,0,0,1]}z[V]=g,delete z.matrix;let T=e?.initialNodeTransforms?.[N];return T&&(T[V[0]]=[...g]),P=!0,!0}if(V==="weights"){Array.isArray(z.weights)||(z.weights=[]);let y=(g,T)=>{for(let C of e?.meshes||[])if(C.nodeIndex===N)for(let B of C.primitives||[])B.pluginData?.morph?.weights&&(B.pluginData.morph.weights[g]=T)};if(M.length===4){let g=Ht(M[3],64);if(g<0)return!1;y(g,z.weights[g]=ae(X))}else if(Array.isArray(X))z.weights=X.slice(0,64).map(g=>ae(g)),z.weights.forEach((g,T)=>y(T,g));else return!1;return D=!0,!0}if(V==="visible"||V==="extensions"&&M[3]==="KHR_node_visibility"&&M[4]==="visible"){let y=Ye(X);return z.visible=y,(!z.extensions||typeof z.extensions!="object")&&(z.extensions={}),z.extensions.KHR_node_visibility={visible:y},k=!0,!0}}else if(M[0]==="materials"&&Array.isArray(n?.materials)){let N=Ht(M[1],n.materials.length),z=n.materials[N];if(!z)return!1;let V=z.pbrMetallicRoughness||(z.pbrMetallicRoughness={}),y=g=>{for(let T of e?.meshes||[])for(let C of T.primitives||[])(C.materialIndex??0)===N&&g(C)};if(M[2]==="pbrMetallicRoughness"){if(M[3]==="baseColorFactor"&&Array.isArray(X)&&X.length>=3){let g=[Rt(ae(X[0],1)),Rt(ae(X[1],1)),Rt(ae(X[2],1)),X[3]!==void 0?Rt(ae(X[3],1)):V.baseColorFactor?.[3]??1];return V.baseColorFactor=g,y(T=>T.baseColor=[...g]),D=!0}if(M[3]==="metallicFactor"||M[3]==="roughnessFactor"){let g=M[3]==="metallicFactor",T=Rt(ae(X,g?0:.5));return V[M[3]]=T,y(C=>C[g?"metallic":"roughness"]=T),D=!0}}if(M[2]==="emissiveFactor"&&Array.isArray(X)&&X.length>=3)return z.emissiveFactor=[0,1,2].map(g=>Math.max(0,ae(X[g]))),D=!0;if(M[2]==="alphaCutoff")return z.alphaCutoff=Rt(ae(X,.5)),D=!0}return!1},Y=(O,X,M=new Set)=>{let N=Re(X,"pointer");if(typeof N!="string"||!N.startsWith("/"))return null;let z=N.replace(/\{([a-zA-Z0-9_]+)\}/g,(V,y)=>{let g=Math.trunc(Number(te(O,y,void 0,M)??Re(X,y)));return Number.isSafeInteger(g)&&g>=0?String(g):"-1"});return hn(z)?z:null},te=(O,X,M,N)=>{let z=i[O]?.values;if(!pr(z,X))return M;let V=z[X];if(V==null)return M;if(typeof V!="object"||Array.isArray(V))return We(V);let y=V;return typeof y.node=="number"?ie(y.node,y.socket||"value",N):pr(y,"value")?We(y.value):M},ie=(O,X,M)=>{if(O<0||O>=i.length||M.has(O)||M.size>128||++R>oa)return;let N=i[O],z=S(N);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(z))return We(u.get(O)?.[X]);M.add(O);try{let V=(y,g=0)=>te(O,y,g,M);if(z==="variable/get"){let y=Re(N,"variable")??Re(N,"id");return typeof y=="number"||typeof y=="string"?We(a.get(y)):void 0}if(z==="pointer/get"){let y=Y(O,N,M);return y?W(y):void 0}if(z.startsWith("math/")){let y=z.slice(5);if(y in Bo)return aa(V("a"),Bo[y]);if(y in zo){let g=/^(mul|div|rem|mod|pow)$/.test(y)?1:0;return fi(V("a",y==="mul"?1:0),V("b",g),zo[y])}if(y==="pi")return Math.PI;if(y==="e")return Math.E;if(y==="random")return Math.random();if(y==="clamp")return fi(fi(V("a"),V("b",V("min",0)),Math.max),V("c",V("max",1)),Math.min);if(y==="mix"||y==="quatSlerp")return Xo(V("a",0),V("b",1),ae(V("c",V("t",.5)),.5),y==="quatSlerp");if(y==="dot"){let g=V("a"),T=V("b");return Array.isArray(g)&&Array.isArray(T)?g.reduce((C,B,w)=>C+(B||0)*(T[w]||0),0):ae(g)*ae(T)}if(y==="cross"){let g=V("a",[0,0,0]),T=V("b",[0,0,0]);return Array.isArray(g)&&Array.isArray(T)?[(g[1]||0)*(T[2]||0)-(g[2]||0)*(T[1]||0),(g[2]||0)*(T[0]||0)-(g[0]||0)*(T[2]||0),(g[0]||0)*(T[1]||0)-(g[1]||0)*(T[0]||0)]:[0,0,0]}if(y==="length"){let g=V("a");return Array.isArray(g)?Math.hypot(...g):Math.abs(ae(g))}if(y==="distance"){let g=V("a"),T=V("b");return Array.isArray(g)&&Array.isArray(T)?Math.hypot(...g.map((C,B)=>(C||0)-(T[B]||0))):Math.abs(ae(g)-ae(T))}if(y==="normalize"){let g=V("a");if(!Array.isArray(g))return ae(g)>=0?1:-1;let T=Math.hypot(...g);return T>1e-8?g.map(C=>C/T):g.map(()=>0)}if(y.startsWith("combine"))return["a","b","c","d"].slice(0,Number(y[7])||2).map(g=>ae(V(g)));if(y.startsWith("extract")){let g=V("a");return Array.isArray(g)?g[X==="0"||X==="x"?0:X==="1"||X==="y"?1:X==="2"||X==="z"?2:3]??0:0}if(y==="eq")return Ho(V("a"),V("b"));if(y==="ne")return!Ho(V("a"),V("b"));if(y==="lt")return ae(V("a"))<ae(V("b"));if(y==="le")return ae(V("a"))<=ae(V("b"));if(y==="gt")return ae(V("a"))>ae(V("b"));if(y==="ge")return ae(V("a"))>=ae(V("b"));if(y==="isNaN")return Number.isNaN(Number(V("a")));if(y==="isInf"){let g=Number(V("a"));return!Number.isFinite(g)&&!Number.isNaN(g)}return y==="and"?Ye(V("a",!1))&&Ye(V("b",!1)):y==="or"?Ye(V("a",!1))||Ye(V("b",!1)):y==="xor"?Ye(V("a",!1))!==Ye(V("b",!1)):y==="not"?!Ye(V("a",!1)):y==="select"?We(Ye(V("condition",!1))?V("a"):V("b")):void 0}return z==="type/boolToInt"||z==="type/boolToFloat"?Ye(V("a",!1))?1:0:z==="type/intToBool"||z==="type/floatToBool"?ae(V("a",0))!==0:z==="type/intToFloat"?ae(V("a",0)):z==="type/floatToInt"?Math.trunc(ae(V("a",0))):void 0}finally{M.delete(O)}},$=()=>{if(P){P=!1,D=!0;let O=it(n);if(e){e.worldMatrices=O;for(let X of e.meshes||[])X.nodeIndex>=0&&X.nodeIndex<O.length&&(X.transform.set(O[X.nodeIndex]),Le(X.normalMatrix,X.transform))}}if(k){k=!1,D=!0;let O=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(O))for(let X of e.meshes){let M=!0;for(let N=X.nodeIndex,z=0;N!==void 0&&N>=0&&z<128;N=p.get(N),z++){let V=O[N];if(V?.visible===!1||V?.extensions?.KHR_node_visibility?.visible===!1){M=!1;break}}X.visible=M}}D&&(D=!1,e?.render?.())},ne=(O,X={steps:0})=>{if(!O||typeof O.node!="number")return;X.steps===0&&(R=0);let M=[O],N=z=>{M.length+X.steps<hr&&M.push(z)};for(;M.length>0&&X.steps<hr;){X.steps++;let z=M.shift();if(!z||z.node<0||z.node>=i.length)continue;let V=z.node,y=i[V];if(!y)continue;let g=z.socket||"in",T=S(y),C=(w,F=void 0)=>te(V,w,F,new Set),B=(w="out")=>{let F=y.flows?.[w];F&&N(F)};switch(T){case"flow/branch":B(Ye(C("condition",!1))?"true":"false");break;case"flow/sequence":for(let w of Object.keys(y.flows||{}).sort((F,H)=>Number(F)-Number(H)||F.localeCompare(H)))B(w);break;case"flow/switch":{let w=y.flows?.[String(C("selection",C("value",0)))]??y.flows?.default;w&&N(w);break}case"flow/for":{let w=Math.trunc(ae(C("startIndex",0))),F=Math.trunc(ae(C("endIndex",0))),H=Math.max(1,Math.trunc(ae(C("step",1),1))),J=y.flows?.body;if(J&&F>w&&I<sa){let ee=Math.min(Math.ceil((F-w)/H),hr);I++;try{for(let j=0;j<ee&&X.steps<hr;j++)_(V,"index",w+j*H),ne(J,X)}finally{I--}}let Z=y.flows?.completed??y.flows?.out;Z&&N(Z);break}case"flow/doN":{let w=g==="reset"?0:(l.get(V)||0)+1;if(l.set(V,w),_(V,"currentCount",w),_(V,"count",w),g!=="reset"){let F=Math.trunc(ae(C("n",Re(y,"stopIterations")??Re(y,"n")??1),1));w<=F&&B()}break}case"flow/multiGate":{if(g==="reset"){h.set(V,0);break}let w=Object.keys(y.flows||{}).sort();if(!w.length)break;let F=Re(y,"isRandom")?Math.floor(Math.random()*w.length):h.get(V)||0;F<w.length&&(B(w[F]),h.set(V,Re(y,"isLoop")!==!1?(F+1)%w.length:F+1));break}case"flow/waitAll":{if(g==="reset"){m.delete(V);break}let w=m.get(V);w||m.set(V,w=new Set),w.add(g),w.size>=Math.max(1,Math.trunc(Number(Re(y,"inputFlows")??2)||2))&&(w.clear(),B("out"),B("completed"));break}case"flow/throttle":{if(g==="reset"){f.delete(V);break}let w=Math.max(0,ae(C("duration",0))),F=f.get(V);F===void 0||A-F>=w?(f.set(V,A),_(V,"lastRemainingTime",0),B()):_(V,"lastRemainingTime",Math.max(0,w-(A-F)));break}case"flow/delay":case"flow/setDelay":{if(g==="cancel"){for(let J=d.length-1;J>=0;J--)d[J].nodeIdx===V&&d.splice(J,1);_(V,"lastDelayIndex",-1);break}let w=Math.max(0,ae(C("duration",Re(y,"duration")??0))),F=y.flows?.done??y.flows?.out;if(w<=0){_(V,"lastDelayIndex",-1),F&&N(F);break}d.length>=ra&&d.shift();let H=E++;_(V,"lastDelayIndex",H),d.push({id:H,nodeIdx:V,rem:w,done:F}),T==="flow/setDelay"&&y.flows?.out&&y.flows?.done&&B("out");break}case"flow/cancelDelay":{let w=Math.trunc(ae(C("delayIndex",-1),-1));if(w<0)d.length=0;else for(let F=d.length-1;F>=0;F--)d[F].id===w&&d.splice(F,1);B();break}case"variable/set":v(Re(y,"variable")??Re(y,"id"),C("value")),B();break;case"variable/interpolate":{let w=Re(y,"variable")??Re(y,"id"),F=C("value",C("target")),H=Math.max(0,ae(C("duration",Re(y,"duration")??.3),.3));w!==void 0&&F!==void 0&&q({key:`var:${String(w)}`,varKey:w,from:We(C("from")??a.get(w)??0),to:We(F),dur:H,elapsed:0,quat:!1,linear:Re(y,"easing")==="linear",done:y.flows?.done}),B();break}case"pointer/set":{let w=Y(V,y),F=C("value");w&&F!==void 0&&(U(`ptr:${w}`),K(w,F)),B();break}case"pointer/interpolate":{let w=Y(V,y),F=C("value",C("target")),H=Math.max(0,ae(C("duration",Re(y,"duration")??.3),.3));if(w&&F!==void 0){let J=C("from")??W(w);J!==void 0&&(H<=0?(K(w,F),B("done")):q({key:`ptr:${w}`,ptr:w,from:We(J),to:We(F),dur:H,elapsed:0,quat:w.endsWith("/rotation"),linear:Re(y,"easing")==="linear",done:y.flows?.done}))}B();break}case"animation/start":{let w=C("animation")??Re(y,"animation")??Re(y,"clipName"),F=typeof w=="number"?e?.animations?.[w]?.name??n?.animations?.[w]?.name:typeof w=="string"?w:void 0;e?.playAnimation?.(F),D=!0,B();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),T==="animation/resetAt"&&e?.evaluateAnimation?.(ae(C("time",0))),D=!0,B();break;case"event/send":case"customEvent/send":{let w=G(Re(y,"event")??Re(y,"id")),F={};for(let H of Object.keys(y.values||{}))at.has(H)||(F[H]=C(H));w&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:w,values:F}})),re(w,F,X)),B();break}default:B();break}}};this.readScenePointer=W,this.writeScenePointer=K,this.fireOnStart=()=>{i.forEach(O=>{S(O)==="event/onStart"&&ne(O.flows?.out)}),$()},this.fireOnSelect=O=>{if(!O)return;let X=typeof O.meshIndex=="number"?O.meshIndex:-1,M=typeof O.nodeIndex=="number"?O.nodeIndex:e?.meshes?.[X]?.nodeIndex??-1;i.forEach((N,z)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(S(N)))return;let V=Re(N,"nodeIndex")??Re(N,"node")??te(z,"nodeIndex",void 0,new Set),y=Re(N,"meshName");if(typeof y=="string"&&y?O.meshName===y:V==null||Number(V)<0||Number.isNaN(Number(V))||L(M,Math.trunc(Number(V)))){if(_(z,"nodeIndex",M),_(z,"meshIndex",X),Array.isArray(O.hitPoint)){let T=[ae(O.hitPoint[0]),ae(O.hitPoint[1]),ae(O.hitPoint[2])];_(z,"hitPoint",T),_(z,"point",T),_(z,"intersectionPoint",T)}if(Array.isArray(O.normal)){let T=[ae(O.normal[0]),ae(O.normal[1],1),ae(O.normal[2])];_(z,"normal",T),_(z,"hitNormal",T)}typeof O.distance=="number"&&_(z,"distance",O.distance),ne(N.flows?.out)}}),$()},this.receiveCustomEvent=(O,X={})=>re(O,X,{steps:0});function re(O,X,M){if(!(x>=ia)){x++;try{let N=G(O);i.forEach((z,V)=>{if(!/^(customE|e)vent\/receive$/.test(S(z)))return;let y=Re(z,"event")??Re(z,"id");if(!(G(y)!==N&&String(y)!==String(O))){for(let[g,T]of Object.entries(X))at.has(g)||_(V,g,We(T));ne(z.flows?.out,M)}}),$()}finally{x--}}}this.tick=O=>{if(!Number.isFinite(O)||O<0)return;let X=Math.min(O,.25);A+=X,i.forEach((N,z)=>{S(N)==="event/onTick"&&(_(z,"timeDelta",X),_(z,"dt",X),_(z,"timeElapsed",A),ne(N.flows?.out))});let M=[];for(let N=b.length-1;N>=0;N--){let z=b[N];z.elapsed+=X;let V=z.dur>1e-6?Rt(z.elapsed/z.dur):1,y=z.linear?V:V*V*(3-2*V),g=Xo(z.from,z.to,y,z.quat);z.ptr?K(z.ptr,g):z.varKey!==void 0&&v(z.varKey,g),V>=1&&(b.splice(N,1),z.done&&M.push(z.done))}for(let N=d.length-1;N>=0;N--){let z=d[N];z.rem-=X,z.rem<=0&&(d.splice(N,1),z.done&&M.push(z.done))}for(let N of M)ne(N);$()},this.dispose=()=>{b.length=0,d.length=0,a.clear(),u.clear(),l.clear(),m.clear(),f.clear(),h.clear()}}},et=new WeakMap,br=new WeakMap;function ca(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||Tn().some(a=>a.name==="xr-live-head-follow")||(typeof t.getAutoRotate=="function"?t.getAutoRotate():t.autoRotate)===!1)return;let r=t.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let o=Math.min(e,.1),s=(br.get(t)||0)+o,c=!1;for(let a=0;a<i.length;a++){let u=i[a],l=ao(u?.extras?.xr?.orbit);if(!l)continue;let m=0,f=0,h=0;if(Array.isArray(l.target))m=l.target[0],f=l.target[1],h=l.target[2];else if(typeof l.target=="string"&&l.target!=="head"){let A=i.find(x=>x?.name===l.target);Array.isArray(A?.translation)&&(m=ae(A.translation[0]),f=ae(A.translation[1]),h=ae(A.translation[2]))}let b=l.phase+l.speed*s,d=m+Math.cos(b)*l.radius,p=f+l.height,E=h+Math.sin(b)*l.radius;if(u.translation=[d,p,E],l.faceCenter){let A=Math.atan2(m-d,h-E);u.rotation=[0,Math.sin(A*.5),0,Math.cos(A*.5)]}c=!0}if(c){br.set(t,s);let a=it(r);t.worldMatrices=a;for(let u of t.meshes||[])u.nodeIndex>=0&&u.nodeIndex<a.length&&(u.transform.set(a[u.nodeIndex]),Le(u.normalMatrix,u.transform))}}function yr(t){if(!(!t||typeof t!="object"))return et.get(t)||et.get(t.viewer)||et.get(t._view)}function hi(t,e,n){let r=yr(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var di={name:"khr-interactivity",sendInteractivityEvent:hi,getInteractivityVM:yr,onLoadModel(t,e){if(!t||typeof t!="object")return;et.get(t)?.dispose(),et.delete(t),br.delete(t);let n=e?.extensions?.KHR_interactivity,r=Array.isArray(n?.graphs)?n.graphs[n.graph??0]:n;if(!r||!Array.isArray(r.nodes))return;let i=new dn(t,e,r);et.set(t,i),i.fireOnStart()},onMeshSelect(t,e){et.get(t)?.fireOnSelect(e)},onUpdate(t,e){et.get(t)?.tick(e),ca(t,e)},onDestroy(t,e){et.get(e)?.dispose(),et.delete(e),br.delete(e)}};var pn=new Map,pi=new WeakMap;function $o(t,e){pn.set(t,e)}var bi={name:"materials",onBuildPrimitiveVAO(t,e,n,r,i){return(((r?.materials&&n.material!==void 0?r.materials[n.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(t,e){let n=pi.get(t);n||(n=t.createTexture(),pi.set(t,n));let r=Math.max(1,e.canvas.width),i=Math.max(1,e.canvas.height);t.activeTexture(33990),t.bindTexture(3553,n),t.copyTexImage2D(3553,0,6408,0,0,r,i,0),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),t.texParameteri(3553,10241,9987),t.texParameteri(3553,10240,9729),t.generateMipmap(3553)},onResolveShader(t,e,n,r){if(!e)return null;if(e.name&&pn.has(e.name)){let b=pn.get(e.name);return{vs:b.vs||n,fs:b.fs||r}}let i=e.extensions||{},o=i.KHR_materials_clearcoat,s=i.KHR_materials_sheen,c=!!i.KHR_materials_transmission,a=!!i.KHR_materials_ior,u=i.KHR_materials_iridescence;if(!o&&!s&&!i.KHR_materials_unlit&&!c&&!i.KHR_materials_volume&&!a&&!i.KHR_materials_dispersion&&!u)return null;if(i.KHR_materials_unlit)return{vs:n,fs:r.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let l=r;if(c){let b=l.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
345
+ `;l=l.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
346
+ ${b}out vec4 fragColor;`)}let m=(b,d,p=0,E=1e6,A=3)=>{let x=Number(b);return(Number.isFinite(x)?Math.min(E,Math.max(p,x)):d).toFixed(A)},f=Number(i.KHR_materials_ior?.ior??1.5),h=Number.isFinite(f)?Math.min(10,Math.max(1,f)):1.5;if(a){let b=Math.pow((h-1)/(h+1),2);l=l.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(b,.04,0,1,4)}),base.rgb,metallic);`)}if(u){let b=m(u.iridescenceFactor,1,0,1),d=m(u.iridescenceIor,1.3,1,10);l=l.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${d}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${b}*pow(1.-NoV,2.));`)}if(c){let b=m(i.KHR_materials_transmission?.transmissionFactor,1,0,1),d=i.KHR_materials_volume||{},p=m(d.thicknessFactor,.5,0,1e4),E=m(d.attenuationDistance,1,.001,1e6),A=Array.isArray(d.attenuationColor)?d.attenuationColor:[1,1,1],x=m(i.KHR_materials_dispersion?.dispersion,0,0,10);l=l.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
347
+ vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(h,1.5,1,10)},dV=${x},tV=${p},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
321
348
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
322
349
  vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
323
- vec3 aCol=vec3(${m(E[0],1,0,1)},${m(E[1],1,0,1)},${m(E[2],1,0,1)});
324
- vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${P},.001));
325
- diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${d});`)}if(o&&!r.includes("uClearcoat")){let d=m(o.clearcoatFactor,1,0,1),p=m(o.clearcoatRoughnessFactor,0,0,1);u=u.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${p},NoV)*${d};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${p})*ccF;fragColor=vec4(color,base.a);`)}if(a){let d=Array.isArray(a.sheenColorFactor)?a.sheenColorFactor:[1,1,1],p=`color+=vec3(${m(d[0],1,0,1)},${m(d[1],1,0,1)},${m(d[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;u.includes("color=applyToneMapping(color,uToneMapping);")?u=u.replace("color=applyToneMapping(color,uToneMapping);",`${p}color=applyToneMapping(color,uToneMapping);`):u=u.replace("fragColor=vec4(color,base.a);",`${p}fragColor=vec4(color,base.a);`)}return{vs:n,fs:u}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=n.materialIndex;if(a!==void 0&&o?.materials){let l=o.materials[a];l?.name&&Mt.has(l.name)&&Mt.get(l.name).onBindUniforms?.(t,e,n)}if(n.isTransmissive){let l=ir.get(t);if(l){t.activeTexture(33990),t.bindTexture(3553,l);let c=t.getUniformLocation(e,"uTransmissionTex");c&&t.uniform1i(c,6);let s=t.getUniformLocation(e,"uViewportSize");s&&t.uniform2f(s,t.drawingBufferWidth||1,t.drawingBufferHeight||1)}}}};var oo=`#version 300 es
326
- layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,so=`#version 300 es
327
- precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Rn=new WeakMap,li=new Float32Array(20);function sr(t,e){let[n,r,i,o,a,l]=e;return[t[0]*n+t[4]*r+t[8]*i+t[12],t[1]*n+t[5]*r+t[9]*i+t[13],t[2]*n+t[6]*r+t[10]*i+t[14],Math.abs(t[0])*o+Math.abs(t[4])*a+Math.abs(t[8])*l,Math.abs(t[1])*o+Math.abs(t[5])*a+Math.abs(t[9])*l,Math.abs(t[2])*o+Math.abs(t[6])*a+Math.abs(t[10])*l]}function ao(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,a=-1e9;for(let l of t.primitives||[]){let c=l.positions;if(c)for(let s=0;s<c.length;s+=3)c[s]<e&&(e=c[s]),c[s+1]<n&&(n=c[s+1]),c[s+2]<r&&(r=c[s+2]),c[s]>i&&(i=c[s]),c[s+1]>o&&(o=c[s+1]),c[s+2]>a&&(a=c[s+2])}return t._lb=e<=i?[(e+i)*.5,(n+o)*.5,(r+a)*.5,(i-e)*.5,(o-n)*.5,(a-r)*.5]:null}function co(t){let e=Rn.get(t);if(e)return e;let n=(l,c)=>{let s=t.createShader(l);return t.shaderSource(s,c),t.compileShader(s),s},r=t.createProgram();t.attachShader(r,n(35633,oo)),t.attachShader(r,n(35632,so)),t.linkProgram(r);let i=t.createVertexArray(),o=t.createBuffer(),a=t.createBuffer();return t.bindVertexArray(i),t.bindBuffer(34962,o),t.bufferData(34962,80,35048),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,5126,!1,20,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,5126,!1,20,12),t.bindBuffer(34963,a),t.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),t.bindVertexArray(null),e={prog:r,vao:i,vbo:o,ibo:a,uMVP:t.getUniformLocation(r,"uMVP"),uIntensity:t.getUniformLocation(r,"uShadowIntensity"),uSoftness:t.getUniformLocation(r,"uShadowSoftness")},Rn.set(t,e),e}var Et={name:"contact-shadow",onAfterRender(t,e,n){let r=e.shadowIntensity;if(r<=0||!e.bounds)return;let i=co(t),o=!e.xrSessionActive&&(e.backdropMeshes?.length??0)>0,a=[],l=[];for(let p of e.meshes||[]){if(!p||p.visible===!1||p.isPluginMesh||p.name==="__xr_reticle__"||p.name?.startsWith("__xr_slot_"))continue;let x=ao(p);if(!x)continue;p.transform&&(x=sr(p.transform,x)),e.modelRootMatrix&&(x=sr(e.modelRootMatrix,x));let[P,E,y,v,g,L]=x,b=[P,y,v,L,E-g,E+g];/floor|table|pedestal|ground|base|plane/i.test(p.name||"")||g<.14&&Math.min(v,L)>.45?l.push(b):a.push(b)}let c=[],s=e.bounds.center||[0,0,0],u=Math.max(.05,Number(e.bounds.radius)||.5),m=e.bounds.min,h=m?[s[0],s[1],s[2],u,Math.max(.01,s[1]-m[1]),u]:[s[0],s[1],s[2],u,u,u];e.modelRootMatrix&&(h=sr(e.modelRootMatrix,h));let d=e.xrSessionActive&&l.length===0&&String(e.container?.tagName||"").toLowerCase()==="xr-live"?(e.modelRootMatrix?e.modelRootMatrix[5]*-.25+e.modelRootMatrix[13]:-.25)+.002:h[1]-h[4]+.002;for(let[p,x,P,E,y]of a){let v=-1/0;for(let[L,b,w,R,,_]of l)y>=_-.08&&Math.abs(p-L)<=w&&Math.abs(x-b)<=R&&_+.002>v&&(v=_+.002);o&&(v=Math.max(v,p>=.04&&p<=.36&&x>=-.34&&x<=-.04&&y>=.01?.036:Math.hypot(p,x)<=.66&&y>=-.06?.003:-.477)),isFinite(v)||(v=d);let g=c.find(L=>Math.hypot(p-L[0],x-L[1])<.06&&Math.abs(v-L[5])<.05);g?(g[2]=Math.max(g[2],P*.78),g[3]=Math.max(g[3],E*.78),g[4]=Math.min(g[4],y)):c.push([p,x,P,E,y,v])}if(c.length===0){let p=Math.max(.1,h[3]*1.5)/1.45;c.push([h[0],h[2],p,p,d,d])}t.useProgram(i.prog),t.uniformMatrix4fv(i.uMVP,!1,n),t.enable(3042),(t.blendFuncSeparate||t.blendFunc).call(t,770,771,1,771),t.depthMask(!1),t.bindVertexArray(i.vao),t.bindBuffer(34962,i.vbo);for(let[p,x,P,E,y,v]of c){let g=Math.max(0,y-v),L=r/(1+g*2);if(L<.02)continue;let b=1+Math.min(.75,g*.85),w=Math.max(.045,P*1.45*b),R=Math.max(.045,E*1.45*b);li.set([p-w,v,x-R,0,0,p+w,v,x-R,1,0,p+w,v,x+R,1,1,p-w,v,x+R,0,1]),t.bufferSubData(34962,0,li),t.uniform1f(i.uIntensity,L),t.uniform1f(i.uSoftness,Math.min(1,e.shadowSoftness+Math.min(.45,g*.6))),t.drawElements(4,6,5123,0)}t.bindVertexArray(null),t.depthMask(!0),t.disable(3042)},onDestroy(t){let e=Rn.get(t);e&&(t.deleteVertexArray(e.vao),t.deleteBuffer(e.vbo),t.deleteBuffer(e.ibo),t.deleteProgram(e.prog),Rn.delete(t))}};var mi=new WeakMap,cr={name:"webxr-suite",onConfigureXRSessionInit(t,e){let n=new Set(e.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=t?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),e.domOverlay={root:r},r.addEventListener?.("beforexrselect",i=>{i.preventDefault()})),e.optionalFeatures=Array.from(n)},onXRFrame(t,e,n,r){if(!t||!e||!n||!r)return;let i=mi.get(e);if(i||(i={lightProbe:null},mi.set(e,i),typeof e.requestLightProbe=="function"&&e.requestLightProbe().then(o=>{i&&o&&(i.lightProbe=o)}).catch(()=>{})),i.lightProbe&&typeof n.getLightEstimate=="function"){let o=n.getLightEstimate(i.lightProbe);if(o){let a=o.primaryLightDirection,l=o.primaryLightIntensity;if(a&&l&&Array.isArray(t.lights)){let c=t.lights.find(u=>u.type==="directional");c||(c={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(c)),c.direction=[a.x,a.y,a.z];let s=Math.max(l.x,l.y,l.z,.001);c.color=[l.x/s,l.y/s,l.z/s],c.intensity=s}o.sphericalHarmonicsCoefficients&&t.gl&&gn(t.gl,o.sphericalHarmonicsCoefficients)}}}};ge(Et);ge(Qn);ge(Kn);ge(or);ge(cr);ge(rr);function lr(){if(typeof window>"u"||typeof navigator>"u")return!1;let t=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(t)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function mr(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function hr(){if(typeof navigator>"u")return!1;let t=navigator;if(!t.xr||typeof t.xr.isSessionSupported!="function")return!1;try{return await t.xr.isSessionSupported("immersive-ar")?!0:await t.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function fi(){return(await Mn()).bestMode}async function Mn(){let[t,e,n]=await Promise.all([hr(),Promise.resolve(lr()),Promise.resolve(mr())]),r=[];e&&r.push("quick-look"),t&&r.push("webxr"),n&&r.push("scene-viewer");let i=null;return e?i="quick-look":t?i="webxr":n&&(i="scene-viewer"),{webxr:t,quickLook:e,sceneViewer:n,availableModes:r,bestMode:i}}function hi(t,e={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,r=!1;if(typeof t=="string"){if(n=uo(t),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(t),r=!0;let i=[];if(e.allowScale===!1&&i.push("allowsContentScaling=0"),e.canonicalWebPageUrl){let l=Tn(e.canonicalWebPageUrl,!1);l&&i.push(`canonicalWebPageURL=${encodeURIComponent(l)}`)}e.checkoutTitle&&i.push(`checkoutTitle=${encodeURIComponent(e.checkoutTitle)}`),e.checkoutSubtitle&&i.push(`checkoutSubtitle=${encodeURIComponent(e.checkoutSubtitle)}`),e.price&&i.push(`price=${encodeURIComponent(e.price)}`),i.length>0&&(n+=`#${i.join("&")}`);let o=document.createElement("a");o.setAttribute("rel","ar"),o.setAttribute("href",n);let a=document.createElement("img");a.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),a.style.display="none",o.appendChild(a),document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),r&&URL.revokeObjectURL(n.split("#")[0])},3e3)}function Tn(t,e=!1){if(typeof t!="string")return"";let n=t.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!n)return"";if(/^[\\/]{2}/.test(n))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${n.slice(0,32)}`);let r=n.toLowerCase();if(r.startsWith("https://")||r.startsWith("http://")||e&&r.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(n))return n;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${n.slice(0,32)}`)}function uo(t){try{return Tn(t,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(t||"").trim().slice(0,32)}`)}}function lo(t,e={}){let n=Tn(t,!0),r=e.mode||"ar_preferred",i=new URLSearchParams({file:n,mode:r,resizable:e.resizable!==!1?"true":"false",enable_vertical_placement:e.enableVerticalPlacement?"true":"false"});return e.title&&i.set("title",e.title),e.link&&i.set("link",Tn(e.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${i.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function mo(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=lo(t,e);window.location.href=n}var $e=null;function ho(t,e){let r=new Float32Array(144),i=new Float32Array(24*6),o=new Float32Array(24*4),a=new Uint16Array(24*6);for(let m=0;m<24;m++){let h=m/24*Math.PI*2,f=Math.cos(h),d=Math.sin(h),p=m*2,x=p+1,P=(m+1)%24*2;r[p*3]=f*.11,r[p*3+1]=.002,r[p*3+2]=d*.11,r[x*3]=f*.145,r[x*3+1]=.002,r[x*3+2]=d*.145,i[p*3+1]=i[x*3+1]=1,a.set([p,P,x,x,P,P+1],m*6)}let l=t.createVertexArray();t.bindVertexArray(l);let c=(m,h,f)=>{let d=t.createBuffer();return t.bindBuffer(34962,d),t.bufferData(34962,m,35044),t.enableVertexAttribArray(h),t.vertexAttribPointer(h,f,5126,!1,0,0),d},s=[c(r,0,3),c(i,1,3),c(o,2,2)],u=t.createBuffer();return s.push(u),t.bindBuffer(34963,u),t.bufferData(34963,a,35044),t.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:l,indexCount:a.length,indexType:5123,baseColor:e&&e.length>=3?[e[0],e[1],e[2],e[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:a,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:s}]}}function di(t,e,n,r,i){let o=Math.cos(r),a=Math.sin(r),l=Math.max(.01,i);t.fill(0),t[0]=l*o,t[2]=-l*a,t[5]=l,t[8]=l*a,t[10]=l*o,t[12]=e[0]-l*(o*n[0]+a*n[2]),t[13]=e[1]-l*n[1],t[14]=e[2]-l*(-a*n[0]+o*n[2]),t[15]=1}var ur=class{constructor(e={}){this.s=null;this.placed=!1;this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);this.cleanFn=null;this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,n){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");$e&&$e!==this&&$e.isSessionActive()&&await $e.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||e?.container,a=String(o?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,c=Number(l?.radius)||1,s=Array.isArray(l?.center)?l.center:[0,0,0],u=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],m=typeof navigator<"u"&&navigator.userAgent||"",h=/Android|iPhone|iPad|iPod/i.test(m)&&!/Quest|Oculus|Pico|Vision/i.test(m),f=a?i.arScale==="fixed"?1:h?.55:1:i.arScale==="fixed"?1:c>.45?.3/c:c<.05?.12/Math.max(c,.001):1,d=a?[0,-.25,0]:[s[0]||0,i.arPlacement==="wall"?s[1]:u[1]??0,s[2]||0],p="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(p="immersive-vr")}catch{p="immersive-vr"}let x=o?.querySelector?.('[slot="ar-overlay"]')||null,P=!1,E=null,y=()=>{P&&x?.parentNode&&x.parentNode.removeChild(x),x=null,E=null,P=!1};if(p==="immersive-ar"){if(x)x.addEventListener?.("beforexrselect",S=>S.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let S=document.createElement("div");S.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let k=document.createElement("button");k.type="button",k.textContent="\u2715 Exit AR",k.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",k.addEventListener("beforexrselect",M=>M.preventDefault()),k.addEventListener("click",M=>{M.stopPropagation(),this.stop().catch(()=>{})}),E=document.createElement("div"),E.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",E.textContent="Move phone to detect a surface \u2022 Tap to place",S.appendChild(k),S.appendChild(E),document.body.appendChild(S),x=S,P=!0}}let v=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),g={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(v)};x&&(v.add("dom-overlay"),g.optionalFeatures=Array.from(v),g.domOverlay={root:x});for(let S of ue)S.onConfigureXRSessionInit?.(o,g);Array.isArray(g.optionalFeatures)&&g.optionalFeatures.includes("dom-overlay")&&!g.domOverlay?.root&&(g.optionalFeatures=g.optionalFeatures.filter(S=>S!=="dom-overlay"));let L=S=>{let k=String(S?.name||"");return k==="NotAllowedError"||k==="SecurityError"};try{this.s=await r.requestSession(p,g)}catch(S){if(y(),L(S))throw i.onError?.(S),S;try{this.s=await r.requestSession(p,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(k){if(L(k))throw i.onError?.(k),k;try{this.s=await r.requestSession(p)}catch(M){throw i.onError?.(M),M}}}let b=this.s;$e=this,this.placed=!1;let w=null,R=null,_=null,B=null,z=null,I=[0,-.25,-1.2],C=[0,-.25,-1.2],G=new Float32Array(16),V=new Float32Array(16),J=!1,j=1,H=0,X=!1,N=null,$=null,Y=0,T=null,A=()=>{$e===this&&($e=null),T?.(),T=null;try{R?.cancel?.()}catch{}if(R=null,_){let S=e?.meshes;if(Array.isArray(S)){let M=S.indexOf(_);M!==-1&&S.splice(M,1)}let k=e.getGLContext?.()||e?.gl;if(k)for(let M of _.primitives||[]){k.deleteVertexArray?.(M.vao);for(let D of M.buffers||[])k.deleteBuffer?.(D)}_=null}e?.setXRSessionActive?.(!1),y(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=A,b.addEventListener("end",()=>{A(),i.onExit?.()}),b.addEventListener("select",()=>{if(!this.placed){let S=z||I;C=[S[0],S[1],S[2]],di(this.placedMat,C,d,H,f*j),this.placed=!0,_&&(_.visible=!1),E&&(E.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let S=e.getGLContext?.()||e?.gl;S&&typeof S.makeXRCompatible=="function"&&await S.makeXRCompatible();let k=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;S&&typeof k=="function"&&typeof b.updateRenderState=="function"&&b.updateRenderState({baseLayer:new k(b,S,{alpha:!0})});try{w=await b.requestReferenceSpace("local")}catch{try{w=await b.requestReferenceSpace("local-floor")}catch{w=await b.requestReferenceSpace("viewer")}}let M=await b.requestReferenceSpace("viewer").catch(()=>w);if(typeof b.requestHitTestSource=="function"&&M&&(R=await b.requestHitTestSource({space:M}).catch(()=>null)),p==="immersive-ar"&&S&&typeof S.createVertexArray=="function"&&Array.isArray(e.meshes)&&(_=ho(S,i.reticleColor),e.meshes.push(_)),typeof window<"u"&&typeof window.addEventListener=="function"){let F=O=>Math.hypot(O.touches[1].clientX-O.touches[0].clientX,O.touches[1].clientY-O.touches[0].clientY),U=O=>Math.atan2(O.touches[1].clientY-O.touches[0].clientY,O.touches[1].clientX-O.touches[0].clientX),K=O=>{this.s&&(O.touches.length===1&&this.placed?X=!0:O.touches.length>=2&&(X=!1,N=F(O),$=U(O)))},Z=O=>{if(!this.s||O.touches.length<2)return;let q=F(O),ee=U(O);if(N&&N>4&&i.arScale!=="fixed"&&(j=Math.max(.15,Math.min(6,j*(q/N)))),$!==null){let ae=ee-$;ae>Math.PI&&(ae-=Math.PI*2),ae<-Math.PI&&(ae+=Math.PI*2),H-=ae}N=q,$=ee},Q=O=>{(!O.touches||O.touches.length===0)&&(X=!1),(!O.touches||O.touches.length<2)&&(N=null,$=null)};window.addEventListener("touchstart",K,{passive:!0}),window.addEventListener("touchmove",Z,{passive:!0}),window.addEventListener("touchend",Q,{passive:!0}),window.addEventListener("touchcancel",Q,{passive:!0}),T=()=>{window.removeEventListener("touchstart",K),window.removeEventListener("touchmove",Z),window.removeEventListener("touchend",Q),window.removeEventListener("touchcancel",Q)}}e.setXRSessionActive?.(!0);let D=(F,U)=>{if(this.s!==b)return;b.requestAnimationFrame(D);let K=Y>0?Math.min(Math.max((F-Y)/1e3,0),.1):1/60;Y=F,e?.stepXRUpdate?.(K);let Z=U.getViewerPose(w);if(!Z)return;let Q=Z.views?.[0];if(!J&&Q?.transform){let pe=Q.transform.position,ce=Q.transform.matrix,De=pe?.x??(ce?ce[12]:0),xe=pe?.y??(ce?ce[13]:0),ve=pe?.z??(ce?ce[14]:0),te=ce?-ce[8]:0,he=ce?-ce[10]:-1,Ee=Math.hypot(te,he);Ee>1e-4?(te/=Ee,he/=Ee):(te=0,he=-1),I=[De+te*1.2,xe-.25,ve+he*1.2],H=Math.atan2(-te,-he),J=!0}if(R&&typeof U.getHitTestResults=="function"&&(!this.placed||X)){let pe=U.getHitTestResults(R)||[],ce=!1;for(let De of pe){let xe=De.getPose(w);if(xe?.transform?.matrix){let ve=xe.transform.matrix,te=ve[5];if(i.arPlacement==="wall"&&Math.abs(te)>.35||i.arPlacement==="floor"&&Math.abs(te)<.65)continue;B||(B=new Float32Array(16)),B.set(ve),z=[ve[12],ve[13],ve[14]],this.placed&&X&&(C=[ve[12],ve[13],ve[14]]),_&&(_.visible=!this.placed||X,_.transform.set(ve)),!this.placed&&E&&(E.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(B),ce=!0;break}}!ce&&_&&(_.visible=!1)}di(G,this.placed?C:z||I,d,H,f*j),this.placed&&this.placedMat.set(G);let O=e.xrRigMatrix;O instanceof Float32Array&&O.length===16?be(V,O,G):V.set(G),e.modelRootMatrix&&e.modelRootMatrix.set(V);for(let pe of ue)pe.onXRFrame?.(e,b,U,w);let q=e.getGLContext?.()||e?.gl,ee=b.renderState?.baseLayer;q&&ee&&ee.framebuffer!==void 0&&q.bindFramebuffer(36160,ee.framebuffer);let ae=p==="immersive-ar",Ve=Z.views||[];for(let pe=0;pe<Ve.length;pe++){let ce=Ve[pe];if(typeof e.renderXRView=="function"){let De;if(ee&&typeof ee.getViewport=="function"){let xe=ee.getViewport(ce);xe&&xe.width>0&&xe.height>0&&(De=[xe.x,xe.y,xe.width,xe.height])}else ee?.framebufferWidth>0&&ee?.framebufferHeight>0&&(De=[0,0,ee.framebufferWidth,ee.framebufferHeight]);e.renderXRView(ce,V,this.placed,De,ae,pe)}}q&&ee&&ee.framebuffer&&q.bindFramebuffer(36160,null)};b.requestAnimationFrame(D)}catch(S){throw typeof b.end=="function"&&await b.end().catch(()=>{}),A(),i.onError?.(S),S}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function En(t){let e=await Mn(),n=t.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let l of n)if(e.availableModes.includes(l)){r=l;break}if(r||(r=e.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let i={...t.quickLookOptions,allowScale:t.arScale==="fixed"?!1:t.quickLookOptions?.allowScale},o={...t.sceneViewerOptions,resizable:t.arScale==="fixed"?!1:t.sceneViewerOptions?.resizable,enableVerticalPlacement:t.arPlacement==="wall"?!0:t.sceneViewerOptions?.enableVerticalPlacement},a={...t.webXROptions,arScale:t.arScale||t.webXROptions?.arScale,arPlacement:t.arPlacement||t.webXROptions?.arPlacement};try{if(r==="quick-look"){let l;if(t.model instanceof Blob&&t.model.type==="model/vnd.usdz+zip")l=t.model;else{if(typeof t.model=="string")return hi(t.model,i),{mode:"quick-look",success:!0};l=Ze(t.model)}return hi(l,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let l=t.glbUrl||(typeof t.model=="string"?t.model:null);if(!l)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return mo(l,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!t.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let l=new ur(a);return await l.start(t.view,t.element),{mode:"webxr",success:!0,session:l}}}catch(l){return{mode:r,success:!1,error:l}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}Pe.registerAR({activateAR:En,createUSDZBlob:Ze});Pe.registerScriptRunner(tt);ge(Et);Pe.registerScriptRunner(tt);typeof window<"u"&&(window.ThreeLiveBundle=dr);
350
+ vec3 aCol=vec3(${m(A[0],1,0,1)},${m(A[1],1,0,1)},${m(A[2],1,0,1)});
351
+ vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${E},.001));
352
+ diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${b});`)}if(o&&!r.includes("uClearcoat")){let b=m(o.clearcoatFactor,1,0,1),d=m(o.clearcoatRoughnessFactor,0,0,1);l=l.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${d},NoV)*${b};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${d})*ccF;fragColor=vec4(color,base.a);`)}if(s){let b=Array.isArray(s.sheenColorFactor)?s.sheenColorFactor:[1,1,1],d=`color+=vec3(${m(b[0],1,0,1)},${m(b[1],1,0,1)},${m(b[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;l.includes("color=applyToneMapping(color,uToneMapping);")?l=l.replace("color=applyToneMapping(color,uToneMapping);",`${d}color=applyToneMapping(color,uToneMapping);`):l=l.replace("fragColor=vec4(color,base.a);",`${d}fragColor=vec4(color,base.a);`)}return{vs:n,fs:l}},onBeforeDrawPrimitive(t,e,n,r,i,o){let s=n.materialIndex;if(s!==void 0&&o?.materials){let c=o.materials[s];c?.name&&pn.has(c.name)&&pn.get(c.name).onBindUniforms?.(t,e,n)}if(n.isTransmissive){let c=pi.get(t);if(c){t.activeTexture(33990),t.bindTexture(3553,c);let a=t.getUniformLocation(e,"uTransmissionTex");a&&t.uniform1i(a,6);let u=t.getUniformLocation(e,"uViewportSize");u&&t.uniform2f(u,t.drawingBufferWidth||1,t.drawingBufferHeight||1)}}}};var qo=64*1024*1024,Yo=128*1024*1024,ua=16777216;function la(t){let e=t<<24>>24;return(e<<1^e>>7)&255}function yi(t){return(t>>>1^-(t&1))&255}function ma(t){return(t<<1^t>>31)>>>0}function fa(t){return t>>>1^-(t&1)}function gr(t,e,n,r="NONE"){if(!r||r==="NONE"||e<=0)return;let i=new DataView(t.buffer,t.byteOffset,t.byteLength);if(r==="OCTAHEDRAL"){if(n!==4&&n!==8)throw new Error(`EXT_meshopt_compression: OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let o=n===4?127:32767;for(let s=0;s<e;s++){let c=s*n,a=n===4?i.getInt8(c):i.getInt16(c,!0),u=n===4?i.getInt8(c+1):i.getInt16(c+2,!0),l=n===4?i.getInt8(c+2):i.getInt16(c+4,!0),m=l===0?1:l,f=a/m,h=u/m,b=1-Math.abs(f)-Math.abs(h),d=Math.max(-b,0);f+=f>=0?-d:d,h+=h>=0?-d:d;let p=Math.hypot(f,h,b)||1,E=Math.max(-o,Math.min(o,Math.round(f/p*o))),A=Math.max(-o,Math.min(o,Math.round(h/p*o))),x=Math.max(-o,Math.min(o,Math.round(b/p*o)));n===4?(i.setInt8(c,E),i.setInt8(c+1,A),i.setInt8(c+2,x)):(i.setInt16(c,E,!0),i.setInt16(c+2,A,!0),i.setInt16(c+4,x,!0))}return}if(r==="QUATERNION"){if(n!==8)throw new Error(`EXT_meshopt_compression: QUATERNION filter requires byteStride 8 (got ${n})`);for(let o=0;o<e;o++){let s=o*8,c=i.getInt16(s,!0),a=i.getInt16(s+2,!0),u=i.getInt16(s+4,!0),l=i.getInt16(s+6,!0),m=l&3,f=l|3,h=Math.SQRT1_2/(f===0?1:f),b=c*h,d=a*h,p=u*h,E=Math.sqrt(Math.max(0,1-b*b-d*d-p*p)),A=Math.hypot(b,d,p,E)||1,x=[0,0,0,0];x[m+1&3]=Math.max(-32767,Math.min(32767,Math.round(b/A*32767))),x[m+2&3]=Math.max(-32767,Math.min(32767,Math.round(d/A*32767))),x[m+3&3]=Math.max(-32767,Math.min(32767,Math.round(p/A*32767))),x[m]=Math.max(-32767,Math.min(32767,Math.round(E/A*32767))),i.setInt16(s,x[0],!0),i.setInt16(s+2,x[1],!0),i.setInt16(s+4,x[2],!0),i.setInt16(s+6,x[3],!0)}return}if(r==="EXPONENTIAL"){if(n<4||n%4!==0)throw new Error(`EXT_meshopt_compression: EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let o=e*n>>>2;for(let s=0;s<o;s++){let c=s*4,a=i.getInt32(c,!0),u=a>>24,l=a<<8>>8,m=Math.pow(2,u)*l;i.setFloat32(c,m,!0)}}}function jo(t){let e=Math.floor(8192/t)&-16;return e<32?32:e>256?256:e}function gi(t,e,n,r,i="NONE"){if(!Number.isInteger(e)||e<0||e>ua||!Number.isInteger(n)||n<=0||n>256)throw new Error(`EXT_meshopt_compression: invalid count (${e}) or byteStride (${n})`);let o=e*n;if(o>qo)throw new Error(`EXT_meshopt_compression: decompressed size (${o}) exceeds MAX_MESHOPT_BUFFER_BYTES (${qo})`);if(e===0)return new Uint8Array(0);let s=new Uint8Array(o),c=t.length>0?t[0]:0;if(r==="ATTRIBUTES"){if(n%4!==0)throw new Error(`EXT_meshopt_compression: ATTRIBUTES byteStride must be a multiple of 4 (got ${n})`);if(c!==160){if(t.byteLength===o)return s.set(t),gr(s,e,n,i),s;throw new Error(`EXT_meshopt_compression: unsupported ATTRIBUTES header 0x${c.toString(16)}`)}if(t.byteLength<1+n)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES stream");let a=t.byteLength-n,u=new Uint8Array(n);u.set(t.subarray(a,a+n));let l=jo(n),m=1,f=0;for(;f<e;){let h=Math.min(e-f,l),b=h+15>>>4,d=b+3>>>2;for(let p=0;p<n;p++){if(m+d>a)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES control header");let E=m;m+=d;let A=u[p];for(let x=0;x<b;x++){let R=t[E+(x>>>2)]>>>(x&3)*2&3,I=x*16,P=Math.min(16,h-I);if(R===0)for(let k=0;k<P;k++)s[(f+I+k)*n+p]=A;else if(R===1){if(m+4>a)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 2-bit group");for(let k=0;k<16;k++){let S=t[m+(k>>>2)]>>>(k&3)*2&3;A=A+yi(S)&255,k<P&&(s[(f+I+k)*n+p]=A)}m+=4}else if(R===2){if(m+8>a)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 4-bit group");for(let k=0;k<16;k++){let S=t[m+(k>>>1)]>>>(k&1)*4&15;A=A+yi(S)&255,k<P&&(s[(f+I+k)*n+p]=A)}m+=8}else{if(m+16>a)throw new Error("EXT_meshopt_compression: truncated ATTRIBUTES 8-bit group");for(let k=0;k<16;k++){let D=t[m+k];A=A+yi(D)&255,k<P&&(s[(f+I+k)*n+p]=A)}m+=16}}u[p]=A}f+=h}return gr(s,e,n,i),s}if(r==="TRIANGLES"||r==="INDICES"){if(n!==2&&n!==4)throw new Error(`EXT_meshopt_compression: ${r} byteStride must be 2 or 4 (got ${n})`);if(r==="TRIANGLES"&&e%3!==0)throw new Error(`EXT_meshopt_compression: TRIANGLES count must be divisible by 3 (got ${e})`);let a=r==="TRIANGLES"?176:192;if((c&240)!==a){if(t.byteLength===o)return s.set(t),s;throw new Error(`EXT_meshopt_compression: unsupported ${r} header 0x${c.toString(16)}`)}let u=new DataView(s.buffer,s.byteOffset,s.byteLength),l=1,m=0;for(let f=0;f<e;f++){let h=0,b=0;for(;;){if(l>=t.byteLength)throw new Error(`EXT_meshopt_compression: truncated ${r} stream`);let d=t[l++];if(h|=(d&127)<<b,!(d&128))break;if(b+=7,b>28)throw new Error(`EXT_meshopt_compression: varint overflow in ${r}`)}m=m+fa(h)>>>0,n===2?u.setUint16(f*2,m&65535,!0):u.setUint32(f*4,m,!0)}return s}throw new Error(`EXT_meshopt_compression: unknown mode "${String(r)}"`)}function Ko(t,e,n,r){let i=e*n;if(t.byteLength<i)throw new Error(`encodeMeshoptBuffer: raw buffer (${t.byteLength}) smaller than count * byteStride (${i})`);if(e===0)return new Uint8Array([r==="ATTRIBUTES"?160:176]);if(r==="ATTRIBUTES"){let a=jo(n),u=[160],l=new Uint8Array(n),m=0;for(;m<e;){let f=Math.min(e-m,a),h=f+15>>>4,b=h+3>>>2;for(let d=0;d<n;d++){let p=new Uint8Array(b),E=[],A=l[d];for(let x=0;x<h;x++){let R=x*16,I=Math.min(16,f-R),P=new Uint8Array(16),k=0;for(let S=0;S<16;S++)if(S<I){let _=t[(m+R+S)*n+d],v=_-A<<24>>24,G=la(v);P[S]=G,G>k&&(k=G),A=_}else P[S]=0;let D=0;if(k===0)D=0;else if(k<=3){D=1;for(let S=0;S<16;S+=4)E.push(P[S]&3|(P[S+1]&3)<<2|(P[S+2]&3)<<4|(P[S+3]&3)<<6)}else if(k<=15){D=2;for(let S=0;S<16;S+=2)E.push(P[S]&15|(P[S+1]&15)<<4)}else{D=3;for(let S=0;S<16;S++)E.push(P[S])}p[x>>>2]|=D<<(x&3)*2}for(let x=0;x<p.length;x++)u.push(p[x]);for(let x=0;x<E.length;x++)u.push(E[x]);l[d]=A}m+=f}for(let f=0;f<n;f++)u.push(0);return new Uint8Array(u)}let o=new DataView(t.buffer,t.byteOffset,t.byteLength),s=[r==="TRIANGLES"?176:192],c=0;for(let a=0;a<e;a++){let u=n===2?o.getUint16(a*2,!0):o.getUint32(a*4,!0),l=u-c|0;c=u;let m=ma(l);for(;m>=128;)s.push(m&127|128),m>>>=7;s.push(m&127)}return new Uint8Array(s)}function bn(t,e){let n=e&&typeof e=="object"?e:t,r=e&&typeof e=="object"?t:n?.gltf;if(!r||!Array.isArray(r.bufferViews))return;let i=new Uint8Array(n.bin),o=[],s=0;for(let m=0;m<r.bufferViews.length;m++){let h=r.bufferViews[m]?.extensions?.EXT_meshopt_compression;if(!h||typeof h!="object")continue;let b=Number(h.count),d=Number(h.byteStride),p=Number(h.byteOffset??0),E=Number(h.byteLength??0),A=h.mode||"ATTRIBUTES",x=h.filter||"NONE";if(!Number.isInteger(p)||p<0||!Number.isInteger(E)||E<0||p+E>i.byteLength)throw new Error(`EXT_meshopt_compression: bufferView ${m} compressed range [${p}, ${p+E}] out of bounds (${i.byteLength})`);let R=b*d;if(s+=R,s>Yo)throw new Error(`EXT_meshopt_compression: total decompressed size (${s}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Yo})`);let I=i.subarray(p,p+E),P=gi(I,b,d,A,x);o.push({index:m,bytes:P,ext:h})}if(o.length===0)return;let c=i.byteLength+3&-4,a=0;for(let m of o)a+=m.bytes.byteLength+3&-4;let u=new Uint8Array(c+a);u.set(i,0);let l=c;for(let m of o){u.set(m.bytes,l);let f=r.bufferViews[m.index];f.byteOffset=l,f.byteLength=m.bytes.byteLength,f._decoded=m.bytes,m.ext.mode==="ATTRIBUTES"&&f.byteStride===void 0&&(f.byteStride=Number(m.ext.byteStride)),f.extensions&&delete f.extensions.EXT_meshopt_compression,l+=m.bytes.byteLength+3&-4}n.bin=u.buffer}var xr={decodeBufferViews(t,e){bn(e)},decodePrimitive(t,e,n){let r=e?.extensions;r?.EXT_meshopt_compression&&delete r.EXT_meshopt_compression,bn({gltf:t,bin:n})}};pe().decoders.set("meshopt",xr);var xi={name:"meshopt",onParseGLB(t){pe().decoders.set("meshopt",xr),bn(t)}};var ha=`#version 300 es
353
+ layout(location=0) in vec3 aPosition;
354
+ layout(location=1) in vec3 aNormal;
355
+ uniform mat4 uMVP,uVP;
356
+ uniform mat3 uNormalMatrix;
357
+ uniform vec2 uViewportSize;
358
+ uniform float uOutlineThickness;
359
+ void main(){
360
+ vec4 clipPos=uMVP*vec4(aPosition,1.0);
361
+ vec3 nPart=length(aNormal)>1e-5?normalize(aNormal):vec3(0.0);
362
+ vec3 pPart=length(aPosition)>1e-5?normalize(aPosition)*0.65:vec3(0.0);
363
+ vec3 rawN=nPart+pPart;
364
+ vec3 worldN=uNormalMatrix*(length(rawN)>1e-5?normalize(rawN):vec3(0.0,1.0,0.0));
365
+ float nLen=length(worldN);
366
+ vec3 n=nLen>1e-5?(worldN/nLen):vec3(0.0,1.0,0.0);
367
+ vec4 clipN=uVP*vec4(n,0.0);
368
+ vec2 dir=length(clipN.xy)>1e-5?normalize(clipN.xy):vec2(0.0);
369
+ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w;
370
+ clipPos.xy+=pxOffset;
371
+ clipPos.z+=1e-4*clipPos.w;
372
+ gl_Position=clipPos;
373
+ }`,da=`#version 300 es
374
+ precision highp float;
375
+ uniform vec4 uOutlineColor;
376
+ out vec4 fragColor;
377
+ void main(){
378
+ fragColor=uOutlineColor;
379
+ }`,Zo=`#version 300 es
380
+ out vec2 vUV;
381
+ void main(){
382
+ vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
383
+ vUV=pos;
384
+ gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
385
+ }`,pa=`#version 300 es
386
+ precision highp float;
387
+ in vec2 vUV;
388
+ uniform sampler2D uSourceTex;
389
+ uniform vec2 uTexelSize;
390
+ uniform float uThreshold;
391
+ out vec4 fragColor;
392
+ vec3 prefilter(vec3 c){
393
+ float br=max(c.r,max(c.g,c.b));
394
+ float knee=max(uThreshold*0.5,1e-4);
395
+ float soft=clamp(br-uThreshold+knee,0.0,2.0*knee);
396
+ soft=(soft*soft)/(4.0*knee+1e-4);
397
+ float contrib=max(soft,br-uThreshold)/max(br,1e-4);
398
+ return c*clamp(contrib,0.0,1.0);
399
+ }
400
+ void main(){
401
+ vec2 h=uTexelSize*0.5;
402
+ vec3 c=prefilter(texture(uSourceTex,vUV).rgb)*0.5;
403
+ c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,-h.y)).rgb)*0.125;
404
+ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
405
+ c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
406
+ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
407
+ fragColor=vec4(c,1.0);
408
+ }`,ba=`#version 300 es
409
+ precision highp float;
410
+ in vec2 vUV;
411
+ uniform sampler2D uBloomTex;
412
+ uniform vec2 uTexelSize;
413
+ uniform float uRadius;
414
+ uniform float uStrength;
415
+ out vec4 fragColor;
416
+ void main(){
417
+ vec2 d=uTexelSize*max(0.25,uRadius*2.5);
418
+ vec3 sum=vec3(0.0);
419
+ sum+=texture(uBloomTex,vUV+vec2(-d.x*2.0,0.0)).rgb;
420
+ sum+=texture(uBloomTex,vUV+vec2(-d.x,d.y)).rgb*2.0;
421
+ sum+=texture(uBloomTex,vUV+vec2(0.0,d.y*2.0)).rgb;
422
+ sum+=texture(uBloomTex,vUV+vec2(d.x,d.y)).rgb*2.0;
423
+ sum+=texture(uBloomTex,vUV+vec2(d.x*2.0,0.0)).rgb;
424
+ sum+=texture(uBloomTex,vUV+vec2(d.x,-d.y)).rgb*2.0;
425
+ sum+=texture(uBloomTex,vUV+vec2(0.0,-d.y*2.0)).rgb;
426
+ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
427
+ vec3 bloom=(sum/12.0)*uStrength;
428
+ float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
429
+ fragColor=vec4(bloom,a);
430
+ }`,vr=3,Tr=new WeakMap;function Ti(t,e=[.22,.74,.97]){let n=Rn(t,"");if(!n.startsWith("#"))return[e[0],e[1],e[2]];let r=n.slice(1);if(r.length===3){let i=+("0x"+r[0]+r[0])/255,o=+("0x"+r[1]+r[1])/255,s=+("0x"+r[2]+r[2])/255;return[i,o,s]}if(r.length===6){let i=+("0x"+r.slice(0,2))/255,o=+("0x"+r.slice(2,4))/255,s=+("0x"+r.slice(4,6))/255;return[i,o,s]}return[e[0],e[1],e[2]]}function Jo(t,e,n=.8,r=.5){let i=Number.isFinite(e)?Math.max(0,e):0;if(i<=0)return[0,0,0];let o=Math.max(0,Number(t[0])||0),s=Math.max(0,Number(t[1])||0),c=Math.max(0,Number(t[2])||0),a=Math.max(o,s,c);if(a<=1e-6)return[0,0,0];let u=Number.isFinite(n)?Math.max(0,n):.8,l=Math.max(u*Math.max(0,r),1e-4),m=Math.max(0,Math.min(2*l,a-u+l)),f=m*m/(4*l+1e-4),b=Math.min(1,Math.max(0,Math.max(f,a-u)/Math.max(a,1e-4)))*i;return[o*b,s*b,c*b]}function es(t,e,n,r){let i=Number(t[0])||0,o=Number(t[1])||0,s=Math.hypot(i,o);if(s<=1e-5||e<=0||n<=0)return[0,0];let c=Math.max(1,Number(r[0])||1),a=Math.max(1,Number(r[1])||1),u=Math.max(0,n)*2*e;return[i/s*(u/c),o/s*(u/a)]}function vi(t,e,n){let r=(o,s)=>{let c=t.createShader(o);return t.shaderSource(c,s),t.compileShader(c),c},i=t.createProgram();return t.attachShader(i,r(35633,e)),t.attachShader(i,r(35632,n)),t.linkProgram(i),i}function Qo(t){let e=Tr.get(t);if(e)return e;let n=vi(t,ha,da),r=vi(t,Zo,pa),i=vi(t,Zo,ba),o=typeof t.createVertexArray=="function"?t.createVertexArray():null;return e={outlineProg:n,uOutlineMVP:t.getUniformLocation(n,"uMVP"),uOutlineVP:t.getUniformLocation(n,"uVP"),uOutlineNormalMatrix:t.getUniformLocation(n,"uNormalMatrix"),uOutlineViewportSize:t.getUniformLocation(n,"uViewportSize"),uOutlineThickness:t.getUniformLocation(n,"uOutlineThickness"),uOutlineColor:t.getUniformLocation(n,"uOutlineColor"),downProg:r,uDownSourceTex:t.getUniformLocation(r,"uSourceTex"),uDownTexelSize:t.getUniformLocation(r,"uTexelSize"),uDownThreshold:t.getUniformLocation(r,"uThreshold"),upProg:i,uUpBloomTex:t.getUniformLocation(i,"uBloomTex"),uUpTexelSize:t.getUniformLocation(i,"uTexelSize"),uUpRadius:t.getUniformLocation(i,"uRadius"),uUpStrength:t.getUniformLocation(i,"uStrength"),fsVao:o,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Tr.set(t,e),e}function ya(t,e,n,r){if(typeof t.createFramebuffer!="function"||typeof t.copyTexSubImage2D!="function")return!1;let i=Math.max(2,n|0),o=Math.max(2,r|0);if(e.sceneTex&&e.bloomFbo.length===vr&&e.texWidth===i&&e.texHeight===o)return!0;e.sceneTex||(e.sceneTex=t.createTexture()),t.bindTexture(3553,e.sceneTex),t.texImage2D(3553,0,6408,i,o,0,6408,5121,null),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071);let s=i,c=o;for(let a=0;a<vr;a++)s=Math.max(1,s>>1),c=Math.max(1,c>>1),e.mipWidth[a]=s,e.mipHeight[a]=c,e.bloomTex[a]||(e.bloomTex[a]=t.createTexture()),t.bindTexture(3553,e.bloomTex[a]),t.texImage2D(3553,0,6408,s,c,0,6408,5121,null),t.texParameteri(3553,10241,9729),t.texParameteri(3553,10240,9729),t.texParameteri(3553,10242,33071),t.texParameteri(3553,10243,33071),e.bloomFbo[a]||(e.bloomFbo[a]=t.createFramebuffer()),t.bindFramebuffer(36160,e.bloomFbo[a]),t.framebufferTexture2D(36160,36064,3553,e.bloomTex[a],0);return t.bindFramebuffer(36160,null),e.texWidth=i,e.texHeight=o,!0}function ga(t){let e=t.container;if(e&&typeof e.getAttribute=="function"){let r=e.getAttribute("bloom");if(r!==null){let i=r.trim().toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let o=i===""||i==="true"?.35:Number(i);if(!Number.isFinite(o)||o<=0)return null;let s=e.getAttribute("bloom-threshold"),c=e.getAttribute("bloom-radius"),a=Br({strength:o,threshold:s!==null?Number(s):.62,radius:c!==null?Number(c):.75});if(a)return a}}let n=null;for(let r of t.meshes||[]){if(r.visible===!1)continue;let i=r?.extras?.xr?.bloom??r?.userData?.xr?.bloom,o=Br(i);o&&(!n||o.strength>n.strength)&&(n=o)}return n}function xa(t,e){if(t==null)return null;let n=t.trim(),r=n.toLowerCase();if(r==="false"||r==="0"||r==="none")return null;let i=e,o=3.5,s=!1;if(n&&r!=="true"){let c=n.split(/\s+/);for(let a of c)if(a.startsWith("#"))i=a;else if(a.toLowerCase()==="pulse")s=!0;else{let u=Number(a);Number.isFinite(u)&&u>0&&(o=u<.25?Math.max(1.5,u*140):u)}}return _n({color:i,thickness:o,pulse:s})}function va(t,e){let n=t.container,r=typeof n?.getAttribute=="function"?n.getAttribute("outline"):null;if(r!=null){let l=r.trim().toLowerCase();if(l==="false"||l==="0"||l==="none")return null}let i=e?.extras?.xr?.outline??e?.userData?.xr?.outline,o=_n(i);if(o)return o;let s=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",c=xa(r,s),a=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",u=t.getSelectedMesh?.()||"";if(u)return e.name!==u?null:c||(a?_n({color:s,thickness:3,pulse:!1}):null);if(c){let l=e.name||"";return/floor|pedestal|ground|table|grid|pad/i.test(l)?null:c}return null}var wi={name:"postprocessing",onAttributeChanged(t,e){(e==="bloom"||e==="bloom-threshold"||e==="bloom-radius"||e==="outline"||e==="outline-selected"||e==="outline-color"||e==="selected-mesh")&&t.viewer?.render?.()},onAfterRender(t,e,n){if(!e.meshes||e.meshes.length===0)return;let r=Math.max(1,e.canvas?.width||300),i=Math.max(1,e.canvas?.height||150),o=[];for(let m of e.meshes){if(m.visible===!1)continue;let f=va(e,m);f&&o.push({mesh:m,trait:f})}if(o.length>0){let m=Qo(t),f=we(),h=we(),b=new Float32Array(9),d=(typeof performance<"u"?performance.now():Date.now())*.001;t.useProgram(m.outlineProg),m.uOutlineViewportSize&&t.uniform2f(m.uOutlineViewportSize,r,i),m.uOutlineVP&&t.uniformMatrix4fv(m.uOutlineVP,!1,n),t.enable(t.CULL_FACE),t.cullFace(t.FRONT),t.enable(2929),t.depthFunc(t.LEQUAL),t.depthMask(!1);for(let{mesh:p,trait:E}of o){let[A,x,R]=Ti(E.color),I=E.pulse?.8+.25*Math.sin(d*4):1;m.uOutlineColor&&t.uniform4f(m.uOutlineColor,A,x,R,1),m.uOutlineThickness&&t.uniform1f(m.uOutlineThickness,E.thickness*I),p.worldSpace===!0?f.set(p.transform):Ee(f,e.modelRootMatrix,p.transform);let P=p.instanceMatrices;for(let k of p.primitives)if(t.bindVertexArray(k.vao),P&&P.length>=16){let D=P.length>>4,S=we();for(let _=0;_<D;_++)Ee(S,f,P.subarray(_*16,_*16+16)),Ee(h,n,S),Le(b,S),t.uniformMatrix4fv(m.uOutlineMVP,!1,h),t.uniformMatrix3fv(m.uOutlineNormalMatrix,!1,b),k.indices?t.drawElements(4,k.indexCount,k.indexType,0):t.drawArrays(4,0,k.indexCount)}else Ee(h,n,f),Le(b,f),t.uniformMatrix4fv(m.uOutlineMVP,!1,h),t.uniformMatrix3fv(m.uOutlineNormalMatrix,!1,b),k.indices?t.drawElements(4,k.indexCount,k.indexType,0):t.drawArrays(4,0,k.indexCount)}t.bindVertexArray(null),t.cullFace(t.BACK),t.disable(t.CULL_FACE),t.depthFunc(t.LESS),t.depthMask(!0)}if(e.xrSessionActive||e.stereoSBS)return;let s=ga(e);if(!s||s.strength<=0)return;let c=Qo(t);if(!ya(t,c,r,i)||!c.fsVao)return;t.activeTexture(33984),t.bindTexture(3553,c.sceneTex),t.copyTexSubImage2D(3553,0,0,0,0,0,r,i),t.disable(2929),t.depthMask(!1),t.disable(3042),t.useProgram(c.downProg),t.uniform1i(c.uDownSourceTex,0),t.bindVertexArray(c.fsVao);let a=c.sceneTex,u=r,l=i;for(let m=0;m<vr;m++){let f=c.mipWidth[m],h=c.mipHeight[m];t.bindFramebuffer(36160,c.bloomFbo[m]),t.viewport(0,0,f,h),t.bindTexture(3553,a),t.uniform2f(c.uDownTexelSize,1/u,1/l),t.uniform1f(c.uDownThreshold,m===0?s.threshold:0),t.drawArrays(4,0,3),a=c.bloomTex[m],u=f,l=h}t.enable(3042),typeof t.blendFuncSeparate=="function"?t.blendFuncSeparate(t.ONE,t.ONE,t.ONE,771):t.blendFunc(t.ONE,t.ONE),t.useProgram(c.upProg),t.uniform1i(c.uUpBloomTex,0),t.uniform1f(c.uUpRadius,s.radius);for(let m=vr-1;m>=1;m--){let f=m-1;t.bindFramebuffer(36160,c.bloomFbo[f]),t.viewport(0,0,c.mipWidth[f],c.mipHeight[f]),t.bindTexture(3553,c.bloomTex[m]),t.uniform2f(c.uUpTexelSize,1/c.mipWidth[m],1/c.mipHeight[m]),t.uniform1f(c.uUpStrength,.85),t.drawArrays(4,0,3)}t.bindFramebuffer(36160,null),t.viewport(0,0,r,i),t.bindTexture(3553,c.bloomTex[0]),t.uniform2f(c.uUpTexelSize,1/c.mipWidth[0],1/c.mipHeight[0]),t.uniform1f(c.uUpStrength,s.strength),t.drawArrays(4,0,3),t.bindVertexArray(null),t.blendFunc(770,771),t.disable(3042),t.depthMask(!0),t.enable(2929)},onDestroy(t){let e=Tr.get(t);if(e){t.deleteProgram(e.outlineProg),t.deleteProgram(e.downProg),t.deleteProgram(e.upProg),e.fsVao&&t.deleteVertexArray(e.fsVao),e.sceneTex&&t.deleteTexture(e.sceneTex);for(let n of e.bloomTex)n&&t.deleteTexture(n);for(let n of e.bloomFbo)n&&t.deleteFramebuffer(n);Tr.delete(t)}}};function Mi(t){let n=t?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(n))return[];let r=[];for(let i=0;i<n.length&&r.length<256;i++){let o=n[i]?.name;r.push(typeof o=="string"&&o.length>0?o:`Variant_${i}`)}return r}function ts(t){let n=t?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(n))return[];let r=[];for(let i of n){if(!i||typeof i!="object")continue;let o=i,s=Number(o.material);if(!Number.isInteger(s)||s<0)continue;let c=[];if(Array.isArray(o.variants))for(let a of o.variants){let u=Number(a);Number.isInteger(u)&&u>=0&&c.push(u)}c.length>0&&r.push({material:s,variants:c})}return r}function ns(t,e,n,r=0){let i=t;if(i&&typeof i.selectVariant=="function"&&!Array.isArray(e))return i.selectVariant(typeof e=="string"?e:null);let o=t,s=Array.isArray(e)?e:[],c=n??null;if(!c)return r;let u=Mi(o).indexOf(c);if(u<0)return r;for(let l of s)if(l.variants.includes(u))return l.material;return r}var Ai={name:"variants",onLoadModel(t,e){let n=t.getVariantName?.();n&&t.selectVariant(n)}};var rs=new WeakMap,Si={name:"webxr-suite",onConfigureXRSessionInit(t,e){let n=new Set(e.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=t?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),e.domOverlay={root:r},r.addEventListener?.("beforexrselect",i=>{i.preventDefault()})),e.optionalFeatures=Array.from(n)},onXRFrame(t,e,n,r){if(!t||!e||!n||!r)return;let i=rs.get(e);if(i||(i={lightProbe:null},rs.set(e,i),typeof e.requestLightProbe=="function"&&e.requestLightProbe().then(o=>{i&&o&&(i.lightProbe=o)}).catch(()=>{})),i.lightProbe&&typeof n.getLightEstimate=="function"){let o=n.getLightEstimate(i.lightProbe);if(o){let s=o.primaryLightDirection,c=o.primaryLightIntensity;if(s&&c&&Array.isArray(t.lights)){let a=t.lights.find(l=>l.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(a)),a.direction=[s.x,s.y,s.z];let u=Math.max(c.x,c.y,c.z,.001);a.color=[c.x/u,c.y/u,c.z/u],a.intensity=u}o.sphericalHarmonicsCoefficients&&t.gl&&fr(t.gl,o.sphericalHarmonicsCoefficients)}}}};Pe(fn);Pe(li);Pe(ai);Pe(bi);Pe(Si);Pe(di);Pe(xi);Pe(Ai);Pe(wi);Je.registerScriptRunner(Gt);typeof window<"u"&&(window.ThreeLiveBundle=Ei);