three-live 1.2.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +22 -0
  3. package/dist/three-author-engine.js +28 -26
  4. package/dist/three-author.cjs +29 -27
  5. package/dist/three-author.d.ts +22 -0
  6. package/dist/three-author.js +29 -27
  7. package/dist/three-convert.cjs +21 -19
  8. package/dist/three-convert.d.ts +22 -0
  9. package/dist/three-convert.js +21 -19
  10. package/dist/three-live-animation.cjs +4 -4
  11. package/dist/three-live-animation.d.ts +22 -0
  12. package/dist/three-live-animation.js +4 -4
  13. package/dist/three-live-animation.min.js +4 -4
  14. package/dist/three-live-cad.cjs +2 -2
  15. package/dist/three-live-cad.d.ts +22 -0
  16. package/dist/three-live-cad.js +2 -2
  17. package/dist/three-live-cad.min.js +2 -2
  18. package/dist/three-live-element.cjs +5 -3
  19. package/dist/three-live-element.d.ts +22 -0
  20. package/dist/three-live-element.js +5 -3
  21. package/dist/three-live-full.cjs +48 -46
  22. package/dist/three-live-full.js +47 -45
  23. package/dist/three-live-full.min.js +48 -46
  24. package/dist/three-live-studio.cjs +10 -10
  25. package/dist/three-live-studio.d.ts +22 -0
  26. package/dist/three-live-studio.js +10 -10
  27. package/dist/three-live-studio.min.js +10 -10
  28. package/dist/three-live-viewer.cjs +5 -3
  29. package/dist/three-live-viewer.d.ts +22 -0
  30. package/dist/three-live-viewer.js +5 -3
  31. package/dist/three-live-viewer.min.js +5 -3
  32. package/dist/three-live.cjs +23 -21
  33. package/dist/three-live.js +25 -23
  34. package/dist/three-live.min.js +23 -21
  35. package/dist/three-view.cjs +8 -6
  36. package/dist/three-view.d.ts +22 -0
  37. package/dist/three-view.js +8 -6
  38. package/dist/three-xr.cjs +24 -22
  39. package/dist/three-xr.d.ts +22 -0
  40. package/dist/three-xr.js +24 -22
  41. package/package.json +1 -1
@@ -14,9 +14,10 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- var Ws=Object.defineProperty;var $s=(e,t)=>{for(var n in t)Ws(e,n,{get:t[n],enumerable:!0})};var $i={};$s($i,{AmbientLight:()=>xn,BoxGeometry:()=>hn,BufferAttribute:()=>Se,BufferGeometry:()=>Ye,Camera:()=>Tn,CapsuleGeometry:()=>gr,CircleGeometry:()=>vr,Clock:()=>mr,Color:()=>et,ConeGeometry:()=>er,CylinderGeometry:()=>Et,DirectionalLight:()=>ur,DodecahedronGeometry:()=>br,Euler:()=>mn,Float32BufferAttribute:()=>Yn,Group:()=>cr,HemisphereLight:()=>Mn,IKSolver:()=>ho,IcosahedronGeometry:()=>hr,InstancedMesh:()=>gn,InteractivityVM:()=>In,Light:()=>Dt,MAX_BSP_DEPTH:()=>ao,MAX_CSG_TRIANGLES:()=>so,MAX_INSTANCES_PER_MESH:()=>yn,MAX_SHAPE_POINTS:()=>uo,MAX_TEXT_GEOMETRY_CHARS:()=>co,Material:()=>at,MathUtils:()=>Xo,Matrix3:()=>Kn,Matrix4:()=>Ct,Mesh:()=>kt,MeshBasicMaterial:()=>ir,MeshLambertMaterial:()=>or,MeshPhongMaterial:()=>sr,MeshPhysicalMaterial:()=>ar,MeshStandardMaterial:()=>Pt,Object3D:()=>tt,OctahedronGeometry:()=>pr,PerspectiveCamera:()=>lr,PlaneGeometry:()=>Jn,PointLight:()=>vn,PolyhedronFallbackGeometry:()=>Nt,Quaternion:()=>dn,RawShaderMaterial:()=>ts,RectAreaLight:()=>ns,RingGeometry:()=>xr,Scene:()=>wn,SceneQuotaValidator:()=>st,ShaderMaterial:()=>An,SphereGeometry:()=>pn,SpotLight:()=>Tr,THREE:()=>Ut,TetrahedronGeometry:()=>yr,Texture:()=>bn,TextureLoader:()=>rr,ThreeLiveElement:()=>ct,ThreeView:()=>Xe,TorusGeometry:()=>tr,TorusKnotGeometry:()=>nr,Uint16BufferAttribute:()=>Zn,Uint32BufferAttribute:()=>Qn,Vector2:()=>jn,Vector3:()=>Fe,Vector4:()=>qn,WebGLRenderer:()=>fr,activateAR:()=>Rr,applyMeshoptFilter:()=>Fi,authorScriptRunner:()=>Jt,buildSandboxWorkerSource:()=>ui,cadPlugin:()=>Vr,clearAuthorWarnings:()=>es,computeOutlineClipOffset:()=>Vs,contactShadowPlugin:()=>En,createUSDZBlob:()=>Zt,crossFadeTo:()=>pi,decodeMeshoptBuffer:()=>Oi,decodeMeshoptGLB:()=>Nr,encodeMeshoptBuffer:()=>Ds,environmentMapPlugin:()=>_i,evaluateKawaseBloom:()=>Os,evaluateToneMapping:()=>So,exportSceneToCanvas3D:()=>si,exportSceneToGLB:()=>ai,exportSceneToUSDZ:()=>$o,extractMaterialVariants:()=>Hi,extractPrimitiveVariantMappings:()=>Bs,generateUSDZ:()=>cn,getARCapabilities:()=>Sr,getAllowClientScripts:()=>Ko,getAuthorWarnings:()=>Jo,getBestARMode:()=>ls,getEnvironmentSH:()=>ds,getInteractivityVM:()=>Pr,getSandboxEngineSrc:()=>ci,getSandboxIframeSrc:()=>qo,glbToUSDZ:()=>an,hotspotPlugin:()=>Ci,ikPlugin:()=>Kr,installCadExtension:()=>Fn,interactivityPlugin:()=>Ni,isAllowedSandboxEngineUrl:()=>_t,isQuickLookSupported:()=>Ai,isSceneViewerSupported:()=>Mi,isWebXRSupported:()=>Si,keyframeAnimationPlugin:()=>bi,materialsPlugin:()=>Ui,meshoptDecoder:()=>Ur,meshoptPlugin:()=>Vi,morphPlugin:()=>yi,noopProxy:()=>ln,parseAnimations:()=>hi,parseHexRgb:()=>zi,parseSafeGltfPointer:()=>_n,postprocessingPlugin:()=>Gi,quatFromUnitVectors:()=>Bn,registerMaterialShader:()=>Ts,sampleChannel:()=>tn,sceneToCanvas3D:()=>Kt,sceneToGLB:()=>sn,sceneToUSDZ:()=>Yt,selectMaterialVariant:()=>zs,sendInteractivityEvent:()=>Di,setAllowClientScripts:()=>Ia,setEnvironmentSH:()=>Er,setMorphTargetWeight:()=>ss,setSandboxEngineSrc:()=>Sa,setSandboxIframeSrc:()=>Ea,skinningPlugin:()=>xi,solveFABRIK:()=>jr,solveTwoBoneIK:()=>$r,threeAuthorPlugin:()=>fn,threeMicroPlugin:()=>Oa,toGLBData:()=>ht,toTrustedWorkerScriptURL:()=>jo,validateSandboxWorkerMessage:()=>li,variantsPlugin:()=>Xi,warnUnsupported:()=>Ze,webxrPlugin:()=>Wi});function oo(e,t,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,A)=>a.push({id:b,type:w,value:A})-1,d=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 A of w)A?.op&&c(A.op);Array.isArray(b.variables)&&a.push(...b.variables);for(let A of b.events||[])A?.id&&l(A.id);for(let A of b.nodes){if(!A||typeof A!="object")continue;let P=A.op||(typeof A.declaration=="number"?w[A.declaration]?.op:"");o.push(P?{...A,declaration:c(P)}:{...A})}}}let h=(b,w,A="translation")=>A==="baseColorFactor"||A==="metallicFactor"||A==="roughnessFactor"?`/materials/${Math.max(0,w)}/pbrMetallicRoughness/${A}`:A==="emissiveFactor"||A==="alphaCutoff"?`/materials/${Math.max(0,w)}/${A}`:A==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${A}`,y=new Map;e.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=e[b];return(typeof w?.mesh=="number"?t[w.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<e.length;b++){let w=e[b],A=w?.extras?.interactivity;if(!A||typeof A!="object")continue;let P=(typeof w.mesh=="number"?t[w.mesh]?.primitives?.[0]?.material:0)??0,k=I=>{let x=Array.isArray(I)?I:[I],g=[];for(let D=0;D<x.length;D++){let _=x[D];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}_${D}`,"bool",!1),H=m("variable/get",{configuration:{variable:re}}),se=m("math/not",{values:{a:d(H)}}),ae=m("variable/set",{configuration:{variable:re},values:{value:d(se)}}),N=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:d(H)},flows:{true:{node:N},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:h(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:h(v(_,b),R(v(_,b)),_.property)},values:{value:{value:_.value}}}))}else if(O==="toggleVisibility"){let q=v(_,b),oe=f(`__vis_${q}_${D}`,"bool",!0),ne=m("variable/get",{configuration:{variable:oe}}),re=m("math/not",{values:{a:d(ne)}}),H=m("variable/set",{configuration:{variable:oe},values:{value:d(re)}});o[H].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${q}/extensions/KHR_node_visibility/visible`},values:{value:d(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}_${D}`,"int",0),re=m("variable/get",{configuration:{variable:ne}}),H=m("math/add",{values:{a:d(re),b:{value:1}}}),se=m("math/rem",{values:{a:d(H),b:{value:_.colors.length}}}),ae=m("variable/set",{configuration:{variable:ne},values:{value:d(se)}}),N={};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];N[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:d(re)},flows:N})}},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 S={};return g.forEach((D,_)=>{S[String(_)]={node:D}}),m("flow/sequence",{flows:S})},L=(I,x,g)=>{let S=k(x);S!==null&&m(I,{...g?{configuration:g}:{},flows:{out:{node:S}}})};if(A.onSelect&&L("pointer/onSelect",A.onSelect,{nodeIndex:b}),A.onHoverIn&&L("pointer/onHoverIn",A.onHoverIn,{nodeIndex:b}),A.onHoverOut&&L("pointer/onHoverOut",A.onHoverOut,{nodeIndex:b}),A.onStart&&L("event/onStart",A.onStart),A.onReceive&&typeof A.onReceive=="object")for(let[I,x]of Object.entries(A.onReceive))L("event/receive",x,{event:l(I)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:a,events:u}],graph:0}:null}var Pn='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).',kn="Security Error: client-side scripts require allow-client-scripts opt-in.";var Dn="__THREE_LIVE_REGISTRY__";function ve(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Dn]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Dn,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Dn]=t}}return e[Dn]}var Ue=ve().plugins;function Nn(e){let t=ve();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function Oe(e){let t=ve().plugins;t.some(n=>n.name===e.name)||t.push(e),e.onRegister?.()}function Un(){return ve().plugins}var so=8192,ao=2048,co=128,uo=4096;function Fn(e,t){if(!e||!e.BufferGeometry)return null;let n=e.Vector2,r=e.Vector3,i=e.Quaternion,o=e.Matrix4,a=e.Matrix3,u=e.Color,s=e.BufferAttribute,c=e.BufferGeometry,l=e.Material,m=e.MeshStandardMaterial,f=e.Mesh,d=8192,p=2048,h=128,y=4096,v=(T,M)=>{let C=T==null?NaN:Number(T);return Number.isFinite(C)?C:M};class R{constructor(M){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(M)&&M.length>0&&this.fromPoints(M)}fromPoints(M){if(!M.length)return this;this.moveTo(M[0].x,M[0].y);for(let C=1;C<M.length;C++)this.lineTo(M[C].x,M[C].y);return this}moveTo(M,C){let B=Number(M)||0,X=Number(C)||0;return this.currentPoint.set(B,X),this.segments.push({type:"move",pts:[B,X]}),this}lineTo(M,C){let B=Number(M)||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(M,C,B,X){let W=this.currentPoint.x,$=this.currentPoint.y,Y=Number(M)||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,$,Y,Z,j,te]}),this}bezierCurveTo(M,C,B,X,W,$){let Y=this.currentPoint.x,Z=this.currentPoint.y,j=Number(M)||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:[Y,Z]}),this.currentPoint.set(ue,fe),this.segments.push({type:"cubic",pts:[Y,Z,j,te,ee,J,ue,fe]}),this}absarc(M,C,B,X,W,$=!1){return this.absellipse(M,C,B,B,X,W,$,0)}arc(M,C,B,X,W,$=!1){return this.absarc(this.currentPoint.x+(Number(M)||0),this.currentPoint.y+(Number(C)||0),B,X,W,$)}absellipse(M,C,B,X,W,$,Y=!1,Z=0){let j=Number(M)||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=Y?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(M,C,B,X,W,$,Y=!1,Z=0){return this.absellipse(this.currentPoint.x+(Number(M)||0),this.currentPoint.y+(Number(C)||0),B,X,W,$,Y,Z)}closePath(){if(this.segments.length>0){let M=this.segments[0],C=0,B=0;if(M.type==="arc"){let X=M.pts[0],W=M.pts[1],$=M.pts[2],Y=M.pts[3],Z=M.pts[4],j=M.pts[7],te=Math.cos(j),ee=Math.sin(j),J=$*Math.cos(Z),ue=Y*Math.sin(Z);C=X+J*te-ue*ee,B=W+J*ee+ue*te}else C=M.pts[0],B=M.pts[1];Math.hypot(this.currentPoint.x-C,this.currentPoint.y-B)>1e-6&&this.lineTo(C,B)}return this}getPoints(M=12){let C=Math.max(1,Math.min(128,Math.floor(Number(M)||12))),B=[],X=(W,$)=>{if(B.length>0){let Y=B[B.length-1];if(Math.hypot(Y.x-W,Y.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 Y=$[0],Z=$[1],j=$[2],te=$[3],ee=$[4],J=$[5];X(Y,Z);for(let ue=1;ue<=C;ue++){let fe=ue/C,pe=1-fe;X(pe*pe*Y+2*pe*fe*j+fe*fe*ee,pe*pe*Z+2*pe*fe*te+fe*fe*J)}}else if(W.type==="cubic"){let Y=$[0],Z=$[1],j=$[2],te=$[3],ee=$[4],J=$[5],ue=$[6],fe=$[7];X(Y,Z);for(let pe=1;pe<=C;pe++){let me=pe/C,ce=1-me,be=ce*ce,xe=me*me;X(be*ce*Y+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 Y=$[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 Ee=0;Ee<=ye;Ee++){let Ae=Ee/ye,_e=ee+Ae*me,Ce=j*Math.cos(_e),ke=te*Math.sin(_e);X(Y+Ce*be-ke*xe,Z+Ce*xe+ke*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(M=12){return this.getPoints(M)}}class b extends R{constructor(M){super(M),this.holes=[]}extractPoints(M=12){return{shape:this.getPoints(M),holes:this.holes.map(C=>C.getPoints(M))}}}function w(T){let M=0,C=T.length;for(let B=0,X=C-1;B<C;X=B++)M+=T[X].x*T[B].y-T[B].x*T[X].y;return M*.5}function A(T,M,C,B,X,W,$,Y){let Z=$-C,j=Y-B,te=X-C,ee=W-B,J=T-C,ue=M-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,Ee=(ce*me-pe*be)*ye,Ae=(fe*be-pe*me)*ye;return Ee>=-1e-7&&Ae>=-1e-7&&Ee+Ae<=1+1e-7}function P(T,M){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 M){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),Y=(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],Ee=$(be,ye,j)>=0,Ae=$(xe,be,j)>=0;if(($(xe,be,ye)>=0?Ee&&Ae:Ee||Ae)&&!Y(j,be,J)&&!W.some(Ce=>Y(j,be,Ce.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,M){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,Y=B[(W+$-1)%$],Z=B[W%$],j=B[(W+1)%$],te=M[Y],ee=M[Z],J=M[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===Y||me===Z||me===j)continue;let ce=M[me];if(A(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([Y,Z,j]),B.splice(W%$,1),W=Math.max(0,W%$-1);continue}}W++,W>=$*2&&(C.push([Y,Z,j]),B.splice((W-1)%$,1),W=0)}return C}function L(T,M){let C=T instanceof b?T.extractPoints(M):{shape:T.getPoints(M),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 I extends c{constructor(M=new b,C=12){super();let B=Array.isArray(M)?M:[M],X=[],W=[],$=[],Y=[];for(let Z of B){if(!(Z instanceof R))continue;let j=L(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,Ee,Ae]of J)Y.push(ue+ye,ue+Ee,ue+Ae)}this.setAttribute("position",new s(x(X),3)),this.setAttribute("normal",new s(x(W),3)),this.setAttribute("uv",new s(x($),2)),this.setIndex(Y)}}function x(T){let M=T.length,C=new Float32Array(M);for(let B=0;B<M;B++)C[B]=T[B];return C}function g(T){let M=T.length,C=[];for(let B=0;B<M;B++){let X=T[(B+M-1)%M],W=T[B],$=T[(B+1)%M],Y=W.x-X.x,Z=W.y-X.y,j=Math.hypot(Y,Z)||1;Y/=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=-Y,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 S extends c{constructor(M=new b,C={}){super();let B=Array.isArray(M)?M:[M],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)))),Y=!!(C.bevelEnabled??!1),Z=Y?Math.max(0,v(C.bevelThickness,.06)):0,j=Y?Math.max(0,v(C.bevelSize,Z*.8)):0,te=Y?v(C.bevelOffset,0):0,ee=Y?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=L(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 Ie=ge.slice();w(Ie)>0&&Ie.reverse(),xe.push(Ie)}let{mergedIndices:ye,allVertices:Ee}=P(be,xe),Ae=k(ye,Ee),_e=[be,...xe],Ce=[];for(let ge of _e){let Ie=g(ge);for(let Pe of Ie)Ce.push(Pe)}let ke=1/0,He=1/0,Ge=-1/0,Ke=-1/0;for(let ge of Ee)ge.x<ke&&(ke=ge.x),ge.y<He&&(He=ge.y),ge.x>Ge&&(Ge=ge.x),ge.y>Ke&&(Ke=ge.y);let We=Math.max(1e-6,Ge-ke),rt=Math.max(1e-6,Ke-He),Vt=-Z,Bt=W+Z,gt=J.length/3;for(let ge=0;ge<Ee.length;ge++){let Ie=Ee[ge],Pe=Ce[ge]??new n(0,0),Ve=Ie.x+Pe.x*te,Be=Ie.y+Pe.y*te;J.push(Ve,Be,Vt),ue.push(0,0,-1),fe.push((Ve-ke)/We,(Be-He)/rt)}for(let[ge,Ie,Pe]of Ae)pe.push(gt+ge,gt+Pe,gt+Ie);let xt=J.length/3;for(let ge=0;ge<Ee.length;ge++){let Ie=Ee[ge],Pe=Ce[ge]??new n(0,0),Ve=Ie.x+Pe.x*te,Be=Ie.y+Pe.y*te;J.push(Ve,Be,Bt),ue.push(0,0,1),fe.push((Ve-ke)/We,(Be-He)/rt)}for(let[ge,Ie,Pe]of Ae)pe.push(xt+ge,xt+Ie,xt+Pe);let je=[];if(Y&&ee>0)for(let ge=0;ge<ee;ge++){let Pe=ge/ee*Math.PI/2;je.push({z:-Z*Math.cos(Pe),expand:te+j*Math.sin(Pe)})}for(let ge=0;ge<=$;ge++){let Ie=ge/$;je.push({z:Ie*W,expand:te+j})}if(Y&&ee>0)for(let ge=1;ge<=ee;ge++){let Pe=ge/ee*Math.PI/2;je.push({z:W+Z*Math.sin(Pe),expand:te+j*Math.cos(Pe)})}let it=0;for(let ge of _e){let Ie=ge.length;for(let Pe=0;Pe<je.length-1;Pe++){let Ve=je[Pe],Be=je[Pe+1];for(let qe=0;qe<Ie;qe++){let ft=(qe+1)%Ie,vt=ge[qe],Tt=ge[ft],wt=Ce[it+qe],At=Ce[it+ft],Mt=vt.x+wt.x*Ve.expand,St=vt.y+wt.y*Ve.expand,It=Tt.x+At.x*Ve.expand,mt=Tt.y+At.y*Ve.expand,Hs=Tt.x+At.x*Be.expand,Xs=Tt.y+At.y*Be.expand,ji=vt.x+wt.x*Be.expand,qi=vt.y+wt.y*Be.expand,Ki=It-Mt,Yi=mt-St,Zi=0,Qi=ji-Mt,Ji=qi-St,eo=Be.z-Ve.z,zt=Yi*eo-Zi*Ji,Gt=Zi*Qi-Ki*eo,Ht=Ki*Ji-Yi*Qi,Or=Math.hypot(zt,Gt,Ht)||1;zt/=Or,Gt/=Or,Ht/=Or;let Xt=J.length/3;J.push(Mt,St,Ve.z,It,mt,Ve.z,Hs,Xs,Be.z,ji,qi,Be.z),ue.push(zt,Gt,Ht,zt,Gt,Ht,zt,Gt,Ht,zt,Gt,Ht);let to=qe/Ie,no=(qe+1)/Ie,ro=Pe/(je.length-1),io=(Pe+1)/(je.length-1);fe.push(to,ro,no,ro,no,io,to,io),pe.push(Xt,Xt+1,Xt+2,Xt,Xt+2,Xt+3)}}it+=Ie}}this.setAttribute("position",new s(x(J),3)),this.setAttribute("normal",new s(x(ue),3)),this.setAttribute("uv",new s(x(fe),2)),this.setIndex(pe)}}function D(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,M,C){let B=T.nx+(M.nx-T.nx)*C,X=T.ny+(M.ny-T.ny)*C,W=T.nz+(M.nz-T.nz)*C,$=Math.hypot(B,X,W)||1;return{x:T.x+(M.x-T.x)*C,y:T.y+(M.y-T.y)*C,z:T.z+(M.z-T.z)*C,nx:B/$,ny:X/$,nz:W/$,u:T.u+(M.u-T.u)*C,v:T.v+(M.v-T.v)*C}}function Q(T){if(T.length<3)return null;let M=T[0],C=T[1],B=T[2],X=C.x-M.x,W=C.y-M.y,$=C.z-M.z,Y=B.x-M.x,Z=B.y-M.y,j=B.z-M.z,te=W*j-$*Z,ee=$*Y-X*j,J=X*Z-W*Y,ue=Math.hypot(te,ee,J);if(ue<1e-9)return null;te/=ue,ee/=ue,J/=ue;let fe=te*M.x+ee*M.y+J*M.z;return{vertices:T,nx:te,ny:ee,nz:J,w:fe}}function q(T){T.vertices.reverse();for(let M=0;M<T.vertices.length;M++)T.vertices[M]=_(T.vertices[M]);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,M,C,B,X,W,$,Y,Z){let j=0,te=[];for(let ee=0;ee<X.vertices.length;ee++){let J=X.vertices[ee],ue=T*J.x+M*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+M*X.ny+C*X.nz>0?W.push(X):$.push(X);break}case re:Y.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],Ee=te[xe],Ae=X.vertices[be],_e=X.vertices[xe];if(ye!==H&&ee.push(Ae),ye!==re&&J.push(ye!==H?D(Ae):Ae),(ye|Ee)===se){let Ce=_e.x-Ae.x,ke=_e.y-Ae.y,He=_e.z-Ae.z,Ge=T*Ce+M*ke+C*He,Ke=Math.abs(Ge)>1e-12?(B-(T*Ae.x+M*Ae.y+C*Ae.z))/Ge:.5,We=O(Ae,_e,Math.max(0,Math.min(1,Ke)));ee.push(We),J.push(D(We))}}let{nx:fe,ny:pe,nz:me,w:ce}=X;ee.length>=3&&Y.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 N{constructor(M,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,M&&M.length>0&&this.build(M,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 M=this.front;this.front=this.back,this.back=M}clipPolygons(M,C=0){if(!this.hasPlane||M.length===0)return M.slice();if(C>=p)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${p})`);let B=[],X=[];for(let W=0;W<M.length;W++)ae(this.nx,this.ny,this.nz,this.w,M[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(M,C=0){this.polygons.length>0&&(this.polygons=M.clipPolygons(this.polygons,0)),C<p&&(this.front&&this.front.clipTo(M,C+1),this.back&&this.back.clipTo(M,C+1))}allPolygons(M=[]){for(let C=0;C<this.polygons.length;C++)M.push(this.polygons[C]);return this.front&&this.front.allPolygons(M),this.back&&this.back.allPolygons(M),M}build(M,C=0){if(!M.length)return;if(!this.hasPlane){let W=M[M.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<M.length;W++)ae(this.nx,this.ny,this.nz,this.w,M[W],this.polygons,this.polygons,B,X);B.length>0&&(this.front||(this.front=new N),this.front.build(B,C+1)),X.length>0&&(this.back||(this.back=new N),this.back.build(X,C+1))}}function G(T,M){if(!M&&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($>d)throw new RangeError(`SecurityError: CSG input triangle count (${$}) exceeds MAX_CSG_TRIANGLES (${d})`);let Y=M?M.elements:null,Z=Y?Y[0]*(Y[5]*Y[10]-Y[9]*Y[6])-Y[4]*(Y[1]*Y[10]-Y[9]*Y[2])+Y[8]*(Y[1]*Y[6]-Y[5]*Y[2])<0:!1,j=Y?new a().getNormalMatrix(M).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(Y&&j){let Ee=Y[0]*ue+Y[4]*fe+Y[8]*pe+Y[12],Ae=Y[1]*ue+Y[5]*fe+Y[9]*pe+Y[13],_e=Y[2]*ue+Y[6]*fe+Y[10]*pe+Y[14];ue=Ee,fe=Ae,pe=_e;let Ce=j[0]*me+j[3]*ce+j[6]*be,ke=j[1]*me+j[4]*ce+j[7]*be,He=j[2]*me+j[5]*ce+j[8]*be,Ge=Math.hypot(Ce,ke,He)||1;me=Ce/Ge,ce=ke/Ge,be=He/Ge}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 M=[],C=[],B=[],X=[];for(let $ of T){let Y=$.vertices;if(Y.length<3)continue;let Z=M.length/3;for(let j of Y)M.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<Y.length-1;j++)X.push(Z,Z+j,Z+j+1)}let W=new c;return W.setAttribute("position",new s(x(M),3)),W.setAttribute("normal",new s(x(C),3)),W.setAttribute("uv",new s(x(B),2)),W.setIndex(X),W._csgPolygons=T,W}function V(T,M,C){if(T.length+M.length>d)throw new RangeError(`SecurityError: Combined CSG triangle count (${T.length+M.length}) exceeds MAX_CSG_TRIANGLES (${d})`);if(T.length===0)return C==="union"?M:[];if(M.length===0)return C==="intersect"?[]:T;let B=1/0,X=1/0,W=1/0,$=-1/0,Y=-1/0,Z=-1/0;for(let ue=0;ue<M.length;ue++){let fe=M[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>Y&&(Y=me.y),me.z>Z&&(Z=me.z)}}B-=1e-4,X-=1e-4,W-=1e-4,$+=1e-4,Y+=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,Ee=-1/0;for(let Ae=0;Ae<pe.length;Ae++){let _e=pe[Ae];_e.x<me&&(me=_e.x),_e.y<ce&&(ce=_e.y),_e.z<be&&(be=_e.z),_e.x>xe&&(xe=_e.x),_e.y>ye&&(ye=_e.y),_e.z>Ee&&(Ee=_e.z)}xe<B||me>$||ye<X||ce>Y||Ee<W||be>Z?te.push(fe):j.push(fe)}if(j.length===0)return C==="union"?T.concat(M):C==="subtract"?T:[];let ee=new N(j),J=new N(M);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,M,C,B=null,X=null){let W=G(T,B),$=G(M,X);return E(V(W,$,C))}function U(T,M,C){let B=T instanceof f||!!T?.isMesh,X=M instanceof f||!!M?.isMesh,W=B?T.geometry:T,$=X?M.geometry:M,Y=null;if(X)if(M.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);Y=ee.multiply(ue).multiply(fe).multiply(M.matrix)}else Y=M.matrix;let Z=F(W,$,C,null,Y),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,M){return U(T,M,"subtract")},union(T,M){return U(T,M,"union")},intersect(T,M){return U(T,M,"intersect")}},K={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(M="",C={}){super();let B=String(M??"").slice(0,h),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,Y=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+Y,te=X*.68,ee=X*.82,J=[],ue=[],fe=[],pe=[],me=(xe,ye,Ee,Ae,_e,Ce,ke)=>{let He=Ee-xe,Ge=Ae-ye,Ke=Math.hypot(He,Ge),We=1,rt=0;Ke>1e-6&&(We=He/Ke,rt=Ge/Ke);let Vt=-rt*_e,Bt=We*_e,gt=We*_e*.6,xt=rt*_e*.6,je=xe-gt+Vt,it=ye-xt+Bt,ge=xe-gt-Vt,Ie=ye-xt-Bt,Pe=Ee+gt-Vt,Ve=Ae+xt-Bt,Be=Ee+gt+Vt,qe=Ae+xt+Bt,ft=(vt,Tt,wt,At,Mt,St,It)=>{let mt=J.length/3;J.push(vt[0],vt[1],vt[2],Tt[0],Tt[1],Tt[2],wt[0],wt[1],wt[2],At[0],At[1],At[2]),ue.push(Mt,St,It,Mt,St,It,Mt,St,It,Mt,St,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,ke],[ge,Ie,ke],[Pe,Ve,ke],[Be,qe,ke],0,0,1),ft([ge,Ie,Ce],[je,it,Ce],[Be,qe,Ce],[Pe,Ve,Ce],0,0,-1),ft([je,it,Ce],[ge,Ie,Ce],[ge,Ie,ke],[je,it,ke],-We,-rt,0),ft([Pe,Ve,Ce],[Be,qe,Ce],[Be,qe,ke],[Pe,Ve,ke],We,rt,0),ft([ge,Ie,Ce],[Pe,Ve,Ce],[Pe,Ve,ke],[ge,Ie,ke],rt,-We,0),ft([Be,qe,Ce],[je,it,Ce],[je,it,ke],[Be,qe,ke],-rt,We,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 Ee=ye.toUpperCase(),Ae=ye!==Ee&&ye>="a"&&ye<="z",_e=K[Ee]??K["?"],Ce=Ae?X*.76:X,ke=Ae?te*.88:te;for(let He of _e)for(let Ge=0;Ge<He.length-1;Ge++){let Ke=He[Ge],We=He[Ge+1];me(ce+Ke[0]*ke,be+Ke[1]*Ce,ce+We[0]*ke,be+We[1]*Ce,j,-Z*.5,Z*.5)}ce+=Ae?ee*.88:ee}this.setAttribute("position",new s(x(J),3)),this.setAttribute("normal",new s(x(ue),3)),this.setAttribute("uv",new s(x(fe),2)),this.setIndex(pe),C.center!==!1?this.center():this.computeBoundingBox()}}function ie(T){if(!T)return;let M=T,C=T.userData?.xr?.text;if(C!=null&&C!==!1){let X=M.geometry?.attributes?.position;if((!X||X.count===0)&&T.userData._textApplied!==!0){let W="",$=.08,Y=.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)&&(Y=Number(j.depth??j.height)||$*.2),(typeof j.color=="string"||typeof j.color=="number")&&(Z=j.color)}W.trim().length>0&&(M.geometry=new le(W,{size:$,depth:Y}),T.userData._textApplied=!0,M.material instanceof l?Z!==void 0&&T.userData._autoTextColorApplied!==!0&&(M.material.color=new u(Z),T.userData._autoTextColorApplied=!0):M.material=new m({color:Z??16317180}))}}let B=T.userData?.csg;if(B&&typeof B=="object"&&T.userData._csgApplied!==!0&&M.geometry instanceof c&&M.geometry.attributes.position?.count>0){T.userData._csgApplied=!0;let X=Array.isArray(B)?B:[B],W=M.geometry;for(let $ of X){if(!$||typeof $!="object")continue;let Y=$,Z=String(Y.op??Y.operation??"subtract"),j=Z==="union"||Z==="intersect"?Z:"subtract",te=Y.target??Y.mesh??Y.geometry;if(te instanceof f||te instanceof c)try{let ee=j==="union"?z.union(M,te):j==="intersect"?z.intersect(M,te):z.subtract(M,te);M.geometry!==W&&M.geometry.dispose?.(),M.geometry=ee.geometry}catch(ee){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ee)}}}}let he={Path:R,Shape:b,ShapeGeometry:I,ExtrudeGeometry:S,TextGeometry:le,CSG:z,MAX_CSG_TRIANGLES:d,MAX_BSP_DEPTH:p,MAX_TEXT_GEOMETRY_CHARS:h,MAX_SHAPE_POINTS:y,materializeDeclarativeGeometry:ie};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,he),t.materializeDeclarativeGeometry=ie),he}var Vr={name:"cad",onRegister(){Nn(Fn);let e=ve(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);t&&Fn(t,e)}};function we(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function On(e,t,n,r,i){let o=1/Math.tan(t/2);e.fill(0),e[0]=o/n,e[5]=o,e[11]=-1;let a=1/(r-i);return e[10]=(i+r)*a,e[14]=2*i*r*a,e}function Wt(e,t,n,r){let[i,o,a]=t,[u,s,c]=r,[l,m,f]=n,d=i-l,p=o-m,h=a-f,y=Math.hypot(d,p,h);y<=1e-5?(d=0,p=0,h=1):(d/=y,p/=y,h/=y);let v=s*h-c*p,R=c*d-u*h,b=u*p-s*d;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-h*R,A=h*v-d*b,P=d*R-p*v;return y=Math.hypot(w,A,P),y<=1e-5?(w=0,A=0,P=0):(w/=y,A/=y,P/=y),e[0]=v,e[1]=w,e[2]=d,e[3]=0,e[4]=R,e[5]=A,e[6]=p,e[7]=0,e[8]=b,e[9]=P,e[10]=h,e[11]=0,e[12]=-(v*i+R*o+b*a),e[13]=-(w*i+A*o+P*a),e[14]=-(d*i+p*o+h*a),e[15]=1,e}function Le(e,t,n){let r=t[0],i=t[1],o=t[2],a=t[3],u=t[4],s=t[5],c=t[6],l=t[7],m=t[8],f=t[9],d=t[10],p=t[11],h=t[12],y=t[13],v=t[14],R=t[15],b=n[0],w=n[1],A=n[2],P=n[3];return e[0]=b*r+w*u+A*m+P*h,e[1]=b*i+w*s+A*f+P*y,e[2]=b*o+w*c+A*d+P*v,e[3]=b*a+w*l+A*p+P*R,b=n[4],w=n[5],A=n[6],P=n[7],e[4]=b*r+w*u+A*m+P*h,e[5]=b*i+w*s+A*f+P*y,e[6]=b*o+w*c+A*d+P*v,e[7]=b*a+w*l+A*p+P*R,b=n[8],w=n[9],A=n[10],P=n[11],e[8]=b*r+w*u+A*m+P*h,e[9]=b*i+w*s+A*f+P*y,e[10]=b*o+w*c+A*d+P*v,e[11]=b*a+w*l+A*p+P*R,b=n[12],w=n[13],A=n[14],P=n[15],e[12]=b*r+w*u+A*m+P*h,e[13]=b*i+w*s+A*f+P*y,e[14]=b*o+w*c+A*d+P*v,e[15]=b*a+w*l+A*p+P*R,e}function Je(e,t,n,r){let i=t[0],o=t[1],a=t[2],u=t[3],s=i+i,c=o+o,l=a+a,m=i*s,f=i*c,d=i*l,p=o*c,h=o*l,y=a*l,v=u*s,R=u*c,b=u*l,w=r[0],A=r[1],P=r[2];return e[0]=(1-(p+y))*w,e[1]=(f+b)*w,e[2]=(d-R)*w,e[3]=0,e[4]=(f-b)*A,e[5]=(1-(m+y))*A,e[6]=(h+v)*A,e[7]=0,e[8]=(d+R)*P,e[9]=(h-v)*P,e[10]=(1-(m+p))*P,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Ne(e,t){let n=t[0],r=t[1],i=t[2],o=t[4],a=t[5],u=t[6],s=t[8],c=t[9],l=t[10],m=l*a-u*c,f=-l*o+u*s,d=c*o-a*s,p=n*m+r*f+i*d;return p&&(p=1/p,e[0]=m*p,e[1]=f*p,e[2]=d*p,e[3]=(-l*r+i*c)*p,e[4]=(l*n-i*s)*p,e[5]=(-c*n+r*s)*p,e[6]=(u*r-i*a)*p,e[7]=(-u*n+i*o)*p,e[8]=(a*n-r*o)*p),e}function $t(e,t){let n=t[0],r=t[1],i=t[2],o=t[3],a=t[4],u=t[5],s=t[6],c=t[7],l=t[8],m=t[9],f=t[10],d=t[11],p=t[12],h=t[13],y=t[14],v=t[15],R=n*u-r*a,b=n*s-i*a,w=n*c-o*a,A=r*s-i*u,P=r*c-o*u,k=i*c-o*s,L=l*h-m*p,I=l*y-f*p,x=l*v-d*p,g=m*y-f*h,S=m*v-d*h,D=f*v-d*y,_=R*D-b*S+w*g+A*x-P*I+k*L;return _?(_=1/_,e[0]=(u*D-s*S+c*g)*_,e[1]=(i*S-r*D-o*g)*_,e[2]=(h*k-y*P+v*A)*_,e[3]=(f*P-m*k-d*A)*_,e[4]=(s*x-a*D-c*I)*_,e[5]=(n*D-i*x+o*I)*_,e[6]=(y*w-p*k-v*b)*_,e[7]=(l*k-f*w+d*b)*_,e[8]=(a*S-u*x+c*L)*_,e[9]=(r*x-n*S-o*L)*_,e[10]=(p*P-h*w+v*R)*_,e[11]=(m*w-l*P-d*R)*_,e[12]=(u*I-a*g-s*L)*_,e[13]=(n*g-r*I+i*L)*_,e[14]=(h*b-p*A-y*R)*_,e[15]=(l*A-m*b+f*R)*_,e):null}function Br(e,t,n,r,i){let o=i[0]*t+i[4]*n+i[8]*r+i[12],a=i[1]*t+i[5]*n+i[9]*r+i[13],u=i[2]*t+i[6]*n+i[10]*r+i[14],s=i[3]*t+i[7]*n+i[11]*r+i[15],c=s!==0?1/s:1;e[0]=o*c,e[1]=a*c,e[2]=u*c}function lo(e,t,n,r,i,o,a,u,s,c,l,m,f,d,p,h,y=0){let v=c-a,R=l-u,b=m-s,w=f-a,A=d-u,P=p-s,k=i*P-o*A,L=o*w-r*P,I=r*A-i*w,x=v*k+R*L+b*I;if(x>-1e-7&&x<1e-7)return!1;let g=1/x,S=e-a,D=t-u,_=n-s,O=g*(S*k+D*L+_*I);if(O<-y||O>1+y)return!1;let Q=D*b-_*R,q=_*v-S*b,oe=S*R-D*v,ne=g*(r*Q+i*q+o*oe);if(ne<-y||O+ne>1+y)return!1;let re=g*(w*Q+A*q+P*oe);if(re>1e-4&&re<h.distance){h.distance=re,h.point=[e+r*re,t+i*re,n+o*re];let H=R*P-b*A,se=b*w-v*P,ae=v*A-R*w,N=Math.hypot(H,se,ae)||1;return h.normal=[H/N,se/N,ae/N],!0}return!1}function dt(e,t){let n=Array.isArray(e?.nodes)?e.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 e.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 d=e.nodes[l];if(!d)return;let p=we();if(t&&t[l])p.set(t[l]);else if(d.matrix&&d.matrix.length===16)p.set(d.matrix);else{let y=d.translation||[0,0,0],v=d.rotation||[0,0,0,1],R=d.scale||[1,1,1];Je(p,v,y,R)}let h=r[l];if(m?Le(h,m,p):h.set(p),Array.isArray(d.children))for(let y of d.children)typeof y=="number"&&u(y,h,f+1)},s=[],c=e.scenes&&e.scenes[e.scene!==void 0?e.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 Hr(e,t){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],d=s[2]*c[0]-s[0]*c[2],p=s[0]*c[1]-s[1]*c[0],h=Math.hypot(f,d,p,m)||1;return[f/h,d/h,p/h,m/h]}function i(s,c,l,m,f){let d=c[0]-s[0],p=c[1]-s[1],h=c[2]-s[2],y=Math.hypot(d,p,h),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 A=[d/y,p/y,h/y],P=[v/w,R/w,b/w],k=m[0]-s[0],L=m[1]-s[1],I=m[2]-s[2],x=Math.hypot(k,L,I),g=x>1e-6?[k/x,L/x,I/x]:A,S=Math.abs(y-w)+1e-5,D=Math.max(S,y+w-1e-5),_=Math.max(S,Math.min(D,x>1e-6?x:S)),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]:d,oe=f?f[1]-s[1]:p,ne=f?f[2]-s[2]:h,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,N=Math.hypot(H,se,ae);if(N<=1e-6){let T=Math.abs(g[1])<.99?0:1,M=Math.abs(g[1])<.99?1:0,C=0;H=g[1]*C-g[2]*M,se=g[2]*T-g[0]*C,ae=g[0]*M-g[1]*T,N=Math.hypot(H,se,ae)||1}let G=[H/N,se/N,ae/N],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],K=Math.hypot(F,U,z),le=K>1e-6?[F/K,U/K,z/K]: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(A,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 d=s.map(x=>[x[0],x[1],x[2]]),p=[],h=[],y=0;for(let x=0;x<f-1;x++){let g=d[x+1][0]-d[x][0],S=d[x+1][1]-d[x][1],D=d[x+1][2]-d[x][2],_=Math.hypot(g,S,D);p.push(_),y+=_,h.push(_>1e-6?[g/_,S/_,D/_]:[0,1,0])}let v=[d[0][0],d[0][1],d[0][2]],R=Math.round(n(l,1,32,8)),b=n(m,1e-5,.1,.001),w=c[0]-v[0],A=c[1]-v[1],P=c[2]-v[2],k=Math.hypot(w,A,P),L=0;if(k>=y&&y>1e-6){let x=k>1e-6?[w/k,A/k,P/k]:h[0];d[0]=[v[0],v[1],v[2]];for(let g=0;g<f-1;g++){let S=p[g];d[g+1]=[d[g][0]+x[0]*S,d[g][1]+x[1]*S,d[g][2]+x[2]*S]}L=1}else for(let x=1;x<=R;x++){let g=d[f-1];if(Math.hypot(g[0]-c[0],g[1]-c[1],g[2]-c[2])<=b)break;L=x;let D=(_,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]};d[f-1]=[c[0],c[1],c[2]];for(let _=f-2;_>=0;_--)d[_]=D(d[_+1],d[_],p[_],h[_],-1);d[0]=[v[0],v[1],v[2]];for(let _=0;_<f-1;_++)d[_+1]=D(d[_],d[_+1],p[_],h[_],1)}let I=[];for(let x=0;x<f-1;x++){let g=d[x+1][0]-d[x][0],S=d[x+1][1]-d[x][1],D=d[x+1][2]-d[x][2],_=Math.hypot(g,S,D),O=_>1e-6?[g/_,S/_,D/_]:h[x];I.push(r(h[x],O))}return{positions:d,rotations:I,iterations:L}}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),d=l(c.effector);if(!f||!d)return null;let p=l(c.mid),h=m(c.target)??l(c.target);if(!h)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:d,target:h,...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 t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=u),{clampNum:n,parseIKTrait:a,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:u}}var jt=Hr(),mo=jt.clampNum,js=jt.parseIKTrait,Bn=jt.quatFromUnitVectors,$r=jt.solveTwoBoneIK,jr=jt.solveFABRIK,ho=jt.IKSolver;function Xr(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 qs(e,t){let n=e?.transform??e?.modelMatrix;!n||n.length<16||(n[12]=t[0],n[13]=t[1],n[14]=t[2])}function Ks(e,t,n,r,i){let o=mo(i,0,1,1),a=t[0]+(n[0]-t[0])*o,u=t[1]+(n[1]-t[1])*o,s=t[2]+(n[2]-t[2])*o,c=a-e[0],l=u-e[1],m=s-e[2],f=Math.hypot(c,l,m);if(f>1e-6&&r>1e-6){let v=r/f;return[e[0]+c*v,e[1]+l*v,e[2]+m*v]}let d=n[0]-e[0],p=n[1]-e[1],h=n[2]-e[2],y=Math.hypot(d,p,h);if(y>1e-6&&r>1e-6){let v=r/y;return[e[0]+d*v,e[1]+p*v,e[2]+h*v]}return[a,u,s]}function Ys(e,t){let n=e?.modelRootMatrix;if(!n||n.length!==16)return t;let r=new Float32Array(16);return $t(r,n instanceof Float32Array?n:Float32Array.from(n))?[r[0]*t[0]+r[4]*t[1]+r[8]*t[2]+r[12],r[1]*t[0]+r[5]*t[1]+r[9]*t[2]+r[13],r[2]*t[0]+r[6]*t[1]+r[10]*t[2]+r[14]]:t}function zr(e,t){e.__ikWarned||(e.__ikWarned=new Set);let n=e.__ikWarned;n.has(t)||(n.add(t),console.warn(`[three-live] ik: joint '${t}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function Wr(e,t,n){if(Array.isArray(e))return[e[0],e[1],e[2]];let r=t.get(e);if(r)return Xr(r);let i;if(e==="head"?i=n?.headPose?.position??n?.headPose??n?.cameraPosition:e==="hand-left"?i=n?.handPoses?.left?.position??n?.handPoses?.left??n?.hands?.left?.position??n?.hands?.left:e==="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 Ys(n,[o[0],o[1],o[2]])}return null}function Gr(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 Zs(e){return[-e[0],-e[1],-e[2],e[3]]}function qr(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 Qs(e,t){if(t>=1)return e;if(t<=0)return[0,0,0,1];let[n,r,i,o]=e;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*t)/u;return qr([n*s,r*s,i*s,Math.cos(a*t)])}function Js(e){let t=Math.hypot(e[0],e[1],e[2])||1,n=Math.hypot(e[4],e[5],e[6])||1,r=Math.hypot(e[8],e[9],e[10])||1,i=e[0]/t,o=e[1]/t,a=e[2]/t,u=e[4]/n,s=e[5]/n,c=e[6]/n,l=e[8]/r,m=e[9]/r,f=e[10]/r,d=i+s+f,p;if(d>0){let h=Math.sqrt(d+1)*2;p=[(c-m)/h,(l-a)/h,(o-u)/h,.25*h]}else if(i>s&&i>f){let h=Math.sqrt(1+i-s-f)*2;p=[.25*h,(u+o)/h,(l+a)/h,(c-m)/h]}else if(s>f){let h=Math.sqrt(1+s-i-f)*2;p=[(u+o)/h,.25*h,(m+c)/h,(l-a)/h]}else{let h=Math.sqrt(1+f-i-s)*2;p=[(l+a)/h,(m+c)/h,.25*h,(o-u)/h]}return qr(p)}function ea(e,t,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),d=2*(r*o-i*a),p=2*(i*o+r*a),h=1-2*(r*r+i*i);for(let y=0;y<3;y++){let v=t[y*4],R=t[y*4+1],b=t[y*4+2];e[y*4]=u*v+s*R+c*b,e[y*4+1]=l*v+m*R+f*b,e[y*4+2]=d*v+p*R+h*b}}function Vn(e,t){let n=t[0]-e[0],r=t[1]-e[1],i=t[2]-e[2],o=Math.hypot(n,r,i);return o>1e-9?[n/o,r/o,i/o]:null}function po(e){e?.normalMatrix&&e?.transform&&Ne(e.normalMatrix,e.transform)}var fo=new WeakMap;function ta(e){let t=fo.get(e);return t||(t=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((n,r)=>{for(let i of Array.isArray(n?.children)?n.children:[])typeof i=="number"&&i>=0&&i<t.length&&(t[i]=r)}),fo.set(e,t)),t}function na(e,t,n){let r=e?.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=(t.mid?[t.root,t.mid,t.effector]:[t.root,t.effector]).map(x=>o.get(x));if(u.some(x=>x===void 0))return!1;let s=u,c=ta(r);for(let x=1;x<s.length;x++){let g=c[s[x]],S=0;for(;g>=0&&g!==s[x-1]&&S++<256;)g=c[g];if(g!==s[x-1])return!1}let l=s[0],m=e.initialNodeTransforms,f=new Map,d=[],p=[l];for(;p.length&&d.length<4096;){let x=p.pop();if(f.has(x))continue;let g=m?.[x],S=i[x];f.set(x,{t:g?[g.t[0],g.t[1],g.t[2]]:S?.translation?[...S.translation]:[0,0,0],r:g?[g.r[0],g.r[1],g.r[2],g.r[3]]:S?.rotation?[...S.rotation]:[0,0,0,1],s:g?[g.s[0],g.s[1],g.s[2]]:S?.scale?[...S.scale]:[1,1,1]}),d.push(x);for(let D of Array.isArray(S?.children)?S.children:[])typeof D=="number"&&p.push(D)}let h=c[l],y=h>=0&&e.worldMatrices?.[h]?.length===16?Float32Array.from(e.worldMatrices[h]):we(),v=new Map,R=()=>{let x=(g,S)=>{let D=f.get(g);if(!D)return;let _=we();Je(_,D.r,D.t,D.s);let O=we();Le(O,S,_),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),A=x=>{if(typeof x=="string"&&!n.has(x)){let g=o.get(x),S=g!==void 0?v.get(g)??e.worldMatrices?.[g]:void 0;if(S&&S.length===16)return[S[12],S[13],S[14]]}return Wr(x,n,e)},P=A(t.target);if(!P)return!0;let k=t.pole?A(t.pole)??void 0:void 0,L=bo(w,t,P,k),I=mo(t.weight,0,1,1);for(let x=0;x<s.length-1;x++){let g=Vn(b(s[x]),b(s[x+1])),S=Vn(L[x],L[x+1]);if(!g||!S)continue;let D=Qs(Bn(g,S),I),_=s[x],O=c[_],Q=O===h||O<0?y:v.get(O)??y,q=Js(Q),oe=f.get(_);oe.r=qr(Gr(Zs(q),Gr(D,Gr(q,oe.r)))),R()}if(Array.isArray(e.worldMatrices))for(let[x,g]of v)e.worldMatrices[x]?.set&&e.worldMatrices[x].set(g);for(let x of e.meshes??[]){let g=v.get(x?.nodeIndex);g&&x.transform?.set&&(x.transform.set(g),po(x))}return!0}function bo(e,t,n,r){if(t.solver==="two-bone"&&e.length===3){let i=$r(e[0],e[1],e[2],n,r);return[e[0],i.midPos,i.effectorPos]}return jr(e,n,t.iterations,t.tolerance).positions}function ra(e,t,n){let r=e.__ikRestOffsets,i=e.__ikRestMats;if(!(!r||!i))for(let o=0;o<t.length-1;o++){let a=t[o]?.transform??t[o]?.modelMatrix,u=i[o],s=Vn([0,0,0],r[o]),c=Vn(n[o],n[o+1]);!a||a.length<16||!u||u.length<16||!s||!c||(ea(a,u,Bn(s,c)),po(t[o]))}}var Kr={name:"ik",onRegister(){let e=ve();Nn(Hr),Hr(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let n=null;for(let r of t){let i=r?.userData?.xr?.ik??r?.extras?.xr?.ik??r?.extensions?.ANDROID_xr_scenecore?.ik;if(!i)continue;let o=js(i);if(!o||o.weight<=0)continue;if(!n){n=new Map;for(let w of t)w&&typeof w.name=="string"&&w.name&&n.set(w.name,w)}if(na(e,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||zr(r,o.root),u||zr(r,o.effector),o.mid&&!s&&zr(r,o.mid),!a||!u)continue;let c=Wr(o.target,n,e);if(!c)continue;let l=o.pole?Wr(o.pole,n,e)??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(Xr),A=[];for(let P=0;P<w.length-1;P++)A.push([w[P+1][0]-w[P][0],w[P+1][1]-w[P][1],w[P+1][2]-w[P][2]]);r.__ikRestOffsets=A,r.__ikRestKey=f,r.__ikRestMats=m.map(P=>Array.from(P.transform??P.modelMatrix??[]))}let d=r.__ikRestOffsets,h=[Xr(a)],y=[];for(let w=0;w<d.length;w++){let A=h[w],P=d[w];h.push([A[0]+P[0],A[1]+P[1],A[2]+P[2]]),y.push(Math.hypot(P[0],P[1],P[2]))}let v=bo(h,o,c,l),R=h[0],b=[h[0]];for(let w=1;w<m.length;w++){let A=d[w-1],P=[R[0]+A[0],R[1]+A[1],R[2]+A[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])],L=Ks(R,P,k,y[w-1],o.weight);qs(m[w],L),R=L,b.push(L)}ra(r,m,b)}}};var ia={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function ot(e,t,n,r){if(!n||n.bufferView===void 0)return null;let i=e.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=ia[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>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(a===5126&&c===s&&l%4===0)return new Float32Array(t,l,o*r);let m=new DataView(t),f=n.normalized===!0,d=new Float32Array(o*r);for(let p=0;p<o;p++){let h=l+p*c;for(let y=0;y<r;y++){let v=h+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)}d[p*r+y]=R}}return d}function yo(e,t){let n=Number(t.offset?.[0]??0)||0,r=Number(t.offset?.[1]??0)||0,i=Number(t.scale?.[0]??1),o=Number(t.scale?.[1]??1),a=Number(t.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 d=0;d+1<e.length;d+=2){let p=e[d],h=e[d+1];e[d]=c*p+l*h+n,e[d+1]=m*p+f*h+r}}var To=["neutral","reinhard","none","aces","agx"];function Lt(e){let t=String(e??"").trim().toLowerCase();return To.includes(t)?t:"neutral"}function oa(e){return To.indexOf(Lt(e))}function sa(e){return new TextDecoder().decode(e)}var wo=ve().decoders;function aa(e,t){wo.set(e.toLowerCase(),t)}function qt(e){return wo.get(e.toLowerCase())}function Ao(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,n=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.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<=t.byteLength;){let f=n.getUint32(a,!0),d=n.getUint32(a+4,!0),p=a+8;if(p+f>t.byteLength)throw new Error(`Truncated GLB chunk: required ${p+f} bytes, buffer has ${t.byteLength}`);if(d===1313821514){let h=new Uint8Array(t,p,f),y=sa(h);u=JSON.parse(y,(v,R)=>v==="__proto__"||v==="constructor"||v==="prototype"?void 0:R)}else d===5130562&&(s=t.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")&&!qt("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)&&!qt("meshopt"))throw new Error(`Model requires ${f}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!qt("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 Ue)f.onParseGLB?.(m);return m}function ca(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 ht(e){if(ca(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return Ao(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Mo=`#version 300 es
19
- layout(location=0) in vec3 aPosition;
17
+ var Xs=Object.defineProperty;var Ws=(t,e)=>{for(var n in e)Xs(t,n,{get:e[n],enumerable:!0})};var $i={};Ws($i,{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:()=>ho,IcosahedronGeometry:()=>hr,InstancedMesh:()=>xn,InteractivityVM:()=>In,Light:()=>Dt,MAX_BSP_DEPTH:()=>ao,MAX_CSG_TRIANGLES:()=>so,MAX_INSTANCES_PER_MESH:()=>gn,MAX_SHAPE_POINTS:()=>uo,MAX_TEXT_GEOMETRY_CHARS:()=>co,Material:()=>at,MathUtils:()=>Ho,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:()=>es,RectAreaLight:()=>ts,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:()=>Fi,authorScriptRunner:()=>en,buildSandboxWorkerSource:()=>ui,cadPlugin:()=>Vr,clearAuthorWarnings:()=>Jo,computeOutlineClipOffset:()=>Fs,contactShadowPlugin:()=>_n,createUSDZBlob:()=>Qt,crossFadeTo:()=>bi,decodeMeshoptBuffer:()=>Vi,decodeMeshoptGLB:()=>Dr,encodeMeshoptBuffer:()=>ks,environmentMapPlugin:()=>Li,evaluateKawaseBloom:()=>Os,evaluateToneMapping:()=>Ao,exportSceneToCanvas3D:()=>si,exportSceneToGLB:()=>ai,exportSceneToUSDZ:()=>Wo,extractMaterialVariants:()=>Hi,extractPrimitiveVariantMappings:()=>Vs,generateUSDZ:()=>un,getARCapabilities:()=>Sr,getAllowClientScripts:()=>qo,getAuthorWarnings:()=>Qo,getBestARMode:()=>us,getEnvironmentSH:()=>ms,getInteractivityVM:()=>Pr,getSandboxEngineSrc:()=>ci,getSandboxIframeSrc:()=>jo,glbToUSDZ:()=>cn,hotspotPlugin:()=>Pi,ikPlugin:()=>Kr,installCadExtension:()=>Fn,interactivityPlugin:()=>Ui,isAllowedSandboxEngineUrl:()=>Lt,isQuickLookSupported:()=>Ai,isSceneViewerSupported:()=>Si,isWebXRSupported:()=>Ri,keyframeAnimationPlugin:()=>yi,materialsPlugin:()=>Oi,meshoptDecoder:()=>Ur,meshoptPlugin:()=>Bi,morphPlugin:()=>gi,noopProxy:()=>fn,parseAnimations:()=>pi,parseHexRgb:()=>zi,parseSafeGltfPointer:()=>Ln,postprocessingPlugin:()=>Gi,quatFromUnitVectors:()=>zn,registerMaterialShader:()=>vs,sampleChannel:()=>nn,sceneToCanvas3D:()=>Yt,sceneToGLB:()=>an,sceneToUSDZ:()=>Zt,selectMaterialVariant:()=>Bs,sendInteractivityEvent:()=>Di,setAllowClientScripts:()=>_a,setEnvironmentSH:()=>Er,setMorphTargetWeight:()=>os,setSandboxEngineSrc:()=>Aa,setSandboxIframeSrc:()=>Ra,skinningPlugin:()=>vi,solveFABRIK:()=>jr,solveTwoBoneIK:()=>$r,threeAuthorPlugin:()=>mn,threeMicroPlugin:()=>Oa,toGLBData:()=>ht,toTrustedWorkerScriptURL:()=>$o,validateSandboxWorkerMessage:()=>li,variantsPlugin:()=>Xi,warnUnsupported:()=>Ze,webxrPlugin:()=>Wi});function oo(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 so=8192,ao=2048,co=128,uo=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,Gs=vt.x+wt.x*Ve.expand,Hs=vt.y+wt.y*Ve.expand,ji=xt.x+Tt.x*Ve.expand,qi=xt.y+Tt.y*Ve.expand,Ki=It-Mt,Yi=mt-At,Zi=0,Qi=ji-Mt,Ji=qi-At,eo=Ve.z-Fe.z,Gt=Yi*eo-Zi*Ji,Ht=Zi*Qi-Ki*eo,Xt=Ki*Ji-Yi*Qi,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,Gs,Hs,Ve.z,ji,qi,Ve.z),ue.push(Gt,Ht,Xt,Gt,Ht,Xt,Gt,Ht,Xt,Gt,Ht,Xt);let to=qe/_e,no=(qe+1)/_e,ro=Ce/(je.length-1),io=(Ce+1)/(je.length-1);fe.push(to,ro,no,ro,no,io,to,io),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 Vr={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 Br(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 lo(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 Hr(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=Hr(),mo=qt.clampNum,$s=qt.parseIKTrait,zn=qt.quatFromUnitVectors,$r=qt.solveTwoBoneIK,jr=qt.solveFABRIK,ho=qt.IKSolver;function Xr(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 js(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 qs(t,e,n,r,i){let o=mo(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 Ks(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 zr(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 Wr(t,e,n){if(Array.isArray(t))return[t[0],t[1],t[2]];let r=e.get(t);if(r)return Xr(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 Ks(n,[o[0],o[1],o[2]])}return null}function Gr(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 Ys(t){return[-t[0],-t[1],-t[2],t[3]]}function qr(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 Zs(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 qr([n*s,r*s,i*s,Math.cos(a*e)])}function Qs(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 qr(p)}function Js(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 po(t){t?.normalMatrix&&t?.transform&&Ne(t.normalMatrix,t.transform)}var fo=new WeakMap;function ea(t){let e=fo.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)}),fo.set(t,e)),e}function ta(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=ea(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 Wr(x,n,t)},P=M(e.target);if(!P)return!0;let k=e.pole?M(e.pole)??void 0:void 0,I=bo(w,e,P,k),L=mo(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=Zs(zn(g,A),L),_=s[x],O=c[_],Q=O===d||O<0?y:v.get(O)??y,q=Qs(Q),oe=f.get(_);oe.r=qr(Gr(Ys(q),Gr(N,Gr(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),po(x))}return!0}function bo(t,e,n,r){if(e.solver==="two-bone"&&t.length===3){let i=$r(t[0],t[1],t[2],n,r);return[t[0],i.midPos,i.effectorPos]}return jr(t,n,e.iterations,e.tolerance).positions}function na(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||(Js(a,u,zn(s,c)),po(e[o]))}}var Kr={name:"ik",onRegister(){let t=ve();Un(Hr),Hr(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=$s(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(ta(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||zr(r,o.root),u||zr(r,o.effector),o.mid&&!s&&zr(r,o.mid),!a||!u)continue;let c=Wr(o.target,n,t);if(!c)continue;let l=o.pole?Wr(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(Xr),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=[Xr(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=bo(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=qs(R,P,k,y[w-1],o.weight);js(m[w],I),R=I,b.push(I)}na(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 ra={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=ra[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 yo(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 vo=["neutral","reinhard","none","aces","agx"];function Ct(t){let e=String(t??"").trim().toLowerCase();return vo.includes(e)?e:"neutral"}function ia(t){return vo.indexOf(Ct(t))}function oa(t){return new TextDecoder().decode(t)}var To=ve().decoders;function sa(t,e){To.set(t.toLowerCase(),e)}function Kt(t){return To.get(t.toLowerCase())}function wo(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=oa(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 aa(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(aa(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return wo(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Mo=`#version 300 es
19
+ layout(location=0) in vec3 aPos;
20
+ layout(location=3) in vec3 aOff;
20
21
  layout(location=1) in vec3 aNormal;
21
22
  layout(location=2) in vec2 aUV;
22
23
  uniform mat4 uMVP,uModel;
@@ -39,6 +40,7 @@ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):u
39
40
  out vec3 vNormal,vWorldPos;
40
41
  out vec2 vUV;
41
42
  void main(){
43
+ vec3 aPosition=aPos+aOff;
42
44
  vInstTint=uInstanced==1?aInstColor:vec4(1.0);
43
45
  vec3 rawN=uNormalMatrix*aNormal;
44
46
  vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
@@ -48,7 +50,7 @@ vec2 scaleUV=uUvTransform.zw;
48
50
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
49
51
  vUV=aUV*scaleUV+uUvTransform.xy;
50
52
  gl_Position=uMVP*vec4(aPosition,1.0);
51
- }`,ua=`#version 300 es
53
+ }`,ca=`#version 300 es
52
54
  precision highp float;
53
55
  in vec3 vNormal,vWorldPos;
54
56
  in vec2 vUV;
@@ -241,15 +243,15 @@ color=applyToneMapping(color,uToneMapping);
241
243
  float outAlpha=base.a;
242
244
  /*XRD_O*/
243
245
  fragColor=vec4(color,outAlpha);
244
- }`;function So(e,t,n=1){t=Lt(t);let r=Number.isFinite(n)?Math.max(0,n):1,i=Math.max(0,(Number(e[0])||0)*r),o=Math.max(0,(Number(e[1])||0)*r),a=Math.max(0,(Number(e[2])||0)*r),u=v=>Math.max(0,Math.min(1,v));if(t==="none")return[u(i),u(o),u(a)];if(t==="reinhard")return[i/(i+1),o/(o+1),a/(a+1)];if(t==="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(t==="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 S=u((Math.log2(Math.max(g,1e-6))+12.47393)/16.5),D=S*S,_=D*D;return 15.5*_*D-40.14*_*S+31.96*_-6.868*D*S+.4298*D+.1191*S-.00232},A=w(v),P=w(R),k=w(b),L=1.196879*A-.09802088*P-.09902974*k,I=-.05289685*A+1.15190313*P-.09896118*k,x=-.05297164*A-.09804345*P+1.15107367*k;return[u(Math.pow(Math.max(L,0),2.2)),u(Math.pow(Math.max(I,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 d=1-s,p=1-d*d/(f+d-s),h=p/f;i*=h,o*=h,a*=h;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 la=`#version 300 es
246
+ }`;function Ao(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 ua=`#version 300 es
245
247
  layout(location=0) in vec3 aPosition;
246
248
  uniform mat4 uMVP;
247
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,fa=`#version 300 es
249
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,la=`#version 300 es
248
250
  precision highp float;
249
251
  uniform vec4 uColorId;
250
252
  out vec4 fragColor;
251
- void main(){fragColor=uColorId;}`;function go(e,t,n){let r=e.createShader(t);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,35713)){let i=e.getShaderInfoLog(r);throw e.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function Qr(e,t,n){let r=go(e,35633,t),i=go(e,35632,n),o=e.createProgram();if(e.attachShader(o,r),e.attachShader(o,i),e.linkProgram(o),!e.getProgramParameter(o,35714)){let a=e.getProgramInfoLog(o);throw e.deleteProgram(o),new Error(`Program link error: ${a}`)}return o}function Jr(e,t,n){let r={};for(let i of n)r[i]=e.getUniformLocation(t,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 e=ve().xrDepthShader;return{fs:ua.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...xo,...e.uniformNames]:xo}}function ma(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let n=t.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:n.startsWith("https://")||n.startsWith("blob:")?t:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Yr(e,t,n,r,i,o,a,u){if(r===void 0||!t.accessors?.[r])return null;let s=ot(t,n,t.accessors[r],o);if(!s)return null;u&&(s=s.slice(),yo(s,u));let c=e.createBuffer();return a.push(c),e.bindBuffer(34962,c),e.bufferData(34962,s,35044),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,o,5126,!1,0,0),s}function Zr(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function Eo(e,t,n){let r=Ro(),i=Mo,o=r.fs,a=!1;for(let s of Ue)if(s.onResolveShader){let c=s.onResolveShader(t,n,i,o);c&&(i=c.vs,o=c.fs,a=!0)}let u=a?Qr(e,i,o):null;return{program:u,uniforms:u?Jr(e,u,r.uniforms):null}}function da(e,t,n){let r=t.instanceMatrices;if(!r||r.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=t.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=e.createBuffer();n.push(u),e.bindBuffer(34962,u),e.bufferData(34962,a,35044);for(let s=0;s<5;s++)e.enableVertexAttribArray(8+s),e.vertexAttribPointer(8+s,4,5126,!1,80,s*16),e.vertexAttribDivisor(8+s,1);return!0}function ha(e,t){let n=e.materials?.[t?.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}),Io=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function zn(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function Lo(e,t){let n=e?.pbrMetallicRoughness,r=n?.baseColorFactor,i=e?.extensions?.KHR_materials_clearcoat,o=a=>a!==void 0&&t[a.index]?t[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(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:o(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Co(e,t,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),e.deleteTexture(o))};for(let o of t)for(let a of o.primitives){if(a.vao&&e.deleteVertexArray(a.vao),a.buffers)for(let s of a.buffers)e.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)e.deleteProgram(s)}if(n)for(let o of n)i(o)}function vo(e,t,n=Io,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return pa(e,t,n,r,i)}catch(o){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Co(e,a,i.gpuTextures),i.vao&&e.deleteVertexArray(i.vao);for(let u of i.buffers)e.deleteBuffer(u);throw o}}function pa(e,t,n,r,i){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=t,a=qt("meshopt");a?.decodeBufferViews&&a.decodeBufferViews(o,t);let u=t.bin,s=[];i.meshes=s;let c=[],l=o.extensions?.KHR_materials_variants;l&&Array.isArray(l.variants)&&l.variants.forEach((S,D)=>{c.push(typeof S?.name=="string"&&S.name?S.name:`Variant_${D}`)});let m=dt(o),f=[];if(Array.isArray(o.nodes))for(let S=0;S<o.nodes.length;S++){let D=o.nodes[S];D.mesh!==void 0&&o.meshes&&o.meshes[D.mesh]&&f.push({node:D,nodeIdx:S,meshIdx:D.mesh})}let d=f.length>0?f:(o.meshes||[]).map((S,D)=>({node:S,nodeIdx:-1,meshIdx:D})),p=[];if(Array.isArray(t.lights)&&t.lights.length>0)p.push(...t.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let S=o.extensions.KHR_lights_punctual.lights;for(let D of S){let _=D.type==="directional"?"directional":D.type==="point"?"point":"ambient";p.push({type:_,color:D.color||[1,1,1],intensity:D.intensity!==void 0?D.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]})),d.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${d.length}`);let h=[];if(i.gpuTextures=h,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 S=0;S<o.textures.length;S++){let D=o.textures[S],_=o.images[D.source];if(_){let O=e.createTexture();if(e.bindTexture(3553,O),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),_.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=>{e.bindTexture(3553,O),e.texImage2D(3553,0,6408,6408,5121,ne),e.generateMipmap(3553),r?.()}).catch(()=>{})}else if(_.uri){let Q=ma(_.uri);if(Q){let q=new Image;q.crossOrigin="anonymous",q.referrerPolicy="no-referrer",q.onload=()=>{e.bindTexture(3553,O),e.texImage2D(3553,0,6408,6408,5121,q),e.generateMipmap(3553),r?.()},q.src=Q}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",_.uri)}h.push(O)}else h.push(null)}}let y=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],R=0,b=0;for(let S=0;S<d.length;S++){let D=d[S],_=o.meshes[D.meshIdx],O=D.nodeIdx>=0?m[D.nodeIdx]:we(),Q=new Float32Array(9);Ne(Q,O);let q={name:D.node.name||_.name||`Mesh_${D.meshIdx}`,nodeIndex:D.nodeIdx,transform:O,normalMatrix:Q,primitives:[],extras:D.node.extras||_.extras};i.mesh=q;let oe=D.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,N=Number(re?.count??H?.count??se?.count??0);if(!Number.isFinite(N)||N<0||N>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${N}`);if(N>0){let G=(ie,he)=>{if(!ie||ie.bufferView===void 0||!o.bufferViews?.[ie.bufferView])return null;let T=ie.componentType??5126,M=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 M(`componentType ${T}`);if(!(Number(ie.count)>=N))return M(`count ${ie.count} < ${N}`);let C=null;try{C=ot(o,u,{...ie,count:N},he)}catch{return M("out of bounds")}return!C||!C.every(Number.isFinite)?M("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),K=new Float32Array(N*16),le=we();for(let ie=0;ie<N;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],M=F?[F[ie*3],F[ie*3+1],F[ie*3+2]]:[1,1,1];Je(le,T,he,M),K.set(le,ie*16)}if(q.instanceMatrices=K,z){let ie=new Float32Array(N*3);for(let he=0;he<N;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=qt("draco");C&&C.decodePrimitive(o,ne,u)}let re=[],H=e.createVertexArray();i.vao=H,i.buffers=re,e.bindVertexArray(H);let se=da(e,q,re),ae=o.accessors[ne.attributes.POSITION],N=Number(ae?.count??0);if(!Number.isFinite(N)||N<0||R+N>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(R+=N,ae?.min&&ae?.max){let C=B=>{for(let X=0;X<3;X++){let W=B[12+X],$=B[12+X];for(let Y=0;Y<3;Y++){let Z=B[Y*4+X]*ae.min[Y],j=B[Y*4+X]*ae.max[Y];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=Yr(e,o,u,ne.attributes.POSITION,0,3,re);Yr(e,o,u,ne.attributes.NORMAL,1,3,re),Yr(e,o,u,ne.attributes.TEXCOORD_0,2,2,re,ha(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=e.createBuffer();re.push(W),e.bindBuffer(34963,W),C.componentType===5125?(F=new Uint32Array(u,X,C.count),e.bufferData(34963,F,35044)):C.componentType===5121?(F=Uint16Array.from(new Uint8Array(u,X,C.count)),e.bufferData(34963,F,35044)):(F=X%2===0?new Uint16Array(u,X,C.count):new Uint16Array(u.slice(X,X+C.count*2)),e.bufferData(34963,F,35044))}else E=ae.count;let U={};for(let C of Ue)if(C.onBuildPrimitiveVAO){let B=C.onBuildPrimitiveVAO(e,H,ne,o,u);B&&(U[C.name]=B)}e.bindVertexArray(null);let z=o.materials&&ne.material!==void 0?o.materials[ne.material]:null,{program:K,uniforms:le}=Eo(e,ne,z),ie=Lo(z,h),he=!!(z?.extensions?.KHR_materials_transmission||U.materials?.isTransmissive),T=ne.extensions?.KHR_materials_variants?.mappings,M=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:M,primitiveDef:ne,programCache:new Map([[ne.material??-1,{program:K,uniforms:le}]]),pluginData:U,customProgram:K,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],A=v[0]-y[0],P=v[1]-y[1],k=v[2]-y[2],L=Math.max(Math.hypot(A,P,k)/2,.5),I=[y[0],y[1],y[2]],x=[v[0],v[1],v[2]],g=t.animations;if(!g){for(let S of Ue)if(S.onParseGLB?.(t),t.animations){g=t.animations;break}}return g||(g=[]),{meshes:s,bounds:{center:w,radius:L,min:I,max:x},lights:p,animations:g,worldMatrices:m,gpuTextures:h,availableVariants:c}}function on(e){let t=e.customTarget||e.bounds.center,n=e.currDistance*Math.cos(e.currPhi);return[t[0]+n*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+n*Math.cos(e.currTheta)]}var Xe=class{constructor(t,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=we();this.clearColor=[0,0,0,0];this.envIntensity=1;this.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=t;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let s=t.querySelector("canvas");s||(s=document.createElement("canvas"),s.style.width="100%",s.style.height="100%",s.style.display="block",s.style.touchAction="none",t.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=Zr(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=Lt(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(t,n){aa(t,n)}static getDecoder(t){return qt(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=n=>{n.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,n=Ro();this.renderProg=Qr(t,Mo,n.fs),this.pickProg=Qr(t,la,fa),this.uRender=Jr(t,this.renderProg,n.uniforms),this.uPick=Jr(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let n of Ue)n.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,n,r,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,n,r),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null)}resizePickingFbo(t,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,t),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(t,n){this.lastGlbData=t,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:a,worldMatrices:u,gpuTextures:s,availableVariants:c}=vo(this.gl,t,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=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let f of t.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 Ue)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=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;l!==void 0&&(this.exposure=Zr(l));let m=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.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(t){this.loadGLBData(Ao(t))}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(t){this.loadGLBData(ht(t))}setBackdropGLB(t,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let r=ht(t),{meshes:i}=vo(this.gl,r,Io,()=>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(t,n,r,i=1){this.clearColor=[t,n,r,i]}updateMeshTransforms(t){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;t instanceof Map?i=t.get(r.name)??t.get(n):Array.isArray(t)?i=t[n]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,r.name)?i=t[r.name]:Object.prototype.hasOwnProperty.call(t,n)&&(i=t[n])),i&&i.length===16&&(r.transform.set(i),Ne(r.normalMatrix,r.transform))}}bindLights(t=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(t.uAmbientColor,r),n.uniform1i(t.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(t.uDirLightDir,i),n.uniform3fv(t.uDirLightColor,o)),n.uniform1i(t.uNumPointLights,a.length/3),a.length>0&&(n.uniform3fv(t.uPointLightPos,a),n.uniform3fv(t.uPointLightColor,u)),n.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Zr(t)}getExposure(){return this.exposure}setShadow(t,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Lt(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let n of Ue)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let n of Ue)if(n.setSkyboxImage){await n.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:t,phi:n,radius:r,toString(){return`${t.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((n,r)=>{let i=this.meshes.flatMap(l=>l.primitives.filter(m=>m.materialIndex===r||t.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(t){if(this.animations.length!==0){if(t){let n=this.animations.find(r=>r.name===t);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let n=this.applyVariantMaterial(t);return n&&this.gl&&this.render(),n}applyVariantMaterial(t){let n=t===null||t==="",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(t),r<0)return!1;this.activeVariantName=t}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,Lo(s,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,s??null)}return!0}applyPrimitiveProgram(t,n,r){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let i=n??-1,o=t.programCache.get(i);o||(o=Eo(this.gl,{...t.primitiveDef,material:n},r),t.programCache.set(i,o)),t.customProgram=o.program,t.customUniforms=o.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let n of Ue)if(n.evaluateAnimation){n.evaluateAnimation(this,t);return}}setTarget(t,n,r){this.customTarget=[t,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(t){let n=Math.max(10,Math.min(90,t));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!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(t){t.minTheta!==void 0&&(this.minTheta=t.minTheta*Math.PI/180),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*Math.PI/180),t.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,t.minPhi*Math.PI/180)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,t.maxPhi*Math.PI/180)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){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(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let 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,t))}setCamera(t,n,r,i){t!==void 0&&(this.targetTheta=this.clampTheta(t*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(t,n,r,i){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*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(t,n){let r=we();Le(r,this.projMatrix,this.viewMatrix);let[i,o,a]=t,u=n?n[0]:0,s=n?n[1]:0,c=n?n[2]:0,l=this.modelRootMatrix;l&&(i=l[0]*t[0]+l[4]*t[1]+l[8]*t[2]+l[12],o=l[1]*t[0]+l[5]*t[1]+l[9]*t[2]+l[13],a=l[2]*t[0]+l[6]*t[1]+l[10]*t[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],d=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 h=m/p,y=f/p,v=d/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,A=(h*.5+.5)*b,P=(-y*.5+.5)*w,k=h>=-1.1&&h<=1.1&&y>=-1.1&&y<=1.1&&v>=-1&&v<=1;if(k&&n){let[L,I,x]=on(this),g=[i-L,o-I,a-x];u*g[0]+s*g[1]+c*g[2]>.05&&(k=!1)}return{x:A,y:P,z:v,visible:k}}setSelectedMesh(t){this.selectedMeshName=t||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let t=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},t.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,t.setPointerCapture(n.pointerId))},t.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(t.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)},t.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{t.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=t.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(t.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},t.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)},t.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),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=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}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=this.canvas;this.boundContextLost&&(t.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(t.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(t.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(t.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(t.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(t.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(t.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(t.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(t,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,a=r.height||300,u=i.width>0?Math.floor((t-i.left)*(o/i.width)):Math.floor(t),s=i.height>0?Math.floor((n-i.top)*(a/i.height)):Math.floor(n);return this.performMeshPick(u,s,!1)}performMeshPick(t,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);t=this.mapStereoPickX(t,o);let u=we();Le(u,this.projMatrix,this.viewMatrix);let s=[],c=Math.max(0,Math.min(o-1,t)),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 L=this.meshes[k];if(L.visible===!1||L.isPluginMesh)continue;let I=k+1,x=(I&255)/255,g=(I>>8&255)/255,S=(I>>16&255)/255;i.uniform4f(this.uPick.uColorId,x,g,S,1),Le(this.modelMatrix,this.modelRootMatrix,L.transform);let D=L.instanceMatrices;if(D&&D.length>=16){let _=D.length>>4,O=we();for(let Q of L.primitives){i.bindVertexArray(Q.vao);for(let q=0;q<_;q++)Le(O,this.modelMatrix,D.subarray(q*16,q*16+16)),Le(this.mvpMatrix,u,O),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),zn(i,Q)}}else{Le(this.mvpMatrix,u,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let _ of L.primitives)i.bindVertexArray(_.vao),zn(i,_)}}let A=new Uint8Array(4);i.readPixels(c,l,1,1,6408,5121,A),i.bindFramebuffer(36160,null);let P=A[0]+(A[1]<<8)+(A[2]<<16);P>0&&P<=this.meshes.length&&(s=[this.meshes[P-1]])}s.length===0&&(s=this.meshes.filter(A=>A.visible!==!1));let m=null,f=1/0,d=[0,0,0],p=[0,1,0],[h,y,v]=on(this),R=we();for(let A of s){Le(R,this.modelRootMatrix,A.transform);let P=A.instanceMatrices,k=P&&P.length>=16?P.length>>4:1;for(let L=0;L<k;L++){P&&P.length>=16?Le(this.modelMatrix,R,P.subarray(L*16,L*16+16)):this.modelMatrix.set(R),Le(this.mvpMatrix,u,this.modelMatrix);let I=we();if(!$t(I,this.mvpMatrix))continue;let x=(c+.5)/o*2-1,g=(l+.5)/a*2-1,S=[0,0,0],D=[0,0,0];Br(S,x,g,-1,I),Br(D,x,g,1,I);let _=D[0]-S[0],O=D[1]-S[1],Q=D[2]-S[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 N of A.primitives){if(!N.positions)continue;let G=N.positions,E=N.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,K=E?E[F*3+2]:F*3+2;lo(S[0],S[1],S[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[K*3],G[K*3+1],G[K*3+2],H,ae)}}})(1e-4),isFinite(H.distance)){let ae=H.point[0],N=H.point[1],G=H.point[2],E=this.modelMatrix,V=E[0]*ae+E[4]*N+E[8]*G+E[12],F=E[1]*ae+E[5]*N+E[9]*G+E[13],U=E[2]*ae+E[6]*N+E[10]*G+E[14],z=V-h,K=F-y,le=U-v,ie=Math.hypot(z,K,le);if(ie<f){Ne(this.normalMatrix,this.modelMatrix);let he=this.normalMatrix,T=H.normal[0],M=H.normal[1],C=H.normal[2],B=he[0]*T+he[3]*M+he[6]*C,X=he[1]*T+he[4]*M+he[7]*C,W=he[2]*T+he[5]*M+he[8]*C,$=Math.hypot(B,X,W)||1;B/=$,X/=$,W/=$,B*z+X*K+W*le>0&&(B=-B,X=-X,W=-W),m=A,f=Math.round(ie*1e3)/1e3,d=[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:d,normal:p,screenX:t,screenY:n};if(r){for(let A of Ue)A.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(t,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return t;let r=Math.max(1,Math.floor(n*.5)),i=t>=r,o=i?t-r:t,a=i?Math.max(1,n-r):r,u=(o+.5)/a*2-1;return Math.floor((u*.5+1)*.5*n)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);On(this.projMatrix,this.fov,t,.1,n);let r=this.customTarget||this.bounds.center;Wt(this.viewMatrix,on(this),r,[0,1,0]),Le(this.mvpMatrix,this.projMatrix,this.viewMatrix),Ne(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*t)),i=Math.max(1,Math.floor(n.height*t));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(t){let n=this.xrSessionActive;if(this.xrSessionActive=t,n&&!t){this.xrDepthState.enabled=!1;for(let r of Ue)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let n of Ue)n.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let t=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(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=t,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]=t,o[11]=0,o[12]=r-(t*r+n*i),o[13]=0,o[14]=i-(-n*r+t*i),o[15]=1}setVisible(t){this.isVisible=t}update(t){for(let a of Ue)a.onUpdate?.(this,t);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let a of Ue)a.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let a={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(a),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:a}))}}renderXRView(t,n,r,i,o=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let u=t?.transform?.inverse?.matrix||this.viewMatrix,s=t?.projectionMatrix||this.projMatrix,c=t?.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:t?.eye||"none",clear:a>0?!1:t?.eye!=="right",isAR:o})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let b=Math.max(2,this.canvas.width||2),w=Math.max(1,this.canvas.height||1),A=Math.max(1,Math.floor(b*.5)),P=Math.max(1,b-A),k=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),L=this.customTarget||this.bounds.center,[I,x,g]=on(this),S=Math.cos(this.currTheta),D=-Math.sin(this.currTheta),_=.032,O=we(),Q=we(),q=[I-S*_,x,g-D*_],oe=[L[0]-S*_*.25,L[1],L[2]-D*_*.25];On(O,this.fov,A/w,.1,k),Wt(Q,q,oe,[0,1,0]);let ne=we(),re=we(),H=[I+S*_,x,g+D*_],se=[L[0]+S*_*.25,L[1],L[2]+D*_*.25];On(ne,this.fov,P/w,.1,k),Wt(re,H,se,[0,1,0]),this.render({viewMatrix:Q,projMatrix:O,eyePos:q,viewport:[0,0,A,w],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:re,projMatrix:ne,eyePos:H,viewport:[A,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;t?.viewport?(r=t.viewport[0],i=t.viewport[1],o=t.viewport[2],a=t.viewport[3],n.viewport(r,i,o,a)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!t||t.clear!==!1)&&(t?.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=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=s,Le(u,t?.projMatrix??this.projMatrix,s);let c=ve().xrDepthShader,l=oa(this.toneMapping),[m,f,d]=t?t.eyePos:on(this);for(let b of Ue)b.onBeforeDrawScene?.(this,n,u,[m,f,d],l);let p=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let h=t?.eye||"none",y=!1,v=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,R=b=>{for(let w=0;w<v.length;w++){let A=v[w];if(A.visible===!1)continue;let P=this.selectedMeshName!==""&&A.name===this.selectedMeshName;w<p||A.worldSpace===!0||A.name==="__xr_reticle__"?this.modelMatrix.set(A.transform):Le(this.modelMatrix,this.modelRootMatrix,A.transform),Le(this.mvpMatrix,u,this.modelMatrix),Ne(A.normalMatrix,this.modelMatrix);let k=A.extras?.xr?.stereo||A.userData?.xr?.stereo,L=0,I=0,x=1,g=1;k==="sbs"?(x=.5,L=h==="right"?.5:0):k==="ou"&&(g=.5,I=h==="right"?.5:0);for(let S of A.primitives){let D=!!S.isTransmissive;if(!b&&D){y=!0;continue}if(b&&!D)continue;let _=S.customProgram||this.renderProg,O=S.customUniforms||this.uRender;n.useProgram(_),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,d),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,A.normalMatrix),O.uUvTransform&&n.uniform4f(O.uUvTransform,L,I,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 Ue)q.onBeforeDrawPrimitive?.(n,_,S,A,this.worldMatrices||[],this.gltf);n.uniform4fv(O.uBaseColor,S.baseColor),n.uniform1f(O.uMetallic,S.metallic),n.uniform1f(O.uRoughness,S.roughness),O.uClearcoat&&n.uniform2f(O.uClearcoat,S.clearcoat??0,S.clearcoatRoughness??.04),S.texture?(n.activeTexture(33984),n.bindTexture(3553,S.texture),n.uniform1i(O.uBaseColorTexture,0),n.uniform1i(O.uHasTexture,1)):n.uniform1i(O.uHasTexture,0),S.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,S.metallicRoughnessTexture),n.uniform1i(O.uMetallicRoughnessTexture,1),n.uniform1i(O.uHasMetallicRoughnessTexture,1)):n.uniform1i(O.uHasMetallicRoughnessTexture,0),S.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,S.normalTexture),n.uniform1i(O.uNormalTexture,2),n.uniform1i(O.uHasNormalTexture,1),n.uniform1f(O.uNormalScale,S.normalScale)):n.uniform1i(O.uHasNormalTexture,0),S.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,S.occlusionTexture),n.uniform1i(O.uOcclusionTexture,3),n.uniform1i(O.uHasOcclusionTexture,1),n.uniform1f(O.uOcclusionStrength,S.occlusionStrength)):n.uniform1i(O.uHasOcclusionTexture,0),n.bindVertexArray(S.vao);let Q=A.instanceMatrices;if(Q&&Q.length>=16&&S.instanced&&O.uInstanced&&O.uViewProj){let q=Q.length>>4;n.uniform1i(O.uInstanced,1),n.uniformMatrix4fv(O.uViewProj,!1,u),S.indices?n.drawElementsInstanced(4,S.indexCount,S.indexType,0,q):n.drawArraysInstanced(4,0,S.indexCount,q),n.uniform1i(O.uInstanced,0)}else if(Q&&Q.length>=16){let q=Q.length>>4,oe=A.instanceColors,ne=we(),re=new Float32Array(9),H=[S.baseColor[0],S.baseColor[1],S.baseColor[2],S.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]=S.baseColor[0]*oe[se*3],H[1]=S.baseColor[1]*oe[se*3+1],H[2]=S.baseColor[2]*oe[se*3+2],H[3]=S.baseColor[3],n.uniform4fv(O.uBaseColor,H)),zn(n,S)}else zn(n,S)}}};if(R(!1),y){for(let b of Ue)b.onBeforeTransmissivePass?.(n,this);R(!0)}for(let b of Ue)b.onAfterRender?.(n,this,u)}disposeMeshListGpuResources(t,n){Co(this.gl,t,n)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of Ue)n.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Xe.registerPlugin=Oe,Xe.getRegisteredPlugins=Un;function ba(e){return e+3&-4}function ya(e,t=0){let n=(H,se)=>typeof H=="number"&&Number.isFinite(H)?H:se,r=n(e[t+12],0),i=n(e[t+13],0),o=n(e[t+14],0),a=n(e[t+0],1),u=n(e[t+1],0),s=n(e[t+2],0),c=n(e[t+4],0),l=n(e[t+5],1),m=n(e[t+6],0),f=n(e[t+8],0),d=n(e[t+9],0),p=n(e[t+10],1),h=Math.hypot(a,u,s),y=Math.hypot(c,l,m),v=Math.hypot(f,d,p);a*(l*p-d*m)-c*(u*p-d*s)+f*(u*m-l*s)<0&&(h=-h);let b=Math.abs(h)>1e-8?1/h:0,w=Math.abs(y)>1e-8?1/y:0,A=Math.abs(v)>1e-8?1/v:0,P=a*b,k=u*b,L=s*b,I=c*w,x=l*w,g=m*w,S=f*A,D=d*A,_=p*A,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-D)*H,q=(S-L)*H,oe=(k-I)*H}else if(P>x&&P>_){let H=2*Math.sqrt(Math.max(0,1+P-x-_));H>1e-8&&(ne=(g-D)/H,Q=.25*H,q=(I+k)/H,oe=(S+L)/H)}else if(x>_){let H=2*Math.sqrt(Math.max(0,1+x-P-_));H>1e-8&&(ne=(S-L)/H,Q=(I+k)/H,q=.25*H,oe=(g+D)/H)}else{let H=2*Math.sqrt(Math.max(0,1+_-P-x));H>1e-8&&(ne=(k-I)/H,Q=(S+L)/H,q=(g+D)/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:[h,y,v]}}function ga(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}function Kt(e,t){e.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],a=[],u=[],s=new Set,c=[],l=[],m=new Map,f=[],d=[];function p(I){let x=m.get(I);if(x!==void 0)return x;x=l.length,m.set(I,x);let g=I,S=g.color?.r??.8,D=g.color?.g??.8,_=g.color?.b??.8,O=g.opacity??1,Q={name:g.name||"",pbrMetallicRoughness:{baseColorFactor:[S,D,_,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 h(I,x){let g=new Uint8Array(I.buffer,I.byteOffset,I.byteLength),S=ba(g.byteLength),D=new Uint8Array(S);D.set(g),n.push(D);let _=i.length;return i.push({buffer:0,byteOffset:r,byteLength:g.byteLength,target:x}),r+=S,_}function y(I,x,g,S,D,_,O){let Q=h(I,g),q=o.length,oe={bufferView:Q,byteOffset:0,componentType:S,count:D,type:x};return _&&(oe.min=_),O&&(oe.max=O),o.push(oe),q}e.traverse(I=>{(I.isLight||I.color&&I.intensity!==void 0)&&d.push({type:I.type,color:[I.color.r,I.color.g,I.color.b],intensity:I.intensity,position:[I.position.x,I.position.y,I.position.z]})});let v=[];function R(I){let x={name:I.name||""},g=I.position,S=I.quaternion,D=I.scale;if((g.x||g.y||g.z)&&(x.translation=[g.x,g.y,g.z]),(S.x||S.y||S.z||S.w!==1)&&(x.rotation=[S.x,S.y,S.z,S.w]),(D.x!==1||D.y!==1||D.z!==1)&&(x.scale=[D.x,D.y,D.z]),I.userData&&Object.keys(I.userData).length>0&&(x.extras=JSON.parse(JSON.stringify(I.userData,(O,Q)=>{if(!(O==="__proto__"||O==="prototype"||O==="constructor"))return typeof Q=="function"?void 0:Q})),I.userData.xr)){let O=ga(I.userData.xr);x.extensions={...x.extensions||{},MOZ_hubs_components:O,ANDROID_xr_scenecore:O},ve().xrTraitSerializer?.gltfNode(x,I.userData.xr),s.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(I.geometry){let O=I.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 N=0;N<Q.count;N++){let G=Q.getX(N),E=Q.getY(N),V=Q.getZ(N);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 N=O.index.array instanceof Uint32Array;re.indices=y(O.index.array,"SCALAR",34963,N?5125:5123,O.index.count)}I.material&&(re.material=p(I.material));let H=I.userData?.variants;if(H&&typeof H=="object"){let N=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=N.get(F);U||(U=[],N.set(F,U)),U.push(V)}if(N.size>0){let G=[];for(let[E,V]of N.entries())G.push({material:E,variants:V});re.extensions={...re.extensions||{},KHR_materials_variants:{mappings:G}},s.add("KHR_materials_variants")}}let se=I;if(se.isInstancedMesh&&typeof se.count=="number"&&se.count>0&&se.instanceMatrix?.array){let N=Math.min(1e4,Math.floor(se.count)),G=se.instanceMatrix.array,E=new Float32Array(N*3),V=new Float32Array(N*4),F=new Float32Array(N*3);for(let z=0;z<N;z++){let{t:K,r:le,s:ie}=ya(G,z*16);E[z*3]=K[0],E[z*3+1]=K[1],E[z*3+2]=K[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,N),ROTATION:y(V,"VEC4",0,5126,N),SCALE:y(F,"VEC3",0,5126,N)};if(se.instanceColor?.array&&se.instanceColor.array.length>=N*3){let z=new Float32Array(se.instanceColor.array.subarray(0,N*3));U._COLOR_0=y(z,"VEC3",0,5126,N)}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:I.name,...x.extras?{extras:x.extras}:{}}),x.mesh=ae}}let _=u.length;if(u.push(x),c.push(I),I.children.length>0){x.children=[];for(let O of I.children)x.children.push(R(O))}return _}for(let I of e.children)v.push(R(I));let b=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),w=[];if(typeof b=="function"&&c.length>0){let I=t?.duration??4,x=t?.fps??15,g=Math.max(2,Math.round(I*x)+1),S=new Float32Array(g),D=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)*I;S[H]=se;try{b(se)}catch{}for(let ae=0;ae<c.length;ae++){let N=c[ae];_[ae][H*3]=N.position.x,_[ae][H*3+1]=N.position.y,_[ae][H*3+2]=N.position.z,O[ae][H*4]=N.quaternion.x,O[ae][H*4+1]=N.quaternion.y,O[ae][H*4+2]=N.quaternion.z,O[ae][H*4+3]=N.quaternion.w,Q[ae][H*3]=N.scale.x,Q[ae][H*3+1]=N.scale.y,Q[ae][H*3+2]=N.scale.z}}for(let H=0;H<c.length;H++){let se=c[H],ae=D[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)}e.updateMatrixWorld(!0);let q=null,oe=()=>(q===null&&(q=y(S,"SCALAR",0,5126,g,[0],[I])),q),ne=[],re=[];for(let H=0;H<c.length;H++){let se=D[H],ae=!1,N=!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)&&(N=!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(N){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 A=oo(u,a,e.userData),P={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:v}],scene:0,nodes:u,meshes:a,materials:l,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...w.length>0?{animations:w}:{},...A||s.size>0?{extensionsUsed:[...A?["KHR_interactivity"]:[],...s]}:{},...A||f.length>0?{extensions:{...A?{KHR_interactivity:A}:{},...f.length>0?{KHR_materials_variants:{variants:f.map(I=>({name:I}))}}:{}}}:{}},k=new Uint8Array(r),L=0;for(let I of n)k.set(I,L),L+=I.byteLength;return{gltf:P,bin:k.buffer,lights:d,environmentIntensity:e.environmentIntensity}}function Hn(e){return new TextEncoder().encode(e)}function sn(e,t){let{gltf:n,bin:r}=Kt(e,t),i=JSON.stringify(n),o=Hn(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 xa(e,t){e.updateMatrixWorld(!0);let n=[];return e.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 L=0;L<a;L++){let I=o.getX(L),x=o.getY(L),g=o.getZ(L);u[L*3]=s[0]*I+s[4]*x+s[8]*g+s[12],u[L*3+1]=s[1]*I+s[5]*x+s[9]*g+s[13],u[L*3+2]=s[2]*I+s[6]*x+s[10]*g+s[14]}let c;if(i.attributes.normal){let L=i.attributes.normal;c=new Float32Array(a*3);let I=new Float32Array(9);Ne(I,s);for(let x=0;x<a;x++){let g=L.getX(x),S=L.getY(x),D=L.getZ(x),_=I[0]*g+I[3]*S+I[6]*D,O=I[1]*g+I[4]*S+I[7]*D,Q=I[2]*g+I[5]*S+I[8]*D,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 L=i.attributes.uv;l=new Float32Array(a*2);for(let I=0;I<a;I++)l[I*2]=L.getX(I),l[I*2+1]=L.getY(I)}let m;if(i.index)m=i.index.array;else{m=a>65535?new Uint32Array(a):new Uint16Array(a);for(let L=0;L<a;L++)m[L]=L}let f="DefaultMaterial",d=[.8,.8,.8],p=.5,h=.1,y=0,v=0,R=1.5,b=1,w=[0,0,0];if(r.material){let L=r.material;f=L.name||`Material_${n.length}`,L.color&&(d=[L.color.r,L.color.g,L.color.b]),typeof L.roughness=="number"&&(p=L.roughness),typeof L.metalness=="number"&&(h=L.metalness),typeof L.clearcoat=="number"&&(y=L.clearcoat),typeof L.clearcoatRoughness=="number"&&(v=L.clearcoatRoughness),typeof L.ior=="number"&&(R=L.ior);let I=typeof L.opacity=="number"?L.opacity:1,x=typeof L.transmission=="number"?L.transmission:0;if(b=I*(1-x),L.emissive&&(L.emissive.r>0||L.emissive.g>0||L.emissive.b>0)){let g=L.emissiveIntensity??1;w=[L.emissive.r*g,L.emissive.g*g,L.emissive.b*g]}}let A,P=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);if(typeof P=="function"){let L=t?.duration??4,I=t?.fps??4,x=Math.max(2,Math.round(L*I)+1),g=[],S=[],D=[],_=[],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)*L;g.push(re);try{P(re)}catch{}S.push([r.position.x,r.position.y,r.position.z]),D.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&&(A={times:g,translations:S,rotations:D,scales:_})}let k=r;if(k.isInstancedMesh&&typeof k.count=="number"&&k.count>0&&k.instanceMatrix?.array){let L=Math.min(1e3,Math.floor(k.count)),I=k.instanceMatrix.array,x=k.instanceColor?.array,g=r.name||`Mesh_${n.length}`,S=new Float32Array(16),D=new Float32Array(9);for(let _=0;_<L;_++){let O=I.subarray(_*16,(_+1)*16);Le(S,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]=S[0]*H+S[4]*se+S[8]*ae+S[12],Q[re*3+1]=S[1]*H+S[5]*se+S[9]*ae+S[13],Q[re*3+2]=S[2]*H+S[6]*se+S[10]*ae+S[14]}let q;if(i.attributes.normal){let re=i.attributes.normal;q=new Float32Array(a*3),Ne(D,S);for(let H=0;H<a;H++){let se=re.getX(H),ae=re.getY(H),N=re.getZ(H),G=D[0]*se+D[3]*ae+D[6]*N,E=D[1]*se+D[4]*ae+D[7]*N,V=D[2]*se+D[5]*ae+D[8]*N,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=d,ne=f;x&&x.length>=(_+1)*3&&(oe=[d[0]*x[_*3],d[1]*x[_*3+1],d[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:h,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:d,roughness:p,metallic:h,clearcoat:y,clearcoatRoughness:v,ior:R,opacity:b,emissiveColor:w,xrTraits:r.userData?.xr,timeSamples:A})}}),n}function Do(e){let t=[],n=e.gltf,r=ve().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,e);let i=e.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 h=a[p];if(!h)throw new Error(`Accessor ${p} not found`);let y=u[h.bufferView||0],v=(y.byteOffset||0)+(h.byteOffset||0),R=y.byteLength||0,b=o.slice(v,v+R);return{acc:h,buffer:b}}let f=new Map;if(l.length>0){let p=dt(n);for(let h=0;h<p.length;h++)f.set(h,p[h])}function d(p,h,y,v){let R=c[p];if(!R)return;let b=new Float32Array(9);Ne(b,h);for(let w=0;w<(R.primitives||[]).length;w++){let A=R.primitives[w],P=A.attributes?.POSITION;if(P===void 0)continue;let{acc:k,buffer:L}=m(P),I=new Float32Array(L,0,k.count*3),x=new Float32Array(I.length);for(let E=0;E<k.count;E++){let V=I[E*3],F=I[E*3+1],U=I[E*3+2];x[E*3]=h[0]*V+h[4]*F+h[8]*U+h[12],x[E*3+1]=h[1]*V+h[5]*F+h[9]*U+h[13],x[E*3+2]=h[2]*V+h[6]*F+h[10]*U+h[14]}let g,S=A.attributes?.NORMAL;if(S!==void 0){let{acc:E,buffer:V}=m(S),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],K=F[U*3+1],le=F[U*3+2],ie=b[0]*z+b[3]*K+b[6]*le,he=b[1]*z+b[4]*K+b[7]*le,T=b[2]*z+b[5]*K+b[8]*le,M=Math.hypot(ie,he,T)||1;g[U*3]=ie/M,g[U*3+1]=he/M,g[U*3+2]=T/M}}let D,_=A.attributes?.TEXCOORD_0;if(_!==void 0){let{acc:E,buffer:V}=m(_);D=new Float32Array(V,0,E.count*2)}let O;if(A.indices!==void 0){let{acc:E,buffer:V}=m(A.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,N=[0,0,0];if(A.material!==void 0&&s[A.material]){let E=s[A.material];Q=E.name||`Material_${A.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&&(N=[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;t.push({name:G,positions:x,indices:O,normals:g,uvs:D,materialName:Q,color:q,roughness:oe,metallic:ne,clearcoat:re,clearcoatRoughness:H,ior:se,opacity:ae,emissiveColor:N,xrTraits:v?.xr||R.extras?.xr})}}if(l.length>0)for(let p=0;p<l.length;p++){let h=l[p];if(h.mesh!==void 0&&h.mesh<c.length){let y=f.get(p)||we(),v=h.name||c[h.mesh].name||`Node_${p}`,R=h.extensions?.EXT_mesh_gpu_instancing?.attributes;if(R&&typeof R=="object"){let b=R.TRANSLATION,w=R.ROTATION,A=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,L=A!==void 0?(()=>{let{acc:x,buffer:g}=m(A);return new Float32Array(g,0,x.count*3)})():null,I=Math.min(1e3,P?P.length/3:k?k.length/4:L?L.length/3:0);if(I>0){let x=new Float32Array(16),g=new Float32Array(16);for(let S=0;S<I;S++){let D=P?[P[S*3],P[S*3+1],P[S*3+2]]:[0,0,0],_=k?[k[S*4],k[S*4+1],k[S*4+2],k[S*4+3]]:[0,0,0,1],O=L?[L[S*3],L[S*3+1],L[S*3+2]]:[1,1,1];Je(x,_,D,O),Le(g,y,x),d(h.mesh,g,`${v}_${S}`,h.extras)}continue}}d(h.mesh,y,v,h.extras)}}else{let p=we();for(let h=0;h<c.length;h++){let y=c[h].name||`Mesh_${h}`;d(h,p,y,c[h].extras)}}return t}function ei(e,t){if(!e||typeof e!="string")return t;let n=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||t}function Po(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Me(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}function ko(e){let t=e.length/3,n=new Array(t);for(let r=0;r<t;r++)n[r]=`(${Me(e[r*3])}, ${Me(e[r*3+1])}, ${Me(e[r*3+2])})`;return n.join(", ")}function va(e,t){let n=new Array(t);for(let r=0;r<t;r++)n[r]=`(${Me(e[r*2])}, ${Me(1-e[r*2+1])})`;return n.join(", ")}function Ta(e){return Array.from(e).join(", ")}function ti(e){let t=new Map;for(let s of e){let c=ei(s.materialName,"DefaultMaterial");t.has(c)||t.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 e){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
252
- endTimeCode = ${Me(n)}
253
+ void main(){fragColor=uColorId;}`;function Qr(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var go=["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 So(){let t=ve().xrDepthShader;return{fs:ca.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...go,...t.uniformNames]:go}}function fa(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 Yr(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(),yo(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 Zr(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Ro(t,e,n){let r=So(),i=Mo,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?Qr(t,u,r.uniforms):null}}function ma(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 da(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 Eo=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),_o=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 Lo(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 Io(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 xo(t,e,n=_o,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ha(t,e,n,r,i)}catch(o){let a=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Io(t,a,i.gpuTextures),i.vao&&t.deleteVertexArray(i.vao);for(let u of i.buffers)t.deleteBuffer(u);throw o}}function ha(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=fa(_.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=ma(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=Yr(t,o,u,ne.attributes.POSITION,0,3,re);Yr(t,o,u,ne.attributes.NORMAL,1,3,re),Yr(t,o,u,ne.attributes.TEXCOORD_0,2,2,re,da(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}=Ro(t,ne,z),ie=Lo(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=Zr(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){sa(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=So();this.renderProg=St(e,Mo,n.fs),this.pickProg=St(e,ua,la),this.uRender=Qr(e,this.renderProg,n.uniforms),this.uPick=Qr(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}=xo(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=Zr(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(wo(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}=xo(this.gl,r,_o,()=>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=Zr(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,Lo(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=Ro(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];Br(A,x,g,-1,L),Br(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;lo(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=ia(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){Io(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 pa(t){return t+3&-4}function ba(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 ya(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=pa(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=ya(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}=ba(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=oo(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 ga(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 ko(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 Jr(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 Co(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 Po(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 xa(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 va(t){return Array.from(t).join(", ")}function ei(t){let e=new Map;for(let s of t){let c=Jr(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)}
253
255
  timeCodesPerSecond = 1.0
254
256
  `);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
255
257
  uniform token preliminary:planeAnchoring:alignment = "${r}"
@@ -266,19 +268,19 @@ kind = "component"
266
268
  {
267
269
  ${o}def Scope "Materials"
268
270
  {
269
- `;for(let[s,c]of t.entries()){let[l,m,f]=c.color,[d,p,h]=c.emissiveColor,y="";c.clearcoat>0&&(y+=`float inputs:clearcoat = ${Me(c.clearcoat)}
270
- `,y+=`float inputs:clearcoatRoughness = ${Me(c.clearcoatRoughness)}
271
- `),c.ior!==1.5&&(y+=`float inputs:ior = ${Me(c.ior)}
272
- `),c.opacity<1&&(y+=`float inputs:opacity = ${Me(c.opacity)}
273
- `),(d>0||p>0||h>0)&&(y+=`color3f inputs:emissiveColor = (${Me(d)}, ${Me(p)}, ${Me(h)})
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)})
274
276
  `),a+=`def Material "${s}"
275
277
  {
276
278
  def Shader "PBRShader"
277
279
  {
278
280
  uniform token info:id = "UsdPreviewSurface"
279
- color3f inputs:diffuseColor = (${Me(l)}, ${Me(m)}, ${Me(f)})
280
- float inputs:metallic = ${Me(c.metallic)}
281
- float inputs:roughness = ${Me(c.roughness)}
281
+ color3f inputs:diffuseColor = (${Ae(l)}, ${Ae(m)}, ${Ae(f)})
282
+ float inputs:metallic = ${Ae(c.metallic)}
283
+ float inputs:roughness = ${Ae(c.roughness)}
282
284
  ${y}token outputs:surface
283
285
  }
284
286
  token outputs:surface.connect = </Root/Materials/${s}/PBRShader.outputs:surface>
@@ -286,9 +288,9 @@ token outputs:surface.connect = </Root/Materials/${s}/PBRShader.outputs:surface>
286
288
  `}a+=`}
287
289
  def Scope "Meshes"
288
290
  {
289
- `;let u=new Set;for(let s=0;s<e.length;s++){let c=e[s],l=c.positions.length/3,m=1/0,f=1/0,d=1/0,p=-1/0,h=-1/0,y=-1/0;for(let k=0;k<l;k++){let L=c.positions[k*3],I=c.positions[k*3+1],x=c.positions[k*3+2];L<m&&(m=L),L>p&&(p=L),I<f&&(f=I),I>h&&(h=I),x<d&&(d=x),x>y&&(y=x)}isFinite(m)||(m=f=d=-1,p=h=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":"",A=c.xrTraits,P="";if(A){let k=[];A.physics&&A.physics!=="none"&&k.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let L=ve().xrTraitSerializer?.usdLines(A,Po)??[];if(!L.length)for(let I of["grab","billboard","follow","anchor","physics"]){let x=I==="follow"&&typeof A.follow=="object"?A.follow.mode??"head":A[I];x!==void 0&&L.push(`string ${I} = "${Po(x)}"`)}L.length>0&&k.push(`customData = {
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=Jr(c.materialName,"DefaultMaterial"),b=Jr(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,Co)??[];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} = "${Co(x)}"`)}I.length>0&&k.push(`customData = {
290
292
  dictionary xr = {
291
- ${L.join(`
293
+ ${I.join(`
292
294
  `)}
293
295
  }
294
296
  }`),k.length>0&&(P=` (
@@ -296,57 +298,57 @@ ${k.join(`
296
298
  `)}
297
299
  )`)}if(a+=`def Mesh "${b}"${P}
298
300
  {
299
- `,A?.physics&&A.physics!=="none"){let k=A.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
301
+ `,M?.physics&&M.physics!=="none"){let k=M.physics==="static"?"true":"false";a+=`bool physics:rigidBodyEnabled = true
300
302
  bool physics:kinematicEnabled = ${k}
301
303
  bool physics:collisionEnabled = true
302
- `}if(c.timeSamples&&c.timeSamples.times.length>0){let k=c.timeSamples,L=k.times.map((g,S)=>{let D=k.translations?.[S]||[0,0,0];return`${Me(g)}: (${Me(D[0])}, ${Me(D[1])}, ${Me(D[2])})`}).join(", "),I=k.times.map((g,S)=>{let D=k.rotations?.[S]||[0,0,0,1];return`${Me(g)}: (${Me(D[3])}, ${Me(D[0])}, ${Me(D[1])}, ${Me(D[2])})`}).join(", "),x=k.times.map((g,S)=>{let D=k.scales?.[S]||[1,1,1];return`${Me(g)}: (${Me(D[0])}, ${Me(D[1])}, ${Me(D[2])})`}).join(", ");a+=`double3 xformOp:translate.timeSamples = { ${L} }
303
- quatf xformOp:orient.timeSamples = { ${I} }
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} }
304
306
  double3 xformOp:scale.timeSamples = { ${x} }
305
307
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
306
- `}a+=`float3[] extent = [(${Me(m)}, ${Me(f)}, ${Me(d)}), (${Me(p)}, ${Me(h)}, ${Me(y)})]
308
+ `}a+=`float3[] extent = [(${Ae(m)}, ${Ae(f)}, ${Ae(h)}), (${Ae(p)}, ${Ae(d)}, ${Ae(y)})]
307
309
  int[] faceVertexCounts = [${w}]
308
- int[] faceVertexIndices = [${Ta(c.indices)}]
309
- point3f[] points = [${ko(c.positions)}]
310
- `,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${ko(c.normals)}] (
310
+ int[] faceVertexIndices = [${va(c.indices)}]
311
+ point3f[] points = [${Po(c.positions)}]
312
+ `,c.normals&&c.normals.length===c.positions.length&&(a+=`normal3f[] normals = [${Po(c.normals)}] (
311
313
  interpolation = "vertex"
312
314
  )
313
- `),c.uvs&&c.uvs.length===l*2&&(a+=`texCoord2f[] primvars:st = [${va(c.uvs,l)}] (
315
+ `),c.uvs&&c.uvs.length===l*2&&(a+=`texCoord2f[] primvars:st = [${xa(c.uvs,l)}] (
314
316
  interpolation = "vertex"
315
317
  )
316
318
  `),a+=`rel material:binding = </Root/Materials/${R}>
317
319
  }
318
320
  `}return a+=`}
319
321
  }
320
- `,a}function No(e,t){if(e&&typeof e.traverse=="function"){let i=xa(e,t);return ti(i)}let n=ht(e),r=Do(n);return ti(r)}var Gn=null;function Uo(e){if(!Gn){Gn=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;Gn[n]=r}}let t=4294967295;for(let n=0;n<e.length;n++)t=Gn[(t^e[n])&255]^t>>>8;return(t^4294967295)>>>0}function ni(e){let t=[],n=0,r=[];for(let l of e){let m=Hn(l.filename),f=Uo(l.data),d=l.data.length,p=30+m.length,h=n+p,y=0,v=h%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,d,!0),b.setUint32(22,d,!0),b.setUint16(26,m.length,!0),b.setUint16(28,y,!0),R.set(m,30),y>0&&R.fill(0,30+m.length),t.push({offset:n,size:d,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 t){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,t.length,!0),u.setUint16(10,t.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 Yt(e){let t=No(e),n=Hn(t);return ni([{filename:"model.usda",data:n}])}function an(e){let t=ht(e),n=Do(t),r=ti(n),i=Hn(r);return ni([{filename:"model.usda",data:i}])}function cn(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():e&&typeof e.traverse=="function"?Yt(e):an(e)}function Zt(e){let t=cn(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function pt(e,t,n,r){let i=typeof e=="number"&&Number.isFinite(e)?e:r;return Math.max(t,Math.min(n,i))}function wa(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function ri(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Aa(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function Fo(e){let t=ri(e);if(!t)return null;let n=t.target;return{target:wa(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:pt(t.radius,.01,50,.5),speed:pt(t.speed,-20,20,.5),height:pt(t.height,-10,10,0),phase:pt(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}function Xn(e,t){let n=Aa(e,16)?.trim();if(!n)return t;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:t}function ii(e){if(e===!1||e===null||e===void 0)return null;if(typeof e=="number")return!Number.isFinite(e)||e<=0?null:{enabled:!0,strength:pt(e,0,5,.35),threshold:.8,radius:.5};if(e===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let t=ri(e);if(!t||t.enabled===!1)return null;let n=pt(t.strength??t.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:pt(t.threshold,0,4,.8),radius:pt(t.radius,0,2,.5)}}function Wn(e){if(!e)return null;if(typeof e=="string")return{enabled:!0,color:Xn(e,"#38bdf8"),thickness:3,pulse:!1};if(e===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let t=ri(e);if(!t||t.enabled===!1)return null;let n=t.thickness??t.width;return{enabled:!0,color:Xn(t.color,"#38bdf8"),thickness:pt(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:t.pulse===!0}}var jn=class e{constructor(t=0,n=0){this.x=Number(t),this.y=Number(n)}set(t,n){return this.x=Number(t),this.y=Number(n),this}clone(){return new e(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}},Fe=class e{constructor(t=0,n=0,r=0){this.x=Number(t),this.y=Number(n),this.z=Number(r)}set(t,n,r){return this.x=Number(t),this.y=Number(n),this.z=Number(r),this}clone(){return new e(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addVectors(t,n){return this.x=t.x+n.x,this.y=t.y+n.y,this.z=t.z+n.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,n){return this.x=t.x-n.x,this.y=t.y-n.y,this.z=t.z-n.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5&&(this.x/=t,this.y/=t,this.z/=t),this}cross(t){let n=this.y*t.z-this.z*t.y,r=this.z*t.x-this.x*t.z,i=this.x*t.y-this.y*t.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(t,n){let r=t.x,i=t.y,o=t.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(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)}applyMatrix4(t){let n=this.x,r=this.y,i=this.z,o=t.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(t=0,n=0,r=0,i=1){this.x=Number(t),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(t,n,r,i){return this.x=Number(t),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},mn=class e{constructor(t=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(t),this._y=Number(n),this._z=Number(r),this.order=i}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,n,r,i=this.order){return this._x=Number(t),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this.order=t.order,this._onChangeCallback?.(),this}clone(){return new e(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},dn=class e{constructor(t=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(t),this._y=Number(n),this._z=Number(r),this._w=Number(i)}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,n,r,i){return this._x=Number(t),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback?.(),this}clone(){return new e(this._x,this._y,this._z,this._w)}setFromEuler(t,n=!0){let r=t.x,i=t.y,o=t.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(t,n){let r=n/2,i=Math.sin(r);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,n){let r=t.x,i=t.y,o=t.z,a=t.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(t){return this._onChangeCallback=t,this}},Ct=class e{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 e;return t.copy(this),t}compose(t,n,r){return Je(this.elements,[n.x,n.y,n.z,n.w],[t.x,t.y,t.z],[r.x,r.y,r.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,n){return Le(this.elements,t.elements,n.elements),this}lookAt(t,n,r){return Wt(this.elements,[t.x,t.y,t.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(t){let n=new Fe(0,0,0),r=new Fe(1,1,1);return this.compose(n,t,r)}makeTranslation(t,n,r){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(t,n,r){return this.identity(),this.elements[0]=Number(t),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 t=this.elements;return t.fill(0),t[0]=1,t[4]=1,t[8]=1,this}getNormalMatrix(t){return Ne(this.elements,t.elements),this}},et=class e{constructor(t,n,r){this.r=1;this.g=1;this.b=1;t!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(t,n,r):this.set(t))}set(t){if(typeof t=="number")this.setHex(t);else if(typeof t=="string")if(t.startsWith("#")){let n=parseInt(t.slice(1),16);this.setHex(n)}else t==="red"?this.setRGB(1,0,0):t==="green"?this.setRGB(0,1,0):t==="blue"?this.setRGB(0,0,1):t==="white"?this.setRGB(1,1,1):t==="black"&&this.setRGB(0,0,0);else t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b));return this}setHex(t){let n=Math.floor(t);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(t,n,r){return this.r=Number(t),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(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new e(this.r,this.g,this.b)}},Xo={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,n)=>Math.max(t,Math.min(n,e)),lerp:(e,t,n)=>e+(t-e)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},Se=class{constructor(t,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(t)?this.array=new Float32Array(t):this.array=t,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(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,n){return this.array[t*this.itemSize]=n,this.needsUpdate=!0,this}setY(t,n){return this.array[t*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(t,n){return this.array[t*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(t,n,r,i){let o=t*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},Yn=class extends Se{constructor(t,n){super(t instanceof Float32Array?t:new Float32Array(t),n)}},Zn=class extends Se{constructor(t,n){super(t instanceof Uint16Array?t:new Uint16Array(t),n)}},Qn=class extends Se{constructor(t,n){super(t instanceof Uint32Array?t:new Uint32Array(t),n)}},Ye=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(t,n){return this.attributes[t]=n,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof Se)this.index=t;else if(Array.isArray(t)){let n=t.length,r=0;for(let o=0;o<n;o++)t[o]>r&&(r=t[o]);let i=r>65535?new Uint32Array(n):new Uint16Array(n);for(let o=0;o<n;o++)i[o]=t[o];this.index=new Se(i,1)}else t&&t.buffer&&(this.index=new Se(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let n=t.count,r=new Float32Array(n*3),i=new Fe,o=new Fe,a=new Fe,u=new Fe,s=new Fe;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],d=c[l+2];i.set(t.getX(m),t.getY(m),t.getZ(m)),o.set(t.getX(f),t.getY(f),t.getZ(f)),a.set(t.getX(d),t.getY(d),t.getZ(d)),u.subVectors(a,o),s.subVectors(i,o),u.cross(s).normalize();for(let p of[m,f,d])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(t.getX(c),t.getY(c),t.getZ(c)),o.set(t.getX(c+1),t.getY(c+1),t.getZ(c+1)),a.set(t.getX(c+2),t.getY(c+2),t.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],d=Math.hypot(l,m,f)||1;r[c*3]=l/d,r[c*3+1]=m/d,r[c*3+2]=f/d}return this.setAttribute("normal",new Se(r,3)),this}setFromBuffers(t,n,r,i){this.setAttribute("position",new Se(t instanceof Float32Array?t:new Float32Array(t),3)),this.setAttribute("normal",new Se(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new Se(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let t=this.attributes.position,n=new Fe(1/0,1/0,1/0),r=new Fe(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let i=0;i<t.count;i++){let o=t.getX(i),a=t.getY(i),u=t.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 t=this.computeBoundingBox(),n=(t.min.x+t.max.x)*.5,r=(t.min.y+t.max.y)*.5,i=(t.min.z+t.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(){}},hn=class extends Ye{constructor(t=1,n=1,r=1){super();let i=t/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=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],l=[];for(let m=0;m<6;m++){let f=m*4;l.push(f,f+1,f+2,f,f+2,f+3)}this.setAttribute("position",new Se(new Float32Array(u),3)),this.setAttribute("normal",new Se(new Float32Array(s),3)),this.setAttribute("uv",new Se(new Float32Array(c),2)),this.setIndex(l)}},Jn=class extends Ye{constructor(t=1,n=1){super();let r=t/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],a=[0,0,1,0,0,1,0,0,1,0,0,1],u=[0,1,1,1,0,0,1,0],s=[0,2,1,2,3,1];this.setAttribute("position",new Se(new Float32Array(o),3)),this.setAttribute("normal",new Se(new Float32Array(a),3)),this.setAttribute("uv",new Se(new Float32Array(u),2)),this.setIndex(s)}},pn=class extends Ye{constructor(t=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=[],s=[];for(let c=0;c<=r;c++){let l=[],m=c/r;for(let f=0;f<=n;f++){let d=f/n,p=d*Math.PI*2,h=m*Math.PI,y=-t*Math.cos(p)*Math.sin(h),v=t*Math.cos(h),R=t*Math.sin(p)*Math.sin(h);i.push(y,v,R);let b=Math.hypot(y,v,R)||1;o.push(y/b,v/b,R/b),a.push(d,1-m),l.push(i.length/3-1)}s.push(l)}for(let c=0;c<r;c++)for(let l=0;l<n;l++){let m=s[c][l+1],f=s[c][l],d=s[c+1][l],p=s[c+1][l+1];c!==0&&u.push(m,f,p),c!==r-1&&u.push(f,d,p)}this.setAttribute("position",new Se(new Float32Array(i),3)),this.setAttribute("normal",new Se(new Float32Array(o),3)),this.setAttribute("uv",new Se(new Float32Array(a),2)),this.setIndex(u)}},Et=class extends Ye{constructor(t=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?t:n,d=l===0?c:-c;for(let p=0;p<=i;p++){let h=p/i,y=h*Math.PI*2,v=Math.sin(y),R=Math.cos(y);o.push(f*v,d,f*R),a.push(v,0,R),u.push(h,1-m)}}for(let l=0;l<i;l++){let m=l,f=l+i+1,d=l+i+2,p=l+1;s.push(m,f,p,f,d,p)}if(t>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 d=f/i*Math.PI*2,p=Math.sin(d),h=Math.cos(d);o.push(t*p,c,t*h),a.push(0,1,0),u.push(h*.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 d=f/i*Math.PI*2,p=Math.sin(d),h=Math.cos(d);o.push(n*p,-c,n*h),a.push(0,-1,0),u.push(h*.5+.5,1-(p*.5+.5))}for(let f=0;f<i;f++)s.push(l,m+f+1,m+f)}this.setAttribute("position",new Se(new Float32Array(o),3)),this.setAttribute("normal",new Se(new Float32Array(a),3)),this.setAttribute("uv",new Se(new Float32Array(u),2)),this.setIndex(s)}},er=class extends Et{constructor(t=1,n=1,r=16){super(0,t,n,r)}},tr=class extends Ye{constructor(t=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],a=[],u=[],s=[];for(let c=0;c<=r;c++){let l=c/r*Math.PI*2;for(let m=0;m<=i;m++){let f=m/i*Math.PI*2,d=(t+n*Math.cos(l))*Math.cos(f),p=(t+n*Math.cos(l))*Math.sin(f),h=n*Math.sin(l);o.push(d,p,h);let y=t*Math.cos(f),v=t*Math.sin(f),R=d-y,b=p-v,w=h,A=Math.hypot(R,b,w)||1;a.push(R/A,b/A,w/A),u.push(m/i,c/r)}}for(let c=1;c<=r;c++)for(let l=1;l<=i;l++){let m=(i+1)*c+l-1,f=(i+1)*(c-1)+l-1,d=(i+1)*(c-1)+l,p=(i+1)*c+l;s.push(m,f,p,f,d,p)}this.setAttribute("position",new Se(new Float32Array(o),3)),this.setAttribute("normal",new Se(new Float32Array(a),3)),this.setAttribute("uv",new Se(new Float32Array(u),2)),this.setIndex(s)}},nr=class extends Ye{constructor(t=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 Fe,f=new Fe,d=new Fe,p=new Fe,h=new Fe;function y(b,w){let A=Math.cos(w),P=Math.sin(w),k=a/o*w,L=t*(2+Math.cos(k))*.5;b.set(L*A,L*P,t*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,A=w*o*Math.PI*2;y(m,A),y(f,A+.01),d.subVectors(f,m).normalize(),p.addVectors(m,f).normalize(),h.crossVectors(d,p).normalize(),p.crossVectors(h,d).normalize();for(let P=0;P<=i;++P){let k=P*3,L=v[k],I=v[k+1],x=v[k+2],g=L*p.x+I*h.x,S=L*p.y+I*h.y,D=L*p.z+I*h.z;u.push(m.x+g,m.y+S,m.z+D);let _=Math.hypot(g,S,D)||1;s.push(g/_,S/_,D/_),c.push(w,x)}}let R=i+1;for(let b=1;b<=r;b++){let w=R*(b-1),A=w+R;for(let P=1;P<=i;P++){let k=w+(P-1),L=A+(P-1),I=A+P,x=w+P;l.push(k,L,x,L,I,x)}}this.setAttribute("position",new Se(new Float32Array(u),3)),this.setAttribute("normal",new Se(new Float32Array(s),3)),this.setAttribute("uv",new Se(new Float32Array(c),2)),this.setIndex(l)}},bn=class{constructor(t=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},rr=class{load(t,n){let r=new bn(t);return n?.(r),r}};function $e(e,t){return e!==void 0?Number(e):t}function oi(e,t){return e!==void 0?!!e:t}var at=class{constructor(t={}){this.name=t.name||"",this.color=new et(t.color!==void 0?t.color:16777215),this.emissive=new et(t.emissive!==void 0?t.emissive:0),this.emissiveIntensity=$e(t.emissiveIntensity,1),this.roughness=$e(t.roughness,.5),this.metalness=$e(t.metalness,.1),this.opacity=$e(t.opacity,1),this.transparent=oi(t.transparent,!1),this.wireframe=oi(t.wireframe,!1),this.side=$e(t.side,2),this.doubleSided=oi(t.doubleSided,!0),this.map=t.map||null,this.clearcoat=$e(t.clearcoat,0),this.clearcoatRoughness=$e(t.clearcoatRoughness,0),this.sheen=$e(t.sheen,0),this.sheenColor=new et(t.sheenColor!==void 0?t.sheenColor:0),this.sheenRoughness=$e(t.sheenRoughness,0),this.transmission=$e(t.transmission,0),this.thickness=$e(t.thickness,0),this.attenuationColor=new et(t.attenuationColor!==void 0?t.attenuationColor:16777215),this.attenuationDistance=$e(t.attenuationDistance,1/0),this.ior=$e(t.ior,1.5),this.dispersion=$e(t.dispersion,0),this.iridescence=$e(t.iridescence,0),this.iridescenceIOR=$e(t.iridescenceIOR,1.3)}dispose(){}},Pt=class extends at{},ir=class extends at{},or=class extends at{},sr=class extends at{},ar=class extends at{},tt=class e{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 Fe,this.rotation=new mn,this.quaternion=new dn,this.scale=new Fe(1,1,1),this.matrix=new Ct,this.matrixWorld=new Ct,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,n=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),i=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(n,r,i)})}add(...t){for(let n of t)n&&n instanceof e&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...t){for(let n of t){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(t){t(this);for(let n of this.children)n.traverse(t)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){Wo(this),(this.matrixAutoUpdate||t)&&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(t)}lookAt(t,n,r){let i=typeof t=="object"?t:new Fe(t,n,r);this.updateMatrixWorld(!0);let o=new Ct;o.lookAt(this.position,i,new Fe(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],d=a[2],p=a[6],h=a[10],y=u+m+h;if(y>0){let v=.5/Math.sqrt(y+1);this.quaternion.set((p-f)*v,(c-d)*v,(l-s)*v,.25/v)}}},cr=class extends tt{},kt=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 hn(.5,.5,.5)):new Ye,this.material=i instanceof at?i:i?(Ze("unsupported material","MeshStandardMaterial"),new Pt({color:13421772})):new Pt}};function Wo(e){let t=ve().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var yn=1e4,gn=class extends kt{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>yn)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${yn})`);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 Se(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 Se(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(t=16777215,n=1){super(),this.color=new et(t),this.intensity=Number(n),this.type="directional"}},xn=class extends Dt{constructor(t,n){super(t,n),this.type="ambient"}},ur=class extends Dt{constructor(n,r){super(n,r);this.target=new tt;this.type="directional"}},vn=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}},Tn=class extends tt{},lr=class extends Tn{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Fe(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},wn=class extends tt{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return st.validate(this),Kt(this)}toGLB(){return st.validate(this),sn(this)}toUSDZ(){return st.validate(this),Yt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof kt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},si=Kt,ai=sn,$o=Yt;var st=class{static validate(t){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};t.traverse(s=>{if(Wo(s),s instanceof kt||s.geometry?.attributes?.position?.count){if(i++,i>1e3&&a("MESHES",1e3,i),s instanceof gn){let l=u("instance",s.count);(l<0||l>yn)&&a("INSTANCES",yn,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 d=Math.min(m,f.length);for(let p=0;p<d;p++){let h=f[p];if(!Number.isFinite(h)||h<0||h>=l)throw new Error(`SecurityError: Index buffer value (${String(h)}) 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(t={}){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=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||n,this.containerId=t.containerId||""}setSize(t,n){return this}setPixelRatio(t){return this}setClearColor(t,n=1){let r=new et(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(t,n){if(this.isSandboxed){st.validate(t);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=t.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=si(t),a=ai(t),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(t.getMeshTransforms()):(r.loadModel(t.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Oo(){return typeof globalThis<"u"&&typeof globalThis.__three_live_sim_time_ms__=="number"?globalThis.__three_live_sim_time_ms__:typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}var mr=class{constructor(t=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=t,t&&this.start()}start(){this.startTime=Oo(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=Oo();t=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=t}return t}};function Ma(){}var ln=new Proxy(Ma,{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:ln},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>ln,construct:()=>ln}),Vo=(()=>{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 Qt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function _t(e,t){if(!e||typeof e!="string")return!1;let n=e.trim();if(!n)return!1;try{let r=new URL(n,Qt());return!(r.protocol!=="https:"&&r.protocol!=="http:"&&r.protocol!=="blob:"||t?.requireSameOrigin&&r.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&r.origin!==location.origin)}catch{return!1}}var Bo,un;function jo(e){if(!_t(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return e;if(un===void 0||Bo!==n){Bo=n;try{un=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!_t(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{un=null}}return un?un.createScriptURL(e):e}function Sa(e){ve().sandboxEngineSrc=e}function ci(){let e=ve().sandboxEngineSrc;if(e)return e;if(Vo)return Vo;try{if(typeof document>"u")return null;let t=Qt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&&_t(i,{requireSameOrigin:!0}))return i}}catch{}return null}function Ra(){let e=ci();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.");if(!_t(e))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Qt()).href}function Ea(e){ve().sandboxIframeSrc=e}function qo(){let e=ve().sandboxIframeSrc;if(e)return e;let t=ci();if(!t||!_t(t))return null;let n=new URL(t,Qt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function _a(){let e=qo();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.");if(!_t(e))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Qt()).href}function Ia(e){ve().allowClientScripts=e}function Ko(){return!!ve().allowClientScripts}function La(e){if(!_t(e))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,Qt()).href}var Ca=["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 Pa(e,t){let n=self,r=e.nonce,i=e.engineSrc,o=e.allowedScriptUrl,a=e.allowClientScripts,u=e.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(I){if(I!==i&&(!o||I!==o))throw new TypeError("Disallowed worker importScripts URL");return I}};a&&(k.createScript=function(I){return String(I)});let L=n.trustedTypes.createPolicy("three-live#worker-boot",k);P=L.createScriptURL(i),o&&(m=L.createScriptURL(o)),a&&typeof L.createScript=="function"&&(f=L.createScript.bind(L))}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 d=n.THREE;if(!d||typeof d.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(t)){let P=n.__THREE_LIVE_REGISTRY__;for(let k=0;k<t.length;k++)if(typeof t[k]=="function")try{t[k](d,P)}catch{}}for(let P=0;P<u.length;P++){let k=u[P],L=n;for(;L&&L!==Object.prototype;){if(L!==n)try{delete L[k]}catch{}try{Object.defineProperty(L,k,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{L=Object.getPrototypeOf(L)}catch{break}}}let p=Object.freeze({now:function(){return Date.now()}}),h=n;for(;h&&h!==Object.prototype;){if(h!==n)try{delete h.performance}catch{}try{Object.defineProperty(h,"performance",{value:p,writable:!1,configurable:!1,enumerable:!1})}catch{}try{h=Object.getPrototypeOf(h)}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 A=!1;n.onmessage=function(P){let k=P&&P.data;if(!(!k||k.nonce!==r)&&!(k.type!=="EXECUTE"&&k.type!=="EXECUTE_URL")&&!A){A=!0;try{let L=new d.Scene,I=new d.PerspectiveCamera(60,1,.1,1e3),x=new d.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,S=l;if(l=null,m=null,n.THREE=d,n.scene=L,n.camera=I,n.renderer=x,S(g),typeof n.__THREE_LIVE_SCENE__=="function"){let D=n.__THREE_LIVE_SCENE__(d,L,I,x);D&&typeof D.toGLB=="function"&&(L=D)}else n.scene&&typeof n.scene.toGLB=="function"&&(L=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) {
322
+ `,a}function No(t,e){if(t&&typeof t.traverse=="function"){let i=ga(t,e);return ei(i)}let n=ht(t),r=ko(n);return ei(r)}var Hn=null;function Do(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 ti(t){let e=[],n=0,r=[];for(let l of t){let m=Xn(l.filename),f=Do(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=No(t),n=Xn(e);return ti([{filename:"model.usda",data:n}])}function cn(t){let e=ht(t),n=ko(e),r=ei(n),i=Xn(r);return ti([{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 Ta(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function ni(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function wa(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Uo(t){let e=ni(t);if(!e)return null;let n=e.target;return{target:Ta(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 ri(t,e){let n=wa(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 ii(t){if(!t||typeof t=="number"&&!(t>0&&Number.isFinite(t)))return null;let e=t===!0?{}:typeof t=="number"?{strength:t}:ni(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}:ni(t);if(!e||e.enabled===!1)return null;let n=e.thickness??e.width;return{enabled:!0,color:ri(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)}},Ho={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 oi(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=oi(e.transparent,!1),this.wireframe=oi(e.wireframe,!1),this.side=We(e.side,2),this.doubleSided=oi(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){Xo(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 Xo(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}},si=Yt,ai=an,Wo=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(Xo(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=si(e),a=ai(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 Oo(){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=Oo(),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=Oo();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Ma(){}var fn=new Proxy(Ma,{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}),Fo=(()=>{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 Vo,ln;function $o(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||Vo!==n){Vo=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 Aa(t){ve().sandboxEngineSrc=t}function ci(){let t=ve().sandboxEngineSrc;if(t)return t;if(Fo)return Fo;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 Sa(){let t=ci();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 Ra(t){ve().sandboxIframeSrc=t}function jo(){let t=ve().sandboxIframeSrc;if(t)return t;let e=ci();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 Ea(){let t=jo();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 _a(t){ve().allowClientScripts=t}function qo(){return!!ve().allowClientScripts}function La(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 Ia=["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 Ca(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) {
321
323
  return (function () {
322
324
  `+k.script+`
323
325
  })();
324
326
  })`)):new Function("THREE","scene","camera","renderer",`return (function () {
325
327
  `+k.script+`
326
- })();`);f=null;let S=g(d,L,I,x);S&&typeof S.toGLB=="function"&&(L=S)}if(!v){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(L);let g=L.toGLB(),S=g instanceof ArrayBuffer?g:g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);R({type:"3D_MODEL_READY",glbBuffer:S},[S])}s({type:"DONE",nonce:r})}catch(L){c(L&&L.message||L)}}},s({type:"READY",nonce:r})}function ui(e,t,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:t,engineSrc:e,allowedScriptUrl:r,allowClientScripts:i,revoked:Ca},a=(ve().workerExtensionInstallers??[]).map(u=>`(${u.toString()})`).join(",");return`'use strict';(${Pa.toString()})(${JSON.stringify(o)},[${a}]);`}function Yo(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 Rt=0;function Zo(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function ka(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Da=1024,Na=256;function zo(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let n=e[t];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function li(e,t){if(!e||typeof e!="object")return null;let n=e;if(n.nonce!==t)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,Da)};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>Na||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 Ua(e){let t=ka(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Qo(e,t,n,r){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":n();return;case"ERROR":n(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Fa(e,t,n,r){let i=Zo(),o=ui(t,i,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.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,Rt++;let u=!1,s=!1,c={modelDispatched:!1},l,m=()=>{if(u||s)return;let h=a.contentWindow;!h||typeof h.postMessage!="function"||(s=!0,h.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:e.script},"*"))},f=()=>{},d=h=>{if(u||!a.contentWindow||h.source!==a.contentWindow)return;let y=h.data;if(y&&typeof y=="object"&&y.type==="IFRAME_READY"){m();return}let v=li(y,i);v&&Qo(v,r,f,c)};f=()=>{u||(u=!0,l!==void 0&&clearTimeout(l),Rt=Math.max(0,Rt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),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",d),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 h=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(h),h}return p.appendChild(a),{terminate:f}}function Go(e,t,n,r){if(t==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Rt>=32)return r(`SecurityError: ${Rt} 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=Ra()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let f;try{f=_a()}catch(d){let p=d instanceof Error?d.message:String(d);return r(p,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Fa(e,i,f,n))}catch(d){return Promise.reject(d)}}let o=Zo(),a=ui(i,o,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),u;try{let f=new Blob([a],{type:"application/javascript"}),d=URL.createObjectURL(f);try{let p=jo(d);u=new Worker(p)}finally{URL.revokeObjectURL(d)}}catch(f){let d=f instanceof Error?f.message:String(f);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}Rt++;let s=!1,c={modelDispatched:!1},l,m=()=>{s||(s=!0,l!==void 0&&clearTimeout(l),Rt=Math.max(0,Rt-1),u.terminate())};return l=setTimeout(()=>{s||(m(),Yo(n))},3e3),u.onmessage=f=>{let d=li(f.data,o);d&&Qo(d,n,m,c)},u.onerror=f=>{m(),n.onError?.(new Error(`Worker execution error: ${f.message}`))},e.kind==="url"?u.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:o}):u.postMessage({type:"EXECUTE",script:e.script,nonce:o}),Promise.resolve({terminate:m})}function Ho(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 Jt={execute(e,t,n,r){let i=(u,s)=>{let c=new Error(u);return n.onError?.(c),s&&n.onToast?.(s),Promise.reject(c)},o=Ho(t,i);if(o)return o;try{Ua(e)}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:e},t,n,i):i(Pn,kn)},executeUrl(e,t,n){let r=(a,u)=>{let s=new Error(a);return n.onError?.(s),u&&n.onToast?.(u),Promise.reject(s)},i=Ho(t,r);if(i)return i;let o;try{o=La(e)}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},t,n,r)}},dr=new Set;function Ze(e,t){let n=`[three-live] ${e} is unsupported; degraded to ${t}.`;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 Pt{constructor(t={}){Ze("ShaderMaterial","MeshStandardMaterial");let n=t.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??t.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=n}},ts=An,Nt=class extends pn{constructor(t=1,n=0,r="PolyhedronGeometry"){Ze(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(t,i,i)}},hr=class extends Nt{constructor(t=1,n=0){super(t,n,"IcosahedronGeometry")}},pr=class extends Nt{constructor(t=1,n=0){super(t,n,"OctahedronGeometry")}},br=class extends Nt{constructor(t=1,n=0){super(t,n,"DodecahedronGeometry")}},yr=class extends Nt{constructor(t=1,n=0){super(t,n,"TetrahedronGeometry")}},gr=class extends Et{constructor(t=1,n=1,r=4,i=8){Ze("CapsuleGeometry","CylinderGeometry"),super(t,t,n+t*2,i)}},xr=class extends Et{constructor(t=.5,n=1,r=16){Ze("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},vr=class extends Et{constructor(t=1,n=16){Ze("CircleGeometry","CylinderGeometry"),super(t,t,.01,Math.max(8,n))}},Tr=class extends vn{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}},Mn=class extends xn{constructor(t,n,r){Ze("HemisphereLight","AmbientLight"),super(t,r),this.groundColor=new et(n??4473924)}},ns=Mn,rs={Vector2:jn,Vector3:Fe,Vector4:qn,Euler:mn,Quaternion:dn,Matrix4:Ct,Matrix3:Kn,Color:et,MathUtils:Xo,BufferAttribute:Se,Float32BufferAttribute:Yn,Uint16BufferAttribute:Zn,Uint32BufferAttribute:Qn,BufferGeometry:Ye,BoxGeometry:hn,PlaneGeometry:Jn,SphereGeometry:pn,CylinderGeometry:Et,ConeGeometry:er,TorusGeometry:tr,TorusKnotGeometry:nr,IcosahedronGeometry:hr,OctahedronGeometry:pr,DodecahedronGeometry:br,TetrahedronGeometry:yr,CapsuleGeometry:gr,RingGeometry:xr,CircleGeometry:vr,Texture:bn,TextureLoader:rr,Material:at,MeshStandardMaterial:Pt,MeshBasicMaterial:ir,MeshLambertMaterial:or,MeshPhongMaterial:sr,MeshPhysicalMaterial:ar,ShaderMaterial:An,RawShaderMaterial:ts,Object3D:tt,Group:cr,Mesh:kt,InstancedMesh:gn,Light:Dt,AmbientLight:xn,DirectionalLight:ur,PointLight:vn,SpotLight:Tr,HemisphereLight:Mn,RectAreaLight:ns,Camera:Tn,PerspectiveCamera:lr,Scene:wn,WebGLRenderer:fr,Clock:mr,SceneQuotaValidator:st,exportSceneToCanvas3D:si,exportSceneToGLB:ai,exportSceneToUSDZ:$o,generateUSDZ:cn,glbToUSDZ:an,sceneToCanvas3D:Kt,sceneToGLB:sn,sceneToUSDZ:Yt,authorScriptRunner:Jt,getAuthorWarnings:Jo,clearAuthorWarnings:es};Object.freeze(st);Object.freeze(st.prototype);Object.freeze(wn.prototype);Object.freeze(rs);var Ut=new Proxy(rs,{get:(e,t)=>{if(t in e)return e[t];let n=ve().authorNamespace;return n&&typeof t=="string"&&t in n?n[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Ze(`THREE.${t}`,"no-op proxy"),ln)},has:(e,t)=>{if(t in e)return!0;let n=ve().authorNamespace;return!!(n&&typeof t=="string"&&t in n)},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")}}),$n=ve();$n.threeNamespace=Ut;if($n.workerExtensionInstallers)for(let e of $n.workerExtensionInstallers)e(Ut,$n);var fn={name:"three_author",THREE:Ut},Oa=fn,bt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof bt.THREE>"u"&&(bt.THREE=Ut);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__||Ze("requestAnimationFrame","single-frame static evaluation"),0));typeof bt.cancelAnimationFrame!="function"&&(bt.cancelAnimationFrame=()=>{});if(typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=Ut,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=fn,e.ThreeLivePlugins.three_author=fn,e.ThreeLivePlugins["three-author"]=fn}function en(e,t){let n=e?.trim(),r=n?Number(n):NaN;return Number.isFinite(r)?r:t}var Va=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 ze=class ze extends Va{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){ze.scriptRunner=n}static registerDecoder(n,r){Xe.registerDecoder(n,r)}static getDecoder(n){return Xe.getDecoder(n)}static registerAR(n){typeof n=="function"?ze.arProvider={activateAR:n}:ze.arProvider=n,typeof document<"u"&&document.querySelectorAll("three-live").forEach(i=>{i instanceof ze&&i.updateARButtonVisibility()})}static isARSupported(){return!!ze.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 Xe.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let n of Xe.getRegisteredPlugins())n.onElementDisconnected?.(this);this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.activeXRSession&&(this.activeXRSession.stop?.().catch?.(()=>{}),this.activeXRSession=null),this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),this.viewer&&(this.viewer.destroy(),this.viewer=null),this.isModelLoaded=!1}attributeChangedCallback(n,r,i){if(r!==i){switch(n){case"src":i&&this.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(Lt(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 Xe.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")||ze.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 ze.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 Lt(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 en(this.getAttribute("bloom-threshold"),.62)}set bloomThreshold(n){this.setAttribute("bloom-threshold",String(n))}get bloomRadius(){return en(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():[]}selectVariant(n){if(!this.viewer)return!1;let r=this.viewer.selectVariant(n);return r&&this.dispatchEvent(new CustomEvent("variant-applied",{bubbles:!0,composed:!0,detail:{variantName:this.viewer.getVariantName()}})),r}get model(){let n=this.viewer?this.viewer.getModelMaterials():[];return{materials:n,getMaterialByName(r){return n.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(n=0){this.viewer?.resetTurntableRotation(n)}setCamera(n,r,i,o){this.viewer&&this.viewer.setCamera(n,r,i,o)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():{x:0,y:0,z:0,toString(){return"0m 0m 0m"}}}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(n,r){return this.viewer&&this.viewer.render?.(),this.canvas?this.canvas.toDataURL(n,r):""}toBlob(n){return this.viewer&&this.viewer.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(o=>{o?r(o):i(new Error("Failed to capture canvas blob."))},n?.mimeType,n?.qualityArgument)})}positionAndNormalFromPoint(n,r){if(!this.viewer)return null;let i=this.viewer.raycastFromScreenPoint(n,r);if(!i)return null;let[o,a,u]=i.hitPoint||i.point,[s,c,l]=i.normal;return{position:{x:o,y:a,z:u,toString(){return`${o}m ${a}m ${u}m`}},normal:{x:s,y:c,z:l,toString(){return`${s}m ${c}m ${l}m`}}}}async loadModel(n){return this.loadModelWithLimits(n)}async loadModelWithLimits(n,r){if(!this.viewer){this.currentModel=n,this.currentModelLimits=r;return}try{let i;if(typeof n=="string"){this.isModelLoaded=!1,this.viewer?.clearScene?.();let 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.updateHotspots();let a=this.getAttribute("selected-mesh");a&&this.viewer.setSelectedMesh(a);let u=this.getAttribute("variant-name");u&&this.selectVariant(u),this.dispatchEvent(new CustomEvent("load",{bubbles:!0,composed:!0,detail:{model:o}}))}catch(i){throw this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),i}}showToast(n,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=n,this.toastTimer&&(clearTimeout(this.toastTimer),this.toastTimer=null),typeof requestAnimationFrame<"u"?requestAnimationFrame(()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")}):(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)"),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){if(this.activeXRSession&&typeof this.activeXRSession.isSessionActive=="function"&&this.activeXRSession.isSessionActive()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null),!this.currentModel){let i=new Error("No 3D model is loaded in <three-live>.");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}if(!ze.arProvider){let i=new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR().");throw this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(i.message,6e3),i}let n=this.getAttribute("ios-src"),r=(this.getAttribute("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"session-started"}}));let i=await ze.arProvider.activateAR({model:n||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:r.length>0?r:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"not-presenting"}}))},onError:o=>{this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:o}})),this.showToast(`AR error: ${o.message}`,6e3)}}});if(i.success)i.session&&(this.activeXRSession=i.session),i.mode==="quick-look"?this.showToast("Opening Apple AR Quick Look..."):i.mode==="scene-viewer"?this.showToast("Opening Google Scene Viewer..."):i.mode==="webxr"&&this.showToast("WebXR AR session started.");else{let o=typeof navigator<"u"&&navigator.userAgent||"",a=/Macintosh/i.test(o)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),u=/Android|iPhone|iPad|iPod/i.test(o);if(a&&!u&&typeof document<"u"&&this.currentModel&&ze.arProvider.createUSDZBlob)try{let s=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:ze.arProvider.createUSDZBlob(this.currentModel),c=URL.createObjectURL(s),l=document.createElement("a");l.href=c,l.download="three_live_model.usdz",document.body.appendChild(l),l.click(),document.body.removeChild(l),setTimeout(()=>URL.revokeObjectURL(c),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3)}else this.showToast(i.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.",6e3);i.error&&this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i.error}}))}return i}catch(i){throw this.activeXRSession=null,this.dispatchEvent(new CustomEvent("ar-status",{bubbles:!0,composed:!0,detail:{status:"failed",error:i}})),this.showToast(`AR error: ${i.message||String(i)}`,6e3),i}}setupDOM(){let n=this.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction=this.cameraControls?"none":"auto",n.style.outline="none",this.appendChild(n)),this.canvas=n;let r=this.getAttribute("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let n=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),o=this.parseOrbitLimit(this.getAttribute("max-camera-orbit")),a=this.parseCameraTarget(this.getAttribute("camera-target")),u=this.parseFieldOfView(this.getAttribute("field-of-view"));this.viewer=new Xe(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.dispatchEvent(new CustomEvent("meshclick",{bubbles:!0,composed:!0,detail:c}))},onCameraChange:c=>{this.updateHotspots();for(let l of Xe.getRegisteredPlugins())l.onCameraChange?.(this.viewer,this);this.dispatchEvent(new CustomEvent("camera-change",{bubbles:!0,composed:!0,detail: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.position="absolute",this.posterEl.style.inset="0",this.posterEl.style.width="100%",this.posterEl.style.height="100%",this.posterEl.style.objectFit="cover",this.posterEl.style.transition="opacity 0.35s ease-out",this.posterEl.style.pointerEvents="none",this.posterEl.style.zIndex="1",this.appendChild(this.posterEl)),this.posterEl.src=n,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let n=document.createElement("button");n.setAttribute("type","button"),n.setAttribute("aria-label","View in Augmented Reality"),n.className="three-live-ar-button",n.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let o=document.createElementNS(r,"svg");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("fill","none"),o.setAttribute("stroke","currentColor"),o.setAttribute("stroke-width","2"),o.setAttribute("stroke-linecap","round"),o.setAttribute("stroke-linejoin","round"),o.style.marginRight="6px";let a=document.createElementNS(r,"path");a.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z");let u=document.createElementNS(r,"polyline");u.setAttribute("points","3.27 6.96 12 12.01 20.73 6.96");let s=document.createElementNS(r,"line");s.setAttribute("x1","12"),s.setAttribute("y1","22.08"),s.setAttribute("x2","12"),s.setAttribute("y2","12"),o.appendChild(a),o.appendChild(u),o.appendChild(s),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")&&!!ze.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=n.trim().split(/\s+/),i={};if(r.length>0&&r[0]!=="auto"){let o=this.parseFieldOfView(r[0]);o!==void 0&&(i.theta=o)}if(r.length>1&&r[1]!=="auto"){let o=this.parseFieldOfView(r[1]);o!==void 0&&(i.phi=o)}if(r.length>2&&r[2]!=="auto"){let o=parseFloat(r[2].replace(/m$/,""));isNaN(o)||(i.distance=o)}return i}applyOrbitLimits(){if(!this.viewer)return;let n=this.parseOrbitLimit(this.getAttribute("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttribute("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:n.theta,maxTheta:r.theta,minPhi:n.phi,maxPhi:r.phi,minDistance:n.distance,maxDistance:r.distance})}parseCameraTarget(n){if(!n)return;let r=n.trim().split(/\s+/).map(i=>parseFloat(i.replace(/m$/,"")));return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(n){if(!n)return;let r=n.endsWith("rad")?parseFloat(n)*180/Math.PI:parseFloat(n.replace(/deg$/,""));return isNaN(r)?void 0:r}parseRotationPerSecond(n){if(!n)return Math.PI/6;let r=n.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(n){let r=this.parseCameraTarget(n);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(n){let r=this.parseFieldOfView(n);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(n){let r=this.querySelector(`[slot="${n.name}"]`);r&&(n.position!==void 0&&r.setAttribute("data-position",n.position),n.normal!==void 0&&r.setAttribute("data-normal",n.normal)),this.updateHotspots()}updateHotspots(){for(let n of Xe.getRegisteredPlugins())if(n.updateHotspotsForElement){n.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(n){let r=ze.scriptRunner;if(!r){let i=new Error('Procedural script execution requires "three-live/full" or ThreeLiveElement.registerScriptRunner().');return this.showToast(i.message),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:i}})),Promise.reject(i)}return this.scriptHandle&&(this.scriptHandle.terminate(),this.scriptHandle=null),this.isModelLoaded=!1,this.viewer?.clearScene?.(),new Promise((i,o)=>{let a=!1;n(r,{onModelReady: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.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:s}})),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(!ze.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Pn);return this.showToast(kn),this.dispatchEvent(new CustomEvent("error",{bubbles:!0,composed:!0,detail:{error:r}})),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(n,this.sandbox,i,{allowClientScripts:!0}))}};ze.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"],ze.registerPlugin=Xe.registerPlugin,ze.getRegisteredPlugins=Xe.getRegisteredPlugins;var ct=ze;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",ct);function is(e,t,n){return t%4===0?new Float32Array(e,t,n):new Float32Array(e.slice(t,t+n*4))}function Ar(e,t,n,r){let i=t[0],o=t[1],a=t[2],u=t[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 e[0]=i,e[1]=o,e[2]=a,e[3]=u,e;let d=Math.acos(f),p=Math.sqrt(1-f*f);if(Math.abs(p)<.001)return e[0]=.5*(i+s),e[1]=.5*(o+c),e[2]=.5*(a+l),e[3]=.5*(u+m),e;let h=Math.sin((1-r)*d)/p,y=Math.sin(r*d)/p;return e[0]=i*h+s*y,e[1]=o*h+c*y,e[2]=a*h+l*y,e[3]=u*h+m*y,e}function os(e,t,n,r){return e[0]=t[0]+r*(n[0]-t[0]),e[1]=t[1]+r*(n[1]-t[1]),e[2]=t[2]+r*(n[2]-t[2]),e}function hi(e,t){if(!Array.isArray(e?.animations))return[];let n=[];for(let r=0;r<e.animations.length;r++){let i=e.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=e.accessors?.[c.input],m=e.accessors?.[c.output];if(!l||!m)continue;let f=e.bufferViews?.[l.bufferView],d=e.bufferViews?.[m.bufferView];if(!f||!d)continue;let p=(f.byteOffset||0)+(l.byteOffset||0),h=(d.byteOffset||0)+(m.byteOffset||0),y=ot(e,t,l,1)??is(t,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(e,t,m,R)??is(t,h,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 tn(e,t,n){let{times:r,values:i,path:o,interpolation:a}=e,u=r.length;if(u===0)return;let s=o==="rotation"?4:o==="weights"?Math.max(1,Math.round(i.length/u)):3;if(t<=r[0]){for(let R=0;R<s;R++)n[R]=i[R];return}if(t>=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]<=t?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 d=r[m],p=r[f],h=(t-d)/Math.max(1e-5,p-d),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]];Ar(n,R,b,h)}else for(let R=0;R<s;R++)n[R]=i[y+R]+h*(i[v+R]-i[y+R])}var wr=new WeakMap;function pi(e,t,n=.3){if(!e?.animations)return;let r=e.animations.find(u=>u.name===t);if(!r)return;let i=wr.get(e);i||(i=[],e.currentClip&&i.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),wr.set(e,i));let o=n>0?1/n:1e3;for(let u of i)u.clip.name!==t&&(u.fadeSpeed=-o);let a=i.find(u=>u.clip.name===t);a?a.fadeSpeed=o:i.push({clip:r,time:0,weight:n>0?0:1,fadeSpeed:o}),e.currentClip=r,e.isPlayingAnimation=!0}function di(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let n=wr.get(e);if(!n||n.length===0){if(!e.currentClip)return;n=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let r=e.gltf.nodes.length,i=[];for(let m=0;m<r;m++){let f=e.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 d of m.clip.channels){if(d.nodeIndex<0||d.nodeIndex>=r)continue;let p=i[d.nodeIndex];if(d.path==="translation")tn(d,m.time,o),os(p.t,p.t,o,f);else if(d.path==="rotation")tn(d,m.time,a),Ar(p.r,p.r,a,f);else if(d.path==="scale")tn(d,m.time,u),os(p.s,p.s,u,f);else if(d.path==="weights"&&(tn(d,m.time,s),e.meshes)){for(let h of e.meshes)if(h.nodeIndex===d.nodeIndex){for(let y of h.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:d,r:p,s:h}=i[m];Je(f,p,d,h),c.push(f)}let l=dt(e.gltf,c);e.worldMatrices=l;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<l.length&&(m.transform.set(l[m.nodeIndex]),Ne(m.normalMatrix,m.transform))}var bi={name:"keyframes",evaluateAnimation:di,crossFadeTo:pi,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=hi(e.gltf,e.bin))},onUpdate(e,t){if(!e.isPlayingAnimation)return;let n=wr.get(e);if(n&&n.length>0){for(let r=n.length-1;r>=0;r--){let i=n[r];if(i.time+=t,i.clip.duration>0&&(i.time%=i.clip.duration),i.fadeSpeed!==0)if(i.weight+=i.fadeSpeed*t,i.weight<=0){n.splice(r,1);continue}else i.weight>=1&&(i.weight=1,i.fadeSpeed=0)}n.length>0&&(e.animationTime=n[n.length-1].time),di(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),di(e,e.animationTime))}};var Sn=64;function ss(e,t,n){if(!(!e?.meshes||t<0||t>=Sn))for(let r of e.meshes)for(let i of r.primitives){let o=i.pluginData?.morph;o?.weights&&(o.weights[t]=n)}}var yi={name:"morph",onResolveShader(e,t,n,r){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let i=n.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
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 ui(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:Ia},a=(ve().workerExtensionInstallers??[]).map(u=>`(${u.toString()})`).join(",");return`'use strict';(${Ca.toString()})(${JSON.stringify(o)},[${a}]);`}function Ko(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 Yo(){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 Pa(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var ka=1024,Na=256;function Bo(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 li(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,ka)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!Bo(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>Na||s==="__proto__"||s==="constructor"||s==="prototype")return null;let c=u[s];if(!Bo(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 Da(t){let e=Pa(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Zo(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 Ua(t,e,n,r){let i=Yo(),o=ui(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=li(y,i);v&&Zo(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(),Ko(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 zo(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=Sa()}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=Ea()}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(Ua(t,i,f,n))}catch(h){return Promise.reject(h)}}let o=Yo(),a=ui(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=$o(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(),Ko(n))},3e3),u.onmessage=f=>{let h=li(f.data,o);h&&Zo(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 Go(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=Go(e,i);if(o)return o;try{Da(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??qo()?zo({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=Go(e,r);if(i)return i;let o;try{o=La(t)}catch(a){let u=a instanceof Error?a.message:String(a);return r(u,"Security Error: disallowed scene script URL.")}return zo({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 Qo(){return Array.from(dr)}function Jo(){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}},es=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)}},ts=Sn,ns={Vector2:jn,Vector3:Ue,Vector4:qn,Euler:dn,Quaternion:hn,Matrix4:Pt,Matrix3:Kn,Color:et,MathUtils:Ho,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:es,Object3D:tt,Group:cr,Mesh:Nt,InstancedMesh:xn,Light:Dt,AmbientLight:vn,DirectionalLight:ur,PointLight:Tn,SpotLight:Tr,HemisphereLight:Sn,RectAreaLight:ts,Camera:wn,PerspectiveCamera:lr,Scene:Mn,WebGLRenderer:fr,Clock:mr,SceneQuotaValidator:st,exportSceneToCanvas3D:si,exportSceneToGLB:ai,exportSceneToUSDZ:Wo,generateUSDZ:un,glbToUSDZ:cn,sceneToCanvas3D:Yt,sceneToGLB:an,sceneToUSDZ:Zt,authorScriptRunner:en,getAuthorWarnings:Qo,clearAuthorWarnings:Jo};Object.freeze(st);Object.freeze(st.prototype);Object.freeze(Mn.prototype);Object.freeze(ns);var Ot=new Proxy(ns,{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},Oa=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 fi=(t,e,n)=>({x:t,y:e,z:n,toString:()=>`${t}m ${e}m ${n}m`}),Fa=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 Fa{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():fi(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:fi(o,a,u),normal:fi(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,Eo).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 rs(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 is(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 pi(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)??rs(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)??rs(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 bi(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 hi(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),is(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),is(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 yi={name:"keyframes",evaluateAnimation:hi,crossFadeTo:bi,onParseGLB(t){!t.animations&&t.gltf?.animations&&(t.animations=pi(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),hi(t,t.animationTime)}else t.currentClip&&(t.animationTime+=e,t.currentClip.duration>0&&(t.animationTime%=t.currentClip.duration),hi(t,t.animationTime))}};var Rn=64;function os(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 gi={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;
327
329
  uniform sampler2D uMorphDeltasTex;
328
- uniform float uMorphWeights[${Sn}];
330
+ uniform float uMorphWeights[${Rn}];
329
331
  uniform int uNumMorphTargets;`);return i=i.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
330
- for (int m = 0; m < ${Sn}; m++) {
332
+ for (int m = 0; m < ${Rn}; m++) {
331
333
  if (m >= uNumMorphTargets) break;
332
334
  float w = uMorphWeights[m];
333
335
  if (abs(w) > 0.0001) {
334
336
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
335
337
  }
336
338
  }
337
- 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(e,t,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,Sn),l=new Float32Array(s*c*4);for(let d=0;d<c;d++){let p=o[d].POSITION;if(p===void 0)continue;let h=r.accessors?.[p],y=r.bufferViews?.[h?.bufferView];if(!h||!y)continue;let v=ot(r,i,h,3);if(!v||v.length<s*3)continue;let R=d*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=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,s,c,0,6408,5126,l),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let f=new Float32Array(Sn);return{hasMorph:!0,morphTex:m,numTargets:c,vertexCount:s,weights:f}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=n.pluginData?.morph;if(!a?.hasMorph||!a.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,a.morphTex);let u=e.getUniformLocation(t,"uMorphDeltasTex");u&&e.uniform1i(u,5);let s=e.getUniformLocation(t,"uNumMorphTargets");s&&e.uniform1i(s,a.numTargets);let c=e.getUniformLocation(t,"uMorphWeights[0]");c&&e.uniform1fv(c,a.weights)}};var gi=64,xi={name:"skinning",onResolveShader(e,t,n,r){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let i=n.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
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 xi=64,vi={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;
338
340
  layout(location=4) in uvec4 aJoints;
339
341
  layout(location=5) in vec4 aWeights;
340
- uniform mat4 uJointMatrix[${gi}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
342
+ uniform mat4 uJointMatrix[${xi}];`),o=i.includes("morphedPos")?"morphedPos":"aPosition";return i=i.replace(`vec4 world=uModel*vec4(${o},1.0);`,`mat4 skinMatrix =
341
343
  aWeights.x * uJointMatrix[int(aJoints.x)] +
342
344
  aWeights.y * uJointMatrix[int(aJoints.y)] +
343
345
  aWeights.z * uJointMatrix[int(aJoints.z)] +
344
346
  aWeights.w * uJointMatrix[int(aJoints.w)];
345
- 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(e,t,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=e.createBuffer();e.bindBuffer(34962,f);let d=a.componentType===5121?5121:5123,p=d===5121?new Uint8Array(i,l,a.count*4):new Uint16Array(i,l,a.count*4);e.bufferData(34962,p,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,d,0,0);let h=e.createBuffer();e.bindBuffer(34962,h);let y=ot(r,i,u,4)??new Float32Array(i,m,u.count*4);return e.bufferData(34962,y,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[f,h]}},onBeforeDrawPrimitive(e,t,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(gi*16);for(let m=0;m<s.length&&m<gi;m++){let f=s[m],d=i[f]||we();c.subarray(m*16,(m+1)*16).set(d)}let l=e.getUniformLocation(t,"uJointMatrix[0]");l&&e.uniformMatrix4fv(l,!1,c)}};Oe(yi);Oe(bi);Oe(xi);Oe(Kr);Oe(Vr);var Ba=`#version 300 es
346
- 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.);}`,za=`#version 300 es
347
- precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Rn=new WeakMap,as=new Float32Array(20);function vi(e,t){let[n,r,i,o,a,u]=t;return[e[0]*n+e[4]*r+e[8]*i+e[12],e[1]*n+e[5]*r+e[9]*i+e[13],e[2]*n+e[6]*r+e[10]*i+e[14],Math.abs(e[0])*o+Math.abs(e[4])*a+Math.abs(e[8])*u,Math.abs(e[1])*o+Math.abs(e[5])*a+Math.abs(e[9])*u,Math.abs(e[2])*o+Math.abs(e[6])*a+Math.abs(e[10])*u]}function Ga(e){if(e._lb!==void 0)return e._lb;let t=1e9,n=1e9,r=1e9,i=-1e9,o=-1e9,a=-1e9;for(let u of e.primitives||[]){let s=u.positions;if(s)for(let c=0;c<s.length;c+=3)s[c]<t&&(t=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 e._lb=t<=i?[(t+i)*.5,(n+o)*.5,(r+a)*.5,(i-t)*.5,(o-n)*.5,(a-r)*.5]:null}function Ha(e){let t=Rn.get(e);if(t)return t;let n=(u,s)=>{let c=e.createShader(u);return e.shaderSource(c,s),e.compileShader(c),c},r=e.createProgram();e.attachShader(r,n(35633,Ba)),e.attachShader(r,n(35632,za)),e.linkProgram(r);let i=e.createVertexArray(),o=e.createBuffer(),a=e.createBuffer();return e.bindVertexArray(i),e.bindBuffer(34962,o),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,a),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:r,vao:i,vbo:o,ibo:a,uMVP:e.getUniformLocation(r,"uMVP"),uIntensity:e.getUniformLocation(r,"uShadowIntensity"),uSoftness:e.getUniformLocation(r,"uShadowSoftness")},Rn.set(e,t),t}var En={name:"contact-shadow",onContextRestored(e){Rn.delete(e)},onAfterRender(e,t,n){let r=t.shadowIntensity;if(r<=0||!t.bounds)return;let i=Ha(e),o=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,a=[],u=[];for(let h of t.meshes||[]){if(!h||h.visible===!1||h.isPluginMesh||h.name==="__xr_reticle__"||h.name?.startsWith("__xr_slot_"))continue;let y=Ga(h);if(!y)continue;h.transform&&(y=vi(h.transform,y)),t.modelRootMatrix&&(y=vi(t.modelRootMatrix,y));let[v,R,b,w,A,P]=y,k=[v,b,w,P,R-A,R+A];/floor|table|pedestal|ground|base|plane/i.test(h.name||"")||A<.14&&Math.min(w,P)>.45?u.push(k):a.push(k)}let s=[],c=t.bounds.center||[0,0,0],l=Math.max(.05,Number(t.bounds.radius)||.5),m=t.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];t.modelRootMatrix&&(f=vi(t.modelRootMatrix,f));let p=t.xrSessionActive&&u.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:f[1]-f[4]+.002;for(let[h,y,v,R,b]of a){let w=-1/0;for(let[P,k,L,I,,x]of u)b>=x-.08&&Math.abs(h-P)<=L&&Math.abs(y-k)<=I&&x+.002>w&&(w=x+.002);o&&(w=Math.max(w,h>=.04&&h<=.36&&y>=-.34&&y<=-.04&&b>=.01?.036:Math.hypot(h,y)<=.66&&b>=-.06?.003:-.477)),isFinite(w)||(w=p);let A=s.find(P=>Math.hypot(h-P[0],y-P[1])<.06&&Math.abs(w-P[5])<.05);A?(A[2]=Math.max(A[2],v*.78),A[3]=Math.max(A[3],R*.78),A[4]=Math.min(A[4],b)):s.push([h,y,v,R,b,w])}if(s.length===0){let h=Math.max(.1,f[3]*1.5)/1.45;s.push([f[0],f[2],h,h,p,p])}e.useProgram(i.prog),e.uniformMatrix4fv(i.uMVP,!1,n),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(i.vao),e.bindBuffer(34962,i.vbo);for(let[h,y,v,R,b,w]of s){let A=Math.max(0,b-w),P=r/(1+A*2);if(P<.02)continue;let k=1+Math.min(.75,A*.85),L=Math.max(.045,v*1.45*k),I=Math.max(.045,R*1.45*k);as.set([h-L,w,y-I,0,0,h+L,w,y-I,1,0,h+L,w,y+I,1,1,h-L,w,y+I,0,1]),e.bufferSubData(34962,0,as),e.uniform1f(i.uIntensity,P),e.uniform1f(i.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,A*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Rn.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Rn.delete(e))}};function Ai(){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 n=document.createElement("a");return n.relList!==void 0&&n.relList.supports!==void 0&&n.relList.supports("ar")}function Mi(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function Si(){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 ls(){return(await Sr()).bestMode}async function Sr(){let[e,t,n]=await Promise.all([Si(),Promise.resolve(Ai()),Promise.resolve(Mi())]),r=[];t&&r.push("quick-look"),e&&r.push("webxr"),n&&r.push("scene-viewer");let i=null;return t?i="quick-look":e?i="webxr":n&&(i="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:n,availableModes:r,bestMode:i}}function cs(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let n,r=!1;if(typeof e=="string"){if(n=Xa(e),!n)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else n=URL.createObjectURL(e),r=!0;let i=[];if(t.allowScale===!1&&i.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let u=Mr(t.canonicalWebPageUrl,!1);u&&i.push(`canonicalWebPageURL=${encodeURIComponent(u)}`)}t.checkoutTitle&&i.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&i.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&i.push(`price=${encodeURIComponent(t.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 Mr(e,t=!1){if(typeof e!="string")return"";let n=e.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://")||t&&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 Xa(e){try{return Mr(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function Wa(e,t={}){let n=Mr(e,!0),r=t.mode||"ar_preferred",i=new URLSearchParams({file:n,mode:r,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&i.set("title",t.title),t.link&&i.set("link",Mr(t.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 $a(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=Wa(e,t);window.location.href=n}var Ft=null;function ja(e,t){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,d=Math.cos(f),p=Math.sin(f),h=m*2,y=h+1,v=(m+1)%24*2;r[h*3]=d*.11,r[h*3+1]=.002,r[h*3+2]=p*.11,r[y*3]=d*.145,r[y*3+1]=.002,r[y*3+2]=p*.145,i[h*3+1]=i[y*3+1]=1,a.set([h,v,y,y,v,v+1],m*6)}let u=e.createVertexArray();e.bindVertexArray(u);let s=(m,f,d)=>{let p=e.createBuffer();return e.bindBuffer(34962,p),e.bufferData(34962,m,35044),e.enableVertexAttribArray(f),e.vertexAttribPointer(f,d,5126,!1,0,0),p},c=[s(r,0,3),s(i,1,3),s(o,2,2)],l=e.createBuffer();return c.push(l),e.bindBuffer(34963,l),e.bufferData(34963,a,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:u,indexCount:a.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:a,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:c}]}}function us(e,t,n,r,i){let o=Math.cos(r),a=Math.sin(r),u=Math.max(.01,i);e.fill(0),e[0]=u*o,e[2]=-u*a,e[5]=u,e[8]=u*a,e[10]=u*o,e[12]=t[0]-u*(o*n[0]+a*n[2]),e[13]=t[1]-u*n[1],e[14]=t[2]-u*(-a*n[0]+o*n[2]),e[15]=1}var wi=class{constructor(t={}){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=t}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(t,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||t?.container,a=String(o?.tagName||"").toLowerCase()==="xr-live",u=t?.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),d=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],h="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(h="immersive-vr")}catch{h="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(h==="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"]),A={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(w)};y&&(w.add("dom-overlay"),A.optionalFeatures=Array.from(w),A.domOverlay={root:y});for(let E of Ue)E.onConfigureXRSessionInit?.(o,A);Array.isArray(A.optionalFeatures)&&A.optionalFeatures.includes("dom-overlay")&&!A.domOverlay?.root&&(A.optionalFeatures=A.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(h,A)}catch(E){if(b(),P(E))throw i.onError?.(E),E;try{this.s=await r.requestSession(h,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(V){if(P(V))throw i.onError?.(V),V;try{this.s=await r.requestSession(h)}catch(F){throw i.onError?.(F),F}}}let k=this.s;Ft=this,this.placed=!1;let L=null,I=null,x=null,g=null,S=null,D=[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,N=null,G=()=>{Ft===this&&(Ft=null),N?.(),N=null;try{I?.cancel?.()}catch{}if(I=null,x){let E=t?.meshes;if(Array.isArray(E)){let F=E.indexOf(x);F!==-1&&E.splice(F,1)}let V=t.getGLContext?.()||t?.gl;if(V)for(let F of x.primitives||[]){V.deleteVertexArray?.(F.vao);for(let U of F.buffers||[])V.deleteBuffer?.(U)}x=null}t?.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=S||D;_=[E[0],E[1],E[2]],us(this.placedMat,_,p,ne,d*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=t.getGLContext?.()||t?.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{L=await k.requestReferenceSpace("local")}catch{try{L=await k.requestReferenceSpace("local-floor")}catch{L=await k.requestReferenceSpace("viewer")}}let F=await k.requestReferenceSpace("viewer").catch(()=>L);if(typeof k.requestHitTestSource=="function"&&F&&(I=await k.requestHitTestSource({space:F}).catch(()=>null)),h==="immersive-ar"&&E&&typeof E.createVertexArray=="function"&&Array.isArray(t.meshes)&&(x=ja(E,i.reticleColor),t.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),K=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=K(T)))},ie=T=>{if(!this.s||T.touches.length<2)return;let M=z(T),C=K(T);if(H&&H>4&&i.arScale!=="fixed"&&(oe=Math.max(.15,Math.min(6,oe*(M/H)))),se!==null){let B=C-se;B>Math.PI&&(B-=Math.PI*2),B<-Math.PI&&(B+=Math.PI*2),ne-=B}H=M,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}),N=()=>{window.removeEventListener("touchstart",le),window.removeEventListener("touchmove",ie),window.removeEventListener("touchend",he),window.removeEventListener("touchcancel",he)}}t.setXRSessionActive?.(!0);let U=(z,K)=>{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,t?.stepXRUpdate?.(le);let ie=K.getViewerPose(L);if(!ie)return;let he=ie.views?.[0];if(!q&&he?.transform){let W=he.transform.position,$=he.transform.matrix,Y=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),D=[Y+te*1.2,Z-.25,j+ee*1.2],ne=Math.atan2(-te,-ee),q=!0}if(I&&typeof K.getHitTestResults=="function"&&(!this.placed||re)){let W=K.getHitTestResults(I)||[],$=!1;for(let Y of W){let Z=Y.getPose(L);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),S=[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?_:S||D,p,ne,d*oe),this.placed&&this.placedMat.set(O);let T=t.xrRigMatrix;T instanceof Float32Array&&T.length===16?Le(Q,T,O):Q.set(O),t.modelRootMatrix&&t.modelRootMatrix.set(Q);for(let W of Ue)W.onXRFrame?.(t,k,K,L);let M=t.getGLContext?.()||t?.gl,C=k.renderState?.baseLayer;M&&C&&C.framebuffer!==void 0&&M.bindFramebuffer(36160,C.framebuffer);let B=h==="immersive-ar",X=ie.views||[];for(let W=0;W<X.length;W++){let $=X[W];if(typeof t.renderXRView=="function"){let Y;if(C&&typeof C.getViewport=="function"){let Z=C.getViewport($);Z&&Z.width>0&&Z.height>0&&(Y=[Z.x,Z.y,Z.width,Z.height])}else C?.framebufferWidth>0&&C?.framebufferHeight>0&&(Y=[0,0,C.framebufferWidth,C.framebufferHeight]);t.renderXRView($,Q,this.placed,Y,B,W)}}M&&C&&C.framebuffer&&M.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 t=this.s;if(t)try{await t.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function Rr(e){let t=await Sr(),n=e.preferredModes||["quick-look","webxr","scene-viewer"],r=null;for(let u of n)if(t.availableModes.includes(u)){r=u;break}if(r||(r=t.bestMode),!r)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let i={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},o={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},a={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(r==="quick-look"){let u;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")u=e.model;else{if(typeof e.model=="string")return cs(e.model,i),{mode:"quick-look",success:!0};u=Zt(e.model)}return cs(u,i),{mode:"quick-look",success:!0}}if(r==="scene-viewer"){let u=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!u)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return $a(u,o),{mode:"scene-viewer",success:!0}}if(r==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let u=new wi(a);return await u.start(e.view,e.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:Zt});ct.registerScriptRunner(Jt);Oe(En);var Ei=new WeakMap;function Er(e,t){let n=t instanceof Float32Array?t:new Float32Array(t);Ei.set(e,n)}function ds(e){return Ei.get(e)}async function qa(e,t){if(!t)return null;let n;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let o=await(await fetch(t)).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=t});else return null;else n=t;let r=e.createTexture();return e.bindTexture(3553,r),e.texImage2D(3553,0,6408,6408,5121,n),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),r}var Ri=new WeakMap,fs=new Float32Array(16);async function ms(e,t,n){let r=n?await qa(e.gl,n):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=r}var _i={name:"environment-map",onContextRestored(e){Ri.delete(e)},setEnvironmentImage(e,t){return ms(e,"environmentTexture",t)},setSkyboxImage(e,t){return ms(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,n,r,i){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let o=Ri.get(t);if(!o){let m=(p,h)=>{let y=t.createShader(p);return t.shaderSource(y,h),t.compileShader(y),y},f=t.createProgram();t.attachShader(f,m(35633,`#version 300 es
348
- 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(f,m(35632,`#version 300 es
349
- 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(f);let d=typeof t.createVertexArray=="function"?t.createVertexArray():null;o={program:f,vao:d},Ri.set(t,o)}let a=$t(fs,n)||fs;t.depthMask(!1),t.useProgram(o.program),o.vao&&t.bindVertexArray(o.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let u=t.getUniformLocation(o.program,"uSkyboxMap");u&&t.uniform1i(u,0);let s=t.getUniformLocation(o.program,"uInvVP");s&&t.uniformMatrix4fv(s,!1,a);let c=t.getUniformLocation(o.program,"uCameraPos");c&&t.uniform3f(c,r[0],r[1],r[2]);let l=t.getUniformLocation(o.program,"uExposure");l&&t.uniform1f(l,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,n,r){if(r.includes("evalSHIrradiance"))return null;let i=r.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
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(xi*16);for(let m=0;m<s.length&&m<xi;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(gi);Oe(yi);Oe(vi);Oe(Kr);Oe(Vr);var Va=`#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.);}`,Ba=`#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,ss=new Float32Array(20);function Ti(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 za(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 Ga(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,Va)),t.attachShader(r,n(35632,Ba)),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=Ga(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=za(d);if(!y)continue;d.transform&&(y=Ti(d.transform,y)),e.modelRootMatrix&&(y=Ti(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=Ti(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);ss.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,ss),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 Ai(){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 Si(){if(typeof navigator>"u")return!1;let t=navigator.userAgent||"";return/android/i.test(t)}async function Ri(){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 us(){return(await Sr()).bestMode}async function Sr(){let[t,e,n]=await Promise.all([Ri(),Promise.resolve(Ai()),Promise.resolve(Si())]),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 as(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=Ha(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 Ha(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 Xa(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 Wa(t,e={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let n=Xa(t,e);window.location.href=n}var Ft=null;function $a(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 cs(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 Mi=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]],cs(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=$a(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)}cs(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 as(t.model,i),{mode:"quick-look",success:!0};u=Qt(t.model)}return as(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 Wa(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 Mi(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 _i=new WeakMap;function Er(t,e){let n=e instanceof Float32Array?e:new Float32Array(e);_i.set(t,n)}function ms(t){return _i.get(t)}async function ja(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 Ei=new WeakMap,ls=new Float32Array(16);async function fs(t,e,n){let r=n?await ja(t.gl,n):null;t[e]&&t.gl.deleteTexture(t[e]),t[e]=r}var Li={name:"environment-map",onContextRestored(t){Ei.delete(t)},setEnvironmentImage(t,e){return fs(t,"environmentTexture",e)},setSkyboxImage(t,e){return fs(t,"skyboxTexture",e)},onBeforeDrawScene(t,e,n,r,i){if(!t.skyboxTexture||typeof e.createProgram!="function")return;let o=Ei.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},Ei.set(e,o)}let a=jt(ls,n)||ls;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];
350
352
  uniform int uHasSH;
351
353
  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);}
352
354
  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));}
@@ -359,15 +361,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
359
361
  }else if(uHasSH==1){
360
362
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
361
363
  envDiffuse=evalSHIrradiance(N);
362
- }`),{vs:n,fs:i}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=Ei.get(e),u=e.getUniformLocation(t,"uHasSH");if(a&&a.length>=27){u&&e.uniform1i(u,1);let s=e.getUniformLocation(t,"uSH");s&&e.uniform3fv(s,a)}else u&&e.uniform1i(u,0)},onAttributeChanged(e,t,n,r){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,r):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,r)}};var Ii=new WeakMap;function Li(e,t){let n=t||e.viewer;if(!n||typeof n.projectPointToScreen!="function")return;let r=e.mockHotspots||e.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 Ci={name:"hotspots",updateHotspotsForElement:Li,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{Li(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ii.set(e,t)},onCameraChange(e,t){t&&Li(t,e)},onElementDisconnected(e){let t=Ii.get(e);t&&(t.disconnect(),Ii.delete(e))}};var hs=1024,Pi=256,_r=2048,Ka=128,Ya=64,Za=16,Qa=1e4,Ja=8,yt=new Set(["__proto__","constructor","prototype"]),ps={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))},bs={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},Ir={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},Lr=(e,t)=>e!==null&&typeof e=="object"&&!yt.has(t)&&Object.prototype.hasOwnProperty.call(e,t),Qe=e=>Array.isArray(e)?[...e]:e,vs=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&Lr(e,"value")?e.value:e,De=(e,t)=>Lr(e.configuration,t)?vs(e.configuration[t]):void 0,de=(e,t=0)=>{let n=Number(e);return Number.isFinite(n)?n:t},Ot=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 _n(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let n of e.slice(1).split("/")){let r=n.replace(/~1/g,"/").replace(/~0/g,"~");if(!r||yt.has(r)||yt.has(n))return null;t.push(r)}return{segments:t}}var nn=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let n=Number(e);return Number.isSafeInteger(n)&&n>=0&&n<t?n:-1},ys=e=>{let t=de(e[0]),n=de(e[1]),r=de(e[2]),i=de(e[3],1),o=Math.hypot(t,n,r,i);return o>1e-8?[t/o,n/o,r/o,i/o]:[0,0,0,1]},gs=(e,t,n,r)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*n;if(Array.isArray(e)&&Array.isArray(t)){if(r&&e.length===4&&t.length===4){let i=[0,0,0,1];return Ar(i,ys(e),ys(t),n),i}return e.slice(0,t.length).map((i,o)=>i+(t[o]-i)*n)}return n>=.5?t:e},ki=(e,t,n)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((r,i)=>n(de(r),de(t[i]))):Array.isArray(e)?e.map(r=>n(de(r),de(t))):Array.isArray(t)?t.map(r=>n(de(e),de(r))):n(de(e),de(t)),ec=(e,t)=>Array.isArray(e)?e.map(n=>t(de(n))):t(de(e)),xs=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((n,r)=>Math.abs(n-t[r])<=1e-6):e===t,In=class{constructor(t,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>Pi)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${Pi})`);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,d=new Map,p=[],h=[],y=new Map,v=1,R=0,b=0,w=0,A=0,P=!1,k=!1,L=!1;o.forEach((N,G)=>{if(!N||typeof N!="object")return;let E=Qe(vs(N.value));s.set(G,E);let V=N.id??N.name;typeof V=="string"&&V&&!yt.has(V)&&s.set(V,E)}),(n?.nodes||[]).forEach((N,G)=>{for(let E of N?.children||[])typeof E=="number"&&y.set(E,G)});let I=N=>N.op||typeof N.declaration=="number"&&a[N.declaration]?.op||"",x=(N,G,E)=>{if(yt.has(G))return;let V=c.get(N);V||c.set(N,V=Object.create(null)),V[G]=E},g=(N,G)=>{if(typeof N!="number"&&typeof N!="string"||typeof N=="string"&&yt.has(N)||!s.has(N)&&s.size>=Pi*2)return;let E=Qe(G);if(s.set(N,E),typeof N=="number"){let V=o[N]?.id??o[N]?.name;typeof V=="string"&&!yt.has(V)&&s.set(V,E)}},S=N=>typeof N=="number"?u[N]?.id??String(N):typeof N=="string"?/^\d+$/.test(N)&&u[Number(N)]?.id?u[Number(N)].id:N:"",D=(N,G)=>{for(let E=N,V=0;E!==void 0&&E>=0&&V<128;E=y.get(E),V++)if(E===G)return!0;return!1},_=N=>{for(let G=p.length-1;G>=0;G--)p[G].key===N&&p.splice(G,1)},O=N=>{_(N.key),p.length>=Ka&&p.shift(),p.push(N)},Q=N=>{let G=_n(N)?.segments;if(G){if(G[0]==="nodes"&&Array.isArray(n?.nodes)){let E=n.nodes[nn(G[1],n.nodes.length)];if(!E)return;let V=G[2];if(V in Ir){let F=Ir[V],U=E[V]||F;return F.map((z,K)=>de(U[K],z))}if(V==="weights"){let F=Array.isArray(E.weights)?E.weights:[0],U=G.length===4?nn(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[nn(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=(N,G)=>{let E=_n(N)?.segments;if(!E)return!1;if(E[0]==="nodes"&&Array.isArray(n?.nodes)){let V=nn(E[1],n.nodes.length),F=n.nodes[V];if(!F)return!1;let U=E[2];if(U in Ir&&Array.isArray(G)){let z=Ir[U];if(G.length<z.length)return!1;let K=z.map((ie,he)=>de(G[he],ie));if(U==="rotation"){let ie=Math.hypot(...K);K=ie>1e-8?K.map(he=>he/ie):[0,0,0,1]}F[U]=K,delete F.matrix;let le=t?.initialNodeTransforms?.[V];return le&&(le[U[0]]=[...K]),P=!0,!0}if(U==="weights"){Array.isArray(F.weights)||(F.weights=[]);let z=(K,le)=>{for(let ie of t?.meshes||[])if(ie.nodeIndex===V)for(let he of ie.primitives||[])he.pluginData?.morph?.weights&&(he.pluginData.morph.weights[K]=le)};if(E.length===4){let K=nn(E[3],64);if(K<0)return!1;z(K,F.weights[K]=de(G))}else if(Array.isArray(G))F.weights=G.slice(0,64).map(K=>de(K)),F.weights.forEach((K,le)=>z(le,K));else return!1;return L=!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=nn(E[1],n.materials.length),F=n.materials[V];if(!F)return!1;let U=F.pbrMetallicRoughness||(F.pbrMetallicRoughness={}),z=K=>{for(let le of t?.meshes||[])for(let ie of le.primitives||[])(ie.materialIndex??0)===V&&K(ie)};if(E[2]==="pbrMetallicRoughness"){if(E[3]==="baseColorFactor"&&Array.isArray(G)&&G.length>=3){let K=[Ot(de(G[0],1)),Ot(de(G[1],1)),Ot(de(G[2],1)),G[3]!==void 0?Ot(de(G[3],1)):U.baseColorFactor?.[3]??1];return U.baseColorFactor=K,z(le=>le.baseColor=[...K]),L=!0}if(E[3]==="metallicFactor"||E[3]==="roughnessFactor"){let K=E[3]==="metallicFactor",le=Ot(de(G,K?0:.5));return U[E[3]]=le,z(ie=>ie[K?"metallic":"roughness"]=le),L=!0}}if(E[2]==="emissiveFactor"&&Array.isArray(G)&&G.length>=3)return F.emissiveFactor=[0,1,2].map(K=>Math.max(0,de(G[K]))),L=!0;if(E[2]==="alphaCutoff")return F.alphaCutoff=Ot(de(G,.5)),L=!0}return!1},oe=(N,G,E=new Set)=>{let V=De(G,"pointer");if(typeof V!="string"||!V.startsWith("/"))return null;let F=V.replace(/\{([a-zA-Z0-9_]+)\}/g,(U,z)=>{let K=Math.trunc(Number(ne(N,z,void 0,E)??De(G,z)));return Number.isSafeInteger(K)&&K>=0?String(K):"-1"});return _n(F)?F:null},ne=(N,G,E,V)=>{let F=i[N]?.values;if(!Lr(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):Lr(z,"value")?Qe(z.value):E},re=(N,G,E)=>{if(N<0||N>=i.length||E.has(N)||E.size>128||++w>Qa)return;let V=i[N],F=I(V);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(F))return Qe(c.get(N)?.[G]);E.add(N);try{let U=(z,K=0)=>ne(N,z,K,E);if(F==="variable/get"){let z=De(V,"variable")??De(V,"id");return typeof z=="number"||typeof z=="string"?Qe(s.get(z)):void 0}if(F==="pointer/get"){let z=oe(N,V,E);return z?Q(z):void 0}if(F.startsWith("math/")){let z=F.slice(5);if(z in ps)return ec(U("a"),ps[z]);if(z in bs){let K=/^(mul|div|rem|mod|pow)$/.test(z)?1:0;return ki(U("a",z==="mul"?1:0),U("b",K),bs[z])}if(z==="pi")return Math.PI;if(z==="e")return Math.E;if(z==="random")return Math.random();if(z==="clamp")return ki(ki(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 K=U("a"),le=U("b");return Array.isArray(K)&&Array.isArray(le)?K.reduce((ie,he,T)=>ie+(he||0)*(le[T]||0),0):de(K)*de(le)}if(z==="cross"){let K=U("a",[0,0,0]),le=U("b",[0,0,0]);return Array.isArray(K)&&Array.isArray(le)?[(K[1]||0)*(le[2]||0)-(K[2]||0)*(le[1]||0),(K[2]||0)*(le[0]||0)-(K[0]||0)*(le[2]||0),(K[0]||0)*(le[1]||0)-(K[1]||0)*(le[0]||0)]:[0,0,0]}if(z==="length"){let K=U("a");return Array.isArray(K)?Math.hypot(...K):Math.abs(de(K))}if(z==="distance"){let K=U("a"),le=U("b");return Array.isArray(K)&&Array.isArray(le)?Math.hypot(...K.map((ie,he)=>(ie||0)-(le[he]||0))):Math.abs(de(K)-de(le))}if(z==="normalize"){let K=U("a");if(!Array.isArray(K))return de(K)>=0?1:-1;let le=Math.hypot(...K);return le>1e-8?K.map(ie=>ie/le):K.map(()=>0)}if(z.startsWith("combine"))return["a","b","c","d"].slice(0,Number(z[7])||2).map(K=>de(U(K)));if(z.startsWith("extract")){let K=U("a");return Array.isArray(K)?K[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 K=Number(U("a"));return!Number.isFinite(K)&&!Number.isNaN(K)}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(N)}},H=()=>{if(P){P=!1,L=!0;let N=dt(n);if(t){t.worldMatrices=N;for(let G of t.meshes||[])G.nodeIndex>=0&&G.nodeIndex<N.length&&(G.transform.set(N[G.nodeIndex]),Ne(G.normalMatrix,G.transform))}}if(k){k=!1,L=!0;let N=n?.nodes;if(Array.isArray(t?.meshes)&&Array.isArray(N))for(let G of t.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=N[V];if(U?.visible===!1||U?.extensions?.KHR_node_visibility?.visible===!1){E=!1;break}}G.visible=E}}L&&(L=!1,t?.render?.())},se=(N,G={steps:0})=>{if(!N||typeof N.node!="number")return;G.steps===0&&(w=0);let E=[N],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 K=F.socket||"in",le=I(z),ie=(T,M=void 0)=>ne(U,T,M,new Set),he=(T="out")=>{let M=z.flows?.[T];M&&V(M)};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((M,C)=>Number(M)-Number(C)||M.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))),M=Math.trunc(de(ie("endIndex",0))),C=Math.max(1,Math.trunc(de(ie("step",1),1))),B=z.flows?.body;if(B&&M>T&&A<Ja){let W=Math.min(Math.ceil((M-T)/C),_r);A++;try{for(let $=0;$<W&&G.steps<_r;$++)x(U,"index",T+$*C),se(B,G)}finally{A--}}let X=z.flows?.completed??z.flows?.out;X&&V(X);break}case"flow/doN":{let T=K==="reset"?0:(l.get(U)||0)+1;if(l.set(U,T),x(U,"currentCount",T),x(U,"count",T),K!=="reset"){let M=Math.trunc(de(ie("n",De(z,"stopIterations")??De(z,"n")??1),1));T<=M&&he()}break}case"flow/multiGate":{if(K==="reset"){d.set(U,0);break}let T=Object.keys(z.flows||{}).sort();if(!T.length)break;let M=De(z,"isRandom")?Math.floor(Math.random()*T.length):d.get(U)||0;M<T.length&&(he(T[M]),d.set(U,De(z,"isLoop")!==!1?(M+1)%T.length:M+1));break}case"flow/waitAll":{if(K==="reset"){m.delete(U);break}let T=m.get(U);T||m.set(U,T=new Set),T.add(K),T.size>=Math.max(1,Math.trunc(Number(De(z,"inputFlows")??2)||2))&&(T.clear(),he("out"),he("completed"));break}case"flow/throttle":{if(K==="reset"){f.delete(U);break}let T=Math.max(0,de(ie("duration",0))),M=f.get(U);M===void 0||R-M>=T?(f.set(U,R),x(U,"lastRemainingTime",0),he()):x(U,"lastRemainingTime",Math.max(0,T-(R-M)));break}case"flow/delay":case"flow/setDelay":{if(K==="cancel"){for(let B=h.length-1;B>=0;B--)h[B].nodeIdx===U&&h.splice(B,1);x(U,"lastDelayIndex",-1);break}let T=Math.max(0,de(ie("duration",De(z,"duration")??0))),M=z.flows?.done??z.flows?.out;if(T<=0){x(U,"lastDelayIndex",-1),M&&V(M);break}h.length>=Ya&&h.shift();let C=v++;x(U,"lastDelayIndex",C),h.push({id:C,nodeIdx:U,rem:T,done:M}),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)h.length=0;else for(let M=h.length-1;M>=0;M--)h[M].id===T&&h.splice(M,1);he();break}case"variable/set":g(De(z,"variable")??De(z,"id"),ie("value")),he();break;case"variable/interpolate":{let T=De(z,"variable")??De(z,"id"),M=ie("value",ie("target")),C=Math.max(0,de(ie("duration",De(z,"duration")??.3),.3));T!==void 0&&M!==void 0&&O({key:`var:${String(T)}`,varKey:T,from:Qe(ie("from")??s.get(T)??0),to:Qe(M),dur:C,elapsed:0,quat:!1,linear:De(z,"easing")==="linear",done:z.flows?.done}),he();break}case"pointer/set":{let T=oe(U,z),M=ie("value");T&&M!==void 0&&(_(`ptr:${T}`),q(T,M)),he();break}case"pointer/interpolate":{let T=oe(U,z),M=ie("value",ie("target")),C=Math.max(0,de(ie("duration",De(z,"duration")??.3),.3));if(T&&M!==void 0){let B=ie("from")??Q(T);B!==void 0&&(C<=0?(q(T,M),he("done")):O({key:`ptr:${T}`,ptr:T,from:Qe(B),to:Qe(M),dur:C,elapsed:0,quat:T.endsWith("/rotation"),linear:De(z,"easing")==="linear",done:z.flows?.done}))}he();break}case"animation/start":{let T=ie("animation")??De(z,"animation")??De(z,"clipName"),M=typeof T=="number"?t?.animations?.[T]?.name??n?.animations?.[T]?.name:typeof T=="string"?T:void 0;t?.playAnimation?.(M),L=!0,he();break}case"animation/stop":case"animation/resetAt":t?.pauseAnimation?.(),le==="animation/resetAt"&&t?.evaluateAnimation?.(de(ie("time",0))),L=!0,he();break;case"event/send":case"customEvent/send":{let T=S(De(z,"event")??De(z,"id")),M={};for(let C of Object.keys(z.values||{}))yt.has(C)||(M[C]=ie(C));T&&(typeof CustomEvent<"u"&&typeof t?.container?.dispatchEvent=="function"&&t.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:T,values:M}})),ae(T,M,G)),he();break}default:he();break}}};this.readScenePointer=Q,this.writeScenePointer=q,this.fireOnStart=()=>{i.forEach(N=>{I(N)==="event/onStart"&&se(N.flows?.out)}),H()},this.fireOnSelect=N=>{if(!N)return;let G=typeof N.meshIndex=="number"?N.meshIndex:-1,E=typeof N.nodeIndex=="number"?N.nodeIndex:t?.meshes?.[G]?.nodeIndex??-1;i.forEach((V,F)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(I(V)))return;let U=De(V,"nodeIndex")??De(V,"node")??ne(F,"nodeIndex",void 0,new Set),z=De(V,"meshName");if(typeof z=="string"&&z?N.meshName===z:U==null||Number(U)<0||Number.isNaN(Number(U))||D(E,Math.trunc(Number(U)))){if(x(F,"nodeIndex",E),x(F,"meshIndex",G),Array.isArray(N.hitPoint)){let le=[de(N.hitPoint[0]),de(N.hitPoint[1]),de(N.hitPoint[2])];x(F,"hitPoint",le),x(F,"point",le),x(F,"intersectionPoint",le)}if(Array.isArray(N.normal)){let le=[de(N.normal[0]),de(N.normal[1],1),de(N.normal[2])];x(F,"normal",le),x(F,"hitNormal",le)}typeof N.distance=="number"&&x(F,"distance",N.distance),se(V.flows?.out)}}),H()},this.receiveCustomEvent=(N,G={})=>ae(N,G,{steps:0});function ae(N,G,E){if(!(b>=Za)){b++;try{let V=S(N);i.forEach((F,U)=>{if(!/^(customE|e)vent\/receive$/.test(I(F)))return;let z=De(F,"event")??De(F,"id");if(!(S(z)!==V&&String(z)!==String(N))){for(let[K,le]of Object.entries(G))yt.has(K)||x(U,K,Qe(le));se(F.flows?.out,E)}}),H()}finally{b--}}}this.tick=N=>{if(!Number.isFinite(N)||N<0)return;let G=Math.min(N,.25);R+=G,i.forEach((V,F)=>{I(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?Ot(F.elapsed/F.dur):1,z=F.linear?U:U*U*(3-2*U),K=gs(F.from,F.to,z,F.quat);F.ptr?q(F.ptr,K):F.varKey!==void 0&&g(F.varKey,K),U>=1&&(p.splice(V,1),F.done&&E.push(F.done))}for(let V=h.length-1;V>=0;V--){let F=h[V];F.rem-=G,F.rem<=0&&(h.splice(V,1),F.done&&E.push(F.done))}for(let V of E)se(V);H()},this.dispose=()=>{p.length=0,h.length=0,s.clear(),c.clear(),l.clear(),m.clear(),f.clear(),d.clear()}}},ut=new WeakMap,Cr=new WeakMap;function tc(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||Un().some(s=>s.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 o=Math.min(t,.1),a=(Cr.get(e)||0)+o,u=!1;for(let s=0;s<i.length;s++){let c=i[s],l=Fo(c?.extras?.xr?.orbit);if(!l)continue;let m=0,f=0,d=0;if(Array.isArray(l.target))m=l.target[0],f=l.target[1],d=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]),d=de(R.translation[2]))}let p=l.phase+l.speed*a,h=m+Math.cos(p)*l.radius,y=f+l.height,v=d+Math.sin(p)*l.radius;if(c.translation=[h,y,v],l.faceCenter){let R=Math.atan2(m-h,d-v);c.rotation=[0,Math.sin(R*.5),0,Math.cos(R*.5)]}u=!0}if(u){Cr.set(e,a);let s=dt(r);e.worldMatrices=s;for(let c of e.meshes||[])c.nodeIndex>=0&&c.nodeIndex<s.length&&(c.transform.set(s[c.nodeIndex]),Ne(c.normalMatrix,c.transform))}}function Pr(e){if(!(!e||typeof e!="object"))return ut.get(e)||ut.get(e.viewer)||ut.get(e._view)}function Di(e,t,n){let r=Pr(e);return r?(r.receiveCustomEvent(t,n),!0):!1}var Ni={name:"khr-interactivity",sendInteractivityEvent:Di,getInteractivityVM:Pr,onLoadModel(e,t){if(!e||typeof e!="object")return;ut.get(e)?.dispose(),ut.delete(e),Cr.delete(e);let n=t?.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(e,t,r);ut.set(e,i),i.fireOnStart()},onMeshSelect(e,t){ut.get(e)?.fireOnSelect(t)},onUpdate(e,t){ut.get(e)?.tick(t),tc(e,t)},onDestroy(e,t){ut.get(t)?.dispose(),ut.delete(t),Cr.delete(t)}};var Ln=new Map,kr=new WeakMap;function Ts(e,t){Ln.set(e,t)}var Ui={name:"materials",onContextRestored(e){kr.delete(e)},onBuildPrimitiveVAO(e,t,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(e,t){let n=kr.get(e);n||(n=e.createTexture(),kr.set(e,n));let r=Math.max(1,t.canvas.width),i=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,n),e.copyTexImage2D(3553,0,6408,0,0,r,i,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,n,r){if(!t)return null;if(t.name&&Ln.has(t.name)){let p=Ln.get(t.name);return{vs:p.vs||n,fs:p.fs||r}}let i=t.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;
364
+ }`),{vs:n,fs:i}},onBeforeDrawPrimitive(t,e,n,r,i,o){let a=_i.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 Ii=new WeakMap;function Ci(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 Pi={name:"hotspots",updateHotspotsForElement:Ci,onElementConnected(t){if(typeof MutationObserver>"u"||!t)return;let e=new MutationObserver(()=>{Ci(t)});e.observe(t,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),Ii.set(t,e)},onCameraChange(t,e){e&&Ci(e,t)},onElementDisconnected(t){let e=Ii.get(t);e&&(e.disconnect(),Ii.delete(t))}};var ds=1024,ki=256,_r=2048,qa=128,Ka=64,Ya=16,Za=1e4,Qa=8,bt=new Set(["__proto__","constructor","prototype"]),hs={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))},ps={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,xs=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&Ir(t,"value")?t.value:t,ke=(t,e)=>Ir(t.configuration,e)?xs(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},bs=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]},ys=(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,bs(t),bs(e),n),i}return t.slice(0,e.length).map((i,o)=>i+(e[o]-i)*n)}return n>=.5?e:t},Ni=(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)),Ja=(t,e)=>Array.isArray(t)?t.map(n=>e(de(n))):e(de(t)),gs=(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>ds)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ds})`);let o=Array.isArray(r.variables)?r.variables:[];if(o.length>ki)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${ki})`);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(xs(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>=ki*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>=qa&&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>Za)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 hs)return Ja(U("a"),hs[z]);if(z in ps){let Y=/^(mul|div|rem|mod|pow)$/.test(z)?1:0;return Ni(U("a",z==="mul"?1:0),U("b",Y),ps[z])}if(z==="pi")return Math.PI;if(z==="e")return Math.E;if(z==="random")return Math.random();if(z==="clamp")return Ni(Ni(U("a"),U("b",U("min",0)),Math.max),U("c",U("max",1)),Math.min);if(z==="mix"||z==="quatSlerp")return ys(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 gs(U("a"),U("b"));if(z==="ne")return!gs(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<Qa){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>=Ka&&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>=Ya)){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=ys(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 ec(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=Uo(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 Di(t,e,n){let r=Pr(t);return r?(r.receiveCustomEvent(e,n),!0):!1}var Ui={name:"khr-interactivity",sendInteractivityEvent:Di,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),ec(t,e)},onDestroy(t,e){ut.get(e)?.dispose(),ut.delete(e),Cr.delete(e)}};var Cn=new Map,kr=new WeakMap;function vs(t,e){Cn.set(t,e)}var Oi={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;
363
365
  `;l=l.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
364
- ${p}out vec4 fragColor;`)}let m=(p,h,y=0,v=1e6,R=3)=>{let b=Number(p);return(Number.isFinite(b)?Math.min(v,Math.max(y,b)):h).toFixed(R)},f=Number(i.KHR_materials_ior?.ior??1.5),d=Number.isFinite(f)?Math.min(10,Math.max(1,f)):1.5;if(s){let p=Math.pow((d-1)/(d+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),h=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.*${h}*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),h=i.KHR_materials_volume||{},y=m(h.thicknessFactor,.5,0,1e4),v=m(h.attenuationDistance,1,.001,1e6),R=Array.isArray(h.attenuationColor)?h.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;
365
- vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(d,1.5,1,10)},dV=${b},tV=${y},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
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);
366
368
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
367
369
  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);
368
370
  vec3 aCol=vec3(${m(R[0],1,0,1)},${m(R[1],1,0,1)},${m(R[2],1,0,1)});
369
371
  vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${v},.001));
370
- diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${p});`)}if(o&&!r.includes("uClearcoat")){let p=m(o.clearcoatFactor,1,0,1),h=m(o.clearcoatRoughnessFactor,0,0,1);l=l.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${h},NoV)*${p};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${h})*ccF;fragColor=vec4(color,base.a);`)}if(a){let p=Array.isArray(a.sheenColorFactor)?a.sheenColorFactor:[1,1,1],h=`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);",`${h}color=applyToneMapping(color,uToneMapping);`):l=l.replace("fragColor=vec4(color,base.a);",`${h}fragColor=vec4(color,base.a);`)}return{vs:n,fs:l}},onBeforeDrawPrimitive(e,t,n,r,i,o){let a=n.materialIndex;if(a!==void 0&&o?.materials){let u=o.materials[a];u?.name&&Ln.has(u.name)&&Ln.get(u.name).onBindUniforms?.(e,t,n)}if(n.isTransmissive){let u=kr.get(e);if(u){e.activeTexture(33990),e.bindTexture(3553,u);let s=e.getUniformLocation(t,"uTransmissionTex");s&&e.uniform1i(s,6);let c=e.getUniformLocation(t,"uViewportSize");c&&e.uniform2f(c,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}};var ws=64*1024*1024,As=128*1024*1024,nc=16777216;function rc(e){return(e>>>1^-(e&1))&255}function ic(e){return(e>>>1^-(e&1))&65535}function oc(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function Ms(e){return(e<<1^e>>31)>>>0}function Es(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw Re(`unknown filter "${String(e)}"`)}var Te=Math.fround;function rn(e){return Math.trunc(Te(e+(e>=0?.5:-.5)))}function Fi(e,t,n,r="NONE"){if(Es(r),!r||r==="NONE"||t<=0)return;let i=new DataView(e.buffer,e.byteOffset,e.byteLength);if(r==="OCTAHEDRAL"){if(n!==4&&n!==8)throw Re(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${n})`);let m=n===8,f=m?32767:127,d=y=>m?i.getInt16(y,!0):i.getInt8(y),p=(y,v)=>m?i.setInt16(y,v,!0):i.setInt8(y,v<<24>>24),h=m?2:1;for(let y=0;y<t;y++){let v=y*n,R=d(v),b=d(v+h),w=Te(d(v+2*h)-Math.abs(R)-Math.abs(b)),A=w>=0?0:w;R=Te(R+(R>=0?A:-A)),b=Te(b+(b>=0?A:-A));let P=Te(Math.sqrt(Te(Te(Te(R*R)+Te(b*b))+Te(w*w))));if(P===0){p(v,0),p(v+h,0),p(v+2*h,f);continue}let k=Te(f/P);p(v,rn(Te(R*k))),p(v+h,rn(Te(b*k))),p(v+2*h,rn(Te(w*k)))}return}if(r==="QUATERNION"){if(n!==8)throw Re(`QUATERNION filter requires byteStride 8 (got ${n})`);let m=Te(32767/Te(Math.SQRT2));for(let f=0;f<t;f++){let d=f*8,p=i.getInt16(d+6,!0),h=p|3,y=i.getInt16(d,!0),v=i.getInt16(d+2,!0),R=i.getInt16(d+4,!0),b=Te(h*h),w=Te(Te(Te(Te(b*2)-Te(y*y))-Te(v*v))-Te(R*R)),A=Te(Math.sqrt(w>=0?w:0)),P=Te(m/h),k=p&3,L=[0,0,0,0];L[k+1&3]=rn(Te(y*P)),L[k+2&3]=rn(Te(v*P)),L[k+3&3]=rn(Te(R*P)),L[k]=Math.trunc(Te(Te(A*P)+.5));for(let I=0;I<4;I++)i.setInt16(d+I*2,L[I]<<16>>16,!0)}return}if(r==="EXPONENTIAL"){if(n<4||n%4!==0)throw Re(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${n})`);let m=t*n>>>2;for(let f=0;f<m;f++){let d=f*4,p=i.getUint32(d,!0),h=p<<8>>8,y=p>>24;i.setUint32(d,y+127<<23>>>0,!0);let v=i.getFloat32(d,!0);i.setFloat32(d,Te(v*h),!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<t;m++){let f=m*n,d=u(f+3*l);d|=d>>1,d|=d>>2,d|=d>>4,d|=d>>8;let p=u(f),h=s(f+l),y=s(f+2*l),v=p+h-y,R=p+y,b=p-h-y,w=u(f+3*l);w=w<<1&d|w&1;let A=d===0?0:Te(a/d);c(f,Math.trunc(Te(Te(v*A)+.5))),c(f+l,Math.trunc(Te(Te(R*A)+.5))),c(f+2*l,Math.trunc(Te(Te(b*A)+.5))),c(f+3*l,Math.trunc(Te(Te(w*A)+.5)))}}var _s=160,lt=16,sc=24,Is=32,ac=24,cc=[0,2,4,8],uc=[0,1,2,4,8];function Ls(e){let t=Math.floor(8192/e)&~(lt-1);return t<256?t:256}function Re(e){return new Error(`EXT_meshopt_compression: ${e}`)}function lc(e,t,n,r,i){if(i===0)return n.fill(0,r,r+lt),t;if(i===8)return n.set(e.subarray(t,t+lt),r),t+lt;let o=(1<<i)-1,a=8/i,u=t+lt*i/8;for(let s=0;s<lt;s++){let c=e[t+Math.floor(s/a)],l=s%a,m=i===1?c>>l&1:c>>8-i-l*i&o;n[r+s]=m===o?e[u++]:m}return u}function Ss(e,t,n,r,i,o,a,u){let s=o/lt,c=s+3>>2;if(n-t<c)throw Re("truncated ATTRIBUTES stream");let l=t;t+=c;for(let m=0;m<s;m++){if(n-t<sc)throw Re("truncated ATTRIBUTES stream");let f=e[l+(m>>2)]>>(m&3)*2&3;t=lc(e,t,r,i+m*lt,a[u+f])}return t}function fc(e,t,n,r){if(n%4!==0||n>256)throw Re(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${n})`);let i=e.byteLength;if(i<1)throw Re("truncated ATTRIBUTES stream");let o=e[0];if((o&240)!==_s)throw Re(`unsupported ATTRIBUTES header 0x${o.toString(16)}`);let a=o&15;if(a>1)throw Re(`unsupported ATTRIBUTES codec version ${a}`);let u=n+(a===0?0:n/4),s=a===0?Is:ac,c=u<s?s:u;if(i-1<c)throw Re("truncated ATTRIBUTES stream");let l=i-u,m=e.slice(l,l+n),f=l+n,d=Ls(n),p=new Uint8Array(256*4),h=1;for(let y=0;y<t;){let v=Math.min(d,t-y),R=v+lt-1&~(lt-1),b=a===0?0:n/4;if(i-h<b)throw Re("truncated ATTRIBUTES stream");let w=h;h+=b;for(let A=0;A<n;A+=4){let P=a===0?0:e[w+A/4];for(let I=0;I<4;I++){let x=P>>I*2&3;if(x===3){if(i-h<v)throw Re("truncated ATTRIBUTES stream");p.set(e.subarray(h,h+v),I*v),h+=v}else x===2?p.fill(0,I*v,I*v+v):h=a===0?Ss(e,h,i,p,I*v,R,cc,0):Ss(e,h,i,p,I*v,R,uc,x)}let k=a===0?0:e[f+A/4],L=k&3;if(L===0)for(let I=0;I<4;I++){let x=m[A+I];for(let g=0;g<v;g++)x=rc(p[I*v+g])+x&255,r[(y+g)*n+A+I]=x}else if(L===1)for(let I=0;I<4;I+=2){let x=m[A+I]|m[A+I+1]<<8,g=I*v;for(let S=0;S<v;S++){let D=p[g+S]|p[g+v+S]<<8;x=ic(D)+x&65535;let _=(y+S)*n+A+I;r[_]=x&255,r[_+1]=x>>8}}else if(L===2){let I=32-(k>>4)&31,x=(m[A]|m[A+1]<<8|m[A+2]<<16|m[A+3]<<24)>>>0;for(let g=0;g<v;g++){let S=(p[g]|p[v+g]<<8|p[2*v+g]<<16|p[3*v+g]<<24)>>>0;S=((S<<I|S>>>(32-I&31))^x)>>>0,x=S;let D=(y+g)*n+A;r[D]=S&255,r[D+1]=S>>>8&255,r[D+2]=S>>>16&255,r[D+3]=S>>>24}}else throw Re(`invalid ATTRIBUTES channel ${k}`)}m.set(r.subarray((y+v-1)*n,(y+v)*n)),y+=v}if(i-h!==c)throw Re("ATTRIBUTES trailing data")}var Cs=224,Ps=208;function ks(e,t){let n=e[t.pos++]??0;if(n<128)return n;let r=n&127,i=7;for(let o=0;o<4;o++){let a=e[t.pos++]??0;if(r=(r|(a&127)<<i)>>>0,i+=7,a<128)break}return r>>>0}function Dr(e,t,n){let r=ks(e,t),i=r>>>1^-(r&1);return n+i>>>0}function mc(e,t,n){if(t%3!==0)throw Re(`TRIANGLES count must be divisible by 3 (got ${t})`);let r=t/3;if(e.byteLength<1+r+16)throw Re("truncated TRIANGLES stream");let i=e[0];if((i&240)!==Cs)throw Re(`unsupported TRIANGLES header 0x${i.toString(16)}`);let o=i&15;if(o>1)throw Re(`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},d=0,p=0,h=o>=1?13:15,y=1+r,v=e.byteLength-16,R=v,b={pos:y},w=0,A=(P,k,L)=>{n(w++,P),n(w++,k),n(w++,L)};for(let P=1;P<y;P++){let k=e[P];if(k<240){let L=k>>4,I=c-1-L&15,x=a[I],g=u[I],S=0,D=k&15;if(D<h){let _=s[l-1-D&15];S=D===0?d:_;let O=D===0?1:0;d=d+O>>>0,f(S,O)}else{if(b.pos>v)throw Re("truncated TRIANGLES stream");S=D!==15?p+(D*2-27)>>>0:Dr(e,b,p),p=S,f(S)}m(S,g),m(x,S),A(x,g,S)}else if(k<254){let L=e[R+(k&15)],I=L>>4,x=L&15,g=d;d=d+1>>>0;let S=s[l-I&15],D=I===0?d:S,_=I===0?1:0;d=d+_>>>0;let O=s[l-x&15],Q=x===0?d:O,q=x===0?1:0;d=d+q>>>0,A(g,D,Q),f(g),f(D,_),f(Q,q),m(D,g),m(Q,D),m(g,Q)}else{if(b.pos>v)throw Re("truncated TRIANGLES stream");let L=e[b.pos++],I=k===254?0:15,x=L>>4,g=L&15;L===0&&(d=0);let S=0;I===0&&(S=d,d=d+1>>>0);let D;x===0?(D=d,d=d+1>>>0):D=s[l-x&15];let _;g===0?(_=d,d=d+1>>>0):_=s[l-g&15],I===15&&(p=S=Dr(e,b,p)),x===15&&(p=D=Dr(e,b,p)),g===15&&(p=_=Dr(e,b,p)),A(S,D,_),f(S),f(D,x===0||x===15?1:0),f(_,g===0||g===15?1:0),m(D,S),m(_,D),m(S,_)}}if(b.pos!==v)throw Re("TRIANGLES trailing data")}function dc(e,t,n){if(e.byteLength<1+t+4)throw Re("truncated INDICES stream");let r=e[0];if((r&240)!==Ps)throw Re(`unsupported INDICES header 0x${r.toString(16)}`);let i=r&15;if(i>1)throw Re(`unsupported INDICES codec version ${i}`);let o=e.byteLength-4,a=[0,0],u={pos:1};for(let s=0;s<t;s++){if(u.pos>=o)throw Re("truncated INDICES stream");let c=ks(e,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 Re("INDICES trailing data")}function Oi(e,t,n,r,i="NONE"){if(Es(i),!Number.isInteger(t)||t<0||t>nc||!Number.isInteger(n)||n<=0||n>256)throw Re(`invalid count (${t}) or byteStride (${n})`);let o=t*n;if(o>ws)throw Re(`decompressed size (${o}) exceeds MAX_MESHOPT_BUFFER_BYTES (${ws})`);if(t===0)return new Uint8Array(0);let a=new Uint8Array(o);if(r==="ATTRIBUTES")return fc(e,t,n,a),Fi(a,t,n,i),a;if(r==="TRIANGLES"||r==="INDICES"){if(n!==2&&n!==4)throw Re(`${r} byteStride must be 2 or 4 (got ${n})`);if(i&&i!=="NONE")throw Re(`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"?mc(e,t,s):dc(e,t,s),a}throw Re(`unknown mode "${String(r)}"`)}function Rs(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Ds(e,t,n,r){let i=t*n;if(e.byteLength<i)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.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=Ls(n),c=new Uint8Array(n);t>0&&c.set(e.subarray(0,n));let l=c.slice(),m=new Uint8Array(256);for(let f=0;f<t;){let d=Math.min(s,t-f),p=d+15&-16;for(let h=0;h<n;h++){m.fill(0);let y=c[h];for(let b=0;b<d;b++){let w=e[(f+b)*n+h];m[b]=oc(w-y&255),y=w}c[h]=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(A=>A===0)){u[R+(b>>2)]|=3<<(b&3)*2;for(let A of w)u.push(A)}}}f+=d}for(let f=n;f<Is;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(e.buffer,e.byteOffset,e.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<t;c++){let l=a(c),m=l-s|0;s=l,Rs(u,Ms(m)<<1>>>0)}return u.push(0,0,0,0),new Uint8Array(u)}if(r==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let u=t/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,Ms(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 Nr(e,t){let n=t&&typeof t=="object"?t:e,r=t&&typeof t=="object"?e: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],d=f?.extensions?.KHR_meshopt_compression,p=d??f?.extensions?.EXT_meshopt_compression;if(!p||typeof p!="object")continue;let h=d?"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",A=p.filter||"NONE";if(A==="COLOR"&&!d)throw Re(`bufferView ${m} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(p.buffer??0)!==0)throw new Error(`${h}: 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(`${h}: bufferView ${m} compressed range [${R}, ${R+b}] out of bounds (${i.byteLength})`);let P=y*v;if(a+=P,a>As)throw Re(`total decompressed size (${a}) exceeds MAX_MESHOPT_TOTAL_BYTES (${As})`);let k=i.subarray(R,R+b),L=Oi(k,y,v,w,A);o.push({index:m,bytes:L,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(e,t){Nr(t)},decodePrimitive(e,t,n){let r=t?.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 Vi={name:"meshopt",onParseGLB(e){ve().decoders.set("meshopt",Ur),Nr(e)}};var hc=`#version 300 es
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 Ts=64*1024*1024,ws=128*1024*1024,tc=16777216;function nc(t){return(t>>>1^-(t&1))&255}function rc(t){return(t>>>1^-(t&1))&65535}function ic(t){let e=t<<24>>24;return(e<<1^e>>7)&255}function Ms(t){return(t<<1^t>>31)>>>0}function Rs(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 Fi(t,e,n,r="NONE"){if(Rs(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 Es=160,lt=16,oc=24,_s=32,sc=24,ac=[0,2,4,8],cc=[0,1,2,4,8];function Ls(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 uc(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 As(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<oc)throw Se("truncated ATTRIBUTES stream");let f=t[l+(m>>2)]>>(m&3)*2&3;e=uc(t,e,r,i+m*lt,a[u+f])}return e}function lc(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)!==Es)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?_s:sc,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=Ls(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?As(t,d,i,p,L*v,R,ac,0):As(t,d,i,p,L*v,R,cc,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=nc(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=rc(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 Is=224,Cs=208;function Ps(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=Ps(t,e),i=r>>>1^-(r&1);return n+i>>>0}function fc(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)!==Is)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 mc(t,e,n){if(t.byteLength<1+e+4)throw Se("truncated INDICES stream");let r=t[0];if((r&240)!==Cs)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=Ps(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 Vi(t,e,n,r,i="NONE"){if(Rs(i),!Number.isInteger(e)||e<0||e>tc||!Number.isInteger(n)||n<=0||n>256)throw Se(`invalid count (${e}) or byteStride (${n})`);let o=e*n;if(o>Ts)throw Se(`decompressed size (${o}) exceeds MAX_MESHOPT_BUFFER_BYTES (${Ts})`);if(e===0)return new Uint8Array(0);let a=new Uint8Array(o);if(r==="ATTRIBUTES")return lc(t,e,n,a),Fi(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"?fc(t,e,s):mc(t,e,s),a}throw Se(`unknown mode "${String(r)}"`)}function Ss(t,e){e>>>=0;do t.push(e&127|(e>127?128:0)),e>>>=7;while(e)}function ks(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=[Es],s=Ls(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]=ic(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<_s;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=[Cs|1],s=0;for(let c=0;c<e;c++){let l=a(c),m=l-s|0;s=l,Ss(u,Ms(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=[Is|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);Ss(s,Ms(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>ws)throw Se(`total decompressed size (${a}) exceeds MAX_MESHOPT_TOTAL_BYTES (${ws})`);let k=i.subarray(R,R+b),I=Vi(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 Bi={name:"meshopt",onParseGLB(t){ve().decoders.set("meshopt",Ur),Dr(t)}};var dc=`#version 300 es
371
373
  layout(location=0) in vec3 aPosition;
372
374
  layout(location=1) in vec3 aNormal;
373
375
  uniform mat4 uMVP,uVP;
@@ -388,7 +390,7 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
388
390
  clipPos.xy+=pxOffset;
389
391
  clipPos.z+=1e-4*clipPos.w;
390
392
  gl_Position=clipPos;
391
- }`,pc=`#version 300 es
393
+ }`,hc=`#version 300 es
392
394
  precision highp float;
393
395
  uniform vec4 uOutlineColor;
394
396
  out vec4 fragColor;
@@ -400,7 +402,7 @@ void main(){
400
402
  vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
401
403
  vUV=pos;
402
404
  gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
403
- }`,bc=`#version 300 es
405
+ }`,pc=`#version 300 es
404
406
  precision highp float;
405
407
  in vec2 vUV;
406
408
  uniform sampler2D uSourceTex;
@@ -423,7 +425,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
423
425
  c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
424
426
  c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
425
427
  fragColor=vec4(c,1.0);
426
- }`,yc=`#version 300 es
428
+ }`,bc=`#version 300 es
427
429
  precision highp float;
428
430
  in vec2 vUV;
429
431
  uniform sampler2D uBloomTex;
@@ -445,4 +447,4 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
445
447
  vec3 bloom=(sum/12.0)*uStrength;
446
448
  float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
447
449
  fragColor=vec4(bloom,a);
448
- }`,Fr=3,Cn=new WeakMap;function zi(e,t=[.22,.74,.97]){let n=Xn(e,"");if(!n.startsWith("#"))return[t[0],t[1],t[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[t[0],t[1],t[2]]}function Os(e,t,n=.8,r=.5){let i=Number.isFinite(t)?Math.max(0,t):0;if(i<=0)return[0,0,0];let o=Math.max(0,Number(e[0])||0),a=Math.max(0,Number(e[1])||0),u=Math.max(0,Number(e[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(e,t,n,r){let i=Number(e[0])||0,o=Number(e[1])||0,a=Math.hypot(i,o);if(a<=1e-5||t<=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*t;return[i/a*(c/u),o/a*(c/s)]}function Bi(e,t,n){let r=e.createProgram();if(!r)return null;let i=[];for(let[o,a]of[[35633,t],[35632,n]]){let u=e.createShader(o);u&&(e.shaderSource(u,a),e.compileShader(u),e.attachShader(r,u),i.push(u))}e.linkProgram(r);for(let o of i)e.detachShader?.(r,o),e.deleteShader?.(o);return i.length<2||typeof e.getProgramParameter=="function"&&!e.getProgramParameter(r,35714)?(e.deleteProgram?.(r),null):r}var Us=new WeakSet;function Fs(e){let t=Cn.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Cn.delete(e)}if(Us.has(e)||e.isContextLost?.())return null;let n=Bi(e,hc,pc),r=Bi(e,Ns,bc),i=Bi(e,Ns,yc);if(!n||!r||!i){for(let a of[n,r,i])a&&e.deleteProgram(a);return Us.add(e),null}let o=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:n,uOutlineMVP:e.getUniformLocation(n,"uMVP"),uOutlineVP:e.getUniformLocation(n,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(n,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(n,"uViewportSize"),uOutlineThickness:e.getUniformLocation(n,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(n,"uOutlineColor"),downProg:r,uDownSourceTex:e.getUniformLocation(r,"uSourceTex"),uDownTexelSize:e.getUniformLocation(r,"uTexelSize"),uDownThreshold:e.getUniformLocation(r,"uThreshold"),upProg:i,uUpBloomTex:e.getUniformLocation(i,"uBloomTex"),uUpTexelSize:e.getUniformLocation(i,"uTexelSize"),uUpRadius:e.getUniformLocation(i,"uRadius"),uUpStrength:e.getUniformLocation(i,"uStrength"),fsVao:o,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Cn.set(e,t),t}function gc(e,t,n,r){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let i=Math.max(2,n|0),o=Math.max(2,r|0);if(t.sceneTex&&t.bloomFbo.length===Fr&&t.texWidth===i&&t.texHeight===o)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,i,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);let a=i,u=o;for(let s=0;s<Fr;s++)a=Math.max(1,a>>1),u=Math.max(1,u>>1),t.mipWidth[s]=a,t.mipHeight[s]=u,t.bloomTex[s]||(t.bloomTex[s]=e.createTexture()),e.bindTexture(3553,t.bloomTex[s]),e.texImage2D(3553,0,6408,a,u,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[s]||(t.bloomFbo[s]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[s]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[s],0);return e.bindFramebuffer(36160,null),t.texWidth=i,t.texHeight=o,!0}function xc(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let r=t.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=ii({strength:o,threshold:en(t.getAttribute("bloom-threshold"),.62),radius:en(t.getAttribute("bloom-radius"),.75)});if(a)return a}}let n=null;for(let r of e.meshes||[]){if(r.visible===!1)continue;let i=r?.extras?.xr?.bloom??r?.userData?.xr?.bloom,o=ii(i);o&&(!n||o.strength>n.strength)&&(n=o)}return n}function vc(e,t){if(e==null)return null;let n=e.trim(),r=n.toLowerCase();if(r==="false"||r==="0"||r==="none")return null;let i=t,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 Tc=new Set(["floor","pedestal","ground","table","grid","pad"]);function wc(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>Tc.has(t))}function Ac(e,t){let n=e.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=t?.extras?.xr?.outline??t?.userData?.xr?.outline,o=Wn(i);if(o)return o;let a=typeof n?.getAttribute=="function"&&n.getAttribute("outline-color")||"#38bdf8",u=vc(r,a),s=n!=null&&typeof n.hasAttribute=="function"&&n.hasAttribute("outline-selected")&&n.getAttribute("outline-selected")!=="false",c=e.getSelectedMesh?.()||"";if(c)return t.name!==c?null:u||(s?Wn({color:a,thickness:3,pulse:!1}):null);if(u){let l=t.name||"";return wc(l)?null:u}return null}var Gi={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,n){if(!t.meshes||t.meshes.length===0)return;let r=Math.max(1,t.canvas?.width||300),i=Math.max(1,t.canvas?.height||150),o=[];for(let f of t.meshes){if(f.visible===!1)continue;let d=Ac(t,f);d&&o.push({mesh:f,trait:d})}let a=o.length>0?Fs(e):null;if(a){let f=a,d=we(),p=we(),h=new Float32Array(9),y=(typeof performance<"u"?performance.now():Date.now())*.001,v=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,R=Math.max(1,v?.[2]||r),b=Math.max(1,v?.[3]||i);e.useProgram(f.outlineProg),f.uOutlineViewportSize&&e.uniform2f(f.uOutlineViewportSize,R,b),f.uOutlineVP&&e.uniformMatrix4fv(f.uOutlineVP,!1,n),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:w,trait:A}of o){let[P,k,L]=zi(A.color),I=A.pulse?.8+.25*Math.sin(y*4):1;f.uOutlineColor&&e.uniform4f(f.uOutlineColor,P,k,L,1),f.uOutlineThickness&&e.uniform1f(f.uOutlineThickness,A.thickness*I),w.worldSpace===!0?d.set(w.transform):Le(d,t.modelRootMatrix,w.transform);let x=w.instanceMatrices;for(let g of w.primitives)if(!(g.pluginData?.skinning?.hasSkin||g.pluginData?.morph?.hasMorph))if(e.bindVertexArray(g.vao),x&&x.length>=16){let S=x.length>>4,D=we();for(let _=0;_<S;_++)Le(D,d,x.subarray(_*16,_*16+16)),Le(p,n,D),Ne(h,D),e.uniformMatrix4fv(f.uOutlineMVP,!1,p),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,h),g.indices?e.drawElements(4,g.indexCount,g.indexType,0):e.drawArrays(4,0,g.indexCount)}else Le(p,n,d),Ne(h,d),e.uniformMatrix4fv(f.uOutlineMVP,!1,p),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,h),g.indices?e.drawElements(4,g.indexCount,g.indexType,0):e.drawArrays(4,0,g.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 u=xc(t);if(!u||u.strength<=0)return;let s=Fs(e);if(!s||!gc(e,s,r,i)||!s.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,s.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,r,i),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(s.downProg),e.uniform1i(s.uDownSourceTex,0),e.bindVertexArray(s.fsVao);let c=s.sceneTex,l=r,m=i;for(let f=0;f<Fr;f++){let d=s.mipWidth[f],p=s.mipHeight[f];e.bindFramebuffer(36160,s.bloomFbo[f]),e.viewport(0,0,d,p),e.bindTexture(3553,c),e.uniform2f(s.uDownTexelSize,1/l,1/m),e.uniform1f(s.uDownThreshold,f===0?u.threshold:0),e.drawArrays(4,0,3),c=s.bloomTex[f],l=d,m=p}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(s.upProg),e.uniform1i(s.uUpBloomTex,0),e.uniform1f(s.uUpRadius,u.radius);for(let f=Fr-1;f>=1;f--){let d=f-1;e.bindFramebuffer(36160,s.bloomFbo[d]),e.viewport(0,0,s.mipWidth[d],s.mipHeight[d]),e.bindTexture(3553,s.bloomTex[f]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[f],1/s.mipHeight[f]),e.uniform1f(s.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,r,i),e.bindTexture(3553,s.bloomTex[0]),e.uniform2f(s.uUpTexelSize,1/s.mipWidth[0],1/s.mipHeight[0]),e.uniform1f(s.uUpStrength,u.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=Cn.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 n of t.bloomTex)n&&e.deleteTexture(n);for(let n of t.bloomFbo)n&&e.deleteFramebuffer(n);Cn.delete(e)}}};function Hi(e){let n=e?.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(e){let n=e?.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(e,t,n,r=0){let i=e;if(i&&typeof i.selectVariant=="function"&&!Array.isArray(t))return i.selectVariant(typeof t=="string"?t:null);let o=e,a=Array.isArray(t)?t:[],u=n??null;if(!u)return r;let c=Hi(o).indexOf(u);if(c<0)return r;for(let l of a)if(l.variants.includes(c))return l.material;return r}var Xi={name:"variants",onLoadModel(e,t){let n=e.getVariantName?.();n&&e.selectVariant(n)}};var Gs=new WeakMap,Wi={name:"webxr-suite",onConfigureXRSessionInit(e,t){let n=new Set(t.optionalFeatures||[]);n.add("hit-test"),n.add("light-estimation");let r=e?.querySelector?.('[slot="ar-overlay"]')||null;r&&(n.add("dom-overlay"),t.domOverlay={root:r},r.addEventListener?.("beforexrselect",i=>{i.preventDefault()})),t.optionalFeatures=Array.from(n)},onXRFrame(e,t,n,r){if(!e||!t||!n||!r)return;let i=Gs.get(t);if(i||(i={lightProbe:null},Gs.set(t,i),typeof t.requestLightProbe=="function"&&t.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(e.lights)){let s=e.lights.find(l=>l.type==="directional");s||(s={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.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&&e.gl&&Er(e.gl,o.sphericalHarmonicsCoefficients)}}}};Oe(En);Oe(Ci);Oe(_i);Oe(Ui);Oe(Wi);Oe(Ni);Oe(Vi);Oe(Xi);Oe(Gi);ct.registerScriptRunner(Jt);typeof window<"u"&&(window.ThreeLiveBundle=$i);export{xn as AmbientLight,hn as BoxGeometry,Se as BufferAttribute,Ye as BufferGeometry,Tn as Camera,gr as CapsuleGeometry,vr as CircleGeometry,mr as Clock,et as Color,er as ConeGeometry,Et as CylinderGeometry,ur as DirectionalLight,br as DodecahedronGeometry,mn as Euler,Yn as Float32BufferAttribute,cr as Group,Mn as HemisphereLight,ho as IKSolver,hr as IcosahedronGeometry,gn as InstancedMesh,In as InteractivityVM,Dt as Light,ao as MAX_BSP_DEPTH,so as MAX_CSG_TRIANGLES,yn as MAX_INSTANCES_PER_MESH,uo as MAX_SHAPE_POINTS,co as MAX_TEXT_GEOMETRY_CHARS,at as Material,Xo as MathUtils,Kn as Matrix3,Ct as Matrix4,kt as Mesh,ir as MeshBasicMaterial,or as MeshLambertMaterial,sr as MeshPhongMaterial,ar as MeshPhysicalMaterial,Pt as MeshStandardMaterial,tt as Object3D,pr as OctahedronGeometry,lr as PerspectiveCamera,Jn as PlaneGeometry,vn as PointLight,Nt as PolyhedronFallbackGeometry,dn as Quaternion,ts as RawShaderMaterial,ns as RectAreaLight,xr as RingGeometry,wn as Scene,st as SceneQuotaValidator,An as ShaderMaterial,pn as SphereGeometry,Tr as SpotLight,Ut as THREE,yr as TetrahedronGeometry,bn as Texture,rr as TextureLoader,ct as ThreeLiveElement,Xe as ThreeView,tr as TorusGeometry,nr as TorusKnotGeometry,Zn as Uint16BufferAttribute,Qn as Uint32BufferAttribute,jn as Vector2,Fe as Vector3,qn as Vector4,fr as WebGLRenderer,Rr as activateAR,Fi as applyMeshoptFilter,Jt as authorScriptRunner,ui as buildSandboxWorkerSource,Vr as cadPlugin,es as clearAuthorWarnings,Vs as computeOutlineClipOffset,En as contactShadowPlugin,Zt as createUSDZBlob,pi as crossFadeTo,Oi as decodeMeshoptBuffer,Nr as decodeMeshoptGLB,Ds as encodeMeshoptBuffer,_i as environmentMapPlugin,Os as evaluateKawaseBloom,So as evaluateToneMapping,si as exportSceneToCanvas3D,ai as exportSceneToGLB,$o as exportSceneToUSDZ,Hi as extractMaterialVariants,Bs as extractPrimitiveVariantMappings,cn as generateUSDZ,Sr as getARCapabilities,Ko as getAllowClientScripts,Jo as getAuthorWarnings,ls as getBestARMode,ds as getEnvironmentSH,Pr as getInteractivityVM,ci as getSandboxEngineSrc,qo as getSandboxIframeSrc,an as glbToUSDZ,Ci as hotspotPlugin,Kr as ikPlugin,Fn as installCadExtension,Ni as interactivityPlugin,_t as isAllowedSandboxEngineUrl,Ai as isQuickLookSupported,Mi as isSceneViewerSupported,Si as isWebXRSupported,bi as keyframeAnimationPlugin,Ui as materialsPlugin,Ur as meshoptDecoder,Vi as meshoptPlugin,yi as morphPlugin,ln as noopProxy,hi as parseAnimations,zi as parseHexRgb,_n as parseSafeGltfPointer,Gi as postprocessingPlugin,Bn as quatFromUnitVectors,Ts as registerMaterialShader,tn as sampleChannel,Kt as sceneToCanvas3D,sn as sceneToGLB,Yt as sceneToUSDZ,zs as selectMaterialVariant,Di as sendInteractivityEvent,Ia as setAllowClientScripts,Er as setEnvironmentSH,ss as setMorphTargetWeight,Sa as setSandboxEngineSrc,Ea as setSandboxIframeSrc,xi as skinningPlugin,jr as solveFABRIK,$r as solveTwoBoneIK,fn as threeAuthorPlugin,Oa as threeMicroPlugin,ht as toGLBData,jo as toTrustedWorkerScriptURL,li as validateSandboxWorkerMessage,Xi as variantsPlugin,Ze as warnUnsupported,Wi as webxrPlugin};
450
+ }`,Or=3,Pn=new WeakMap;function zi(t,e=[.22,.74,.97]){let n=ri(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 Os(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 Fs(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 Ds=new WeakSet;function Us(t){let e=Pn.get(t);if(e){if(typeof t.isProgram!="function"||t.isProgram(e.outlineProg))return e;Pn.delete(t)}if(Ds.has(t)||t.isContextLost?.())return null;let n=St(t,dc,hc,!1),r=St(t,Ns,pc,!1),i=St(t,Ns,bc,!1);if(!n||!r||!i){for(let a of[n,r,i])a&&t.deleteProgram(a);return Ds.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 yc(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 gc(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=ii({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=ii(i);o&&(!n||o.strength>n.strength)&&(n=o)}return n}function xc(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 vc=new Set(["floor","pedestal","ground","table","grid","pad"]);function Tc(t){return t.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(e=>vc.has(e))}function wc(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=xc(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 Tc(l)?null:u}return null}var Gi={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=wc(e,f);h&&o.push({mesh:f,trait:h})}let a=o.length>0?Us(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]=zi(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=gc(e);if(!u||u.strength<=0)return;let s=Us(t);if(!s||!yc(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 Hi(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 Vs(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 Bs(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=Hi(o).indexOf(u);if(c<0)return r;for(let l of a)if(l.variants.includes(c))return l.material;return r}var Xi={name:"variants",onLoadModel(t,e){let n=t.getVariantName?.();n&&t.selectVariant(n)}};var zs=new WeakMap,Wi={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=zs.get(e);if(i||(i={lightProbe:null},zs.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(Pi);Oe(Li);Oe(Oi);Oe(Wi);Oe(Ui);Oe(Bi);Oe(Xi);Oe(Gi);ct.registerScriptRunner(en);typeof window<"u"&&(window.ThreeLiveBundle=$i);export{vn as AmbientLight,pn as BoxGeometry,$e as BufferAttribute,Ye as BufferGeometry,wn as Camera,gr as CapsuleGeometry,vr as CircleGeometry,mr as Clock,et as Color,er as ConeGeometry,_t as CylinderGeometry,ur as DirectionalLight,br as DodecahedronGeometry,dn as Euler,Yn as Float32BufferAttribute,cr as Group,Sn as HemisphereLight,ho as IKSolver,hr as IcosahedronGeometry,xn as InstancedMesh,In as InteractivityVM,Dt as Light,ao as MAX_BSP_DEPTH,so as MAX_CSG_TRIANGLES,gn as MAX_INSTANCES_PER_MESH,uo as MAX_SHAPE_POINTS,co as MAX_TEXT_GEOMETRY_CHARS,at as Material,Ho as MathUtils,Kn as Matrix3,Pt as Matrix4,Nt as Mesh,ir as MeshBasicMaterial,or as MeshLambertMaterial,sr as MeshPhongMaterial,ar as MeshPhysicalMaterial,kt as MeshStandardMaterial,tt as Object3D,pr as OctahedronGeometry,lr as PerspectiveCamera,Jn as PlaneGeometry,Tn as PointLight,Ut as PolyhedronFallbackGeometry,hn as Quaternion,es as RawShaderMaterial,ts as RectAreaLight,xr as RingGeometry,Mn as Scene,st as SceneQuotaValidator,An as ShaderMaterial,bn as SphereGeometry,Tr as SpotLight,Ot as THREE,yr as TetrahedronGeometry,yn as Texture,rr as TextureLoader,ct as ThreeLiveElement,He as ThreeView,tr as TorusGeometry,nr as TorusKnotGeometry,Zn as Uint16BufferAttribute,Qn as Uint32BufferAttribute,jn as Vector2,Ue as Vector3,qn as Vector4,fr as WebGLRenderer,Rr as activateAR,Fi as applyMeshoptFilter,en as authorScriptRunner,ui as buildSandboxWorkerSource,Vr as cadPlugin,Jo as clearAuthorWarnings,Fs as computeOutlineClipOffset,_n as contactShadowPlugin,Qt as createUSDZBlob,bi as crossFadeTo,Vi as decodeMeshoptBuffer,Dr as decodeMeshoptGLB,ks as encodeMeshoptBuffer,Li as environmentMapPlugin,Os as evaluateKawaseBloom,Ao as evaluateToneMapping,si as exportSceneToCanvas3D,ai as exportSceneToGLB,Wo as exportSceneToUSDZ,Hi as extractMaterialVariants,Vs as extractPrimitiveVariantMappings,un as generateUSDZ,Sr as getARCapabilities,qo as getAllowClientScripts,Qo as getAuthorWarnings,us as getBestARMode,ms as getEnvironmentSH,Pr as getInteractivityVM,ci as getSandboxEngineSrc,jo as getSandboxIframeSrc,cn as glbToUSDZ,Pi as hotspotPlugin,Kr as ikPlugin,Fn as installCadExtension,Ui as interactivityPlugin,Lt as isAllowedSandboxEngineUrl,Ai as isQuickLookSupported,Si as isSceneViewerSupported,Ri as isWebXRSupported,yi as keyframeAnimationPlugin,Oi as materialsPlugin,Ur as meshoptDecoder,Bi as meshoptPlugin,gi as morphPlugin,fn as noopProxy,pi as parseAnimations,zi as parseHexRgb,Ln as parseSafeGltfPointer,Gi as postprocessingPlugin,zn as quatFromUnitVectors,vs as registerMaterialShader,nn as sampleChannel,Yt as sceneToCanvas3D,an as sceneToGLB,Zt as sceneToUSDZ,Bs as selectMaterialVariant,Di as sendInteractivityEvent,_a as setAllowClientScripts,Er as setEnvironmentSH,os as setMorphTargetWeight,Aa as setSandboxEngineSrc,Ra as setSandboxIframeSrc,vi as skinningPlugin,jr as solveFABRIK,$r as solveTwoBoneIK,mn as threeAuthorPlugin,Oa as threeMicroPlugin,ht as toGLBData,$o as toTrustedWorkerScriptURL,li as validateSandboxWorkerMessage,Xi as variantsPlugin,Ze as warnUnsupported,Wi as webxrPlugin};