three-live 1.3.0 → 1.3.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 (42) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +37 -0
  3. package/dist/three-author-engine.js +112 -61
  4. package/dist/three-author.cjs +110 -59
  5. package/dist/three-author.d.ts +37 -0
  6. package/dist/three-author.js +109 -58
  7. package/dist/three-convert.cjs +106 -59
  8. package/dist/three-convert.d.ts +37 -0
  9. package/dist/three-convert.js +105 -58
  10. package/dist/three-live-animation.cjs +8 -9
  11. package/dist/three-live-animation.d.ts +37 -0
  12. package/dist/three-live-animation.js +7 -8
  13. package/dist/three-live-animation.min.js +6 -7
  14. package/dist/three-live-cad.cjs +3 -4
  15. package/dist/three-live-cad.d.ts +37 -0
  16. package/dist/three-live-cad.js +2 -3
  17. package/dist/three-live-cad.min.js +3 -4
  18. package/dist/three-live-cli.js +231 -0
  19. package/dist/three-live-element.cjs +17 -20
  20. package/dist/three-live-element.d.ts +37 -0
  21. package/dist/three-live-element.js +16 -19
  22. package/dist/three-live-full.cjs +138 -87
  23. package/dist/three-live-full.js +137 -86
  24. package/dist/three-live-full.min.js +138 -87
  25. package/dist/three-live-studio.cjs +19 -20
  26. package/dist/three-live-studio.d.ts +37 -0
  27. package/dist/three-live-studio.js +18 -19
  28. package/dist/three-live-studio.min.js +18 -19
  29. package/dist/three-live-viewer.cjs +17 -20
  30. package/dist/three-live-viewer.d.ts +37 -0
  31. package/dist/three-live-viewer.js +16 -19
  32. package/dist/three-live-viewer.min.js +17 -20
  33. package/dist/three-live.cjs +115 -64
  34. package/dist/three-live.js +113 -62
  35. package/dist/three-live.min.js +115 -64
  36. package/dist/three-view.cjs +17 -20
  37. package/dist/three-view.d.ts +37 -0
  38. package/dist/three-view.js +16 -19
  39. package/dist/three-xr.cjs +105 -58
  40. package/dist/three-xr.d.ts +37 -0
  41. package/dist/three-xr.js +104 -57
  42. package/package.json +25 -1
@@ -1,4 +1,4 @@
1
- /**
1
+ "use strict";/**
2
2
  * @license
3
3
  * Copyright 2026 Google LLC
4
4
  *
@@ -13,9 +13,8 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */
17
- "use strict";var ThreeLiveBundle=(()=>{var Vr=Object.defineProperty;var Ws=Object.getOwnPropertyDescriptor;var $s=Object.getOwnPropertyNames;var js=Object.prototype.hasOwnProperty;var qs=(t,e)=>{for(var n in e)Vr(t,n,{get:e[n],enumerable:!0})},Ks=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of $s(e))!js.call(t,i)&&i!==n&&Vr(t,i,{get:()=>e[i],enumerable:!(r=Ws(e,i))||r.enumerable});return t};var Ys=t=>Ks(Vr({},"__esModule",{value:!0}),t);var ji={};qs(ji,{AmbientLight:()=>vn,BoxGeometry:()=>pn,BufferAttribute:()=>$e,BufferGeometry:()=>Ye,Camera:()=>wn,CapsuleGeometry:()=>gr,CircleGeometry:()=>vr,Clock:()=>mr,Color:()=>et,ConeGeometry:()=>er,CylinderGeometry:()=>_t,DirectionalLight:()=>ur,DodecahedronGeometry:()=>br,Euler:()=>dn,Float32BufferAttribute:()=>Yn,Group:()=>cr,HemisphereLight:()=>Sn,IKSolver:()=>po,IcosahedronGeometry:()=>hr,InstancedMesh:()=>xn,InteractivityVM:()=>In,Light:()=>Dt,MAX_BSP_DEPTH:()=>co,MAX_CSG_TRIANGLES:()=>ao,MAX_INSTANCES_PER_MESH:()=>gn,MAX_SHAPE_POINTS:()=>lo,MAX_TEXT_GEOMETRY_CHARS:()=>uo,Material:()=>at,MathUtils:()=>Xo,Matrix3:()=>Kn,Matrix4:()=>Pt,Mesh:()=>Nt,MeshBasicMaterial:()=>ir,MeshLambertMaterial:()=>or,MeshPhongMaterial:()=>sr,MeshPhysicalMaterial:()=>ar,MeshStandardMaterial:()=>kt,Object3D:()=>tt,OctahedronGeometry:()=>pr,PerspectiveCamera:()=>lr,PlaneGeometry:()=>Jn,PointLight:()=>Tn,PolyhedronFallbackGeometry:()=>Ut,Quaternion:()=>hn,RawShaderMaterial:()=>ts,RectAreaLight:()=>ns,RingGeometry:()=>xr,Scene:()=>Mn,SceneQuotaValidator:()=>st,ShaderMaterial:()=>An,SphereGeometry:()=>bn,SpotLight:()=>Tr,THREE:()=>Ot,TetrahedronGeometry:()=>yr,Texture:()=>yn,TextureLoader:()=>rr,ThreeLiveElement:()=>ct,ThreeView:()=>He,TorusGeometry:()=>tr,TorusKnotGeometry:()=>nr,Uint16BufferAttribute:()=>Zn,Uint32BufferAttribute:()=>Qn,Vector2:()=>jn,Vector3:()=>Ue,Vector4:()=>qn,WebGLRenderer:()=>fr,activateAR:()=>Rr,applyMeshoptFilter:()=>Vi,authorScriptRunner:()=>en,buildSandboxWorkerSource:()=>li,cadPlugin:()=>Br,clearAuthorWarnings:()=>es,computeOutlineClipOffset:()=>Vs,contactShadowPlugin:()=>_n,createUSDZBlob:()=>Qt,crossFadeTo:()=>yi,decodeMeshoptBuffer:()=>Bi,decodeMeshoptGLB:()=>Dr,encodeMeshoptBuffer:()=>Ns,environmentMapPlugin:()=>Ii,evaluateKawaseBloom:()=>Fs,evaluateToneMapping:()=>So,exportSceneToCanvas3D:()=>ai,exportSceneToGLB:()=>ci,exportSceneToUSDZ:()=>$o,extractMaterialVariants:()=>Xi,extractPrimitiveVariantMappings:()=>Bs,generateUSDZ:()=>un,getARCapabilities:()=>Sr,getAllowClientScripts:()=>Ko,getAuthorWarnings:()=>Jo,getBestARMode:()=>ls,getEnvironmentSH:()=>ds,getInteractivityVM:()=>Pr,getSandboxEngineSrc:()=>ui,getSandboxIframeSrc:()=>qo,glbToUSDZ:()=>cn,hotspotPlugin:()=>ki,ikPlugin:()=>Yr,installCadExtension:()=>Fn,interactivityPlugin:()=>Oi,isAllowedSandboxEngineUrl:()=>Lt,isQuickLookSupported:()=>Si,isSceneViewerSupported:()=>Ri,isWebXRSupported:()=>Ei,keyframeAnimationPlugin:()=>gi,materialsPlugin:()=>Fi,meshoptDecoder:()=>Ur,meshoptPlugin:()=>zi,morphPlugin:()=>xi,noopProxy:()=>fn,parseAnimations:()=>bi,parseHexRgb:()=>Gi,parseSafeGltfPointer:()=>Ln,postprocessingPlugin:()=>Hi,quatFromUnitVectors:()=>zn,registerMaterialShader:()=>Ts,sampleChannel:()=>nn,sceneToCanvas3D:()=>Yt,sceneToGLB:()=>an,sceneToUSDZ:()=>Zt,selectMaterialVariant:()=>zs,sendInteractivityEvent:()=>Ui,setAllowClientScripts:()=>ka,setEnvironmentSH:()=>Er,setMorphTargetWeight:()=>ss,setSandboxEngineSrc:()=>La,setSandboxIframeSrc:()=>Ca,skinningPlugin:()=>Ti,solveFABRIK:()=>qr,solveTwoBoneIK:()=>jr,threeAuthorPlugin:()=>mn,threeMicroPlugin:()=>Ga,toGLBData:()=>ht,toTrustedWorkerScriptURL:()=>jo,validateSandboxWorkerMessage:()=>fi,variantsPlugin:()=>Wi,warnUnsupported:()=>Ze,webxrPlugin:()=>$i});function so(t,e,n){let r=[],i=new Map,o=[],a=[],u=[],s=new Map,c=b=>{let w=i.get(b);return w===void 0&&(w=r.length,r.push({op:b}),i.set(b,w)),w},l=b=>{let w=s.get(b);return w===void 0&&(w=u.length,u.push({id:b}),s.set(b,w)),w},m=(b,w={})=>o.push({declaration:c(b),...w})-1,f=(b,w,M)=>a.push({id:b,type:w,value:M})-1,h=b=>({node:b,socket:"value"}),p=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(p&&typeof p=="object"){let b=Array.isArray(p.graphs)?p.graphs[p.graph??0]:p;if(b&&Array.isArray(b.nodes)){let w=Array.isArray(b.declarations)?b.declarations:[];for(let M of w)M?.op&&c(M.op);Array.isArray(b.variables)&&a.push(...b.variables);for(let M of b.events||[])M?.id&&l(M.id);for(let M of b.nodes){if(!M||typeof M!="object")continue;let P=M.op||(typeof M.declaration=="number"?w[M.declaration]?.op:"");o.push(P?{...M,declaration:c(P)}:{...M})}}}let d=(b,w,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,w)}/${M}`:M==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${M}`,y=new Map;t.forEach((b,w)=>{typeof b?.name=="string"&&!y.has(b.name)&&y.set(b.name,w)});let v=(b,w)=>typeof b.target=="string"&&y.has(b.target)?y.get(b.target):typeof b.targetNode=="number"?b.targetNode:w,R=b=>{let w=t[b];return(typeof w?.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<t.length;b++){let w=t[b],M=w?.extras?.interactivity;if(!M||typeof M!="object")continue;let P=(typeof w.mesh=="number"?e[w.mesh]?.primitives?.[0]?.material:0)??0,k=L=>{let x=Array.isArray(L)?L:[L],g=[];for(let N=0;N<x.length;N++){let _=x[N];if(!_||typeof _!="object")continue;let O=_.action||"interpolate",Q=typeof _.duration=="number"?_.duration:.35;if(O==="toggleTransform"){let q=_.property==="rotation"||_.property==="scale"?_.property:"translation",oe=q==="rotation"?w.rotation||[0,0,0,1]:q==="scale"?w.scale||[1,1,1]:w.translation||[0,0,0],ne=`/nodes/${b}/${q}`,re=f(`__toggle_${b}_${N}`,"bool",!1),H=m("variable/get",{configuration:{variable:re}}),se=m("math/not",{values:{a:h(H)}}),ae=m("variable/set",{configuration:{variable:re},values:{value:h(se)}}),D=m("pointer/interpolate",{configuration:{pointer:ne},values:{value:{value:Array.isArray(_.to)?_.to:oe},duration:{value:Q}}}),G=m("pointer/interpolate",{configuration:{pointer:ne},values:{value:{value:Array.isArray(_.from)?_.from:oe},duration:{value:Q}}});o[ae].flows={out:{node:m("flow/branch",{values:{condition:h(H)},flows:{true:{node:D},false:{node:G}}})}},g.push(ae)}else if(O==="interpolate"){let q=_.to??_.value;if(q===void 0)continue;let oe={value:{value:q},duration:{value:Q}};_.from!==void 0&&(oe.from={value:_.from}),g.push(m("pointer/interpolate",{configuration:{pointer:typeof _.pointer=="string"?_.pointer:d(v(_,b),R(v(_,b)),_.property)},values:oe}))}else if(O==="setProperty"){if(_.value===void 0)continue;g.push(m("pointer/set",{configuration:{pointer:typeof _.pointer=="string"?_.pointer:d(v(_,b),R(v(_,b)),_.property)},values:{value:{value:_.value}}}))}else if(O==="toggleVisibility"){let q=v(_,b),oe=f(`__vis_${q}_${N}`,"bool",!0),ne=m("variable/get",{configuration:{variable:oe}}),re=m("math/not",{values:{a:h(ne)}}),H=m("variable/set",{configuration:{variable:oe},values:{value:h(re)}});o[H].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${q}/extensions/KHR_node_visibility/visible`},values:{value:h(ne)}})}},g.push(H)}else if(O==="cycleMaterialColor"&&Array.isArray(_.colors)&&_.colors.length>0){let q=typeof _.duration=="number"?_.duration:.25,oe=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,ne=f(`__color_idx_${b}_${N}`,"int",0),re=m("variable/get",{configuration:{variable:ne}}),H=m("math/add",{values:{a:h(re),b:{value:1}}}),se=m("math/rem",{values:{a:h(H),b:{value:_.colors.length}}}),ae=m("variable/set",{configuration:{variable:ne},values:{value:h(se)}}),D={};for(let G=0;G<_.colors.length;G++){let E=_.colors[G],V=Array.isArray(E)&&E.length>=3?[E[0],E[1],E[2],E[3]??1]:[1,1,1,1];D[String(G)]={node:q>0?m("pointer/interpolate",{configuration:{pointer:oe},values:{value:{value:V},duration:{value:q}}}):m("pointer/set",{configuration:{pointer:oe},values:{value:{value:V}}})}}o[ae].flows={out:{node:m("flow/switch",{values:{selection:h(re)},flows:D})}},g.push(ae)}else if(O==="playAnimation")g.push(m("animation/start",{configuration:{animation:_.animation??_.clip??0}}));else if(O==="stopAnimation")g.push(m("animation/stop"));else if(O==="sendEvent"){let q={};for(let[oe,ne]of Object.entries(_.values||{}))q[oe]={value:ne};g.push(m("event/send",{configuration:{event:l(String(_.event??_.id??"custom"))},values:q}))}}if(!g.length)return null;if(g.length===1)return g[0];let A={};return g.forEach((N,_)=>{A[String(_)]={node:N}}),m("flow/sequence",{flows:A})},I=(L,x,g)=>{let A=k(x);A!==null&&m(L,{...g?{configuration:g}:{},flows:{out:{node:A}}})};if(M.onSelect&&I("pointer/onSelect",M.onSelect,{nodeIndex:b}),M.onHoverIn&&I("pointer/onHoverIn",M.onHoverIn,{nodeIndex:b}),M.onHoverOut&&I("pointer/onHoverOut",M.onHoverOut,{nodeIndex:b}),M.onStart&&I("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[L,x]of Object.entries(M.onReceive))I("event/receive",x,{event:l(L)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:a,events:u}],graph:0}:null}var kn='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).',Nn="Security Error: client-side scripts require allow-client-scripts opt-in.";var Dn="__THREE_LIVE_REGISTRY__";function ve(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Dn]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Dn,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Dn]=e}}return t[Dn]}var De=ve().plugins;function Un(t){let e=ve();e.workerExtensionInstallers||(e.workerExtensionInstallers=[]),e.workerExtensionInstallers.includes(t)||e.workerExtensionInstallers.push(t)}function Oe(t){let e=ve().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function On(){return ve().plugins}var ao=8192,co=2048,uo=128,lo=4096;function Fn(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,a=t.Matrix3,u=t.Color,s=t.BufferAttribute,c=t.BufferGeometry,l=t.Material,m=t.MeshStandardMaterial,f=t.Mesh,h=8192,p=2048,d=128,y=4096,v=(T,S)=>{let C=T==null?NaN:Number(T);return Number.isFinite(C)?C:S};class R{constructor(S){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(S)&&S.length>0&&this.fromPoints(S)}fromPoints(S){if(!S.length)return this;this.moveTo(S[0].x,S[0].y);for(let C=1;C<S.length;C++)this.lineTo(S[C].x,S[C].y);return this}moveTo(S,C){let B=Number(S)||0,X=Number(C)||0;return this.currentPoint.set(B,X),this.segments.push({type:"move",pts:[B,X]}),this}lineTo(S,C){let B=Number(S)||0,X=Number(C)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(B,X),this.segments.push({type:"line",pts:[B,X]}),this}quadraticCurveTo(S,C,B,X){let W=this.currentPoint.x,$=this.currentPoint.y,K=Number(S)||0,Z=Number(C)||0,j=Number(B)||0,te=Number(X)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[W,$]}),this.currentPoint.set(j,te),this.segments.push({type:"quad",pts:[W,$,K,Z,j,te]}),this}bezierCurveTo(S,C,B,X,W,$){let K=this.currentPoint.x,Z=this.currentPoint.y,j=Number(S)||0,te=Number(C)||0,ee=Number(B)||0,J=Number(X)||0,ue=Number(W)||0,fe=Number($)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[K,Z]}),this.currentPoint.set(ue,fe),this.segments.push({type:"cubic",pts:[K,Z,j,te,ee,J,ue,fe]}),this}absarc(S,C,B,X,W,$=!1){return this.absellipse(S,C,B,B,X,W,$,0)}arc(S,C,B,X,W,$=!1){return this.absarc(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(C)||0),B,X,W,$)}absellipse(S,C,B,X,W,$,K=!1,Z=0){let j=Number(S)||0,te=Number(C)||0,ee=Math.max(0,Number(B)||0),J=Math.max(0,Number(X)||0),ue=Number(W)||0,fe=Number($)||0,pe=K?1:0,me=Number(Z)||0;this.segments.push({type:"arc",pts:[j,te,ee,J,ue,fe,pe,me]});let ce=Math.cos(me),be=Math.sin(me),xe=ee*Math.cos(fe),ye=J*Math.sin(fe);return this.currentPoint.set(j+xe*ce-ye*be,te+xe*be+ye*ce),this}ellipse(S,C,B,X,W,$,K=!1,Z=0){return this.absellipse(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(C)||0),B,X,W,$,K,Z)}closePath(){if(this.segments.length>0){let S=this.segments[0],C=0,B=0;if(S.type==="arc"){let X=S.pts[0],W=S.pts[1],$=S.pts[2],K=S.pts[3],Z=S.pts[4],j=S.pts[7],te=Math.cos(j),ee=Math.sin(j),J=$*Math.cos(Z),ue=K*Math.sin(Z);C=X+J*te-ue*ee,B=W+J*ee+ue*te}else C=S.pts[0],B=S.pts[1];Math.hypot(this.currentPoint.x-C,this.currentPoint.y-B)>1e-6&&this.lineTo(C,B)}return this}getPoints(S=12){let C=Math.max(1,Math.min(128,Math.floor(Number(S)||12))),B=[],X=(W,$)=>{if(B.length>0){let K=B[B.length-1];if(Math.hypot(K.x-W,K.y-$)<1e-6)return}B.push(new n(W,$))};for(let W of this.segments){let $=W.pts;if(W.type==="move"||W.type==="line")X($[0],$[1]);else if(W.type==="quad"){let K=$[0],Z=$[1],j=$[2],te=$[3],ee=$[4],J=$[5];X(K,Z);for(let ue=1;ue<=C;ue++){let fe=ue/C,pe=1-fe;X(pe*pe*K+2*pe*fe*j+fe*fe*ee,pe*pe*Z+2*pe*fe*te+fe*fe*J)}}else if(W.type==="cubic"){let K=$[0],Z=$[1],j=$[2],te=$[3],ee=$[4],J=$[5],ue=$[6],fe=$[7];X(K,Z);for(let pe=1;pe<=C;pe++){let me=pe/C,ce=1-me,be=ce*ce,xe=me*me;X(be*ce*K+3*be*me*j+3*ce*xe*ee+xe*me*ue,be*ce*Z+3*be*me*te+3*ce*xe*J+xe*me*fe)}}else if(W.type==="arc"){let K=$[0],Z=$[1],j=$[2],te=$[3],ee=$[4],J=$[5],ue=$[6]!==0,fe=$[7],pe=Math.PI*2,me=J-ee,ce=Math.abs(me)<1e-9;for(;me<0;)me+=pe;for(;me>pe;)me-=pe;me<1e-9&&(me=ce?0:pe),ue&&!ce&&(me=me===pe?-pe:me-pe);let be=Math.cos(fe),xe=Math.sin(fe),ye=Math.max(2,C);for(let Re=0;Re<=ye;Re++){let Me=Re/ye,Ee=ee+Me*me,Ie=j*Math.cos(Ee),Pe=te*Math.sin(Ee);X(K+Ie*be-Pe*xe,Z+Ie*xe+Pe*be)}}}if(B.length>2){let W=B[0],$=B[B.length-1];Math.hypot(W.x-$.x,W.y-$.y)<1e-6&&B.pop()}return B}getSpacedPoints(S=12){return this.getPoints(S)}}class b extends R{constructor(S){super(S),this.holes=[]}extractPoints(S=12){return{shape:this.getPoints(S),holes:this.holes.map(C=>C.getPoints(S))}}}function w(T){let S=0,C=T.length;for(let B=0,X=C-1;B<C;X=B++)S+=T[X].x*T[B].y-T[B].x*T[X].y;return S*.5}function M(T,S,C,B,X,W,$,K){let Z=$-C,j=K-B,te=X-C,ee=W-B,J=T-C,ue=S-B,fe=Z*Z+j*j,pe=Z*te+j*ee,me=Z*J+j*ue,ce=te*te+ee*ee,be=te*J+ee*ue,xe=fe*ce-pe*pe;if(Math.abs(xe)<1e-12)return!1;let ye=1/xe,Re=(ce*me-pe*be)*ye,Me=(fe*be-pe*me)*ye;return Re>=-1e-7&&Me>=-1e-7&&Re+Me<=1+1e-7}function P(T,S){let C=T.slice();w(C)<0&&C.reverse();let B=C.map(Z=>new n(Z.x,Z.y)),X=C.map((Z,j)=>j),W=[];for(let Z of S){if(!Z||Z.length<3)continue;let j=Z.slice();w(j)>0&&j.reverse();let te=[],ee=-1/0,J=0;for(let ue=0;ue<j.length;ue++){let fe=j[ue],pe=B.length;B.push(new n(fe.x,fe.y)),te.push(pe),fe.x>ee&&(ee=fe.x,J=ue)}W.push({pts:j,indices:te,maxX:ee,maxIdx:J})}W.sort((Z,j)=>j.maxX-Z.maxX);let $=(Z,j,te)=>(j.x-Z.x)*(te.y-Z.y)-(j.y-Z.y)*(te.x-Z.x),K=(Z,j,te)=>{for(let ee=0;ee<te.length;ee++){let J=te[ee],ue=te[(ee+1)%te.length];if($(Z,j,J)*$(Z,j,ue)<0&&$(J,ue,Z)*$(J,ue,j)<0)return!0}return!1};for(let Z of W){let j=Z.pts[Z.maxIdx],te=j.x,ee=X.length,J=X.map(ce=>B[ce]),ue=ce=>Math.hypot(J[ce].x-te,J[ce].y-j.y),fe=J.map((ce,be)=>be).sort((ce,be)=>+(J[ce].x<te)-+(J[be].x<te)||ue(ce)-ue(be)),pe=fe[0];for(let ce of fe){let be=J[ce],xe=J[(ce+ee-1)%ee],ye=J[(ce+1)%ee],Re=$(be,ye,j)>=0,Me=$(xe,be,j)>=0;if(($(xe,be,ye)>=0?Re&&Me:Re||Me)&&!K(j,be,J)&&!W.some(Ie=>K(j,be,Ie.pts))){pe=ce;break}}let me=[];for(let ce=0;ce<=pe;ce++)me.push(X[ce]);for(let ce=0;ce<=Z.indices.length;ce++){let be=Z.indices[(Z.maxIdx+ce)%Z.indices.length];me.push(be)}for(let ce=pe;ce<X.length;ce++)me.push(X[ce]);X=me}return{merged:X.map(Z=>B[Z]),mergedIndices:X,allVertices:B}}function k(T,S){let C=[],B=T.slice();if(B.length<3)return C;let X=B.length*B.length+64,W=0;for(;B.length>2&&X-- >0;){let $=B.length,K=B[(W+$-1)%$],Z=B[W%$],j=B[(W+1)%$],te=S[K],ee=S[Z],J=S[j];if((ee.x-te.x)*(J.y-te.y)-(ee.y-te.y)*(J.x-te.x)>1e-9){let fe=!0;for(let pe=0;pe<$;pe++){let me=B[pe];if(me===K||me===Z||me===j)continue;let ce=S[me];if(M(ce.x,ce.y,te.x,te.y,ee.x,ee.y,J.x,J.y)&&Math.hypot(ce.x-te.x,ce.y-te.y)>=1e-6&&Math.hypot(ce.x-ee.x,ce.y-ee.y)>=1e-6&&Math.hypot(ce.x-J.x,ce.y-J.y)>=1e-6){fe=!1;break}}if(fe){C.push([K,Z,j]),B.splice(W%$,1),W=Math.max(0,W%$-1);continue}}W++,W>=$*2&&(C.push([K,Z,j]),B.splice((W-1)%$,1),W=0)}return C}function I(T,S){let C=T instanceof b?T.extractPoints(S):{shape:T.getPoints(S),holes:[]},B=C.shape.length;for(let X of C.holes)B+=X.length;if(B>y)throw new RangeError(`SecurityError: shape point count (${B}) exceeds MAX_SHAPE_POINTS (${y})`);return C}class L extends c{constructor(S=new b,C=12){super();let B=Array.isArray(S)?S:[S],X=[],W=[],$=[],K=[];for(let Z of B){if(!(Z instanceof R))continue;let j=I(Z,C);if(j.shape.length<3)continue;let{mergedIndices:te,allVertices:ee}=P(j.shape,j.holes),J=k(te,ee),ue=X.length/3,fe=1/0,pe=1/0,me=-1/0,ce=-1/0;for(let ye of ee)ye.x<fe&&(fe=ye.x),ye.y<pe&&(pe=ye.y),ye.x>me&&(me=ye.x),ye.y>ce&&(ce=ye.y);let be=Math.max(1e-6,me-fe),xe=Math.max(1e-6,ce-pe);for(let ye of ee)X.push(ye.x,ye.y,0),W.push(0,0,1),$.push((ye.x-fe)/be,(ye.y-pe)/xe);for(let[ye,Re,Me]of J)K.push(ue+ye,ue+Re,ue+Me)}x(this,X,W,$,K)}}function x(T,S,C,B,X){return T.setAttribute("position",new s(S,3)),T.setAttribute("normal",new s(C,3)),T.setAttribute("uv",new s(B,2)),T.setIndex(X),T}function g(T){let S=T.length,C=[];for(let B=0;B<S;B++){let X=T[(B+S-1)%S],W=T[B],$=T[(B+1)%S],K=W.x-X.x,Z=W.y-X.y,j=Math.hypot(K,Z)||1;K/=j,Z/=j;let te=$.x-W.x,ee=$.y-W.y,J=Math.hypot(te,ee)||1;te/=J,ee/=J;let ue=Z,fe=-K,pe=ee,me=-te,ce=ue+pe,be=fe+me,xe=Math.hypot(ce,be);if(xe>1e-6){ce/=xe,be/=xe;let ye=Math.max(.35,ce*ue+be*fe);C.push(new n(ce/ye,be/ye))}else C.push(new n(ue,fe))}return C}class A extends c{constructor(S=new b,C={}){super();let B=Array.isArray(S)?S:[S],X=Math.max(1,Math.min(64,Math.floor(v(C.curveSegments,12)))),W=v(C.depth??C.amount,1),$=Math.max(1,Math.min(32,Math.floor(v(C.steps,1)))),K=!!(C.bevelEnabled??!1),Z=K?Math.max(0,v(C.bevelThickness,.06)):0,j=K?Math.max(0,v(C.bevelSize,Z*.8)):0,te=K?v(C.bevelOffset,0):0,ee=K?Math.max(1,Math.min(8,Math.floor(v(C.bevelSegments,2)))):0,J=[],ue=[],fe=[],pe=[];for(let me of B){if(!(me instanceof R))continue;let ce=I(me,X);if(ce.shape.length<3)continue;let be=ce.shape.slice();w(be)<0&&be.reverse();let xe=[];for(let ge of ce.holes){if(ge.length<3)continue;let _e=ge.slice();w(_e)>0&&_e.reverse(),xe.push(_e)}let{mergedIndices:ye,allVertices:Re}=P(be,xe),Me=k(ye,Re),Ee=[be,...xe],Ie=[];for(let ge of Ee){let _e=g(ge);for(let Ce of _e)Ie.push(Ce)}let Pe=1/0,Ge=1/0,ze=-1/0,Ke=-1/0;for(let ge of Re)ge.x<Pe&&(Pe=ge.x),ge.y<Ge&&(Ge=ge.y),ge.x>ze&&(ze=ge.x),ge.y>Ke&&(Ke=ge.y);let Xe=Math.max(1e-6,ze-Pe),rt=Math.max(1e-6,Ke-Ge),Bt=-Z,zt=W+Z,yt=J.length/3;for(let ge=0;ge<Re.length;ge++){let _e=Re[ge],Ce=Ie[ge]??new n(0,0),Fe=_e.x+Ce.x*te,Ve=_e.y+Ce.y*te;J.push(Fe,Ve,Bt),ue.push(0,0,-1),fe.push((Fe-Pe)/Xe,(Ve-Ge)/rt)}for(let[ge,_e,Ce]of Me)pe.push(yt+ge,yt+Ce,yt+_e);let gt=J.length/3;for(let ge=0;ge<Re.length;ge++){let _e=Re[ge],Ce=Ie[ge]??new n(0,0),Fe=_e.x+Ce.x*te,Ve=_e.y+Ce.y*te;J.push(Fe,Ve,zt),ue.push(0,0,1),fe.push((Fe-Pe)/Xe,(Ve-Ge)/rt)}for(let[ge,_e,Ce]of Me)pe.push(gt+ge,gt+_e,gt+Ce);let je=[];if(K&&ee>0)for(let ge=0;ge<ee;ge++){let Ce=ge/ee*Math.PI/2;je.push({z:-Z*Math.cos(Ce),expand:te+j*Math.sin(Ce)})}for(let ge=0;ge<=$;ge++){let _e=ge/$;je.push({z:_e*W,expand:te+j})}if(K&&ee>0)for(let ge=1;ge<=ee;ge++){let Ce=ge/ee*Math.PI/2;je.push({z:W+Z*Math.sin(Ce),expand:te+j*Math.cos(Ce)})}let it=0;for(let ge of Ee){let _e=ge.length;for(let Ce=0;Ce<je.length-1;Ce++){let Fe=je[Ce],Ve=je[Ce+1];for(let qe=0;qe<_e;qe++){let ft=(qe+1)%_e,xt=ge[qe],vt=ge[ft],Tt=Ie[it+qe],wt=Ie[it+ft],Mt=xt.x+Tt.x*Fe.expand,At=xt.y+Tt.y*Fe.expand,It=vt.x+wt.x*Fe.expand,mt=vt.y+wt.y*Fe.expand,Hs=vt.x+wt.x*Ve.expand,Xs=vt.y+wt.y*Ve.expand,qi=xt.x+Tt.x*Ve.expand,Ki=xt.y+Tt.y*Ve.expand,Yi=It-Mt,Zi=mt-At,Qi=0,Ji=qi-Mt,eo=Ki-At,to=Ve.z-Fe.z,Gt=Zi*to-Qi*eo,Ht=Qi*Ji-Yi*to,Xt=Yi*eo-Zi*Ji,Fr=Math.hypot(Gt,Ht,Xt)||1;Gt/=Fr,Ht/=Fr,Xt/=Fr;let Wt=J.length/3;J.push(Mt,At,Fe.z,It,mt,Fe.z,Hs,Xs,Ve.z,qi,Ki,Ve.z),ue.push(Gt,Ht,Xt,Gt,Ht,Xt,Gt,Ht,Xt,Gt,Ht,Xt);let no=qe/_e,ro=(qe+1)/_e,io=Ce/(je.length-1),oo=(Ce+1)/(je.length-1);fe.push(no,io,ro,io,ro,oo,no,oo),pe.push(Wt,Wt+1,Wt+2,Wt,Wt+2,Wt+3)}}it+=_e}}x(this,J,ue,fe,pe)}}function N(T){return{x:T.x,y:T.y,z:T.z,nx:T.nx,ny:T.ny,nz:T.nz,u:T.u,v:T.v}}function _(T){return{x:T.x,y:T.y,z:T.z,nx:-T.nx,ny:-T.ny,nz:-T.nz,u:T.u,v:T.v}}function O(T,S,C){let B=T.nx+(S.nx-T.nx)*C,X=T.ny+(S.ny-T.ny)*C,W=T.nz+(S.nz-T.nz)*C,$=Math.hypot(B,X,W)||1;return{x:T.x+(S.x-T.x)*C,y:T.y+(S.y-T.y)*C,z:T.z+(S.z-T.z)*C,nx:B/$,ny:X/$,nz:W/$,u:T.u+(S.u-T.u)*C,v:T.v+(S.v-T.v)*C}}function Q(T){if(T.length<3)return null;let S=T[0],C=T[1],B=T[2],X=C.x-S.x,W=C.y-S.y,$=C.z-S.z,K=B.x-S.x,Z=B.y-S.y,j=B.z-S.z,te=W*j-$*Z,ee=$*K-X*j,J=X*Z-W*K,ue=Math.hypot(te,ee,J);if(ue<1e-9)return null;te/=ue,ee/=ue,J/=ue;let fe=te*S.x+ee*S.y+J*S.z;return{vertices:T,nx:te,ny:ee,nz:J,w:fe}}function q(T){T.vertices.reverse();for(let S=0;S<T.vertices.length;S++)T.vertices[S]=_(T.vertices[S]);T.nx=-T.nx,T.ny=-T.ny,T.nz=-T.nz,T.w=-T.w}let oe=1e-5,ne=0,re=1,H=2,se=3;function ae(T,S,C,B,X,W,$,K,Z){let j=0,te=[];for(let ee=0;ee<X.vertices.length;ee++){let J=X.vertices[ee],ue=T*J.x+S*J.y+C*J.z-B,fe=ue<-oe?H:ue>oe?re:ne;j|=fe,te.push(fe)}switch(j){case ne:{T*X.nx+S*X.ny+C*X.nz>0?W.push(X):$.push(X);break}case re:K.push(X);break;case H:Z.push(X);break;case se:{let ee=[],J=[],ue=X.vertices.length;for(let be=0;be<ue;be++){let xe=(be+1)%ue,ye=te[be],Re=te[xe],Me=X.vertices[be],Ee=X.vertices[xe];if(ye!==H&&ee.push(Me),ye!==re&&J.push(ye!==H?N(Me):Me),(ye|Re)===se){let Ie=Ee.x-Me.x,Pe=Ee.y-Me.y,Ge=Ee.z-Me.z,ze=T*Ie+S*Pe+C*Ge,Ke=Math.abs(ze)>1e-12?(B-(T*Me.x+S*Me.y+C*Me.z))/ze:.5,Xe=O(Me,Ee,Math.max(0,Math.min(1,Ke)));ee.push(Xe),J.push(N(Xe))}}let{nx:fe,ny:pe,nz:me,w:ce}=X;ee.length>=3&&K.push({vertices:ee,nx:fe,ny:pe,nz:me,w:ce}),J.length>=3&&Z.push({vertices:J,nx:fe,ny:pe,nz:me,w:ce});break}default:break}}class D{constructor(S,C=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,S&&S.length>0&&this.build(S,C)}invert(){for(let C=0;C<this.polygons.length;C++)q(this.polygons[C]);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 S=this.front;this.front=this.back,this.back=S}clipPolygons(S,C=0){if(!this.hasPlane||S.length===0)return S.slice();if(C>=p)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${p})`);let B=[],X=[];for(let W=0;W<S.length;W++)ae(this.nx,this.ny,this.nz,this.w,S[W],B,X,B,X);return this.front&&B.length>0&&(B=this.front.clipPolygons(B,C+1)),this.back?X=X.length>0?this.back.clipPolygons(X,C+1):[]:X=[],B.concat(X)}clipTo(S,C=0){this.polygons.length>0&&(this.polygons=S.clipPolygons(this.polygons,0)),C<p&&(this.front&&this.front.clipTo(S,C+1),this.back&&this.back.clipTo(S,C+1))}allPolygons(S=[]){for(let C=0;C<this.polygons.length;C++)S.push(this.polygons[C]);return this.front&&this.front.allPolygons(S),this.back&&this.back.allPolygons(S),S}build(S,C=0){if(!S.length)return;if(!this.hasPlane){let W=S[S.length>>1];this.nx=W.nx,this.ny=W.ny,this.nz=W.nz,this.w=W.w,this.hasPlane=!0}if(C>=p)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${p})`);let B=[],X=[];for(let W=0;W<S.length;W++)ae(this.nx,this.ny,this.nz,this.w,S[W],this.polygons,this.polygons,B,X);B.length>0&&(this.front||(this.front=new D),this.front.build(B,C+1)),X.length>0&&(this.back||(this.back=new D),this.back.build(X,C+1))}}function G(T,S){if(!S&&T._csgPolygons)return T._csgPolygons;let C=T.attributes.position;if(!C||C.count===0)return[];let B=T.attributes.normal,X=T.attributes.uv,W=T.index?T.index.array:null,$=Math.floor(W?W.length/3:C.count/3);if($>h)throw new RangeError(`SecurityError: CSG input triangle count (${$}) exceeds MAX_CSG_TRIANGLES (${h})`);let K=S?S.elements:null,Z=K?K[0]*(K[5]*K[10]-K[9]*K[6])-K[4]*(K[1]*K[10]-K[9]*K[2])+K[8]*(K[1]*K[6]-K[5]*K[2])<0:!1,j=K?new a().getNormalMatrix(S).elements:null,te=J=>{let ue=C.getX(J),fe=C.getY(J),pe=C.getZ(J),me=B?B.getX(J):NaN,ce=B?B.getY(J):NaN,be=B?B.getZ(J):NaN;if(K&&j){let Re=K[0]*ue+K[4]*fe+K[8]*pe+K[12],Me=K[1]*ue+K[5]*fe+K[9]*pe+K[13],Ee=K[2]*ue+K[6]*fe+K[10]*pe+K[14];ue=Re,fe=Me,pe=Ee;let Ie=j[0]*me+j[3]*ce+j[6]*be,Pe=j[1]*me+j[4]*ce+j[7]*be,Ge=j[2]*me+j[5]*ce+j[8]*be,ze=Math.hypot(Ie,Pe,Ge)||1;me=Ie/ze,ce=Pe/ze,be=Ge/ze}let xe=X?X.getX(J):0,ye=X?X.getY(J):0;return{x:ue,y:fe,z:pe,nx:me,ny:ce,nz:be,u:xe,v:ye}},ee=[];for(let J=0;J<$;J++){let ue=W?W[J*3]:J*3,fe=W?W[J*3+1]:J*3+1,pe=W?W[J*3+2]:J*3+2,me=Q(Z?[te(ue),te(pe),te(fe)]:[te(ue),te(fe),te(pe)]);me&&ee.push(me)}return ee}function E(T){let S=[],C=[],B=[],X=[];for(let $ of T){let K=$.vertices;if(K.length<3)continue;let Z=S.length/3;for(let j of K)S.push(j.x,j.y,j.z),Number.isFinite(j.nx)&&j.nx*j.nx+j.ny*j.ny+j.nz*j.nz>.5?C.push(j.nx,j.ny,j.nz):C.push($.nx,$.ny,$.nz),B.push(j.u,j.v);for(let j=1;j<K.length-1;j++)X.push(Z,Z+j,Z+j+1)}let W=x(new c,S,C,B,X);return W._csgPolygons=T,W}function V(T,S,C){if(T.length+S.length>h)throw new RangeError(`SecurityError: Combined CSG triangle count (${T.length+S.length}) exceeds MAX_CSG_TRIANGLES (${h})`);if(T.length===0)return C==="union"?S:[];if(S.length===0)return C==="intersect"?[]:T;let B=1/0,X=1/0,W=1/0,$=-1/0,K=-1/0,Z=-1/0;for(let ue=0;ue<S.length;ue++){let fe=S[ue].vertices;for(let pe=0;pe<fe.length;pe++){let me=fe[pe];me.x<B&&(B=me.x),me.y<X&&(X=me.y),me.z<W&&(W=me.z),me.x>$&&($=me.x),me.y>K&&(K=me.y),me.z>Z&&(Z=me.z)}}B-=1e-4,X-=1e-4,W-=1e-4,$+=1e-4,K+=1e-4,Z+=1e-4;let j=[],te=[];for(let ue=0;ue<T.length;ue++){let fe=T[ue],pe=fe.vertices,me=1/0,ce=1/0,be=1/0,xe=-1/0,ye=-1/0,Re=-1/0;for(let Me=0;Me<pe.length;Me++){let Ee=pe[Me];Ee.x<me&&(me=Ee.x),Ee.y<ce&&(ce=Ee.y),Ee.z<be&&(be=Ee.z),Ee.x>xe&&(xe=Ee.x),Ee.y>ye&&(ye=Ee.y),Ee.z>Re&&(Re=Ee.z)}xe<B||me>$||ye<X||ce>K||Re<W||be>Z?te.push(fe):j.push(fe)}if(j.length===0)return C==="union"?T.concat(S):C==="subtract"?T:[];let ee=new D(j),J=new D(S);return C==="union"?(ee.clipTo(J),J.clipTo(ee),J.invert(),J.clipTo(ee),J.invert(),ee.build(J.allPolygons()),te.concat(ee.allPolygons())):C==="subtract"?(ee.invert(),ee.clipTo(J),J.clipTo(ee),J.invert(),J.clipTo(ee),J.invert(),ee.build(J.allPolygons()),ee.invert(),te.concat(ee.allPolygons())):(ee.invert(),J.clipTo(ee),J.invert(),ee.clipTo(J),J.clipTo(ee),ee.build(J.allPolygons()),ee.invert(),ee.allPolygons())}function F(T,S,C,B=null,X=null){let W=G(T,B),$=G(S,X);return E(V(W,$,C))}function U(T,S,C){let B=T instanceof f||!!T?.isMesh,X=S instanceof f||!!S?.isMesh,W=B?T.geometry:T,$=X?S.geometry:S,K=null;if(X)if(S.updateMatrix(),B){T.updateMatrix();let ee=new o().makeScale(1/(T.scale.x||1),1/(T.scale.y||1),1/(T.scale.z||1)),J=Math.hypot(T.quaternion.x,T.quaternion.y,T.quaternion.z,T.quaternion.w)||1,ue=new o().compose(new r(0,0,0),new i(-T.quaternion.x/J,-T.quaternion.y/J,-T.quaternion.z/J,T.quaternion.w/J),new r(1,1,1)),fe=new o().makeTranslation(-T.position.x,-T.position.y,-T.position.z);K=ee.multiply(ue).multiply(fe).multiply(S.matrix)}else K=S.matrix;let Z=F(W,$,C,null,K),j=B?T.material:new m,te=new f(Z,j);return B&&(te.position.copy(T.position),te.quaternion.copy(T.quaternion),te.scale.copy(T.scale),te.name=T.name),te}let z={toGeometry:F,subtract(T,S){return U(T,S,"subtract")},union(T,S){return U(T,S,"union")},intersect(T,S){return U(T,S,"intersect")}},Y={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 le extends c{constructor(S="",C={}){super();let B=String(S??"").slice(0,d),X=Math.max(.005,Math.min(100,v(C.size,.2))),W=!!(C.bevelEnabled??!1),$=W?Math.max(0,Math.min(2,v(C.bevelThickness,X*.04))):0,K=W?Math.max(0,Math.min(2,v(C.bevelSize,X*.03))):0,Z=Math.max(.001,Math.min(20,v(C.depth??C.height,X*.2)))+$*2,j=X*.085+K,te=X*.68,ee=X*.82,J=[],ue=[],fe=[],pe=[],me=(xe,ye,Re,Me,Ee,Ie,Pe)=>{let Ge=Re-xe,ze=Me-ye,Ke=Math.hypot(Ge,ze),Xe=1,rt=0;Ke>1e-6&&(Xe=Ge/Ke,rt=ze/Ke);let Bt=-rt*Ee,zt=Xe*Ee,yt=Xe*Ee*.6,gt=rt*Ee*.6,je=xe-yt+Bt,it=ye-gt+zt,ge=xe-yt-Bt,_e=ye-gt-zt,Ce=Re+yt-Bt,Fe=Me+gt-zt,Ve=Re+yt+Bt,qe=Me+gt+zt,ft=(xt,vt,Tt,wt,Mt,At,It)=>{let mt=J.length/3;J.push(xt[0],xt[1],xt[2],vt[0],vt[1],vt[2],Tt[0],Tt[1],Tt[2],wt[0],wt[1],wt[2]),ue.push(Mt,At,It,Mt,At,It,Mt,At,It,Mt,At,It),fe.push(0,0,1,0,1,1,0,1),pe.push(mt,mt+1,mt+2,mt,mt+2,mt+3)};ft([je,it,Pe],[ge,_e,Pe],[Ce,Fe,Pe],[Ve,qe,Pe],0,0,1),ft([ge,_e,Ie],[je,it,Ie],[Ve,qe,Ie],[Ce,Fe,Ie],0,0,-1),ft([je,it,Ie],[ge,_e,Ie],[ge,_e,Pe],[je,it,Pe],-Xe,-rt,0),ft([Ce,Fe,Ie],[Ve,qe,Ie],[Ve,qe,Pe],[Ce,Fe,Pe],Xe,rt,0),ft([ge,_e,Ie],[Ce,Fe,Ie],[Ce,Fe,Pe],[ge,_e,Pe],rt,-Xe,0),ft([Ve,qe,Ie],[je,it,Ie],[je,it,Pe],[Ve,qe,Pe],-rt,Xe,0)},ce=0,be=0;for(let xe=0;xe<B.length;xe++){let ye=B[xe];if(ye===`
18
- `){ce=0,be-=X*1.35;continue}if(ye===" "||ye===" "){ce+=ee*(ye===" "?.75:3);continue}if(ye==="\r")continue;let Re=ye.toUpperCase(),Me=ye!==Re&&ye>="a"&&ye<="z",Ee=Y[Re]??Y["?"],Ie=Me?X*.76:X,Pe=Me?te*.88:te;for(let Ge of Ee)for(let ze=0;ze<Ge.length-1;ze++){let Ke=Ge[ze],Xe=Ge[ze+1];me(ce+Ke[0]*Pe,be+Ke[1]*Ie,ce+Xe[0]*Pe,be+Xe[1]*Ie,j,-Z*.5,Z*.5)}ce+=Me?ee*.88:ee}x(this,J,ue,fe,pe),C.center!==!1?this.center():this.computeBoundingBox()}}function ie(T){if(!T)return;let S=T,C=T.userData?.xr?.text;if(C!=null&&C!==!1){let X=S.geometry?.attributes?.position;if((!X||X.count===0)&&T.userData._textApplied!==!0){let W="",$=.08,K=.015,Z;if(typeof C=="string"||typeof C=="number")W=String(C);else if(typeof C=="object"){let j=C;W=String(j.text??j.value??""),j.size!==void 0&&($=Number(j.size)||.08),(j.depth!==void 0||j.height!==void 0)&&(K=Number(j.depth??j.height)||$*.2),(typeof j.color=="string"||typeof j.color=="number")&&(Z=j.color)}W.trim().length>0&&(S.geometry=new le(W,{size:$,depth:K}),T.userData._textApplied=!0,S.material instanceof l?Z!==void 0&&T.userData._autoTextColorApplied!==!0&&(S.material.color=new u(Z),T.userData._autoTextColorApplied=!0):S.material=new m({color:Z??16317180}))}}let B=T.userData?.csg;if(B&&typeof B=="object"&&T.userData._csgApplied!==!0&&S.geometry instanceof c&&S.geometry.attributes.position?.count>0){T.userData._csgApplied=!0;let X=Array.isArray(B)?B:[B],W=S.geometry;for(let $ of X){if(!$||typeof $!="object")continue;let K=$,Z=String(K.op??K.operation??"subtract"),j=Z==="union"||Z==="intersect"?Z:"subtract",te=K.target??K.mesh??K.geometry;if(te instanceof f||te instanceof c)try{let ee=j==="union"?z.union(S,te):j==="intersect"?z.intersect(S,te):z.subtract(S,te);S.geometry!==W&&S.geometry.dispose?.(),S.geometry=ee.geometry}catch(ee){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ee)}}}}let he={Path:R,Shape:b,ShapeGeometry:L,ExtrudeGeometry:A,TextGeometry:le,CSG:z,MAX_CSG_TRIANGLES:h,MAX_BSP_DEPTH:p,MAX_TEXT_GEOMETRY_CHARS:d,MAX_SHAPE_POINTS:y,materializeDeclarativeGeometry:ie};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,he),e.materializeDeclarativeGeometry=ie),he}var Br={name:"cad",onRegister(){Un(Fn);let t=ve(),e=t.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);e&&Fn(e,t)}};function we(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Vn(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 $t(t,e,n,r){let[i,o,a]=e,[u,s,c]=r,[l,m,f]=n,h=i-l,p=o-m,d=a-f,y=Math.hypot(h,p,d);y<=1e-5?(h=0,p=0,d=1):(h/=y,p/=y,d/=y);let v=s*d-c*p,R=c*h-u*d,b=u*p-s*h;y=Math.hypot(v,R,b),y<=1e-5?(v=0,R=0,b=0):(v/=y,R/=y,b/=y);let w=p*b-d*R,M=d*v-h*b,P=h*R-p*v;return y=Math.hypot(w,M,P),y<=1e-5?(w=0,M=0,P=0):(w/=y,M/=y,P/=y),t[0]=v,t[1]=w,t[2]=h,t[3]=0,t[4]=R,t[5]=M,t[6]=p,t[7]=0,t[8]=b,t[9]=P,t[10]=d,t[11]=0,t[12]=-(v*i+R*o+b*a),t[13]=-(w*i+M*o+P*a),t[14]=-(h*i+p*o+d*a),t[15]=1,t}function Le(t,e,n){let r=e[0],i=e[1],o=e[2],a=e[3],u=e[4],s=e[5],c=e[6],l=e[7],m=e[8],f=e[9],h=e[10],p=e[11],d=e[12],y=e[13],v=e[14],R=e[15],b=n[0],w=n[1],M=n[2],P=n[3];return t[0]=b*r+w*u+M*m+P*d,t[1]=b*i+w*s+M*f+P*y,t[2]=b*o+w*c+M*h+P*v,t[3]=b*a+w*l+M*p+P*R,b=n[4],w=n[5],M=n[6],P=n[7],t[4]=b*r+w*u+M*m+P*d,t[5]=b*i+w*s+M*f+P*y,t[6]=b*o+w*c+M*h+P*v,t[7]=b*a+w*l+M*p+P*R,b=n[8],w=n[9],M=n[10],P=n[11],t[8]=b*r+w*u+M*m+P*d,t[9]=b*i+w*s+M*f+P*y,t[10]=b*o+w*c+M*h+P*v,t[11]=b*a+w*l+M*p+P*R,b=n[12],w=n[13],M=n[14],P=n[15],t[12]=b*r+w*u+M*m+P*d,t[13]=b*i+w*s+M*f+P*y,t[14]=b*o+w*c+M*h+P*v,t[15]=b*a+w*l+M*p+P*R,t}function Je(t,e,n,r){let i=e[0],o=e[1],a=e[2],u=e[3],s=i+i,c=o+o,l=a+a,m=i*s,f=i*c,h=i*l,p=o*c,d=o*l,y=a*l,v=u*s,R=u*c,b=u*l,w=r[0],M=r[1],P=r[2];return t[0]=(1-(p+y))*w,t[1]=(f+b)*w,t[2]=(h-R)*w,t[3]=0,t[4]=(f-b)*M,t[5]=(1-(m+y))*M,t[6]=(d+v)*M,t[7]=0,t[8]=(h+R)*P,t[9]=(d-v)*P,t[10]=(1-(m+p))*P,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function Ne(t,e,n=0){let r=e[0],i=e[1],o=e[2],a=e[4],u=e[5],s=e[6],c=e[8],l=e[9],m=e[10],f=m*u-s*l,h=-m*a+s*c,p=l*a-u*c,d=r*f+i*h+o*p;return!d||n>0&&(!Number.isFinite(d)||Math.abs(d)<=n)||(d=1/d,t[0]=f*d,t[1]=h*d,t[2]=p*d,t[3]=(-m*i+o*l)*d,t[4]=(m*r-o*c)*d,t[5]=(-l*r+i*c)*d,t[6]=(s*i-o*u)*d,t[7]=(-s*r+o*a)*d,t[8]=(u*r-i*a)*d),t}function jt(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],a=e[4],u=e[5],s=e[6],c=e[7],l=e[8],m=e[9],f=e[10],h=e[11],p=e[12],d=e[13],y=e[14],v=e[15],R=n*u-r*a,b=n*s-i*a,w=n*c-o*a,M=r*s-i*u,P=r*c-o*u,k=i*c-o*s,I=l*d-m*p,L=l*y-f*p,x=l*v-h*p,g=m*y-f*d,A=m*v-h*d,N=f*v-h*y,_=R*N-b*A+w*g+M*x-P*L+k*I;return _?(_=1/_,t[0]=(u*N-s*A+c*g)*_,t[1]=(i*A-r*N-o*g)*_,t[2]=(d*k-y*P+v*M)*_,t[3]=(f*P-m*k-h*M)*_,t[4]=(s*x-a*N-c*L)*_,t[5]=(n*N-i*x+o*L)*_,t[6]=(y*w-p*k-v*b)*_,t[7]=(l*k-f*w+h*b)*_,t[8]=(a*A-u*x+c*I)*_,t[9]=(r*x-n*A-o*I)*_,t[10]=(p*P-d*w+v*R)*_,t[11]=(m*w-l*P-h*R)*_,t[12]=(u*L-a*g-s*I)*_,t[13]=(n*g-r*L+i*I)*_,t[14]=(d*b-p*M-y*R)*_,t[15]=(l*M-m*b+f*R)*_,t):null}function zr(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],u=i[2]*e+i[6]*n+i[10]*r+i[14],s=i[3]*e+i[7]*n+i[11]*r+i[15],c=s!==0?1/s:1;t[0]=o*c,t[1]=a*c,t[2]=u*c}function fo(t,e,n,r,i,o,a,u,s,c,l,m,f,h,p,d,y=0){let v=c-a,R=l-u,b=m-s,w=f-a,M=h-u,P=p-s,k=i*P-o*M,I=o*w-r*P,L=r*M-i*w,x=v*k+R*I+b*L;if(x>-1e-7&&x<1e-7)return!1;let g=1/x,A=t-a,N=e-u,_=n-s,O=g*(A*k+N*I+_*L);if(O<-y||O>1+y)return!1;let Q=N*b-_*R,q=_*v-A*b,oe=A*R-N*v,ne=g*(r*Q+i*q+o*oe);if(ne<-y||O+ne>1+y)return!1;let re=g*(w*Q+M*q+P*oe);if(re>1e-4&&re<d.distance){d.distance=re,d.point=[t+r*re,e+i*re,n+o*re];let H=R*P-b*M,se=b*w-v*P,ae=v*M-R*w,D=Math.hypot(H,se,ae)||1;return d.normal=[H/D,se/D,ae/D],!0}return!1}function dt(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,a=128,u=(l,m,f=0)=>{if(f>a||l<0||l>=n||o.has(l))return;o.add(l);let h=t.nodes[l];if(!h)return;let p=we();if(e&&e[l])p.set(e[l]);else if(h.matrix&&h.matrix.length===16)p.set(h.matrix);else{let y=h.translation||[0,0,0],v=h.rotation||[0,0,0,1],R=h.scale||[1,1,1];Je(p,v,y,R)}let d=r[l];if(m?Le(d,m,p):d.set(p),Array.isArray(h.children))for(let y of h.children)typeof y=="number"&&u(y,d,f+1)},s=[],c=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(c&&Array.isArray(c.nodes))s.push(...c.nodes);else for(let l=0;l<n;l++)i.has(l)||s.push(l);for(let l of s)u(l,null);for(let l=0;l<n;l++)!i.has(l)&&!s.includes(l)&&u(l,null);return r}function Xr(t,e){function n(s,c,l,m){let f=typeof s=="number"?s:Number(s);return Number.isFinite(f)?Math.max(c,Math.min(l,f)):m}function r(s,c){let m=s[0]*c[0]+s[1]*c[1]+s[2]*c[2]+1;if(m<1e-6){if(Math.abs(s[0])>Math.abs(s[2])){let v=Math.hypot(s[1],s[0])||1;return[-s[1]/v,s[0]/v,0,0]}let y=Math.hypot(s[2],s[1])||1;return[0,-s[2]/y,s[1]/y,0]}let f=s[1]*c[2]-s[2]*c[1],h=s[2]*c[0]-s[0]*c[2],p=s[0]*c[1]-s[1]*c[0],d=Math.hypot(f,h,p,m)||1;return[f/d,h/d,p/d,m/d]}function i(s,c,l,m,f){let h=c[0]-s[0],p=c[1]-s[1],d=c[2]-s[2],y=Math.hypot(h,p,d),v=l[0]-c[0],R=l[1]-c[1],b=l[2]-c[2],w=Math.hypot(v,R,b);if(y<1e-6||w<1e-6)return{rootPos:[s[0],s[1],s[2]],midPos:[c[0],c[1],c[2]],effectorPos:[l[0],l[1],l[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let M=[h/y,p/y,d/y],P=[v/w,R/w,b/w],k=m[0]-s[0],I=m[1]-s[1],L=m[2]-s[2],x=Math.hypot(k,I,L),g=x>1e-6?[k/x,I/x,L/x]:M,A=Math.abs(y-w)+1e-5,N=Math.max(A,y+w-1e-5),_=Math.max(A,Math.min(N,x>1e-6?x:A)),O=n((y*y+_*_-w*w)/(2*y*_),-1,1,1),Q=Math.sqrt(Math.max(0,1-O*O)),q=f?f[0]-s[0]:h,oe=f?f[1]-s[1]:p,ne=f?f[2]-s[2]:d,re=q*g[0]+oe*g[1]+ne*g[2],H=q-g[0]*re,se=oe-g[1]*re,ae=ne-g[2]*re,D=Math.hypot(H,se,ae);if(D<=1e-6){let T=Math.abs(g[1])<.99?0:1,S=Math.abs(g[1])<.99?1:0,C=0;H=g[1]*C-g[2]*S,se=g[2]*T-g[0]*C,ae=g[0]*S-g[1]*T,D=Math.hypot(H,se,ae)||1}let G=[H/D,se/D,ae/D],E=[s[0]+g[0]*(y*O)+G[0]*(y*Q),s[1]+g[1]*(y*O)+G[1]*(y*Q),s[2]+g[2]*(y*O)+G[2]*(y*Q)],V=[s[0]+g[0]*_,s[1]+g[1]*_,s[2]+g[2]*_],F=V[0]-E[0],U=V[1]-E[1],z=V[2]-E[2],Y=Math.hypot(F,U,z),le=Y>1e-6?[F/Y,U/Y,z/Y]:g,ie=[E[0]+le[0]*w,E[1]+le[1]*w,E[2]+le[2]*w],he=[(E[0]-s[0])/y,(E[1]-s[1])/y,(E[2]-s[2])/y];return{rootPos:[s[0],s[1],s[2]],midPos:E,effectorPos:ie,rootRotation:r(M,he),midRotation:r(P,le)}}function o(s,c,l=8,m=.001){let f=s.length;if(f<2)return{positions:s.map(x=>[x[0],x[1],x[2]]),rotations:[],iterations:0};let h=s.map(x=>[x[0],x[1],x[2]]),p=[],d=[],y=0;for(let x=0;x<f-1;x++){let g=h[x+1][0]-h[x][0],A=h[x+1][1]-h[x][1],N=h[x+1][2]-h[x][2],_=Math.hypot(g,A,N);p.push(_),y+=_,d.push(_>1e-6?[g/_,A/_,N/_]:[0,1,0])}let v=[h[0][0],h[0][1],h[0][2]],R=Math.round(n(l,1,32,8)),b=n(m,1e-5,.1,.001),w=c[0]-v[0],M=c[1]-v[1],P=c[2]-v[2],k=Math.hypot(w,M,P),I=0;if(k>=y&&y>1e-6){let x=k>1e-6?[w/k,M/k,P/k]:d[0];h[0]=[v[0],v[1],v[2]];for(let g=0;g<f-1;g++){let A=p[g];h[g+1]=[h[g][0]+x[0]*A,h[g][1]+x[1]*A,h[g][2]+x[2]*A]}I=1}else for(let x=1;x<=R;x++){let g=h[f-1];if(Math.hypot(g[0]-c[0],g[1]-c[1],g[2]-c[2])<=b)break;I=x;let N=(_,O,Q,q,oe)=>{let ne=O[0]-_[0],re=O[1]-_[1],H=O[2]-_[2],se=Math.hypot(ne,re,H);if(se>1e-6){let ae=Q/se;return[_[0]+ne*ae,_[1]+re*ae,_[2]+H*ae]}return[_[0]+q[0]*Q*oe,_[1]+q[1]*Q*oe,_[2]+q[2]*Q*oe]};h[f-1]=[c[0],c[1],c[2]];for(let _=f-2;_>=0;_--)h[_]=N(h[_+1],h[_],p[_],d[_],-1);h[0]=[v[0],v[1],v[2]];for(let _=0;_<f-1;_++)h[_+1]=N(h[_],h[_+1],p[_],d[_],1)}let L=[];for(let x=0;x<f-1;x++){let g=h[x+1][0]-h[x][0],A=h[x+1][1]-h[x][1],N=h[x+1][2]-h[x][2],_=Math.hypot(g,A,N),O=_>1e-6?[g/_,A/_,N/_]:d[x];L.push(r(d[x],O))}return{positions:h,rotations:L,iterations:I}}function a(s){if(!s||typeof s!="object"||Array.isArray(s))return null;let c=s;if(c.enabled===!1)return null;let l=b=>{if(typeof b!="string")return;let w=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(w)?w:void 0},m=b=>Array.isArray(b)&&b.length===3&&b.every(w=>typeof w=="number"&&Number.isFinite(w))?[n(b[0],-1e3,1e3,0),n(b[1],-1e3,1e3,0),n(b[2],-1e3,1e3,0)]:void 0,f=l(c.root),h=l(c.effector);if(!f||!h)return null;let p=l(c.mid),d=m(c.target)??l(c.target);if(!d)return null;let y=c.pole??c.poleTarget,v=m(y)??l(y),R=c.solver==="fabrik"?"fabrik":c.solver==="two-bone"||p?"two-bone":"fabrik";return{root:f,...p?{mid:p}:{},effector:h,target:d,...v?{pole:v}:{},solver:R,iterations:Math.round(n(c.iterations,1,32,8)),tolerance:n(c.tolerance,1e-5,.1,.001),weight:n(c.weight,0,1,1)}}let u=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:a});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=u),{clampNum:n,parseIKTrait:a,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:u}}var qt=Xr(),ho=qt.clampNum,Zs=qt.parseIKTrait,zn=qt.quatFromUnitVectors,jr=qt.solveTwoBoneIK,qr=qt.solveFABRIK,po=qt.IKSolver;function Wr(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 Qs(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 Js(t,e,n,r,i){let o=ho(i,0,1,1),a=e[0]+(n[0]-e[0])*o,u=e[1]+(n[1]-e[1])*o,s=e[2]+(n[2]-e[2])*o,c=a-t[0],l=u-t[1],m=s-t[2],f=Math.hypot(c,l,m);if(f>1e-6&&r>1e-6){let v=r/f;return[t[0]+c*v,t[1]+l*v,t[2]+m*v]}let h=n[0]-t[0],p=n[1]-t[1],d=n[2]-t[2],y=Math.hypot(h,p,d);if(y>1e-6&&r>1e-6){let v=r/y;return[t[0]+h*v,t[1]+p*v,t[2]+d*v]}return[a,u,s]}function ea(t,e){let n=t?.modelRootMatrix;if(!n||n.length!==16)return e;let r=new Float32Array(16);return jt(r,n instanceof Float32Array?n:Float32Array.from(n))?[r[0]*e[0]+r[4]*e[1]+r[8]*e[2]+r[12],r[1]*e[0]+r[5]*e[1]+r[9]*e[2]+r[13],r[2]*e[0]+r[6]*e[1]+r[10]*e[2]+r[14]]:e}function Gr(t,e){t.__ikWarned||(t.__ikWarned=new Set);let n=t.__ikWarned;n.has(e)||(n.add(e),console.warn(`[three-live] ik: joint '${e}' on '${t?.name??""}' not found among scene nodes or meshes.`))}function $r(t,e,n){if(Array.isArray(t))return[t[0],t[1],t[2]];let r=e.get(t);if(r)return Wr(r);let i;if(t==="head"?i=n?.headPose?.position??n?.headPose??n?.cameraPosition:t==="hand-left"?i=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left:t==="hand-right"&&(i=n?.handPoses?.right?.position??n?.handPoses?.right??n?.hands?.right?.position??n?.hands?.right),(Array.isArray(i)||ArrayBuffer.isView(i))&&i.length>=3){let o=i;return ea(n,[o[0],o[1],o[2]])}return null}function Hr(t,e){return[t[3]*e[0]+t[0]*e[3]+t[1]*e[2]-t[2]*e[1],t[3]*e[1]-t[0]*e[2]+t[1]*e[3]+t[2]*e[0],t[3]*e[2]+t[0]*e[1]-t[1]*e[0]+t[2]*e[3],t[3]*e[3]-t[0]*e[0]-t[1]*e[1]-t[2]*e[2]]}function ta(t){return[-t[0],-t[1],-t[2],t[3]]}function Kr(t){let e=Math.hypot(t[0],t[1],t[2],t[3]);return e>1e-12?[t[0]/e,t[1]/e,t[2]/e,t[3]/e]:[0,0,0,1]}function na(t,e){if(e>=1)return t;if(e<=0)return[0,0,0,1];let[n,r,i,o]=t;o<0&&(n=-n,r=-r,i=-i,o=-o);let a=Math.acos(Math.min(1,o)),u=Math.sin(a);if(u<1e-9)return[0,0,0,1];let s=Math.sin(a*e)/u;return Kr([n*s,r*s,i*s,Math.cos(a*e)])}function ra(t){let e=Math.hypot(t[0],t[1],t[2])||1,n=Math.hypot(t[4],t[5],t[6])||1,r=Math.hypot(t[8],t[9],t[10])||1,i=t[0]/e,o=t[1]/e,a=t[2]/e,u=t[4]/n,s=t[5]/n,c=t[6]/n,l=t[8]/r,m=t[9]/r,f=t[10]/r,h=i+s+f,p;if(h>0){let d=Math.sqrt(h+1)*2;p=[(c-m)/d,(l-a)/d,(o-u)/d,.25*d]}else if(i>s&&i>f){let d=Math.sqrt(1+i-s-f)*2;p=[.25*d,(u+o)/d,(l+a)/d,(c-m)/d]}else if(s>f){let d=Math.sqrt(1+s-i-f)*2;p=[(u+o)/d,.25*d,(m+c)/d,(l-a)/d]}else{let d=Math.sqrt(1+f-i-s)*2;p=[(l+a)/d,(m+c)/d,.25*d,(o-u)/d]}return Kr(p)}function ia(t,e,n){let[r,i,o,a]=n,u=1-2*(i*i+o*o),s=2*(r*i-o*a),c=2*(r*o+i*a),l=2*(r*i+o*a),m=1-2*(r*r+o*o),f=2*(i*o-r*a),h=2*(r*o-i*a),p=2*(i*o+r*a),d=1-2*(r*r+i*i);for(let y=0;y<3;y++){let v=e[y*4],R=e[y*4+1],b=e[y*4+2];t[y*4]=u*v+s*R+c*b,t[y*4+1]=l*v+m*R+f*b,t[y*4+2]=h*v+p*R+d*b}}function Bn(t,e){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2],o=Math.hypot(n,r,i);return o>1e-9?[n/o,r/o,i/o]:null}function bo(t){t?.normalMatrix&&t?.transform&&Ne(t.normalMatrix,t.transform)}var mo=new WeakMap;function oa(t){let e=mo.get(t);return e||(e=new Int32Array(t.nodes.length).fill(-1),t.nodes.forEach((n,r)=>{for(let i of Array.isArray(n?.children)?n.children:[])typeof i=="number"&&i>=0&&i<e.length&&(e[i]=r)}),mo.set(t,e)),e}function sa(t,e,n){let r=t?.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return!1;let o=new Map;i.forEach((x,g)=>{typeof x?.name=="string"&&x.name&&!o.has(x.name)&&o.set(x.name,g)});let u=(e.mid?[e.root,e.mid,e.effector]:[e.root,e.effector]).map(x=>o.get(x));if(u.some(x=>x===void 0))return!1;let s=u,c=oa(r);for(let x=1;x<s.length;x++){let g=c[s[x]],A=0;for(;g>=0&&g!==s[x-1]&&A++<256;)g=c[g];if(g!==s[x-1])return!1}let l=s[0],m=t.initialNodeTransforms,f=new Map,h=[],p=[l];for(;p.length&&h.length<4096;){let x=p.pop();if(f.has(x))continue;let g=m?.[x],A=i[x];f.set(x,{t:g?[g.t[0],g.t[1],g.t[2]]:A?.translation?[...A.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:A?.rotation?[...A.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.s[2]]:A?.scale?[...A.scale]:[1,1,1]}),h.push(x);for(let N of Array.isArray(A?.children)?A.children:[])typeof N=="number"&&p.push(N)}let d=c[l],y=d>=0&&t.worldMatrices?.[d]?.length===16?Float32Array.from(t.worldMatrices[d]):we(),v=new Map,R=()=>{let x=(g,A)=>{let N=f.get(g);if(!N)return;let _=we();Je(_,N.r,N.t,N.s);let O=we();Le(O,A,_),v.set(g,O);for(let Q of Array.isArray(i[g]?.children)?i[g].children:[])typeof Q=="number"&&x(Q,O)};x(l,y)},b=x=>{let g=v.get(x);return[g[12],g[13],g[14]]};R();let w=s.map(b),M=x=>{if(typeof x=="string"&&!n.has(x)){let g=o.get(x),A=g!==void 0?v.get(g)??t.worldMatrices?.[g]:void 0;if(A&&A.length===16)return[A[12],A[13],A[14]]}return $r(x,n,t)},P=M(e.target);if(!P)return!0;let k=e.pole?M(e.pole)??void 0:void 0,I=yo(w,e,P,k),L=ho(e.weight,0,1,1);for(let x=0;x<s.length-1;x++){let g=Bn(b(s[x]),b(s[x+1])),A=Bn(I[x],I[x+1]);if(!g||!A)continue;let N=na(zn(g,A),L),_=s[x],O=c[_],Q=O===d||O<0?y:v.get(O)??y,q=ra(Q),oe=f.get(_);oe.r=Kr(Hr(ta(q),Hr(N,Hr(q,oe.r)))),R()}if(Array.isArray(t.worldMatrices))for(let[x,g]of v)t.worldMatrices[x]?.set&&t.worldMatrices[x].set(g);for(let x of t.meshes??[]){let g=v.get(x?.nodeIndex);g&&x.transform?.set&&(x.transform.set(g),bo(x))}return!0}function yo(t,e,n,r){if(e.solver==="two-bone"&&t.length===3){let i=jr(t[0],t[1],t[2],n,r);return[t[0],i.midPos,i.effectorPos]}return qr(t,n,e.iterations,e.tolerance).positions}function aa(t,e,n){let r=t.__ikRestOffsets,i=t.__ikRestMats;if(!(!r||!i))for(let o=0;o<e.length-1;o++){let a=e[o]?.transform??e[o]?.modelMatrix,u=i[o],s=Bn([0,0,0],r[o]),c=Bn(n[o],n[o+1]);!a||a.length<16||!u||u.length<16||!s||!c||(ia(a,u,zn(s,c)),bo(e[o]))}}var Yr={name:"ik",onRegister(){let t=ve();Un(Xr),Xr(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=Zs(i);if(!o||o.weight<=0)continue;if(!n){n=new Map;for(let w of e)w&&typeof w.name=="string"&&w.name&&n.set(w.name,w)}if(sa(t,o,n))continue;let a=n.get(o.root),u=n.get(o.effector),s=o.mid?n.get(o.mid):void 0;if(a||Gr(r,o.root),u||Gr(r,o.effector),o.mid&&!s&&Gr(r,o.mid),!a||!u)continue;let c=$r(o.target,n,t);if(!c)continue;let l=o.pole?$r(o.pole,n,t)??void 0:void 0,m=s?[a,s,u]:[a,u],f=m.map(w=>w.name||"").join(">");if(!r.__ikRestOffsets||r.__ikRestKey!==f){let w=m.map(Wr),M=[];for(let P=0;P<w.length-1;P++)M.push([w[P+1][0]-w[P][0],w[P+1][1]-w[P][1],w[P+1][2]-w[P][2]]);r.__ikRestOffsets=M,r.__ikRestKey=f,r.__ikRestMats=m.map(P=>Array.from(P.transform??P.modelMatrix??[]))}let h=r.__ikRestOffsets,d=[Wr(a)],y=[];for(let w=0;w<h.length;w++){let M=d[w],P=h[w];d.push([M[0]+P[0],M[1]+P[1],M[2]+P[2]]),y.push(Math.hypot(P[0],P[1],P[2]))}let v=yo(d,o,c,l),R=d[0],b=[d[0]];for(let w=1;w<m.length;w++){let M=h[w-1],P=[R[0]+M[0],R[1]+M[1],R[2]+M[2]],k=[R[0]+(v[w][0]-v[w-1][0]),R[1]+(v[w][1]-v[w-1][1]),R[2]+(v[w][2]-v[w-1][2])],I=Js(R,P,k,y[w-1],o.weight);Qs(m[w],I),R=I,b.push(I)}aa(r,m,b)}}};function St(t,e,n,r=!0){let i=[],o=null;try{for(let[a,u]of[[35633,e],[35632,n]]){let s=t.createShader(a);if(!s){if(r)throw new Error("Shader allocation failed");return null}if(i.push(s),t.shaderSource(s,u),t.compileShader(s),t.getShaderParameter&&!t.getShaderParameter(s,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(s)}`);return null}}if(o=t.createProgram(),!o){if(r)throw new Error("Program allocation failed");return null}for(let a of i)t.attachShader(o,a);if(t.linkProgram(o),t.getProgramParameter&&!t.getProgramParameter(o,35714)){let a=r?t.getProgramInfoLog(o):null;if(t.deleteProgram?.(o),o=null,r)throw new Error(`Program link error: ${a}`);return null}return o}finally{for(let a of i)o&&t.detachShader?.(o,a),t.deleteShader?.(a)}}var ca={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function ot(t,e,n,r){if(!n||n.bufferView===void 0)return null;let i=t.bufferViews?.[n.bufferView];if(!i)return null;let o=Number(n.count??0);if(!Number.isInteger(o)||o<=0)return null;let a=n.componentType??5126,u=ca[a];if(!u)throw new RangeError(`glTF accessor has unsupported componentType ${a}`);let s=u*r,c=i.byteStride&&i.byteStride>0?i.byteStride:s,l=(i.byteOffset||0)+(n.byteOffset||0);if(!Number.isInteger(l)||l<0||c<s||l+(o-1)*c+s>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(a===5126&&c===s&&l%4===0)return new Float32Array(e,l,o*r);let m=new DataView(e),f=n.normalized===!0,h=new Float32Array(o*r);for(let p=0;p<o;p++){let d=l+p*c;for(let y=0;y<r;y++){let v=d+y*u,R;switch(a){case 5126:R=m.getFloat32(v,!0);break;case 5120:R=m.getInt8(v),f&&(R=Math.max(R/127,-1));break;case 5121:R=m.getUint8(v),f&&(R/=255);break;case 5122:R=m.getInt16(v,!0),f&&(R=Math.max(R/32767,-1));break;case 5123:R=m.getUint16(v,!0),f&&(R/=65535);break;default:R=m.getUint32(v,!0),f&&(R/=4294967295)}h[p*r+y]=R}}return h}function go(t,e){let n=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),o=Number(e.scale?.[1]??1),a=Number(e.rotation??0)||0,u=Math.cos(a),s=Math.sin(a),c=(Number.isFinite(i)?i:1)*u,l=(Number.isFinite(i)?i:1)*s,m=-(Number.isFinite(o)?o:1)*s,f=(Number.isFinite(o)?o:1)*u;for(let h=0;h+1<t.length;h+=2){let p=t[h],d=t[h+1];t[h]=c*p+l*d+n,t[h+1]=m*p+f*d+r}}var To=["neutral","reinhard","none","aces","agx"];function Ct(t){let e=String(t??"").trim().toLowerCase();return To.includes(e)?e:"neutral"}function ua(t){return To.indexOf(Ct(t))}function la(t){return new TextDecoder().decode(t)}var wo=ve().decoders;function fa(t,e){wo.set(t.toLowerCase(),e)}function Kt(t){return wo.get(t.toLowerCase())}function Mo(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),a=12,u=null,s=null;for(;a+8<=o&&a+8<=e.byteLength;){let f=n.getUint32(a,!0),h=n.getUint32(a+4,!0),p=a+8;if(p+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${p+f} bytes, buffer has ${e.byteLength}`);if(h===1313821514){let d=new Uint8Array(e,p,f),y=la(d);u=JSON.parse(y,(v,R)=>v==="__proto__"||v==="constructor"||v==="prototype"?void 0:R)}else h===5130562&&(s=e.slice(p,p+f));a=p+f}if(!u)throw new Error("Missing JSON chunk in GLB");let c=u.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!Kt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let f of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(f)&&!Kt("meshopt"))throw new Error(`Model requires ${f}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!Kt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let l=s||new ArrayBuffer(0),m={gltf:u,bin:l,animations:[]};for(let f of De)f.onParseGLB?.(m);return m}function ma(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 ht(t){if(ma(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Mo(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Ao=`#version 300 es
16
+ */var ThreeLiveBundle=(()=>{var Zr=Object.defineProperty,co=Object.getOwnPropertyDescriptor,mo=Object.getOwnPropertyNames,fo=Object.prototype.hasOwnProperty,po=(e,t)=>{for(var r in t)Zr(e,r,{get:t[r],enumerable:!0})},go=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of mo(t))!fo.call(e,n)&&n!==r&&Zr(e,n,{get:()=>t[n],enumerable:!(i=co(t,n))||i.enumerable});return e},yo=e=>go(Zr({},"__esModule",{value:!0}),e),Qr={};po(Qr,{AmbientLight:()=>Ei,BoxGeometry:()=>Ai,BufferAttribute:()=>He,BufferGeometry:()=>Ue,Camera:()=>Ci,CapsuleGeometry:()=>Os,CatmullRomCurve3:()=>is,CircleGeometry:()=>Bs,Clock:()=>bs,Color:()=>gt,ConeGeometry:()=>Yn,CubicBezierCurve3:()=>rs,Curve3:()=>Rt,CylinderGeometry:()=>Ti,DataTexture:()=>ss,DirectionalLight:()=>fs,DodecahedronGeometry:()=>Us,EdgesGeometry:()=>Ws,Euler:()=>wi,Float32BufferAttribute:()=>Gn,Group:()=>cs,HemisphereLight:()=>zi,IKSolver:()=>So,IcosahedronGeometry:()=>Vs,InstancedMesh:()=>Pi,InteractivityVM:()=>Aa,LOD:()=>Vo,LatheGeometry:()=>Si,Light:()=>ar,Line:()=>zt,LineBasicMaterial:()=>Ur,LineCurve3:()=>es,LineDashedMaterial:()=>zs,LineLoop:()=>Gs,LineSegments:()=>js,LodController:()=>xn,MAX_BSP_DEPTH:()=>vo,MAX_CSG_TRIANGLES:()=>xo,MAX_INSTANCES_PER_MESH:()=>sr,MAX_SHAPE_POINTS:()=>wo,MAX_TEXT_GEOMETRY_CHARS:()=>Mo,Material:()=>it,MathUtils:()=>Wn,Matrix3:()=>$n,Matrix4:()=>Ot,Mesh:()=>At,MeshBasicMaterial:()=>os,MeshLambertMaterial:()=>ls,MeshPhongMaterial:()=>us,MeshPhysicalMaterial:()=>hs,MeshStandardMaterial:()=>nr,Object3D:()=>yt,OctahedronGeometry:()=>Fs,PerspectiveCamera:()=>ps,PlaneGeometry:()=>Xn,PointLight:()=>Ni,Points:()=>qs,PointsMaterial:()=>Bi,PolyhedronFallbackGeometry:()=>Rl,PolyhedronGeometry:()=>Et,QuadraticBezierCurve3:()=>ts,Quaternion:()=>Cr,RawShaderMaterial:()=>Is,RectAreaLight:()=>Ks,RingGeometry:()=>Oi,Scene:()=>Li,SceneQuotaValidator:()=>Tt,ShaderMaterial:()=>Ui,SphereGeometry:()=>Kn,SpotLight:()=>Xs,THREE:()=>$t,TetrahedronGeometry:()=>Ds,Texture:()=>Ir,TextureLoader:()=>as,ThreeLiveElement:()=>Ht,ThreeView:()=>Qe,TorusGeometry:()=>Zn,TorusKnotGeometry:()=>Jn,TubeGeometry:()=>ns,Uint16BufferAttribute:()=>jn,Uint32BufferAttribute:()=>qn,Vector2:()=>ut,Vector3:()=>xe,Vector4:()=>zn,WebGLRenderer:()=>gs,WireframeGeometry:()=>Hs,activateAR:()=>ha,applyMeshoptFilter:()=>La,authorScriptRunner:()=>kr,buildSandboxWorkerSource:()=>Fi,cadPlugin:()=>hn,clearAuthorWarnings:()=>_s,computeOutlineClipOffset:()=>yu,contactShadowPlugin:()=>Xi,createUSDZBlob:()=>xi,crossFadeTo:()=>ea,decimateGeometry:()=>Fo,decodeMeshoptBuffer:()=>Oa,decodeMeshoptGLB:()=>nn,defineModelViewer:()=>Ll,encodeMeshoptBuffer:()=>cu,environmentMapPlugin:()=>pa,evaluateKawaseBloom:()=>gu,evaluateToneMapping:()=>jo,exportSceneToCanvas3D:()=>_i,exportSceneToGLB:()=>Ii,exportSceneToUSDZ:()=>ds,extractMaterialVariants:()=>qa,extractPrimitiveVariantMappings:()=>Tu,generateUSDZ:()=>bi,getARCapabilities:()=>Ki,getAllowClientScripts:()=>As,getAuthorWarnings:()=>Ls,getBestARMode:()=>Vl,getEnvironmentSH:()=>Hl,getInteractivityVM:()=>rn,getLodController:()=>Uo,getSandboxEngineSrc:()=>Di,getSandboxIframeSrc:()=>ws,glbToUSDZ:()=>yi,hotspotPlugin:()=>da,ikPlugin:()=>bn,installCadExtension:()=>ei,installLodExtension:()=>wr,interactivityPlugin:()=>Sa,isAllowedSandboxEngineUrl:()=>Bt,isQuickLookSupported:()=>sa,isSceneViewerSupported:()=>aa,isWebXRSupported:()=>oa,keyframeAnimationPlugin:()=>ta,lodPlugin:()=>vn,materialsPlugin:()=>Ra,meshoptDecoder:()=>sn,meshoptPlugin:()=>za,morphPlugin:()=>ra,noopProxy:()=>or,parseAnimations:()=>Js,parseHexRgb:()=>Ha,parseLod:()=>ci,parseSafeGltfPointer:()=>jr,postprocessingPlugin:()=>ja,quatFromUnitVectors:()=>ni,registerMaterialShader:()=>Ql,sampleChannel:()=>hr,sceneToCanvas3D:()=>ir,sceneToGLB:()=>Tr,sceneToUSDZ:()=>Nr,selectLodLevelIndex:()=>hi,selectMaterialVariant:()=>Su,sendInteractivityEvent:()=>Ta,setAllowClientScripts:()=>yl,setEnvironmentSH:()=>ca,setMorphTargetWeight:()=>_l,setSandboxEngineSrc:()=>fl,setSandboxIframeSrc:()=>dl,skinningPlugin:()=>ia,solveFABRIK:()=>pn,solveTwoBoneIK:()=>fn,threeAuthorPlugin:()=>ur,threeMicroPlugin:()=>Nl,toGLBData:()=>tr,toTrustedWorkerScriptURL:()=>Ms,validateSandboxWorkerMessage:()=>Vi,variantsPlugin:()=>Xa,warnUnsupported:()=>Pt,webxrPlugin:()=>Ya});function bo(e,t,r){let i=[],n=new Map,s=[],l=[],o=[],a=new Map,u=p=>{let y=n.get(p);return y===void 0&&(y=i.length,i.push({op:p}),n.set(p,y)),y},h=p=>{let y=a.get(p);return y===void 0&&(y=o.length,o.push({id:p}),a.set(p,y)),y},m=(p,y={})=>s.push({declaration:u(p),...y})-1,c=(p,y,M)=>l.push({id:p,type:y,value:M})-1,d=p=>({node:p,socket:"value"}),f=r?.interactivity??r?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let p=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(p&&Array.isArray(p.nodes)){let y=Array.isArray(p.declarations)?p.declarations:[];for(let M of y)M?.op&&u(M.op);Array.isArray(p.variables)&&l.push(...p.variables);for(let M of p.events||[])M?.id&&h(M.id);for(let M of p.nodes){if(!M||typeof M!="object")continue;let P=M.op||(typeof M.declaration=="number"?y[M.declaration]?.op:"");s.push(P?{...M,declaration:u(P)}:{...M})}}}let g=(p,y,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,y)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,y)}/${M}`:M==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${M}`,x=new Map;e.forEach((p,y)=>{typeof p?.name=="string"&&!x.has(p.name)&&x.set(p.name,y)});let b=(p,y)=>typeof p.target=="string"&&x.has(p.target)?x.get(p.target):typeof p.targetNode=="number"?p.targetNode:y,v=p=>{let y=e[p];return(typeof y?.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<e.length;p++){let y=e[p],M=y?.extras?.interactivity;if(!M||typeof M!="object")continue;let P=(typeof y.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0,F=T=>{let E=Array.isArray(T)?T:[T],S=[];for(let k=0;k<E.length;k++){let w=E[k];if(!w||typeof w!="object")continue;let ie=w.action||"interpolate",oe=typeof w.duration=="number"?w.duration:.35;if(ie==="toggleTransform"){let I=w.property==="rotation"||w.property==="scale"?w.property:"translation",H=I==="rotation"?y.rotation||[0,0,0,1]:I==="scale"?y.scale||[1,1,1]:y.translation||[0,0,0],N=`/nodes/${p}/${I}`,z=c(`__toggle_${p}_${k}`,"bool",!1),ue=m("variable/get",{configuration:{variable:z}}),he=m("math/not",{values:{a:d(ue)}}),B=m("variable/set",{configuration:{variable:z},values:{value:d(he)}}),$=m("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(w.to)?w.to:H},duration:{value:oe}}}),_=m("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(w.from)?w.from:H},duration:{value:oe}}});s[B].flows={out:{node:m("flow/branch",{values:{condition:d(ue)},flows:{true:{node:$},false:{node:_}}})}},S.push(B)}else if(ie==="interpolate"){let I=w.to??w.value;if(I===void 0)continue;let H={value:{value:I},duration:{value:oe}};w.from!==void 0&&(H.from={value:w.from}),S.push(m("pointer/interpolate",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,p),v(b(w,p)),w.property)},values:H}))}else if(ie==="setProperty"){if(w.value===void 0)continue;S.push(m("pointer/set",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,p),v(b(w,p)),w.property)},values:{value:{value:w.value}}}))}else if(ie==="toggleVisibility"){let I=b(w,p),H=c(`__vis_${I}_${k}`,"bool",!0),N=m("variable/get",{configuration:{variable:H}}),z=m("math/not",{values:{a:d(N)}}),ue=m("variable/set",{configuration:{variable:H},values:{value:d(z)}});s[ue].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${I}/extensions/KHR_node_visibility/visible`},values:{value:d(N)}})}},S.push(ue)}else if(ie==="cycleMaterialColor"&&Array.isArray(w.colors)&&w.colors.length>0){let I=typeof w.duration=="number"?w.duration:.25,H=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,N=c(`__color_idx_${p}_${k}`,"int",0),z=m("variable/get",{configuration:{variable:N}}),ue=m("math/add",{values:{a:d(z),b:{value:1}}}),he=m("math/rem",{values:{a:d(ue),b:{value:w.colors.length}}}),B=m("variable/set",{configuration:{variable:N},values:{value:d(he)}}),$={};for(let _=0;_<w.colors.length;_++){let G=w.colors[_],j=Array.isArray(G)&&G.length>=3?[G[0],G[1],G[2],G[3]??1]:[1,1,1,1];$[String(_)]={node:I>0?m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:j},duration:{value:I}}}):m("pointer/set",{configuration:{pointer:H},values:{value:{value:j}}})}}s[B].flows={out:{node:m("flow/switch",{values:{selection:d(z)},flows:$})}},S.push(B)}else if(ie==="playAnimation")S.push(m("animation/start",{configuration:{animation:w.animation??w.clip??0}}));else if(ie==="stopAnimation")S.push(m("animation/stop"));else if(ie==="sendEvent"){let I={};for(let[H,N]of Object.entries(w.values||{}))I[H]={value:N};S.push(m("event/send",{configuration:{event:h(String(w.event??w.id??"custom"))},values:I}))}}if(!S.length)return null;if(S.length===1)return S[0];let O={};return S.forEach((k,w)=>{O[String(w)]={node:k}}),m("flow/sequence",{flows:O})},W=(T,E,S)=>{let O=F(E);O!==null&&m(T,{...S?{configuration:S}:{},flows:{out:{node:O}}})};if(M.onSelect&&W("pointer/onSelect",M.onSelect,{nodeIndex:p}),M.onHoverIn&&W("pointer/onHoverIn",M.onHoverIn,{nodeIndex:p}),M.onHoverOut&&W("pointer/onHoverOut",M.onHoverOut,{nodeIndex:p}),M.onStart&&W("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[T,E]of Object.entries(M.onReceive))W("event/receive",E,{event:h(T)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:l,events:o}],graph:0}:null}var on='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).',ln="Security Error: client-side scripts require allow-client-scripts opt-in.",br="__THREE_LIVE_REGISTRY__";function Ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[br]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,br,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[br]=t}}return e[br]}var Fe=Ae().plugins;function Jr(e){let t=Ae();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function Ge(e){let t=Ae().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function un(){return Ae().plugins}var xo=8192,vo=2048,Mo=128,wo=4096;function ei(e,t){if(!e||!e.BufferGeometry)return null;let r=e.Vector2,i=e.Vector3,n=e.Quaternion,s=e.Matrix4,l=e.Matrix3,o=e.Color,a=e.BufferAttribute,u=e.BufferGeometry,h=e.Material,m=e.MeshStandardMaterial,c=e.Mesh,d=8192,f=2048,g=128,x=4096,b=(R,A)=>{let L=R==null?NaN:Number(R);return Number.isFinite(L)?L:A};class v{constructor(A){this.currentPoint=new r(0,0),this.segments=[],Array.isArray(A)&&A.length>0&&this.fromPoints(A)}fromPoints(A){if(!A.length)return this;this.moveTo(A[0].x,A[0].y);for(let L=1;L<A.length;L++)this.lineTo(A[L].x,A[L].y);return this}moveTo(A,L){let C=Number(A)||0,U=Number(L)||0;return this.currentPoint.set(C,U),this.segments.push({type:"move",pts:[C,U]}),this}lineTo(A,L){let C=Number(A)||0,U=Number(L)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(C,U),this.segments.push({type:"line",pts:[C,U]}),this}quadraticCurveTo(A,L,C,U){let Q=this.currentPoint.x,X=this.currentPoint.y,Z=Number(A)||0,J=Number(L)||0,K=Number(C)||0,ae=Number(U)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[Q,X]}),this.currentPoint.set(K,ae),this.segments.push({type:"quad",pts:[Q,X,Z,J,K,ae]}),this}bezierCurveTo(A,L,C,U,Q,X){let Z=this.currentPoint.x,J=this.currentPoint.y,K=Number(A)||0,ae=Number(L)||0,ne=Number(C)||0,re=Number(U)||0,ce=Number(Q)||0,me=Number(X)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[Z,J]}),this.currentPoint.set(ce,me),this.segments.push({type:"cubic",pts:[Z,J,K,ae,ne,re,ce,me]}),this}absarc(A,L,C,U,Q,X=!1){return this.absellipse(A,L,C,C,U,Q,X,0)}arc(A,L,C,U,Q,X=!1){return this.absarc(this.currentPoint.x+(Number(A)||0),this.currentPoint.y+(Number(L)||0),C,U,Q,X)}absellipse(A,L,C,U,Q,X,Z=!1,J=0){let K=Number(A)||0,ae=Number(L)||0,ne=Math.max(0,Number(C)||0),re=Math.max(0,Number(U)||0),ce=Number(Q)||0,me=Number(X)||0,ge=Z?1:0,de=Number(J)||0;this.segments.push({type:"arc",pts:[K,ae,ne,re,ce,me,ge,de]});let pe=Math.cos(de),ye=Math.sin(de),Me=ne*Math.cos(me),be=re*Math.sin(me);return this.currentPoint.set(K+Me*pe-be*ye,ae+Me*ye+be*pe),this}ellipse(A,L,C,U,Q,X,Z=!1,J=0){return this.absellipse(this.currentPoint.x+(Number(A)||0),this.currentPoint.y+(Number(L)||0),C,U,Q,X,Z,J)}closePath(){if(this.segments.length>0){let A=this.segments[0],L=0,C=0;if(A.type==="arc"){let U=A.pts[0],Q=A.pts[1],X=A.pts[2],Z=A.pts[3],J=A.pts[4],K=A.pts[7],ae=Math.cos(K),ne=Math.sin(K),re=X*Math.cos(J),ce=Z*Math.sin(J);L=U+re*ae-ce*ne,C=Q+re*ne+ce*ae}else L=A.pts[0],C=A.pts[1];Math.hypot(this.currentPoint.x-L,this.currentPoint.y-C)>1e-6&&this.lineTo(L,C)}return this}getPoints(A=12){let L=Math.max(1,Math.min(128,Math.floor(Number(A)||12))),C=[],U=(Q,X)=>{if(C.length>0){let Z=C[C.length-1];if(Math.hypot(Z.x-Q,Z.y-X)<1e-6)return}C.push(new r(Q,X))};for(let Q of this.segments){let X=Q.pts;if(Q.type==="move"||Q.type==="line")U(X[0],X[1]);else if(Q.type==="quad"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5];U(Z,J);for(let ce=1;ce<=L;ce++){let me=ce/L,ge=1-me;U(ge*ge*Z+2*ge*me*K+me*me*ne,ge*ge*J+2*ge*me*ae+me*me*re)}}else if(Q.type==="cubic"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5],ce=X[6],me=X[7];U(Z,J);for(let ge=1;ge<=L;ge++){let de=ge/L,pe=1-de,ye=pe*pe,Me=de*de;U(ye*pe*Z+3*ye*de*K+3*pe*Me*ne+Me*de*ce,ye*pe*J+3*ye*de*ae+3*pe*Me*re+Me*de*me)}}else if(Q.type==="arc"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5],ce=X[6]!==0,me=X[7],ge=Math.PI*2,de=re-ne,pe=Math.abs(de)<1e-9;for(;de<0;)de+=ge;for(;de>ge;)de-=ge;de<1e-9&&(de=pe?0:ge),ce&&!pe&&(de=de===ge?-ge:de-ge);let ye=Math.cos(me),Me=Math.sin(me),be=Math.max(2,L);for(let Ee=0;Ee<=be;Ee++){let Se=Ee/be,Re=ne+Se*de,Ne=K*Math.cos(Re),De=ae*Math.sin(Re);U(Z+Ne*ye-De*Me,J+Ne*Me+De*ye)}}}if(C.length>2){let Q=C[0],X=C[C.length-1];Math.hypot(Q.x-X.x,Q.y-X.y)<1e-6&&C.pop()}return C}getSpacedPoints(A=12){return this.getPoints(A)}clone(){let A=new this.constructor;return A.currentPoint.copy(this.currentPoint),A.segments=this.segments.map(L=>({type:L.type,pts:[...L.pts]})),Array.isArray(this.holes)&&(A.holes=this.holes.map(L=>L.clone())),A}}class p extends v{constructor(A){super(A),this.holes=[]}extractPoints(A=12){return{shape:this.getPoints(A),holes:this.holes.map(L=>L.getPoints(A))}}}function y(R){let A=0,L=R.length;for(let C=0,U=L-1;C<L;U=C++)A+=R[U].x*R[C].y-R[C].x*R[U].y;return A*.5}function M(R,A,L,C,U,Q,X,Z){let J=X-L,K=Z-C,ae=U-L,ne=Q-C,re=R-L,ce=A-C,me=J*J+K*K,ge=J*ae+K*ne,de=J*re+K*ce,pe=ae*ae+ne*ne,ye=ae*re+ne*ce,Me=me*pe-ge*ge;if(Math.abs(Me)<1e-12)return!1;let be=1/Me,Ee=(pe*de-ge*ye)*be,Se=(me*ye-ge*de)*be;return Ee>=-1e-7&&Se>=-1e-7&&Ee+Se<=1.0000001}function P(R,A){let L=R.slice();y(L)<0&&L.reverse();let C=L.map(J=>new r(J.x,J.y)),U=L.map((J,K)=>K),Q=[];for(let J of A){if(!J||J.length<3)continue;let K=J.slice();y(K)>0&&K.reverse();let ae=[],ne=-1/0,re=0;for(let ce=0;ce<K.length;ce++){let me=K[ce],ge=C.length;C.push(new r(me.x,me.y)),ae.push(ge),me.x>ne&&(ne=me.x,re=ce)}Q.push({pts:K,indices:ae,maxX:ne,maxIdx:re})}Q.sort((J,K)=>K.maxX-J.maxX);let X=(J,K,ae)=>(K.x-J.x)*(ae.y-J.y)-(K.y-J.y)*(ae.x-J.x),Z=(J,K,ae)=>{for(let ne=0;ne<ae.length;ne++){let re=ae[ne],ce=ae[(ne+1)%ae.length];if(X(J,K,re)*X(J,K,ce)<0&&X(re,ce,J)*X(re,ce,K)<0)return!0}return!1};for(let J of Q){let K=J.pts[J.maxIdx],ae=K.x,ne=U.length,re=U.map(pe=>C[pe]),ce=pe=>Math.hypot(re[pe].x-ae,re[pe].y-K.y),me=re.map((pe,ye)=>ye).sort((pe,ye)=>+(re[pe].x<ae)-+(re[ye].x<ae)||ce(pe)-ce(ye)),ge=me[0];for(let pe of me){let ye=re[pe],Me=re[(pe+ne-1)%ne],be=re[(pe+1)%ne],Ee=X(ye,be,K)>=0,Se=X(Me,ye,K)>=0;if((X(Me,ye,be)>=0?Ee&&Se:Ee||Se)&&!Z(K,ye,re)&&!Q.some(Re=>Z(K,ye,Re.pts))){ge=pe;break}}let de=[];for(let pe=0;pe<=ge;pe++)de.push(U[pe]);for(let pe=0;pe<=J.indices.length;pe++){let ye=J.indices[(J.maxIdx+pe)%J.indices.length];de.push(ye)}for(let pe=ge;pe<U.length;pe++)de.push(U[pe]);U=de}return{merged:U.map(J=>C[J]),mergedIndices:U,allVertices:C}}function F(R,A){let L=[],C=R.slice();if(C.length<3)return L;let U=C.length*C.length+64,Q=0;for(;C.length>2&&U-- >0;){let X=C.length,Z=C[(Q+X-1)%X],J=C[Q%X],K=C[(Q+1)%X],ae=A[Z],ne=A[J],re=A[K];if((ne.x-ae.x)*(re.y-ae.y)-(ne.y-ae.y)*(re.x-ae.x)>1e-9){let ce=!0,me=Math.min(ae.x,ne.x,re.x)-1e-7,ge=Math.max(ae.x,ne.x,re.x)+1e-7,de=Math.min(ae.y,ne.y,re.y)-1e-7,pe=Math.max(ae.y,ne.y,re.y)+1e-7;for(let ye=0;ye<X;ye++){let Me=C[ye];if(Me===Z||Me===J||Me===K)continue;let be=A[Me];if(be.x>=me&&be.x<=ge&&be.y>=de&&be.y<=pe&&M(be.x,be.y,ae.x,ae.y,ne.x,ne.y,re.x,re.y)&&(be.x-ae.x)*(be.x-ae.x)+(be.y-ae.y)*(be.y-ae.y)>=1e-12&&(be.x-ne.x)*(be.x-ne.x)+(be.y-ne.y)*(be.y-ne.y)>=1e-12&&(be.x-re.x)*(be.x-re.x)+(be.y-re.y)*(be.y-re.y)>=1e-12){ce=!1;break}}if(ce){L.push([Z,J,K]),C.splice(Q%X,1),Q=Math.max(0,Q%X-1);continue}}Q++,Q>=X*2&&(L.push([Z,J,K]),C.splice((Q-1)%X,1),Q=0)}return L}function W(R,A){let L=R instanceof p?R.extractPoints(A):{shape:R.getPoints(A),holes:[]},C=L.shape.length;for(let U of L.holes)C+=U.length;if(C>x)throw new RangeError(`SecurityError: shape point count (${C}) exceeds MAX_SHAPE_POINTS (${x})`);return L}function T(R){let A=1/0,L=1/0,C=-1/0,U=-1/0;for(let Q of R)Q.x<A&&(A=Q.x),Q.y<L&&(L=Q.y),Q.x>C&&(C=Q.x),Q.y>U&&(U=Q.y);return[A,L,Math.max(1e-6,C-A),Math.max(1e-6,U-L)]}class E extends u{constructor(A=new p,L=12){super();let C=Array.isArray(A)?A:[A],U=[],Q=[],X=[],Z=[];for(let J of C){if(!(J instanceof v))continue;let K=W(J,L);if(K.shape.length<3)continue;let{mergedIndices:ae,allVertices:ne}=P(K.shape,K.holes),re=F(ae,ne),ce=U.length/3,[me,ge,de,pe]=T(ne);for(let ye of ne)U.push(ye.x,ye.y,0),Q.push(0,0,1),X.push((ye.x-me)/de,(ye.y-ge)/pe);for(let[ye,Me,be]of re)Z.push(ce+ye,ce+Me,ce+be)}S(this,U,Q,X,Z)}}function S(R,A,L,C,U){return R.setAttribute("position",new a(A,3)),R.setAttribute("normal",new a(L,3)),R.setAttribute("uv",new a(C,2)),R.setIndex(U),R}function O(R){let A=R.length,L=[];for(let C=0;C<A;C++){let U=R[(C+A-1)%A],Q=R[C],X=R[(C+1)%A],Z=Q.x-U.x,J=Q.y-U.y,K=Math.hypot(Z,J)||1;Z/=K,J/=K;let ae=X.x-Q.x,ne=X.y-Q.y,re=Math.hypot(ae,ne)||1;ae/=re,ne/=re;let ce=J,me=-Z,ge=ne,de=-ae,pe=ce+ge,ye=me+de,Me=Math.hypot(pe,ye);if(Me>1e-6){pe/=Me,ye/=Me;let be=Math.max(.35,pe*ce+ye*me);L.push(new r(pe/be,ye/be))}else L.push(new r(ce,me))}return L}class k extends u{constructor(A=new p,L={}){super();let C=Array.isArray(A)?A:[A],U=Math.max(1,Math.min(64,Math.floor(b(L.curveSegments,12)))),Q=b(L.depth??L.amount,1),X=Math.max(1,Math.min(32,Math.floor(b(L.steps,1)))),Z=!!(L.bevelEnabled??!1),J=Z?Math.max(0,b(L.bevelThickness,.06)):0,K=Z?Math.max(0,b(L.bevelSize,J*.8)):0,ae=Z?b(L.bevelOffset,0):0,ne=Z?Math.max(1,Math.min(8,Math.floor(b(L.bevelSegments,2)))):0,re=[],ce=[],me=[],ge=[];for(let de of C){if(!(de instanceof v))continue;let pe=W(de,U);if(pe.shape.length<3)continue;let ye=pe.shape.slice();y(ye)<0&&ye.reverse();let Me=[];for(let _e of pe.holes){if(_e.length<3)continue;let Ce=_e.slice();y(Ce)>0&&Ce.reverse(),Me.push(Ce)}let{mergedIndices:be,allVertices:Ee}=P(ye,Me),Se=F(be,Ee),Re=[ye,...Me],Ne=[];for(let _e of Re){let Ce=O(_e);for(let je of Ce)Ne.push(je)}let[De,Je,Xe,mt]=T(Ee);for(let[_e,Ce]of[[-J,-1],[Q+J,1]]){let je=re.length/3;for(let $e=0;$e<Ee.length;$e++){let Oe=Ee[$e],Be=Ne[$e]??new r(0,0),rt=Oe.x+Be.x*ae,Ze=Oe.y+Be.y*ae;re.push(rt,Ze,_e),ce.push(0,0,Ce),me.push((rt-De)/Xe,(Ze-Je)/mt)}for(let[$e,Oe,Be]of Se)ge.push(je+$e,je+(Ce<0?Be:Oe),je+(Ce<0?Oe:Be))}let Ve=[];if(Z&&ne>0)for(let _e=0;_e<ne;_e++){let Ce=_e/ne*Math.PI/2;Ve.push({z:-J*Math.cos(Ce),expand:ae+K*Math.sin(Ce)})}for(let _e=0;_e<=X;_e++){let Ce=_e/X;Ve.push({z:Ce*Q,expand:ae+K})}if(Z&&ne>0)for(let _e=1;_e<=ne;_e++){let Ce=_e/ne*Math.PI/2;Ve.push({z:Q+J*Math.sin(Ce),expand:ae+K*Math.cos(Ce)})}let st=0;for(let _e of Re){let Ce=_e.length;for(let je=0;je<Ve.length-1;je++){let $e=Ve[je],Oe=Ve[je+1];for(let Be=0;Be<Ce;Be++){let rt=(Be+1)%Ce,Ze=_e[Be],at=_e[rt],ot=Ne[st+Be],lt=Ne[st+rt],ft=Ze.x+ot.x*$e.expand,pt=Ze.y+ot.y*$e.expand,jt=at.x+lt.x*$e.expand,qt=at.y+lt.y*$e.expand,gr=at.x+lt.x*Oe.expand,yr=at.y+lt.y*Oe.expand,Lt=Ze.x+ot.x*Oe.expand,_t=Ze.y+ot.y*Oe.expand,It=jt-ft,vt=qt-pt,Ru=Lt-ft,Pu=_t-pt,Za=Oe.z-$e.z,Xt=vt*Za,Kt=-It*Za,Yt=It*Pu-vt*Ru,an=Math.hypot(Xt,Kt,Yt)||1;Xt/=an,Kt/=an,Yt/=an;let Zt=re.length/3;re.push(ft,pt,$e.z,jt,qt,$e.z,gr,yr,Oe.z,Lt,_t,Oe.z),ce.push(Xt,Kt,Yt,Xt,Kt,Yt,Xt,Kt,Yt,Xt,Kt,Yt);let Qa=Be/Ce,Ja=(Be+1)/Ce,eo=je/(Ve.length-1),to=(je+1)/(Ve.length-1);me.push(Qa,eo,Ja,eo,Ja,to,Qa,to),ge.push(Zt,Zt+1,Zt+2,Zt,Zt+2,Zt+3)}}st+=Ce}}S(this,re,ce,me,ge)}}function w(R){return{x:R.x,y:R.y,z:R.z,nx:R.nx,ny:R.ny,nz:R.nz,u:R.u,v:R.v}}function ie(R){return{x:R.x,y:R.y,z:R.z,nx:-R.nx,ny:-R.ny,nz:-R.nz,u:R.u,v:R.v}}function oe(R,A,L){let C=R.nx+(A.nx-R.nx)*L,U=R.ny+(A.ny-R.ny)*L,Q=R.nz+(A.nz-R.nz)*L,X=Math.hypot(C,U,Q)||1;return{x:R.x+(A.x-R.x)*L,y:R.y+(A.y-R.y)*L,z:R.z+(A.z-R.z)*L,nx:C/X,ny:U/X,nz:Q/X,u:R.u+(A.u-R.u)*L,v:R.v+(A.v-R.v)*L}}function I(R){if(R.length<3)return null;let A=R[0],L=R[1],C=R[2],U=L.x-A.x,Q=L.y-A.y,X=L.z-A.z,Z=C.x-A.x,J=C.y-A.y,K=C.z-A.z,ae=Q*K-X*J,ne=X*Z-U*K,re=U*J-Q*Z,ce=Math.hypot(ae,ne,re);if(ce<1e-9)return null;ae/=ce,ne/=ce,re/=ce;let me=ae*A.x+ne*A.y+re*A.z;return{vertices:R,nx:ae,ny:ne,nz:re,w:me}}function H(R){R.vertices.reverse();for(let A=0;A<R.vertices.length;A++)R.vertices[A]=ie(R.vertices[A]);R.nx=-R.nx,R.ny=-R.ny,R.nz=-R.nz,R.w=-R.w}let N=1e-5,z=0,ue=1,he=2,B=3;function $(R,A,L,C,U,Q,X,Z,J){let K=0,ae=[];for(let ne=0;ne<U.vertices.length;ne++){let re=U.vertices[ne],ce=R*re.x+A*re.y+L*re.z-C,me=ce<-N?he:ce>N?ue:z;K|=me,ae.push(me)}switch(K){case z:{R*U.nx+A*U.ny+L*U.nz>0?Q.push(U):X.push(U);break}case ue:Z.push(U);break;case he:J.push(U);break;case B:{let ne=[],re=[],ce=U.vertices.length;for(let ye=0;ye<ce;ye++){let Me=(ye+1)%ce,be=ae[ye],Ee=ae[Me],Se=U.vertices[ye],Re=U.vertices[Me];if(be!==he&&ne.push(Se),be!==ue&&re.push(be!==he?w(Se):Se),(be|Ee)===B){let Ne=Re.x-Se.x,De=Re.y-Se.y,Je=Re.z-Se.z,Xe=R*Ne+A*De+L*Je,mt=Math.abs(Xe)>1e-12?(C-(R*Se.x+A*Se.y+L*Se.z))/Xe:.5,Ve=oe(Se,Re,Math.max(0,Math.min(1,mt)));ne.push(Ve),re.push(w(Ve))}}let{nx:me,ny:ge,nz:de,w:pe}=U;ne.length>=3&&Z.push({vertices:ne,nx:me,ny:ge,nz:de,w:pe}),re.length>=3&&J.push({vertices:re,nx:me,ny:ge,nz:de,w:pe});break}default:break}}class _{constructor(A,L=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,A&&A.length>0&&this.build(A,L)}invert(){for(let L=0;L<this.polygons.length;L++)H(this.polygons[L]);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 A=this.front;this.front=this.back,this.back=A}clipPolygons(A,L=0){if(!this.hasPlane||A.length===0)return A.slice();if(L>=f)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${f})`);let C=[],U=[];for(let Q=0;Q<A.length;Q++)$(this.nx,this.ny,this.nz,this.w,A[Q],C,U,C,U);return this.front&&C.length>0&&(C=this.front.clipPolygons(C,L+1)),this.back?U=U.length>0?this.back.clipPolygons(U,L+1):[]:U=[],C.concat(U)}clipTo(A,L=0){this.polygons.length>0&&(this.polygons=A.clipPolygons(this.polygons,0)),L<f&&(this.front&&this.front.clipTo(A,L+1),this.back&&this.back.clipTo(A,L+1))}allPolygons(A=[]){for(let L=0;L<this.polygons.length;L++)A.push(this.polygons[L]);return this.front&&this.front.allPolygons(A),this.back&&this.back.allPolygons(A),A}build(A,L=0){if(!A.length)return;if(!this.hasPlane){let Q=A[A.length>>1];this.nx=Q.nx,this.ny=Q.ny,this.nz=Q.nz,this.w=Q.w,this.hasPlane=!0}if(L>=f)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${f})`);let C=[],U=[];for(let Q=0;Q<A.length;Q++)$(this.nx,this.ny,this.nz,this.w,A[Q],this.polygons,this.polygons,C,U);C.length>0&&(this.front||(this.front=new _),this.front.build(C,L+1)),U.length>0&&(this.back||(this.back=new _),this.back.build(U,L+1))}}function G(R,A){if(!A&&R._csgPolygons)return R._csgPolygons;let L=R.attributes.position;if(!L||L.count===0)return[];let C=R.attributes.normal,U=R.attributes.uv,Q=R.index?R.index.array:null,X=Math.floor(Q?Q.length/3:L.count/3);if(X>d)throw new RangeError(`SecurityError: CSG input triangle count (${X}) exceeds MAX_CSG_TRIANGLES (${d})`);let Z=A?A.elements:null,J=Z?Z[0]*(Z[5]*Z[10]-Z[9]*Z[6])-Z[4]*(Z[1]*Z[10]-Z[9]*Z[2])+Z[8]*(Z[1]*Z[6]-Z[5]*Z[2])<0:!1,K=Z?new l().getNormalMatrix(A).elements:null,ae=re=>{let ce=L.getX(re),me=L.getY(re),ge=L.getZ(re),de=C?C.getX(re):NaN,pe=C?C.getY(re):NaN,ye=C?C.getZ(re):NaN;if(Z&&K){let Ee=Z[0]*ce+Z[4]*me+Z[8]*ge+Z[12],Se=Z[1]*ce+Z[5]*me+Z[9]*ge+Z[13],Re=Z[2]*ce+Z[6]*me+Z[10]*ge+Z[14];ce=Ee,me=Se,ge=Re;let Ne=K[0]*de+K[3]*pe+K[6]*ye,De=K[1]*de+K[4]*pe+K[7]*ye,Je=K[2]*de+K[5]*pe+K[8]*ye,Xe=Math.hypot(Ne,De,Je)||1;de=Ne/Xe,pe=De/Xe,ye=Je/Xe}let Me=U?U.getX(re):0,be=U?U.getY(re):0;return{x:ce,y:me,z:ge,nx:de,ny:pe,nz:ye,u:Me,v:be}},ne=[];for(let re=0;re<X;re++){let ce=Q?Q[re*3]:re*3,me=Q?Q[re*3+1]:re*3+1,ge=Q?Q[re*3+2]:re*3+2,de=I(J?[ae(ce),ae(ge),ae(me)]:[ae(ce),ae(me),ae(ge)]);de&&ne.push(de)}return ne}function j(R){let A=[],L=[],C=[],U=[];for(let X of R){let Z=X.vertices;if(Z.length<3)continue;let J=A.length/3;for(let K of Z)A.push(K.x,K.y,K.z),Number.isFinite(K.nx)&&K.nx*K.nx+K.ny*K.ny+K.nz*K.nz>.5?L.push(K.nx,K.ny,K.nz):L.push(X.nx,X.ny,X.nz),C.push(K.u,K.v);for(let K=1;K<Z.length-1;K++)U.push(J,J+K,J+K+1)}let Q=S(new u,A,L,C,U);return Q._csgPolygons=R,Q}function q(R,A,L){if(R.length+A.length>d)throw new RangeError(`SecurityError: Combined CSG triangle count (${R.length+A.length}) exceeds MAX_CSG_TRIANGLES (${d})`);if(R.length===0)return L==="union"?A:[];if(A.length===0)return L==="intersect"?[]:R;let C=1/0,U=1/0,Q=1/0,X=-1/0,Z=-1/0,J=-1/0;for(let ce=0;ce<A.length;ce++){let me=A[ce].vertices;for(let ge=0;ge<me.length;ge++){let de=me[ge];de.x<C&&(C=de.x),de.y<U&&(U=de.y),de.z<Q&&(Q=de.z),de.x>X&&(X=de.x),de.y>Z&&(Z=de.y),de.z>J&&(J=de.z)}}C-=1e-4,U-=1e-4,Q-=1e-4,X+=1e-4,Z+=1e-4,J+=1e-4;let K=[],ae=[];for(let ce=0;ce<R.length;ce++){let me=R[ce],ge=me.vertices,de=1/0,pe=1/0,ye=1/0,Me=-1/0,be=-1/0,Ee=-1/0;for(let Se=0;Se<ge.length;Se++){let Re=ge[Se];Re.x<de&&(de=Re.x),Re.y<pe&&(pe=Re.y),Re.z<ye&&(ye=Re.z),Re.x>Me&&(Me=Re.x),Re.y>be&&(be=Re.y),Re.z>Ee&&(Ee=Re.z)}Me<C||de>X||be<U||pe>Z||Ee<Q||ye>J?ae.push(me):K.push(me)}if(K.length===0)return L==="union"?R.concat(A):L==="subtract"?R:[];let ne=new _(K),re=new _(A);return L==="union"?(ne.clipTo(re),re.clipTo(ne),re.invert(),re.clipTo(ne),re.invert(),ne.build(re.allPolygons()),ae.concat(ne.allPolygons())):L==="subtract"?(ne.invert(),ne.clipTo(re),re.clipTo(ne),re.invert(),re.clipTo(ne),re.invert(),ne.build(re.allPolygons()),ne.invert(),ae.concat(ne.allPolygons())):(ne.invert(),re.clipTo(ne),re.invert(),ne.clipTo(re),re.clipTo(ne),ne.build(re.allPolygons()),ne.invert(),ne.allPolygons())}function D(R,A,L,C=null,U=null){let Q=G(R,C),X=G(A,U);return j(q(Q,X,L))}function Y(R,A,L){let C=R instanceof c||!!R?.isMesh,U=A instanceof c||!!A?.isMesh,Q=C?R.geometry:R,X=U?A.geometry:A,Z=null;if(U)if(A.updateMatrix(),C){R.updateMatrix();let ne=new s().makeScale(1/(R.scale.x||1),1/(R.scale.y||1),1/(R.scale.z||1)),re=Math.hypot(R.quaternion.x,R.quaternion.y,R.quaternion.z,R.quaternion.w)||1,ce=new s().compose(new i(0,0,0),new n(-R.quaternion.x/re,-R.quaternion.y/re,-R.quaternion.z/re,R.quaternion.w/re),new i(1,1,1)),me=new s().makeTranslation(-R.position.x,-R.position.y,-R.position.z);Z=ne.multiply(ce).multiply(me).multiply(A.matrix)}else Z=A.matrix;let J=D(Q,X,L,null,Z),K=C?R.material:new m,ae=new c(J,K);return C&&(ae.position.copy(R.position),ae.quaternion.copy(R.quaternion),ae.scale.copy(R.scale),ae.name=R.name),ae}let te={toGeometry:D,subtract(R,A){return Y(R,A,"subtract")},union(R,A){return Y(R,A,"union")},intersect(R,A){return Y(R,A,"intersect")}},se={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 le extends u{constructor(A="",L={}){super();let C=String(A??"").slice(0,g),U=Math.max(.005,Math.min(100,b(L.size,.2))),Q=!!(L.bevelEnabled??!1),X=Q?Math.max(0,Math.min(2,b(L.bevelThickness,U*.04))):0,Z=Q?Math.max(0,Math.min(2,b(L.bevelSize,U*.03))):0,J=Math.max(.001,Math.min(20,b(L.depth??L.height,U*.2)))+X*2,K=U*.085+Z,ae=U*.68,ne=U*.82,re=[],ce=[],me=[],ge=[],de=(Me,be,Ee,Se,Re,Ne,De)=>{let Je=Ee-Me,Xe=Se-be,mt=Math.hypot(Je,Xe),Ve=1,st=0;mt>1e-6&&(Ve=Je/mt,st=Xe/mt);let _e=-st*Re,Ce=Ve*Re,je=Ve*Re*.6,$e=st*Re*.6,Oe=Me-je+_e,Be=be-$e+Ce,rt=Me-je-_e,Ze=be-$e-Ce,at=Ee+je-_e,ot=Se+$e-Ce,lt=Ee+je+_e,ft=Se+$e+Ce,pt=(jt,qt,gr,yr,Lt,_t,It)=>{let vt=re.length/3;re.push(jt[0],jt[1],jt[2],qt[0],qt[1],qt[2],gr[0],gr[1],gr[2],yr[0],yr[1],yr[2]),ce.push(Lt,_t,It,Lt,_t,It,Lt,_t,It,Lt,_t,It),me.push(0,0,1,0,1,1,0,1),ge.push(vt,vt+1,vt+2,vt,vt+2,vt+3)};pt([Oe,Be,De],[rt,Ze,De],[at,ot,De],[lt,ft,De],0,0,1),pt([rt,Ze,Ne],[Oe,Be,Ne],[lt,ft,Ne],[at,ot,Ne],0,0,-1),pt([Oe,Be,Ne],[rt,Ze,Ne],[rt,Ze,De],[Oe,Be,De],-Ve,-st,0),pt([at,ot,Ne],[lt,ft,Ne],[lt,ft,De],[at,ot,De],Ve,st,0),pt([rt,Ze,Ne],[at,ot,Ne],[at,ot,De],[rt,Ze,De],st,-Ve,0),pt([lt,ft,Ne],[Oe,Be,Ne],[Oe,Be,De],[lt,ft,De],-st,Ve,0)},pe=0,ye=0;for(let Me=0;Me<C.length;Me++){let be=C[Me];if(be===`
17
+ `){pe=0,ye-=U*1.35;continue}if(be===" "||be===" "){pe+=ne*(be===" "?.75:3);continue}if(be==="\r")continue;let Ee=be.toUpperCase(),Se=be!==Ee&&be>="a"&&be<="z",Re=se[Ee]??se["?"],Ne=Se?U*.76:U,De=Se?ae*.88:ae;for(let Je of Re)for(let Xe=0;Xe<Je.length-1;Xe++){let mt=Je[Xe],Ve=Je[Xe+1];de(pe+mt[0]*De,ye+mt[1]*Ne,pe+Ve[0]*De,ye+Ve[1]*Ne,K,-J*.5,J*.5)}pe+=Se?ne*.88:ne}S(this,re,ce,me,ge),L.center!==!1?this.center():this.computeBoundingBox()}}function V(R){if(!R)return;let A=R,L=R.userData?.xr?.text??R.userData?.xr?.label??R.userData?.xr?.title??R.userData?.xr?.caption??R.userData?.xr?.spatialLabel;if(L!=null&&L!==!1){let U=A.geometry?.attributes?.position;if((!U||U.count===0)&&R.userData._textApplied!==!0){let Q="",X=.08,Z=.015,J;if(typeof L=="string"||typeof L=="number")Q=String(L);else if(typeof L=="object"){let K=L;Q=String(K.text??K.value??""),K.size!==void 0&&(X=Number(K.size)||.08),(K.depth!==void 0||K.height!==void 0)&&(Z=Number(K.depth??K.height)||X*.2),(typeof K.color=="string"||typeof K.color=="number")&&(J=K.color)}Q.trim().length>0&&(A.geometry=new le(Q,{size:X,depth:Z}),R.userData._textApplied=!0,A.material instanceof h?J!==void 0&&R.userData._autoTextColorApplied!==!0&&(A.material.color=new o(J),R.userData._autoTextColorApplied=!0):A.material=new m({color:J??16317180}))}}let C=R.userData?.csg;if(C&&typeof C=="object"&&R.userData._csgApplied!==!0&&A.geometry instanceof u&&A.geometry.attributes.position?.count>0){R.userData._csgApplied=!0;let U=Array.isArray(C)?C:[C],Q=A.geometry;for(let X of U){if(!X||typeof X!="object")continue;let Z=X,J=String(Z.op??Z.operation??"subtract"),K=J==="union"||J==="intersect"?J:"subtract",ae=Z.target??Z.mesh??Z.geometry;if(ae instanceof c||ae instanceof u)try{let ne=K==="union"?te.union(A,ae):K==="intersect"?te.intersect(A,ae):te.subtract(A,ae);A.geometry!==Q&&A.geometry.dispose?.(),A.geometry=ne.geometry}catch(ne){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ne)}}}}let ee={Path:v,Shape:p,ShapeGeometry:E,ExtrudeGeometry:k,TextGeometry:le,CSG:te,MAX_CSG_TRIANGLES:d,MAX_BSP_DEPTH:f,MAX_TEXT_GEOMETRY_CHARS:g,MAX_SHAPE_POINTS:x,materializeDeclarativeGeometry:V};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,ee),t._cadMaterialize=V,t.materializeDeclarativeGeometry=R=>{t._cadMaterialize?.(R),t._lodMaterialize?.(R)}),ee}var hn={name:"cad",onRegister(){Jr(ei);let e=Ae(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);t&&ei(t,e)}};function Pe(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function ti(e,t,r,i,n){let s=1/Math.tan(t/2);e.fill(0),e[0]=s/r,e[5]=s,e[11]=-1;let l=1/(i-n);return e[10]=(n+i)*l,e[14]=2*n*i*l,e}function xr(e,t,r,i){let[n,s,l]=t,[o,a,u]=i,[h,m,c]=r,d=n-h,f=s-m,g=l-c,x=Math.hypot(d,f,g);x<=1e-5?(d=0,f=0,g=1):(d/=x,f/=x,g/=x);let b=a*g-u*f,v=u*d-o*g,p=o*f-a*d;x=Math.hypot(b,v,p),x<=1e-5?(b=0,v=0,p=0):(b/=x,v/=x,p/=x);let y=f*p-g*v,M=g*b-d*p,P=d*v-f*b;return x=Math.hypot(y,M,P),x<=1e-5?(y=0,M=0,P=0):(y/=x,M/=x,P/=x),e[0]=b,e[1]=y,e[2]=d,e[3]=0,e[4]=v,e[5]=M,e[6]=f,e[7]=0,e[8]=p,e[9]=P,e[10]=g,e[11]=0,e[12]=-(b*n+v*s+p*l),e[13]=-(y*n+M*s+P*l),e[14]=-(d*n+f*s+g*l),e[15]=1,e}function ke(e,t,r){let i=t[0],n=t[1],s=t[2],l=t[3],o=t[4],a=t[5],u=t[6],h=t[7],m=t[8],c=t[9],d=t[10],f=t[11],g=t[12],x=t[13],b=t[14],v=t[15],p=r[0],y=r[1],M=r[2],P=r[3];return e[0]=p*i+y*o+M*m+P*g,e[1]=p*n+y*a+M*c+P*x,e[2]=p*s+y*u+M*d+P*b,e[3]=p*l+y*h+M*f+P*v,p=r[4],y=r[5],M=r[6],P=r[7],e[4]=p*i+y*o+M*m+P*g,e[5]=p*n+y*a+M*c+P*x,e[6]=p*s+y*u+M*d+P*b,e[7]=p*l+y*h+M*f+P*v,p=r[8],y=r[9],M=r[10],P=r[11],e[8]=p*i+y*o+M*m+P*g,e[9]=p*n+y*a+M*c+P*x,e[10]=p*s+y*u+M*d+P*b,e[11]=p*l+y*h+M*f+P*v,p=r[12],y=r[13],M=r[14],P=r[15],e[12]=p*i+y*o+M*m+P*g,e[13]=p*n+y*a+M*c+P*x,e[14]=p*s+y*u+M*d+P*b,e[15]=p*l+y*h+M*f+P*v,e}function Qt(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=n+n,u=s+s,h=l+l,m=n*a,c=n*u,d=n*h,f=s*u,g=s*h,x=l*h,b=o*a,v=o*u,p=o*h,y=i[0],M=i[1],P=i[2];return e[0]=(1-(f+x))*y,e[1]=(c+p)*y,e[2]=(d-v)*y,e[3]=0,e[4]=(c-p)*M,e[5]=(1-(m+x))*M,e[6]=(g+b)*M,e[7]=0,e[8]=(d+v)*P,e[9]=(g-b)*P,e[10]=(1-(m+f))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function Ke(e,t,r=0){let i=t[0],n=t[1],s=t[2],l=t[4],o=t[5],a=t[6],u=t[8],h=t[9],m=t[10],c=m*o-a*h,d=-m*l+a*u,f=h*l-o*u,g=i*c+n*d+s*f;return!g||r>0&&(!Number.isFinite(g)||Math.abs(g)<=r)||(g=1/g,e[0]=c*g,e[1]=d*g,e[2]=f*g,e[3]=(-m*n+s*h)*g,e[4]=(m*i-s*u)*g,e[5]=(-h*i+n*u)*g,e[6]=(a*n-s*o)*g,e[7]=(-a*i+s*l)*g,e[8]=(o*i-n*l)*g),e}function ri(e,t){let r=t[0],i=t[1],n=t[2],s=t[3],l=t[4],o=t[5],a=t[6],u=t[7],h=t[8],m=t[9],c=t[10],d=t[11],f=t[12],g=t[13],x=t[14],b=t[15],v=r*o-i*l,p=r*a-n*l,y=r*u-s*l,M=i*a-n*o,P=i*u-s*o,F=n*u-s*a,W=h*g-m*f,T=h*x-c*f,E=h*b-d*f,S=m*x-c*g,O=m*b-d*g,k=c*b-d*x,w=v*k-p*O+y*S+M*E-P*T+F*W;return w?(w=1/w,e[0]=(o*k-a*O+u*S)*w,e[1]=(n*O-i*k-s*S)*w,e[2]=(g*F-x*P+b*M)*w,e[3]=(c*P-m*F-d*M)*w,e[4]=(a*E-l*k-u*T)*w,e[5]=(r*k-n*E+s*T)*w,e[6]=(x*y-f*F-b*p)*w,e[7]=(h*F-c*y+d*p)*w,e[8]=(l*O-o*E+u*W)*w,e[9]=(i*E-r*O-s*W)*w,e[10]=(f*P-g*y+b*v)*w,e[11]=(m*y-h*P-d*v)*w,e[12]=(o*T-l*S-a*W)*w,e[13]=(r*S-i*T+n*W)*w,e[14]=(g*p-f*M-x*v)*w,e[15]=(h*M-m*p+c*v)*w,e):null}function cn(e,t,r,i,n){let s=n[0]*t+n[4]*r+n[8]*i+n[12],l=n[1]*t+n[5]*r+n[9]*i+n[13],o=n[2]*t+n[6]*r+n[10]*i+n[14],a=n[3]*t+n[7]*r+n[11]*i+n[15],u=a!==0?1/a:1;e[0]=s*u,e[1]=l*u,e[2]=o*u}function Ao(e,t,r,i,n,s,l,o,a,u,h,m,c,d,f,g,x=0){let b=u-l,v=h-o,p=m-a,y=c-l,M=d-o,P=f-a,F=n*P-s*M,W=s*y-i*P,T=i*M-n*y,E=b*F+v*W+p*T;if(E>-1e-7&&E<1e-7)return!1;let S=1/E,O=e-l,k=t-o,w=r-a,ie=S*(O*F+k*W+w*T);if(ie<-x||ie>1+x)return!1;let oe=k*p-w*v,I=w*b-O*p,H=O*v-k*b,N=S*(i*oe+n*I+s*H);if(N<-x||ie+N>1+x)return!1;let z=S*(y*oe+M*I+P*H);if(z>1e-4&&z<g.distance){g.distance=z,g.point=[e+i*z,t+n*z,r+s*z];let ue=v*P-p*M,he=p*y-b*P,B=b*M-v*y,$=Math.hypot(ue,he,B)||1;return g.normal=[ue/$,he/$,B/$],!0}return!1}function vr(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let h=0;h<r;h++)i.push(Pe());if(r===0)return i;let n=new Set;for(let h of e.nodes)if(Array.isArray(h.children))for(let m of h.children)n.add(m);let s=new Set,l=128,o=(h,m,c=0)=>{if(c>l||h<0||h>=r||s.has(h))return;s.add(h);let d=e.nodes[h];if(!d)return;let f=Pe();if(t&&t[h])f.set(t[h]);else if(d.matrix&&d.matrix.length===16)f.set(d.matrix);else{let x=d.translation||[0,0,0],b=d.rotation||[0,0,0,1],v=d.scale||[1,1,1];Qt(f,b,x,v)}let g=i[h];if(m?ke(g,m,f):g.set(f),Array.isArray(d.children))for(let x of d.children)typeof x=="number"&&o(x,g,c+1)},a=[],u=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let h=0;h<r;h++)n.has(h)||a.push(h);for(let h of a)o(h,null);for(let h=0;h<r;h++)!n.has(h)&&!a.includes(h)&&o(h,null);return i}function ii(e,t){function r(a,u,h,m){let c=typeof a=="number"?a:Number(a);return Number.isFinite(c)?Math.max(u,Math.min(h,c)):m}function i(a,u){let h=a[0]*u[0]+a[1]*u[1]+a[2]*u[2]+1;if(h<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let x=Math.hypot(a[1],a[0])||1;return[-a[1]/x,a[0]/x,0,0]}let g=Math.hypot(a[2],a[1])||1;return[0,-a[2]/g,a[1]/g,0]}let m=a[1]*u[2]-a[2]*u[1],c=a[2]*u[0]-a[0]*u[2],d=a[0]*u[1]-a[1]*u[0],f=Math.hypot(m,c,d,h)||1;return[m/f,c/f,d/f,h/f]}function n(a,u,h,m,c){let d=u[0]-a[0],f=u[1]-a[1],g=u[2]-a[2],x=Math.hypot(d,f,g),b=h[0]-u[0],v=h[1]-u[1],p=h[2]-u[2],y=Math.hypot(b,v,p);if(x<1e-6||y<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[u[0],u[1],u[2]],effectorPos:[h[0],h[1],h[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let M=[d/x,f/x,g/x],P=[b/y,v/y,p/y],F=m[0]-a[0],W=m[1]-a[1],T=m[2]-a[2],E=Math.hypot(F,W,T),S=E>1e-6?[F/E,W/E,T/E]:M,O=Math.abs(x-y)+1e-5,k=Math.max(O,x+y-1e-5),w=Math.max(O,Math.min(k,E>1e-6?E:O)),ie=r((x*x+w*w-y*y)/(2*x*w),-1,1,1),oe=Math.sqrt(Math.max(0,1-ie*ie)),I=c?c[0]-a[0]:d,H=c?c[1]-a[1]:f,N=c?c[2]-a[2]:g,z=I*S[0]+H*S[1]+N*S[2],ue=I-S[0]*z,he=H-S[1]*z,B=N-S[2]*z,$=Math.hypot(ue,he,B);if($<=1e-6){let ee=Math.abs(S[1])<.99?0:1,R=Math.abs(S[1])<.99?1:0,A=0;ue=S[1]*A-S[2]*R,he=S[2]*ee-S[0]*A,B=S[0]*R-S[1]*ee,$=Math.hypot(ue,he,B)||1}let _=[ue/$,he/$,B/$],G=[a[0]+S[0]*(x*ie)+_[0]*(x*oe),a[1]+S[1]*(x*ie)+_[1]*(x*oe),a[2]+S[2]*(x*ie)+_[2]*(x*oe)],j=[a[0]+S[0]*w,a[1]+S[1]*w,a[2]+S[2]*w],q=j[0]-G[0],D=j[1]-G[1],Y=j[2]-G[2],te=Math.hypot(q,D,Y),se=te>1e-6?[q/te,D/te,Y/te]:S,le=[G[0]+se[0]*y,G[1]+se[1]*y,G[2]+se[2]*y],V=[(G[0]-a[0])/x,(G[1]-a[1])/x,(G[2]-a[2])/x];return{rootPos:[a[0],a[1],a[2]],midPos:G,effectorPos:le,rootRotation:i(M,V),midRotation:i(P,se)}}function s(a,u,h=8,m=.001){let c=a.length;if(c<2)return{positions:a.map(E=>[E[0],E[1],E[2]]),rotations:[],iterations:0};let d=a.map(E=>[E[0],E[1],E[2]]),f=[],g=[],x=0;for(let E=0;E<c-1;E++){let S=d[E+1][0]-d[E][0],O=d[E+1][1]-d[E][1],k=d[E+1][2]-d[E][2],w=Math.hypot(S,O,k);f.push(w),x+=w,g.push(w>1e-6?[S/w,O/w,k/w]:[0,1,0])}let b=[d[0][0],d[0][1],d[0][2]],v=Math.round(r(h,1,32,8)),p=r(m,1e-5,.1,.001),y=u[0]-b[0],M=u[1]-b[1],P=u[2]-b[2],F=Math.hypot(y,M,P),W=0;if(F>=x&&x>1e-6){let E=F>1e-6?[y/F,M/F,P/F]:g[0];d[0]=[b[0],b[1],b[2]];for(let S=0;S<c-1;S++){let O=f[S];d[S+1]=[d[S][0]+E[0]*O,d[S][1]+E[1]*O,d[S][2]+E[2]*O]}W=1}else for(let E=1;E<=v;E++){let S=d[c-1];if(Math.hypot(S[0]-u[0],S[1]-u[1],S[2]-u[2])<=p)break;W=E;let O=(k,w,ie,oe,I)=>{let H=w[0]-k[0],N=w[1]-k[1],z=w[2]-k[2],ue=Math.hypot(H,N,z);if(ue>1e-6){let he=ie/ue;return[k[0]+H*he,k[1]+N*he,k[2]+z*he]}return[k[0]+oe[0]*ie*I,k[1]+oe[1]*ie*I,k[2]+oe[2]*ie*I]};d[c-1]=[u[0],u[1],u[2]];for(let k=c-2;k>=0;k--)d[k]=O(d[k+1],d[k],f[k],g[k],-1);d[0]=[b[0],b[1],b[2]];for(let k=0;k<c-1;k++)d[k+1]=O(d[k],d[k+1],f[k],g[k],1)}let T=[];for(let E=0;E<c-1;E++){let S=d[E+1][0]-d[E][0],O=d[E+1][1]-d[E][1],k=d[E+1][2]-d[E][2],w=Math.hypot(S,O,k),ie=w>1e-6?[S/w,O/w,k/w]:g[E];T.push(i(g[E],ie))}return{positions:d,rotations:T,iterations:W}}function l(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let u=a;if(u.enabled===!1)return null;let h=p=>{if(typeof p!="string")return;let y=p.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(y)?y:void 0},m=p=>Array.isArray(p)&&p.length===3&&p.every(y=>typeof y=="number"&&Number.isFinite(y))?[r(p[0],-1e3,1e3,0),r(p[1],-1e3,1e3,0),r(p[2],-1e3,1e3,0)]:void 0,c=h(u.root),d=h(u.effector);if(!c||!d)return null;let f=h(u.mid),g=m(u.target)??h(u.target);if(!g)return null;let x=u.pole??u.poleTarget,b=m(x)??h(x),v=u.solver==="fabrik"?"fabrik":u.solver==="two-bone"||f?"two-bone":"fabrik";return{root:c,...f?{mid:f}:{},effector:d,target:g,...b?{pole:b}:{},solver:v,iterations:Math.round(r(u.iterations,1,32,8)),tolerance:r(u.tolerance,1e-5,.1,.001),weight:r(u.weight,0,1,1)}}let o=Object.freeze({solveTwoBone:n,solveFABRIK:s,parseIKTrait:l});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=o),{clampNum:r,parseIKTrait:l,quatFromUnitVectors:i,solveTwoBoneIK:n,solveFABRIK:s,IKSolver:o}}var Dt=ii(),mn=Dt.clampNum,To=Dt.parseIKTrait,ni=Dt.quatFromUnitVectors,fn=Dt.solveTwoBoneIK,pn=Dt.solveFABRIK,So=Dt.IKSolver;function si(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function Ro(e,t){let r=e?.transform??e?.modelMatrix;!r||r.length<16||(r[12]=t[0],r[13]=t[1],r[14]=t[2])}function Po(e,t,r,i,n){let s=mn(n,0,1,1),l=t[0]+(r[0]-t[0])*s,o=t[1]+(r[1]-t[1])*s,a=t[2]+(r[2]-t[2])*s,u=l-e[0],h=o-e[1],m=a-e[2],c=Math.hypot(u,h,m);if(c>1e-6&&i>1e-6){let b=i/c;return[e[0]+u*b,e[1]+h*b,e[2]+m*b]}let d=r[0]-e[0],f=r[1]-e[1],g=r[2]-e[2],x=Math.hypot(d,f,g);if(x>1e-6&&i>1e-6){let b=i/x;return[e[0]+d*b,e[1]+f*b,e[2]+g*b]}return[l,o,a]}function Eo(e,t){let r=e?.modelRootMatrix;if(!r||r.length!==16)return t;let i=new Float32Array(16);return ri(i,r instanceof Float32Array?r:Float32Array.from(r))?[i[0]*t[0]+i[4]*t[1]+i[8]*t[2]+i[12],i[1]*t[0]+i[5]*t[1]+i[9]*t[2]+i[13],i[2]*t[0]+i[6]*t[1]+i[10]*t[2]+i[14]]:t}function ai(e,t){e.__ikWarned||(e.__ikWarned=new Set);let r=e.__ikWarned;r.has(t)||(r.add(t),console.warn(`[three-live] ik: joint '${t}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function oi(e,t,r){if(Array.isArray(e))return[e[0],e[1],e[2]];let i=t.get(e);if(i)return si(i);let n;if(e==="head"?n=r?.headPose?.position??r?.headPose??r?.cameraPosition:e==="hand-left"?n=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:e==="hand-right"&&(n=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(n)||ArrayBuffer.isView(n))&&n.length>=3){let s=n;return Eo(r,[s[0],s[1],s[2]])}return null}function li(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function No(e){return[-e[0],-e[1],-e[2],e[3]]}function ui(e){let t=Math.hypot(e[0],e[1],e[2],e[3]);return t>1e-12?[e[0]/t,e[1]/t,e[2]/t,e[3]/t]:[0,0,0,1]}function Co(e,t){if(t>=1)return e;if(t<=0)return[0,0,0,1];let[r,i,n,s]=e;s<0&&(r=-r,i=-i,n=-n,s=-s);let l=Math.acos(Math.min(1,s)),o=Math.sin(l);if(o<1e-9)return[0,0,0,1];let a=Math.sin(l*t)/o;return ui([r*a,i*a,n*a,Math.cos(l*t)])}function Lo(e){let t=Math.hypot(e[0],e[1],e[2])||1,r=Math.hypot(e[4],e[5],e[6])||1,i=Math.hypot(e[8],e[9],e[10])||1,n=e[0]/t,s=e[1]/t,l=e[2]/t,o=e[4]/r,a=e[5]/r,u=e[6]/r,h=e[8]/i,m=e[9]/i,c=e[10]/i,d=n+a+c,f;if(d>0){let g=Math.sqrt(d+1)*2;f=[(u-m)/g,(h-l)/g,(s-o)/g,.25*g]}else if(n>a&&n>c){let g=Math.sqrt(1+n-a-c)*2;f=[.25*g,(o+s)/g,(h+l)/g,(u-m)/g]}else if(a>c){let g=Math.sqrt(1+a-n-c)*2;f=[(o+s)/g,.25*g,(m+u)/g,(h-l)/g]}else{let g=Math.sqrt(1+c-n-a)*2;f=[(h+l)/g,(m+u)/g,.25*g,(s-o)/g]}return ui(f)}function _o(e,t,r){let[i,n,s,l]=r,o=1-2*(n*n+s*s),a=2*(i*n-s*l),u=2*(i*s+n*l),h=2*(i*n+s*l),m=1-2*(i*i+s*s),c=2*(n*s-i*l),d=2*(i*s-n*l),f=2*(n*s+i*l),g=1-2*(i*i+n*n);for(let x=0;x<3;x++){let b=t[x*4],v=t[x*4+1],p=t[x*4+2];e[x*4]=o*b+a*v+u*p,e[x*4+1]=h*b+m*v+c*p,e[x*4+2]=d*b+f*v+g*p}}function Mr(e,t){let r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],s=Math.hypot(r,i,n);return s>1e-9?[r/s,i/s,n/s]:null}function dn(e){e?.normalMatrix&&e?.transform&&Ke(e.normalMatrix,e.transform)}var gn=new WeakMap;function Io(e){let t=gn.get(e);return t||(t=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((r,i)=>{for(let n of Array.isArray(r?.children)?r.children:[])typeof n=="number"&&n>=0&&n<t.length&&(t[n]=i)}),gn.set(e,t)),t}function Do(e,t,r){let i=e?.gltf,n=i?.nodes;if(!Array.isArray(n)||n.length===0)return!1;let s=new Map;n.forEach((T,E)=>{typeof T?.name=="string"&&T.name&&!s.has(T.name)&&s.set(T.name,E)});let l=(t.mid?[t.root,t.mid,t.effector]:[t.root,t.effector]).map(T=>s.get(T));if(l.some(T=>T===void 0))return!1;let o=l,a=Io(i);for(let T=1;T<o.length;T++){let E=a[o[T]],S=0;for(;E>=0&&E!==o[T-1]&&S++<256;)E=a[E];if(E!==o[T-1])return!1}let u=o[0],h=e.initialNodeTransforms,m=new Map,c=[],d=[u];for(;d.length&&c.length<4096;){let T=d.pop();if(m.has(T))continue;let E=h?.[T],S=n[T];m.set(T,{t:E?[E.t[0],E.t[1],E.t[2]]:S?.translation?[...S.translation]:[0,0,0],r:E?[E.r[0],E.r[1],E.r[2],E.r[3]]:S?.rotation?[...S.rotation]:[0,0,0,1],s:E?[E.s[0],E.s[1],E.s[2]]:S?.scale?[...S.scale]:[1,1,1]}),c.push(T);for(let O of Array.isArray(S?.children)?S.children:[])typeof O=="number"&&d.push(O)}let f=a[u],g=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):Pe(),x=new Map,b=()=>{let T=(E,S)=>{let O=m.get(E);if(!O)return;let k=Pe();Qt(k,O.r,O.t,O.s);let w=Pe();ke(w,S,k),x.set(E,w);for(let ie of Array.isArray(n[E]?.children)?n[E].children:[])typeof ie=="number"&&T(ie,w)};T(u,g)},v=T=>{let E=x.get(T);return[E[12],E[13],E[14]]};b();let p=o.map(v),y=T=>{if(typeof T=="string"&&!r.has(T)){let E=s.get(T),S=E!==void 0?x.get(E)??e.worldMatrices?.[E]:void 0;if(S&&S.length===16)return[S[12],S[13],S[14]]}return oi(T,r,e)},M=y(t.target);if(!M)return!0;let P=t.pole?y(t.pole)??void 0:void 0,F=yn(p,t,M,P),W=mn(t.weight,0,1,1);for(let T=0;T<o.length-1;T++){let E=Mr(v(o[T]),v(o[T+1])),S=Mr(F[T],F[T+1]);if(!E||!S)continue;let O=Co(ni(E,S),W),k=o[T],w=a[k],ie=w===f||w<0?g:x.get(w)??g,oe=Lo(ie),I=m.get(k);I.r=ui(li(No(oe),li(O,li(oe,I.r)))),b()}if(Array.isArray(e.worldMatrices))for(let[T,E]of x)e.worldMatrices[T]?.set&&e.worldMatrices[T].set(E);for(let T of e.meshes??[]){let E=x.get(T?.nodeIndex);E&&T.transform?.set&&(T.transform.set(E),dn(T))}return!0}function yn(e,t,r,i){if(t.solver==="two-bone"&&e.length===3){let n=fn(e[0],e[1],e[2],r,i);return[e[0],n.midPos,n.effectorPos]}return pn(e,r,t.iterations,t.tolerance).positions}function ko(e,t,r){let i=e.__ikRestOffsets,n=e.__ikRestMats;if(!(!i||!n))for(let s=0;s<t.length-1;s++){let l=t[s]?.transform??t[s]?.modelMatrix,o=n[s],a=Mr([0,0,0],i[s]),u=Mr(r[s],r[s+1]);!l||l.length<16||!o||o.length<16||!a||!u||(_o(l,o,ni(a,u)),dn(t[s]))}}var bn={name:"ik",onRegister(){let e=Ae();Jr(ii),ii(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let r=null;for(let i of t){let n=i?.userData?.xr?.ik??i?.extras?.xr?.ik??i?.extensions?.ANDROID_xr_scenecore?.ik;if(!n)continue;let s=To(n);if(!s||s.weight<=0)continue;if(!r){r=new Map;for(let p of t)p&&typeof p.name=="string"&&p.name&&r.set(p.name,p)}if(Do(e,s,r))continue;let l=r.get(s.root),o=r.get(s.effector),a=s.mid?r.get(s.mid):void 0;if(l||ai(i,s.root),o||ai(i,s.effector),s.mid&&!a&&ai(i,s.mid),!l||!o)continue;let u=oi(s.target,r,e);if(!u)continue;let h=s.pole?oi(s.pole,r,e)??void 0:void 0,m=a?[l,a,o]:[l,o],c=m.map(p=>p.name||"").join(">");if(!i.__ikRestOffsets||i.__ikRestKey!==c){let p=m.map(si),y=[];for(let M=0;M<p.length-1;M++)y.push([p[M+1][0]-p[M][0],p[M+1][1]-p[M][1],p[M+1][2]-p[M][2]]);i.__ikRestOffsets=y,i.__ikRestKey=c,i.__ikRestMats=m.map(M=>Array.from(M.transform??M.modelMatrix??[]))}let d=i.__ikRestOffsets,f=[si(l)],g=[];for(let p=0;p<d.length;p++){let y=f[p],M=d[p];f.push([y[0]+M[0],y[1]+M[1],y[2]+M[2]]),g.push(Math.hypot(M[0],M[1],M[2]))}let x=yn(f,s,u,h),b=f[0],v=[f[0]];for(let p=1;p<m.length;p++){let y=d[p-1],M=[b[0]+y[0],b[1]+y[1],b[2]+y[2]],P=[b[0]+(x[p][0]-x[p-1][0]),b[1]+(x[p][1]-x[p-1][1]),b[2]+(x[p][2]-x[p-1][2])],F=Po(b,M,P,g[p-1],s.weight);Ro(m[p],F),b=F,v.push(F)}ko(i,m,v)}}};function wr(e,t){let r=(h,m,c,d)=>{let f=typeof h=="number"?h:Number(h);return Number.isFinite(f)?Math.max(m,Math.min(c,f)):d};function i(h,m,c=0,d=.05,f){if(!h||!h.length)return-1;let g=h[0]>0?[0,...h]:h,x=Number.isFinite(m)?Math.max(0,m):0,b=Number.isFinite(d)?Math.max(0,Math.min(.5,d)):.05;if(typeof f=="number"&&Number.isFinite(f)&&f>0){let y=c===-1?f*(1-b):f*(1+b);if(x>y)return-1}let v=0;for(let y=g.length-1;y>=1;y--)if(x>=g[y]){v=y;break}if(c<0||c>=g.length||c===v)return v;if(v>c){let y=c;for(let M=c+1;M<=v&&x>=g[M]*(1+b);M++)y=M;return y}let p=c;for(let y=c;y>v&&x<g[y]*(1-b);y--)p=y-1;return p}function n(h){if(!h)return null;let m=h===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(h)?{distances:h}:typeof h=="object"?h:null;if(!m||m.enabled===!1)return null;let c=r(m.hysteresis,0,.5,.05),d=[],f;if(Array.isArray(m.levels)&&m.levels.length>0){let v=m.levels.slice(0,8);for(let y=0;y<v.length;y++){let M=v[y];if(!M||typeof M!="object"||Array.isArray(M))continue;let P=M,F=r(P.distance,0,1e4,y===0?0:y*4),W=typeof P.hysteresis=="number"?r(P.hysteresis,0,.5,c):void 0,T=typeof P.ratio=="number"?r(P.ratio,.05,1,.5):void 0,E=typeof P.childIndex=="number"&&Number.isFinite(P.childIndex)?Math.max(0,Math.round(P.childIndex)):void 0,S=typeof P.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(P.node.trim())?P.node.trim().slice(0,64):void 0;d.push({distance:F,...W!==void 0?{hysteresis:W}:{},...T!==void 0?{ratio:T}:{},...E!==void 0?{childIndex:E}:{},...S?{node:S}:{}})}d.sort((y,M)=>y.distance-M.distance),d.length>0&&d[0].distance>0&&d.unshift({distance:0,childIndex:0});let p=0;d=d.slice(0,8).map((y,M)=>{let P=M===0?0:Math.max(p,y.distance);return p=P,{...y,distance:P,childIndex:y.childIndex??M}})}if(Array.isArray(m.ratios)&&m.ratios.length>0){let v=[];for(let p of m.ratios.slice(0,7))typeof p=="number"&&v.push(r(p,.05,1,.5));v.length>0&&(f=v)}if(d.length===0){let v=Array.isArray(m.distances)?m.distances:[],p=[];for(let M of v.slice(0,8))typeof M=="number"&&p.push(r(M,0,1e4,4));if(p.length===0&&f&&f.length>0)for(let M=0;M<f.length;M++)p.push((M+1)*4);if(p.length===0&&m.cullDistance===void 0)return null;p.length===0||p[0]>0?p.unshift(0):f&&f.length===p.length&&f[0]===1&&(f=f.slice(1));let y=0;for(let M=0;M<Math.min(8,p.length);M++){let P=M===0?0:Math.max(y,p[M]);y=P;let F=M>0&&f?f[M-1]:void 0;d.push({distance:P,childIndex:M,...F!==void 0?{ratio:F}:{}})}}else if(!f){let v=[];for(let p=1;p<d.length;p++)typeof d[p].ratio=="number"&&v.push(d[p].ratio);v.length>0&&(f=v)}let g=d.map(v=>v.distance),x=g[g.length-1]??0,b=m.cullDistance!==void 0&&m.cullDistance!==null&&m.cullDistance!==!1?r(m.cullDistance,Math.max(1,x),1e4,100):void 0;return{levels:d,distances:g,...f?{ratios:f}:{},hysteresis:c,...b!==void 0?{cullDistance:b}:{}}}function s(h,m){let c=h?.attributes?.position;if(!c||!c.array||c.count<3)return h;let d=r(m,.05,1,.5),f=c.array,g=c.count,x=h.attributes?.normal?.array,b=h.attributes?.uv?.array,v=h.index?.array,p=Math.floor((v?v.length:g)/3);if(p<1)return h;let y=Math.max(1,Math.min(p,Math.round(p*d))),M=1/0,P=1/0,F=1/0,W=-1/0,T=-1/0,E=-1/0;for(let $=0;$<g;$++){let _=f[$*3],G=f[$*3+1],j=f[$*3+2];_<M&&(M=_),G<P&&(P=G),j<F&&(F=j),_>W&&(W=_),G>T&&(T=G),j>E&&(E=j)}let S=Math.max(1e-5,W-M),O=Math.max(1e-5,T-P),k=Math.max(1e-5,E-F),w=Math.max(S,O,k),ie=$=>{let _=Math.max(1,Math.round(S/w*$)),G=Math.max(1,Math.round(O/w*$)),j=Math.max(1,Math.round(k/w*$)),q=new Map,D=new Int32Array(g),Y=[],te=[],se=[],le=[];for(let C=0;C<g;C++){let U=f[C*3],Q=f[C*3+1],X=f[C*3+2],Z=Math.min(_-1,Math.max(0,Math.floor((U-M)/S*_))),J=Math.min(G-1,Math.max(0,Math.floor((Q-P)/O*G))),K=Math.min(j-1,Math.max(0,Math.floor((X-F)/k*j))),ae=Z+J*_+K*_*G,ne=q.get(ae);ne===void 0?(ne=le.length,q.set(ae,ne),Y.push(U,Q,X),x&&te.push(x[C*3],x[C*3+1],x[C*3+2]),b&&se.push(b[C*2],b[C*2+1]),le.push(1)):(Y[ne*3]+=U,Y[ne*3+1]+=Q,Y[ne*3+2]+=X,x&&(te[ne*3]+=x[C*3],te[ne*3+1]+=x[C*3+1],te[ne*3+2]+=x[C*3+2]),le[ne]++),D[C]=ne}let V=[],ee=new Set;for(let C=0;C<p;C++){let U=v?v[C*3]:C*3,Q=v?v[C*3+1]:C*3+1,X=v?v[C*3+2]:C*3+2,Z=D[U],J=D[Q],K=D[X];if(Z===J||J===K||K===Z)continue;let ae=Math.min(Z,J,K),ne=Math.max(Z,J,K),re=Z+J+K-ae-ne,ce=`${ae}_${re}_${ne}`;ee.has(ce)||(ee.add(ce),V.push(Z,J,K))}let R=le.length,A=new Float32Array(R*3),L=x?new Float32Array(R*3):null;for(let C=0;C<R;C++){let U=1/le[C];if(A[C*3]=Y[C*3]*U,A[C*3+1]=Y[C*3+1]*U,A[C*3+2]=Y[C*3+2]*U,L){let Q=te[C*3],X=te[C*3+1],Z=te[C*3+2],J=Math.hypot(Q,X,Z)||1;L[C*3]=Q/J,L[C*3+1]=X/J,L[C*3+2]=Z/J}}return{pos:A,norm:L,uv:b?new Float32Array(se):null,tris:V,triCount:V.length/3,vertCount:R}},oe=Math.max(2,Math.round(Math.sqrt(y/4))),I=ie(oe);if(I.triCount>y*1.25&&oe>2){let $=Math.max(2,Math.round(oe*Math.sqrt(y/I.triCount)));if($!==oe){let _=ie($);_.triCount>=Math.min(4,y)&&(I=_)}}else if(I.triCount<Math.min(4,y)){let $=ie(Math.max(oe*2,8));$.triCount>I.triCount&&(I=$)}let H=I.tris;if(d<1&&I.triCount>y){let $=[],_=I.triCount/y;for(let G=0;G<y;G++){let j=Math.min(I.triCount-1,Math.floor(G*_));$.push(I.tris[j*3],I.tris[j*3+1],I.tris[j*3+2])}H=$}if(H.length<3){H=[];for(let $=0;$<y*3;$++)H.push(v?v[$]:$);I={pos:f.slice(),norm:x?x.slice():null,uv:b?b.slice():null,tris:H,triCount:y,vertCount:g}}let N=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),z=N?.BufferGeometry??h.constructor,ue=N?.BufferAttribute??c.constructor,he=new z;he.setAttribute("position",new ue(I.pos,3)),I.norm&&he.setAttribute("normal",new ue(I.norm,3)),I.uv&&he.setAttribute("uv",new ue(I.uv,2));let B=I.vertCount>65535?new Uint32Array(H):new Uint16Array(H);return typeof he.setIndex=="function"?he.setIndex(new ue(B,1)):he.index=new ue(B,1),he}let l=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...h){for(let m of h)m&&(m.parent=this,this.children.push(m));return this}};class o extends l{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(m,c=0,d=.05){if(!m)return this;let f=Math.max(0,Number.isFinite(Number(c))?Number(c):0),g=r(d,0,.5,.05),x=this.levels.length;for(let p=0;p<this.levels.length;p++)if(f<this.levels[p].distance){x=p;break}this.levels.splice(x,0,{object:m,distance:f,hysteresis:g}),this.add(m);let b=this.levels.map(p=>p.object),v=this.children.filter(p=>!b.includes(p));this.children=[...b,...v];for(let p=0;p<this.levels.length;p++)this.levels[p].object.visible=p===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(m){if(!this.levels.length)return null;let c=i(this.levels.map(d=>d.distance),m,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return c>=0&&c<this.levels.length?this.levels[c].object:null}update(m){if(this.levels.length===0||!m)return;let c=m.position??{x:0,y:0,z:0},d=this.position??{x:0,y:0,z:0},f=Math.hypot((Number(c.x)||0)-(Number(d.x)||0),(Number(c.y)||0)-(Number(d.y)||0),(Number(c.z)||0)-(Number(d.z)||0)),g=i(this.levels.map(x=>x.distance),f,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=g;for(let x=0;x<this.levels.length;x++)this.levels[x].object.visible=x===g}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let m=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((c,d)=>({distance:c.distance,hysteresis:c.hysteresis,childIndex:d,...c.object?.name?{node:c.object.name}:{}})),distances:this.levels.map(c=>c.distance),hysteresis:this.levels[0]?.hysteresis??.05,...m!==void 0?{cullDistance:m}:{}}}}function a(h){if(!h||h._lodMaterialized||!h.userData?.xr?.lod||h.isLOD||Array.isArray(h.children)&&h.children.length>0)return;let m=h.geometry?.attributes?.position;if(!m||!m.array||m.count<3)return;let c=n(h.userData.xr.lod);if(!c||c.levels.length<2)return;h._lodMaterialized=!0;let d=h.geometry;h._lodOriginalGeometry=d;let f=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),g=f?.Mesh??h.constructor,x=f?.BufferGeometry??d.constructor,b=typeof h.name=="string"&&h.name.trim()?h.name.trim():"Mesh",v=new g(d,h.material);v.name=`${b}_LOD0`,v.visible=!0,v.castShadow=!!h.castShadow,v.receiveShadow=!!h.receiveShadow,h.add(v);for(let p=1;p<c.levels.length;p++){let y=c.levels[p].ratio??c.ratios?.[p-1]??Math.max(.05,Math.pow(.5,p)),M=s(d,y),P=new g(M,h.material);P.name=`${b}_LOD${p}`,P.visible=!1,P.castShadow=!!h.castShadow,P.receiveShadow=!!h.receiveShadow,h.add(P)}h.geometry=new x,h.userData.xr.lod={...c,levels:c.levels.map((p,y)=>({...p,childIndex:y,node:`${b}_LOD${y}`}))}}let u={LOD:o,decimateGeometry:s,selectLodLevelIndex:i,parseLod:n,materializeLodGeometry:a};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:o,decimateGeometry:s}),t._lodMaterialize=a,t.materializeDeclarativeGeometry=h=>{t._cadMaterialize?.(h),t._lodMaterialize?.(h)}),u}var Jt=wr(),Fo=Jt.decimateGeometry,hi=Jt.selectLodLevelIndex,ci=Jt.parseLod,Eu=Jt.materializeLodGeometry,Vo=Jt.LOD,er=new WeakMap;function Uo(e){return e&&typeof e=="object"?er.get(e):void 0}var xn=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let n=t.get(i.nodeIndex);n||(n=[],t.set(i.nodeIndex,n)),n.push(i)}let r=i=>{let n=[],s=new Set,l=[i];for(;l.length>0;){let o=l.pop();if(s.has(o)||o<0||o>=e.length)continue;s.add(o);let a=t.get(o);a&&n.push(...a);let u=e[o]?.children;if(Array.isArray(u))for(let h=u.length-1;h>=0;h--)typeof u[h]=="number"&&l.push(u[h])}return n};for(let i=0;i<e.length;i++){let n=e[i];if(!n||typeof n!="object")continue;let s=n.extras?.xr?.lod??n.extensions?.ANDROID_xr_scenecore?.lod??n.extensions?.MOZ_hubs_components?.lod,l=Array.isArray(n.extensions?.MSFT_lod?.ids)?n.extensions.MSFT_lod.ids.filter(d=>typeof d=="number"&&Number.isInteger(d)&&d>=0&&d<e.length):[],o=ci(s);if(!o&&l.length>0&&(o=ci({distances:l.map((d,f)=>f*4)})),!o)continue;let a=l.length>0?l:Array.isArray(n.children)?n.children.filter(d=>typeof d=="number"&&Number.isInteger(d)&&d>=0&&d<e.length):[],u=[],h=[];if(a.length>0){let d=Math.min(a.length,o.levels.length);for(let f=0;f<d;f++){let g=a[f];u.push(g),h.push(r(g))}}else{let d=t.get(i)??[];if(d.length===0)continue;u.push(i),h.push(d)}let m=o.distances.slice(0,h.length);m.length===0&&m.push(0);let c={nodeIndex:i,name:typeof n.name=="string"?n.name:`LOD_${i}`,distances:m,hysteresis:o.hysteresis,...o.cullDistance!==void 0?{cullDistance:o.cullDistance}:{},childNodeIndices:u,levelMeshes:h,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(c,0),this.groups.push(c)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let n=hi(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=n,this.applyGroupVisibility(r,n);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let n=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,s=n&&n[12]||0,l=n&&n[13]||0,o=n&&n[14]||0,a=r?r[0]*s+r[4]*l+r[8]*o+r[12]:s,u=r?r[1]*s+r[5]*l+r[9]*o+r[13]:l,h=r?r[2]*s+r[6]*l+r[10]*o+r[14]:o,m=Math.hypot((e[0]||0)-a,(e[1]||0)-u,(e[2]||0)-h);if(i.lastDistance=m,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let c=hi(i.distances,m,i.activeLevelIndex,i.hysteresis,i.cullDistance);c!==i.activeLevelIndex&&(i.activeLevelIndex=c,this.applyGroupVisibility(i,c))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let n=i===t;for(let o of e.levelMeshes[i])o.visible=n;let s=e.childNodeIndices[i],l=Array.isArray(r)?r[s]:null;l&&typeof l=="object"&&(l.visible=n,l.extensions=l.extensions||{},l.extensions.KHR_node_visibility={visible:n})}}},vn={name:"lod",onRegister(){Jr(wr);let e=Ae(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);wr(t,e)},onLoadModel(e,t){!e||typeof e!="object"||er.set(e,new xn(e,t))},onUpdate(e){let t=er.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},n=r?.radius??3,s=r?.phi??0,l=r?.theta??0,o=Math.cos(s),a=(i.x||0)+n*o*Math.sin(l),u=(i.y||0)+n*Math.sin(s),h=(i.z||0)+n*o*Math.cos(l);t.update([a,u,h])},onBeforeDrawScene(e,t,r,i){let n=er.get(e);n&&n.update(i)},onDestroy(e,t){t&&typeof t=="object"&&er.delete(t)}},Oo={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function kt(e,t,r,i){if(!r||r.bufferView===void 0)return null;let n=e.bufferViews?.[r.bufferView];if(!n)return null;let s=Number(r.count??0);if(!Number.isInteger(s)||s<=0)return null;let l=r.componentType??5126,o=Oo[l];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let a=o*i,u=n.byteStride&&n.byteStride>0?n.byteStride:a,h=(n.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(h)||h<0||u<a||h+(s-1)*u+a>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(l===5126&&u===a&&h%4===0)return new Float32Array(t,h,s*i);let m=new DataView(t),c=r.normalized===!0,d=new Float32Array(s*i);for(let f=0;f<s;f++){let g=h+f*u;for(let x=0;x<i;x++){let b=g+x*o,v;switch(l){case 5126:v=m.getFloat32(b,!0);break;case 5120:v=m.getInt8(b),c&&(v=Math.max(v/127,-1));break;case 5121:v=m.getUint8(b),c&&(v/=255);break;case 5122:v=m.getInt16(b,!0),c&&(v=Math.max(v/32767,-1));break;case 5123:v=m.getUint16(b,!0),c&&(v/=65535);break;default:v=m.getUint32(b,!0),c&&(v/=4294967295)}d[f*i+x]=v}}return d}function Bo(e,t){let r=Number(t.offset?.[0]??0)||0,i=Number(t.offset?.[1]??0)||0,n=Number(t.scale?.[0]??1),s=Number(t.scale?.[1]??1),l=Number(t.rotation??0)||0,o=Math.cos(l),a=Math.sin(l),u=(Number.isFinite(n)?n:1)*o,h=(Number.isFinite(n)?n:1)*a,m=-(Number.isFinite(s)?s:1)*a,c=(Number.isFinite(s)?s:1)*o;for(let d=0;d+1<e.length;d+=2){let f=e[d],g=e[d+1];e[d]=u*f+h*g+r,e[d+1]=m*f+c*g+i}}function Ft(e,t,r,i=!0){let n=[],s=null;try{for(let[l,o]of[[35633,t],[35632,r]]){let a=e.createShader(l);if(!a){if(i)throw new Error("Shader allocation failed");return null}if(n.push(a),e.shaderSource(a,o),e.compileShader(a),e.getShaderParameter&&!e.getShaderParameter(a,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(a)}`);return null}}if(s=e.createProgram(),!s){if(i)throw new Error("Program allocation failed");return null}for(let l of n)e.attachShader(s,l);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let l=i?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,i)throw new Error(`Program link error: ${l}`);return null}return s}finally{for(let l of n)s&&e.detachShader?.(s,l),e.deleteShader?.(l)}}var Mn=["neutral","reinhard","none","aces","agx"];function Vt(e){let t=String(e??"").trim().toLowerCase();return Mn.includes(t)?t:"neutral"}function zo(e){return Mn.indexOf(Vt(e))}function $o(e){return new TextDecoder().decode(e)}var wn=Ae().decoders;function Ho(e,t){wn.set(e.toLowerCase(),t)}function Ut(e){return wn.get(e.toLowerCase())}function An(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,r=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let i=r.getUint32(0,!0);if(i!==1179937895){let c=r.getUint8(0);throw c===123||c===32||c===10||c===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${i.toString(16)}`)}let n=r.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=r.getUint32(8,!0),l=12,o=null,a=null;for(;l+8<=s&&l+8<=t.byteLength;){let c=r.getUint32(l,!0),d=r.getUint32(l+4,!0),f=l+8;if(f+c>t.byteLength)throw new Error(`Truncated GLB chunk: required ${f+c} bytes, buffer has ${t.byteLength}`);if(d===1313821514){let g=new Uint8Array(t,f,c),x=$o(g);o=JSON.parse(x,(b,v)=>b==="__proto__"||b==="constructor"||b==="prototype"?void 0:v)}else d===5130562&&(a=t.slice(f,f+c));l=f+c}if(!o)throw new Error("Missing JSON chunk in GLB");let u=o.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!Ut("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let c of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(c)&&!Ut("meshopt"))throw new Error(`Model requires ${c}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!Ut("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let h=a||new ArrayBuffer(0),m={gltf:o,bin:h,animations:[]};for(let c of Fe)c.onParseGLB?.(m);return m}function Wo(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function tr(e){if(Wo(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return An(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Tn=`#version 300 es
19
18
  layout(location=0) in vec3 aPos;
20
19
  layout(location=3) in vec3 aOff;
21
20
  layout(location=1) in vec3 aNormal;
@@ -50,7 +49,7 @@ vec2 scaleUV=uUvTransform.zw;
50
49
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
51
50
  vUV=aUV*scaleUV+uUvTransform.xy;
52
51
  gl_Position=uMVP*vec4(aPosition,1.0);
53
- }`,da=`#version 300 es
52
+ }`,Go=`#version 300 es
54
53
  precision highp float;
55
54
  in vec3 vNormal,vWorldPos;
56
55
  in vec2 vUV;
@@ -67,7 +66,8 @@ uniform float uNormalScale,uOcclusionStrength;
67
66
  uniform vec2 uViewportSize;
68
67
  uniform vec4 uSectionPlane;
69
68
  uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
70
- uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2];
69
+ uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
70
+ uniform vec2 uPointLightSpotCone[2];
71
71
  out vec4 fragColor;
72
72
 
73
73
  vec2 envBRDF(float r,float n){
@@ -158,6 +158,11 @@ if(mode==4)return agxToneMapping(color);
158
158
  return color;
159
159
  }
160
160
 
161
+ vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 base,float specExp,float specWeight){
162
+ float NoH=max(dot(N,normalize(L+V)),0.0);
163
+ return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
164
+ }
165
+
161
166
  void main(){
162
167
  if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
163
168
  vec4 base=uBaseColor;
@@ -195,24 +200,16 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
195
200
  vec3 directLight=vec3(0.0);
196
201
  for(int i=0;i<2;i++){
197
202
  if(i>=uNumDirLights)break;
198
- vec3 L=normalize(uDirLightDir[i]);
199
- float NdotL=max(dot(N,L),0.0);
200
- vec3 H=normalize(L+V);
201
- float NoH=max(dot(N,H),0.0);
202
- float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
203
- directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uDirLightColor[i];
203
+ directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i];
204
204
  }
205
205
  for(int i=0;i<2;i++){
206
206
  if(i>=uNumPointLights)break;
207
207
  vec3 toLight=uPointLightPos[i]-vWorldPos;
208
208
  float dist=length(toLight);
209
209
  vec3 L=toLight/max(dist,0.0001);
210
- float atten=1.0/(1.0+0.09*dist+0.032*dist*dist);
211
- float NdotL=max(dot(N,L),0.0);
212
- vec3 H=normalize(L+V);
213
- float NoH=max(dot(N,H),0.0);
214
- float spec=pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35;
215
- directLight+=(base.rgb*NdotL*0.75+vec3(spec))*uPointLightColor[i]*atten;
210
+ float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
211
+ spotAtt*=spotAtt;
212
+ directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist);
216
213
  }
217
214
 
218
215
  vec3 R=reflect(-V,N);
@@ -243,116 +240,170 @@ color=applyToneMapping(color,uToneMapping);
243
240
  float outAlpha=base.a;
244
241
  /*XRD_O*/
245
242
  fragColor=vec4(color,outAlpha);
246
- }`;function So(t,e,n=1){e=Ct(e);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),a=Math.max(0,(Number(t[2])||0)*r),u=v=>Math.max(0,Math.min(1,v));if(e==="none")return[u(i),u(o),u(a)];if(e==="reinhard")return[i/(i+1),o/(o+1),a/(a+1)];if(e==="aces"){let v=R=>{let b=R*.6;return u(b*(2.51*b+.03)/(b*(2.43*b+.59)+.14))};return[v(i),v(o),v(a)]}if(e==="agx"){let v=.84247906*i+.0784336*o+.07922375*a,R=.04232824*i+.87846864*o+.07916613*a,b=.04237565*i+.0784336*o+.87914297*a,w=g=>{let A=u((Math.log2(Math.max(g,1e-6))+12.47393)/16.5),N=A*A,_=N*N;return 15.5*_*N-40.14*_*A+31.96*_-6.868*N*A+.4298*N+.1191*A-.00232},M=w(v),P=w(R),k=w(b),I=1.196879*M-.09802088*P-.09902974*k,L=-.05289685*M+1.15190313*P-.09896118*k,x=-.05297164*M-.09804345*P+1.15107367*k;return[u(Math.pow(Math.max(I,0),2.2)),u(Math.pow(Math.max(L,0),2.2)),u(Math.max(0,Math.pow(Math.max(x,0),2.2)))]}let s=.76,c=.15,l=Math.min(i,o,a),m=l<.08?l-6.25*l*l:.04;i-=m,o-=m,a-=m;let f=Math.max(i,o,a);if(f<s)return[u(i),u(o),u(a)];let h=1-s,p=1-h*h/(f+h-s),d=p/f;i*=d,o*=d,a*=d;let y=1-1/(c*(f-p)+1);return[u(i+(p-i)*y),u(o+(p-o)*y),u(a+(p-a)*y)]}var ha=`#version 300 es
243
+ }`;function jo(e,t,r=1){t=Vt(t);let i=Number.isFinite(r)?Math.max(0,r):1,[n,s,l]=[0,1,2].map(g=>Math.max(0,(Number(e[g])||0)*i)),o=g=>Math.max(0,Math.min(1,g)),a=g=>[g(n),g(s),g(l)];if(t==="none")return a(o);if(t==="reinhard")return a(g=>g/(g+1));if(t==="aces")return a(g=>{let x=g*.6;return o(x*(2.51*x+.03)/(x*(2.43*x+.59)+.14))});if(t==="agx"){let[g,x,b]=[.84247906*n+.0784336*s+.07922375*l,.04232824*n+.87846864*s+.07916613*l,.04237565*n+.0784336*s+.87914297*l].map(v=>{let p=o((Math.log2(Math.max(v,1e-6))+12.47393)/16.5),y=p*p,M=y*y;return 15.5*M*y-40.14*M*p+31.96*M-6.868*y*p+.4298*y+.1191*p-.00232});return[1.196879*g-.09802088*x-.09902974*b,-.05289685*g+1.15190313*x-.09896118*b,-.05297164*g-.09804345*x+1.15107367*b].map(v=>o(Math.pow(Math.max(v,0),2.2)))}let u=Math.min(n,s,l),h=u<.08?u-6.25*u*u:.04;[n,s,l]=a(g=>g-h);let m=Math.max(n,s,l);if(m<.76)return a(o);let c=1-.0576/(m-.52),d=c/m,f=1-1/(.15*(m-c)+1);return a(g=>o(g*d+(c-g*d)*f))}var qo=`#version 300 es
247
244
  layout(location=0) in vec3 aPosition;
248
245
  uniform mat4 uMVP;
249
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,pa=`#version 300 es
246
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Xo=`#version 300 es
250
247
  precision highp float;
251
248
  uniform vec4 uColorId;
252
249
  out vec4 fragColor;
253
- void main(){fragColor=uColorId;}`;function Jr(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var xo=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Ro(){let t=ve().xrDepthShader;return{fs:da.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...xo,...t.uniformNames]:xo}}function ba(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 Zr(t,e,n,r,i,o,a,u){if(r===void 0||!e.accessors?.[r])return null;let s=ot(e,n,e.accessors[r],o);if(!s)return null;u&&(s=s.slice(),go(s,u));let c=t.createBuffer();return a.push(c),t.bindBuffer(34962,c),t.bufferData(34962,s,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),s}function Qr(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Eo(t,e,n){let r=Ro(),i=Ao,o=r.fs,a=!1;for(let s of De)if(s.onResolveShader){let c=s.onResolveShader(e,n,i,o);c&&(i=c.vs,o=c.fs,a=!0)}let u=a?St(t,i,o):null;return{program:u,uniforms:u?Jr(t,u,r.uniforms):null}}function ya(t,e,n){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=e.instanceColors,a=new Float32Array(i*20);for(let s=0;s<i;s++)a.set(r.subarray(s*16,s*16+16),s*20),a[s*20+16]=o?o[s*3]:1,a[s*20+17]=o?o[s*3+1]:1,a[s*20+18]=o?o[s*3+2]:1,a[s*20+19]=1;let u=t.createBuffer();n.push(u),t.bindBuffer(34962,u),t.bufferData(34962,a,35044);for(let s=0;s<5;s++)t.enableVertexAttribArray(8+s),t.vertexAttribPointer(8+s,4,5126,!1,80,s*16),t.vertexAttribDivisor(8+s,1);return!0}function ga(t,e){let n=t.materials?.[e?.material];if(!n)return null;let r=[n.pbrMetallicRoughness?.baseColorTexture,n.pbrMetallicRoughness?.metallicRoughnessTexture,n.normalTexture,n.occlusionTexture,n.emissiveTexture];for(let i of r){let o=i?.extensions?.KHR_texture_transform;if(o&&typeof o=="object")return o}return null}var _o=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Lo=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Gn(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Io(t,e){let n=t?.pbrMetallicRoughness,r=n?.baseColorFactor,i=t?.extensions?.KHR_materials_clearcoat,o=a=>a!==void 0&&e[a.index]?e[a.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:n?.metallicFactor??.1,roughness:n?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:o(n?.baseColorTexture),metallicRoughnessTexture:o(n?.metallicRoughnessTexture),normalTexture:o(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:o(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Co(t,e,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),t.deleteTexture(o))};for(let o of e)for(let a of o.primitives){if(a.vao&&t.deleteVertexArray(a.vao),a.buffers)for(let s of a.buffers)t.deleteBuffer(s);i(a.texture),i(a.metallicRoughnessTexture),i(a.normalTexture),i(a.occlusionTexture);let u=new Set;a.customProgram&&u.add(a.customProgram);for(let s of a.programCache?.values()??[])s.program&&u.add(s.program);for(let s of u)t.deleteProgram(s)}if(n)for(let o of n)i(o)}function vo(t,e,n=Lo,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return xa(t,e,n,r,i)}catch(o){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Co(t,a,i.gpuTextures),i.vao&&t.deleteVertexArray(i.vao);for(let u of i.buffers)t.deleteBuffer(u);throw o}}function xa(t,e,n,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=e,a=Kt("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(o,e);let u=e.bin,s=[];i.meshes=s;let c=[],l=o.extensions?.KHR_materials_variants;l&&Array.isArray(l.variants)&&l.variants.forEach((A,N)=>{c.push(typeof A?.name=="string"&&A.name?A.name:`Variant_${N}`)});let m=dt(o),f=[];if(Array.isArray(o.nodes))for(let A=0;A<o.nodes.length;A++){let N=o.nodes[A];N.mesh!==void 0&&o.meshes&&o.meshes[N.mesh]&&f.push({node:N,nodeIdx:A,meshIdx:N.mesh})}let h=f.length>0?f:(o.meshes||[]).map((A,N)=>({node:A,nodeIdx:-1,meshIdx:N})),p=[];if(Array.isArray(e.lights)&&e.lights.length>0)p.push(...e.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let A=o.extensions.KHR_lights_punctual.lights;for(let N of A){let _=N.type==="directional"?"directional":N.type==="point"?"point":"ambient";p.push({type:_,color:N.color||[1,1,1],intensity:N.intensity!==void 0?N.intensity:1})}}if(p.length===0&&(p.push({type:"ambient",color:[1,1,1],intensity:.35}),p.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),h.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${h.length}`);let d=[];if(i.gpuTextures=d,o.textures&&o.images){if(o.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${o.textures.length}`);for(let A=0;A<o.textures.length;A++){let N=o.textures[A],_=o.images[N.source];if(_){let O=t.createTexture();if(t.bindTexture(3553,O),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 Q=o.bufferViews[_.bufferView],q=u.slice(Q.byteOffset||0,(Q.byteOffset||0)+Q.byteLength),oe=new Blob([q],{type:_.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(oe).then(ne=>{t.bindTexture(3553,O),t.texImage2D(3553,0,6408,6408,5121,ne),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let Q=ba(_.uri);if(Q){let q=new Image;q.crossOrigin="anonymous",q.referrerPolicy="no-referrer",q.onload=()=>{t.bindTexture(3553,O),t.texImage2D(3553,0,6408,6408,5121,q),t.generateMipmap(3553),r?.()},q.src=Q}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}d.push(O)}else d.push(null)}}let y=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],R=0,b=0;for(let A=0;A<h.length;A++){let N=h[A],_=o.meshes[N.meshIdx],O=N.nodeIdx>=0?m[N.nodeIdx]:we(),Q=new Float32Array(9);Ne(Q,O);let q={name:N.node.name||_.name||`Mesh_${N.meshIdx}`,nodeIndex:N.nodeIdx,transform:O,normalMatrix:Q,primitives:[],extras:N.node.extras||_.extras};i.mesh=q;let oe=N.node?.extensions?.EXT_mesh_gpu_instancing;if(oe&&oe.attributes&&typeof oe.attributes=="object"){let ne=oe.attributes,re=ne.TRANSLATION!==void 0?o.accessors?.[ne.TRANSLATION]:null,H=ne.ROTATION!==void 0?o.accessors?.[ne.ROTATION]:null,se=ne.SCALE!==void 0?o.accessors?.[ne.SCALE]:null,ae=ne._COLOR_0!==void 0?o.accessors?.[ne._COLOR_0]:null,D=Number(re?.count??H?.count??se?.count??0);if(!Number.isFinite(D)||D<0||D>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${D}`);if(D>0){let G=(ie,he)=>{if(!ie||ie.bufferView===void 0||!o.bufferViews?.[ie.bufferView])return null;let T=ie.componentType??5126,S=B=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${B})`),null);if(T!==5120&&T!==5121&&T!==5122&&T!==5123&&T!==5126)return S(`componentType ${T}`);if(!(Number(ie.count)>=D))return S(`count ${ie.count} < ${D}`);let C=null;try{C=ot(o,u,{...ie,count:D},he)}catch{return S("out of bounds")}return!C||!C.every(Number.isFinite)?S("non-finite value"):C},E=G(re,3),V=G(H,4),F=G(se,3),U=ae?.type==="VEC4"?4:3,z=G(ae,U),Y=new Float32Array(D*16),le=we();for(let ie=0;ie<D;ie++){let he=E?[E[ie*3],E[ie*3+1],E[ie*3+2]]:[0,0,0],T=V?[V[ie*4],V[ie*4+1],V[ie*4+2],V[ie*4+3]]:[0,0,0,1],S=F?[F[ie*3],F[ie*3+1],F[ie*3+2]]:[1,1,1];Je(le,T,he,S),Y.set(le,ie*16)}if(q.instanceMatrices=Y,z){let ie=new Float32Array(D*3);for(let he=0;he<D;he++)ie[he*3]=z[he*U],ie[he*3+1]=z[he*U+1],ie[he*3+2]=z[he*U+2];q.instanceColors=ie}}}for(let ne of _.primitives||[]){if(ne.extensions?.KHR_draco_mesh_compression){let C=Kt("draco");C&&C.decodePrimitive(o,ne,u)}let re=[],H=t.createVertexArray();i.vao=H,i.buffers=re,t.bindVertexArray(H);let se=ya(t,q,re),ae=o.accessors[ne.attributes.POSITION],D=Number(ae?.count??0);if(!Number.isFinite(D)||D<0||R+D>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(R+=D,ae?.min&&ae?.max){let C=B=>{for(let X=0;X<3;X++){let W=B[12+X],$=B[12+X];for(let K=0;K<3;K++){let Z=B[K*4+X]*ae.min[K],j=B[K*4+X]*ae.max[K];W+=Z<j?Z:j,$+=Z>j?Z:j}W<y[X]&&(y[X]=W),$>v[X]&&(v[X]=$)}};if(q.instanceMatrices&&q.instanceMatrices.length>=16){let B=q.instanceMatrices.length>>4,X=we();for(let W=0;W<B;W++){let $=q.instanceMatrices.subarray(W*16,W*16+16);Le(X,O,$),C(X)}}else C(O)}let G=Zr(t,o,u,ne.attributes.POSITION,0,3,re);Zr(t,o,u,ne.attributes.NORMAL,1,3,re),Zr(t,o,u,ne.attributes.TEXCOORD_0,2,2,re,ga(o,ne));let E=0,V=5123,F=null;if(ne.indices!==void 0){let C=o.accessors[ne.indices],X=(o.bufferViews[C.bufferView].byteOffset||0)+(C.byteOffset||0);if(E=Number(C.count??0),!Number.isFinite(E)||E<0||b+E>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);b+=E,V=C.componentType===5125?5125||5125:5123||5123;let W=t.createBuffer();re.push(W),t.bindBuffer(34963,W),C.componentType===5125?(F=new Uint32Array(u,X,C.count),t.bufferData(34963,F,35044)):C.componentType===5121?(F=Uint16Array.from(new Uint8Array(u,X,C.count)),t.bufferData(34963,F,35044)):(F=X%2===0?new Uint16Array(u,X,C.count):new Uint16Array(u.slice(X,X+C.count*2)),t.bufferData(34963,F,35044))}else E=ae.count;let U={};for(let C of De)if(C.onBuildPrimitiveVAO){let B=C.onBuildPrimitiveVAO(t,H,ne,o,u);B&&(U[C.name]=B)}t.bindVertexArray(null);let z=o.materials&&ne.material!==void 0?o.materials[ne.material]:null,{program:Y,uniforms:le}=Eo(t,ne,z),ie=Io(z,d),he=!!(z?.extensions?.KHR_materials_transmission||U.materials?.isTransmissive),T=ne.extensions?.KHR_materials_variants?.mappings,S=Array.isArray(T)?T.filter(C=>C&&typeof C.material=="number"&&Array.isArray(C.variants)).map(C=>({material:C.material|0,variants:C.variants.map(B=>Number(B)|0)})):void 0;q.primitives.push({vao:H,instanced:se,indexCount:E,indexType:V,...ie,positions:G,indices:F,buffers:re,materialIndex:ne.material,defaultMaterialIndex:ne.material,variantMappings:S,primitiveDef:ne,programCache:new Map([[ne.material??-1,{program:Y,uniforms:le}]]),pluginData:U,customProgram:Y,customUniforms:le,isTransmissive:he})}s.push(q)}isFinite(y[0])||(y=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let w=[(y[0]+v[0])/2,(y[1]+v[1])/2,(y[2]+v[2])/2],M=v[0]-y[0],P=v[1]-y[1],k=v[2]-y[2],I=Math.max(Math.hypot(M,P,k)/2,.5),L=[y[0],y[1],y[2]],x=[v[0],v[1],v[2]],g=e.animations;if(!g){for(let A of De)if(A.onParseGLB?.(e),e.animations){g=e.animations;break}}return g||(g=[]),{meshes:s,bounds:{center:w,radius:I,min:L,max:x},lights:p,animations:g,worldMatrices:m,gpuTextures:d,availableVariants:c}}function sn(t){let e=t.customTarget||t.bounds.center,n=t.currDistance*Math.cos(t.currPhi);return[e[0]+n*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+n*Math.cos(t.currTheta)]}var He=class{constructor(e,n,r){this.supportsInstanceOffsets=!0;this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=we();this.clearColor=[0,0,0,0];this.envIntensity=1;this.exposure=1;this.shadowIntensity=0;this.shadowSoftness=.5;this.toneMapping="neutral";this.environmentTexture=null;this.animations=[];this.currentClip=null;this.animationTime=0;this.isPlayingAnimation=!1;this.autoplay=!1;this.animationName="";this.gpuTextures=[];this.availableVariants=[];this.activeVariantName=null;this.gltf=null;this.worldMatrices=[];this.initialNodeTransforms=[];this.projMatrix=we();this.viewMatrix=we();this.activeViewMatrix=null;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.contextLost=!1;this.lastGlbData=null;this.boundContextLost=null;this.boundContextRestored=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 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.exposure=Qr(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=Ct(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 u=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!u)throw new Error("WebGL2 not supported");this.gl=u,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){fa(e,n)}static getDecoder(e){return Kt(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=n=>{n.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,n=Ro();this.renderProg=St(e,Ao,n.fs),this.pickProg=St(e,ha,pa),this.uRender=Jr(e,this.renderProg,n.uniforms),this.uPick=Jr(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let n of De)n.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let 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){this.lastGlbData=e,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:a,worldMatrices:u,gpuTextures:s,availableVariants:c}=vo(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=u||[],this.gpuTextures=s||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of De)f.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.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=Qr(l));let m=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;m!==void 0&&(this.envIntensity=Math.max(0,Number(m)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Mo(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(ht(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=ht(e),{meshes:i}=vo(this.gl,r,Lo,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],Ne(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),Ne(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],a=[],u=[];for(let s of this.lights){let c=s.color||[1,1,1],l=s.intensity!==void 0?s.intensity:1;if(s.type==="ambient")r=[c[0]*l,c[1]*l,c[2]*l];else if(s.type==="directional"&&i.length<6){let m=s.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(c[0]*l,c[1]*l,c[2]*l)}else if(s.type==="point"&&a.length<6){let m=s.position||[0,0,0];a.push(m[0],m[1],m[2]),u.push(c[0]*l,c[1]*l,c[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,a.length/3),a.length>0&&(n.uniform3fv(e.uPointLightPos,a),n.uniform3fv(e.uPointLightColor,u)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Qr(e)}getExposure(){return this.exposure}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=Ct(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of De)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of De)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],a=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],u=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,s=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:u,roughnessFactor:s,setBaseColorFactor:l=>{let m=[l[0],l[1],l[2],l[3]??1];c.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let f of i)f.baseColor=m;this.render()},setMetallicFactor:l=>{c.metallicFactor=l,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=l);for(let m of i)m.metallic=l;this.render()},setRoughnessFactor:l=>{c.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:c}})}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==="",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 a of o.primitives){let u=a.defaultMaterialIndex;if(!n&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){u=c.material;break}}let s=u!==void 0?i[u]:void 0;a.materialIndex=s?u:void 0,Object.assign(a,Io(s,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,s??null)}return!0}applyPrimitiveProgram(e,n,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=n??-1,o=e.programCache.get(i);o||(o=Eo(this.gl,{...e.primitiveDef,material:n},r),e.programCache.set(i,o)),e.customProgram=o.program,e.customUniforms=o.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of De)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();Le(r,this.projMatrix,this.viewMatrix);let[i,o,a]=e,u=n?n[0]:0,s=n?n[1]:0,c=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],a=l[2]*e[0]+l[6]*e[1]+l[10]*e[2]+l[14],n&&(u=l[0]*n[0]+l[4]*n[1]+l[8]*n[2],s=l[1]*n[0]+l[5]*n[1]+l[9]*n[2],c=l[2]*n[0]+l[6]*n[1]+l[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*a+r[12],f=r[1]*i+r[5]*o+r[9]*a+r[13],h=r[2]*i+r[6]*o+r[10]*a+r[14],p=r[3]*i+r[7]*o+r[11]*a+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let d=m/p,y=f/p,v=h/p,R=this.canvas.getBoundingClientRect(),b=R.width||this.canvas.clientWidth||this.canvas.width||300,w=R.height||this.canvas.clientHeight||this.canvas.height||150,M=(d*.5+.5)*b,P=(-y*.5+.5)*w,k=d>=-1.1&&d<=1.1&&y>=-1.1&&y<=1.1&&v>=-1&&v<=1;if(k&&n){let[I,L,x]=sn(this),g=[i-I,o-L,a-x];u*g[0]+s*g[1]+c*g[2]>.05&&(k=!1)}return{x:M,y:P,z:v,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 a=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],u=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],s=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;s[0]+=(-i*a[0]+o*u[0])*c,s[1]+=(-i*a[1]+o*u[1])*c,s[2]+=(-i*a[2]+o*u[2])*c,this.customTarget=s}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.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),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,u=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),s=i.height>0?Math.floor((n-i.top)*(a/i.height)):Math.floor(n);return this.performMeshPick(u,s,!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 u=we();Le(u,this.projMatrix,this.viewMatrix);let s=[],c=Math.max(0,Math.min(o-1,e)),l=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 k=0;k<this.meshes.length;k++){let I=this.meshes[k];if(I.visible===!1||I.isPluginMesh)continue;let L=k+1,x=(L&255)/255,g=(L>>8&255)/255,A=(L>>16&255)/255;i.uniform4f(this.uPick.uColorId,x,g,A,1),Le(this.modelMatrix,this.modelRootMatrix,I.transform);let N=I.instanceMatrices;if(N&&N.length>=16){let _=N.length>>4,O=we();for(let Q of I.primitives){i.bindVertexArray(Q.vao);for(let q=0;q<_;q++)Le(O,this.modelMatrix,N.subarray(q*16,q*16+16)),Le(this.mvpMatrix,u,O),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Gn(i,Q)}}else{Le(this.mvpMatrix,u,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let _ of I.primitives)i.bindVertexArray(_.vao),Gn(i,_)}}let M=new Uint8Array(4);i.readPixels(c,l,1,1,6408,5121,M),i.bindFramebuffer(36160,null);let P=M[0]+(M[1]<<8)+(M[2]<<16);P>0&&P<=this.meshes.length&&(s=[this.meshes[P-1]])}s.length===0&&(s=this.meshes.filter(M=>M.visible!==!1));let m=null,f=1/0,h=[0,0,0],p=[0,1,0],[d,y,v]=sn(this),R=we();for(let M of s){Le(R,this.modelRootMatrix,M.transform);let P=M.instanceMatrices,k=P&&P.length>=16?P.length>>4:1;for(let I=0;I<k;I++){P&&P.length>=16?Le(this.modelMatrix,R,P.subarray(I*16,I*16+16)):this.modelMatrix.set(R),Le(this.mvpMatrix,u,this.modelMatrix);let L=we();if(!jt(L,this.mvpMatrix))continue;let x=(c+.5)/o*2-1,g=(l+.5)/a*2-1,A=[0,0,0],N=[0,0,0];zr(A,x,g,-1,L),zr(N,x,g,1,L);let _=N[0]-A[0],O=N[1]-A[1],Q=N[2]-A[2],q=Math.hypot(_,O,Q)||1,oe=_/q,ne=O/q,re=Q/q,H={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((ae=>{for(let D of M.primitives){if(!D.positions)continue;let G=D.positions,E=D.indices,V=Math.floor(E?E.length/3:G.length/9);for(let F=0;F<V;F++){let U=E?E[F*3]:F*3,z=E?E[F*3+1]:F*3+1,Y=E?E[F*3+2]:F*3+2;fo(A[0],A[1],A[2],oe,ne,re,G[U*3],G[U*3+1],G[U*3+2],G[z*3],G[z*3+1],G[z*3+2],G[Y*3],G[Y*3+1],G[Y*3+2],H,ae)}}})(1e-4),isFinite(H.distance)){let ae=H.point[0],D=H.point[1],G=H.point[2],E=this.modelMatrix,V=E[0]*ae+E[4]*D+E[8]*G+E[12],F=E[1]*ae+E[5]*D+E[9]*G+E[13],U=E[2]*ae+E[6]*D+E[10]*G+E[14],z=V-d,Y=F-y,le=U-v,ie=Math.hypot(z,Y,le);if(ie<f){Ne(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,T=H.normal[0],S=H.normal[1],C=H.normal[2],B=he[0]*T+he[3]*S+he[6]*C,X=he[1]*T+he[4]*S+he[7]*C,W=he[2]*T+he[5]*S+he[8]*C,$=Math.hypot(B,X,W)||1;B/=$,X/=$,W/=$,B*z+X*Y+W*le>0&&(B=-B,X=-X,W=-W),m=M,f=Math.round(ie*1e3)/1e3,h=[Math.round(V*1e3)/1e3,Math.round(F*1e3)/1e3,Math.round(U*1e3)/1e3],p=[Math.round(B*1e3)/1e3,Math.round(X*1e3)/1e3,Math.round(W*1e3)/1e3]}}}}if(!m)return null;let w={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:f,hitPoint:h,normal:p,screenX:e,screenY:n};if(r){for(let M of De)M.onMeshSelect?.(this,w);this.opts.onMeshClick&&this.opts.onMeshClick(w),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:w}))}return w}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,u=(o+.5)/a*2-1;return Math.floor((u*.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);Vn(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center;$t(this.viewMatrix,sn(this),r,[0,1,0]),Le(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ne(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 De)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 De)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 De)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 De)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 u=e?.transform?.inverse?.matrix||this.viewMatrix,s=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,l=c?[c.x,c.y,c.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:u,projMatrix:s,eyePos:l,viewport:i,eye:e?.eye||"none",clear:a>0?!1:e?.eye!=="right",isAR:o})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let b=Math.max(2,this.canvas.width||2),w=Math.max(1,this.canvas.height||1),M=Math.max(1,Math.floor(b*.5)),P=Math.max(1,b-M),k=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),I=this.customTarget||this.bounds.center,[L,x,g]=sn(this),A=Math.cos(this.currTheta),N=-Math.sin(this.currTheta),_=.032,O=we(),Q=we(),q=[L-A*_,x,g-N*_],oe=[I[0]-A*_*.25,I[1],I[2]-N*_*.25];Vn(O,this.fov,M/w,.1,k),$t(Q,q,oe,[0,1,0]);let ne=we(),re=we(),H=[L+A*_,x,g+N*_],se=[I[0]+A*_*.25,I[1],I[2]+N*_*.25];Vn(ne,this.fov,P/w,.1,k),$t(re,H,se,[0,1,0]),this.render({viewMatrix:Q,projMatrix:O,eyePos:q,viewport:[0,0,M,w],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:re,projMatrix:ne,eyePos:H,viewport:[M,0,P,w],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,b,w);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 u=we(),s=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=s,Le(u,e?.projMatrix??this.projMatrix,s);let c=ve().xrDepthShader,l=ua(this.toneMapping),[m,f,h]=e?e.eyePos:sn(this);for(let b of De)b.onBeforeDrawScene?.(this,n,u,[m,f,h],l);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let d=e?.eye||"none",y=!1,v=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,R=b=>{for(let w=0;w<v.length;w++){let M=v[w];if(M.visible===!1)continue;let P=this.selectedMeshName!==""&&M.name===this.selectedMeshName;w<p||M.worldSpace===!0||M.name==="__xr_reticle__"?this.modelMatrix.set(M.transform):Le(this.modelMatrix,this.modelRootMatrix,M.transform),Le(this.mvpMatrix,u,this.modelMatrix),Ne(M.normalMatrix,this.modelMatrix);let k=M.extras?.xr?.stereo||M.userData?.xr?.stereo,I=0,L=0,x=1,g=1;k==="sbs"?(x=.5,I=d==="right"?.5:0):k==="ou"&&(g=.5,L=d==="right"?.5:0);for(let A of M.primitives){let N=!!A.isTransmissive;if(!b&&N){y=!0;continue}if(b&&!N)continue;let _=A.customProgram||this.renderProg,O=A.customUniforms||this.uRender;n.useProgram(_),n.vertexAttrib3f(3,0,0,0),O.uInstanced&&n.uniform1i(O.uInstanced,0),n.uniform1i(O.uToneMapping,l),n.uniform1f(O.uEnvIntensity,this.envIntensity),O.uExposure&&n.uniform1f(O.uExposure,this.exposure),n.uniform3f(O.uCameraPos,m,f,h),n.uniform1f(O.uEmissive,P?1:0),n.uniformMatrix4fv(O.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(O.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(O.uNormalMatrix,!1,M.normalMatrix),O.uUvTransform&&n.uniform4f(O.uUvTransform,I,L,x,g),O.uViewportSize&&n.uniform2f(O.uViewportSize,Math.max(1,o),Math.max(1,a)),c?.bind(n,O,this.xrDepthState,s,[r,i,Math.max(1,o),Math.max(1,a)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(O.uEnvironmentMap,4),n.uniform1i(O.uHasEnvironmentMap,1)):n.uniform1i(O.uHasEnvironmentMap,0),this.bindLights(O),O.uSectionEnabled&&n.uniform1i(O.uSectionEnabled,0);for(let q of De)q.onBeforeDrawPrimitive?.(n,_,A,M,this.worldMatrices||[],this.gltf);n.uniform4fv(O.uBaseColor,A.baseColor),n.uniform1f(O.uMetallic,A.metallic),n.uniform1f(O.uRoughness,A.roughness),O.uClearcoat&&n.uniform2f(O.uClearcoat,A.clearcoat??0,A.clearcoatRoughness??.04),A.texture?(n.activeTexture(33984),n.bindTexture(3553,A.texture),n.uniform1i(O.uBaseColorTexture,0),n.uniform1i(O.uHasTexture,1)):n.uniform1i(O.uHasTexture,0),A.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,A.metallicRoughnessTexture),n.uniform1i(O.uMetallicRoughnessTexture,1),n.uniform1i(O.uHasMetallicRoughnessTexture,1)):n.uniform1i(O.uHasMetallicRoughnessTexture,0),A.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,A.normalTexture),n.uniform1i(O.uNormalTexture,2),n.uniform1i(O.uHasNormalTexture,1),n.uniform1f(O.uNormalScale,A.normalScale)):n.uniform1i(O.uHasNormalTexture,0),A.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,A.occlusionTexture),n.uniform1i(O.uOcclusionTexture,3),n.uniform1i(O.uHasOcclusionTexture,1),n.uniform1f(O.uOcclusionStrength,A.occlusionStrength)):n.uniform1i(O.uHasOcclusionTexture,0),n.bindVertexArray(A.vao);let Q=M.instanceMatrices;if(A.instanceCount!==void 0)n.drawElementsInstanced(4,A.indexCount,A.indexType,0,A.instanceCount);else if(Q&&Q.length>=16&&A.instanced&&O.uInstanced&&O.uViewProj){let q=Q.length>>4;n.uniform1i(O.uInstanced,1),n.uniformMatrix4fv(O.uViewProj,!1,u),A.indices?n.drawElementsInstanced(4,A.indexCount,A.indexType,0,q):n.drawArraysInstanced(4,0,A.indexCount,q),n.uniform1i(O.uInstanced,0)}else if(Q&&Q.length>=16){let q=Q.length>>4,oe=M.instanceColors,ne=we(),re=new Float32Array(9),H=[A.baseColor[0],A.baseColor[1],A.baseColor[2],A.baseColor[3]];for(let se=0;se<q;se++)Le(ne,this.modelMatrix,Q.subarray(se*16,se*16+16)),Le(this.mvpMatrix,u,ne),Ne(re,ne),n.uniformMatrix4fv(O.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(O.uModel,!1,ne),n.uniformMatrix3fv(O.uNormalMatrix,!1,re),oe&&(H[0]=A.baseColor[0]*oe[se*3],H[1]=A.baseColor[1]*oe[se*3+1],H[2]=A.baseColor[2]*oe[se*3+2],H[3]=A.baseColor[3],n.uniform4fv(O.uBaseColor,H)),Gn(n,A)}else Gn(n,A)}}};if(R(!1),y){for(let b of De)b.onBeforeTransmissivePass?.(n,this);R(!0)}for(let b of De)b.onAfterRender?.(n,this,u,e?.eye??"none",[r,i,o,a],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,n){Co(this.gl,e,n)}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 De)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()}};He.registerPlugin=Oe,He.getRegisteredPlugins=On;function va(t){return t+3&-4}function Ta(t,e=0){let n=(H,se)=>typeof H=="number"&&Number.isFinite(H)?H:se,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),a=n(t[e+0],1),u=n(t[e+1],0),s=n(t[e+2],0),c=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),p=n(t[e+10],1),d=Math.hypot(a,u,s),y=Math.hypot(c,l,m),v=Math.hypot(f,h,p);a*(l*p-h*m)-c*(u*p-h*s)+f*(u*m-l*s)<0&&(d=-d);let b=Math.abs(d)>1e-8?1/d:0,w=Math.abs(y)>1e-8?1/y:0,M=Math.abs(v)>1e-8?1/v:0,P=a*b,k=u*b,I=s*b,L=c*w,x=l*w,g=m*w,A=f*M,N=h*M,_=p*M,O=P+x+_,Q=0,q=0,oe=0,ne=1;if(O>0){let H=.5/Math.sqrt(O+1);ne=.25/H,Q=(g-N)*H,q=(A-I)*H,oe=(k-L)*H}else if(P>x&&P>_){let H=2*Math.sqrt(Math.max(0,1+P-x-_));H>1e-8&&(ne=(g-N)/H,Q=.25*H,q=(L+k)/H,oe=(A+I)/H)}else if(x>_){let H=2*Math.sqrt(Math.max(0,1+x-P-_));H>1e-8&&(ne=(A-I)/H,Q=(L+k)/H,q=.25*H,oe=(g+N)/H)}else{let H=2*Math.sqrt(Math.max(0,1+_-P-x));H>1e-8&&(ne=(k-L)/H,Q=(A+I)/H,q=(g+N)/H,oe=.25*H)}let re=Math.hypot(Q,q,oe,ne);return re>1e-8&&Number.isFinite(re)?(Q/=re,q/=re,oe/=re,ne/=re):(Q=0,q=0,oe=0,ne=1),{t:[r,i,o],r:[Q,q,oe,ne],s:[d,y,v]}}function wa(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 Yt(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],a=[],u=[],s=new Set,c=[],l=[],m=new Map,f=[],h=[];function p(L){let x=m.get(L);if(x!==void 0)return x;x=l.length,m.set(L,x);let g=L,A=g.color?.r??.8,N=g.color?.g??.8,_=g.color?.b??.8,O=g.opacity??1,Q={name:g.name||"",pbrMetallicRoughness:{baseColorFactor:[A,N,_,O],metallicFactor:g.metalness??.1,roughnessFactor:g.roughness??.5},doubleSided:g.side===2||!!g.doubleSided};if(g.emissive&&(g.emissive.r>0||g.emissive.g>0||g.emissive.b>0)){let oe=g.emissiveIntensity??1;Q.emissiveFactor=[g.emissive.r*oe,g.emissive.g*oe,g.emissive.b*oe]}let q={};return g.clearcoat&&g.clearcoat>0&&(q.KHR_materials_clearcoat={clearcoatFactor:g.clearcoat,clearcoatRoughnessFactor:g.clearcoatRoughness||0}),g.sheen&&g.sheen>0&&(q.KHR_materials_sheen={sheenColorFactor:g.sheenColor?[g.sheenColor.r,g.sheenColor.g,g.sheenColor.b]:[1,1,1],sheenRoughnessFactor:g.sheenRoughness||0}),g.transmission&&g.transmission>0&&(q.KHR_materials_transmission={transmissionFactor:g.transmission}),g.thickness&&g.thickness>0&&(q.KHR_materials_volume={thicknessFactor:g.thickness,attenuationDistance:g.attenuationDistance??1/0,attenuationColor:g.attenuationColor?[g.attenuationColor.r,g.attenuationColor.g,g.attenuationColor.b]:[1,1,1]}),g.ior!==void 0&&g.ior!==1.5&&(q.KHR_materials_ior={ior:g.ior}),g.dispersion&&g.dispersion>0&&(q.KHR_materials_dispersion={dispersion:g.dispersion}),g.iridescence&&g.iridescence>0&&(q.KHR_materials_iridescence={iridescenceFactor:g.iridescence,iridescenceIor:g.iridescenceIOR??1.3}),Object.keys(q).length>0&&(Q.extensions=q),l.push(Q),x}function d(L,x){let g=new Uint8Array(L.buffer,L.byteOffset,L.byteLength),A=va(g.byteLength),N=new Uint8Array(A);N.set(g),n.push(N);let _=i.length;return i.push({buffer:0,byteOffset:r,byteLength:g.byteLength,target:x}),r+=A,_}function y(L,x,g,A,N,_,O){let Q=d(L,g),q=o.length,oe={bufferView:Q,byteOffset:0,componentType:A,count:N,type:x};return _&&(oe.min=_),O&&(oe.max=O),o.push(oe),q}t.traverse(L=>{(L.isLight||L.color&&L.intensity!==void 0)&&h.push({type:L.type,color:[L.color.r,L.color.g,L.color.b],intensity:L.intensity,position:[L.position.x,L.position.y,L.position.z]})});let v=[];function R(L){let x={name:L.name||""},g=L.position,A=L.quaternion,N=L.scale;if((g.x||g.y||g.z)&&(x.translation=[g.x,g.y,g.z]),(A.x||A.y||A.z||A.w!==1)&&(x.rotation=[A.x,A.y,A.z,A.w]),(N.x!==1||N.y!==1||N.z!==1)&&(x.scale=[N.x,N.y,N.z]),L.userData&&Object.keys(L.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(L.userData,(O,Q)=>{if(!(O==="__proto__"||O==="prototype"||O==="constructor"))return typeof Q=="function"?void 0:Q})),L.userData.xr)){let O=wa(L.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:O,ANDROID_xr_scenecore:O},ve().xrTraitSerializer?.gltfNode(x,L.userData.xr),s.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(L.geometry){let O=L.geometry,Q=O.attributes.position;if(Q&&Q.count>0){let q=[1/0,1/0,1/0],oe=[-1/0,-1/0,-1/0];for(let D=0;D<Q.count;D++){let G=Q.getX(D),E=Q.getY(D),V=Q.getZ(D);G<q[0]&&(q[0]=G),G>oe[0]&&(oe[0]=G),E<q[1]&&(q[1]=E),E>oe[1]&&(oe[1]=E),V<q[2]&&(q[2]=V),V>oe[2]&&(oe[2]=V)}let re={attributes:{POSITION:y(Q.array,"VEC3",34962,5126,Q.count,q,oe)}};if(O.attributes.normal&&(re.attributes.NORMAL=y(O.attributes.normal.array,"VEC3",34962,5126,O.attributes.normal.count)),O.attributes.uv&&(re.attributes.TEXCOORD_0=y(O.attributes.uv.array,"VEC2",34962,5126,O.attributes.uv.count)),O.index){let D=O.index.array instanceof Uint32Array;re.indices=y(O.index.array,"SCALAR",34963,D?5125:5123,O.index.count)}L.material&&(re.material=p(L.material));let H=L.userData?.variants;if(H&&typeof H=="object"){let D=new Map;for(let G of Object.keys(H)){if(!G||G==="__proto__"||G==="constructor"||G==="prototype")continue;let E=H[G];if(!E||typeof E!="object")continue;let V=f.indexOf(G);if(V===-1&&f.length<256&&(V=f.length,f.push(G)),V===-1)continue;let F=p(E),U=D.get(F);U||(U=[],D.set(F,U)),U.push(V)}if(D.size>0){let G=[];for(let[E,V]of D.entries())G.push({material:E,variants:V});re.extensions={...re.extensions||{},KHR_materials_variants:{mappings:G}},s.add("KHR_materials_variants")}}let se=L;if(se.isInstancedMesh&&typeof se.count=="number"&&se.count>0&&se.instanceMatrix?.array){let D=Math.min(1e4,Math.floor(se.count)),G=se.instanceMatrix.array,E=new Float32Array(D*3),V=new Float32Array(D*4),F=new Float32Array(D*3);for(let z=0;z<D;z++){let{t:Y,r:le,s:ie}=Ta(G,z*16);E[z*3]=Y[0],E[z*3+1]=Y[1],E[z*3+2]=Y[2],V[z*4]=le[0],V[z*4+1]=le[1],V[z*4+2]=le[2],V[z*4+3]=le[3],F[z*3]=ie[0],F[z*3+1]=ie[1],F[z*3+2]=ie[2]}let U={TRANSLATION:y(E,"VEC3",0,5126,D),ROTATION:y(V,"VEC4",0,5126,D),SCALE:y(F,"VEC3",0,5126,D)};if(se.instanceColor?.array&&se.instanceColor.array.length>=D*3){let z=new Float32Array(se.instanceColor.array.subarray(0,D*3));U._COLOR_0=y(z,"VEC3",0,5126,D)}x.extensions={...x.extensions||{},EXT_mesh_gpu_instancing:{attributes:U}},s.add("EXT_mesh_gpu_instancing")}let ae=a.length;a.push({primitives:[re],name:L.name,...x.extras?{extras:x.extras}:{}}),x.mesh=ae}}let _=u.length;if(u.push(x),c.push(L),L.children.length>0){x.children=[];for(let O of L.children)x.children.push(R(O))}return _}for(let L of t.children)v.push(R(L));let b=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),w=[];if(typeof b=="function"&&c.length>0){let L=e?.duration??4,x=e?.fps??15,g=Math.max(2,Math.round(L*x)+1),A=new Float32Array(g),N=c.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})),_=c.map(()=>new Float32Array(g*3)),O=c.map(()=>new Float32Array(g*4)),Q=c.map(()=>new Float32Array(g*3));for(let H=0;H<g;H++){let se=H/(g-1)*L;A[H]=se;try{b(se)}catch{}for(let ae=0;ae<c.length;ae++){let D=c[ae];_[ae][H*3]=D.position.x,_[ae][H*3+1]=D.position.y,_[ae][H*3+2]=D.position.z,O[ae][H*4]=D.quaternion.x,O[ae][H*4+1]=D.quaternion.y,O[ae][H*4+2]=D.quaternion.z,O[ae][H*4+3]=D.quaternion.w,Q[ae][H*3]=D.scale.x,Q[ae][H*3+1]=D.scale.y,Q[ae][H*3+2]=D.scale.z}}for(let H=0;H<c.length;H++){let se=c[H],ae=N[H];se.position.set(ae.px,ae.py,ae.pz),se.quaternion.set(ae.qx,ae.qy,ae.qz,ae.qw),se.scale.set(ae.sx,ae.sy,ae.sz)}t.updateMatrixWorld(!0);let q=null,oe=()=>(q===null&&(q=y(A,"SCALAR",0,5126,g,[0],[L])),q),ne=[],re=[];for(let H=0;H<c.length;H++){let se=N[H],ae=!1,D=!1,G=!1;for(let E=0;E<g;E++)(Math.abs(_[H][E*3]-se.px)>1e-4||Math.abs(_[H][E*3+1]-se.py)>1e-4||Math.abs(_[H][E*3+2]-se.pz)>1e-4)&&(ae=!0),(Math.abs(O[H][E*4]-se.qx)>1e-4||Math.abs(O[H][E*4+1]-se.qy)>1e-4||Math.abs(O[H][E*4+2]-se.qz)>1e-4||Math.abs(O[H][E*4+3]-se.qw)>1e-4)&&(D=!0),(Math.abs(Q[H][E*3]-se.sx)>1e-4||Math.abs(Q[H][E*3+1]-se.sy)>1e-4||Math.abs(Q[H][E*3+2]-se.sz)>1e-4)&&(G=!0);if(ae){let E=y(_[H],"VEC3",0,5126,g),V=ne.length;ne.push({input:oe(),interpolation:"LINEAR",output:E}),re.push({sampler:V,target:{node:H,path:"translation"}})}if(D){let E=y(O[H],"VEC4",0,5126,g),V=ne.length;ne.push({input:oe(),interpolation:"LINEAR",output:E}),re.push({sampler:V,target:{node:H,path:"rotation"}})}if(G){let E=y(Q[H],"VEC3",0,5126,g),V=ne.length;ne.push({input:oe(),interpolation:"LINEAR",output:E}),re.push({sampler:V,target:{node:H,path:"scale"}})}}re.length>0&&w.push({name:"ProceduralLoop",samplers:ne,channels:re})}let M=so(u,a,t.userData),P={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:u,meshes:a,materials:l,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...w.length>0?{animations:w}:{},...M||s.size>0?{extensionsUsed:[...M?["KHR_interactivity"]:[],...s]}:{},...M||f.length>0?{extensions:{...M?{KHR_interactivity:M}:{},...f.length>0?{KHR_materials_variants:{variants:f.map(L=>({name:L}))}}:{}}}:{}},k=new Uint8Array(r),I=0;for(let L of n)k.set(L,I),I+=L.byteLength;return{gltf:P,bin:k.buffer,lights:h,environmentIntensity:t.environmentIntensity}}function Xn(t){return new TextEncoder().encode(t)}function an(t,e){let{gltf:n,bin:r}=Yt(t,e),i=JSON.stringify(n),o=Xn(i),a=(4-o.byteLength%4)%4,u=o.byteLength+a,s=20+u+8+r.byteLength,c=new Uint8Array(s),l=new DataView(c.buffer);l.setUint32(0,1179937895,!0),l.setUint32(4,2,!0),l.setUint32(8,s,!0),l.setUint32(12,u,!0),l.setUint32(16,1313821514,!0),c.set(o,20);for(let f=0;f<a;f++)c[20+o.byteLength+f]=32;let m=20+u;return l.setUint32(m,r.byteLength,!0),l.setUint32(m+4,5130562,!0),c.set(new Uint8Array(r),m+8),c}function Ma(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,u=new Float32Array(a*3),s=r.matrixWorld.elements;for(let I=0;I<a;I++){let L=o.getX(I),x=o.getY(I),g=o.getZ(I);u[I*3]=s[0]*L+s[4]*x+s[8]*g+s[12],u[I*3+1]=s[1]*L+s[5]*x+s[9]*g+s[13],u[I*3+2]=s[2]*L+s[6]*x+s[10]*g+s[14]}let c;if(i.attributes.normal){let I=i.attributes.normal;c=new Float32Array(a*3);let L=new Float32Array(9);Ne(L,s);for(let x=0;x<a;x++){let g=I.getX(x),A=I.getY(x),N=I.getZ(x),_=L[0]*g+L[3]*A+L[6]*N,O=L[1]*g+L[4]*A+L[7]*N,Q=L[2]*g+L[5]*A+L[8]*N,q=Math.hypot(_,O,Q)||1;c[x*3]=_/q,c[x*3+1]=O/q,c[x*3+2]=Q/q}}let l;if(i.attributes.uv){let I=i.attributes.uv;l=new Float32Array(a*2);for(let L=0;L<a;L++)l[L*2]=I.getX(L),l[L*2+1]=I.getY(L)}let m;if(i.index)m=i.index.array;else{m=a>65535?new Uint32Array(a):new Uint16Array(a);for(let I=0;I<a;I++)m[I]=I}let f="DefaultMaterial",h=[.8,.8,.8],p=.5,d=.1,y=0,v=0,R=1.5,b=1,w=[0,0,0];if(r.material){let I=r.material;f=I.name||`Material_${n.length}`,I.color&&(h=[I.color.r,I.color.g,I.color.b]),typeof I.roughness=="number"&&(p=I.roughness),typeof I.metalness=="number"&&(d=I.metalness),typeof I.clearcoat=="number"&&(y=I.clearcoat),typeof I.clearcoatRoughness=="number"&&(v=I.clearcoatRoughness),typeof I.ior=="number"&&(R=I.ior);let L=typeof I.opacity=="number"?I.opacity:1,x=typeof I.transmission=="number"?I.transmission:0;if(b=L*(1-x),I.emissive&&(I.emissive.r>0||I.emissive.g>0||I.emissive.b>0)){let g=I.emissiveIntensity??1;w=[I.emissive.r*g,I.emissive.g*g,I.emissive.b*g]}}let M,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 I=e?.duration??4,L=e?.fps??4,x=Math.max(2,Math.round(I*L)+1),g=[],A=[],N=[],_=[],O=[r.position.x,r.position.y,r.position.z],Q=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],q=[r.scale.x,r.scale.y,r.scale.z],oe=!1;for(let ne=0;ne<x;ne++){let re=ne/(x-1)*I;g.push(re);try{P(re)}catch{}A.push([r.position.x,r.position.y,r.position.z]),N.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),_.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-O[0])>1e-4||Math.abs(r.position.y-O[1])>1e-4||Math.abs(r.position.z-O[2])>1e-4||Math.abs(r.quaternion.x-Q[0])>1e-4||Math.abs(r.quaternion.y-Q[1])>1e-4||Math.abs(r.quaternion.z-Q[2])>1e-4||Math.abs(r.quaternion.w-Q[3])>1e-4||Math.abs(r.scale.x-q[0])>1e-4)&&(oe=!0)}r.position.set(O[0],O[1],O[2]),r.quaternion.set(Q[0],Q[1],Q[2],Q[3]),r.scale.set(q[0],q[1],q[2]),oe&&(M={times:g,translations:A,rotations:N,scales:_})}let k=r;if(k.isInstancedMesh&&typeof k.count=="number"&&k.count>0&&k.instanceMatrix?.array){let I=Math.min(1e3,Math.floor(k.count)),L=k.instanceMatrix.array,x=k.instanceColor?.array,g=r.name||`Mesh_${n.length}`,A=new Float32Array(16),N=new Float32Array(9);for(let _=0;_<I;_++){let O=L.subarray(_*16,(_+1)*16);Le(A,s,O);let Q=new Float32Array(a*3);for(let re=0;re<a;re++){let H=o.getX(re),se=o.getY(re),ae=o.getZ(re);Q[re*3]=A[0]*H+A[4]*se+A[8]*ae+A[12],Q[re*3+1]=A[1]*H+A[5]*se+A[9]*ae+A[13],Q[re*3+2]=A[2]*H+A[6]*se+A[10]*ae+A[14]}let q;if(i.attributes.normal){let re=i.attributes.normal;q=new Float32Array(a*3),Ne(N,A);for(let H=0;H<a;H++){let se=re.getX(H),ae=re.getY(H),D=re.getZ(H),G=N[0]*se+N[3]*ae+N[6]*D,E=N[1]*se+N[4]*ae+N[7]*D,V=N[2]*se+N[5]*ae+N[8]*D,F=Math.hypot(G,E,V)||1;q[H*3]=G/F,q[H*3+1]=E/F,q[H*3+2]=V/F}}let oe=h,ne=f;x&&x.length>=(_+1)*3&&(oe=[h[0]*x[_*3],h[1]*x[_*3+1],h[2]*x[_*3+2]],ne=`${f}_inst_${_}`),n.push({name:`${g}_${_}`,positions:Q,indices:m,normals:q,uvs:l,materialName:ne,color:oe,roughness:p,metallic:d,clearcoat:y,clearcoatRoughness:v,ior:R,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:u,indices:m,normals:c,uvs:l,materialName:f,color:h,roughness:p,metallic:d,clearcoat:y,clearcoatRoughness:v,ior:R,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:M})}}),n}function No(t){let e=[],n=t.gltf,r=ve().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),a=n.accessors||[],u=n.bufferViews||[],s=n.materials||[],c=n.meshes||[],l=n.nodes||[];function m(p){let d=a[p];if(!d)throw new Error(`Accessor ${p} not found`);let y=u[d.bufferView||0],v=(y.byteOffset||0)+(d.byteOffset||0),R=y.byteLength||0,b=o.slice(v,v+R);return{acc:d,buffer:b}}let f=new Map;if(l.length>0){let p=dt(n);for(let d=0;d<p.length;d++)f.set(d,p[d])}function h(p,d,y,v){let R=c[p];if(!R)return;let b=new Float32Array(9);Ne(b,d);for(let w=0;w<(R.primitives||[]).length;w++){let M=R.primitives[w],P=M.attributes?.POSITION;if(P===void 0)continue;let{acc:k,buffer:I}=m(P),L=new Float32Array(I,0,k.count*3),x=new Float32Array(L.length);for(let E=0;E<k.count;E++){let V=L[E*3],F=L[E*3+1],U=L[E*3+2];x[E*3]=d[0]*V+d[4]*F+d[8]*U+d[12],x[E*3+1]=d[1]*V+d[5]*F+d[9]*U+d[13],x[E*3+2]=d[2]*V+d[6]*F+d[10]*U+d[14]}let g,A=M.attributes?.NORMAL;if(A!==void 0){let{acc:E,buffer:V}=m(A),F=new Float32Array(V,0,E.count*3);g=new Float32Array(F.length);for(let U=0;U<E.count;U++){let z=F[U*3],Y=F[U*3+1],le=F[U*3+2],ie=b[0]*z+b[3]*Y+b[6]*le,he=b[1]*z+b[4]*Y+b[7]*le,T=b[2]*z+b[5]*Y+b[8]*le,S=Math.hypot(ie,he,T)||1;g[U*3]=ie/S,g[U*3+1]=he/S,g[U*3+2]=T/S}}let N,_=M.attributes?.TEXCOORD_0;if(_!==void 0){let{acc:E,buffer:V}=m(_);N=new Float32Array(V,0,E.count*2)}let O;if(M.indices!==void 0){let{acc:E,buffer:V}=m(M.indices);E.componentType===5125?O=new Uint32Array(V,0,E.count):O=new Uint16Array(V,0,E.count);let F=k.count;for(let U of O)if(U>=F)throw new Error(`SecurityError: Index buffer value (${U}) out of vertex bounds [0, ${F}).`)}else{let E=k.count;O=E>65535?new Uint32Array(E):new Uint16Array(E);for(let V=0;V<E;V++)O[V]=V}let Q="DefaultMaterial",q=[.8,.8,.8],oe=.5,ne=.1,re=0,H=0,se=1.5,ae=1,D=[0,0,0];if(M.material!==void 0&&s[M.material]){let E=s[M.material];Q=E.name||`Material_${M.material}`;let V=E.pbrMetallicRoughness||{},F=1;Array.isArray(V.baseColorFactor)&&(q=[V.baseColorFactor[0],V.baseColorFactor[1],V.baseColorFactor[2]],typeof V.baseColorFactor[3]=="number"&&(F=V.baseColorFactor[3])),typeof V.roughnessFactor=="number"&&(oe=V.roughnessFactor),typeof V.metallicFactor=="number"&&(ne=V.metallicFactor),Array.isArray(E.emissiveFactor)&&E.emissiveFactor.length>=3&&(D=[E.emissiveFactor[0],E.emissiveFactor[1],E.emissiveFactor[2]]);let U=E.extensions||{};U.KHR_materials_clearcoat&&(re=U.KHR_materials_clearcoat.clearcoatFactor??0,H=U.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),U.KHR_materials_ior&&typeof U.KHR_materials_ior.ior=="number"&&(se=U.KHR_materials_ior.ior);let z=U.KHR_materials_transmission?.transmissionFactor??0;ae=F*(1-z)}let G=(R.primitives||[]).length>1?`${y}_p${w}`:y;e.push({name:G,positions:x,indices:O,normals:g,uvs:N,materialName:Q,color:q,roughness:oe,metallic:ne,clearcoat:re,clearcoatRoughness:H,ior:se,opacity:ae,emissiveColor:D,xrTraits:v?.xr||R.extras?.xr})}}if(l.length>0)for(let p=0;p<l.length;p++){let d=l[p];if(d.mesh!==void 0&&d.mesh<c.length){let y=f.get(p)||we(),v=d.name||c[d.mesh].name||`Node_${p}`,R=d.extensions?.EXT_mesh_gpu_instancing?.attributes;if(R&&typeof R=="object"){let b=R.TRANSLATION,w=R.ROTATION,M=R.SCALE,P=b!==void 0?(()=>{let{acc:x,buffer:g}=m(b);return new Float32Array(g,0,x.count*3)})():null,k=w!==void 0?(()=>{let{acc:x,buffer:g}=m(w);return new Float32Array(g,0,x.count*4)})():null,I=M!==void 0?(()=>{let{acc:x,buffer:g}=m(M);return new Float32Array(g,0,x.count*3)})():null,L=Math.min(1e3,P?P.length/3:k?k.length/4:I?I.length/3:0);if(L>0){let x=new Float32Array(16),g=new Float32Array(16);for(let A=0;A<L;A++){let N=P?[P[A*3],P[A*3+1],P[A*3+2]]:[0,0,0],_=k?[k[A*4],k[A*4+1],k[A*4+2],k[A*4+3]]:[0,0,0,1],O=I?[I[A*3],I[A*3+1],I[A*3+2]]:[1,1,1];Je(x,_,N,O),Le(g,y,x),h(d.mesh,g,`${v}_${A}`,d.extras)}continue}}h(d.mesh,y,v,d.extras)}}else{let p=we();for(let d=0;d<c.length;d++){let y=c[d].name||`Mesh_${d}`;h(d,p,y,c[d].extras)}}return e}function ei(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 Po(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Ae(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 ko(t){let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Ae(t[r*3])}, ${Ae(t[r*3+1])}, ${Ae(t[r*3+2])})`;return n.join(", ")}function Aa(t,e){let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Ae(t[r*2])}, ${Ae(1-t[r*2+1])})`;return n.join(", ")}function Sa(t){return Array.from(t).join(", ")}function ti(t){let e=new Map;for(let s of t){let c=ei(s.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:s.color||[.8,.8,.8],roughness:s.roughness??.5,metallic:s.metallic??0,clearcoat:s.clearcoat??0,clearcoatRoughness:s.clearcoatRoughness??0,ior:s.ior??1.5,opacity:s.opacity??1,emissiveColor:s.emissiveColor||[0,0,0]})}let n=0,r=null;for(let s of t){if(s.timeSamples&&s.timeSamples.times.length>0){let c=s.timeSamples.times[s.timeSamples.times.length-1];c>n&&(n=c)}s.xrTraits?.anchor&&!r&&(r=s.xrTraits.anchor==="vertical"||s.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
254
- endTimeCode = ${Ae(n)}
250
+ void main(){fragColor=uColorId;}`;function mi(e,t,r){let i={};for(let n of r)i[n]=e.getUniformLocation(t,n);return i}var Sn=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Rn(){let e=Ae().xrDepthShader;return{fs:Go.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...Sn,...e.uniformNames]:Sn}}function Ko(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let r=t.toLowerCase();return r.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:r.startsWith("https://")||r.startsWith("blob:")?t:r.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function fi(e,t,r,i,n,s,l,o){if(i===void 0||!t.accessors?.[i])return null;let a=kt(t,r,t.accessors[i],s);if(!a)return null;o&&(a=a.slice(),Bo(a,o));let u=e.createBuffer();return l.push(u),e.bindBuffer(34962,u),e.bufferData(34962,a,35044),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,s,5126,!1,0,0),a}function pi(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function Pn(e,t,r){let i=Rn(),n=Tn,s=i.fs,l=!1;for(let a of Fe)if(a.onResolveShader){let u=a.onResolveShader(t,r,n,s);u&&(n=u.vs,s=u.fs,l=!0)}let o=l?Ft(e,n,s):null;return{program:o,uniforms:o?mi(e,o,i.uniforms):null}}function Yo(e,t,r){let i=t.instanceMatrices;if(!i||i.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let n=i.length>>4,s=t.instanceColors,l=new Float32Array(n*20);for(let a=0;a<n;a++)l.set(i.subarray(a*16,a*16+16),a*20),l[a*20+16]=s?s[a*3]:1,l[a*20+17]=s?s[a*3+1]:1,l[a*20+18]=s?s[a*3+2]:1,l[a*20+19]=1;let o=e.createBuffer();r.push(o),e.bindBuffer(34962,o),e.bufferData(34962,l,35044);for(let a=0;a<5;a++)e.enableVertexAttribArray(8+a),e.vertexAttribPointer(8+a,4,5126,!1,80,a*16),e.vertexAttribDivisor(8+a,1);return!0}function Zo(e,t){let r=e.materials?.[t?.material];if(!r)return null;let i=[r.pbrMetallicRoughness?.baseColorTexture,r.pbrMetallicRoughness?.metallicRoughnessTexture,r.normalTexture,r.occlusionTexture,r.emissiveTexture];for(let n of i){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var Qo=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),En=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ar(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function Nn(e,t){let r=e?.pbrMetallicRoughness,i=r?.baseColorFactor,n=e?.extensions?.KHR_materials_clearcoat,s=l=>l!==void 0&&t[l.index]?t[l.index]:null;return{baseColor:i?[i[0],i[1],i[2],i[3]??1]:[.8,.8,.8,1],metallic:r?.metallicFactor??.1,roughness:r?.roughnessFactor??.5,clearcoat:n?n.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,n?.clearcoatRoughnessFactor??.04),texture:s(r?.baseColorTexture),metallicRoughnessTexture:s(r?.metallicRoughnessTexture),normalTexture:s(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:s(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Cn(e,t,r){let i=new Set,n=s=>{s&&!i.has(s)&&(i.add(s),e.deleteTexture(s))};for(let s of t)for(let l of s.primitives){if(l.vao&&e.deleteVertexArray(l.vao),l.buffers)for(let a of l.buffers)e.deleteBuffer(a);n(l.texture),n(l.metallicRoughnessTexture),n(l.normalTexture),n(l.occlusionTexture);let o=new Set;l.customProgram&&o.add(l.customProgram);for(let a of l.programCache?.values()??[])a.program&&o.add(a.program);for(let a of o)e.deleteProgram(a)}if(r)for(let s of r)n(s)}function Ln(e,t,r=En,i){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Jo(e,t,r,i,n)}catch(s){let l=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;Cn(e,l,n.gpuTextures),n.vao&&e.deleteVertexArray(n.vao);for(let o of n.buffers)e.deleteBuffer(o);throw s}}function Jo(e,t,r,i,n){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=t,l=Ut("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(s,t);let o=t.bin,a=[];n.meshes=a;let u=[],h=s.extensions?.KHR_materials_variants;h&&Array.isArray(h.variants)&&h.variants.forEach((k,w)=>{u.push(typeof k?.name=="string"&&k.name?k.name:`Variant_${w}`)});let m=vr(s),c=[];if(Array.isArray(s.nodes))for(let k=0;k<s.nodes.length;k++){let w=s.nodes[k];w.mesh!==void 0&&s.meshes&&s.meshes[w.mesh]&&c.push({node:w,nodeIdx:k,meshIdx:w.mesh})}let d=c.length>0?c:(s.meshes||[]).map((k,w)=>({node:k,nodeIdx:-1,meshIdx:w})),f=[],g=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(g)for(let k of g)f.push({...k,type:k.type||k.light_type||"point",innerConeAngle:k.innerConeAngle??k.inner_cone_angle,outerConeAngle:k.outerConeAngle??k.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let k=s.extensions.KHR_lights_punctual.lights;for(let w of k){let ie=w.type==="directional"?"directional":w.type==="point"?"point":w.type==="spot"?"spot":"ambient";f.push({type:ie,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(f.length===0&&(f.push({type:"ambient",color:[1,1,1],intensity:.35}),f.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>r.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${r.maxMeshes}). Found: ${d.length}`);let x=[];if(n.gpuTextures=x,s.textures&&s.images){if(s.textures.length>r.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${r.maxTextures}). Found: ${s.textures.length}`);for(let k=0;k<s.textures.length;k++){let w=s.textures[k],ie=s.images[w.source];if(ie){let oe=e.createTexture();e.bindTexture(3553,oe),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let I=H=>{e.bindTexture(3553,oe),e.texImage2D(3553,0,6408,6408,5121,H),e.generateMipmap(3553),i?.()};if(ie.bufferView!==void 0){let H=s.bufferViews[ie.bufferView],N=H.byteOffset||0,z=new Blob([o.slice(N,N+H.byteLength)],{type:ie.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(z).then(I).catch(()=>{})}else if(ie.uri){let H=Ko(ie.uri);if(H){let N=new Image;N.crossOrigin="anonymous",N.referrerPolicy="no-referrer",N.onload=()=>I(N),N.src=H}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",ie.uri)}x.push(oe)}else x.push(null)}}let b=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],p=0,y=0;for(let k=0;k<d.length;k++){let w=d[k],ie=s.meshes[w.meshIdx],oe=w.nodeIdx>=0?m[w.nodeIdx]:Pe(),I=new Float32Array(9);Ke(I,oe);let H={name:w.node.name||ie.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:oe,normalMatrix:I,primitives:[],extras:w.node.extras||ie.extras,...w.node?.visible===!1||w.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};n.mesh=H;let N=w.node?.extensions?.EXT_mesh_gpu_instancing;if(N&&N.attributes&&typeof N.attributes=="object"){let z=N.attributes,ue=z.TRANSLATION!==void 0?s.accessors?.[z.TRANSLATION]:null,he=z.ROTATION!==void 0?s.accessors?.[z.ROTATION]:null,B=z.SCALE!==void 0?s.accessors?.[z.SCALE]:null,$=z._COLOR_0!==void 0?s.accessors?.[z._COLOR_0]:null,_=Number(ue?.count??he?.count??B?.count??0);if(!Number.isFinite(_)||_<0||_>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${_}`);if(_>0){let G=(V,ee)=>{if(!V||V.bufferView===void 0||!s.bufferViews?.[V.bufferView])return null;let R=V.componentType??5126,A=C=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${C})`),null);if(R!==5120&&R!==5121&&R!==5122&&R!==5123&&R!==5126)return A(`componentType ${R}`);if(!(Number(V.count)>=_))return A(`count ${V.count} < ${_}`);let L=null;try{L=kt(s,o,{...V,count:_},ee)}catch{return A("out of bounds")}return!L||!L.every(Number.isFinite)?A("non-finite value"):L},j=G(ue,3),q=G(he,4),D=G(B,3),Y=$?.type==="VEC4"?4:3,te=G($,Y),se=new Float32Array(_*16),le=Pe();for(let V=0;V<_;V++){let ee=j?[j[V*3],j[V*3+1],j[V*3+2]]:[0,0,0],R=q?[q[V*4],q[V*4+1],q[V*4+2],q[V*4+3]]:[0,0,0,1],A=D?[D[V*3],D[V*3+1],D[V*3+2]]:[1,1,1];Qt(le,R,ee,A),se.set(le,V*16)}if(H.instanceMatrices=se,te){let V=new Float32Array(_*3);for(let ee=0;ee<_;ee++)V[ee*3]=te[ee*Y],V[ee*3+1]=te[ee*Y+1],V[ee*3+2]=te[ee*Y+2];H.instanceColors=V}}}for(let z of ie.primitives||[]){if(z.extensions?.KHR_draco_mesh_compression){let L=Ut("draco");L&&L.decodePrimitive(s,z,o)}let ue=[],he=e.createVertexArray();n.vao=he,n.buffers=ue,e.bindVertexArray(he);let B=Yo(e,H,ue),$=s.accessors[z.attributes.POSITION],_=Number($?.count??0);if(!Number.isFinite(_)||_<0||p+_>r.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${r.maxVertices}).`);if(p+=_,$?.min&&$?.max){let L=C=>{for(let U=0;U<3;U++){let Q=C[12+U],X=C[12+U];for(let Z=0;Z<3;Z++){let J=C[Z*4+U]*$.min[Z],K=C[Z*4+U]*$.max[Z];Q+=J<K?J:K,X+=J>K?J:K}Q<b[U]&&(b[U]=Q),X>v[U]&&(v[U]=X)}};if(H.instanceMatrices&&H.instanceMatrices.length>=16){let C=H.instanceMatrices.length>>4,U=Pe();for(let Q=0;Q<C;Q++){let X=H.instanceMatrices.subarray(Q*16,Q*16+16);ke(U,oe,X),L(U)}}else L(oe)}let G=fi(e,s,o,z.attributes.POSITION,0,3,ue);fi(e,s,o,z.attributes.NORMAL,1,3,ue),fi(e,s,o,z.attributes.TEXCOORD_0,2,2,ue,Zo(s,z));let j=0,q=5123,D=null;if(z.indices!==void 0){let L=s.accessors[z.indices],C=(s.bufferViews[L.bufferView].byteOffset||0)+(L.byteOffset||0);if(j=Number(L.count??0),!Number.isFinite(j)||j<0||y+j>r.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${r.maxIndices}).`);y+=j,q=L.componentType===5125?5125:5123;let U=e.createBuffer();ue.push(U),e.bindBuffer(34963,U),L.componentType===5125?D=new Uint32Array(o,C,L.count):L.componentType===5121?D=Uint16Array.from(new Uint8Array(o,C,L.count)):D=C%2===0?new Uint16Array(o,C,L.count):new Uint16Array(o.slice(C,C+L.count*2)),e.bufferData(34963,D,35044)}else j=$.count;let Y={};for(let L of Fe)if(L.onBuildPrimitiveVAO){let C=L.onBuildPrimitiveVAO(e,he,z,s,o);C&&(Y[L.name]=C)}e.bindVertexArray(null);let te=s.materials&&z.material!==void 0?s.materials[z.material]:null,{program:se,uniforms:le}=Pn(e,z,te),V=Nn(te,x),ee=!!(te?.extensions?.KHR_materials_transmission||Y.materials?.isTransmissive),R=z.extensions?.KHR_materials_variants?.mappings,A=Array.isArray(R)?R.filter(L=>L&&typeof L.material=="number"&&Array.isArray(L.variants)).map(L=>({material:L.material|0,variants:L.variants.map(C=>Number(C)|0)})):void 0;H.primitives.push({vao:he,instanced:B,indexCount:j,indexType:q,...V,positions:G,indices:D,buffers:ue,materialIndex:z.material,defaultMaterialIndex:z.material,variantMappings:A,primitiveDef:z,programCache:new Map([[z.material??-1,{program:se,uniforms:le}]]),pluginData:Y,customProgram:se,customUniforms:le,isTransmissive:ee})}a.push(H)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let M=[(b[0]+v[0])/2,(b[1]+v[1])/2,(b[2]+v[2])/2],P=v[0]-b[0],F=v[1]-b[1],W=v[2]-b[2],T=Math.max(Math.hypot(P,F,W)/2,.5),E=[b[0],b[1],b[2]],S=[v[0],v[1],v[2]],O=t.animations;if(!O){for(let k of Fe)if(k.onParseGLB?.(t),t.animations){O=t.animations;break}}return O||(O=[]),{meshes:a,bounds:{center:M,radius:T,min:E,max:S},lights:f,animations:O,worldMatrices:m,gpuTextures:x,availableVariants:u}}function rr(e){let t=e.customTarget||e.bounds.center,r=e.currDistance*Math.cos(e.currPhi);return[t[0]+r*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+r*Math.cos(e.currTheta)]}var Qe=class{constructor(e,t,r){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=Pe(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=Pe(),this.viewMatrix=Pe(),this.activeViewMatrix=null,this.modelMatrix=Pe(),this.mvpMatrix=Pe(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshName="",this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:Pe(),rawValueToMeters:.001,format:0},this.container=e;let i,n;if(t&&typeof t.getContext=="function"?(i=t,n=r):(n=t,i=n?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=n||{},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.exposure=pi(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=Vt(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 l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Ho(e,t)}static getDecoder(e){return Ut(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=Rn();this.renderProg=Ft(e,Tn,t.fs),this.pickProg=Ft(e,qo,Xo),this.uRender=mi(e,this.renderProg,t.uniforms),this.uPick=mi(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of Fe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,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,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),n=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=n,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,n,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,n)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:n,animations:s,worldMatrices:l,gpuTextures:o,availableVariants:a}=Ln(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=o||[],this.availableVariants=a||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),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 Fe)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 u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=pi(u));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(An(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of Fe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(tr(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=tr(e),{meshes:i}=Ln(this.gl,r,En,()=>this.render());if(t)for(let n of i)n.transform[12]+=t[0],n.transform[13]+=t[1],n.transform[14]+=t[2],Ke(n.normalMatrix,n.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),Ke(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],n=[],s=[],l=[],o=[],a=[];for(let u of this.lights){let h=u.color||[1,1,1],m=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[h[0]*m,h[1]*m,h[2]*m];else if(u.type==="directional"&&i.length<6){let c=u.direction||[.5,1,.8];i.push(c[0],c[1],c[2]),n.push(h[0]*m,h[1]*m,h[2]*m)}else if((u.type==="point"||u.type==="spot")&&s.length<6){let c=u.position||[0,0,0];if(s.push(c[0],c[1],c[2]),l.push(h[0]*m,h[1]*m,h[2]*m),u.type==="spot"){let d=u.direction||[0,-1,0],f=Math.max(.01,Math.min(Math.PI/2,u.outerConeAngle??Math.PI/3)),g=Math.max(0,Math.min(f-1e-4,u.innerConeAngle??0));o.push(d[0],d[1],d[2]),a.push(Math.cos(g),Math.cos(f))}else o.push(0,-1,0),a.push(-2,-3)}}i.length===0&&(i.push(.5,1,.8),n.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,n)),t.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(t.uniform3fv(e.uPointLightPos,s),t.uniform3fv(e.uPointLightColor,l),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,a)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=pi(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Vt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Fe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Fe)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.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((t,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),n=i[0],s=n?[...n.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=n?n.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:s,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:u=>{let h=[u[0],u[1],u[2],u[3]??1];a.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let m of i)m.baseColor=h;this.render()},setMetallicFactor:u=>{a.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let h of i)h.metallic=u;this.render()},setRoughnessFactor:u=>{a.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let h of i)h.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)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 t;for(let n of this.meshes)for(let s of n.primitives){let l=s.defaultMaterialIndex;if(!t&&Array.isArray(s.variantMappings)){for(let a of s.variantMappings)if(Array.isArray(a.variants)&&a.variants.includes(r)){l=a.material;break}}let o=l!==void 0?i[l]:void 0;s.materialIndex=o?l:void 0,Object.assign(s,Nn(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,n=e.programCache.get(i);n||(n=Pn(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,n)),e.customProgram=n.program,e.customUniforms=n.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of Fe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,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 t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*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,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let n=this.clampDistance(r);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else if(i!==void 0&&i>0){let n=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else{this.customDistance=!1;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())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=Pe();ke(r,this.projMatrix,this.viewMatrix);let[i,n,s]=e,l=t?t[0]:0,o=t?t[1]:0,a=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],n=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(l=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],a=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let h=r[0]*i+r[4]*n+r[8]*s+r[12],m=r[1]*i+r[5]*n+r[9]*s+r[13],c=r[2]*i+r[6]*n+r[10]*s+r[14],d=r[3]*i+r[7]*n+r[11]*s+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let f=h/d,g=m/d,x=c/d,b=this.canvas.getBoundingClientRect(),v=b.width||this.canvas.clientWidth||this.canvas.width||300,p=b.height||this.canvas.clientHeight||this.canvas.height||150,y=(f*.5+.5)*v,M=(-g*.5+.5)*p,P=f>=-1.1&&f<=1.1&&g>=-1.1&&g<=1.1&&x>=-1&&x<=1;if(P&&t){let[F,W,T]=rr(this),E=[i-F,n-W,s-T];l*E[0]+o*E[1]+a*E[2]>.05&&(P=!1)}return{x:y,y:M,z:x,visible:P}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=r=>{r.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=r=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist=0,this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.isPanning=r.button===2||r.shiftKey||this.activePointers.size===2,e.setPointerCapture(r.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=r=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let i=this.activePointers.get(r.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=r.clientX-i.x,s=r.clientY-i.y;if(this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||r.button===2||r.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[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]+=(-n*l[0]+s*o[0])*u,a[1]+=(-n*l[1]+s*o[1])*u,a[2]+=(-n*l[2]+s*o[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=r=>{this.lastInteractionTime=t(),this.activePointers.delete(r.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(r.pointerId)}catch{}if(this.totalDragDist<5&&r.button===0){let i=e.getBoundingClientRect(),n=Math.floor((r.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((r.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(n,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=r=>{if(!this.interactive)return;r.preventDefault(),this.lastInteractionTime=t();let i=Math.exp(r.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=r=>{let i=r.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.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=r=>{if(this.interactive){switch(r.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),r.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(r,i,n)=>{this[n]&&(r.removeEventListener(i,this[n]),this[n]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),n=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(n/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(s/i.height)):Math.floor(t);return this.performMeshPick(l,o,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,n);let l=Pe();ke(l,this.projMatrix,this.viewMatrix);let o=[],a=Math.max(0,Math.min(n-1,e)),u=Math.max(0,Math.min(s-1,s-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,n,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16640),i.useProgram(this.pickProg);for(let M=0;M<this.meshes.length;M++){let P=this.meshes[M];if(P.visible===!1||P.isPluginMesh)continue;let F=M+1,W=(F&255)/255,T=(F>>8&255)/255,E=(F>>16&255)/255;i.uniform4f(this.uPick.uColorId,W,T,E,1),ke(this.modelMatrix,this.modelRootMatrix,P.transform);let S=P.instanceMatrices;if(S&&S.length>=16){let O=S.length>>4,k=Pe();for(let w of P.primitives){i.bindVertexArray(w.vao);for(let ie=0;ie<O;ie++)ke(k,this.modelMatrix,S.subarray(ie*16,ie*16+16)),ke(this.mvpMatrix,l,k),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ar(i,w)}}else{ke(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let O of P.primitives)i.bindVertexArray(O.vao),Ar(i,O)}}let p=new Uint8Array(4);i.readPixels(a,u,1,1,6408,5121,p),i.bindFramebuffer(36160,null);let y=p[0]+(p[1]<<8)+(p[2]<<16);y>0&&y<=this.meshes.length&&(o=[this.meshes[y-1]])}o.length===0&&(o=this.meshes.filter(p=>p.visible!==!1));let h=null,m=1/0,c=[0,0,0],d=[0,1,0],[f,g,x]=rr(this),b=Pe();for(let p of o){ke(b,this.modelRootMatrix,p.transform);let y=p.instanceMatrices,M=y&&y.length>=16?y.length>>4:1;for(let P=0;P<M;P++){y&&y.length>=16?ke(this.modelMatrix,b,y.subarray(P*16,P*16+16)):this.modelMatrix.set(b),ke(this.mvpMatrix,l,this.modelMatrix);let F=Pe();if(!ri(F,this.mvpMatrix))continue;let W=(a+.5)/n*2-1,T=(u+.5)/s*2-1,E=[0,0,0],S=[0,0,0];cn(E,W,T,-1,F),cn(S,W,T,1,F);let O=S[0]-E[0],k=S[1]-E[1],w=S[2]-E[2],ie=Math.hypot(O,k,w)||1,oe=O/ie,I=k/ie,H=w/ie,N={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((z=>{for(let ue of p.primitives){if(!ue.positions)continue;let he=ue.positions,B=ue.indices,$=Math.floor(B?B.length/3:he.length/9);for(let _=0;_<$;_++){let G=B?B[_*3]:_*3,j=B?B[_*3+1]:_*3+1,q=B?B[_*3+2]:_*3+2;Ao(E[0],E[1],E[2],oe,I,H,he[G*3],he[G*3+1],he[G*3+2],he[j*3],he[j*3+1],he[j*3+2],he[q*3],he[q*3+1],he[q*3+2],N,z)}}})(1e-4),isFinite(N.distance)){let z=N.point[0],ue=N.point[1],he=N.point[2],B=this.modelMatrix,$=B[0]*z+B[4]*ue+B[8]*he+B[12],_=B[1]*z+B[5]*ue+B[9]*he+B[13],G=B[2]*z+B[6]*ue+B[10]*he+B[14],j=$-f,q=_-g,D=G-x,Y=Math.hypot(j,q,D);if(Y<m){Ke(this.normalMatrix,this.modelMatrix);let te=this.normalMatrix,se=N.normal[0],le=N.normal[1],V=N.normal[2],ee=te[0]*se+te[3]*le+te[6]*V,R=te[1]*se+te[4]*le+te[7]*V,A=te[2]*se+te[5]*le+te[8]*V,L=Math.hypot(ee,R,A)||1;ee/=L,R/=L,A/=L,ee*j+R*q+A*D>0&&(ee=-ee,R=-R,A=-A),h=p,m=Math.round(Y*1e3)/1e3,c=[Math.round($*1e3)/1e3,Math.round(_*1e3)/1e3,Math.round(G*1e3)/1e3],d=[Math.round(ee*1e3)/1e3,Math.round(R*1e3)/1e3,Math.round(A*1e3)/1e3]}}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:m,hitPoint:c,normal:d,screenX:e,screenY:t};if(r){for(let p of Fe)p.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,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,n=i?e-r:e,s=i?Math.max(1,t-r):r,l=(n+.5)/s*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);ti(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;xr(this.viewMatrix,rr(this),r,[0,1,0]),ke(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ke(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.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 t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of Fe)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 t of Fe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,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),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],n=this.modelRootMatrix;n[0]=e,n[1]=0,n[2]=-t,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=t,n[9]=0,n[10]=e,n[11]=0,n[12]=r-(e*r+t*i),n[13]=0,n[14]=i-(-t*r+e*i),n[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Fe)s.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of Fe)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),n=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(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=n;let s={theta:r,phi:i,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,t,r,i,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,u=a?[a.x,a.y,a.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:n})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),y=Math.max(1,Math.floor(v*.5)),M=Math.max(1,v-y),P=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),F=this.customTarget||this.bounds.center,[W,T,E]=rr(this),S=Math.cos(this.currTheta),O=-Math.sin(this.currTheta),k=.032,w=Pe(),ie=Pe(),oe=[W-S*k,T,E-O*k],I=[F[0]-S*k*.25,F[1],F[2]-O*k*.25];ti(w,this.fov,y/p,.1,P),xr(ie,oe,I,[0,1,0]);let H=Pe(),N=Pe(),z=[W+S*k,T,E+O*k],ue=[F[0]+S*k*.25,F[1],F[2]+O*k*.25];ti(H,this.fov,M/p,.1,P),xr(N,z,ue,[0,1,0]),this.render({viewMatrix:ie,projMatrix:w,eyePos:oe,viewport:[0,0,y,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:N,projMatrix:H,eyePos:z,viewport:[y,0,M,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,r=0,i=0,n=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],n=e.viewport[2],s=e.viewport[3],t.viewport(r,i,n,s)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let l=Pe(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,ke(l,e?.projMatrix??this.projMatrix,o);let a=Ae().xrDepthShader,u=zo(this.toneMapping),[h,m,c]=e?e.eyePos:rr(this);for(let v of Fe)v.onBeforeDrawScene?.(this,t,l,[h,m,c],u);let d=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&d===0)return;let f=e?.eye||"none",g=!1,x=d>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=v=>{for(let p=0;p<x.length;p++){let y=x[p];if(y.visible===!1)continue;let M=this.selectedMeshName!==""&&y.name===this.selectedMeshName;p<d||y.worldSpace===!0||y.name==="__xr_reticle__"?this.modelMatrix.set(y.transform):ke(this.modelMatrix,this.modelRootMatrix,y.transform),ke(this.mvpMatrix,l,this.modelMatrix),Ke(y.normalMatrix,this.modelMatrix);let P=y.extras?.xr?.stereo||y.userData?.xr?.stereo,F=0,W=0,T=1,E=1;P==="sbs"?(T=.5,F=f==="right"?.5:0):P==="ou"&&(E=.5,W=f==="right"?.5:0);for(let S of y.primitives){let O=!!S.isTransmissive;if(!v&&O){g=!0;continue}if(v&&!O)continue;let k=S.customProgram||this.renderProg,w=S.customUniforms||this.uRender;t.useProgram(k),t.vertexAttrib3f(3,0,0,0),w.uInstanced&&t.uniform1i(w.uInstanced,0),t.uniform1i(w.uToneMapping,u),t.uniform1f(w.uEnvIntensity,this.envIntensity),w.uExposure&&t.uniform1f(w.uExposure,this.exposure),t.uniform3f(w.uCameraPos,h,m,c),t.uniform1f(w.uEmissive,M?1:0),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(w.uNormalMatrix,!1,y.normalMatrix),w.uUvTransform&&t.uniform4f(w.uUvTransform,F,W,T,E),w.uViewportSize&&t.uniform2f(w.uViewportSize,Math.max(1,n),Math.max(1,s)),a?.bind(t,w,this.xrDepthState,o,[r,i,Math.max(1,n),Math.max(1,s)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(w.uEnvironmentMap,4),t.uniform1i(w.uHasEnvironmentMap,1)):t.uniform1i(w.uHasEnvironmentMap,0),this.bindLights(w),w.uSectionEnabled&&t.uniform1i(w.uSectionEnabled,0);for(let oe of Fe)oe.onBeforeDrawPrimitive?.(t,k,S,y,this.worldMatrices||[],this.gltf);t.uniform4fv(w.uBaseColor,S.baseColor),t.uniform1f(w.uMetallic,S.metallic),t.uniform1f(w.uRoughness,S.roughness),w.uClearcoat&&t.uniform2f(w.uClearcoat,S.clearcoat??0,S.clearcoatRoughness??.04),S.texture?(t.activeTexture(33984),t.bindTexture(3553,S.texture),t.uniform1i(w.uBaseColorTexture,0),t.uniform1i(w.uHasTexture,1)):t.uniform1i(w.uHasTexture,0),S.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,S.metallicRoughnessTexture),t.uniform1i(w.uMetallicRoughnessTexture,1),t.uniform1i(w.uHasMetallicRoughnessTexture,1)):t.uniform1i(w.uHasMetallicRoughnessTexture,0),S.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,S.normalTexture),t.uniform1i(w.uNormalTexture,2),t.uniform1i(w.uHasNormalTexture,1),t.uniform1f(w.uNormalScale,S.normalScale)):t.uniform1i(w.uHasNormalTexture,0),S.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,S.occlusionTexture),t.uniform1i(w.uOcclusionTexture,3),t.uniform1i(w.uHasOcclusionTexture,1),t.uniform1f(w.uOcclusionStrength,S.occlusionStrength)):t.uniform1i(w.uHasOcclusionTexture,0),t.bindVertexArray(S.vao);let ie=y.instanceMatrices;if(S.instanceCount!==void 0)t.drawElementsInstanced(4,S.indexCount,S.indexType,0,S.instanceCount);else if(ie&&ie.length>=16&&S.instanced&&w.uInstanced&&w.uViewProj){let oe=ie.length>>4;t.uniform1i(w.uInstanced,1),t.uniformMatrix4fv(w.uViewProj,!1,l),S.indices?t.drawElementsInstanced(4,S.indexCount,S.indexType,0,oe):t.drawArraysInstanced(4,0,S.indexCount,oe),t.uniform1i(w.uInstanced,0)}else if(ie&&ie.length>=16){let oe=ie.length>>4,I=y.instanceColors,H=Pe(),N=new Float32Array(9),z=[S.baseColor[0],S.baseColor[1],S.baseColor[2],S.baseColor[3]];for(let ue=0;ue<oe;ue++)ke(H,this.modelMatrix,ie.subarray(ue*16,ue*16+16)),ke(this.mvpMatrix,l,H),Ke(N,H),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,H),t.uniformMatrix3fv(w.uNormalMatrix,!1,N),I&&(z[0]=S.baseColor[0]*I[ue*3],z[1]=S.baseColor[1]*I[ue*3+1],z[2]=S.baseColor[2]*I[ue*3+2],z[3]=S.baseColor[3],t.uniform4fv(w.uBaseColor,z)),Ar(t,S)}else Ar(t,S)}}};if(b(!1),g){for(let v of Fe)v.onBeforeTransmissivePass?.(t,this);b(!0)}for(let v of Fe)v.onAfterRender?.(t,this,l,e?.eye??"none",[r,i,n,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){Cn(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Fe)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Qe.registerPlugin=Ge,Qe.getRegisteredPlugins=un;function el(e){return e+3&-4}var ve=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function _n(e,t){let r=t,i=1;for(;e.has(r);)r=`${t}_${i++}`;return e.add(r),r}function In(e,t=0){let[r,i,n,,s,l,o,,a,u,h,,m,c,d]=Array.from({length:15},(N,z)=>ve(e[t+z],z%5===0?1:0)),f=Math.hypot(r,i,n),g=Math.hypot(s,l,o),x=Math.hypot(a,u,h);r*(l*h-u*o)-s*(i*h-u*n)+a*(i*o-l*n)<0&&(f=-f);let b=Math.abs(f)>1e-8?1/f:0,v=Math.abs(g)>1e-8?1/g:0,p=Math.abs(x)>1e-8?1/x:0,y=r*b,M=i*b,P=n*b,F=s*v,W=l*v,T=o*v,E=a*p,S=u*p,O=h*p,k=y+W+O,w=0,ie=0,oe=0,I=1;if(k>0){let N=.5/Math.sqrt(k+1);I=.25/N,w=(T-S)*N,ie=(E-P)*N,oe=(M-F)*N}else if(y>W&&y>O){let N=2*Math.sqrt(Math.max(0,1+y-W-O));N>1e-8&&(I=(T-S)/N,w=.25*N,ie=(F+M)/N,oe=(E+P)/N)}else if(W>O){let N=2*Math.sqrt(Math.max(0,1+W-y-O));N>1e-8&&(I=(E-P)/N,w=(F+M)/N,ie=.25*N,oe=(T+S)/N)}else{let N=2*Math.sqrt(Math.max(0,1+O-y-W));N>1e-8&&(I=(M-F)/N,w=(E+P)/N,ie=(T+S)/N,oe=.25*N)}let H=Math.hypot(w,ie,oe,I);return H>1e-8&&Number.isFinite(H)?(w/=H,ie/=H,oe/=H,I/=H):(w=0,ie=0,oe=0,I=1),{t:[m,c,d],r:[w,ie,oe,I],s:[f,g,x]}}function tl(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Mt=(e,t,r,i)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(r,e)):i;function Dn(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let r=typeof t=="string"?{preset:t}:t,i=typeof r.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(r.src)?r.src:void 0,n=typeof r.preset=="string"?r.preset:void 0;return!i&&!n?null:{ae:r,src:i,preset:n,volume:Mt(r.volume,0,2,.6),loop:typeof r.loop=="boolean"?r.loop:!0,isGlobal:r.type==="global"||r.positional===!1}}function ir(e,t){return kn(e,t)[0]}function kn(e,t){e.updateMatrixWorld(!0);let r=[],i=0,n=[],s=[],l=[],o=[],a=new Set,u=[],h=[],m=new Map,c=[],d=[],f=[],g=new Map,x=[],b=[];function v(I){let H=m.get(I);if(H!==void 0)return H;H=h.length,m.set(I,H);let N=I,z=N.color?.r??1,ue=N.color?.g??1,he=N.color?.b??1,B=N.opacity??1,$={baseColorFactor:[z,ue,he,B],metallicFactor:N.metalness??0,roughnessFactor:N.roughness??.5},_={},G=ee=>{if(!ee)return;let R=(typeof ee=="string"?ee:typeof ee.source=="string"?ee.source:typeof ee.image=="string"?ee.image:"").trim();if(!R||/[\x00-\x1f\x7f\\]|\.\./.test(R)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(R)||!R.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(R)))return;let A=g.get(R);if(A===void 0){let L=c.length;c.push({uri:R}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),A=f.length,f.push({sampler:0,source:L}),g.set(R,A)}return{index:A}},j=G(N.map);j&&($.baseColorTexture=j);let q=G(N.roughnessMap||N.metalnessMap);q&&($.metallicRoughnessTexture=q);let D=N.map?.avgColor;Array.isArray(D)&&D.length>=3&&(_.avgColor=[D[0],D[1],D[2]]);let Y=G(N.normalMap),te=G(N.emissiveMap),se=G(N.aoMap),le={name:N.name||"",pbrMetallicRoughness:$,doubleSided:N.side===2||!!N.doubleSided,...Y?{normalTexture:Y}:{},...te?{emissiveTexture:te}:{},...se?{occlusionTexture:se}:{},...Object.keys(_).length>0?{extras:_}:{}};if(N.emissive&&(N.emissive.r>0||N.emissive.g>0||N.emissive.b>0)){let ee=N.emissiveIntensity??1;le.emissiveFactor=[N.emissive.r*ee,N.emissive.g*ee,N.emissive.b*ee]}let V={};return N.clearcoat&&N.clearcoat>0&&(V.KHR_materials_clearcoat={clearcoatFactor:N.clearcoat,clearcoatRoughnessFactor:N.clearcoatRoughness||0}),N.sheen&&N.sheen>0&&(V.KHR_materials_sheen={sheenColorFactor:N.sheenColor?[N.sheenColor.r,N.sheenColor.g,N.sheenColor.b]:[1,1,1],sheenRoughnessFactor:N.sheenRoughness||0}),N.transmission&&N.transmission>0&&(V.KHR_materials_transmission={transmissionFactor:N.transmission}),N.thickness&&N.thickness>0&&(V.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&&(V.KHR_materials_ior={ior:N.ior}),N.dispersion&&N.dispersion>0&&(V.KHR_materials_dispersion={dispersion:N.dispersion}),N.iridescence&&N.iridescence>0&&(V.KHR_materials_iridescence={iridescenceFactor:N.iridescence,iridescenceIor:N.iridescenceIOR??1.3}),Object.keys(V).length>0&&(le.extensions=V),h.push(le),H}function p(I,H){let N=new Uint8Array(I.buffer,I.byteOffset,I.byteLength),z=el(N.byteLength),ue=new Uint8Array(z);ue.set(N),r.push(ue);let he=n.length;return n.push({buffer:0,byteOffset:i,byteLength:N.byteLength,target:H}),i+=z,he}function y(I,H,N,z,ue,he,B){let $=p(I,N),_=s.length,G={bufferView:$,byteOffset:0,componentType:z,count:ue,type:H};return he&&(G.min=he),B&&(G.max=B),s.push(G),_}e.traverse(I=>{if(I.isLight||I.color&&I.intensity!==void 0){let H=I.matrixWorld?.elements,N=ve(H?H[12]:I.position?.x,0),z=ve(H?H[13]:I.position?.y,0),ue=ve(H?H[14]:I.position?.z,0),he=I.target,B=he?.parent?he?.matrixWorld?.elements:void 0,$=ve(B?B[12]:he?.position?.x,0),_=ve(B?B[13]:he?.position?.y,0),G=ve(B?B[14]:he?.position?.z,0),j=$-N,q=_-z,D=G-ue,Y=Math.hypot(j,q,D),te=Math.max(.01,Math.min(Math.PI/2,ve(I.angle,Math.PI/3))),se=Math.max(0,Math.min(1,ve(I.penumbra,0)));b.push({type:I.type,color:[I.color.r,I.color.g,I.color.b],intensity:I.intensity,position:[N,z,ue],...I.type==="spot"?{direction:Y>1e-6?[j/Y,q/Y,D/Y]:[0,-1,0],outerConeAngle:te,innerConeAngle:Math.max(0,te*(1-se)),range:Math.max(0,ve(I.distance,0))}:I.type==="point"?{range:Math.max(0,ve(I.distance,0))}:{}})}});let M=[],P=new Set([e]),F=[];if(Array.isArray(e.children))for(let I=e.children.length-1;I>=0;I--)F.push({obj:e.children[I],parentKids:M});for(;F.length>0;){let{obj:I,parentKids:H}=F.pop();if(!I||typeof I!="object"||P.has(I))continue;P.add(I),I._bakeAuthorGeometry?.(),Ae().materializeDeclarativeGeometry?.(I);let N=!!(I.userData&&(I.userData.xr&&typeof I.userData.xr=="object"&&Object.keys(I.userData.xr).length>0||I.userData.interactivity&&typeof I.userData.interactivity=="object"&&Object.keys(I.userData.interactivity).length>0)),z={name:I.name||(N?`Node_${o.length}`:"")},ue=ve(I.position?.x,0),he=ve(I.position?.y,0),B=ve(I.position?.z,0),$=ve(I.quaternion?.x,0),_=ve(I.quaternion?.y,0),G=ve(I.quaternion?.z,0),j=ve(I.quaternion?.w,1),q=ve(I.scale?.x,1),D=ve(I.scale?.y,1),Y=ve(I.scale?.z,1);if((ue||he||B)&&(z.translation=[ue,he,B]),($||_||G||j!==1)&&(z.rotation=[$,_,G,j]),(q!==1||D!==1||Y!==1)&&(z.scale=[q,D,Y]),I.visible===!1&&(z.extensions={...z.extensions||{},KHR_node_visibility:{visible:!1}},a.add("KHR_node_visibility")),I.userData&&Object.keys(I.userData).length>0&&(z.extras=JSON.parse(JSON.stringify(I.userData,(le,V)=>{if(!(le==="__proto__"||le==="prototype"||le==="constructor"))return typeof V=="function"?void 0:V})),I.userData.xr)){let le=tl(I.userData.xr);z.extensions={...z.extensions||{},MOZ_hubs_components:le,ANDROID_xr_scenecore:le},Ae().xrTraitSerializer?.gltfNode(z,I.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(I.geometry){let le=I.geometry,V=le.attributes.position;if(V&&V.count>0){let ee=[1/0,1/0,1/0],R=[-1/0,-1/0,-1/0];for(let X=0;X<V.count;X++){let Z=V.getX(X),J=V.getY(X),K=V.getZ(X);Z<ee[0]&&(ee[0]=Z),Z>R[0]&&(R[0]=Z),J<ee[1]&&(ee[1]=J),J>R[1]&&(R[1]=J),K<ee[2]&&(ee[2]=K),K>R[2]&&(R[2]=K)}let A={attributes:{POSITION:y(V.array,"VEC3",34962,5126,V.count,ee,R)}};if(le.attributes.normal&&(A.attributes.NORMAL=y(le.attributes.normal.array,"VEC3",34962,5126,le.attributes.normal.count)),le.attributes.uv&&(A.attributes.TEXCOORD_0=y(le.attributes.uv.array,"VEC2",34962,5126,le.attributes.uv.count)),le.index){let X=le.index.array instanceof Uint32Array;A.indices=y(le.index.array,"SCALAR",34963,X?5125:5123,le.index.count)}let L=Array.isArray(I.material)?I.material[0]:I.material;L&&(A.material=v(L));let C=I.userData?.variants;if(C&&typeof C=="object"){let X=new Map;for(let Z of Object.keys(C)){if(!Z||Z==="__proto__"||Z==="constructor"||Z==="prototype")continue;let J=C[Z];if(!J||typeof J!="object")continue;let K=x.indexOf(Z);if(K===-1&&x.length<256&&(K=x.length,x.push(Z)),K===-1)continue;let ae=v(J),ne=X.get(ae);ne||(ne=[],X.set(ae,ne)),ne.push(K)}if(X.size>0){let Z=[];for(let[J,K]of X.entries())Z.push({material:J,variants:K});A.extensions={...A.extensions||{},KHR_materials_variants:{mappings:Z}},a.add("KHR_materials_variants")}}let U=I;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let X=Math.min(1e4,Math.floor(U.count)),Z=U.instanceMatrix.array,J=new Float32Array(X*3),K=new Float32Array(X*4),ae=new Float32Array(X*3);for(let re=0;re<X;re++){let{t:ce,r:me,s:ge}=In(Z,re*16);J[re*3]=ce[0],J[re*3+1]=ce[1],J[re*3+2]=ce[2],K[re*4]=me[0],K[re*4+1]=me[1],K[re*4+2]=me[2],K[re*4+3]=me[3],ae[re*3]=ge[0],ae[re*3+1]=ge[1],ae[re*3+2]=ge[2]}let ne={TRANSLATION:y(J,"VEC3",0,5126,X),ROTATION:y(K,"VEC4",0,5126,X),SCALE:y(ae,"VEC3",0,5126,X)};if(U.instanceColor?.array&&U.instanceColor.array.length>=X*3){let re=new Float32Array(U.instanceColor.array.subarray(0,X*3));ne._COLOR_0=y(re,"VEC3",0,5126,X)}z.extensions={...z.extensions||{},EXT_mesh_gpu_instancing:{attributes:ne}},a.add("EXT_mesh_gpu_instancing")}let Q=l.length;l.push({primitives:[A],name:I.name,...z.extras?{extras:z.extras}:{}}),z.mesh=Q}}let te=o.length;o.push(z),u.push(I),H.push(te);let se=I.children;if(Array.isArray(se)&&se.length>0){let le=[];z.children=le;for(let V=se.length-1;V>=0;V--)F.push({obj:se[V],parentKids:le})}}for(let I=0;I<o.length;I++){let H=o[I];H.children&&H.children.length===0?delete H.children:H.children&&H.children.length>0&&(H.extras?.xr?.lod||H.extensions?.ANDROID_xr_scenecore?.lod||u[I]?.isLOD)&&(H.extensions={...H.extensions||{},MSFT_lod:{ids:[...H.children]}},a.add("MSFT_lod"))}let W=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),T=[];if(typeof W=="function"&&u.length>0){let I=t?.duration??4,H=t?.fps??15,N=Math.max(2,Math.round(I*H)+1),z=new Float32Array(N),ue=u.map(D=>[ve(D.position?.x,0),ve(D.position?.y,0),ve(D.position?.z,0),ve(D.quaternion?.x,0),ve(D.quaternion?.y,0),ve(D.quaternion?.z,0),ve(D.quaternion?.w,1),ve(D.scale?.x,1),ve(D.scale?.y,1),ve(D.scale?.z,1)]),he=u.map(()=>new Float32Array(N*3)),B=u.map(()=>new Float32Array(N*4)),$=u.map(()=>new Float32Array(N*3));for(let D=0;D<N;D++){let Y=D/(N-1)*I;z[D]=Y;try{W(Y)}catch{}for(let te=0;te<u.length;te++){let se=u[te];he[te][D*3]=ve(se.position?.x,0),he[te][D*3+1]=ve(se.position?.y,0),he[te][D*3+2]=ve(se.position?.z,0);let le=ve(se.quaternion?.x,0),V=ve(se.quaternion?.y,0),ee=ve(se.quaternion?.z,0),R=ve(se.quaternion?.w,1),A=Math.hypot(le,V,ee,R)||1;if(le/=A,V/=A,ee/=A,R/=A,D>0){let L=(D-1)*4,C=B[te];C[L]*le+C[L+1]*V+C[L+2]*ee+C[L+3]*R<0&&(le=-le,V=-V,ee=-ee,R=-R)}B[te][D*4]=le,B[te][D*4+1]=V,B[te][D*4+2]=ee,B[te][D*4+3]=R,$[te][D*3]=ve(se.scale?.x,1),$[te][D*3+1]=ve(se.scale?.y,1),$[te][D*3+2]=ve(se.scale?.z,1)}}for(let D=0;D<u.length;D++){let Y=u[D],te=ue[D];Y.position?.set(te[0],te[1],te[2]),Y.quaternion?.set(te[3],te[4],te[5],te[6]),Y.scale?.set(te[7],te[8],te[9])}e.updateMatrixWorld(!0);let _=null,G=()=>(_===null&&(_=y(z,"SCALAR",0,5126,N,[0],[I])),_),j=[],q=[];for(let D=0;D<u.length;D++){let Y=ue[D],te=(le,V,ee)=>le.some((R,A)=>Math.abs(R-Y[ee+A%V])>1e-4),se=(le,V,ee,R)=>{le&&q.push({sampler:j.push({input:G(),interpolation:"LINEAR",output:y(V,ee,0,5126,N)})-1,target:{node:D,path:R}})};se(te(he[D],3,0),he[D],"VEC3","translation"),se(te(B[D],4,3),B[D],"VEC4","rotation"),se(te($[D],3,7),$[D],"VEC3","scale")}q.length>0&&T.push({name:"ProceduralLoop",samplers:j,channels:q})}let E=bo(o,l,e.userData),S=[],O=[],k=[];for(let I=0;I<o.length;I++){let H=o[I],N=Dn(H.extras?.xr);if(!N)continue;let{ae:z,src:ue,preset:he,volume:B,loop:$,isGlobal:_}=N,G=H.name||`Node_${I}`,j=O.length;O.push({name:`${G}_source`,gain:B,loop:$,autoPlay:typeof z.autoplay=="boolean"?z.autoplay:!0,...ue!==void 0?{audio:S.push({uri:ue})-1}:{},...he?{extras:{preset:he,pitch:Mt(z.pitch,.25,4,1)}}:{}});let q=k.length,D=Mt(z.refDistance,.05,100,1),Y=Mt(z.coneInnerAngle,0,360,360),te=Mt(z.coneOuterAngle,Y,360,360);k.push({name:`${G}_emitter`,type:_?"global":"positional",gain:B,sources:[j],..._?{}:{positional:{distanceModel:z.distanceModel==="linear"||z.distanceModel==="exponential"?z.distanceModel:"inverse",refDistance:D,maxDistance:Mt(z.maxDistance,D,500,Math.max(D,25)),rolloffFactor:Mt(z.rolloffFactor,0,10,1),coneInnerAngle:+(Y*Math.PI/180).toFixed(6),coneOuterAngle:+(te*Math.PI/180).toFixed(6),coneOuterGain:Mt(z.coneOuterGain,0,1,0)}}}),H.extensions={...H.extensions||{},KHR_audio_emitter:{emitter:q}},a.add("KHR_audio_emitter")}let w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:M}],scene:0,nodes:o,meshes:l,materials:h,...c.length>0?{images:c}:{},...d.length>0?{samplers:d}:{},...f.length>0?{textures:f}:{},accessors:s,bufferViews:n,buffers:[{byteLength:i}],...T.length>0?{animations:T}:{},...E||a.size>0?{extensionsUsed:[...E?["KHR_interactivity"]:[],...a]}:{},...E||x.length>0||k.length>0?{extensions:{...E?{KHR_interactivity:E}:{},...x.length>0?{KHR_materials_variants:{variants:x.map(I=>({name:I}))}}:{},...k.length>0?{KHR_audio_emitter:{...S.length>0?{audio:S}:{},sources:O,emitters:k}}:{}}}:{}},ie=new Uint8Array(i),oe=0;for(let I of r)ie.set(I,oe),oe+=I.byteLength;return[{gltf:w,bin:ie.buffer,lights:b,environmentIntensity:e.environmentIntensity},u]}function di(e){return new TextEncoder().encode(e)}function Tr(e,t){let{gltf:r,bin:i}=ir(e,t),n=JSON.stringify(r),s=di(n),l=(4-s.byteLength%4)%4,o=s.byteLength+l,a=20+o+8+i.byteLength,u=new Uint8Array(a),h=new DataView(u.buffer);h.setUint32(0,1179937895,!0),h.setUint32(4,2,!0),h.setUint32(8,a,!0),h.setUint32(12,o,!0),h.setUint32(16,1313821514,!0),u.set(s,20);for(let c=0;c<l;c++)u[20+s.byteLength+c]=32;let m=20+o;return h.setUint32(m,i.byteLength,!0),h.setUint32(m+4,5130562,!0),u.set(new Uint8Array(i),m+8),u}function rl(e,t){let[r,i]=kn(e,t);return Fn(r,i)}function Fn(e,t){let r=[],i=e.gltf,n=Ae().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(i,e);let s=e.bin,l=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=i.accessors||[],a=i.bufferViews||[],u=i.materials||[],h=i.meshes||[],m=i.nodes||[],c=i.textures||[],d=i.images||[],f=i.samplers||[],g=new Set,x=u.map((P,F)=>_n(g,Sr(P?.name,`Material_${F}`))),b=new Map;function v(P){let F=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!F)return null;let W=F[2].replace(/\s+/g,""),T=W.endsWith("==")?2:W.endsWith("=")?1:0,E=new Uint8Array((W.length*3>>2)-T),S=k=>{let w=W.charCodeAt(k);return w>96?w-71:w>64?w-65:w>47?w+4:w===43?62:w===47?63:0},O=0;for(let k=0;k<W.length;k+=4){let w=S(k)<<18|S(k+1)<<12|S(k+2)<<6|S(k+3);E[O++]=w>>16&255,O<E.length&&(E[O++]=w>>8&255),O<E.length&&(E[O++]=w&255)}return E}function p(P,F,W){let T=P?.index;if(typeof T!="number")return;let E=c[T],S=E?.source;if(typeof S!="number"||!d[S])return;let O=b.get(S);if(O===void 0){O=null;let ie=d[S],oe=null;if(typeof ie.bufferView=="number"){let I=a[ie.bufferView],H=I?.byteOffset||0,N=I?.byteLength||0;I&&N>0&&H>=0&&H+N<=l.byteLength&&(oe=new Uint8Array(l,H,N))}else typeof ie.uri=="string"&&(oe=v(ie.uri));if(oe&&oe.byteLength>0){let I=oe[0]===255&&oe[1]===216&&oe[2]===255||!(oe[0]===137&&oe[1]===80)&&/jpe?g/i.test(ie.mimeType||ie.uri||"");O={file:`texture_${S}.${I?"jpg":"png"}`,data:oe}}b.set(S,O)}if(!O)return;let k=typeof E.sampler=="number"?f[E.sampler]:void 0,w=ie=>ie===33071?"clamp":ie===33648?"mirror":"repeat";return{file:O.file,data:O.data,wrapS:w(k?.wrapS),wrapT:w(k?.wrapT),...F?{scale:F}:{},...W?{bias:W}:{}}}function y(P){let F=o[P];if(!F)throw new Error(`Accessor ${P} not found`);let W=a[F.bufferView||0],T=(W.byteOffset||0)+(F.byteOffset||0),E=W.byteLength||0;return{acc:F,buffer:l.slice(T,T+E)}}function M(P,F,W,T){let E=[],S=h[P];if(!S)return E;let O=S.primitives||[];for(let k=0;k<O.length;k++){let w=O[k],ie=w.attributes?.POSITION;if(ie===void 0)continue;let{acc:oe,buffer:I}=y(ie),H=new Float32Array(I,0,oe.count*3),N,z=w.attributes?.NORMAL;if(z!==void 0){let{acc:V,buffer:ee}=y(z),R=new Float32Array(ee,0,V.count*3);N=new Float32Array(R.length);for(let A=0;A<V.count;A++){let L=R[A*3],C=R[A*3+1],U=R[A*3+2],Q=Math.hypot(L,C,U)||1;N[A*3]=L/Q,N[A*3+1]=C/Q,N[A*3+2]=U/Q}}let ue,he=w.attributes?.TEXCOORD_0;if(he!==void 0){let{acc:V,buffer:ee}=y(he);ue=new Float32Array(ee,0,V.count*2)}let B;if(w.indices!==void 0){let{acc:V,buffer:ee}=y(w.indices);B=V.componentType===5125?new Uint32Array(ee,0,V.count):new Uint16Array(ee,0,V.count);let R=oe.count;for(let A of B)if(A>=R)throw new Error(`SecurityError: Index buffer value (${A}) out of vertex bounds [0, ${R}).`)}else{let V=oe.count;B=V>65535?new Uint32Array(V):new Uint16Array(V);for(let ee=0;ee<V;ee++)B[ee]=ee}let $="DefaultMaterial",_=[1,1,1],G=.5,j=0,q=0,D=0,Y=1.5,te=1,se=[0,0,0],le;if(w.material!==void 0&&u[w.material]){let V=u[w.material];$=x[w.material]||`Material_${w.material}`;let ee=V.pbrMetallicRoughness||{},R=(ce,me)=>Array.isArray(ce)&&ce.length>=3?[ce[0],ce[1],ce[2]]:me;_=R(ee.baseColorFactor,[1,1,1]);let A=Array.isArray(ee.baseColorFactor)&&typeof ee.baseColorFactor[3]=="number"?ee.baseColorFactor[3]:1,L=_[0]!==1||_[1]!==1||_[2]!==1||A!==1,C=p(ee.baseColorTexture,L?[_[0],_[1],_[2],A]:void 0),U=V.extras?.avgColor;!C&&Array.isArray(U)&&U.length>=3&&(_=[_[0]*U[0],_[1]*U[1],_[2]*U[2]]),typeof ee.roughnessFactor=="number"&&(G=ee.roughnessFactor),typeof ee.metallicFactor=="number"&&(j=ee.metallicFactor);let Q=typeof ee.roughnessFactor=="number"?ee.roughnessFactor:1,X=typeof ee.metallicFactor=="number"?ee.metallicFactor:1,Z=p(ee.metallicRoughnessTexture,Q!==1||X!==1?[1,Q,X,1]:void 0);se=R(V.emissiveFactor,[0,0,0]);let J=(se[0]>0||se[1]>0||se[2]>0)&&(se[0]!==1||se[1]!==1||se[2]!==1)?[se[0],se[1],se[2],1]:void 0,K=p(V.emissiveTexture,J),ae=p(V.normalTexture,[2,2,2,1],[-1,-1,-1,0]),ne=p(V.occlusionTexture);(C||Z||ae||K||ne)&&(le=[C,Z,ae,K,ne]);let re=V.extensions||{};re.KHR_materials_clearcoat&&(q=re.KHR_materials_clearcoat.clearcoatFactor??0,D=re.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof re.KHR_materials_ior?.ior=="number"&&(Y=re.KHR_materials_ior.ior),te=A*(1-(re.KHR_materials_transmission?.transmissionFactor??0))}E.push({name:O.length>1?`${F}_p${k}`:F,positions:H,indices:B,normals:N,uvs:ue,materialName:$,color:_,roughness:G,metallic:j,clearcoat:q,clearcoatRoughness:D,ior:Y,opacity:te,emissiveColor:se,...le?{textures:le}:{},xrTraits:W||S.extras?.xr,...T?{invisible:!0}:{}})}return E}if(m.length>0){let P=new Float32Array(0),F=new Uint16Array(0),W=(H,N)=>{if(H===void 0)return null;let{acc:z,buffer:ue}=y(H);return new Float32Array(ue,0,z.count*N)},T=(H,N)=>Array.isArray(H)&&H.length>=3?[ve(H[0],N),ve(H[1],N),ve(H[2],N)]:[N,N,N],E=(H,N,z)=>H&&H.length>=(N+1)*3?[H[N*3],H[N*3+1],H[N*3+2]]:z,S=(H,N,z)=>H&&H.length>=(N+1)*4?[H[N*4],H[N*4+1],H[N*4+2],H[N*4+3]]:z,O=new Map,k=i.animations?.[0];if(k&&Array.isArray(k.channels)&&Array.isArray(k.samplers))for(let H of k.channels){let N=k.samplers[H?.sampler],z=H?.target?.node,ue=H?.target?.path;if(!N||typeof z!="number"||N.input===void 0)continue;let he=O.get(z);he||(he={input:N.input},O.set(z,he)),ue==="translation"?he.t=N.output:ue==="rotation"?he.r=N.output:ue==="scale"&&(he.s=N.output)}let w=i.scenes?.[i.scene??0]?.nodes??[];if(!Array.isArray(w)||w.length===0){let H=new Set;for(let N of m)if(Array.isArray(N?.children))for(let z of N.children)H.add(z);w=[];for(let N=0;N<m.length;N++)H.has(N)||w.push(N);w.length===0&&(w=[0])}let ie=new Set,oe=[],I=(H,N)=>{if(Array.isArray(H))for(let z=H.length-1;z>=0;z--)oe.push({idx:H[z],out:N})};for(I(w,r);oe.length>0;){let{idx:H,out:N}=oe.pop();if(typeof H!="number"||H<0||H>=m.length||ie.has(H))continue;ie.add(H);let z=m[H];if(!z)continue;let ue=[0,0,0],he=[0,0,0,1],B=[1,1,1];if(Array.isArray(z.matrix)&&z.matrix.length===16){let te=In(z.matrix);ue=te.t,he=te.r,B=te.s}else ue=T(z.translation,0),Array.isArray(z.rotation)&&z.rotation.length>=4&&(he=[ve(z.rotation[0],0),ve(z.rotation[1],0),ve(z.rotation[2],0),ve(z.rotation[3],1)]),B=T(z.scale,1);let $,_=O.get(H);if(_){let te=W(_.input,1);if(te&&te.length>0){let se=W(_.t,3),le=W(_.r,4),V=W(_.s,3),ee=Array.from(te),R=[],A=[],L=[];for(let C=0;C<te.length;C++)R.push(E(se,C,ue)),A.push(S(le,C,he)),L.push(E(V,C,B));$={times:ee,translations:R,rotations:A,scales:L}}}let G=Array.isArray(z.children)?z.children:[],j=typeof z.mesh=="number"&&z.mesh>=0&&z.mesh<h.length,q=t?.[H]?.userData?.xr??z.extras?.xr;if(!j&&G.length===0&&(z.camera!==void 0||z.extensions?.KHR_lights_punctual||!z.name&&!z.extras&&!q&&!$))continue;let D=(te,se,le)=>({name:te,positions:P,indices:F,isXform:!0,xrTraits:q,timeSamples:$,translation:ue,rotation:he,scale:B,children:se,...le?{invisible:!0}:{}}),Y=z.visible===!1||z.extensions?.KHR_node_visibility?.visible===!1||t?.[H]?.visible===!1;if(j){let te=z.name||h[z.mesh]?.name||`Mesh_${H}`,se=M(z.mesh,te,q,Y),le=z.extensions?.EXT_mesh_gpu_instancing?.attributes;if(le&&typeof le=="object"&&se.length>0){let V=W(le.TRANSLATION,3),ee=W(le.ROTATION,4),R=W(le.SCALE,3),A=W(le._COLOR_0,3),L=Math.min(1e3,V?V.length/3:ee?ee.length/4:R?R.length/3:0);if(L>0){let C=[];for(let U=0;U<L;U++){let Q=E(V,U,[0,0,0]),X=S(ee,U,[0,0,0,1]),Z=E(R,U,[1,1,1]);for(let J of se){let K=J.color||[.8,.8,.8],ae=A&&A.length>=(U+1)*3;C.push({...J,name:`${J.name}_${U}`,materialName:ae?`${J.materialName}_inst_${U}`:J.materialName,color:ae?[K[0]*A[U*3],K[1]*A[U*3+1],K[2]*A[U*3+2]]:J.color,translation:Q,rotation:X,scale:Z})}}I(G,C),N.push(D(te,C,Y));continue}}if(se.length===1)se[0].translation=ue,se[0].rotation=he,se[0].scale=B,se[0].timeSamples=$,G.length>0&&(se[0].children=[],I(G,se[0].children)),N.push(se[0]);else{let V=[...se];I(G,V),N.push(D(te,V,Y))}}else{let te=[];I(G,te),N.push(D(z.name||`Group_${H}`,te,Y))}}}else for(let P=0;P<h.length;P++){let F=h[P].name||`Mesh_${P}`;r.push(...M(P,F,h[P].extras?.xr))}return r}function Sr(e,t){if(!e||typeof e!="string")return t;let r=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(r)&&(r="_"+r),r||t}function Rr(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function ze(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var dt=(e,t,r)=>`(${ze(e)}, ${ze(t)}, ${ze(r)})`,Pr=(e,t,r,i)=>`(${ze(e)}, ${ze(t)}, ${ze(r)}, ${ze(i)})`;function Vn(e){let t=e.length/3,r=new Array(t);for(let i=0;i<t;i++)r[i]=dt(e[i*3],e[i*3+1],e[i*3+2]);return r.join(", ")}function il(e,t){let r=new Array(t);for(let i=0;i<t;i++)r[i]=`(${ze(e[i*2])}, ${ze(1-e[i*2+1])})`;return r.join(", ")}function nl(e){return Array.from(e).join(", ")}function sl(e){let t=new Map,r=0,i=null,n=[...e];for(;n.length>0;){let f=n.pop();if(!f.isXform&&f.positions&&f.positions.length>0){let g=Sr(f.materialName,"DefaultMaterial");t.has(g)||t.set(g,{color:f.color||[1,1,1],roughness:f.roughness??.5,metallic:f.metallic??0,clearcoat:f.clearcoat??0,clearcoatRoughness:f.clearcoatRoughness??0,ior:f.ior??1.5,opacity:f.opacity??1,emissiveColor:f.emissiveColor||[0,0,0],textures:f.textures})}if(f.timeSamples&&f.timeSamples.times.length>0){let g=f.timeSamples.times[f.timeSamples.times.length-1];g>r&&(r=g)}if(f.xrTraits?.anchor&&!i&&(i=f.xrTraits.anchor==="vertical"||f.xrTraits.anchor==="wall"?"vertical":"horizontal"),f.children)for(let g=f.children.length-1;g>=0;g--)n.push(f.children[g])}let s="";r>0&&(s=`startTimeCode = 0
251
+ endTimeCode = ${ze(r)}
255
252
  timeCodesPerSecond = 1.0
256
- `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
257
- uniform token preliminary:planeAnchoring:alignment = "${r}"
258
- `);let a=`#usda 1.0
253
+ `);let l="";i&&(l=`uniform token preliminary:anchoring:type = "plane"
254
+ uniform token preliminary:planeAnchoring:alignment = "${i}"
255
+ `);let o=`#usda 1.0
259
256
  (
260
257
  defaultPrim = "Root"
261
258
  metersPerUnit = 1.0
262
259
  upAxis = "Y"
263
- ${i})
260
+ ${s})
264
261
 
265
262
  def Xform "Root" (
266
263
  kind = "component"
267
264
  )
268
265
  {
269
- ${o}def Scope "Materials"
266
+ ${l}def Scope "Materials"
267
+ {
268
+ `;for(let[f,g]of t.entries()){let[x,b,v]=g.color,[p,y,M]=g.emissiveColor,P=`/Root/Materials/${f}`,[F,W,T,E,S]=g.textures||[],O=(I,H)=>`.connect = <${P}/${I}.outputs:${H}>`,k=F?`color3f inputs:diffuseColor${O("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${dt(x,b,v)}`,w=W?`float inputs:metallic${O("MetallicRoughnessTexture","b")}
269
+ float inputs:roughness${O("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${ze(g.metallic)}
270
+ float inputs:roughness = ${ze(g.roughness)}`,ie="";g.clearcoat>0&&(ie+=`float inputs:clearcoat = ${ze(g.clearcoat)}
271
+ `,ie+=`float inputs:clearcoatRoughness = ${ze(g.clearcoatRoughness)}
272
+ `),g.ior!==1.5&&(ie+=`float inputs:ior = ${ze(g.ior)}
273
+ `),g.opacity<1&&(ie+=`float inputs:opacity = ${ze(g.opacity)}
274
+ `),E?ie+=`color3f inputs:emissiveColor${O("EmissiveTexture","rgb")}
275
+ `:(p>0||y>0||M>0)&&(ie+=`color3f inputs:emissiveColor = ${dt(p,y,M)}
276
+ `),T&&(ie+=`normal3f inputs:normal${O("NormalTexture","rgb")}
277
+ `),S&&(ie+=`float inputs:occlusion${O("OcclusionTexture","r")}
278
+ `);let oe="";if(F||W||T||E||S){oe+=`def Shader "PrimvarReader"
279
+ {
280
+ uniform token info:id = "UsdPrimvarReader_float2"
281
+ string inputs:varname = "st"
282
+ float2 outputs:result
283
+ }
284
+ `;let I=(H,N,z,ue)=>{if(!N)return;let he=N.scale?`float4 inputs:scale = ${Pr(N.scale[0],N.scale[1],N.scale[2],N.scale[3])}
285
+ `:"",B=N.bias?`float4 inputs:bias = ${Pr(N.bias[0],N.bias[1],N.bias[2],N.bias[3])}
286
+ `:"";oe+=`def Shader "${H}"
270
287
  {
271
- `;for(let[s,c]of e.entries()){let[l,m,f]=c.color,[h,p,d]=c.emissiveColor,y="";c.clearcoat>0&&(y+=`float inputs:clearcoat = ${Ae(c.clearcoat)}
272
- `,y+=`float inputs:clearcoatRoughness = ${Ae(c.clearcoatRoughness)}
273
- `),c.ior!==1.5&&(y+=`float inputs:ior = ${Ae(c.ior)}
274
- `),c.opacity<1&&(y+=`float inputs:opacity = ${Ae(c.opacity)}
275
- `),(h>0||p>0||d>0)&&(y+=`color3f inputs:emissiveColor = (${Ae(h)}, ${Ae(p)}, ${Ae(d)})
276
- `),a+=`def Material "${s}"
288
+ uniform token info:id = "UsdUVTexture"
289
+ asset inputs:file = @${Rr(N.file)}@
290
+ float2 inputs:st${O("PrimvarReader","result")}
291
+ token inputs:sourceColorSpace = "${z}"
292
+ token inputs:wrapS = "${N.wrapS||"repeat"}"
293
+ token inputs:wrapT = "${N.wrapT||"repeat"}"
294
+ ${he}${B}${ue}}
295
+ `};I("DiffuseTexture",F,"sRGB",`float3 outputs:rgb
296
+ `),I("MetallicRoughnessTexture",W,"raw",`float outputs:g
297
+ float outputs:b
298
+ `),I("NormalTexture",T,"raw",`float3 outputs:rgb
299
+ `),I("EmissiveTexture",E,"sRGB",`float3 outputs:rgb
300
+ `),I("OcclusionTexture",S,"raw",`float outputs:r
301
+ `)}o+=`def Material "${f}"
277
302
  {
278
303
  def Shader "PBRShader"
279
304
  {
280
305
  uniform token info:id = "UsdPreviewSurface"
281
- color3f inputs:diffuseColor = (${Ae(l)}, ${Ae(m)}, ${Ae(f)})
282
- float inputs:metallic = ${Ae(c.metallic)}
283
- float inputs:roughness = ${Ae(c.roughness)}
284
- ${y}token outputs:surface
285
- }
286
- token outputs:surface.connect = </Root/Materials/${s}/PBRShader.outputs:surface>
306
+ ${k}
307
+ ${w}
308
+ ${ie}token outputs:surface
287
309
  }
288
- `}a+=`}
310
+ token outputs:surface${O("PBRShader","surface")}
311
+ ${oe}}
312
+ `}o+=`}
289
313
  def Scope "Meshes"
290
314
  {
291
- `;let u=new Set;for(let s=0;s<t.length;s++){let c=t[s],l=c.positions.length/3,m=1/0,f=1/0,h=1/0,p=-1/0,d=-1/0,y=-1/0;for(let k=0;k<l;k++){let I=c.positions[k*3],L=c.positions[k*3+1],x=c.positions[k*3+2];I<m&&(m=I),I>p&&(p=I),L<f&&(f=L),L>d&&(d=L),x<h&&(h=x),x>y&&(y=x)}isFinite(m)||(m=f=h=-1,p=d=y=1);let v=Math.floor(c.indices.length/3),R=ei(c.materialName,"DefaultMaterial"),b=ei(c.name,`Mesh_${s}`);u.has(b)&&(b=`${b}_${s}`),u.add(b);let w=v>0?v===1?"3":"3, ".repeat(v-1)+"3":"",M=c.xrTraits,P="";if(M){let k=[];M.physics&&M.physics!=="none"&&k.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let I=ve().xrTraitSerializer?.usdLines(M,Po)??[];if(!I.length)for(let L of["grab","billboard","follow","anchor","physics"]){let x=L==="follow"&&typeof M.follow=="object"?M.follow.mode??"head":M[L];x!==void 0&&I.push(`string ${L} = "${Po(x)}"`)}I.length>0&&k.push(`customData = {
315
+ `;let a=(f,g,x)=>{let b=[];g&&b.push('"MaterialBindingAPI"');let v=!!(f?.rigidBody&&f.rigidBody!=="none"&&(typeof f.rigidBody!="object"||f.rigidBody.enabled!==!1)),p=!!(f?.physics&&f.physics!=="none"||v);p&&b.push(...v?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let y=[];if(b.length>0&&y.push(`prepend apiSchemas = [${b.join(", ")}]`),f){let T=Ae().xrTraitSerializer?.usdLines(f,Rr)??[];if(!T.length)for(let E of["grab","billboard","follow","anchor","physics"]){let S=E==="follow"&&typeof f.follow=="object"?f.follow.mode??"head":f[E];S!==void 0&&T.push(`string ${E} = "${Rr(S)}"`)}T.length>0&&y.push(`customData = {
292
316
  dictionary xr = {
293
- ${I.join(`
317
+ ${T.join(`
294
318
  `)}
295
319
  }
296
- }`),k.length>0&&(P=` (
297
- ${k.join(`
320
+ }`)}let M=y.length>0?` (
321
+ ${y.join(`
298
322
  `)}
299
- )`)}if(a+=`def Mesh "${b}"${P}
300
- {
301
- `,M?.physics&&M.physics!=="none"){let k=M.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
302
- bool physics:kinematicEnabled = ${k}
323
+ )`:"",P=x?`uniform token visibility = "invisible"
324
+ `:"";if(p){let T=f?.rigidBody??f?.physics,E=T?.body??T?.mode??T;P+=`bool physics:rigidBodyEnabled = true
325
+ bool physics:kinematicEnabled = ${E==="static"||E==="kinematic"}
303
326
  bool physics:collisionEnabled = true
304
- `}if(c.timeSamples&&c.timeSamples.times.length>0){let k=c.timeSamples,I=k.times.map((g,A)=>{let N=k.translations?.[A]||[0,0,0];return`${Ae(g)}: (${Ae(N[0])}, ${Ae(N[1])}, ${Ae(N[2])})`}).join(", "),L=k.times.map((g,A)=>{let N=k.rotations?.[A]||[0,0,0,1];return`${Ae(g)}: (${Ae(N[3])}, ${Ae(N[0])}, ${Ae(N[1])}, ${Ae(N[2])})`}).join(", "),x=k.times.map((g,A)=>{let N=k.scales?.[A]||[1,1,1];return`${Ae(g)}: (${Ae(N[0])}, ${Ae(N[1])}, ${Ae(N[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${I} }
305
- quatf xformOp:orient.timeSamples = { ${L} }
306
- double3 xformOp:scale.timeSamples = { ${x} }
327
+ `,T?.mass>0&&Number.isFinite(T.mass)&&(P+=`float physics:mass = ${ze(T.mass)}
328
+ `)}let F=Dn(f),W=F?`def SpatialAudio "AudioEmitter"
329
+ {
330
+ ${F.src?`asset inputs:file = @${Rr(F.src)}@
331
+ `:""}uniform token inputs:auralMode = "${F.isGlobal?"nonSpatial":"spatial"}"
332
+ uniform token inputs:playbackMode = "${F.loop?"loopFromStart":"onceFromStart"}"
333
+ double gain = ${ze(F.volume)}
334
+ }
335
+ `:"";return{header:M,body:P,tail:W}},u=f=>{if(f.timeSamples&&f.timeSamples.times.length>0){let y=f.timeSamples,M=(T,E,S)=>y.times.map((O,k)=>`${ze(O)}: ${S(T?.[k]||E)}`).join(", "),P=M(y.translations,[0,0,0],T=>dt(T[0],T[1],T[2])),F=M(y.rotations,[0,0,0,1],T=>{let E=Math.hypot(T[0],T[1],T[2],T[3])||1;return Pr(T[3]/E,T[0]/E,T[1]/E,T[2]/E)}),W=M(y.scales,[1,1,1],T=>dt(T[0],T[1],T[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
336
+ quatf xformOp:orient.timeSamples = { ${F} }
337
+ double3 xformOp:scale.timeSamples = { ${W} }
307
338
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
308
- `}a+=`float3[] extent = [(${Ae(m)}, ${Ae(f)}, ${Ae(h)}), (${Ae(p)}, ${Ae(d)}, ${Ae(y)})]
309
- int[] faceVertexCounts = [${w}]
310
- int[] faceVertexIndices = [${Sa(c.indices)}]
311
- point3f[] points = [${ko(c.positions)}]
312
- `,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${ko(c.normals)}] (
339
+ `}let g=[],x="",b=f.translation;b&&(Math.abs(b[0])>1e-7||Math.abs(b[1])>1e-7||Math.abs(b[2])>1e-7)&&(x+=`double3 xformOp:translate = ${dt(b[0],b[1],b[2])}
340
+ `,g.push('"xformOp:translate"'));let v=f.rotation;if(v){let y=Math.hypot(v[0],v[1],v[2],v[3])||1,M=v[0]/y,P=v[1]/y,F=v[2]/y,W=v[3]/y;(1-Math.abs(W)>1e-7||Math.hypot(M,P,F)>1e-7)&&(x+=`quatf xformOp:orient = ${Pr(W,M,P,F)}
341
+ `,g.push('"xformOp:orient"'))}let p=f.scale;return p&&(Math.abs(p[0]-1)>1e-7||Math.abs(p[1]-1)>1e-7||Math.abs(p[2]-1)>1e-7)&&(x+=`float3 xformOp:scale = ${dt(p[0],p[1],p[2])}
342
+ `,g.push('"xformOp:scale"')),g.length>0&&(x+=`uniform token[] xformOpOrder = [${g.join(", ")}]
343
+ `),x},h=f=>{let g=f.positions.length/3,x=1/0,b=1/0,v=1/0,p=-1/0,y=-1/0,M=-1/0;for(let E=0;E<g;E++){let S=f.positions[E*3],O=f.positions[E*3+1],k=f.positions[E*3+2];S<x&&(x=S),S>p&&(p=S),O<b&&(b=O),O>y&&(y=O),k<v&&(v=k),k>M&&(M=k)}isFinite(x)||(x=b=v=-1,p=y=M=1);let P=Math.floor(f.indices.length/3),F=Sr(f.materialName,"DefaultMaterial"),W=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",T=`float3[] extent = [${dt(x,b,v)}, ${dt(p,y,M)}]
344
+ int[] faceVertexCounts = [${W}]
345
+ int[] faceVertexIndices = [${nl(f.indices)}]
346
+ point3f[] points = [${Vn(f.positions)}]
347
+ `;return f.normals&&f.normals.length===f.positions.length&&(T+=`normal3f[] normals = [${Vn(f.normals)}] (
313
348
  interpolation = "vertex"
314
349
  )
315
- `),c.uvs&&c.uvs.length===l*2&&(a+=`texCoord2f[] primvars:st = [${Aa(c.uvs,l)}] (
350
+ `),f.uvs&&f.uvs.length===g*2&&(T+=`texCoord2f[] primvars:st = [${il(f.uvs,g)}] (
316
351
  interpolation = "vertex"
317
352
  )
318
- `),a+=`rel material:binding = </Root/Materials/${R}>
319
- }
320
- `}return a+=`}
353
+ `),T+=`rel material:binding = </Root/Materials/${F}>
354
+ `,T},m=new Set,c=[];for(let f=e.length-1;f>=0;f--)c.push({node:e[f],siblings:m});let d=0;for(;c.length>0;){let f=c.pop();if(f.close){o+=`}
355
+ `;continue}let{node:g,siblings:x}=f,b=!!(g.isXform||g.positions.length===0),v=_n(x,Sr(g.name,b?`Group_${d}`:`Mesh_${d}`));d++;let p=g.children||[];if(b){let y=a(g.xrTraits,!1,g.invisible);o+=`def Xform "${v}"${y.header}
356
+ {
357
+ ${y.body}${u(g)}${y.tail}`,c.push({close:!0});let M=new Set;for(let P=p.length-1;P>=0;P--)c.push({node:p[P],siblings:M})}else if(p.length>0){let y=a(g.xrTraits,!1,g.invisible),M=`${v}_mesh`;o+=`def Xform "${v}"${y.header}
358
+ {
359
+ ${y.body}${u(g)}${y.tail}`,o+=`def Mesh "${M}" (
360
+ prepend apiSchemas = ["MaterialBindingAPI"]
361
+ )
362
+ {
363
+ ${h(g)}}
364
+ `,c.push({close:!0});let P=new Set([M]);for(let F=p.length-1;F>=0;F--)c.push({node:p[F],siblings:P})}else{let y=a(g.xrTraits,!0,g.invisible);o+=`def Mesh "${v}"${y.header}
365
+ {
366
+ ${y.body}${u(g)}${h(g)}${y.tail}}
367
+ `}}return o+=`}
321
368
  }
322
- `,a}function Do(t,e){if(t&&typeof t.traverse=="function"){let i=Ma(t,e);return ti(i)}let n=ht(t),r=No(n);return ti(r)}var Hn=null;function Uo(t){if(!Hn){Hn=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;Hn[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=Hn[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function ni(t){let e=[],n=0,r=[];for(let l of t){let m=Xn(l.filename),f=Uo(l.data),h=l.data.length,p=30+m.length,d=n+p,y=0,v=d%64;v!==0&&(y=64-v);let R=new Uint8Array(p+y),b=new DataView(R.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,f,!0),b.setUint32(18,h,!0),b.setUint32(22,h,!0),b.setUint16(26,m.length,!0),b.setUint16(28,y,!0),R.set(m,30),y>0&&R.fill(0,30+m.length),e.push({offset:n,size:h,crc:f,filenameBytes:m,entry:l}),r.push(R),r.push(l.data),n+=R.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,a=new Uint8Array(22),u=new DataView(a.buffer);u.setUint32(0,101010256,!0),u.setUint16(4,0,!0),u.setUint16(6,0,!0),u.setUint16(8,e.length,!0),u.setUint16(10,e.length,!0),u.setUint32(12,o,!0),u.setUint32(16,i,!0),u.setUint16(20,0,!0),r.push(a),n+=22;let s=new Uint8Array(n),c=0;for(let l of r)s.set(l,c),c+=l.length;return s}function Zt(t){let e=Do(t),n=Xn(e);return ni([{filename:"model.usda",data:n}])}function cn(t){let e=ht(t),n=No(e),r=ti(n),i=Xn(r);return ni([{filename:"model.usda",data:i}])}function un(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Zt(t):cn(t)}function Qt(t){let e=un(t);return new Blob([e],{type:"model/vnd.usdz+zip"})}function Rt(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function Ra(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function ri(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Ea(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Oo(t){let e=ri(t);if(!e)return null;let n=e.target;return{target:Ra(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:Rt(e.radius,.01,50,.5),speed:Rt(e.speed,-20,20,.5),height:Rt(e.height,-10,10,0),phase:Rt(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function ii(t,e){let n=Ea(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 oi(t){if(!t||typeof t=="number"&&!(t>0&&Number.isFinite(t)))return null;let e=t===!0?{}:typeof t=="number"?{strength:t}:ri(t);if(!e||e.enabled===!1)return null;let n=Rt(e.strength??e.intensity,0,5,.35);return n>0?{enabled:!0,strength:n,threshold:Rt(e.threshold,0,4,.8),radius:Rt(e.radius,0,2,.5)}:null}function Wn(t){if(!t)return null;let e=t===!0?{}:typeof t=="string"?{color:t}:ri(t);if(!e||e.enabled===!1)return null;let n=e.thickness??e.width;return{enabled:!0,color:ii(e.color,"#38bdf8"),thickness:Rt(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:e.pulse===!0}}var jn=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}},Ue=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,u=n.y,s=n.z;return this.x=i*s-o*u,this.y=o*a-r*s,this.z=r*u-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)}lerp(e,n){return this.lerpVectors(this,e,n)}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this}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}},qn=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}},dn=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}},hn=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),u=Math.cos(i/2),s=Math.cos(o/2),c=Math.sin(r/2),l=Math.sin(i/2),m=Math.sin(o/2);return this._x=c*u*s+a*l*m,this._y=a*l*s-c*u*m,this._z=a*u*m+c*l*s,this._w=a*u*s-c*l*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this.set(e.x*i,e.y*i,e.z*i,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,n){let r=e.dot(n)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*n.z-e.z*n.y,e.z*n.x-e.x*n.z,e.x*n.y-e.y*n.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,a=e.w,u=n.x,s=n.y,c=n.z,l=n.w;return this._x=r*l+a*u+i*c-o*s,this._y=i*l+a*s+o*u-r*c,this._z=o*l+a*c+r*s-i*u,this._w=a*l-r*u-i*s-o*c,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Pt=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 Je(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 Le(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return $t(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 Ue(0,0,0),r=new Ue(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}},Kn=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 Ne(this.elements,e.elements),this}},et=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)}},Xo={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)},$e=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}},Yn=class extends $e{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Zn=class extends $e{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},Qn=class extends $e{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Ye=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 $e)this.index=e;else if(Array.isArray(e)){let n=0;for(let r of e)r>n&&(n=r);this.index=new $e(new(n>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new $e(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 Ue,o=new Ue,a=new Ue,u=new Ue,s=new Ue;if(this.index){let c=this.index.array;for(let l=0;l<c.length;l+=3){let m=c[l],f=c[l+1],h=c[l+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(f),e.getY(f),e.getZ(f)),a.set(e.getX(h),e.getY(h),e.getZ(h)),u.subVectors(a,o),s.subVectors(i,o),u.cross(s).normalize();for(let p of[m,f,h])r[p*3]+=u.x,r[p*3+1]+=u.y,r[p*3+2]+=u.z}}else for(let c=0;c<n;c+=3){i.set(e.getX(c),e.getY(c),e.getZ(c)),o.set(e.getX(c+1),e.getY(c+1),e.getZ(c+1)),a.set(e.getX(c+2),e.getY(c+2),e.getZ(c+2)),u.subVectors(a,o),s.subVectors(i,o),u.cross(s).normalize();for(let l=0;l<3;l++)r[(c+l)*3]=u.x,r[(c+l)*3+1]=u.y,r[(c+l)*3+2]=u.z}for(let c=0;c<n;c++){let l=r[c*3],m=r[c*3+1],f=r[c*3+2],h=Math.hypot(l,m,f)||1;r[c*3]=l/h,r[c*3+1]=m/h,r[c*3+2]=f/h}return this.setAttribute("normal",new $e(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new $e(e,3)),this.setAttribute("normal",new $e(n,3)),this.setAttribute("uv",new $e(r,2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new Ue(1/0,1/0,1/0),r=new Ue(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),a=e.getY(i),u=e.getZ(i);o<n.x&&(n.x=o),a<n.y&&(n.y=a),u<n.z&&(n.z=u),o>r.x&&(r.x=o),a>r.y&&(r.y=a),u>r.z&&(r.z=u)}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 a=0;a<o.count;a++)o.setXYZ(a,o.getX(a)-n,o.getY(a)-r,o.getZ(a)-i);this.computeBoundingBox()}return this}dispose(){}},pn=class extends Ye{constructor(e=1,n=1,r=1){super();let i=e/2,o=n/2,a=r/2,u=[-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],s=[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],c=[],l=[];for(let m=0;m<6;m++){let f=m*4;c.push(0,0,1,0,1,1,0,1),l.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(u,s,c,l)}},Jn=class extends Ye{constructor(e=1,n=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let o=[],a=[],u=[],s=[];for(let c=0;c<=i;c++){let l=c/i;for(let m=0;m<=r;m++){let f=m/r;if(o.push((f-.5)*e,(.5-l)*n,0),a.push(0,0,1),u.push(f,1-l),c>0&&m>0){let h=(r+1)*c+m-1,p=h-(r+1);s.push(p,h,p+1,h,h+1,p+1)}}}this.setFromBuffers(o,a,u,s)}},bn=class extends Ye{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=[],u=[];for(let s=0;s<=r;s++){let c=s/r;for(let l=0;l<=n;l++){let m=l/n,f=m*Math.PI*2,h=c*Math.PI,p=-Math.cos(f)*Math.sin(h),d=Math.cos(h),y=Math.sin(f)*Math.sin(h);if(i.push(e*p,e*d,e*y),o.push(p,d,y),a.push(m,1-c),s>0&&l>0){let v=(n+1)*s+l,R=v-(n+1),b=R-1,w=v-1;s!==1&&u.push(R,b,v),s!==r&&u.push(b,w,v)}}}this.setFromBuffers(i,o,a,u)}},_t=class extends Ye{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let o=[],a=[],u=[],s=[],c=r/2;for(let l=0;l<=1;l++){let m=l,f=l===0?e:n,h=l===0?c:-c;for(let p=0;p<=i;p++){let d=p/i,y=d*Math.PI*2,v=Math.sin(y),R=Math.cos(y);o.push(f*v,h,f*R),a.push(v,0,R),u.push(d,1-m)}}for(let l=0;l<i;l++){let m=l,f=l+i+1,h=l+i+2,p=l+1;s.push(m,f,p,f,h,p)}if(e>0){let l=o.length/3;o.push(0,c,0),a.push(0,1,0),u.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let h=f/i*Math.PI*2,p=Math.sin(h),d=Math.cos(h);o.push(e*p,c,e*d),a.push(0,1,0),u.push(d*.5+.5,p*.5+.5)}for(let f=0;f<i;f++)s.push(l,m+f,m+f+1)}if(n>0){let l=o.length/3;o.push(0,-c,0),a.push(0,-1,0),u.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let h=f/i*Math.PI*2,p=Math.sin(h),d=Math.cos(h);o.push(n*p,-c,n*d),a.push(0,-1,0),u.push(d*.5+.5,1-(p*.5+.5))}for(let f=0;f<i;f++)s.push(l,m+f+1,m+f)}this.setFromBuffers(o,a,u,s)}},er=class extends _t{constructor(e=1,n=1,r=16){super(0,e,n,r)}},tr=class extends Ye{constructor(e=1,n=.4,r=12,i=48,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let a=[],u=[],s=[],c=[];for(let l=0;l<=r;l++){let m=l/r*Math.PI*2,f=Math.cos(m),h=Math.sin(m);for(let p=0;p<=i;p++){let d=p/i*o,y=Math.cos(d),v=Math.sin(d);if(a.push((e+n*f)*y,(e+n*f)*v,n*h),u.push(f*y,f*v,h),s.push(p/i,l/r),l>0&&p>0){let R=(i+1)*l+p-1,b=R-(i+1);c.push(R,b,R+1,b,b+1,R+1)}}}this.setFromBuffers(a,u,s,c)}},nr=class extends Ye{constructor(e=1,n=.4,r=64,i=8,o=2,a=3){super(),r=Math.floor(r),i=Math.floor(i);let u=[],s=[],c=[],l=[],m=new Ue,f=new Ue,h=new Ue,p=new Ue,d=new Ue;function y(b,w){let M=Math.cos(w),P=Math.sin(w),k=a/o*w,I=e*(2+Math.cos(k))*.5;b.set(I*M,I*P,e*Math.sin(k)*.5)}let v=[];for(let b=0;b<=i;++b){let w=b/i*Math.PI*2;v.push(-n*Math.cos(w),n*Math.sin(w),b/i)}for(let b=0;b<=r;++b){let w=b/r,M=w*o*Math.PI*2;y(m,M),y(f,M+.01),h.subVectors(f,m).normalize(),p.addVectors(m,f).normalize(),d.crossVectors(h,p).normalize(),p.crossVectors(d,h).normalize();for(let P=0;P<=i;++P){let k=P*3,I=v[k],L=v[k+1],x=v[k+2],g=I*p.x+L*d.x,A=I*p.y+L*d.y,N=I*p.z+L*d.z;u.push(m.x+g,m.y+A,m.z+N);let _=Math.hypot(g,A,N)||1;s.push(g/_,A/_,N/_),c.push(w,x)}}let R=i+1;for(let b=1;b<=r;b++){let w=R*(b-1),M=w+R;for(let P=1;P<=i;P++){let k=w+(P-1),I=M+(P-1),L=M+P,x=w+P;l.push(k,I,x,I,L,x)}}this.setFromBuffers(u,s,c,l)}},yn=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(){}},rr=class{load(e,n){let r=new yn(e);return n?.(r),r}};function We(t,e){return t!==void 0?Number(t):e}function si(t,e){return t!==void 0?!!t:e}var at=class{constructor(e={}){this.name=e.name||"",this.color=new et(e.color!==void 0?e.color:16777215),this.emissive=new et(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=We(e.emissiveIntensity,1),this.roughness=We(e.roughness,.5),this.metalness=We(e.metalness,.1),this.opacity=We(e.opacity,1),this.transparent=si(e.transparent,!1),this.wireframe=si(e.wireframe,!1),this.side=We(e.side,2),this.doubleSided=si(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=We(e.clearcoat,0),this.clearcoatRoughness=We(e.clearcoatRoughness,0),this.sheen=We(e.sheen,0),this.sheenColor=new et(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=We(e.sheenRoughness,0),this.transmission=We(e.transmission,0),this.thickness=We(e.thickness,0),this.attenuationColor=new et(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=We(e.attenuationDistance,1/0),this.ior=We(e.ior,1.5),this.dispersion=We(e.dispersion,0),this.iridescence=We(e.iridescence,0),this.iridescenceIOR=We(e.iridescenceIOR,1.3)}dispose(){}},kt=class extends at{},ir=class extends at{},or=class extends at{},sr=class extends at{},ar=class extends at{},tt=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 Ue,this.rotation=new dn,this.quaternion=new hn,this.scale=new Ue(1,1,1),this.matrix=new Pt,this.matrixWorld=new Pt,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){Wo(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 Ue(e,n,r);this.updateMatrixWorld(!0);let o=new Pt;o.lookAt(this.position,i,new Ue(0,1,0));let a=o.elements,u=a[0],s=a[4],c=a[8],l=a[1],m=a[5],f=a[9],h=a[2],p=a[6],d=a[10],y=u+m+d;if(y>0){let v=.5/Math.sqrt(y+1);this.quaternion.set((p-f)*v,(c-h)*v,(l-s)*v,.25/v)}}},cr=class extends tt{},Nt=class extends tt{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Ye?n:n?(Ze("unsupported geometry","BoxGeometry"),new pn(.5,.5,.5)):new Ye,this.material=i instanceof at?i:i?(Ze("unsupported material","MeshStandardMaterial"),new kt({color:13421772})):new kt}};function Wo(t){let e=ve().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var gn=1e4,xn=class extends Nt{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>gn)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${gn})`);this.count=Math.floor(o);let a=new Float32Array(this.count*16);for(let u=0;u<this.count;u++){let s=u*16;a[s]=1,a[s+5]=1,a[s+10]=1,a[s+15]=1}this.instanceMatrix=new $e(a,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,a=i*16;if(!(a+16>o.length))for(let u=0;u<16;u++){let s=Number(r.elements[u]);o[a+u]=Number.isFinite(s)?s:u%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,a=i*16;if(!(a+16>o.length))for(let u=0;u<16;u++)r.elements[u]=o[a+u]}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 u=new Float32Array(this.count*3);u.fill(1),this.instanceColor=new $e(u,3)}let o=this.instanceColor.array,a=i*3;o[a]=Number.isFinite(r.r)?r.r:1,o[a+1]=Number.isFinite(r.g)?r.g:1,o[a+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,a=i*3;r.setRGB(o[a],o[a+1],o[a+2])}dispose(){}},Dt=class extends tt{constructor(e=16777215,n=1){super(),this.color=new et(e),this.intensity=Number(n),this.type="directional"}},vn=class extends Dt{constructor(e,n){super(e,n),this.type="ambient"}},ur=class extends Dt{constructor(n,r){super(n,r);this.target=new tt;this.type="directional"}},Tn=class extends Dt{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}},wn=class extends tt{},lr=class extends wn{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Ue(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},Mn=class extends tt{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return st.validate(this),Yt(this)}toGLB(){return st.validate(this),an(this)}toUSDZ(){return st.validate(this),Zt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Nt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},ai=Yt,ci=an,$o=Zt;var st=class{static validate(e){let n=0,r=0,i=0,o=new Set,a=(s,c,l)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${s} (${c}). Found: ${l}`)},u=(s,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${s} count (${String(c)}), which cannot be bounds-checked.`);return c};e.traverse(s=>{if(Wo(s),s instanceof Nt||s.geometry?.attributes?.position?.count){if(i++,i>1e3&&a("MESHES",1e3,i),s instanceof xn){let l=u("instance",s.count);(l<0||l>gn)&&a("INSTANCES",gn,l)}let c=s.geometry;if(c){let l=0;if(c.attributes.position&&(l=u("vertex",c.attributes.position.count),n+=l,n>1e5&&a("VERTICES",1e5,n)),c.index){let m=u("index",c.index.count);r+=m,r>3e5&&a("INDICES",3e5,r);let f=c.index.array;if(f&&l>0){let h=Math.min(m,f.length);for(let p=0;p<h;p++){let d=f[p];if(!Number.isFinite(d)||d<0||d>=l)throw new Error(`SecurityError: Index buffer value (${String(d)}) out of vertex bounds [0, ${l}).`)}}}}if(s.material){let l=s.material;l.map&&o.add(l.map),l.normalMap&&o.add(l.normalMap),l.roughnessMap&&o.add(l.roughnessMap)}}}),o.size>16&&a("TEXTURES",16,o.size);for(let s of o){let c=s,l=c.image,m=Number(l?.width??c.width??0)||0,f=Number(l?.height??c.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(f)||m>2048||f>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(m,f))}}},fr=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 et(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){st.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[u,s]of o.entries())a[u]=Array.from(s);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let o=ai(e),a=ci(e),u=(o.lights||[]).map(s=>({type:s.type,color:s.color,intensity:s.intensity,position:s.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:u,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 Fo(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var mr=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=Fo(),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=Fo();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function _a(){}var fn=new Proxy(_a,{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:fn},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>fn,construct:()=>fn}),Vo=(()=>{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 Jt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Lt(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Jt());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 Bo,ln;function jo(t){if(!Lt(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(ln===void 0||Bo!==n){Bo=n;try{ln=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Lt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{ln=null}}return ln?ln.createScriptURL(t):t}function La(t){ve().sandboxEngineSrc=t}function ui(){let t=ve().sandboxEngineSrc;if(t)return t;if(Vo)return Vo;try{if(typeof document>"u")return null;let e=Jt(),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)&&Lt(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ia(){let t=ui();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(!Lt(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,Jt()).href}function Ca(t){ve().sandboxIframeSrc=t}function qo(){let t=ve().sandboxIframeSrc;if(t)return t;let e=ui();if(!e||!Lt(e))return null;let n=new URL(e,Jt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Pa(){let t=qo();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(!Lt(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,Jt()).href}function ka(t){ve().allowClientScripts=t}function Ko(){return!!ve().allowClientScripts}function Na(t){if(!Lt(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,Jt()).href}var Da=["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 Ua(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,a=t.allowClientScripts,u=t.revoked,s=n.postMessage.bind(n);function c(P){s({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(L){if(L!==i&&(!o||L!==o))throw new TypeError("Disallowed worker importScripts URL");return L}};a&&(k.createScript=function(L){return String(L)});let I=n.trustedTypes.createPolicy("three-live#worker-boot",k);P=I.createScriptURL(i),o&&(m=I.createScriptURL(o)),a&&typeof I.createScript=="function"&&(f=I.createScript.bind(I))}catch{}l(P)}catch(P){c('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"){c('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<u.length;P++){let k=u[P],I=n;for(;I&&I!==Object.prototype;){if(I!==n)try{delete I[k]}catch{}try{Object.defineProperty(I,k,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{I=Object.getPrototypeOf(I)}catch{break}}}let p=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:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{d=Object.getPrototypeOf(d)}catch{break}}let y=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],v=!1;function R(P,k){if(P.type==="3D_MODEL_READY"){if(v)return;v=!0}P.nonce=r,k&&k.length?s(P,k):s(P)}let b=function(P,k){if(!P||y.indexOf(P.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+y.join(", ")+").");R(P,k)},w=n;for(;w&&w!==Object.prototype;){if(w===n||Object.prototype.hasOwnProperty.call(w,"postMessage"))try{Object.defineProperty(w,"postMessage",{value:b,writable:!1,configurable:!1})}catch{}try{w=Object.getPrototypeOf(w)}catch{break}}let M=!1;n.onmessage=function(P){let k=P&&P.data;if(!(!k||k.nonce!==r)&&!(k.type!=="EXECUTE"&&k.type!=="EXECUTE_URL")&&!M){M=!0;try{let I=new h.Scene,L=new h.PerspectiveCamera(60,1,.1,1e3),x=new h.WebGLRenderer({isSandboxed:!0});if(k.type==="EXECUTE_URL"){if(!o||k.scriptUrl!==o||typeof l!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let g=m||o,A=l;if(l=null,m=null,n.THREE=h,n.scene=I,n.camera=L,n.renderer=x,A(g),typeof n.__THREE_LIVE_SCENE__=="function"){let N=n.__THREE_LIVE_SCENE__(h,I,L,x);N&&typeof N.toGLB=="function"&&(I=N)}else n.scene&&typeof n.scene.toGLB=="function"&&(I=n.scene)}else{if(!a){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let g=f?(0,eval)(f(`(function (THREE, scene, camera, renderer) {
369
+ `,o}var Er=null;function gi(e){if(!Er){Er=new Uint32Array(256);for(let r=0;r<256;r++){let i=r;for(let n=0;n<8;n++)i=i&1?3988292384^i>>>1:i>>>1;Er[r]=i}}let t=4294967295;for(let r=0;r<e.length;r++)t=Er[(t^e[r])&255]^t>>>8;return(t^4294967295)>>>0}function al(e){let t=[],r=0,i=[];for(let h of e){let m=di(h.filename),c=gi(h.data),d=h.data.length,f=30+m.length,g=(r+f)%64,x=g!==0?64-g:0;x>0&&x<4&&(x+=64);let b=new Uint8Array(f+x),v=new DataView(b.buffer);v.setUint32(0,67324752,!0),v.setUint16(4,20,!0),v.setUint32(14,c,!0),v.setUint32(18,d,!0),v.setUint32(22,d,!0),v.setUint16(26,m.length,!0),v.setUint16(28,x,!0),b.set(m,30),x>=4&&(v.setUint16(f,6534,!0),v.setUint16(f+2,x-4,!0)),t.push({offset:r,size:d,crc:c,filenameBytes:m,entry:h}),i.push(b,h.data),r+=b.length+h.data.length}let n=r;for(let h of t){let m=new Uint8Array(46+h.filenameBytes.length),c=new DataView(m.buffer);c.setUint32(0,33639248,!0),c.setUint16(4,20,!0),c.setUint16(6,20,!0),c.setUint32(16,h.crc,!0),c.setUint32(20,h.size,!0),c.setUint32(24,h.size,!0),c.setUint16(28,h.filenameBytes.length,!0),c.setUint32(42,h.offset,!0),m.set(h.filenameBytes,46),i.push(m),r+=m.length}let s=r-n,l=new Uint8Array(22),o=new DataView(l.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),i.push(l),r+=22;let a=new Uint8Array(r),u=0;for(let h of i)a.set(h,u),u+=h.length;return a}function Un(e){let t=[{filename:"model.usda",data:di(sl(e))}],r=new Set(["model.usda"]),i=[...e];for(;i.length>0;){let n=i.pop();for(let s of n.textures||[])s?.file&&s.data?.byteLength&&!r.has(s.file)&&(r.add(s.file),t.push({filename:s.file,data:s.data}));if(n.children)for(let s=n.children.length-1;s>=0;s--)i.push(n.children[s])}return al(t)}function Nr(e){return Un(rl(e))}function yi(e){return Un(Fn(tr(e)))}function bi(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():yi(e)}function xi(e){let t=bi(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function wt(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function ol(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function vi(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function ll(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function ul(e){let t=vi(e);if(!t)return null;let r=t.target;return{target:ol(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:wt(t.radius,.01,50,.5),speed:wt(t.speed,-20,20,.5),height:wt(t.height,-10,10,0),phase:wt(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var hl=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],cl=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Nu=new Set(hl),Cu=new Set(cl);function On(e,t){let r=ll(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function Bn(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:vi(e);if(!t||t.enabled===!1)return null;let r=wt(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:wt(t.threshold,0,4,.8),radius:wt(t.radius,0,2,.5)}:null}function Mi(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:vi(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:On(t.color,"#38bdf8"),thickness:wt(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}var ut=class ro{constructor(t=0,r=0){this.x=Number(t),this.y=Number(r)}set(t,r){return this.x=Number(t),this.y=Number(r),this}clone(){return new ro(this.x,this.y)}copy(t){return this.set(t.x,t.y)}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},xe=class io{constructor(t=0,r=0,i=0){this.x=Number(t),this.y=Number(r),this.z=Number(i)}set(t,r,i){return this.x=Number(t),this.y=Number(r),this.z=Number(i),this}clone(){return new io(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,r){return this.set(t.x+r.x,t.y+r.y,t.z+r.z)}sub(t){return this.subVectors(this,t)}subVectors(t,r){return this.set(t.x-r.x,t.y-r.y,t.z-r.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,r){return this.set(this.x+t.x*r,this.y+t.y*r,this.z+t.z*r)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,r){let i=t.x,n=t.y,s=t.z,l=r.x,o=r.y,a=r.z;return this.set(n*a-s*o,s*l-i*a,i*o-n*l)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,r){return this.lerpVectors(this,t,r)}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this}applyMatrix4(t){let r=this.x,i=this.y,n=this.z,s=t.elements,l=1/(s[3]*r+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*r+s[4]*i+s[8]*n+s[12])*l,this.y=(s[1]*r+s[5]*i+s[9]*n+s[13])*l,this.z=(s[2]*r+s[6]*i+s[10]*n+s[14])*l,this}},zn=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},wi=class no{constructor(t=0,r=0,i=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,r,i,n=this.order){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new no(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Cr=class so{constructor(t=0,r=0,i=0,n=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,r,i,n){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new so(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,r=!0){let i=t.x,n=t.y,s=t.z,l=Math.cos(i/2),o=Math.cos(n/2),a=Math.cos(s/2),u=Math.sin(i/2),h=Math.sin(n/2),m=Math.sin(s/2);return this._x=u*o*a+l*h*m,this._y=l*h*a-u*o*m,this._z=l*o*m+u*h*a,this._w=l*o*a-u*h*m,r&&this._onChangeCallback?.(),this}setFromAxisAngle(t,r){let i=r/2,n=Math.sin(i);return this.set(t.x*n,t.y*n,t.z*n,Math.cos(i))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,r){let i=t.dot(r)+1;return i<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*r.z-t.z*r.y,t.z*r.x-t.x*r.z,t.x*r.y-t.y*r.x,i).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,r){let i=t.x,n=t.y,s=t.z,l=t.w,o=r.x,a=r.y,u=r.z,h=r.w;return this._x=i*h+l*o+n*u-s*a,this._y=n*h+l*a+s*o-i*u,this._z=s*h+l*u+i*a-n*o,this._w=l*h-i*o-n*a-s*u,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Ot=class ao{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new ao;return t.copy(this),t}compose(t,r,i){return Qt(this.elements,[r.x,r.y,r.z,r.w],[t.x,t.y,t.z],[i.x,i.y,i.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,r){return ke(this.elements,t.elements,r.elements),this}lookAt(t,r,i){return xr(this.elements,[t.x,t.y,t.z],[r.x,r.y,r.z],[i.x,i.y,i.z]),this}makeRotationFromQuaternion(t){let r=new xe(0,0,0),i=new xe(1,1,1);return this.compose(r,t,i)}makeTranslation(t,r,i){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(r),this.elements[14]=Number(i),this}makeScale(t,r,i){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(r),this.elements[10]=Number(i),this}},$n=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 Ke(this.elements,e.elements),this}},Ye=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,Lr=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,Hn={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},gt=class oo{constructor(t,r,i){this.r=1,this.g=1,this.b=1,t!==void 0&&(r!==void 0&&i!==void 0?this.setRGB(t,r,i):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let r=t.trim().toLowerCase();if(r[0]==="#"){let i=r.slice(1);i.length===3||i.length===4?i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i.length===8&&(i=i.slice(0,6));let n=parseInt(i,16);i.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(r in Hn)this.setHex(Hn[r]);else if(r.startsWith("hsl")){let i=/^hsla?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);i&&i.length>=3&&this.setHSL((parseFloat(i[0])||0)/360,(parseFloat(i[1])||0)/100,(parseFloat(i[2])||0)/100)}else{let i=/^rgba?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);if(i&&i.length>=3){let n=s=>Ye(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(i[0]),n(i[1]),n(i[2]))}}return this}setHSL(t,r,i){if(t=((Number(t)||0)%1+1)%1,r=Math.max(0,Math.min(1,Number(r)||0)),i=Math.max(0,Math.min(1,Number(i)||0)),r===0){let o=Ye(i);return this.setRGB(o,o,o)}let n=i<=.5?i*(1+r):i+r-i*r,s=2*i-n,l=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(Ye(l(t+1/3)),Ye(l(t)),Ye(l(t-1/3)))}lerp(t,r){return this.lerpColors(this,t,r)}lerpColors(t,r,i){let n=Number(i)||0;return this.setRGB(t.r+(r.r-t.r)*n,t.g+(r.g-t.g)*n,t.b+(r.b-t.b)*n)}multiplyScalar(t){let r=Number(t)||0;return this.setRGB(this.r*r,this.g*r,this.b*r)}setScalar(t){let r=Number(t)||0;return this.setRGB(r,r,r)}setHex(t){let r=Math.floor(t);return this.setRGB(Ye((r>>16&255)/255),Ye((r>>8&255)/255),Ye((r&255)/255))}setRGB(t,r,i){return this.r=Number(t),this.g=Number(r),this.b=Number(i),this}convertSRGBToLinear(){return this.setRGB(Ye(this.r),Ye(this.g),Ye(this.b))}convertLinearToSRGB(){return this.setRGB(Lr(this.r),Lr(this.g),Lr(this.b))}getHex(){let t=r=>Math.round(Lr(Math.max(0,Math.min(1,r)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new oo(this.r,this.g,this.b)}},Wn={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,r)=>Math.max(t,Math.min(r,e)),lerp:(e,t,r)=>e+(t-e)*r,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},He=class lo{constructor(t,r){if(this.needsUpdate=!1,typeof r!="number"||!Number.isInteger(r)||r<1||r>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(r)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=r;let i=this.array?this.array.length:0;if(!Number.isFinite(i)||i<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(i)}`);this.count=Math.floor(i/r)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,r){return this.array[t*this.itemSize]=r,this.needsUpdate=!0,this}setY(t,r){return this.array[t*this.itemSize+1]=r,this.needsUpdate=!0,this}setZ(t,r){return this.array[t*this.itemSize+2]=r,this.needsUpdate=!0,this}setXYZ(t,r,i,n){let s=t*this.itemSize;return this.array[s]=r,this.array[s+1]=i,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new lo(new t(this.array),this.itemSize)}},Gn=class extends He{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},jn=class extends He{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},qn=class extends He{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},Ue=class uo{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,r){return this.attributes[t]=r,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof He)this.index=t;else if(Array.isArray(t)){let r=0;for(let i of t)i>r&&(r=i);this.index=new He(new(r>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new He(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let r=!1;if(typeof r=="function"){let a=r(t.array,this.index?.array);return this.setAttribute("normal",new He(a,3)),this}let i=t.count,n=t.array,s=new Float32Array(i*3),l=this.index?.array,o=l?l.length:i;for(let a=0;a<o;a+=3){let u=(l?l[a]:a)*3,h=(l?l[a+1]:a+1)*3,m=(l?l[a+2]:a+2)*3,c=n[h],d=n[h+1],f=n[h+2],g=n[m]-c,x=n[m+1]-d,b=n[m+2]-f,v=n[u]-c,p=n[u+1]-d,y=n[u+2]-f,M=x*y-b*p,P=b*v-g*y,F=g*p-x*v;s[u]+=M,s[u+1]+=P,s[u+2]+=F,s[h]+=M,s[h+1]+=P,s[h+2]+=F,s[m]+=M,s[m+1]+=P,s[m+2]+=F}for(let a=0;a<i*3;a+=3){let u=s[a],h=s[a+1],m=s[a+2],c=Math.hypot(u,h,m)||1;s[a]=u/c,s[a+1]=h/c,s[a+2]=m/c}return this.setAttribute("normal",new He(s,3)),this}setFromBuffers(t,r,i,n){this.setAttribute("position",new He(t,3)),this.setAttribute("normal",new He(r,3)),this.setAttribute("uv",new He(i,2)),this.setIndex(n)}setFromPoints(t){let r=[];if(Array.isArray(t))for(let i of t)r.push(Number(i?.x)||0,Number(i?.y)||0,Number(i?.z)||0);return this.setAttribute("position",new He(r,3))}computeBoundingBox(){let t=this.attributes.position,r=new xe(1/0,1/0,1/0),i=new xe(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let n=0;n<t.count;n++){let s=t.getX(n),l=t.getY(n),o=t.getZ(n);s<r.x&&(r.x=s),l<r.y&&(r.y=l),o<r.z&&(r.z=o),s>i.x&&(i.x=s),l>i.y&&(i.y=l),o>i.z&&(i.z=o)}else r.set(0,0,0),i.set(0,0,0);return this.boundingBox={min:r,max:i},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,r){let i=this.attributes.position;if(i){let n=i.array;for(let s=0;s<n.length;s+=3)t(n,s);i.needsUpdate=!0,r&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,r=0,i=0){return this._xform((n,s)=>{n[s]+=t,n[s+1]+=r,n[s+2]+=i})}scale(t=1,r=1,i=1){return this._xform((n,s)=>{n[s]*=t,n[s+1]*=r,n[s+2]*=i},!0)}_rot(t,r,i){let n=Math.cos(i),s=Math.sin(i);for(let l of[this.attributes.position,this.attributes.normal]){if(!l)continue;let o=l.array;for(let a=0;a<o.length;a+=3){let u=o[a+t],h=o[a+r];o[a+t]=u*n-h*s,o[a+r]=u*s+h*n}l.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let r=this.attributes.position;if(r&&t?.elements){let i=new xe;for(let n=0;n<r.count;n++)i.set(r.getX(n),r.getY(n),r.getZ(n)).applyMatrix4(t),r.setXYZ(n,i.x,i.y,i.z);this.computeVertexNormals()}return this}clone(){let t=new uo;t.name=this.name;for(let r of Object.keys(this.attributes))t.attributes[r]=this.attributes[r].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},Ai=class extends Ue{constructor(e=1,t=1,r=1){super();let i=e/2,n=t/2,s=r/2,l=[-i,-n,s,i,-n,s,i,n,s,-i,n,s,i,-n,-s,-i,-n,-s,-i,n,-s,i,n,-s,-i,n,s,i,n,s,i,n,-s,-i,n,-s,-i,-n,-s,i,-n,-s,i,-n,s,-i,-n,s,i,-n,s,i,-n,-s,i,n,-s,i,n,s,-i,-n,-s,-i,-n,s,-i,n,s,-i,n,-s],o=[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],a=[],u=[];for(let h=0;h<6;h++){let m=h*4;a.push(0,0,1,0,1,1,0,1),u.push(m,m+1,m+2,m,m+2,m+3)}this.setFromBuffers(l,o,a,u)}},Xn=class extends Ue{constructor(e=1,t=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let n=[],s=[],l=[],o=[];for(let a=0;a<=i;a++){let u=a/i;for(let h=0;h<=r;h++){let m=h/r;if(n.push((m-.5)*e,(.5-u)*t,0),s.push(0,0,1),l.push(m,1-u),a>0&&h>0){let c=(r+1)*a+h-1,d=c-(r+1);o.push(d,c,d+1,c,c+1,d+1)}}}this.setFromBuffers(n,s,l,o)}},Kn=class extends Ue{constructor(e=1,t=16,r=12,i=0,n=Math.PI*2,s=0,l=Math.PI){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let o=[],a=[],u=[],h=[],m=Math.min(s+l,Math.PI);for(let c=0;c<=r;c++){let d=c/r,f=s+d*l;for(let g=0;g<=t;g++){let x=g/t,b=i+x*n,v=-Math.cos(b)*Math.sin(f),p=Math.cos(f),y=Math.sin(b)*Math.sin(f);if(o.push(e*v,e*p,e*y),a.push(v,p,y),u.push(x,1-d),c>0&&g>0){let M=(t+1)*c+g,P=M-(t+1),F=P-1,W=M-1;(c!==1||s>0)&&h.push(P,F,M),(c!==r||m<Math.PI)&&h.push(F,W,M)}}}this.setFromBuffers(o,a,u,h)}},Ti=class extends Ue{constructor(e=1,t=1,r=1,i=16,n=1,s=!1,l=0,o=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),n=Math.max(1,Math.floor(Number(n)||1));let a=[],u=[],h=[],m=[],c=r/2,d=(t-e)/(r||1),f=i+1;for(let x=0;x<=n;x++){let b=x/n,v=b*(t-e)+e,p=c-b*r;for(let y=0;y<=i;y++){let M=y/i,P=l+M*o,F=Math.sin(P),W=Math.cos(P),T=Math.hypot(F,d,W)||1;if(a.push(v*F,p,v*W),u.push(F/T,d/T,W/T),h.push(M,1-b),x<n&&y<i){let E=x*f+y,S=E+f;m.push(E,S,E+1,S,S+1,E+1)}}}let g=(x,b)=>{if(s||x<=0)return;let v=b*c,p=a.length/3;a.push(0,v,0),u.push(0,b,0),h.push(.5,.5);let y=p+1;for(let M=0;M<=i;M++){let P=l+M/i*o,F=Math.sin(P),W=Math.cos(P);a.push(x*F,v,x*W),u.push(0,b,0),h.push(W*.5+.5,.5+b*F*.5),M<i&&m.push(p,y+M+(b>0?0:1),y+M+(b>0?1:0))}};g(e,1),g(t,-1),this.setFromBuffers(a,u,h,m)}},Yn=class extends Ti{constructor(e=1,t=1,r=16,i=1,n=!1,s=0,l=Math.PI*2){super(0,e,t,r,i,n,s,l)}},Zn=class extends Ue{constructor(e=1,t=.4,r=12,i=48,n=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],l=[],o=[],a=[];for(let u=0;u<=r;u++){let h=u/r*Math.PI*2,m=Math.cos(h),c=Math.sin(h);for(let d=0;d<=i;d++){let f=d/i*n,g=Math.cos(f),x=Math.sin(f);if(s.push((e+t*m)*g,(e+t*m)*x,t*c),l.push(m*g,m*x,c),o.push(d/i,u/r),u>0&&d>0){let b=(i+1)*u+d-1,v=b-(i+1);a.push(b,v,b+1,v,v+1,b+1)}}}this.setFromBuffers(s,l,o,a)}};function Qn(e,t,r,i,n){let s=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),l=Math.max(3,Math.min(64,Math.floor(Number(r)||8))),o=Number(i)||.1,a=[],u=[],h=[],m=[],c=[],d=new xe,f=new xe,g=new xe;for(let b=0;b<=s;b++){let v=new xe;n(b/s,v),c.push(v)}let x=l+1;for(let b=0;b<=s;b++){let v=b/s,p=c[b];d.subVectors(c[Math.min(s,b+1)],c[Math.max(0,b-1)]).normalize(),b===0&&f.set(Math.abs(d.y)>.9?1:0,Math.abs(d.y)>.9?0:1,0),g.crossVectors(d,f).normalize(),f.crossVectors(g,d).normalize();for(let y=0;y<=l;y++){let M=y/l*Math.PI*2,P=-Math.cos(M),F=Math.sin(M),W=P*f.x+F*g.x,T=P*f.y+F*g.y,E=P*f.z+F*g.z;if(a.push(p.x+o*W,p.y+o*T,p.z+o*E),u.push(W,T,E),h.push(v,y/l),b>0&&y>0){let S=x*(b-1)+y-1,O=S+x;m.push(S,O,S+1,O,O+1,S+1)}}}e.setFromBuffers(a,u,h,m)}var Jn=class extends Ue{constructor(e=1,t=.4,r=64,i=8,n=2,s=3){super(),r=Math.floor(r),i=Math.floor(i),Qn(this,r,i,t,(l,o)=>{let a=l*n*Math.PI*2,u=s/n*a,h=e*(2+Math.cos(u))*.5;o.set(h*Math.cos(a),h*Math.sin(a),e*Math.sin(u)*.5)})}},Rt=class{getPoint(e,t=new xe){return t}getPointAt(e,t=new xe){return this.getPoint(e,t)}getTangent(e,t=new xe){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),r=[];for(let i=0;i<=t;i++)r.push(this.getPoint(i/t));return r}getSpacedPoints(e=5){return this.getPoints(e)}},es=class extends Rt{constructor(e=new xe,t=new xe){super(),this.v1=e,this.v2=t}getPoint(e,t=new xe){return t.lerpVectors(this.v1,this.v2,e)}},ts=class extends Rt{constructor(e=new xe,t=new xe,r=new xe){super(),this.v0=e,this.v1=t,this.v2=r}getPoint(e,t=new xe){return t.lerpVectors(this.v0,this.v1,e).lerp(new xe().lerpVectors(this.v1,this.v2,e),e)}},rs=class extends Rt{constructor(e=new xe,t=new xe,r=new xe,i=new xe){super(),this.v0=e,this.v1=t,this.v2=r,this.v3=i}getPoint(e,t=new xe){let r=new xe().lerpVectors(this.v0,this.v1,e),i=new xe().lerpVectors(this.v1,this.v2,e),n=new xe().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(r.lerp(i,e),i.lerp(n,e),e)}},is=class extends Rt{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new xe){let r=this.points,i=r.length;if(!i)return t.set(0,0,0);if(i===1)return t.copy(r[0]);let n=(this.closed?i:i-1)*Math.max(0,Math.min(1,Number(e)||0)),s=Math.floor(n),l=n-s;!this.closed&&s>=i-1&&(s=i-2,l=1);let o=g=>r[this.closed?(g%i+i)%i:Math.max(0,Math.min(i-1,g))],a=o(s-1),u=o(s),h=o(s+1),m=o(s+2),c=l*l,d=c*l,f=(g,x,b,v)=>.5*(2*x+(b-g)*l+(2*g-5*x+4*b-v)*c+(3*x-g-3*b+v)*d);return t.set(f(a.x,u.x,h.x,m.x),f(a.y,u.y,h.y,m.y),f(a.z,u.z,h.z,m.z))}},Si=class extends Ue{constructor(e=[new ut(0,-.5),new ut(.5,0),new ut(0,.5)],t=12,r=0,i=Math.PI*2){super();let n=Array.isArray(e)&&e.length>=2?e:[new ut(.2,0),new ut(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),l=[],o=[],a=[],u=[],h=n.length;for(let m=0;m<=s;m++){let c=m/s,d=r+c*i,f=Math.sin(d),g=Math.cos(d),x=m*h;for(let b=0;b<h;b++){let v=n[b],p=Number(v?.x)||0,y=Number(v?.y)||0;l.push(p*f,y,p*g);let M=n[Math.max(0,b-1)],P=n[Math.min(h-1,b+1)],F=(Number(P?.x)||0)-(Number(M?.x)||0),W=(Number(P?.y)||0)-(Number(M?.y)||0),T=Math.hypot(W,F)||1;if(o.push(W/T*f,-F/T,W/T*g),a.push(c,b/(h-1)),m<s&&b<h-1){let E=x+b,S=E+h;u.push(E,S,E+1,S,S+1,E+1)}}}this.setFromBuffers(l,o,a,u)}},ns=class extends Ue{constructor(e,t=64,r=1,i=8,n=!1){super(),Qn(this,t,i,r,(s,l)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let a=o.call(e,s,l);a&&a!==l&&l.copy(a)}else l.set(0,s,0)})}},_r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ir=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new ut(1,1),this.offset=new ut(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},ss=class extends Ir{constructor(e=null,t=1,r=1,i=1023,n=1009,s,l=1001,o=1001,a=1003,u=1003,h=1,m=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let c=Number(t),d=Number(r),f=e&&typeof e.length=="number"?e:null;this.width=c,this.height=d,this.image={data:f,width:c,height:d},this.format=Number(i)||1023,this.type=Number(n)||1009,this.wrapS=Number(l)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(a)||1003,this.minFilter=Number(u)||1003,this.colorSpace=m||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,r=Number(e?.width??this.width),i=Number(e?.height??this.height);if(!t||!t.length||!(r>0&&i>0)||r>2048||i>2048){this.source="";return}let n=Math.max(1,r|0),s=Math.max(1,i|0),l=n*s,o=this.format,a=o===1021||o===1024||o===1028||t.length===l?1:o===1025||o===1030||t.length===l*2?2:o===1022||t.length===l*3?3:4,u=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,h=Math.min(n,48),m=Math.min(s,48),c=(this.flipY?257:1)^this.colorSpace.length^t.length,d=Math.max(1,t.length>>6|0);for(let O=0;O<t.length;O+=d)c=Math.imul(c^(t[O]*256|0),16777619)|0;if(c===this._sig&&this.source)return;this._sig=c;let f=m*(1+h*4),g=new Uint8Array(68+f),x=new DataView(g.buffer);x.setUint32(0,2303741511),x.setUint32(4,218765834),x.setUint32(8,13),x.setUint32(12,1229472850),x.setUint32(16,h),x.setUint32(20,m),g[24]=8,g[25]=6,x.setUint32(29,gi(g.subarray(12,29))),x.setUint32(33,f+11),x.setUint32(37,1229209940),g[41]=120,g[42]=1,g[43]=1,x.setUint16(44,f,!0),x.setUint16(46,~f&65535,!0);let b=48,v=1,p=0,y=0,M=0,P=0,F=0,W=O=>{if(!Number.isFinite(O))return 0;let k=u&&O<=1?O*255:O;return k>0?k<255?k+.5|0:255:0};for(let O=0;O<m;O++){let k=O*s/m|0,w=this.flipY?s-1-k:k;g[b++]=0,p+=v;for(let ie=0;ie<h;ie++){let oe=(w*n+(ie*n/h|0))*a,I=o===1021?255:W(t[oe]??0),H=a>=3||o===1030?W(t[oe+1]??0):I,N=a>=3?W(t[oe+2]??0):o===1030?0:I,z=a===4?W(t[oe+3]??255):o===1021?W(t[oe]??255):o===1025?W(t[oe+1]??255):255;g[b++]=I,v+=I,p+=v,g[b++]=H,v+=H,p+=v,g[b++]=N,v+=N,p+=v,g[b++]=z,v+=z,p+=v,y+=I,M+=H,P+=N,F+=z}v%=65521,p%=65521}x.setUint32(b,(p<<16|v)>>>0),x.setUint32(b+4,gi(g.subarray(37,b+4))),x.setUint32(b+12,1229278788),x.setUint32(b+16,2923585666);let T=h*m*255,E=this.colorSpace==="srgb-linear";this.avgColor=[E?y/T:Ye(y/T),E?M/T:Ye(M/T),E?P/T:Ye(P/T),F/T];let S=["data:image/png;base64,"];for(let O=0;O<g.length;O+=3){let k=g[O]<<16|(g[O+1]??0)<<8|(g[O+2]??0);S.push(_r[k>>18&63]+_r[k>>12&63]+(O+1<g.length?_r[k>>6&63]:"=")+(O+2<g.length?_r[k&63]:"="))}this.source=S.join("")}},as=class{load(e,t){let r=new Ir(e);return t?.(r),r}};function qe(e,t){return e!==void 0?Number(e):t}function Ri(e,t){return e!==void 0?!!e:t}var it=class{constructor(e={}){this.name=e.name||"",this.color=new gt(e.color??16777215),this.emissive=new gt(e.emissive??0),this.emissiveIntensity=qe(e.emissiveIntensity,1),this.roughness=qe(e.roughness,.5),this.metalness=qe(e.metalness,0),this.opacity=qe(e.opacity,1),this.transparent=Ri(e.transparent,!1),this.wireframe=Ri(e.wireframe,!1),this.side=qe(e.side,2),this.doubleSided=Ri(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=qe(e.clearcoat,0),this.clearcoatRoughness=qe(e.clearcoatRoughness,0),this.sheen=qe(e.sheen,0),this.sheenColor=new gt(e.sheenColor??0),this.sheenRoughness=qe(e.sheenRoughness,0),this.transmission=qe(e.transmission,0),this.thickness=qe(e.thickness,0),this.attenuationColor=new gt(e.attenuationColor??16777215),this.attenuationDistance=qe(e.attenuationDistance,1/0),this.ior=qe(e.ior,1.5),this.dispersion=qe(e.dispersion,0),this.iridescence=qe(e.iridescence,0),this.iridescenceIOR=qe(e.iridescenceIOR,1.3)}dispose(){}},nr=class extends it{},os=class extends it{},ls=class extends it{},us=class extends it{},hs=class extends it{},yt=class ho{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 xe,this.rotation=new wi,this.quaternion=new Cr,this.scale=new xe(1,1,1),this.matrix=new Ot,this.matrixWorld=new Ot,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,r=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),i=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),n=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(r,i,n)})}add(...t){for(let r of t)r&&r instanceof ho&&(r.parent&&r.parent.remove(r),r.parent=this,this.children.push(r));return this}remove(...t){for(let r of t){let i=this.children.indexOf(r);i!==-1&&(r.parent=null,this.children.splice(i,1))}return this}traverse(t){let r=new Set,i=[this];for(;i.length>0;){let n=i.pop();if(!n||typeof n!="object"||r.has(n))continue;r.add(n),t(n);let s=n.children;if(Array.isArray(s))for(let l=s.length-1;l>=0;l--)i.push(s[l])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(r=>{ms(r),(r.matrixAutoUpdate||t)&&r.updateMatrix?.(),r.parent&&r.parent.matrixWorld?r.matrixWorld?.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrix&&r.matrixWorld?.copy(r.matrix)})}lookAt(t,r,i){let n=typeof t=="object"?t:new xe(t,r,i);this.target instanceof xe?this.target.copy(n):this.target?.position instanceof xe&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new Ot;s.lookAt(this.position,n,new xe(0,1,0));let l=s.elements,o=l[0],a=l[4],u=l[8],h=l[1],m=l[5],c=l[9],d=l[2],f=l[6],g=l[10],x=o+m+g;if(x>0){let b=.5/Math.sqrt(x+1);this.quaternion.set((f-c)*b,(u-d)*b,(h-a)*b,.25/b)}}translateOnAxis(t,r){let i=t.clone().applyMatrix4(new Ot().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(r);return this.position.add(i),this}translateX(t){return this.translateOnAxis(new xe(1,0,0),t)}translateY(t){return this.translateOnAxis(new xe(0,1,0),t)}translateZ(t){return this.translateOnAxis(new xe(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let r=this;r&&t.length<64;r=r.parent)t.push(r);return t}_syncWorld(){let t=this._chain();for(let r=t.length-1;r>=0;r--){let i=t[r];i.updateMatrix?.(),i.parent?.matrixWorld?i.matrixWorld.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrixWorld?.copy(i.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new xe){let r=this._syncWorld();return t.set(r[12],r[13],r[14])}getWorldScale(t=new xe){let r=this._syncWorld();return t.set(Math.hypot(r[0],r[1],r[2]),Math.hypot(r[4],r[5],r[6]),Math.hypot(r[8],r[9],r[10]))}getWorldDirection(t=new xe){let r=this._syncWorld();return t.set(r[8],r[9],r[10]).normalize()}getWorldQuaternion(t=new Cr){let r=this._chain();t.set(0,0,0,1);for(let i=r.length-1;i>=0;i--)t.multiply(r[i].quaternion);return t}clone(t=!0){let r=this instanceof zt?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof At?new At(this.geometry,this.material):new this.constructor;r.name=this.name,r.position.copy(this.position),r.quaternion.copy(this.quaternion),r.scale.copy(this.scale),r.visible=this.visible,r.castShadow=this.castShadow,r.receiveShadow=this.receiveShadow;try{r.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{r.userData={...this.userData||{}}}if(t)for(let i of this.children)r.add(i.clone(!0));return r}},cs=class extends yt{},At=class extends yt{constructor(e,t){super(),this.isMesh=!0;let r=Array.isArray(t)?t[0]:t;this.geometry=e instanceof Ue?e:e?(Pt("unsupported geometry","BoxGeometry"),new Ai(.5,.5,.5)):new Ue,this.material=r instanceof it?r:r?(Pt("unsupported material","MeshStandardMaterial"),new nr({color:13421772})):new nr}};function ms(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=Ae().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var sr=1e4,Pi=class extends At{constructor(e,t,r=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let i=Number(r);if(!Number.isFinite(i)||i<0||i>sr)throw new RangeError(`SecurityError: InstancedMesh count (${String(r)}) exceeds MAX_INSTANCES_PER_MESH (${sr})`);this.count=Math.floor(i);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let l=s*16;n[l]=1,n[l+5]=1,n[l+10]=1,n[l+15]=1}this.instanceMatrix=new He(n,16)}setMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++){let l=Number(t.elements[s]);i[n+s]=Number.isFinite(l)?l:s%5===0?1:0}}getMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++)t.elements[s]=i[n+s]}setColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new He(s,3)}let i=this.instanceColor.array,n=r*3;i[n]=Number.isFinite(t.r)?t.r:1,i[n+1]=Number.isFinite(t.g)?t.g:1,i[n+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(r+1)*3){t.setRGB(1,1,1);return}let i=this.instanceColor.array,n=r*3;t.setRGB(i[n],i[n+1],i[n+2])}dispose(){}},ar=class extends yt{constructor(e=16777215,t=1){super(),this.color=new gt(e),this.intensity=Number(t),this.type="directional"}},Ei=class extends ar{constructor(e,t){super(e,t),this.type="ambient"}},fs=class extends ar{constructor(e,t){super(e,t),this.target=new yt,this.type="directional"}},Ni=class extends ar{constructor(e,t,r=0,i=2){super(e,t),this.type="point",this.distance=r,this.decay=i}},Ci=class extends yt{},ps=class extends Ci{constructor(e=45,t=1,r=.1,i=1e3){super(),this.target=new xe(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(r),this.far=Number(i)}},Li=class extends yt{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Tt.validate(this),ir(this)}toGLB(){return Tt.validate(this),Tr(this)}toUSDZ(){return Tt.validate(this),Nr(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(r=>{if(r instanceof At){let i=new Float32Array(r.matrixWorld.elements);e.set(t,i),r.name&&e.set(r.name,i),t++}}),e}},_i=ir,Ii=Tr,ds=Nr,Tt=class{static validate(e){let t=0,r=0,i=0,n=new Set,s=(o,a,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${a}). Found: ${u}`)},l=(o,a)=>{if(!Number.isFinite(a))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(a)}), which cannot be bounds-checked.`);return a};e.traverse(o=>{if(ms(o),o instanceof At||o.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),o instanceof Pi){let u=l("instance",o.count);(u<0||u>sr)&&s("INSTANCES",sr,u)}let a=o.geometry;if(a){let u=0;if(a.attributes.position&&(u=l("vertex",a.attributes.position.count),t+=u,t>1e5&&s("VERTICES",1e5,t)),a.index){let h=l("index",a.index.count);r+=h,r>3e5&&s("INDICES",3e5,r);let m=a.index.array;if(m&&u>0){let c=Math.min(h,m.length);for(let d=0;d<c;d++){let f=m[d];if(!Number.isFinite(f)||f<0||f>=u)throw new Error(`SecurityError: Index buffer value (${String(f)}) out of vertex bounds [0, ${u}).`)}}}}if(o.material){let u=o.material;for(let h of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])u[h]&&n.add(u[h])}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let a=o,u=a.image,h=Number(u?.width??a.width??0)||0,m=Number(u?.height??a.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(m)||h>2048||m>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(h,m))}}},gs=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new gt(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){Tt.validate(e);let i=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=e.getMeshTransforms(),s={};for(let[l,o]of n.entries())s[l]=Array.from(o);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=_i(e),s=Ii(e),l=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.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 ys(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var bs=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=ys(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=ys();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function ml(){}var or=new Proxy(ml,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:or},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>or,construct:()=>or}),xs=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function Dr(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Bt(e,t){if(!e||typeof e!="string")return!1;let r=e.trim();if(!r)return!1;try{let i=new URL(r,Dr());return!(i.protocol!=="https:"&&i.protocol!=="http:"&&i.protocol!=="blob:"||t?.requireSameOrigin&&i.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&i.origin!==location.origin)}catch{return!1}}var vs,lr;function Ms(e){if(!Bt(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(lr===void 0||vs!==t){vs=t;try{lr=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!Bt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{lr=null}}return lr?lr.createScriptURL(e):e}function fl(e){Ae().sandboxEngineSrc=e}function Di(){let e=Ae().sandboxEngineSrc;if(e)return e;if(xs)return xs;try{if(typeof document>"u")return null;let t=Dr(),r=Array.from(document.querySelectorAll("script[src]"));for(let i of r){let n=i.src;if(!n)continue;let s=new URL(n,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&Bt(n,{requireSameOrigin:!0}))return n}}catch{}return null}function ki(e,t){if(!Bt(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Dr()).href}function pl(){let e=Di();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return ki(e,"sandbox engine")}function dl(e){Ae().sandboxIframeSrc=e}function ws(){let e=Ae().sandboxIframeSrc;if(e)return e;let t=Di();if(!t||!Bt(t))return null;let r=new URL(t,Dr());return r.protocol==="blob:"?null:new URL("three-live-sandbox.html",r).href}function gl(){let e=ws();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return ki(e,"sandbox iframe")}function yl(e){Ae().allowClientScripts=e}function As(){return!!Ae().allowClientScripts}function bl(e){return ki(e,"procedural scene script")}var xl=["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 vl(e,t){let r=self,i=e.nonce,n=e.engineSrc,s=e.allowedScriptUrl,l=e.allowClientScripts,o=e.revoked,a=r.postMessage.bind(r);function u(p){a({type:"ERROR",nonce:i,message:String(p)})}let h=typeof r.importScripts=="function"?r.importScripts.bind(r):null,m=s,c=null;try{let p=n;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let y={createScriptURL:function(P){if(P!==n&&(!s||P!==s))throw new TypeError("Disallowed worker importScripts URL");return P}};l&&(y.createScript=function(P){return String(P)});let M=r.trustedTypes.createPolicy("three-live#worker-boot",y);p=M.createScriptURL(n),s&&(m=M.createScriptURL(s)),l&&typeof M.createScript=="function"&&(c=M.createScript.bind(M))}catch{}h(p)}catch(p){u('Sandbox failed to load the Three-Live engine from "'+n+'". 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 d=r.THREE;if(!d||typeof d.Scene!="function"){u('Sandbox loaded "'+n+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let p=r.__THREE_LIVE_REGISTRY__;for(let y=0;y<t.length;y++)if(typeof t[y]=="function")try{t[y](d,p)}catch{}}function f(p,y,M){let P=r;for(;P&&P!==Object.prototype;){if(!M&&P!==r)try{delete P[p]}catch{}if(!M||P===r||Object.prototype.hasOwnProperty.call(P,p))try{Object.defineProperty(P,p,M?{value:y,writable:!1,configurable:!1}:{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{P=Object.getPrototypeOf(P)}catch{break}}}for(let p=0;p<o.length;p++)f(o[p],void 0);f("performance",Object.freeze({now:function(){return Date.now()}}));let g=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function b(p,y){if(p.type==="3D_MODEL_READY"){if(x)return;x=!0}p.nonce=i,y&&y.length?a(p,y):a(p)}f("postMessage",function(p,y){if(!p||g.indexOf(p.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+g.join(", ")+").");b(p,y)},!0);let v=!1;r.onmessage=function(p){let y=p&&p.data;if(!(!y||y.nonce!==i)&&!(y.type!=="EXECUTE"&&y.type!=="EXECUTE_URL")&&!v){v=!0;try{let M=new d.Scene,P=new d.PerspectiveCamera(60,1,.1,1e3),F=new d.WebGLRenderer({isSandboxed:!0});if(y.type==="EXECUTE_URL"){if(!s||y.scriptUrl!==s||typeof h!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let W=m||s,T=h;if(h=null,m=null,r.THREE=d,r.scene=M,r.camera=P,r.renderer=F,T(W),typeof r.__THREE_LIVE_SCENE__=="function"){let E=r.__THREE_LIVE_SCENE__(d,M,P,F);E&&typeof E.toGLB=="function"&&(M=E)}else r.scene&&typeof r.scene.toGLB=="function"&&(M=r.scene)}else{if(!l){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let W=c?(0,eval)(c(`(function (THREE, scene, camera, renderer) {
323
370
  return (function () {
324
- `+k.script+`
371
+ `+y.script+`
372
+ ;
373
+ return typeof scene === "object" && scene ? scene : undefined;
325
374
  })();
326
375
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
327
- `+k.script+`
328
- })();`);f=null;let A=g(h,I,L,x);A&&typeof A.toGLB=="function"&&(I=A)}if(!v){h.SceneQuotaValidator&&h.SceneQuotaValidator.validate(I);let g=I.toGLB(),A=g instanceof ArrayBuffer?g:g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);R({type:"3D_MODEL_READY",glbBuffer:A},[A])}s({type:"DONE",nonce:r})}catch(I){c(I&&I.message||I)}}},s({type:"READY",nonce:r})}function li(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Da},a=(ve().workerExtensionInstallers??[]).map(u=>`(${u.toString()})`).join(",");return`'use strict';(${Ua.toString()})(${JSON.stringify(o)},[${a}]);`}function Yo(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 Et=0;function Zo(){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 Oa(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var Fa=1024,Va=256;function zo(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 fi(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,Fa)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!zo(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),u=i;for(let s of o){if(s.length>Va||s==="__proto__"||s==="constructor"||s==="prototype")return null;let c=u[s];if(!zo(c))return null;a[s]=c}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 Ba(t){let e=Oa(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Qo(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 za(t,e,n,r){let i=Zo(),o=li(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,Et++;let u=!1,s=!1,c={modelDispatched:!1},l,m=()=>{if(u||s)return;let d=a.contentWindow;!d||typeof d.postMessage!="function"||(s=!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(u||!a.contentWindow||d.source!==a.contentWindow)return;let y=d.data;if(y&&typeof y=="object"&&y.type==="IFRAME_READY"){m();return}let v=fi(y,i);v&&Qo(v,r,f,c)};f=()=>{u||(u=!0,l!==void 0&&clearTimeout(l),Et=Math.max(0,Et-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",h),typeof a.remove=="function"?a.remove():a.parentNode&&a.parentNode.removeChild(a))},l=setTimeout(()=>{u||(f(),Yo(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",h),a.onload=()=>{m()},a.onerror=()=>{f(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let p=document.body||document.documentElement;if(!p||typeof p.appendChild!="function"){f();let d=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(d),d}return p.appendChild(a),{terminate:f}}function Go(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(Et>=32)return r(`SecurityError: ${Et} 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=Ia()}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=Pa()}catch(h){let p=h instanceof Error?h.message:String(h);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(za(t,i,f,n))}catch(h){return Promise.reject(h)}}let o=Zo(),a=li(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),u;try{let f=new Blob([a],{type:"application/javascript"}),h=URL.createObjectURL(f);try{let p=jo(h);u=new Worker(p)}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.")}Et++;let s=!1,c={modelDispatched:!1},l,m=()=>{s||(s=!0,l!==void 0&&clearTimeout(l),Et=Math.max(0,Et-1),u.terminate())};return l=setTimeout(()=>{s||(m(),Yo(n))},3e3),u.onmessage=f=>{let h=fi(f.data,o);h&&Qo(h,n,m,c)},u.onerror=f=>{m(),n.onError?.(new Error(`Worker execution error: ${f.message}`))},t.kind==="url"?u.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):u.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 en={execute(t,e,n,r){let i=(u,s)=>{let c=new Error(u);return n.onError?.(c),s&&n.onToast?.(s),Promise.reject(c)},o=Ho(e,i);if(o)return o;try{Ba(t)}catch(u){let s=u instanceof Error?u.message:String(u);return i(s,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Ko()?Go({kind:"script",script:t},e,n,i):i(kn,Nn)},executeUrl(t,e,n){let r=(a,u)=>{let s=new Error(a);return n.onError?.(s),u&&n.onToast?.(u),Promise.reject(s)},i=Ho(e,r);if(i)return i;let o;try{o=Na(t)}catch(a){let u=a instanceof Error?a.message:String(a);return r(u,"Security Error: disallowed scene script URL.")}return Go({kind:"url",scriptUrl:o},e,n,r)}},dr=new Set;function Ze(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;dr.has(n)||(dr.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function Jo(){return Array.from(dr)}function es(){dr.clear()}var An=class extends kt{constructor(e={}){Ze("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}},ts=An,Ut=class extends bn{constructor(e=1,n=0,r="PolyhedronGeometry"){Ze(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},hr=class extends Ut{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},pr=class extends Ut{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},br=class extends Ut{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},yr=class extends Ut{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},gr=class extends _t{constructor(e=1,n=1,r=4,i=8){Ze("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},xr=class extends _t{constructor(e=.5,n=1,r=16){Ze("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},vr=class extends _t{constructor(e=1,n=16){Ze("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Tr=class extends Tn{constructor(n,r,i=0,o=Math.PI/3,a=0,u=2){Ze("SpotLight","PointLight");super(n,r,i,u);this.target=new tt;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=a}},Sn=class extends vn{constructor(e,n,r){Ze("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new et(n??4473924)}},ns=Sn,rs={Vector2:jn,Vector3:Ue,Vector4:qn,Euler:dn,Quaternion:hn,Matrix4:Pt,Matrix3:Kn,Color:et,MathUtils:Xo,BufferAttribute:$e,Float32BufferAttribute:Yn,Uint16BufferAttribute:Zn,Uint32BufferAttribute:Qn,BufferGeometry:Ye,BoxGeometry:pn,PlaneGeometry:Jn,SphereGeometry:bn,CylinderGeometry:_t,ConeGeometry:er,TorusGeometry:tr,TorusKnotGeometry:nr,IcosahedronGeometry:hr,OctahedronGeometry:pr,DodecahedronGeometry:br,TetrahedronGeometry:yr,CapsuleGeometry:gr,RingGeometry:xr,CircleGeometry:vr,Texture:yn,TextureLoader:rr,Material:at,MeshStandardMaterial:kt,MeshBasicMaterial:ir,MeshLambertMaterial:or,MeshPhongMaterial:sr,MeshPhysicalMaterial:ar,ShaderMaterial:An,RawShaderMaterial:ts,Object3D:tt,Group:cr,Mesh:Nt,InstancedMesh:xn,Light:Dt,AmbientLight:vn,DirectionalLight:ur,PointLight:Tn,SpotLight:Tr,HemisphereLight:Sn,RectAreaLight:ns,Camera:wn,PerspectiveCamera:lr,Scene:Mn,WebGLRenderer:fr,Clock:mr,SceneQuotaValidator:st,exportSceneToCanvas3D:ai,exportSceneToGLB:ci,exportSceneToUSDZ:$o,generateUSDZ:un,glbToUSDZ:cn,sceneToCanvas3D:Yt,sceneToGLB:an,sceneToUSDZ:Zt,authorScriptRunner:en,getAuthorWarnings:Jo,clearAuthorWarnings:es};Object.freeze(st);Object.freeze(st.prototype);Object.freeze(Mn.prototype);Object.freeze(rs);var Ot=new Proxy(rs,{get:(t,e)=>{if(e in t)return t[e];let n=ve().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Ze(`THREE.${e}`,"no-op proxy"),fn)},has:(t,e)=>{if(e in t)return!0;let n=ve().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")}}),$n=ve();$n.threeNamespace=Ot;if($n.workerExtensionInstallers)for(let t of $n.workerExtensionInstallers)t(Ot,$n);var mn={name:"three_author",THREE:Ot},Ga=mn,pt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof pt.THREE>"u"&&(pt.THREE=Ot);typeof pt.requestAnimationFrame!="function"&&(pt.requestAnimationFrame=t=>(typeof t=="function"&&typeof pt.__three_live_raf_cb__!="function"&&(pt.__three_live_raf_cb__=t),pt.__three_live_in_step__||Ze("requestAnimationFrame","single-frame static evaluation"),0));typeof pt.cancelAnimationFrame!="function"&&(pt.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=Ot,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=mn,t.ThreeLivePlugins.three_author=mn,t.ThreeLivePlugins["three-author"]=mn}function tn(t,e){let n=t?.trim(),r=n?Number(n):NaN;return Number.isFinite(r)?r:e}var mi=(t,e,n)=>({x:t,y:e,z:n,toString:()=>`${t}m ${e}m ${n}m`}),Ha=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 Be=class Be extends Ha{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 ve().arProvider}static set arProvider(n){ve().arProvider=n}static get scriptRunner(){return ve().scriptRunner}static set scriptRunner(n){ve().scriptRunner=n}static get sandboxEngineSrc(){return ve().sandboxEngineSrc??null}static set sandboxEngineSrc(n){ve().sandboxEngineSrc=n}static get sandboxIframeSrc(){return ve().sandboxIframeSrc??null}static set sandboxIframeSrc(n){ve().sandboxIframeSrc=n}static get allowClientScripts(){return!!ve().allowClientScripts}static set allowClientScripts(n){ve().allowClientScripts=n}static registerScriptRunner(n){Be.scriptRunner=n}static registerDecoder(n,r){He.registerDecoder(n,r)}static getDecoder(n){return He.getDecoder(n)}static registerAR(n){typeof n=="function"?Be.arProvider={activateAR:n}:Be.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof Be&&i.updateARButtonVisibility()})}static isARSupported(){return!!Be.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.loadModel(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 He.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of He.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle?.terminate(),this.scriptHandle=null,this.mutationObserver?.disconnect(),this.mutationObserver=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.activeXRSession?.stop?.().catch?.(()=>{}),this.activeXRSession=null,this.toastTimer&&clearTimeout(this.toastTimer),this.toastTimer=null,this.viewer?.destroy(),this.viewer=null,this.isModelLoaded=!1}attributeChangedCallback(n,r,i){if(r!==i){switch(n){case"src":i&&this.loadModel(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?.setToneMapping(Ct(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 He.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")||(ve().sandboxIframeSrc?"iframe":"worker")}set sandbox(n){this.setAttribute("sandbox",n)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||Be.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 Be.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 Ct(this.getAttribute("tone-mapping"))}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 tn(this.getAttribute("bloom-threshold"),.62)}set bloomThreshold(n){this.setAttribute("bloom-threshold",String(n))}get bloomRadius(){return tn(this.getAttribute("bloom-radius"),.75)}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():[]}fireEvent(n,r){this.dispatchEvent(new CustomEvent(n,{bubbles:!0,composed:!0,detail:r}))}setSlotVisible(n,r){let i=typeof this.querySelector=="function"?this.querySelector(`[slot="${n}"]`):null;i&&(i.hidden=!r,i.style&&(i.style.display=r?"":"none"))}emitError(n,r="script"){this.setSlotVisible("error",!0),this.fireEvent("error",{error:n}),this.fireEvent("three-error",{error:n,message:n?.message||String(n),stage:r})}selectVariant(n){if(!this.viewer)return!1;let r=this.viewer.selectVariant(n);return r&&this.fireEvent("variant-applied",{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():mi(0,0,0)}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,r){return this.viewer?.render?.(),this.canvas?this.canvas.toDataURL(n,r):""}toBlob(n){return 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){let i=this.viewer?.raycastFromScreenPoint(n,r);if(!i)return null;let[o,a,u]=i.hitPoint||i.point,[s,c,l]=i.normal;return{position:mi(o,a,u),normal:mi(s,c,l)}}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 s=await fetch(n);if(!s.ok)throw new Error(`Failed to load 3D model from "${n}": HTTP ${s.status}`);i=await s.arrayBuffer()}else i=n;let o=ht(i);this.viewer.loadGLBData(o,r),this.currentModel=o,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.setSlotVisible("error",!1),this.updateHotspots();let a=this.getAttribute("selected-mesh");a&&this.viewer.setSelectedMesh(a);let u=this.getAttribute("variant-name");u&&this.selectVariant(u),this.fireEvent("load",{model:o}),this.fireEvent("three-load",{model:o,source:typeof n=="string"?"src":"model"})}catch(i){throw this.emitError(i,"load"),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);let o=()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")};typeof requestAnimationFrame<"u"?requestAnimationFrame(o):o(),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){this.activeXRSession?.isSessionActive?.()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null);let n=(o,a=o.message)=>{throw this.fireEvent("ar-status",{status:"failed",error:o}),this.showToast(a,6e3),o};this.currentModel||n(new Error("No 3D model is loaded in <three-live>.")),Be.arProvider||n(new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR()."));let r=this.getAttribute("ios-src"),i=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.fireEvent("ar-status",{status:"session-started"});let o=await Be.arProvider.activateAR({model:r||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:i.length>0?i:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"not-presenting"})},onError:a=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"failed",error:a}),this.showToast(`AR error: ${a.message}`,6e3)}}});if(o.success){o.session&&(this.activeXRSession=o.session);let a=o.mode==="quick-look"?"Opening Apple AR Quick Look...":o.mode==="scene-viewer"?"Opening Google Scene Viewer...":o.mode==="webxr"?"WebXR AR session started.":"";a&&this.showToast(a)}else{let a=typeof navigator<"u"&&navigator.userAgent||"",u=/Macintosh/i.test(a)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),s=/Android|iPhone|iPad|iPod/i.test(a),c=o.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.";if(u&&!s&&typeof document<"u"&&this.currentModel&&Be.arProvider.createUSDZBlob)try{let l=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:Be.arProvider.createUSDZBlob(this.currentModel),m=URL.createObjectURL(l),f=document.createElement("a");f.href=m,f.download="three_live_model.usdz",document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(m),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(c,6e3)}else this.showToast(c,6e3);o.error&&this.fireEvent("ar-status",{status:"failed",error:o.error})}return o}catch(o){return this.activeXRSession=null,n(o,`AR error: ${o.message||String(o)}`)}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.cssText=`width:100%;height:100%;display:block;touch-action:${this.cameraControls?"none":"auto"};outline:none`,this.appendChild(n)),this.canvas=n,typeof n.addEventListener=="function"&&!n.__tlCtxBound&&(n.__tlCtxBound=!0,n.addEventListener("webglcontextlost",i=>this.fireEvent("three-context-lost",{originalEvent:i})),n.addEventListener("webglcontextrestored",i=>this.fireEvent("three-context-restored",{originalEvent:i}))),this.setSlotVisible("error",!1),this.isModelLoaded||this.setSlotVisible("poster",!0);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")),u=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new He(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:u,cameraTarget:a,minCameraOrbit:i,maxCameraOrbit:o,onMeshClick:c=>{this.fireEvent("meshclick",c)},onCameraChange:c=>{this.updateHotspots();for(let l of He.getRegisteredPlugins())l.onCameraChange?.(this.viewer,this);this.fireEvent("camera-change",c)}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let s=this.getAttribute("camera-orbit");s&&this.applyCameraOrbit(s),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.cssText="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:opacity .35s ease-out;pointer-events:none;z-index:1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.setSlotVisible("poster",!1),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");for(let[u,s]of[["width","20"],["height","20"],["viewBox","0 0 24 24"],["fill","none"],["stroke","currentColor"],["stroke-width","2"],["stroke-linecap","round"],["stroke-linejoin","round"]])o.setAttribute(u,s);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 16zM3.27 6.96 12 12.01l8.73-5.05M12 22.08V12"),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")&&!!Be.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=this.parseOrbitLimit(n);(r.theta!==void 0||r.phi!==void 0)&&this.viewer.setInitialCamera(r.theta,r.phi,r.distance)}}parseOrbitLimit(n){if(!n)return{};let[r,i,o]=n.trim().split(/\s+/),a=o&&o!=="auto"?parseFloat(o):NaN;return{theta:r&&r!=="auto"?this.parseFieldOfView(r):void 0,phi:i&&i!=="auto"?this.parseFieldOfView(i):void 0,distance:isNaN(a)?void 0:a}}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(parseFloat);return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(n){if(!n)return;let r=parseFloat(n);return isNaN(r)?void 0:n.endsWith("rad")?r*180/Math.PI: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 He.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(n){let r=Be.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.emitError(i,"script"),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:s=>{this.loadModelWithLimits(s,_o).then(()=>{a||(a=!0,i(s))},c=>{let l=c instanceof Error?c.message:String(c);this.showToast(l),a||(a=!0,o(c))})},onUpdateTransforms:s=>this.viewer?.updateMeshTransforms(s),onError:s=>{this.showToast(s.message),this.emitError(s,"script"),a||(a=!0,o(s))},onToast:s=>this.showToast(s)}).then(s=>{s&&(this.scriptHandle=s)},s=>{s instanceof Error&&s.message&&this.showToast(s.message),a||(a=!0,o(s))})})}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(!Be.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(kn);return this.showToast(Nn),this.emitError(r,"security"),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(n,this.sandbox,i,{allowClientScripts:!0}))}};Be.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"],Be.registerPlugin=He.registerPlugin,Be.getRegisteredPlugins=He.getRegisteredPlugins;var ct=Be;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",ct);function is(t,e,n){return e%4===0?new Float32Array(t,e,n):new Float32Array(t.slice(e,e+n*4))}function Mr(t,e,n,r){let i=e[0],o=e[1],a=e[2],u=e[3],s=n[0],c=n[1],l=n[2],m=n[3],f=i*s+o*c+a*l+u*m;if(f<0&&(s=-s,c=-c,l=-l,m=-m,f=-f),Math.abs(f)>=1)return t[0]=i,t[1]=o,t[2]=a,t[3]=u,t;let h=Math.acos(f),p=Math.sqrt(1-f*f);if(Math.abs(p)<.001)return t[0]=.5*(i+s),t[1]=.5*(o+c),t[2]=.5*(a+l),t[3]=.5*(u+m),t;let d=Math.sin((1-r)*h)/p,y=Math.sin(r*h)/p;return t[0]=i*d+s*y,t[1]=o*d+c*y,t[2]=a*d+l*y,t[3]=u*d+m*y,t}function os(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 bi(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=[],u=0;if(Array.isArray(i.channels)&&Array.isArray(i.samplers))for(let s of i.channels){if(!s.target||s.target.node===void 0||!s.target.path)continue;let c=i.samplers[s.sampler];if(!c)continue;let l=t.accessors?.[c.input],m=t.accessors?.[c.output];if(!l||!m)continue;let f=t.bufferViews?.[l.bufferView],h=t.bufferViews?.[m.bufferView];if(!f||!h)continue;let p=(f.byteOffset||0)+(l.byteOffset||0),d=(h.byteOffset||0)+(m.byteOffset||0),y=ot(t,e,l,1)??is(e,p,l.count);y.length>0&&y[y.length-1]>u&&(u=y[y.length-1]);let v=s.target.path==="rotation"?4:s.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,l.count))):3,R=s.target.path==="weights"?1:v,b=ot(t,e,m,R)??is(e,d,m.count*R),w=c.interpolation==="STEP"?"STEP":"LINEAR";a.push({nodeIndex:s.target.node,path:s.target.path,times:y,values:b,interpolation:w})}a.length>0&&n.push({name:o,duration:u,channels:a})}return n}function nn(t,e,n){let{times:r,values:i,path:o,interpolation:a}=t,u=r.length;if(u===0)return;let s=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/u)):3;if(e<=r[0]){for(let R=0;R<s;R++)n[R]=i[R];return}if(e>=r[u-1]){let R=(u-1)*s;for(let b=0;b<s;b++)n[b]=i[R+b];return}let c=0,l=u-1;for(;c<=l;){let R=c+l>>1;r[R]<=e?c=R+1:l=R-1}let m=Math.max(0,l),f=Math.min(u-1,m+1);if(a==="STEP"||m===f){let R=m*s;for(let b=0;b<s;b++)n[b]=i[R+b];return}let h=r[m],p=r[f],d=(e-h)/Math.max(1e-5,p-h),y=m*s,v=f*s;if(o==="rotation"){let R=[i[y],i[y+1],i[y+2],i[y+3]],b=[i[v],i[v+1],i[v+2],i[v+3]];Mr(n,R,b,d)}else for(let R=0;R<s;R++)n[R]=i[y+R]+d*(i[v+R]-i[y+R])}var wr=new WeakMap;function yi(t,e,n=.3){if(!t?.animations)return;let r=t.animations.find(u=>u.name===e);if(!r)return;let i=wr.get(t);i||(i=[],t.currentClip&&i.push({clip:t.currentClip,time:t.animationTime||0,weight:1,fadeSpeed:0}),wr.set(t,i));let o=n>0?1/n:1e3;for(let u of i)u.clip.name!==e&&(u.fadeSpeed=-o);let a=i.find(u=>u.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 pi(t,e){if(!t.gltf||!Array.isArray(t.gltf.nodes))return;let n=wr.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],a=[0,0,0,1],u=[1,1,1],s=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 p=i[h.nodeIndex];if(h.path==="translation")nn(h,m.time,o),os(p.t,p.t,o,f);else if(h.path==="rotation")nn(h,m.time,a),Mr(p.r,p.r,a,f);else if(h.path==="scale")nn(h,m.time,u),os(p.s,p.s,u,f);else if(h.path==="weights"&&(nn(h,m.time,s),t.meshes)){for(let d of t.meshes)if(d.nodeIndex===h.nodeIndex){for(let y of d.primitives)if(y.pluginData?.morph?.weights){let v=y.pluginData.morph.weights,R=y.pluginData.morph.numTargets||v.length;for(let b=0;b<R;b++)v[b]=v[b]*(1-f)+s[b]*f}}}}}let c=[];for(let m=0;m<r;m++){let f=we(),{t:h,r:p,s:d}=i[m];Je(f,p,h,d),c.push(f)}let l=dt(t.gltf,c);t.worldMatrices=l;for(let m of t.meshes)m.nodeIndex>=0&&m.nodeIndex<l.length&&(m.transform.set(l[m.nodeIndex]),Ne(m.normalMatrix,m.transform))}var gi={name:"keyframes",evaluateAnimation:pi,crossFadeTo:yi,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=bi(t.gltf,t.bin))},onUpdate(t,e){if(!t.isPlayingAnimation)return;let n=wr.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),pi(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),pi(t,t.animationTime))}};var Rn=64;function ss(t,e,n){if(!(!t?.meshes||e<0||e>=Rn))for(let r of t.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[e]=n)}}var xi={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;
376
+ `+y.script+`
377
+ ;
378
+ return typeof scene === "object" && scene ? scene : undefined;
379
+ })();`);c=null;let T=W(d,M,P,F);T&&typeof T.toGLB=="function"&&(M=T)}if(!x){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(M);let W=M.toGLB(),T=W instanceof ArrayBuffer?W:W.buffer.slice(W.byteOffset,W.byteOffset+W.byteLength);b({type:"3D_MODEL_READY",glbBuffer:T},[T])}a({type:"DONE",nonce:i})}catch(M){u(M&&M.message||M)}}},a({type:"READY",nonce:i})}function Fi(e,t,r){let i=r?.allowedScriptUrl??null,n=r?.allowClientScripts??i===null,s={nonce:t,engineSrc:e,allowedScriptUrl:i,allowClientScripts:n,revoked:xl},l=(Ae().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${vl.toString()})(${JSON.stringify(s)},[${l}]);`}function Ts(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var St=0;function Ss(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Ml(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var wl=1024,Al=256;function Rs(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let r=e[t];if(typeof r!="number"||!Number.isFinite(r))return!1}return!0}function Vi(e,t){if(!e||typeof e!="object")return null;let r=e;if(r.nonce!==t)return null;switch(r.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof r.message=="string"?r.message:String(r.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,wl)};case"3D_UPDATE_TRANSFORMS":{let i=r.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let n of i)if(!Rs(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let n=Object.keys(i);if(n.length>1e3)return null;let s=Object.create(null),l=i;for(let o of n){if(o.length>Al||o==="__proto__"||o==="constructor"||o==="prototype")return null;let a=l[o];if(!Rs(a))return null;s[o]=a}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=r.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Tl(e){let t=Ml(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ps(e,t,r,i){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(i.modelDispatched)return;i.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":r();return;case"ERROR":r(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Sl(e,t,r,i){let n=Ss(),s=Fi(t,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l=document.createElement("iframe");l.setAttribute("sandbox","allow-scripts"),l.setAttribute("aria-hidden","true"),l.tabIndex=-1,l.style.display="none",l.src=r,St++;let o=!1,a=!1,u={modelDispatched:!1},h,m=()=>{if(o||a)return;let g=l.contentWindow;!g||typeof g.postMessage!="function"||(a=!0,g.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:e.script},"*"))},c=()=>{},d=g=>{if(o||!l.contentWindow||g.source!==l.contentWindow)return;let x=g.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){m();return}let b=Vi(x,n);b&&Ps(b,i,c,u)};c=()=>{o||(o=!0,h!==void 0&&clearTimeout(h),St=Math.max(0,St-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof l.remove=="function"?l.remove():l.parentNode&&l.parentNode.removeChild(l))},h=setTimeout(()=>{o||(c(),Ts(i))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),l.onload=()=>{m()},l.onerror=()=>{c(),i.onError?.(new Error(`Sandbox iframe failed to load "${r}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){c();let g=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw i.onError?.(g),g}return f.appendChild(l),{terminate:c}}function Es(e,t,r,i){if(t==="worker"&&typeof Worker>"u")return i("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return i("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(St>=32)return i(`SecurityError: ${St} 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 n;try{n=pl()}catch(c){let d=c instanceof Error?c.message:String(c);return i(d,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let c;try{c=gl()}catch(d){let f=d instanceof Error?d.message:String(d);return i(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Sl(e,n,c,r))}catch(d){return Promise.reject(d)}}let s=Ss(),l=Fi(n,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let c=new Blob([l],{type:"application/javascript"}),d=URL.createObjectURL(c);try{let f=Ms(d);o=new Worker(f)}finally{URL.revokeObjectURL(d)}}catch(c){let d=c instanceof Error?c.message:String(c);return i(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}St++;let a=!1,u={modelDispatched:!1},h,m=()=>{a||(a=!0,h!==void 0&&clearTimeout(h),St=Math.max(0,St-1),o.terminate())};return h=setTimeout(()=>{a||(m(),Ts(r))},3e3),o.onmessage=c=>{let d=Vi(c.data,s);d&&Ps(d,r,m,u)},o.onerror=c=>{m(),r.onError?.(new Error(`Worker execution error: ${c.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:s}):o.postMessage({type:"EXECUTE",script:e.script,nonce:s}),Promise.resolve({terminate:m})}function Ns(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Cs=e=>(t,r)=>{let i=new Error(t);return e.onError?.(i),r&&e.onToast?.(r),Promise.reject(i)},kr={execute(e,t,r,i){let n=Cs(r),s=Ns(t,n);if(s)return s;try{Tl(e)}catch(l){let o=l instanceof Error?l.message:String(l);return n(o,"Security Error: script exceeds the size limit.")}return i?.allowClientScripts??As()?Es({kind:"script",script:e},t,r,n):n(on,ln)},executeUrl(e,t,r){let i=Cs(r),n=Ns(t,i);if(n)return n;let s;try{s=bl(e)}catch(l){let o=l instanceof Error?l.message:String(l);return i(o,"Security Error: disallowed scene script URL.")}return Es({kind:"url",scriptUrl:s},t,r,i)}},Fr=new Set;function Pt(e,t){let r=`[three-live] ${e} is unsupported; degraded to ${t}.`;Fr.has(r)||(Fr.add(r),typeof console<"u"&&typeof console.warn=="function"&&console.warn(r))}function Ls(){return Array.from(Fr)}function _s(){Fr.clear()}var Ui=class extends nr{constructor(e={}){Pt("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Is=Ui,Et=class extends Ue{constructor(e=[],t=[],r=1,i=0){super();let n=Number(r)||1,s=Math.max(0,Math.min(7,Math.floor(Number(i)||0))),l=s+1,o=[],a=[],u=[],h=[],m=new xe,c=new xe,d=new xe,f=(b,v)=>v.set(e[b*3]||0,e[b*3+1]||0,e[b*3+2]||0),g=(b,v)=>{let p=b.clone().normalize();o.push(p.x*n,p.y*n,p.z*n),a.push(v.x,v.y,v.z),u.push(Math.atan2(p.z,-p.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,p.y)))/Math.PI)},x=(b,v,p)=>{let y=o.length/3,M=s===0?new xe().subVectors(p,v).cross(new xe().subVectors(b,v)).normalize():null;g(b,M||b.clone().normalize()),g(v,M||v.clone().normalize()),g(p,M||p.clone().normalize()),h.push(y,y+1,y+2)};for(let b=0;b<t.length;b+=3){f(t[b],m),f(t[b+1],c),f(t[b+2],d);let v=[];for(let p=0;p<=l;p++){v[p]=[];let y=m.clone().lerp(d,p/l),M=c.clone().lerp(d,p/l),P=l-p;for(let F=0;F<=P;F++)v[p][F]=P===0?y.clone():y.clone().lerp(M,F/P)}for(let p=0;p<l;p++)for(let y=0;y<2*(l-p)-1;y++){let M=y>>1;(y&1)===0?x(v[p][M+1],v[p+1][M],v[p][M]):x(v[p][M+1],v[p+1][M+1],v[p+1][M])}}this.setFromBuffers(o,a,u,h)}},Rl=Et,Ds=class extends Et{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},Vr=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],ks=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],Fs=class extends Et{constructor(e=1,t=0){super(Vr,ks,e,t)}},Ie=(1+Math.sqrt(5))/2,Vs=class extends Et{constructor(e=1,t=0){super([-1,Ie,0,1,Ie,0,-1,-Ie,0,1,-Ie,0,0,-1,Ie,0,1,Ie,0,-1,-Ie,0,1,-Ie,Ie,0,-1,Ie,0,1,-Ie,0,-1,-Ie,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},et=1/Ie,Us=class extends Et{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-et,-Ie,0,-et,Ie,0,et,-Ie,0,et,Ie,-et,-Ie,0,-et,Ie,0,et,-Ie,0,et,Ie,0,-Ie,0,-et,Ie,0,-et,-Ie,0,et,Ie,0,et],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},Os=class extends Si{constructor(e=1,t=1,r=4,i=8){let n=Math.max(1e-4,Number(e)||1),s=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,l=Math.max(2,Math.min(64,Math.floor(Number(r)||4))),o=[];for(let a=-1;a<=1;a+=2)for(let u=0;u<=l;u++){if(a>0&&u===0&&s===0)continue;let h=(a<0?u/l-1:u/l)*(Math.PI/2);o.push(new ut(Math.max(0,Math.cos(h)*n),a*s+Math.sin(h)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(i)||8))))}},Oi=class extends Ue{constructor(e=.5,t=1,r=32,i=1,n=0,s=Math.PI*2){super();let l=Math.max(1e-4,Number(t)||1),o=Number(e),a=Number.isFinite(o)?Math.max(0,o):l*.5,u=Math.max(l,a),h=Math.min(u*.999,Math.min(l,a)),m=Math.max(3,Math.min(256,Math.floor(Number(r)||32))),c=Math.max(1,Math.min(64,Math.floor(Number(i)||1))),d=Number.isFinite(Number(n))?Number(n):0,f=Number.isFinite(Number(s))?Number(s):Math.PI*2,g=[],x=[],b=[],v=[];for(let p=0;p<=c;p++){let y=h+p/c*(u-h);for(let M=0;M<=m;M++){let P=d+M/m*f,F=Math.cos(P),W=Math.sin(P);if(g.push(y*F,y*W,0),x.push(0,0,1),b.push(y/u*F*.5+.5,y/u*W*.5+.5),p<c&&M<m){let T=p*(m+1)+M,E=T+m+1;y>1e-6&&v.push(T,E,T+1),v.push(E,E+1,T+1)}}}this.setFromBuffers(g,x,b,v)}},Bs=class extends Oi{constructor(e=1,t=32,r=0,i=Math.PI*2){super(0,e,t,1,r,i)}},Bi=class extends it{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Ur=class extends it{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},zs=class extends Ur{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function $s(e,t){let r=e?.attributes?.position;if(!r?.array||r.count<3)return new Float32Array(0);let i=r.array,n=e?.index?.array,s=Math.min(8192,Math.floor((n?n.length:r.count)/3)),l=c=>`${Math.round((i[c*3]||0)*1e4)},${Math.round((i[c*3+1]||0)*1e4)},${Math.round((i[c*3+2]||0)*1e4)}`,o=t===void 0,a=o?1:Math.cos(t*Math.PI/180),u={},h=[],m=(c,d)=>h.push(i[c*3]||0,i[c*3+1]||0,i[c*3+2]||0,i[d*3]||0,i[d*3+1]||0,i[d*3+2]||0);for(let c=0;c<s;c++){let d=n?n[c*3]:c*3,f=n?n[c*3+1]:c*3+1,g=n?n[c*3+2]:c*3+2,x=i[d*3]||0,b=i[d*3+1]||0,v=i[d*3+2]||0,p=(i[f*3]||0)-x,y=(i[f*3+1]||0)-b,M=(i[f*3+2]||0)-v,P=(i[g*3]||0)-x,F=(i[g*3+1]||0)-b,W=(i[g*3+2]||0)-v,T=y*W-M*F,E=M*P-p*W,S=p*F-y*P,O=Math.hypot(T,E,S);if(!o&&O<1e-8)continue;O>0&&(T/=O,E/=O,S/=O);let k=[d,f,g];for(let w=0;w<3;w++){let ie=k[w],oe=k[(w+1)%3],I=l(ie),H=l(oe);if(I===H)continue;let N=I<H?`${I}|${H}`:`${H}|${I}`,z=u[N];z?z.m||(z.m=1,z.nx*T+z.ny*E+z.nz*S<=a&&m(ie,oe)):(u[N]={va:ie,vb:oe,nx:T,ny:E,nz:S,m:o?1:0},o&&m(ie,oe))}}if(!o){let c=Object.keys(u);for(let d=0;d<c.length;d++){let f=u[c[d]];f&&!f.m&&m(f.va,f.vb)}}return new Float32Array(h)}var Hs=class extends Ue{constructor(e){super(),this.setAttribute("position",new He($s(e),3)),this.__isSegmentPairs=!0}},Ws=class extends Ue{constructor(e,t=1){super();let r=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new He($s(e,r),3)),this.__isSegmentPairs=!0}};function Pl(e,t,r=1){let i=new Ue;i.__baked=!0;let n=e?.attributes?.position;if(!n?.array||n.count<2)return i;let s=n.array,l=e.index?.array,o=e.__isSegmentPairs?"segments":t,a=l?l.length:n.count,u=Math.min(4096,Math.max(0,o==="segments"?Math.floor(a/2):o==="loop"&&a>=3?a:a-1));if(u===0)return i;e.computeBoundingBox();let h=e.boundingBox,m=h&&h.max.distanceTo(h.min)||1,c=Math.max(.0015,Math.min(.025,m*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(r)||1))),d=[],f=[],g=[],x=[];for(let b=0;b<u;b++){let v=o==="segments"?b*2:b,p=o==="segments"?b*2+1:(b+1)%a,y=l?l[v]:v,M=l?l[p]:p,P=s[y*3]||0,F=s[y*3+1]||0,W=s[y*3+2]||0,T=(s[M*3]||0)-P,E=(s[M*3+1]||0)-F,S=(s[M*3+2]||0)-W,O=Math.hypot(T,E,S);if(O<1e-6)continue;let k=T/O,w=E/O,ie=S/O,oe=(Math.abs(w)<.9?Math.hypot(ie,k):Math.hypot(ie,w))||1,I=Math.abs(w)<.9?ie/oe:0,H=Math.abs(w)<.9?0:-ie/oe,N=Math.abs(w)<.9?-k/oe:w/oe,z=w*N-ie*H,ue=ie*I-k*N,he=k*H-w*I,B=d.length/3,$=[[I,H,N],[z,ue,he],[-I,-H,-N],[-z,-ue,-he]];for(let _=0;_<2;_++){let G=P+_*T,j=F+_*E,q=W+_*S;for(let D=0;D<4;D++){let Y=$[D];d.push(G+Y[0]*c,j+Y[1]*c,q+Y[2]*c),f.push(Y[0],Y[1],Y[2]),g.push(D/4,_)}}for(let _=0;_<4;_++){let G=(_+1)%4;x.push(B+_,B+G,B+4+G,B+_,B+4+G,B+4+_)}}return d.length>0&&i.setFromBuffers(d,f,g,x),i}function El(e,t=.05){let r=new Ue;r.__baked=!0;let i=e?.attributes?.position;if(!i?.array||i.count<1)return r;let n=i.array,s=i.count,l=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),a=[],u=[],h=[],m=[];for(let c=0;c<l;c++){let d=s<=5e3?c:Math.floor(c*s/l),f=n[d*3]||0,g=n[d*3+1]||0,x=n[d*3+2]||0,b=c*6;for(let v=0;v<6;v++){let p=Vr[v*3],y=Vr[v*3+1],M=Vr[v*3+2];a.push(f+p*o,g+y*o,x+M*o),u.push(p,y,M),h.push(.5,.5)}for(let v=0;v<24;v++)m.push(b+ks[v])}return r.setFromBuffers(a,u,h,m),r}var zt=class extends At{constructor(e,t,r="strip"){let i=t&&typeof t=="object"?t:{},n=t instanceof it?t:r==="points"?new Bi(i):new Ur(i),s=e instanceof Ue?e:new Ue;super(s,n),this.isLine=!0,this._lineMode=r,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let r=t.array,i=Math.min(t.count,64),n=0,s=0,l=0;for(let o=0;o<i;o++)n+=r[o*3]||0,s+=r[o*3+1]||0,l+=r[o*3+2]||0;this.material.color.setRGB(n/i,s/i,l/i)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?El(this._sourceGeo,this.material?.size??.05):Pl(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Gs=class extends zt{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},js=class extends zt{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},qs=class extends zt{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},Xs=class extends Ni{constructor(e,t,r=0,i=Math.PI/3,n=0,s=2){super(e,t,r,s),this.target=new yt,this.type="spot";let l=Number(i);this.angle=Number.isFinite(l)?Math.max(.01,Math.min(Math.PI/2,l)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},zi=class extends Ei{constructor(e,t,r){Pt("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new gt(t??4473924)}},Ks=zi,Ys={Vector2:ut,Vector3:xe,Vector4:zn,Euler:wi,Quaternion:Cr,Matrix4:Ot,Matrix3:$n,Color:gt,MathUtils:Wn,BufferAttribute:He,Float32BufferAttribute:Gn,Uint16BufferAttribute:jn,Uint32BufferAttribute:qn,BufferGeometry:Ue,BoxGeometry:Ai,PlaneGeometry:Xn,SphereGeometry:Kn,CylinderGeometry:Ti,ConeGeometry:Yn,TorusGeometry:Zn,TorusKnotGeometry:Jn,Curve:Rt,Curve3:Rt,LineCurve3:es,QuadraticBezierCurve3:ts,CubicBezierCurve3:rs,CatmullRomCurve3:is,LatheGeometry:Si,TubeGeometry:ns,PolyhedronGeometry:Et,IcosahedronGeometry:Vs,OctahedronGeometry:Fs,DodecahedronGeometry:Us,TetrahedronGeometry:Ds,CapsuleGeometry:Os,RingGeometry:Oi,CircleGeometry:Bs,WireframeGeometry:Hs,EdgesGeometry:Ws,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:Ir,DataTexture:ss,TextureLoader:as,Material:it,MeshStandardMaterial:nr,MeshBasicMaterial:os,MeshLambertMaterial:ls,MeshPhongMaterial:us,MeshPhysicalMaterial:hs,PointsMaterial:Bi,LineBasicMaterial:Ur,LineDashedMaterial:zs,ShaderMaterial:Ui,RawShaderMaterial:Is,Object3D:yt,Group:cs,Mesh:At,InstancedMesh:Pi,Line:zt,LineLoop:Gs,LineSegments:js,Points:qs,Light:ar,AmbientLight:Ei,DirectionalLight:fs,PointLight:Ni,SpotLight:Xs,HemisphereLight:zi,RectAreaLight:Ks,Camera:Ci,PerspectiveCamera:ps,Scene:Li,WebGLRenderer:gs,Clock:bs,SceneQuotaValidator:Tt,exportSceneToCanvas3D:_i,exportSceneToGLB:Ii,exportSceneToUSDZ:ds,generateUSDZ:bi,glbToUSDZ:yi,sceneToCanvas3D:ir,sceneToGLB:Tr,sceneToUSDZ:Nr,authorScriptRunner:kr,getAuthorWarnings:Ls,clearAuthorWarnings:_s};Object.freeze(Tt),Object.freeze(Tt.prototype),Object.freeze(Li.prototype),Object.freeze(Ys);var $t=new Proxy(Ys,{get:(e,t)=>{if(t in e)return e[t];let r=Ae().authorNamespace;return r&&typeof t=="string"&&t in r?r[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Pt(`THREE.${t}`,"no-op proxy"),or)},has:(e,t)=>{if(t in e)return!0;let r=Ae().authorNamespace;return!!(r&&typeof t=="string"&&t in r)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Or=Ae();if(Or.threeNamespace=$t,Or.workerExtensionInstallers)for(let e of Or.workerExtensionInstallers)e($t,Or);var ur={name:"three_author",THREE:$t},Nl=ur,bt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof bt.THREE>"u"&&(bt.THREE=$t),typeof bt.requestAnimationFrame!="function"&&(bt.requestAnimationFrame=e=>(typeof e=="function"&&typeof bt.__three_live_raf_cb__!="function"&&(bt.__three_live_raf_cb__=e),bt.__three_live_in_step__||Pt("requestAnimationFrame","single-frame static evaluation"),0)),typeof bt.cancelAnimationFrame!="function"&&(bt.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=$t,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=ur,e.ThreeLivePlugins.three_author=ur,e.ThreeLivePlugins["three-author"]=ur}function Br(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var $i=(e,t,r)=>({x:e,y:t,z:r,toString:()=>`${e}m ${t}m ${r}m`}),Cl=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(e,t){super(e,t),this.detail=t?.detail??null}});var zr=class We extends Cl{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.loadController=null,this.resizeObserver=null,this.mutationObserver=null}static get arProvider(){return Ae().arProvider}static set arProvider(t){Ae().arProvider=t}static get scriptRunner(){return Ae().scriptRunner}static set scriptRunner(t){Ae().scriptRunner=t}static get sandboxEngineSrc(){return Ae().sandboxEngineSrc??null}static set sandboxEngineSrc(t){Ae().sandboxEngineSrc=t}static get sandboxIframeSrc(){return Ae().sandboxIframeSrc??null}static set sandboxIframeSrc(t){Ae().sandboxIframeSrc=t}static get allowClientScripts(){return!!Ae().allowClientScripts}static set allowClientScripts(t){Ae().allowClientScripts=t}static registerScriptRunner(t){We.scriptRunner=t}static defineModelViewer(t="model-viewer"){if(typeof customElements>"u")return!1;let r=customElements.get(t);if(r!=null)return r===We||r.prototype instanceof We;class i extends We{}return customElements.define(t,i),!0}static registerDecoder(t,r){Qe.registerDecoder(t,r)}static getDecoder(t){return Qe.getDecoder(t)}static registerAR(t){typeof t=="function"?We.arProvider={activateAR:t}:We.arProvider=t,typeof document<"u"&&document.querySelectorAll("three-live").forEach(r=>{r instanceof We&&r.updateARButtonVisibility()})}static isARSupported(){return!!We.arProvider}getLoadedModel(){return this.currentModel}beginLoad(){let t=this.loadController,r=this.scriptHandle,i=new AbortController;return this.loadController=i,this.scriptHandle=null,t?.abort(),r?.terminate(),i}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 t=this.getAttribute("src"),r=this.getAttribute("script-src");if(t)this.loadModel(t).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 Qe.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let t of Qe.getRegisteredPlugins())t.onElementDisconnected?.(this);this.beginLoad().abort(),this.mutationObserver?.disconnect(),this.mutationObserver=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.activeXRSession?.stop?.().catch?.(()=>{}),this.activeXRSession=null,this.toastTimer&&clearTimeout(this.toastTimer),this.toastTimer=null,this.viewer?.destroy(),this.viewer=null,this.isModelLoaded=!1}attributeChangedCallback(t,r,i){if(r!==i){switch(t){case"src":i&&this.loadModel(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 n=parseFloat(i);isNaN(n)||this.viewer.setExposure(n)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer?.setToneMapping(Vt(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 n=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(n),this.canvas&&(this.canvas.style.touchAction=n?"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 n of Qe.getRegisteredPlugins())n.onAttributeChanged?.(this,t,r,i)}}getAttr(t){return this.getAttribute(t)}setAttr(t,r){r!==null?this.setAttribute(t,String(r)):this.removeAttribute(t)}getBoolAttr(t){return this.hasAttribute(t)&&this.getAttr(t)!=="false"}setBoolAttr(t,r){this.setAttr(t,r?"":null)}getFloatAttr(t,r){let i=this.getAttr(t);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(t){this.setAttr("src",t)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(t){this.setBoolAttr("camera-controls",t)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(t){this.setAttr("camera-orbit",t)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(t){this.setAttr("camera-target",t)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(t){this.setAttr("min-camera-orbit",t)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(t){this.setAttr("max-camera-orbit",t)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(t){this.setAttr("field-of-view",t)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(t){this.setAttr("ios-src",t)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(t){this.setAttr("script-src",t)}get sandbox(){return this.getAttr("sandbox")||(Ae().sandboxIframeSrc?"iframe":"worker")}set sandbox(t){this.setAttr("sandbox",t)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||We.allowClientScripts}set allowClientScripts(t){this.setBoolAttr("allow-client-scripts",t)}get poster(){return this.getAttr("poster")}set poster(t){this.setAttr("poster",t)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(t){this.setAttr("selected-mesh",t)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(t){this.setAttr("exposure",t)}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(t){this.setBoolAttr("auto-rotate",t)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(t){this.setAttr("auto-rotate-delay",t)}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(t){this.setAttr("rotation-per-second",t)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(t){this.setBoolAttr("ar",t)}get arScale(){return this.getAttr("ar-scale")||"auto"}set arScale(t){this.setAttr("ar-scale",t)}get arPlacement(){return this.getAttr("ar-placement")||"floor"}set arPlacement(t){this.setAttr("ar-placement",t)}get canActivateAR(){return We.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(t){this.setAttr("shadow-intensity",t)}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(t){this.setAttr("shadow-softness",t)}get toneMapping(){return Vt(this.getAttr("tone-mapping"))}set toneMapping(t){this.setAttr("tone-mapping",t)}get bloom(){return this.getFloatAttr("bloom",0)}set bloom(t){this.setAttr("bloom",t)}get bloomThreshold(){return Br(this.getAttr("bloom-threshold"),.62)}set bloomThreshold(t){this.setAttr("bloom-threshold",t)}get bloomRadius(){return Br(this.getAttr("bloom-radius"),.75)}set bloomRadius(t){this.setAttr("bloom-radius",t)}get outlineSelected(){return this.getBoolAttr("outline-selected")}set outlineSelected(t){this.setBoolAttr("outline-selected",t)}get outlineColor(){return this.getAttr("outline-color")||"#38bdf8"}set outlineColor(t){this.setAttr("outline-color",t)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(t){this.setAttr("environment-image",t)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(t){this.setAttr("skybox-image",t)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(t){this.setBoolAttr("autoplay",t)}get animationName(){return this.getAttr("animation-name")}set animationName(t){this.setAttr("animation-name",t)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get variantName(){return this.viewer?this.viewer.getVariantName():this.getAttr("variant-name")}set variantName(t){this.setAttr("variant-name",t)}get availableVariants(){return this.viewer?this.viewer.getAvailableVariants():[]}fireEvent(t,r){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:r}))}setSlotVisible(t,r){let i=typeof this.querySelector=="function"?this.querySelector(`[slot="${t}"]`):null;i&&(i.hidden=!r,i.style&&(i.style.display=r?"":"none"))}emitError(t,r="script"){this.setSlotVisible("error",!0),this.fireEvent("error",{error:t}),this.fireEvent("three-error",{error:t,message:t?.message||String(t),stage:r})}selectVariant(t){if(!this.viewer)return!1;let r=this.viewer.selectVariant(t);return r&&this.fireEvent("variant-applied",{variantName:this.viewer.getVariantName()}),r}get model(){let t=this.viewer?this.viewer.getModelMaterials():[];return{materials:t,getMaterialByName(r){return t.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(t=0){this.viewer?.resetTurntableRotation(t)}setCamera(t,r,i,n){this.viewer&&this.viewer.setCamera(t,r,i,n)}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():$i(0,0,0)}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(t,r){return this.viewer?.render?.(),this.canvas?this.canvas.toDataURL(t,r):""}toBlob(t){return 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(n=>{n?r(n):i(new Error("Failed to capture canvas blob."))},t?.mimeType,t?.qualityArgument)})}positionAndNormalFromPoint(t,r){let i=this.viewer?.raycastFromScreenPoint(t,r);if(!i)return null;let[n,s,l]=i.hitPoint||i.point,[o,a,u]=i.normal;return{position:$i(n,s,l),normal:$i(o,a,u)}}loadModel(t){return this.loadModelWithLimits(t)}async loadModelWithLimits(t,r,i=this.beginLoad()){if(i.signal.throwIfAborted(),!this.viewer){this.currentModel=t,this.currentModelLimits=r;return}try{let n;if(typeof t=="string"){let a=await fetch(t,{signal:i.signal});if(!a.ok)throw new Error(`Failed to load "${t}": HTTP ${a.status}`);n=await a.arrayBuffer()}else n=t;i.signal.throwIfAborted();let s=tr(n);this.viewer.loadGLBData(s,r),this.currentModel=s,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.setSlotVisible("error",!1),this.updateHotspots();let l=this.getAttr("selected-mesh");l&&this.viewer.setSelectedMesh(l);let o=this.getAttr("variant-name");o&&this.selectVariant(o),this.fireEvent("load",{model:s}),this.fireEvent("three-load",{model:s,source:typeof t=="string"?"src":"model"})}catch(n){throw i.signal.aborted||this.emitError(n,"load"),n}}showToast(t,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=t,this.toastTimer&&clearTimeout(this.toastTimer);let n=()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")};typeof requestAnimationFrame<"u"?requestAnimationFrame(n):n(),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){this.activeXRSession?.isSessionActive?.()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null);let t=(n,s=n.message)=>{throw this.fireEvent("ar-status",{status:"failed",error:n}),this.showToast(s,6e3),n};this.currentModel||t(new Error("No 3D model is loaded in <three-live>.")),We.arProvider||t(new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR()."));let r=this.getAttr("ios-src"),i=(this.getAttr("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.fireEvent("ar-status",{status:"session-started"});let n=await We.arProvider.activateAR({model:r||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:i.length>0?i:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"not-presenting"})},onError:s=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"failed",error:s}),this.showToast(`AR error: ${s.message}`,6e3)}}});if(n.success){n.session&&(this.activeXRSession=n.session);let s=n.mode==="quick-look"?"Opening Apple AR Quick Look...":n.mode==="scene-viewer"?"Opening Google Scene Viewer...":n.mode==="webxr"?"WebXR AR session started.":"";s&&this.showToast(s)}else{let s=n.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.";if(this.isDesktopMac()&&typeof document<"u"&&this.currentModel&&We.arProvider.createUSDZBlob)try{let l=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:We.arProvider.createUSDZBlob(this.currentModel),o=URL.createObjectURL(l),a=document.createElement("a");a.href=o,a.download="three_live_model.usdz",document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(()=>URL.revokeObjectURL(o),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(s,6e3)}else this.showToast(s,6e3);n.error&&this.fireEvent("ar-status",{status:"failed",error:n.error})}return n}catch(n){return this.activeXRSession=null,t(n,`AR error: ${n.message||String(n)}`)}}setupDOM(){let t=this.querySelector("canvas");t||(t=document.createElement("canvas"),t.style.cssText=`width:100%;height:100%;display:block;touch-action:${this.cameraControls?"none":"auto"};outline:none`,this.appendChild(t)),this.canvas=t,typeof t.addEventListener=="function"&&!t.__tlCtxBound&&(t.__tlCtxBound=!0,t.addEventListener("webglcontextlost",i=>this.fireEvent("three-context-lost",{originalEvent:i})),t.addEventListener("webglcontextrestored",i=>this.fireEvent("three-context-restored",{originalEvent:i}))),this.setSlotVisible("error",!1),this.isModelLoaded||this.setSlotVisible("poster",!0);let r=this.getAttr("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 t=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),n=this.parseOrbitLimit(this.getAttr("max-camera-orbit")),s=this.parseCameraTarget(this.getAttr("camera-target")),l=this.parseFieldOfView(this.getAttr("field-of-view"));this.viewer=new Qe(this,this.canvas,{autoRotate:t,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttr("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.getAttr("variant-name")||void 0,fieldOfView:l,cameraTarget:s,minCameraOrbit:i,maxCameraOrbit:n,onMeshClick:a=>{this.fireEvent("meshclick",a)},onCameraChange:a=>{this.updateHotspots();for(let u of Qe.getRegisteredPlugins())u.onCameraChange?.(this.viewer,this);this.fireEvent("camera-change",a)}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let o=this.getAttr("camera-orbit");o&&this.applyCameraOrbit(o),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(t){if(!(typeof document>"u")){if(!t){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.alt="3D Scene Preview",this.posterEl.style.cssText="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:opacity .35s ease-out;pointer-events:none;z-index:1",this.appendChild(this.posterEl)),this.posterEl.src=t,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.setSlotVisible("poster",!1),this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}isDesktopMac(){let t=typeof navigator<"u"&&navigator.userAgent||"";return/Macintosh/i.test(t)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1)&&!/Android|iPhone|iPad|iPod/i.test(t)}syncARButtonLabel(t){let r=this.isDesktopMac(),i=r?"Quick Look (.usdz)":"View in AR",n=r?"Download .usdz preview for macOS Quick Look (live camera AR requires iOS or Android)":"View in Augmented Reality";typeof t.setAttribute=="function"&&(t.setAttribute("aria-label",n),t.setAttribute("title",n));let s=t._labelSpan||(typeof t.querySelector=="function"?t.querySelector("span"):null);s&&(s.textContent=i)}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let t=document.createElement("button");t.type="button",t.className="three-live-ar-button",t.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let n=document.createElementNS(r,"svg");for(let[l,o]of[["width","20"],["height","20"],["viewBox","0 0 24 24"],["fill","none"],["stroke","currentColor"],["stroke-width","2"],["stroke-linecap","round"],["stroke-linejoin","round"]])n.setAttribute(l,o);n.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 16zM3.27 6.96 12 12.01l8.73-5.05M12 22.08V12"),n.appendChild(s),t.appendChild(n)}let i=document.createElement("span");t._labelSpan=i,t.appendChild(i),this.syncARButtonLabel(t),t.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",t.addEventListener("mouseenter",()=>{t.style.backgroundColor="rgba(30, 41, 59, 0.95)",t.style.transform="scale(1.04)"}),t.addEventListener("mouseleave",()=>{t.style.backgroundColor="rgba(15, 23, 42, 0.85)",t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),this.activateAR()}),this.arButton=t,this.appendChild(t)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let t=this.hasAttribute("ar")&&!!We.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=t?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.syncARButtonLabel(this.arButton),this.arButton.style.display=t?"flex":"none")}applyCameraOrbit(t){if(!(!t||!this.viewer))try{let r=JSON.parse(t);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=this.parseOrbitLimit(t);(r.theta!==void 0||r.phi!==void 0)&&this.viewer.setInitialCamera(r.theta,r.phi,r.distance)}}parseOrbitLimit(t){if(!t)return{};let[r,i,n]=t.trim().split(/\s+/),s=n&&n!=="auto"?parseFloat(n):NaN;return{theta:r&&r!=="auto"?this.parseFieldOfView(r):void 0,phi:i&&i!=="auto"?this.parseFieldOfView(i):void 0,distance:isNaN(s)?void 0:s}}applyOrbitLimits(){if(!this.viewer)return;let t=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttr("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:t.theta,maxTheta:r.theta,minPhi:t.phi,maxPhi:r.phi,minDistance:t.distance,maxDistance:r.distance})}parseCameraTarget(t){if(!t)return;let r=t.trim().split(/\s+/).map(parseFloat);return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(t){if(!t)return;let r=parseFloat(t);return isNaN(r)?void 0:t.endsWith("rad")?r*180/Math.PI:r}parseRotationPerSecond(t){if(!t)return Math.PI/6;let r=t.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(t){let r=this.parseCameraTarget(t);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(t){let r=this.parseFieldOfView(t);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(t){let r=this.querySelector(`[slot="${t.name}"]`);r&&(t.position!==void 0&&r.setAttribute("data-position",t.position),t.normal!==void 0&&r.setAttribute("data-normal",t.normal)),this.updateHotspots()}updateHotspots(){for(let t of Qe.getRegisteredPlugins())if(t.updateHotspotsForElement){t.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(t){let r=We.scriptRunner;if(!r){let s=new Error('Script execution requires "three-live/full" or registerScriptRunner().');return this.showToast(s.message),this.emitError(s,"script"),Promise.reject(s)}let i=this.beginLoad(),n=()=>!i.signal.aborted;return new Promise((s,l)=>{let o=()=>l(i.signal.reason);if(i.signal.addEventListener("abort",o,{once:!0}),!n()){o();return}let a={onModelReady:u=>{this.loadModelWithLimits(u,Qo,i).then(()=>s(u),l)},onUpdateTransforms:u=>{n()&&this.viewer?.updateMeshTransforms(u)},onError:u=>{n()&&(this.showToast(u.message),this.emitError(u,"script"),l(u))},onToast:u=>{n()&&this.showToast(u)}};t(r,a).then(u=>{n()?this.scriptHandle=u||null:u?.terminate()},u=>{n()&&a.onError?.(u)})})}loadScriptFromSrc(t){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let n=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(n),Promise.reject(n)}return r.executeUrl(t,this.sandbox,i)})}executeScript(t){if(!We.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(on);return this.showToast(ln),this.emitError(r,"security"),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(t,this.sandbox,i,{allowClientScripts:!0}))}};zr.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"],zr.registerPlugin=Qe.registerPlugin,zr.getRegisteredPlugins=Qe.getRegisteredPlugins;var Ht=zr;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",Ht);function Ll(e="model-viewer"){return Ht.defineModelViewer(e)}function Zs(e,t,r){return t%4===0?new Float32Array(e,t,r):new Float32Array(e.slice(t,t+r*4))}function Hi(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=r[0],u=r[1],h=r[2],m=r[3],c=n*a+s*u+l*h+o*m;if(c<0&&(a=-a,u=-u,h=-h,m=-m,c=-c),Math.abs(c)>=1)return e[0]=n,e[1]=s,e[2]=l,e[3]=o,e;let d=Math.acos(c),f=Math.sqrt(1-c*c);if(Math.abs(f)<.001)return e[0]=.5*(n+a),e[1]=.5*(s+u),e[2]=.5*(l+h),e[3]=.5*(o+m),e;let g=Math.sin((1-i)*d)/f,x=Math.sin(i*d)/f;return e[0]=n*g+a*x,e[1]=s*g+u*x,e[2]=l*g+h*x,e[3]=o*g+m*x,e}function Qs(e,t,r,i){return e[0]=t[0]+i*(r[0]-t[0]),e[1]=t[1]+i*(r[1]-t[1]),e[2]=t[2]+i*(r[2]-t[2]),e}function Js(e,t){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let n=e.animations[i],s=n.name||`Animation_${i}`,l=[],o=0;if(Array.isArray(n.channels)&&Array.isArray(n.samplers))for(let a of n.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let u=n.samplers[a.sampler];if(!u)continue;let h=e.accessors?.[u.input],m=e.accessors?.[u.output];if(!h||!m)continue;let c=e.bufferViews?.[h.bufferView],d=e.bufferViews?.[m.bufferView];if(!c||!d)continue;let f=(c.byteOffset||0)+(h.byteOffset||0),g=(d.byteOffset||0)+(m.byteOffset||0),x=kt(e,t,h,1)??Zs(t,f,h.count);x.length>0&&x[x.length-1]>o&&(o=x[x.length-1]);let b=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,h.count))):3,v=a.target.path==="weights"?1:b,p=kt(e,t,m,v)??Zs(t,g,m.count*v),y=u.interpolation==="STEP"?"STEP":"LINEAR";l.push({nodeIndex:a.target.node,path:a.target.path,times:x,values:p,interpolation:y})}l.length>0&&r.push({name:s,duration:o,channels:l})}return r}function hr(e,t,r){let{times:i,values:n,path:s,interpolation:l}=e,o=i.length;if(o===0)return;let a=s==="rotation"?4:s==="weights"?Math.max(1,Math.round(n.length/o)):3;if(t<=i[0]){for(let v=0;v<a;v++)r[v]=n[v];return}if(t>=i[o-1]){let v=(o-1)*a;for(let p=0;p<a;p++)r[p]=n[v+p];return}let u=0,h=o-1;for(;u<=h;){let v=u+h>>1;i[v]<=t?u=v+1:h=v-1}let m=Math.max(0,h),c=Math.min(o-1,m+1);if(l==="STEP"||m===c){let v=m*a;for(let p=0;p<a;p++)r[p]=n[v+p];return}let d=i[m],f=i[c],g=(t-d)/Math.max(1e-5,f-d),x=m*a,b=c*a;if(s==="rotation"){let v=[n[x],n[x+1],n[x+2],n[x+3]],p=[n[b],n[b+1],n[b+2],n[b+3]];Hi(r,v,p,g)}else for(let v=0;v<a;v++)r[v]=n[x+v]+g*(n[b+v]-n[x+v])}var cr=new WeakMap;function ea(e,t,r=.3){if(!e?.animations)return;let i=e.animations.find(o=>o.name===t);if(!i)return;let n=cr.get(e);n||(n=[],e.currentClip&&n.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),cr.set(e,n));let s=r>0?1/r:1e3;for(let o of n)o.clip.name!==t&&(o.fadeSpeed=-s);let l=n.find(o=>o.clip.name===t);l?l.fadeSpeed=s:n.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:s}),e.currentClip=i,e.isPlayingAnimation=!0}function Wi(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=cr.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,n=[];for(let m=0;m<i;m++){let c=e.initialNodeTransforms[m];c?n.push({t:[c.t[0],c.t[1],c.t[2]],r:[c.r[0],c.r[1],c.r[2],c.r[3]],s:[c.s[0],c.s[1],c.s[2]]}):n.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let s=[0,0,0],l=[0,0,0,1],o=[1,1,1],a=new Float32Array(64);for(let m of r){let c=Math.max(0,Math.min(1,m.weight));if(!(c<=1e-4))for(let d of m.clip.channels){if(d.nodeIndex<0||d.nodeIndex>=i)continue;let f=n[d.nodeIndex];if(d.path==="translation")hr(d,m.time,s),Qs(f.t,f.t,s,c);else if(d.path==="rotation")hr(d,m.time,l),Hi(f.r,f.r,l,c);else if(d.path==="scale")hr(d,m.time,o),Qs(f.s,f.s,o,c);else if(d.path==="weights"&&(hr(d,m.time,a),e.meshes)){for(let g of e.meshes)if(g.nodeIndex===d.nodeIndex){for(let x of g.primitives)if(x.pluginData?.morph?.weights){let b=x.pluginData.morph.weights,v=x.pluginData.morph.numTargets||b.length;for(let p=0;p<v;p++)b[p]=b[p]*(1-c)+a[p]*c}}}}}let u=[];for(let m=0;m<i;m++){let c=Pe(),{t:d,r:f,s:g}=n[m];Qt(c,f,d,g),u.push(c)}let h=vr(e.gltf,u);e.worldMatrices=h;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<h.length&&(m.transform.set(h[m.nodeIndex]),Ke(m.normalMatrix,m.transform))}var Gi=e=>{cr.delete(e)},ta={name:"keyframes",evaluateAnimation:Wi,crossFadeTo:ea,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Js(e.gltf,e.bin))},onLoadModel:Gi,onClearScene:Gi,onDestroy:(e,t)=>Gi(t),onUpdate(e,t){if(!e.isPlayingAnimation)return;let r=cr.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let n=r[i];if(n.time+=t,n.clip.duration>0&&(n.time%=n.clip.duration),n.fadeSpeed!==0)if(n.weight+=n.fadeSpeed*t,n.weight<=0){r.splice(i,1);continue}else n.weight>=1&&(n.weight=1,n.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),Wi(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),Wi(e,e.animationTime))}},mr=64;function _l(e,t,r){if(!(!e?.meshes||t<0||t>=mr))for(let i of e.meshes)for(let n of i.primitives){let s=n.pluginData?.morph;s?.weights&&(s.weights[t]=r)}}var ra={name:"morph",onResolveShader(e,t,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let n=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
329
380
  uniform sampler2D uMorphDeltasTex;
330
- uniform float uMorphWeights[${Rn}];
331
- uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
332
- for (int m = 0; m < ${Rn}; m++) {
381
+ uniform float uMorphWeights[${mr}];
382
+ uniform int uNumMorphTargets;`);return n=n.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
383
+ for (int m = 0; m < ${mr}; m++) {
333
384
  if (m >= uNumMorphTargets) break;
334
385
  float w = uMorphWeights[m];
335
386
  if (abs(w) > 0.0001) {
336
387
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
337
388
  }
338
389
  }
339
- 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,u=r?.accessors?.[a];if(!u)return null;let s=u.count,c=Math.min(o.length,Rn),l=new Float32Array(s*c*4);for(let h=0;h<c;h++){let p=o[h].POSITION;if(p===void 0)continue;let d=r.accessors?.[p],y=r.bufferViews?.[d?.bufferView];if(!d||!y)continue;let v=ot(r,i,d,3);if(!v||v.length<s*3)continue;let R=h*s*4;for(let b=0;b<s;b++)l[R+b*4]=v[b*3],l[R+b*4+1]=v[b*3+1],l[R+b*4+2]=v[b*3+2],l[R+b*4+3]=0}let m=t.createTexture();t.bindTexture(3553,m),t.texImage2D(3553,0,34836,s,c,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(Rn);return{hasMorph:!0,morphTex:m,numTargets:c,vertexCount:s,weights:f}},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 u=t.getUniformLocation(e,"uMorphDeltasTex");u&&t.uniform1i(u,5);let s=t.getUniformLocation(e,"uNumMorphTargets");s&&t.uniform1i(s,a.numTargets);let c=t.getUniformLocation(e,"uMorphWeights[0]");c&&t.uniform1fv(c,a.weights)}};var vi=64,Ti={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;
390
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.targets;if(!Array.isArray(s)||s.length===0)return null;let l=r.attributes?.POSITION,o=i?.accessors?.[l];if(!o)return null;let a=o.count,u=Math.min(s.length,mr),h=new Float32Array(a*u*4);for(let d=0;d<u;d++){let f=s[d].POSITION;if(f===void 0)continue;let g=i.accessors?.[f],x=i.bufferViews?.[g?.bufferView];if(!g||!x)continue;let b=kt(i,n,g,3);if(!b||b.length<a*3)continue;let v=d*a*4;for(let p=0;p<a;p++)h[v+p*4]=b[p*3],h[v+p*4+1]=b[p*3+1],h[v+p*4+2]=b[p*3+2],h[v+p*4+3]=0}let m=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,a,u,0,6408,5126,h),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let c=new Float32Array(mr);return{hasMorph:!0,morphTex:m,numTargets:u,vertexCount:a,weights:c}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.pluginData?.morph;if(!l?.hasMorph||!l.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,l.morphTex);let o=e.getUniformLocation(t,"uMorphDeltasTex");o&&e.uniform1i(o,5);let a=e.getUniformLocation(t,"uNumMorphTargets");a&&e.uniform1i(a,l.numTargets);let u=e.getUniformLocation(t,"uMorphWeights[0]");u&&e.uniform1fv(u,l.weights)}},ji=64,ia={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
340
391
  layout(location=4) in uvec4 aJoints;
341
392
  layout(location=5) in vec4 aWeights;
342
- uniform mat4 uJointMatrix[${vi}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
393
+ uniform mat4 uJointMatrix[${ji}];`),s=n.includes("morphedPos")?"morphedPos":"aPosition";return n=n.replace(`vec4 world=uModel*vec4(${s},1.0);`,`mat4 skinMatrix =
343
394
  aWeights.x * uJointMatrix[int(aJoints.x)] +
344
395
  aWeights.y * uJointMatrix[int(aJoints.y)] +
345
396
  aWeights.z * uJointMatrix[int(aJoints.z)] +
346
397
  aWeights.w * uJointMatrix[int(aJoints.w)];
347
- 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],u=r.accessors[o.WEIGHTS_0];if(!a||!u)return null;let s=r.bufferViews[a.bufferView],c=r.bufferViews[u.bufferView];if(!s||!c)return null;let l=(s.byteOffset||0)+(a.byteOffset||0),m=(c.byteOffset||0)+(u.byteOffset||0),f=t.createBuffer();t.bindBuffer(34962,f);let h=a.componentType===5121?5121:5123,p=h===5121?new Uint8Array(i,l,a.count*4):new Uint16Array(i,l,a.count*4);t.bufferData(34962,p,35044),t.enableVertexAttribArray(4),t.vertexAttribIPointer(4,4,h,0,0);let d=t.createBuffer();t.bindBuffer(34962,d);let y=ot(r,i,u,4)??new Float32Array(i,m,u.count*4);return t.bufferData(34962,y,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 a=o?.nodes?.[r.nodeIndex]?.skin;if(a===void 0||!o.skins||!o.skins[a])return;let s=o.skins[a].joints||[],c=new Float32Array(vi*16);for(let m=0;m<s.length&&m<vi;m++){let f=s[m],h=i[f]||we();c.subarray(m*16,(m+1)*16).set(h)}let l=t.getUniformLocation(e,"uJointMatrix[0]");l&&t.uniformMatrix4fv(l,!1,c)}};Oe(xi);Oe(gi);Oe(Ti);Oe(Yr);Oe(Br);var Xa=`#version 300 es
348
- 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.);}`,Wa=`#version 300 es
349
- 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);}`,En=new WeakMap,as=new Float32Array(20);function wi(t,e){let[n,r,i,o,a,u]=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])*u,Math.abs(t[1])*o+Math.abs(t[5])*a+Math.abs(t[9])*u,Math.abs(t[2])*o+Math.abs(t[6])*a+Math.abs(t[10])*u]}function $a(t){if(t._lb!==void 0)return t._lb;let e=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,a=-1e9;for(let u of t.primitives||[]){let s=u.positions;if(s)for(let c=0;c<s.length;c+=3)s[c]<e&&(e=s[c]),s[c+1]<n&&(n=s[c+1]),s[c+2]<r&&(r=s[c+2]),s[c]>i&&(i=s[c]),s[c+1]>o&&(o=s[c+1]),s[c+2]>a&&(a=s[c+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 ja(t){let e=En.get(t);if(e)return e;let n=(u,s)=>{let c=t.createShader(u);return t.shaderSource(c,s),t.compileShader(c),c},r=t.createProgram();t.attachShader(r,n(35633,Xa)),t.attachShader(r,n(35632,Wa)),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")},En.set(t,e),e}var _n={name:"contact-shadow",onContextRestored(t){En.delete(t)},onAfterRender(t,e,n){let r=e.shadowIntensity;if(r<=0||!e.bounds)return;let i=ja(t),o=!e.xrSessionActive&&(e.backdropMeshes?.length??0)>0,a=[],u=[];for(let d of e.meshes||[]){if(!d||d.visible===!1||d.isPluginMesh||d.name==="__xr_reticle__"||d.name?.startsWith("__xr_slot_"))continue;let y=$a(d);if(!y)continue;d.transform&&(y=wi(d.transform,y)),e.modelRootMatrix&&(y=wi(e.modelRootMatrix,y));let[v,R,b,w,M,P]=y,k=[v,b,w,P,R-M,R+M];/floor|table|pedestal|ground|base|plane/i.test(d.name||"")||M<.14&&Math.min(w,P)>.45?u.push(k):a.push(k)}let s=[],c=e.bounds.center||[0,0,0],l=Math.max(.05,Number(e.bounds.radius)||.5),m=e.bounds.min,f=m?[c[0],c[1],c[2],l,Math.max(.01,c[1]-m[1]),l]:[c[0],c[1],c[2],l,l,l];e.modelRootMatrix&&(f=wi(e.modelRootMatrix,f));let p=e.xrSessionActive&&u.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,y,v,R,b]of a){let w=-1/0;for(let[P,k,I,L,,x]of u)b>=x-.08&&Math.abs(d-P)<=I&&Math.abs(y-k)<=L&&x+.002>w&&(w=x+.002);o&&(w=Math.max(w,d>=.04&&d<=.36&&y>=-.34&&y<=-.04&&b>=.01?.036:Math.hypot(d,y)<=.66&&b>=-.06?.003:-.477)),isFinite(w)||(w=p);let M=s.find(P=>Math.hypot(d-P[0],y-P[1])<.06&&Math.abs(w-P[5])<.05);M?(M[2]=Math.max(M[2],v*.78),M[3]=Math.max(M[3],R*.78),M[4]=Math.min(M[4],b)):s.push([d,y,v,R,b,w])}if(s.length===0){let d=Math.max(.1,f[3]*1.5)/1.45;s.push([f[0],f[2],d,d,p,p])}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,y,v,R,b,w]of s){let M=Math.max(0,b-w),P=r/(1+M*2);if(P<.02)continue;let k=1+Math.min(.75,M*.85),I=Math.max(.045,v*1.45*k),L=Math.max(.045,R*1.45*k);as.set([d-I,w,y-L,0,0,d+I,w,y-L,1,0,d+I,w,y+L,1,1,d-I,w,y+L,0,1]),t.bufferSubData(34962,0,as),t.uniform1f(i.uIntensity,P),t.uniform1f(i.uSoftness,Math.min(1,e.shadowSoftness+Math.min(.45,M*.6))),t.drawElements(4,6,5123,0)}t.bindVertexArray(null),t.depthMask(!0),t.disable(3042)},onDestroy(t){let e=En.get(t);e&&(t.deleteVertexArray(e.vao),t.deleteBuffer(e.vbo),t.deleteBuffer(e.ibo),t.deleteProgram(e.prog),En.delete(t))}};function Si(){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 Ri(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function Ei(){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 ls(){return(await Sr()).bestMode}async function Sr(){let[t,e,n]=await Promise.all([Ei(),Promise.resolve(Si()),Promise.resolve(Ri())]),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 cs(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=qa(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 u=Ar(e.canonicalWebPageUrl,!1);u&&i.push(`canonicalWebPageURL=${encodeURIComponent(u)}`)}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 Ar(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 qa(t){try{return Ar(t,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(t||"").trim().slice(0,32)}`)}}function Ka(t,e={}){let n=Ar(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",Ar(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 Ya(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=Ka(t,e);window.location.href=n}var Ft=null;function Za(t,e){let r=new Float32Array(144),i=new Float32Array(144),o=new Float32Array(96),a=new Uint16Array(144);for(let m=0;m<24;m++){let f=m/24*Math.PI*2,h=Math.cos(f),p=Math.sin(f),d=m*2,y=d+1,v=(m+1)%24*2;r[d*3]=h*.11,r[d*3+1]=.002,r[d*3+2]=p*.11,r[y*3]=h*.145,r[y*3+1]=.002,r[y*3+2]=p*.145,i[d*3+1]=i[y*3+1]=1,a.set([d,v,y,y,v,v+1],m*6)}let u=t.createVertexArray();t.bindVertexArray(u);let s=(m,f,h)=>{let p=t.createBuffer();return t.bindBuffer(34962,p),t.bufferData(34962,m,35044),t.enableVertexAttribArray(f),t.vertexAttribPointer(f,h,5126,!1,0,0),p},c=[s(r,0,3),s(i,1,3),s(o,2,2)],l=t.createBuffer();return c.push(l),t.bindBuffer(34963,l),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:u,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:c}]}}function us(t,e,n,r,i){let o=Math.cos(r),a=Math.sin(r),u=Math.max(.01,i);t.fill(0),t[0]=u*o,t[2]=-u*a,t[5]=u,t[8]=u*a,t[10]=u*o,t[12]=e[0]-u*(o*n[0]+a*n[2]),t[13]=e[1]-u*n[1],t[14]=e[2]-u*(-a*n[0]+o*n[2]),t[15]=1}var Ai=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.");Ft&&Ft!==this&&Ft.isSessionActive()&&await Ft.stop().catch(()=>{});let r=navigator.xr,i=this.opts,o=n||e?.container,a=String(o?.tagName||"").toLowerCase()==="xr-live",u=e?.bounds,s=Number(u?.radius)||1,c=Array.isArray(u?.center)?u.center:[0,0,0],l=Array.isArray(u?.min)?u.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=a?i.arScale==="fixed"?1:f?.55:1:i.arScale==="fixed"?1:s>.45?.3/s:s<.05?.12/Math.max(s,.001):1,p=a?[0,-.25,0]:[c[0]||0,i.arPlacement==="wall"?c[1]:l[1]??0,c[2]||0],d="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(d="immersive-vr")}catch{d="immersive-vr"}let y=o?.querySelector?.('[slot="ar-overlay"]')||null,v=!1,R=null,b=()=>{v&&y?.parentNode&&y.parentNode.removeChild(y),y=null,R=null,v=!1};if(d==="immersive-ar"){if(y)y.addEventListener?.("beforexrselect",E=>E.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let E=document.createElement("div");E.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 V=document.createElement("button");V.type="button",V.textContent="\u2715 Exit AR",V.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",V.addEventListener("beforexrselect",F=>F.preventDefault()),V.addEventListener("click",F=>{F.stopPropagation(),this.stop().catch(()=>{})}),R=document.createElement("div"),R.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",R.textContent="Move phone to detect a surface \u2022 Tap to place",E.appendChild(V),E.appendChild(R),document.body.appendChild(E),y=E,v=!0}}let w=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),M={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(w)};y&&(w.add("dom-overlay"),M.optionalFeatures=Array.from(w),M.domOverlay={root:y});for(let E of De)E.onConfigureXRSessionInit?.(o,M);Array.isArray(M.optionalFeatures)&&M.optionalFeatures.includes("dom-overlay")&&!M.domOverlay?.root&&(M.optionalFeatures=M.optionalFeatures.filter(E=>E!=="dom-overlay"));let P=E=>{let V=String(E?.name||"");return V==="NotAllowedError"||V==="SecurityError"};try{this.s=await r.requestSession(d,M)}catch(E){if(b(),P(E))throw i.onError?.(E),E;try{this.s=await r.requestSession(d,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(V){if(P(V))throw i.onError?.(V),V;try{this.s=await r.requestSession(d)}catch(F){throw i.onError?.(F),F}}}let k=this.s;Ft=this,this.placed=!1;let I=null,L=null,x=null,g=null,A=null,N=[0,-.25,-1.2],_=[0,-.25,-1.2],O=new Float32Array(16),Q=new Float32Array(16),q=!1,oe=1,ne=0,re=!1,H=null,se=null,ae=0,D=null,G=()=>{Ft===this&&(Ft=null),D?.(),D=null;try{L?.cancel?.()}catch{}if(L=null,x){let E=e?.meshes;if(Array.isArray(E)){let F=E.indexOf(x);F!==-1&&E.splice(F,1)}let V=e.getGLContext?.()||e?.gl;if(V)for(let F of x.primitives||[]){V.deleteVertexArray?.(F.vao);for(let U of F.buffers||[])V.deleteBuffer?.(U)}x=null}e?.setXRSessionActive?.(!1),b(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=G,k.addEventListener("end",()=>{G(),i.onExit?.()}),k.addEventListener("select",()=>{if(!this.placed){let E=A||N;_=[E[0],E[1],E[2]],us(this.placedMat,_,p,ne,h*oe),this.placed=!0,x&&(x.visible=!1),R&&(R.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let E=e.getGLContext?.()||e?.gl;E&&typeof E.makeXRCompatible=="function"&&await E.makeXRCompatible();let V=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;E&&typeof V=="function"&&typeof k.updateRenderState=="function"&&k.updateRenderState({baseLayer:new V(k,E,{alpha:!0})});try{I=await k.requestReferenceSpace("local")}catch{try{I=await k.requestReferenceSpace("local-floor")}catch{I=await k.requestReferenceSpace("viewer")}}let F=await k.requestReferenceSpace("viewer").catch(()=>I);if(typeof k.requestHitTestSource=="function"&&F&&(L=await k.requestHitTestSource({space:F}).catch(()=>null)),d==="immersive-ar"&&E&&typeof E.createVertexArray=="function"&&Array.isArray(e.meshes)&&(x=Za(E,i.reticleColor),e.meshes.push(x)),typeof window<"u"&&typeof window.addEventListener=="function"){let z=T=>Math.hypot(T.touches[1].clientX-T.touches[0].clientX,T.touches[1].clientY-T.touches[0].clientY),Y=T=>Math.atan2(T.touches[1].clientY-T.touches[0].clientY,T.touches[1].clientX-T.touches[0].clientX),le=T=>{this.s&&(T.touches.length===1&&this.placed?re=!0:T.touches.length>=2&&(re=!1,H=z(T),se=Y(T)))},ie=T=>{if(!this.s||T.touches.length<2)return;let S=z(T),C=Y(T);if(H&&H>4&&i.arScale!=="fixed"&&(oe=Math.max(.15,Math.min(6,oe*(S/H)))),se!==null){let B=C-se;B>Math.PI&&(B-=Math.PI*2),B<-Math.PI&&(B+=Math.PI*2),ne-=B}H=S,se=C},he=T=>{(!T.touches||T.touches.length===0)&&(re=!1),(!T.touches||T.touches.length<2)&&(H=null,se=null)};window.addEventListener("touchstart",le,{passive:!0}),window.addEventListener("touchmove",ie,{passive:!0}),window.addEventListener("touchend",he,{passive:!0}),window.addEventListener("touchcancel",he,{passive:!0}),D=()=>{window.removeEventListener("touchstart",le),window.removeEventListener("touchmove",ie),window.removeEventListener("touchend",he),window.removeEventListener("touchcancel",he)}}e.setXRSessionActive?.(!0);let U=(z,Y)=>{if(this.s!==k)return;k.requestAnimationFrame(U);let le=ae>0?Math.min(Math.max((z-ae)/1e3,0),.1):1/60;ae=z,e?.stepXRUpdate?.(le);let ie=Y.getViewerPose(I);if(!ie)return;let he=ie.views?.[0];if(!q&&he?.transform){let W=he.transform.position,$=he.transform.matrix,K=W?.x??($?$[12]:0),Z=W?.y??($?$[13]:0),j=W?.z??($?$[14]:0),te=$?-$[8]:0,ee=$?-$[10]:-1,J=Math.hypot(te,ee);J>1e-4?(te/=J,ee/=J):(te=0,ee=-1),N=[K+te*1.2,Z-.25,j+ee*1.2],ne=Math.atan2(-te,-ee),q=!0}if(L&&typeof Y.getHitTestResults=="function"&&(!this.placed||re)){let W=Y.getHitTestResults(L)||[],$=!1;for(let K of W){let Z=K.getPose(I);if(Z?.transform?.matrix){let j=Z.transform.matrix,te=j[5];if(i.arPlacement==="wall"&&Math.abs(te)>.35||i.arPlacement==="floor"&&Math.abs(te)<.65)continue;g||(g=new Float32Array(16)),g.set(j),A=[j[12],j[13],j[14]],this.placed&&re&&(_=[j[12],j[13],j[14]]),x&&(x.visible=!this.placed||re,x.transform.set(j)),!this.placed&&R&&(R.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(g),$=!0;break}}!$&&x&&(x.visible=!1)}us(O,this.placed?_:A||N,p,ne,h*oe),this.placed&&this.placedMat.set(O);let T=e.xrRigMatrix;T instanceof Float32Array&&T.length===16?Le(Q,T,O):Q.set(O),e.modelRootMatrix&&e.modelRootMatrix.set(Q);for(let W of De)W.onXRFrame?.(e,k,Y,I);let S=e.getGLContext?.()||e?.gl,C=k.renderState?.baseLayer;S&&C&&C.framebuffer!==void 0&&S.bindFramebuffer(36160,C.framebuffer);let B=d==="immersive-ar",X=ie.views||[];for(let W=0;W<X.length;W++){let $=X[W];if(typeof e.renderXRView=="function"){let K;if(C&&typeof C.getViewport=="function"){let Z=C.getViewport($);Z&&Z.width>0&&Z.height>0&&(K=[Z.x,Z.y,Z.width,Z.height])}else C?.framebufferWidth>0&&C?.framebufferHeight>0&&(K=[0,0,C.framebufferWidth,C.framebufferHeight]);e.renderXRView($,Q,this.placed,K,B,W)}}S&&C&&C.framebuffer&&S.bindFramebuffer(36160,null)};k.requestAnimationFrame(U)}catch(E){throw typeof k.end=="function"&&await k.end().catch(()=>{}),G(),i.onError?.(E),E}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function Rr(t){let e=await Sr(),n=t.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let u of n)if(e.availableModes.includes(u)){r=u;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 u;if(t.model instanceof Blob&&t.model.type==="model/vnd.usdz+zip")u=t.model;else{if(typeof t.model=="string")return cs(t.model,i),{mode:"quick-look",success:!0};u=Qt(t.model)}return cs(u,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let u=t.glbUrl||(typeof t.model=="string"?t.model:null);if(!u)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Ya(u,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!t.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let u=new Ai(a);return await u.start(t.view,t.element),{mode:"webxr",success:!0,session:u}}}catch(u){return{mode:r,success:!1,error:u}}return{mode:r,success:!1,error:new Error(`Unhandled AR mode: ${r}`)}}ct.registerAR({activateAR:Rr,createUSDZBlob:Qt});ct.registerScriptRunner(en);Oe(_n);var Li=new WeakMap;function Er(t,e){let n=e instanceof Float32Array?e:new Float32Array(e);Li.set(t,n)}function ds(t){return Li.get(t)}async function Qa(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 _i=new WeakMap,fs=new Float32Array(16);async function ms(t,e,n){let r=n?await Qa(t.gl,n):null;t[e]&&t.gl.deleteTexture(t[e]),t[e]=r}var Ii={name:"environment-map",onContextRestored(t){_i.delete(t)},setEnvironmentImage(t,e){return ms(t,"environmentTexture",e)},setSkyboxImage(t,e){return ms(t,"skyboxTexture",e)},onBeforeDrawScene(t,e,n,r,i){if(!t.skyboxTexture||typeof e.createProgram!="function")return;let o=_i.get(e);if(!o){let m=(p,d)=>{let y=e.createShader(p);return e.shaderSource(y,d),e.compileShader(y),y},f=e.createProgram();e.attachShader(f,m(35633,`#version 300 es
350
- 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
351
- 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},_i.set(e,o)}let a=jt(fs,n)||fs;e.depthMask(!1),e.useProgram(o.program),o.vao&&e.bindVertexArray(o.vao),e.activeTexture(33984),e.bindTexture(3553,t.skyboxTexture);let u=e.getUniformLocation(o.program,"uSkyboxMap");u&&e.uniform1i(u,0);let s=e.getUniformLocation(o.program,"uInvVP");s&&e.uniformMatrix4fv(s,!1,a);let c=e.getUniformLocation(o.program,"uCameraPos");c&&e.uniform3f(c,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];
398
+ vec4 world=uModel*(skinMatrix*vec4(${s},1.0));`).replace(`gl_Position=uMVP*vec4(${s},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${s},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.attributes;if(!s||s.JOINTS_0===void 0||s.WEIGHTS_0===void 0)return null;let l=i.accessors[s.JOINTS_0],o=i.accessors[s.WEIGHTS_0];if(!l||!o)return null;let a=i.bufferViews[l.bufferView],u=i.bufferViews[o.bufferView];if(!a||!u)return null;let h=(a.byteOffset||0)+(l.byteOffset||0),m=(u.byteOffset||0)+(o.byteOffset||0),c=e.createBuffer();e.bindBuffer(34962,c);let d=l.componentType===5121?5121:5123,f=d===5121?new Uint8Array(n,h,l.count*4):new Uint16Array(n,h,l.count*4);e.bufferData(34962,f,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,d,0,0);let g=e.createBuffer();e.bindBuffer(34962,g);let x=kt(i,n,o,4)??new Float32Array(n,m,o.count*4);return e.bufferData(34962,x,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[c,g]}},onBeforeDrawPrimitive(e,t,r,i,n,s){if(!r.pluginData?.skinning?.hasSkin)return;let l=s?.nodes?.[i.nodeIndex]?.skin;if(l===void 0||!s.skins||!s.skins[l])return;let o=s.skins[l].joints||[],a=new Float32Array(ji*16);for(let h=0;h<o.length&&h<ji;h++){let m=o[h],c=n[m]||Pe();a.subarray(h*16,(h+1)*16).set(c)}let u=e.getUniformLocation(t,"uJointMatrix[0]");u&&e.uniformMatrix4fv(u,!1,a)}};Ge(ra),Ge(ta),Ge(ia),Ge(bn),Ge(hn);var Il=`#version 300 es
399
+ 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.);}`,Dl=`#version 300 es
400
+ 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);}`,fr=new WeakMap,na=new Float32Array(20);function qi(e,t){let[r,i,n,s,l,o]=t;return[e[0]*r+e[4]*i+e[8]*n+e[12],e[1]*r+e[5]*i+e[9]*n+e[13],e[2]*r+e[6]*i+e[10]*n+e[14],Math.abs(e[0])*s+Math.abs(e[4])*l+Math.abs(e[8])*o,Math.abs(e[1])*s+Math.abs(e[5])*l+Math.abs(e[9])*o,Math.abs(e[2])*s+Math.abs(e[6])*l+Math.abs(e[10])*o]}function kl(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,n=-1e9,s=-1e9,l=-1e9;for(let o of e.primitives||[]){let a=o.positions;if(a)for(let u=0;u<a.length;u+=3)a[u]<t&&(t=a[u]),a[u+1]<r&&(r=a[u+1]),a[u+2]<i&&(i=a[u+2]),a[u]>n&&(n=a[u]),a[u+1]>s&&(s=a[u+1]),a[u+2]>l&&(l=a[u+2])}return e._lb=t<=n?[(t+n)*.5,(r+s)*.5,(i+l)*.5,(n-t)*.5,(s-r)*.5,(l-i)*.5]:null}function Fl(e){let t=fr.get(e);if(t)return t;let r=(o,a)=>{let u=e.createShader(o);return e.shaderSource(u,a),e.compileShader(u),u},i=e.createProgram();e.attachShader(i,r(35633,Il)),e.attachShader(i,r(35632,Dl)),e.linkProgram(i);let n=e.createVertexArray(),s=e.createBuffer(),l=e.createBuffer();return e.bindVertexArray(n),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,l),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:n,vbo:s,ibo:l,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},fr.set(e,t),t}var Xi={name:"contact-shadow",onContextRestored(e){fr.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let n=Fl(e),s=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,l=[],o=[];for(let f of t.meshes||[]){if(!f||f.visible===!1||f.isPluginMesh||f.name==="__xr_reticle__"||f.name?.startsWith("__xr_slot_"))continue;let g=kl(f);if(!g)continue;f.transform&&(g=qi(f.transform,g)),t.modelRootMatrix&&(g=qi(t.modelRootMatrix,g));let[x,b,v,p,y,M]=g,P=[x,v,p,M,b-y,b+y];/floor|table|pedestal|ground|base|plane/i.test(f.name||"")||y<.14&&Math.min(p,M)>.45?o.push(P):l.push(P)}let a=[],u=t.bounds.center||[0,0,0],h=Math.max(.05,Number(t.bounds.radius)||.5),m=t.bounds.min,c=m?[u[0],u[1],u[2],h,Math.max(.01,u[1]-m[1]),h]:[u[0],u[1],u[2],h,h,h];t.modelRootMatrix&&(c=qi(t.modelRootMatrix,c));let d=t.xrSessionActive&&o.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:c[1]-c[4]+.002;for(let[f,g,x,b,v]of l){let p=-1/0;for(let[M,P,F,W,,T]of o)v>=T-.08&&Math.abs(f-M)<=F&&Math.abs(g-P)<=W&&T+.002>p&&(p=T+.002);s&&(p=Math.max(p,f>=.04&&f<=.36&&g>=-.34&&g<=-.04&&v>=.01?.036:Math.hypot(f,g)<=.66&&v>=-.06?.003:-.477)),isFinite(p)||(p=d);let y=a.find(M=>Math.hypot(f-M[0],g-M[1])<.06&&Math.abs(p-M[5])<.05);y?(y[2]=Math.max(y[2],x*.78),y[3]=Math.max(y[3],b*.78),y[4]=Math.min(y[4],v)):a.push([f,g,x,b,v,p])}if(a.length===0){let f=Math.max(.1,c[3]*1.5)/1.45;a.push([c[0],c[2],f,f,d,d])}e.useProgram(n.prog),e.uniformMatrix4fv(n.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(n.vao),e.bindBuffer(34962,n.vbo);for(let[f,g,x,b,v,p]of a){let y=Math.max(0,v-p),M=i/(1+y*2);if(M<.02)continue;let P=1+Math.min(.75,y*.85),F=Math.max(.045,x*1.45*P),W=Math.max(.045,b*1.45*P);na.set([f-F,p,g-W,0,0,f+F,p,g-W,1,0,f+F,p,g+W,1,1,f-F,p,g+W,0,1]),e.bufferSubData(34962,0,na),e.uniform1f(n.uIntensity,M),e.uniform1f(n.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,y*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=fr.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),fr.delete(e))}};function sa(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let t=document.createElement("a");return t.relList!==void 0&&t.relList.supports!==void 0&&t.relList.supports("ar")}function aa(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function oa(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function Vl(){return(await Ki()).bestMode}async function Ki(){let[e,t,r]=await Promise.all([oa(),Promise.resolve(sa()),Promise.resolve(aa())]),i=[];t&&i.push("quick-look"),e&&i.push("webxr"),r&&i.push("scene-viewer");let n=null;return t?n="quick-look":e?n="webxr":r&&(n="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:r,availableModes:i,bestMode:n}}function la(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let r,i=!1;if(typeof e=="string"){if(r=Ul(e),!r)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else r=URL.createObjectURL(e),i=!0;let n=[];if(t.allowScale===!1&&n.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let o=$r(t.canonicalWebPageUrl,!1);o&&n.push(`canonicalWebPageURL=${encodeURIComponent(o)}`)}t.checkoutTitle&&n.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&n.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&n.push(`price=${encodeURIComponent(t.price)}`),n.length>0&&(r+=`#${n.join("&")}`);let s=document.createElement("a");s.setAttribute("rel","ar"),s.setAttribute("href",r);let l=document.createElement("img");l.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),l.style.display="none",s.appendChild(l),document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s),i&&URL.revokeObjectURL(r.split("#")[0])},3e3)}function $r(e,t=!1){if(typeof e!="string")return"";let r=e.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!r)return"";if(/^[\\/]{2}/.test(r))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${r.slice(0,32)}`);let i=r.toLowerCase();if(i.startsWith("https://")||i.startsWith("http://")||t&&i.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(r))return r;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${r.slice(0,32)}`)}function Ul(e){try{return $r(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function Ol(e,t={}){let r=$r(e,!0),i=t.mode||"ar_preferred",n=new URLSearchParams({file:r,mode:i,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&n.set("title",t.title),t.link&&n.set("link",$r(t.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${n.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function Bl(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let r=Ol(e,t);window.location.href=r}var Nt=null;function zl(e,t){let r=new Float32Array(144),i=new Float32Array(144),n=new Float32Array(96),s=new Uint16Array(144);for(let h=0;h<24;h++){let m=h/24*Math.PI*2,c=Math.cos(m),d=Math.sin(m),f=h*2,g=f+1,x=(h+1)%24*2;r[f*3]=c*.11,r[f*3+1]=.002,r[f*3+2]=d*.11,r[g*3]=c*.145,r[g*3+1]=.002,r[g*3+2]=d*.145,i[f*3+1]=i[g*3+1]=1,s.set([f,x,g,g,x,x+1],h*6)}let l=e.createVertexArray();e.bindVertexArray(l);let o=(h,m,c)=>{let d=e.createBuffer();return e.bindBuffer(34962,d),e.bufferData(34962,h,35044),e.enableVertexAttribArray(m),e.vertexAttribPointer(m,c,5126,!1,0,0),d},a=[o(r,0,3),o(i,1,3),o(n,2,2)],u=e.createBuffer();return a.push(u),e.bindBuffer(34963,u),e.bufferData(34963,s,35044),e.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:s.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[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:a}]}}function ua(e,t,r,i,n){let s=Math.cos(i),l=Math.sin(i),o=Math.max(.01,n);e.fill(0),e[0]=o*s,e[2]=-o*l,e[5]=o,e[8]=o*l,e[10]=o*s,e[12]=t[0]-o*(s*r[0]+l*r[2]),e[13]=t[1]-o*r[1],e[14]=t[2]-o*(-l*r[0]+s*r[2]),e[15]=1}var $l=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,t){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");Nt&&Nt!==this&&Nt.isSessionActive()&&await Nt.stop().catch(()=>{});let r=navigator.xr,i=this.opts,n=t||e?.container,s=String(n?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,o=Number(l?.radius)||1,a=Array.isArray(l?.center)?l.center:[0,0,0],u=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],h=typeof navigator<"u"&&navigator.userAgent||"",m=/Android|iPhone|iPad|iPod/i.test(h)&&!/Quest|Oculus|Pico|Vision/i.test(h),c=s?i.arScale==="fixed"?1:m?.55:1:i.arScale==="fixed"?1:o>.45?.3/o:o<.05?.12/Math.max(o,.001):1,d=s?[0,-.25,0]:[a[0]||0,i.arPlacement==="wall"?a[1]:u[1]??0,a[2]||0],f="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(f="immersive-vr")}catch{f="immersive-vr"}let g=n?.querySelector?.('[slot="ar-overlay"]')||null,x=!1,b=null,v=()=>{x&&g?.parentNode&&g.parentNode.removeChild(g),g=null,b=null,x=!1};if(f==="immersive-ar"){if(g)g.addEventListener?.("beforexrselect",_=>_.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let _=document.createElement("div");_.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 G=document.createElement("button");G.type="button",G.textContent="\u2715 Exit AR",G.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",G.addEventListener("beforexrselect",j=>j.preventDefault()),G.addEventListener("click",j=>{j.stopPropagation(),this.stop().catch(()=>{})}),b=document.createElement("div"),b.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",b.textContent="Move phone to detect a surface \u2022 Tap to place",_.appendChild(G),_.appendChild(b),document.body.appendChild(_),g=_,x=!0}}let p=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),y={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(p)};g&&(p.add("dom-overlay"),y.optionalFeatures=Array.from(p),y.domOverlay={root:g});for(let _ of Fe)_.onConfigureXRSessionInit?.(n,y);Array.isArray(y.optionalFeatures)&&y.optionalFeatures.includes("dom-overlay")&&!y.domOverlay?.root&&(y.optionalFeatures=y.optionalFeatures.filter(_=>_!=="dom-overlay"));let M=_=>{let G=String(_?.name||"");return G==="NotAllowedError"||G==="SecurityError"};try{this.s=await r.requestSession(f,y)}catch(_){if(v(),M(_))throw i.onError?.(_),_;try{this.s=await r.requestSession(f,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(G){if(M(G))throw i.onError?.(G),G;try{this.s=await r.requestSession(f)}catch(j){throw i.onError?.(j),j}}}let P=this.s;Nt=this,this.placed=!1;let F=null,W=null,T=null,E=null,S=null,O=[0,-.25,-1.2],k=[0,-.25,-1.2],w=new Float32Array(16),ie=new Float32Array(16),oe=!1,I=1,H=0,N=!1,z=null,ue=null,he=0,B=null,$=()=>{Nt===this&&(Nt=null),B?.(),B=null;try{W?.cancel?.()}catch{}if(W=null,T){let _=e?.meshes;if(Array.isArray(_)){let j=_.indexOf(T);j!==-1&&_.splice(j,1)}let G=e.getGLContext?.()||e?.gl;if(G)for(let j of T.primitives||[]){G.deleteVertexArray?.(j.vao);for(let q of j.buffers||[])G.deleteBuffer?.(q)}T=null}e?.setXRSessionActive?.(!1),v(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=$,P.addEventListener("end",()=>{$(),i.onExit?.()}),P.addEventListener("select",()=>{if(!this.placed){let _=S||O;k=[_[0],_[1],_[2]],ua(this.placedMat,k,d,H,c*I),this.placed=!0,T&&(T.visible=!1),b&&(b.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let _=e.getGLContext?.()||e?.gl;_&&typeof _.makeXRCompatible=="function"&&await _.makeXRCompatible();let G=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;_&&typeof G=="function"&&typeof P.updateRenderState=="function"&&P.updateRenderState({baseLayer:new G(P,_,{alpha:!0})});try{F=await P.requestReferenceSpace("local")}catch{try{F=await P.requestReferenceSpace("local-floor")}catch{F=await P.requestReferenceSpace("viewer")}}let j=await P.requestReferenceSpace("viewer").catch(()=>F);if(typeof P.requestHitTestSource=="function"&&j&&(W=await P.requestHitTestSource({space:j}).catch(()=>null)),f==="immersive-ar"&&_&&typeof _.createVertexArray=="function"&&Array.isArray(e.meshes)&&(T=zl(_,i.reticleColor),e.meshes.push(T)),typeof window<"u"&&typeof window.addEventListener=="function"){let D=V=>Math.hypot(V.touches[1].clientX-V.touches[0].clientX,V.touches[1].clientY-V.touches[0].clientY),Y=V=>Math.atan2(V.touches[1].clientY-V.touches[0].clientY,V.touches[1].clientX-V.touches[0].clientX),te=V=>{this.s&&(V.touches.length===1&&this.placed?N=!0:V.touches.length>=2&&(N=!1,z=D(V),ue=Y(V)))},se=V=>{if(!this.s||V.touches.length<2)return;let ee=D(V),R=Y(V);if(z&&z>4&&i.arScale!=="fixed"&&(I=Math.max(.15,Math.min(6,I*(ee/z)))),ue!==null){let A=R-ue;A>Math.PI&&(A-=Math.PI*2),A<-Math.PI&&(A+=Math.PI*2),H-=A}z=ee,ue=R},le=V=>{(!V.touches||V.touches.length===0)&&(N=!1),(!V.touches||V.touches.length<2)&&(z=null,ue=null)};window.addEventListener("touchstart",te,{passive:!0}),window.addEventListener("touchmove",se,{passive:!0}),window.addEventListener("touchend",le,{passive:!0}),window.addEventListener("touchcancel",le,{passive:!0}),B=()=>{window.removeEventListener("touchstart",te),window.removeEventListener("touchmove",se),window.removeEventListener("touchend",le),window.removeEventListener("touchcancel",le)}}e.setXRSessionActive?.(!0);let q=(D,Y)=>{if(this.s!==P)return;P.requestAnimationFrame(q);let te=he>0?Math.min(Math.max((D-he)/1e3,0),.1):1/60;he=D,e?.stepXRUpdate?.(te);let se=Y.getViewerPose(F);if(!se)return;let le=se.views?.[0];if(!oe&&le?.transform){let C=le.transform.position,U=le.transform.matrix,Q=C?.x??(U?U[12]:0),X=C?.y??(U?U[13]:0),Z=C?.z??(U?U[14]:0),J=U?-U[8]:0,K=U?-U[10]:-1,ae=Math.hypot(J,K);ae>1e-4?(J/=ae,K/=ae):(J=0,K=-1),O=[Q+J*1.2,X-.25,Z+K*1.2],H=Math.atan2(-J,-K),oe=!0}if(W&&typeof Y.getHitTestResults=="function"&&(!this.placed||N)){let C=Y.getHitTestResults(W)||[],U=!1;for(let Q of C){let X=Q.getPose(F);if(X?.transform?.matrix){let Z=X.transform.matrix,J=Z[5];if(i.arPlacement==="wall"&&Math.abs(J)>.35||i.arPlacement==="floor"&&Math.abs(J)<.65)continue;E||(E=new Float32Array(16)),E.set(Z),S=[Z[12],Z[13],Z[14]],this.placed&&N&&(k=[Z[12],Z[13],Z[14]]),T&&(T.visible=!this.placed||N,T.transform.set(Z)),!this.placed&&b&&(b.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(E),U=!0;break}}!U&&T&&(T.visible=!1)}ua(w,this.placed?k:S||O,d,H,c*I),this.placed&&this.placedMat.set(w);let V=e.xrRigMatrix;V instanceof Float32Array&&V.length===16?ke(ie,V,w):ie.set(w),e.modelRootMatrix&&e.modelRootMatrix.set(ie);for(let C of Fe)C.onXRFrame?.(e,P,Y,F);let ee=e.getGLContext?.()||e?.gl,R=P.renderState?.baseLayer;ee&&R&&R.framebuffer!==void 0&&ee.bindFramebuffer(36160,R.framebuffer);let A=f==="immersive-ar",L=se.views||[];for(let C=0;C<L.length;C++){let U=L[C];if(typeof e.renderXRView=="function"){let Q;if(R&&typeof R.getViewport=="function"){let X=R.getViewport(U);X&&X.width>0&&X.height>0&&(Q=[X.x,X.y,X.width,X.height])}else R?.framebufferWidth>0&&R?.framebufferHeight>0&&(Q=[0,0,R.framebufferWidth,R.framebufferHeight]);e.renderXRView(U,ie,this.placed,Q,A,C)}}ee&&R&&R.framebuffer&&ee.bindFramebuffer(36160,null)};P.requestAnimationFrame(q)}catch(_){throw typeof P.end=="function"&&await P.end().catch(()=>{}),$(),i.onError?.(_),_}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function ha(e){let t=await Ki(),r=e.preferredModes||["quick-look","webxr","scene-viewer"],i=null;for(let o of r)if(t.availableModes.includes(o)){i=o;break}if(i||(i=t.bestMode),!i)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let n={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},s={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},l={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(i==="quick-look"){let o;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")o=e.model;else{if(typeof e.model=="string")return la(e.model,n),{mode:"quick-look",success:!0};o=xi(e.model)}return la(o,n),{mode:"quick-look",success:!0}}if(i==="scene-viewer"){let o=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!o)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Bl(o,s),{mode:"scene-viewer",success:!0}}if(i==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let o=new $l(l);return await o.start(e.view,e.element),{mode:"webxr",success:!0,session:o}}}catch(o){return{mode:i,success:!1,error:o}}return{mode:i,success:!1,error:new Error(`Unhandled AR mode: ${i}`)}}Ht.registerAR({activateAR:ha,createUSDZBlob:xi}),Ht.registerScriptRunner(kr),Ge(Xi);var Yi=new WeakMap;function ca(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);Yi.set(e,r)}function Hl(e){return Yi.get(e)}async function Wl(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let n=await(await fetch(t)).blob();r=await createImageBitmap(n)}else if(typeof Image<"u")r=await new Promise((n,s)=>{let l=new Image;l.crossOrigin="anonymous",l.onload=()=>n(l),l.onerror=s,l.src=t});else return null;else r=t;let i=e.createTexture();return e.bindTexture(3553,i),e.texImage2D(3553,0,6408,6408,5121,r),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),i}var Zi=new WeakMap,ma=new Float32Array(16);async function fa(e,t,r){let i=r?await Wl(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var pa={name:"environment-map",onContextRestored(e){Zi.delete(e)},setEnvironmentImage(e,t){return fa(e,"environmentTexture",t)},setSkyboxImage(e,t){return fa(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,n){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=Zi.get(t);if(!s){let m=(f,g)=>{let x=t.createShader(f);return t.shaderSource(x,g),t.compileShader(x),x},c=t.createProgram();t.attachShader(c,m(35633,`#version 300 es
401
+ 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.);}`)),t.attachShader(c,m(35632,`#version 300 es
402
+ 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.);}`)),t.linkProgram(c);let d=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:c,vao:d},Zi.set(t,s)}let l=ri(ma,r)||ma;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let o=t.getUniformLocation(s.program,"uSkyboxMap");o&&t.uniform1i(o,0);let a=t.getUniformLocation(s.program,"uInvVP");a&&t.uniformMatrix4fv(a,!1,l);let u=t.getUniformLocation(s.program,"uCameraPos");u&&t.uniform3f(u,i[0],i[1],i[2]);let h=t.getUniformLocation(s.program,"uExposure");h&&t.uniform1f(h,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let n=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
352
403
  uniform int uHasSH;
353
404
  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);}
354
405
  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));}
355
- void main(){`);return i=i.replace(`if(uHasEnvironmentMap==1){
406
+ void main(){`);return n=n.replace(`if(uHasEnvironmentMap==1){
356
407
  specularIBL=texture(uEnvironmentMap,equirectangularUV(R)).rgb*(F*brdf.x+brdf.y);
357
408
  envDiffuse=texture(uEnvironmentMap,equirectangularUV(N)).rgb;
358
409
  }`,`if(uHasEnvironmentMap==1){
@@ -361,15 +412,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
361
412
  }else if(uHasSH==1){
362
413
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
363
414
  envDiffuse=evalSHIrradiance(N);
364
- }`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=Li.get(t),u=t.getUniformLocation(e,"uHasSH");if(a&&a.length>=27){u&&t.uniform1i(u,1);let s=t.getUniformLocation(e,"uSH");s&&t.uniform3fv(s,a)}else u&&t.uniform1i(u,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 Pi(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 u=a.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(u.length<3||u.some(isNaN))continue;let s=o.getAttribute("data-normal"),c;if(s){let m=s.trim().split(/\s+/).map(f=>parseFloat(f));m.length>=3&&!m.some(isNaN)&&(c=[m[0],m[1],m[2]])}let l=n.projectPointToScreen([u[0],u[1],u[2]],c);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 ki={name:"hotspots",updateHotspotsForElement:Pi,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{Pi(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ci.set(t,e)},onCameraChange(t,e){e&&Pi(e,t)},onElementDisconnected(t){let e=Ci.get(t);e&&(e.disconnect(),Ci.delete(t))}};var hs=1024,Ni=256,_r=2048,Ja=128,ec=64,tc=16,nc=1e4,rc=8,bt=new Set(["__proto__","constructor","prototype"]),ps={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))},bs={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},Lr={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Ir=(t,e)=>t!==null&&typeof t=="object"&&!bt.has(e)&&Object.prototype.hasOwnProperty.call(t,e),Qe=t=>Array.isArray(t)?[...t]:t,vs=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&Ir(t,"value")?t.value:t,ke=(t,e)=>Ir(t.configuration,e)?vs(t.configuration[e]):void 0,de=(t,e=0)=>{let n=Number(t);return Number.isFinite(n)?n:e},Vt=t=>Math.max(0,Math.min(1,t)),nt=t=>typeof t=="boolean"?t:typeof t=="number"?t!==0&&!Number.isNaN(t):typeof t=="string"?t.length>0&&t!=="false":!!t;function Ln(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||bt.has(r)||bt.has(n))return null;e.push(r)}return{segments:e}}var rn=(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},ys=t=>{let e=de(t[0]),n=de(t[1]),r=de(t[2]),i=de(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]},gs=(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 Mr(i,ys(t),ys(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},Di=(t,e,n)=>Array.isArray(t)&&Array.isArray(e)?t.slice(0,e.length).map((r,i)=>n(de(r),de(e[i]))):Array.isArray(t)?t.map(r=>n(de(r),de(e))):Array.isArray(e)?e.map(r=>n(de(t),de(r))):n(de(t),de(e)),ic=(t,e)=>Array.isArray(t)?t.map(n=>e(de(n))):e(de(t)),xs=(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,In=class{constructor(e,n,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>hs)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${hs})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>Ni)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Ni})`);let a=Array.isArray(r.declarations)?r.declarations:[],u=Array.isArray(r.events)?r.events:[],s=new Map,c=new Map,l=new Map,m=new Map,f=new Map,h=new Map,p=[],d=[],y=new Map,v=1,R=0,b=0,w=0,M=0,P=!1,k=!1,I=!1;o.forEach((D,G)=>{if(!D||typeof D!="object")return;let E=Qe(vs(D.value));s.set(G,E);let V=D.id??D.name;typeof V=="string"&&V&&!bt.has(V)&&s.set(V,E)}),(n?.nodes||[]).forEach((D,G)=>{for(let E of D?.children||[])typeof E=="number"&&y.set(E,G)});let L=D=>D.op||typeof D.declaration=="number"&&a[D.declaration]?.op||"",x=(D,G,E)=>{if(bt.has(G))return;let V=c.get(D);V||c.set(D,V=Object.create(null)),V[G]=E},g=(D,G)=>{if(typeof D!="number"&&typeof D!="string"||typeof D=="string"&&bt.has(D)||!s.has(D)&&s.size>=Ni*2)return;let E=Qe(G);if(s.set(D,E),typeof D=="number"){let V=o[D]?.id??o[D]?.name;typeof V=="string"&&!bt.has(V)&&s.set(V,E)}},A=D=>typeof D=="number"?u[D]?.id??String(D):typeof D=="string"?/^\d+$/.test(D)&&u[Number(D)]?.id?u[Number(D)].id:D:"",N=(D,G)=>{for(let E=D,V=0;E!==void 0&&E>=0&&V<128;E=y.get(E),V++)if(E===G)return!0;return!1},_=D=>{for(let G=p.length-1;G>=0;G--)p[G].key===D&&p.splice(G,1)},O=D=>{_(D.key),p.length>=Ja&&p.shift(),p.push(D)},Q=D=>{let G=Ln(D)?.segments;if(G){if(G[0]==="nodes"&&Array.isArray(n?.nodes)){let E=n.nodes[rn(G[1],n.nodes.length)];if(!E)return;let V=G[2];if(V in Lr){let F=Lr[V],U=E[V]||F;return F.map((z,Y)=>de(U[Y],z))}if(V==="weights"){let F=Array.isArray(E.weights)?E.weights:[0],U=G.length===4?rn(G[3],64):-2;return U===-2?F.map(z=>de(z)):U>=0?de(F[U]):void 0}if(V==="visible"||V==="extensions"&&G[3]==="KHR_node_visibility"&&G[4]==="visible")return E.extensions?.KHR_node_visibility?.visible??E.visible??!0}else if(G[0]==="materials"&&Array.isArray(n?.materials)){let E=n.materials[rn(G[1],n.materials.length)];if(!E)return;let V=E.pbrMetallicRoughness||{};if(G[2]==="pbrMetallicRoughness"){if(G[3]==="baseColorFactor"){let F=V.baseColorFactor||[1,1,1,1];return[de(F[0],1),de(F[1],1),de(F[2],1),de(F[3],1)]}if(G[3]==="metallicFactor"||G[3]==="roughnessFactor")return de(V[G[3]],1)}if(G[2]==="emissiveFactor"){let F=E.emissiveFactor||[0,0,0];return[de(F[0]),de(F[1]),de(F[2])]}if(G[2]==="alphaCutoff")return de(E.alphaCutoff,.5)}}},q=(D,G)=>{let E=Ln(D)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(n?.nodes)){let V=rn(E[1],n.nodes.length),F=n.nodes[V];if(!F)return!1;let U=E[2];if(U in Lr&&Array.isArray(G)){let z=Lr[U];if(G.length<z.length)return!1;let Y=z.map((ie,he)=>de(G[he],ie));if(U==="rotation"){let ie=Math.hypot(...Y);Y=ie>1e-8?Y.map(he=>he/ie):[0,0,0,1]}F[U]=Y,delete F.matrix;let le=e?.initialNodeTransforms?.[V];return le&&(le[U[0]]=[...Y]),P=!0,!0}if(U==="weights"){Array.isArray(F.weights)||(F.weights=[]);let z=(Y,le)=>{for(let ie of e?.meshes||[])if(ie.nodeIndex===V)for(let he of ie.primitives||[])he.pluginData?.morph?.weights&&(he.pluginData.morph.weights[Y]=le)};if(E.length===4){let Y=rn(E[3],64);if(Y<0)return!1;z(Y,F.weights[Y]=de(G))}else if(Array.isArray(G))F.weights=G.slice(0,64).map(Y=>de(Y)),F.weights.forEach((Y,le)=>z(le,Y));else return!1;return I=!0,!0}if(U==="visible"||U==="extensions"&&E[3]==="KHR_node_visibility"&&E[4]==="visible"){let z=nt(G);return F.visible=z,(!F.extensions||typeof F.extensions!="object")&&(F.extensions={}),F.extensions.KHR_node_visibility={visible:z},k=!0,!0}}else if(E[0]==="materials"&&Array.isArray(n?.materials)){let V=rn(E[1],n.materials.length),F=n.materials[V];if(!F)return!1;let U=F.pbrMetallicRoughness||(F.pbrMetallicRoughness={}),z=Y=>{for(let le of e?.meshes||[])for(let ie of le.primitives||[])(ie.materialIndex??0)===V&&Y(ie)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(G)&&G.length>=3){let Y=[Vt(de(G[0],1)),Vt(de(G[1],1)),Vt(de(G[2],1)),G[3]!==void 0?Vt(de(G[3],1)):U.baseColorFactor?.[3]??1];return U.baseColorFactor=Y,z(le=>le.baseColor=[...Y]),I=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let Y=E[3]==="metallicFactor",le=Vt(de(G,Y?0:.5));return U[E[3]]=le,z(ie=>ie[Y?"metallic":"roughness"]=le),I=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(G)&&G.length>=3)return F.emissiveFactor=[0,1,2].map(Y=>Math.max(0,de(G[Y]))),I=!0;if(E[2]==="alphaCutoff")return F.alphaCutoff=Vt(de(G,.5)),I=!0}return!1},oe=(D,G,E=new Set)=>{let V=ke(G,"pointer");if(typeof V!="string"||!V.startsWith("/"))return null;let F=V.replace(/\{([a-zA-Z0-9_]+)\}/g,(U,z)=>{let Y=Math.trunc(Number(ne(D,z,void 0,E)??ke(G,z)));return Number.isSafeInteger(Y)&&Y>=0?String(Y):"-1"});return Ln(F)?F:null},ne=(D,G,E,V)=>{let F=i[D]?.values;if(!Ir(F,G))return E;let U=F[G];if(U==null)return E;if(typeof U!="object"||Array.isArray(U))return Qe(U);let z=U;return typeof z.node=="number"?re(z.node,z.socket||"value",V):Ir(z,"value")?Qe(z.value):E},re=(D,G,E)=>{if(D<0||D>=i.length||E.has(D)||E.size>128||++w>nc)return;let V=i[D],F=L(V);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(F))return Qe(c.get(D)?.[G]);E.add(D);try{let U=(z,Y=0)=>ne(D,z,Y,E);if(F==="variable/get"){let z=ke(V,"variable")??ke(V,"id");return typeof z=="number"||typeof z=="string"?Qe(s.get(z)):void 0}if(F==="pointer/get"){let z=oe(D,V,E);return z?Q(z):void 0}if(F.startsWith("math/")){let z=F.slice(5);if(z in ps)return ic(U("a"),ps[z]);if(z in bs){let Y=/^(mul|div|rem|mod|pow)$/.test(z)?1:0;return Di(U("a",z==="mul"?1:0),U("b",Y),bs[z])}if(z==="pi")return Math.PI;if(z==="e")return Math.E;if(z==="random")return Math.random();if(z==="clamp")return Di(Di(U("a"),U("b",U("min",0)),Math.max),U("c",U("max",1)),Math.min);if(z==="mix"||z==="quatSlerp")return gs(U("a",0),U("b",1),de(U("c",U("t",.5)),.5),z==="quatSlerp");if(z==="dot"){let Y=U("a"),le=U("b");return Array.isArray(Y)&&Array.isArray(le)?Y.reduce((ie,he,T)=>ie+(he||0)*(le[T]||0),0):de(Y)*de(le)}if(z==="cross"){let Y=U("a",[0,0,0]),le=U("b",[0,0,0]);return Array.isArray(Y)&&Array.isArray(le)?[(Y[1]||0)*(le[2]||0)-(Y[2]||0)*(le[1]||0),(Y[2]||0)*(le[0]||0)-(Y[0]||0)*(le[2]||0),(Y[0]||0)*(le[1]||0)-(Y[1]||0)*(le[0]||0)]:[0,0,0]}if(z==="length"){let Y=U("a");return Array.isArray(Y)?Math.hypot(...Y):Math.abs(de(Y))}if(z==="distance"){let Y=U("a"),le=U("b");return Array.isArray(Y)&&Array.isArray(le)?Math.hypot(...Y.map((ie,he)=>(ie||0)-(le[he]||0))):Math.abs(de(Y)-de(le))}if(z==="normalize"){let Y=U("a");if(!Array.isArray(Y))return de(Y)>=0?1:-1;let le=Math.hypot(...Y);return le>1e-8?Y.map(ie=>ie/le):Y.map(()=>0)}if(z.startsWith("combine"))return["a","b","c","d"].slice(0,Number(z[7])||2).map(Y=>de(U(Y)));if(z.startsWith("extract")){let Y=U("a");return Array.isArray(Y)?Y[G==="0"||G==="x"?0:G==="1"||G==="y"?1:G==="2"||G==="z"?2:3]??0:0}if(z==="eq")return xs(U("a"),U("b"));if(z==="ne")return!xs(U("a"),U("b"));if(z==="lt")return de(U("a"))<de(U("b"));if(z==="le")return de(U("a"))<=de(U("b"));if(z==="gt")return de(U("a"))>de(U("b"));if(z==="ge")return de(U("a"))>=de(U("b"));if(z==="isNaN")return Number.isNaN(Number(U("a")));if(z==="isInf"){let Y=Number(U("a"));return!Number.isFinite(Y)&&!Number.isNaN(Y)}return z==="and"?nt(U("a",!1))&&nt(U("b",!1)):z==="or"?nt(U("a",!1))||nt(U("b",!1)):z==="xor"?nt(U("a",!1))!==nt(U("b",!1)):z==="not"?!nt(U("a",!1)):z==="select"?Qe(nt(U("condition",!1))?U("a"):U("b")):void 0}return F==="type/boolToInt"||F==="type/boolToFloat"?nt(U("a",!1))?1:0:F==="type/intToBool"||F==="type/floatToBool"?de(U("a",0))!==0:F==="type/intToFloat"?de(U("a",0)):F==="type/floatToInt"?Math.trunc(de(U("a",0))):void 0}finally{E.delete(D)}},H=()=>{if(P){P=!1,I=!0;let D=dt(n);if(e){e.worldMatrices=D;for(let G of e.meshes||[])G.nodeIndex>=0&&G.nodeIndex<D.length&&(G.transform.set(D[G.nodeIndex]),Ne(G.normalMatrix,G.transform))}}if(k){k=!1,I=!0;let D=n?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(D))for(let G of e.meshes){let E=!0;for(let V=G.nodeIndex,F=0;V!==void 0&&V>=0&&F<128;V=y.get(V),F++){let U=D[V];if(U?.visible===!1||U?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}G.visible=E}}I&&(I=!1,e?.render?.())},se=(D,G={steps:0})=>{if(!D||typeof D.node!="number")return;G.steps===0&&(w=0);let E=[D],V=F=>{E.length+G.steps<_r&&E.push(F)};for(;E.length>0&&G.steps<_r;){G.steps++;let F=E.shift();if(!F||F.node<0||F.node>=i.length)continue;let U=F.node,z=i[U];if(!z)continue;let Y=F.socket||"in",le=L(z),ie=(T,S=void 0)=>ne(U,T,S,new Set),he=(T="out")=>{let S=z.flows?.[T];S&&V(S)};switch(le){case"flow/branch":he(nt(ie("condition",!1))?"true":"false");break;case"flow/sequence":for(let T of Object.keys(z.flows||{}).sort((S,C)=>Number(S)-Number(C)||S.localeCompare(C)))he(T);break;case"flow/switch":{let T=z.flows?.[String(ie("selection",ie("value",0)))]??z.flows?.default;T&&V(T);break}case"flow/for":{let T=Math.trunc(de(ie("startIndex",0))),S=Math.trunc(de(ie("endIndex",0))),C=Math.max(1,Math.trunc(de(ie("step",1),1))),B=z.flows?.body;if(B&&S>T&&M<rc){let W=Math.min(Math.ceil((S-T)/C),_r);M++;try{for(let $=0;$<W&&G.steps<_r;$++)x(U,"index",T+$*C),se(B,G)}finally{M--}}let X=z.flows?.completed??z.flows?.out;X&&V(X);break}case"flow/doN":{let T=Y==="reset"?0:(l.get(U)||0)+1;if(l.set(U,T),x(U,"currentCount",T),x(U,"count",T),Y!=="reset"){let S=Math.trunc(de(ie("n",ke(z,"stopIterations")??ke(z,"n")??1),1));T<=S&&he()}break}case"flow/multiGate":{if(Y==="reset"){h.set(U,0);break}let T=Object.keys(z.flows||{}).sort();if(!T.length)break;let S=ke(z,"isRandom")?Math.floor(Math.random()*T.length):h.get(U)||0;S<T.length&&(he(T[S]),h.set(U,ke(z,"isLoop")!==!1?(S+1)%T.length:S+1));break}case"flow/waitAll":{if(Y==="reset"){m.delete(U);break}let T=m.get(U);T||m.set(U,T=new Set),T.add(Y),T.size>=Math.max(1,Math.trunc(Number(ke(z,"inputFlows")??2)||2))&&(T.clear(),he("out"),he("completed"));break}case"flow/throttle":{if(Y==="reset"){f.delete(U);break}let T=Math.max(0,de(ie("duration",0))),S=f.get(U);S===void 0||R-S>=T?(f.set(U,R),x(U,"lastRemainingTime",0),he()):x(U,"lastRemainingTime",Math.max(0,T-(R-S)));break}case"flow/delay":case"flow/setDelay":{if(Y==="cancel"){for(let B=d.length-1;B>=0;B--)d[B].nodeIdx===U&&d.splice(B,1);x(U,"lastDelayIndex",-1);break}let T=Math.max(0,de(ie("duration",ke(z,"duration")??0))),S=z.flows?.done??z.flows?.out;if(T<=0){x(U,"lastDelayIndex",-1),S&&V(S);break}d.length>=ec&&d.shift();let C=v++;x(U,"lastDelayIndex",C),d.push({id:C,nodeIdx:U,rem:T,done:S}),le==="flow/setDelay"&&z.flows?.out&&z.flows?.done&&he("out");break}case"flow/cancelDelay":{let T=Math.trunc(de(ie("delayIndex",-1),-1));if(T<0)d.length=0;else for(let S=d.length-1;S>=0;S--)d[S].id===T&&d.splice(S,1);he();break}case"variable/set":g(ke(z,"variable")??ke(z,"id"),ie("value")),he();break;case"variable/interpolate":{let T=ke(z,"variable")??ke(z,"id"),S=ie("value",ie("target")),C=Math.max(0,de(ie("duration",ke(z,"duration")??.3),.3));T!==void 0&&S!==void 0&&O({key:`var:${String(T)}`,varKey:T,from:Qe(ie("from")??s.get(T)??0),to:Qe(S),dur:C,elapsed:0,quat:!1,linear:ke(z,"easing")==="linear",done:z.flows?.done}),he();break}case"pointer/set":{let T=oe(U,z),S=ie("value");T&&S!==void 0&&(_(`ptr:${T}`),q(T,S)),he();break}case"pointer/interpolate":{let T=oe(U,z),S=ie("value",ie("target")),C=Math.max(0,de(ie("duration",ke(z,"duration")??.3),.3));if(T&&S!==void 0){let B=ie("from")??Q(T);B!==void 0&&(C<=0?(q(T,S),he("done")):O({key:`ptr:${T}`,ptr:T,from:Qe(B),to:Qe(S),dur:C,elapsed:0,quat:T.endsWith("/rotation"),linear:ke(z,"easing")==="linear",done:z.flows?.done}))}he();break}case"animation/start":{let T=ie("animation")??ke(z,"animation")??ke(z,"clipName"),S=typeof T=="number"?e?.animations?.[T]?.name??n?.animations?.[T]?.name:typeof T=="string"?T:void 0;e?.playAnimation?.(S),I=!0,he();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),le==="animation/resetAt"&&e?.evaluateAnimation?.(de(ie("time",0))),I=!0,he();break;case"event/send":case"customEvent/send":{let T=A(ke(z,"event")??ke(z,"id")),S={};for(let C of Object.keys(z.values||{}))bt.has(C)||(S[C]=ie(C));T&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:T,values:S}})),ae(T,S,G)),he();break}default:he();break}}};this.readScenePointer=Q,this.writeScenePointer=q,this.fireOnStart=()=>{i.forEach(D=>{L(D)==="event/onStart"&&se(D.flows?.out)}),H()},this.fireOnSelect=D=>{if(!D)return;let G=typeof D.meshIndex=="number"?D.meshIndex:-1,E=typeof D.nodeIndex=="number"?D.nodeIndex:e?.meshes?.[G]?.nodeIndex??-1;i.forEach((V,F)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(L(V)))return;let U=ke(V,"nodeIndex")??ke(V,"node")??ne(F,"nodeIndex",void 0,new Set),z=ke(V,"meshName");if(typeof z=="string"&&z?D.meshName===z:U==null||Number(U)<0||Number.isNaN(Number(U))||N(E,Math.trunc(Number(U)))){if(x(F,"nodeIndex",E),x(F,"meshIndex",G),Array.isArray(D.hitPoint)){let le=[de(D.hitPoint[0]),de(D.hitPoint[1]),de(D.hitPoint[2])];x(F,"hitPoint",le),x(F,"point",le),x(F,"intersectionPoint",le)}if(Array.isArray(D.normal)){let le=[de(D.normal[0]),de(D.normal[1],1),de(D.normal[2])];x(F,"normal",le),x(F,"hitNormal",le)}typeof D.distance=="number"&&x(F,"distance",D.distance),se(V.flows?.out)}}),H()},this.receiveCustomEvent=(D,G={})=>ae(D,G,{steps:0});function ae(D,G,E){if(!(b>=tc)){b++;try{let V=A(D);i.forEach((F,U)=>{if(!/^(customE|e)vent\/receive$/.test(L(F)))return;let z=ke(F,"event")??ke(F,"id");if(!(A(z)!==V&&String(z)!==String(D))){for(let[Y,le]of Object.entries(G))bt.has(Y)||x(U,Y,Qe(le));se(F.flows?.out,E)}}),H()}finally{b--}}}this.tick=D=>{if(!Number.isFinite(D)||D<0)return;let G=Math.min(D,.25);R+=G,i.forEach((V,F)=>{L(V)==="event/onTick"&&(x(F,"timeDelta",G),x(F,"dt",G),x(F,"timeElapsed",R),se(V.flows?.out))});let E=[];for(let V=p.length-1;V>=0;V--){let F=p[V];F.elapsed+=G;let U=F.dur>1e-6?Vt(F.elapsed/F.dur):1,z=F.linear?U:U*U*(3-2*U),Y=gs(F.from,F.to,z,F.quat);F.ptr?q(F.ptr,Y):F.varKey!==void 0&&g(F.varKey,Y),U>=1&&(p.splice(V,1),F.done&&E.push(F.done))}for(let V=d.length-1;V>=0;V--){let F=d[V];F.rem-=G,F.rem<=0&&(d.splice(V,1),F.done&&E.push(F.done))}for(let V of E)se(V);H()},this.dispose=()=>{p.length=0,d.length=0,s.clear(),c.clear(),l.clear(),m.clear(),f.clear(),h.clear()}}},ut=new WeakMap,Cr=new WeakMap;function oc(t,e){if(!t||typeof t!="object"||!Number.isFinite(e)||e<=0||On().some(s=>s.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),a=(Cr.get(t)||0)+o,u=!1;for(let s=0;s<i.length;s++){let c=i[s],l=Oo(c?.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 R=i.find(b=>b?.name===l.target);Array.isArray(R?.translation)&&(m=de(R.translation[0]),f=de(R.translation[1]),h=de(R.translation[2]))}let p=l.phase+l.speed*a,d=m+Math.cos(p)*l.radius,y=f+l.height,v=h+Math.sin(p)*l.radius;if(c.translation=[d,y,v],l.faceCenter){let R=Math.atan2(m-d,h-v);c.rotation=[0,Math.sin(R*.5),0,Math.cos(R*.5)]}u=!0}if(u){Cr.set(t,a);let s=dt(r);t.worldMatrices=s;for(let c of t.meshes||[])c.nodeIndex>=0&&c.nodeIndex<s.length&&(c.transform.set(s[c.nodeIndex]),Ne(c.normalMatrix,c.transform))}}function Pr(t){if(!(!t||typeof t!="object"))return ut.get(t)||ut.get(t.viewer)||ut.get(t._view)}function Ui(t,e,n){let r=Pr(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var Oi={name:"khr-interactivity",sendInteractivityEvent:Ui,getInteractivityVM:Pr,onLoadModel(t,e){if(!t||typeof t!="object")return;ut.get(t)?.dispose(),ut.delete(t),Cr.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 In(t,e,r);ut.set(t,i),i.fireOnStart()},onMeshSelect(t,e){ut.get(t)?.fireOnSelect(e)},onUpdate(t,e){ut.get(t)?.tick(e),oc(t,e)},onDestroy(t,e){ut.get(e)?.dispose(),ut.delete(e),Cr.delete(e)}};var Cn=new Map,kr=new WeakMap;function Ts(t,e){Cn.set(t,e)}var Fi={name:"materials",onContextRestored(t){kr.delete(t)},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=kr.get(t);n||(n=t.createTexture(),kr.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&&Cn.has(e.name)){let p=Cn.get(e.name);return{vs:p.vs||n,fs:p.fs||r}}let i=e.extensions||{},o=i.KHR_materials_clearcoat,a=i.KHR_materials_sheen,u=!!i.KHR_materials_transmission,s=!!i.KHR_materials_ior,c=i.KHR_materials_iridescence;if(!o&&!a&&!i.KHR_materials_unlit&&!u&&!i.KHR_materials_volume&&!s&&!i.KHR_materials_dispersion&&!c)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(u){let p=l.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
365
- `;l=l.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
366
- ${p}out vec4 fragColor;`)}let m=(p,d,y=0,v=1e6,R=3)=>{let b=Number(p);return(Number.isFinite(b)?Math.min(v,Math.max(y,b)):d).toFixed(R)},f=Number(i.KHR_materials_ior?.ior??1.5),h=Number.isFinite(f)?Math.min(10,Math.max(1,f)):1.5;if(s){let p=Math.pow((h-1)/(h+1),2);l=l.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(p,.04,0,1,4)}),base.rgb,metallic);`)}if(c){let p=m(c.iridescenceFactor,1,0,1),d=m(c.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,${p}*pow(1.-NoV,2.));`)}if(u){let p=m(i.KHR_materials_transmission?.transmissionFactor,1,0,1),d=i.KHR_materials_volume||{},y=m(d.thicknessFactor,.5,0,1e4),v=m(d.attenuationDistance,1,.001,1e6),R=Array.isArray(d.attenuationColor)?d.attenuationColor:[1,1,1],b=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;
367
- vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(h,1.5,1,10)},dV=${b},tV=${y},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
415
+ }`),{vs:r,fs:n}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=Yi.get(e),o=e.getUniformLocation(t,"uHasSH");if(l&&l.length>=27){o&&e.uniform1i(o,1);let a=e.getUniformLocation(t,"uSH");a&&e.uniform3fv(a,l)}else o&&e.uniform1i(o,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},Qi=new WeakMap;function Ji(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let n=0;n<i.length;n++){let s=i[n],l=s.getAttribute("data-position");if(!l)continue;let o=l.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(o.length<3||o.some(isNaN))continue;let a=s.getAttribute("data-normal"),u;if(a){let m=a.trim().split(/\s+/).map(c=>parseFloat(c));m.length>=3&&!m.some(isNaN)&&(u=[m[0],m[1],m[2]])}let h=r.projectPointToScreen([o[0],o[1],o[2]],u);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${h.x}px, ${h.y}px, 0)`,s.style.zIndex="3",h.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var da={name:"hotspots",updateHotspotsForElement:Ji,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Ji(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Qi.set(e,t)},onCameraChange(e,t){t&&Ji(t,e)},onElementDisconnected(e){let t=Qi.get(e);t&&(t.disconnect(),Qi.delete(e))}},ga=1024,en=256,Hr=2048,Gl=128,jl=64,ql=16,Xl=1e4,Kl=8,xt=new Set(["__proto__","constructor","prototype"]),ya={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},ba={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},Wr={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Gr=(e,t)=>e!==null&&typeof e=="object"&&!xt.has(t)&&Object.prototype.hasOwnProperty.call(e,t),tt=e=>Array.isArray(e)?[...e]:e,xa=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Gr(e,"value")?e.value:e,Le=(e,t)=>Gr(e.configuration,t)?xa(e.configuration[t]):void 0,fe=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},Ct=e=>Math.max(0,Math.min(1,e)),nt=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function jr(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||xt.has(i)||xt.has(r))return null;t.push(i)}return{segments:t}}var Wt=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},va=e=>{let t=fe(e[0]),r=fe(e[1]),i=fe(e[2]),n=fe(e[3],1),s=Math.hypot(t,r,i,n);return s>1e-8?[t/s,r/s,i/s,n/s]:[0,0,0,1]},Ma=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let n=[0,0,0,1];return Hi(n,va(e),va(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},tn=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(fe(i),fe(t[n]))):Array.isArray(e)?e.map(i=>r(fe(i),fe(t))):Array.isArray(t)?t.map(i=>r(fe(e),fe(i))):r(fe(e),fe(t)),Yl=(e,t)=>Array.isArray(e)?e.map(r=>t(fe(r))):t(fe(e)),wa=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,Aa=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>ga)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ga})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>en)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${en})`);let s=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],o=new Map,a=new Map,u=new Map,h=new Map,m=new Map,c=new Map,d=[],f=[],g=new Map,x=1,b=0,v=0,p=0,y=0,M=!1,P=!1,F=!1;n.forEach((B,$)=>{if(!B||typeof B!="object")return;let _=tt(xa(B.value));o.set($,_);let G=B.id??B.name;typeof G=="string"&&G&&!xt.has(G)&&o.set(G,_)}),(t?.nodes||[]).forEach((B,$)=>{for(let _ of B?.children||[])typeof _=="number"&&g.set(_,$)});let W=B=>B.op||typeof B.declaration=="number"&&s[B.declaration]?.op||"",T=(B,$,_)=>{if(xt.has($))return;let G=a.get(B);G||a.set(B,G=Object.create(null)),G[$]=_},E=(B,$)=>{if(typeof B!="number"&&typeof B!="string"||typeof B=="string"&&xt.has(B)||!o.has(B)&&o.size>=en*2)return;let _=tt($);if(o.set(B,_),typeof B=="number"){let G=n[B]?.id??n[B]?.name;typeof G=="string"&&!xt.has(G)&&o.set(G,_)}},S=B=>typeof B=="number"?l[B]?.id??String(B):typeof B=="string"?/^\d+$/.test(B)&&l[Number(B)]?.id?l[Number(B)].id:B:"",O=(B,$)=>{for(let _=B,G=0;_!==void 0&&_>=0&&G<128;_=g.get(_),G++)if(_===$)return!0;return!1},k=B=>{for(let $=d.length-1;$>=0;$--)d[$].key===B&&d.splice($,1)},w=B=>{k(B.key),d.length>=Gl&&d.shift(),d.push(B)},ie=B=>{let $=jr(B)?.segments;if($){if($[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[Wt($[1],t.nodes.length)];if(!_)return;let G=$[2];if(G in Wr){let j=Wr[G],q=_[G]||j;return j.map((D,Y)=>fe(q[Y],D))}if(G==="weights"){let j=Array.isArray(_.weights)?_.weights:[0],q=$.length===4?Wt($[3],64):-2;return q===-2?j.map(D=>fe(D)):q>=0?fe(j[q]):void 0}if(G==="visible"||G==="extensions"&&$[3]==="KHR_node_visibility"&&$[4]==="visible")return _.extensions?.KHR_node_visibility?.visible??_.visible??!0}else if($[0]==="materials"&&Array.isArray(t?.materials)){let _=t.materials[Wt($[1],t.materials.length)];if(!_)return;let G=_.pbrMetallicRoughness||{};if($[2]==="pbrMetallicRoughness"){if($[3]==="baseColorFactor"){let j=G.baseColorFactor||[1,1,1,1];return[fe(j[0],1),fe(j[1],1),fe(j[2],1),fe(j[3],1)]}if($[3]==="metallicFactor"||$[3]==="roughnessFactor")return fe(G[$[3]],1)}if($[2]==="emissiveFactor"){let j=_.emissiveFactor||[0,0,0];return[fe(j[0]),fe(j[1]),fe(j[2])]}if($[2]==="alphaCutoff")return fe(_.alphaCutoff,.5)}}},oe=(B,$)=>{let _=jr(B)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let G=Wt(_[1],t.nodes.length),j=t.nodes[G];if(!j)return!1;let q=_[2];if(q in Wr&&Array.isArray($)){let D=Wr[q];if($.length<D.length)return!1;let Y=D.map((se,le)=>fe($[le],se));if(q==="rotation"){let se=Math.hypot(...Y);Y=se>1e-8?Y.map(le=>le/se):[0,0,0,1]}j[q]=Y,delete j.matrix;let te=e?.initialNodeTransforms?.[G];return te&&(te[q[0]]=[...Y]),M=!0,!0}if(q==="weights"){Array.isArray(j.weights)||(j.weights=[]);let D=(Y,te)=>{for(let se of e?.meshes||[])if(se.nodeIndex===G)for(let le of se.primitives||[])le.pluginData?.morph?.weights&&(le.pluginData.morph.weights[Y]=te)};if(_.length===4){let Y=Wt(_[3],64);if(Y<0)return!1;D(Y,j.weights[Y]=fe($))}else if(Array.isArray($))j.weights=$.slice(0,64).map(Y=>fe(Y)),j.weights.forEach((Y,te)=>D(te,Y));else return!1;return F=!0,!0}if(q==="visible"||q==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let D=nt($);return j.visible=D,(!j.extensions||typeof j.extensions!="object")&&(j.extensions={}),j.extensions.KHR_node_visibility={visible:D},P=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let G=Wt(_[1],t.materials.length),j=t.materials[G];if(!j)return!1;let q=j.pbrMetallicRoughness||(j.pbrMetallicRoughness={}),D=Y=>{for(let te of e?.meshes||[])for(let se of te.primitives||[])(se.materialIndex??0)===G&&Y(se)};if(_[2]==="pbrMetallicRoughness"){if(_[3]==="baseColorFactor"&&Array.isArray($)&&$.length>=3){let Y=[Ct(fe($[0],1)),Ct(fe($[1],1)),Ct(fe($[2],1)),$[3]!==void 0?Ct(fe($[3],1)):q.baseColorFactor?.[3]??1];return q.baseColorFactor=Y,D(te=>te.baseColor=[...Y]),F=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let Y=_[3]==="metallicFactor",te=Ct(fe($,Y?0:.5));return q[_[3]]=te,D(se=>se[Y?"metallic":"roughness"]=te),F=!0}}if(_[2]==="emissiveFactor"&&Array.isArray($)&&$.length>=3)return j.emissiveFactor=[0,1,2].map(Y=>Math.max(0,fe($[Y]))),F=!0;if(_[2]==="alphaCutoff")return j.alphaCutoff=Ct(fe($,.5)),F=!0}return!1},I=(B,$,_=new Set)=>{let G=Le($,"pointer");if(typeof G!="string"||!G.startsWith("/"))return null;let j=G.replace(/\{([a-zA-Z0-9_]+)\}/g,(q,D)=>{let Y=Math.trunc(Number(H(B,D,void 0,_)??Le($,D)));return Number.isSafeInteger(Y)&&Y>=0?String(Y):"-1"});return jr(j)?j:null},H=(B,$,_,G)=>{let j=i[B]?.values;if(!Gr(j,$))return _;let q=j[$];if(q==null)return _;if(typeof q!="object"||Array.isArray(q))return tt(q);let D=q;return typeof D.node=="number"?N(D.node,D.socket||"value",G):Gr(D,"value")?tt(D.value):_},N=(B,$,_)=>{if(B<0||B>=i.length||_.has(B)||_.size>128||++p>Xl)return;let G=i[B],j=W(G);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(j))return tt(a.get(B)?.[$]);_.add(B);try{let q=(D,Y=0)=>H(B,D,Y,_);if(j==="variable/get"){let D=Le(G,"variable")??Le(G,"id");return typeof D=="number"||typeof D=="string"?tt(o.get(D)):void 0}if(j==="pointer/get"){let D=I(B,G,_);return D?ie(D):void 0}if(j.startsWith("math/")){let D=j.slice(5);if(D in ya)return Yl(q("a"),ya[D]);if(D in ba){let Y=/^(mul|div|rem|mod|pow)$/.test(D)?1:0;return tn(q("a",D==="mul"?1:0),q("b",Y),ba[D])}if(D==="pi")return Math.PI;if(D==="e")return Math.E;if(D==="random")return Math.random();if(D==="clamp")return tn(tn(q("a"),q("b",q("min",0)),Math.max),q("c",q("max",1)),Math.min);if(D==="mix"||D==="quatSlerp")return Ma(q("a",0),q("b",1),fe(q("c",q("t",.5)),.5),D==="quatSlerp");if(D==="dot"){let Y=q("a"),te=q("b");return Array.isArray(Y)&&Array.isArray(te)?Y.reduce((se,le,V)=>se+(le||0)*(te[V]||0),0):fe(Y)*fe(te)}if(D==="cross"){let Y=q("a",[0,0,0]),te=q("b",[0,0,0]);return Array.isArray(Y)&&Array.isArray(te)?[(Y[1]||0)*(te[2]||0)-(Y[2]||0)*(te[1]||0),(Y[2]||0)*(te[0]||0)-(Y[0]||0)*(te[2]||0),(Y[0]||0)*(te[1]||0)-(Y[1]||0)*(te[0]||0)]:[0,0,0]}if(D==="length"){let Y=q("a");return Array.isArray(Y)?Math.hypot(...Y):Math.abs(fe(Y))}if(D==="distance"){let Y=q("a"),te=q("b");return Array.isArray(Y)&&Array.isArray(te)?Math.hypot(...Y.map((se,le)=>(se||0)-(te[le]||0))):Math.abs(fe(Y)-fe(te))}if(D==="normalize"){let Y=q("a");if(!Array.isArray(Y))return fe(Y)>=0?1:-1;let te=Math.hypot(...Y);return te>1e-8?Y.map(se=>se/te):Y.map(()=>0)}if(D.startsWith("combine"))return["a","b","c","d"].slice(0,Number(D[7])||2).map(Y=>fe(q(Y)));if(D.startsWith("extract")){let Y=q("a");return Array.isArray(Y)?Y[$==="0"||$==="x"?0:$==="1"||$==="y"?1:$==="2"||$==="z"?2:3]??0:0}if(D==="eq")return wa(q("a"),q("b"));if(D==="ne")return!wa(q("a"),q("b"));if(D==="lt")return fe(q("a"))<fe(q("b"));if(D==="le")return fe(q("a"))<=fe(q("b"));if(D==="gt")return fe(q("a"))>fe(q("b"));if(D==="ge")return fe(q("a"))>=fe(q("b"));if(D==="isNaN")return Number.isNaN(Number(q("a")));if(D==="isInf"){let Y=Number(q("a"));return!Number.isFinite(Y)&&!Number.isNaN(Y)}return D==="and"?nt(q("a",!1))&&nt(q("b",!1)):D==="or"?nt(q("a",!1))||nt(q("b",!1)):D==="xor"?nt(q("a",!1))!==nt(q("b",!1)):D==="not"?!nt(q("a",!1)):D==="select"?tt(nt(q("condition",!1))?q("a"):q("b")):void 0}return j==="type/boolToInt"||j==="type/boolToFloat"?nt(q("a",!1))?1:0:j==="type/intToBool"||j==="type/floatToBool"?fe(q("a",0))!==0:j==="type/intToFloat"?fe(q("a",0)):j==="type/floatToInt"?Math.trunc(fe(q("a",0))):void 0}finally{_.delete(B)}},z=()=>{if(M){M=!1,F=!0;let B=vr(t);if(e){e.worldMatrices=B;for(let $ of e.meshes||[])$.nodeIndex>=0&&$.nodeIndex<B.length&&($.transform.set(B[$.nodeIndex]),Ke($.normalMatrix,$.transform))}}if(P){P=!1,F=!0;let B=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(B))for(let $ of e.meshes){let _=!0;for(let G=$.nodeIndex,j=0;G!==void 0&&G>=0&&j<128;G=g.get(G),j++){let q=B[G];if(q?.visible===!1||q?.extensions?.KHR_node_visibility?.visible===!1){_=!1;break}}$.visible=_}}F&&(F=!1,e?.render?.())},ue=(B,$={steps:0})=>{if(!B||typeof B.node!="number")return;$.steps===0&&(p=0);let _=[B],G=j=>{_.length+$.steps<Hr&&_.push(j)};for(;_.length>0&&$.steps<Hr;){$.steps++;let j=_.shift();if(!j||j.node<0||j.node>=i.length)continue;let q=j.node,D=i[q];if(!D)continue;let Y=j.socket||"in",te=W(D),se=(V,ee=void 0)=>H(q,V,ee,new Set),le=(V="out")=>{let ee=D.flows?.[V];ee&&G(ee)};switch(te){case"flow/branch":le(nt(se("condition",!1))?"true":"false");break;case"flow/sequence":for(let V of Object.keys(D.flows||{}).sort((ee,R)=>Number(ee)-Number(R)||ee.localeCompare(R)))le(V);break;case"flow/switch":{let V=D.flows?.[String(se("selection",se("value",0)))]??D.flows?.default;V&&G(V);break}case"flow/for":{let V=Math.trunc(fe(se("startIndex",0))),ee=Math.trunc(fe(se("endIndex",0))),R=Math.max(1,Math.trunc(fe(se("step",1),1))),A=D.flows?.body;if(A&&ee>V&&y<Kl){let C=Math.min(Math.ceil((ee-V)/R),Hr);y++;try{for(let U=0;U<C&&$.steps<Hr;U++)T(q,"index",V+U*R),ue(A,$)}finally{y--}}let L=D.flows?.completed??D.flows?.out;L&&G(L);break}case"flow/doN":{let V=Y==="reset"?0:(u.get(q)||0)+1;if(u.set(q,V),T(q,"currentCount",V),T(q,"count",V),Y!=="reset"){let ee=Math.trunc(fe(se("n",Le(D,"stopIterations")??Le(D,"n")??1),1));V<=ee&&le()}break}case"flow/multiGate":{if(Y==="reset"){c.set(q,0);break}let V=Object.keys(D.flows||{}).sort();if(!V.length)break;let ee=Le(D,"isRandom")?Math.floor(Math.random()*V.length):c.get(q)||0;ee<V.length&&(le(V[ee]),c.set(q,Le(D,"isLoop")!==!1?(ee+1)%V.length:ee+1));break}case"flow/waitAll":{if(Y==="reset"){h.delete(q);break}let V=h.get(q);V||h.set(q,V=new Set),V.add(Y),V.size>=Math.max(1,Math.trunc(Number(Le(D,"inputFlows")??2)||2))&&(V.clear(),le("out"),le("completed"));break}case"flow/throttle":{if(Y==="reset"){m.delete(q);break}let V=Math.max(0,fe(se("duration",0))),ee=m.get(q);ee===void 0||b-ee>=V?(m.set(q,b),T(q,"lastRemainingTime",0),le()):T(q,"lastRemainingTime",Math.max(0,V-(b-ee)));break}case"flow/delay":case"flow/setDelay":{if(Y==="cancel"){for(let A=f.length-1;A>=0;A--)f[A].nodeIdx===q&&f.splice(A,1);T(q,"lastDelayIndex",-1);break}let V=Math.max(0,fe(se("duration",Le(D,"duration")??0))),ee=D.flows?.done??D.flows?.out;if(V<=0){T(q,"lastDelayIndex",-1),ee&&G(ee);break}f.length>=jl&&f.shift();let R=x++;T(q,"lastDelayIndex",R),f.push({id:R,nodeIdx:q,rem:V,done:ee}),te==="flow/setDelay"&&D.flows?.out&&D.flows?.done&&le("out");break}case"flow/cancelDelay":{let V=Math.trunc(fe(se("delayIndex",-1),-1));if(V<0)f.length=0;else for(let ee=f.length-1;ee>=0;ee--)f[ee].id===V&&f.splice(ee,1);le();break}case"variable/set":E(Le(D,"variable")??Le(D,"id"),se("value")),le();break;case"variable/interpolate":{let V=Le(D,"variable")??Le(D,"id"),ee=se("value",se("target")),R=Math.max(0,fe(se("duration",Le(D,"duration")??.3),.3));V!==void 0&&ee!==void 0&&w({key:`var:${String(V)}`,varKey:V,from:tt(se("from")??o.get(V)??0),to:tt(ee),dur:R,elapsed:0,quat:!1,linear:Le(D,"easing")==="linear",done:D.flows?.done}),le();break}case"pointer/set":{let V=I(q,D),ee=se("value");V&&ee!==void 0&&(k(`ptr:${V}`),oe(V,ee)),le();break}case"pointer/interpolate":{let V=I(q,D),ee=se("value",se("target")),R=Math.max(0,fe(se("duration",Le(D,"duration")??.3),.3));if(V&&ee!==void 0){let A=se("from")??ie(V);A!==void 0&&(R<=0?(oe(V,ee),le("done")):w({key:`ptr:${V}`,ptr:V,from:tt(A),to:tt(ee),dur:R,elapsed:0,quat:V.endsWith("/rotation"),linear:Le(D,"easing")==="linear",done:D.flows?.done}))}le();break}case"animation/start":{let V=se("animation")??Le(D,"animation")??Le(D,"clipName"),ee=typeof V=="number"?e?.animations?.[V]?.name??t?.animations?.[V]?.name:typeof V=="string"?V:void 0;e?.playAnimation?.(ee),F=!0,le();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),te==="animation/resetAt"&&e?.evaluateAnimation?.(fe(se("time",0))),F=!0,le();break;case"event/send":case"customEvent/send":{let V=S(Le(D,"event")??Le(D,"id")),ee={};for(let R of Object.keys(D.values||{}))xt.has(R)||(ee[R]=se(R));V&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:V,values:ee}})),he(V,ee,$)),le();break}default:le();break}}};this.readScenePointer=ie,this.writeScenePointer=oe,this.fireOnStart=()=>{i.forEach(B=>{W(B)==="event/onStart"&&ue(B.flows?.out)}),z()},this.fireOnSelect=B=>{if(!B)return;let $=typeof B.meshIndex=="number"?B.meshIndex:-1,_=typeof B.nodeIndex=="number"?B.nodeIndex:e?.meshes?.[$]?.nodeIndex??-1;i.forEach((G,j)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(W(G)))return;let q=Le(G,"nodeIndex")??Le(G,"node")??H(j,"nodeIndex",void 0,new Set),D=Le(G,"meshName");if(typeof D=="string"&&D?B.meshName===D:q==null||Number(q)<0||Number.isNaN(Number(q))||O(_,Math.trunc(Number(q)))){if(T(j,"nodeIndex",_),T(j,"meshIndex",$),Array.isArray(B.hitPoint)){let Y=[fe(B.hitPoint[0]),fe(B.hitPoint[1]),fe(B.hitPoint[2])];T(j,"hitPoint",Y),T(j,"point",Y),T(j,"intersectionPoint",Y)}if(Array.isArray(B.normal)){let Y=[fe(B.normal[0]),fe(B.normal[1],1),fe(B.normal[2])];T(j,"normal",Y),T(j,"hitNormal",Y)}typeof B.distance=="number"&&T(j,"distance",B.distance),ue(G.flows?.out)}}),z()},this.receiveCustomEvent=(B,$={})=>he(B,$,{steps:0});function he(B,$,_){if(!(v>=ql)){v++;try{let G=S(B);i.forEach((j,q)=>{if(!/^(customE|e)vent\/receive$/.test(W(j)))return;let D=Le(j,"event")??Le(j,"id");if(!(S(D)!==G&&String(D)!==String(B))){for(let[Y,te]of Object.entries($))xt.has(Y)||T(q,Y,tt(te));ue(j.flows?.out,_)}}),z()}finally{v--}}}this.tick=B=>{if(!Number.isFinite(B)||B<0)return;let $=Math.min(B,.25);b+=$,i.forEach((G,j)=>{W(G)==="event/onTick"&&(T(j,"timeDelta",$),T(j,"dt",$),T(j,"timeElapsed",b),ue(G.flows?.out))});let _=[];for(let G=d.length-1;G>=0;G--){let j=d[G];j.elapsed+=$;let q=j.dur>1e-6?Ct(j.elapsed/j.dur):1,D=j.linear?q:q*q*(3-2*q),Y=Ma(j.from,j.to,D,j.quat);j.ptr?oe(j.ptr,Y):j.varKey!==void 0&&E(j.varKey,Y),q>=1&&(d.splice(G,1),j.done&&_.push(j.done))}for(let G=f.length-1;G>=0;G--){let j=f[G];j.rem-=$,j.rem<=0&&(f.splice(G,1),j.done&&_.push(j.done))}for(let G of _)ue(G);z()},this.dispose=()=>{d.length=0,f.length=0,o.clear(),a.clear(),u.clear(),h.clear(),m.clear(),c.clear()}}},ht=new WeakMap,qr=new WeakMap;function Zl(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||un().some(o=>o.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let n=Math.min(t,.1),s=(qr.get(e)||0)+n,l=!1;for(let o=0;o<i.length;o++){let a=i[o],u=ul(a?.extras?.xr?.orbit);if(!u)continue;let h=0,m=0,c=0;if(Array.isArray(u.target))h=u.target[0],m=u.target[1],c=u.target[2];else if(typeof u.target=="string"&&u.target!=="head"){let b=i.find(v=>v?.name===u.target);Array.isArray(b?.translation)&&(h=fe(b.translation[0]),m=fe(b.translation[1]),c=fe(b.translation[2]))}let d=u.phase+u.speed*s,f=h+Math.cos(d)*u.radius,g=m+u.height,x=c+Math.sin(d)*u.radius;if(a.translation=[f,g,x],u.faceCenter){let b=Math.atan2(h-f,c-x);a.rotation=[0,Math.sin(b*.5),0,Math.cos(b*.5)]}l=!0}if(l){qr.set(e,s);let o=vr(r);e.worldMatrices=o;for(let a of e.meshes||[])a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),Ke(a.normalMatrix,a.transform))}}function rn(e){if(!(!e||typeof e!="object"))return ht.get(e)||ht.get(e.viewer)||ht.get(e._view)}function Ta(e,t,r){let i=rn(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var Sa={name:"khr-interactivity",sendInteractivityEvent:Ta,getInteractivityVM:rn,onLoadModel(e,t){if(!e||typeof e!="object")return;ht.get(e)?.dispose(),ht.delete(e),qr.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let n=new Aa(e,t,i);ht.set(e,n),n.fireOnStart()},onMeshSelect(e,t){ht.get(e)?.fireOnSelect(t)},onUpdate(e,t){ht.get(e)?.tick(t),Zl(e,t)},onDestroy(e,t){ht.get(t)?.dispose(),ht.delete(t),qr.delete(t)}},pr=new Map,Xr=new WeakMap;function Ql(e,t){pr.set(e,t)}var Ra={name:"materials",onContextRestored(e){Xr.delete(e)},onBuildPrimitiveVAO(e,t,r,i,n){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=Xr.get(e);r||(r=e.createTexture(),Xr.set(e,r));let i=Math.max(1,t.canvas.width),n=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,n,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&pr.has(t.name)){let f=pr.get(t.name);return{vs:f.vs||r,fs:f.fs||i}}let n=t.extensions||{},s=n.KHR_materials_clearcoat,l=n.KHR_materials_sheen,o=!!n.KHR_materials_transmission,a=!!n.KHR_materials_ior,u=n.KHR_materials_iridescence;if(!s&&!l&&!n.KHR_materials_unlit&&!o&&!n.KHR_materials_volume&&!a&&!n.KHR_materials_dispersion&&!u)return null;if(n.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let h=i;if(o){let f=h.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
416
+ `;h=h.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
417
+ ${f}out vec4 fragColor;`)}let m=(f,g,x=0,b=1e6,v=3)=>{let p=Number(f);return(Number.isFinite(p)?Math.min(b,Math.max(x,p)):g).toFixed(v)},c=Number(n.KHR_materials_ior?.ior??1.5),d=Number.isFinite(c)?Math.min(10,Math.max(1,c)):1.5;if(a){let f=Math.pow((d-1)/(d+1),2);h=h.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(f,.04,0,1,4)}),base.rgb,metallic);`)}if(u){let f=m(u.iridescenceFactor,1,0,1),g=m(u.iridescenceIor,1.3,1,10);h=h.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${g}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${f}*pow(1.-NoV,2.));`)}if(o){let f=m(n.KHR_materials_transmission?.transmissionFactor,1,0,1),g=n.KHR_materials_volume||{},x=m(g.thicknessFactor,.5,0,1e4),b=m(g.attenuationDistance,1,.001,1e6),v=Array.isArray(g.attenuationColor)?g.attenuationColor:[1,1,1],p=m(n.KHR_materials_dispersion?.dispersion,0,0,10);h=h.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
418
+ vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(d,1.5,1,10)},dV=${p},tV=${x},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
368
419
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
369
420
  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);
370
- vec3 aCol=vec3(${m(R[0],1,0,1)},${m(R[1],1,0,1)},${m(R[2],1,0,1)});
371
- vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${v},.001));
372
- diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${p});`)}if(o&&!r.includes("uClearcoat")){let p=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)*${p};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${d})*ccF;fragColor=vec4(color,base.a);`)}if(a){let p=Array.isArray(a.sheenColorFactor)?a.sheenColorFactor:[1,1,1],d=`color+=vec3(${m(p[0],1,0,1)},${m(p[1],1,0,1)},${m(p[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 a=n.materialIndex;if(a!==void 0&&o?.materials){let u=o.materials[a];u?.name&&Cn.has(u.name)&&Cn.get(u.name).onBindUniforms?.(t,e,n)}if(n.isTransmissive){let u=kr.get(t);if(u){t.activeTexture(33990),t.bindTexture(3553,u);let s=t.getUniformLocation(e,"uTransmissionTex");s&&t.uniform1i(s,6);let c=t.getUniformLocation(e,"uViewportSize");c&&t.uniform2f(c,t.drawingBufferWidth||1,t.drawingBufferHeight||1)}}}};var ws=64*1024*1024,Ms=128*1024*1024,sc=16777216;function ac(t){return(t>>>1^-(t&1))&255}function cc(t){return(t>>>1^-(t&1))&65535}function uc(t){let e=t<<24>>24;return(e<<1^e>>7)&255}function As(t){return(t<<1^t>>31)>>>0}function Es(t){if(t!==void 0&&t!=="NONE"&&t!=="OCTAHEDRAL"&&t!=="QUATERNION"&&t!=="EXPONENTIAL"&&t!=="COLOR")throw Se(`unknown filter "${String(t)}"`)}var Te=Math.fround;function on(t){return Math.trunc(Te(t+(t>=0?.5:-.5)))}function Vi(t,e,n,r="NONE"){if(Es(r),!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 Se(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let m=n===8,f=m?32767:127,h=y=>m?i.getInt16(y,!0):i.getInt8(y),p=(y,v)=>m?i.setInt16(y,v,!0):i.setInt8(y,v<<24>>24),d=m?2:1;for(let y=0;y<e;y++){let v=y*n,R=h(v),b=h(v+d),w=Te(h(v+2*d)-Math.abs(R)-Math.abs(b)),M=w>=0?0:w;R=Te(R+(R>=0?M:-M)),b=Te(b+(b>=0?M:-M));let P=Te(Math.sqrt(Te(Te(Te(R*R)+Te(b*b))+Te(w*w))));if(P===0){p(v,0),p(v+d,0),p(v+2*d,f);continue}let k=Te(f/P);p(v,on(Te(R*k))),p(v+d,on(Te(b*k))),p(v+2*d,on(Te(w*k)))}return}if(r==="QUATERNION"){if(n!==8)throw Se(`QUATERNION filter requires byteStride 8 (got ${n})`);let m=Te(32767/Te(Math.SQRT2));for(let f=0;f<e;f++){let h=f*8,p=i.getInt16(h+6,!0),d=p|3,y=i.getInt16(h,!0),v=i.getInt16(h+2,!0),R=i.getInt16(h+4,!0),b=Te(d*d),w=Te(Te(Te(Te(b*2)-Te(y*y))-Te(v*v))-Te(R*R)),M=Te(Math.sqrt(w>=0?w:0)),P=Te(m/d),k=p&3,I=[0,0,0,0];I[k+1&3]=on(Te(y*P)),I[k+2&3]=on(Te(v*P)),I[k+3&3]=on(Te(R*P)),I[k]=Math.trunc(Te(Te(M*P)+.5));for(let L=0;L<4;L++)i.setInt16(h+L*2,I[L]<<16>>16,!0)}return}if(r==="EXPONENTIAL"){if(n<4||n%4!==0)throw Se(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let m=e*n>>>2;for(let f=0;f<m;f++){let h=f*4,p=i.getUint32(h,!0),d=p<<8>>8,y=p>>24;i.setUint32(h,y+127<<23>>>0,!0);let v=i.getFloat32(h,!0);i.setFloat32(h,Te(v*d),!0)}return}if(n!==4&&n!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${n})`);let o=n===8,a=o?65535:255,u=m=>o?i.getUint16(m,!0):i.getUint8(m),s=m=>o?i.getInt16(m,!0):i.getInt8(m),c=(m,f)=>o?i.setUint16(m,f&65535,!0):i.setUint8(m,f&255),l=o?2:1;for(let m=0;m<e;m++){let f=m*n,h=u(f+3*l);h|=h>>1,h|=h>>2,h|=h>>4,h|=h>>8;let p=u(f),d=s(f+l),y=s(f+2*l),v=p+d-y,R=p+y,b=p-d-y,w=u(f+3*l);w=w<<1&h|w&1;let M=h===0?0:Te(a/h);c(f,Math.trunc(Te(Te(v*M)+.5))),c(f+l,Math.trunc(Te(Te(R*M)+.5))),c(f+2*l,Math.trunc(Te(Te(b*M)+.5))),c(f+3*l,Math.trunc(Te(Te(w*M)+.5)))}}var _s=160,lt=16,lc=24,Ls=32,fc=24,mc=[0,2,4,8],dc=[0,1,2,4,8];function Is(t){let e=Math.floor(8192/t)&~(lt-1);return e<256?e:256}function Se(t){return new Error(`EXT_meshopt_compression: ${t}`)}function hc(t,e,n,r,i){if(i===0)return n.fill(0,r,r+lt),e;if(i===8)return n.set(t.subarray(e,e+lt),r),e+lt;let o=(1<<i)-1,a=8/i,u=e+lt*i/8;for(let s=0;s<lt;s++){let c=t[e+Math.floor(s/a)],l=s%a,m=i===1?c>>l&1:c>>8-i-l*i&o;n[r+s]=m===o?t[u++]:m}return u}function Ss(t,e,n,r,i,o,a,u){let s=o/lt,c=s+3>>2;if(n-e<c)throw Se("truncated ATTRIBUTES stream");let l=e;e+=c;for(let m=0;m<s;m++){if(n-e<lc)throw Se("truncated ATTRIBUTES stream");let f=t[l+(m>>2)]>>(m&3)*2&3;e=hc(t,e,r,i+m*lt,a[u+f])}return e}function pc(t,e,n,r){if(n%4!==0||n>256)throw Se(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let i=t.byteLength;if(i<1)throw Se("truncated ATTRIBUTES stream");let o=t[0];if((o&240)!==_s)throw Se(`unsupported ATTRIBUTES header 0x${o.toString(16)}`);let a=o&15;if(a>1)throw Se(`unsupported ATTRIBUTES codec version ${a}`);let u=n+(a===0?0:n/4),s=a===0?Ls:fc,c=u<s?s:u;if(i-1<c)throw Se("truncated ATTRIBUTES stream");let l=i-u,m=t.slice(l,l+n),f=l+n,h=Is(n),p=new Uint8Array(256*4),d=1;for(let y=0;y<e;){let v=Math.min(h,e-y),R=v+lt-1&~(lt-1),b=a===0?0:n/4;if(i-d<b)throw Se("truncated ATTRIBUTES stream");let w=d;d+=b;for(let M=0;M<n;M+=4){let P=a===0?0:t[w+M/4];for(let L=0;L<4;L++){let x=P>>L*2&3;if(x===3){if(i-d<v)throw Se("truncated ATTRIBUTES stream");p.set(t.subarray(d,d+v),L*v),d+=v}else x===2?p.fill(0,L*v,L*v+v):d=a===0?Ss(t,d,i,p,L*v,R,mc,0):Ss(t,d,i,p,L*v,R,dc,x)}let k=a===0?0:t[f+M/4],I=k&3;if(I===0)for(let L=0;L<4;L++){let x=m[M+L];for(let g=0;g<v;g++)x=ac(p[L*v+g])+x&255,r[(y+g)*n+M+L]=x}else if(I===1)for(let L=0;L<4;L+=2){let x=m[M+L]|m[M+L+1]<<8,g=L*v;for(let A=0;A<v;A++){let N=p[g+A]|p[g+v+A]<<8;x=cc(N)+x&65535;let _=(y+A)*n+M+L;r[_]=x&255,r[_+1]=x>>8}}else if(I===2){let L=32-(k>>4)&31,x=(m[M]|m[M+1]<<8|m[M+2]<<16|m[M+3]<<24)>>>0;for(let g=0;g<v;g++){let A=(p[g]|p[v+g]<<8|p[2*v+g]<<16|p[3*v+g]<<24)>>>0;A=((A<<L|A>>>(32-L&31))^x)>>>0,x=A;let N=(y+g)*n+M;r[N]=A&255,r[N+1]=A>>>8&255,r[N+2]=A>>>16&255,r[N+3]=A>>>24}}else throw Se(`invalid ATTRIBUTES channel ${k}`)}m.set(r.subarray((y+v-1)*n,(y+v)*n)),y+=v}if(i-d!==c)throw Se("ATTRIBUTES trailing data")}var Cs=224,Ps=208;function ks(t,e){let n=t[e.pos++]??0;if(n<128)return n;let r=n&127,i=7;for(let o=0;o<4;o++){let a=t[e.pos++]??0;if(r=(r|(a&127)<<i)>>>0,i+=7,a<128)break}return r>>>0}function Nr(t,e,n){let r=ks(t,e),i=r>>>1^-(r&1);return n+i>>>0}function bc(t,e,n){if(e%3!==0)throw Se(`TRIANGLES count must be divisible by 3 (got ${e})`);let r=e/3;if(t.byteLength<1+r+16)throw Se("truncated TRIANGLES stream");let i=t[0];if((i&240)!==Cs)throw Se(`unsupported TRIANGLES header 0x${i.toString(16)}`);let o=i&15;if(o>1)throw Se(`unsupported TRIANGLES codec version ${o}`);let a=new Uint32Array(16).fill(4294967295),u=new Uint32Array(16).fill(4294967295),s=new Uint32Array(16).fill(4294967295),c=0,l=0,m=(P,k)=>{a[c]=P,u[c]=k,c=c+1&15},f=(P,k=1)=>{s[l]=P,l=l+k&15},h=0,p=0,d=o>=1?13:15,y=1+r,v=t.byteLength-16,R=v,b={pos:y},w=0,M=(P,k,I)=>{n(w++,P),n(w++,k),n(w++,I)};for(let P=1;P<y;P++){let k=t[P];if(k<240){let I=k>>4,L=c-1-I&15,x=a[L],g=u[L],A=0,N=k&15;if(N<d){let _=s[l-1-N&15];A=N===0?h:_;let O=N===0?1:0;h=h+O>>>0,f(A,O)}else{if(b.pos>v)throw Se("truncated TRIANGLES stream");A=N!==15?p+(N*2-27)>>>0:Nr(t,b,p),p=A,f(A)}m(A,g),m(x,A),M(x,g,A)}else if(k<254){let I=t[R+(k&15)],L=I>>4,x=I&15,g=h;h=h+1>>>0;let A=s[l-L&15],N=L===0?h:A,_=L===0?1:0;h=h+_>>>0;let O=s[l-x&15],Q=x===0?h:O,q=x===0?1:0;h=h+q>>>0,M(g,N,Q),f(g),f(N,_),f(Q,q),m(N,g),m(Q,N),m(g,Q)}else{if(b.pos>v)throw Se("truncated TRIANGLES stream");let I=t[b.pos++],L=k===254?0:15,x=I>>4,g=I&15;I===0&&(h=0);let A=0;L===0&&(A=h,h=h+1>>>0);let N;x===0?(N=h,h=h+1>>>0):N=s[l-x&15];let _;g===0?(_=h,h=h+1>>>0):_=s[l-g&15],L===15&&(p=A=Nr(t,b,p)),x===15&&(p=N=Nr(t,b,p)),g===15&&(p=_=Nr(t,b,p)),M(A,N,_),f(A),f(N,x===0||x===15?1:0),f(_,g===0||g===15?1:0),m(N,A),m(_,N),m(A,_)}}if(b.pos!==v)throw Se("TRIANGLES trailing data")}function yc(t,e,n){if(t.byteLength<1+e+4)throw Se("truncated INDICES stream");let r=t[0];if((r&240)!==Ps)throw Se(`unsupported INDICES header 0x${r.toString(16)}`);let i=r&15;if(i>1)throw Se(`unsupported INDICES codec version ${i}`);let o=t.byteLength-4,a=[0,0],u={pos:1};for(let s=0;s<e;s++){if(u.pos>=o)throw Se("truncated INDICES stream");let c=ks(t,u),l=c&1;c>>>=1;let m=c>>>1^-(c&1),f=a[l]+m>>>0;a[l]=f,n(s,f)}if(u.pos!==o)throw Se("INDICES trailing data")}function Bi(t,e,n,r,i="NONE"){if(Es(i),!Number.isInteger(e)||e<0||e>sc||!Number.isInteger(n)||n<=0||n>256)throw Se(`invalid count (${e}) or byteStride (${n})`);let o=e*n;if(o>ws)throw Se(`decompressed size (${o}) exceeds MAX_MESHOPT_BUFFER_BYTES (${ws})`);if(e===0)return new Uint8Array(0);let a=new Uint8Array(o);if(r==="ATTRIBUTES")return pc(t,e,n,a),Vi(a,e,n,i),a;if(r==="TRIANGLES"||r==="INDICES"){if(n!==2&&n!==4)throw Se(`${r} byteStride must be 2 or 4 (got ${n})`);if(i&&i!=="NONE")throw Se(`filter ${i} is only valid for ATTRIBUTES`);let u=new DataView(a.buffer),s=n===2?(c,l)=>u.setUint16(c*2,l&65535,!0):(c,l)=>u.setUint32(c*4,l>>>0,!0);return r==="TRIANGLES"?bc(t,e,s):yc(t,e,s),a}throw Se(`unknown mode "${String(r)}"`)}function Rs(t,e){e>>>=0;do t.push(e&127|(e>127?128:0)),e>>>=7;while(e)}function Ns(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(r==="ATTRIBUTES"){if(n%4!==0||n>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let u=[_s],s=Is(n),c=new Uint8Array(n);e>0&&c.set(t.subarray(0,n));let l=c.slice(),m=new Uint8Array(256);for(let f=0;f<e;){let h=Math.min(s,e-f),p=h+15&-16;for(let d=0;d<n;d++){m.fill(0);let y=c[d];for(let b=0;b<h;b++){let w=t[(f+b)*n+d];m[b]=uc(w-y&255),y=w}c[d]=y;let v=p/16,R=u.length;for(let b=0;b<v+3>>2;b++)u.push(0);for(let b=0;b<v;b++){let w=m.subarray(b*16,b*16+16);if(!w.every(M=>M===0)){u[R+(b>>2)]|=3<<(b&3)*2;for(let M of w)u.push(M)}}}f+=h}for(let f=n;f<Ls;f++)u.push(0);for(let f=0;f<n;f++)u.push(l[f]);return new Uint8Array(u)}if(n!==2&&n!==4)throw new Error(`encodeMeshoptBuffer: ${r} byteStride must be 2 or 4 (got ${n})`);let o=new DataView(t.buffer,t.byteOffset,t.byteLength),a=u=>n===2?o.getUint16(u*2,!0):o.getUint32(u*4,!0);if(r==="INDICES"){let u=[Ps|1],s=0;for(let c=0;c<e;c++){let l=a(c),m=l-s|0;s=l,Rs(u,As(m)<<1>>>0)}return u.push(0,0,0,0),new Uint8Array(u)}if(r==="TRIANGLES"){if(e%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${e})`);let u=e/3,s=[Cs|1];for(let l=0;l<u;l++)s.push(255);let c=0;for(let l=0;l<u;l++){s.push(255);for(let m=0;m<3;m++){let f=a(l*3+m);Rs(s,As(f-c|0)),c=f}}for(let l=0;l<16;l++)s.push(0);return new Uint8Array(s)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(r)}"`)}function Dr(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=[],a=0;for(let m=0;m<r.bufferViews.length;m++){let f=r.bufferViews[m],h=f?.extensions?.KHR_meshopt_compression,p=h??f?.extensions?.EXT_meshopt_compression;if(!p||typeof p!="object")continue;let d=h?"KHR_meshopt_compression":"EXT_meshopt_compression",y=Number(p.count),v=Number(p.byteStride),R=Number(p.byteOffset??0),b=Number(p.byteLength??0),w=p.mode||"ATTRIBUTES",M=p.filter||"NONE";if(M==="COLOR"&&!h)throw Se(`bufferView ${m} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(p.buffer??0)!==0)throw new Error(`${d}: bufferView ${m} references buffer ${String(p.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(R)||R<0||!Number.isInteger(b)||b<0||R+b>i.byteLength)throw new Error(`${d}: bufferView ${m} compressed range [${R}, ${R+b}] out of bounds (${i.byteLength})`);let P=y*v;if(a+=P,a>Ms)throw Se(`total decompressed size (${a}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Ms})`);let k=i.subarray(R,R+b),I=Bi(k,y,v,w,M);o.push({index:m,bytes:I,ext:p})}if(o.length===0)return;let u=i.byteLength+3&-4,s=0;for(let m of o)s+=m.bytes.byteLength+3&-4;let c=new Uint8Array(u+s);c.set(i,0);let l=u;for(let m of o){c.set(m.bytes,l);let f=r.bufferViews[m.index];f.buffer=0,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,delete f.extensions.KHR_meshopt_compression),l+=m.bytes.byteLength+3&-4}n.bin=c.buffer}var Ur={decodeBufferViews(t,e){Dr(e)},decodePrimitive(t,e,n){let r=e?.extensions;r?.EXT_meshopt_compression&&delete r.EXT_meshopt_compression,r?.KHR_meshopt_compression&&delete r.KHR_meshopt_compression}};ve().decoders.set("meshopt",Ur);var zi={name:"meshopt",onParseGLB(t){ve().decoders.set("meshopt",Ur),Dr(t)}};var gc=`#version 300 es
421
+ vec3 aCol=vec3(${m(v[0],1,0,1)},${m(v[1],1,0,1)},${m(v[2],1,0,1)});
422
+ vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${b},.001));
423
+ diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${f});`)}if(s&&!i.includes("uClearcoat")){let f=m(s.clearcoatFactor,1,0,1),g=m(s.clearcoatRoughnessFactor,0,0,1);h=h.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${g},NoV)*${f};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${g})*ccF;fragColor=vec4(color,base.a);`)}if(l){let f=Array.isArray(l.sheenColorFactor)?l.sheenColorFactor:[1,1,1],g=`color+=vec3(${m(f[0],1,0,1)},${m(f[1],1,0,1)},${m(f[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;h.includes("color=applyToneMapping(color,uToneMapping);")?h=h.replace("color=applyToneMapping(color,uToneMapping);",`${g}color=applyToneMapping(color,uToneMapping);`):h=h.replace("fragColor=vec4(color,base.a);",`${g}fragColor=vec4(color,base.a);`)}return{vs:r,fs:h}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.materialIndex;if(l!==void 0&&s?.materials){let o=s.materials[l];o?.name&&pr.has(o.name)&&pr.get(o.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let o=Xr.get(e);if(o){e.activeTexture(33990),e.bindTexture(3553,o);let a=e.getUniformLocation(t,"uTransmissionTex");a&&e.uniform1i(a,6);let u=e.getUniformLocation(t,"uViewportSize");u&&e.uniform2f(u,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},Pa=64*1024*1024,Ea=128*1024*1024,Jl=16777216;function eu(e){return(e>>>1^-(e&1))&255}function tu(e){return(e>>>1^-(e&1))&65535}function ru(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Na(e){return(e<<1^e>>31)>>>0}function Ca(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw Te(`unknown filter "${String(e)}"`)}var we=Math.fround;function Gt(e){return Math.trunc(we(e+(e>=0?.5:-.5)))}function La(e,t,r,i="NONE"){if(Ca(i),!i||i==="NONE"||t<=0)return;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw Te(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let m=r===8,c=m?32767:127,d=x=>m?n.getInt16(x,!0):n.getInt8(x),f=(x,b)=>m?n.setInt16(x,b,!0):n.setInt8(x,b<<24>>24),g=m?2:1;for(let x=0;x<t;x++){let b=x*r,v=d(b),p=d(b+g),y=we(d(b+2*g)-Math.abs(v)-Math.abs(p)),M=y>=0?0:y;v=we(v+(v>=0?M:-M)),p=we(p+(p>=0?M:-M));let P=we(Math.sqrt(we(we(we(v*v)+we(p*p))+we(y*y))));if(P===0){f(b,0),f(b+g,0),f(b+2*g,c);continue}let F=we(c/P);f(b,Gt(we(v*F))),f(b+g,Gt(we(p*F))),f(b+2*g,Gt(we(y*F)))}return}if(i==="QUATERNION"){if(r!==8)throw Te(`QUATERNION filter requires byteStride 8 (got ${r})`);let m=we(32767/we(Math.SQRT2));for(let c=0;c<t;c++){let d=c*8,f=n.getInt16(d+6,!0),g=f|3,x=n.getInt16(d,!0),b=n.getInt16(d+2,!0),v=n.getInt16(d+4,!0),p=we(g*g),y=we(we(we(we(p*2)-we(x*x))-we(b*b))-we(v*v)),M=we(Math.sqrt(y>=0?y:0)),P=we(m/g),F=f&3,W=[0,0,0,0];W[F+1&3]=Gt(we(x*P)),W[F+2&3]=Gt(we(b*P)),W[F+3&3]=Gt(we(v*P)),W[F]=Math.trunc(we(we(M*P)+.5));for(let T=0;T<4;T++)n.setInt16(d+T*2,W[T]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw Te(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let m=t*r>>>2;for(let c=0;c<m;c++){let d=c*4,f=n.getUint32(d,!0),g=f<<8>>8,x=f>>24;n.setUint32(d,x+127<<23>>>0,!0);let b=n.getFloat32(d,!0);n.setFloat32(d,we(b*g),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let s=r===8,l=s?65535:255,o=m=>s?n.getUint16(m,!0):n.getUint8(m),a=m=>s?n.getInt16(m,!0):n.getInt8(m),u=(m,c)=>s?n.setUint16(m,c&65535,!0):n.setUint8(m,c&255),h=s?2:1;for(let m=0;m<t;m++){let c=m*r,d=o(c+3*h);d|=d>>1,d|=d>>2,d|=d>>4,d|=d>>8;let f=o(c),g=a(c+h),x=a(c+2*h),b=f+g-x,v=f+x,p=f-g-x,y=o(c+3*h);y=y<<1&d|y&1;let M=d===0?0:we(l/d);u(c,Math.trunc(we(we(b*M)+.5))),u(c+h,Math.trunc(we(we(v*M)+.5))),u(c+2*h,Math.trunc(we(we(p*M)+.5))),u(c+3*h,Math.trunc(we(we(y*M)+.5)))}}var _a=160,ct=16,iu=24,Ia=32,nu=24,su=[0,2,4,8],au=[0,1,2,4,8];function Da(e){let t=Math.floor(8192/e)&~(ct-1);return t<256?t:256}function Te(e){return new Error(`EXT_meshopt_compression: ${e}`)}function ou(e,t,r,i,n){if(n===0)return r.fill(0,i,i+ct),t;if(n===8)return r.set(e.subarray(t,t+ct),i),t+ct;let s=(1<<n)-1,l=8/n,o=t+ct*n/8;for(let a=0;a<ct;a++){let u=e[t+Math.floor(a/l)],h=a%l,m=n===1?u>>h&1:u>>8-n-h*n&s;r[i+a]=m===s?e[o++]:m}return o}function ka(e,t,r,i,n,s,l,o){let a=s/ct,u=a+3>>2;if(r-t<u)throw Te("truncated ATTRIBUTES stream");let h=t;t+=u;for(let m=0;m<a;m++){if(r-t<iu)throw Te("truncated ATTRIBUTES stream");let c=e[h+(m>>2)]>>(m&3)*2&3;t=ou(e,t,i,n+m*ct,l[o+c])}return t}function lu(e,t,r,i){if(r%4!==0||r>256)throw Te(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw Te("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==_a)throw Te(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let l=s&15;if(l>1)throw Te(`unsupported ATTRIBUTES codec version ${l}`);let o=r+(l===0?0:r/4),a=l===0?Ia:nu,u=o<a?a:o;if(n-1<u)throw Te("truncated ATTRIBUTES stream");let h=n-o,m=e.slice(h,h+r),c=h+r,d=Da(r),f=new Uint8Array(256*4),g=1;for(let x=0;x<t;){let b=Math.min(d,t-x),v=b+ct-1&~(ct-1),p=l===0?0:r/4;if(n-g<p)throw Te("truncated ATTRIBUTES stream");let y=g;g+=p;for(let M=0;M<r;M+=4){let P=l===0?0:e[y+M/4];for(let T=0;T<4;T++){let E=P>>T*2&3;if(E===3){if(n-g<b)throw Te("truncated ATTRIBUTES stream");f.set(e.subarray(g,g+b),T*b),g+=b}else E===2?f.fill(0,T*b,T*b+b):g=l===0?ka(e,g,n,f,T*b,v,su,0):ka(e,g,n,f,T*b,v,au,E)}let F=l===0?0:e[c+M/4],W=F&3;if(W===0)for(let T=0;T<4;T++){let E=m[M+T];for(let S=0;S<b;S++)E=eu(f[T*b+S])+E&255,i[(x+S)*r+M+T]=E}else if(W===1)for(let T=0;T<4;T+=2){let E=m[M+T]|m[M+T+1]<<8,S=T*b;for(let O=0;O<b;O++){let k=f[S+O]|f[S+b+O]<<8;E=tu(k)+E&65535;let w=(x+O)*r+M+T;i[w]=E&255,i[w+1]=E>>8}}else if(W===2){let T=32-(F>>4)&31,E=(m[M]|m[M+1]<<8|m[M+2]<<16|m[M+3]<<24)>>>0;for(let S=0;S<b;S++){let O=(f[S]|f[b+S]<<8|f[2*b+S]<<16|f[3*b+S]<<24)>>>0;O=((O<<T|O>>>(32-T&31))^E)>>>0,E=O;let k=(x+S)*r+M;i[k]=O&255,i[k+1]=O>>>8&255,i[k+2]=O>>>16&255,i[k+3]=O>>>24}}else throw Te(`invalid ATTRIBUTES channel ${F}`)}m.set(i.subarray((x+b-1)*r,(x+b)*r)),x+=b}if(n-g!==u)throw Te("ATTRIBUTES trailing data")}var Fa=224,Va=208;function Ua(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,n=7;for(let s=0;s<4;s++){let l=e[t.pos++]??0;if(i=(i|(l&127)<<n)>>>0,n+=7,l<128)break}return i>>>0}function Kr(e,t,r){let i=Ua(e,t),n=i>>>1^-(i&1);return r+n>>>0}function uu(e,t,r){if(t%3!==0)throw Te(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw Te("truncated TRIANGLES stream");let n=e[0];if((n&240)!==Fa)throw Te(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw Te(`unsupported TRIANGLES codec version ${s}`);let l=new Uint32Array(16).fill(4294967295),o=new Uint32Array(16).fill(4294967295),a=new Uint32Array(16).fill(4294967295),u=0,h=0,m=(P,F)=>{l[u]=P,o[u]=F,u=u+1&15},c=(P,F=1)=>{a[h]=P,h=h+F&15},d=0,f=0,g=s>=1?13:15,x=1+i,b=e.byteLength-16,v=b,p={pos:x},y=0,M=(P,F,W)=>{r(y++,P),r(y++,F),r(y++,W)};for(let P=1;P<x;P++){let F=e[P];if(F<240){let W=F>>4,T=u-1-W&15,E=l[T],S=o[T],O=0,k=F&15;if(k<g){let w=a[h-1-k&15];O=k===0?d:w;let ie=k===0?1:0;d=d+ie>>>0,c(O,ie)}else{if(p.pos>b)throw Te("truncated TRIANGLES stream");O=k!==15?f+(k*2-27)>>>0:Kr(e,p,f),f=O,c(O)}m(O,S),m(E,O),M(E,S,O)}else if(F<254){let W=e[v+(F&15)],T=W>>4,E=W&15,S=d;d=d+1>>>0;let O=a[h-T&15],k=T===0?d:O,w=T===0?1:0;d=d+w>>>0;let ie=a[h-E&15],oe=E===0?d:ie,I=E===0?1:0;d=d+I>>>0,M(S,k,oe),c(S),c(k,w),c(oe,I),m(k,S),m(oe,k),m(S,oe)}else{if(p.pos>b)throw Te("truncated TRIANGLES stream");let W=e[p.pos++],T=F===254?0:15,E=W>>4,S=W&15;W===0&&(d=0);let O=0;T===0&&(O=d,d=d+1>>>0);let k;E===0?(k=d,d=d+1>>>0):k=a[h-E&15];let w;S===0?(w=d,d=d+1>>>0):w=a[h-S&15],T===15&&(f=O=Kr(e,p,f)),E===15&&(f=k=Kr(e,p,f)),S===15&&(f=w=Kr(e,p,f)),M(O,k,w),c(O),c(k,E===0||E===15?1:0),c(w,S===0||S===15?1:0),m(k,O),m(w,k),m(O,w)}}if(p.pos!==b)throw Te("TRIANGLES trailing data")}function hu(e,t,r){if(e.byteLength<1+t+4)throw Te("truncated INDICES stream");let i=e[0];if((i&240)!==Va)throw Te(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw Te(`unsupported INDICES codec version ${n}`);let s=e.byteLength-4,l=[0,0],o={pos:1};for(let a=0;a<t;a++){if(o.pos>=s)throw Te("truncated INDICES stream");let u=Ua(e,o),h=u&1;u>>>=1;let m=u>>>1^-(u&1),c=l[h]+m>>>0;l[h]=c,r(a,c)}if(o.pos!==s)throw Te("INDICES trailing data")}function Oa(e,t,r,i,n="NONE"){if(Ca(n),!Number.isInteger(t)||t<0||t>Jl||!Number.isInteger(r)||r<=0||r>256)throw Te(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>Pa)throw Te(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${Pa})`);if(t===0)return new Uint8Array(0);let l=new Uint8Array(s);if(i==="ATTRIBUTES")return lu(e,t,r,l),La(l,t,r,n),l;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw Te(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw Te(`filter ${n} is only valid for ATTRIBUTES`);let o=new DataView(l.buffer),a=r===2?(u,h)=>o.setUint16(u*2,h&65535,!0):(u,h)=>o.setUint32(u*4,h>>>0,!0);return i==="TRIANGLES"?uu(e,t,a):hu(e,t,a),l}throw Te(`unknown mode "${String(i)}"`)}function Ba(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function cu(e,t,r,i){let n=t*r;if(e.byteLength<n)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${n})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let o=[_a],a=Da(r),u=new Uint8Array(r);t>0&&u.set(e.subarray(0,r));let h=u.slice(),m=new Uint8Array(256);for(let c=0;c<t;){let d=Math.min(a,t-c),f=d+15&-16;for(let g=0;g<r;g++){m.fill(0);let x=u[g];for(let p=0;p<d;p++){let y=e[(c+p)*r+g];m[p]=ru(y-x&255),x=y}u[g]=x;let b=f/16,v=o.length;for(let p=0;p<b+3>>2;p++)o.push(0);for(let p=0;p<b;p++){let y=m.subarray(p*16,p*16+16);if(!y.every(M=>M===0)){o[v+(p>>2)]|=3<<(p&3)*2;for(let M of y)o.push(M)}}}c+=d}for(let c=r;c<Ia;c++)o.push(0);for(let c=0;c<r;c++)o.push(h[c]);return new Uint8Array(o)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let s=new DataView(e.buffer,e.byteOffset,e.byteLength),l=o=>r===2?s.getUint16(o*2,!0):s.getUint32(o*4,!0);if(i==="INDICES"){let o=[Va|1],a=0;for(let u=0;u<t;u++){let h=l(u),m=h-a|0;a=h,Ba(o,Na(m)<<1>>>0)}return o.push(0,0,0,0),new Uint8Array(o)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let o=t/3,a=[Fa|1];for(let h=0;h<o;h++)a.push(255);let u=0;for(let h=0;h<o;h++){a.push(255);for(let m=0;m<3;m++){let c=l(h*3+m);Ba(a,Na(c-u|0)),u=c}}for(let h=0;h<16;h++)a.push(0);return new Uint8Array(a)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function nn(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let n=new Uint8Array(r.bin),s=[],l=0;for(let m=0;m<i.bufferViews.length;m++){let c=i.bufferViews[m],d=c?.extensions?.KHR_meshopt_compression,f=d??c?.extensions?.EXT_meshopt_compression;if(!f||typeof f!="object")continue;let g=d?"KHR_meshopt_compression":"EXT_meshopt_compression",x=Number(f.count),b=Number(f.byteStride),v=Number(f.byteOffset??0),p=Number(f.byteLength??0),y=f.mode||"ATTRIBUTES",M=f.filter||"NONE";if(M==="COLOR"&&!d)throw Te(`bufferView ${m} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(f.buffer??0)!==0)throw new Error(`${g}: bufferView ${m} references buffer ${String(f.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(v)||v<0||!Number.isInteger(p)||p<0||v+p>n.byteLength)throw new Error(`${g}: bufferView ${m} compressed range [${v}, ${v+p}] out of bounds (${n.byteLength})`);let P=x*b;if(l+=P,l>Ea)throw Te(`total decompressed size (${l}) exceeds MAX_MESHOPT_TOTAL_BYTES (${Ea})`);let F=n.subarray(v,v+p),W=Oa(F,x,b,y,M);s.push({index:m,bytes:W,ext:f})}if(s.length===0)return;let o=n.byteLength+3&-4,a=0;for(let m of s)a+=m.bytes.byteLength+3&-4;let u=new Uint8Array(o+a);u.set(n,0);let h=o;for(let m of s){u.set(m.bytes,h);let c=i.bufferViews[m.index];c.buffer=0,c.byteOffset=h,c.byteLength=m.bytes.byteLength,c._decoded=m.bytes,m.ext.mode==="ATTRIBUTES"&&c.byteStride===void 0&&(c.byteStride=Number(m.ext.byteStride)),c.extensions&&(delete c.extensions.EXT_meshopt_compression,delete c.extensions.KHR_meshopt_compression),h+=m.bytes.byteLength+3&-4}r.bin=u.buffer}var sn={decodeBufferViews(e,t){nn(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};Ae().decoders.set("meshopt",sn);var za={name:"meshopt",onParseGLB(e){Ae().decoders.set("meshopt",sn),nn(e)}},mu=`#version 300 es
373
424
  layout(location=0) in vec3 aPosition;
374
425
  layout(location=1) in vec3 aNormal;
375
426
  uniform mat4 uMVP,uVP;
@@ -390,19 +441,19 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
390
441
  clipPos.xy+=pxOffset;
391
442
  clipPos.z+=1e-4*clipPos.w;
392
443
  gl_Position=clipPos;
393
- }`,xc=`#version 300 es
444
+ }`,fu=`#version 300 es
394
445
  precision highp float;
395
446
  uniform vec4 uOutlineColor;
396
447
  out vec4 fragColor;
397
448
  void main(){
398
449
  fragColor=uOutlineColor;
399
- }`,Ds=`#version 300 es
450
+ }`,$a=`#version 300 es
400
451
  out vec2 vUV;
401
452
  void main(){
402
453
  vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
403
454
  vUV=pos;
404
455
  gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
405
- }`,vc=`#version 300 es
456
+ }`,pu=`#version 300 es
406
457
  precision highp float;
407
458
  in vec2 vUV;
408
459
  uniform sampler2D uSourceTex;
@@ -425,7 +476,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
425
476
  c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
426
477
  c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
427
478
  fragColor=vec4(c,1.0);
428
- }`,Tc=`#version 300 es
479
+ }`,du=`#version 300 es
429
480
  precision highp float;
430
481
  in vec2 vUV;
431
482
  uniform sampler2D uBloomTex;
@@ -447,4 +498,4 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
447
498
  vec3 bloom=(sum/12.0)*uStrength;
448
499
  float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
449
500
  fragColor=vec4(bloom,a);
450
- }`,Or=3,Pn=new WeakMap;function Gi(t,e=[.22,.74,.97]){let n=ii(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,a=+("0x"+r[2]+r[2])/255;return[i,o,a]}if(r.length===6){let i=+("0x"+r.slice(0,2))/255,o=+("0x"+r.slice(2,4))/255,a=+("0x"+r.slice(4,6))/255;return[i,o,a]}return[e[0],e[1],e[2]]}function Fs(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),a=Math.max(0,Number(t[1])||0),u=Math.max(0,Number(t[2])||0),s=Math.max(o,a,u);if(s<=1e-6)return[0,0,0];let c=Number.isFinite(n)?Math.max(0,n):.8,l=Math.max(c*Math.max(0,r),1e-4),m=Math.max(0,Math.min(2*l,s-c+l)),f=m*m/(4*l+1e-4),p=Math.min(1,Math.max(0,Math.max(f,s-c)/Math.max(s,1e-4)))*i;return[o*p,a*p,u*p]}function Vs(t,e,n,r){let i=Number(t[0])||0,o=Number(t[1])||0,a=Math.hypot(i,o);if(a<=1e-5||e<=0||n<=0)return[0,0];let u=Math.max(1,Number(r[0])||1),s=Math.max(1,Number(r[1])||1),c=Math.max(0,n)*2*e;return[i/a*(c/u),o/a*(c/s)]}var Us=new WeakSet;function Os(t){let e=Pn.get(t);if(e){if(typeof t.isProgram!="function"||t.isProgram(e.outlineProg))return e;Pn.delete(t)}if(Us.has(t)||t.isContextLost?.())return null;let n=St(t,gc,xc,!1),r=St(t,Ds,vc,!1),i=St(t,Ds,Tc,!1);if(!n||!r||!i){for(let a of[n,r,i])a&&t.deleteProgram(a);return Us.add(t),null}let 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},Pn.set(t,e),e}function wc(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===Or&&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 a=i,u=o;for(let s=0;s<Or;s++)a=Math.max(1,a>>1),u=Math.max(1,u>>1),e.mipWidth[s]=a,e.mipHeight[s]=u,e.bloomTex[s]||(e.bloomTex[s]=t.createTexture()),t.bindTexture(3553,e.bloomTex[s]),t.texImage2D(3553,0,6408,a,u,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[s]||(e.bloomFbo[s]=t.createFramebuffer()),t.bindFramebuffer(36160,e.bloomFbo[s]),t.framebufferTexture2D(36160,36064,3553,e.bloomTex[s],0);return t.bindFramebuffer(36160,null),e.texWidth=i,e.texHeight=o,!0}function Mc(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 a=oi({strength:o,threshold:tn(e.getAttribute("bloom-threshold"),.62),radius:tn(e.getAttribute("bloom-radius"),.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=oi(i);o&&(!n||o.strength>n.strength)&&(n=o)}return n}function Ac(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,a=!1;if(n&&r!=="true"){let u=n.split(/\s+/);for(let s of u)if(s.startsWith("#"))i=s;else if(s.toLowerCase()==="pulse")a=!0;else{let c=Number(s);Number.isFinite(c)&&c>0&&(o=c)}}return Wn({color:i,thickness:o,pulse:a})}var Sc=new Set(["floor","pedestal","ground","table","grid","pad"]);function Rc(t){return t.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(e=>Sc.has(e))}function Ec(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=Wn(i);if(o)return o;let a=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",u=Ac(r,a),s=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",c=t.getSelectedMesh?.()||"";if(c)return e.name!==c?null:u||(s?Wn({color:a,thickness:3,pulse:!1}):null);if(u){let l=e.name||"";return Rc(l)?null:u}return null}var Hi={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 f of e.meshes){if(f.visible===!1)continue;let h=Ec(e,f);h&&o.push({mesh:f,trait:h})}let a=o.length>0?Os(t):null;if(a){let f=a,h=we(),p=we(),d=new Float32Array(9),y=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof t.getParameter=="function"?t.getParameter(t.VIEWPORT):null,R=Math.max(1,v?.[2]||r),b=Math.max(1,v?.[3]||i);t.useProgram(f.outlineProg),f.uOutlineViewportSize&&t.uniform2f(f.uOutlineViewportSize,R,b),f.uOutlineVP&&t.uniformMatrix4fv(f.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:w,trait:M}of o){let[P,k,I]=Gi(M.color),L=M.pulse?.8+.25*Math.sin(y*4):1;f.uOutlineColor&&t.uniform4f(f.uOutlineColor,P,k,I,1),f.uOutlineThickness&&t.uniform1f(f.uOutlineThickness,M.thickness*L),w.worldSpace===!0?h.set(w.transform):Le(h,e.modelRootMatrix,w.transform);let x=w.instanceMatrices;for(let g of w.primitives)if(!(g.pluginData?.skinning?.hasSkin||g.pluginData?.morph?.hasMorph))if(t.bindVertexArray(g.vao),x&&x.length>=16){let A=x.length>>4,N=we();for(let _=0;_<A;_++)Le(N,h,x.subarray(_*16,_*16+16)),Le(p,n,N),Ne(d,N),t.uniformMatrix4fv(f.uOutlineMVP,!1,p),t.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,d),g.indices?t.drawElements(4,g.indexCount,g.indexType,0):t.drawArrays(4,0,g.indexCount)}else Le(p,n,h),Ne(d,h),t.uniformMatrix4fv(f.uOutlineMVP,!1,p),t.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,d),g.indices?t.drawElements(4,g.indexCount,g.indexType,0):t.drawArrays(4,0,g.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 u=Mc(e);if(!u||u.strength<=0)return;let s=Os(t);if(!s||!wc(t,s,r,i)||!s.fsVao)return;t.activeTexture(33984),t.bindTexture(3553,s.sceneTex),t.copyTexSubImage2D(3553,0,0,0,0,0,r,i),t.disable(2929),t.depthMask(!1),t.disable(3042),t.useProgram(s.downProg),t.uniform1i(s.uDownSourceTex,0),t.bindVertexArray(s.fsVao);let c=s.sceneTex,l=r,m=i;for(let f=0;f<Or;f++){let h=s.mipWidth[f],p=s.mipHeight[f];t.bindFramebuffer(36160,s.bloomFbo[f]),t.viewport(0,0,h,p),t.bindTexture(3553,c),t.uniform2f(s.uDownTexelSize,1/l,1/m),t.uniform1f(s.uDownThreshold,f===0?u.threshold:0),t.drawArrays(4,0,3),c=s.bloomTex[f],l=h,m=p}t.enable(3042),typeof t.blendFuncSeparate=="function"?t.blendFuncSeparate(t.ONE,t.ONE,t.ONE,771):t.blendFunc(t.ONE,t.ONE),t.useProgram(s.upProg),t.uniform1i(s.uUpBloomTex,0),t.uniform1f(s.uUpRadius,u.radius);for(let f=Or-1;f>=1;f--){let h=f-1;t.bindFramebuffer(36160,s.bloomFbo[h]),t.viewport(0,0,s.mipWidth[h],s.mipHeight[h]),t.bindTexture(3553,s.bloomTex[f]),t.uniform2f(s.uUpTexelSize,1/s.mipWidth[f],1/s.mipHeight[f]),t.uniform1f(s.uUpStrength,.85),t.drawArrays(4,0,3)}t.bindFramebuffer(36160,null),t.viewport(0,0,r,i),t.bindTexture(3553,s.bloomTex[0]),t.uniform2f(s.uUpTexelSize,1/s.mipWidth[0],1/s.mipHeight[0]),t.uniform1f(s.uUpStrength,u.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=Pn.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);Pn.delete(t)}}};function Xi(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 Bs(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,a=Number(o.material);if(!Number.isInteger(a)||a<0)continue;let u=[];if(Array.isArray(o.variants))for(let s of o.variants){let c=Number(s);Number.isInteger(c)&&c>=0&&u.push(c)}u.length>0&&r.push({material:a,variants:u})}return r}function zs(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,a=Array.isArray(e)?e:[],u=n??null;if(!u)return r;let c=Xi(o).indexOf(u);if(c<0)return r;for(let l of a)if(l.variants.includes(c))return l.material;return r}var Wi={name:"variants",onLoadModel(t,e){let n=t.getVariantName?.();n&&t.selectVariant(n)}};var Gs=new WeakMap,$i={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=Gs.get(e);if(i||(i={lightProbe:null},Gs.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,u=o.primaryLightIntensity;if(a&&u&&Array.isArray(t.lights)){let s=t.lights.find(l=>l.type==="directional");s||(s={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},t.lights.push(s)),s.direction=[a.x,a.y,a.z];let c=Math.max(u.x,u.y,u.z,.001);s.color=[u.x/c,u.y/c,u.z/c],s.intensity=c}o.sphericalHarmonicsCoefficients&&t.gl&&Er(t.gl,o.sphericalHarmonicsCoefficients)}}}};Oe(_n);Oe(ki);Oe(Ii);Oe(Fi);Oe($i);Oe(Oi);Oe(zi);Oe(Wi);Oe(Hi);ct.registerScriptRunner(en);typeof window<"u"&&(window.ThreeLiveBundle=ji);return Ys(ji);})();
501
+ }`,Yr=3,dr=new WeakMap;function Ha(e,t=[.22,.74,.97]){let r=On(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let n=+("0x"+i[0]+i[0])/255,s=+("0x"+i[1]+i[1])/255,l=+("0x"+i[2]+i[2])/255;return[n,s,l]}if(i.length===6){let n=+("0x"+i.slice(0,2))/255,s=+("0x"+i.slice(2,4))/255,l=+("0x"+i.slice(4,6))/255;return[n,s,l]}return[t[0],t[1],t[2]]}function gu(e,t,r=.8,i=.5){let n=Number.isFinite(t)?Math.max(0,t):0;if(n<=0)return[0,0,0];let s=Math.max(0,Number(e[0])||0),l=Math.max(0,Number(e[1])||0),o=Math.max(0,Number(e[2])||0),a=Math.max(s,l,o);if(a<=1e-6)return[0,0,0];let u=Number.isFinite(r)?Math.max(0,r):.8,h=Math.max(u*Math.max(0,i),1e-4),m=Math.max(0,Math.min(2*h,a-u+h)),c=m*m/(4*h+1e-4),d=Math.min(1,Math.max(0,Math.max(c,a-u)/Math.max(a,1e-4)))*n;return[s*d,l*d,o*d]}function yu(e,t,r,i){let n=Number(e[0])||0,s=Number(e[1])||0,l=Math.hypot(n,s);if(l<=1e-5||t<=0||r<=0)return[0,0];let o=Math.max(1,Number(i[0])||1),a=Math.max(1,Number(i[1])||1),u=Math.max(0,r)*2*t;return[n/l*(u/o),s/l*(u/a)]}var Wa=new WeakSet;function Ga(e){let t=dr.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;dr.delete(e)}if(Wa.has(e)||e.isContextLost?.())return null;let r=Ft(e,mu,fu,!1),i=Ft(e,$a,pu,!1),n=Ft(e,$a,du,!1);if(!r||!i||!n){for(let l of[r,i,n])l&&e.deleteProgram(l);return Wa.add(e),null}let s=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:n,uUpBloomTex:e.getUniformLocation(n,"uBloomTex"),uUpTexelSize:e.getUniformLocation(n,"uTexelSize"),uUpRadius:e.getUniformLocation(n,"uRadius"),uUpStrength:e.getUniformLocation(n,"uStrength"),fsVao:s,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},dr.set(e,t),t}function bu(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let n=Math.max(2,r|0),s=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===Yr&&t.texWidth===n&&t.texHeight===s)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,n,s,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let l=n,o=s;for(let a=0;a<Yr;a++)l=Math.max(1,l>>1),o=Math.max(1,o>>1),t.mipWidth[a]=l,t.mipHeight[a]=o,t.bloomTex[a]||(t.bloomTex[a]=e.createTexture()),e.bindTexture(3553,t.bloomTex[a]),e.texImage2D(3553,0,6408,l,o,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[a]||(t.bloomFbo[a]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[a]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[a],0);return e.bindFramebuffer(36160,null),t.texWidth=n,t.texHeight=s,!0}function xu(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let n=i.trim().toLowerCase();if(n==="false"||n==="0"||n==="none")return null;let s=n===""||n==="true"?.35:Number(n);if(!Number.isFinite(s)||s<=0)return null;let l=Bn({strength:s,threshold:Br(t.getAttribute("bloom-threshold"),.62),radius:Br(t.getAttribute("bloom-radius"),.75)});if(l)return l}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let n=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,s=Bn(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function vu(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let n=t,s=3.5,l=!1;if(r&&i!=="true"){let o=r.split(/\s+/);for(let a of o)if(a.startsWith("#"))n=a;else if(a.toLowerCase()==="pulse")l=!0;else{let u=Number(a);Number.isFinite(u)&&u>0&&(s=u)}}return Mi({color:n,thickness:s,pulse:l})}var Mu=new Set(["floor","pedestal","ground","table","grid","pad"]);function wu(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Mu.has(t))}function Au(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let h=i.trim().toLowerCase();if(h==="false"||h==="0"||h==="none")return null}let n=t?.extras?.xr?.outline??t?.userData?.xr?.outline,s=Mi(n);if(s)return s;let l=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",o=vu(i,l),a=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",u=e.getSelectedMesh?.()||"";if(u)return t.name!==u?null:o||(a?Mi({color:l,thickness:3,pulse:!1}):null);if(o){let h=t.name||"";return wu(h)?null:o}return null}var ja={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),n=Math.max(1,t.canvas?.height||150),s=[];for(let c of t.meshes){if(c.visible===!1)continue;let d=Au(t,c);d&&s.push({mesh:c,trait:d})}let l=s.length>0?Ga(e):null;if(l){let c=l,d=Pe(),f=Pe(),g=new Float32Array(9),x=(typeof performance<"u"?performance.now():Date.now())*.001,b=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,v=Math.max(1,b?.[2]||i),p=Math.max(1,b?.[3]||n);e.useProgram(c.outlineProg),c.uOutlineViewportSize&&e.uniform2f(c.uOutlineViewportSize,v,p),c.uOutlineVP&&e.uniformMatrix4fv(c.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:y,trait:M}of s){let[P,F,W]=Ha(M.color),T=M.pulse?.8+.25*Math.sin(x*4):1;c.uOutlineColor&&e.uniform4f(c.uOutlineColor,P,F,W,1),c.uOutlineThickness&&e.uniform1f(c.uOutlineThickness,M.thickness*T),y.worldSpace===!0?d.set(y.transform):ke(d,t.modelRootMatrix,y.transform);let E=y.instanceMatrices;for(let S of y.primitives)if(!(S.pluginData?.skinning?.hasSkin||S.pluginData?.morph?.hasMorph))if(e.bindVertexArray(S.vao),E&&E.length>=16){let O=E.length>>4,k=Pe();for(let w=0;w<O;w++)ke(k,d,E.subarray(w*16,w*16+16)),ke(f,r,k),Ke(g,k),e.uniformMatrix4fv(c.uOutlineMVP,!1,f),e.uniformMatrix3fv(c.uOutlineNormalMatrix,!1,g),S.indices?e.drawElements(4,S.indexCount,S.indexType,0):e.drawArrays(4,0,S.indexCount)}else ke(f,r,d),Ke(g,d),e.uniformMatrix4fv(c.uOutlineMVP,!1,f),e.uniformMatrix3fv(c.uOutlineNormalMatrix,!1,g),S.indices?e.drawElements(4,S.indexCount,S.indexType,0):e.drawArrays(4,0,S.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let o=xu(t);if(!o||o.strength<=0)return;let a=Ga(e);if(!a||!bu(e,a,i,n)||!a.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,a.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,n),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(a.downProg),e.uniform1i(a.uDownSourceTex,0),e.bindVertexArray(a.fsVao);let u=a.sceneTex,h=i,m=n;for(let c=0;c<Yr;c++){let d=a.mipWidth[c],f=a.mipHeight[c];e.bindFramebuffer(36160,a.bloomFbo[c]),e.viewport(0,0,d,f),e.bindTexture(3553,u),e.uniform2f(a.uDownTexelSize,1/h,1/m),e.uniform1f(a.uDownThreshold,c===0?o.threshold:0),e.drawArrays(4,0,3),u=a.bloomTex[c],h=d,m=f}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(a.upProg),e.uniform1i(a.uUpBloomTex,0),e.uniform1f(a.uUpRadius,o.radius);for(let c=Yr-1;c>=1;c--){let d=c-1;e.bindFramebuffer(36160,a.bloomFbo[d]),e.viewport(0,0,a.mipWidth[d],a.mipHeight[d]),e.bindTexture(3553,a.bloomTex[c]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[c],1/a.mipHeight[c]),e.uniform1f(a.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,n),e.bindTexture(3553,a.bloomTex[0]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[0],1/a.mipHeight[0]),e.uniform1f(a.uUpStrength,o.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=dr.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);dr.delete(e)}}};function qa(e){let t=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(t))return[];let r=[];for(let i=0;i<t.length&&r.length<256;i++){let n=t[i]?.name;r.push(typeof n=="string"&&n.length>0?n:`Variant_${i}`)}return r}function Tu(e){let t=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let n=i,s=Number(n.material);if(!Number.isInteger(s)||s<0)continue;let l=[];if(Array.isArray(n.variants))for(let o of n.variants){let a=Number(o);Number.isInteger(a)&&a>=0&&l.push(a)}l.length>0&&r.push({material:s,variants:l})}return r}function Su(e,t,r,i=0){let n=e;if(n&&typeof n.selectVariant=="function"&&!Array.isArray(t))return n.selectVariant(typeof t=="string"?t:null);let s=e,l=Array.isArray(t)?t:[],o=r??null;if(!o)return i;let a=qa(s).indexOf(o);if(a<0)return i;for(let u of l)if(u.variants.includes(a))return u.material;return i}var Xa={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},Ka=new WeakMap,Ya={name:"webxr-suite",onConfigureXRSessionInit(e,t){let r=new Set(t.optionalFeatures||[]);r.add("hit-test"),r.add("light-estimation");let i=e?.querySelector?.('[slot="ar-overlay"]')||null;i&&(r.add("dom-overlay"),t.domOverlay={root:i},i.addEventListener?.("beforexrselect",n=>{n.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let n=Ka.get(t);if(n||(n={lightProbe:null},Ka.set(t,n),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(s=>{n&&s&&(n.lightProbe=s)}).catch(()=>{})),n.lightProbe&&typeof r.getLightEstimate=="function"){let s=r.getLightEstimate(n.lightProbe);if(s){let l=s.primaryLightDirection,o=s.primaryLightIntensity;if(l&&o&&Array.isArray(e.lights)){let a=e.lights.find(h=>h.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(a)),a.direction=[l.x,l.y,l.z];let u=Math.max(o.x,o.y,o.z,.001);a.color=[o.x/u,o.y/u,o.z/u],a.intensity=u}s.sphericalHarmonicsCoefficients&&e.gl&&ca(e.gl,s.sphericalHarmonicsCoefficients)}}}};return Ge(Xi),Ge(da),Ge(pa),Ge(Ra),Ge(Ya),Ge(Sa),Ge(za),Ge(Xa),Ge(ja),Ge(vn),Ht.registerScriptRunner(kr),typeof window<"u"&&(window.ThreeLiveBundle=Qr),yo(Qr)})();