three-live 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/index.d.ts +190 -0
- package/dist/three-author-engine.js +171 -163
- package/dist/three-author.cjs +145 -163
- package/dist/three-author.d.ts +190 -0
- package/dist/three-author.js +145 -163
- package/dist/three-convert.cjs +142 -160
- package/dist/three-convert.d.ts +190 -0
- package/dist/three-convert.js +142 -160
- package/dist/three-live-ai.cjs +41 -0
- package/dist/three-live-ai.d.ts +759 -0
- package/dist/three-live-ai.js +41 -0
- package/dist/three-live-ai.min.js +41 -0
- package/dist/three-live-animation.cjs +6 -6
- package/dist/three-live-animation.d.ts +190 -0
- package/dist/three-live-animation.js +5 -5
- package/dist/three-live-animation.min.js +5 -5
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +190 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +50 -85
- package/dist/three-live-element.d.ts +190 -0
- package/dist/three-live-element.js +50 -85
- package/dist/three-live-full.cjs +907 -189
- package/dist/three-live-full.js +907 -189
- package/dist/three-live-full.min.js +907 -189
- package/dist/three-live-procedural.cjs +16 -0
- package/dist/three-live-procedural.d.ts +759 -0
- package/dist/three-live-procedural.js +16 -0
- package/dist/three-live-procedural.min.js +16 -0
- package/dist/three-live-sandbox.html +11 -1
- package/dist/three-live-studio.cjs +72 -17
- package/dist/three-live-studio.d.ts +190 -0
- package/dist/three-live-studio.js +72 -17
- package/dist/three-live-studio.min.js +73 -18
- package/dist/three-live-tsl.cjs +103 -0
- package/dist/three-live-tsl.d.ts +759 -0
- package/dist/three-live-tsl.js +103 -0
- package/dist/three-live-tsl.min.js +103 -0
- package/dist/three-live-viewer.cjs +50 -85
- package/dist/three-live-viewer.d.ts +190 -0
- package/dist/three-live-viewer.js +50 -85
- package/dist/three-live-viewer.min.js +50 -85
- package/dist/three-live-webgpu.cjs +585 -0
- package/dist/three-live-webgpu.d.ts +759 -0
- package/dist/three-live-webgpu.js +585 -0
- package/dist/three-live-webgpu.min.js +585 -0
- package/dist/three-live.cjs +147 -165
- package/dist/three-live.js +147 -165
- package/dist/three-live.min.js +147 -165
- package/dist/three-view.cjs +49 -84
- package/dist/three-view.d.ts +190 -0
- package/dist/three-view.js +50 -85
- package/dist/three-xr.cjs +141 -159
- package/dist/three-xr.d.ts +190 -0
- package/dist/three-xr.js +140 -158
- package/package.json +21 -1
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
|
-
*/var ThreeEngine=(()=>{var wi=Object.defineProperty,da=Object.getOwnPropertyDescriptor,pa=Object.getOwnPropertyNames,fa=Object.prototype.hasOwnProperty,ma=(t,e)=>{for(var i in e)wi(t,i,{get:e[i],enumerable:!0})},ga=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of pa(e))!fa.call(t,s)&&s!==i&&wi(t,s,{get:()=>e[s],enumerable:!(r=da(e,s))||r.enumerable});return t},ya=t=>ga(wi({},"__esModule",{value:!0}),t),lr={};ma(lr,{AmbientLight:()=>Wi,BoxGeometry:()=>Bi,BufferAttribute:()=>Oe,BufferGeometry:()=>Ie,Camera:()=>Xi,CapsuleGeometry:()=>Bs,CatmullRomCurve3:()=>us,CircleGeometry:()=>js,Clock:()=>Ms,Color:()=>nt,ConeGeometry:()=>is,CubicBezierCurve3:()=>ls,Curve3:()=>Mt,CylinderGeometry:()=>ji,DataTexture:()=>cs,DirectionalLight:()=>qi,DodecahedronGeometry:()=>Os,EdgesGeometry:()=>Ws,Euler:()=>Oi,Float32BufferAttribute:()=>Zr,Group:()=>ys,HemisphereLight:()=>or,IcosahedronGeometry:()=>$s,InstancedMesh:()=>pi,LatheGeometry:()=>Vi,Light:()=>Rt,Line:()=>zt,LineBasicMaterial:()=>xi,LineCurve3:()=>os,LineDashedMaterial:()=>Vs,LineLoop:()=>qs,LineSegments:()=>Xs,MAX_INSTANCES_PER_MESH:()=>Ht,Material:()=>Xe,MathUtils:()=>Yr,Matrix3:()=>Xr,Matrix4:()=>pt,Mesh:()=>yt,MeshBasicMaterial:()=>ps,MeshLambertMaterial:()=>fs,MeshPhongMaterial:()=>ms,MeshPhysicalMaterial:()=>gs,MeshStandardMaterial:()=>Nt,Object3D:()=>Ye,OctahedronGeometry:()=>Fs,PerspectiveCamera:()=>mi,PlaneGeometry:()=>es,PointLight:()=>fi,Points:()=>Ks,PointsMaterial:()=>ar,PolyhedronFallbackGeometry:()=>on,PolyhedronGeometry:()=>wt,QuadraticBezierCurve3:()=>ns,Quaternion:()=>ui,RawShaderMaterial:()=>Cs,RectAreaLight:()=>Ys,RingGeometry:()=>sr,Scene:()=>Wt,SceneQuotaValidator:()=>bt,ShaderMaterial:()=>rr,SphereGeometry:()=>ts,SpotLight:()=>vi,THREE:()=>lt,TetrahedronGeometry:()=>Is,Texture:()=>di,TextureLoader:()=>ds,TorusGeometry:()=>rs,TorusKnotGeometry:()=>as,TubeGeometry:()=>hs,Uint16BufferAttribute:()=>Jr,Uint32BufferAttribute:()=>Qr,Vector2:()=>ot,Vector3:()=>ve,Vector4:()=>qr,WebGLRenderer:()=>xs,WireframeGeometry:()=>Hs,authorScriptRunner:()=>ks,buildSandboxWorkerSource:()=>Qi,clearAuthorWarnings:()=>ir,default:()=>hn,exportSceneToCanvas3D:()=>Ki,exportSceneToGLB:()=>Yi,exportSceneToUSDZ:()=>bs,generateUSDZ:()=>zr,getAllowClientScripts:()=>As,getAuthorWarnings:()=>tr,getSandboxEngineSrc:()=>Zi,getSandboxIframeSrc:()=>Ss,glbToUSDZ:()=>zi,isAllowedSandboxEngineUrl:()=>Lt,noopProxy:()=>Et,sceneToCanvas3D:()=>jt,sceneToGLB:()=>ei,sceneToUSDZ:()=>ai,setAllowClientScripts:()=>Yo,setSandboxEngineSrc:()=>Wo,setSandboxIframeSrc:()=>Xo,threeAuthorPlugin:()=>Xt,threeMicroPlugin:()=>un,toTrustedWorkerScriptURL:()=>Ts,validateSandboxWorkerMessage:()=>er,warnUnsupported:()=>vt});function ur(t,e,i){let r=[],s=new Map,a=[],o=[],n=[],u=new Map,d=f=>{let g=s.get(f);return g===void 0&&(g=r.length,r.push({op:f}),s.set(f,g)),g},h=f=>{let g=u.get(f);return g===void 0&&(g=n.length,n.push({id:f}),u.set(f,g)),g},l=(f,g={})=>a.push({declaration:d(f),...g})-1,p=(f,g,T)=>o.push({id:f,type:g,value:T})-1,m=f=>({node:f,socket:"value"}),y=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(y&&typeof y=="object"){let f=Array.isArray(y.graphs)?y.graphs[y.graph??0]:y;if(f&&Array.isArray(f.nodes)){let g=Array.isArray(f.declarations)?f.declarations:[];for(let T of g)T?.op&&d(T.op);Array.isArray(f.variables)&&o.push(...f.variables);for(let T of f.events||[])T?.id&&h(T.id);for(let T of f.nodes){if(!T||typeof T!="object")continue;let R=T.op||(typeof T.declaration=="number"?g[T.declaration]?.op:"");a.push(R?{...T,declaration:d(R)}:{...T})}}}let x=(f,g,T="translation")=>T==="baseColorFactor"||T==="metallicFactor"||T==="roughnessFactor"?`/materials/${Math.max(0,g)}/pbrMetallicRoughness/${T}`:T==="emissiveFactor"||T==="alphaCutoff"?`/materials/${Math.max(0,g)}/${T}`:T==="visible"?`/nodes/${f}/extensions/KHR_node_visibility/visible`:`/nodes/${f}/${T}`,w=new Map;t.forEach((f,g)=>{typeof f?.name=="string"&&!w.has(f.name)&&w.set(f.name,g)});let v=(f,g)=>typeof f.target=="string"&&w.has(f.target)?w.get(f.target):typeof f.targetNode=="number"?f.targetNode:g,_=f=>{let g=t[f];return(typeof g?.mesh=="number"?e[g.mesh]?.primitives?.[0]?.material:0)??0};for(let f=0;f<t.length;f++){let g=t[f],T=g?.extras?.interactivity;if(!T||typeof T!="object")continue;let R=(typeof g.mesh=="number"?e[g.mesh]?.primitives?.[0]?.material:0)??0,U=$=>{let L=Array.isArray($)?$:[$],E=[];for(let I=0;I<L.length;I++){let c=L[I];if(!c||typeof c!="object")continue;let k=c.action||"interpolate",K=typeof c.duration=="number"?c.duration:.35;if(k==="toggleTransform"){let A=c.property==="rotation"||c.property==="scale"?c.property:"translation",z=A==="rotation"?g.rotation||[0,0,0,1]:A==="scale"?g.scale||[1,1,1]:g.translation||[0,0,0],S=`/nodes/${f}/${A}`,b=p(`__toggle_${f}_${I}`,"bool",!1),O=l("variable/get",{configuration:{variable:b}}),X=l("math/not",{values:{a:m(O)}}),te=l("variable/set",{configuration:{variable:b},values:{value:m(X)}}),re=l("pointer/interpolate",{configuration:{pointer:S},values:{value:{value:Array.isArray(c.to)?c.to:z},duration:{value:K}}}),Z=l("pointer/interpolate",{configuration:{pointer:S},values:{value:{value:Array.isArray(c.from)?c.from:z},duration:{value:K}}});a[te].flows={out:{node:l("flow/branch",{values:{condition:m(O)},flows:{true:{node:re},false:{node:Z}}})}},E.push(te)}else if(k==="interpolate"){let A=c.to??c.value;if(A===void 0)continue;let z={value:{value:A},duration:{value:K}};c.from!==void 0&&(z.from={value:c.from}),E.push(l("pointer/interpolate",{configuration:{pointer:typeof c.pointer=="string"?c.pointer:x(v(c,f),_(v(c,f)),c.property)},values:z}))}else if(k==="setProperty"){if(c.value===void 0)continue;E.push(l("pointer/set",{configuration:{pointer:typeof c.pointer=="string"?c.pointer:x(v(c,f),_(v(c,f)),c.property)},values:{value:{value:c.value}}}))}else if(k==="toggleVisibility"){let A=v(c,f),z=p(`__vis_${A}_${I}`,"bool",!0),S=l("variable/get",{configuration:{variable:z}}),b=l("math/not",{values:{a:m(S)}}),O=l("variable/set",{configuration:{variable:z},values:{value:m(b)}});a[O].flows={out:{node:l("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:m(S)}})}},E.push(O)}else if(k==="cycleMaterialColor"&&Array.isArray(c.colors)&&c.colors.length>0){let A=typeof c.duration=="number"?c.duration:.25,z=`/materials/${Math.max(0,R)}/pbrMetallicRoughness/baseColorFactor`,S=p(`__color_idx_${f}_${I}`,"int",0),b=l("variable/get",{configuration:{variable:S}}),O=l("math/add",{values:{a:m(b),b:{value:1}}}),X=l("math/rem",{values:{a:m(O),b:{value:c.colors.length}}}),te=l("variable/set",{configuration:{variable:S},values:{value:m(X)}}),re={};for(let Z=0;Z<c.colors.length;Z++){let ne=c.colors[Z],pe=Array.isArray(ne)&&ne.length>=3?[ne[0],ne[1],ne[2],ne[3]??1]:[1,1,1,1];re[String(Z)]={node:A>0?l("pointer/interpolate",{configuration:{pointer:z},values:{value:{value:pe},duration:{value:A}}}):l("pointer/set",{configuration:{pointer:z},values:{value:{value:pe}}})}}a[te].flows={out:{node:l("flow/switch",{values:{selection:m(b)},flows:re})}},E.push(te)}else if(k==="playAnimation")E.push(l("animation/start",{configuration:{animation:c.animation??c.clip??0}}));else if(k==="stopAnimation")E.push(l("animation/stop"));else if(k==="sendEvent"){let A={};for(let[z,S]of Object.entries(c.values||{}))A[z]={value:S};E.push(l("event/send",{configuration:{event:h(String(c.event??c.id??"custom"))},values:A}))}}if(!E.length)return null;if(E.length===1)return E[0];let B={};return E.forEach((I,c)=>{B[String(c)]={node:I}}),l("flow/sequence",{flows:B})},j=($,L,E)=>{let B=U(L);B!==null&&l($,{...E?{configuration:E}:{},flows:{out:{node:B}}})};if(T.onSelect&&j("pointer/onSelect",T.onSelect,{nodeIndex:f}),T.onHoverIn&&j("pointer/onHoverIn",T.onHoverIn,{nodeIndex:f}),T.onHoverOut&&j("pointer/onHoverOut",T.onHoverOut,{nodeIndex:f}),T.onStart&&j("event/onStart",T.onStart),T.onReceive&&typeof T.onReceive=="object")for(let[$,L]of Object.entries(T.onReceive))j("event/receive",L,{event:h($)})}return a.length?{graphs:[{declarations:r,nodes:a,variables:o,events:n}],graph:0}:null}var ba='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).',xa="Security Error: client-side scripts require allow-client-scripts opt-in.",Zt="__THREE_LIVE_REGISTRY__";function Re(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Zt]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Zt,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Zt]=e}}return t[Zt]}var Ce=Re().plugins;function va(t){let e=Re().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function Ma(){return Re().plugins}function wa(t,e){if(!t||!t.BufferGeometry)return null;let i=t.Vector2,r=t.Vector3,s=t.Quaternion,a=t.Matrix4,o=t.Matrix3,n=t.Color,u=t.BufferAttribute,d=t.BufferGeometry,h=t.Material,l=t.MeshStandardMaterial,p=t.Mesh,m=8192,y=2048,x=128,w=4096,v=(P,M)=>{let D=P==null?NaN:Number(P);return Number.isFinite(D)?D:M};class _{constructor(M){this.currentPoint=new i(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 D=1;D<M.length;D++)this.lineTo(M[D].x,M[D].y);return this}moveTo(M,D){let N=Number(M)||0,C=Number(D)||0;return this.currentPoint.set(N,C),this.segments.push({type:"move",pts:[N,C]}),this}lineTo(M,D){let N=Number(M)||0,C=Number(D)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(N,C),this.segments.push({type:"line",pts:[N,C]}),this}quadraticCurveTo(M,D,N,C){let H=this.currentPoint.x,V=this.currentPoint.y,G=Number(M)||0,W=Number(D)||0,F=Number(N)||0,Q=Number(C)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[H,V]}),this.currentPoint.set(F,Q),this.segments.push({type:"quad",pts:[H,V,G,W,F,Q]}),this}bezierCurveTo(M,D,N,C,H,V){let G=this.currentPoint.x,W=this.currentPoint.y,F=Number(M)||0,Q=Number(D)||0,Y=Number(N)||0,q=Number(C)||0,oe=Number(H)||0,ce=Number(V)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[G,W]}),this.currentPoint.set(oe,ce),this.segments.push({type:"cubic",pts:[G,W,F,Q,Y,q,oe,ce]}),this}absarc(M,D,N,C,H,V=!1){return this.absellipse(M,D,N,N,C,H,V,0)}arc(M,D,N,C,H,V=!1){return this.absarc(this.currentPoint.x+(Number(M)||0),this.currentPoint.y+(Number(D)||0),N,C,H,V)}absellipse(M,D,N,C,H,V,G=!1,W=0){let F=Number(M)||0,Q=Number(D)||0,Y=Math.max(0,Number(N)||0),q=Math.max(0,Number(C)||0),oe=Number(H)||0,ce=Number(V)||0,me=G?1:0,fe=Number(W)||0;this.segments.push({type:"arc",pts:[F,Q,Y,q,oe,ce,me,fe]});let de=Math.cos(fe),ge=Math.sin(fe),we=Y*Math.cos(ce),be=q*Math.sin(ce);return this.currentPoint.set(F+we*de-be*ge,Q+we*ge+be*de),this}ellipse(M,D,N,C,H,V,G=!1,W=0){return this.absellipse(this.currentPoint.x+(Number(M)||0),this.currentPoint.y+(Number(D)||0),N,C,H,V,G,W)}closePath(){if(this.segments.length>0){let M=this.segments[0],D=0,N=0;if(M.type==="arc"){let C=M.pts[0],H=M.pts[1],V=M.pts[2],G=M.pts[3],W=M.pts[4],F=M.pts[7],Q=Math.cos(F),Y=Math.sin(F),q=V*Math.cos(W),oe=G*Math.sin(W);D=C+q*Q-oe*Y,N=H+q*Y+oe*Q}else D=M.pts[0],N=M.pts[1];Math.hypot(this.currentPoint.x-D,this.currentPoint.y-N)>1e-6&&this.lineTo(D,N)}return this}getPoints(M=12){let D=Math.max(1,Math.min(128,Math.floor(Number(M)||12))),N=[],C=(H,V)=>{if(N.length>0){let G=N[N.length-1];if(Math.hypot(G.x-H,G.y-V)<1e-6)return}N.push(new i(H,V))};for(let H of this.segments){let V=H.pts;if(H.type==="move"||H.type==="line")C(V[0],V[1]);else if(H.type==="quad"){let G=V[0],W=V[1],F=V[2],Q=V[3],Y=V[4],q=V[5];C(G,W);for(let oe=1;oe<=D;oe++){let ce=oe/D,me=1-ce;C(me*me*G+2*me*ce*F+ce*ce*Y,me*me*W+2*me*ce*Q+ce*ce*q)}}else if(H.type==="cubic"){let G=V[0],W=V[1],F=V[2],Q=V[3],Y=V[4],q=V[5],oe=V[6],ce=V[7];C(G,W);for(let me=1;me<=D;me++){let fe=me/D,de=1-fe,ge=de*de,we=fe*fe;C(ge*de*G+3*ge*fe*F+3*de*we*Y+we*fe*oe,ge*de*W+3*ge*fe*Q+3*de*we*q+we*fe*ce)}}else if(H.type==="arc"){let G=V[0],W=V[1],F=V[2],Q=V[3],Y=V[4],q=V[5],oe=V[6]!==0,ce=V[7],me=Math.PI*2,fe=q-Y,de=Math.abs(fe)<1e-9;for(;fe<0;)fe+=me;for(;fe>me;)fe-=me;fe<1e-9&&(fe=de?0:me),oe&&!de&&(fe=fe===me?-me:fe-me);let ge=Math.cos(ce),we=Math.sin(ce),be=Math.max(2,D);for(let Ae=0;Ae<=be;Ae++){let Te=Ae/be,Se=Y+Te*fe,Pe=F*Math.cos(Se),Le=Q*Math.sin(Se);C(G+Pe*ge-Le*we,W+Pe*we+Le*ge)}}}if(N.length>2){let H=N[0],V=N[N.length-1];Math.hypot(H.x-V.x,H.y-V.y)<1e-6&&N.pop()}return N}getSpacedPoints(M=12){return this.getPoints(M)}clone(){let M=new this.constructor;return M.currentPoint.copy(this.currentPoint),M.segments=this.segments.map(D=>({type:D.type,pts:[...D.pts]})),Array.isArray(this.holes)&&(M.holes=this.holes.map(D=>D.clone())),M}}class f extends _{constructor(M){super(M),this.holes=[]}extractPoints(M=12){return{shape:this.getPoints(M),holes:this.holes.map(D=>D.getPoints(M))}}}function g(P){let M=0,D=P.length;for(let N=0,C=D-1;N<D;C=N++)M+=P[C].x*P[N].y-P[N].x*P[C].y;return M*.5}function T(P,M,D,N,C,H,V,G){let W=V-D,F=G-N,Q=C-D,Y=H-N,q=P-D,oe=M-N,ce=W*W+F*F,me=W*Q+F*Y,fe=W*q+F*oe,de=Q*Q+Y*Y,ge=Q*q+Y*oe,we=ce*de-me*me;if(Math.abs(we)<1e-12)return!1;let be=1/we,Ae=(de*fe-me*ge)*be,Te=(ce*ge-me*fe)*be;return Ae>=-1e-7&&Te>=-1e-7&&Ae+Te<=1.0000001}function R(P,M){let D=P.slice();g(D)<0&&D.reverse();let N=D.map(W=>new i(W.x,W.y)),C=D.map((W,F)=>F),H=[];for(let W of M){if(!W||W.length<3)continue;let F=W.slice();g(F)>0&&F.reverse();let Q=[],Y=-1/0,q=0;for(let oe=0;oe<F.length;oe++){let ce=F[oe],me=N.length;N.push(new i(ce.x,ce.y)),Q.push(me),ce.x>Y&&(Y=ce.x,q=oe)}H.push({pts:F,indices:Q,maxX:Y,maxIdx:q})}H.sort((W,F)=>F.maxX-W.maxX);let V=(W,F,Q)=>(F.x-W.x)*(Q.y-W.y)-(F.y-W.y)*(Q.x-W.x),G=(W,F,Q)=>{for(let Y=0;Y<Q.length;Y++){let q=Q[Y],oe=Q[(Y+1)%Q.length];if(V(W,F,q)*V(W,F,oe)<0&&V(q,oe,W)*V(q,oe,F)<0)return!0}return!1};for(let W of H){let F=W.pts[W.maxIdx],Q=F.x,Y=C.length,q=C.map(de=>N[de]),oe=de=>Math.hypot(q[de].x-Q,q[de].y-F.y),ce=q.map((de,ge)=>ge).sort((de,ge)=>+(q[de].x<Q)-+(q[ge].x<Q)||oe(de)-oe(ge)),me=ce[0];for(let de of ce){let ge=q[de],we=q[(de+Y-1)%Y],be=q[(de+1)%Y],Ae=V(ge,be,F)>=0,Te=V(we,ge,F)>=0;if((V(we,ge,be)>=0?Ae&&Te:Ae||Te)&&!G(F,ge,q)&&!H.some(Se=>G(F,ge,Se.pts))){me=de;break}}let fe=[];for(let de=0;de<=me;de++)fe.push(C[de]);for(let de=0;de<=W.indices.length;de++){let ge=W.indices[(W.maxIdx+de)%W.indices.length];fe.push(ge)}for(let de=me;de<C.length;de++)fe.push(C[de]);C=fe}return{merged:C.map(W=>N[W]),mergedIndices:C,allVertices:N}}function U(P,M){let D=[],N=P.slice();if(N.length<3)return D;let C=N.length*N.length+64,H=0;for(;N.length>2&&C-- >0;){let V=N.length,G=N[(H+V-1)%V],W=N[H%V],F=N[(H+1)%V],Q=M[G],Y=M[W],q=M[F];if((Y.x-Q.x)*(q.y-Q.y)-(Y.y-Q.y)*(q.x-Q.x)>1e-9){let oe=!0,ce=Math.min(Q.x,Y.x,q.x)-1e-7,me=Math.max(Q.x,Y.x,q.x)+1e-7,fe=Math.min(Q.y,Y.y,q.y)-1e-7,de=Math.max(Q.y,Y.y,q.y)+1e-7;for(let ge=0;ge<V;ge++){let we=N[ge];if(we===G||we===W||we===F)continue;let be=M[we];if(be.x>=ce&&be.x<=me&&be.y>=fe&&be.y<=de&&T(be.x,be.y,Q.x,Q.y,Y.x,Y.y,q.x,q.y)&&(be.x-Q.x)*(be.x-Q.x)+(be.y-Q.y)*(be.y-Q.y)>=1e-12&&(be.x-Y.x)*(be.x-Y.x)+(be.y-Y.y)*(be.y-Y.y)>=1e-12&&(be.x-q.x)*(be.x-q.x)+(be.y-q.y)*(be.y-q.y)>=1e-12){oe=!1;break}}if(oe){D.push([G,W,F]),N.splice(H%V,1),H=Math.max(0,H%V-1);continue}}H++,H>=V*2&&(D.push([G,W,F]),N.splice((H-1)%V,1),H=0)}return D}function j(P,M){let D=P instanceof f?P.extractPoints(M):{shape:P.getPoints(M),holes:[]},N=D.shape.length;for(let C of D.holes)N+=C.length;if(N>w)throw new RangeError(`SecurityError: shape point count (${N}) exceeds MAX_SHAPE_POINTS (${w})`);return D}function $(P){let M=1/0,D=1/0,N=-1/0,C=-1/0;for(let H of P)H.x<M&&(M=H.x),H.y<D&&(D=H.y),H.x>N&&(N=H.x),H.y>C&&(C=H.y);return[M,D,Math.max(1e-6,N-M),Math.max(1e-6,C-D)]}class L extends d{constructor(M=new f,D=12){super();let N=Array.isArray(M)?M:[M],C=[],H=[],V=[],G=[];for(let W of N){if(!(W instanceof _))continue;let F=j(W,D);if(F.shape.length<3)continue;let{mergedIndices:Q,allVertices:Y}=R(F.shape,F.holes),q=U(Q,Y),oe=C.length/3,[ce,me,fe,de]=$(Y);for(let ge of Y)C.push(ge.x,ge.y,0),H.push(0,0,1),V.push((ge.x-ce)/fe,(ge.y-me)/de);for(let[ge,we,be]of q)G.push(oe+ge,oe+we,oe+be)}E(this,C,H,V,G)}}function E(P,M,D,N,C){return P.setAttribute("position",new u(M,3)),P.setAttribute("normal",new u(D,3)),P.setAttribute("uv",new u(N,2)),P.setIndex(C),P}function B(P){let M=P.length,D=[];for(let N=0;N<M;N++){let C=P[(N+M-1)%M],H=P[N],V=P[(N+1)%M],G=H.x-C.x,W=H.y-C.y,F=Math.hypot(G,W)||1;G/=F,W/=F;let Q=V.x-H.x,Y=V.y-H.y,q=Math.hypot(Q,Y)||1;Q/=q,Y/=q;let oe=W,ce=-G,me=Y,fe=-Q,de=oe+me,ge=ce+fe,we=Math.hypot(de,ge);if(we>1e-6){de/=we,ge/=we;let be=Math.max(.35,de*oe+ge*ce);D.push(new i(de/be,ge/be))}else D.push(new i(oe,ce))}return D}class I extends d{constructor(M=new f,D={}){super();let N=Array.isArray(M)?M:[M],C=Math.max(1,Math.min(64,Math.floor(v(D.curveSegments,12)))),H=v(D.depth??D.amount,1),V=Math.max(1,Math.min(32,Math.floor(v(D.steps,1)))),G=!!(D.bevelEnabled??!1),W=G?Math.max(0,v(D.bevelThickness,.06)):0,F=G?Math.max(0,v(D.bevelSize,W*.8)):0,Q=G?v(D.bevelOffset,0):0,Y=G?Math.max(1,Math.min(8,Math.floor(v(D.bevelSegments,2)))):0,q=[],oe=[],ce=[],me=[];for(let fe of N){if(!(fe instanceof _))continue;let de=j(fe,C);if(de.shape.length<3)continue;let ge=de.shape.slice();g(ge)<0&&ge.reverse();let we=[];for(let Ne of de.holes){if(Ne.length<3)continue;let De=Ne.slice();g(De)>0&&De.reverse(),we.push(De)}let{mergedIndices:be,allVertices:Ae}=R(ge,we),Te=U(be,Ae),Se=[ge,...we],Pe=[];for(let Ne of Se){let De=B(Ne);for(let Ve of De)Pe.push(Ve)}let[Le,Ke,He,ut]=$(Ae);for(let[Ne,De]of[[-W,-1],[H+W,1]]){let Ve=q.length/3;for(let Be=0;Be<Ae.length;Be++){let Ue=Ae[Be],Fe=Pe[Be]??new i(0,0),Je=Ue.x+Fe.x*Q,qe=Ue.y+Fe.y*Q;q.push(Je,qe,Ne),oe.push(0,0,De),ce.push((Je-Le)/He,(qe-Ke)/ut)}for(let[Be,Ue,Fe]of Te)me.push(Ve+Be,Ve+(De<0?Fe:Ue),Ve+(De<0?Ue:Fe))}let ke=[];if(G&&Y>0)for(let Ne=0;Ne<Y;Ne++){let De=Ne/Y*Math.PI/2;ke.push({z:-W*Math.cos(De),expand:Q+F*Math.sin(De)})}for(let Ne=0;Ne<=V;Ne++){let De=Ne/V;ke.push({z:De*H,expand:Q+F})}if(G&&Y>0)for(let Ne=1;Ne<=Y;Ne++){let De=Ne/Y*Math.PI/2;ke.push({z:H+W*Math.sin(De),expand:Q+F*Math.cos(De)})}let et=0;for(let Ne of Se){let De=Ne.length;for(let Ve=0;Ve<ke.length-1;Ve++){let Be=ke[Ve],Ue=ke[Ve+1];for(let Fe=0;Fe<De;Fe++){let Je=(Fe+1)%De,qe=Ne[Fe],tt=Ne[Je],it=Pe[et+Fe],rt=Pe[et+Je],ht=qe.x+it.x*Be.expand,ct=qe.y+it.y*Be.expand,kt=tt.x+rt.x*Be.expand,Ct=tt.y+rt.y*Be.expand,Kt=tt.x+rt.x*Ue.expand,Yt=tt.y+rt.y*Ue.expand,_t=qe.x+it.x*Ue.expand,Tt=qe.y+it.y*Ue.expand,St=kt-ht,ft=Ct-ct,cn=_t-ht,dn=Tt-ct,Js=Ue.z-Be.z,It=ft*Js,Ut=-St*Js,Ft=St*dn-ft*cn,nr=Math.hypot(It,Ut,Ft)||1;It/=nr,Ut/=nr,Ft/=nr;let $t=q.length/3;q.push(ht,ct,Be.z,kt,Ct,Be.z,Kt,Yt,Ue.z,_t,Tt,Ue.z),oe.push(It,Ut,Ft,It,Ut,Ft,It,Ut,Ft,It,Ut,Ft);let Qs=Fe/De,ea=(Fe+1)/De,ta=Ve/(ke.length-1),ia=(Ve+1)/(ke.length-1);ce.push(Qs,ta,ea,ta,ea,ia,Qs,ia),me.push($t,$t+1,$t+2,$t,$t+2,$t+3)}}et+=De}}E(this,q,oe,ce,me)}}function c(P){return{x:P.x,y:P.y,z:P.z,nx:P.nx,ny:P.ny,nz:P.nz,u:P.u,v:P.v}}function k(P){return{x:P.x,y:P.y,z:P.z,nx:-P.nx,ny:-P.ny,nz:-P.nz,u:P.u,v:P.v}}function K(P,M,D){let N=P.nx+(M.nx-P.nx)*D,C=P.ny+(M.ny-P.ny)*D,H=P.nz+(M.nz-P.nz)*D,V=Math.hypot(N,C,H)||1;return{x:P.x+(M.x-P.x)*D,y:P.y+(M.y-P.y)*D,z:P.z+(M.z-P.z)*D,nx:N/V,ny:C/V,nz:H/V,u:P.u+(M.u-P.u)*D,v:P.v+(M.v-P.v)*D}}function A(P){if(P.length<3)return null;let M=P[0],D=P[1],N=P[2],C=D.x-M.x,H=D.y-M.y,V=D.z-M.z,G=N.x-M.x,W=N.y-M.y,F=N.z-M.z,Q=H*F-V*W,Y=V*G-C*F,q=C*W-H*G,oe=Math.hypot(Q,Y,q);if(oe<1e-9)return null;Q/=oe,Y/=oe,q/=oe;let ce=Q*M.x+Y*M.y+q*M.z;return{vertices:P,nx:Q,ny:Y,nz:q,w:ce}}function z(P){P.vertices.reverse();for(let M=0;M<P.vertices.length;M++)P.vertices[M]=k(P.vertices[M]);P.nx=-P.nx,P.ny=-P.ny,P.nz=-P.nz,P.w=-P.w}let S=1e-5,b=0,O=1,X=2,te=3;function re(P,M,D,N,C,H,V,G,W){let F=0,Q=[];for(let Y=0;Y<C.vertices.length;Y++){let q=C.vertices[Y],oe=P*q.x+M*q.y+D*q.z-N,ce=oe<-S?X:oe>S?O:b;F|=ce,Q.push(ce)}switch(F){case b:{P*C.nx+M*C.ny+D*C.nz>0?H.push(C):V.push(C);break}case O:G.push(C);break;case X:W.push(C);break;case te:{let Y=[],q=[],oe=C.vertices.length;for(let ge=0;ge<oe;ge++){let we=(ge+1)%oe,be=Q[ge],Ae=Q[we],Te=C.vertices[ge],Se=C.vertices[we];if(be!==X&&Y.push(Te),be!==O&&q.push(be!==X?c(Te):Te),(be|Ae)===te){let Pe=Se.x-Te.x,Le=Se.y-Te.y,Ke=Se.z-Te.z,He=P*Pe+M*Le+D*Ke,ut=Math.abs(He)>1e-12?(N-(P*Te.x+M*Te.y+D*Te.z))/He:.5,ke=K(Te,Se,Math.max(0,Math.min(1,ut)));Y.push(ke),q.push(c(ke))}}let{nx:ce,ny:me,nz:fe,w:de}=C;Y.length>=3&&G.push({vertices:Y,nx:ce,ny:me,nz:fe,w:de}),q.length>=3&&W.push({vertices:q,nx:ce,ny:me,nz:fe,w:de});break}default:break}}class Z{constructor(M,D=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,D)}invert(){for(let D=0;D<this.polygons.length;D++)z(this.polygons[D]);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,D=0){if(!this.hasPlane||M.length===0)return M.slice();if(D>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let N=[],C=[];for(let H=0;H<M.length;H++)re(this.nx,this.ny,this.nz,this.w,M[H],N,C,N,C);return this.front&&N.length>0&&(N=this.front.clipPolygons(N,D+1)),this.back?C=C.length>0?this.back.clipPolygons(C,D+1):[]:C=[],N.concat(C)}clipTo(M,D=0){this.polygons.length>0&&(this.polygons=M.clipPolygons(this.polygons,0)),D<y&&(this.front&&this.front.clipTo(M,D+1),this.back&&this.back.clipTo(M,D+1))}allPolygons(M=[]){for(let D=0;D<this.polygons.length;D++)M.push(this.polygons[D]);return this.front&&this.front.allPolygons(M),this.back&&this.back.allPolygons(M),M}build(M,D=0){if(!M.length)return;if(!this.hasPlane){let H=M[M.length>>1];this.nx=H.nx,this.ny=H.ny,this.nz=H.nz,this.w=H.w,this.hasPlane=!0}if(D>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let N=[],C=[];for(let H=0;H<M.length;H++)re(this.nx,this.ny,this.nz,this.w,M[H],this.polygons,this.polygons,N,C);N.length>0&&(this.front||(this.front=new Z),this.front.build(N,D+1)),C.length>0&&(this.back||(this.back=new Z),this.back.build(C,D+1))}}function ne(P,M){if(!M&&P._csgPolygons)return P._csgPolygons;let D=P.attributes.position;if(!D||D.count===0)return[];let N=P.attributes.normal,C=P.attributes.uv,H=P.index?P.index.array:null,V=Math.floor(H?H.length/3:D.count/3);if(V>m)throw new RangeError(`SecurityError: CSG input triangle count (${V}) exceeds MAX_CSG_TRIANGLES (${m})`);let G=M?M.elements:null,W=G?G[0]*(G[5]*G[10]-G[9]*G[6])-G[4]*(G[1]*G[10]-G[9]*G[2])+G[8]*(G[1]*G[6]-G[5]*G[2])<0:!1,F=G?new o().getNormalMatrix(M).elements:null,Q=q=>{let oe=D.getX(q),ce=D.getY(q),me=D.getZ(q),fe=N?N.getX(q):NaN,de=N?N.getY(q):NaN,ge=N?N.getZ(q):NaN;if(G&&F){let Ae=G[0]*oe+G[4]*ce+G[8]*me+G[12],Te=G[1]*oe+G[5]*ce+G[9]*me+G[13],Se=G[2]*oe+G[6]*ce+G[10]*me+G[14];oe=Ae,ce=Te,me=Se;let Pe=F[0]*fe+F[3]*de+F[6]*ge,Le=F[1]*fe+F[4]*de+F[7]*ge,Ke=F[2]*fe+F[5]*de+F[8]*ge,He=Math.hypot(Pe,Le,Ke)||1;fe=Pe/He,de=Le/He,ge=Ke/He}let we=C?C.getX(q):0,be=C?C.getY(q):0;return{x:oe,y:ce,z:me,nx:fe,ny:de,nz:ge,u:we,v:be}},Y=[];for(let q=0;q<V;q++){let oe=H?H[q*3]:q*3,ce=H?H[q*3+1]:q*3+1,me=H?H[q*3+2]:q*3+2,fe=A(W?[Q(oe),Q(me),Q(ce)]:[Q(oe),Q(ce),Q(me)]);fe&&Y.push(fe)}return Y}function pe(P){let M=[],D=[],N=[],C=[];for(let V of P){let G=V.vertices;if(G.length<3)continue;let W=M.length/3;for(let F of G)M.push(F.x,F.y,F.z),Number.isFinite(F.nx)&&F.nx*F.nx+F.ny*F.ny+F.nz*F.nz>.5?D.push(F.nx,F.ny,F.nz):D.push(V.nx,V.ny,V.nz),N.push(F.u,F.v);for(let F=1;F<G.length-1;F++)C.push(W,W+F,W+F+1)}let H=E(new d,M,D,N,C);return H._csgPolygons=P,H}function xe(P,M,D){if(P.length+M.length>m)throw new RangeError(`SecurityError: Combined CSG triangle count (${P.length+M.length}) exceeds MAX_CSG_TRIANGLES (${m})`);if(P.length===0)return D==="union"?M:[];if(M.length===0)return D==="intersect"?[]:P;let N=1/0,C=1/0,H=1/0,V=-1/0,G=-1/0,W=-1/0;for(let oe=0;oe<M.length;oe++){let ce=M[oe].vertices;for(let me=0;me<ce.length;me++){let fe=ce[me];fe.x<N&&(N=fe.x),fe.y<C&&(C=fe.y),fe.z<H&&(H=fe.z),fe.x>V&&(V=fe.x),fe.y>G&&(G=fe.y),fe.z>W&&(W=fe.z)}}N-=1e-4,C-=1e-4,H-=1e-4,V+=1e-4,G+=1e-4,W+=1e-4;let F=[],Q=[];for(let oe=0;oe<P.length;oe++){let ce=P[oe],me=ce.vertices,fe=1/0,de=1/0,ge=1/0,we=-1/0,be=-1/0,Ae=-1/0;for(let Te=0;Te<me.length;Te++){let Se=me[Te];Se.x<fe&&(fe=Se.x),Se.y<de&&(de=Se.y),Se.z<ge&&(ge=Se.z),Se.x>we&&(we=Se.x),Se.y>be&&(be=Se.y),Se.z>Ae&&(Ae=Se.z)}we<N||fe>V||be<C||de>G||Ae<H||ge>W?Q.push(ce):F.push(ce)}if(F.length===0)return D==="union"?P.concat(M):D==="subtract"?P:[];let Y=new Z(F),q=new Z(M);return D==="union"?(Y.clipTo(q),q.clipTo(Y),q.invert(),q.clipTo(Y),q.invert(),Y.build(q.allPolygons()),Q.concat(Y.allPolygons())):D==="subtract"?(Y.invert(),Y.clipTo(q),q.clipTo(Y),q.invert(),q.clipTo(Y),q.invert(),Y.build(q.allPolygons()),Y.invert(),Q.concat(Y.allPolygons())):(Y.invert(),q.clipTo(Y),q.invert(),Y.clipTo(q),q.clipTo(Y),Y.build(q.allPolygons()),Y.invert(),Y.allPolygons())}function ie(P,M,D,N=null,C=null){{let G=globalThis.__three_live_native_csg_boolean__;if(typeof G=="function"&&P?.attributes?.position?.array&&M?.attributes?.position?.array){let W=D==="subtract"?0:D==="union"?1:2,F=G(P.attributes.position.array,P.attributes.normal?P.attributes.normal.array:null,P.attributes.uv?P.attributes.uv.array:null,P.index?P.index.array:null,N?N.elements:null,M.attributes.position.array,M.attributes.normal?M.attributes.normal.array:null,M.attributes.uv?M.attributes.uv.array:null,M.index?M.index.array:null,C?C.elements:null,W);if(F)return E(new d,F.positions,F.normals,F.uvs,F.indices)}}let H=ne(P,N),V=ne(M,C);return pe(xe(H,V,D))}function he(P,M,D){let N=P instanceof p||!!P?.isMesh,C=M instanceof p||!!M?.isMesh,H=N?P.geometry:P,V=C?M.geometry:M,G=null;if(C)if(M.updateMatrix(),N){P.updateMatrix();let Y=new a().makeScale(1/(P.scale.x||1),1/(P.scale.y||1),1/(P.scale.z||1)),q=Math.hypot(P.quaternion.x,P.quaternion.y,P.quaternion.z,P.quaternion.w)||1,oe=new a().compose(new r(0,0,0),new s(-P.quaternion.x/q,-P.quaternion.y/q,-P.quaternion.z/q,P.quaternion.w/q),new r(1,1,1)),ce=new a().makeTranslation(-P.position.x,-P.position.y,-P.position.z);G=Y.multiply(oe).multiply(ce).multiply(M.matrix)}else G=M.matrix;let W=ie(H,V,D,null,G),F=N?P.material:new l,Q=new p(W,F);return N&&(Q.position.copy(P.position),Q.quaternion.copy(P.quaternion),Q.scale.copy(P.scale),Q.name=P.name),Q}let ee={toGeometry:ie,subtract(P,M){return he(P,M,"subtract")},union(P,M){return he(P,M,"union")},intersect(P,M){return he(P,M,"intersect")}},le={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 ue extends d{constructor(M="",D={}){super();let N=String(M??"").slice(0,x),C=Math.max(.005,Math.min(100,v(D.size,.2))),H=!!(D.bevelEnabled??!1),V=H?Math.max(0,Math.min(2,v(D.bevelThickness,C*.04))):0,G=H?Math.max(0,Math.min(2,v(D.bevelSize,C*.03))):0,W=Math.max(.001,Math.min(20,v(D.depth??D.height,C*.2)))+V*2,F=C*.085+G,Q=C*.68,Y=C*.82,q=[],oe=[],ce=[],me=[],fe=(we,be,Ae,Te,Se,Pe,Le)=>{let Ke=Ae-we,He=Te-be,ut=Math.hypot(Ke,He),ke=1,et=0;ut>1e-6&&(ke=Ke/ut,et=He/ut);let Ne=-et*Se,De=ke*Se,Ve=ke*Se*.6,Be=et*Se*.6,Ue=we-Ve+Ne,Fe=be-Be+De,Je=we-Ve-Ne,qe=be-Be-De,tt=Ae+Ve-Ne,it=Te+Be-De,rt=Ae+Ve+Ne,ht=Te+Be+De,ct=(kt,Ct,Kt,Yt,_t,Tt,St)=>{let ft=q.length/3;q.push(kt[0],kt[1],kt[2],Ct[0],Ct[1],Ct[2],Kt[0],Kt[1],Kt[2],Yt[0],Yt[1],Yt[2]),oe.push(_t,Tt,St,_t,Tt,St,_t,Tt,St,_t,Tt,St),ce.push(0,0,1,0,1,1,0,1),me.push(ft,ft+1,ft+2,ft,ft+2,ft+3)};ct([Ue,Fe,Le],[Je,qe,Le],[tt,it,Le],[rt,ht,Le],0,0,1),ct([Je,qe,Pe],[Ue,Fe,Pe],[rt,ht,Pe],[tt,it,Pe],0,0,-1),ct([Ue,Fe,Pe],[Je,qe,Pe],[Je,qe,Le],[Ue,Fe,Le],-ke,-et,0),ct([tt,it,Pe],[rt,ht,Pe],[rt,ht,Le],[tt,it,Le],ke,et,0),ct([Je,qe,Pe],[tt,it,Pe],[tt,it,Le],[Je,qe,Le],et,-ke,0),ct([rt,ht,Pe],[Ue,Fe,Pe],[Ue,Fe,Le],[rt,ht,Le],-et,ke,0)},de=0,ge=0;for(let we=0;we<N.length;we++){let be=N[we];if(be===`
|
|
17
|
-
`){de=0,ge-=C*1.35;continue}if(be===" "||be===" "){de+=Y*(be===" "?.75:3);continue}if(be==="\r")continue;let Ae=be.toUpperCase(),Te=be!==Ae&&be>="a"&&be<="z",Se=le[Ae]??le["?"],Pe=Te?C*.76:C,Le=Te?Q*.88:Q;for(let Ke of Se)for(let He=0;He<Ke.length-1;He++){let ut=Ke[He],ke=Ke[He+1];fe(de+ut[0]*Le,ge+ut[1]*Pe,de+ke[0]*Le,ge+ke[1]*Pe,F,-W*.5,W*.5)}de+=Te?Y*.88:Y}E(this,q,oe,ce,me),D.center!==!1?this.center():this.computeBoundingBox()}}function J(P){if(!P)return;let M=P,D=P.userData?.xr?.text??P.userData?.xr?.label??P.userData?.xr?.title??P.userData?.xr?.caption??P.userData?.xr?.spatialLabel;if(D!=null&&D!==!1){let C=M.geometry?.attributes?.position;if((!C||C.count===0)&&P.userData._textApplied!==!0){let H="",V=.08,G=.015,W;if(typeof D=="string"||typeof D=="number")H=String(D);else if(typeof D=="object"){let F=D;H=String(F.text??F.value??""),F.size!==void 0&&(V=Number(F.size)||.08),(F.depth!==void 0||F.height!==void 0)&&(G=Number(F.depth??F.height)||V*.2),(typeof F.color=="string"||typeof F.color=="number")&&(W=F.color)}H.trim().length>0&&(M.geometry=new ue(H,{size:V,depth:G}),P.userData._textApplied=!0,M.material instanceof h?W!==void 0&&P.userData._autoTextColorApplied!==!0&&(M.material.color=new n(W),P.userData._autoTextColorApplied=!0):M.material=new l({color:W??16317180}))}}let N=P.userData?.csg;if(N&&typeof N=="object"&&P.userData._csgApplied!==!0&&M.geometry instanceof d&&M.geometry.attributes.position?.count>0){P.userData._csgApplied=!0;let C=Array.isArray(N)?N:[N],H=M.geometry;for(let V of C){if(!V||typeof V!="object")continue;let G=V,W=String(G.op??G.operation??"subtract"),F=W==="union"||W==="intersect"?W:"subtract",Q=G.target??G.mesh??G.geometry;if(Q instanceof p||Q instanceof d)try{let Y=F==="union"?ee.union(M,Q):F==="intersect"?ee.intersect(M,Q):ee.subtract(M,Q);M.geometry!==H&&M.geometry.dispose?.(),M.geometry=Y.geometry}catch(Y){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",Y)}}}}let se={Path:_,Shape:f,ShapeGeometry:L,ExtrudeGeometry:I,TextGeometry:ue,CSG:ee,MAX_CSG_TRIANGLES:m,MAX_BSP_DEPTH:y,MAX_TEXT_GEOMETRY_CHARS:x,MAX_SHAPE_POINTS:w,materializeDeclarativeGeometry:J};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,se),e._cadMaterialize=J,e.materializeDeclarativeGeometry=P=>{e._cadMaterialize?.(P),e._lodMaterialize?.(P)}),se}function ze(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function _i(t,e,i,r,s){let a=1/Math.tan(e/2);t.fill(0),t[0]=a/i,t[5]=a,t[11]=-1;let o=1/(r-s);return t[10]=(s+r)*o,t[14]=2*s*r*o,t}function Jt(t,e,i,r){let[s,a,o]=e,[n,u,d]=r,[h,l,p]=i,m=s-h,y=a-l,x=o-p,w=Math.hypot(m,y,x);w<=1e-5?(m=0,y=0,x=1):(m/=w,y/=w,x/=w);let v=u*x-d*y,_=d*m-n*x,f=n*y-u*m;w=Math.hypot(v,_,f),w<=1e-5?(v=0,_=0,f=0):(v/=w,_/=w,f/=w);let g=y*f-x*_,T=x*v-m*f,R=m*_-y*v;return w=Math.hypot(g,T,R),w<=1e-5?(g=0,T=0,R=0):(g/=w,T/=w,R/=w),t[0]=v,t[1]=g,t[2]=m,t[3]=0,t[4]=_,t[5]=T,t[6]=y,t[7]=0,t[8]=f,t[9]=R,t[10]=x,t[11]=0,t[12]=-(v*s+_*a+f*o),t[13]=-(g*s+T*a+R*o),t[14]=-(m*s+y*a+x*o),t[15]=1,t}function je(t,e,i){let r=e[0],s=e[1],a=e[2],o=e[3],n=e[4],u=e[5],d=e[6],h=e[7],l=e[8],p=e[9],m=e[10],y=e[11],x=e[12],w=e[13],v=e[14],_=e[15],f=i[0],g=i[1],T=i[2],R=i[3];return t[0]=f*r+g*n+T*l+R*x,t[1]=f*s+g*u+T*p+R*w,t[2]=f*a+g*d+T*m+R*v,t[3]=f*o+g*h+T*y+R*_,f=i[4],g=i[5],T=i[6],R=i[7],t[4]=f*r+g*n+T*l+R*x,t[5]=f*s+g*u+T*p+R*w,t[6]=f*a+g*d+T*m+R*v,t[7]=f*o+g*h+T*y+R*_,f=i[8],g=i[9],T=i[10],R=i[11],t[8]=f*r+g*n+T*l+R*x,t[9]=f*s+g*u+T*p+R*w,t[10]=f*a+g*d+T*m+R*v,t[11]=f*o+g*h+T*y+R*_,f=i[12],g=i[13],T=i[14],R=i[15],t[12]=f*r+g*n+T*l+R*x,t[13]=f*s+g*u+T*p+R*w,t[14]=f*a+g*d+T*m+R*v,t[15]=f*o+g*h+T*y+R*_,t}function Ti(t,e,i,r){let s=e[0],a=e[1],o=e[2],n=e[3],u=s+s,d=a+a,h=o+o,l=s*u,p=s*d,m=s*h,y=a*d,x=a*h,w=o*h,v=n*u,_=n*d,f=n*h,g=r[0],T=r[1],R=r[2];return t[0]=(1-(y+w))*g,t[1]=(p+f)*g,t[2]=(m-_)*g,t[3]=0,t[4]=(p-f)*T,t[5]=(1-(l+w))*T,t[6]=(x+v)*T,t[7]=0,t[8]=(m+_)*R,t[9]=(x-v)*R,t[10]=(1-(l+y))*R,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function mt(t,e,i=0){let r=e[0],s=e[1],a=e[2],o=e[4],n=e[5],u=e[6],d=e[8],h=e[9],l=e[10],p=l*n-u*h,m=-l*o+u*d,y=h*o-n*d,x=r*p+s*m+a*y;return!x||i>0&&(!Number.isFinite(x)||Math.abs(x)<=i)||(x=1/x,t[0]=p*x,t[1]=m*x,t[2]=y*x,t[3]=(-l*s+a*h)*x,t[4]=(l*r-a*d)*x,t[5]=(-h*r+s*d)*x,t[6]=(u*s-a*n)*x,t[7]=(-u*r+a*o)*x,t[8]=(n*r-s*o)*x),t}function _a(t,e){let i=e[0],r=e[1],s=e[2],a=e[3],o=e[4],n=e[5],u=e[6],d=e[7],h=e[8],l=e[9],p=e[10],m=e[11],y=e[12],x=e[13],w=e[14],v=e[15],_=i*n-r*o,f=i*u-s*o,g=i*d-a*o,T=r*u-s*n,R=r*d-a*n,U=s*d-a*u,j=h*x-l*y,$=h*w-p*y,L=h*v-m*y,E=l*w-p*x,B=l*v-m*x,I=p*v-m*w,c=_*I-f*B+g*E+T*L-R*$+U*j;return c?(c=1/c,t[0]=(n*I-u*B+d*E)*c,t[1]=(s*B-r*I-a*E)*c,t[2]=(x*U-w*R+v*T)*c,t[3]=(p*R-l*U-m*T)*c,t[4]=(u*L-o*I-d*$)*c,t[5]=(i*I-s*L+a*$)*c,t[6]=(w*g-y*U-v*f)*c,t[7]=(h*U-p*g+m*f)*c,t[8]=(o*B-n*L+d*j)*c,t[9]=(r*L-i*B-a*j)*c,t[10]=(y*R-x*g+v*_)*c,t[11]=(l*g-h*R-m*_)*c,t[12]=(n*$-o*E-u*j)*c,t[13]=(i*E-r*$+s*j)*c,t[14]=(x*f-y*T-w*_)*c,t[15]=(h*T-l*f+p*_)*c,t):null}function hr(t,e,i,r,s){let a=s[0]*e+s[4]*i+s[8]*r+s[12],o=s[1]*e+s[5]*i+s[9]*r+s[13],n=s[2]*e+s[6]*i+s[10]*r+s[14],u=s[3]*e+s[7]*i+s[11]*r+s[15],d=u!==0?1/u:1;t[0]=a*d,t[1]=o*d,t[2]=n*d}function Ta(t,e,i,r,s,a,o,n,u,d,h,l,p,m,y,x,w=0){let v=d-o,_=h-n,f=l-u,g=p-o,T=m-n,R=y-u,U=s*R-a*T,j=a*g-r*R,$=r*T-s*g,L=v*U+_*j+f*$;if(L>-1e-7&&L<1e-7)return!1;let E=1/L,B=t-o,I=e-n,c=i-u,k=E*(B*U+I*j+c*$);if(k<-w||k>1+w)return!1;let K=I*f-c*_,A=c*v-B*f,z=B*_-I*v,S=E*(r*K+s*A+a*z);if(S<-w||k+S>1+w)return!1;let b=E*(g*K+T*A+R*z);if(b>1e-4&&b<x.distance){x.distance=b,x.point=[t+r*b,e+s*b,i+a*b];let O=_*R-f*T,X=f*g-v*R,te=v*T-_*g,re=Math.hypot(O,X,te)||1;return x.normal=[O/re,X/re,te/re],!0}return!1}function Sa(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let h=0;h<i;h++)r.push(ze());if(i===0)return r;let s=new Set;for(let h of t.nodes)if(Array.isArray(h.children))for(let l of h.children)s.add(l);let a=new Set,o=128,n=(h,l,p=0)=>{if(p>o||h<0||h>=i||a.has(h))return;a.add(h);let m=t.nodes[h];if(!m)return;let y=ze();if(e&&e[h])y.set(e[h]);else if(m.matrix&&m.matrix.length===16)y.set(m.matrix);else{let w=m.translation||[0,0,0],v=m.rotation||[0,0,0,1],_=m.scale||[1,1,1];Ti(y,v,w,_)}let x=r[h];if(l?je(x,l,y):x.set(y),Array.isArray(m.children))for(let w of m.children)typeof w=="number"&&n(w,x,p+1)},u=[],d=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(d&&Array.isArray(d.nodes))u.push(...d.nodes);else for(let h=0;h<i;h++)s.has(h)||u.push(h);for(let h of u)n(h,null);for(let h=0;h<i;h++)!s.has(h)&&!u.includes(h)&&n(h,null);return r}function cr(t,e){function i(u,d,h,l){let p=typeof u=="number"?u:Number(u);return Number.isFinite(p)?Math.max(d,Math.min(h,p)):l}function r(u,d){let h=u[0]*d[0]+u[1]*d[1]+u[2]*d[2]+1;if(h<1e-6){if(Math.abs(u[0])>Math.abs(u[2])){let w=Math.hypot(u[1],u[0])||1;return[-u[1]/w,u[0]/w,0,0]}let x=Math.hypot(u[2],u[1])||1;return[0,-u[2]/x,u[1]/x,0]}let l=u[1]*d[2]-u[2]*d[1],p=u[2]*d[0]-u[0]*d[2],m=u[0]*d[1]-u[1]*d[0],y=Math.hypot(l,p,m,h)||1;return[l/y,p/y,m/y,h/y]}function s(u,d,h,l,p){let m=d[0]-u[0],y=d[1]-u[1],x=d[2]-u[2],w=Math.hypot(m,y,x),v=h[0]-d[0],_=h[1]-d[1],f=h[2]-d[2],g=Math.hypot(v,_,f);if(w<1e-6||g<1e-6)return{rootPos:[u[0],u[1],u[2]],midPos:[d[0],d[1],d[2]],effectorPos:[h[0],h[1],h[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let T=[m/w,y/w,x/w],R=[v/g,_/g,f/g],U=l[0]-u[0],j=l[1]-u[1],$=l[2]-u[2],L=Math.hypot(U,j,$),E=L>1e-6?[U/L,j/L,$/L]:T,B=Math.abs(w-g)+1e-5,I=Math.max(B,w+g-1e-5),c=Math.max(B,Math.min(I,L>1e-6?L:B)),k=i((w*w+c*c-g*g)/(2*w*c),-1,1,1),K=Math.sqrt(Math.max(0,1-k*k)),A=p?p[0]-u[0]:m,z=p?p[1]-u[1]:y,S=p?p[2]-u[2]:x,b=A*E[0]+z*E[1]+S*E[2],O=A-E[0]*b,X=z-E[1]*b,te=S-E[2]*b,re=Math.hypot(O,X,te);if(re<=1e-6){let se=Math.abs(E[1])<.99?0:1,P=Math.abs(E[1])<.99?1:0,M=0;O=E[1]*M-E[2]*P,X=E[2]*se-E[0]*M,te=E[0]*P-E[1]*se,re=Math.hypot(O,X,te)||1}let Z=[O/re,X/re,te/re],ne=[u[0]+E[0]*(w*k)+Z[0]*(w*K),u[1]+E[1]*(w*k)+Z[1]*(w*K),u[2]+E[2]*(w*k)+Z[2]*(w*K)],pe=[u[0]+E[0]*c,u[1]+E[1]*c,u[2]+E[2]*c],xe=pe[0]-ne[0],ie=pe[1]-ne[1],he=pe[2]-ne[2],ee=Math.hypot(xe,ie,he),le=ee>1e-6?[xe/ee,ie/ee,he/ee]:E,ue=[ne[0]+le[0]*g,ne[1]+le[1]*g,ne[2]+le[2]*g],J=[(ne[0]-u[0])/w,(ne[1]-u[1])/w,(ne[2]-u[2])/w];return{rootPos:[u[0],u[1],u[2]],midPos:ne,effectorPos:ue,rootRotation:r(T,J),midRotation:r(R,le)}}function a(u,d,h=8,l=.001){let p=u.length;if(p<2)return{positions:u.map(L=>[L[0],L[1],L[2]]),rotations:[],iterations:0};let m=u.map(L=>[L[0],L[1],L[2]]),y=[],x=[],w=0;for(let L=0;L<p-1;L++){let E=m[L+1][0]-m[L][0],B=m[L+1][1]-m[L][1],I=m[L+1][2]-m[L][2],c=Math.hypot(E,B,I);y.push(c),w+=c,x.push(c>1e-6?[E/c,B/c,I/c]:[0,1,0])}let v=[m[0][0],m[0][1],m[0][2]],_=Math.round(i(h,1,32,8)),f=i(l,1e-5,.1,.001),g=d[0]-v[0],T=d[1]-v[1],R=d[2]-v[2],U=Math.hypot(g,T,R),j=0;if(U>=w&&w>1e-6){let L=U>1e-6?[g/U,T/U,R/U]:x[0];m[0]=[v[0],v[1],v[2]];for(let E=0;E<p-1;E++){let B=y[E];m[E+1]=[m[E][0]+L[0]*B,m[E][1]+L[1]*B,m[E][2]+L[2]*B]}j=1}else for(let L=1;L<=_;L++){let E=m[p-1];if(Math.hypot(E[0]-d[0],E[1]-d[1],E[2]-d[2])<=f)break;j=L;let B=(I,c,k,K,A)=>{let z=c[0]-I[0],S=c[1]-I[1],b=c[2]-I[2],O=Math.hypot(z,S,b);if(O>1e-6){let X=k/O;return[I[0]+z*X,I[1]+S*X,I[2]+b*X]}return[I[0]+K[0]*k*A,I[1]+K[1]*k*A,I[2]+K[2]*k*A]};m[p-1]=[d[0],d[1],d[2]];for(let I=p-2;I>=0;I--)m[I]=B(m[I+1],m[I],y[I],x[I],-1);m[0]=[v[0],v[1],v[2]];for(let I=0;I<p-1;I++)m[I+1]=B(m[I],m[I+1],y[I],x[I],1)}let $=[];for(let L=0;L<p-1;L++){let E=m[L+1][0]-m[L][0],B=m[L+1][1]-m[L][1],I=m[L+1][2]-m[L][2],c=Math.hypot(E,B,I),k=c>1e-6?[E/c,B/c,I/c]:x[L];$.push(r(x[L],k))}return{positions:m,rotations:$,iterations:j}}function o(u){if(!u||typeof u!="object"||Array.isArray(u))return null;let d=u;if(d.enabled===!1)return null;let h=f=>{if(typeof f!="string")return;let g=f.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(g)?g:void 0},l=f=>Array.isArray(f)&&f.length===3&&f.every(g=>typeof g=="number"&&Number.isFinite(g))?[i(f[0],-1e3,1e3,0),i(f[1],-1e3,1e3,0),i(f[2],-1e3,1e3,0)]:void 0,p=h(d.root),m=h(d.effector);if(!p||!m)return null;let y=h(d.mid),x=l(d.target)??h(d.target);if(!x)return null;let w=d.pole??d.poleTarget,v=l(w)??h(w),_=d.solver==="fabrik"?"fabrik":d.solver==="two-bone"||y?"two-bone":"fabrik";return{root:p,...y?{mid:y}:{},effector:m,target:x,...v?{pole:v}:{},solver:_,iterations:Math.round(i(d.iterations,1,32,8)),tolerance:i(d.tolerance,1e-5,.1,.001),weight:i(d.weight,0,1,1)}}let n=Object.freeze({solveTwoBone:s,solveFABRIK:a,parseIKTrait:o});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=n),{clampNum:i,parseIKTrait:o,quatFromUnitVectors:r,solveTwoBoneIK:s,solveFABRIK:a,IKSolver:n}}var At=cr(),pn=At.clampNum,fn=At.parseIKTrait,mn=At.quatFromUnitVectors,gn=At.solveTwoBoneIK,yn=At.solveFABRIK,bn=At.IKSolver;function dr(t,e){let i=(h,l,p,m)=>{let y=typeof h=="number"?h:Number(h);return Number.isFinite(y)?Math.max(l,Math.min(p,y)):m};function r(h,l,p=0,m=.05,y){if(!h||!h.length)return-1;let x=h[0]>0?[0,...h]:h,w=Number.isFinite(l)?Math.max(0,l):0,v=Number.isFinite(m)?Math.max(0,Math.min(.5,m)):.05;if(typeof y=="number"&&Number.isFinite(y)&&y>0){let g=p===-1?y*(1-v):y*(1+v);if(w>g)return-1}let _=0;for(let g=x.length-1;g>=1;g--)if(w>=x[g]){_=g;break}if(p<0||p>=x.length||p===_)return _;if(_>p){let g=p;for(let T=p+1;T<=_&&w>=x[T]*(1+v);T++)g=T;return g}let f=p;for(let g=p;g>_&&w<x[g]*(1-v);g--)f=g-1;return f}function s(h){if(!h)return null;let l=h===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(h)?{distances:h}:typeof h=="object"?h:null;if(!l||l.enabled===!1)return null;let p=i(l.hysteresis,0,.5,.05),m=[],y;if(Array.isArray(l.levels)&&l.levels.length>0){let _=l.levels.slice(0,8);for(let g=0;g<_.length;g++){let T=_[g];if(!T||typeof T!="object"||Array.isArray(T))continue;let R=T,U=i(R.distance,0,1e4,g===0?0:g*4),j=typeof R.hysteresis=="number"?i(R.hysteresis,0,.5,p):void 0,$=typeof R.ratio=="number"?i(R.ratio,.05,1,.5):void 0,L=typeof R.childIndex=="number"&&Number.isFinite(R.childIndex)?Math.max(0,Math.round(R.childIndex)):void 0,E=typeof R.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(R.node.trim())?R.node.trim().slice(0,64):void 0;m.push({distance:U,...j!==void 0?{hysteresis:j}:{},...$!==void 0?{ratio:$}:{},...L!==void 0?{childIndex:L}:{},...E?{node:E}:{}})}m.sort((g,T)=>g.distance-T.distance),m.length>0&&m[0].distance>0&&m.unshift({distance:0,childIndex:0});let f=0;m=m.slice(0,8).map((g,T)=>{let R=T===0?0:Math.max(f,g.distance);return f=R,{...g,distance:R,childIndex:g.childIndex??T}})}if(Array.isArray(l.ratios)&&l.ratios.length>0){let _=[];for(let f of l.ratios.slice(0,7))typeof f=="number"&&_.push(i(f,.05,1,.5));_.length>0&&(y=_)}if(m.length===0){let _=Array.isArray(l.distances)?l.distances:[],f=[];for(let T of _.slice(0,8))typeof T=="number"&&f.push(i(T,0,1e4,4));if(f.length===0&&y&&y.length>0)for(let T=0;T<y.length;T++)f.push((T+1)*4);if(f.length===0&&l.cullDistance===void 0)return null;f.length===0||f[0]>0?f.unshift(0):y&&y.length===f.length&&y[0]===1&&(y=y.slice(1));let g=0;for(let T=0;T<Math.min(8,f.length);T++){let R=T===0?0:Math.max(g,f[T]);g=R;let U=T>0&&y?y[T-1]:void 0;m.push({distance:R,childIndex:T,...U!==void 0?{ratio:U}:{}})}}else if(!y){let _=[];for(let f=1;f<m.length;f++)typeof m[f].ratio=="number"&&_.push(m[f].ratio);_.length>0&&(y=_)}let x=m.map(_=>_.distance),w=x[x.length-1]??0,v=l.cullDistance!==void 0&&l.cullDistance!==null&&l.cullDistance!==!1?i(l.cullDistance,Math.max(1,w),1e4,100):void 0;return{levels:m,distances:x,...y?{ratios:y}:{},hysteresis:p,...v!==void 0?{cullDistance:v}:{}}}function a(h,l){let p=h?.attributes?.position;if(!p||!p.array||p.count<3)return h;let m=i(l,.05,1,.5),y=p.array,x=p.count,w=h.attributes?.normal?.array,v=h.attributes?.uv?.array,_=h.index?.array,f=Math.floor((_?_.length:x)/3);if(f<1)return h;let g=Math.max(1,Math.min(f,Math.round(f*m))),T=1/0,R=1/0,U=1/0,j=-1/0,$=-1/0,L=-1/0;for(let re=0;re<x;re++){let Z=y[re*3],ne=y[re*3+1],pe=y[re*3+2];Z<T&&(T=Z),ne<R&&(R=ne),pe<U&&(U=pe),Z>j&&(j=Z),ne>$&&($=ne),pe>L&&(L=pe)}let E=Math.max(1e-5,j-T),B=Math.max(1e-5,$-R),I=Math.max(1e-5,L-U),c=Math.max(E,B,I),k=re=>{let Z=Math.max(1,Math.round(E/c*re)),ne=Math.max(1,Math.round(B/c*re)),pe=Math.max(1,Math.round(I/c*re)),xe=new Map,ie=new Int32Array(x),he=[],ee=[],le=[],ue=[];for(let N=0;N<x;N++){let C=y[N*3],H=y[N*3+1],V=y[N*3+2],G=Math.min(Z-1,Math.max(0,Math.floor((C-T)/E*Z))),W=Math.min(ne-1,Math.max(0,Math.floor((H-R)/B*ne))),F=Math.min(pe-1,Math.max(0,Math.floor((V-U)/I*pe))),Q=G+W*Z+F*Z*ne,Y=xe.get(Q);Y===void 0?(Y=ue.length,xe.set(Q,Y),he.push(C,H,V),w&&ee.push(w[N*3],w[N*3+1],w[N*3+2]),v&&le.push(v[N*2],v[N*2+1]),ue.push(1)):(he[Y*3]+=C,he[Y*3+1]+=H,he[Y*3+2]+=V,w&&(ee[Y*3]+=w[N*3],ee[Y*3+1]+=w[N*3+1],ee[Y*3+2]+=w[N*3+2]),ue[Y]++),ie[N]=Y}let J=[],se=new Set;for(let N=0;N<f;N++){let C=_?_[N*3]:N*3,H=_?_[N*3+1]:N*3+1,V=_?_[N*3+2]:N*3+2,G=ie[C],W=ie[H],F=ie[V];if(G===W||W===F||F===G)continue;let Q=Math.min(G,W,F),Y=Math.max(G,W,F),q=G+W+F-Q-Y,oe=`${Q}_${q}_${Y}`;se.has(oe)||(se.add(oe),J.push(G,W,F))}let P=ue.length,M=new Float32Array(P*3),D=w?new Float32Array(P*3):null;for(let N=0;N<P;N++){let C=1/ue[N];if(M[N*3]=he[N*3]*C,M[N*3+1]=he[N*3+1]*C,M[N*3+2]=he[N*3+2]*C,D){let H=ee[N*3],V=ee[N*3+1],G=ee[N*3+2],W=Math.hypot(H,V,G)||1;D[N*3]=H/W,D[N*3+1]=V/W,D[N*3+2]=G/W}}return{pos:M,norm:D,uv:v?new Float32Array(le):null,tris:J,triCount:J.length/3,vertCount:P}},K=Math.max(2,Math.round(Math.sqrt(g/4))),A=k(K);if(A.triCount>g*1.25&&K>2){let re=Math.max(2,Math.round(K*Math.sqrt(g/A.triCount)));if(re!==K){let Z=k(re);Z.triCount>=Math.min(4,g)&&(A=Z)}}else if(A.triCount<Math.min(4,g)){let re=k(Math.max(K*2,8));re.triCount>A.triCount&&(A=re)}let z=A.tris;if(m<1&&A.triCount>g){let re=[],Z=A.triCount/g;for(let ne=0;ne<g;ne++){let pe=Math.min(A.triCount-1,Math.floor(ne*Z));re.push(A.tris[pe*3],A.tris[pe*3+1],A.tris[pe*3+2])}z=re}if(z.length<3){z=[];for(let re=0;re<g*3;re++)z.push(_?_[re]:re);A={pos:y.slice(),norm:w?w.slice():null,uv:v?v.slice():null,tris:z,triCount:g,vertCount:x}}let S=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),b=S?.BufferGeometry??h.constructor,O=S?.BufferAttribute??p.constructor,X=new b;X.setAttribute("position",new O(A.pos,3)),A.norm&&X.setAttribute("normal",new O(A.norm,3)),A.uv&&X.setAttribute("uv",new O(A.uv,2));let te=A.vertCount>65535?new Uint32Array(z):new Uint16Array(z);return typeof X.setIndex=="function"?X.setIndex(new O(te,1)):X.index=new O(te,1),X}let o=t?.Object3D??e?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...h){for(let l of h)l&&(l.parent=this,this.children.push(l));return this}};class n extends o{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(l,p=0,m=.05){if(!l)return this;let y=Math.max(0,Number.isFinite(Number(p))?Number(p):0),x=i(m,0,.5,.05),w=this.levels.length;for(let f=0;f<this.levels.length;f++)if(y<this.levels[f].distance){w=f;break}this.levels.splice(w,0,{object:l,distance:y,hysteresis:x}),this.add(l);let v=this.levels.map(f=>f.object),_=this.children.filter(f=>!v.includes(f));this.children=[...v,..._];for(let f=0;f<this.levels.length;f++)this.levels[f].object.visible=f===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(l){if(!this.levels.length)return null;let p=r(this.levels.map(m=>m.distance),l,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return p>=0&&p<this.levels.length?this.levels[p].object:null}update(l){if(this.levels.length===0||!l)return;let p=l.position??{x:0,y:0,z:0},m=this.position??{x:0,y:0,z:0},y=Math.hypot((Number(p.x)||0)-(Number(m.x)||0),(Number(p.y)||0)-(Number(m.y)||0),(Number(p.z)||0)-(Number(m.z)||0)),x=r(this.levels.map(w=>w.distance),y,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=x;for(let w=0;w<this.levels.length;w++)this.levels[w].object.visible=w===x}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let l=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((p,m)=>({distance:p.distance,hysteresis:p.hysteresis,childIndex:m,...p.object?.name?{node:p.object.name}:{}})),distances:this.levels.map(p=>p.distance),hysteresis:this.levels[0]?.hysteresis??.05,...l!==void 0?{cullDistance:l}:{}}}}function u(h){if(!h||h._lodMaterialized||!h.userData?.xr?.lod||h.isLOD||Array.isArray(h.children)&&h.children.length>0)return;let l=h.geometry?.attributes?.position;if(!l||!l.array||l.count<3)return;let p=s(h.userData.xr.lod);if(!p||p.levels.length<2)return;h._lodMaterialized=!0;let m=h.geometry;h._lodOriginalGeometry=m;let y=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),x=y?.Mesh??h.constructor,w=y?.BufferGeometry??m.constructor,v=typeof h.name=="string"&&h.name.trim()?h.name.trim():"Mesh",_=new x(m,h.material);_.name=`${v}_LOD0`,_.visible=!0,_.castShadow=!!h.castShadow,_.receiveShadow=!!h.receiveShadow,h.add(_);for(let f=1;f<p.levels.length;f++){let g=p.levels[f].ratio??p.ratios?.[f-1]??Math.max(.05,Math.pow(.5,f)),T=a(m,g),R=new x(T,h.material);R.name=`${v}_LOD${f}`,R.visible=!1,R.castShadow=!!h.castShadow,R.receiveShadow=!!h.receiveShadow,h.add(R)}h.geometry=new w,h.userData.xr.lod={...p,levels:p.levels.map((f,g)=>({...f,childIndex:g,node:`${v}_LOD${g}`}))}}let d={LOD:n,decimateGeometry:a,selectLodLevelIndex:r,parseLod:s,materializeLodGeometry:u};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,{LOD:n,decimateGeometry:a}),e._lodMaterialize=u,e.materializeDeclarativeGeometry=h=>{e._cadMaterialize?.(h),e._lodMaterialize?.(h)}),d}var Ot=dr(),xn=Ot.decimateGeometry,vn=Ot.selectLodLevelIndex,Mn=Ot.parseLod,wn=Ot.materializeLodGeometry,_n=Ot.LOD,Aa={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function pr(t,e,i,r){if(!i||i.bufferView===void 0)return null;let s=t.bufferViews?.[i.bufferView];if(!s)return null;let a=Number(i.count??0);if(!Number.isInteger(a)||a<=0)return null;let o=i.componentType??5126,n=Aa[o];if(!n)throw new RangeError(`glTF accessor has unsupported componentType ${o}`);let u=n*r,d=s.byteStride&&s.byteStride>0?s.byteStride:u,h=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(h)||h<0||d<u||h+(a-1)*d+u>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(o===5126&&d===u&&h%4===0)return new Float32Array(e,h,a*r);let l=new DataView(e),p=i.normalized===!0,m=new Float32Array(a*r);for(let y=0;y<a;y++){let x=h+y*d;for(let w=0;w<r;w++){let v=x+w*n,_;switch(o){case 5126:_=l.getFloat32(v,!0);break;case 5120:_=l.getInt8(v),p&&(_=Math.max(_/127,-1));break;case 5121:_=l.getUint8(v),p&&(_/=255);break;case 5122:_=l.getInt16(v,!0),p&&(_=Math.max(_/32767,-1));break;case 5123:_=l.getUint16(v,!0),p&&(_/=65535);break;default:_=l.getUint32(v,!0),p&&(_/=4294967295)}m[y*r+w]=_}}return m}function Pa(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,s=Number(e.scale?.[0]??1),a=Number(e.scale?.[1]??1),o=Number(e.rotation??0)||0,n=Math.cos(o),u=Math.sin(o),d=(Number.isFinite(s)?s:1)*n,h=(Number.isFinite(s)?s:1)*u,l=-(Number.isFinite(a)?a:1)*u,p=(Number.isFinite(a)?a:1)*n;for(let m=0;m+1<t.length;m+=2){let y=t[m],x=t[m+1];t[m]=d*y+h*x+i,t[m+1]=l*y+p*x+r}}function Si(t,e,i,r=!0){let s=[],a=null;try{for(let[o,n]of[[35633,e],[35632,i]]){let u=t.createShader(o);if(!u){if(r)throw new Error("Shader allocation failed");return null}if(s.push(u),t.shaderSource(u,n),t.compileShader(u),t.getShaderParameter&&!t.getShaderParameter(u,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(u)}`);return null}}if(a=t.createProgram(),!a){if(r)throw new Error("Program allocation failed");return null}for(let o of s)t.attachShader(a,o);if(t.linkProgram(a),t.getProgramParameter&&!t.getProgramParameter(a,35714)){let o=r?t.getProgramInfoLog(a):null;if(t.deleteProgram?.(a),a=null,r)throw new Error(`Program link error: ${o}`);return null}return a}finally{for(let o of s)a&&t.detachShader?.(a,o),t.deleteShader?.(o)}}var fr=["neutral","reinhard","none","aces","agx"];function Ai(t){let e=String(t??"").trim().toLowerCase();return fr.includes(e)?e:"neutral"}function Da(t){return fr.indexOf(Ai(t))}function Na(t){return new TextDecoder().decode(t)}var mr=Re().decoders;function Ra(t,e){mr.set(t.toLowerCase(),e)}function Pt(t){return mr.get(t.toLowerCase())}function gr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let p=i.getUint8(0);throw p===123||p===32||p===10||p===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let a=i.getUint32(8,!0),o=12,n=null,u=null;for(;o+8<=a&&o+8<=e.byteLength;){let p=i.getUint32(o,!0),m=i.getUint32(o+4,!0),y=o+8;if(y+p>e.byteLength)throw new Error(`Truncated GLB chunk: required ${y+p} bytes, buffer has ${e.byteLength}`);if(m===1313821514){let x=new Uint8Array(e,y,p),w=Na(x);n=JSON.parse(w,(v,_)=>v==="__proto__"||v==="constructor"||v==="prototype"?void 0:_)}else m===5130562&&(u=e.slice(y,y+p));o=y+p}if(!n)throw new Error("Missing JSON chunk in GLB");let d=n.extensionsRequired||[];if(d.includes("KHR_draco_mesh_compression")&&!Pt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let p of["EXT_meshopt_compression","KHR_meshopt_compression"])if(d.includes(p)&&!Pt("meshopt"))throw new Error(`Model requires ${p}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(d.includes("KHR_texture_basisu")&&!Pt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let h=u||new ArrayBuffer(0),l={gltf:n,bin:h,animations:[]};for(let p of Ce)p.onParseGLB?.(l);return l}function Ea(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 Pi(t){if(Ea(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return gr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var yr=`#version 300 es
|
|
16
|
+
*/var ThreeEngine=(()=>{var Kr=Object.defineProperty,co=Object.getOwnPropertyDescriptor,fo=Object.getOwnPropertyNames,po=Object.prototype.hasOwnProperty,mo=(t,e)=>{for(var i in e)Kr(t,i,{get:e[i],enumerable:!0})},go=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of fo(e))!po.call(t,s)&&s!==i&&Kr(t,s,{get:()=>e[s],enumerable:!(r=co(e,s))||r.enumerable});return t},yo=t=>go(Kr({},"__esModule",{value:!0}),t),Yn={};mo(Yn,{AmbientLight:()=>Cn,BoxGeometry:()=>wn,BufferAttribute:()=>$t,BufferGeometry:()=>Pt,Camera:()=>Ln,CapsuleGeometry:()=>Da,CatmullRomCurve3:()=>Ks,CircleGeometry:()=>$a,Clock:()=>ca,Color:()=>_i,ConeGeometry:()=>Ws,CubicBezierCurve3:()=>Qs,Curve3:()=>Bi,CylinderGeometry:()=>_n,DataTexture:()=>ta,DirectionalLight:()=>Pn,DodecahedronGeometry:()=>La,EdgesGeometry:()=>Fa,Euler:()=>Mn,Float32BufferAttribute:()=>Bs,Group:()=>oa,HemisphereLight:()=>Xr,IcosahedronGeometry:()=>Pa,InstancedMesh:()=>Or,LatheGeometry:()=>Sn,Light:()=>Ni,LightShadow:()=>Nn,Line:()=>Qi,LineBasicMaterial:()=>Wr,LineCurve3:()=>Js,LineDashedMaterial:()=>za,LineLoop:()=>Ra,LineSegments:()=>Ia,MAX_INSTANCES_PER_MESH:()=>or,Material:()=>Zt,MathUtils:()=>Os,Matrix3:()=>Is,Matrix4:()=>Ti,Mesh:()=>Ei,MeshBasicMaterial:()=>ra,MeshLambertMaterial:()=>na,MeshPhongMaterial:()=>sa,MeshPhysicalMaterial:()=>aa,MeshStandardMaterial:()=>Yi,Object3D:()=>oi,OctahedronGeometry:()=>Ca,PerspectiveCamera:()=>jr,PlaneGeometry:()=>Hs,PointLight:()=>Br,Points:()=>Ua,PointsMaterial:()=>jn,PolyhedronFallbackGeometry:()=>Th,PolyhedronGeometry:()=>ji,QuadraticBezierCurve3:()=>Zs,Quaternion:()=>Er,RawShaderMaterial:()=>Aa,RectAreaLight:()=>Oa,RingGeometry:()=>Bn,Scene:()=>lr,SceneQuotaValidator:()=>Fi,ShaderMaterial:()=>Un,SphereGeometry:()=>Gs,SpotLight:()=>qr,THREE:()=>hi,TetrahedronGeometry:()=>Ta,Texture:()=>Ur,TextureLoader:()=>ia,TorusGeometry:()=>qs,TorusKnotGeometry:()=>Ys,TubeGeometry:()=>ea,Uint16BufferAttribute:()=>js,Uint32BufferAttribute:()=>Vs,Vector2:()=>Jt,Vector3:()=>Qe,Vector4:()=>Rs,WebGLRenderer:()=>ha,WireframeGeometry:()=>Ea,authorScriptRunner:()=>Sa,buildSandboxWorkerSource:()=>En,clearAuthorWarnings:()=>In,default:()=>Lh,exportSceneToCanvas3D:()=>Dn,exportSceneToGLB:()=>$n,exportSceneToUSDZ:()=>la,generateUSDZ:()=>ws,getAllowClientScripts:()=>ga,getAuthorWarnings:()=>Rn,getSandboxEngineSrc:()=>zn,getSandboxIframeSrc:()=>da,glbToUSDZ:()=>fn,isAllowedSandboxEngineUrl:()=>Zi,noopProxy:()=>Ji,sceneToCanvas3D:()=>ir,sceneToGLB:()=>Nr,sceneToUSDZ:()=>Lr,setAllowClientScripts:()=>yh,setSandboxEngineSrc:()=>ph,setSandboxIframeSrc:()=>dh,threeAuthorPlugin:()=>ur,threeMicroPlugin:()=>Ph,toTrustedWorkerScriptURL:()=>ma,validateSandboxWorkerMessage:()=>Fn,warnUnsupported:()=>Ci});function Jn(t,e,i){let r=[],s=new Map,a=[],f=[],c=[],h=new Map,C=T=>{let M=s.get(T);return M===void 0&&(M=r.length,r.push({op:T}),s.set(T,M)),M},d=T=>{let M=h.get(T);return M===void 0&&(M=c.length,c.push({id:T}),h.set(T,M)),M},p=(T,M={})=>a.push({declaration:C(T),...M})-1,m=(T,M,N)=>f.push({id:T,type:M,value:N})-1,y=T=>({node:T,socket:"value"}),z=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(z&&typeof z=="object"){let T=Array.isArray(z.graphs)?z.graphs[z.graph??0]:z;if(T&&Array.isArray(T.nodes)){let M=Array.isArray(T.declarations)?T.declarations:[];for(let N of M)N?.op&&C(N.op);Array.isArray(T.variables)&&f.push(...T.variables);for(let N of T.events||[])N?.id&&d(N.id);for(let N of T.nodes){if(!N||typeof N!="object")continue;let k=N.op||(typeof N.declaration=="number"?M[N.declaration]?.op:"");a.push(k?{...N,declaration:C(k)}:{...N})}}}let E=(T,M,N="translation")=>N==="baseColorFactor"||N==="metallicFactor"||N==="roughnessFactor"?`/materials/${Math.max(0,M)}/pbrMetallicRoughness/${N}`:N==="emissiveFactor"||N==="alphaCutoff"?`/materials/${Math.max(0,M)}/${N}`:N==="visible"?`/nodes/${T}/extensions/KHR_node_visibility/visible`:`/nodes/${T}/${N}`,_=new Map;t.forEach((T,M)=>{typeof T?.name=="string"&&!_.has(T.name)&&_.set(T.name,M)});let b=(T,M)=>typeof T.target=="string"&&_.has(T.target)?_.get(T.target):typeof T.targetNode=="number"?T.targetNode:M,$=T=>{let M=t[T];return(typeof M?.mesh=="number"?e[M.mesh]?.primitives?.[0]?.material:0)??0};for(let T=0;T<t.length;T++){let M=t[T],N=M?.extras?.interactivity;if(!N||typeof N!="object")continue;let k=(typeof M.mesh=="number"?e[M.mesh]?.primitives?.[0]?.material:0)??0,A=w=>{let v=Array.isArray(w)?w:[w],P=[];for(let G=0;G<v.length;G++){let x=v[G];if(!x||typeof x!="object")continue;let V=x.action||"interpolate",Y=typeof x.duration=="number"?x.duration:.35;if(V==="toggleTransform"){let Z=x.property==="rotation"||x.property==="scale"?x.property:"translation",q=Z==="rotation"?M.rotation||[0,0,0,1]:Z==="scale"?M.scale||[1,1,1]:M.translation||[0,0,0],X=`/nodes/${T}/${Z}`,F=m(`__toggle_${T}_${G}`,"bool",!1),Q=p("variable/get",{configuration:{variable:F}}),L=p("math/not",{values:{a:y(Q)}}),ee=p("variable/set",{configuration:{variable:F},values:{value:y(L)}}),ae=p("pointer/interpolate",{configuration:{pointer:X},values:{value:{value:Array.isArray(x.to)?x.to:q},duration:{value:Y}}}),be=p("pointer/interpolate",{configuration:{pointer:X},values:{value:{value:Array.isArray(x.from)?x.from:q},duration:{value:Y}}});a[ee].flows={out:{node:p("flow/branch",{values:{condition:y(Q)},flows:{true:{node:ae},false:{node:be}}})}},P.push(ee)}else if(V==="interpolate"){let Z=x.to??x.value;if(Z===void 0)continue;let q={value:{value:Z},duration:{value:Y}};x.from!==void 0&&(q.from={value:x.from}),P.push(p("pointer/interpolate",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:E(b(x,T),$(b(x,T)),x.property)},values:q}))}else if(V==="setProperty"){if(x.value===void 0)continue;P.push(p("pointer/set",{configuration:{pointer:typeof x.pointer=="string"?x.pointer:E(b(x,T),$(b(x,T)),x.property)},values:{value:{value:x.value}}}))}else if(V==="toggleVisibility"){let Z=b(x,T),q=m(`__vis_${Z}_${G}`,"bool",!0),X=p("variable/get",{configuration:{variable:q}}),F=p("math/not",{values:{a:y(X)}}),Q=p("variable/set",{configuration:{variable:q},values:{value:y(F)}});a[Q].flows={out:{node:p("pointer/set",{configuration:{pointer:`/nodes/${Z}/extensions/KHR_node_visibility/visible`},values:{value:y(X)}})}},P.push(Q)}else if(V==="cycleMaterialColor"&&Array.isArray(x.colors)&&x.colors.length>0){let Z=typeof x.duration=="number"?x.duration:.25,q=`/materials/${Math.max(0,k)}/pbrMetallicRoughness/baseColorFactor`,X=m(`__color_idx_${T}_${G}`,"int",0),F=p("variable/get",{configuration:{variable:X}}),Q=p("math/add",{values:{a:y(F),b:{value:1}}}),L=p("math/rem",{values:{a:y(Q),b:{value:x.colors.length}}}),ee=p("variable/set",{configuration:{variable:X},values:{value:y(L)}}),ae={};for(let be=0;be<x.colors.length;be++){let Ne=x.colors[be],De=Array.isArray(Ne)&&Ne.length>=3?[Ne[0],Ne[1],Ne[2],Ne[3]??1]:[1,1,1,1];ae[String(be)]={node:Z>0?p("pointer/interpolate",{configuration:{pointer:q},values:{value:{value:De},duration:{value:Z}}}):p("pointer/set",{configuration:{pointer:q},values:{value:{value:De}}})}}a[ee].flows={out:{node:p("flow/switch",{values:{selection:y(F)},flows:ae})}},P.push(ee)}else if(V==="playAnimation")P.push(p("animation/start",{configuration:{animation:x.animation??x.clip??0}}));else if(V==="stopAnimation")P.push(p("animation/stop"));else if(V==="sendEvent"){let Z={};for(let[q,X]of Object.entries(x.values||{}))Z[q]={value:X};P.push(p("event/send",{configuration:{event:d(String(x.event??x.id??"custom"))},values:Z}))}}if(!P.length)return null;if(P.length===1)return P[0];let H={};return P.forEach((G,x)=>{H[String(x)]={node:G}}),p("flow/sequence",{flows:H})},S=(w,v,P)=>{let H=A(v);H!==null&&p(w,{...P?{configuration:P}:{},flows:{out:{node:H}}})};if(N.onSelect&&S("pointer/onSelect",N.onSelect,{nodeIndex:T}),N.onHoverIn&&S("pointer/onHoverIn",N.onHoverIn,{nodeIndex:T}),N.onHoverOut&&S("pointer/onHoverOut",N.onHoverOut,{nodeIndex:T}),N.onStart&&S("event/onStart",N.onStart),N.onReceive&&typeof N.onReceive=="object")for(let[w,v]of Object.entries(N.onReceive))S("event/receive",v,{event:d(w)})}return a.length?{graphs:[{declarations:r,nodes:a,variables:f,events:c}],graph:0}:null}var bo='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).',xo="Security Error: client-side scripts require allow-client-scripts opt-in.",Mr="__THREE_LIVE_REGISTRY__";function mt(){let t=typeof globalThis<"u"?globalThis:{};if(!t[Mr]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,Mr,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[Mr]=e}}return t[Mr]}var Nt=mt().plugins;function vo(t){let e=mt().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function Mo(){return mt().plugins}function wo(t,e){if(!t||!t.BufferGeometry)return null;let i=t.Vector2,r=t.Vector3,s=t.Quaternion,a=t.Matrix4,f=t.Matrix3,c=t.Color,h=t.BufferAttribute,C=t.BufferGeometry,d=t.Material,p=t.MeshStandardMaterial,m=t.Mesh,y=8192,z=2048,E=128,_=4096,b=(J,j)=>{let I=J==null?NaN:Number(J);return Number.isFinite(I)?I:j};class ${constructor(j){this.currentPoint=new i(0,0),this.segments=[],Array.isArray(j)&&j.length>0&&this.fromPoints(j)}fromPoints(j){if(!j.length)return this;this.moveTo(j[0].x,j[0].y);for(let I=1;I<j.length;I++)this.lineTo(j[I].x,j[I].y);return this}moveTo(j,I){let O=Number(j)||0,K=Number(I)||0;return this.currentPoint.set(O,K),this.segments.push({type:"move",pts:[O,K]}),this}lineTo(j,I){let O=Number(j)||0,K=Number(I)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(O,K),this.segments.push({type:"line",pts:[O,K]}),this}quadraticCurveTo(j,I,O,K){let ie=this.currentPoint.x,he=this.currentPoint.y,ue=Number(j)||0,ge=Number(I)||0,oe=Number(O)||0,_e=Number(K)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[ie,he]}),this.currentPoint.set(oe,_e),this.segments.push({type:"quad",pts:[ie,he,ue,ge,oe,_e]}),this}bezierCurveTo(j,I,O,K,ie,he){let ue=this.currentPoint.x,ge=this.currentPoint.y,oe=Number(j)||0,_e=Number(I)||0,fe=Number(O)||0,ye=Number(K)||0,Ae=Number(ie)||0,Pe=Number(he)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[ue,ge]}),this.currentPoint.set(Ae,Pe),this.segments.push({type:"cubic",pts:[ue,ge,oe,_e,fe,ye,Ae,Pe]}),this}absarc(j,I,O,K,ie,he=!1){return this.absellipse(j,I,O,O,K,ie,he,0)}arc(j,I,O,K,ie,he=!1){return this.absarc(this.currentPoint.x+(Number(j)||0),this.currentPoint.y+(Number(I)||0),O,K,ie,he)}absellipse(j,I,O,K,ie,he,ue=!1,ge=0){let oe=Number(j)||0,_e=Number(I)||0,fe=Math.max(0,Number(O)||0),ye=Math.max(0,Number(K)||0),Ae=Number(ie)||0,Pe=Number(he)||0,Le=ue?1:0,ke=Number(ge)||0;this.segments.push({type:"arc",pts:[oe,_e,fe,ye,Ae,Pe,Le,ke]});let $e=Math.cos(ke),Fe=Math.sin(ke),qe=fe*Math.cos(Pe),Oe=ye*Math.sin(Pe);return this.currentPoint.set(oe+qe*$e-Oe*Fe,_e+qe*Fe+Oe*$e),this}ellipse(j,I,O,K,ie,he,ue=!1,ge=0){return this.absellipse(this.currentPoint.x+(Number(j)||0),this.currentPoint.y+(Number(I)||0),O,K,ie,he,ue,ge)}add(j){if(j&&typeof j.getPoints=="function"){this.segments.push({type:"curve",pts:[],curve:j});let I=j.getPoint?.(1);I&&this.currentPoint.set(Number(I.x)||0,Number(I.y)||0)}return this}splineThru(j){if(!Array.isArray(j)||j.length===0)return this;let I=t.SplineCurve||e?.authorNamespace?.SplineCurve;if(I)return this.add(new I([this.currentPoint.clone(),...j]));for(let O of j)O&&this.lineTo(Number(O.x)||0,Number(O.y)||0);return this}closePath(){if(this.segments.length>0){let j=this.segments[0],I=0,O=0;if(j.type==="curve"&&j.curve?.getPoint){let K=j.curve.getPoint(0);I=Number(K?.x)||0,O=Number(K?.y)||0}else if(j.type==="arc"){let K=j.pts[0],ie=j.pts[1],he=j.pts[2],ue=j.pts[3],ge=j.pts[4],oe=j.pts[7],_e=Math.cos(oe),fe=Math.sin(oe),ye=he*Math.cos(ge),Ae=ue*Math.sin(ge);I=K+ye*_e-Ae*fe,O=ie+ye*fe+Ae*_e}else I=j.pts[0],O=j.pts[1];Math.hypot(this.currentPoint.x-I,this.currentPoint.y-O)>1e-6&&this.lineTo(I,O)}return this}getPoints(j=12){let I=Math.max(1,Math.min(128,Math.floor(Number(j)||12))),O=[],K=(ie,he)=>{if(O.length>0){let ue=O[O.length-1];if(Math.hypot(ue.x-ie,ue.y-he)<1e-6)return}O.push(new i(ie,he))};for(let ie of this.segments){let he=ie.pts;if(ie.type==="move"||ie.type==="line")K(he[0],he[1]);else if(ie.type==="quad"){let ue=he[0],ge=he[1],oe=he[2],_e=he[3],fe=he[4],ye=he[5];K(ue,ge);for(let Ae=1;Ae<=I;Ae++){let Pe=Ae/I,Le=1-Pe;K(Le*Le*ue+2*Le*Pe*oe+Pe*Pe*fe,Le*Le*ge+2*Le*Pe*_e+Pe*Pe*ye)}}else if(ie.type==="cubic"){let ue=he[0],ge=he[1],oe=he[2],_e=he[3],fe=he[4],ye=he[5],Ae=he[6],Pe=he[7];K(ue,ge);for(let Le=1;Le<=I;Le++){let ke=Le/I,$e=1-ke,Fe=$e*$e,qe=ke*ke;K(Fe*$e*ue+3*Fe*ke*oe+3*$e*qe*fe+qe*ke*Ae,Fe*$e*ge+3*Fe*ke*_e+3*$e*qe*ye+qe*ke*Pe)}}else if(ie.type==="arc"){let ue=he[0],ge=he[1],oe=he[2],_e=he[3],fe=he[4],ye=he[5],Ae=he[6]!==0,Pe=he[7],Le=Math.PI*2,ke=ye-fe,$e=Math.abs(ke)<1e-9;for(;ke<0;)ke+=Le;for(;ke>Le;)ke-=Le;ke<1e-9&&(ke=$e?0:Le),Ae&&!$e&&(ke=ke===Le?-Le:ke-Le);let Fe=Math.cos(Pe),qe=Math.sin(Pe),Oe=Math.max(2,I);for(let lt=0;lt<=Oe;lt++){let rt=lt/Oe,nt=fe+rt*ke,ht=oe*Math.cos(nt),Ke=_e*Math.sin(nt);K(ue+ht*Fe-Ke*qe,ge+ht*qe+Ke*Fe)}}else if(ie.type==="curve"&&ie.curve?.getPoints)for(let ue of ie.curve.getPoints(I))ue&&K(Number(ue.x)||0,Number(ue.y)||0)}if(O.length>2){let ie=O[0],he=O[O.length-1];Math.hypot(ie.x-he.x,ie.y-he.y)<1e-6&&O.pop()}return O}getSpacedPoints(j=12){return this.getPoints(j)}clone(){let j=new this.constructor;return j.currentPoint.copy(this.currentPoint),j.segments=this.segments.map(I=>({type:I.type,pts:[...I.pts],...I.curve?{curve:I.curve.clone?I.curve.clone():I.curve}:{}})),Array.isArray(this.holes)&&(j.holes=this.holes.map(I=>I.clone())),j}}class T extends ${constructor(j){super(j),this.holes=[]}extractPoints(j=12){return{shape:this.getPoints(j),holes:this.holes.map(I=>I.getPoints(j))}}}function M(J){let j=0,I=J.length;for(let O=0,K=I-1;O<I;K=O++)j+=J[K].x*J[O].y-J[O].x*J[K].y;return j*.5}function N(J,j,I,O,K,ie,he,ue){let ge=he-I,oe=ue-O,_e=K-I,fe=ie-O,ye=J-I,Ae=j-O,Pe=ge*ge+oe*oe,Le=ge*_e+oe*fe,ke=ge*ye+oe*Ae,$e=_e*_e+fe*fe,Fe=_e*ye+fe*Ae,qe=Pe*$e-Le*Le;if(Math.abs(qe)<1e-12)return!1;let Oe=1/qe,lt=($e*ke-Le*Fe)*Oe,rt=(Pe*Fe-Le*ke)*Oe;return lt>=-1e-7&&rt>=-1e-7&<+rt<=1.0000001}function k(J,j){let I=J.slice();M(I)<0&&I.reverse();let O=I.map(ge=>new i(ge.x,ge.y)),K=I.map((ge,oe)=>oe),ie=[];for(let ge of j){if(!ge||ge.length<3)continue;let oe=ge.slice();M(oe)>0&&oe.reverse();let _e=[],fe=-1/0,ye=0;for(let Ae=0;Ae<oe.length;Ae++){let Pe=oe[Ae],Le=O.length;O.push(new i(Pe.x,Pe.y)),_e.push(Le),Pe.x>fe&&(fe=Pe.x,ye=Ae)}ie.push({pts:oe,indices:_e,maxX:fe,maxIdx:ye})}ie.sort((ge,oe)=>oe.maxX-ge.maxX);let he=(ge,oe,_e)=>(oe.x-ge.x)*(_e.y-ge.y)-(oe.y-ge.y)*(_e.x-ge.x),ue=(ge,oe,_e)=>{for(let fe=0;fe<_e.length;fe++){let ye=_e[fe],Ae=_e[(fe+1)%_e.length];if(he(ge,oe,ye)*he(ge,oe,Ae)<0&&he(ye,Ae,ge)*he(ye,Ae,oe)<0)return!0}return!1};for(let ge of ie){let oe=ge.pts[ge.maxIdx],_e=oe.x,fe=K.length,ye=K.map($e=>O[$e]),Ae=$e=>Math.hypot(ye[$e].x-_e,ye[$e].y-oe.y),Pe=ye.map(($e,Fe)=>Fe).sort(($e,Fe)=>+(ye[$e].x<_e)-+(ye[Fe].x<_e)||Ae($e)-Ae(Fe)),Le=Pe[0];for(let $e of Pe){let Fe=ye[$e],qe=ye[($e+fe-1)%fe],Oe=ye[($e+1)%fe],lt=he(Fe,Oe,oe)>=0,rt=he(qe,Fe,oe)>=0;if((he(qe,Fe,Oe)>=0?lt&&rt:lt||rt)&&!ue(oe,Fe,ye)&&!ie.some(nt=>ue(oe,Fe,nt.pts))){Le=$e;break}}let ke=[];for(let $e=0;$e<=Le;$e++)ke.push(K[$e]);for(let $e=0;$e<=ge.indices.length;$e++){let Fe=ge.indices[(ge.maxIdx+$e)%ge.indices.length];ke.push(Fe)}for(let $e=Le;$e<K.length;$e++)ke.push(K[$e]);K=ke}return{merged:K.map(ge=>O[ge]),mergedIndices:K,allVertices:O}}function A(J,j){let I=[],O=J.slice();if(O.length<3)return I;let K=O.length*O.length+64,ie=0;for(;O.length>2&&K-- >0;){let he=O.length,ue=O[(ie+he-1)%he],ge=O[ie%he],oe=O[(ie+1)%he],_e=j[ue],fe=j[ge],ye=j[oe];if((fe.x-_e.x)*(ye.y-_e.y)-(fe.y-_e.y)*(ye.x-_e.x)>1e-9){let Ae=!0,Pe=Math.min(_e.x,fe.x,ye.x)-1e-7,Le=Math.max(_e.x,fe.x,ye.x)+1e-7,ke=Math.min(_e.y,fe.y,ye.y)-1e-7,$e=Math.max(_e.y,fe.y,ye.y)+1e-7;for(let Fe=0;Fe<he;Fe++){let qe=O[Fe];if(qe===ue||qe===ge||qe===oe)continue;let Oe=j[qe];if(Oe.x>=Pe&&Oe.x<=Le&&Oe.y>=ke&&Oe.y<=$e&&N(Oe.x,Oe.y,_e.x,_e.y,fe.x,fe.y,ye.x,ye.y)&&(Oe.x-_e.x)*(Oe.x-_e.x)+(Oe.y-_e.y)*(Oe.y-_e.y)>=1e-12&&(Oe.x-fe.x)*(Oe.x-fe.x)+(Oe.y-fe.y)*(Oe.y-fe.y)>=1e-12&&(Oe.x-ye.x)*(Oe.x-ye.x)+(Oe.y-ye.y)*(Oe.y-ye.y)>=1e-12){Ae=!1;break}}if(Ae){I.push([ue,ge,oe]),O.splice(ie%he,1),ie=Math.max(0,ie%he-1);continue}}ie++,ie>=he*2&&(I.push([ue,ge,oe]),O.splice((ie-1)%he,1),ie=0)}return I}function S(J,j){let I=J instanceof T?J.extractPoints(j):{shape:J.getPoints(j),holes:[]},O=I.shape.length;for(let K of I.holes)O+=K.length;if(O>_)throw new RangeError(`SecurityError: shape point count (${O}) exceeds MAX_SHAPE_POINTS (${_})`);return I}function w(J){let j=1/0,I=1/0,O=-1/0,K=-1/0;for(let ie of J)ie.x<j&&(j=ie.x),ie.y<I&&(I=ie.y),ie.x>O&&(O=ie.x),ie.y>K&&(K=ie.y);return[j,I,Math.max(1e-6,O-j),Math.max(1e-6,K-I)]}class v extends C{constructor(j=new T,I=12){super();let O=Array.isArray(j)?j:[j],K=[],ie=[],he=[],ue=[];for(let ge of O){if(!(ge instanceof $))continue;let oe=S(ge,I);if(oe.shape.length<3)continue;let{mergedIndices:_e,allVertices:fe}=k(oe.shape,oe.holes),ye=A(_e,fe),Ae=K.length/3,[Pe,Le,ke,$e]=w(fe);for(let Fe of fe)K.push(Fe.x,Fe.y,0),ie.push(0,0,1),he.push((Fe.x-Pe)/ke,(Fe.y-Le)/$e);for(let[Fe,qe,Oe]of ye)ue.push(Ae+Fe,Ae+qe,Ae+Oe)}P(this,K,ie,he,ue)}}function P(J,j,I,O,K){return J.setAttribute("position",new h(j,3)),J.setAttribute("normal",new h(I,3)),J.setAttribute("uv",new h(O,2)),J.setIndex(K),J}function H(J){let j=J.length,I=[];for(let O=0;O<j;O++){let K=J[(O+j-1)%j],ie=J[O],he=J[(O+1)%j],ue=ie.x-K.x,ge=ie.y-K.y,oe=Math.hypot(ue,ge)||1;ue/=oe,ge/=oe;let _e=he.x-ie.x,fe=he.y-ie.y,ye=Math.hypot(_e,fe)||1;_e/=ye,fe/=ye;let Ae=ge,Pe=-ue,Le=fe,ke=-_e,$e=Ae+Le,Fe=Pe+ke,qe=Math.hypot($e,Fe);if(qe>1e-6){$e/=qe,Fe/=qe;let Oe=Math.max(.35,$e*Ae+Fe*Pe);I.push(new i($e/Oe,Fe/Oe))}else I.push(new i(Ae,Pe))}return I}class G extends C{constructor(j=new T,I={}){super();let O=Array.isArray(j)?j:[j],K=Math.max(1,Math.min(64,Math.floor(b(I.curveSegments,12)))),ie=b(I.depth??I.amount,1),he=Math.max(1,Math.min(32,Math.floor(b(I.steps,1)))),ue=!!(I.bevelEnabled??!1),ge=ue?Math.max(0,b(I.bevelThickness,.06)):0,oe=ue?Math.max(0,b(I.bevelSize,ge*.8)):0,_e=ue?b(I.bevelOffset,0):0,fe=ue?Math.max(1,Math.min(8,Math.floor(b(I.bevelSegments,2)))):0,ye=[],Ae=[],Pe=[],Le=[];for(let ke of O){if(!(ke instanceof $))continue;let $e=S(ke,K);if($e.shape.length<3)continue;let Fe=$e.shape.slice();M(Fe)<0&&Fe.reverse();let qe=[];for(let ve of $e.holes){if(ve.length<3)continue;let st=ve.slice();M(st)>0&&st.reverse(),qe.push(st)}let{mergedIndices:Oe,allVertices:lt}=k(Fe,qe),rt=A(Oe,lt),nt=[Fe,...qe],ht=[];for(let ve of nt){let st=H(ve);for(let yt of st)ht.push(yt)}let[Ke,Dt,zt,Qt]=w(lt);for(let[ve,st]of[[-ge,-1],[ie+ge,1]]){let yt=ye.length/3;for(let xt=0;xt<lt.length;xt++){let wt=lt[xt],St=ht[xt]??new i(0,0),Bt=wt.x+St.x*_e,Rt=wt.y+St.y*_e;ye.push(Bt,Rt,ve),Ae.push(0,0,st),Pe.push((Bt-Ke)/zt,(Rt-Dt)/Qt)}for(let[xt,wt,St]of rt)Le.push(yt+xt,yt+(st<0?St:wt),yt+(st<0?wt:St))}let bt=[];if(ue&&fe>0)for(let ve=0;ve<fe;ve++){let st=ve/fe*Math.PI/2;bt.push({z:-ge*Math.cos(st),expand:_e+oe*Math.sin(st)})}for(let ve=0;ve<=he;ve++){let st=ve/he;bt.push({z:st*ie,expand:_e+oe})}if(ue&&fe>0)for(let ve=1;ve<=fe;ve++){let st=ve/fe*Math.PI/2;bt.push({z:ie+ge*Math.sin(st),expand:_e+oe*Math.cos(st)})}let It=0;for(let ve of nt){let st=ve.length;for(let yt=0;yt<bt.length-1;yt++){let xt=bt[yt],wt=bt[yt+1];for(let St=0;St<st;St++){let Bt=(St+1)%st,Rt=ve[St],jt=ve[Bt],Ht=ht[It+St],Gt=ht[It+Bt],Kt=Rt.x+Ht.x*xt.expand,ui=Rt.y+Ht.y*xt.expand,Ii=jt.x+Gt.x*xt.expand,Wt=jt.y+Gt.y*xt.expand,qt=jt.x+Gt.x*wt.expand,Vi=jt.y+Gt.y*wt.expand,Pi=Rt.x+Ht.x*wt.expand,ci=Rt.y+Ht.y*wt.expand,ei=Ii-Kt,Ut=Wt-ui,Vn=Pi-Kt,cr=ci-ui,Hi=wt.z-xt.z,xi=Ut*Hi,vi=-ei*Hi,Mi=ei*cr-Ut*Vn,Ui=Math.hypot(xi,vi,Mi)||1;xi/=Ui,vi/=Ui,Mi/=Ui;let ti=ye.length/3;ye.push(Kt,ui,xt.z,Ii,Wt,xt.z,qt,Vi,wt.z,Pi,ci,wt.z),Ae.push(xi,vi,Mi,xi,vi,Mi,xi,vi,Mi,xi,vi,Mi);let fr=St/st,Jr=(St+1)/st,fi=yt/(bt.length-1),ii=(yt+1)/(bt.length-1);Pe.push(fr,fi,Jr,fi,Jr,ii,fr,ii),Le.push(ti,ti+1,ti+2,ti,ti+2,ti+3)}}It+=st}}P(this,ye,Ae,Pe,Le)}}function x(J){return{x:J.x,y:J.y,z:J.z,nx:J.nx,ny:J.ny,nz:J.nz,u:J.u,v:J.v}}function V(J){return{x:J.x,y:J.y,z:J.z,nx:-J.nx,ny:-J.ny,nz:-J.nz,u:J.u,v:J.v}}function Y(J,j,I){let O=J.nx+(j.nx-J.nx)*I,K=J.ny+(j.ny-J.ny)*I,ie=J.nz+(j.nz-J.nz)*I,he=Math.hypot(O,K,ie)||1;return{x:J.x+(j.x-J.x)*I,y:J.y+(j.y-J.y)*I,z:J.z+(j.z-J.z)*I,nx:O/he,ny:K/he,nz:ie/he,u:J.u+(j.u-J.u)*I,v:J.v+(j.v-J.v)*I}}function Z(J){if(J.length<3)return null;let j=J[0],I=J[1],O=J[2],K=I.x-j.x,ie=I.y-j.y,he=I.z-j.z,ue=O.x-j.x,ge=O.y-j.y,oe=O.z-j.z,_e=ie*oe-he*ge,fe=he*ue-K*oe,ye=K*ge-ie*ue,Ae=Math.hypot(_e,fe,ye);if(Ae<1e-9)return null;_e/=Ae,fe/=Ae,ye/=Ae;let Pe=_e*j.x+fe*j.y+ye*j.z;return{vertices:J,nx:_e,ny:fe,nz:ye,w:Pe}}function q(J){J.vertices.reverse();for(let j=0;j<J.vertices.length;j++)J.vertices[j]=V(J.vertices[j]);J.nx=-J.nx,J.ny=-J.ny,J.nz=-J.nz,J.w=-J.w}let X=1e-5,F=0,Q=1,L=2,ee=3;function ae(J,j,I,O,K,ie,he,ue,ge){let oe=0,_e=[];for(let fe=0;fe<K.vertices.length;fe++){let ye=K.vertices[fe],Ae=J*ye.x+j*ye.y+I*ye.z-O,Pe=Ae<-X?L:Ae>X?Q:F;oe|=Pe,_e.push(Pe)}switch(oe){case F:{J*K.nx+j*K.ny+I*K.nz>0?ie.push(K):he.push(K);break}case Q:ue.push(K);break;case L:ge.push(K);break;case ee:{let fe=[],ye=[],Ae=K.vertices.length;for(let Fe=0;Fe<Ae;Fe++){let qe=(Fe+1)%Ae,Oe=_e[Fe],lt=_e[qe],rt=K.vertices[Fe],nt=K.vertices[qe];if(Oe!==L&&fe.push(rt),Oe!==Q&&ye.push(Oe!==L?x(rt):rt),(Oe|lt)===ee){let ht=nt.x-rt.x,Ke=nt.y-rt.y,Dt=nt.z-rt.z,zt=J*ht+j*Ke+I*Dt,Qt=Math.abs(zt)>1e-12?(O-(J*rt.x+j*rt.y+I*rt.z))/zt:.5,bt=Y(rt,nt,Math.max(0,Math.min(1,Qt)));fe.push(bt),ye.push(x(bt))}}let{nx:Pe,ny:Le,nz:ke,w:$e}=K;fe.length>=3&&ue.push({vertices:fe,nx:Pe,ny:Le,nz:ke,w:$e}),ye.length>=3&&ge.push({vertices:ye,nx:Pe,ny:Le,nz:ke,w:$e});break}default:break}}class be{constructor(j,I=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,j&&j.length>0&&this.build(j,I)}invert(){for(let I=0;I<this.polygons.length;I++)q(this.polygons[I]);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 j=this.front;this.front=this.back,this.back=j}clipPolygons(j,I=0){if(!this.hasPlane||j.length===0)return j.slice();if(I>=z)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${z})`);let O=[],K=[];for(let ie=0;ie<j.length;ie++)ae(this.nx,this.ny,this.nz,this.w,j[ie],O,K,O,K);return this.front&&O.length>0&&(O=this.front.clipPolygons(O,I+1)),this.back?K=K.length>0?this.back.clipPolygons(K,I+1):[]:K=[],O.concat(K)}clipTo(j,I=0){this.polygons.length>0&&(this.polygons=j.clipPolygons(this.polygons,0)),I<z&&(this.front&&this.front.clipTo(j,I+1),this.back&&this.back.clipTo(j,I+1))}allPolygons(j=[]){for(let I=0;I<this.polygons.length;I++)j.push(this.polygons[I]);return this.front&&this.front.allPolygons(j),this.back&&this.back.allPolygons(j),j}build(j,I=0){if(!j.length)return;if(!this.hasPlane){let ie=j[j.length>>1];this.nx=ie.nx,this.ny=ie.ny,this.nz=ie.nz,this.w=ie.w,this.hasPlane=!0}if(I>=z)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${z})`);let O=[],K=[];for(let ie=0;ie<j.length;ie++)ae(this.nx,this.ny,this.nz,this.w,j[ie],this.polygons,this.polygons,O,K);O.length>0&&(this.front||(this.front=new be),this.front.build(O,I+1)),K.length>0&&(this.back||(this.back=new be),this.back.build(K,I+1))}}function Ne(J,j){if(!j&&J._csgPolygons)return J._csgPolygons;let I=J.attributes.position;if(!I||I.count===0)return[];let O=J.attributes.normal,K=J.attributes.uv,ie=J.index?J.index.array:null,he=Math.floor(ie?ie.length/3:I.count/3);if(he>y)throw new RangeError(`SecurityError: CSG input triangle count (${he}) exceeds MAX_CSG_TRIANGLES (${y})`);let ue=j?j.elements:null,ge=ue?ue[0]*(ue[5]*ue[10]-ue[9]*ue[6])-ue[4]*(ue[1]*ue[10]-ue[9]*ue[2])+ue[8]*(ue[1]*ue[6]-ue[5]*ue[2])<0:!1,oe=ue?new f().getNormalMatrix(j).elements:null,_e=ye=>{let Ae=I.getX(ye),Pe=I.getY(ye),Le=I.getZ(ye),ke=O?O.getX(ye):NaN,$e=O?O.getY(ye):NaN,Fe=O?O.getZ(ye):NaN;if(ue&&oe){let lt=ue[0]*Ae+ue[4]*Pe+ue[8]*Le+ue[12],rt=ue[1]*Ae+ue[5]*Pe+ue[9]*Le+ue[13],nt=ue[2]*Ae+ue[6]*Pe+ue[10]*Le+ue[14];Ae=lt,Pe=rt,Le=nt;let ht=oe[0]*ke+oe[3]*$e+oe[6]*Fe,Ke=oe[1]*ke+oe[4]*$e+oe[7]*Fe,Dt=oe[2]*ke+oe[5]*$e+oe[8]*Fe,zt=Math.hypot(ht,Ke,Dt)||1;ke=ht/zt,$e=Ke/zt,Fe=Dt/zt}let qe=K?K.getX(ye):0,Oe=K?K.getY(ye):0;return{x:Ae,y:Pe,z:Le,nx:ke,ny:$e,nz:Fe,u:qe,v:Oe}},fe=[];for(let ye=0;ye<he;ye++){let Ae=ie?ie[ye*3]:ye*3,Pe=ie?ie[ye*3+1]:ye*3+1,Le=ie?ie[ye*3+2]:ye*3+2,ke=Z(ge?[_e(Ae),_e(Le),_e(Pe)]:[_e(Ae),_e(Pe),_e(Le)]);ke&&fe.push(ke)}return fe}function De(J){let j=[],I=[],O=[],K=[];for(let he of J){let ue=he.vertices;if(ue.length<3)continue;let ge=j.length/3;for(let oe of ue)j.push(oe.x,oe.y,oe.z),Number.isFinite(oe.nx)&&oe.nx*oe.nx+oe.ny*oe.ny+oe.nz*oe.nz>.5?I.push(oe.nx,oe.ny,oe.nz):I.push(he.nx,he.ny,he.nz),O.push(oe.u,oe.v);for(let oe=1;oe<ue.length-1;oe++)K.push(ge,ge+oe,ge+oe+1)}let ie=P(new C,j,I,O,K);return ie._csgPolygons=J,ie}function Be(J,j,I){if(J.length+j.length>y)throw new RangeError(`SecurityError: Combined CSG triangle count (${J.length+j.length}) exceeds MAX_CSG_TRIANGLES (${y})`);if(J.length===0)return I==="union"?j:[];if(j.length===0)return I==="intersect"?[]:J;let O=1/0,K=1/0,ie=1/0,he=-1/0,ue=-1/0,ge=-1/0;for(let Ae=0;Ae<j.length;Ae++){let Pe=j[Ae].vertices;for(let Le=0;Le<Pe.length;Le++){let ke=Pe[Le];ke.x<O&&(O=ke.x),ke.y<K&&(K=ke.y),ke.z<ie&&(ie=ke.z),ke.x>he&&(he=ke.x),ke.y>ue&&(ue=ke.y),ke.z>ge&&(ge=ke.z)}}O-=1e-4,K-=1e-4,ie-=1e-4,he+=1e-4,ue+=1e-4,ge+=1e-4;let oe=[],_e=[];for(let Ae=0;Ae<J.length;Ae++){let Pe=J[Ae],Le=Pe.vertices,ke=1/0,$e=1/0,Fe=1/0,qe=-1/0,Oe=-1/0,lt=-1/0;for(let rt=0;rt<Le.length;rt++){let nt=Le[rt];nt.x<ke&&(ke=nt.x),nt.y<$e&&($e=nt.y),nt.z<Fe&&(Fe=nt.z),nt.x>qe&&(qe=nt.x),nt.y>Oe&&(Oe=nt.y),nt.z>lt&&(lt=nt.z)}qe<O||ke>he||Oe<K||$e>ue||lt<ie||Fe>ge?_e.push(Pe):oe.push(Pe)}if(oe.length===0)return I==="union"?J.concat(j):I==="subtract"?J:[];let fe=new be(oe),ye=new be(j);return I==="union"?(fe.clipTo(ye),ye.clipTo(fe),ye.invert(),ye.clipTo(fe),ye.invert(),fe.build(ye.allPolygons()),_e.concat(fe.allPolygons())):I==="subtract"?(fe.invert(),fe.clipTo(ye),ye.clipTo(fe),ye.invert(),ye.clipTo(fe),ye.invert(),fe.build(ye.allPolygons()),fe.invert(),_e.concat(fe.allPolygons())):(fe.invert(),ye.clipTo(fe),ye.invert(),fe.clipTo(ye),ye.clipTo(fe),fe.build(ye.allPolygons()),fe.invert(),fe.allPolygons())}function je(J,j,I,O=null,K=null){{let ue=globalThis.__three_live_native_csg_boolean__;if(typeof ue=="function"&&J?.attributes?.position?.array&&j?.attributes?.position?.array){let ge=I==="subtract"?0:I==="union"?1:2,oe=ue(J.attributes.position.array,J.attributes.normal?J.attributes.normal.array:null,J.attributes.uv?J.attributes.uv.array:null,J.index?J.index.array:null,O?O.elements:null,j.attributes.position.array,j.attributes.normal?j.attributes.normal.array:null,j.attributes.uv?j.attributes.uv.array:null,j.index?j.index.array:null,K?K.elements:null,ge);if(oe)return P(new C,oe.positions,oe.normals,oe.uvs,oe.indices)}}let ie=Ne(J,O),he=Ne(j,K);return De(Be(ie,he,I))}function Ve(J,j,I){let O=J instanceof m||!!J?.isMesh,K=j instanceof m||!!j?.isMesh,ie=O?J.geometry:J,he=K?j.geometry:j,ue=null;if(K)if(j.updateMatrix(),O){J.updateMatrix();let fe=new a().makeScale(1/(J.scale.x||1),1/(J.scale.y||1),1/(J.scale.z||1)),ye=Math.hypot(J.quaternion.x,J.quaternion.y,J.quaternion.z,J.quaternion.w)||1,Ae=new a().compose(new r(0,0,0),new s(-J.quaternion.x/ye,-J.quaternion.y/ye,-J.quaternion.z/ye,J.quaternion.w/ye),new r(1,1,1)),Pe=new a().makeTranslation(-J.position.x,-J.position.y,-J.position.z);ue=fe.multiply(Ae).multiply(Pe).multiply(j.matrix)}else ue=j.matrix;let ge=je(ie,he,I,null,ue),oe=O?J.material:new p,_e=new m(ge,oe);return O&&(_e.position.copy(J.position),_e.quaternion.copy(J.quaternion),_e.scale.copy(J.scale),_e.name=J.name),_e}let Ie={toGeometry:je,subtract(J,j){return Ve(J,j,"subtract")},union(J,j){return Ve(J,j,"union")},intersect(J,j){return Ve(J,j,"intersect")}},Me={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 ze extends C{constructor(j="",I={}){super();let O=String(j??"").slice(0,E),K=Math.max(.005,Math.min(100,b(I.size,.2))),ie=!!(I.bevelEnabled??!1),he=ie?Math.max(0,Math.min(2,b(I.bevelThickness,K*.04))):0,ue=ie?Math.max(0,Math.min(2,b(I.bevelSize,K*.03))):0,ge=Math.max(.001,Math.min(20,b(I.depth??I.height,K*.2)))+he*2,oe=K*.085+ue,_e=K*.68,fe=K*.82,ye=[],Ae=[],Pe=[],Le=[],ke=(qe,Oe,lt,rt,nt,ht,Ke)=>{let Dt=lt-qe,zt=rt-Oe,Qt=Math.hypot(Dt,zt),bt=1,It=0;Qt>1e-6&&(bt=Dt/Qt,It=zt/Qt);let ve=-It*nt,st=bt*nt,yt=bt*nt*.6,xt=It*nt*.6,wt=qe-yt+ve,St=Oe-xt+st,Bt=qe-yt-ve,Rt=Oe-xt-st,jt=lt+yt-ve,Ht=rt+xt-st,Gt=lt+yt+ve,Kt=rt+xt+st,ui=(Ii,Wt,qt,Vi,Pi,ci,ei)=>{let Ut=ye.length/3;ye.push(Ii[0],Ii[1],Ii[2],Wt[0],Wt[1],Wt[2],qt[0],qt[1],qt[2],Vi[0],Vi[1],Vi[2]),Ae.push(Pi,ci,ei,Pi,ci,ei,Pi,ci,ei,Pi,ci,ei),Pe.push(0,0,1,0,1,1,0,1),Le.push(Ut,Ut+1,Ut+2,Ut,Ut+2,Ut+3)};ui([wt,St,Ke],[Bt,Rt,Ke],[jt,Ht,Ke],[Gt,Kt,Ke],0,0,1),ui([Bt,Rt,ht],[wt,St,ht],[Gt,Kt,ht],[jt,Ht,ht],0,0,-1),ui([wt,St,ht],[Bt,Rt,ht],[Bt,Rt,Ke],[wt,St,Ke],-bt,-It,0),ui([jt,Ht,ht],[Gt,Kt,ht],[Gt,Kt,Ke],[jt,Ht,Ke],bt,It,0),ui([Bt,Rt,ht],[jt,Ht,ht],[jt,Ht,Ke],[Bt,Rt,Ke],It,-bt,0),ui([Gt,Kt,ht],[wt,St,ht],[wt,St,Ke],[Gt,Kt,Ke],-It,bt,0)},$e=0,Fe=0;for(let qe=0;qe<O.length;qe++){let Oe=O[qe];if(Oe===`
|
|
17
|
+
`){$e=0,Fe-=K*1.35;continue}if(Oe===" "||Oe===" "){$e+=fe*(Oe===" "?.75:3);continue}if(Oe==="\r")continue;let lt=Oe.toUpperCase(),rt=Oe!==lt&&Oe>="a"&&Oe<="z",nt=Me[lt]??Me["?"],ht=rt?K*.76:K,Ke=rt?_e*.88:_e;for(let Dt of nt)for(let zt=0;zt<Dt.length-1;zt++){let Qt=Dt[zt],bt=Dt[zt+1];ke($e+Qt[0]*Ke,Fe+Qt[1]*ht,$e+bt[0]*Ke,Fe+bt[1]*ht,oe,-ge*.5,ge*.5)}$e+=rt?fe*.88:fe}P(this,ye,Ae,Pe,Le),I.center!==!1?this.center():this.computeBoundingBox()}}function Se(J){if(!J)return;let j=J,I=J.userData?.xr?.text??J.userData?.xr?.label??J.userData?.xr?.title??J.userData?.xr?.caption??J.userData?.xr?.spatialLabel;if(I!=null&&I!==!1){let K=j.geometry?.attributes?.position;if((!K||K.count===0)&&J.userData._textApplied!==!0){let ie="",he=.08,ue=.015,ge;if(typeof I=="string"||typeof I=="number")ie=String(I);else if(typeof I=="object"){let oe=I;ie=String(oe.text??oe.value??""),oe.size!==void 0&&(he=Number(oe.size)||.08),(oe.depth!==void 0||oe.height!==void 0)&&(ue=Number(oe.depth??oe.height)||he*.2),(typeof oe.color=="string"||typeof oe.color=="number")&&(ge=oe.color)}ie.trim().length>0&&(j.geometry=new ze(ie,{size:he,depth:ue}),J.userData._textApplied=!0,j.material instanceof d?ge!==void 0&&J.userData._autoTextColorApplied!==!0&&(j.material.color=new c(ge),J.userData._autoTextColorApplied=!0):j.material=new p({color:ge??16317180}))}}let O=J.userData?.csg;if(O&&typeof O=="object"&&J.userData._csgApplied!==!0&&j.geometry instanceof C&&j.geometry.attributes.position?.count>0){J.userData._csgApplied=!0;let K=Array.isArray(O)?O:[O],ie=j.geometry;for(let he of K){if(!he||typeof he!="object")continue;let ue=he,ge=String(ue.op??ue.operation??"subtract"),oe=ge==="union"||ge==="intersect"?ge:"subtract",_e=ue.target??ue.mesh??ue.geometry;if(_e instanceof m||_e instanceof C)try{let fe=oe==="union"?Ie.union(j,_e):oe==="intersect"?Ie.intersect(j,_e):Ie.subtract(j,_e);j.geometry!==ie&&j.geometry.dispose?.(),j.geometry=fe.geometry}catch(fe){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",fe)}}}}let He={Path:$,Shape:T,ShapeGeometry:v,ExtrudeGeometry:G,TextGeometry:ze,CSG:Ie,MAX_CSG_TRIANGLES:y,MAX_BSP_DEPTH:z,MAX_TEXT_GEOMETRY_CHARS:E,MAX_SHAPE_POINTS:_,materializeDeclarativeGeometry:Se};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,He),e._cadMaterialize=Se,e.materializeDeclarativeGeometry=J=>{e._cadMaterialize?.(J),e._lodMaterialize?.(J),e._procMaterialize?.(J)}),He}function Ct(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function Zn(t,e,i,r,s){let a=1/Math.tan(e/2);t.fill(0),t[0]=a/i,t[5]=a,t[11]=-1;let f=1/(r-s);return t[10]=(s+r)*f,t[14]=2*s*r*f,t}function en(t,e,i,r){let[s,a,f]=e,[c,h,C]=r,[d,p,m]=i,y=s-d,z=a-p,E=f-m,_=Math.hypot(y,z,E);_<=1e-5?(y=0,z=0,E=1):(y/=_,z/=_,E/=_);let b=h*E-C*z,$=C*y-c*E,T=c*z-h*y;_=Math.hypot(b,$,T),_<=1e-5?(b=0,$=0,T=0):(b/=_,$/=_,T/=_);let M=z*T-E*$,N=E*b-y*T,k=y*$-z*b;return _=Math.hypot(M,N,k),_<=1e-5?(M=0,N=0,k=0):(M/=_,N/=_,k/=_),t[0]=b,t[1]=M,t[2]=y,t[3]=0,t[4]=$,t[5]=N,t[6]=z,t[7]=0,t[8]=T,t[9]=k,t[10]=E,t[11]=0,t[12]=-(b*s+$*a+T*f),t[13]=-(M*s+N*a+k*f),t[14]=-(y*s+z*a+E*f),t[15]=1,t}function Et(t,e,i){let r=e[0],s=e[1],a=e[2],f=e[3],c=e[4],h=e[5],C=e[6],d=e[7],p=e[8],m=e[9],y=e[10],z=e[11],E=e[12],_=e[13],b=e[14],$=e[15],T=i[0],M=i[1],N=i[2],k=i[3];return t[0]=T*r+M*c+N*p+k*E,t[1]=T*s+M*h+N*m+k*_,t[2]=T*a+M*C+N*y+k*b,t[3]=T*f+M*d+N*z+k*$,T=i[4],M=i[5],N=i[6],k=i[7],t[4]=T*r+M*c+N*p+k*E,t[5]=T*s+M*h+N*m+k*_,t[6]=T*a+M*C+N*y+k*b,t[7]=T*f+M*d+N*z+k*$,T=i[8],M=i[9],N=i[10],k=i[11],t[8]=T*r+M*c+N*p+k*E,t[9]=T*s+M*h+N*m+k*_,t[10]=T*a+M*C+N*y+k*b,t[11]=T*f+M*d+N*z+k*$,T=i[12],M=i[13],N=i[14],k=i[15],t[12]=T*r+M*c+N*p+k*E,t[13]=T*s+M*h+N*m+k*_,t[14]=T*a+M*C+N*y+k*b,t[15]=T*f+M*d+N*z+k*$,t}function tn(t,e,i,r){let s=e[0],a=e[1],f=e[2],c=e[3],h=s+s,C=a+a,d=f+f,p=s*h,m=s*C,y=s*d,z=a*C,E=a*d,_=f*d,b=c*h,$=c*C,T=c*d,M=r[0],N=r[1],k=r[2];return t[0]=(1-(z+_))*M,t[1]=(m+T)*M,t[2]=(y-$)*M,t[3]=0,t[4]=(m-T)*N,t[5]=(1-(p+_))*N,t[6]=(E+b)*N,t[7]=0,t[8]=(y+$)*k,t[9]=(E-b)*k,t[10]=(1-(p+z))*k,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function zi(t,e,i=0){let r=e[0],s=e[1],a=e[2],f=e[4],c=e[5],h=e[6],C=e[8],d=e[9],p=e[10],m=p*c-h*d,y=-p*f+h*C,z=d*f-c*C,E=r*m+s*y+a*z;return!E||i>0&&(!Number.isFinite(E)||Math.abs(E)<=i)||(E=1/E,t[0]=m*E,t[1]=y*E,t[2]=z*E,t[3]=(-p*s+a*d)*E,t[4]=(p*r-a*C)*E,t[5]=(-d*r+s*C)*E,t[6]=(h*s-a*c)*E,t[7]=(-h*r+a*f)*E,t[8]=(c*r-s*f)*E),t}function _o(t,e){let i=e[0],r=e[1],s=e[2],a=e[3],f=e[4],c=e[5],h=e[6],C=e[7],d=e[8],p=e[9],m=e[10],y=e[11],z=e[12],E=e[13],_=e[14],b=e[15],$=i*c-r*f,T=i*h-s*f,M=i*C-a*f,N=r*h-s*c,k=r*C-a*c,A=s*C-a*h,S=d*E-p*z,w=d*_-m*z,v=d*b-y*z,P=p*_-m*E,H=p*b-y*E,G=m*b-y*_,x=$*G-T*H+M*P+N*v-k*w+A*S;return x?(x=1/x,t[0]=(c*G-h*H+C*P)*x,t[1]=(s*H-r*G-a*P)*x,t[2]=(E*A-_*k+b*N)*x,t[3]=(m*k-p*A-y*N)*x,t[4]=(h*v-f*G-C*w)*x,t[5]=(i*G-s*v+a*w)*x,t[6]=(_*M-z*A-b*T)*x,t[7]=(d*A-m*M+y*T)*x,t[8]=(f*H-c*v+C*S)*x,t[9]=(r*v-i*H-a*S)*x,t[10]=(z*k-E*M+b*$)*x,t[11]=(p*M-d*k-y*$)*x,t[12]=(c*w-f*P-h*S)*x,t[13]=(i*P-r*w+s*S)*x,t[14]=(E*T-z*N-_*$)*x,t[15]=(d*N-p*T+m*$)*x,t):null}function Qn(t,e,i,r,s){let a=s[0]*e+s[4]*i+s[8]*r+s[12],f=s[1]*e+s[5]*i+s[9]*r+s[13],c=s[2]*e+s[6]*i+s[10]*r+s[14],h=s[3]*e+s[7]*i+s[11]*r+s[15],C=h!==0?1/h:1;t[0]=a*C,t[1]=f*C,t[2]=c*C}function So(t,e,i,r,s,a,f,c,h,C,d,p,m,y,z,E,_=0){let b=C-f,$=d-c,T=p-h,M=m-f,N=y-c,k=z-h,A=s*k-a*N,S=a*M-r*k,w=r*N-s*M,v=b*A+$*S+T*w;if(v>-1e-7&&v<1e-7)return!1;let P=1/v,H=t-f,G=e-c,x=i-h,V=P*(H*A+G*S+x*w);if(V<-_||V>1+_)return!1;let Y=G*T-x*$,Z=x*b-H*T,q=H*$-G*b,X=P*(r*Y+s*Z+a*q);if(X<-_||V+X>1+_)return!1;let F=P*(M*Y+N*Z+k*q);if(F>1e-4&&F<E.distance){E.distance=F,E.point=[t+r*F,e+s*F,i+a*F];let Q=$*k-T*N,L=T*M-b*k,ee=b*N-$*M,ae=Math.hypot(Q,L,ee)||1;return E.normal=[Q/ae,L/ae,ee/ae],!0}return!1}function Kn(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let d=0;d<i;d++)r.push(Ct());if(i===0)return r;let s=new Set;for(let d of t.nodes)if(Array.isArray(d.children))for(let p of d.children)s.add(p);let a=new Set,f=128,c=(d,p,m=0)=>{if(m>f||d<0||d>=i||a.has(d))return;a.add(d);let y=t.nodes[d];if(!y)return;let z=Ct();if(e&&e[d])z.set(e[d]);else if(y.matrix&&y.matrix.length===16)z.set(y.matrix);else{let _=y.translation||[0,0,0],b=y.rotation||[0,0,0,1],$=y.scale||[1,1,1];tn(z,b,_,$)}let E=r[d];if(p?Et(E,p,z):E.set(z),Array.isArray(y.children))for(let _ of y.children)typeof _=="number"&&c(_,E,m+1)},h=[],C=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(C&&Array.isArray(C.nodes))h.push(...C.nodes);else for(let d=0;d<i;d++)s.has(d)||h.push(d);for(let d of h)c(d,null);for(let d=0;d<i;d++)!s.has(d)&&!h.includes(d)&&c(d,null);return r}function es(t,e){function i(h,C,d,p){let m=typeof h=="number"?h:Number(h);return Number.isFinite(m)?Math.max(C,Math.min(d,m)):p}function r(h,C){let d=h[0]*C[0]+h[1]*C[1]+h[2]*C[2]+1;if(d<1e-6){if(Math.abs(h[0])>Math.abs(h[2])){let _=Math.hypot(h[1],h[0])||1;return[-h[1]/_,h[0]/_,0,0]}let E=Math.hypot(h[2],h[1])||1;return[0,-h[2]/E,h[1]/E,0]}let p=h[1]*C[2]-h[2]*C[1],m=h[2]*C[0]-h[0]*C[2],y=h[0]*C[1]-h[1]*C[0],z=Math.hypot(p,m,y,d)||1;return[p/z,m/z,y/z,d/z]}function s(h,C,d,p,m){let y=C[0]-h[0],z=C[1]-h[1],E=C[2]-h[2],_=Math.hypot(y,z,E),b=d[0]-C[0],$=d[1]-C[1],T=d[2]-C[2],M=Math.hypot(b,$,T);if(_<1e-6||M<1e-6)return{rootPos:[h[0],h[1],h[2]],midPos:[C[0],C[1],C[2]],effectorPos:[d[0],d[1],d[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let N=[y/_,z/_,E/_],k=[b/M,$/M,T/M],A=p[0]-h[0],S=p[1]-h[1],w=p[2]-h[2],v=Math.hypot(A,S,w),P=v>1e-6?[A/v,S/v,w/v]:N,H=Math.abs(_-M)+1e-5,G=Math.max(H,_+M-1e-5),x=Math.max(H,Math.min(G,v>1e-6?v:H)),V=i((_*_+x*x-M*M)/(2*_*x),-1,1,1),Y=Math.sqrt(Math.max(0,1-V*V)),Z=m?m[0]-h[0]:y,q=m?m[1]-h[1]:z,X=m?m[2]-h[2]:E,F=Z*P[0]+q*P[1]+X*P[2],Q=Z-P[0]*F,L=q-P[1]*F,ee=X-P[2]*F,ae=Math.hypot(Q,L,ee);if(ae<=1e-6){let He=Math.abs(P[1])<.99?0:1,J=Math.abs(P[1])<.99?1:0,j=0;Q=P[1]*j-P[2]*J,L=P[2]*He-P[0]*j,ee=P[0]*J-P[1]*He,ae=Math.hypot(Q,L,ee)||1}let be=[Q/ae,L/ae,ee/ae],Ne=[h[0]+P[0]*(_*V)+be[0]*(_*Y),h[1]+P[1]*(_*V)+be[1]*(_*Y),h[2]+P[2]*(_*V)+be[2]*(_*Y)],De=[h[0]+P[0]*x,h[1]+P[1]*x,h[2]+P[2]*x],Be=De[0]-Ne[0],je=De[1]-Ne[1],Ve=De[2]-Ne[2],Ie=Math.hypot(Be,je,Ve),Me=Ie>1e-6?[Be/Ie,je/Ie,Ve/Ie]:P,ze=[Ne[0]+Me[0]*M,Ne[1]+Me[1]*M,Ne[2]+Me[2]*M],Se=[(Ne[0]-h[0])/_,(Ne[1]-h[1])/_,(Ne[2]-h[2])/_];return{rootPos:[h[0],h[1],h[2]],midPos:Ne,effectorPos:ze,rootRotation:r(N,Se),midRotation:r(k,Me)}}function a(h,C,d=8,p=.001){let m=h.length;if(m<2)return{positions:h.map(v=>[v[0],v[1],v[2]]),rotations:[],iterations:0};let y=h.map(v=>[v[0],v[1],v[2]]),z=[],E=[],_=0;for(let v=0;v<m-1;v++){let P=y[v+1][0]-y[v][0],H=y[v+1][1]-y[v][1],G=y[v+1][2]-y[v][2],x=Math.hypot(P,H,G);z.push(x),_+=x,E.push(x>1e-6?[P/x,H/x,G/x]:[0,1,0])}let b=[y[0][0],y[0][1],y[0][2]],$=Math.round(i(d,1,32,8)),T=i(p,1e-5,.1,.001),M=C[0]-b[0],N=C[1]-b[1],k=C[2]-b[2],A=Math.hypot(M,N,k),S=0;if(A>=_&&_>1e-6){let v=A>1e-6?[M/A,N/A,k/A]:E[0];y[0]=[b[0],b[1],b[2]];for(let P=0;P<m-1;P++){let H=z[P];y[P+1]=[y[P][0]+v[0]*H,y[P][1]+v[1]*H,y[P][2]+v[2]*H]}S=1}else for(let v=1;v<=$;v++){let P=y[m-1];if(Math.hypot(P[0]-C[0],P[1]-C[1],P[2]-C[2])<=T)break;S=v;let H=(G,x,V,Y,Z)=>{let q=x[0]-G[0],X=x[1]-G[1],F=x[2]-G[2],Q=Math.hypot(q,X,F);if(Q>1e-6){let L=V/Q;return[G[0]+q*L,G[1]+X*L,G[2]+F*L]}return[G[0]+Y[0]*V*Z,G[1]+Y[1]*V*Z,G[2]+Y[2]*V*Z]};y[m-1]=[C[0],C[1],C[2]];for(let G=m-2;G>=0;G--)y[G]=H(y[G+1],y[G],z[G],E[G],-1);y[0]=[b[0],b[1],b[2]];for(let G=0;G<m-1;G++)y[G+1]=H(y[G],y[G+1],z[G],E[G],1)}let w=[];for(let v=0;v<m-1;v++){let P=y[v+1][0]-y[v][0],H=y[v+1][1]-y[v][1],G=y[v+1][2]-y[v][2],x=Math.hypot(P,H,G),V=x>1e-6?[P/x,H/x,G/x]:E[v];w.push(r(E[v],V))}return{positions:y,rotations:w,iterations:S}}function f(h){if(!h||typeof h!="object"||Array.isArray(h))return null;let C=h;if(C.enabled===!1)return null;let d=T=>{if(typeof T!="string")return;let M=T.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(M)?M:void 0},p=T=>Array.isArray(T)&&T.length===3&&T.every(M=>typeof M=="number"&&Number.isFinite(M))?[i(T[0],-1e3,1e3,0),i(T[1],-1e3,1e3,0),i(T[2],-1e3,1e3,0)]:void 0,m=d(C.root),y=d(C.effector);if(!m||!y)return null;let z=d(C.mid),E=p(C.target)??d(C.target);if(!E)return null;let _=C.pole??C.poleTarget,b=p(_)??d(_),$=C.solver==="fabrik"?"fabrik":C.solver==="two-bone"||z?"two-bone":"fabrik";return{root:m,...z?{mid:z}:{},effector:y,target:E,...b?{pole:b}:{},solver:$,iterations:Math.round(i(C.iterations,1,32,8)),tolerance:i(C.tolerance,1e-5,.1,.001),weight:i(C.weight,0,1,1)}}let c=Object.freeze({solveTwoBone:s,solveFABRIK:a,parseIKTrait:f});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=c),{clampNum:i,parseIKTrait:f,quatFromUnitVectors:r,solveTwoBoneIK:s,solveFABRIK:a,IKSolver:c}}var Wi=es(),Xh=Wi.clampNum,Yh=Wi.parseIKTrait,Jh=Wi.quatFromUnitVectors,Zh=Wi.solveTwoBoneIK,Qh=Wi.solveFABRIK,Kh=Wi.IKSolver;function ts(t,e){let i=(d,p,m,y)=>{let z=typeof d=="number"?d:Number(d);return Number.isFinite(z)?Math.max(p,Math.min(m,z)):y};function r(d,p,m=0,y=.05,z){if(!d||!d.length)return-1;let E=d[0]>0?[0,...d]:d,_=Number.isFinite(p)?Math.max(0,p):0,b=Number.isFinite(y)?Math.max(0,Math.min(.5,y)):.05;if(typeof z=="number"&&Number.isFinite(z)&&z>0){let M=m===-1?z*(1-b):z*(1+b);if(_>M)return-1}let $=0;for(let M=E.length-1;M>=1;M--)if(_>=E[M]){$=M;break}if(m<0||m>=E.length||m===$)return $;if($>m){let M=m;for(let N=m+1;N<=$&&_>=E[N]*(1+b);N++)M=N;return M}let T=m;for(let M=m;M>$&&_<E[M]*(1-b);M--)T=M-1;return T}function s(d){if(!d)return null;let p=d===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(d)?{distances:d}:typeof d=="object"?d:null;if(!p||p.enabled===!1)return null;let m=i(p.hysteresis,0,.5,.05),y=[],z;if(Array.isArray(p.levels)&&p.levels.length>0){let $=p.levels.slice(0,8);for(let M=0;M<$.length;M++){let N=$[M];if(!N||typeof N!="object"||Array.isArray(N))continue;let k=N,A=i(k.distance,0,1e4,M===0?0:M*4),S=typeof k.hysteresis=="number"?i(k.hysteresis,0,.5,m):void 0,w=typeof k.ratio=="number"?i(k.ratio,.05,1,.5):void 0,v=typeof k.childIndex=="number"&&Number.isFinite(k.childIndex)?Math.max(0,Math.round(k.childIndex)):void 0,P=typeof k.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(k.node.trim())?k.node.trim().slice(0,64):void 0;y.push({distance:A,...S!==void 0?{hysteresis:S}:{},...w!==void 0?{ratio:w}:{},...v!==void 0?{childIndex:v}:{},...P?{node:P}:{}})}y.sort((M,N)=>M.distance-N.distance),y.length>0&&y[0].distance>0&&y.unshift({distance:0,childIndex:0});let T=0;y=y.slice(0,8).map((M,N)=>{let k=N===0?0:Math.max(T,M.distance);return T=k,{...M,distance:k,childIndex:M.childIndex??N}})}if(Array.isArray(p.ratios)&&p.ratios.length>0){let $=[];for(let T of p.ratios.slice(0,7))typeof T=="number"&&$.push(i(T,.05,1,.5));$.length>0&&(z=$)}if(y.length===0){let $=Array.isArray(p.distances)?p.distances:[],T=[];for(let N of $.slice(0,8))typeof N=="number"&&T.push(i(N,0,1e4,4));if(T.length===0&&z&&z.length>0)for(let N=0;N<z.length;N++)T.push((N+1)*4);if(T.length===0&&p.cullDistance===void 0)return null;T.length===0||T[0]>0?T.unshift(0):z&&z.length===T.length&&z[0]===1&&(z=z.slice(1));let M=0;for(let N=0;N<Math.min(8,T.length);N++){let k=N===0?0:Math.max(M,T[N]);M=k;let A=N>0&&z?z[N-1]:void 0;y.push({distance:k,childIndex:N,...A!==void 0?{ratio:A}:{}})}}else if(!z){let $=[];for(let T=1;T<y.length;T++)typeof y[T].ratio=="number"&&$.push(y[T].ratio);$.length>0&&(z=$)}let E=y.map($=>$.distance),_=E[E.length-1]??0,b=p.cullDistance!==void 0&&p.cullDistance!==null&&p.cullDistance!==!1?i(p.cullDistance,Math.max(1,_),1e4,100):void 0;return{levels:y,distances:E,...z?{ratios:z}:{},hysteresis:m,...b!==void 0?{cullDistance:b}:{}}}function a(d,p){let m=d?.attributes?.position;if(!m||!m.array||m.count<3)return d;let y=i(p,.05,1,.5),z=m.array,E=m.count,_=d.attributes?.normal?.array,b=d.attributes?.uv?.array,$=d.index?.array,T=Math.floor(($?$.length:E)/3);if(T<1)return d;let M=Math.max(1,Math.min(T,Math.round(T*y))),N=1/0,k=1/0,A=1/0,S=-1/0,w=-1/0,v=-1/0;for(let ae=0;ae<E;ae++){let be=z[ae*3],Ne=z[ae*3+1],De=z[ae*3+2];be<N&&(N=be),Ne<k&&(k=Ne),De<A&&(A=De),be>S&&(S=be),Ne>w&&(w=Ne),De>v&&(v=De)}let P=Math.max(1e-5,S-N),H=Math.max(1e-5,w-k),G=Math.max(1e-5,v-A),x=Math.max(P,H,G),V=ae=>{let be=Math.max(1,Math.round(P/x*ae)),Ne=Math.max(1,Math.round(H/x*ae)),De=Math.max(1,Math.round(G/x*ae)),Be=new Map,je=new Int32Array(E),Ve=[],Ie=[],Me=[],ze=[];for(let O=0;O<E;O++){let K=z[O*3],ie=z[O*3+1],he=z[O*3+2],ue=Math.min(be-1,Math.max(0,Math.floor((K-N)/P*be))),ge=Math.min(Ne-1,Math.max(0,Math.floor((ie-k)/H*Ne))),oe=Math.min(De-1,Math.max(0,Math.floor((he-A)/G*De))),_e=ue+ge*be+oe*be*Ne,fe=Be.get(_e);fe===void 0?(fe=ze.length,Be.set(_e,fe),Ve.push(K,ie,he),_&&Ie.push(_[O*3],_[O*3+1],_[O*3+2]),b&&Me.push(b[O*2],b[O*2+1]),ze.push(1)):(Ve[fe*3]+=K,Ve[fe*3+1]+=ie,Ve[fe*3+2]+=he,_&&(Ie[fe*3]+=_[O*3],Ie[fe*3+1]+=_[O*3+1],Ie[fe*3+2]+=_[O*3+2]),ze[fe]++),je[O]=fe}let Se=[],He=new Set;for(let O=0;O<T;O++){let K=$?$[O*3]:O*3,ie=$?$[O*3+1]:O*3+1,he=$?$[O*3+2]:O*3+2,ue=je[K],ge=je[ie],oe=je[he];if(ue===ge||ge===oe||oe===ue)continue;let _e=Math.min(ue,ge,oe),fe=Math.max(ue,ge,oe),ye=ue+ge+oe-_e-fe,Ae=`${_e}_${ye}_${fe}`;He.has(Ae)||(He.add(Ae),Se.push(ue,ge,oe))}let J=ze.length,j=new Float32Array(J*3),I=_?new Float32Array(J*3):null;for(let O=0;O<J;O++){let K=1/ze[O];if(j[O*3]=Ve[O*3]*K,j[O*3+1]=Ve[O*3+1]*K,j[O*3+2]=Ve[O*3+2]*K,I){let ie=Ie[O*3],he=Ie[O*3+1],ue=Ie[O*3+2],ge=Math.hypot(ie,he,ue)||1;I[O*3]=ie/ge,I[O*3+1]=he/ge,I[O*3+2]=ue/ge}}return{pos:j,norm:I,uv:b?new Float32Array(Me):null,tris:Se,triCount:Se.length/3,vertCount:J}},Y=Math.max(2,Math.round(Math.sqrt(M/4))),Z=V(Y);if(Z.triCount>M*1.25&&Y>2){let ae=Math.max(2,Math.round(Y*Math.sqrt(M/Z.triCount)));if(ae!==Y){let be=V(ae);be.triCount>=Math.min(4,M)&&(Z=be)}}else if(Z.triCount<Math.min(4,M)){let ae=V(Math.max(Y*2,8));ae.triCount>Z.triCount&&(Z=ae)}let q=Z.tris;if(y<1&&Z.triCount>M){let ae=[],be=Z.triCount/M;for(let Ne=0;Ne<M;Ne++){let De=Math.min(Z.triCount-1,Math.floor(Ne*be));ae.push(Z.tris[De*3],Z.tris[De*3+1],Z.tris[De*3+2])}q=ae}if(q.length<3){q=[];for(let ae=0;ae<M*3;ae++)q.push($?$[ae]:ae);Z={pos:z.slice(),norm:_?_.slice():null,uv:b?b.slice():null,tris:q,triCount:M,vertCount:E}}let X=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),F=X?.BufferGeometry??d.constructor,Q=X?.BufferAttribute??m.constructor,L=new F;L.setAttribute("position",new Q(Z.pos,3)),Z.norm&&L.setAttribute("normal",new Q(Z.norm,3)),Z.uv&&L.setAttribute("uv",new Q(Z.uv,2));let ee=Z.vertCount>65535?new Uint32Array(q):new Uint16Array(q);return typeof L.setIndex=="function"?L.setIndex(new Q(ee,1)):L.index=new Q(ee,1),L}let f=t?.Object3D??e?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...d){for(let p of d)p&&(p.parent=this,this.children.push(p));return this}};class c extends f{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(p,m=0,y=.05){if(!p)return this;let z=Math.max(0,Number.isFinite(Number(m))?Number(m):0),E=i(y,0,.5,.05),_=this.levels.length;for(let T=0;T<this.levels.length;T++)if(z<this.levels[T].distance){_=T;break}this.levels.splice(_,0,{object:p,distance:z,hysteresis:E}),this.add(p);let b=this.levels.map(T=>T.object),$=this.children.filter(T=>!b.includes(T));this.children=[...b,...$];for(let T=0;T<this.levels.length;T++)this.levels[T].object.visible=T===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(p){if(!this.levels.length)return null;let m=r(this.levels.map(y=>y.distance),p,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return m>=0&&m<this.levels.length?this.levels[m].object:null}update(p){if(this.levels.length===0||!p)return;let m=p.position??{x:0,y:0,z:0},y=this.position??{x:0,y:0,z:0},z=Math.hypot((Number(m.x)||0)-(Number(y.x)||0),(Number(m.y)||0)-(Number(y.y)||0),(Number(m.z)||0)-(Number(y.z)||0)),E=r(this.levels.map(_=>_.distance),z,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=E;for(let _=0;_<this.levels.length;_++)this.levels[_].object.visible=_===E}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let p=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((m,y)=>({distance:m.distance,hysteresis:m.hysteresis,childIndex:y,...m.object?.name?{node:m.object.name}:{}})),distances:this.levels.map(m=>m.distance),hysteresis:this.levels[0]?.hysteresis??.05,...p!==void 0?{cullDistance:p}:{}}}}function h(d){if(!d||d._lodMaterialized||!d.userData?.xr?.lod||d.isLOD||Array.isArray(d.children)&&d.children.length>0)return;let p=d.geometry?.attributes?.position;if(!p||!p.array||p.count<3)return;let m=s(d.userData.xr.lod);if(!m||m.levels.length<2)return;d._lodMaterialized=!0;let y=d.geometry;d._lodOriginalGeometry=y;let z=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),E=z?.Mesh??d.constructor,_=z?.BufferGeometry??y.constructor,b=typeof d.name=="string"&&d.name.trim()?d.name.trim():"Mesh",$=new E(y,d.material);$.name=`${b}_LOD0`,$.visible=!0,$.castShadow=!!d.castShadow,$.receiveShadow=!!d.receiveShadow,d.add($);for(let T=1;T<m.levels.length;T++){let M=m.levels[T].ratio??m.ratios?.[T-1]??Math.max(.05,Math.pow(.5,T)),N=a(y,M),k=new E(N,d.material);k.name=`${b}_LOD${T}`,k.visible=!1,k.castShadow=!!d.castShadow,k.receiveShadow=!!d.receiveShadow,d.add(k)}d.geometry=new _,d.userData.xr.lod={...m,levels:m.levels.map((T,M)=>({...T,childIndex:M,node:`${b}_LOD${M}`}))}}let C={LOD:c,decimateGeometry:a,selectLodLevelIndex:r,parseLod:s,materializeLodGeometry:h};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,{LOD:c,decimateGeometry:a}),e._lodMaterialize=h,e.materializeDeclarativeGeometry=d=>{e._cadMaterialize?.(d),e._lodMaterialize?.(d),e._procMaterialize?.(d)}),C}var er=ts(),eu=er.decimateGeometry,tu=er.selectLodLevelIndex,iu=er.parseLod,ru=er.materializeLodGeometry,nu=er.LOD;function Ao(t,e){if(!t||!t.Vector3||!t.BufferGeometry)return null;let i=t.Vector3,r=t.Matrix4,s=t.BufferGeometry;if(typeof i.prototype.distanceToSquared!="function"&&(i.prototype.distanceToSquared=function(u){let n=this.x-Number(u?.x??0),o=this.y-Number(u?.y??0),l=this.z-Number(u?.z??0);return n*n+o*o+l*l}),typeof i.prototype.addScalar!="function"&&(i.prototype.addScalar=function(u){let n=Number(u)||0;return this.set(this.x+n,this.y+n,this.z+n)}),typeof i.prototype.applyQuaternion!="function"&&(i.prototype.applyQuaternion=function(u){let n=this.x,o=this.y,l=this.z,g=Number(u?.x)||0,D=Number(u?.y)||0,R=Number(u?.z)||0,U=u?.w===void 0?1:Number(u.w)||0,B=2*(D*l-R*o),W=2*(R*n-g*l),ne=2*(g*o-D*n);return this.set(n+U*B+(D*ne-R*W),o+U*W+(R*B-g*ne),l+U*ne+(g*W-D*B))}),typeof i.prototype.min!="function"&&(i.prototype.min=function(u){return this.set(Math.min(this.x,u.x),Math.min(this.y,u.y),Math.min(this.z,u.z))}),typeof i.prototype.max!="function"&&(i.prototype.max=function(u){return this.set(Math.max(this.x,u.x),Math.max(this.y,u.y),Math.max(this.z,u.z))}),typeof i.prototype.clamp!="function"&&(i.prototype.clamp=function(u,n){return this.set(Math.max(u.x,Math.min(n.x,this.x)),Math.max(u.y,Math.min(n.y,this.y)),Math.max(u.z,Math.min(n.z,this.z)))}),typeof i.prototype.clampScalar!="function"&&(i.prototype.clampScalar=function(u,n){return this.set(Math.max(u,Math.min(n,this.x)),Math.max(u,Math.min(n,this.y)),Math.max(u,Math.min(n,this.z)))}),typeof i.prototype.negate!="function"&&(i.prototype.negate=function(){return this.multiplyScalar(-1)}),typeof i.prototype.equals!="function"&&(i.prototype.equals=function(u){return!!u&&u.x===this.x&&u.y===this.y&&u.z===this.z}),r&&typeof r.prototype.getMaxScaleOnAxis!="function"&&(r.prototype.getMaxScaleOnAxis=function(){let u=this.elements;return Math.sqrt(Math.max(u[0]*u[0]+u[1]*u[1]+u[2]*u[2],u[4]*u[4]+u[5]*u[5]+u[6]*u[6],u[8]*u[8]+u[9]*u[9]+u[10]*u[10]))}),t.MathUtils&&typeof t.MathUtils=="object"){let u=1234567;try{typeof t.MathUtils.seededRandom!="function"&&(t.MathUtils.seededRandom=n=>{n!==void 0&&(u=Number.isFinite(n)?n|0:0);let o=u=u+1831565813|0;return o=Math.imul(o^o>>>15,o|1),o^=o+Math.imul(o^o>>>7,o|61),((o^o>>>14)>>>0)/4294967296}),typeof t.MathUtils.randInt!="function"&&(t.MathUtils.randInt=(n,o)=>n+Math.floor(Math.random()*(o-n+1))),typeof t.MathUtils.randFloatSpread!="function"&&(t.MathUtils.randFloatSpread=n=>n*(.5-Math.random()))}catch{}}class a{constructor(n,o){this.isBox3=!0,this.min=n!=null?new i(n.x,n.y,n.z):new i(1/0,1/0,1/0),this.max=o!=null?new i(o.x,o.y,o.z):new i(-1/0,-1/0,-1/0)}set(n,o){return this.min.copy(n),this.max.copy(o),this}makeEmpty(){return this.min.set(1/0,1/0,1/0),this.max.set(-1/0,-1/0,-1/0),this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}clone(){return new a(this.min,this.max)}copy(n){return n?(this.min.copy(n.min),this.max.copy(n.max),this):this}expandByPoint(n){if(!n)return this;let o=Number(n.x),l=Number(n.y),g=n.z===void 0?0:Number(n.z);return!Number.isFinite(o)||!Number.isFinite(l)||!Number.isFinite(g)?this:(o<this.min.x&&(this.min.x=o),l<this.min.y&&(this.min.y=l),g<this.min.z&&(this.min.z=g),o>this.max.x&&(this.max.x=o),l>this.max.y&&(this.max.y=l),g>this.max.z&&(this.max.z=g),this)}expandByVector(n){if(this.isEmpty()||!n)return this;let o=Number(n.x),l=Number(n.y),g=Number(n.z);return!Number.isFinite(o)||!Number.isFinite(l)||!Number.isFinite(g)?this:(this.min.set(this.min.x-o,this.min.y-l,this.min.z-g),this.max.set(this.max.x+o,this.max.y+l,this.max.z+g),this.isEmpty()&&this.makeEmpty(),this)}expandByScalar(n){let o=Number(n);return this.isEmpty()||!Number.isFinite(o)?this:(this.min.set(this.min.x-o,this.min.y-o,this.min.z-o),this.max.set(this.max.x+o,this.max.y+o,this.max.z+o),this.isEmpty()&&this.makeEmpty(),this)}setFromArray(n){if(this.makeEmpty(),!n)return this;for(let o=0,l=n.length-2;o<l;o+=3)this.expandByPoint({x:n[o],y:n[o+1],z:n[o+2]});return this}setFromBufferAttribute(n){if(this.makeEmpty(),!n||typeof n.count!="number")return this;for(let o=0;o<n.count;o++)this.expandByPoint({x:n.getX(o),y:n.getY(o),z:n.getZ(o)});return this}setFromPoints(n){if(this.makeEmpty(),Array.isArray(n))for(let o of n)this.expandByPoint(o);return this}setFromCenterAndSize(n,o){if(!n||!o)return this;let l=Math.abs(Number(o.x)||0)*.5,g=Math.abs(Number(o.y)||0)*.5,D=Math.abs(Number(o.z)||0)*.5,R=Number(n.x)||0,U=Number(n.y)||0,B=Number(n.z)||0;return this.min.set(R-l,U-g,B-D),this.max.set(R+l,U+g,B+D),this}setFromObject(n,o){return this.makeEmpty().expandByObject(n,!!o)}expandByObject(n,o){return f(this,n,!!o),this}getCenter(n=new i){return this.isEmpty()?n.set(0,0,0):n.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(n=new i){return this.isEmpty()?n.set(0,0,0):n.subVectors(this.max,this.min)}getParameter(n,o=new i){let l=this.max.x-this.min.x,g=this.max.y-this.min.y,D=this.max.z-this.min.z;return o.set(l!==0?(n.x-this.min.x)/l:0,g!==0?(n.y-this.min.y)/g:0,D!==0?(n.z-this.min.z)/D:0)}containsPoint(n){return!!n&&!this.isEmpty()&&n.x>=this.min.x&&n.x<=this.max.x&&n.y>=this.min.y&&n.y<=this.max.y&&n.z>=this.min.z&&n.z<=this.max.z}containsBox(n){return!!n&&this.min.x<=n.min.x&&n.max.x<=this.max.x&&this.min.y<=n.min.y&&n.max.y<=this.max.y&&this.min.z<=n.min.z&&n.max.z<=this.max.z}intersectsBox(n){return!!n&&n.max.x>=this.min.x&&n.min.x<=this.max.x&&n.max.y>=this.min.y&&n.min.y<=this.max.y&&n.max.z>=this.min.z&&n.min.z<=this.max.z}intersectsSphere(n){return!n||this.isEmpty()||n.isEmpty()?!1:this.clampPoint(n.center,new i).distanceToSquared(n.center)<=n.radius*n.radius}intersectsPlane(n){if(!n?.normal||this.isEmpty())return!1;let o=n.normal.x,l=n.normal.y,g=n.normal.z,D=Number(n.constant)||0,R=(o>0?o*this.min.x:o*this.max.x)+(l>0?l*this.min.y:l*this.max.y)+(g>0?g*this.min.z:g*this.max.z),U=(o>0?o*this.max.x:o*this.min.x)+(l>0?l*this.max.y:l*this.min.y)+(g>0?g*this.max.z:g*this.min.z);return R<=-D&&U>=-D}clampPoint(n,o=new i){return this.isEmpty()?o.copy(n):o.copy(n).clamp(this.min,this.max)}distanceToPoint(n){return this.isEmpty()?1/0:this.clampPoint(n,new i).distanceTo(n)}getBoundingSphere(n=new c){return this.isEmpty()?n.makeEmpty():(this.getCenter(n.center),n.radius=this.getSize(new i).length()*.5,n)}intersect(n){return n?(this.min.max(n.min),this.max.min(n.max),this.isEmpty()&&this.makeEmpty(),this):this}union(n){return!n||n.isEmpty()?this:this.isEmpty()?this.copy(n):(this.min.min(n.min),this.max.max(n.max),this)}applyMatrix4(n){if(this.isEmpty()||!n)return this;let o=this.min.x,l=this.min.y,g=this.min.z,D=this.max.x,R=this.max.y,U=this.max.z,B=new i;this.makeEmpty();for(let W=0;W<8;W++)B.set(W&1?D:o,W&2?R:l,W&4?U:g).applyMatrix4(n),this.expandByPoint(B);return this}translate(n){return this.isEmpty()||!n?this:(this.min.add(n),this.max.add(n),this)}equals(n){return!!n&&n.min.equals(this.min)&&n.max.equals(this.max)}}function f(u,n,o){if(!n)return;n.updateMatrixWorld?.(!0);let l=new i,g=new a,D=new r,R=new r,U=new Set,B=new Map,W=(re,te)=>{let se=re?.attributes?.position;if(!(!se||!(se.count>0)))if(o)for(let le=0;le<se.count;le++)l.set(se.getX(le),se.getY(le),se.getZ(le)).applyMatrix4(te),u.expandByPoint(l);else{let le=B.get(re);le||(le=new a().setFromBufferAttribute(se),B.set(re,le)),le.isEmpty()||u.union(g.copy(le).applyMatrix4(te))}},ne=re=>{if(!re||typeof re!="object"||U.has(re)||(U.add(re),e?.materializeDeclarativeGeometry?.(re),re.isBoxHelper&&re!==n))return;(re.isSprite||re.isBox3Helper)&&re._bakeAuthorGeometry?.();let te=re._sourceGeo||re.geometry;if(te&&te.attributes?.position&&re.matrixWorld)if(re.isInstancedMesh&&typeof re.getMatrixAt=="function"){let se=Math.floor((re.instanceMatrix?.array?.length??0)/16),le=Math.min(Math.max(0,Math.floor(Number(re.count)||0)),se);for(let pe=0;pe<le;pe++)re.getMatrixAt(pe,D),R.multiplyMatrices(re.matrixWorld,D),W(te,R)}else W(te,re.matrixWorld);if(Array.isArray(re.children))for(let se of re.children)ne(se)};ne(n)}class c{constructor(n,o=-1){this.isSphere=!0,this.center=n!=null?new i(n.x,n.y,n.z):new i;let l=Number(o);this.radius=Number.isFinite(l)?l:-1}set(n,o){n&&this.center.copy(n);let l=Number(o);return this.radius=Number.isFinite(l)?l:-1,this}setFromPoints(n,o){if(!Array.isArray(n)||n.length===0)return this.makeEmpty();if(o)this.center.copy(o);else{let R=new a().setFromPoints(n);if(R.isEmpty())return this.makeEmpty();R.getCenter(this.center)}let l=0,g=!1,D=new i;for(let R of n){let U=Number(R?.x),B=Number(R?.y),W=R?.z===void 0?0:Number(R.z);Number.isFinite(U)&&Number.isFinite(B)&&Number.isFinite(W)&&(g=!0,l=Math.max(l,this.center.distanceToSquared(D.set(U,B,W))))}return g?(this.radius=Math.sqrt(l),this):this.makeEmpty()}copy(n){return n?(this.center.copy(n.center),this.radius=n.radius,this):this}clone(){return new c(this.center,this.radius)}isEmpty(){return!(this.radius>=0)||!Number.isFinite(this.radius)}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(n){return!!n&&!this.isEmpty()&&n.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(n){return this.isEmpty()?1/0:n.distanceTo(this.center)-this.radius}intersectsSphere(n){if(!n||this.isEmpty()||n.isEmpty())return!1;let o=this.radius+n.radius;return n.center.distanceToSquared(this.center)<=o*o}intersectsBox(n){return!!n&&n.intersectsSphere(this)}intersectsPlane(n){if(!n?.normal||this.isEmpty())return!1;let o=n.normal.dot(this.center)+(Number(n.constant)||0);return Math.abs(o)<=this.radius}clampPoint(n,o=new i){return o.copy(n),this.isEmpty()||this.center.distanceToSquared(n)>this.radius*this.radius&&o.sub(this.center).normalize().multiplyScalar(this.radius).add(this.center),o}getBoundingBox(n=new a){return this.isEmpty()?n.makeEmpty():(n.set(this.center,this.center),n.expandByScalar(this.radius),n)}applyMatrix4(n){if(this.isEmpty()||!n)return this;let o=n.getMaxScaleOnAxis();return Number.isFinite(o)?(this.center.applyMatrix4(n),this.radius*=o,this):this.makeEmpty()}translate(n){return!this.isEmpty()&&n&&this.center.add(n),this}expandByPoint(n){if(!n||!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Number.isFinite(n.z))return this;if(this.isEmpty())return this.center.copy(n),this.radius=0,this;let o=this.center.distanceToSquared(n);if(o>this.radius*this.radius){let l=Math.sqrt(o),g=(this.radius+l)*.5;this.center.addScaledVector(new i().subVectors(n,this.center),(l-this.radius)/(2*l)),this.radius=g}return this}union(n){if(!n||n.isEmpty())return this;if(this.isEmpty())return this.copy(n);if(this.center.equals(n.center))return this.radius=Math.max(this.radius,n.radius),this;let o=new i().subVectors(n.center,this.center),l=o.length();if(l+n.radius<=this.radius)return this;if(l+this.radius<=n.radius)return this.copy(n);let g=(this.radius+l+n.radius)*.5;return this.center.addScaledVector(o,(g-this.radius)/l),this.radius=g,this}equals(n){return!!n&&n.center.equals(this.center)&&n.radius===this.radius}}s.prototype.computeBoundingSphere=function(){(!this.boundingSphere||!this.boundingSphere.isSphere)&&(this.boundingSphere=new c);let u=this.attributes?.position;if(!u||!(u.count>0))return this.boundingSphere.makeEmpty();let n=new a().setFromBufferAttribute(u);if(n.isEmpty())return this.boundingSphere.makeEmpty();let o=n.getCenter(this.boundingSphere.center),l=0,g=new i;for(let D=0;D<u.count;D++){let R=u.getX(D),U=u.getY(D),B=u.getZ(D);Number.isFinite(R)&&Number.isFinite(U)&&Number.isFinite(B)&&(l=Math.max(l,o.distanceToSquared(g.set(R,U,B))))}return this.boundingSphere.radius=Math.sqrt(l),this.boundingSphere},s.prototype.computeBoundingBox=function(){(!this.boundingBox||!this.boundingBox.isBox3)&&(this.boundingBox=new a);let u=this.attributes?.position;return u&&u.count>0?this.boundingBox.setFromBufferAttribute(u):this.boundingBox.makeEmpty(),this.boundingSphere&&this.computeBoundingSphere(),this.boundingBox};let h="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",C=512,d=2048,p=16384,m=256,y="AAAAAAAAAF8AAAAHAAcAFH8UfxQkKn8qEiMTCGRiNklVIlAABQMAAAAcIkEAAEEiHAAUCD4IFAgIPggIAFAwAAAICAgICABgYAAAIBAIBAI+UUlFPgBCf0AAQmFRSUYhQUVLMRgUEn8QJ0VFRTk8SklJMAFxCQUDNklJSTYGSUkpHgA2NgAAAFY2AAAIFCJBABQUFBQUAEEiFAgCAVEJBjJJeUE+fhEREX5/SUlJNj5BQUEif0FBIhx/SUlJQX8JCQkBPkFJSXp/CAgIfwBBf0EAIEBBPwF/CBQiQX9AQEBAfwIMAn9/BAgQfz5BQUE+fwkJCQY+QVEhXn8JGSlGRklJSTEBAX8BAT9AQEA/HyBAIB8/QDhAP2MUCBRjBwhwCAdhUUlFQwB/QUEAAgQIECAAQUF/AAQCAQIEQEBAQEAAAQIEACBUVFR4f0hERDg4REREIDhEREh/OFRUVBgIfgkBAgxSUlI+fwgEBHgARH1AACBARD0AfxAoRAAAQX9AAHwEGAR4fAgEBHg4REREOHwUFBQICBQUGHx8CAQECEhUVFQgBD9EQCA8QEAgfBwgQCAcPEAwQDxEKBAoRAxQUFA8RGRUTEQACDZBAAAAfwAAAEE2CAAIBAgQCA==",z=new Int16Array(128).fill(-1);for(let u=0;u<64;u++)z[h.charCodeAt(u)]=u;let E=(()=>{let u=new Uint8Array(475),n=0,o=0,l=0;for(let g=0;g<y.length&&l<475;g++){let D=y.charCodeAt(g);if(D===61)break;let R=D<128?z[D]:-1;R<0||(n=n<<6|R,o+=6,o>=8&&(o-=8,u[l++]=n>>o&255))}return u})(),_=(()=>{let u=new Uint32Array(256);for(let n=0;n<256;n++){let o=n;for(let l=0;l<8;l++)o=o&1?3988292384^o>>>1:o>>>1;u[n]=o>>>0}return u})(),b=u=>{let n=4294967295;for(let o=0;o<u.length;o++)n=_[(n^u[o])&255]^n>>>8;return(n^4294967295)>>>0},$=(()=>{let u=new Float32Array(256);for(let n=0;n<256;n++){let o=n/255;u[n]=o<=.04045?o/12.92:Math.pow((o+.055)/1.055,2.4)}return u})(),T=typeof globalThis<"u"?globalThis.__three_live_native_encode_rgba_png__:void 0,M={};for(let u of"black:000000,white:ffffff,red:ff0000,lime:00ff00,green:008000,blue:0000ff,yellow:ffff00,cyan:00ffff,aqua:00ffff,magenta:ff00ff,fuchsia:ff00ff,silver:c0c0c0,gray:808080,grey:808080,darkgray:a9a9a9,darkgrey:a9a9a9,dimgray:696969,dimgrey:696969,lightgray:d3d3d3,lightgrey:d3d3d3,slategray:708090,slategrey:708090,darkslategray:2f4f4f,darkslategrey:2f4f4f,maroon:800000,olive:808000,purple:800080,teal:008080,navy:000080,orange:ffa500,orangered:ff4500,gold:ffd700,coral:ff7f50,salmon:fa8072,tomato:ff6347,crimson:dc143c,pink:ffc0cb,hotpink:ff69b4,deeppink:ff1493,indigo:4b0082,violet:ee82ee,plum:dda0dd,orchid:da70d6,brown:a52a2a,saddlebrown:8b4513,sienna:a0522d,chocolate:d2691e,peru:cd853f,tan:d2b48c,wheat:f5deb3,beige:f5f5dc,ivory:fffff0,linen:faf0e6,snow:fffafa,khaki:f0e68c,skyblue:87ceeb,deepskyblue:00bfff,dodgerblue:1e90ff,royalblue:4169e1,steelblue:4682b4,turquoise:40e0d0,aquamarine:7fffd4,chartreuse:7fff00,forestgreen:228b22,seagreen:2e8b57".split(",")){let[n,o]=u.split(":");M[n]=parseInt(o,16)}let N=u=>u>0?u<255?u+.5|0:255:0,k=u=>{let n=u.trim();return n.endsWith("%")?N(parseFloat(n)*255/100):N(parseFloat(n))},A=u=>{if(!u)return 255;let n=u.trim();if(!n)return 255;let o=n.endsWith("%")?parseFloat(n)/100:parseFloat(n);return Number.isFinite(o)?N(Math.max(0,Math.min(1,o))*255):255},S=(u,n=[0,0,0,255])=>{if(typeof u!="string")return n;let o=u.trim().toLowerCase();if(!o)return n;if(o==="transparent")return[0,0,0,0];if(o.charCodeAt(0)===35){let pe=o.slice(1);if(pe.length===3||pe.length===4){let me=parseInt(pe[0]+pe[0],16),xe=parseInt(pe[1]+pe[1],16),de=parseInt(pe[2]+pe[2],16),ce=pe.length===4?parseInt(pe[3]+pe[3],16):255;if(Number.isFinite(me+xe+de+ce))return[me,xe,de,ce]}else if(pe.length===6||pe.length===8){let me=parseInt(pe.slice(0,2),16),xe=parseInt(pe.slice(2,4),16),de=parseInt(pe.slice(4,6),16),ce=pe.length===8?parseInt(pe.slice(6,8),16):255;if(Number.isFinite(me+xe+de+ce))return[me,xe,de,ce]}return n}let l=M[o];if(l!==void 0)return[l>>16&255,l>>8&255,l&255,255];let g=/^(rgba?|hsla?)\(([^)]+)\)$/.exec(o);if(!g)return n;let D=g[1],R=g[2].replace(/\//g," ").split(/[\s,]+/).filter(Boolean);if(R.length<3)return n;if(D.startsWith("rgb"))return[k(R[0]),k(R[1]),k(R[2]),A(R[3])];let U=parseFloat(R[0]);if(!Number.isFinite(U))return n;R[0].endsWith("turn")?U*=360:R[0].endsWith("rad")&&(U=U*180/Math.PI);let B=(U%360+360)%360/360,W=Math.max(0,Math.min(1,(parseFloat(R[1])||0)/100)),ne=Math.max(0,Math.min(1,(parseFloat(R[2])||0)/100)),re=A(R[3]);if(W===0){let pe=N(ne*255);return[pe,pe,pe,re]}let te=ne<.5?ne*(1+W):ne+W-ne*W,se=2*ne-te,le=pe=>{let me=pe;return me<0&&(me+=1),me>1&&(me-=1),me<1/6?se+(te-se)*6*me:me<1/2?te:me<2/3?se+(te-se)*(2/3-me)*6:se};return[N(le(B+1/3)*255),N(le(B)*255),N(le(B-1/3)*255),re]},w=(u,n,o,l,g,D=C)=>{if(!u||n<=0||o<=0||u.length<n*o*4)return{uri:"",avgColor:[1,1,1,1]};if(typeof T=="function"){let Ue=T(u,n,o,l,g,D);if(Array.isArray(Ue)&&typeof Ue[0]=="string")return{uri:Ue[0],avgColor:[Ue[1],Ue[2],Ue[3],Ue[4]]}}let R=n>D||o>D?D/Math.max(n,o):1,U=Math.max(1,Math.round(n*R)),B=Math.max(1,Math.round(o*R)),W=1+U*4,ne=B*W,re=2+Math.max(1,Math.ceil(ne/65535))*5+ne+4,te=new Uint8Array(57+re),se=new DataView(te.buffer);se.setUint32(0,2303741511),se.setUint32(4,218765834),se.setUint32(8,13),se.setUint32(12,1229472850),se.setUint32(16,U),se.setUint32(20,B),te[24]=8,te[25]=6,se.setUint32(29,b(te.subarray(12,29))),se.setUint32(33,re),se.setUint32(37,1229209940),te[41]=120,te[42]=1;let le=new Uint8Array(ne),pe=0,me=1,xe=0,de=0,ce=0,we=0,Te=0,Ee=U===n&&B===o;for(let Ue=0;Ue<B;Ue++){le[pe++]=0,xe=(xe+me)%65521;let Ye=l?B-1-Ue:Ue,it=Ee?Ye:Math.floor(Ye*o/B),dt=Ee?Ye+1:Math.max(it+1,Math.floor((Ye+1)*o/B));for(let ct=0;ct<U;ct++){let ot=0,gt=0,vt=0,ft=0;if(Ee){let pt=(it*n+ct)*4;ot=u[pt]|0,gt=u[pt+1]|0,vt=u[pt+2]|0,ft=u[pt+3]|0}else{let pt=Math.floor(ct*n/U),kt=Math.max(pt+1,Math.floor((ct+1)*n/U)),_t=0;for(let Ft=it;Ft<dt&&Ft<o;Ft++)for(let At=pt;At<kt&&At<n;At++){let Ot=(Ft*n+At)*4;ot+=u[Ot]|0,gt+=u[Ot+1]|0,vt+=u[Ot+2]|0,ft+=u[Ot+3]|0,_t++}_t>1&&(ot=ot/_t+.5|0,gt=gt/_t+.5|0,vt=vt/_t+.5|0,ft=ft/_t+.5|0)}le[pe++]=ot,me+=ot,xe+=me,le[pe++]=gt,me+=gt,xe+=me,le[pe++]=vt,me+=vt,xe+=me,le[pe++]=ft,me+=ft,xe+=me,de+=g?ot/255:$[ot],ce+=g?gt/255:$[gt],we+=g?vt/255:$[vt],Te+=ft/255}me%=65521,xe%=65521}let Re=43,We=ne,Xe=0;for(;We>0||Xe===0;){let Ue=Math.min(65535,We),Ye=We-Ue===0?1:0;if(te[Re++]=Ye,se.setUint16(Re,Ue,!0),se.setUint16(Re+2,~Ue&65535,!0),Re+=4,Ue>0&&(te.set(le.subarray(Xe,Xe+Ue),Re),Re+=Ue,Xe+=Ue,We-=Ue),Ye)break}se.setUint32(Re,(xe<<16|me)>>>0),Re+=4,se.setUint32(Re,b(te.subarray(37,Re))),Re+=4,se.setUint32(Re,0),se.setUint32(Re+4,1229278788),se.setUint32(Re+8,2923585666);let et=Math.max(1,U*B),Ze=[de/et,ce/et,we/et,Te/et],tt=["data:image/png;base64,"];for(let Ue=0;Ue<te.length;Ue+=3){let Ye=te[Ue]<<16|(te[Ue+1]??0)<<8|(te[Ue+2]??0);tt.push(h[Ye>>18&63]+h[Ye>>12&63]+(Ue+1<te.length?h[Ye>>6&63]:"=")+(Ue+2<te.length?h[Ye&63]:"="))}return{uri:tt.join(""),avgColor:Ze}},v=(u,n,o,l)=>(u&255|(n&255)<<8|(o&255)<<16|(l&255)<<24)>>>0,P=u=>{if(u._lut)return u._lut;let n=new Uint32Array(256),o=u.s;if(o.length===1){let l=o[0].c;n.fill(v(l[0],l[1],l[2],l[3]))}else if(o.length>1){let l=0;for(let g=0;g<256;g++){let D=g/255;if(D<=o[0].o){let R=o[0].c;n[g]=v(R[0],R[1],R[2],R[3])}else if(D>=o[o.length-1].o){let R=o[o.length-1].c;n[g]=v(R[0],R[1],R[2],R[3])}else{for(;l<o.length-2&&D>o[l+1].o;)l++;let R=o[l],U=o[l+1],B=U.o-R.o,W=B>1e-9?(D-R.o)/B:0;n[g]=v(R.c[0]+(U.c[0]-R.c[0])*W+.5|0,R.c[1]+(U.c[1]-R.c[1])*W+.5|0,R.c[2]+(U.c[2]-R.c[2])*W+.5|0,R.c[3]+(U.c[3]-R.c[3])*W+.5|0)}}}return u._lut=n,n},H=(u,n,o)=>{if(u.s.length===0)return 0;let l=P(u),g=0;if(u.rad){let R=u.x1-u.x0,U=u.y1-u.y0,B=u.r1-u.r0,W=n-u.x0,ne=o-u.y0,re=R*R+U*U-B*B,te=-2*(W*R+ne*U+u.r0*B),se=W*W+ne*ne-u.r0*u.r0;if(Math.abs(re)<1e-9)g=Math.abs(te)>1e-9?-se/te:0;else{let le=Math.sqrt(Math.max(0,te*te-4*re*se)),pe=(-te+le)/(2*re),me=(-te-le)/(2*re);g=u.r0+pe*B>=0?pe:u.r0+me*B>=0?me:Math.max(pe,me)}}else{let R=u.x1-u.x0,U=u.y1-u.y0,B=R*R+U*U;if(B<=1e-12)return l[255];g=((n-u.x0)*R+(o-u.y0)*U)/B}let D=g<=0?0:g>=1?255:g*255+.5|0;return l[D]};class G{constructor(n,o,l,g,D,R,U){this._g=1,this.rad=n,this.x0=Number(o)||0,this.y0=Number(l)||0,this.r0=Math.max(0,Number(g)||0),this.x1=Number(D)||0,this.y1=Number(R)||0,this.r1=Math.max(0,Number(U)||0),this.s=[],this._lut=null}addColorStop(n,o){let l=Math.max(0,Math.min(1,Number(n)||0));this.s.push({o:l,c:S(o,[0,0,0,255]),i:this.s.length}),this.s.sort((g,D)=>g.o-D.o||g.i-D.i),this._lut=null}}class x{constructor(n,o,l,g){this._g=2,this.d=n,this.w=Math.max(1,o|0),this.h=Math.max(1,l|0);let D=(g||"repeat").toLowerCase();this.rx=D==="repeat"||D==="repeat-x",this.ry=D==="repeat"||D==="repeat-y"}}let V=(u,n,o)=>{let l=Math.floor(n),g=Math.floor(o);if(u.rx)l=(l%u.w+u.w)%u.w;else if(l<0||l>=u.w)return 0;if(u.ry)g=(g%u.h+u.h)%u.h;else if(g<0||g>=u.h)return 0;let D=(g*u.w+l)*4;return v(u.d[D],u.d[D+1],u.d[D+2],u.d[D+3])},Y=u=>u>=32&&u<=126?u:u===176?39:u===8226||u===183?42:u===8211||u===8212||u===8722?45:u===215?120:u===8216||u===8217?39:u===8220||u===8221?34:63,Z=new Array(190),q=(u,n)=>{let o=(u-32)*2+(n?1:0),l=Z[o];if(l)return l;let g=new Uint8Array(63),D=(u-32)*5;for(let U=0;U<5;U++){let B=E[D+U]??0;for(let W=0;W<7;W++)B>>W&1&&(g[(W+1)*7+(U+1)]=1)}let R=new Uint8Array(140);for(let U=0;U<7;U++)for(let B=0;B<5;B++){let W=(U+1)*7+(B+1),ne=g[W],re=g[W-7],te=g[W+1],se=g[W-1],le=g[W+7],pe=U*2,me=B*2;R[pe*10+me]=se===re&&se!==le&&re!==te?re:ne,R[pe*10+me+1]=re===te&&re!==se&&te!==le?te:ne,R[(pe+1)*10+me]=le===se&&le!==te&&se!==re?se:ne,R[(pe+1)*10+me+1]=te===le&&te!==re&&le!==se?le:ne}if(n)for(let U=0;U<14;U++)for(let B=9;B>=1;B--)R[U*10+B-1]&&(R[U*10+B]=1);return Z[o]=R,R},X=u=>{let n=String(u||"10px sans-serif"),o=/\b(bold|bolder|[6-9]00)\b/i.test(n),l=/(\d+(?:\.\d+)?)\s*(px|pt|em|rem)\b/i.exec(n);if(!l)return{sizePx:10,bold:o};let g=parseFloat(l[1]),D=l[2].toLowerCase();return D==="pt"?g*=4/3:(D==="em"||D==="rem")&&(g*=16),{sizePx:Number.isFinite(g)&&g>0?Math.min(1024,g):10,bold:o}},F=u=>{u.fillStyle="#000000",u.strokeStyle="#000000",u.globalAlpha=1,u.globalCompositeOperation="source-over",u.lineWidth=1,u.lineCap="butt",u.lineJoin="miter",u.lineDashOffset=0,u.font="10px sans-serif",u.textAlign="start",u.textBaseline="alphabetic",u.shadowColor="rgba(0, 0, 0, 0)",u.shadowBlur=0,u.shadowOffsetX=0,u.shadowOffsetY=0,u._m=[1,0,0,1,0,0],u._dash=[],u._clip=null,u._stack=[],u._subs=[],u._cur=null,u._pts=0},Q=(u,n,o)=>{let l=u._m;return[(l[0]*n+l[2]*o+l[4])*u.canvas._sx,(l[1]*n+l[3]*o+l[5])*u.canvas._sy]},L=u=>{let n=u.canvas._sx>0?1/u.canvas._sx:1,o=u.canvas._sy>0?1/u.canvas._sy:1,l=u._m,g=l[0]*l[3]-l[1]*l[2];if(Math.abs(g)<1e-12)return[0,0,0,0,0,0];let D=1/g;return[l[3]*n*D,-l[2]*o*D,(-l[3]*l[4]+l[2]*l[5])*D,-l[1]*n*D,l[0]*o*D,(l[1]*l[4]-l[0]*l[5])*D]},ee=(u,n,o)=>{let[l,g,D,R,U,B]=L(u);return[l*n+g*o+D,R*n+U*o+B]},ae=u=>{let n=String(u.globalCompositeOperation||"source-over").toLowerCase();return n==="source-over"?0:n==="copy"?1:n==="destination-out"?2:n==="lighter"||n==="add"?3:n==="multiply"?4:n==="screen"?5:0},be=(u,n,o)=>{u._pts>=p||!u._cur||(u._cur.pts.push([n,o]),u._pts++)},Ne=(u,n)=>{let o=Number(u.globalAlpha),l=Number.isFinite(o)?Math.max(0,Math.min(1,o)):1,g=Math.round(l*256);if(typeof n=="string"){let U=S(n,[0,0,0,255]),B=v(U[0],U[1],U[2],U[3]*g+128>>8);return()=>B}let D=n?n._g:0;if(D===1||D===2){let[U,B,W,ne,re,te]=L(u);return(se,le)=>{let pe=U*se+B*le+W,me=ne*se+re*le+te,xe=D===1?H(n,pe,me):V(n,pe,me);if(g>=256)return xe;let de=(xe>>>24)*g+128>>8&255;return(xe&16777215|de<<24)>>>0}}let R=v(0,0,0,255*g+128>>8);return()=>R},De=(u,n,o,l,g)=>{let D=u.canvas._bw,R=u.canvas._bh;if(o<0||o>=D||l<0||l>=R)return;let U=l*D+o;if(u._clip&&!u._clip[U])return;let B=u.canvas._data,W=U*4,ne=g&255,re=g>>>8&255,te=g>>>16&255,se=g>>>24;if(n===1){B[W]=ne,B[W+1]=re,B[W+2]=te,B[W+3]=se;return}if(se<=0)return;if(se>=255&&n===0){B[W]=ne,B[W+1]=re,B[W+2]=te,B[W+3]=255;return}if(n===2){B[W+3]=(B[W+3]*(255-se)+127)/255|0,B[W+3]===0&&(B[W]=B[W+1]=B[W+2]=0);return}if(n===3){B[W]=Math.min(255,B[W]+((ne*se+127)/255|0)),B[W+1]=Math.min(255,B[W+1]+((re*se+127)/255|0)),B[W+2]=Math.min(255,B[W+2]+((te*se+127)/255|0)),B[W+3]=Math.min(255,B[W+3]+se);return}let le=B[W+3],pe=se/255,me=le/255,xe=pe+me*(1-pe);if(xe<=1e-6){B[W]=B[W+1]=B[W+2]=B[W+3]=0;return}let de=ne,ce=re,we=te;n===4&&le>0?(de=(de*B[W]+127)/255,ce=(ce*B[W+1]+127)/255,we=(we*B[W+2]+127)/255):n===5&&le>0&&(de=255-(255-de)*(255-B[W])/255,ce=255-(255-ce)*(255-B[W+1])/255,we=255-(255-we)*(255-B[W+2])/255),B[W]=N((de*pe+B[W]*me*(1-pe))/xe),B[W+1]=N((ce*pe+B[W+1]*me*(1-pe))/xe),B[W+2]=N((we*pe+B[W+2]*me*(1-pe))/xe),B[W+3]=N(xe*255)},Be=(u,n,o,l)=>{if(u.canvas.width<=0||u.canvas.height<=0)return;let g=u.canvas._bw,D=u.canvas._bh,R=[],U=D,B=-1;for(let le of n){let pe=le.pts,me=pe.length;if(!(me<2))for(let xe=0;xe<me;xe++){let[de,ce]=pe[xe],[we,Te]=pe[(xe+1)%me];if(ce===Te)continue;let Ee=Math.min(ce,Te),Re=Math.max(ce,Te);R.push([Ee,Re,Te>ce?de:we,(Te>ce?we-de:de-we)/(Re-Ee),Te>ce?1:-1]),Ee<U&&(U=Ee),Re>B&&(B=Re)}}if(R.length===0)return;let W=Math.max(0,Math.floor(U)),ne=Math.min(D-1,Math.ceil(B)),re=o==="evenodd",te=(le,pe,me)=>{for(let xe=pe;xe<=me;xe++)l(xe,le)},se=[];for(let le=W;le<=ne;le++){let pe=le+.5;se.length=0;for(let me=0;me<R.length;me++){let xe=R[me];xe[0]<=pe&&xe[1]>pe&&se.push([xe[2]+(pe-xe[0])*xe[3],xe[4]])}if(!(se.length<2))if(se.sort((me,xe)=>me[0]-xe[0]),re)for(let me=0;me+1<se.length;me+=2)te(le,Math.max(0,Math.ceil(se[me][0]-.5)),Math.min(g-1,Math.floor(se[me+1][0]-.5)));else{let me=0,xe=0;for(let de=0;de<se.length;de++){let ce=me;me+=se[de][1],ce===0&&me!==0?xe=se[de][0]:ce!==0&&me===0&&te(le,Math.max(0,Math.ceil(xe-.5)),Math.min(g-1,Math.floor(se[de][0]-.5)))}}}},je=(u,n,o,l,g,D)=>{if(!Number.isFinite(o+l)||u.canvas.width<=0||u.canvas.height<=0)return;let R=String(n??"").slice(0,1024);if(!R)return;let U=Array.from(R),{sizePx:B,bold:W}=X(u.font),ne=B,re=B*(W?.54:.5),te=B*(W?.64:.6),se=U.length*te-B*.1,le=1;if(g!==void 0&&Number.isFinite(g)){if(g<=0)return;se>g&&se>0&&(le=g/se)}let pe=se*le,me=o;u.textAlign==="center"?me-=pe*.5:(u.textAlign==="right"||u.textAlign==="end")&&(me-=pe);let xe=l,de=u.textBaseline;de==="middle"?xe-=ne*.5:de==="bottom"||de==="ideographic"?xe-=ne:de==="alphabetic"?xe-=ne*.82:de==="hanging"&&(xe-=ne*.08);let ce=Ne(u,D?u.strokeStyle:u.fillStyle),we=ae(u),[Te,Ee,Re,We,Xe,et]=L(u),Ze=u.canvas._bw,tt=u.canvas._bh,Ue=new Uint8Array(Ze*tt),Ye=re*le;if(Ye<=1e-6||ne<=1e-6)return;let it=1/Ye,dt=1/ne;for(let ct=0;ct<U.length;ct++){let ot=Y(U[ct].codePointAt(0)??32);if(ot===32)continue;let gt=me+ct*te*le,vt=q(ot,W),ft=Q(u,gt,xe),pt=Q(u,gt+Ye,xe),kt=Q(u,gt+Ye,xe+ne),_t=Q(u,gt,xe+ne),Ft=Math.max(0,Math.floor(Math.min(ft[0],pt[0],kt[0],_t[0]))),At=Math.min(Ze-1,Math.ceil(Math.max(ft[0],pt[0],kt[0],_t[0]))),Ot=Math.max(0,Math.floor(Math.min(ft[1],pt[1],kt[1],_t[1]))),Xt=Math.min(tt-1,Math.ceil(Math.max(ft[1],pt[1],kt[1],_t[1])));for(let mi=Ot;mi<=Xt;mi++){let ri=mi+.5;for(let Li=Ft;Li<=At;Li++){let Ki=mi*Ze+Li;if(Ue[Ki])continue;let Gi=Li+.5,mr=Te*Gi+Ee*ri+Re,dr=We*Gi+Xe*ri+et,Di=(mr-gt)*it,$i=(dr-xe)*dt;if(Di<0||Di>=1||$i<0||$i>=1)continue;let ni=Math.min(9,Di*10|0),si=Math.min(13,$i*14|0);vt[si*10+ni]===1&&(D&&ni>0&&ni<9&&si>0&&si<13&&vt[si*10+ni-1]&&vt[si*10+ni+1]&&vt[(si-1)*10+ni]&&vt[(si+1)*10+ni]||(Ue[Ki]=1,De(u,we,Li,mi,ce(Gi,ri))))}}}u.canvas._ver++};class Ve{constructor(n){this.canvas=n,F(this)}save(){this._stack.length>=m||this._stack.push([this._m.slice(),this.fillStyle,this.strokeStyle,this.globalAlpha,this.globalCompositeOperation,this.lineWidth,this.lineCap,this.lineJoin,this._dash.slice(),this.lineDashOffset,this.font,this.textAlign,this.textBaseline,this.shadowColor,this.shadowBlur,this.shadowOffsetX,this.shadowOffsetY,this._clip?new Uint8Array(this._clip):null])}restore(){let n=this._stack.pop();n&&([this._m,this.fillStyle,this.strokeStyle,this.globalAlpha,this.globalCompositeOperation,this.lineWidth,this.lineCap,this.lineJoin,this._dash,this.lineDashOffset,this.font,this.textAlign,this.textBaseline,this.shadowColor,this.shadowBlur,this.shadowOffsetX,this.shadowOffsetY,this._clip]=n)}setLineDash(n){if(!Array.isArray(n))return;let o=[];for(let l=0;l<Math.min(64,n.length);l++){let g=Number(n[l]);if(!Number.isFinite(g)||g<0)return;o.push(g)}this._dash=o.length%2===1?[...o,...o]:o}getLineDash(){return[...this._dash]}resetTransform(){this._m=[1,0,0,1,0,0]}setTransform(n,o,l,g,D,R){if(n&&typeof n=="object"){this.setTransform(n.a??1,n.b??0,n.c??0,n.d??1,n.e??0,n.f??0);return}let U=Number(n??1),B=Number(o??0),W=Number(l??0),ne=Number(g??1),re=Number(D??0),te=Number(R??0);Number.isFinite(U+B+W+ne+re+te)&&(this._m=[U,B,W,ne,re,te])}getTransform(){let n=this._m;return{a:n[0],b:n[1],c:n[2],d:n[3],e:n[4],f:n[5]}}transform(n,o,l,g,D,R){if(!Number.isFinite(n+o+l+g+D+R))return;let U=this._m;this._m=[U[0]*n+U[2]*o,U[1]*n+U[3]*o,U[0]*l+U[2]*g,U[1]*l+U[3]*g,U[0]*D+U[2]*R+U[4],U[1]*D+U[3]*R+U[5]]}translate(n,o){this.transform(1,0,0,1,n,o)}rotate(n){if(!Number.isFinite(n))return;let o=Math.cos(n),l=Math.sin(n);this.transform(o,l,-l,o,0,0)}scale(n,o){this.transform(n,0,0,o,0,0)}createLinearGradient(n,o,l,g){return new G(!1,n,o,0,l,g,0)}createRadialGradient(n,o,l,g,D,R){return new G(!0,n,o,l,g,D,R)}createPattern(n,o="repeat"){let l=ze(n);return l?new x(l.data,l.width,l.height,o):null}beginPath(){this._subs.length=0,this._cur=null,this._pts=0}closePath(){if(this._cur&&this._cur.pts.length>0){this._cur.closed=!0;let n=this._cur.pts[0];this._cur={pts:[[n[0],n[1]]],closed:!1},this._subs.push(this._cur)}}moveTo(n,o){Number.isFinite(n+o)&&(this._cur={pts:[Q(this,n,o)],closed:!1},this._subs.push(this._cur),this._pts++)}lineTo(n,o){if(!Number.isFinite(n+o))return;if(!this._cur||this._cur.pts.length===0){this.moveTo(n,o);return}let l=Q(this,n,o);be(this,l[0],l[1])}rect(n,o,l,g){Number.isFinite(n+o+l+g)&&(this.moveTo(n,o),this.lineTo(n+l,o),this.lineTo(n+l,o+g),this.lineTo(n,o+g),this.closePath())}roundRect(n,o,l,g,D){if(!Number.isFinite(n+o+l+g))return;l<0&&(n+=l,l=-l),g<0&&(o+=g,g=-g);let R=Array.isArray(D)?D:D!==void 0?[D]:[0],U=se=>{let le=Number(se&&typeof se=="object"?se.x??0:se??0);return Number.isFinite(le)?Math.max(0,le):0},B=U(R[0]),W=U(R[1]??R[0]),ne=U(R[2]??R[0]),re=U(R[3]??R[1]??R[0]),te=Math.min(1,l/Math.max(1e-6,B+W),l/Math.max(1e-6,re+ne),g/Math.max(1e-6,B+re),g/Math.max(1e-6,W+ne));if(B*=te,W*=te,ne*=te,re*=te,B+W+ne+re<=1e-4){this.rect(n,o,l,g);return}this.moveTo(n+B,o),this.lineTo(n+l-W,o),W>0&&this.arc(n+l-W,o+W,W,-Math.PI/2,0),this.lineTo(n+l,o+g-ne),ne>0&&this.arc(n+l-ne,o+g-ne,ne,0,Math.PI/2),this.lineTo(n+re,o+g),re>0&&this.arc(n+re,o+g-re,re,Math.PI/2,Math.PI),this.lineTo(n,o+B),B>0&&this.arc(n+B,o+B,B,Math.PI,Math.PI*3/2),this.closePath()}quadraticCurveTo(n,o,l,g){if(!Number.isFinite(n+o+l+g))return;(!this._cur||this._cur.pts.length===0)&&this.moveTo(n,o);let D=this._cur.pts,[R,U]=D[D.length-1],[B,W]=Q(this,n,o),[ne,re]=Q(this,l,g),te=Math.max(4,Math.min(64,Math.ceil((Math.hypot(B-R,W-U)+Math.hypot(ne-B,re-W))*.5)));for(let se=1;se<=te;se++){let le=se/te,pe=1-le;be(this,pe*pe*R+2*pe*le*B+le*le*ne,pe*pe*U+2*pe*le*W+le*le*re)}}bezierCurveTo(n,o,l,g,D,R){if(!Number.isFinite(n+o+l+g+D+R))return;(!this._cur||this._cur.pts.length===0)&&this.moveTo(n,o);let U=this._cur.pts,[B,W]=U[U.length-1],[ne,re]=Q(this,n,o),[te,se]=Q(this,l,g),[le,pe]=Q(this,D,R),me=Math.max(6,Math.min(64,Math.ceil((Math.hypot(ne-B,re-W)+Math.hypot(te-ne,se-re)+Math.hypot(le-te,pe-se))*.4)));for(let xe=1;xe<=me;xe++){let de=xe/me,ce=1-de,we=ce*ce,Te=de*de;be(this,we*ce*B+3*we*de*ne+3*ce*Te*te+Te*de*le,we*ce*W+3*we*de*re+3*ce*Te*se+Te*de*pe)}}ellipse(n,o,l,g,D=0,R=0,U=Math.PI*2,B=!1){if(!Number.isFinite(n+o+l+g+D+R+U))return;let W=Math.max(0,l),ne=Math.max(0,g),re=Math.PI*2,te=U-R;if(!B)te>=re?te=re:te<0&&(te=(te%re+re)%re);else if(te<=-re)te=-re;else if(te>0){let xe=te%re;te=xe===0?0:xe-re}let se=Math.cos(D),le=Math.sin(D),pe=Math.hypot(this._m[0]*this.canvas._sx,this._m[1]*this.canvas._sy,this._m[2]*this.canvas._sx,this._m[3]*this.canvas._sy),me=Math.max(8,Math.min(96,Math.ceil(Math.abs(te)*Math.max(1,W,ne)*pe/3)));for(let xe=0;xe<=me;xe++){let de=R+te*xe/me,ce=W*Math.cos(de),we=ne*Math.sin(de),Te=n+ce*se-we*le,Ee=o+ce*le+we*se;xe===0&&(!this._cur||this._cur.pts.length===0)?this.moveTo(Te,Ee):this.lineTo(Te,Ee)}}arc(n,o,l,g,D,R=!1){this.ellipse(n,o,l,l,0,g,D,R)}arcTo(n,o,l,g,D){if(!Number.isFinite(n+o+l+g+D))return;let R=Math.max(0,D);if(!this._cur||this._cur.pts.length===0){this.moveTo(n,o);return}if(R<=1e-6){this.lineTo(n,o);return}let U=this._cur.pts,[B,W]=U[U.length-1],[ne,re]=ee(this,B,W),te=ne-n,se=re-o,le=l-n,pe=g-o,me=Math.hypot(te,se),xe=Math.hypot(le,pe);if(me<1e-6||xe<1e-6){this.lineTo(n,o);return}let de=te/me,ce=se/me,we=le/xe,Te=pe/xe,Ee=de*Te-ce*we;if(Math.abs(Ee)<1e-6){this.lineTo(n,o);return}let Re=Math.acos(Math.max(-1,Math.min(1,de*we+ce*Te)))*.5,We=R/Math.tan(Re),Xe=de+we,et=ce+Te,Ze=Math.hypot(Xe,et)||1,tt=R/Math.sin(Re),Ue=n+Xe/Ze*tt,Ye=o+et/Ze*tt;this.arc(Ue,Ye,R,Math.atan2(o+ce*We-Ye,n+de*We-Ue),Math.atan2(o+Te*We-Ye,n+we*We-Ue),Ee>0)}fill(n){if(this.canvas.width<=0||this.canvas.height<=0)return;let o=Ne(this,this.fillStyle),l=ae(this);Be(this,this._subs,typeof n=="string"?n:"nonzero",(g,D)=>De(this,l,g,D,o(g+.5,D+.5))),this.canvas._ver++}clip(n){let o=this.canvas._bw,l=this.canvas._bh,g=new Uint8Array(o*l);if(Be(this,this._subs,typeof n=="string"?n:"nonzero",(D,R)=>{g[R*o+D]=1}),this._clip)for(let D=0;D<g.length;D++)g[D]&=this._clip[D];this._clip=g}stroke(){if(this.canvas.width<=0||this.canvas.height<=0)return;let n=this._m,o=(Math.hypot(n[0]*this.canvas._sx,n[1]*this.canvas._sy)+Math.hypot(n[2]*this.canvas._sx,n[3]*this.canvas._sy))*.5,l=Number(this.lineWidth),g=Number.isFinite(l)&&l>0?l:1,D=Math.max(.5,g*o*.5),R=D*D,U=this.lineCap,B=this.canvas._bw,W=this.canvas._bh,ne=Ne(this,this.strokeStyle),re=ae(this),te=new Uint8Array(B*W),se=0,le=[];for(let de=0;de<this._dash.length;de++){let ce=this._dash[de]*o;le.push(ce),se+=ce}let pe=(de,ce,we,Te,Ee,Re)=>{let We=de,Xe=ce,et=we,Ze=Te,tt=et-We,Ue=Ze-Xe,Ye=Math.hypot(tt,Ue);if(U==="square"&&Ye>1e-6){let ft=tt/Ye*D,pt=Ue/Ye*D;Ee&&(We-=ft,Xe-=pt),Re&&(et+=ft,Ze+=pt),tt=et-We,Ue=Ze-Xe}let it=tt*tt+Ue*Ue,dt=D+.5,ct=Math.max(0,Math.floor(Math.min(We,et)-dt)),ot=Math.min(B-1,Math.ceil(Math.max(We,et)+dt)),gt=Math.max(0,Math.floor(Math.min(Xe,Ze)-dt)),vt=Math.min(W-1,Math.ceil(Math.max(Xe,Ze)+dt));for(let ft=gt;ft<=vt;ft++){let pt=ft+.5;for(let kt=ct;kt<=ot;kt++){let _t=ft*B+kt;if(te[_t])continue;let Ft=kt+.5,At=it>1e-9?((Ft-We)*tt+(pt-Xe)*Ue)/it:0;if(U==="butt"&&(At<0&&Ee||At>1&&Re))continue;At=Math.max(0,Math.min(1,At));let Ot=We+At*tt,Xt=Xe+At*Ue;(Ft-Ot)*(Ft-Ot)+(pt-Xt)*(pt-Xt)<=R&&(te[_t]=1,De(this,re,kt,ft,ne(Ft,pt)))}}},me=Number(this.lineDashOffset),xe=Number.isFinite(me)?me:0;for(let de of this._subs){let ce=de.pts,we=ce.length;if(we<2)continue;let Te=de.closed?we:we-1,Ee=se>1e-6?(xe*o%se+se)%se:0;for(let Re=0;Re<Te;Re++){let[We,Xe]=ce[Re],[et,Ze]=ce[(Re+1)%we];if(se<=1e-6)pe(We,Xe,et,Ze,!de.closed&&Re===0,!de.closed&&Re===Te-1);else{let tt=Math.hypot(et-We,Ze-Xe);if(tt<=1e-6)continue;let Ue=0;for(;Ue<tt;){let Ye=Ee,it=0;for(;it<le.length&&Ye>=le[it];)Ye-=le[it],it++;let dt=Math.min(tt-Ue,it<le.length?Math.max(.25,le[it]-Ye):tt-Ue);if(it%2===0){let ct=Ue/tt,ot=(Ue+dt)/tt;pe(We+(et-We)*ct,Xe+(Ze-Xe)*ct,We+(et-We)*ot,Xe+(Ze-Xe)*ot,!0,!0)}Ue+=dt,Ee=(Ee+dt)%se}}}}this.canvas._ver++}clearRect(n,o,l,g){if(!Number.isFinite(n+o+l+g)||this.canvas.width<=0||this.canvas.height<=0)return;let D=this._m;if(D[0]===1&&D[1]===0&&D[2]===0&&D[3]===1&&D[4]===0&&D[5]===0&&!this._clip&&n<=0&&o<=0&&n+l>=this.canvas.width&&o+g>=this.canvas.height){this.canvas._data.fill(0),this.canvas._ver++;return}let R=this.canvas._data,U=this.canvas._bw,B=this._clip;Be(this,[{pts:[Q(this,n,o),Q(this,n+l,o),Q(this,n+l,o+g),Q(this,n,o+g)],closed:!0}],"nonzero",(W,ne)=>{let re=ne*U+W;if(B&&!B[re])return;let te=re*4;R[te]=R[te+1]=R[te+2]=R[te+3]=0}),this.canvas._ver++}fillRect(n,o,l,g){if(!Number.isFinite(n+o+l+g)||l===0||g===0||this.canvas.width<=0||this.canvas.height<=0)return;let D=Ne(this,this.fillStyle),R=ae(this),U=this._m;if(U[1]===0&&U[2]===0){let B=this.canvas._bw,W=this.canvas._bh,ne=(U[0]*n+U[4])*this.canvas._sx,re=(U[0]*(n+l)+U[4])*this.canvas._sx,te=(U[3]*o+U[5])*this.canvas._sy,se=(U[3]*(o+g)+U[5])*this.canvas._sy,le=Math.max(0,Math.ceil(Math.min(ne,re)-.5)),pe=Math.min(B-1,Math.ceil(Math.max(ne,re)-.5)-1),me=Math.max(0,Math.ceil(Math.min(te,se)-.5)),xe=Math.min(W-1,Math.ceil(Math.max(te,se)-.5)-1);if(le<=pe&&me<=xe){if(!this._clip&&typeof this.fillStyle=="string"){let ce=D(0,0),we=ce>>>24;if(R===0&&we>=255||R===1){let Te=new Uint32Array(new Uint8Array([ce&255,ce>>>8&255,ce>>>16&255,we]).buffer)[0],Ee=this.canvas._data,Re=new Uint32Array(Ee.buffer,Ee.byteOffset,B*W);if(le===0&&pe===B-1)Re.fill(Te,me*B,(xe+1)*B);else for(let We=me;We<=xe;We++)Re.fill(Te,We*B+le,We*B+pe+1);this.canvas._ver++;return}}let de=ce=>{let we=ce+.5;for(let Te=le;Te<=pe;Te++)De(this,R,Te,ce,D(Te+.5,we))};for(let ce=me;ce<=xe;ce++)de(ce)}this.canvas._ver++;return}Be(this,[{pts:[Q(this,n,o),Q(this,n+l,o),Q(this,n+l,o+g),Q(this,n,o+g)],closed:!0}],"nonzero",(B,W)=>De(this,R,B,W,D(B+.5,W+.5))),this.canvas._ver++}strokeRect(n,o,l,g){if(!Number.isFinite(n+o+l+g)||l===0&&g===0)return;let D=this._subs,R=this._cur,U=this._pts;this._subs=[],this._cur=null,this._pts=0,this.rect(n,o,l,g),this.stroke(),this._subs=D,this._cur=R,this._pts=U}measureText(n){let{sizePx:o,bold:l}=X(this.font),g=Array.from(String(n??"")).length;return{width:g>0?g*o*(l?.64:.6)-o*.1:0,actualBoundingBoxAscent:o*.8,actualBoundingBoxDescent:o*.2,fontBoundingBoxAscent:o*.85,fontBoundingBoxDescent:o*.2}}fillText(n,o,l,g){je(this,n,o,l,g,!1)}strokeText(n,o,l,g){je(this,n,o,l,g,!0)}createImageData(n,o){let l=n&&typeof n=="object",g=Math.max(1,Math.min(d,Math.floor(Math.abs(Number(l?n.width:n))||1))),D=Math.max(1,Math.min(d,Math.floor(Math.abs(Number(l?n.height:o))||1)));return{data:new Uint8ClampedArray(g*D*4),width:g,height:D}}getImageData(n,o,l,g){let D=Math.floor(Number(n)||0),R=Math.floor(Number(o)||0),U=Math.floor(Number(l)||0),B=Math.floor(Number(g)||0);U<0&&(D+=U,U=-U),B<0&&(R+=B,B=-B),U=Math.max(1,Math.min(d,U)),B=Math.max(1,Math.min(d,B));let W=new Uint8ClampedArray(U*B*4);if(this.canvas.width<=0||this.canvas.height<=0)return{data:W,width:U,height:B};let ne=this.canvas._bw,re=this.canvas._bh,te=this.canvas._sx,se=this.canvas._sy,le=this.canvas._data;for(let pe=0;pe<B;pe++){let me=R+pe;if(me<0||me>=this.canvas.height)continue;let xe=Math.min(re-1,Math.floor((me+.5)*se));for(let de=0;de<U;de++){let ce=D+de;if(ce<0||ce>=this.canvas.width)continue;let we=(xe*ne+Math.min(ne-1,Math.floor((ce+.5)*te)))*4,Te=(pe*U+de)*4;W[Te]=le[we],W[Te+1]=le[we+1],W[Te+2]=le[we+2],W[Te+3]=le[we+3]}}return{data:W,width:U,height:B}}putImageData(n,o,l,g=0,D=0,R,U){if(!n?.data||this.canvas.width<=0||this.canvas.height<=0)return;let B=Math.floor(Number(n.width)||0),W=Math.floor(Number(n.height)||0);if(B<=0||W<=0)return;let ne=Math.floor(Number(g)||0),re=Math.floor(Number(D)||0),te=R!==void 0?Math.floor(Number(R)):B,se=U!==void 0?Math.floor(Number(U)):W;te<0&&(ne+=te,te=-te),se<0&&(re+=se,se=-se);let le=Math.max(0,ne),pe=Math.max(0,re),me=Math.min(B,ne+te),xe=Math.min(W,re+se);if(le>=me||pe>=xe)return;let de=Math.floor(Number(o)||0),ce=Math.floor(Number(l)||0),we=this.canvas._bw,Te=this.canvas._bh,Ee=1/this.canvas._sx,Re=1/this.canvas._sy,We=this.canvas._data,Xe=n.data,et=Math.max(0,Math.floor((de+le)*this.canvas._sx)),Ze=Math.min(we-1,Math.ceil((de+me)*this.canvas._sx)-1),tt=Math.max(0,Math.floor((ce+pe)*this.canvas._sy)),Ue=Math.min(Te-1,Math.ceil((ce+xe)*this.canvas._sy)-1);for(let Ye=tt;Ye<=Ue;Ye++){let it=Math.floor((Ye+.5)*Re)-ce;if(!(it<pe||it>=xe))for(let dt=et;dt<=Ze;dt++){let ct=Math.floor((dt+.5)*Ee)-de;if(ct<le||ct>=me)continue;let ot=(it*B+ct)*4,gt=(Ye*we+dt)*4;We[gt]=Xe[ot]|0,We[gt+1]=Xe[ot+1]|0,We[gt+2]=Xe[ot+2]|0,We[gt+3]=Xe[ot+3]|0}}this.canvas._ver++}drawImage(n,...o){let l=ze(n);if(!l||l.width<=0||l.height<=0||this.canvas.width<=0||this.canvas.height<=0)return;let g=Number(n?.width)>0?Number(n.width):l.width,D=Number(n?.height)>0?Number(n.height):l.height,R=0,U=0,B=g,W=D,ne=0,re=0,te=g,se=D;if(o.length>=8)[R,U,B,W,ne,re,te,se]=o;else if(o.length>=4)[ne,re,te,se]=o;else if(o.length>=2)[ne,re]=o;else return;if(!Number.isFinite(R+U+B+W+ne+re+te+se)||B===0||W===0||te===0||se===0)return;let le=Number(this.globalAlpha),pe=Number.isFinite(le)?Math.max(0,Math.min(1,le)):1,me=Math.round(pe*256),xe=ae(this),[de,ce,we,Te,Ee,Re]=L(this),We=1/te,Xe=1/se,et=l.width/g,Ze=l.height/D;Be(this,[{pts:[Q(this,ne,re),Q(this,ne+te,re),Q(this,ne+te,re+se),Q(this,ne,re+se)],closed:!0}],"nonzero",(tt,Ue)=>{let Ye=tt+.5,it=Ue+.5,dt=de*Ye+ce*it+we,ct=Te*Ye+Ee*it+Re,ot=(dt-ne)*We,gt=(ct-re)*Xe;if(ot<0||ot>=1||gt<0||gt>=1)return;let vt=Math.floor((R+ot*B)*et),ft=Math.floor((U+gt*W)*Ze);if(vt<0||vt>=l.width||ft<0||ft>=l.height)return;let pt=(ft*l.width+vt)*4;De(this,xe,tt,Ue,v(l.data[pt],l.data[pt+1],l.data[pt+2],l.data[pt+3]*me+128>>8))}),this.canvas._ver++}}let Ie=(u,n,o)=>{let l=Math.floor(Number(n)),g=Math.floor(Number(o));u._w=Number.isFinite(l)&&l>=0?l:0,u._h=Number.isFinite(g)&&g>=0?g:0,u._bw=u._w>0?Math.min(C,u._w):1,u._bh=u._h>0?Math.min(C,u._h):1,u._sx=u._w>0?u._bw/u._w:1,u._sy=u._h>0?u._bh/u._h:1,u._data=new Uint8ClampedArray(u._bw*u._bh*4),u._ctx2d&&F(u._ctx2d),u._ver++};class Me{constructor(n=300,o=150){this._vc=!0,this._ver=1,this._ctx2d=null,this.style={},Ie(this,n,o)}get width(){return this._w}set width(n){Ie(this,n,this._h)}get height(){return this._h}set height(n){Ie(this,this._w,n)}getContext(n){return String(n).toLowerCase()!=="2d"?null:this._ctx2d??(this._ctx2d=new Ve(this))}toDataURL(){return this._w<=0||this._h<=0||this._w>d||this._h>d?"":w(this._data,this._bw,this._bh,!1,!1).uri}addEventListener(){}removeEventListener(){}getBoundingClientRect(){return{left:0,top:0,width:this._w,height:this._h,right:this._w,bottom:this._h}}}function ze(u){if(!u||typeof u!="object")return null;let n=u._vc?u:u.canvas?._vc?u.canvas:u.image?._vc?u.image:null;if(n)return{data:n._data,width:n._bw,height:n._bh,logicalW:n._w,logicalH:n._h,ver:n._ver};let o=u.image&&typeof u.image=="object"?u.image:u;if(o.data&&typeof o.data.length=="number"&&Number(o.width)>0&&Number(o.height)>0){let l=Math.floor(Number(o.width)),g=Math.floor(Number(o.height));return{data:o.data instanceof Uint8ClampedArray?o.data:new Uint8ClampedArray(o.data),width:l,height:g,logicalW:l,logicalH:g,ver:-1}}if(typeof o.getContext=="function"){let l=Math.floor(Number(o.width)||0),g=Math.floor(Number(o.height)||0);if(l>0&&g>0&&l<=d&&g<=d)try{let D=o.getContext("2d")?.getImageData?.(0,0,l,g);if(D?.data)return{data:D.data instanceof Uint8ClampedArray?D.data:new Uint8ClampedArray(D.data),width:l,height:g,logicalW:l,logicalH:g,ver:-1}}catch{}}return null}let Se=t.Texture??class{constructor(u=""){this.source=u,this.isTexture=!0,this.image=null,this.width=0,this.height=0}dispose(){}},He=u=>{let n=ze(u.image);if(!n){u.width=Number(u.image?.width??0)||0,u.height=Number(u.image?.height??0)||0,u._cs="";return}if(u.width=n.logicalW,u.height=n.logicalH,n.logicalW<=0||n.logicalH<=0||n.logicalW>d||n.logicalH>d){u._cs="";return}let o=`${n.ver>=0?n.ver:u._fs}|${n.logicalW}x${n.logicalH}|${u.flipY?1:0}|${u.colorSpace}`;if(o===u._bk&&u._cs)return;u._bk=o;let l=w(n.data,n.width,n.height,u.flipY,u.colorSpace==="srgb-linear",Math.min(d,Number(u._pngDim)||C));u._cs=l.uri,u._ca=l.avgColor};class J extends Se{constructor(n=null,o,l=1001,g=1001,D=1006,R=1008,U=1023,B=1009,W=1,ne="srgb"){super(""),delete this.source,this.isCanvasTexture=!0,this.isDataTexture=!0,this.image=n,this.width=Number(n?.width??0)||0,this.height=Number(n?.height??0)||0,this.wrapS=Number(l)||1001,this.wrapT=Number(g)||1001,this.magFilter=Number(D)||1006,this.minFilter=Number(R)||1008,this.format=Number(U)||1023,this.type=Number(B)||1009,this.flipY=!0,this.generateMipmaps=!0,this.unpackAlignment=4,this.colorSpace=ne||"srgb",this._bk="",this._cs="",this._ca=[1,1,1,1],this._ms="",this._fs=1}get needsUpdate(){return!1}set needsUpdate(n){n&&(this._ms="",this._fs++,this.width=Number(this.image?.width??0)||0,this.height=Number(this.image?.height??0)||0)}get source(){return this._ms?this._ms:(He(this),this._cs)}set source(n){this._ms=typeof n=="string"?n:""}get avgColor(){return this._ms||He(this),this._ca}set avgColor(n){Array.isArray(n)&&n.length===4&&(this._ca=[n[0],n[1],n[2],n[3]])}}try{Object.freeze(G.prototype),Object.freeze(x.prototype),Object.freeze(Ve.prototype),Object.freeze(Me.prototype)}catch{}let j=(u=300,n=150)=>new Me(u,n);try{let u=typeof globalThis<"u"?globalThis:typeof self<"u"?self:void 0;if(u&&typeof u.HTMLCanvasElement>"u"){let n=o=>String(o).toLowerCase()==="canvas"?new Me(300,150):{style:{},getContext:()=>null,addEventListener:()=>{},removeEventListener:()=>{},appendChild:()=>{},removeChild:()=>{},setAttribute:()=>{}};if(typeof u.document>"u"||u.document===null){let o=Object.freeze({appendChild:()=>{},removeChild:()=>{},style:{}}),l=Object.freeze({style:{}});u.document=Object.freeze({__threeLiveVirtualCanvas:!0,createElement:n,createTextNode:()=>({}),querySelectorAll:()=>[],querySelector:()=>null,getElementById:()=>null,head:o,body:o,documentElement:l,addEventListener:()=>{},removeEventListener:()=>{}})}else if(typeof u.document=="object"&&!u.document.__threeLiveVirtualCanvas){let o=typeof u.document.createElement=="function"?u.document.createElement.bind(u.document):null;try{u.document.__threeLiveVirtualCanvas=!0,u.document.createElement=l=>String(l).toLowerCase()==="canvas"?new Me(300,150):o?o(l):n(l)}catch{}}}}catch{}let I=new Uint8Array([151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180]),O=new Uint8Array(512);for(let u=0;u<256;u++)O[u]=I[u],O[u+256]=I[u];let K=u=>u*u*u*(u*(u*6-15)+10),ie=(u,n,o)=>n+u*(o-n),he=(u,n,o,l)=>{let g=u&15,D=g<8?n:o,R=g<4?o:g===12||g===14?n:l;return((g&1)===0?D:-D)+((g&2)===0?R:-R)};class ue{noise(n,o,l=0){let g=Number(n),D=Number(o),R=Number(l);if(!Number.isFinite(g)||!Number.isFinite(D)||!Number.isFinite(R))return 0;let U=Math.floor(g),B=Math.floor(D),W=Math.floor(R),ne=U&255,re=B&255,te=W&255;g-=U,D-=B,R-=W;let se=g-1,le=D-1,pe=R-1,me=K(g),xe=K(D),de=K(R),ce=O[ne]+re,we=O[ce]+te,Te=O[ce+1]+te,Ee=O[ne+1]+re,Re=O[Ee]+te,We=O[Ee+1]+te;return ie(de,ie(xe,ie(me,he(O[we],g,D,R),he(O[Re],se,D,R)),ie(me,he(O[Te],g,le,R),he(O[We],se,le,R))),ie(xe,ie(me,he(O[we+1],g,D,pe),he(O[Re+1],se,D,pe)),ie(me,he(O[Te+1],g,le,pe),he(O[We+1],se,le,pe))))}}Object.freeze(ue.prototype);let ge=new Int8Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),oe=new Int8Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]),_e=.5*(Math.sqrt(3)-1),fe=(3-Math.sqrt(3))/6,ye=1/3,Ae=1/6,Pe=(Math.sqrt(5)-1)/4,Le=(5-Math.sqrt(5))/20,ke=(u,n,o)=>ge[u]*n+ge[u+1]*o,$e=(u,n,o,l)=>ge[u]*n+ge[u+1]*o+ge[u+2]*l,Fe=(u,n,o,l,g)=>oe[u]*n+oe[u+1]*o+oe[u+2]*l+oe[u+3]*g;function qe(u){let n=u===void 0?Math:u;if(typeof n=="function")return n;if(typeof n=="number"){let o=Number.isFinite(n)?n|0:0;return()=>{let l=o=o+1831565813|0;return l=Math.imul(l^l>>>15,l|1),l^=l+Math.imul(l^l>>>7,l|61),((l^l>>>14)>>>0)/4294967296}}return n&&typeof n=="object"&&typeof n.random=="function"?()=>n.random():Math.random}class Oe{constructor(n){let o=qe(n),l=new Uint8Array(256);for(let R=0;R<256;R++){let U=Number(o()),B=Number.isFinite(U)?(U%1+1)%1:0;l[R]=Math.floor(B*256)&255}let g=new Uint8Array(512),D=new Uint8Array(512);for(let R=0;R<512;R++){let U=l[R&255];g[R]=U,D[R]=U%12}this.p=l,this.perm=g,this.permMod12=D}noise(n,o){let l=Number(n),g=Number(o);if(!Number.isFinite(l)||!Number.isFinite(g))return 0;let D=this.perm,R=this.permMod12,U=(l+g)*_e,B=Math.floor(l+U),W=Math.floor(g+U),ne=(B+W)*fe,re=B-ne,te=W-ne,se=l-re,le=g-te,pe=se>le?1:0,me=se>le?0:1,xe=se-pe+fe,de=le-me+fe,ce=se-1+2*fe,we=le-1+2*fe,Te=B&255,Ee=W&255,Re=R[Te+D[Ee]]*3,We=R[Te+pe+D[Ee+me]]*3,Xe=R[Te+1+D[Ee+1]]*3,et=0,Ze=.5-se*se-le*le;Ze>=0&&(Ze*=Ze,et=Ze*Ze*ke(Re,se,le));let tt=0,Ue=.5-xe*xe-de*de;Ue>=0&&(Ue*=Ue,tt=Ue*Ue*ke(We,xe,de));let Ye=0,it=.5-ce*ce-we*we;return it>=0&&(it*=it,Ye=it*it*ke(Xe,ce,we)),70*(et+tt+Ye)}noise3d(n,o,l){let g=Number(n),D=Number(o),R=Number(l);if(!Number.isFinite(g)||!Number.isFinite(D)||!Number.isFinite(R))return 0;let U=this.perm,B=this.permMod12,W=(g+D+R)*ye,ne=Math.floor(g+W),re=Math.floor(D+W),te=Math.floor(R+W),se=(ne+re+te)*Ae,le=g-(ne-se),pe=D-(re-se),me=R-(te-se),xe,de,ce,we,Te,Ee;le>=pe?pe>=me?(xe=1,de=0,ce=0,we=1,Te=1,Ee=0):le>=me?(xe=1,de=0,ce=0,we=1,Te=0,Ee=1):(xe=0,de=0,ce=1,we=1,Te=0,Ee=1):pe<me?(xe=0,de=0,ce=1,we=0,Te=1,Ee=1):le<me?(xe=0,de=1,ce=0,we=0,Te=1,Ee=1):(xe=0,de=1,ce=0,we=1,Te=1,Ee=0);let Re=le-xe+Ae,We=pe-de+Ae,Xe=me-ce+Ae,et=le-we+2*Ae,Ze=pe-Te+2*Ae,tt=me-Ee+2*Ae,Ue=le-1+3*Ae,Ye=pe-1+3*Ae,it=me-1+3*Ae,dt=ne&255,ct=re&255,ot=te&255,gt=B[dt+U[ct+U[ot]]]*3,vt=B[dt+xe+U[ct+de+U[ot+ce]]]*3,ft=B[dt+we+U[ct+Te+U[ot+Ee]]]*3,pt=B[dt+1+U[ct+1+U[ot+1]]]*3,kt=0,_t=.6-le*le-pe*pe-me*me;_t>=0&&(_t*=_t,kt=_t*_t*$e(gt,le,pe,me));let Ft=0,At=.6-Re*Re-We*We-Xe*Xe;At>=0&&(At*=At,Ft=At*At*$e(vt,Re,We,Xe));let Ot=0,Xt=.6-et*et-Ze*Ze-tt*tt;Xt>=0&&(Xt*=Xt,Ot=Xt*Xt*$e(ft,et,Ze,tt));let mi=0,ri=.6-Ue*Ue-Ye*Ye-it*it;return ri>=0&&(ri*=ri,mi=ri*ri*$e(pt,Ue,Ye,it)),32*(kt+Ft+Ot+mi)}noise4d(n,o,l,g){let D=Number(n),R=Number(o),U=Number(l),B=Number(g);if(!Number.isFinite(D)||!Number.isFinite(R)||!Number.isFinite(U)||!Number.isFinite(B))return 0;let W=this.perm,ne=(D+R+U+B)*Pe,re=Math.floor(D+ne),te=Math.floor(R+ne),se=Math.floor(U+ne),le=Math.floor(B+ne),pe=(re+te+se+le)*Le,me=D-(re-pe),xe=R-(te-pe),de=U-(se-pe),ce=B-(le-pe),we=(me>xe?1:0)+(me>de?1:0)+(me>ce?1:0),Te=(me<=xe?1:0)+(xe>de?1:0)+(xe>ce?1:0),Ee=(me<=de?1:0)+(xe<=de?1:0)+(de>ce?1:0),Re=(me<=ce?1:0)+(xe<=ce?1:0)+(de<=ce?1:0),We=we>=3?1:0,Xe=Te>=3?1:0,et=Ee>=3?1:0,Ze=Re>=3?1:0,tt=we>=2?1:0,Ue=Te>=2?1:0,Ye=Ee>=2?1:0,it=Re>=2?1:0,dt=we>=1?1:0,ct=Te>=1?1:0,ot=Ee>=1?1:0,gt=Re>=1?1:0,vt=me-We+Le,ft=xe-Xe+Le,pt=de-et+Le,kt=ce-Ze+Le,_t=me-tt+2*Le,Ft=xe-Ue+2*Le,At=de-Ye+2*Le,Ot=ce-it+2*Le,Xt=me-dt+3*Le,mi=xe-ct+3*Le,ri=de-ot+3*Le,Li=ce-gt+3*Le,Ki=me-1+4*Le,Gi=xe-1+4*Le,mr=de-1+4*Le,dr=ce-1+4*Le,Di=re&255,$i=te&255,ni=se&255,si=le&255,Vh=(W[Di+W[$i+W[ni+W[si]]]]&31)*4,Hh=(W[Di+We+W[$i+Xe+W[ni+et+W[si+Ze]]]]&31)*4,Gh=(W[Di+tt+W[$i+Ue+W[ni+Ye+W[si+it]]]]&31)*4,Wh=(W[Di+dt+W[$i+ct+W[ni+ot+W[si+gt]]]]&31)*4,qh=(W[Di+1+W[$i+1+W[ni+1+W[si+1]]]]&31)*4,Ja=0,gr=.6-me*me-xe*xe-de*de-ce*ce;gr>=0&&(gr*=gr,Ja=gr*gr*Fe(Vh,me,xe,de,ce));let Za=0,yr=.6-vt*vt-ft*ft-pt*pt-kt*kt;yr>=0&&(yr*=yr,Za=yr*yr*Fe(Hh,vt,ft,pt,kt));let Qa=0,br=.6-_t*_t-Ft*Ft-At*At-Ot*Ot;br>=0&&(br*=br,Qa=br*br*Fe(Gh,_t,Ft,At,Ot));let Ka=0,xr=.6-Xt*Xt-mi*mi-ri*ri-Li*Li;xr>=0&&(xr*=xr,Ka=xr*xr*Fe(Wh,Xt,mi,ri,Li));let eo=0,vr=.6-Ki*Ki-Gi*Gi-mr*mr-dr*dr;return vr>=0&&(vr*=vr,eo=vr*vr*Fe(qh,Ki,Gi,mr,dr)),27*(Ja+Za+Qa+Ka+eo)}noise2D(n,o){return this.noise(n,o)}noise3D(n,o,l){return this.noise3d(n,o,l)}noise4D(n,o,l,g){return this.noise4d(n,o,l,g)}}Object.freeze(Oe.prototype);let lt=u=>{if(!u||typeof u!="object")return null;let n=u,o=n.image,l=ze(o??n);if(l&&o?._vc)return{buf:l.data,w:l.width,h:l.height,ch:4,isFloat:!1,flipY:!!n.flipY};let g=o?.data,D=Number(o?.width??n.width)|0,R=Number(o?.height??n.height)|0;if(!g||!(D>0&&R>0)||!g.length)return null;let U=D*R,B=n.format,W=B===1021||B===1024||B===1028||g.length===U?1:B===1025||B===1030||g.length===U*2?2:B===1022||g.length===U*3?3:4;return{buf:g,w:D,h:R,ch:W,isFloat:n.type===1015||n.type===1016||g instanceof Float32Array||g instanceof Float64Array,flipY:!!n.flipY}},rt=(u,n,o,l)=>{let g=Math.min(u.w-1,Math.max(0,n*u.w|0)),D=Math.min(u.h-1,Math.max(0,o*u.h|0)),R=u.flipY?u.h-1-D:D,U=Number(u.buf[(R*u.w+g)*u.ch+Math.min(l,u.ch-1)]??0);if(!Number.isFinite(U))return 0;let B=u.isFloat&&U<=1?U*255:U;return B>0?B<255?B+.5|0:255:0},nt=t.MeshStandardMaterial?.prototype&&(Object.getPrototypeOf(t.MeshStandardMaterial.prototype)||t.MeshStandardMaterial.prototype);nt&&typeof nt._packPbr!="function"&&(nt._packPbr=function(){let u;if((this.roughnessMap||this.metalnessMap)&&this.roughnessMap!==this.metalnessMap){let l=lt(this.roughnessMap),g=lt(this.metalnessMap);if(l||g){let D=Math.min(128,Math.max(l?.w??1,g?.w??1)),R=Math.min(128,Math.max(l?.h??1,g?.h??1)),U=new Uint8ClampedArray(D*R*4);for(let B=0;B<R;B++){let W=(B+.5)/R;for(let ne=0;ne<D;ne++){let re=(ne+.5)/D,te=(B*D+ne)*4;U[te]=255,U[te+1]=l?rt(l,re,W,1):255,U[te+2]=g?rt(g,re,W,2):255,U[te+3]=255}}u=w(U,D,R,!1,!0,128).uri}}let n,o;if(!this.normalMap&&this.bumpMap){let l=lt(this.bumpMap);if(l){let g=Number.isFinite(this.bumpScale)?this.bumpScale:1,D=Math.min(128,l.w),R=Math.min(128,l.h),U=new Uint8ClampedArray(D*R*4),B=(W,ne)=>rt(l,((W%D+D)%D+.5)/D,((ne%R+R)%R+.5)/R,0)/255;for(let W=0;W<R;W++)for(let ne=0;ne<D;ne++){let re=(B(ne+1,W)-B(ne-1,W))*g*2,te=(B(ne,W+1)-B(ne,W-1))*g*2,se=1/Math.hypot(re,te,1),le=(W*D+ne)*4;U[le]=(-re*se*.5+.5)*255+.5|0,U[le+1]=(te*se*.5+.5)*255+.5|0,U[le+2]=(se*.5+.5)*255+.5|0,U[le+3]=255}n=w(U,D,R,!1,!0,128).uri,o=1}}return{mrUri:u,normUri:n,normScale:o}});let ht=0,Ke=t.Vector2,Dt=t.PlaneGeometry,zt=t.Mesh,Qt=t.Material;class bt extends Qt{constructor(n={}){super({roughness:.85,metalness:0,side:2,transparent:n.transparent??!0,...n}),this.isSpriteMaterial=!0;let o=Number(n.rotation);this.rotation=Number.isFinite(o)?o:0,this.sizeAttenuation=n.sizeAttenuation!==!1,n.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35,this.map&&!this.emissiveMap&&(this.emissiveMap=this.map))}clone(){return new bt({...this,emissive:this._em?this.emissive:void 0})}}class It extends zt{constructor(n){super(new Dt(1,1),n instanceof Qt?n:new bt(n||{})),this.isSprite=!0,this.center=new Ke(.5,.5),this.userData={xr:{billboard:"spherical"}}}_cloneCustom(){let n=new It(this.material);return n.center.copy(this.center),n._autoNamed=!!this._autoNamed,n._noBillboard=!!this._noBillboard,n}_bakeAuthorGeometry(){this._bakedOwner!==this?((!this.name||this._autoNamed)&&(this.name=`Sprite_${++ht}`,this._autoNamed=!0),this._bakedOwner=this):this.name||(this.name=`Sprite_${++ht}`,this._autoNamed=!0);let n=this.userData?.xr?.billboard;n===!1||n===null?(this._noBillboard=!0,delete this.userData.xr.billboard,Object.keys(this.userData.xr).length===0&&delete this.userData.xr):((typeof n=="string"||n===!0)&&(this._noBillboard=!1),this._noBillboard||(!this.userData||typeof this.userData!="object"?this.userData={xr:{billboard:"spherical"}}:!this.userData.xr||typeof this.userData.xr!="object"?this.userData.xr={billboard:"spherical"}:this.userData.xr.billboard===void 0&&(this.userData.xr.billboard="spherical")));let o=Number.isFinite(this.center?.x)?this.center.x:.5,l=Number.isFinite(this.center?.y)?this.center.y:.5,g=Number(this.material?.rotation),D=Number.isFinite(g)?g:0,R=`${o},${l},${D}`;if(this._bakedKey!==R&&(this._bakedKey!==void 0||o!==.5||l!==.5||D!==0)){let U=new Dt(1,1),B=U.attributes.position?.array,W=.5-o,ne=.5-l,re=Math.cos(D),te=Math.sin(D);if(B){for(let se=0;se<B.length;se+=3){let le=B[se]+W,pe=B[se+1]+ne;B[se]=le*re-pe*te,B[se+1]=le*te+pe*re}U.boundingBox=null,U.boundingSphere=null}U.__baked=!0,this._bakedKey=R,this.geometry=U}}}if(Object.freeze(bt.prototype),Object.freeze(It.prototype),Ke?.prototype){let u=Ke.prototype,n=(o,l)=>{typeof u[o]!="function"&&(u[o]=l)};n("length",function(){return Math.hypot(this.x,this.y)}),n("normalize",function(){return this.divideScalar(Math.hypot(this.x,this.y)||1)}),n("distanceTo",function(o){return Math.hypot(this.x-(o?.x||0),this.y-(o?.y||0))}),n("dot",function(o){return this.x*(o?.x||0)+this.y*(o?.y||0)}),n("lerp",function(o,l){let g=Number(l)||0;return this.set(this.x+((o?.x||0)-this.x)*g,this.y+((o?.y||0)-this.y)*g)}),n("lerpVectors",function(o,l,g){let D=Number(g)||0,R=o?.x||0,U=o?.y||0;return this.set(R+((l?.x||0)-R)*D,U+((l?.y||0)-U)*D)}),n("equals",function(o){return!!o&&o.x===this.x&&o.y===this.y})}let ve=(u,n=0)=>{let o=Number(u);return Number.isFinite(o)?o:n},st=u=>Math.max(0,Math.min(1,ve(u,0))),yt=u=>new Ke(ve(u?.x),ve(u?.y));class xt{constructor(n="Curve"){this.type=n,this.arcLengthDivisions=200,this._lenCache=null}getPoint(n,o=new Ke){return o.set(0,0)}getPointAt(n,o){return this.getPoint(this.getUtoTMapping(n),o)}getPoints(n=5){let o=Math.max(1,Math.min(1024,Math.floor(ve(n,5)))),l=[];for(let g=0;g<=o;g++)l.push(this.getPoint(g/o));return l}getSpacedPoints(n=5){let o=Math.max(1,Math.min(1024,Math.floor(ve(n,5)))),l=[];for(let g=0;g<=o;g++)l.push(this.getPointAt(g/o));return l}getLength(){let n=this.getLengths();return n[n.length-1]||0}getLengths(n=this.arcLengthDivisions){let o=Math.max(1,Math.min(2048,Math.floor(ve(n,200))));if(this._lenCache&&this._lenCache.length===o+1)return this._lenCache;let l=[0],g=0,D=this.getPoint(0);for(let R=1;R<=o;R++){let U=this.getPoint(R/o);g+=Math.hypot(ve(U.x)-ve(D.x),ve(U.y)-ve(D.y),ve(U.z)-ve(D.z)),l.push(g),D=U}return o===this.arcLengthDivisions&&(this._lenCache=l),l}updateArcLengths(){this._lenCache=null,this.getLengths()}getUtoTMapping(n,o){let l=this.getLengths(),g=l.length,D=l[g-1]||0;if(D<=0||g<2)return st(n);let R=o!==void 0&&Number.isFinite(Number(o))?Math.max(0,Math.min(D,Number(o))):st(n)*D,U=0,B=g-1;for(;U<=B;){let te=U+B>>1,se=l[te]-R;if(se<0)U=te+1;else if(se>0)B=te-1;else return te/(g-1)}let W=Math.max(0,U-1),ne=l[W],re=(l[W+1]??D)-ne;return(W+(re>1e-12?(R-ne)/re:0))/(g-1)}getTangent(n,o){let l=st(n),g=this.getPoint(Math.max(0,l-1e-4)),D=this.getPoint(Math.min(1,l+1e-4)),R=ve(D.x)-ve(g.x),U=ve(D.y)-ve(g.y);if("z"in g||o?.isVector3){let W=ve(D.z)-ve(g.z),ne=Math.hypot(R,U,W)||1;return(o||new i).set(R/ne,U/ne,W/ne)}let B=Math.hypot(R,U)||1;return(o||new Ke).set(R/B,U/B)}getTangentAt(n,o){return this.getTangent(this.getUtoTMapping(n),o)}clone(){return new this.constructor().copy(this)}copy(n){if(!n||typeof n!="object")return this;let o=n,l=this;for(let g of Object.keys(o)){if(g==="type"||g.startsWith("is"))continue;if(g.startsWith("_")){l[g]=null;continue}let D=o[g];Array.isArray(D)?l[g]=D.map(R=>R?.clone?R.clone():R&&typeof R=="object"&&"x"in R?yt(R):R):D?.clone?l[g]=D.clone():D&&typeof D=="object"&&"x"in D?l[g]=yt(D):l[g]=D}return this}}class wt extends xt{constructor(n,o){super("LineCurve"),this.isLineCurve=!0,this.v1=yt(n),this.v2=yt(o)}getPoint(n,o=new Ke){let l=ve(n,0),g=ve(this.v1.x),D=ve(this.v1.y);return l===1?o.set(ve(this.v2.x),ve(this.v2.y)):o.set(g+(ve(this.v2.x)-g)*l,D+(ve(this.v2.y)-D)*l)}getPointAt(n,o=new Ke){return this.getPoint(st(n),o)}}class St extends xt{constructor(n,o,l){super("QuadraticBezierCurve"),this.isQuadraticBezierCurve=!0,this.v0=yt(n),this.v1=yt(o),this.v2=yt(l)}getPoint(n,o=new Ke){let l=st(n),g=1-l;return o.set(g*g*ve(this.v0.x)+2*g*l*ve(this.v1.x)+l*l*ve(this.v2.x),g*g*ve(this.v0.y)+2*g*l*ve(this.v1.y)+l*l*ve(this.v2.y))}}class Bt extends xt{constructor(n,o,l,g){super("CubicBezierCurve"),this.isCubicBezierCurve=!0,this.v0=yt(n),this.v1=yt(o),this.v2=yt(l),this.v3=yt(g)}getPoint(n,o=new Ke){let l=st(n),g=1-l,D=g*g,R=l*l;return o.set(D*g*ve(this.v0.x)+3*D*l*ve(this.v1.x)+3*g*R*ve(this.v2.x)+R*l*ve(this.v3.x),D*g*ve(this.v0.y)+3*D*l*ve(this.v1.y)+3*g*R*ve(this.v2.y)+R*l*ve(this.v3.y))}}class Rt extends xt{constructor(n=[]){super("SplineCurve"),this.isSplineCurve=!0,this.points=Array.isArray(n)?n:[]}getPoint(n,o=new Ke){let l=this.points,g=Array.isArray(l)?l.length:0;if(g===0)return o.set(0,0);if(g===1)return o.set(ve(l[0]?.x),ve(l[0]?.y));let D=(g-1)*st(n),R=Math.floor(D),U=D-R;R>=g-1&&(R=g-2,U=1);let B=l[R===0?0:R-1],W=l[R],ne=l[R+1],re=l[R>g-3?g-1:R+2],te=U*U,se=te*U,le=(pe,me,xe,de)=>.5*(2*me+(xe-pe)*U+(2*pe-5*me+4*xe-de)*te+(3*me-pe-3*xe+de)*se);return o.set(le(ve(B?.x),ve(W?.x),ve(ne?.x),ve(re?.x)),le(ve(B?.y),ve(W?.y),ve(ne?.y),ve(re?.y)))}}class jt extends xt{constructor(n=0,o=0,l=1,g=1,D=0,R=Math.PI*2,U=!1,B=0){super("EllipseCurve"),this.isEllipseCurve=!0,this.aX=ve(n,0),this.aY=ve(o,0),this.xRadius=ve(l,1),this.yRadius=ve(g,1),this.aStartAngle=ve(D,0),this.aEndAngle=ve(R,Math.PI*2),this.aClockwise=!!U,this.aRotation=ve(B,0)}getPoint(n,o=new Ke){let l=Math.PI*2,g=ve(this.aStartAngle,0),D=ve(this.aEndAngle,l)-g;Math.abs(D)>=1e-9?(D=(D%l+l)%l,D<1e-9&&(D=l),this.aClockwise&&(D=D===l?-l:D-l)):D=0;let R=g+st(n)*D,U=ve(this.xRadius,1)*Math.cos(R),B=ve(this.yRadius,1)*Math.sin(R),W=ve(this.aRotation,0),ne=Math.cos(W),re=Math.sin(W);return o.set(this.aX+U*ne-B*re,this.aY+U*re+B*ne)}}class Ht extends jt{constructor(n=0,o=0,l=1,g=0,D=Math.PI*2,R=!1){super(n,o,l,l,g,D,R,0),this.type="ArcCurve",this.isArcCurve=!0}}class Gt extends xt{constructor(){super("CurvePath"),this.isCurvePath=!0,this.curves=[],this.autoClose=!1,this._curveLens=null}add(n){return n&&typeof n.getPoint=="function"&&(this.curves.push(n),this._curveLens=null,this._lenCache=null),this}closePath(){if(this.curves.length===0)return this;let n=this.curves[0].getPoint(0),o=this.curves[this.curves.length-1].getPoint(1),l=!!(n&&("z"in n||n.isVector3));if(Math.hypot(ve(n?.x)-ve(o?.x),ve(n?.y)-ve(o?.y),l?ve(n?.z)-ve(o?.z):0)>1e-6){let g=t.LineCurve3;this.add(l&&g?new g(o,n):new wt(o,n))}return this}getCurveLengths(){if(this._curveLens&&this._curveLens.length===this.curves.length)return this._curveLens;let n=[],o=0;for(let l of this.curves){let g=0;if(typeof l?.getLength=="function")g=ve(l.getLength(),0);else if(typeof l?.getPoints=="function"){let D=l.getPoints(32);for(let R=1;R<D.length;R++)g+=Math.hypot(ve(D[R]?.x)-ve(D[R-1]?.x),ve(D[R]?.y)-ve(D[R-1]?.y),ve(D[R]?.z)-ve(D[R-1]?.z))}o+=g,n.push(o)}return this._curveLens=n,n}getLength(){let n=this.getCurveLengths();return n[n.length-1]||0}updateArcLengths(){this._curveLens=null,this._lenCache=null;for(let n of this.curves)n?.updateArcLengths?.();this.getCurveLengths()}getPoint(n,o){if(this.curves.length===0)return(o||new Ke).set(0,0);let l=this.getCurveLengths(),g=l[l.length-1]||0;if(g<=1e-12)return this.curves[0].getPoint(0,o);let D=st(n)*g;for(let R=0;R<l.length;R++)if(D<=l[R]||R===l.length-1){let U=R>0?l[R-1]:0,B=l[R]-U,W=B>1e-12?(D-U)/B:0,ne=this.curves[R];return typeof ne.getPointAt=="function"?ne.getPointAt(W,o):ne.getPoint(W,o)}return this.curves[this.curves.length-1].getPoint(1,o)}getPoints(n=12){let o=Math.max(1,Math.min(1024,Math.floor(ve(n,12)))),l=[],g=null;for(let D of this.curves){let R=D?.isEllipseCurve?o*2:D?.isLineCurve||D instanceof(t.LineCurve3||Function)?1:D?.isSplineCurve&&Array.isArray(D.points)?o*Math.max(1,D.points.length):o;for(let U of D.getPoints(Math.min(1024,R)))g&&Math.hypot(ve(g.x)-ve(U.x),ve(g.y)-ve(U.y),ve(g.z)-ve(U.z))<1e-6||(l.push(U),g=U)}if(this.autoClose&&l.length>1){let D=l[0];Math.hypot(ve(g.x)-ve(D.x),ve(g.y)-ve(D.y),ve(g.z)-ve(D.z))>1e-6&&l.push(D.clone?D.clone():D)}return l}getSpacedPoints(n=40){let o=Math.max(1,Math.min(1024,Math.floor(ve(n,40)))),l=[];for(let g=0;g<=o;g++)l.push(this.getPoint(g/o));return this.autoClose&&l.length>0&&l.push(l[0].clone?l[0].clone():l[0]),l}}let Kt=t.BufferAttribute,ui=t.Object3D,Ii=t.Line,Wt=t.LineSegments,qt=t.LineBasicMaterial,Vi=t.MeshBasicMaterial,Pi=t.ConeGeometry,ci=t.Color,ei=(u,n,o,l)=>{u.name=n.name,u.position.copy(n.position),u.quaternion.copy(n.quaternion),u.scale.copy(n.scale),u.visible=n.visible,u.castShadow=n.castShadow,u.receiveShadow=n.receiveShadow;try{u.userData=JSON.parse(JSON.stringify(n.userData||{}))}catch{u.userData={...n.userData||{}}}if(l&&Array.isArray(n.children))for(let g=o;g<n.children.length;g++)u.add(n.children[g].clone(!0));return u},Ut=u=>{let n=new s;return n.setAttribute("position",new Kt(new Float32Array(u),3)),n.__isSegmentPairs=!0,n},Vn=[0,1,1,3,3,2,2,0,4,5,5,7,7,6,6,4,0,4,1,5,3,7,2,6],cr=(u,n,o,l,g,D)=>{if(!Number.isFinite(u+n+o+l+g+D)||l<u||g<n||D<o)return new s;let R=[];for(let U of Vn)R.push(U&1?l:u,U&2?g:n,U&4?D:o);return Ut(R)};class Hi extends Wt{constructor(n=10,o=10,l=4473924,g=8947848){let D=Math.max(1e-4,Math.abs(ve(n,10))),R=Math.max(1,Math.min(256,Math.floor(ve(o,10)))),U=new ci(l??4473924),B=new ci(g??8947848),W=D*.5,ne=D/R,re=R%2===0&&U.getHex()!==B.getHex()?R>>1:-1,te=[],se=[];for(let le=0,pe=-W;le<=R;le++,pe+=ne)(le===re?se:te).push(-W,0,pe,W,0,pe,pe,0,-W,pe,0,W);if(super(Ut(te.length?te:se),new qt({color:te.length?B:U})),this.type="GridHelper",this.isGridHelper=!0,this._size=D,this._divisions=R,this._internalKids=0,se.length&&te.length){let le=new Wt(Ut(se),new qt({color:U}));this._centerLines=le,this._internalKids=1,this.add(le)}}_bakeAuthorGeometry(){this._centerLines?.material&&this.material&&(this._centerLines.material.transparent=this.material.transparent,this._centerLines.material.opacity=this.material.opacity),super._bakeAuthorGeometry()}clone(n=!0){let o=new Hi(this._size,this._divisions,this._centerLines?this._centerLines.material.color:this.material.color,this.material.color);return o.material.transparent=this.material.transparent,o.material.opacity=this.material.opacity,ei(o,this,this._internalKids,n)}dispose(){}}class xi extends Wt{constructor(n=1){let o=Math.max(1e-4,Math.abs(ve(n,1)));super(Ut([0,0,0,o,0,0]),new qt({color:16724736})),this.type="AxesHelper",this.isAxesHelper=!0,this._size=o,this._yAxis=new Wt(Ut([0,0,0,0,o,0]),new qt({color:3407616})),this._zAxis=new Wt(Ut([0,0,0,0,0,o]),new qt({color:35071})),this.add(this._yAxis),this.add(this._zAxis)}setColors(n,o,l){return this.material.color.set(n),this._yAxis.material.color.set(o),this._zAxis.material.color.set(l),this}_bakeAuthorGeometry(){for(let n of[this._yAxis,this._zAxis])n?.material&&this.material&&(n.material.transparent=this.material.transparent,n.material.opacity=this.material.opacity);super._bakeAuthorGeometry()}clone(n=!0){let o=new xi(this._size).setColors(this.material.color,this._yAxis.material.color,this._zAxis.material.color);return o.material.transparent=this.material.transparent,o.material.opacity=this.material.opacity,ei(o,this,2,n)}dispose(){}}class vi extends ui{constructor(n=new i(0,0,1),o=new i(0,0,0),l=1,g=16776960,D,R){super(),this.type="ArrowHelper",this.isArrowHelper=!0,this.position.set(ve(o?.x),ve(o?.y),ve(o?.z));let U=new s;U.setAttribute("position",new Kt(new Float32Array([0,0,0,0,1,0]),3)),this.line=new Ii(U,new qt({color:g})),this.cone=new zt(new Pi(.5,1,8).translate(0,-.5,0),new Vi({color:g})),this.add(this.line),this.add(this.cone),this.setDirection(n).setLength(l,D,R)}setDirection(n){let o=ve(n?.x,0),l=ve(n?.y,0),g=ve(n?.z,1),D=Math.hypot(o,l,g),R=D>1e-9?o/D:0,U=D>1e-9?l/D:1,B=D>1e-9?g/D:0;return U>.99999?this.quaternion.set(0,0,0,1):U<-.99999?this.quaternion.set(1,0,0,0):this.quaternion.setFromAxisAngle(new i(B,0,-R).normalize(),Math.acos(Math.max(-1,Math.min(1,U)))),this}setLength(n,o,l){let g=Math.max(1e-4,Math.abs(ve(n,1))),D=o!==void 0&&Number.isFinite(Number(o))?Math.max(1e-4,Math.abs(Number(o))):.2*g,R=l!==void 0&&Number.isFinite(Number(l))?Math.max(1e-4,Math.abs(Number(l))):.2*D;return this.line.scale.set(1,Math.max(1e-4,g-D),1),this.line.updateMatrix?.(),this.cone.scale.set(R,D,R),this.cone.position.set(0,g,0),this.cone.updateMatrix?.(),this}setColor(n){return this.line.material.color.set(n),this.cone.material.color.set(n),this}clone(n=!0){let o=new vi;return o.line.scale.copy(this.line.scale),o.cone.scale.copy(this.cone.scale),o.cone.position.copy(this.cone.position),o.setColor(this.cone.material.color),o.line.material.transparent=this.line.material.transparent,o.line.material.opacity=this.line.material.opacity,o.cone.material.transparent=this.cone.material.transparent,o.cone.material.opacity=this.cone.material.opacity,ei(o,this,2,n)}dispose(){}}class Mi extends Wt{constructor(n=new a,o=16776960){let l=n instanceof a?n:new a(n?.min,n?.max);super(l.isEmpty()?new s:cr(l.min.x,l.min.y,l.min.z,l.max.x,l.max.y,l.max.z),new qt({color:o})),this.type="Box3Helper",this.isBox3Helper=!0,this.box=l}_bakeAuthorGeometry(){let n=this.box,o=!n||n.isEmpty()?new s:cr(n.min.x,n.min.y,n.min.z,n.max.x,n.max.y,n.max.z);this._sourceGeo=o,this.geometry=o,super._bakeAuthorGeometry()}clone(n=!0){let o=new Mi(this.box.clone(),this.material.color);return o.material.transparent=this.material.transparent,o.material.opacity=this.material.opacity,ei(o,this,0,n)}dispose(){}}class Ui extends Wt{constructor(n,o=16776960){super(new s,new qt({color:o})),this.type="BoxHelper",this.isBoxHelper=!0,this.object=n,n&&this.update()}update(n){n!==void 0&&(this.object=n);let o=new a;this.object&&this.object!==this&&o.setFromObject(this.object);let l=o.isEmpty()?new s:cr(o.min.x,o.min.y,o.min.z,o.max.x,o.max.y,o.max.z);return this.position.set(0,0,0),this.quaternion.set(0,0,0,1),this.scale.set(1,1,1),this._sourceGeo=l,this.geometry=l,this}setFromObject(n){return this.update(n)}_bakeAuthorGeometry(){this.update(),super._bakeAuthorGeometry()}clone(n=!0){let o=new Ui(this.object,this.material.color);return o.material.transparent=this.material.transparent,o.material.opacity=this.material.opacity,ei(o,this,0,n)}dispose(){}}for(let u of[xt,wt,St,Bt,Rt,jt,Ht,Gt,Hi,xi,vi,Mi,Ui])Object.freeze(u.prototype);let ti=["checkerboard","grid","wood","marble","brushedMetal","carbonFiber","concrete","brick","fabric","leather","rust"],fr=[[8,3359061,14870768,.6],[8,16317180,6583435,.7],[10,9132587,0,.6],[3,15857145,4674921,.25],[1,12106946,0,.32],[8,2040616,0,.35],[4,10265519,0,.9],[8,10107694,13157048,.85],[32,3890060,0,.9],[12,5913128,0,.6],[4,9124378,9080985,.9]],Jr=(u,n,o)=>{let l=Math.imul(u,668265261)^Math.imul(n,374761393)^Math.imul(o,2654435769);return l^=l>>>15,l=Math.imul(l,2246822507),l^=l>>>13,l=Math.imul(l,3266489909),l^=l>>>16,l>>>0},fi=(u,n,o)=>Jr(u,n,o)/4294967296,ii=(u,n)=>(u%n+n)%n,ja=(u,n,o,l,g)=>{let D=Math.floor(u),R=Math.floor(n),U=u-D,B=n-R,W=ii(D,o),ne=ii(R,l),re=(W+1)%o,te=(ne+1)%l,se=U*U*(3-2*U),le=B*B*(3-2*B),pe=fi(W,ne,g),me=fi(re,ne,g),xe=fi(W,te,g),de=fi(re,te,g);return pe+(me-pe)*se+(xe-pe)*le+(pe-me-xe+de)*se*le},Si=(u,n,o,l,g,D)=>{let R=0,U=.5,B=0,W=1;for(let ne=0;ne<g;ne++){let re=o*W,te=l*W;R+=U*ja(u*re,n*te,re,te,D+ne>>>0),B+=U,U*=.5,W*=2}return R/B},Hn=u=>u-Math.floor(u),Gn=u=>Math.abs(Hn(u)*2-1),pr=(u,n,o)=>{let l=(o-u)/(n-u);return l<0?l=0:l>1&&(l=1),l*l*(3-2*l)},pi=(u,n,o)=>u+(n-u)*o,Ai=u=>u<=0?0:u>=1?255:Math.floor(u*255+.5),Dh=(u,n,o,l,g,D,R,U,B,W,ne)=>{let re=de=>[g[0]*de,g[1]*de,g[2]*de],te=(de,ce,we)=>[pi(de[0],ce[0],we),pi(de[1],ce[1],we),pi(de[2],ce[2],we)];if(u===0){let de=ii(Math.floor(U*o)+Math.floor(B*o),2)===1?D:g;return[de[0],de[1],de[2],.5,R,0]}if(u===1){let de=Hn(U*o),ce=Hn(B*o),we=Math.max(.035,o/n),Te=1-pr(we*.5,we,Math.min(de,1-de,ce,1-ce));return[...te(g,D,Te),.3+.4*Te,R,0]}if(u===2){let de=Si(U,B,4,4,4,l),ce=Gn(B*o+de*1.5),we=Si(U,B,2,96,2,l+7>>>0),Te=ce*.7+we*.3;return[...re(pi(.55,1,Te)),Te,R+(1-Te)*.15,0]}if(u===3){let de=Si(U,B,3,3,5,l),ce=Gn((U+B)*o+de*2.5),we=ce*ce,Te=we*we,Ee=Te*Te,Re=.92+.08*de,We=te(g,D,Ee*.85);return[We[0]*Re,We[1]*Re,We[2]*Re,.5-Ee*.2,R+Ee*.1,0]}if(u===4){let de=Si(U,B,2,192*o,2,l),ce=fi(W,ne,l+3>>>0);return[...re(.85+.12*de+.03*ce),.35+de*.3,R+(de-.5)*.12,1]}if(u===5){let de=o*2,ce=U*de,we=B*de,Te=ce-Math.floor(ce),Ee=we-Math.floor(we),Re=ii(Math.floor(ce)+Math.floor(we),2)===0,We=Re?Ee*2-1:Te*2-1,Xe=1-We*We,et=.08*Gn(Re?Ee*8:Te*8),Ze=.6+.4*Xe;return[g[0]*Ze+et,g[1]*Ze+et,g[2]*Ze+et,Xe*.8,R+.1*(1-Xe),0]}if(u===6){let de=Si(U,B,o,o,5,l),ce=fi(W,ne,l+31>>>0),we=o*16,Te=pr(.82,.9,ja(U*we,B*we,we,we,l+17>>>0));return[...re((.82+.25*de+.06*(ce-.5))*(1-.35*Te)),.5+.25*(de-.5)-.3*Te,R-.05*de,0]}if(u===7){let de=Math.floor(o/2),ce=B*o,we=Math.floor(ce),Te=ce-we,Ee=U*de+(ii(we,2)===1?.5:0),Re=Math.floor(Ee),We=Ee-Re,Xe=Math.min(Math.min(We,1-We)*2,Math.min(Te,1-Te)),et=Math.max(.06,1.5*o/n),Ze=1-pr(et*.5,et,Xe),tt=fi(ii(Re,de),ii(we,o),l),Ue=Si(U,B,o,o,3,l+5>>>0),Ye=.8+.25*tt+.15*(Ue-.5),it=.9+.1*Ue;return[pi(g[0]*Ye,D[0]*it,Ze),pi(g[1]*Ye,D[1]*it,Ze),pi(g[2]*Ye,D[2]*it,Ze),(1-Ze)*(.75+.1*Ue)+Ze*.2,pi(R,.95,Ze),0]}if(u===8){let de=U*o,ce=B*o,we=(de-Math.floor(de))*2-1,Te=(ce-Math.floor(ce))*2-1,Ee=ii(Math.floor(de)+Math.floor(ce),2)===0?1-we*we:1-Te*Te,Re=Si(U,B,4,4,2,l);return[...re((.75+.25*Ee)*(.95+.1*(Re-.5))),Ee,R,0]}if(u===9){let de=U*o,ce=B*o,we=Math.floor(de),Te=Math.floor(ce),Ee=1e9,Re=1e9;for(let et=-1;et<=1;et++)for(let Ze=-1;Ze<=1;Ze++){let tt=we+Ze,Ue=Te+et,Ye=ii(tt,o),it=ii(Ue,o),dt=tt+fi(Ye,it,l)-de,ct=Ue+fi(Ye,it,l+1>>>0)-ce,ot=dt*dt+ct*ct;ot<Ee?(Re=Ee,Ee=ot):ot<Re&&(Re=ot)}let We=1-pr(0,.12,Math.sqrt(Re)-Math.sqrt(Ee)),Xe=Si(U,B,4,4,3,l+3>>>0);return[...re((.85+.2*(Xe-.5))*(1-.3*We)),.6-.4*We+.1*(Xe-.5),R+.15*We,0]}let se=Si(U,B,o,o,5,l),le=pr(.45,.6,se),pe=Si(U,B,o*8,o*8,3,l+9>>>0),me=.9+.1*pe,xe=.7+.5*pe;return[pi(D[0]*me,g[0]*xe,le),pi(D[1]*me,g[1]*xe,le),pi(D[2]*me,g[2]*xe,le),.4+.4*le*pe+.1*le,pi(.35,R,le),1-le]},$h=(u,n,o,l,g,D,R,U)=>{let B=globalThis.__three_live_native_material_preset__;if(typeof B=="function"){let te=B(u,n,o,l,...g,...D,R,U);if(Array.isArray(te)&&te.length===3)return te}let W=new Uint8Array(n*n*4),ne=new Uint8Array(n*n*4),re=new Float64Array(n*n);for(let te=0;te<n;te++){let se=(te+.5)/n;for(let le=0;le<n;le++){let pe=Dh(u,n,o,l,g,D,R,(le+.5)/n,se,le,te),me=(te*n+le)*4;W[me]=Ai(pe[0]),W[me+1]=Ai(pe[1]),W[me+2]=Ai(pe[2]),W[me+3]=255,ne[me]=255,ne[me+1]=Ai(pe[4]),ne[me+2]=Ai(pe[5]),ne[me+3]=255,re[te*n+le]=pe[3]}}return[W,Va(re,n,U),ne]},Va=(u,n,o)=>{let l=new Uint8Array(n*n*4),g=o*n*.0625;for(let D=0;D<n;D++){let R=(D+n-1)%n,U=(D+1)%n;for(let B=0;B<n;B++){let W=-(u[D*n+(B+1)%n]-u[D*n+(B+n-1)%n])*g,ne=(u[U*n+B]-u[R*n+B])*g,re=1/Math.sqrt(W*W+ne*ne+1),te=(D*n+B)*4;l[te]=Ai(W*re*.5+.5),l[te+1]=Ai(ne*re*.5+.5),l[te+2]=Ai(re*.5+.5),l[te+3]=255}}return l},Ha=(u,n)=>{let o=n;try{u!=null&&(o=new ci(u).getHex())}catch{}return[(o>>16&255)/255,(o>>8&255)/255,(o&255)/255]},Zr=new Map,Wn=(u,n={})=>{let o=ti.indexOf(u);if(o<0)throw new TypeError(`THREE.ProceduralTexture: unknown preset '${u}' (use ${ti.join(", ")})`);let l=n&&typeof n=="object"?n:{},g=fr[o],D=Math.max(1,Math.min(256,Math.round(ve(l.scale,g[0]))));(o===0||o===7||o===8)&&D%2===1&&D++;let R=Math.max(16,Math.min(512,Math.round(ve(l.size,256)))),U=Math.round(Math.abs(ve(l.seed,1)))>>>0,B=Ha(l.color,g[1]),W=Ha(l.color2,g[2]||g[1]),ne=st(ve(l.roughness,g[3])),re=Math.max(0,Math.min(8,ve(l.normalStrength,1))),te=[o,R,D,U,...B,...W,ne,re].join(","),se=Zr.get(te);if(se)return{...se};let[le,pe,me]=$h(o,R,D,U,B,W,ne,re),xe=(we,Te)=>{let Ee=new Me(R,R);Ee._data.set(we),Ee._ver++;let Re=new J(Ee);return Re.flipY=!1,Re.colorSpace=Te,Re.name=`${u}_${Te==="srgb"?"albedo":we===pe?"normal":"orm"}`,Re},de=xe(me,"srgb-linear"),ce={map:xe(le,"srgb")};return re>0&&(ce.normalMap=xe(pe,"srgb-linear")),ce.roughnessMap=de,ce.metalnessMap=de,Zr.size>=64&&Zr.clear(),Zr.set(te,ce),{...ce}},qn={presets:Object.freeze(ti.slice()),create:(u,n)=>Wn(String(u),n)};for(let u of ti)qn[u]=n=>Wn(u,n);Object.freeze(qn);let zh=500,kh=u=>{if(typeof u!="string")return null;let n="",o=!1;for(let l=0;l<u.length;l++){let g=u.charCodeAt(l);if(g<=32||g===127){o=n.length>0;continue}o&&(n+=" ",o=!1),n+=u[l]}return n.length===0||n.length>zh?null:n},Eh=u=>{let n=typeof u=="number"?u:NaN;return Number.isFinite(n)?n<=384?256:n<=768?512:1024:512},Ga=u=>u>512&&u%2===0?u/2:u,Fh=(u,n)=>{let o=n/2,l=new Uint8Array(o*o*4);for(let g=0;g<o;g++)for(let D=0;D<o;D++){let R=(2*g*n+2*D)*4,U=R+n*4,B=(g*o+D)*4;for(let W=0;W<4;W++)l[B+W]=u[R+W]+u[R+4+W]+u[U+W]+u[U+4+W]+2>>2}return l},Rh=u=>{let n=typeof u=="number"?u:NaN,o=Number.isFinite(n)?Math.abs(n):1;return Math.floor(o+.5)%4294967296},Ih=u=>{let n=[];for(let o=0;o<u.length;o++){let l=u.charCodeAt(o);if(l>=55296&&l<=56319&&o+1<u.length){let g=u.charCodeAt(o+1);g>=56320&&g<=57343?(l=65536+(l-55296<<10)+(g-56320),o++):l=65533}else l>=55296&&l<=57343&&(l=65533);l<128?n.push(l):l<2048?n.push(192|l>>6,128|l&63):l<65536?n.push(224|l>>12,128|l>>6&63,128|l&63):n.push(240|l>>18,128|l>>12&63,128|l>>6&63,128|l&63)}return n},Uh=(u,n,o)=>{let l=Ih(`three-live-texture1${u}${n}${o}`),g=3421674724,D=2216829733;for(let R of l){D=(D^R)>>>0;let U=D&65535,B=D>>>16,W=U*435,ne=B*435+(W>>>16),re=(ne&65535)<<16|W&65535,te=Math.floor(ne/65536);g=Math.imul(g,435)+te+(D<<8>>>0)>>>0,D=re>>>0}return g.toString(16).padStart(8,"0")+D.toString(16).padStart(8,"0")},Wa=u=>{let n=kh(u?.prompt);if(n===null)return null;let o=Eh(u?.size),l=Rh(u?.seed);return{prompt:n,size:o,seed:l,key:Uh(n,o,l)}},Xn=(u,n,o,l,g)=>{if(Ga(n)!==n)return Xn(Fh(u,n),n/2,o,l,g);let D=new Float64Array(n*n);for(let ce=0;ce<n*n;ce++){let we=ce*4;D[ce]=2126*u[we]+7152*u[we+1]+722*u[we+2]}let R=Math.min(4,Math.floor((n-1)/2)),U=new Float64Array(n*n);for(let ce=0;ce<n;ce++)for(let we=0;we<n;we++){let Te=0;for(let Ee=0;Ee<=2*R;Ee++)Te+=D[ce*n+(we+n+Ee-R)%n];U[ce*n+we]=Te}let B=(2*R+1)*(2*R+1),W=new Float64Array(n*n),ne=1/0,re=-1/0;for(let ce=0;ce<n;ce++)for(let we=0;we<n;we++){let Te=0;for(let Re=0;Re<=2*R;Re++)Te+=U[(ce+n+Re-R)%n*n+we];let Ee=B*D[ce*n+we]-Te;W[ce*n+we]=Ee,Ee<ne&&(ne=Ee),Ee>re&&(re=Ee)}let te=re-ne,se=new Float64Array(n*n);for(let ce=0;ce<n*n;ce++)se[ce]=te===0?.5:(W[ce]-ne)/te;let le=Number.isFinite(o)?Math.max(0,Math.min(8,o)):1,pe=Va(se,n,le),me=Number.isFinite(l)?Math.max(0,Math.min(1,l)):0,xe=Ai(Number.isFinite(g)?Math.max(0,Math.min(1,g)):0),de=new Uint8Array(n*n*4);for(let ce=0;ce<n*n;ce++){let we=ce*4;de[we]=255,de[we+1]=Ai(me+.35*(.5-se[ce])),de[we+2]=xe,de[we+3]=255}return[pe,de]},Qr=new Map,qa=new WeakMap,Oh=0,Bh=(u,n)=>{let o=Wa(u);if(!o)return null;let{prompt:l,size:g,seed:D,key:R}=o,U=st(ve(u.roughness,n>=0?fr[n][3]:.8)),B=st(ve(u.metalness,0)),W=Math.max(0,Math.min(8,ve(u.normalStrength,1))),ne=globalThis,re=ne.__three_live_native_texture_pack__,te=ne.__three_live_texture_pack__,se=0;if(typeof re=="function"){let Te=ne.__three_live_native_texture_pack_token__;se=typeof Te=="function"&&Number(Te())||0}else te&&typeof te=="object"&&(se=qa.get(te)??0,se||qa.set(te,se=++Oh));let le=[se,R,W,U,B].join(","),pe=se?Qr.get(le):void 0;if(pe)return{...pe};let me=null;if(typeof re=="function"){let Te=re(l,g,D,W,U,B);Array.isArray(Te)&&Te.length===3&&(me=Te)}else{let Te=te&&typeof te=="object"&&Object.prototype.hasOwnProperty.call(te,R)?te[R]:null;Te&&Te.size===g&&Te.rgba instanceof Uint8Array&&Te.rgba.length===g*g*4&&(me=[Te.rgba,...Xn(Te.rgba,g,W,U,B)])}if(!me)return null;let xe=(Te,Ee,Re,We)=>{let Xe=new J({data:new Uint8ClampedArray(Te.buffer,Te.byteOffset,Ee*Ee*4),width:Ee,height:Ee});return Xe.flipY=!1,Xe.colorSpace=Re,Xe.name=`ai_${R}_${We}`,Xe._pngDim=Ee,Xe},de=Ga(g),ce=xe(me[2],de,"srgb-linear","orm"),we={map:xe(me[0],g,"srgb","albedo")};return W>0&&(we.normalMap=xe(me[1],de,"srgb-linear","normal")),we.roughnessMap=ce,we.metalnessMap=ce,se&&(Qr.size>=32&&Qr.clear(),Qr.set(le,we)),{...we}},Xa=new Set,jh=u=>{let n=u?.userData?.xr?.material,o=u?.material;if(n==null||!o||typeof o!="object"||Array.isArray(o))return;let l=typeof n=="string"?{preset:n}:typeof n=="object"?n:null,g=String(l?.preset??l?.type??""),D=ti.indexOf(g),R=!!l&&l.prompt!==void 0&&l.prompt!==null,U=R?Bh(l,D):null;if(!l||D<0&&!U){!(R&&g==="")&&!Xa.has(g)&&(Xa.add(g),console.warn(`[three-live] userData.xr.material: unknown preset '${g}' (use ${ti.join(", ")}).`));return}o._presetTint===void 0&&(o._presetTint=o.color?.getHex?.()??16777215);let B="";try{B=JSON.stringify([l,o._presetTint])}catch{B=g}if(o._presetKey===B)return;if(o._presetOwner&&o._presetOwner!==u){let re=Object.assign(Object.create(Object.getPrototypeOf(o)),o);re.color=new ci(o._presetTint);for(let te of["_presetKey","_presetMaps","_presetOwner"])re[te]=void 0;for(let te of["map","normalMap","roughnessMap","metalnessMap"])o._presetMaps?.[te]&&re[te]===o._presetMaps[te]&&(re[te]=null);u.material=o=re}let W=U??Wn(g,{...l,color:l.color??(o._presetTint===16777215?void 0:o._presetTint)}),ne=o._presetMaps||{};for(let re of["map","normalMap","roughnessMap","metalnessMap"])(!o[re]||o[re]===ne[re])&&(o[re]=W[re]??null,ne[re]=W[re]??null);ne.map===o.map&&o.color?.set?.(16777215),ne.roughnessMap===o.roughnessMap&&(o.roughness=1),ne.metalnessMap===o.metalnessMap&&(o.metalness=1),o._presetMaps=ne,o._presetKey=B,o._presetOwner=u},Ya={Box3:a,Sphere:c,CanvasTexture:J,ImprovedNoise:ue,SimplexNoise:Oe,SpriteMaterial:bt,Sprite:It,LineCurve:wt,QuadraticBezierCurve:St,CubicBezierCurve:Bt,SplineCurve:Rt,EllipseCurve:jt,ArcCurve:Ht,CurvePath:Gt,GridHelper:Hi,AxesHelper:xi,ArrowHelper:vi,Box3Helper:Mi,BoxHelper:Ui,ProceduralTexture:qn};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,Ya),e.createCanvas=j,e._procMaterialize=jh,e.canonicalTextureSpec=Wa,e.deriveTextureMaps=Xn,e.encodeRgbaPngDataUri=(u,n,o)=>w(u,n,o,!1,!1,d).uri,e.materializeDeclarativeGeometry=u=>{e._cadMaterialize?.(u),e._lodMaterialize?.(u),e._procMaterialize?.(u)}),Ya}function is(t){if(typeof t!="function")return null;let e=new Uint32Array(256);for(let m=0;m<256;m++){let y=m;for(let z=0;z<8;z++)y=y&1?3988292384^y>>>1:y>>>1;e[m]=y>>>0}let i=(m,y,z)=>{let E=4294967295;for(let _=y;_<z;_++)E=e[(E^m[_])&255]^E>>>8;return(E^4294967295)>>>0},r=(m,y)=>(m[y]<<24|m[y+1]<<16|m[y+2]<<8|m[y+3])>>>0,s=(m,y,z)=>{m[y]=z>>>24,m[y+1]=z>>>16&255,m[y+2]=z>>>8&255,m[y+3]=z&255},a=m=>{let y=new t("deflate"),z=y.writable.getWriter();z.write(m).catch(()=>{}),z.close().catch(()=>{});let E=y.readable.getReader(),_=[],b=0,$=()=>E.read().then(T=>{if(T.done){let M=new Uint8Array(b),N=0;for(let k=0;k<_.length;k++)M.set(_[k],N),N+=_[k].length;return M}return T.value&&(_.push(T.value),b+=T.value.length),$()});return $()},f=m=>{if(m.length<45||r(m,0)!==2303741511||r(m,12)!==1229472850)return null;let y=r(m,16),z=r(m,20);if(m[24]!==8||m[25]!==6||m[28]!==0||!y||!z||y>4096||z>4096)return null;let E=1+y*4,_=new Uint8Array(E*z),b=0,$=33,T=-2,M=0,N=[],k=!1;for(;$+8<=m.length&&!k;){let A=r(m,$),S=r(m,$+4),w=$+8,v=w+A;if(v+4>m.length)return null;if(S===1229209940)for(let P=w;P<v&&!k;){if(T<0)T++,P++;else if(M>0){let H=Math.min(M,v-P);if(b+H>_.length)return null;_.set(m.subarray(P,P+H),b),b+=H,P+=H,M-=H,M===0&&N[0]&1&&(k=!0)}else{if(N.push(m[P++]),N.length===1&&N[0]>>1&3)return null;if(N.length===5){let H=N[1]|N[2]<<8;if((H^(N[3]|N[4]<<8))!==65535)return null;M=H,H===0&&(N[0]&1&&(k=!0),N=[])}}M===0&&N.length===5&&(N=[])}else if(S===1229278788)break;$=v+4}if(b!==_.length)return null;for(let A=0;A<z;A++)if(_[A*E]!==0)return null;return{w:y,h:z,raw:_}},c=(m,y,z)=>{let E=y*4,_=E+1,b=new Uint8Array(m.length),$=new Uint8Array(E),T=new Uint8Array(E);for(let M=0;M<z;M++){let N=M*_+1,k=N-_,A=0,S=1/0;for(let w=0;w<5;w++){if(w===3||(w===2||w===4)&&M===0)continue;let v=0;for(let P=0;P<E;P++){let H=P>=4?m[N+P-4]:0,G=M>0?m[k+P]:0,x=0;if(w===1)x=H;else if(w===2)x=G;else if(w===4){let Y=P>=4&&M>0?m[k+P-4]:0,Z=H+G-Y,q=Math.abs(Z-H),X=Math.abs(Z-G),F=Math.abs(Z-Y);x=q<=X&&q<=F?H:X<=F?G:Y}let V=m[N+P]-x&255;$[P]=V,v+=V<128?V:256-V}v<S&&(S=v,A=w,T.set($))}b[M*_]=A,b.set(T,N)}return b},h=m=>{let y=null;try{y=f(m)}catch{y=null}if(!y)return Promise.resolve(m);let{w:z,h:E,raw:_}=y;return a(c(_,z,E)).then(b=>{let $=45+b.length+12;if($>=m.length)return m;let T=new Uint8Array($);T.set(m.subarray(0,33),0),s(T,33,b.length),s(T,37,1229209940),T.set(b,41),s(T,41+b.length,i(T,37,41+b.length));let M=45+b.length;return s(T,M,0),s(T,M+4,1229278788),s(T,M+8,2923585666),T},()=>m)},C=new Int16Array(128).fill(-1),d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let m=0;m<64;m++)C[d.charCodeAt(m)]=m;let p=m=>{let y=m.length;for(;y>0&&m.charCodeAt(y-1)===61;)y--;let z=new Uint8Array(Math.floor(y*3/4)),E=0,_=0,b=0;for(let $=0;$<y;$++){let T=m.charCodeAt($),M=T<128?C[T]:-1;if(M<0)return null;E=(E<<6|M)&16777215,_+=6,_>=8&&(_-=8,z[b++]=E>>_&255)}return b===z.length?z:null};return{png:h,glb:m=>{let y=(P,H)=>(P[H]|P[H+1]<<8|P[H+2]<<16|P[H+3]<<24)>>>0,z=(P,H,G)=>{P[H]=G&255,P[H+1]=G>>>8&255,P[H+2]=G>>>16&255,P[H+3]=G>>>24},E,_=new Uint8Array(0);try{if(m.length<20||y(m,0)!==1179937895)return Promise.resolve(m);let P=Math.min(m.length,y(m,8)),H=y(m,12);if(y(m,16)!==1313821514||20+H>P)return Promise.resolve(m);E=JSON.parse(new TextDecoder().decode(m.subarray(20,20+H)));let G=20+H;if(G+8<=P){let x=y(m,G);if(y(m,G+4)!==5130562||G+8+x>P)return Promise.resolve(m);_=m.subarray(G+8,G+8+x)}}catch{return Promise.resolve(m)}if(!E||typeof E!="object")return Promise.resolve(m);let b=Array.isArray(E.bufferViews)?E.bufferViews:[],$=Array.isArray(E.images)?E.images:[],T=[],M=[],N=[],k="data:image/png;base64,";for(let P=0;P<$.length;P++){let H=$[P];if(!H||typeof H!="object")continue;let G=b[H.bufferView];if(typeof H.uri=="string"&&H.uri.indexOf(k)===0){let x=p(H.uri.slice(k.length));x&&(M.push(P),N.push(x))}else H.mimeType==="image/png"&&G&&(G.buffer||0)===0&&T.indexOf(H.bufferView)<0&&T.push(H.bufferView)}if(!T.length&&!M.length)return Promise.resolve(m);let A=[];for(let P=0;P<b.length;P++)A.push(P);A.sort((P,H)=>(b[P].byteOffset||0)-(b[H].byteOffset||0));let S=0;for(let P=0;P<A.length;P++){let H=b[A[P]],G=H.byteOffset||0;if(typeof H.byteLength!="number"||(H.buffer||0)!==0||G<S||G+H.byteLength>_.length)return Promise.resolve(m);S=G+H.byteLength}let w=P=>{let H=b[P].byteOffset||0;return _.subarray(H,H+b[P].byteLength)},v=[];for(let P=0;P<T.length;P++)v.push(h(w(T[P])));for(let P=0;P<N.length;P++)v.push(h(N[P]));return Promise.all(v).then(P=>{let H=[];for(let F=0;F<b.length;F++){let Q=T.indexOf(F);H.push(Q>=0?P[Q]:w(F))}let G=0;for(let F=0;F<A.length;F++)G=(G+3&-4)+H[A[F]].length;for(let F=0;F<M.length;F++)G=(G+3&-4)+P[T.length+F].length;let x=G+3&-4,V=new Uint8Array(x),Y=0;for(let F=0;F<A.length;F++){let Q=A[F];Y=Y+3&-4,V.set(H[Q],Y),b[Q].byteOffset=Y,b[Q].byteLength=H[Q].length,Y+=H[Q].length}for(let F=0;F<M.length;F++){let Q=P[T.length+F];Y=Y+3&-4,V.set(Q,Y);let L=$[M[F]];delete L.uri,L.mimeType="image/png",L.bufferView=b.length,b.push({buffer:0,byteOffset:Y,byteLength:Q.length}),Y+=Q.length}E.bufferViews=b,!Array.isArray(E.buffers)||!E.buffers.length?E.buffers=[{byteLength:x}]:E.buffers[0].byteLength=x;let Z=new TextEncoder().encode(JSON.stringify(E)),q=Z.length+3&-4;if(q!==Z.length){let F=new Uint8Array(q).fill(32);F.set(Z),Z=F}let X=new Uint8Array(20+q+8+x);return z(X,0,1179937895),z(X,4,2),z(X,8,X.length),z(X,12,q),z(X,16,1313821514),X.set(Z,20),z(X,20+q,x),z(X,24+q,5130562),X.set(V,28+q),X.length<m.length?X:m})}}}var To={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function rs(t,e,i,r){if(!i||i.bufferView===void 0)return null;let s=t.bufferViews?.[i.bufferView];if(!s)return null;let a=Number(i.count??0);if(!Number.isInteger(a)||a<=0)return null;let f=i.componentType??5126,c=To[f];if(!c)throw new RangeError(`glTF accessor has unsupported componentType ${f}`);let h=c*r,C=s.byteStride&&s.byteStride>0?s.byteStride:h,d=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(d)||d<0||C<h||d+(a-1)*C+h>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(f===5126&&C===h&&d%4===0)return new Float32Array(e,d,a*r);let p=new DataView(e),m=i.normalized===!0,y=new Float32Array(a*r);for(let z=0;z<a;z++){let E=d+z*C;for(let _=0;_<r;_++){let b=E+_*c,$;switch(f){case 5126:$=p.getFloat32(b,!0);break;case 5120:$=p.getInt8(b),m&&($=Math.max($/127,-1));break;case 5121:$=p.getUint8(b),m&&($/=255);break;case 5122:$=p.getInt16(b,!0),m&&($=Math.max($/32767,-1));break;case 5123:$=p.getUint16(b,!0),m&&($/=65535);break;default:$=p.getUint32(b,!0),m&&($/=4294967295)}y[z*r+_]=$}}return y}function No(t,e){let i=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,s=Number(e.scale?.[0]??1),a=Number(e.scale?.[1]??1),f=Number(e.rotation??0)||0,c=Math.cos(f),h=Math.sin(f),C=(Number.isFinite(s)?s:1)*c,d=(Number.isFinite(s)?s:1)*h,p=-(Number.isFinite(a)?a:1)*h,m=(Number.isFinite(a)?a:1)*c;for(let y=0;y+1<t.length;y+=2){let z=t[y],E=t[y+1];t[y]=C*z+d*E+i,t[y+1]=p*z+m*E+r}}function wr(t,e,i,r=!0){let s=[],a=null;try{for(let[f,c]of[[35633,e],[35632,i]]){let h=t.createShader(f);if(!h){if(r)throw new Error("Shader allocation failed");return null}if(s.push(h),t.shaderSource(h,c),t.compileShader(h),t.getShaderParameter&&!t.getShaderParameter(h,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(h)}`);return null}}if(a=t.createProgram(),!a){if(r)throw new Error("Program allocation failed");return null}for(let f of s)t.attachShader(a,f);if(t.linkProgram(a),t.getProgramParameter&&!t.getProgramParameter(a,35714)){let f=r?t.getProgramInfoLog(a):null;if(t.deleteProgram?.(a),a=null,r)throw new Error(`Program link error: ${f}`);return null}return a}finally{for(let f of s)a&&t.detachShader?.(a,f),t.deleteShader?.(f)}}var ns=["neutral","reinhard","none","aces","agx"];function rn(t){let e=String(t??"").trim().toLowerCase();return ns.includes(e)?e:"neutral"}function Co(t){return ns.indexOf(rn(t))}function Po(t){return new TextDecoder().decode(t)}var ss=mt().decoders;function Lo(t,e){ss.set(t.toLowerCase(),e)}function _r(t){return ss.get(t.toLowerCase())}function as(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,i=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=i.getUint32(0,!0);if(r!==1179937895){let m=i.getUint8(0);throw m===123||m===32||m===10||m===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let a=i.getUint32(8,!0),f=12,c=null,h=null;for(;f+8<=a&&f+8<=e.byteLength;){let m=i.getUint32(f,!0),y=i.getUint32(f+4,!0),z=f+8;if(z+m>e.byteLength)throw new Error(`Truncated GLB chunk: required ${z+m} bytes, buffer has ${e.byteLength}`);if(y===1313821514){let E=new Uint8Array(e,z,m),_=Po(E);c=JSON.parse(_,(b,$)=>b==="__proto__"||b==="constructor"||b==="prototype"?void 0:$)}else y===5130562&&(h=e.slice(z,z+m));f=z+m}if(!c)throw new Error("Missing JSON chunk in GLB");let C=c.extensionsRequired||[];for(let[m,y]of[["KHR_draco_mesh_compression","draco"],["EXT_meshopt_compression","meshopt"],["KHR_meshopt_compression","meshopt"],["KHR_texture_basisu","ktx2"]])if(C.includes(m)&&!_r(y))throw new Error(`Model requires ${m}. Register a decoder via ThreeLiveElement.registerDecoder('${y}', decoder).`);let d=h||new ArrayBuffer(0),p={gltf:c,bin:d,animations:[],animationsParsed:!1};for(let m of Nt)m.onParseGLB?.(p);return p}function os(t,e=Kn(t)){let i=t?.extensions?.KHR_lights_punctual?.lights;if(!Array.isArray(i))return[];let r=[],s=new Set,a=(f,c,h,C)=>{let d=f.type,p=d==="directional"||d==="point"||d==="spot"?d:"ambient",m=c?c[8]:-.5,y=c?c[9]:-1,z=c?c[10]:-.8,E=Math.hypot(m,y,z)||1,_=f.extras?.shadow??h,b=f.name||C,$={type:p,color:f.color||[1,1,1],intensity:f.intensity??1};b&&($.name=b),c&&($.position=[c[12],c[13],c[14]]),p==="directional"&&c?$.direction=[m/E,y/E,z/E]:(p==="spot"&&($.direction=c?[-m/E,-y/E,-z/E]:[0,-1,0],$.innerConeAngle=f.spot?.innerConeAngle??0,$.outerConeAngle=f.spot?.outerConeAngle??Math.PI/4),$.range=f.range),_&&($.shadow=_),r.push($)};return(t.nodes||[]).forEach((f,c)=>{let h=f?.extensions?.KHR_lights_punctual?.light;typeof h=="number"&&i[h]&&(s.add(h),a(i[h],e[c],f.extras?.shadow,f.name))}),i.forEach((f,c)=>{s.has(c)||a(f)}),r}function Do(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 nn(t){if(Do(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return as(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var sn=`#version 300 es
|
|
18
18
|
layout(location=0) in vec3 aPos;
|
|
19
19
|
layout(location=3) in vec3 aOff;
|
|
20
20
|
layout(location=1) in vec3 aNormal;
|
|
@@ -49,7 +49,7 @@ vec2 scaleUV=uUvTransform.zw;
|
|
|
49
49
|
if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
|
|
50
50
|
vUV=aUV*scaleUV+uUvTransform.xy;
|
|
51
51
|
gl_Position=uMVP*vec4(aPosition,1.0);
|
|
52
|
-
}
|
|
52
|
+
}`,$o=`#version 300 es
|
|
53
53
|
precision highp float;
|
|
54
54
|
in vec3 vNormal,vWorldPos;
|
|
55
55
|
in vec2 vUV;
|
|
@@ -58,117 +58,81 @@ in vec4 vInstTint;
|
|
|
58
58
|
#define uBaseColor (uBaseColor*vInstTint)
|
|
59
59
|
uniform float uMetallic,uRoughness,uEmissive,uEnvIntensity,uExposure;
|
|
60
60
|
uniform vec2 uClearcoat;
|
|
61
|
-
uniform vec3 uCameraPos,uAmbientColor;
|
|
62
|
-
uniform
|
|
63
|
-
uniform
|
|
61
|
+
uniform vec3 uCameraPos,uAmbientColor,uEmissiveFactor;
|
|
62
|
+
uniform mat3 uHemi;
|
|
63
|
+
uniform sampler2D uBaseColorTexture,uMetallicRoughnessTexture,uNormalTexture,uOcclusionTexture,uEnvironmentMap,uEmissiveTexture;
|
|
64
|
+
uniform int uHasTexture,uHasMetallicRoughnessTexture,uHasNormalTexture,uHasOcclusionTexture,uHasEnvironmentMap,uHasEmissiveTexture;
|
|
64
65
|
uniform float uNormalScale,uOcclusionStrength;
|
|
65
|
-
/*XRD_U*/
|
|
66
|
+
/*XRD_U*//*SHD_U*/
|
|
66
67
|
uniform vec2 uViewportSize;
|
|
67
68
|
uniform vec4 uSectionPlane;
|
|
68
69
|
uniform int uToneMapping,uNumDirLights,uNumPointLights,uSectionEnabled;
|
|
69
70
|
uniform vec3 uDirLightDir[2],uDirLightColor[2],uPointLightPos[2],uPointLightColor[2],uPointLightSpotDir[2];
|
|
70
71
|
uniform vec2 uPointLightSpotCone[2];
|
|
71
72
|
out vec4 fragColor;
|
|
72
|
-
|
|
73
73
|
vec2 envBRDF(float r,float n){
|
|
74
|
-
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04);
|
|
75
|
-
vec4 rv=r*c0+c1;
|
|
74
|
+
vec4 c0=vec4(-1.0,-0.0275,-0.572,0.022),c1=vec4(1.0,0.0425,1.04,-0.04),rv=r*c0+c1;
|
|
76
75
|
float a=min(rv.x*rv.x,exp2(-9.28*n))*rv.x+rv.y;
|
|
77
76
|
return vec2(-1.04,1.04)*a+rv.zw;
|
|
78
77
|
}
|
|
79
|
-
|
|
80
78
|
vec3 F_SchlickRoughness(vec3 F0,float r,float n){
|
|
81
79
|
return F0+(max(vec3(1.0-r),F0)-F0)*pow(clamp(1.0-n,0.0,1.0),5.0);
|
|
82
80
|
}
|
|
83
|
-
|
|
84
81
|
vec3 getStudioRadiance(vec3 R,float r){
|
|
85
|
-
vec3 kd=normalize(vec3(0.0,1.0,0.35));
|
|
82
|
+
vec3 kd=normalize(vec3(0.0,1.0,0.35)),fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
86
83
|
float ki=pow(max(dot(R,kd),0.0),mix(96.0,1.5,r))*mix(2.4,0.5,r);
|
|
87
|
-
vec3 fd=normalize(vec3(-0.85,0.45,-0.35));
|
|
88
84
|
float fi=pow(max(dot(R,fd),0.0),mix(36.0,1.2,r))*mix(1.3,0.35,r);
|
|
89
85
|
float ri=pow(clamp(1.0-abs(R.y),0.0,1.0),3.5)*mix(0.55,0.22,r);
|
|
90
|
-
|
|
91
|
-
return ag+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
86
|
+
return mix(vec3(0.06,0.06,0.08),vec3(0.48,0.50,0.55),R.y*0.5+0.5)+vec3(1.0,0.98,0.94)*ki+vec3(0.85,0.92,1.0)*fi+vec3(0.65,0.72,0.85)*ri;
|
|
92
87
|
}
|
|
93
|
-
|
|
94
|
-
vec3
|
|
95
|
-
vec3
|
|
96
|
-
|
|
97
|
-
vec3
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
vec2 duv2=dFdy(uv);
|
|
101
|
-
vec3 dp2perp=cross(dp2,N);
|
|
102
|
-
vec3 dp1perp=cross(N,dp1);
|
|
103
|
-
vec3 T=dp2perp*duv1.x+dp1perp*duv2.x;
|
|
104
|
-
vec3 B=dp2perp*duv1.y+dp1perp*duv2.y;
|
|
105
|
-
float invmax=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
106
|
-
return normalize(mat3(T*invmax,B*invmax,N)*normalize(mapNormal));
|
|
88
|
+
vec3 perturbNormal(vec3 N,vec3 V,vec2 uv,sampler2D m,float s){
|
|
89
|
+
vec3 q=texture(m,uv).xyz*2.0-1.0;q.xy*=s;
|
|
90
|
+
vec3 p1=dFdx(vWorldPos),p2=dFdy(vWorldPos),c2=cross(p2,N),c1=cross(N,p1);
|
|
91
|
+
vec2 u1=dFdx(uv),u2=dFdy(uv);
|
|
92
|
+
vec3 T=c2*u1.x+c1*u2.x,B=c2*u1.y+c1*u2.y;
|
|
93
|
+
float k=inversesqrt(max(dot(T,T),dot(B,B)));
|
|
94
|
+
return normalize(mat3(T*k,B*k,N)*normalize(q));
|
|
107
95
|
}
|
|
108
|
-
|
|
109
96
|
vec2 equirectangularUV(vec3 dir){
|
|
110
97
|
vec3 d=normalize(dir);
|
|
111
|
-
|
|
112
|
-
float v=asin(clamp(d.y,-1.0,1.0))*0.31830988618+0.5;
|
|
113
|
-
return vec2(u,1.0-v);
|
|
98
|
+
return vec2(atan(d.z,d.x)*0.15915494309+0.5,0.5-asin(clamp(d.y,-1.0,1.0))*0.31830988618);
|
|
114
99
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
float
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if(peak<startCompression)return color;
|
|
124
|
-
const float d=1.0-startCompression;
|
|
125
|
-
float newPeak=1.0-d*d/(peak+d-startCompression);
|
|
126
|
-
color*=newPeak/peak;
|
|
127
|
-
float g=1.0-1.0/(desaturation*(peak-newPeak)+1.0);
|
|
128
|
-
return mix(color,newPeak*vec3(1.0),g);
|
|
100
|
+
vec3 neutralToneMapping(vec3 c){
|
|
101
|
+
float x=min(c.r,min(c.g,c.b));
|
|
102
|
+
c-=x<0.08?x-6.25*x*x:0.04;
|
|
103
|
+
float p=max(c.r,max(c.g,c.b));
|
|
104
|
+
if(p<0.76)return c;
|
|
105
|
+
float n=1.0-0.0576/(p-0.52);
|
|
106
|
+
c*=n/p;
|
|
107
|
+
return mix(c,vec3(n),1.0-1.0/(0.15*(p-n)+1.0));
|
|
129
108
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
color*=0.6;
|
|
133
|
-
return clamp((color*(2.51*color+0.03))/(color*(2.43*color+0.59)+0.14),0.0,1.0);
|
|
109
|
+
vec3 acesToneMapping(vec3 c){
|
|
110
|
+
c*=0.6;return clamp((c*(2.51*c+0.03))/(c*(2.43*c+0.59)+0.14),0.0,1.0);
|
|
134
111
|
}
|
|
135
|
-
|
|
136
|
-
vec3
|
|
137
|
-
|
|
138
|
-
vec3
|
|
139
|
-
|
|
140
|
-
0.
|
|
141
|
-
0.
|
|
142
|
-
vec3 ev=clamp((log2(max(inset,vec3(1e-6)))+12.47393)/16.5,0.0,1.0);
|
|
143
|
-
vec3 x2=ev*ev;
|
|
144
|
-
vec3 x4=x2*x2;
|
|
145
|
-
vec3 s=15.5*x4*x2-40.14*x4*ev+31.96*x4-6.868*x2*ev+0.4298*x2+0.1191*ev-0.00232;
|
|
146
|
-
vec3 outset=vec3(
|
|
147
|
-
1.196879*s.r-0.09802088*s.g-0.09902974*s.b,
|
|
148
|
-
-0.05289685*s.r+1.15190313*s.g-0.09896118*s.b,
|
|
149
|
-
-0.05297164*s.r-0.09804345*s.g+1.15107367*s.b);
|
|
150
|
-
return clamp(pow(max(outset,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
112
|
+
vec3 agxToneMapping(vec3 c){
|
|
113
|
+
c=max(c,vec3(0.0));
|
|
114
|
+
vec3 i=mat3(0.84247906,0.04232824,0.04237565,0.0784336,0.87846864,0.0784336,0.07922375,0.07916613,0.87914297)*c;
|
|
115
|
+
vec3 e=clamp((log2(max(i,vec3(1e-6)))+12.47393)/16.5,0.0,1.0),x2=e*e,x4=x2*x2;
|
|
116
|
+
vec3 s=15.5*x4*x2-40.14*x4*e+31.96*x4-6.868*x2*e+0.4298*x2+0.1191*e-0.00232;
|
|
117
|
+
vec3 o=mat3(1.196879,-0.05289685,-0.05297164,-0.09802088,1.15190313,-0.09804345,-0.09902974,-0.09896118,1.15107367)*s;
|
|
118
|
+
return clamp(pow(max(o,vec3(0.0)),vec3(2.2)),0.0,1.0);
|
|
151
119
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if(mode==0)return neutralToneMapping(color);
|
|
155
|
-
if(mode==1)return color/(color+vec3(1.0));
|
|
156
|
-
if(mode==3)return acesToneMapping(color);
|
|
157
|
-
if(mode==4)return agxToneMapping(color);
|
|
158
|
-
return color;
|
|
120
|
+
vec3 applyToneMapping(vec3 c,int m){
|
|
121
|
+
return m==0?neutralToneMapping(c):m==1?c/(c+vec3(1.0)):m==3?acesToneMapping(c):m==4?agxToneMapping(c):c;
|
|
159
122
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return base*max(dot(N,L),0.0)*0.75+vec3(pow(NoH,specExp)*specWeight+uClearcoat.x*pow(NoH,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
123
|
+
vec3 evalLight(vec3 L,vec3 V,vec3 N,vec3 b,float e,float w){
|
|
124
|
+
float h=max(dot(N,normalize(L+V)),0.0);
|
|
125
|
+
return b*max(dot(N,L),0.0)*0.75+vec3(pow(h,e)*w+uClearcoat.x*pow(h,mix(64.0,512.0,1.0-uClearcoat.y))*0.35);
|
|
164
126
|
}
|
|
165
127
|
|
|
166
128
|
void main(){
|
|
167
129
|
if(uSectionEnabled==1&&dot(vWorldPos,uSectionPlane.xyz)>uSectionPlane.w)discard;
|
|
168
130
|
vec4 base=uBaseColor;
|
|
169
131
|
if(uHasTexture==1)base*=texture(uBaseColorTexture,vUV);
|
|
132
|
+
if(base.a<0.004)discard;
|
|
133
|
+
vec3 em=uHasEmissiveTexture==1?uEmissiveFactor*texture(uEmissiveTexture,vUV).rgb:uEmissiveFactor;
|
|
170
134
|
if(length(vNormal)<1e-4&&uHasTexture==1){
|
|
171
|
-
vec3 unlit=base.rgb+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
135
|
+
vec3 unlit=base.rgb+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
172
136
|
fragColor=vec4(unlit,base.a);
|
|
173
137
|
return;
|
|
174
138
|
}
|
|
@@ -200,7 +164,7 @@ float specWeight=mix(0.22*gloss,1.0,metallic);
|
|
|
200
164
|
vec3 directLight=vec3(0.0);
|
|
201
165
|
for(int i=0;i<2;i++){
|
|
202
166
|
if(i>=uNumDirLights)break;
|
|
203
|
-
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]
|
|
167
|
+
directLight+=evalLight(normalize(uDirLightDir[i]),V,N,base.rgb,specExp,specWeight)*uDirLightColor[i]/*SHD_D*/;
|
|
204
168
|
}
|
|
205
169
|
for(int i=0;i<2;i++){
|
|
206
170
|
if(i>=uNumPointLights)break;
|
|
@@ -209,7 +173,7 @@ float dist=length(toLight);
|
|
|
209
173
|
vec3 L=toLight/max(dist,0.0001);
|
|
210
174
|
float spotAtt=clamp((dot(-L,uPointLightSpotDir[i])-uPointLightSpotCone[i].y)/max(uPointLightSpotCone[i].x-uPointLightSpotCone[i].y,0.0001),0.0,1.0);
|
|
211
175
|
spotAtt*=spotAtt;
|
|
212
|
-
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)
|
|
176
|
+
directLight+=evalLight(L,V,N,base.rgb,specExp,specWeight)*uPointLightColor[i]*spotAtt/(1.0+0.09*dist+0.032*dist*dist)/*SHD_P*/;
|
|
213
177
|
}
|
|
214
178
|
|
|
215
179
|
vec3 R=reflect(-V,N);
|
|
@@ -229,8 +193,9 @@ envDiffuse=mix(vec3(0.10,0.10,0.12),vec3(0.52,0.54,0.58),N.y*0.5+0.5);
|
|
|
229
193
|
}
|
|
230
194
|
|
|
231
195
|
vec3 kD=(vec3(1.0)-F)*(1.0-metallic);
|
|
196
|
+
directLight+=kD*base.rgb*mix(uHemi[1],uHemi[0],dot(N,uHemi[2])*0.5+0.5)*occ;
|
|
232
197
|
vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
|
|
233
|
-
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
198
|
+
vec3 color=directLight+(diffuseIBL+specularIBL)*uEnvIntensity+em+vec3(uEmissive*0.35,uEmissive*0.5,uEmissive*0.7);
|
|
234
199
|
if(uClearcoat.x>0.0){
|
|
235
200
|
vec3 ccF=F_SchlickRoughness(vec3(0.04),uClearcoat.y,NoV)*uClearcoat.x;
|
|
236
201
|
color=color*(vec3(1.0)-ccF)+getStudioRadiance(R,uClearcoat.y)*ccF*uEnvIntensity;
|
|
@@ -240,140 +205,183 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
240
205
|
float outAlpha=base.a;
|
|
241
206
|
/*XRD_O*/
|
|
242
207
|
fragColor=vec4(color,outAlpha);
|
|
243
|
-
}`,
|
|
208
|
+
}`,zo=`#version 300 es
|
|
244
209
|
layout(location=0) in vec3 aPosition;
|
|
245
210
|
uniform mat4 uMVP;
|
|
246
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
211
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ko=`#version 300 es
|
|
247
212
|
precision highp float;
|
|
248
213
|
uniform vec4 uColorId;
|
|
249
214
|
out vec4 fragColor;
|
|
250
|
-
void main(){fragColor=uColorId;}`;function Di(t,e,i){let r={};for(let s of i)r[s]=t.getUniformLocation(e,s);return r}var br=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function xr(){let t=Re().xrDepthShader;return{fs:La.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...br,...t.uniformNames]:br}}function Ca(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Ni(t,e,i,r,s,a,o,n){if(r===void 0||!e.accessors?.[r])return null;let u=pr(e,i,e.accessors[r],a);if(!u)return null;n&&(u=u.slice(),Pa(u,n));let d=t.createBuffer();return o.push(d),t.bindBuffer(34962,d),t.bufferData(34962,u,35044),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,a,5126,!1,0,0),u}function Ri(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function vr(t,e,i){let r=xr(),s=yr,a=r.fs,o=!1;for(let u of Ce)if(u.onResolveShader){let d=u.onResolveShader(e,i,s,a);d&&(s=d.vs,a=d.fs,o=!0)}let n=o?Si(t,s,a):null;return{program:n,uniforms:n?Di(t,n,r.uniforms):null}}function Ia(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let s=r.length>>4,a=e.instanceColors,o=new Float32Array(s*20);for(let u=0;u<s;u++)o.set(r.subarray(u*16,u*16+16),u*20),o[u*20+16]=a?a[u*3]:1,o[u*20+17]=a?a[u*3+1]:1,o[u*20+18]=a?a[u*3+2]:1,o[u*20+19]=1;let n=t.createBuffer();i.push(n),t.bindBuffer(34962,n),t.bufferData(34962,o,35044);for(let u=0;u<5;u++)t.enableVertexAttribArray(8+u),t.vertexAttribPointer(8+u,4,5126,!1,80,u*16),t.vertexAttribDivisor(8+u,1);return!0}function Ua(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let a=s?.extensions?.KHR_texture_transform;if(a&&typeof a=="object")return a}return null}var Tn=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Mr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Qt(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function wr(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,s=t?.extensions?.KHR_materials_clearcoat,a=o=>o!==void 0&&e[o.index]?e[o.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:s?s.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,s?.clearcoatRoughnessFactor??.04),texture:a(i?.baseColorTexture),metallicRoughnessTexture:a(i?.metallicRoughnessTexture),normalTexture:a(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:a(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function _r(t,e,i){let r=new Set,s=a=>{a&&!r.has(a)&&(r.add(a),t.deleteTexture(a))};for(let a of e)for(let o of a.primitives){if(o.vao&&t.deleteVertexArray(o.vao),o.buffers)for(let u of o.buffers)t.deleteBuffer(u);s(o.texture),s(o.metallicRoughnessTexture),s(o.normalTexture),s(o.occlusionTexture);let n=new Set;o.customProgram&&n.add(o.customProgram);for(let u of o.programCache?.values()??[])u.program&&n.add(u.program);for(let u of n)t.deleteProgram(u)}if(i)for(let a of i)s(a)}function Tr(t,e,i=Mr,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Fa(t,e,i,r,s)}catch(a){let o=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;_r(t,o,s.gpuTextures),s.vao&&t.deleteVertexArray(s.vao);for(let n of s.buffers)t.deleteBuffer(n);throw a}}function Fa(t,e,i,r,s){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:a}=e,o=Pt("meshopt");o?.decodeBufferViews&&o.decodeBufferViews(a,e);let n=e.bin,u=[];s.meshes=u;let d=[],h=a.extensions?.KHR_materials_variants;h&&Array.isArray(h.variants)&&h.variants.forEach((I,c)=>{d.push(typeof I?.name=="string"&&I.name?I.name:`Variant_${c}`)});let l=Sa(a),p=[];if(Array.isArray(a.nodes))for(let I=0;I<a.nodes.length;I++){let c=a.nodes[I];c.mesh!==void 0&&a.meshes&&a.meshes[c.mesh]&&p.push({node:c,nodeIdx:I,meshIdx:c.mesh})}let m=p.length>0?p:(a.meshes||[]).map((I,c)=>({node:I,nodeIdx:-1,meshIdx:c})),y=[],x=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(a.asset?.extras?.lights)&&a.asset.extras.lights.length>0?a.asset.extras.lights:null;if(x)for(let I of x)y.push({...I,type:I.type||I.light_type||"point",innerConeAngle:I.innerConeAngle??I.inner_cone_angle,outerConeAngle:I.outerConeAngle??I.outer_cone_angle});else if(a.extensions?.KHR_lights_punctual?.lights){let I=a.extensions.KHR_lights_punctual.lights;for(let c of I){let k=c.type==="directional"?"directional":c.type==="point"?"point":c.type==="spot"?"spot":"ambient";y.push({type:k,color:c.color||[1,1,1],intensity:c.intensity!==void 0?c.intensity:1})}}if(y.length===0&&(y.push({type:"ambient",color:[1,1,1],intensity:.35}),y.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),m.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${m.length}`);let w=[];if(s.gpuTextures=w,a.textures&&a.images){if(a.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${a.textures.length}`);for(let I=0;I<a.textures.length;I++){let c=a.textures[I],k=a.images[c.source];if(k){let K=t.createTexture();t.bindTexture(3553,K),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);let A=z=>{t.bindTexture(3553,K),t.texImage2D(3553,0,6408,6408,5121,z),t.generateMipmap(3553),r?.()};if(k.bufferView!==void 0){let z=a.bufferViews[k.bufferView],S=z.byteOffset||0,b=new Blob([n.slice(S,S+z.byteLength)],{type:k.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(b).then(A).catch(()=>{})}else if(k.uri){let z=Ca(k.uri);if(z){let S=new Image;S.crossOrigin="anonymous",S.referrerPolicy="no-referrer",S.onload=()=>A(S),S.src=z}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",k.uri)}w.push(K)}else w.push(null)}}let v=[1/0,1/0,1/0],_=[-1/0,-1/0,-1/0],f=0,g=0;for(let I=0;I<m.length;I++){let c=m[I],k=a.meshes[c.meshIdx],K=c.nodeIdx>=0?l[c.nodeIdx]:ze(),A=new Float32Array(9);mt(A,K);let z={name:c.node.name||k.name||`Mesh_${c.meshIdx}`,nodeIndex:c.nodeIdx,transform:K,normalMatrix:A,primitives:[],extras:c.node.extras||k.extras,...c.node?.visible===!1||c.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=z;let S=c.node?.extensions?.EXT_mesh_gpu_instancing;if(S&&S.attributes&&typeof S.attributes=="object"){let b=S.attributes,O=b.TRANSLATION!==void 0?a.accessors?.[b.TRANSLATION]:null,X=b.ROTATION!==void 0?a.accessors?.[b.ROTATION]:null,te=b.SCALE!==void 0?a.accessors?.[b.SCALE]:null,re=b._COLOR_0!==void 0?a.accessors?.[b._COLOR_0]:null,Z=Number(O?.count??X?.count??te?.count??0);if(!Number.isFinite(Z)||Z<0||Z>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${Z}`);if(Z>0){let ne=(J,se)=>{if(!J||J.bufferView===void 0||!a.bufferViews?.[J.bufferView])return null;let P=J.componentType??5126,M=N=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${N})`),null);if(P!==5120&&P!==5121&&P!==5122&&P!==5123&&P!==5126)return M(`componentType ${P}`);if(!(Number(J.count)>=Z))return M(`count ${J.count} < ${Z}`);let D=null;try{D=pr(a,n,{...J,count:Z},se)}catch{return M("out of bounds")}return!D||!D.every(Number.isFinite)?M("non-finite value"):D},pe=ne(O,3),xe=ne(X,4),ie=ne(te,3),he=re?.type==="VEC4"?4:3,ee=ne(re,he),le=new Float32Array(Z*16),ue=ze();for(let J=0;J<Z;J++){let se=pe?[pe[J*3],pe[J*3+1],pe[J*3+2]]:[0,0,0],P=xe?[xe[J*4],xe[J*4+1],xe[J*4+2],xe[J*4+3]]:[0,0,0,1],M=ie?[ie[J*3],ie[J*3+1],ie[J*3+2]]:[1,1,1];Ti(ue,P,se,M),le.set(ue,J*16)}if(z.instanceMatrices=le,ee){let J=new Float32Array(Z*3);for(let se=0;se<Z;se++)J[se*3]=ee[se*he],J[se*3+1]=ee[se*he+1],J[se*3+2]=ee[se*he+2];z.instanceColors=J}}}for(let b of k.primitives||[]){if(b.extensions?.KHR_draco_mesh_compression){let D=Pt("draco");D&&D.decodePrimitive(a,b,n)}let O=[],X=t.createVertexArray();s.vao=X,s.buffers=O,t.bindVertexArray(X);let te=Ia(t,z,O),re=a.accessors[b.attributes.POSITION],Z=Number(re?.count??0);if(!Number.isFinite(Z)||Z<0||f+Z>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(f+=Z,re?.min&&re?.max){let D=N=>{for(let C=0;C<3;C++){let H=N[12+C],V=N[12+C];for(let G=0;G<3;G++){let W=N[G*4+C]*re.min[G],F=N[G*4+C]*re.max[G];H+=W<F?W:F,V+=W>F?W:F}H<v[C]&&(v[C]=H),V>_[C]&&(_[C]=V)}};if(z.instanceMatrices&&z.instanceMatrices.length>=16){let N=z.instanceMatrices.length>>4,C=ze();for(let H=0;H<N;H++){let V=z.instanceMatrices.subarray(H*16,H*16+16);je(C,K,V),D(C)}}else D(K)}let ne=Ni(t,a,n,b.attributes.POSITION,0,3,O);Ni(t,a,n,b.attributes.NORMAL,1,3,O),Ni(t,a,n,b.attributes.TEXCOORD_0,2,2,O,Ua(a,b));let pe=0,xe=5123,ie=null;if(b.indices!==void 0){let D=a.accessors[b.indices],N=(a.bufferViews[D.bufferView].byteOffset||0)+(D.byteOffset||0);if(pe=Number(D.count??0),!Number.isFinite(pe)||pe<0||g+pe>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);g+=pe,xe=D.componentType===5125?5125:5123;let C=t.createBuffer();O.push(C),t.bindBuffer(34963,C),D.componentType===5125?ie=new Uint32Array(n,N,D.count):D.componentType===5121?ie=Uint16Array.from(new Uint8Array(n,N,D.count)):ie=N%2===0?new Uint16Array(n,N,D.count):new Uint16Array(n.slice(N,N+D.count*2)),t.bufferData(34963,ie,35044)}else pe=re.count;let he={};for(let D of Ce)if(D.onBuildPrimitiveVAO){let N=D.onBuildPrimitiveVAO(t,X,b,a,n);N&&(he[D.name]=N)}t.bindVertexArray(null);let ee=a.materials&&b.material!==void 0?a.materials[b.material]:null,{program:le,uniforms:ue}=vr(t,b,ee),J=wr(ee,w),se=!!(ee?.extensions?.KHR_materials_transmission||he.materials?.isTransmissive),P=b.extensions?.KHR_materials_variants?.mappings,M=Array.isArray(P)?P.filter(D=>D&&typeof D.material=="number"&&Array.isArray(D.variants)).map(D=>({material:D.material|0,variants:D.variants.map(N=>Number(N)|0)})):void 0;z.primitives.push({vao:X,instanced:te,indexCount:pe,indexType:xe,...J,positions:ne,indices:ie,buffers:O,materialIndex:b.material,defaultMaterialIndex:b.material,variantMappings:M,primitiveDef:b,programCache:new Map([[b.material??-1,{program:le,uniforms:ue}]]),pluginData:he,customProgram:le,customUniforms:ue,isTransmissive:se})}u.push(z)}isFinite(v[0])||(v=[-1,-1,-1]),isFinite(_[0])||(_=[1,1,1]);let T=[(v[0]+_[0])/2,(v[1]+_[1])/2,(v[2]+_[2])/2],R=_[0]-v[0],U=_[1]-v[1],j=_[2]-v[2],$=Math.max(Math.hypot(R,U,j)/2,.5),L=[v[0],v[1],v[2]],E=[_[0],_[1],_[2]],B=e.animations;if(!B){for(let I of Ce)if(I.onParseGLB?.(e),e.animations){B=e.animations;break}}return B||(B=[]),{meshes:u,bounds:{center:T,radius:$,min:L,max:E},lights:y,animations:B,worldMatrices:l,gpuTextures:w,availableVariants:d}}function Bt(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var Sr=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=ze(),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=ze(),this.viewMatrix=ze(),this.activeViewMatrix=null,this.modelMatrix=ze(),this.mvpMatrix=ze(),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:ze(),rawValueToMeters:.001,format:0},this.container=t;let r,s;if(e&&typeof e.getContext=="function"?(r=e,s=i):(s=e,r=s?.canvas),!r){let n=t.querySelector("canvas");n||(n=document.createElement("canvas"),n.style.width="100%",n.style.height="100%",n.style.display="block",n.style.touchAction="none",t.prepend(n)),r=n}this.canvas=r,this.opts=s||{},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=Ri(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=Ai(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let o=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!o)throw new Error("WebGL2 not supported");this.gl=o,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(t,e){Ra(t,e)}static getDecoder(t){return Pt(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=xr();this.renderProg=Si(t,yr,e.fs),this.pickProg=Si(t,za,ka),this.uRender=Di(t,this.renderProg,e.uniforms),this.uPick=Di(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of Ce)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;if(typeof t.createFramebuffer!="function")return;this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer();let e=Math.max(1,this.canvas.width),i=Math.max(1,this.canvas.height);this.pickFboWidth=e,this.pickFboHeight=i,t.bindTexture(3553,this.pickTexture),t.texImage2D(3553,0,6408,e,i,0,6408,5121,null),t.texParameteri(3553,10241,9728),t.texParameteri(3553,10240,9728),t.bindRenderbuffer(36161,this.pickDepth),t.renderbufferStorage(36161,33189,e,i),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null)}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),s=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:s,animations:a,worldMatrices:o,gpuTextures:n,availableVariants:u}=Tr(this.gl,t,e,()=>this.render());if(this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=a||[],this.worldMatrices=o||[],this.gpuTextures=n||[],this.availableVariants=u||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let l of t.gltf.nodes)this.initialNodeTransforms.push({t:l.translation?[l.translation[0],l.translation[1],l.translation[2]]:[0,0,0],r:l.rotation?[l.rotation[0],l.rotation[1],l.rotation[2],l.rotation[3]]:[0,0,0,1],s:l.scale?[l.scale[0],l.scale[1],l.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let l of Ce)l.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let d=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;d!==void 0&&(this.exposure=Ri(d));let h=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(t){this.loadGLBData(gr(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of Ce)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(Pi(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=Pi(t),{meshes:r}=Tr(this.gl,i,Mr,()=>this.render());if(e)for(let s of r)s.transform[12]+=e[0],s.transform[13]+=e[1],s.transform[14]+=e[2],mt(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r;t instanceof Map?r=t.get(i.name)??t.get(e):Array.isArray(t)?r=t[e]:t&&typeof t=="object"&&(Object.prototype.hasOwnProperty.call(t,i.name)?r=t[i.name]:Object.prototype.hasOwnProperty.call(t,e)&&(r=t[e])),r&&r.length===16&&(i.transform.set(r),mt(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[],s=[],a=[],o=[],n=[],u=[];for(let d of this.lights){let h=d.color||[1,1,1],l=d.intensity!==void 0?d.intensity:1;if(d.type==="ambient")i=[h[0]*l,h[1]*l,h[2]*l];else if(d.type==="directional"&&r.length<6){let p=d.direction||[.5,1,.8];r.push(p[0],p[1],p[2]),s.push(h[0]*l,h[1]*l,h[2]*l)}else if((d.type==="point"||d.type==="spot")&&a.length<6){let p=d.position||[0,0,0];if(a.push(p[0],p[1],p[2]),o.push(h[0]*l,h[1]*l,h[2]*l),d.type==="spot"){let m=d.direction||[0,-1,0],y=Math.max(.01,Math.min(Math.PI/2,d.outerConeAngle??Math.PI/3)),x=Math.max(0,Math.min(y-1e-4,d.innerConeAngle??0));n.push(m[0],m[1],m[2]),u.push(Math.cos(x),Math.cos(y))}else n.push(0,-1,0),u.push(-2,-3)}}r.length===0&&(r.push(.5,1,.8),s.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),e.uniform1i(t.uNumDirLights,r.length/3),r.length>0&&(e.uniform3fv(t.uDirLightDir,r),e.uniform3fv(t.uDirLightColor,s)),e.uniform1i(t.uNumPointLights,a.length/3),a.length>0&&(e.uniform3fv(t.uPointLightPos,a),e.uniform3fv(t.uPointLightColor,o),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,n),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,u)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=Ri(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=Ai(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let e of Ce)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let e of Ce)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(d=>d.primitives.filter(h=>h.materialIndex===i||t.length===1&&h.materialIndex===void 0)),s=r[0],a=s?[...s.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],o=s?s.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,n=s?s.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,u={baseColorFactor:a,metallicFactor:o,roughnessFactor:n,setBaseColorFactor:d=>{let h=[d[0],d[1],d[2],d[3]??1];u.baseColorFactor=h,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.baseColorFactor=h);for(let l of r)l.baseColor=h;this.render()},setMetallicFactor:d=>{u.metallicFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.metallicFactor=d);for(let h of r)h.metallic=d;this.render()},setRoughnessFactor:d=>{u.roughnessFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.roughnessFactor=d);for(let h of r)h.roughness=d;this.render()}};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:u}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let s of this.meshes)for(let a of s.primitives){let o=a.defaultMaterialIndex;if(!e&&Array.isArray(a.variantMappings)){for(let u of a.variantMappings)if(Array.isArray(u.variants)&&u.variants.includes(i)){o=u.material;break}}let n=o!==void 0?r[o]:void 0;a.materialIndex=n?o:void 0,Object.assign(a,wr(n,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,n??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,s=t.programCache.get(r);s||(s=vr(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,s)),t.customProgram=s.program,t.customUniforms=s.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of Ce)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){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 e=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,i=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(e,Math.min(i,t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(t,e,i,r){if(t!==void 0&&(this.initialTheta=this.clampTheta(t*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),e!==void 0&&(this.initialPhi=this.clampPhi(e*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),i!==void 0&&i>0){let s=this.clampDistance(i);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else if(r!==void 0&&r>0){let s=this.clampDistance(this.bounds.radius*2.5/r);this.initialDistance=s,this.customDistance=!0,this.targetDistance=s,this.currDistance=s}else{this.customDistance=!1;let s=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=s,this.targetDistance=s,this.currDistance=s}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let i=ze();je(i,this.projMatrix,this.viewMatrix);let[r,s,a]=t,o=e?e[0]:0,n=e?e[1]:0,u=e?e[2]:0,d=this.modelRootMatrix;d&&(r=d[0]*t[0]+d[4]*t[1]+d[8]*t[2]+d[12],s=d[1]*t[0]+d[5]*t[1]+d[9]*t[2]+d[13],a=d[2]*t[0]+d[6]*t[1]+d[10]*t[2]+d[14],e&&(o=d[0]*e[0]+d[4]*e[1]+d[8]*e[2],n=d[1]*e[0]+d[5]*e[1]+d[9]*e[2],u=d[2]*e[0]+d[6]*e[1]+d[10]*e[2]));let h=i[0]*r+i[4]*s+i[8]*a+i[12],l=i[1]*r+i[5]*s+i[9]*a+i[13],p=i[2]*r+i[6]*s+i[10]*a+i[14],m=i[3]*r+i[7]*s+i[11]*a+i[15];if(m<=1e-4)return{x:0,y:0,z:1,visible:!1};let y=h/m,x=l/m,w=p/m,v=this.canvas.getBoundingClientRect(),_=v.width||this.canvas.clientWidth||this.canvas.width||300,f=v.height||this.canvas.clientHeight||this.canvas.height||150,g=(y*.5+.5)*_,T=(-x*.5+.5)*f,R=y>=-1.1&&y<=1.1&&x>=-1.1&&x<=1.1&&w>=-1&&w<=1;if(R&&e){let[U,j,$]=Bt(this),L=[r-U,s-j,a-$];o*L[0]+n*L[1]+u*L[2]>.05&&(R=!1)}return{x:g,y:T,z:w,visible:R}}setSelectedMesh(t){this.selectedMeshName=t||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let t=this.canvas,e=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,a=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,a),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let o=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],n=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],u=this.customTarget?[...this.customTarget]:[...this.bounds.center],d=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;u[0]+=(-s*o[0]+a*n[0])*d,u[1]+=(-s*o[1]+a*n[1])*d,u[2]+=(-s*o[2]+a*n[2])*d,this.customTarget=u}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+a*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),a=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(s,a,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},e=this.canvas;t(e,"webglcontextlost","boundContextLost"),t(e,"webglcontextrestored","boundContextRestored"),t(e,"contextmenu","boundContextMenu"),t(e,"pointerdown","boundPointerDown"),t(e,"pointermove","boundPointerMove"),t(e,"pointerup","boundPointerUp"),t(e,"wheel","boundWheel"),t(e,"keydown","boundKeyDown"),t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,a=i.height||300,o=r.width>0?Math.floor((t-r.left)*(s/r.width)):Math.floor(t),n=r.height>0?Math.floor((e-r.top)*(a/r.height)):Math.floor(e);return this.performMeshPick(o,n,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,s);let o=ze();je(o,this.projMatrix,this.viewMatrix);let n=[],u=Math.max(0,Math.min(s-1,t)),d=Math.max(0,Math.min(a-1,a-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,a),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let T=0;T<this.meshes.length;T++){let R=this.meshes[T];if(R.visible===!1||R.isPluginMesh)continue;let U=T+1,j=(U&255)/255,$=(U>>8&255)/255,L=(U>>16&255)/255;r.uniform4f(this.uPick.uColorId,j,$,L,1),je(this.modelMatrix,this.modelRootMatrix,R.transform);let E=R.instanceMatrices;if(E&&E.length>=16){let B=E.length>>4,I=ze();for(let c of R.primitives){r.bindVertexArray(c.vao);for(let k=0;k<B;k++)je(I,this.modelMatrix,E.subarray(k*16,k*16+16)),je(this.mvpMatrix,o,I),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Qt(r,c)}}else{je(this.mvpMatrix,o,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let B of R.primitives)r.bindVertexArray(B.vao),Qt(r,B)}}let f=new Uint8Array(4);r.readPixels(u,d,1,1,6408,5121,f),r.bindFramebuffer(36160,null);let g=f[0]+(f[1]<<8)+(f[2]<<16);g>0&&g<=this.meshes.length&&(n=[this.meshes[g-1]])}n.length===0&&(n=this.meshes.filter(f=>f.visible!==!1));let h=null,l=1/0,p=[0,0,0],m=[0,1,0],[y,x,w]=Bt(this),v=ze();for(let f of n){je(v,this.modelRootMatrix,f.transform);let g=f.instanceMatrices,T=g&&g.length>=16?g.length>>4:1;for(let R=0;R<T;R++){g&&g.length>=16?je(this.modelMatrix,v,g.subarray(R*16,R*16+16)):this.modelMatrix.set(v),je(this.mvpMatrix,o,this.modelMatrix);let U=ze();if(!_a(U,this.mvpMatrix))continue;let j=(u+.5)/s*2-1,$=(d+.5)/a*2-1,L=[0,0,0],E=[0,0,0];hr(L,j,$,-1,U),hr(E,j,$,1,U);let B=E[0]-L[0],I=E[1]-L[1],c=E[2]-L[2],k=Math.hypot(B,I,c)||1,K=B/k,A=I/k,z=c/k,S={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((b=>{for(let O of f.primitives){if(!O.positions)continue;let X=O.positions,te=O.indices,re=Math.floor(te?te.length/3:X.length/9);for(let Z=0;Z<re;Z++){let ne=te?te[Z*3]:Z*3,pe=te?te[Z*3+1]:Z*3+1,xe=te?te[Z*3+2]:Z*3+2;Ta(L[0],L[1],L[2],K,A,z,X[ne*3],X[ne*3+1],X[ne*3+2],X[pe*3],X[pe*3+1],X[pe*3+2],X[xe*3],X[xe*3+1],X[xe*3+2],S,b)}}})(1e-4),isFinite(S.distance)){let b=S.point[0],O=S.point[1],X=S.point[2],te=this.modelMatrix,re=te[0]*b+te[4]*O+te[8]*X+te[12],Z=te[1]*b+te[5]*O+te[9]*X+te[13],ne=te[2]*b+te[6]*O+te[10]*X+te[14],pe=re-y,xe=Z-x,ie=ne-w,he=Math.hypot(pe,xe,ie);if(he<l){mt(this.normalMatrix,this.modelMatrix);let ee=this.normalMatrix,le=S.normal[0],ue=S.normal[1],J=S.normal[2],se=ee[0]*le+ee[3]*ue+ee[6]*J,P=ee[1]*le+ee[4]*ue+ee[7]*J,M=ee[2]*le+ee[5]*ue+ee[8]*J,D=Math.hypot(se,P,M)||1;se/=D,P/=D,M/=D,se*pe+P*xe+M*ie>0&&(se=-se,P=-P,M=-M),h=f,l=Math.round(he*1e3)/1e3,p=[Math.round(re*1e3)/1e3,Math.round(Z*1e3)/1e3,Math.round(ne*1e3)/1e3],m=[Math.round(se*1e3)/1e3,Math.round(P*1e3)/1e3,Math.round(M*1e3)/1e3]}}}}if(!h)return null;let _={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:l,hitPoint:p,normal:m,screenX:t,screenY:e};if(i){for(let f of Ce)f.onMeshSelect?.(this,_);this.opts.onMeshClick&&this.opts.onMeshClick(_),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:_}))}return _}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,s=r?t-i:t,a=r?Math.max(1,e-i):i,o=(s+.5)/a*2-1;return Math.floor((o*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);_i(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;Jt(this.viewMatrix,Bt(this),i,[0,1,0]),je(this.mvpMatrix,this.projMatrix,this.viewMatrix),mt(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of Ce)i.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of Ce)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),i=this.bounds.center[0],r=this.bounds.center[2],s=this.modelRootMatrix;s[0]=t,s[1]=0,s[2]=-e,s[3]=0,s[4]=0,s[5]=1,s[6]=0,s[7]=0,s[8]=e,s[9]=0,s[10]=t,s[11]=0,s[12]=i-(t*i+e*r),s[13]=0,s[14]=r-(-e*i+t*r),s[15]=1}setVisible(t){this.isVisible=t}update(t){for(let a of Ce)a.onUpdate?.(this,t);let e=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let a of Ce)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 i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let a={theta:i,phi:r,zoom:s,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,e,i,r,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let o=t?.transform?.inverse?.matrix||this.viewMatrix,n=t?.projectionMatrix||this.projMatrix,u=t?.transform?.position,d=u?[u.x,u.y,u.z]:[0,1.6,0];e?this.modelRootMatrix.set(e):i&&e&&this.modelRootMatrix.set(e),this.render({viewMatrix:o,projMatrix:n,eyePos:d,viewport:r,eye:t?.eye||"none",clear:a>0?!1:t?.eye!=="right",isAR:s})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let _=Math.max(2,this.canvas.width||2),f=Math.max(1,this.canvas.height||1),g=Math.max(1,Math.floor(_*.5)),T=Math.max(1,_-g),R=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),U=this.customTarget||this.bounds.center,[j,$,L]=Bt(this),E=Math.cos(this.currTheta),B=-Math.sin(this.currTheta),I=.032,c=ze(),k=ze(),K=[j-E*I,$,L-B*I],A=[U[0]-E*I*.25,U[1],U[2]-B*I*.25];_i(c,this.fov,g/f,.1,R),Jt(k,K,A,[0,1,0]);let z=ze(),S=ze(),b=[j+E*I,$,L+B*I],O=[U[0]+E*I*.25,U[1],U[2]+B*I*.25];_i(z,this.fov,T/f,.1,R),Jt(S,b,O,[0,1,0]),this.render({viewMatrix:k,projMatrix:c,eyePos:K,viewport:[0,0,g,f],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:S,projMatrix:z,eyePos:b,viewport:[g,0,T,f],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,_,f);return}let e=this.gl,i=0,r=0,s=this.canvas.width,a=this.canvas.height;t?.viewport?(i=t.viewport[0],r=t.viewport[1],s=t.viewport[2],a=t.viewport[3],e.viewport(i,r,s,a)):e.viewport(0,0,this.canvas.width,this.canvas.height),e.enable(2929),(!t||t.clear!==!1)&&(t?.isAR?e.clearColor(0,0,0,0):e.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),e.clear(16640));let o=ze(),n=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=n,je(o,t?.projMatrix??this.projMatrix,n);let u=Re().xrDepthShader,d=Da(this.toneMapping),[h,l,p]=t?t.eyePos:Bt(this);for(let _ of Ce)_.onBeforeDrawScene?.(this,e,o,[h,l,p],d);let m=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&m===0)return;let y=t?.eye||"none",x=!1,w=m>0?[...this.backdropMeshes,...this.meshes]:this.meshes,v=_=>{for(let f=0;f<w.length;f++){let g=w[f];if(g.visible===!1)continue;let T=this.selectedMeshName!==""&&g.name===this.selectedMeshName;f<m||g.worldSpace===!0||g.name==="__xr_reticle__"?this.modelMatrix.set(g.transform):je(this.modelMatrix,this.modelRootMatrix,g.transform),je(this.mvpMatrix,o,this.modelMatrix),mt(g.normalMatrix,this.modelMatrix);let R=g.extras?.xr?.stereo||g.userData?.xr?.stereo,U=0,j=0,$=1,L=1;R==="sbs"?($=.5,U=y==="right"?.5:0):R==="ou"&&(L=.5,j=y==="right"?.5:0);for(let E of g.primitives){let B=!!E.isTransmissive;if(!_&&B){x=!0;continue}if(_&&!B)continue;let I=E.customProgram||this.renderProg,c=E.customUniforms||this.uRender;e.useProgram(I),e.vertexAttrib3f(3,0,0,0),c.uInstanced&&e.uniform1i(c.uInstanced,0),e.uniform1i(c.uToneMapping,d),e.uniform1f(c.uEnvIntensity,this.envIntensity),c.uExposure&&e.uniform1f(c.uExposure,this.exposure),e.uniform3f(c.uCameraPos,h,l,p),e.uniform1f(c.uEmissive,T?1:0),e.uniformMatrix4fv(c.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(c.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(c.uNormalMatrix,!1,g.normalMatrix),c.uUvTransform&&e.uniform4f(c.uUvTransform,U,j,$,L),c.uViewportSize&&e.uniform2f(c.uViewportSize,Math.max(1,s),Math.max(1,a)),u?.bind(e,c,this.xrDepthState,n,[i,r,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(e.activeTexture(33988),e.bindTexture(3553,this.environmentTexture),e.uniform1i(c.uEnvironmentMap,4),e.uniform1i(c.uHasEnvironmentMap,1)):e.uniform1i(c.uHasEnvironmentMap,0),this.bindLights(c),c.uSectionEnabled&&e.uniform1i(c.uSectionEnabled,0);for(let K of Ce)K.onBeforeDrawPrimitive?.(e,I,E,g,this.worldMatrices||[],this.gltf);e.uniform4fv(c.uBaseColor,E.baseColor),e.uniform1f(c.uMetallic,E.metallic),e.uniform1f(c.uRoughness,E.roughness),c.uClearcoat&&e.uniform2f(c.uClearcoat,E.clearcoat??0,E.clearcoatRoughness??.04),E.texture?(e.activeTexture(33984),e.bindTexture(3553,E.texture),e.uniform1i(c.uBaseColorTexture,0),e.uniform1i(c.uHasTexture,1)):e.uniform1i(c.uHasTexture,0),E.metallicRoughnessTexture?(e.activeTexture(33985),e.bindTexture(3553,E.metallicRoughnessTexture),e.uniform1i(c.uMetallicRoughnessTexture,1),e.uniform1i(c.uHasMetallicRoughnessTexture,1)):e.uniform1i(c.uHasMetallicRoughnessTexture,0),E.normalTexture?(e.activeTexture(33986),e.bindTexture(3553,E.normalTexture),e.uniform1i(c.uNormalTexture,2),e.uniform1i(c.uHasNormalTexture,1),e.uniform1f(c.uNormalScale,E.normalScale)):e.uniform1i(c.uHasNormalTexture,0),E.occlusionTexture?(e.activeTexture(33987),e.bindTexture(3553,E.occlusionTexture),e.uniform1i(c.uOcclusionTexture,3),e.uniform1i(c.uHasOcclusionTexture,1),e.uniform1f(c.uOcclusionStrength,E.occlusionStrength)):e.uniform1i(c.uHasOcclusionTexture,0),e.bindVertexArray(E.vao);let k=g.instanceMatrices;if(E.instanceCount!==void 0)e.drawElementsInstanced(4,E.indexCount,E.indexType,0,E.instanceCount);else if(k&&k.length>=16&&E.instanced&&c.uInstanced&&c.uViewProj){let K=k.length>>4;e.uniform1i(c.uInstanced,1),e.uniformMatrix4fv(c.uViewProj,!1,o),E.indices?e.drawElementsInstanced(4,E.indexCount,E.indexType,0,K):e.drawArraysInstanced(4,0,E.indexCount,K),e.uniform1i(c.uInstanced,0)}else if(k&&k.length>=16){let K=k.length>>4,A=g.instanceColors,z=ze(),S=new Float32Array(9),b=[E.baseColor[0],E.baseColor[1],E.baseColor[2],E.baseColor[3]];for(let O=0;O<K;O++)je(z,this.modelMatrix,k.subarray(O*16,O*16+16)),je(this.mvpMatrix,o,z),mt(S,z),e.uniformMatrix4fv(c.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(c.uModel,!1,z),e.uniformMatrix3fv(c.uNormalMatrix,!1,S),A&&(b[0]=E.baseColor[0]*A[O*3],b[1]=E.baseColor[1]*A[O*3+1],b[2]=E.baseColor[2]*A[O*3+2],b[3]=E.baseColor[3],e.uniform4fv(c.uBaseColor,b)),Qt(e,E)}else Qt(e,E)}}};if(v(!1),x){for(let _ of Ce)_.onBeforeTransmissivePass?.(e,this);v(!0)}for(let _ of Ce)_.onAfterRender?.(e,this,o,t?.eye??"none",[i,r,s,a],t?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(t,e){_r(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of Ce)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Sr.registerPlugin=va,Sr.getRegisteredPlugins=Ma;function $a(t){return t+3&-4}var Me=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function Ar(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function Pr(t,e=0){let[i,r,s,,a,o,n,,u,d,h,,l,p,m]=Array.from({length:15},(S,b)=>Me(t[e+b],b%5===0?1:0)),y=Math.hypot(i,r,s),x=Math.hypot(a,o,n),w=Math.hypot(u,d,h);i*(o*h-d*n)-a*(r*h-d*s)+u*(r*n-o*s)<0&&(y=-y);let v=Math.abs(y)>1e-8?1/y:0,_=Math.abs(x)>1e-8?1/x:0,f=Math.abs(w)>1e-8?1/w:0,g=i*v,T=r*v,R=s*v,U=a*_,j=o*_,$=n*_,L=u*f,E=d*f,B=h*f,I=g+j+B,c=0,k=0,K=0,A=1;if(I>0){let S=.5/Math.sqrt(I+1);A=.25/S,c=($-E)*S,k=(L-R)*S,K=(T-U)*S}else if(g>j&&g>B){let S=2*Math.sqrt(Math.max(0,1+g-j-B));S>1e-8&&(A=($-E)/S,c=.25*S,k=(U+T)/S,K=(L+R)/S)}else if(j>B){let S=2*Math.sqrt(Math.max(0,1+j-g-B));S>1e-8&&(A=(L-R)/S,c=(U+T)/S,k=.25*S,K=($+E)/S)}else{let S=2*Math.sqrt(Math.max(0,1+B-g-j));S>1e-8&&(A=(T-U)/S,c=(L+R)/S,k=($+E)/S,K=.25*S)}let z=Math.hypot(c,k,K,A);return z>1e-8&&Number.isFinite(z)?(c/=z,k/=z,K/=z,A/=z):(c=0,k=0,K=0,A=1),{t:[l,p,m],r:[c,k,K,A],s:[y,x,w]}}function Oa(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var gt=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Dr(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:gt(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function jt(t,e){return Nr(t,e)[0]}function Nr(t,e){t.updateMatrixWorld(!0);let i=[],r=0,s=[],a=[],o=[],n=[],u=new Set,d=[],h=[],l=new Map,p=[],m=[],y=[],x=new Map,w=[],v=[];function _(A){let z=l.get(A);if(z!==void 0)return z;z=h.length,l.set(A,z);let S=A,b=S.color?.r??1,O=S.color?.g??1,X=S.color?.b??1,te=S.opacity??1,re={baseColorFactor:[b,O,X,te],metallicFactor:S.metalness??0,roughnessFactor:S.roughness??.5},Z={},ne=se=>{if(!se)return;let P=(typeof se=="string"?se:typeof se.source=="string"?se.source:typeof se.image=="string"?se.image:"").trim();if(!P||/[\x00-\x1f\x7f\\]|\.\./.test(P)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(P)||!P.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(P)))return;let M=x.get(P);if(M===void 0){let D=p.length;p.push({uri:P}),m.length===0&&m.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),M=y.length,y.push({sampler:0,source:D}),x.set(P,M)}return{index:M}},pe=ne(S.map);pe&&(re.baseColorTexture=pe);let xe=ne(S.roughnessMap||S.metalnessMap);xe&&(re.metallicRoughnessTexture=xe);let ie=S.map?.avgColor;Array.isArray(ie)&&ie.length>=3&&(Z.avgColor=[ie[0],ie[1],ie[2]]);let he=ne(S.normalMap),ee=ne(S.emissiveMap),le=ne(S.aoMap),ue={name:S.name||"",pbrMetallicRoughness:re,doubleSided:S.side===2||!!S.doubleSided,...he?{normalTexture:he}:{},...ee?{emissiveTexture:ee}:{},...le?{occlusionTexture:le}:{},...Object.keys(Z).length>0?{extras:Z}:{}};if(S.emissive&&(S.emissive.r>0||S.emissive.g>0||S.emissive.b>0)){let se=S.emissiveIntensity??1;ue.emissiveFactor=[S.emissive.r*se,S.emissive.g*se,S.emissive.b*se]}let J={};return S.clearcoat&&S.clearcoat>0&&(J.KHR_materials_clearcoat={clearcoatFactor:S.clearcoat,clearcoatRoughnessFactor:S.clearcoatRoughness||0}),S.sheen&&S.sheen>0&&(J.KHR_materials_sheen={sheenColorFactor:S.sheenColor?[S.sheenColor.r,S.sheenColor.g,S.sheenColor.b]:[1,1,1],sheenRoughnessFactor:S.sheenRoughness||0}),S.transmission&&S.transmission>0&&(J.KHR_materials_transmission={transmissionFactor:S.transmission}),S.thickness&&S.thickness>0&&(J.KHR_materials_volume={thicknessFactor:S.thickness,attenuationDistance:S.attenuationDistance??1/0,attenuationColor:S.attenuationColor?[S.attenuationColor.r,S.attenuationColor.g,S.attenuationColor.b]:[1,1,1]}),S.ior!==void 0&&S.ior!==1.5&&(J.KHR_materials_ior={ior:S.ior}),S.dispersion&&S.dispersion>0&&(J.KHR_materials_dispersion={dispersion:S.dispersion}),S.iridescence&&S.iridescence>0&&(J.KHR_materials_iridescence={iridescenceFactor:S.iridescence,iridescenceIor:S.iridescenceIOR??1.3}),Object.keys(J).length>0&&(ue.extensions=J),h.push(ue),z}function f(A,z){let S=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),b=$a(S.byteLength),O=new Uint8Array(b);O.set(S),i.push(O);let X=s.length;return s.push({buffer:0,byteOffset:r,byteLength:S.byteLength,target:z}),r+=b,X}function g(A,z,S,b,O,X,te){let re=f(A,S),Z=a.length,ne={bufferView:re,byteOffset:0,componentType:b,count:O,type:z};return X&&(ne.min=X),te&&(ne.max=te),a.push(ne),Z}t.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let z=A.matrixWorld?.elements,S=Me(z?z[12]:A.position?.x,0),b=Me(z?z[13]:A.position?.y,0),O=Me(z?z[14]:A.position?.z,0),X=A.target,te=X?.parent?X?.matrixWorld?.elements:void 0,re=Me(te?te[12]:X?.position?.x,0),Z=Me(te?te[13]:X?.position?.y,0),ne=Me(te?te[14]:X?.position?.z,0),pe=re-S,xe=Z-b,ie=ne-O,he=Math.hypot(pe,xe,ie),ee=Math.max(.01,Math.min(Math.PI/2,Me(A.angle,Math.PI/3))),le=Math.max(0,Math.min(1,Me(A.penumbra,0)));v.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[S,b,O],...A.type==="spot"?{direction:he>1e-6?[pe/he,xe/he,ie/he]:[0,-1,0],outerConeAngle:ee,innerConeAngle:Math.max(0,ee*(1-le)),range:Math.max(0,Me(A.distance,0))}:A.type==="point"?{range:Math.max(0,Me(A.distance,0))}:{}})}});let T=[],R=new Set([t]),U=[];if(Array.isArray(t.children))for(let A=t.children.length-1;A>=0;A--)U.push({obj:t.children[A],parentKids:T});for(;U.length>0;){let{obj:A,parentKids:z}=U.pop();if(!A||typeof A!="object"||R.has(A))continue;R.add(A),A._bakeAuthorGeometry?.(),Re().materializeDeclarativeGeometry?.(A);let S=!!(A.userData&&(A.userData.xr&&typeof A.userData.xr=="object"&&Object.keys(A.userData.xr).length>0||A.userData.interactivity&&typeof A.userData.interactivity=="object"&&Object.keys(A.userData.interactivity).length>0)),b={name:A.name||(S?`Node_${n.length}`:"")},O=Me(A.position?.x,0),X=Me(A.position?.y,0),te=Me(A.position?.z,0),re=Me(A.quaternion?.x,0),Z=Me(A.quaternion?.y,0),ne=Me(A.quaternion?.z,0),pe=Me(A.quaternion?.w,1),xe=Me(A.scale?.x,1),ie=Me(A.scale?.y,1),he=Me(A.scale?.z,1);if((O||X||te)&&(b.translation=[O,X,te]),(re||Z||ne||pe!==1)&&(b.rotation=[re,Z,ne,pe]),(xe!==1||ie!==1||he!==1)&&(b.scale=[xe,ie,he]),A.visible===!1&&(b.extensions={...b.extensions||{},KHR_node_visibility:{visible:!1}},u.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(b.extras=JSON.parse(JSON.stringify(A.userData,(ue,J)=>{if(!(ue==="__proto__"||ue==="prototype"||ue==="constructor"))return typeof J=="function"?void 0:J})),A.userData.xr)){let ue=Oa(A.userData.xr);b.extensions={...b.extensions||{},MOZ_hubs_components:ue,ANDROID_xr_scenecore:ue},Re().xrTraitSerializer?.gltfNode(b,A.userData.xr),u.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let ue=A.geometry,J=ue.attributes.position;if(J&&J.count>0){let se=[1/0,1/0,1/0],P=[-1/0,-1/0,-1/0];for(let V=0;V<J.count;V++){let G=J.getX(V),W=J.getY(V),F=J.getZ(V);G<se[0]&&(se[0]=G),G>P[0]&&(P[0]=G),W<se[1]&&(se[1]=W),W>P[1]&&(P[1]=W),F<se[2]&&(se[2]=F),F>P[2]&&(P[2]=F)}let M={attributes:{POSITION:g(J.array,"VEC3",34962,5126,J.count,se,P)}};if(ue.attributes.normal&&(M.attributes.NORMAL=g(ue.attributes.normal.array,"VEC3",34962,5126,ue.attributes.normal.count)),ue.attributes.uv&&(M.attributes.TEXCOORD_0=g(ue.attributes.uv.array,"VEC2",34962,5126,ue.attributes.uv.count)),ue.index){let V=ue.index.array instanceof Uint32Array;M.indices=g(ue.index.array,"SCALAR",34963,V?5125:5123,ue.index.count)}let D=Array.isArray(A.material)?A.material[0]:A.material;D&&(M.material=_(D));let N=A.userData?.variants;if(N&&typeof N=="object"){let V=new Map;for(let G of Object.keys(N)){if(!G||G==="__proto__"||G==="constructor"||G==="prototype")continue;let W=N[G];if(!W||typeof W!="object")continue;let F=w.indexOf(G);if(F===-1&&w.length<256&&(F=w.length,w.push(G)),F===-1)continue;let Q=_(W),Y=V.get(Q);Y||(Y=[],V.set(Q,Y)),Y.push(F)}if(V.size>0){let G=[];for(let[W,F]of V.entries())G.push({material:W,variants:F});M.extensions={...M.extensions||{},KHR_materials_variants:{mappings:G}},u.add("KHR_materials_variants")}}let C=A;if(C.isInstancedMesh&&typeof C.count=="number"&&C.count>0&&C.instanceMatrix?.array){let V=Math.min(1e4,Math.floor(C.count)),G=C.instanceMatrix.array,W=new Float32Array(V*3),F=new Float32Array(V*4),Q=new Float32Array(V*3);for(let q=0;q<V;q++){let{t:oe,r:ce,s:me}=Pr(G,q*16);W[q*3]=oe[0],W[q*3+1]=oe[1],W[q*3+2]=oe[2],F[q*4]=ce[0],F[q*4+1]=ce[1],F[q*4+2]=ce[2],F[q*4+3]=ce[3],Q[q*3]=me[0],Q[q*3+1]=me[1],Q[q*3+2]=me[2]}let Y={TRANSLATION:g(W,"VEC3",0,5126,V),ROTATION:g(F,"VEC4",0,5126,V),SCALE:g(Q,"VEC3",0,5126,V)};if(C.instanceColor?.array&&C.instanceColor.array.length>=V*3){let q=new Float32Array(C.instanceColor.array.subarray(0,V*3));Y._COLOR_0=g(q,"VEC3",0,5126,V)}b.extensions={...b.extensions||{},EXT_mesh_gpu_instancing:{attributes:Y}},u.add("EXT_mesh_gpu_instancing")}let H=o.length;o.push({primitives:[M],name:A.name,...b.extras?{extras:b.extras}:{}}),b.mesh=H}}let ee=n.length;n.push(b),d.push(A),z.push(ee);let le=A.children;if(Array.isArray(le)&&le.length>0){let ue=[];b.children=ue;for(let J=le.length-1;J>=0;J--)U.push({obj:le[J],parentKids:ue})}}for(let A=0;A<n.length;A++){let z=n[A];z.children&&z.children.length===0?delete z.children:z.children&&z.children.length>0&&(z.extras?.xr?.lod||z.extensions?.ANDROID_xr_scenecore?.lod||d[A]?.isLOD)&&(z.extensions={...z.extensions||{},MSFT_lod:{ids:[...z.children]}},u.add("MSFT_lod"))}let j=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 j=="function"&&d.length>0){let A=e?.duration??4,z=e?.fps??15,S=Math.max(2,Math.round(A*z)+1),b=new Float32Array(S),O=d.map(ie=>[Me(ie.position?.x,0),Me(ie.position?.y,0),Me(ie.position?.z,0),Me(ie.quaternion?.x,0),Me(ie.quaternion?.y,0),Me(ie.quaternion?.z,0),Me(ie.quaternion?.w,1),Me(ie.scale?.x,1),Me(ie.scale?.y,1),Me(ie.scale?.z,1)]),X=d.map(()=>new Float32Array(S*3)),te=d.map(()=>new Float32Array(S*4)),re=d.map(()=>new Float32Array(S*3));for(let ie=0;ie<S;ie++){let he=ie/(S-1)*A;b[ie]=he;try{j(he)}catch{}for(let ee=0;ee<d.length;ee++){let le=d[ee];X[ee][ie*3]=Me(le.position?.x,0),X[ee][ie*3+1]=Me(le.position?.y,0),X[ee][ie*3+2]=Me(le.position?.z,0);let ue=Me(le.quaternion?.x,0),J=Me(le.quaternion?.y,0),se=Me(le.quaternion?.z,0),P=Me(le.quaternion?.w,1),M=Math.hypot(ue,J,se,P)||1;if(ue/=M,J/=M,se/=M,P/=M,ie>0){let D=(ie-1)*4,N=te[ee];N[D]*ue+N[D+1]*J+N[D+2]*se+N[D+3]*P<0&&(ue=-ue,J=-J,se=-se,P=-P)}te[ee][ie*4]=ue,te[ee][ie*4+1]=J,te[ee][ie*4+2]=se,te[ee][ie*4+3]=P,re[ee][ie*3]=Me(le.scale?.x,1),re[ee][ie*3+1]=Me(le.scale?.y,1),re[ee][ie*3+2]=Me(le.scale?.z,1)}}for(let ie=0;ie<d.length;ie++){let he=d[ie],ee=O[ie];he.position?.set(ee[0],ee[1],ee[2]),he.quaternion?.set(ee[3],ee[4],ee[5],ee[6]),he.scale?.set(ee[7],ee[8],ee[9])}t.updateMatrixWorld(!0);let Z=null,ne=()=>(Z===null&&(Z=g(b,"SCALAR",0,5126,S,[0],[A])),Z),pe=[],xe=[];for(let ie=0;ie<d.length;ie++){let he=O[ie],ee=(ue,J,se)=>ue.some((P,M)=>Math.abs(P-he[se+M%J])>1e-4),le=(ue,J,se,P)=>{ue&&xe.push({sampler:pe.push({input:ne(),interpolation:"LINEAR",output:g(J,se,0,5126,S)})-1,target:{node:ie,path:P}})};le(ee(X[ie],3,0),X[ie],"VEC3","translation"),le(ee(te[ie],4,3),te[ie],"VEC4","rotation"),le(ee(re[ie],3,7),re[ie],"VEC3","scale")}xe.length>0&&$.push({name:"ProceduralLoop",samplers:pe,channels:xe})}let L=ur(n,o,t.userData),E=[],B=[],I=[];for(let A=0;A<n.length;A++){let z=n[A],S=Dr(z.extras?.xr);if(!S)continue;let{ae:b,src:O,preset:X,volume:te,loop:re,isGlobal:Z}=S,ne=z.name||`Node_${A}`,pe=B.length;B.push({name:`${ne}_source`,gain:te,loop:re,autoPlay:typeof b.autoplay=="boolean"?b.autoplay:!0,...O!==void 0?{audio:E.push({uri:O})-1}:{},...X?{extras:{preset:X,pitch:gt(b.pitch,.25,4,1)}}:{}});let xe=I.length,ie=gt(b.refDistance,.05,100,1),he=gt(b.coneInnerAngle,0,360,360),ee=gt(b.coneOuterAngle,he,360,360);I.push({name:`${ne}_emitter`,type:Z?"global":"positional",gain:te,sources:[pe],...Z?{}:{positional:{distanceModel:b.distanceModel==="linear"||b.distanceModel==="exponential"?b.distanceModel:"inverse",refDistance:ie,maxDistance:gt(b.maxDistance,ie,500,Math.max(ie,25)),rolloffFactor:gt(b.rolloffFactor,0,10,1),coneInnerAngle:+(he*Math.PI/180).toFixed(6),coneOuterAngle:+(ee*Math.PI/180).toFixed(6),coneOuterGain:gt(b.coneOuterGain,0,1,0)}}}),z.extensions={...z.extensions||{},KHR_audio_emitter:{emitter:xe}},u.add("KHR_audio_emitter")}let c={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:T}],scene:0,nodes:n,meshes:o,materials:h,...p.length>0?{images:p}:{},...m.length>0?{samplers:m}:{},...y.length>0?{textures:y}:{},accessors:a,bufferViews:s,buffers:[{byteLength:r}],...$.length>0?{animations:$}:{},...L||u.size>0?{extensionsUsed:[...L?["KHR_interactivity"]:[],...u]}:{},...L||w.length>0||I.length>0?{extensions:{...L?{KHR_interactivity:L}:{},...w.length>0?{KHR_materials_variants:{variants:w.map(A=>({name:A}))}}:{},...I.length>0?{KHR_audio_emitter:{...E.length>0?{audio:E}:{},sources:B,emitters:I}}:{}}}:{}},k=new Uint8Array(r),K=0;for(let A of i)k.set(A,K),K+=A.byteLength;return[{gltf:c,bin:k.buffer,lights:v,environmentIntensity:t.environmentIntensity},d]}function Ei(t){return new TextEncoder().encode(t)}function ei(t,e){let{gltf:i,bin:r}=jt(t,e),s=JSON.stringify(i),a=Ei(s),o=(4-a.byteLength%4)%4,n=a.byteLength+o,u=20+n+8+r.byteLength,d=new Uint8Array(u),h=new DataView(d.buffer);h.setUint32(0,1179937895,!0),h.setUint32(4,2,!0),h.setUint32(8,u,!0),h.setUint32(12,n,!0),h.setUint32(16,1313821514,!0),d.set(a,20);for(let p=0;p<o;p++)d[20+a.byteLength+p]=32;let l=20+n;return h.setUint32(l,r.byteLength,!0),h.setUint32(l+4,5130562,!0),d.set(new Uint8Array(r),l+8),d}function Ba(t,e){let[i,r]=Nr(t,e);return Rr(i,r)}function Rr(t,e){let i=[],r=t.gltf,s=Re().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,t);let a=t.bin,o=a instanceof ArrayBuffer?a:a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),n=r.accessors||[],u=r.bufferViews||[],d=r.materials||[],h=r.meshes||[],l=r.nodes||[],p=r.textures||[],m=r.images||[],y=r.samplers||[],x=new Set,w=d.map((R,U)=>Ar(x,ti(R?.name,`Material_${U}`))),v=new Map;function _(R){let U=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(R);if(!U)return null;let j=U[2].replace(/\s+/g,""),$=j.endsWith("==")?2:j.endsWith("=")?1:0,L=new Uint8Array((j.length*3>>2)-$),E=I=>{let c=j.charCodeAt(I);return c>96?c-71:c>64?c-65:c>47?c+4:c===43?62:c===47?63:0},B=0;for(let I=0;I<j.length;I+=4){let c=E(I)<<18|E(I+1)<<12|E(I+2)<<6|E(I+3);L[B++]=c>>16&255,B<L.length&&(L[B++]=c>>8&255),B<L.length&&(L[B++]=c&255)}return L}function f(R,U,j){let $=R?.index;if(typeof $!="number")return;let L=p[$],E=L?.source;if(typeof E!="number"||!m[E])return;let B=v.get(E);if(B===void 0){B=null;let k=m[E],K=null;if(typeof k.bufferView=="number"){let A=u[k.bufferView],z=A?.byteOffset||0,S=A?.byteLength||0;A&&S>0&&z>=0&&z+S<=o.byteLength&&(K=new Uint8Array(o,z,S))}else typeof k.uri=="string"&&(K=_(k.uri));if(K&&K.byteLength>0){let A=K[0]===255&&K[1]===216&&K[2]===255||!(K[0]===137&&K[1]===80)&&/jpe?g/i.test(k.mimeType||k.uri||"");B={file:`texture_${E}.${A?"jpg":"png"}`,data:K}}v.set(E,B)}if(!B)return;let I=typeof L.sampler=="number"?y[L.sampler]:void 0,c=k=>k===33071?"clamp":k===33648?"mirror":"repeat";return{file:B.file,data:B.data,wrapS:c(I?.wrapS),wrapT:c(I?.wrapT),...U?{scale:U}:{},...j?{bias:j}:{}}}function g(R){let U=n[R];if(!U)throw new Error(`Accessor ${R} not found`);let j=u[U.bufferView||0],$=(j.byteOffset||0)+(U.byteOffset||0),L=j.byteLength||0;return{acc:U,buffer:o.slice($,$+L)}}function T(R,U,j,$){let L=[],E=h[R];if(!E)return L;let B=E.primitives||[];for(let I=0;I<B.length;I++){let c=B[I],k=c.attributes?.POSITION;if(k===void 0)continue;let{acc:K,buffer:A}=g(k),z=new Float32Array(A,0,K.count*3),S,b=c.attributes?.NORMAL;if(b!==void 0){let{acc:J,buffer:se}=g(b),P=new Float32Array(se,0,J.count*3);S=new Float32Array(P.length);for(let M=0;M<J.count;M++){let D=P[M*3],N=P[M*3+1],C=P[M*3+2],H=Math.hypot(D,N,C)||1;S[M*3]=D/H,S[M*3+1]=N/H,S[M*3+2]=C/H}}let O,X=c.attributes?.TEXCOORD_0;if(X!==void 0){let{acc:J,buffer:se}=g(X);O=new Float32Array(se,0,J.count*2)}let te;if(c.indices!==void 0){let{acc:J,buffer:se}=g(c.indices);te=J.componentType===5125?new Uint32Array(se,0,J.count):new Uint16Array(se,0,J.count);let P=K.count;for(let M of te)if(M>=P)throw new Error(`SecurityError: Index buffer value (${M}) out of vertex bounds [0, ${P}).`)}else{let J=K.count;te=J>65535?new Uint32Array(J):new Uint16Array(J);for(let se=0;se<J;se++)te[se]=se}let re="DefaultMaterial",Z=[1,1,1],ne=.5,pe=0,xe=0,ie=0,he=1.5,ee=1,le=[0,0,0],ue;if(c.material!==void 0&&d[c.material]){let J=d[c.material];re=w[c.material]||`Material_${c.material}`;let se=J.pbrMetallicRoughness||{},P=(oe,ce)=>Array.isArray(oe)&&oe.length>=3?[oe[0],oe[1],oe[2]]:ce;Z=P(se.baseColorFactor,[1,1,1]);let M=Array.isArray(se.baseColorFactor)&&typeof se.baseColorFactor[3]=="number"?se.baseColorFactor[3]:1,D=Z[0]!==1||Z[1]!==1||Z[2]!==1||M!==1,N=f(se.baseColorTexture,D?[Z[0],Z[1],Z[2],M]:void 0),C=J.extras?.avgColor;!N&&Array.isArray(C)&&C.length>=3&&(Z=[Z[0]*C[0],Z[1]*C[1],Z[2]*C[2]]),typeof se.roughnessFactor=="number"&&(ne=se.roughnessFactor),typeof se.metallicFactor=="number"&&(pe=se.metallicFactor);let H=typeof se.roughnessFactor=="number"?se.roughnessFactor:1,V=typeof se.metallicFactor=="number"?se.metallicFactor:1,G=f(se.metallicRoughnessTexture,H!==1||V!==1?[1,H,V,1]:void 0);le=P(J.emissiveFactor,[0,0,0]);let W=(le[0]>0||le[1]>0||le[2]>0)&&(le[0]!==1||le[1]!==1||le[2]!==1)?[le[0],le[1],le[2],1]:void 0,F=f(J.emissiveTexture,W),Q=f(J.normalTexture,[2,2,2,1],[-1,-1,-1,0]),Y=f(J.occlusionTexture);(N||G||Q||F||Y)&&(ue=[N,G,Q,F,Y]);let q=J.extensions||{};q.KHR_materials_clearcoat&&(xe=q.KHR_materials_clearcoat.clearcoatFactor??0,ie=q.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof q.KHR_materials_ior?.ior=="number"&&(he=q.KHR_materials_ior.ior),ee=M*(1-(q.KHR_materials_transmission?.transmissionFactor??0))}L.push({name:B.length>1?`${U}_p${I}`:U,positions:z,indices:te,normals:S,uvs:O,materialName:re,color:Z,roughness:ne,metallic:pe,clearcoat:xe,clearcoatRoughness:ie,ior:he,opacity:ee,emissiveColor:le,...ue?{textures:ue}:{},xrTraits:j||E.extras?.xr,...$?{invisible:!0}:{}})}return L}if(l.length>0){let R=new Float32Array(0),U=new Uint16Array(0),j=(z,S)=>{if(z===void 0)return null;let{acc:b,buffer:O}=g(z);return new Float32Array(O,0,b.count*S)},$=(z,S)=>Array.isArray(z)&&z.length>=3?[Me(z[0],S),Me(z[1],S),Me(z[2],S)]:[S,S,S],L=(z,S,b)=>z&&z.length>=(S+1)*3?[z[S*3],z[S*3+1],z[S*3+2]]:b,E=(z,S,b)=>z&&z.length>=(S+1)*4?[z[S*4],z[S*4+1],z[S*4+2],z[S*4+3]]:b,B=new Map,I=r.animations?.[0];if(I&&Array.isArray(I.channels)&&Array.isArray(I.samplers))for(let z of I.channels){let S=I.samplers[z?.sampler],b=z?.target?.node,O=z?.target?.path;if(!S||typeof b!="number"||S.input===void 0)continue;let X=B.get(b);X||(X={input:S.input},B.set(b,X)),O==="translation"?X.t=S.output:O==="rotation"?X.r=S.output:O==="scale"&&(X.s=S.output)}let c=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(c)||c.length===0){let z=new Set;for(let S of l)if(Array.isArray(S?.children))for(let b of S.children)z.add(b);c=[];for(let S=0;S<l.length;S++)z.has(S)||c.push(S);c.length===0&&(c=[0])}let k=new Set,K=[],A=(z,S)=>{if(Array.isArray(z))for(let b=z.length-1;b>=0;b--)K.push({idx:z[b],out:S})};for(A(c,i);K.length>0;){let{idx:z,out:S}=K.pop();if(typeof z!="number"||z<0||z>=l.length||k.has(z))continue;k.add(z);let b=l[z];if(!b)continue;let O=[0,0,0],X=[0,0,0,1],te=[1,1,1];if(Array.isArray(b.matrix)&&b.matrix.length===16){let ee=Pr(b.matrix);O=ee.t,X=ee.r,te=ee.s}else O=$(b.translation,0),Array.isArray(b.rotation)&&b.rotation.length>=4&&(X=[Me(b.rotation[0],0),Me(b.rotation[1],0),Me(b.rotation[2],0),Me(b.rotation[3],1)]),te=$(b.scale,1);let re,Z=B.get(z);if(Z){let ee=j(Z.input,1);if(ee&&ee.length>0){let le=j(Z.t,3),ue=j(Z.r,4),J=j(Z.s,3),se=Array.from(ee),P=[],M=[],D=[];for(let N=0;N<ee.length;N++)P.push(L(le,N,O)),M.push(E(ue,N,X)),D.push(L(J,N,te));re={times:se,translations:P,rotations:M,scales:D}}}let ne=Array.isArray(b.children)?b.children:[],pe=typeof b.mesh=="number"&&b.mesh>=0&&b.mesh<h.length,xe=e?.[z]?.userData?.xr??b.extras?.xr;if(!pe&&ne.length===0&&(b.camera!==void 0||b.extensions?.KHR_lights_punctual||!b.name&&!b.extras&&!xe&&!re))continue;let ie=(ee,le,ue)=>({name:ee,positions:R,indices:U,isXform:!0,xrTraits:xe,timeSamples:re,translation:O,rotation:X,scale:te,children:le,...ue?{invisible:!0}:{}}),he=b.visible===!1||b.extensions?.KHR_node_visibility?.visible===!1||e?.[z]?.visible===!1;if(pe){let ee=b.name||h[b.mesh]?.name||`Mesh_${z}`,le=T(b.mesh,ee,xe,he),ue=b.extensions?.EXT_mesh_gpu_instancing?.attributes;if(ue&&typeof ue=="object"&&le.length>0){let J=j(ue.TRANSLATION,3),se=j(ue.ROTATION,4),P=j(ue.SCALE,3),M=j(ue._COLOR_0,3),D=Math.min(1e3,J?J.length/3:se?se.length/4:P?P.length/3:0);if(D>0){let N=[];for(let C=0;C<D;C++){let H=L(J,C,[0,0,0]),V=E(se,C,[0,0,0,1]),G=L(P,C,[1,1,1]);for(let W of le){let F=W.color||[.8,.8,.8],Q=M&&M.length>=(C+1)*3;N.push({...W,name:`${W.name}_${C}`,materialName:Q?`${W.materialName}_inst_${C}`:W.materialName,color:Q?[F[0]*M[C*3],F[1]*M[C*3+1],F[2]*M[C*3+2]]:W.color,translation:H,rotation:V,scale:G})}}A(ne,N),S.push(ie(ee,N,he));continue}}if(le.length===1)le[0].translation=O,le[0].rotation=X,le[0].scale=te,le[0].timeSamples=re,ne.length>0&&(le[0].children=[],A(ne,le[0].children)),S.push(le[0]);else{let J=[...le];A(ne,J),S.push(ie(ee,J,he))}}else{let ee=[];A(ne,ee),S.push(ie(b.name||`Group_${z}`,ee,he))}}}else for(let R=0;R<h.length;R++){let U=h[R].name||`Mesh_${R}`;i.push(...T(R,U,h[R].extras?.xr))}return i}function ti(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function ii(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function $e(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var dt=(t,e,i)=>`(${$e(t)}, ${$e(e)}, ${$e(i)})`,ri=(t,e,i,r)=>`(${$e(t)}, ${$e(e)}, ${$e(i)}, ${$e(r)})`;function Er(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=dt(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function ja(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${$e(t[r*2])}, ${$e(1-t[r*2+1])})`;return i.join(", ")}function Va(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function Ga(t){let e=new Map,i=0,r=null,s=[...t];for(;s.length>0;){let y=s.pop();if(!y.isXform&&y.positions&&y.positions.length>0){let x=ti(y.materialName,"DefaultMaterial");e.has(x)||e.set(x,{color:y.color||[1,1,1],roughness:y.roughness??.5,metallic:y.metallic??0,clearcoat:y.clearcoat??0,clearcoatRoughness:y.clearcoatRoughness??0,ior:y.ior??1.5,opacity:y.opacity??1,emissiveColor:y.emissiveColor||[0,0,0],textures:y.textures})}if(y.timeSamples&&y.timeSamples.times.length>0){let x=y.timeSamples.times[y.timeSamples.times.length-1];x>i&&(i=x)}if(y.xrTraits?.anchor&&!r&&(r=y.xrTraits.anchor==="vertical"||y.xrTraits.anchor==="wall"?"vertical":"horizontal"),y.children)for(let x=y.children.length-1;x>=0;x--)s.push(y.children[x])}let a="";i>0&&(a=`startTimeCode = 0
|
|
251
|
-
endTimeCode = ${
|
|
215
|
+
void main(){fragColor=uColorId;}`;function Sr(t,e,i){let r={};for(let s of i)r[s]=t.getUniformLocation(e,s);return r}var Eo="uMVP uModel uInstanced uViewProj uNormalMatrix uUvTransform uBaseColor uMetallic uRoughness uClearcoat uEmissive uCameraPos uBaseColorTexture uHasTexture uMetallicRoughnessTexture uHasMetallicRoughnessTexture uNormalTexture uHasNormalTexture uNormalScale uOcclusionTexture uHasOcclusionTexture uOcclusionStrength uEmissiveFactor uEmissiveTexture uHasEmissiveTexture uToneMapping uEnvironmentMap uHasEnvironmentMap uAmbientColor uHemi uNumDirLights uDirLightDir uDirLightColor uNumPointLights uPointLightPos uPointLightColor uPointLightSpotDir uPointLightSpotCone uEnvIntensity uExposure uViewportSize uSectionPlane uSectionEnabled".split(" ");function an(){let t=mt(),e=t.xrDepthShader,i=t.shadowMapShader;return{fs:$o.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||"").replace("/*SHD_U*/",i?.uniformsGLSL||"").replace("/*SHD_D*/",i?.dirGLSL||"").replace("/*SHD_P*/",i?.ptGLSL||""),uniforms:[...Eo,...e?.uniformNames||[],...i?.uniformNames||[]]}}function Fo(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let i=e.toLowerCase();return i.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:i.startsWith("https://")||i.startsWith("blob:")?e:i.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function on(t,e,i,r,s,a,f,c){if(r===void 0||!e.accessors?.[r])return null;let h=rs(e,i,e.accessors[r],a);if(!h)return null;c&&(h=h.slice(),No(h,c));let C=t.createBuffer();return f.push(C),t.bindBuffer(34962,C),t.bufferData(34962,h,35044),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,a,5126,!1,0,0),h}function ln(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function ls(t,e,i){let r=an(),s=sn,a=r.fs,f=!1;for(let h of Nt)if(h.onResolveShader){let C=h.onResolveShader(e,i,s,a);C&&(s=C.vs,a=C.fs,f=!0)}let c=f?wr(t,s,a):null;return{program:c,uniforms:c?Sr(t,c,r.uniforms):null}}function Ro(t,e,i){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let s=r.length>>4,a=e.instanceColors,f=new Float32Array(s*20);for(let h=0;h<s;h++)f.set(r.subarray(h*16,h*16+16),h*20),f[h*20+16]=a?a[h*3]:1,f[h*20+17]=a?a[h*3+1]:1,f[h*20+18]=a?a[h*3+2]:1,f[h*20+19]=1;let c=t.createBuffer();i.push(c),t.bindBuffer(34962,c),t.bufferData(34962,f,35044);for(let h=0;h<5;h++)t.enableVertexAttribArray(8+h),t.vertexAttribPointer(8+h,4,5126,!1,80,h*16),t.vertexAttribDivisor(8+h,1);return!0}function Io(t,e){let i=t.materials?.[e?.material];if(!i)return null;let r=[i.pbrMetallicRoughness?.baseColorTexture,i.pbrMetallicRoughness?.metallicRoughnessTexture,i.normalTexture,i.occlusionTexture,i.emissiveTexture];for(let s of r){let a=s?.extensions?.KHR_texture_transform;if(a&&typeof a=="object")return a}return null}var su=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),hs=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function Ar(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function us(t,e){let i=t?.pbrMetallicRoughness,r=i?.baseColorFactor,s=t?.emissiveFactor,a=t?.extensions?.KHR_materials_clearcoat,f=c=>c!==void 0&&e[c.index]?e[c.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:i?.metallicFactor??.1,roughness:i?.roughnessFactor??.5,clearcoat:a?a.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,a?.clearcoatRoughnessFactor??.04),texture:f(i?.baseColorTexture),metallicRoughnessTexture:f(i?.metallicRoughnessTexture),normalTexture:f(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:f(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,emissiveTexture:f(t?.emissiveTexture),emissiveFactor:Array.isArray(s)&&s.length>=3?[s[0],s[1],s[2]]:[0,0,0],isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function cs(t,e,i){let r=new Set,s=a=>{a&&!r.has(a)&&(r.add(a),t.deleteTexture(a))};for(let a of e)for(let f of a.primitives){if(f.vao&&t.deleteVertexArray(f.vao),f.buffers)for(let h of f.buffers)t.deleteBuffer(h);for(let h of[f.texture,f.metallicRoughnessTexture,f.normalTexture,f.occlusionTexture,f.emissiveTexture])s(h);let c=new Set;f.customProgram&&c.add(f.customProgram);for(let h of f.programCache?.values()??[])h.program&&c.add(h.program);for(let h of c)t.deleteProgram(h)}if(i)for(let a of i)s(a)}function fs(t,e,i=hs,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Uo(t,e,i,r,s)}catch(a){let f=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;cs(t,f,s.gpuTextures),s.vao&&t.deleteVertexArray(s.vao);for(let c of s.buffers)t.deleteBuffer(c);throw a}}function Uo(t,e,i,r,s){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:a}=e,f=_r("meshopt");f?.decodeBufferViews&&f.decodeBufferViews(a,e);let c=e.bin,h=[];s.meshes=h;let C=[],d=a.extensions?.KHR_materials_variants;d&&Array.isArray(d.variants)&&d.variants.forEach((v,P)=>{C.push(typeof v?.name=="string"&&v.name?v.name:`Variant_${P}`)});let p=Kn(a),m=[];if(Array.isArray(a.nodes))for(let v=0;v<a.nodes.length;v++){let P=a.nodes[v];P.mesh!==void 0&&a.meshes&&a.meshes[P.mesh]&&m.push({node:P,nodeIdx:v,meshIdx:P.mesh})}let y=m.length>0?m:(a.meshes||[]).map((v,P)=>({node:v,nodeIdx:-1,meshIdx:P})),z=[],E=Array.isArray(e.lights)&&e.lights.length>0?e.lights:Array.isArray(a.asset?.extras?.lights)&&a.asset.extras.lights.length>0?a.asset.extras.lights:null;if(E)for(let v of E)z.push({...v,type:v.type||v.light_type||"point",groundColor:v.groundColor??v.ground_color,innerConeAngle:v.innerConeAngle??v.inner_cone_angle,outerConeAngle:v.outerConeAngle??v.outer_cone_angle});else a.extensions?.KHR_lights_punctual?.lights&&z.push(...os(a,p));if(z.length===0&&(z.push({type:"ambient",color:[1,1,1],intensity:.35}),z.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),y.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${y.length}`);let _=[];if(s.gpuTextures=_,a.textures&&a.images){if(a.textures.length>i.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${i.maxTextures}). Found: ${a.textures.length}`);for(let v=0;v<a.textures.length;v++){let P=a.textures[v],H=a.images[P.source];if(H){let G=t.createTexture();t.bindTexture(3553,G),t.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255]));for(let[V,Y]of[[10242,10497],[10243,10497],[10241,9729],[10240,9729]])t.texParameteri(3553,V,Y);let x=V=>{G.__gpuImageSource=V,t.bindTexture(3553,G),t.texImage2D(3553,0,6408,6408,5121,V),t.generateMipmap(3553),r?.()};if(H.bufferView!==void 0){let V=a.bufferViews[H.bufferView],Y=V.byteOffset||0,Z=new Blob([c.slice(Y,Y+V.byteLength)],{type:H.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(Z).then(x).catch(()=>{})}else if(H.uri){let V=Fo(H.uri);if(V){let Y=new Image;Y.crossOrigin="anonymous",Y.referrerPolicy="no-referrer",Y.onload=()=>x(Y),Y.src=V}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",H.uri)}_.push(G)}else _.push(null)}}let b=[1/0,1/0,1/0],$=[-1/0,-1/0,-1/0],T=0,M=0;for(let v=0;v<y.length;v++){let P=y[v],H=a.meshes[P.meshIdx],G=P.nodeIdx>=0?p[P.nodeIdx]:Ct(),x=new Float32Array(9);zi(x,G);let V=P.node?.extras?.shadow,Y={name:P.node.name||H.name||`Mesh_${P.meshIdx}`,nodeIndex:P.nodeIdx,transform:G,normalMatrix:x,primitives:[],extras:P.node.extras||H.extras,...P.node?.visible===!1||P.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{},...typeof V?.cast=="boolean"?{castShadow:V.cast}:{},...typeof V?.receive=="boolean"?{receiveShadow:V.receive}:{}};s.mesh=Y;let Z=P.node?.extensions?.EXT_mesh_gpu_instancing;if(Z&&Z.attributes&&typeof Z.attributes=="object"){let q=Z.attributes,X=q.TRANSLATION!==void 0?a.accessors?.[q.TRANSLATION]:null,F=q.ROTATION!==void 0?a.accessors?.[q.ROTATION]:null,Q=q.SCALE!==void 0?a.accessors?.[q.SCALE]:null,L=q._COLOR_0!==void 0?a.accessors?.[q._COLOR_0]:null,ee=Number(X?.count??F?.count??Q?.count??0);if(!Number.isFinite(ee)||ee<0||ee>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${ee}`);if(ee>0){let ae=(Me,ze)=>{if(!Me||Me.bufferView===void 0||!a.bufferViews?.[Me.bufferView])return null;let Se=Me.componentType??5126,He=j=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${j})`),null);if(Se!==5120&&Se!==5121&&Se!==5122&&Se!==5123&&Se!==5126)return He(`componentType ${Se}`);if(!(Number(Me.count)>=ee))return He(`count ${Me.count} < ${ee}`);let J=null;try{J=rs(a,c,{...Me,count:ee},ze)}catch{return He("out of bounds")}return!J||!J.every(Number.isFinite)?He("non-finite value"):J},be=ae(X,3),Ne=ae(F,4),De=ae(Q,3),Be=L?.type==="VEC4"?4:3,je=ae(L,Be),Ve=new Float32Array(ee*16),Ie=Ct();for(let Me=0;Me<ee;Me++){let ze=Me*3,Se=Me*4;tn(Ie,Ne?[Ne[Se],Ne[Se+1],Ne[Se+2],Ne[Se+3]]:[0,0,0,1],be?[be[ze],be[ze+1],be[ze+2]]:[0,0,0],De?[De[ze],De[ze+1],De[ze+2]]:[1,1,1]),Ve.set(Ie,Me*16)}if(Y.instanceMatrices=Ve,je){let Me=new Float32Array(ee*3);for(let ze=0;ze<ee;ze++)Me[ze*3]=je[ze*Be],Me[ze*3+1]=je[ze*Be+1],Me[ze*3+2]=je[ze*Be+2];Y.instanceColors=Me}}}for(let q of H.primitives||[]){if(q.extensions?.KHR_draco_mesh_compression){let I=_r("draco");I&&I.decodePrimitive(a,q,c)}let X=[],F=t.createVertexArray();s.vao=F,s.buffers=X,t.bindVertexArray(F);let Q=Ro(t,Y,X),L=a.accessors[q.attributes.POSITION],ee=Number(L?.count??0);if(!Number.isFinite(ee)||ee<0||T+ee>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(T+=ee,L?.min&&L?.max){let I=O=>{for(let K=0;K<3;K++){let ie=O[12+K],he=ie;for(let ue=0;ue<3;ue++){let ge=O[ue*4+K]*L.min[ue],oe=O[ue*4+K]*L.max[ue];ie+=ge<oe?ge:oe,he+=ge>oe?ge:oe}ie<b[K]&&(b[K]=ie),he>$[K]&&($[K]=he)}};if(Y.instanceMatrices&&Y.instanceMatrices.length>=16){let O=Y.instanceMatrices.length>>4,K=Ct();for(let ie=0;ie<O;ie++)Et(K,G,Y.instanceMatrices.subarray(ie*16,ie*16+16)),I(K)}else I(G)}let ae=on(t,a,c,q.attributes.POSITION,0,3,X),be=on(t,a,c,q.attributes.NORMAL,1,3,X),Ne=on(t,a,c,q.attributes.TEXCOORD_0,2,2,X,Io(a,q)),De=0,Be=5123,je=null;if(q.indices!==void 0){let I=a.accessors[q.indices],O=(a.bufferViews[I.bufferView].byteOffset||0)+(I.byteOffset||0);if(De=Number(I.count??0),!Number.isFinite(De)||De<0||M+De>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);M+=De,Be=I.componentType===5125?5125:5123;let K=t.createBuffer();X.push(K),t.bindBuffer(34963,K),I.componentType===5125?je=new Uint32Array(c,O,I.count):I.componentType===5121?je=Uint16Array.from(new Uint8Array(c,O,I.count)):je=O%2===0?new Uint16Array(c,O,I.count):new Uint16Array(c.slice(O,O+I.count*2)),t.bufferData(34963,je,35044)}else De=L.count;let Ve={};for(let I of Nt)if(I.onBuildPrimitiveVAO){let O=I.onBuildPrimitiveVAO(t,F,q,a,c);O&&(Ve[I.name]=O)}t.bindVertexArray(null);let Ie=a.materials&&q.material!==void 0?a.materials[q.material]:null,{program:Me,uniforms:ze}=ls(t,q,Ie),Se=us(Ie,_),He=!!(Ie?.extensions?.KHR_materials_transmission||Ve.materials?.isTransmissive),J=q.extensions?.KHR_materials_variants?.mappings,j=Array.isArray(J)?J.filter(I=>I&&typeof I.material=="number"&&Array.isArray(I.variants)).map(I=>({material:I.material|0,variants:I.variants.map(O=>Number(O)|0)})):void 0;Y.primitives.push({vao:F,instanced:Q,indexCount:De,indexType:Be,...Se,positions:ae,normals:be,uvs:Ne,indices:je,buffers:X,materialIndex:q.material,defaultMaterialIndex:q.material,variantMappings:j,primitiveDef:q,programCache:new Map([[q.material??-1,{program:Me,uniforms:ze}]]),pluginData:Ve,customProgram:Me,customUniforms:ze,isTransmissive:He})}h.push(Y)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite($[0])||($=[1,1,1]);let N=[(b[0]+$[0])/2,(b[1]+$[1])/2,(b[2]+$[2])/2],k=Math.max(Math.hypot($[0]-b[0],$[1]-b[1],$[2]-b[2])/2,.5),A=[...b],S=[...$],w=e.animations;if(e.animationsParsed===!1||!w){for(let v of Nt)if(v.onParseGLB?.(e),e.animations){w=e.animations;break}}return w||(w=[]),{meshes:h,bounds:{center:N,radius:k,min:A,max:S},lights:z,animations:w,worldMatrices:p,gpuTextures:_,availableVariants:C}}function Tr(){return typeof performance<"u"?performance.now():Date.now()}function tr(t){let e=t.customTarget||t.bounds.center,i=t.currDistance*Math.cos(t.currPhi);return[e[0]+i*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+i*Math.cos(t.currTheta)]}var ps=class{constructor(t,e,i){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=Ct(),this.clearColor=[0,0,0,0],this.envIntensity=1,this.exposure=1,this.shadowIntensity=0,this.shadowSoftness=.5,this.toneMapping="neutral",this.environmentTexture=null,this.environmentSource=null,this.animations=[],this.currentClip=null,this.animationTime=0,this.isPlayingAnimation=!1,this.autoplay=!1,this.animationName="",this.gpuTextures=[],this.availableVariants=[],this.activeVariantName=null,this.gltf=null,this.worldMatrices=[],this.initialNodeTransforms=[],this.projMatrix=Ct(),this.viewMatrix=Ct(),this.activeViewMatrix=null,this.modelMatrix=Ct(),this.mvpMatrix=Ct(),this.normalMatrix=new Float32Array(9),this.initialTheta=.6,this.initialPhi=.35,this.initialDistance=null,this.customDistance=!1,this.distanceMode="auto",this.initialCustomTarget=null,this.customTarget=null,this.fov=Math.PI/4,this.minTheta=-1/0,this.maxTheta=1/0,this.minPhi=-Math.PI*.48,this.maxPhi=Math.PI*.48,this.minDistanceLimit=null,this.maxDistanceLimit=null,this.activePointers=new Map,this.isPanning=!1,this.targetTheta=.6,this.currTheta=.6,this.targetPhi=.35,this.currPhi=.35,this.targetDistance=3,this.currDistance=3,this.autoRotate=!1,this.autoRotateSpeed=Math.PI/6,this.autoRotateDelay=3e3,this.lastInteractionTime=-1/0,this.turntableRotation=0,this.isPointerDown=!1,this.interactive=!0,this.skyboxTexture=null,this.lastPointerX=0,this.lastPointerY=0,this.totalDragDist=0,this.selectedMeshNames=new Set,this.pickFbo=null,this.pickTexture=null,this.pickDepth=null,this.pickFboWidth=0,this.pickFboHeight=0,this.animFrameId=null,this.isVisible=!0,this.xrSessionActive=!1,this.lastTime=0,this.lastReportedTheta=-999,this.lastReportedPhi=-999,this.lastReportedZoom=-999,this.boundPointerDown=null,this.boundPointerMove=null,this.boundPointerUp=null,this.boundWheel=null,this.boundKeyDown=null,this.boundContextMenu=null,this.boundSetCamera=null,this.boundResetCamera=null,this.contextLost=!1,this.lastGlbData=null,this.boundContextLost=null,this.boundContextRestored=null,this.stereoSBS=!1,this.renderErrorReported=!1,this.xrDepthState={enabled:!1,texture:null,uvTransform:Ct(),rawValueToMeters:.001,format:0},this.container=t;let r,s;if(e&&typeof e.getContext=="function"?(r=e,s=i):(s=e,r=s?.canvas),!r){let h=t.querySelector("canvas");h||(h=document.createElement("canvas"),h.style.cssText="width:100%;height:100%;display:block;touch-action:none",t.prepend(h)),r=h}this.canvas=r;let a=this.opts=s||{};a.clearColor&&(this.clearColor=a.clearColor);let f=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;a.autoRotate!==void 0?this.autoRotate=a.autoRotate&&!f:f&&(this.autoRotate=!1),a.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=a.autoRotateSpeed),a.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(a.autoRotateDelay)||0)),a.exposure!==void 0&&(this.exposure=ln(a.exposure)),a.camera&&this.setInitialCamera(a.camera.theta,a.camera.phi,a.camera.distance,a.camera.zoom),(a.shadowIntensity!==void 0||a.shadowSoftness!==void 0)&&this.setShadow(a.shadowIntensity??0,a.shadowSoftness),a.shadowMaps!==void 0&&(this.shadowMaps=a.shadowMaps),a.toneMapping!==void 0&&(this.toneMapping=rn(a.toneMapping)),a.autoplay!==void 0&&(this.autoplay=a.autoplay),a.animationName!==void 0&&(this.animationName=a.animationName),a.variantName!==void 0&&(this.activeVariantName=a.variantName||null),a.fieldOfView!==void 0&&(this.fov=a.fieldOfView*Math.PI/180),a.distanceMode!==void 0&&(this.distanceMode=a.distanceMode),a.cameraTarget!==void 0&&(this.setTarget(a.cameraTarget[0],a.cameraTarget[1],a.cameraTarget[2]),this.initialCustomTarget=[...a.cameraTarget]),(a.minCameraOrbit||a.maxCameraOrbit)&&this.setOrbitLimits({minTheta:a.minCameraOrbit?.theta,maxTheta:a.maxCameraOrbit?.theta,minPhi:a.minCameraOrbit?.phi,maxPhi:a.maxCameraOrbit?.phi,minDistance:a.minCameraOrbit?.distance,maxDistance:a.maxCameraOrbit?.distance});let c=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!c)throw new Error("WebGL2 not supported");this.gl=c,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),a.environmentImage&&this.setEnvironmentImage(a.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&a.autoStart!==!1&&this.start()}static registerDecoder(t,e){Lo(t,e)}static getDecoder(t){return _r(t)}setupContextLossHandling(){let t=this.canvas;typeof t?.addEventListener=="function"&&(this.boundContextLost=e=>{e.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),t.addEventListener("webglcontextlost",this.boundContextLost),t.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let t=this.gl,e=an();this.renderProg=wr(t,sn,e.fs),this.pickProg=wr(t,zo,ko),this.uRender=Sr(t,this.renderProg,e.uniforms),this.uPick=Sr(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}recompileRenderProgram(){if(this.contextLost)return;let t=this.gl,e=an();this.renderProg&&t.deleteProgram(this.renderProg),this.renderProg=wr(t,sn,e.fs),this.uRender=Sr(t,this.renderProg,e.uniforms);for(let i of this.meshes)for(let r of i.primitives)r.customProgram&&(t.deleteProgram(r.customProgram),r.programCache?.clear(),this.applyPrimitiveProgram(r,r.materialIndex,this.gltf?.materials?.[r.materialIndex??-1]??null))}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of Nt)e.onContextRestored?.(t,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let t=this.gl;typeof t.createFramebuffer=="function"&&(this.pickFbo=t.createFramebuffer(),this.pickTexture=t.createTexture(),this.pickDepth=t.createRenderbuffer(),this.resizePickingFbo(this.canvas.width,this.canvas.height),t.bindFramebuffer(36160,this.pickFbo),t.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),t.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),t.bindFramebuffer(36160,null))}resizePickingFbo(t,e){if(!this.pickFbo)return;let i=this.gl,r=Math.max(1,t),s=Math.max(1,e);this.pickFboWidth=r,this.pickFboHeight=s,i.bindTexture(3553,this.pickTexture),i.texImage2D(3553,0,6408,r,s,0,6408,5121,null),i.texParameteri(3553,10241,9728),i.texParameteri(3553,10240,9728),i.bindRenderbuffer(36161,this.pickDepth),i.renderbufferStorage(36161,33189,r,s)}loadGLBData(t,e){let{meshes:i,bounds:r,lights:s,animations:a,worldMatrices:f,gpuTextures:c,availableVariants:h}=fs(this.gl,t,e,()=>this.render());this.lastGlbData=t,this.lastLimits=e,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=i,this.bounds=r,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=s,this.animations=a||[],this.worldMatrices=f||[],this.gpuTextures=c||[],this.availableVariants=h||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=(t.gltf?.nodes||[]).map(p=>({t:[p.translation?.[0]??0,p.translation?.[1]??0,p.translation?.[2]??0],r:[p.rotation?.[0]??0,p.rotation?.[1]??0,p.rotation?.[2]??0,p.rotation?.[3]??1],s:[p.scale?.[0]??1,p.scale?.[1]??1,p.scale?.[2]??1]})),this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let p of Nt)p.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:r.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let C=t.exposure??t.gltf?.extras?.exposure??t.gltf?.asset?.extras?.exposure;C!==void 0&&(this.exposure=ln(C));let d=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;d!==void 0&&(this.envIntensity=Math.max(0,Number(d)||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(as(t))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let t of Nt)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(nn(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=nn(t),{meshes:r}=fs(this.gl,i,hs,()=>this.render());if(e)for(let s of r)s.transform[12]+=e[0],s.transform[13]+=e[1],s.transform[14]+=e[2],zi(s.normalMatrix,s.transform);this.backdropMeshes=r,this.update(0),this.render()}setClearColor(t,e,i,r=1){this.clearColor=[t,e,i,r]}updateMeshTransforms(t){for(let e=0;e<this.meshes.length;e++){let i=this.meshes[e],r=t instanceof Map?t.get(i.name)??t.get(e):Array.isArray(t)?t[e]:t&&typeof t=="object"?Object.prototype.hasOwnProperty.call(t,i.name)?t[i.name]:Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0:void 0;r&&r.length===16&&(i.transform.set(r),zi(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[0,0,0,0,0,0,0,1,0],s=!1,a=[],f=[],c=[],h=[],C=[],d=[];for(let p of this.lights){let m=p.color||[1,1,1],y=p.intensity!==void 0?p.intensity:1;if(p.type==="ambient")i=[m[0]*y,m[1]*y,m[2]*y];else if(p.type==="hemisphere"){s=!0;let z=p.groundColor||[.2,.2,.2],E=y*.65;for(let $=0;$<3;$++)r[$]+=m[$]*E,r[$+3]+=z[$]*E;let _=p.position||[0,1,0],b=Math.hypot(_[0],_[1],_[2]);b>1e-5&&(r[6]=_[0]/b,r[7]=_[1]/b,r[8]=_[2]/b)}else if(p.type==="directional"&&a.length<6){let z=p.direction||[.5,1,.8];a.push(z[0],z[1],z[2]),f.push(m[0]*y,m[1]*y,m[2]*y)}else if((p.type==="point"||p.type==="spot")&&c.length<6){let z=p.position||[0,0,0];if(c.push(z[0],z[1],z[2]),h.push(m[0]*y,m[1]*y,m[2]*y),p.type==="spot"){let E=p.direction||[0,-1,0],_=Math.max(.01,Math.min(Math.PI/2,p.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(_-1e-4,p.innerConeAngle??0));C.push(E[0],E[1],E[2]),d.push(Math.cos(b),Math.cos(_))}else C.push(0,-1,0),d.push(-2,-3)}}a.length===0&&!s&&(a.push(.5,1,.8),f.push(1,1,1)),e.uniform3fv(t.uAmbientColor,i),t.uHemi&&e.uniformMatrix3fv(t.uHemi,!1,r),e.uniform1i(t.uNumDirLights,a.length/3),a.length>0&&(e.uniform3fv(t.uDirLightDir,a),e.uniform3fv(t.uDirLightColor,f)),e.uniform1i(t.uNumPointLights,c.length/3),c.length>0&&(e.uniform3fv(t.uPointLightPos,c),e.uniform3fv(t.uPointLightColor,h),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,C),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,d)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=ln(t)}getExposure(){return this.exposure}setShadow(t,e){this.shadowIntensity=Math.max(0,Math.min(1,Number(t)||0)),e!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(e)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(t){this.toneMapping=rn(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){this.environmentSource=t&&typeof t=="object"?t:null;for(let e of Nt)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t),this.render();return}this.render()}async setSkyboxImage(t){for(let e of Nt)if(e.setSkyboxImage){await e.setSkyboxImage(this,t);return}}setInteractive(t){this.interactive=t}isInteractive(){return this.interactive}getCameraOrbit(){let t=this.currTheta,e=this.currPhi,i=this.currDistance;return{theta:t,phi:e,radius:i,toString(){return`${t.toFixed(4)}rad ${e.toFixed(4)}rad ${i.toFixed(4)}m`}}}getCameraTarget(){let t=this.customTarget||this.bounds.center;return{x:t[0],y:t[1],z:t[2],toString(){return`${t[0].toFixed(4)}m ${t[1].toFixed(4)}m ${t[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let t=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return t.map((e,i)=>{let r=this.meshes.flatMap(d=>d.primitives.filter(p=>p.materialIndex===i||t.length===1&&p.materialIndex===void 0)),s=r[0],a=s?[...s.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],f=s?s.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,c=s?s.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,h=(d,p,m)=>{C[d]=m,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness[d]=m);for(let y of r)y[p]=m;this.render()},C={baseColorFactor:a,metallicFactor:f,roughnessFactor:c,setBaseColorFactor:d=>h("baseColorFactor","baseColor",[d[0],d[1],d[2],d[3]??1]),setMetallicFactor:d=>h("metallicFactor","metallic",d),setRoughnessFactor:d=>h("roughnessFactor","roughness",d)};return{name:e.name||`Material_${i}`,pbrMetallicRoughness:C}})}playAnimation(t){if(this.animations.length!==0){if(t){let e=this.animations.find(i=>i.name===t);e&&(this.currentClip=e)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(t=>t.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(t){let e=this.applyVariantMaterial(t);return e&&this.gl&&this.render(),e}applyVariantMaterial(t){let e=t===null||t==="",i=-1;if(e)this.activeVariantName=null;else{if(i=this.availableVariants.indexOf(t),i<0)return!1;this.activeVariantName=t}let r=this.gltf?.materials;if(!Array.isArray(r))return e;for(let s of this.meshes)for(let a of s.primitives){let f=a.defaultMaterialIndex;if(!e&&Array.isArray(a.variantMappings)){for(let h of a.variantMappings)if(Array.isArray(h.variants)&&h.variants.includes(i)){f=h.material;break}}let c=f!==void 0?r[f]:void 0;a.materialIndex=c?f:void 0,Object.assign(a,us(c,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,c??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,s=t.programCache.get(r);s||(s=ls(this.gl,{...t.primitiveDef,material:e},i),t.programCache.set(r,s)),t.customProgram=s.program,t.customUniforms=s.uniforms,t.pluginData&&(t.pluginData.materials=t.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(t){this.autoplay=t,t?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(t){this.animationName=t,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(t)}evaluateAnimation(t){for(let e of Nt)if(e.evaluateAnimation){e.evaluateAnimation(this,t);return}}setTarget(t,e,i){this.customTarget=[t,e,i],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(t){let e=Math.max(10,Math.min(90,t));this.fov=e*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(t){if(this.distanceMode=t,!this.customDistance){let e=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=e,this.targetDistance=e,this.currDistance=e,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(t){let e=Math.PI/180,i=Math.PI*.48;t.minTheta!==void 0&&(this.minTheta=t.minTheta*e),t.maxTheta!==void 0&&(this.maxTheta=t.maxTheta*e),t.minPhi!==void 0&&(this.minPhi=Math.max(-i,t.minPhi*e)),t.maxPhi!==void 0&&(this.maxPhi=Math.min(i,t.maxPhi*e)),t.minDistance!==void 0&&(this.minDistanceLimit=t.minDistance),t.maxDistance!==void 0&&(this.maxDistanceLimit=t.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){let t=180/Math.PI;return{minTheta:isFinite(this.minTheta)?this.minTheta*t:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*t:void 0,minPhi:this.minPhi*t,maxPhi:this.maxPhi*t,minDistance:this.minDistanceLimit??void 0,maxDistance:this.maxDistanceLimit??void 0}}clampTheta(t){return Math.max(this.minTheta,Math.min(this.maxTheta,t))}clampPhi(t){return Math.max(this.minPhi,Math.min(this.maxPhi,t))}clampDistance(t){let e=this.bounds?.radius;return Math.max(this.minDistanceLimit??(e?e*.5:.1),Math.min(this.maxDistanceLimit??(e?e*8:100),t))}setCamera(t,e,i,r){t!==void 0&&(this.targetTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.targetPhi=this.clampPhi(e*Math.PI/180)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(i)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/r))}setInitialCamera(t,e,i,r){t!==void 0&&(this.initialTheta=this.targetTheta=this.currTheta=this.clampTheta(t*Math.PI/180)),e!==void 0&&(this.initialPhi=this.targetPhi=this.currPhi=this.clampPhi(e*Math.PI/180));let s=i!==void 0&&i>0?i:r!==void 0&&r>0?this.bounds.radius*2.5/r:null;this.customDistance=s!==null,this.initialDistance=this.targetDistance=this.currDistance=this.clampDistance(s??(this.distanceMode==="absolute"?3:this.bounds.radius*2.5)),this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.targetDistance=this.clampDistance(this.initialDistance??this.bounds.radius*2.5),this.customTarget=this.initialCustomTarget?[...this.initialCustomTarget]:null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(t,e){let i=Ct();Et(i,this.projMatrix,this.viewMatrix);let r=(S,w,v=1)=>[S[0]*w[0]+S[4]*w[1]+S[8]*w[2]+S[12]*v,S[1]*w[0]+S[5]*w[1]+S[9]*w[2]+S[13]*v,S[2]*w[0]+S[6]*w[1]+S[10]*w[2]+S[14]*v,S[3]*w[0]+S[7]*w[1]+S[11]*w[2]+S[15]*v],s=this.modelRootMatrix,[a,f,c]=s?r(s,t):t,[h,C,d]=e?s?r(s,e,0):e:[0,0,0],[p,m,y,z]=r(i,[a,f,c]);if(z<=1e-4)return{x:0,y:0,z:1,visible:!1};let E=p/z,_=m/z,b=y/z,$=this.canvas.getBoundingClientRect(),T=$.width||this.canvas.clientWidth||this.canvas.width||300,M=$.height||this.canvas.clientHeight||this.canvas.height||150,N=(E*.5+.5)*T,k=(-_*.5+.5)*M,A=E>=-1.1&&E<=1.1&&_>=-1.1&&_<=1.1&&b>=-1&&b<=1;if(A&&e){let[S,w,v]=tr(this),P=[a-S,f-w,c-v];h*P[0]+C*P[1]+d*P[2]>.05&&(A=!1)}return{x:N,y:k,z:b,visible:A}}setSelectedMesh(t){this.setSelectedMeshes([t])}setSelectedMeshes(t){this.selectedMeshNames=new Set(t.filter(Boolean))}getSelectedMesh(){return[...this.selectedMeshNames][0]||""}setupEvents(){let t=this.canvas,e=Tr;this.boundContextMenu=i=>{i.preventDefault()},t.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=i=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=e(),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist=0,this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.isPanning=i.button===2||i.shiftKey||this.activePointers.size===2,t.setPointerCapture(i.pointerId))},t.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=i=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=e();let r=this.activePointers.get(i.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},s=i.clientX-r.x,a=i.clientY-r.y;if(this.activePointers.set(i.pointerId,{x:i.clientX,y:i.clientY}),this.lastPointerX=i.clientX,this.lastPointerY=i.clientY,this.totalDragDist+=Math.hypot(s,a),this.isPanning||i.button===2||i.shiftKey||this.activePointers.size===2){let f=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],c=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],h=this.customTarget?[...this.customTarget]:[...this.bounds.center],C=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;h[0]+=(-s*f[0]+a*c[0])*C,h[1]+=(-s*f[1]+a*c[1])*C,h[2]+=(-s*f[2]+a*c[2])*C,this.customTarget=h}else this.targetTheta=this.clampTheta(this.targetTheta-s*.008),this.targetPhi=this.clampPhi(this.targetPhi+a*.008)},t.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=i=>{this.lastInteractionTime=e(),this.activePointers.delete(i.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{t.releasePointerCapture(i.pointerId)}catch{}if(this.totalDragDist<5&&i.button===0){let r=t.getBoundingClientRect(),s=Math.floor((i.clientX-r.left)*(t.width/Math.max(r.width,1))),a=Math.floor((i.clientY-r.top)*(t.height/Math.max(r.height,1)));this.performMeshPick(s,a,!0)}},t.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=i=>{if(!this.interactive)return;i.preventDefault(),this.lastInteractionTime=e();let r=Math.exp(i.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},t.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=i=>{let r=i.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),t.tabIndex!==void 0&&t.tabIndex<0&&(t.tabIndex=0),t.getAttribute?.("role")||t.setAttribute?.("role","region"),t.getAttribute?.("aria-label")||t.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=i=>{if(this.interactive){switch(i.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=e(),i.preventDefault()}},t.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let t=(i,r,s)=>{this[s]&&(i.removeEventListener(r,this[s]),this[s]=null)},e=this.canvas;for(let[i,r]of[["webglcontextlost","boundContextLost"],["webglcontextrestored","boundContextRestored"],["contextmenu","boundContextMenu"],["pointerdown","boundPointerDown"],["pointermove","boundPointerMove"],["pointerup","boundPointerUp"],["wheel","boundWheel"],["keydown","boundKeyDown"]])t(e,i,r);t(this.container,"setCamera","boundSetCamera"),t(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(t,e){let i=this.canvas,r=i.getBoundingClientRect(),s=i.width||300,a=i.height||300,f=r.width>0?Math.floor((t-r.left)*(s/r.width)):Math.floor(t),c=r.height>0?Math.floor((e-r.top)*(a/r.height)):Math.floor(e);return this.performMeshPick(f,c,!1)}performMeshPick(t,e,i=!0){if(this.meshes.length===0)return null;let r=this.gl,s=Math.max(1,this.canvas.width||300),a=Math.max(1,this.canvas.height||300);t=this.mapStereoPickX(t,s);let f=Ct();Et(f,this.projMatrix,this.viewMatrix);let c=[],h=Math.max(0,Math.min(s-1,t)),C=Math.max(0,Math.min(a-1,a-1-e));if(this.pickFbo&&r&&!this.xrSessionActive){(this.pickFboWidth!==s||this.pickFboHeight!==a)&&this.resizePickingFbo(s,a),r.bindFramebuffer(36160,this.pickFbo),r.viewport(0,0,s,a),r.enable(2929),r.clearColor(0,0,0,0),r.clear(16640),r.useProgram(this.pickProg);for(let N=0;N<this.meshes.length;N++){let k=this.meshes[N];if(k.visible===!1||k.isPluginMesh)continue;let A=N+1,S=(A&255)/255,w=(A>>8&255)/255,v=(A>>16&255)/255;r.uniform4f(this.uPick.uColorId,S,w,v,1),Et(this.modelMatrix,this.modelRootMatrix,k.transform);let P=k.instanceMatrices;if(P&&P.length>=16){let H=P.length>>4,G=Ct();for(let x of k.primitives){r.bindVertexArray(x.vao);for(let V=0;V<H;V++)Et(G,this.modelMatrix,P.subarray(V*16,V*16+16)),Et(this.mvpMatrix,f,G),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Ar(r,x)}}else{Et(this.mvpMatrix,f,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let H of k.primitives)r.bindVertexArray(H.vao),Ar(r,H)}}let T=new Uint8Array(4);r.readPixels(h,C,1,1,6408,5121,T),r.bindFramebuffer(36160,null);let M=T[0]+(T[1]<<8)+(T[2]<<16);M>0&&M<=this.meshes.length&&(c=[this.meshes[M-1]])}c.length===0&&(c=this.meshes.filter(T=>T.visible!==!1));let d=null,p=1/0,m=[0,0,0],y=[0,1,0],[z,E,_]=tr(this),b=Ct();for(let T of c){Et(b,this.modelRootMatrix,T.transform);let M=T.instanceMatrices,N=M&&M.length>=16?M.length>>4:1;for(let k=0;k<N;k++){M&&M.length>=16?Et(this.modelMatrix,b,M.subarray(k*16,k*16+16)):this.modelMatrix.set(b),Et(this.mvpMatrix,f,this.modelMatrix);let A=Ct();if(!_o(A,this.mvpMatrix))continue;let S=(h+.5)/s*2-1,w=(C+.5)/a*2-1,v=[0,0,0],P=[0,0,0];Qn(v,S,w,-1,A),Qn(P,S,w,1,A);let H=P[0]-v[0],G=P[1]-v[1],x=P[2]-v[2],V=Math.hypot(H,G,x)||1,Y=H/V,Z=G/V,q=x/V,X={distance:1/0,point:[0,0,0],normal:[0,1,0]};for(let F of T.primitives){if(!F.positions)continue;let Q=F.positions,L=F.indices,ee=Math.floor(L?L.length/3:Q.length/9);for(let ae=0;ae<ee;ae++){let be=(L?L[ae*3]:ae*3)*3,Ne=(L?L[ae*3+1]:ae*3+1)*3,De=(L?L[ae*3+2]:ae*3+2)*3;So(v[0],v[1],v[2],Y,Z,q,Q[be],Q[be+1],Q[be+2],Q[Ne],Q[Ne+1],Q[Ne+2],Q[De],Q[De+1],Q[De+2],X,1e-4)}}if(isFinite(X.distance)){let F=X.point[0],Q=X.point[1],L=X.point[2],ee=this.modelMatrix,ae=ee[0]*F+ee[4]*Q+ee[8]*L+ee[12],be=ee[1]*F+ee[5]*Q+ee[9]*L+ee[13],Ne=ee[2]*F+ee[6]*Q+ee[10]*L+ee[14],De=ae-z,Be=be-E,je=Ne-_,Ve=Math.hypot(De,Be,je);if(Ve<p){zi(this.normalMatrix,this.modelMatrix);let Ie=this.normalMatrix,Me=X.normal[0],ze=X.normal[1],Se=X.normal[2],He=Ie[0]*Me+Ie[3]*ze+Ie[6]*Se,J=Ie[1]*Me+Ie[4]*ze+Ie[7]*Se,j=Ie[2]*Me+Ie[5]*ze+Ie[8]*Se,I=Math.hypot(He,J,j)||1;He/=I,J/=I,j/=I,He*De+J*Be+j*je>0&&(He=-He,J=-J,j=-j);let O=K=>Math.round(K*1e3)/1e3;d=T,p=O(Ve),m=[O(ae),O(be),O(Ne)],y=[O(He),O(J),O(j)]}}}}if(!d)return null;let $={meshIndex:this.meshes.indexOf(d),meshName:d.name,nodeIndex:d.nodeIndex,distance:p,hitPoint:m,normal:y,screenX:t,screenY:e};if(i){for(let T of Nt)T.onMeshSelect?.(this,$);this.opts.onMeshClick&&this.opts.onMeshClick($),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:$}))}return $}mapStereoPickX(t,e){if(!this.stereoSBS||this.xrSessionActive||e<2)return t;let i=Math.max(1,Math.floor(e*.5)),r=t>=i,s=r?t-i:t,a=r?Math.max(1,e-i):i,f=(s+.5)/a*2-1;return Math.floor((f*.5+1)*.5*e)}setStereoSBS(t){this.stereoSBS=!!t,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let t=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),e=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);Zn(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;en(this.viewMatrix,tr(this),i,[0,1,0]),Et(this.mvpMatrix,this.projMatrix,this.viewMatrix),zi(this.normalMatrix,this.modelMatrix)}resize(){let t=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),e=this.canvas.getBoundingClientRect(),i=Math.max(1,Math.floor(e.width*t)),r=Math.max(1,Math.floor(e.height*t));this.canvas.width!==i||this.canvas.height!==r?(this.canvas.width=i,this.canvas.height=r,this.resizePickingFbo(i,r),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(t){let e=this.xrSessionActive;if(this.xrSessionActive=t,e&&!t){this.xrDepthState.enabled=!1;for(let i of Nt)i.onXRSessionEnd?.(this);if(this.lastTime=Tr(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(i){this.reportRenderError(i)}}}reportRenderError(t){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",t))}stepXRUpdate(t){for(let e of Nt)e.onUpdate?.(this,t)}start(){if(this.animFrameId!==null)return;this.lastTime=Tr();let t=e=>{if(this.animFrameId===null)return;let i=Math.min(Math.max((e-this.lastTime)/1e3,0),.1);if(this.lastTime=e,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(i),this.render()}catch(r){this.reportRenderError(r)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(t))};this.animFrameId=requestAnimationFrame(t)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(t){this.autoRotate=t}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(t){this.autoRotateSpeed=t}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(t){this.autoRotateDelay=Math.max(0,Number(t)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(t=0){this.turntableRotation=Number(t)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let t=Math.cos(this.turntableRotation),e=Math.sin(this.turntableRotation),[i,,r]=this.bounds.center;this.modelRootMatrix.set([t,0,-e,0,0,1,0,0,e,0,t,0,i-(t*i+e*r),0,r-(-e*i+t*r),1])}setVisible(t){this.isVisible=t}update(t){for(let a of Nt)a.onUpdate?.(this,t);let e=Tr();if(!this.isPointerDown&&this.autoRotate&&e-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*t,this.updateTurntableMatrix();for(let a of Nt)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 i=Math.round((this.currTheta*180/Math.PI%360+360)%360),r=Math.round(this.currPhi*180/Math.PI),s=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(i-this.lastReportedTheta)>=1||Math.abs(r-this.lastReportedPhi)>=1||Math.abs(s-this.lastReportedZoom)>=.02){this.lastReportedTheta=i,this.lastReportedPhi=r,this.lastReportedZoom=s;let a={theta:i,phi:r,zoom:s,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,e,i,r,s=!0,a=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(t);let f=t?.transform?.inverse?.matrix||this.viewMatrix,c=t?.projectionMatrix||this.projMatrix,h=t?.transform?.position,C=h?[h.x,h.y,h.z]:[0,1.6,0];e&&this.modelRootMatrix.set(e),this.render({viewMatrix:f,projMatrix:c,eyePos:C,viewport:r,eye:t?.eye||"none",clear:a>0?!1:t?.eye!=="right",isAR:s})}render(t){if(this.contextLost)return;if(!t&&this.stereoSBS){let k=Math.max(2,this.canvas.width||2),A=Math.max(1,this.canvas.height||1),S=Math.max(1,Math.floor(k*.5)),w=Math.max(1,k-S),v=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),P=this.customTarget||this.bounds.center,[H,G,x]=tr(this),V=Math.cos(this.currTheta),Y=-Math.sin(this.currTheta),Z=.032;for(let q of[-1,1]){let X=Ct(),F=Ct(),Q=q<0?S:w,L=[H+q*V*Z,G,x+q*Y*Z];Zn(X,this.fov,Q/A,.1,v),en(F,L,[P[0]+q*V*Z*.25,P[1],P[2]+q*Y*Z*.25],[0,1,0]),this.render({viewMatrix:F,projMatrix:X,eyePos:L,viewport:[q<0?0:S,0,Q,A],eye:q<0?"left":"right",clear:q<0,isAR:!1})}this.gl.viewport(0,0,k,A);return}let e=this.gl,[i,r,s,a]=t?.viewport||[0,0,this.canvas.width,this.canvas.height];if(e.viewport(i,r,s,a),e.enable(2929),!t||t.clear!==!1){let k=t?.isAR?[0,0,0,0]:this.clearColor;e.clearColor(k[0],k[1],k[2],k[3]),e.clear(16640)}let f=Ct(),c=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=c;let h=t?.projMatrix??this.projMatrix;Et(f,h,c);let C=mt(),d=C.xrDepthShader,p=Co(this.toneMapping),[m,y,z]=t?t.eyePos:tr(this);for(let k of Nt)k.onBeforeDrawScene?.(this,e,f,[m,y,z],p);let E=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&E===0){C.gpuSceneAccelerator?.hideLayer?.(this);return}let _=t?.eye||"none",b=!t||t.clear!==!1;if(!this.xrSessionActive&&C.gpuSceneAccelerator?.renderScene(this,f,h,c,[m,y,z],p,[i,r,s,a],_,b,!!t?.isAR)){b&&!this.skyboxTexture&&(e.clearColor(0,0,0,0),e.clear(16384));for(let k of Nt)k.name.includes("webgpu")&&k.onAfterRender?.(e,this,f,_,[i,r,s,a],h);return}let $=!1,T=E>0?[...this.backdropMeshes,...this.meshes]:this.meshes,M=(k,A,S,w)=>{A?(e.activeTexture(33984+k),e.bindTexture(3553,A),e.uniform1i(S,k),e.uniform1i(w,1)):e.uniform1i(w,0)},N=k=>{for(let A=0;A<T.length;A++){let S=T[A];if(S.visible===!1)continue;let w=this.selectedMeshNames.has(S.name);if(A<E||S.worldSpace===!0||S.name==="__xr_reticle__")this.modelMatrix.set(S.transform);else{Et(this.modelMatrix,this.modelRootMatrix,S.transform);let V=!t&&(S.extras?.xr?.billboard??S.userData?.xr?.billboard);if(V){let Y=this.modelMatrix,Z=Math.hypot(Y[0],Y[1],Y[2])||1,q=Math.hypot(Y[4],Y[5],Y[6])||1,X=Math.hypot(Y[8],Y[9],Y[10])||1,F=V==="y"||V==="cylindrical"||V==="capsule",Q=m-Y[12],L=z-Y[14],ee=Math.hypot(Q,L),ae=ee>1e-5?Q/ee:0,be=ee>1e-5?L/ee:1;Y.set(F?[be*Z,0,-ae*Z,0,0,q,0,0,ae*X,0,be*X]:[c[0]*Z,c[4]*Z,c[8]*Z,0,c[1]*q,c[5]*q,c[9]*q,0,c[2]*X,c[6]*X,c[10]*X])}}Et(this.mvpMatrix,f,this.modelMatrix),zi(S.normalMatrix,this.modelMatrix);let v=S.extras?.xr?.stereo||S.userData?.xr?.stereo,P=0,H=0,G=1,x=1;v==="sbs"?(G=.5,P=_==="right"?.5:0):v==="ou"&&(x=.5,H=_==="right"?.5:0);for(let V of S.primitives){let Y=!!V.isTransmissive;if(!k&&Y){$=!0;continue}if(k&&!Y)continue;let Z=V.customProgram||this.renderProg,q=V.customUniforms||this.uRender;e.useProgram(Z),e.vertexAttrib3f(3,0,0,0),q.uInstanced&&e.uniform1i(q.uInstanced,0),e.uniform1i(q.uToneMapping,p),e.uniform1f(q.uEnvIntensity,this.envIntensity),q.uExposure&&e.uniform1f(q.uExposure,this.exposure),e.uniform3f(q.uCameraPos,m,y,z),e.uniform1f(q.uEmissive,w?1:0),e.uniformMatrix4fv(q.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(q.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(q.uNormalMatrix,!1,S.normalMatrix),q.uUvTransform&&e.uniform4f(q.uUvTransform,P,H,G,x),q.uViewportSize&&e.uniform2f(q.uViewportSize,Math.max(1,s),Math.max(1,a)),d?.bind(e,q,this.xrDepthState,c,[i,r,Math.max(1,s),Math.max(1,a)]),C.shadowMapShader?.bind(e,q,this,S),M(4,this.environmentTexture,q.uEnvironmentMap,q.uHasEnvironmentMap),this.bindLights(q),q.uSectionEnabled&&e.uniform1i(q.uSectionEnabled,0);for(let F of Nt)F.onBeforeDrawPrimitive?.(e,Z,V,S,this.worldMatrices||[],this.gltf);e.uniform4fv(q.uBaseColor,V.baseColor),e.uniform1f(q.uMetallic,V.metallic),e.uniform1f(q.uRoughness,V.roughness),q.uClearcoat&&e.uniform2f(q.uClearcoat,V.clearcoat??0,V.clearcoatRoughness??.04),M(0,V.texture,q.uBaseColorTexture,q.uHasTexture),M(1,V.metallicRoughnessTexture,q.uMetallicRoughnessTexture,q.uHasMetallicRoughnessTexture),M(2,V.normalTexture,q.uNormalTexture,q.uHasNormalTexture),V.normalTexture&&e.uniform1f(q.uNormalScale,V.normalScale),M(3,V.occlusionTexture,q.uOcclusionTexture,q.uHasOcclusionTexture),V.occlusionTexture&&e.uniform1f(q.uOcclusionStrength,V.occlusionStrength),e.uniform3fv(q.uEmissiveFactor,V.emissiveFactor),M(8,V.emissiveTexture,q.uEmissiveTexture,q.uHasEmissiveTexture),e.bindVertexArray(V.vao);let X=S.instanceMatrices;if(V.instanceCount!==void 0)e.drawElementsInstanced(4,V.indexCount,V.indexType,0,V.instanceCount);else if(X&&X.length>=16&&V.instanced&&q.uInstanced&&q.uViewProj){let F=X.length>>4;e.uniform1i(q.uInstanced,1),e.uniformMatrix4fv(q.uViewProj,!1,f),V.indices?e.drawElementsInstanced(4,V.indexCount,V.indexType,0,F):e.drawArraysInstanced(4,0,V.indexCount,F),e.uniform1i(q.uInstanced,0)}else if(X&&X.length>=16){let F=X.length>>4,Q=S.instanceColors,L=Ct(),ee=new Float32Array(9);for(let ae=0;ae<F;ae++){if(Et(L,this.modelMatrix,X.subarray(ae*16,ae*16+16)),Et(this.mvpMatrix,f,L),zi(ee,L),e.uniformMatrix4fv(q.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(q.uModel,!1,L),e.uniformMatrix3fv(q.uNormalMatrix,!1,ee),Q){let be=V.baseColor,Ne=ae*3;e.uniform4fv(q.uBaseColor,[be[0]*Q[Ne],be[1]*Q[Ne+1],be[2]*Q[Ne+2],be[3]])}Ar(e,V)}}else Ar(e,V)}}};if(N(!1),$){for(let k of Nt)k.onBeforeTransmissivePass?.(e,this);N(!0)}for(let k of Nt)k.onAfterRender?.(e,this,f,_,[i,r,s,a],h)}disposeMeshListGpuResources(t,e){cs(this.gl,t,e)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let t=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let e of Nt)e.onDestroy?.(t,this);this.environmentTexture&&(t.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&t.deleteProgram(this.renderProg),this.pickProg&&t.deleteProgram(this.pickProg),this.pickFbo&&t.deleteFramebuffer(this.pickFbo),this.pickTexture&&t.deleteTexture(this.pickTexture),this.pickDepth&&t.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};ps.registerPlugin=vo,ps.getRegisteredPlugins=Mo;function Oo(t){return t+3&-4}var Je=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function hn(t,e){let i=e,r=1;for(;t.has(i);)i=`${e}_${r++}`;return t.add(i),i}function ms(t,e,i){let r=Math.hypot(t,e,i)||1,s=t/r,a=e/r,f=-(i/r);if(f<-.999999)return[0,1,0,0];let c=Math.sqrt((1+f)*2);return[a/c,-s/c,0,c*.5]}function ds(t,e=0){let[i,r,s,,a,f,c,,h,C,d,,p,m,y]=Array.from({length:15},(X,F)=>Je(t[e+F],F%5===0?1:0)),z=Math.hypot(i,r,s),E=Math.hypot(a,f,c),_=Math.hypot(h,C,d);i*(f*d-C*c)-a*(r*d-C*s)+h*(r*c-f*s)<0&&(z=-z);let b=Math.abs(z)>1e-8?1/z:0,$=Math.abs(E)>1e-8?1/E:0,T=Math.abs(_)>1e-8?1/_:0,M=i*b,N=r*b,k=s*b,A=a*$,S=f*$,w=c*$,v=h*T,P=C*T,H=d*T,G=M+S+H,x=0,V=0,Y=0,Z=1;if(G>0){let X=.5/Math.sqrt(G+1);Z=.25/X,x=(w-P)*X,V=(v-k)*X,Y=(N-A)*X}else if(M>S&&M>H){let X=2*Math.sqrt(Math.max(0,1+M-S-H));X>1e-8&&(Z=(w-P)/X,x=.25*X,V=(A+N)/X,Y=(v+k)/X)}else if(S>H){let X=2*Math.sqrt(Math.max(0,1+S-M-H));X>1e-8&&(Z=(v-k)/X,x=(A+N)/X,V=.25*X,Y=(w+P)/X)}else{let X=2*Math.sqrt(Math.max(0,1+H-M-S));X>1e-8&&(Z=(N-A)/X,x=(v+k)/X,V=(w+P)/X,Y=.25*X)}let q=Math.hypot(x,V,Y,Z);return q>1e-8&&Number.isFinite(q)?(x/=q,V/=q,Y/=q,Z/=q):(x=0,V=0,Y=0,Z=1),{t:[p,m,y],r:[x,V,Y,Z],s:[z,E,_]}}function Bo(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}var di=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function gs(t){let e=t?.audioEmitter??t?.spatialAudio??(typeof t?.audio=="object"&&t.audio&&("preset"in t.audio||"distanceModel"in t.audio||"coneInnerAngle"in t.audio||"maxDistance"in t.audio||"volume"in t.audio)?t.audio:typeof t?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(t.audio)?{preset:t.audio}:void 0);if(!e||typeof e=="object"&&e.enabled===!1)return null;let i=typeof e=="string"?{preset:e}:e,r=typeof i.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(i.src)?i.src:void 0,s=typeof i.preset=="string"?i.preset:void 0;return!r&&!s?null:{ae:i,src:r,preset:s,volume:di(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function ys(t){let e=t?.material,i=e?._presetMaps?.map;if(!i||i!==e.map)return null;let r=/^ai_([0-9a-f]{16})_albedo$/.exec(String(i.name??""));return r?r[1]:null}function jo(t,e){let i=ys(e),r=t?.material;return!i||!r||typeof r!="object"||Array.isArray(r)?t:{...t,material:{...r,textureKey:i}}}function ir(t,e){return bs(t,e)[0]}function bs(t,e){t.updateMatrixWorld(!0);let i=[],r=0,s=[],a=[],f=[],c=[],h=new Set,C=[],d=[],p=new Map,m=[],y=[],z=[],E=new Map,_=[],b=[],$=[],T=!1;function M(F){let Q=p.get(F);if(Q!==void 0)return Q;Q=d.length,p.set(F,Q);let L=F,ee=L.color?.r??1,ae=L.color?.g??1,be=L.color?.b??1,Ne=L.opacity??1,De={baseColorFactor:[ee,ae,be,Ne],metallicFactor:L.metalness??0,roughnessFactor:L.roughness??.5},Be={},je=oe=>{if(!oe)return;let _e=(typeof oe=="string"?oe:typeof oe.source=="string"?oe.source:typeof oe.image=="string"?oe.image:"").trim();if(!_e||/[\x00-\x1f\x7f\\]|\.\./.test(_e)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(_e)||!_e.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(_e)))return;let fe=E.get(_e);if(fe===void 0){let ye=m.length;m.push({uri:_e}),y.length===0&&y.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),fe=z.length,z.push({sampler:0,source:ye}),E.set(_e,fe)}return{index:fe}},Ve=L._packPbr?.(),Ie=je(L.map);Ie&&(De.baseColorTexture=Ie);let Me=je(Ve?.mrUri||L.roughnessMap||L.metalnessMap);Me&&(De.metallicRoughnessTexture=Me);let ze=L.map?.avgColor;Array.isArray(ze)&&ze.length>=3&&(Be.avgColor=[ze[0],ze[1],ze[2]]);let Se=je(Ve?.normUri||L.normalMap),He=L.normalScale,J=Ve?.normUri?Ve.normScale??1:typeof He=="number"?Math.max(0,Je(He,1)):He?Math.max(0,(Je(He.x,1)+Je(He.y,1))*.5):1;Se&&J!==1&&(Se.scale=J);let j=je(L.emissiveMap),I=je(L.aoMap),O=Math.max(0,Math.min(1,Je(L.aoMapIntensity,1)));I&&O!==1&&(I.strength=O);let K={name:L.name||"",pbrMetallicRoughness:De,doubleSided:L.side===2||!!L.doubleSided,...Ne<1||L.transparent?{alphaMode:"BLEND"}:{},...Se?{normalTexture:Se}:{},...j?{emissiveTexture:j}:{},...I?{occlusionTexture:I}:{},...Object.keys(Be).length>0?{extras:Be}:{}},ie=Math.max(0,Je(L.emissiveIntensity,1)),he=L.emissive&&(L.emissive.r>0||L.emissive.g>0||L.emissive.b>0);(he||j&&!L._em&&ie>0)&&(K.emissiveFactor=he?[L.emissive.r*ie,L.emissive.g*ie,L.emissive.b*ie]:[ie,ie,ie]);let ue={};L.clearcoat&&L.clearcoat>0&&(ue.KHR_materials_clearcoat={clearcoatFactor:L.clearcoat,clearcoatRoughnessFactor:L.clearcoatRoughness||0}),L.sheen&&L.sheen>0&&(ue.KHR_materials_sheen={sheenColorFactor:L.sheenColor?[L.sheenColor.r,L.sheenColor.g,L.sheenColor.b]:[1,1,1],sheenRoughnessFactor:L.sheenRoughness||0}),L.transmission&&L.transmission>0&&(ue.KHR_materials_transmission={transmissionFactor:L.transmission}),L.thickness&&L.thickness>0&&(ue.KHR_materials_volume={thicknessFactor:L.thickness,attenuationDistance:L.attenuationDistance??1/0,attenuationColor:L.attenuationColor?[L.attenuationColor.r,L.attenuationColor.g,L.attenuationColor.b]:[1,1,1]}),L.ior!==void 0&&L.ior!==1.5&&(ue.KHR_materials_ior={ior:L.ior}),L.dispersion&&L.dispersion>0&&(ue.KHR_materials_dispersion={dispersion:L.dispersion}),L.iridescence&&L.iridescence>0&&(ue.KHR_materials_iridescence={iridescenceFactor:L.iridescence,iridescenceIor:L.iridescenceIOR??1.3});let ge=L._serializeTslGraph?.();return ge&&(ue.GOOGLE_material_tsl=ge,h.add("GOOGLE_material_tsl")),Object.keys(ue).length>0&&(K.extensions=ue),d.push(K),Q}function N(F,Q){let L=new Uint8Array(F.buffer,F.byteOffset,F.byteLength),ee=Oo(L.byteLength),ae=new Uint8Array(ee);ae.set(L),i.push(ae);let be=s.length;return s.push({buffer:0,byteOffset:r,byteLength:L.byteLength,target:Q}),r+=ee,be}function k(F,Q,L,ee,ae,be,Ne){let De=N(F,L),Be=a.length,je={bufferView:De,byteOffset:0,componentType:ee,count:ae,type:Q};return be&&(je.min=be),Ne&&(je.max=Ne),a.push(je),Be}let A=[],S=[],w=new Set([t]),v=[];if(Array.isArray(t.children))for(let F=t.children.length-1;F>=0;F--)v.push({obj:t.children[F],parentKids:S});for(;v.length>0;){let{obj:F,parentKids:Q}=v.pop();if(!F||typeof F!="object"||w.has(F))continue;w.add(F),F._bakeAuthorGeometry?.(),mt().materializeDeclarativeGeometry?.(F);let L=!!(F.userData&&(F.userData.xr&&typeof F.userData.xr=="object"&&Object.keys(F.userData.xr).length>0||F.userData.interactivity&&typeof F.userData.interactivity=="object"&&Object.keys(F.userData.interactivity).length>0)),ee={name:F.name||(L?`Node_${c.length}`:"")},ae=Je(F.position?.x,0),be=Je(F.position?.y,0),Ne=Je(F.position?.z,0),De=Je(F.quaternion?.x,0),Be=Je(F.quaternion?.y,0),je=Je(F.quaternion?.z,0),Ve=Je(F.quaternion?.w,1),Ie=Je(F.scale?.x,1),Me=Je(F.scale?.y,1),ze=Je(F.scale?.z,1);if((ae||be||Ne)&&(ee.translation=[ae,be,Ne]),(De||Be||je||Ve!==1)&&(ee.rotation=[De,Be,je,Ve]),(Ie!==1||Me!==1||ze!==1)&&(ee.scale=[Ie,Me,ze]),F.visible===!1&&(ee.extensions={...ee.extensions||{},KHR_node_visibility:{visible:!1}},h.add("KHR_node_visibility")),F.userData&&Object.keys(F.userData).length>0&&(ee.extras=JSON.parse(JSON.stringify(F.userData,(I,O)=>{if(!(I==="__proto__"||I==="prototype"||I==="constructor"))return typeof O=="function"?void 0:O})),F.userData.xr)){let I=Bo(F.userData.xr);ee.extensions={...ee.extensions||{},MOZ_hubs_components:I,ANDROID_xr_scenecore:I},mt().xrTraitSerializer?.gltfNode(ee,F.userData.xr);let O=ys(F),K=ee.extras?.xr?.material;O&&K&&typeof K=="object"&&!Array.isArray(K)&&(K.textureKey=O),h.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}let Se=F,He=Se.isLight||Se.color&&Se.intensity!==void 0;if(!He&&(Se._castShdSet||Se._recvShdSet||F.castShadow||F.receiveShadow)&&(ee.extras={...ee.extras||{},shadow:{cast:!!F.castShadow,receive:Se._recvShdSet?!!F.receiveShadow:!!(F.receiveShadow||F.castShadow)}}),He){let I=Se.matrixWorld?.elements,O=Je(I?I[12]:F.position?.x,0),K=Je(I?I[13]:F.position?.y,0),ie=Je(I?I[14]:F.position?.z,0),he=Se.target,ue=he?.parent?he?.matrixWorld?.elements:void 0,ge=Je(ue?ue[12]:he?.position?.x,0),oe=Je(ue?ue[13]:he?.position?.y,0),_e=Je(ue?ue[14]:he?.position?.z,0),fe=ge-O,ye=oe-K,Ae=_e-ie,Pe=Math.hypot(fe,ye,Ae),Le=Math.max(.01,Math.min(Math.PI/2,Je(Se.angle,Math.PI/3))),ke=Math.max(0,Math.min(1,Je(Se.penumbra,0))),$e=Math.max(0,Le*(1-ke)),Fe=Math.max(0,Je(Se.distance,0)),qe=F.type==="directional"||F.type==="spot"||F.type==="point",Oe;if(F.castShadow&&qe){let Ke=Se.shadow,Dt=Math.max(256,Math.min(2048,Math.round(Je(Ke?.mapSize?.x??Ke?.mapSize?.width,1024))));Oe={cast:!0,mapSize:Dt<=384?256:Dt<=768?512:Dt<=1536?1024:2048,bias:di(Ke?.bias,-.05,.05,-5e-4),normalBias:di(Ke?.normalBias,0,.2,.015),radius:di(Ke?.radius,0,8,1.5)},T=!0}let lt=O-ge,rt=K-oe,nt=ie-_e,ht=Math.hypot(lt,rt,nt);b.push({type:F.type,color:[F.color.r,F.color.g,F.color.b],intensity:F.intensity,position:F.type==="directional"?[lt,rt,nt]:[O,K,ie],...F.type==="directional"?{direction:ht>1e-6?[lt/ht,rt/ht,nt/ht]:[0,1,0]}:F.type==="spot"?{direction:Pe>1e-6?[fe/Pe,ye/Pe,Ae/Pe]:[0,-1,0],outerConeAngle:Le,innerConeAngle:$e,range:Fe}:F.type==="point"?{range:Fe}:F.type==="hemisphere"&&Se.groundColor?{groundColor:[Se.groundColor.r,Se.groundColor.g,Se.groundColor.b]}:{},...Oe?{shadow:Oe}:{}}),qe&&A.push({node:ee,obj:F,px:O,py:K,pz:ie,tx:ge,ty:oe,tz:_e,dx:fe,dy:ye,dz:Ae,dLen:Pe,outerAngle:Le,innerAngle:$e,range:Fe,shadowSpec:Oe})}if(F.geometry){let I=F.geometry,O=I.attributes.position;if(O&&O.count>0){let K=[1/0,1/0,1/0],ie=[-1/0,-1/0,-1/0];for(let fe=0;fe<O.count;fe++){let ye=O.getX(fe),Ae=O.getY(fe),Pe=O.getZ(fe);ye<K[0]&&(K[0]=ye),ye>ie[0]&&(ie[0]=ye),Ae<K[1]&&(K[1]=Ae),Ae>ie[1]&&(ie[1]=Ae),Pe<K[2]&&(K[2]=Pe),Pe>ie[2]&&(ie[2]=Pe)}let he={attributes:{POSITION:k(O.array,"VEC3",34962,5126,O.count,K,ie)}};if(I.attributes.normal&&(he.attributes.NORMAL=k(I.attributes.normal.array,"VEC3",34962,5126,I.attributes.normal.count)),I.attributes.uv&&(he.attributes.TEXCOORD_0=k(I.attributes.uv.array,"VEC2",34962,5126,I.attributes.uv.count)),I.index){let fe=I.index.array instanceof Uint32Array;he.indices=k(I.index.array,"SCALAR",34963,fe?5125:5123,I.index.count)}let ue=Array.isArray(F.material)?F.material[0]:F.material;ue&&(he.material=M(ue));let ge=F.userData?.variants;if(ge&&typeof ge=="object"){let fe=new Map;for(let ye of Object.keys(ge)){if(!ye||ye==="__proto__"||ye==="constructor"||ye==="prototype")continue;let Ae=ge[ye];if(!Ae||typeof Ae!="object")continue;let Pe=_.indexOf(ye);if(Pe===-1&&_.length<256&&(Pe=_.length,_.push(ye)),Pe===-1)continue;let Le=M(Ae),ke=fe.get(Le);ke||(ke=[],fe.set(Le,ke)),ke.push(Pe)}if(fe.size>0){let ye=[];for(let[Ae,Pe]of fe.entries())ye.push({material:Ae,variants:Pe});he.extensions={...he.extensions||{},KHR_materials_variants:{mappings:ye}},h.add("KHR_materials_variants")}}let oe=F;if(oe.isInstancedMesh&&typeof oe.count=="number"&&oe.count>0&&oe.instanceMatrix?.array){let fe=Math.min(1e4,Math.floor(oe.count)),ye=oe.instanceMatrix.array,Ae=new Float32Array(fe*3),Pe=new Float32Array(fe*4),Le=new Float32Array(fe*3);for(let $e=0;$e<fe;$e++){let{t:Fe,r:qe,s:Oe}=ds(ye,$e*16);Ae[$e*3]=Fe[0],Ae[$e*3+1]=Fe[1],Ae[$e*3+2]=Fe[2],Pe[$e*4]=qe[0],Pe[$e*4+1]=qe[1],Pe[$e*4+2]=qe[2],Pe[$e*4+3]=qe[3],Le[$e*3]=Oe[0],Le[$e*3+1]=Oe[1],Le[$e*3+2]=Oe[2]}let ke={TRANSLATION:k(Ae,"VEC3",0,5126,fe),ROTATION:k(Pe,"VEC4",0,5126,fe),SCALE:k(Le,"VEC3",0,5126,fe)};if(oe.instanceColor?.array&&oe.instanceColor.array.length>=fe*3){let $e=new Float32Array(oe.instanceColor.array.subarray(0,fe*3));ke._COLOR_0=k($e,"VEC3",0,5126,fe)}ee.extensions={...ee.extensions||{},EXT_mesh_gpu_instancing:{attributes:ke}},h.add("EXT_mesh_gpu_instancing")}let _e=f.length;f.push({primitives:[he],name:F.name,...ee.extras?{extras:ee.extras}:{}}),ee.mesh=_e}}let J=c.length;c.push(ee),C.push(F),Q.push(J);let j=F.children;if(Array.isArray(j)&&j.length>0){let I=[];ee.children=I;for(let O=j.length-1;O>=0;O--)v.push({obj:j[O],parentKids:I})}}if(T)for(let F of A){let Q=$.length;if($.push({name:F.obj.name||`Light_${Q}`,type:F.obj.type,color:[F.obj.color.r,F.obj.color.g,F.obj.color.b],intensity:F.obj.intensity,...F.range>0&&(F.obj.type==="point"||F.obj.type==="spot")?{range:F.range}:{},...F.obj.type==="spot"?{spot:{innerConeAngle:F.innerAngle,outerConeAngle:F.outerAngle}}:{},...F.shadowSpec?{extras:{shadow:F.shadowSpec}}:{}}),F.node.extensions={...F.node.extensions||{},KHR_lights_punctual:{light:Q}},h.add("KHR_lights_punctual"),F.obj.type==="directional"||F.obj.type==="spot"){let L=F.dLen>1e-6?F.dx/F.dLen:0,ee=F.dLen>1e-6?F.dy/F.dLen:-1,ae=F.dLen>1e-6?F.dz/F.dLen:0;F.node.rotation=ms(L,ee,ae),F.obj.type==="directional"&&(F.tx||F.ty||F.tz)&&(F.node.translation=[F.px-F.tx,F.py-F.ty,F.pz-F.tz])}}for(let F=0;F<c.length;F++){let Q=c[F];Q.children&&Q.children.length===0?delete Q.children:Q.children&&Q.children.length>0&&(Q.extras?.xr?.lod||Q.extensions?.ANDROID_xr_scenecore?.lod||C[F]?.isLOD)&&(Q.extensions={...Q.extensions||{},MSFT_lod:{ids:[...Q.children]}},h.add("MSFT_lod"))}let P=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),H=[];if(typeof P=="function"&&C.length>0){let F=e?.duration??4,Q=e?.fps??15,L=Math.max(2,Math.round(F*Q)+1),ee=new Float32Array(L),ae=C.map(Me=>[Je(Me.position?.x,0),Je(Me.position?.y,0),Je(Me.position?.z,0),Je(Me.quaternion?.x,0),Je(Me.quaternion?.y,0),Je(Me.quaternion?.z,0),Je(Me.quaternion?.w,1),Je(Me.scale?.x,1),Je(Me.scale?.y,1),Je(Me.scale?.z,1)]),be=C.map(()=>new Float32Array(L*3)),Ne=C.map(()=>new Float32Array(L*4)),De=C.map(()=>new Float32Array(L*3));for(let Me=0;Me<L;Me++){let ze=Me/(L-1)*F;ee[Me]=ze;try{P(ze)}catch{}for(let Se=0;Se<C.length;Se++){let He=C[Se];be[Se][Me*3]=Je(He.position?.x,0),be[Se][Me*3+1]=Je(He.position?.y,0),be[Se][Me*3+2]=Je(He.position?.z,0);let J=Je(He.quaternion?.x,0),j=Je(He.quaternion?.y,0),I=Je(He.quaternion?.z,0),O=Je(He.quaternion?.w,1),K=Math.hypot(J,j,I,O)||1;if(J/=K,j/=K,I/=K,O/=K,Me>0){let ie=(Me-1)*4,he=Ne[Se];he[ie]*J+he[ie+1]*j+he[ie+2]*I+he[ie+3]*O<0&&(J=-J,j=-j,I=-I,O=-O)}Ne[Se][Me*4]=J,Ne[Se][Me*4+1]=j,Ne[Se][Me*4+2]=I,Ne[Se][Me*4+3]=O,De[Se][Me*3]=Je(He.scale?.x,1),De[Se][Me*3+1]=Je(He.scale?.y,1),De[Se][Me*3+2]=Je(He.scale?.z,1)}}for(let Me=0;Me<C.length;Me++){let ze=C[Me],Se=ae[Me];ze.position?.set(Se[0],Se[1],Se[2]),ze.quaternion?.set(Se[3],Se[4],Se[5],Se[6]),ze.scale?.set(Se[7],Se[8],Se[9])}t.updateMatrixWorld(!0);let Be=null,je=()=>(Be===null&&(Be=k(ee,"SCALAR",0,5126,L,[0],[F])),Be),Ve=[],Ie=[];for(let Me=0;Me<C.length;Me++){let ze=ae[Me],Se=(J,j,I)=>J.some((O,K)=>Math.abs(O-ze[I+K%j])>1e-4),He=(J,j,I,O)=>{J&&Ie.push({sampler:Ve.push({input:je(),interpolation:"LINEAR",output:k(j,I,0,5126,L)})-1,target:{node:Me,path:O}})};He(Se(be[Me],3,0),be[Me],"VEC3","translation"),He(Se(Ne[Me],4,3),Ne[Me],"VEC4","rotation"),He(Se(De[Me],3,7),De[Me],"VEC3","scale")}Ie.length>0&&H.push({name:"ProceduralLoop",samplers:Ve,channels:Ie})}let G=Jn(c,f,t.userData),x=[],V=[],Y=[];for(let F=0;F<c.length;F++){let Q=c[F],L=gs(Q.extras?.xr);if(!L)continue;let{ae:ee,src:ae,preset:be,volume:Ne,loop:De,isGlobal:Be}=L,je=Q.name||`Node_${F}`,Ve=V.length;V.push({name:`${je}_source`,gain:Ne,loop:De,autoPlay:typeof ee.autoplay=="boolean"?ee.autoplay:!0,...ae!==void 0?{audio:x.push({uri:ae})-1}:{},...be?{extras:{preset:be,pitch:di(ee.pitch,.25,4,1)}}:{}});let Ie=Y.length,Me=di(ee.refDistance,.05,100,1),ze=di(ee.coneInnerAngle,0,360,360),Se=di(ee.coneOuterAngle,ze,360,360);Y.push({name:`${je}_emitter`,type:Be?"global":"positional",gain:Ne,sources:[Ve],...Be?{}:{positional:{distanceModel:ee.distanceModel==="linear"||ee.distanceModel==="exponential"?ee.distanceModel:"inverse",refDistance:Me,maxDistance:di(ee.maxDistance,Me,500,Math.max(Me,25)),rolloffFactor:di(ee.rolloffFactor,0,10,1),coneInnerAngle:+(ze*Math.PI/180).toFixed(6),coneOuterAngle:+(Se*Math.PI/180).toFixed(6),coneOuterGain:di(ee.coneOuterGain,0,1,0)}}}),Q.extensions={...Q.extensions||{},KHR_audio_emitter:{emitter:Ie}},h.add("KHR_audio_emitter")}let Z={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity,...b.length>0?{lights:b}:{}}},scenes:[{nodes:S}],scene:0,nodes:c,meshes:f,materials:d,...m.length>0?{images:m}:{},...y.length>0?{samplers:y}:{},...z.length>0?{textures:z}:{},accessors:a,bufferViews:s,buffers:[{byteLength:r}],...H.length>0?{animations:H}:{},...G||h.size>0?{extensionsUsed:[...G?["KHR_interactivity"]:[],...h]}:{},...G||_.length>0||Y.length>0||$.length>0?{extensions:{...G?{KHR_interactivity:G}:{},..._.length>0?{KHR_materials_variants:{variants:_.map(F=>({name:F}))}}:{},...Y.length>0?{KHR_audio_emitter:{...x.length>0?{audio:x}:{},sources:V,emitters:Y}}:{},...$.length>0?{KHR_lights_punctual:{lights:$}}:{}}}:{}},q=new Uint8Array(r),X=0;for(let F of i)q.set(F,X),X+=F.byteLength;return[{gltf:Z,bin:q.buffer,lights:b,environmentIntensity:t.environmentIntensity},C]}function un(t){return new TextEncoder().encode(t)}function Nr(t,e){let{gltf:i,bin:r}=ir(t,e),s=JSON.stringify(i),a=un(s),f=(4-a.byteLength%4)%4,c=a.byteLength+f,h=20+c+8+r.byteLength,C=new Uint8Array(h),d=new DataView(C.buffer);d.setUint32(0,1179937895,!0),d.setUint32(4,2,!0),d.setUint32(8,h,!0),d.setUint32(12,c,!0),d.setUint32(16,1313821514,!0),C.set(a,20);for(let m=0;m<f;m++)C[20+a.byteLength+m]=32;let p=20+c;return d.setUint32(p,r.byteLength,!0),d.setUint32(p+4,5130562,!0),C.set(new Uint8Array(r),p+8),C}function Vo(t,e){let[i,r]=bs(t,e);return xs(i,r)}function xs(t,e){let i=[],r=t.gltf,s=mt().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,t);let a=t.bin,f=a instanceof ArrayBuffer?a:a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),c=r.accessors||[],h=r.bufferViews||[],C=r.materials||[],d=r.meshes||[],p=r.nodes||[],m=r.textures||[],y=r.images||[],z=r.samplers||[],E=new Set,_=C.map((S,w)=>hn(E,rr(S?.name,`Material_${w}`))),b=new Map;function $(S){{let V=globalThis.__three_live_native_decode_b64_image__;if(typeof V=="function")return V(S)??null}let w=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(S);if(!w)return null;let v=w[2].replace(/\s+/g,""),P=v.endsWith("==")?2:v.endsWith("=")?1:0,H=new Uint8Array((v.length*3>>2)-P),G=V=>{let Y=v.charCodeAt(V);return Y>96?Y-71:Y>64?Y-65:Y>47?Y+4:Y===43?62:Y===47?63:0},x=0;for(let V=0;V<v.length;V+=4){let Y=G(V)<<18|G(V+1)<<12|G(V+2)<<6|G(V+3);H[x++]=Y>>16&255,x<H.length&&(H[x++]=Y>>8&255),x<H.length&&(H[x++]=Y&255)}return H}function T(S,w,v){let P=S?.index;if(typeof P!="number")return;let H=m[P],G=H?.source;if(typeof G!="number"||!y[G])return;let x=b.get(G);if(x===void 0){x=null;let Z=y[G],q=null;if(typeof Z.bufferView=="number"){let X=h[Z.bufferView],F=X?.byteOffset||0,Q=X?.byteLength||0;X&&Q>0&&F>=0&&F+Q<=f.byteLength&&(q=new Uint8Array(f,F,Q))}else typeof Z.uri=="string"&&(q=$(Z.uri));if(q&&q.byteLength>0){let X=q[0]===255&&q[1]===216&&q[2]===255||!(q[0]===137&&q[1]===80)&&/jpe?g/i.test(Z.mimeType||Z.uri||"");x={file:`texture_${G}.${X?"jpg":"png"}`,data:q}}b.set(G,x)}if(!x)return;let V=typeof H.sampler=="number"?z[H.sampler]:void 0,Y=Z=>Z===33071?"clamp":Z===33648?"mirror":"repeat";return{file:x.file,data:x.data,wrapS:Y(V?.wrapS),wrapT:Y(V?.wrapT),...w?{scale:w}:{},...v?{bias:v}:{}}}function M(S){let w=c[S];if(!w)throw new Error(`Accessor ${S} not found`);let v=h[w.bufferView||0],P=(v.byteOffset||0)+(w.byteOffset||0),H=v.byteLength||0;return{acc:w,buffer:f.slice(P,P+H)}}function N(S,w,v,P){let H=[],G=d[S];if(!G)return H;let x=G.primitives||[];for(let V=0;V<x.length;V++){let Y=x[V],Z=Y.attributes?.POSITION;if(Z===void 0)continue;let{acc:q,buffer:X}=M(Z),F=new Float32Array(X,0,q.count*3),Q,L=Y.attributes?.NORMAL;if(L!==void 0){let{acc:j,buffer:I}=M(L),O=new Float32Array(I,0,j.count*3);Q=new Float32Array(O.length);for(let K=0;K<j.count;K++){let ie=O[K*3],he=O[K*3+1],ue=O[K*3+2],ge=Math.hypot(ie,he,ue)||1;Q[K*3]=ie/ge,Q[K*3+1]=he/ge,Q[K*3+2]=ue/ge}}let ee,ae=Y.attributes?.TEXCOORD_0;if(ae!==void 0){let{acc:j,buffer:I}=M(ae);ee=new Float32Array(I,0,j.count*2)}let be;if(Y.indices!==void 0){let{acc:j,buffer:I}=M(Y.indices);be=j.componentType===5125?new Uint32Array(I,0,j.count):new Uint16Array(I,0,j.count);let O=q.count;for(let K of be)if(K>=O)throw new Error(`SecurityError: Index buffer value (${K}) out of vertex bounds [0, ${O}).`)}else{let j=q.count;be=j>65535?new Uint32Array(j):new Uint16Array(j);for(let I=0;I<j;I++)be[I]=I}let Ne="DefaultMaterial",De=[1,1,1],Be=.5,je=0,Ve=0,Ie=0,Me=1.5,ze=1,Se=[0,0,0],He,J={};if(Y.material!==void 0&&C[Y.material]){let j=C[Y.material];Ne=_[Y.material]||`Material_${Y.material}`;let I=j.pbrMetallicRoughness||{},O=($e,Fe)=>Array.isArray($e)&&$e.length>=3?[$e[0],$e[1],$e[2]]:Fe;De=O(I.baseColorFactor,[1,1,1]);let K=Array.isArray(I.baseColorFactor)&&typeof I.baseColorFactor[3]=="number"?I.baseColorFactor[3]:1,ie=De[0]!==1||De[1]!==1||De[2]!==1||K!==1,he=T(I.baseColorTexture,ie?[De[0],De[1],De[2],K]:void 0),ue=j.extras?.avgColor;!he&&Array.isArray(ue)&&ue.length>=3&&(De=[De[0]*ue[0],De[1]*ue[1],De[2]*ue[2]]),typeof I.roughnessFactor=="number"&&(Be=I.roughnessFactor),typeof I.metallicFactor=="number"&&(je=I.metallicFactor);let ge=typeof I.roughnessFactor=="number"?I.roughnessFactor:1,oe=typeof I.metallicFactor=="number"?I.metallicFactor:1,_e=T(I.metallicRoughnessTexture,ge!==1||oe!==1?[1,ge,oe,1]:void 0);Se=O(j.emissiveFactor,[0,0,0]);let fe=(Se[0]>0||Se[1]>0||Se[2]>0)&&(Se[0]!==1||Se[1]!==1||Se[2]!==1)?[Se[0],Se[1],Se[2],1]:void 0,ye=T(j.emissiveTexture,fe),Ae=typeof j.normalTexture?.scale=="number"?j.normalTexture.scale:1,Pe=T(j.normalTexture,[2*Ae,2*Ae,2,1],[-Ae,-Ae,-1,0]),Le=typeof j.occlusionTexture?.strength=="number"?j.occlusionTexture.strength:1,ke=Le!==1?T(j.occlusionTexture,[Le,Le,Le,1],[1-Le,1-Le,1-Le,0]):T(j.occlusionTexture);(he||_e||Pe||ye||ke)&&(He=[he,_e,Pe,ye,ke]),J=j.extensions||{},J.KHR_materials_clearcoat&&(Ve=J.KHR_materials_clearcoat.clearcoatFactor??0,Ie=J.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof J.KHR_materials_ior?.ior=="number"&&(Me=J.KHR_materials_ior.ior),ze=K*(1-(J.KHR_materials_transmission?.transmissionFactor??0))}H.push({name:x.length>1?`${w}_p${V}`:w,positions:F,indices:be,normals:Q,uvs:ee,materialName:Ne,color:De,roughness:Be,metallic:je,clearcoat:Ve,clearcoatRoughness:Ie,ior:Me,opacity:ze,emissiveColor:Se,...He?{textures:He}:{},...J.GOOGLE_material_tsl?{tslGraph:J.GOOGLE_material_tsl}:{},xrTraits:v||G.extras?.xr,...P?{invisible:!0}:{}})}return H}if(p.length>0){let S=new Float32Array(0),w=new Uint16Array(0),v=(F,Q)=>{if(F===void 0)return null;let{acc:L,buffer:ee}=M(F);return new Float32Array(ee,0,L.count*Q)},P=(F,Q)=>Array.isArray(F)&&F.length>=3?[Je(F[0],Q),Je(F[1],Q),Je(F[2],Q)]:[Q,Q,Q],H=(F,Q,L)=>F&&F.length>=(Q+1)*3?[F[Q*3],F[Q*3+1],F[Q*3+2]]:L,G=(F,Q,L)=>F&&F.length>=(Q+1)*4?[F[Q*4],F[Q*4+1],F[Q*4+2],F[Q*4+3]]:L,x=new Map,V=r.animations?.[0];if(V&&Array.isArray(V.channels)&&Array.isArray(V.samplers))for(let F of V.channels){let Q=V.samplers[F?.sampler],L=F?.target?.node,ee=F?.target?.path;if(!Q||typeof L!="number"||Q.input===void 0)continue;let ae=x.get(L);ae||(ae={input:Q.input},x.set(L,ae)),ee==="translation"?ae.t=Q.output:ee==="rotation"?ae.r=Q.output:ee==="scale"&&(ae.s=Q.output)}let Y=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(Y)||Y.length===0){let F=new Set;for(let Q of p)if(Array.isArray(Q?.children))for(let L of Q.children)F.add(L);Y=[];for(let Q=0;Q<p.length;Q++)F.has(Q)||Y.push(Q);Y.length===0&&(Y=[0])}let Z=new Set,q=[],X=(F,Q)=>{if(Array.isArray(F))for(let L=F.length-1;L>=0;L--)q.push({idx:F[L],out:Q})};for(X(Y,i);q.length>0;){let{idx:F,out:Q}=q.pop();if(typeof F!="number"||F<0||F>=p.length||Z.has(F))continue;Z.add(F);let L=p[F];if(!L)continue;let ee=[0,0,0],ae=[0,0,0,1],be=[1,1,1];if(Array.isArray(L.matrix)&&L.matrix.length===16){let ze=ds(L.matrix);ee=ze.t,ae=ze.r,be=ze.s}else ee=P(L.translation,0),Array.isArray(L.rotation)&&L.rotation.length>=4&&(ae=[Je(L.rotation[0],0),Je(L.rotation[1],0),Je(L.rotation[2],0),Je(L.rotation[3],1)]),be=P(L.scale,1);let Ne,De=x.get(F);if(De){let ze=v(De.input,1);if(ze&&ze.length>0){let Se=v(De.t,3),He=v(De.r,4),J=v(De.s,3),j=Array.from(ze),I=[],O=[],K=[];for(let ie=0;ie<ze.length;ie++)I.push(H(Se,ie,ee)),O.push(G(He,ie,ae)),K.push(H(J,ie,be));Ne={times:j,translations:I,rotations:O,scales:K}}}let Be=Array.isArray(L.children)?L.children:[],je=typeof L.mesh=="number"&&L.mesh>=0&&L.mesh<d.length,Ve=e?.[F]?.userData?.xr??L.extras?.xr;if(!je&&Be.length===0&&(L.camera!==void 0||L.extensions?.KHR_lights_punctual||!L.name&&!L.extras&&!Ve&&!Ne))continue;let Ie=(ze,Se,He)=>({name:ze,positions:S,indices:w,isXform:!0,xrTraits:Ve,timeSamples:Ne,translation:ee,rotation:ae,scale:be,children:Se,...He?{invisible:!0}:{}}),Me=L.visible===!1||L.extensions?.KHR_node_visibility?.visible===!1||e?.[F]?.visible===!1;if(je){let ze=L.name||d[L.mesh]?.name||`Mesh_${F}`,Se=N(L.mesh,ze,Ve,Me),He=e?.[F],J=!!(He?._castShdSet||He?._recvShdSet),j=typeof L.extras?.shadow?.cast=="boolean"?L.extras.shadow.cast:J?!!He?.castShadow:void 0;if(j!==void 0)for(let O of Se)O.castShadow=j;let I=L.extensions?.EXT_mesh_gpu_instancing?.attributes;if(I&&typeof I=="object"&&Se.length>0){let O=v(I.TRANSLATION,3),K=v(I.ROTATION,4),ie=v(I.SCALE,3),he=v(I._COLOR_0,3),ue=Math.min(1e3,O?O.length/3:K?K.length/4:ie?ie.length/3:0);if(ue>0){let ge=[];for(let oe=0;oe<ue;oe++){let _e=H(O,oe,[0,0,0]),fe=G(K,oe,[0,0,0,1]),ye=H(ie,oe,[1,1,1]);for(let Ae of Se){let Pe=Ae.color||[.8,.8,.8],Le=he&&he.length>=(oe+1)*3;ge.push({...Ae,name:`${Ae.name}_${oe}`,materialName:Le?`${Ae.materialName}_inst_${oe}`:Ae.materialName,color:Le?[Pe[0]*he[oe*3],Pe[1]*he[oe*3+1],Pe[2]*he[oe*3+2]]:Ae.color,translation:_e,rotation:fe,scale:ye})}}X(Be,ge),Q.push(Ie(ze,ge,Me));continue}}if(Se.length===1)Se[0].translation=ee,Se[0].rotation=ae,Se[0].scale=be,Se[0].timeSamples=Ne,Be.length>0&&(Se[0].children=[],X(Be,Se[0].children)),Q.push(Se[0]);else{let O=[...Se];X(Be,O),Q.push(Ie(ze,O,Me))}}else{let ze=[];X(Be,ze),Q.push(Ie(L.name||`Group_${F}`,ze,Me))}}}else for(let S=0;S<d.length;S++){let w=d[S].name||`Mesh_${S}`;i.push(...N(S,w,d[S].extras?.xr))}let k=(Array.isArray(t.lights)&&t.lights.length>0?t.lights:void 0)??os(r)??(Array.isArray(r?.asset?.extras?.lights)?r.asset.extras.lights:[]),A=[];for(let S=0;S<k.length;S++){let w=k[S];w?.shadow?.cast&&(w.type==="directional"||w.type==="spot"||w.type==="point")&&A.push({name:`Light_${S}`,type:w.type,color:w.color,intensity:w.intensity,position:w.position,direction:w.direction,range:w.range,innerConeAngle:w.innerConeAngle,outerConeAngle:w.outerConeAngle,shadow:w.shadow})}return A.length>0&&(i.__usdaShadowLights=A),i}function rr(t,e){if(!t||typeof t!="string")return e;let i=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(i)&&(i="_"+i),i||e}function Cr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Tt(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}var gi=(t,e,i)=>`(${Tt(t)}, ${Tt(e)}, ${Tt(i)})`,nr=(t,e,i,r)=>`(${Tt(t)}, ${Tt(e)}, ${Tt(i)}, ${Tt(r)})`;function vs(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,i=new Array(e);for(let r=0;r<e;r++)i[r]=gi(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ho(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let i=new Array(e);for(let r=0;r<e;r++)i[r]=`(${Tt(t[r*2])}, ${Tt(1-t[r*2+1])})`;return i.join(", ")}function Go(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function Wo(t,e){let i=(e??t.__usdaShadowLights??[]).filter(_=>_?.shadow?.cast),r=new Map,s=0,a=null,f=[...t];for(;f.length>0;){let _=f.pop();if(!_.isXform&&_.positions&&_.positions.length>0){let b=rr(_.materialName,"DefaultMaterial");r.has(b)||r.set(b,{color:_.color||[1,1,1],roughness:_.roughness??.5,metallic:_.metallic??0,clearcoat:_.clearcoat??0,clearcoatRoughness:_.clearcoatRoughness??0,ior:_.ior??1.5,opacity:_.opacity??1,emissiveColor:_.emissiveColor||[0,0,0],textures:_.textures,tslGraph:_.tslGraph})}if(_.timeSamples&&_.timeSamples.times.length>0){let b=_.timeSamples.times[_.timeSamples.times.length-1];b>s&&(s=b)}else _.tslGraph&&s<=0&&JSON.stringify(_.tslGraph).includes('"time"')&&(s=60);if(_.xrTraits?.anchor&&!a&&(a=_.xrTraits.anchor==="vertical"||_.xrTraits.anchor==="wall"?"vertical":"horizontal"),_.children)for(let b=_.children.length-1;b>=0;b--)f.push(_.children[b])}let c="";s>0&&(c=`startTimeCode = 0
|
|
216
|
+
endTimeCode = ${Tt(s)}
|
|
252
217
|
timeCodesPerSecond = 1.0
|
|
253
|
-
`);let
|
|
254
|
-
uniform token preliminary:planeAnchoring:alignment = "${
|
|
255
|
-
`);let
|
|
218
|
+
`);let h="";a&&(h=`uniform token preliminary:anchoring:type = "plane"
|
|
219
|
+
uniform token preliminary:planeAnchoring:alignment = "${a}"
|
|
220
|
+
`);let C=`#usda 1.0
|
|
256
221
|
(
|
|
257
222
|
defaultPrim = "Root"
|
|
258
223
|
metersPerUnit = 1.0
|
|
259
224
|
upAxis = "Y"
|
|
260
|
-
${
|
|
225
|
+
${c})
|
|
261
226
|
|
|
262
227
|
def Xform "Root" (
|
|
263
228
|
kind = "component"
|
|
264
229
|
)
|
|
265
230
|
{
|
|
266
|
-
${
|
|
231
|
+
${h}def Scope "Materials"
|
|
267
232
|
{
|
|
268
|
-
`;for(let[
|
|
269
|
-
float inputs:roughness${
|
|
270
|
-
float inputs:roughness = ${
|
|
271
|
-
`,
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
274
|
-
`),
|
|
275
|
-
`:(
|
|
276
|
-
`)
|
|
277
|
-
`),
|
|
278
|
-
`);let
|
|
233
|
+
`;for(let[_,b]of r.entries()){let[$,T,M]=b.color,[N,k,A]=b.emissiveColor,S=`/Root/Materials/${_}`,[w,v,P,H,G]=b.textures||[],x=(Q,L)=>`.connect = <${S}/${Q}.outputs:${L}>`,V=w?`color3f inputs:diffuseColor${x("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${gi($,T,M)}`,Y=v?`float inputs:metallic${x("MetallicRoughnessTexture","b")}
|
|
234
|
+
float inputs:roughness${x("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${Tt(b.metallic)}
|
|
235
|
+
float inputs:roughness = ${Tt(b.roughness)}`,Z="";b.clearcoat>0&&(Z+=`float inputs:clearcoat = ${Tt(b.clearcoat)}
|
|
236
|
+
`,Z+=`float inputs:clearcoatRoughness = ${Tt(b.clearcoatRoughness)}
|
|
237
|
+
`),b.ior!==1.5&&(Z+=`float inputs:ior = ${Tt(b.ior)}
|
|
238
|
+
`),b.opacity<1&&(Z+=`float inputs:opacity = ${Tt(b.opacity)}
|
|
239
|
+
`),H?Z+=`color3f inputs:emissiveColor${x("EmissiveTexture","rgb")}
|
|
240
|
+
`:(N>0||k>0||A>0)&&(Z+=`color3f inputs:emissiveColor = ${gi(N,k,A)}
|
|
241
|
+
`),P&&(Z+=`normal3f inputs:normal${x("NormalTexture","rgb")}
|
|
242
|
+
`),G&&(Z+=`float inputs:occlusion${x("OcclusionTexture","r")}
|
|
243
|
+
`);let q="";if(w||v||P||H||G){q+=`def Shader "PrimvarReader"
|
|
279
244
|
{
|
|
280
245
|
uniform token info:id = "UsdPrimvarReader_float2"
|
|
281
246
|
string inputs:varname = "st"
|
|
282
247
|
float2 outputs:result
|
|
283
248
|
}
|
|
284
|
-
`;let
|
|
285
|
-
`:"",
|
|
286
|
-
`:"";
|
|
249
|
+
`;let Q=(L,ee,ae,be)=>{if(!ee)return;let Ne=ee.scale?`float4 inputs:scale = ${nr(ee.scale[0],ee.scale[1],ee.scale[2],ee.scale[3])}
|
|
250
|
+
`:"",De=ee.bias?`float4 inputs:bias = ${nr(ee.bias[0],ee.bias[1],ee.bias[2],ee.bias[3])}
|
|
251
|
+
`:"";q+=`def Shader "${L}"
|
|
287
252
|
{
|
|
288
253
|
uniform token info:id = "UsdUVTexture"
|
|
289
|
-
asset inputs:file = @${
|
|
290
|
-
float2 inputs:st${
|
|
291
|
-
token inputs:sourceColorSpace = "${
|
|
292
|
-
token inputs:wrapS = "${
|
|
293
|
-
token inputs:wrapT = "${
|
|
294
|
-
${
|
|
295
|
-
`};
|
|
296
|
-
`),
|
|
254
|
+
asset inputs:file = @${Cr(ee.file)}@
|
|
255
|
+
float2 inputs:st${x("PrimvarReader","result")}
|
|
256
|
+
token inputs:sourceColorSpace = "${ae}"
|
|
257
|
+
token inputs:wrapS = "${ee.wrapS||"repeat"}"
|
|
258
|
+
token inputs:wrapT = "${ee.wrapT||"repeat"}"
|
|
259
|
+
${Ne}${De}${be}}
|
|
260
|
+
`};Q("DiffuseTexture",w,"sRGB",`float3 outputs:rgb
|
|
261
|
+
`),Q("MetallicRoughnessTexture",v,"raw",`float outputs:g
|
|
297
262
|
float outputs:b
|
|
298
|
-
`),
|
|
299
|
-
`),
|
|
300
|
-
`),
|
|
301
|
-
`)}
|
|
263
|
+
`),Q("NormalTexture",P,"raw",`float3 outputs:rgb
|
|
264
|
+
`),Q("EmissiveTexture",H,"sRGB",`float3 outputs:rgb
|
|
265
|
+
`),Q("OcclusionTexture",G,"raw",`float outputs:r
|
|
266
|
+
`)}let X=`${V}
|
|
267
|
+
${Y}
|
|
268
|
+
${Z}`,F=b.tslGraph&&mt().tslUsdzSerializer?.(b.tslGraph,_,X);F&&(X=F.surfaceInputsUsda||X,q+=F.nodeGraphUsda),C+=`def Material "${_}"
|
|
302
269
|
{
|
|
303
270
|
def Shader "PBRShader"
|
|
304
271
|
{
|
|
305
272
|
uniform token info:id = "UsdPreviewSurface"
|
|
306
|
-
${
|
|
307
|
-
${c}
|
|
308
|
-
${k}token outputs:surface
|
|
273
|
+
${X}token outputs:surface
|
|
309
274
|
}
|
|
310
|
-
token outputs:surface${
|
|
311
|
-
${
|
|
312
|
-
`}
|
|
275
|
+
token outputs:surface${x("PBRShader","surface")}
|
|
276
|
+
${q}}
|
|
277
|
+
`}C+=`}
|
|
313
278
|
def Scope "Meshes"
|
|
314
279
|
{
|
|
315
|
-
`;let
|
|
280
|
+
`;let d=(_,b,$)=>{let T=[];b&&T.push('"MaterialBindingAPI"');let M=!!(_?.rigidBody&&_.rigidBody!=="none"&&(typeof _.rigidBody!="object"||_.rigidBody.enabled!==!1)),N=!!(_?.physics&&_.physics!=="none"||M);N&&T.push(...M?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let k=[];T.length>0&&k.push(`prepend apiSchemas = [${T.join(", ")}]`);let A=mt().xrTraitSerializer;if(_){let H=A?.usdLines(_,Cr)??[];if(!H.length)for(let G of["grab","billboard","follow","anchor","physics"]){let x=G==="follow"&&typeof _.follow=="object"?_.follow.mode??"head":_[G];x!==void 0&&H.push(`string ${G} = "${Cr(x)}"`)}H.length>0&&k.push(`customData = {
|
|
316
281
|
dictionary xr = {
|
|
317
|
-
${
|
|
282
|
+
${H.join(`
|
|
318
283
|
`)}
|
|
319
284
|
}
|
|
320
|
-
}`)}let
|
|
321
|
-
${
|
|
285
|
+
}`)}let S=k.length>0?` (
|
|
286
|
+
${k.join(`
|
|
322
287
|
`)}
|
|
323
|
-
)`:"",
|
|
324
|
-
`:"";if(
|
|
325
|
-
bool physics:kinematicEnabled = ${
|
|
288
|
+
)`:"",w=$?`uniform token visibility = "invisible"
|
|
289
|
+
`:"";if(N){let H=_?.rigidBody??_?.physics,G=H?.body??H?.mode??H;w+=`bool physics:rigidBodyEnabled = true
|
|
290
|
+
bool physics:kinematicEnabled = ${G==="static"||G==="kinematic"}
|
|
326
291
|
bool physics:collisionEnabled = true
|
|
327
|
-
|
|
328
|
-
`)}let
|
|
292
|
+
`,H?.mass>0&&Number.isFinite(H.mass)&&(w+=`float physics:mass = ${Tt(H.mass)}
|
|
293
|
+
`)}let v=gs(_),P=(v?`def SpatialAudio "AudioEmitter"
|
|
329
294
|
{
|
|
330
|
-
${
|
|
331
|
-
`:""}uniform token inputs:auralMode = "${
|
|
332
|
-
uniform token inputs:playbackMode = "${
|
|
333
|
-
double gain = ${
|
|
295
|
+
${v.src?`asset inputs:file = @${Cr(v.src)}@
|
|
296
|
+
`:""}uniform token inputs:auralMode = "${v.isGlobal?"nonSpatial":"spatial"}"
|
|
297
|
+
uniform token inputs:playbackMode = "${v.loop?"loopFromStart":"onceFromStart"}"
|
|
298
|
+
double gain = ${Tt(v.volume)}
|
|
334
299
|
}
|
|
335
|
-
`:"";return{header:
|
|
336
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
337
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
300
|
+
`:"")+(_?A?.usdPrims?.(_)??"":"");return{header:S,body:w,tail:P}},p=_=>{if(_.timeSamples&&_.timeSamples.times.length>0){let k=_.timeSamples,A=(P,H,G)=>k.times.map((x,V)=>`${Tt(x)}: ${G(P?.[V]||H)}`).join(", "),S=A(k.translations,[0,0,0],P=>gi(P[0],P[1],P[2])),w=A(k.rotations,[0,0,0,1],P=>{let H=Math.hypot(P[0],P[1],P[2],P[3])||1;return nr(P[3]/H,P[0]/H,P[1]/H,P[2]/H)}),v=A(k.scales,[1,1,1],P=>gi(P[0],P[1],P[2]));return`double3 xformOp:translate.timeSamples = { ${S} }
|
|
301
|
+
quatf xformOp:orient.timeSamples = { ${w} }
|
|
302
|
+
double3 xformOp:scale.timeSamples = { ${v} }
|
|
338
303
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
339
|
-
`}let
|
|
340
|
-
`,
|
|
341
|
-
`,
|
|
342
|
-
`,
|
|
343
|
-
`)
|
|
344
|
-
int[] faceVertexCounts = [${
|
|
345
|
-
int[] faceVertexIndices = [${
|
|
346
|
-
point3f[] points = [${
|
|
347
|
-
`;return
|
|
304
|
+
`}let b=[],$="",T=_.translation;T&&(Math.abs(T[0])>1e-7||Math.abs(T[1])>1e-7||Math.abs(T[2])>1e-7)&&($+=`double3 xformOp:translate = ${gi(T[0],T[1],T[2])}
|
|
305
|
+
`,b.push('"xformOp:translate"'));let M=_.rotation;if(M){let k=Math.hypot(M[0],M[1],M[2],M[3])||1,A=M[0]/k,S=M[1]/k,w=M[2]/k,v=M[3]/k;(1-Math.abs(v)>1e-7||Math.hypot(A,S,w)>1e-7)&&($+=`quatf xformOp:orient = ${nr(v,A,S,w)}
|
|
306
|
+
`,b.push('"xformOp:orient"'))}let N=_.scale;return N&&(Math.abs(N[0]-1)>1e-7||Math.abs(N[1]-1)>1e-7||Math.abs(N[2]-1)>1e-7)&&($+=`float3 xformOp:scale = ${gi(N[0],N[1],N[2])}
|
|
307
|
+
`,b.push('"xformOp:scale"')),b.length>0&&($+=`uniform token[] xformOpOrder = [${b.join(", ")}]
|
|
308
|
+
`),$},m=_=>{let b=_.positions.length/3,$=1/0,T=1/0,M=1/0,N=-1/0,k=-1/0,A=-1/0;for(let H=0;H<b;H++){let G=_.positions[H*3],x=_.positions[H*3+1],V=_.positions[H*3+2];G<$&&($=G),G>N&&(N=G),x<T&&(T=x),x>k&&(k=x),V<M&&(M=V),V>A&&(A=V)}isFinite($)||($=T=M=-1,N=k=A=1);let S=Math.floor(_.indices.length/3),w=rr(_.materialName,"DefaultMaterial"),v=S>0?S===1?"3":"3, ".repeat(S-1)+"3":"",P=`float3[] extent = [${gi($,T,M)}, ${gi(N,k,A)}]
|
|
309
|
+
int[] faceVertexCounts = [${v}]
|
|
310
|
+
int[] faceVertexIndices = [${Go(_.indices)}]
|
|
311
|
+
point3f[] points = [${vs(_.positions)}]
|
|
312
|
+
`;return _.normals&&_.normals.length===_.positions.length&&(P+=`normal3f[] normals = [${vs(_.normals)}] (
|
|
348
313
|
interpolation = "vertex"
|
|
349
314
|
)
|
|
350
|
-
`),
|
|
315
|
+
`),_.uvs&&_.uvs.length===b*2&&(P+=`texCoord2f[] primvars:st = [${Ho(_.uvs,b)}] (
|
|
351
316
|
interpolation = "vertex"
|
|
352
317
|
)
|
|
353
|
-
`)
|
|
354
|
-
|
|
355
|
-
|
|
318
|
+
`),P+=`rel material:binding = </Root/Materials/${w}>
|
|
319
|
+
`,_.castShadow===!1&&i.length>0&&(P+=`bool primvars:doNotCastShadows = 1
|
|
320
|
+
`),P},y=new Set,z=[];for(let _=t.length-1;_>=0;_--)z.push({node:t[_],siblings:y});let E=0;for(;z.length>0;){let _=z.pop();if(_.close){C+=`}
|
|
321
|
+
`;continue}let{node:b,siblings:$}=_,T=!!(b.isXform||b.positions.length===0),M=hn($,rr(b.name,T?`Group_${E}`:`Mesh_${E}`));E++;let N=b.children||[];if(T){let k=d(b.xrTraits,!1,b.invisible);C+=`def Xform "${M}"${k.header}
|
|
356
322
|
{
|
|
357
|
-
${
|
|
323
|
+
${k.body}${p(b)}${k.tail}`,z.push({close:!0});let A=new Set;for(let S=N.length-1;S>=0;S--)z.push({node:N[S],siblings:A})}else if(N.length>0){let k=d(b.xrTraits,!1,b.invisible),A=`${M}_mesh`;C+=`def Xform "${M}"${k.header}
|
|
358
324
|
{
|
|
359
|
-
${
|
|
325
|
+
${k.body}${p(b)}${k.tail}`,C+=`def Mesh "${A}" (
|
|
360
326
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
361
327
|
)
|
|
362
328
|
{
|
|
363
|
-
${
|
|
364
|
-
`,
|
|
329
|
+
${m(b)}}
|
|
330
|
+
`,z.push({close:!0});let S=new Set([A]);for(let w=N.length-1;w>=0;w--)z.push({node:N[w],siblings:S})}else{let k=d(b.xrTraits,!0,b.invisible);C+=`def Mesh "${M}"${k.header}
|
|
331
|
+
{
|
|
332
|
+
${k.body}${p(b)}${m(b)}${k.tail}}
|
|
333
|
+
`}}if(C+=`}
|
|
334
|
+
`,i.length>0){C+=`def Scope "Lights"
|
|
335
|
+
{
|
|
336
|
+
`;let _=new Set;for(let b=0;b<i.length;b++){let $=i[b],T=hn(_,rr($.name,`Light_${b}`)),M=$.type==="directional"?"DistantLight":$.type==="spot"?"DiskLight":"SphereLight",N=$.type==="spot"?'["ShapingAPI", "ShadowAPI"]':'["ShadowAPI"]',[k,A,S]=$.color||[1,1,1],[w,v,P]=$.position||[0,5,5],H=-w,G=-v,x=-P;$.direction&&$.direction.length>=3&&($.type==="directional"?(H=-$.direction[0],G=-$.direction[1],x=-$.direction[2]):(H=$.direction[0],G=$.direction[1],x=$.direction[2]));let[V,Y,Z,q]=ms(H,G,x),X="",F=[];$.type!=="directional"&&(Math.abs(w)>1e-7||Math.abs(v)>1e-7||Math.abs(P)>1e-7)&&(X+=`double3 xformOp:translate = ${gi(w,v,P)}
|
|
337
|
+
`,F.push('"xformOp:translate"')),$.type!=="point"&&(1-Math.abs(q)>1e-7||Math.hypot(V,Y,Z)>1e-7)&&(X+=`quatf xformOp:orient = ${nr(q,V,Y,Z)}
|
|
338
|
+
`,F.push('"xformOp:orient"')),F.length>0&&(X+=`uniform token[] xformOpOrder = [${F.join(", ")}]
|
|
339
|
+
`);let Q="";if($.type==="spot"){let L=($.outerConeAngle??Math.PI/3)*180/Math.PI,ee=($.innerConeAngle??L*.8)*180/Math.PI,ae=L>1e-4?Math.max(0,Math.min(1,1-ee/L)):0;Q=`float inputs:shaping:cone:angle = ${Tt(L)}
|
|
340
|
+
float inputs:shaping:cone:softness = ${Tt(ae)}
|
|
341
|
+
`}C+=`def ${M} "${T}" (
|
|
342
|
+
prepend apiSchemas = ${N}
|
|
343
|
+
)
|
|
344
|
+
{
|
|
345
|
+
color3f inputs:color = ${gi(k,A,S)}
|
|
346
|
+
float inputs:intensity = ${Tt($.intensity??1)}
|
|
347
|
+
bool inputs:shadow:enable = 1
|
|
348
|
+
${Q}${X}}
|
|
349
|
+
`}C+=`}
|
|
350
|
+
`}return C+=`}
|
|
351
|
+
`,C}var Pr=null;function cn(t){{let i=globalThis.__three_live_native_crc32__;if(typeof i=="function")return i(t)}if(!Pr){Pr=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;Pr[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=Pr[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function qo(t){{let d=globalThis.__three_live_native_build_usdz_zip__;if(typeof d=="function")return d(t)}let e=[],i=0,r=[];for(let d of t){let p=un(d.filename),m=cn(d.data),y=d.data.length,z=30+p.length,E=(i+z)%64,_=E!==0?64-E:0;_>0&&_<4&&(_+=64);let b=new Uint8Array(z+_),$=new DataView(b.buffer);$.setUint32(0,67324752,!0),$.setUint16(4,20,!0),$.setUint32(14,m,!0),$.setUint32(18,y,!0),$.setUint32(22,y,!0),$.setUint16(26,p.length,!0),$.setUint16(28,_,!0),b.set(p,30),_>=4&&($.setUint16(z,6534,!0),$.setUint16(z+2,_-4,!0)),e.push({offset:i,size:y,crc:m,filenameBytes:p,entry:d}),r.push(b,d.data),i+=b.length+d.data.length}let s=i;for(let d of e){let p=new Uint8Array(46+d.filenameBytes.length),m=new DataView(p.buffer);m.setUint32(0,33639248,!0),m.setUint16(4,20,!0),m.setUint16(6,20,!0),m.setUint32(16,d.crc,!0),m.setUint32(20,d.size,!0),m.setUint32(24,d.size,!0),m.setUint16(28,d.filenameBytes.length,!0),m.setUint32(42,d.offset,!0),p.set(d.filenameBytes,46),r.push(p),i+=p.length}let a=i-s,f=new Uint8Array(22),c=new DataView(f.buffer);c.setUint32(0,101010256,!0),c.setUint16(8,e.length,!0),c.setUint16(10,e.length,!0),c.setUint32(12,a,!0),c.setUint32(16,s,!0),r.push(f),i+=22;let h=new Uint8Array(i),C=0;for(let d of r)h.set(d,C),C+=d.length;return h}function Ms(t){let e=[{filename:"model.usda",data:un(Wo(t))}],i=new Set(["model.usda"]),r=[...t];for(;r.length>0;){let s=r.pop();for(let a of s.textures||[])a?.file&&a.data?.byteLength&&!i.has(a.file)&&(i.add(a.file),e.push({filename:a.file,data:a.data}));if(s.children)for(let a=s.children.length-1;a>=0;a--)r.push(s.children[a])}return qo(e)}function Lr(t){return Ms(Vo(t))}function fn(t){return Ms(xs(nn(t)))}function ws(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():fn(t)}function Xo(t,e){if(!t||!t.MeshPhysicalMaterial)return null;if(e?.authorNamespace?.TSL&&e?.authorNamespace?.MeshStandardNodeMaterial)return{TSL:e.authorNamespace.TSL,MeshStandardNodeMaterial:e.authorNamespace.MeshStandardNodeMaterial,MeshPhysicalNodeMaterial:e.authorNamespace.MeshPhysicalNodeMaterial};let i=128,r=16,s=0,a=(A,S,w)=>{typeof t.warnUnsupported=="function"&&t.warnUnsupported(`${S} [${A}]`,w)},f=A=>A==="vec4"?4:A==="vec3"?3:A==="vec2"?2:1,c=A=>A===4?"vec4":A===3?"vec3":A===2?"vec2":"float",h=(A,S=0)=>{let w=Number(A);return Number.isFinite(w)?Math.fround(w):S},C=A=>!!(A&&A.isTSLNode===!0),d=(A,S=1)=>{if(C(A))return A;if(typeof A=="number"||typeof A=="boolean"){let w=h(Number(A),0);return S>1?new y("const",c(S),[],new Array(S).fill(w)):new y("const","float",[],[w])}if(typeof A=="string"){let w=new t.Color(A);return new y("const","vec3",[],[h(w.r,1),h(w.g,1),h(w.b,1)])}if(Array.isArray(A)||A instanceof Float32Array){let w=Math.max(1,Math.min(4,A.length)),v=[];for(let P=0;P<w;P++)v.push(h(A[P],0));return new y("const",c(w),[],v)}if(A&&typeof A=="object"){let w=A;if("isColor"in w||"r"in w&&"g"in w&&"b"in w)return new y("const","vec3",[],[h(w.r,1),h(w.g,1),h(w.b,1)]);if("x"in w&&"y"in w)return"z"in w&&"w"in w?new y("const","vec4",[],[h(w.x),h(w.y),h(w.z),h(w.w,1)]):"z"in w?new y("const","vec3",[],[h(w.x),h(w.y),h(w.z)]):new y("const","vec2",[],[h(w.x),h(w.y)])}return new y("const","float",[],[0])},p=(A,S)=>{let w=d(A),v=d(S);if(w._type===v._type)return[w,v,w._type];if(w._type==="float")return[w,v,v._type];if(v._type==="float")return[w,v,w._type];let P=f(w._type),H=f(v._type);if(H>P)v=v.swizzle("xyzw".slice(0,P));else{let G=[v];for(let x=H;x<P;x++)G.push(new y("const","float",[],[0]));v=new y("construct",w._type,G)}return[w,v,w._type]},m=(A,S)=>{let w=d(A);if(w._type===S)return w;let v=f(S),P=f(w._type);if(v===1)return w.swizzle("x");if(P===1)return w._op==="const"&&w._val?new y("const",S,[],new Array(v).fill(w._val[0])):new y("construct",S,[w]);if(P>v)return w.swizzle("xyzw".slice(0,v));let H=[w];for(let G=P;G<v;G++)H.push(new y("const","float",[],[G===3?1:0]));return new y("construct",S,H)};class y{constructor(S,w,v,P,H,G){this.isTSLNode=!0,this._op=S,this._type=w,this._args=v,P!==void 0&&(this._val=P),H!==void 0&&(this._name=H),G!==void 0&&(this._mask=G)}get nodeType(){return this._type}get value(){return this._uVal}set value(S){this._op==="uniform"&&(this._uVal=S)}swizzle(S){let w=String(S||"x").trim().replace(/[rgba]/g,P=>"xyzw"["rgba".indexOf(P)]);if(!/^[xyzw]{1,4}$/.test(w))return a("TL501",`Invalid TSL swizzle '${S}'`,".x"),new y("const","float",[],[0]);let v=f(this._type);if(v===1&&w==="x")return this;for(let P=0;P<w.length;P++)if("xyzw".indexOf(w[P])>=v)return a("TL501",`TSL swizzle '.${S}' out of range`,"0"),new y("const",c(w.length),[],new Array(w.length).fill(0));return new y("swizzle",c(w.length),[this],void 0,void 0,w)}clamp(S=0,w=1){let v=d(S),P=d(w);return(v._type!=="float"||P._type!=="float")&&(v=m(v,this._type),P=m(P,this._type)),new y("clamp",this._type,[this,v,P])}saturate(){return this.clamp(0,1)}oneMinus(){return d(1,f(this._type)).sub(this)}mix(S,w){let[v,P,H]=p(this,S),G=d(w);return G._type!=="float"&&G._type!==H&&(G=m(G,H)),new y("mix",H,[v,P,G])}step(S){let w=d(S);return this._type==="float"?new y("step",w._type,[this,w]):new y("step",this._type,[this,m(w,this._type)])}smoothstep(S,w){let v=d(w),P=this,H=d(S);return(P._type!=="float"||H._type!=="float")&&(P=m(P,v._type),H=m(H,v._type)),new y("smoothstep",v._type,[P,H,v])}dot(S){let[w,v]=p(this,S);return new y("dot","float",[w,v])}cross(S){return new y("cross","vec3",[m(this,"vec3"),m(S,"vec3")])}length(){return new y("length","float",[this])}distance(S){let[w,v]=p(this,S);return new y("distance","float",[w,v])}reflect(S){let w=this._type==="float"?m(this,"vec3"):this;return new y("reflect",w._type,[w,m(S,w._type)])}remap(S,w,v,P){let H=this.sub(S).div(d(w).sub(S)).clamp(0,1);return d(v).mix(P,H)}}let z=y.prototype;for(let[A,S]of[["x","x"],["y","y"],["z","z"],["w","w"],["r","x"],["g","y"],["b","z"],["a","w"],["xy","xy"],["xz","xz"],["yz","yz"],["xyz","xyz"],["rgb","xyz"],["xyzw","xyzw"],["rgba","xyzw"]])Object.defineProperty(z,A,{get(){return this.swizzle(S)}});let E=["add","sub","mul","div","mod","pow","atan2","min","max"];for(let A of E)z[A]=function(S){let[w,v,P]=p(this,S);return new y(A,P,[w,v])};let _=["neg","abs","sign","floor","ceil","fract","sqrt","exp","log","sin","cos","normalize"];for(let A of _)z[A]=function(){return new y(A,this._type,[this])};let b=(A,S)=>{let w=new y("builtin",S,[],void 0,A),v=()=>w;return Object.setPrototypeOf(v,z),Object.defineProperty(v,"length",{value:z.length,configurable:!0}),Object.assign(v,w),v},$=(A,S)=>{let w=f(A);if(S.length===0)return new y("const",A,[],new Array(w).fill(0));if(S.length===1)return m(S[0],A);let v=S.map(V=>d(V)),P=!0,H=[],G=0;for(let V of v)if(G+=f(V._type),V._op==="const"&&V._val)for(let Y of V._val)H.push(Y);else P=!1;if(P&&H.length>=w)return new y("const",A,[],H.slice(0,w));if(G===w)return new y("construct",A,v);let x=[];for(let V of v){let Y=f(V._type);for(let Z=0;Z<Y&&x.length<w;Z++)x.push(Y===1?V:V.swizzle("xyzw"[Z]))}for(;x.length<w;)x.push(new y("const","float",[],[x.length===3?1:0]));return new y("construct",A,x)},T=b("positionWorld","vec3"),M={float:(A=0)=>m(A,"float"),vec2:(...A)=>$("vec2",A),vec3:(...A)=>$("vec3",A),vec4:(...A)=>$("vec4",A),color:(A=16777215,S,w)=>{if(typeof A=="number"&&typeof S=="number"&&typeof w=="number"){let P=new t.Color(A,S,w);return new y("const","vec3",[],[h(P.r,1),h(P.g,1),h(P.b,1)])}if(C(A))return m(A,"vec3");let v=new t.Color(A);return new y("const","vec3",[],[h(v.r,1),h(v.g,1),h(v.b,1)])},uniform:(A=0,S)=>{let w=d(A),v=typeof S=="string"&&S.trim().length>0?S.trim().replace(/[^A-Za-z0-9_]/g,"_").slice(0,63):`uParam_${s++}`;/^[0-9]/.test(v)&&(v="_"+v.slice(0,62)),(v==="__proto__"||v==="constructor"||v==="prototype")&&(v=`uParam_${s++}`);let P=new y("uniform",w._type,[],void 0,v);return P._uVal=A,P},positionLocal:b("positionLocal","vec3"),positionWorld:T,normalLocal:b("normalLocal","vec3"),normalWorld:b("normalWorld","vec3"),viewDirection:b("viewDirection","vec3"),uv:b("uv","vec2"),vertexColor:b("vertexColor","vec4"),instanceIndex:b("instanceIndex","float"),time:b("time","float"),clamp:(A,S=0,w=1)=>d(A).clamp(S,w),saturate:A=>d(A).saturate(),oneMinus:A=>d(A).oneMinus(),mix:(A,S,w)=>d(A).mix(S,w),step:(A,S)=>d(A).step(S),smoothstep:(A,S,w)=>d(A).smoothstep(S,w),dot:(A,S)=>d(A).dot(S),cross:(A,S)=>d(A).cross(S),length:A=>d(A).length(),distance:(A,S)=>d(A).distance(S),reflect:(A,S)=>d(A).reflect(S),remap:(A,S,w,v,P)=>d(A).remap(S,w,v,P),fresnel:(A=2)=>new y("fresnel","float",[m(A,"float")]),simplexNoise2D:A=>new y("simplexNoise2D","float",[m(A,"vec2")]),simplexNoise3D:A=>new y("simplexNoise3D","float",[m(A,"vec3")]),voronoi2D:(A,S=1)=>new y("voronoi2D","float",[m(A,"vec2"),m(S,"float")]),checker:A=>new y("checker","float",[m(A,"vec2")]),triplanar:(A=1,S=4)=>{let w=d(A),v=w._type==="vec3"?w:T.mul(m(w,"float"));return new y("triplanar","float",[v,m(S,"float")])},hueShift:(A,S)=>new y("hueShift","vec3",[m(A,"vec3"),m(S,"float")]),bumpFromHeight:(A,S=1)=>new y("bumpFromHeight","vec3",[m(A,"float"),m(S,"float")]),Loop:()=>(a("TL504","THREE.TSL.Loop","loop-free TSL constant"),new y("const","float",[],[0])),While:()=>(a("TL504","THREE.TSL.While","loop-free TSL constant"),new y("const","float",[],[0]))};for(let A of E)M[A]=(S,w)=>d(S)[A](w);for(let A of _)M[A]=S=>d(S)[A]();class N extends t.MeshPhysicalMaterial{get opacityNode(){return this._opacityNode}set opacityNode(S){this._opacityNode=S,S!=null&&!(Number(this.alphaTest)>0)&&(this.transparent=!0)}constructor(S={}){super(S),this._opacityNode=null,this.isMeshStandardNodeMaterial=!0,this.colorNode=S.colorNode??null,this.opacityNode=S.opacityNode??null,this.emissiveNode=S.emissiveNode??null,this.roughnessNode=S.roughnessNode??null,this.metalnessNode=S.metalnessNode??null,this.normalScaleNode=S.normalScaleNode??null,this.bumpNode=S.bumpNode??null,this.positionNode=S.positionNode??null}_serializeTslGraph(){let S=[["color",this.colorNode,"vec3"],["opacity",this.opacityNode,"float"],["emissive",this.emissiveNode,"vec3"],["roughness",this.roughnessNode,"float"],["metalness",this.metalnessNode,"float"],["normalScale",this.normalScaleNode,"float"],["bump",this.bumpNode,"vec3"],["position",this.positionNode,"vec3"]],w=[];for(let[X,F,Q]of S)F!=null&&w.push([X,m(F,Q)]);if(w.length===0)return null;let v=[],P={},H=new Map,G=new Set,x="",V="",Y=(X,F)=>{if(x)return 0;if(!X||!X.isTSLNode)return x="TL501",V="Invalid non-TSL node in material socket",0;if(G.has(X))return x="TL501",V="Cyclic TSL node reference",0;if(F&&(X._op==="builtin"&&X._name==="viewDirection"||X._op==="fresnel"||X._op==="bumpFromHeight"))return x="TL503",V=`Fragment-only TSL op '${X._name||X._op}' used in positionNode`,0;G.add(X);let Q=[];for(let Ne of X._args)if(Q.push(Y(Ne,F)),x)return G.delete(X),0;if(G.delete(X),X._op==="uniform"){let Ne=X._name||"uParam";if(Ne in P){if(P[Ne].type!==X._type)return x="TL501",V=`Conflicting types for TSL uniform '${Ne}' (${P[Ne].type} vs ${X._type})`,0}else{if(Object.keys(P).length>=r)return x="TL502",V=`TSL material exceeds MAX_TSL_UNIFORMS (${r})`,0;let De=m(X._uVal??0,X._type)._val??[0];P[Ne]={type:X._type,value:X._type==="float"?De[0]:De}}}let L=`${X._op}|${X._type}|${Q.join(",")}|${X._val?X._val.join(","):""}|${X._name??""}|${X._mask??""}`,ee=H.get(L);if(ee!==void 0)return ee;if(v.length>=i)return x="TL502",V=`TSL material exceeds MAX_TSL_NODES (${i})`,0;let ae=v.length,be={op:X._op,type:X._type};return Q.length>0&&(be.args=Q),X._val&&(be.value=[...X._val]),X._name&&(be.name=X._name),X._mask&&(be.mask=X._mask),v.push(be),H.set(L,ae),ae},Z={};for(let[X,F]of w)if(Z[X]=Y(F,X==="position"),x)return a(x,V,"base MeshStandardMaterial factors"),null;let q={version:1,nodes:v,outputs:Z};return Object.keys(P).length>0&&(q.uniforms=P),q}clone(){let S=new N;for(let w of["name","_em","roughness","metalness","emissiveIntensity","opacity","transparent","wireframe","side","doubleSided","map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","aoMapIntensity","bumpMap","bumpScale","clearcoat","clearcoatRoughness","sheen","sheenRoughness","ior","transmission","thickness","attenuationDistance","dispersion","iridescence","iridescenceIOR","colorNode","opacityNode","emissiveNode","roughnessNode","metalnessNode","normalScaleNode","bumpNode","positionNode"])S[w]=this[w];return S.color.copy(this.color),S.emissive.copy(this.emissive),S.normalScale.copy(this.normalScale),S.sheenColor.copy(this.sheenColor),S.attenuationColor.copy(this.attenuationColor),S}}let k={TSL:M,TSLNode:y,MeshStandardNodeMaterial:N,MeshPhysicalNodeMaterial:N};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,k)),k}var Yo={positionLocal:"vec3",positionWorld:"vec3",normalLocal:"vec3",normalWorld:"vec3",viewDirection:"vec3",uv:"vec2",vertexColor:"vec4",instanceIndex:"float",time:"float"},Jo={color:"vec3",opacity:"float",emissive:"vec3",roughness:"float",metalness:"float",normalScale:"float",bump:"vec3",position:"vec3"},Zo=new Set(["neg","abs","sign","floor","ceil","fract","sqrt","exp","log","sin","cos","normalize"]),Qo=new Set(["add","sub","mul","div","mod","pow","atan2","min","max"]),_s={cross:[["vec3","vec3"],"vec3"],fresnel:[["float"],"float"],simplexNoise2D:[["vec2"],"float"],checker:[["vec2"],"float"],simplexNoise3D:[["vec3"],"float"],voronoi2D:[["vec2","float"],"float"],triplanar:[["vec3","float"],"float"],hueShift:[["vec3","float"],"vec3"],bumpFromHeight:[["float","float"],"vec3"]},Ko=/^[A-Za-z_][A-Za-z0-9_]{0,63}$/,el=new Set(["__proto__","constructor","prototype"]);function wi(t){return t==="vec4"?4:t==="vec3"?3:t==="vec2"?2:1}function tl(t){return t===1?"float":t===2?"vec2":t===3?"vec3":t===4?"vec4":null}function pn(t){return t==="float"||t==="vec2"||t==="vec3"||t==="vec4"}function ut(t,e,i="Use loop-free THREE.TSL expressions on MeshStandardNodeMaterial (<= 128 nodes, <= 16 uniforms)."){return{ok:!1,issue:{code:t,message:e,hint:i}}}function Oi(t,e){for(let i=0;i<e.length;i++)t=Math.imul((t^e.charCodeAt(i))>>>0,16777619)>>>0;return t}var Ss=new Float32Array(1),il=new Uint32Array(Ss.buffer);function rl(t,e){return Ss[0]=e,Math.imul((t^il[0])>>>0,16777619)>>>0}function nl(t,e){let i=wi(t);if(i===1){let s=typeof e=="number"?e:Array.isArray(e)&&e.length===1?Number(e[0]):NaN;return Number.isFinite(s)?[Math.fround(s),0,0,0]:null}if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length<i)return null;let r=[0,0,0,0];for(let s=0;s<i;s++){let a=Number(e[s]);if(!Number.isFinite(a))return null;r[s]=Math.fround(a)}return r}function sl(t,e="Material"){if(!t||typeof t!="object"||Array.isArray(t))return ut("TL501",`Invalid GOOGLE_material_tsl on '${e}'.`);let i=t;if(i.version!==1)return ut("TL501",`Unsupported TSL version on '${e}'.`);let r=[],s=new Map,a=i.uniforms;if(a!=null){if(typeof a!="object"||Array.isArray(a))return ut("TL501",`Invalid TSL uniforms on '${e}'.`);let b=a,$=Object.keys(b).sort();if($.length>16)return ut("TL502",`TSL '${e}' exceeds MAX_TSL_UNIFORMS (16).`);for(let T=0;T<$.length;T++){let M=$[T],N=b[M],k=N&&!Array.isArray(N)?N.type:null,A=pn(k)?nl(k,N.value):null;if(el.has(M)||!Ko.test(M)||!pn(k)||!A)return ut("TL501",`Invalid TSL uniform '${M}' on '${e}'.`);let S={name:M,slot:T,type:k,defaultVec4:A};r.push(S),s.set(M,S)}}let f=i.nodes;if(!Array.isArray(f)||f.length===0)return ut("TL501",`Empty TSL nodes on '${e}'.`);if(f.length>128)return ut("TL502",`TSL '${e}' exceeds MAX_TSL_NODES (128).`);let c=[],h=2166136261;for(let b of r)h=Oi(h,`U:${b.slot}:${b.type};`);for(let b=0;b<f.length;b++){let $=f[b];if(!$||typeof $!="object"||Array.isArray($))return ut("TL501",`Invalid TSL node ${b} on '${e}'.`);let T=$,M=T.op,N=T.type;if(M==="loop"||M==="while"||M==="for"||M==="call")return ut("TL504",`Unsupported loop/call op '${M}' at node ${b} on '${e}'.`);if(typeof M!="string"||!pn(N))return ut("TL501",`Malformed TSL node ${b} on '${e}'.`);let k=M,A=T.args,S=[];if(A!==void 0){if(!Array.isArray(A)||A.length>4)return ut("TL501",`Invalid args at node ${b} on '${e}'.`);for(let v of A){if(typeof v!="number"||!Number.isInteger(v)||v<0||v>=b)return ut("TL501",`Cyclic or out-of-order arg at node ${b} on '${e}'.`);S.push(v)}}h=Oi(h,`N${b}:${k}:${N}:`);for(let v of S)h=Oi(h,`${v},`);let w=S.map(v=>c[v].type);if(k==="const"){let v=wi(N),P=T.value;if(S.length!==0||!Array.isArray(P)||P.length!==v)return ut("TL501",`Invalid const node ${b} on '${e}'.`);let H=[];for(let G=0;G<v;G++){let x=Number(P[G]);if(!Number.isFinite(x))return ut("TL501",`Non-finite const at node ${b}.`);let V=Math.fround(x);H.push(V),h=rl(h,V)}c.push({op:k,type:N,args:[],value:H})}else if(k==="builtin"){let v=T.name;if(S.length!==0||typeof v!="string"||Yo[v]!==N)return ut("TL501",`Invalid builtin at node ${b}.`);h=Oi(h,v),c.push({op:k,type:N,args:[],builtin:v})}else if(k==="uniform"){let v=T.name,P=typeof v=="string"?s.get(v):void 0;if(S.length!==0||!P||P.type!==N)return ut("TL501",`Invalid uniform ref at node ${b}.`);h=Oi(h,`S${P.slot}`),c.push({op:k,type:N,args:[],uniformSlot:P.slot})}else if(k==="swizzle"){let v=T.mask;if(S.length!==1||typeof v!="string"||!/^[xyzw]{1,4}$/.test(v)||tl(v.length)!==N)return ut("TL501",`Invalid swizzle at node ${b}.`);let P=wi(w[0]);for(let H=0;H<v.length;H++)if("xyzw".indexOf(v[H])>=P)return ut("TL501",`Swizzle '.${v}' out of bounds at node ${b}.`);h=Oi(h,v),c.push({op:k,type:N,args:S,mask:v})}else if(k==="construct"){let v=wi(N),P=w.reduce((H,G)=>H+wi(G),0);if(S.length===0||!(S.length===1&&w[0]==="float")&&P!==v)return ut("TL501",`Invalid construct at node ${b}.`);c.push({op:k,type:N,args:S})}else if(Zo.has(k)){if(S.length!==1||w[0]!==N)return ut("TL501",`Type mismatch on '${k}' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(Qo.has(k)){if((S.length===2?w[0]===w[1]?w[0]:w[0]==="float"?w[1]:w[1]==="float"?w[0]:null:null)!==N)return ut("TL501",`Type mismatch on '${k}' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="step"){if(S.length!==2||w[0]!==w[1]&&w[0]!=="float"||N!==w[1])return ut("TL501",`Invalid 'step' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="clamp"){if(!(S.length===3&&N===w[0]&&(w[1]===w[0]&&w[2]===w[0]||w[1]==="float"&&w[2]==="float")))return ut("TL501",`Invalid 'clamp' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="mix"){if(!(S.length===3&&w[0]===w[1]&&N===w[0]&&(w[2]===w[0]||w[2]==="float")))return ut("TL501",`Invalid 'mix' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="smoothstep"){if(!(S.length===3&&N===w[2]&&(w[0]===w[2]&&w[1]===w[2]||w[0]==="float"&&w[1]==="float")))return ut("TL501",`Invalid 'smoothstep' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="dot"||k==="distance"){if(S.length!==2||w[0]!==w[1]||N!=="float")return ut("TL501",`Invalid '${k}' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="length"){if(S.length!==1||N!=="float")return ut("TL501",`Invalid 'length' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k==="reflect"){if(S.length!==2||w[0]!==w[1]||w[0]==="float"||N!==w[0])return ut("TL501",`Invalid 'reflect' at node ${b}.`);c.push({op:k,type:N,args:S})}else if(k in _s){let[v,P]=_s[k];if(S.length!==v.length||N!==P||v.some((H,G)=>w[G]!==H))return ut("TL501",`Invalid '${k}' at node ${b}.`);c.push({op:k,type:N,args:S})}else return ut("TL501",`Unknown TSL op '${String(k)}' at node ${b}.`)}let C=i.outputs;if(!C||typeof C!="object"||Array.isArray(C))return ut("TL501",`Missing TSL outputs on '${e}'.`);let d=C,p={},m=0;for(let b of Object.keys(d).sort()){let $=Jo[b];if(!$)return ut("TL501",`Unknown TSL socket '${b}' on '${e}'.`);let T=d[b];if(T!=null){if(typeof T!="number"||!Number.isInteger(T)||T<0||T>=c.length||c[T].type!==$)return ut("TL501",`Invalid TSL output '${b}' on '${e}'.`);p[b]=T,m++,h=Oi(h,`O:${b}=${T};`)}}if(m===0)return ut("TL501",`No active TSL outputs on '${e}'.`);let y=new Uint8Array(c.length),z=new Uint8Array(c.length);for(let[b,$]of Object.entries(p))b==="position"?z[$]=1:y[$]=1;for(let b=c.length-1;b>=0;b--){if(y[b])for(let $ of c[b].args)y[$]=1;if(z[b])for(let $ of c[b].args)z[$]=1}let E=!1,_=!1;for(let b=0;b<c.length;b++){let $=c[b];if(z[b]&&($.op==="builtin"&&$.builtin==="viewDirection"||$.op==="fresnel"||$.op==="bumpFromHeight"))return ut("TL503",`Fragment-only TSL op '${$.builtin||$.op}' used in positionNode on '${e}'.`);(y[b]||z[b])&&($.op==="builtin"&&$.builtin==="time"&&(E=!0),$.op==="bumpFromHeight"&&(_=!0))}return{ok:!0,graph:{nodes:c,outputs:p,uniformSlots:r,uniformSlotByName:s,hash:(h>>>0).toString(16).padStart(8,"0"),usesTime:E,usesVertexPosition:p.position!==void 0,usesDerivatives:_,fragmentReachable:y,vertexReachable:z}}}function mn(t){if(!Number.isFinite(t)||t===0)return"0.0";let e=Math.fround(t),i=Math.abs(e);if(i>=1e-4&&i<1e6){let s=Number(e.toPrecision(7)).toString();return s.includes(".")?s:`${s}.0`}let r=e.toExponential(6).split("e");return`${r[0].replace(/(\.\d*?[1-9])0+$/,"$1").replace(/\.0+$/,".0")}e${r[1]}`}var al={float:"float",vec2:"float2",vec3:"float3",vec4:"float4"},ol={float:"float",vec2:"vector2",vec3:"vector3",vec4:"vector4"};function Yt(t){return al[t]||"float"}function ki(t){return ol[t]||"float"}function sr(t,e){if(e===1)return mn(t[0]??0);let i=[];for(let r=0;r<e;r++)i.push(mn(t[r]??0));return`(${i.join(", ")})`}function ll(t,e,i=""){let r;if(t&&typeof t=="object"&&"fragmentReachable"in t)r=t;else{let M=sl(t,e);if(!M.ok)return null;r=M.graph}if(!r.fragmentReachable.some(M=>M===1))return null;let s=`/Root/Materials/${(e||"Material").replace(/[^A-Za-z0-9_]/g,"_").replace(/^([0-9])/,"_$1")||"Material"}/TSLGraph`,a=[],f=[],c=0;for(let M of r.uniformSlots){let N=Yt(M.type),k=wi(M.type);f.push(`${N} inputs:u_${M.slot} = ${sr(M.defaultVec4,k)}`)}let h=(M,N,k,A)=>(a.push(`def Shader "${M}"
|
|
352
|
+
{
|
|
353
|
+
uniform token info:id = "${N}"
|
|
354
|
+
${A.join(`
|
|
355
|
+
`)}${A.length>0?`
|
|
356
|
+
`:""}${k} outputs:out
|
|
357
|
+
}`),`${s}/${M}.outputs:out`),C=(M,N)=>{let k=wi(M),A=`C_${c++}`;return h(A,`ND_constant_${ki(M)}`,Yt(M),[`${Yt(M)} inputs:value = ${sr(N,k)}`])},d=(M,N)=>{if(N==="float")return M;let k=wi(N),A=`B_${c++}`,S=[];for(let w=1;w<=k;w++)S.push(`float inputs:in${w}.connect = <${M}>`);return h(A,`ND_combine${k}_${ki(N)}`,Yt(N),S)},p=(M,N,k)=>N===k?M:d(M,k),m=(M,N,k)=>{if(N==="float")return M;let A=`E_${c++}`;return h(A,`ND_extract_${ki(N)}`,"float",[`${Yt(N)} inputs:in.connect = <${M}>`,`int inputs:index = ${k}`])},y=new Map,z=M=>{let N=y.get(M);if(N)return N;let k="";switch(M){case"positionLocal":k=h("BI_posLocal","ND_position_vector3","float3",['string inputs:space = "object"']);break;case"positionWorld":k=h("BI_posWorld","ND_position_vector3","float3",['string inputs:space = "world"']);break;case"normalLocal":k=h("BI_normLocal","ND_normal_vector3","float3",['string inputs:space = "object"']);break;case"normalWorld":k=h("BI_normWorld","ND_normal_vector3","float3",['string inputs:space = "world"']);break;case"viewDirection":{let A=h("BI_rawView","ND_viewdirection_vector3","float3",['string inputs:space = "world"']);k=h("BI_viewDir","ND_multiply_vector3FA","float3",[`float3 inputs:in1.connect = <${A}>`,"float inputs:in2 = -1.0"]);break}case"uv":k=h("BI_uv","ND_texcoord_vector2","float2",["int inputs:index = 0"]);break;case"vertexColor":{let A=h("BI_vcCol","ND_geomcolor_color4","color4f",["int inputs:index = 0"]);k=h("BI_vcVec","ND_convert_color4_vector4","float4",[`color4f inputs:in.connect = <${A}>`]);break}case"instanceIndex":k=C("float",[0]);break;case"time":{let A=h("BI_rawTime","ND_time_float","float",[]);k=h("BI_time","ND_modulo_float","float",[`float inputs:in1.connect = <${A}>`,`float inputs:in2 = ${mn(3600)}`]);break}default:k=C("float",[0]);break}return y.set(M,k),k},E=new Array(r.nodes.length).fill("");for(let M=0;M<r.nodes.length;M++){if(!r.fragmentReachable[M])continue;let N=r.nodes[M],k=N.type,A=Yt(k),S=ki(k),w=wi(k),v=N.args[0]!==void 0?E[N.args[0]]:"",P=N.args[1]!==void 0?E[N.args[1]]:"",H=N.args[2]!==void 0?E[N.args[2]]:"",G=N.args[0]!==void 0?r.nodes[N.args[0]].type:"float",x=N.args[1]!==void 0?r.nodes[N.args[1]].type:"float",V=N.args[2]!==void 0?r.nodes[N.args[2]].type:"float",Y=`N${M}`;switch(N.op){case"const":E[M]=h(Y,`ND_constant_${S}`,A,[`${A} inputs:value = ${sr(N.value??[0],w)}`]);break;case"builtin":E[M]=z(N.builtin??"time");break;case"uniform":E[M]=`${s}.inputs:u_${N.uniformSlot??0}`;break;case"swizzle":{let Z=N.mask??"x";if(G==="float")E[M]=d(v,k);else if(Z.length===1)E[M]=m(v,G,"xyzw".indexOf(Z[0]));else{let q=Array.from(Z).map(X=>m(v,G,"xyzw".indexOf(X)));E[M]=h(Y,`ND_combine${Z.length}_${S}`,A,q.map((X,F)=>`float inputs:in${F+1}.connect = <${X}>`))}break}case"construct":{if(k==="float")E[M]=v;else if(N.args.length===1&&G==="float")E[M]=d(v,k);else{let Z=[];for(let q of N.args){let X=r.nodes[q].type,F=E[q],Q=wi(X);if(Q===1)Z.push(F);else for(let L=0;L<Q;L++)Z.push(m(F,X,L))}E[M]=h(Y,`ND_combine${w}_${S}`,A,Z.slice(0,w).map((q,X)=>`float inputs:in${X+1}.connect = <${q}>`))}break}case"neg":{E[M]=h(Y,`ND_multiply_${S}`,A,[`${A} inputs:in1.connect = <${v}>`,`${A} inputs:in2 = ${sr([-1,-1,-1,-1],w)}`]);break}case"abs":case"sign":case"floor":case"ceil":case"sqrt":case"exp":case"sin":case"cos":case"normalize":{let Z=N.op==="abs"?"absval":N.op;N.op==="normalize"&&k==="float"?E[M]=h(Y,"ND_sign_float","float",[`float inputs:in.connect = <${v}>`]):E[M]=h(Y,`ND_${Z}_${S}`,A,[`${A} inputs:in.connect = <${v}>`]);break}case"log":E[M]=h(Y,`ND_ln_${S}`,A,[`${A} inputs:in.connect = <${v}>`]);break;case"fract":{E[M]=h(Y,`ND_modulo_${S}`,A,[`${A} inputs:in1.connect = <${v}>`,`${A} inputs:in2 = ${sr([1,1,1,1],w)}`]);break}case"add":case"sub":case"mul":case"div":case"mod":case"pow":case"atan2":case"min":case"max":{let Z={add:"add",sub:"subtract",mul:"multiply",div:"divide",mod:"modulo",pow:"power",atan2:"atan2",min:"min",max:"max"},q=p(v,G,k),X=p(P,x,k);E[M]=h(Y,`ND_${Z[N.op]}_${S}`,A,[`${A} inputs:in1.connect = <${q}>`,`${A} inputs:in2.connect = <${X}>`]);break}case"step":{let Z=p(v,G,k);if(k==="float")E[M]=h(Y,"ND_ifgreater_float","float",[`float inputs:value1.connect = <${P}>`,`float inputs:value2.connect = <${Z}>`,"float inputs:in1 = 1.0","float inputs:in2 = 0.0"]);else{let q=[];for(let X=0;X<w;X++){let F=m(Z,k,X),Q=m(P,k,X);q.push(h(`S_${c++}`,"ND_ifgreater_float","float",[`float inputs:value1.connect = <${Q}>`,`float inputs:value2.connect = <${F}>`,"float inputs:in1 = 1.0","float inputs:in2 = 0.0"]))}E[M]=h(Y,`ND_combine${w}_${S}`,A,q.map((X,F)=>`float inputs:in${F+1}.connect = <${X}>`))}break}case"clamp":{let Z=p(P,x,k),q=p(H,V,k);E[M]=h(Y,`ND_clamp_${S}`,A,[`${A} inputs:in.connect = <${v}>`,`${A} inputs:low.connect = <${Z}>`,`${A} inputs:high.connect = <${q}>`]);break}case"mix":{let Z=p(H,V,k);E[M]=h(Y,`ND_mix_${S}`,A,[`${A} inputs:bg.connect = <${v}>`,`${A} inputs:fg.connect = <${P}>`,`${A} inputs:mix.connect = <${Z}>`]);break}case"smoothstep":{let Z=p(v,G,k),q=p(P,x,k);E[M]=h(Y,`ND_smoothstep_${S}`,A,[`${A} inputs:in.connect = <${H}>`,`${A} inputs:low.connect = <${Z}>`,`${A} inputs:high.connect = <${q}>`]);break}case"dot":G==="float"?E[M]=h(Y,"ND_multiply_float","float",[`float inputs:in1.connect = <${v}>`,`float inputs:in2.connect = <${P}>`]):E[M]=h(Y,`ND_dotproduct_${ki(G)}`,"float",[`${Yt(G)} inputs:in1.connect = <${v}>`,`${Yt(G)} inputs:in2.connect = <${P}>`]);break;case"length":G==="float"?E[M]=h(Y,"ND_absval_float","float",[`float inputs:in.connect = <${v}>`]):E[M]=h(Y,`ND_magnitude_${ki(G)}`,"float",[`${Yt(G)} inputs:in.connect = <${v}>`]);break;case"distance":{let Z=h(`D_${c++}`,`ND_subtract_${ki(G)}`,Yt(G),[`${Yt(G)} inputs:in1.connect = <${v}>`,`${Yt(G)} inputs:in2.connect = <${P}>`]);E[M]=G==="float"?h(Y,"ND_absval_float","float",[`float inputs:in.connect = <${Z}>`]):h(Y,`ND_magnitude_${ki(G)}`,"float",[`${Yt(G)} inputs:in.connect = <${Z}>`]);break}case"cross":E[M]=h(Y,"ND_crossproduct_vector3","float3",[`float3 inputs:in1.connect = <${v}>`,`float3 inputs:in2.connect = <${P}>`]);break;case"reflect":if(k==="vec3")E[M]=h(Y,"ND_reflect_vector3","float3",[`float3 inputs:in.connect = <${v}>`,`float3 inputs:normal.connect = <${P}>`]);else{let Z=k==="float"?h(`RF_${c++}`,"ND_multiply_float","float",[`float inputs:in1.connect = <${P}>`,`float inputs:in2.connect = <${v}>`]):h(`RF_${c++}`,`ND_dotproduct_${S}`,"float",[`${A} inputs:in1.connect = <${P}>`,`${A} inputs:in2.connect = <${v}>`]),q=h(`RF_${c++}`,"ND_multiply_float","float",[`float inputs:in1.connect = <${Z}>`,"float inputs:in2 = 2.0"]),X=h(`RF_${c++}`,`ND_multiply_${S}`,A,[`${A} inputs:in1.connect = <${P}>`,`${A} inputs:in2.connect = <${p(q,"float",k)}>`]);E[M]=h(Y,`ND_subtract_${S}`,A,[`${A} inputs:in1.connect = <${v}>`,`${A} inputs:in2.connect = <${X}>`])}break;case"fresnel":{let Z=z("normalWorld"),q=z("viewDirection"),X=h(`FR_${c++}`,"ND_dotproduct_vector3","float",[`float3 inputs:in1.connect = <${Z}>`,`float3 inputs:in2.connect = <${q}>`]),F=h(`FR_${c++}`,"ND_clamp_float","float",[`float inputs:in.connect = <${X}>`,"float inputs:low = 0.0","float inputs:high = 1.0"]),Q=h(`FR_${c++}`,"ND_subtract_float","float",["float inputs:in1 = 1.0",`float inputs:in2.connect = <${F}>`]);E[M]=h(Y,"ND_power_float","float",[`float inputs:in1.connect = <${Q}>`,`float inputs:in2.connect = <${v}>`]);break}case"simplexNoise2D":E[M]=h(Y,"ND_noise2d_float","float",[`float2 inputs:texcoord.connect = <${v}>`,"float inputs:amplitude = 0.5","float inputs:pivot = 0.5"]);break;case"simplexNoise3D":E[M]=h(Y,"ND_noise3d_float","float",[`float3 inputs:position.connect = <${v}>`,"float inputs:amplitude = 0.5","float inputs:pivot = 0.5"]);break;case"voronoi2D":E[M]=h(Y,"ND_cellnoise2d_float","float",[`float2 inputs:texcoord.connect = <${v}>`]);break;case"checker":{let Z=h(`CK_${c++}`,"ND_floor_vector2","float2",[`float2 inputs:in.connect = <${v}>`]),q=m(Z,"vec2",0),X=m(Z,"vec2",1),F=h(`CK_${c++}`,"ND_add_float","float",[`float inputs:in1.connect = <${q}>`,`float inputs:in2.connect = <${X}>`]),Q=h(`CK_${c++}`,"ND_modulo_float","float",[`float inputs:in1.connect = <${F}>`,"float inputs:in2 = 2.0"]);E[M]=h(Y,"ND_ifgreater_float","float",[`float inputs:value1.connect = <${Q}>`,"float inputs:value2 = 0.999","float inputs:in1 = 1.0","float inputs:in2 = 0.0"]);break}case"triplanar":E[M]=h(Y,"ND_noise3d_float","float",[`float3 inputs:position.connect = <${v}>`,"float inputs:amplitude = 0.5","float inputs:pivot = 0.5"]);break;case"hueShift":{let Z=h(`HS_${c++}`,"ND_convert_vector3_color3","color3f",[`float3 inputs:in.connect = <${v}>`]),q=h(`HS_${c++}`,"ND_multiply_float","float",[`float inputs:in1.connect = <${P}>`,"float inputs:in2 = 0.15915494"]),X=h(`HS_${c++}`,"ND_combine3_vector3","float3",[`float inputs:in1.connect = <${q}>`,"float inputs:in2 = 1.0","float inputs:in3 = 1.0"]),F=h(`HS_${c++}`,"ND_hsvadjust_color3","color3f",[`color3f inputs:in.connect = <${Z}>`,`float3 inputs:amount.connect = <${X}>`]);E[M]=h(Y,"ND_convert_color3_vector3","float3",[`color3f inputs:in.connect = <${F}>`]);break}case"bumpFromHeight":{E[M]=h(Y,"ND_heighttonormal_vector3","float3",[`float inputs:in.connect = <${v}>`,`float inputs:scale.connect = <${P}>`]);break}default:E[M]=C(k,[0,0,0,0]);break}}let _=[],b={};if(r.outputs.color!==void 0){let M=h("OUT_color","ND_convert_vector3_color3","color3f",[`float3 inputs:in.connect = <${E[r.outputs.color]}>`]);_.push(`color3f outputs:diffuseColor.connect = <${M}>`),b.diffuseColor=`${s}.outputs:diffuseColor`}if(r.outputs.emissive!==void 0){let M=h("OUT_emissive","ND_convert_vector3_color3","color3f",[`float3 inputs:in.connect = <${E[r.outputs.emissive]}>`]);_.push(`color3f outputs:emissiveColor.connect = <${M}>`),b.emissiveColor=`${s}.outputs:emissiveColor`}if(r.outputs.opacity!==void 0&&(_.push(`float outputs:opacity.connect = <${E[r.outputs.opacity]}>`),b.opacity=`${s}.outputs:opacity`),r.outputs.roughness!==void 0&&(_.push(`float outputs:roughness.connect = <${E[r.outputs.roughness]}>`),b.roughness=`${s}.outputs:roughness`),r.outputs.metalness!==void 0&&(_.push(`float outputs:metallic.connect = <${E[r.outputs.metalness]}>`),b.metallic=`${s}.outputs:metallic`),r.outputs.bump!==void 0&&(_.push(`normal3f outputs:normal.connect = <${E[r.outputs.bump]}>`),b.normal=`${s}.outputs:normal`),_.length===0)return null;let $=[["diffuseColor","color3f"],["metallic","float"],["roughness","float"],["opacity","float"],["emissiveColor","color3f"],["normal","normal3f"]],T=i;for(let[M,N]of $){let k=b[M];if(!k)continue;let A=`${N} inputs:${M}.connect = <${k}>`,S=new RegExp(`^${N}\\s+inputs:${M}[^
|
|
358
|
+
]*$`,"m");S.test(T)?T=T.replace(S,A):T+=`${T.endsWith(`
|
|
359
|
+
`)||!T?"":`
|
|
360
|
+
`}${A}
|
|
361
|
+
`}return{nodeGraphUsda:`def NodeGraph "TSLGraph"
|
|
365
362
|
{
|
|
366
|
-
${
|
|
367
|
-
`}
|
|
363
|
+
${[...f,..._,...a].join(`
|
|
364
|
+
`)}
|
|
368
365
|
}
|
|
369
|
-
`,n}var si=null;function Li(t){{let i=globalThis.__three_live_native_crc32__;if(typeof i=="function")return i(t)}if(!si){si=new Uint32Array(256);for(let i=0;i<256;i++){let r=i;for(let s=0;s<8;s++)r=r&1?3988292384^r>>>1:r>>>1;si[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=si[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Ha(t){{let h=globalThis.__three_live_native_build_usdz_zip__;if(typeof h=="function")return h(t)}let e=[],i=0,r=[];for(let h of t){let l=Ei(h.filename),p=Li(h.data),m=h.data.length,y=30+l.length,x=(i+y)%64,w=x!==0?64-x:0;w>0&&w<4&&(w+=64);let v=new Uint8Array(y+w),_=new DataView(v.buffer);_.setUint32(0,67324752,!0),_.setUint16(4,20,!0),_.setUint32(14,p,!0),_.setUint32(18,m,!0),_.setUint32(22,m,!0),_.setUint16(26,l.length,!0),_.setUint16(28,w,!0),v.set(l,30),w>=4&&(_.setUint16(y,6534,!0),_.setUint16(y+2,w-4,!0)),e.push({offset:i,size:m,crc:p,filenameBytes:l,entry:h}),r.push(v,h.data),i+=v.length+h.data.length}let s=i;for(let h of e){let l=new Uint8Array(46+h.filenameBytes.length),p=new DataView(l.buffer);p.setUint32(0,33639248,!0),p.setUint16(4,20,!0),p.setUint16(6,20,!0),p.setUint32(16,h.crc,!0),p.setUint32(20,h.size,!0),p.setUint32(24,h.size,!0),p.setUint16(28,h.filenameBytes.length,!0),p.setUint32(42,h.offset,!0),l.set(h.filenameBytes,46),r.push(l),i+=l.length}let a=i-s,o=new Uint8Array(22),n=new DataView(o.buffer);n.setUint32(0,101010256,!0),n.setUint16(8,e.length,!0),n.setUint16(10,e.length,!0),n.setUint32(12,a,!0),n.setUint32(16,s,!0),r.push(o),i+=22;let u=new Uint8Array(i),d=0;for(let h of r)u.set(h,d),d+=h.length;return u}function Lr(t){let e=[{filename:"model.usda",data:Ei(Ga(t))}],i=new Set(["model.usda"]),r=[...t];for(;r.length>0;){let s=r.pop();for(let a of s.textures||[])a?.file&&a.data?.byteLength&&!i.has(a.file)&&(i.add(a.file),e.push({filename:a.file,data:a.data}));if(s.children)for(let a=s.children.length-1;a>=0;a--)r.push(s.children[a])}return Ha(e)}function ai(t){return Lr(Ba(t))}function zi(t){return Lr(Rr(Pi(t)))}function zr(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():zi(t)}function ae(t,e,i,r){let s=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(i,s))}function st(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function ye(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Qe(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Wa(t){let e=ye(t);if(!e||e.lazy===!1)return null;let i=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=i!=="head";return{mode:i,lazy:!0,distance:ae(e.distance,.1,10,r?.15:1),deadzoneDeg:ae(e.deadzoneDeg,0,90,r?0:15),stiffness:ae(e.stiffness,.5,40,6),height:ae(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function qa(t){let e=ye(t);if(!e)return null;let i=e.target;return{target:st(i)?[i[0],i[1],i[2]]:typeof i=="string"&&i.length>0&&i.length<=256?i:[0,0,0],radius:ae(e.radius,.01,50,.5),speed:ae(e.speed,-20,20,.5),height:ae(e.height,-10,10,0),phase:ae(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function Xa(t){if(!t)return null;let e=ye(t)??{},i=ae(e.minScale??e.min,.001,1e3,.1),r=ae(e.maxScale??e.max,i,1e3,Math.max(i,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:i,maxScale:r}}var kr=2e3,Ka={rain:600,snow:400,sparks:300,confetti:300};function Ya(t){let e=ye(t);if(!e)return null;let i=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,s=o=>ae(o,.05,50,2),a=st(r)?[s(r[0]),s(r[1]),s(r[2])]:typeof r=="number"?[s(r),s(r),s(r)]:[2,2,2];return{preset:i,count:Math.round(ae(e.count,1,kr,Ka[i])),area:a,speed:ae(e.speed,.05,10,1)}}var Za=4e3;function Ja(t){if(!t)return null;let e=ye(t)??{};return{prompt:Qe(e.prompt,Za)??"What is this?",holdMs:ae(e.holdMs,100,5e3,600)}}function Qa(t){if(!t)return null;let e=ye(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function oi(t){let e=Qe(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function eo(t){let e=typeof t=="string"?{src:t}:ye(t),i=oi(e?.src);return!e||!i?null:{src:i,refDistance:ae(e.refDistance,.01,1e3,1),loop:e.loop===!0}}var Cr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],to=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Ir=new Set(Cr),io=new Set(to);function Dt(t){return!!(t&&(Ir.has(t)||io.has(t)))}function Ur(t){if(!t)return null;let e=null;if(typeof t=="string"){let f=t.trim();if(!f)return null;e=Dt(f)?{preset:f}:{src:f}}else e=ye(t);if(!e||e.enabled===!1)return null;let i=Qe(e.preset,32)?.trim(),r=Dt(i)?i:void 0,s=oi(e.src??e.url??e.uri);if(!r&&!s)return null;let a=!r||Ir.has(r),o=e.type==="global"||e.positional===!1?"global":"positional",n=ae(e.volume??e.gain,0,2,.6),u=ae(e.pitch??e.playbackRate,.25,4,1),d=typeof e.loop=="boolean"?e.loop:a,h=typeof e.autoplay=="boolean"?e.autoplay:typeof e.autoPlay=="boolean"?e.autoPlay:!0,l=e.distanceModel==="linear"||e.distanceModel==="exponential"?e.distanceModel:"inverse",p=ae(e.refDistance,.05,100,1),m=ae(e.maxDistance,p,500,Math.max(p,25)),y=ae(e.rolloffFactor,0,10,1),x=ae(e.coneInnerAngle,0,360,360),w=ae(e.coneOuterAngle,x,360,Math.max(x,360)),v=ae(e.coneOuterGain,0,1,0),_=e.playOnSelect===!0||e.playOnTap===!0;return{...r?{preset:r}:{},...s?{src:s}:{},type:o,volume:n,pitch:u,loop:d,autoplay:h,distanceModel:l,refDistance:p,maxDistance:m,rolloffFactor:y,coneInnerAngle:x,coneOuterAngle:w,coneOuterGain:v,playOnSelect:_}}function Vt(t,e){let i=Qe(t,16)?.trim();if(!i)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(i);return r?`#${r[1].toLowerCase()}`:e}var ro=new Set(["m","cm","mm","in","ft-in","auto"]),Fr=["x","y","z"];function so(t){if(!t)return null;let e=ye(t);if(e&&e.enabled===!1)return null;let i=e?.unit,r=typeof i=="string"&&ro.has(i)?i:"auto",s=e?.axes,a=new Set(Array.isArray(s)?s.filter(n=>typeof n=="string"):typeof s=="string"?s.split(""):[]),o=Fr.filter(n=>a.has(n));return{enabled:!0,unit:r,axes:o.length>0?o:[...Fr],color:Vt(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var ao=new Set(["none","floor","wall","ceiling","any"]);function oo(t){if(!t)return null;let e=ye(t)??{},i=e.grid,r=o=>ae(o,.001,100,.1),s=st(i)?[r(i[0]),r(i[1]),r(i[2])]:typeof i=="number"&&Number.isFinite(i)&&i>0?[r(i),r(i),r(i)]:null,a=e.surface;return{grid:s,angleDeg:ae(e.angleDeg,0,180,0),surface:typeof a=="string"&&ao.has(a)?a:"none",socketTag:Qe(e.socketTag,128)??"",radius:ae(e.radius,.01,2,.15)}}function no(t){let e=typeof t=="string"?{tag:t}:ye(t),i=Qe(e?.tag,128);return!e||!i?null:{tag:i,radius:ae(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:Vt(e.highlightColor,"#22c55e")}}function lo(t){if(!t)return null;let e=ye(t);if(e&&e.enabled===!1)return null;let i=e?.action;return{enabled:!0,dwellMs:Math.round(ae(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:i==="ask"?"ask":"select"}}function uo(t){if(!t)return null;let e=ye(t);if(e&&e.enabled===!1)return null;let i=e?.direction??e?.offset,r=null,s;if(st(i)){let o=Math.hypot(i[0],i[1],i[2]);o>1e-8&&(r=[i[0]/o,i[1]/o,i[2]/o],e?.direction===void 0&&e?.offset!==void 0&&(s=o))}let a=typeof e?.distance=="number"&&Number.isFinite(e.distance)?e.distance:s;return typeof a=="number"&&a<0&&r&&(r=[-r[0],-r[1],-r[2]]),{enabled:!0,direction:r,distance:ae(typeof a=="number"?Math.abs(a):void 0,0,10,.35),layer:Math.round(ae(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var ki=new Set(["__proto__","constructor","prototype"]);function at(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||ki.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function Ci(t){let e=ye(t);if(!e||e.persist===!1)return null;let i=at(e.id);return e.persist!==!0&&!i?null:i?{id:i,persist:!0}:{persist:!0}}function ho(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function co(t){let e=typeof t=="string"?{text:t}:ye(t),i=Qe(e?.text??e?.value,256);if(!e||!i)return null;let r=ae(e.size,.005,10,.12);return{text:i,size:r,depth:ae(e.depth??e.height,.001,5,r*.2),color:Vt(e.color,"#ffffff")}}function po(t){if(!t||typeof t=="number"&&!(t>0&&Number.isFinite(t)))return null;let e=t===!0?{}:typeof t=="number"?{strength:t}:ye(t);if(!e||e.enabled===!1)return null;let i=ae(e.strength??e.intensity,0,5,.35);return i>0?{enabled:!0,strength:i,threshold:ae(e.threshold,0,4,.8),radius:ae(e.radius,0,2,.5)}:null}function fo(t){if(!t)return null;let e=t===!0?{}:typeof t=="string"?{color:t}:ye(t);if(!e||e.enabled===!1)return null;let i=e.thickness??e.width;return{enabled:!0,color:Vt(e.color,"#38bdf8"),thickness:ae(typeof i=="number"&&i>0&&i<.25?Math.max(1.5,i*140):i,.5,20,3),pulse:e.pulse===!0}}function mo(t){let e=ye(t);if(!e||e.enabled===!1)return null;let i=at(e.root),r=at(e.effector);if(!i||!r)return null;let s=at(e.mid),a=e.target,o;if(st(a))o=[ae(a[0],-1e3,1e3,0),ae(a[1],-1e3,1e3,0),ae(a[2],-1e3,1e3,0)];else{let h=at(a);if(!h)return null;o=h}let n=e.pole??e.poleTarget,u=st(n)?[ae(n[0],-1e3,1e3,0),ae(n[1],-1e3,1e3,0),ae(n[2],-1e3,1e3,0)]:at(n),d=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||s?"two-bone":"fabrik";return{root:i,...s?{mid:s}:{},effector:r,target:o,...u?{pole:u}:{},solver:d,iterations:Math.round(ae(e.iterations,1,32,8)),tolerance:ae(e.tolerance,1e-5,.1,.001),weight:ae(e.weight,0,1,1)}}function go(t){if(!t)return null;let e=t===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(t)?{distances:t}:ye(t);if(!e||e.enabled===!1)return null;let i=ae(e.hysteresis,0,.5,.05),r=[],s;if(Array.isArray(e.levels)&&e.levels.length>0){let u=e.levels.slice(0,8);for(let h=0;h<u.length;h++){let l=ye(u[h]);if(!l)continue;let p=ae(l.distance,0,1e4,h===0?0:h*4),m=typeof l.hysteresis=="number"?ae(l.hysteresis,0,.5,i):void 0,y=typeof l.ratio=="number"?ae(l.ratio,.05,1,.5):void 0,x=typeof l.childIndex=="number"&&Number.isFinite(l.childIndex)?Math.max(0,Math.round(l.childIndex)):void 0,w=at(l.node);r.push({distance:p,...m!==void 0?{hysteresis:m}:{},...y!==void 0?{ratio:y}:{},...x!==void 0?{childIndex:x}:{},...w?{node:w}:{}})}r.sort((h,l)=>h.distance-l.distance),r.length>0&&r[0].distance>0&&r.unshift({distance:0,childIndex:0});let d=0;r=r.slice(0,8).map((h,l)=>{let p=l===0?0:Math.max(d,h.distance);return d=p,{...h,distance:p,childIndex:h.childIndex??l}})}if(Array.isArray(e.ratios)&&e.ratios.length>0){let u=[];for(let d of e.ratios.slice(0,7))typeof d=="number"&&u.push(ae(d,.05,1,.5));u.length>0&&(s=u)}if(r.length===0){let u=Array.isArray(e.distances)?e.distances:[],d=[];for(let l of u.slice(0,8))typeof l=="number"&&d.push(ae(l,0,1e4,4));if(d.length===0&&s&&s.length>0)for(let l=0;l<s.length;l++)d.push((l+1)*4);if(d.length===0&&e.cullDistance===void 0)return null;d.length===0||d[0]>0?d.unshift(0):s&&s.length===d.length&&s[0]===1&&(s=s.slice(1));let h=0;for(let l=0;l<Math.min(8,d.length);l++){let p=l===0?0:Math.max(h,d[l]);h=p;let m=l>0&&s?s[l-1]:void 0;r.push({distance:p,childIndex:l,...m!==void 0?{ratio:m}:{}})}}else if(!s){let u=[];for(let d=1;d<r.length;d++)typeof r[d].ratio=="number"&&u.push(r[d].ratio);u.length>0&&(s=u)}let a=r.map(u=>u.distance),o=a[a.length-1]??0,n=e.cullDistance!==void 0&&e.cullDistance!==null&&e.cullDistance!==!1?ae(e.cullDistance,Math.max(1,o),1e4,100):void 0;return{levels:r,distances:a,...s?{ratios:s}:{},hysteresis:i,...n!==void 0?{cullDistance:n}:{}}}var $r=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),yo=new Set(["capsule","cylindrical","spherical"]),Gt=[];function bo(t){Gt.includes(t)||Gt.push(t)}function Ii(t){let e=ye(t);if(!e)return null;let i=Array.isArray(e.traits)?e.traits:[],r=k=>i.includes(k),s={},a=e.grab??e.grabbable;a==="1-hand"||a==="2-hand"?s.grab=a:(a===!0||e.draggable===!0||e.movable===!0||e.interactable===!0||e.interactive===!0||r("grab"))&&(s.grab="2-hand"),s.grab&&(s.grabbable=!0);let o=e.scale??e.scalable;if(o||r("scale")){let k=ye(o)??{},K=ae(k.min,.001,1e3,.05);s.scale={min:K,max:ae(k.max,K,1e3,Math.max(K,5))},s.scalable=!0}let n=e.billboard;typeof n=="string"&&yo.has(n)?s.billboard=n:(n===!0||r("billboard"))&&(s.billboard="capsule");let u=e.follow,d=typeof u=="string"?u:ye(u)?.mode;if(typeof u=="string"?u:ye(u)?.lazy===!1)s.follow=d==="hand-left"||d==="hand-right"?d:"head";else{let k=Wa(u);k&&(s.follow=k)}let h=e.anchor??(e.floor===!0||e.ground===!0?"floor":void 0);if(typeof h=="string"&&$r.has(h))s.anchor=h;else{let k=ye(h)?.target;typeof k=="string"&&$r.has(k)&&(s.anchor=k);let K=Ci(h)??Ci(e.anchorPersist);K&&(s.anchorPersist=K)}if(!s.anchorPersist){let k=Ci(e.anchorPersist)??(s.anchor&&e.persist===!0?{persist:!0,...at(e.id)?{id:at(e.id)}:{}}:null);k&&(s.anchorPersist=k)}(e.physics==="dynamic"||e.physics==="static")&&(s.physics=e.physics);let l=qa(e.orbit??(typeof e.radius=="number"&&(typeof e.speed=="number"||e.target!==void 0)&&e.character===void 0&&e.agent===void 0&&e.zone===void 0&&e.objective===void 0&&e.snapTo===void 0&&e.snapSocket===void 0?e:void 0));l&&(s.orbit=l);let p=Xa(e.handles??e.resizable??e.scaleLimits);p&&(s.handles=p);let m=Ya(e.particles??e.emitter);m&&(s.particles=m);let y=Ja(e.holdToAsk);y&&(s.holdToAsk=y);let x=Qa(e.worldUnderstanding);x&&(s.worldUnderstanding=x);let w=oi(e.splatUrl);w&&(s.splatUrl=w),(e.splatQuality==="high"||e.splatQuality==="standard")&&(s.splatQuality=e.splatQuality);let v=Qe(e.spatialSlot);v&&(s.spatialSlot=v);let _=typeof e.audio=="string"&&Dt(e.audio.trim())?null:eo(e.audio);_&&(s.audio=_);let f=e.audioEmitter??e.spatialAudio??e.positionalAudio??e.sound??e.panner;if(f!==void 0){let k=Ur(f);k&&(s.audioEmitter=k)}else if(e.audio!==void 0){let k=ye(e.audio),K=!!(k&&("preset"in k||"type"in k||"positional"in k||"volume"in k||"gain"in k||"pitch"in k||"playbackRate"in k||"autoplay"in k||"autoPlay"in k||"distanceModel"in k||"maxDistance"in k||"rolloffFactor"in k||"coneInnerAngle"in k||"coneOuterAngle"in k||"coneOuterGain"in k||"playOnSelect"in k||"playOnTap"in k));if(!_||K){let A=Ur(e.audio);A&&(s.audioEmitter=A)}}let g=so(e.dimensions??e.measure??e.measurement??e.ruler);g&&(s.dimensions=g);let T=oo(e.snapTo??e.snap??e.magnetic);T&&(s.snapTo=T);let R=no(e.snapSocket);R&&(s.snapSocket=R);let U=lo(e.gaze??e.dwell);U&&(s.gaze=U);let j=uo(e.explode??e.exploded??e.disassemble);j&&(s.explode=j);let $=ho(e.navigable??(e.walkable!==void 0?e.walkable?"walkable":"blocked":e.teleport===!0?"walkable":void 0));$&&(s.navigable=$);let L=co(e.text??e.label??e.title??e.caption??e.spatialLabel);L&&(s.text=L);let E=po(e.bloom??e.glow);E&&(s.bloom=E);let B=fo(e.outline);B&&(s.outline=B);let I=mo(e.ik);I&&(s.ik=I);let c=go(e.lod??e.levelOfDetail??e.detail??e.decimate??e.simplify);c&&(s.lod=c),typeof e.sync=="boolean"&&(s.sync=e.sync),e.pointerEvents==="none"&&(s.pointerEvents="none");for(let k of Gt)k.normalize(e,s);return Object.keys(s).length>0?s:null}var Or=1;function Br(t){let e={schemaVersion:Or};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let i={};t.anchor&&(i.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",i.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(i.persist=t.anchorPersist.persist,t.anchorPersist.id&&(i.id=t.anchorPersist.id)),e.anchor=i}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat=t.splatQuality?{url:t.splatUrl,quality:t.splatQuality}:{url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.audioEmitter&&(e.audioEmitter={...t.audioEmitter}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),t.text&&(e.text3d={...t.text}),t.bloom&&(e.bloom={...t.bloom}),t.outline&&(e.outline={...t.outline}),t.ik&&(e.ik={...t.ik,...Array.isArray(t.ik.target)?{target:[...t.ik.target]}:{},...Array.isArray(t.ik.pole)?{pole:[...t.ik.pole]}:{}}),t.lod&&(e.lod={distances:[...t.lod.distances],...t.lod.ratios?{ratios:[...t.lod.ratios]}:{},hysteresis:t.lod.hysteresis,...t.lod.cullDistance!==void 0?{cullDistance:t.lod.cullDistance}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let i of Gt)i.sceneCore(t,e);return e}function xo(t){let e={schemaVersion:Or},i=(r,s)=>{for(let[a,o]of Object.entries(s)){let n=r+a[0].toUpperCase()+a.slice(1);typeof o=="string"||typeof o=="number"||typeof o=="boolean"?e[n]=o:st(o)&&(e[n]=[o[0],o[1],o[2]])}};t.grab&&(e.grab=t.grab),t.scale&&i("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,i("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&i("orbit",t.orbit),t.handles&&(e.handles=!0,i("handles",t.handles)),t.particles&&i("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,i("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&i("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&i("audio",t.audio),t.audioEmitter&&i("audioEmitter",t.audioEmitter),t.dimensions&&i("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,i("snapTo",t.snapTo)),t.snapSocket&&i("snapSocket",t.snapSocket),t.gaze&&i("gaze",t.gaze),t.explode&&i("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&i("text",t.text),t.bloom&&i("bloom",t.bloom),t.outline&&i("outline",t.outline),t.ik&&i("ik",t.ik),t.lod&&(e.lodEnabled=!0,e.lodHysteresis=t.lod.hysteresis,e.lodDistances=t.lod.distances.join(","),t.lod.ratios&&(e.lodRatios=t.lod.ratios.join(",")),t.lod.cullDistance!==void 0&&(e.lodCullDistance=t.lod.cullDistance)),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Gt)r.usd(t,i,e);return e}function vo(t,e){let i=Ii(e);if(!i)return;let r={...t.extras?.xr,...i};i.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,i.physics===void 0&&typeof r.physics=="object"&&delete r.physics,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:jr(i),ANDROID_xr_scenecore:Br(i)}}function jr(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function Mo(t,e){let i=Ii(t),r=[];if(!i)return r;for(let[s,a]of Object.entries(xo(i)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(s)&&(typeof a=="boolean"?r.push(`bool ${s} = ${a}`):typeof a=="number"?Number.isFinite(a)&&r.push(`double ${s} = ${a}`):typeof a=="string"?r.push(`string ${s} = "${e(a)}"`):a.length===3&&a.every(o=>Number.isFinite(o))&&r.push(`double3 ${s} = (${a.join(", ")})`));return r}function wo(){try{Object.defineProperty(Re(),"xrTraitSerializer",{value:Object.freeze({gltfNode:vo,usdLines:Mo}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var Ui=new Set(["grab","scale","billboard","follow","anchor","anchorPersist","physics","orbit","handles","particles","holdToAsk","worldUnderstanding","splatUrl","splatQuality","spatialSlot","audio","audioEmitter","spatialAudio","dimensions","snapTo","snapSocket","gaze","explode","navigable","text","bloom","outline","ik","lod","sync","pointerEvents","character","agent","integrity","zone","spawner","objective","audioCues","rigidBody","collidable","traits","schemaVersion"]),ni={rigidbody:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", mass: 1, restitution: 0.35 }' or 'physics' instead of 'rigidbody'.`},levelofdetail:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'levelOfDetail'."},detail:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'detail'."},decimate:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'decimate'."},simplify:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'simplify'."},grabbable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'grabbable'.`},draggable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'draggable'.`},movable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'movable'.`},interactable:{target:"grab",hint:"Use 'grab: true' or 'userData.interactivity' instead of 'interactable'."},scalable:{target:"scale",hint:"Use 'scale: { min: 0.05, max: 5 }' instead of 'scalable'."},resizable:{target:"handles",hint:"Use 'handles: true' or 'scale: { min, max }' instead of 'resizable'."},health:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'health'.`},hp:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'hp'.`},hitpoints:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'hitpoints'.`},damage:{target:"integrity",hint:"Use 'integrity: { contactAmount: ... }' instead of 'damage'."},team:{target:"integrity",hint:`Use 'integrity: { group: "..." }' instead of 'team'.`},faction:{target:"integrity",hint:`Use 'integrity: { group: "..." }' instead of 'faction'.`},collides:{target:"collidable",hint:`Use 'collidable: true' or 'physics: "static" | "dynamic"' instead of 'collides'.`},collider:{target:"collidable",hint:`Use 'collidable: true' or 'physics: "static" | "dynamic"' instead of 'collider'.`},solid:{target:"collidable",hint:"Use 'collidable: true' instead of 'solid'."},obstacle:{target:"collidable",hint:"Use 'collidable: true' instead of 'obstacle'."},walkable:{target:"navigable",hint:`Use 'navigable: "walkable"' instead of 'walkable'.`},floor:{target:"anchor",hint:`Use 'anchor: "floor"' or 'navigable: "walkable"' instead of 'floor'.`},ground:{target:"anchor",hint:`Use 'anchor: "floor"' or 'navigable: "walkable"' instead of 'ground'.`},teleport:{target:"navigable",hint:`Use 'navigable: "walkable"' instead of 'teleport'.`},sound:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", refDistance: 1 }' or 'audio' instead of 'sound'.`},positionalaudio:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", refDistance: 1 }' instead of 'positionalAudio'.`},panner:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", coneInnerAngle: 90 }' instead of 'panner'.`},sfx:{target:"audioCues",hint:`Use 'audioCues: { onTap: "confirm" }' instead of 'sfx'.`},measure:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measure'."},interactive:{target:"grab",hint:"Use 'grab: true' instead of 'interactive'."},scaleLimits:{target:"handles",hint:"Use 'handles: { minScale, maxScale }' instead of 'scaleLimits'."},scalelimits:{target:"handles",hint:"Use 'handles: { minScale, maxScale }' instead of 'scaleLimits'."},spatialLabel:{target:"text",hint:`Use 'text: "..."' instead of 'spatialLabel'.`},spatiallabel:{target:"text",hint:`Use 'text: "..."' instead of 'spatialLabel'.`},measurement:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measurement'."},ruler:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'ruler'."},snap:{target:"snapTo",hint:"Use 'snapTo' or 'snapSocket' instead of 'snap'."},magnetic:{target:"snapTo",hint:"Use 'snapTo' or 'snapSocket' instead of 'magnetic'."},dwell:{target:"gaze",hint:"Use 'gaze: { dwellMs: 1200 }' instead of 'dwell'."},exploded:{target:"explode",hint:"Use 'explode: { distance: 0.35, layer: 1 }' instead of 'exploded'."},disassemble:{target:"explode",hint:"Use 'explode: true' instead of 'disassemble'."},label:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'label'.`},title:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'title'.`},caption:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'caption'.`},mass:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", mass: 1 }' instead of top-level 'mass'.`},restitution:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", restitution: 0.35 }' instead of top-level 'restitution'.`},bounciness:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", restitution: 0.35 }' instead of 'bounciness'.`},friction:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", friction: 0.5 }' instead of top-level 'friction'.`},glow:{target:"bloom",hint:"Use 'bloom: { strength: 0.5 }' or 'outline' instead of 'glow'."},emissive:{target:"bloom",hint:"Use 'bloom: { strength: 0.5 }' on userData.xr or material.emissive."},ai:{target:"agent",hint:`Use 'agent: { mode: "patrol" | "chase" | "wander" }' instead of 'ai'.`},npc:{target:"agent",hint:`Use 'agent: { mode: "wander" }' instead of 'npc'.`},enemy:{target:"agent",hint:`Use 'agent: { mode: "chase" }' and 'integrity: { group: "enemy" }' instead of 'enemy'.`},bot:{target:"agent",hint:`Use 'agent: { mode: "patrol" }' instead of 'bot'.`},steering:{target:"agent",hint:"Use 'agent' instead of 'steering'."},player:{target:"character",hint:`Use 'character: { speed: 4, cameraMode: "third-person" }' instead of 'player'.`},avatar:{target:"character",hint:"Use 'character: true' instead of 'avatar'."},controller:{target:"character",hint:"Use 'character: true' instead of 'controller'."},trigger:{target:"zone",hint:`Use 'zone: { shape: "box", size: [1, 1, 1] }' instead of 'trigger'.`},hitbox:{target:"zone",hint:"Use 'zone' or 'integrity' instead of 'hitbox'."},sensor:{target:"zone",hint:"Use 'zone' instead of 'sensor'."},hazard:{target:"zone",hint:`Use 'zone: { shape: "box", watchGroups: ["player"] }' instead of 'hazard'.`},persist:{target:"anchorPersist",hint:`Use 'anchor: { target: "wall", persist: true }' or 'anchorPersist: { persist: true }' instead of top-level 'persist'.`},spawn:{target:"spawner",hint:`Use 'spawner: { template: "..." }' instead of 'spawn'.`},emitter:{target:"particles",hint:`Use 'particles: { preset: "sparks" }' or 'spawner' instead of 'emitter'.`},goal:{target:"objective",hint:`Use 'objective: { type: "pickup" | "checkpoint" }' instead of 'goal'.`},quest:{target:"objective",hint:"Use 'objective' instead of 'quest'."},collectible:{target:"objective",hint:`Use 'objective: { type: "pickup" }' instead of 'collectible'.`},pickup:{target:"objective",hint:`Use 'objective: { type: "pickup" }' instead of 'pickup'.`}};function _o(t,e){let i=t.length,r=e.length,s=Array.from({length:r+1},(a,o)=>o);for(let a=1;a<=i;a++){let o=s[0];s[0]=a;for(let n=1;n<=r;n++){let u=s[n];s[n]=t[a-1]===e[n-1]?o:1+Math.min(o,s[n],s[n-1]),o=u}}return s[r]}var Vr=null;function Gr(t){let e=t.toLowerCase(),i=null,r=4,s=Vr??(Vr=Array.from(Ui));for(let a=0;a<s.length;a++){let o=s[a];if(o==="traits")continue;let n=_o(e,o.toLowerCase());n<r&&(r=n,i=o)}return i}function To(t,e="unnamed"){let i=[];if(t==null)return i;let r=(b,O,X,te="warning")=>i.push({code:b,severity:te,node:e,message:O,hint:X}),s=ye(t);if(!s)return r("TL201",`userData.xr on node '${e}' must be a plain object.`,"Assign an object such as mesh.userData.xr = { grab: true }."),i;for(let b of Object.keys(s)){if(Ui.has(b))continue;let O=ni[b]??ni[b.toLowerCase()];if(O)r("TL201",`Unrecognized key '${b}' in userData.xr on node '${e}' (auto-normalized to '${O.target}'); did you mean '${O.target}'?`,O.hint,"info");else if((b==="radius"||b==="speed"||b==="target")&&typeof s.radius=="number"&&(typeof s.speed=="number"||s.target!==void 0)&&s.character===void 0&&s.player===void 0&&s.avatar===void 0&&s.controller===void 0)r("TL201",`Top-level '${b}' in userData.xr on node '${e}' auto-normalized to 'orbit.${b}'.`,"Use 'orbit: { target, radius, speed }' instead of top-level orbit properties.","info");else if((b==="speed"||b==="height"||b==="radius")&&(s.character!==void 0||s.player!==void 0||s.avatar!==void 0||s.controller!==void 0))r("TL201",`Top-level '${b}' in userData.xr on node '${e}' auto-normalized to 'character.${b}'.`,"Use 'character: { speed, height, radius }' instead of top-level character properties.","info");else if(b==="radius"&&(s.zone!==void 0||s.trigger!==void 0||s.hitbox!==void 0||s.sensor!==void 0||s.hazard!==void 0))r("TL201",`Top-level 'radius' in userData.xr on node '${e}' auto-normalized to 'zone.radius'.`,`Use 'zone: { shape: "sphere", radius }' instead of top-level 'radius'.`,"info");else{let X=Gr(b);r("TL201",X?`Unknown key '${b}' on node '${e}'; did you mean '${X}'?`:`Unknown key '${b}' in userData.xr on node '${e}'.`,X?`Replace '${b}' with '${X}'.`:"Supported userData.xr traits include: grab, scale, billboard, follow, anchor, physics, orbit, handles, particles, holdToAsk, audio, dimensions, snapTo, snapSocket, gaze, explode, navigable, text, bloom, outline, ik, character, agent, integrity, zone, spawner, objective, audioCues, collidable.")}}if(Array.isArray(s.traits)){for(let b of s.traits)if(typeof b=="string"&&!Ui.has(b)){let O=ni[b]??ni[b.toLowerCase()],X=O?.target??Gr(b);r("TL201",X?`Unknown trait '${b}' in userData.xr.traits on node '${e}'; did you mean '${X}'?`:`Unknown trait '${b}' in userData.xr.traits on node '${e}'.`,O?.hint??(X?`Use '${X}' instead of '${b}'.`:"Use canonical trait keys on userData.xr directly."))}}let a=(b,O,X,te)=>{if(typeof O=="number"){if(!Number.isFinite(O)){r("TL202",`Numeric trait parameter '${b}' on node '${e}' is non-finite (${O}); clamped to default.`,`Provide a finite number in [${X}, ${te}] for '${b}'.`);return}if(O<X||O>te){let re=Math.max(X,Math.min(te,O));r("TL202",`Numeric trait parameter '${b}' (${O}) on node '${e}' is out of range [${X}, ${te}]; clamped to ${re}.`,`Keep '${b}' within [${X}, ${te}].`)}}},o=ye(s.scale);if(o){a("scale.min",o.min,.001,1e3);let b=ae(o.min,.001,1e3,.05);a("scale.max",o.max,b,1e3)}let n=ye(s.follow);n&&n.lazy!==!1&&(a("follow.distance",n.distance,.1,10),a("follow.deadzoneDeg",n.deadzoneDeg,0,90),a("follow.stiffness",n.stiffness,.5,40),a("follow.height",n.height,-2,2));let u=ye(s.orbit);u&&(a("orbit.radius",u.radius,.01,50),a("orbit.speed",u.speed,-20,20),a("orbit.height",u.height,-10,10),a("orbit.phase",u.phase,-1e6,1e6));let d=ye(s.handles);if(d){a("handles.minScale",d.minScale,.001,1e3);let b=ae(d.minScale,.001,1e3,.1);a("handles.maxScale",d.maxScale,b,1e3)}let h=ye(s.particles);if(h){if(a("particles.count",h.count,1,kr),a("particles.speed",h.speed,.05,10),typeof h.area=="number")a("particles.area",h.area,.05,50);else if(Array.isArray(h.area))for(let b=0;b<Math.min(3,h.area.length);b++)a(`particles.area[${b}]`,h.area[b],.05,50)}let l=ye(s.holdToAsk);l&&a("holdToAsk.holdMs",l.holdMs,100,5e3);let p=ye(s.audio);p&&a("audio.refDistance",p.refDistance,.01,1e3);let m=ye(s.audioEmitter)??ye(s.spatialAudio)??(p&&!p.src?p:null);if(m&&m.enabled!==!1){a("audioEmitter.volume",m.volume??m.gain,0,2),a("audioEmitter.pitch",m.pitch??m.playbackRate,.25,4),a("audioEmitter.refDistance",m.refDistance,.05,100);let b=ae(m.refDistance,.05,100,1);a("audioEmitter.maxDistance",m.maxDistance,b,500),a("audioEmitter.rolloffFactor",m.rolloffFactor,0,10),a("audioEmitter.coneInnerAngle",m.coneInnerAngle,0,360);let O=ae(m.coneInnerAngle,0,360,360);a("audioEmitter.coneOuterAngle",m.coneOuterAngle,O,360),a("audioEmitter.coneOuterGain",m.coneOuterGain,0,1)}let y=ye(s.snapTo);if(y){if(a("snapTo.angleDeg",y.angleDeg,0,180),a("snapTo.radius",y.radius,.01,2),typeof y.grid=="number"&&y.grid>0)a("snapTo.grid",y.grid,.001,100);else if(Array.isArray(y.grid))for(let b=0;b<Math.min(3,y.grid.length);b++)a(`snapTo.grid[${b}]`,y.grid[b],.001,100)}let x=ye(s.snapSocket);x&&a("snapSocket.radius",x.radius,.01,2);let w=ye(s.gaze);w&&w.enabled!==!1&&a("gaze.dwellMs",w.dwellMs,250,1e4);let v=ye(s.explode);v&&v.enabled!==!1&&(a("explode.distance",v.distance,-10,10),a("explode.layer",v.layer,1,10));let _=ye(s.text);if(_&&(a("text.size",_.size,.005,10),a("text.depth",_.depth??_.height,.001,5)),typeof s.bloom=="number"&&s.bloom>0)a("bloom",s.bloom,0,5);else{let b=ye(s.bloom);b&&b.enabled!==!1&&(a("bloom.strength",b.strength??b.intensity,0,5),a("bloom.threshold",b.threshold,0,4),a("bloom.radius",b.radius,0,2))}let f=ye(s.outline);if(f&&f.enabled!==!1){let b=f.thickness??f.width;typeof b=="number"&&!(b>0&&b<.25)&&a("outline.thickness",b,.5,20)}let g=ye(s.ik);g&&g.enabled!==!1&&(a("ik.iterations",g.iterations,1,32),a("ik.tolerance",g.tolerance,1e-5,.1),a("ik.weight",g.weight,0,1));let T=ye(s.lod);if(T&&T.enabled!==!1){if(a("lod.hysteresis",T.hysteresis,0,.5),T.cullDistance!==void 0&&T.cullDistance!==null&&T.cullDistance!==!1&&a("lod.cullDistance",T.cullDistance,1,1e4),Array.isArray(T.distances)){let b=-1/0;for(let O=0;O<Math.min(8,T.distances.length);O++){let X=T.distances[O];a(`lod.distances[${O}]`,X,0,1e4),typeof X=="number"&&Number.isFinite(X)&&(X<b&&r("TL202",`lod.distances[${O}] (${X}) on node '${e}' is less than previous distance (${b}); clamped to monotonic order.`,"Sort lod.distances in non-decreasing order (e.g. [3, 8])."),b=Math.max(b,X))}}if(Array.isArray(T.ratios))for(let b=0;b<Math.min(7,T.ratios.length);b++)a(`lod.ratios[${b}]`,T.ratios[b],.05,1)}let R=ye(s.character);if(R&&R.enabled!==!1){a("character.speed",R.speed,.1,20),a("character.runMultiplier",R.runMultiplier,1,4),a("character.jumpVelocity",R.jumpVelocity,0,30),a("character.gravity",R.gravity,0,50),a("character.radius",R.radius,.05,5);let b=ae(R.radius,.05,5,.35);a("character.height",R.height,b*2,10),a("character.cameraDistance",R.cameraDistance,.5,50),a("character.cameraHeight",R.cameraHeight,-10,50)}let U=ye(s.agent);if(U&&U.enabled!==!1&&(a("agent.speed",U.speed,.1,20),a("agent.turnSpeed",U.turnSpeed,.1,50),a("agent.sightRadius",U.sightRadius,0,100),a("agent.stopDistance",U.stopDistance,.01,10),a("agent.separationRadius",U.separationRadius,0,10)),typeof s.integrity=="number")a("integrity.max",s.integrity,1,1e6);else{let b=ye(s.integrity);if(b&&b.enabled!==!1){a("integrity.max",b.max,1,1e6);let O=ae(b.max,1,1e6,100);a("integrity.current",b.current,0,O),a("integrity.cooldownMs",b.cooldownMs,0,1e4),a("integrity.scoreValue",b.scoreValue,-1e6,1e6),a("integrity.contactAmount",b.contactAmount,0,1e6)}}let j=ye(s.zone);if(j&&j.enabled!==!1){if(a("zone.radius",j.radius,.01,1e3),typeof j.size=="number")a("zone.size",j.size,.01,1e3);else if(Array.isArray(j.size))for(let b=0;b<Math.min(3,j.size.length);b++)a(`zone.size[${b}]`,j.size[b],.01,1e3)}let $=ye(s.spawner);$&&$.enabled!==!1&&(a("spawner.intervalSec",$.intervalSec,.05,3600),a("spawner.maxActive",$.maxActive,1,32),a("spawner.totalCount",$.totalCount,0,1e4),a("spawner.spawnRadius",$.spawnRadius,0,100));let L=ye(s.objective);L&&L.enabled!==!1&&(a("objective.amount",L.amount??L.points,-1e6,1e6),a("objective.radius",L.radius,.05,50),a("objective.order",L.order,0,1e3),a("objective.spinSpeed",L.spinSpeed,-50,50),a("objective.bobAmplitude",L.bobAmplitude,0,5),a("objective.respawnSec",L.respawnSec,0,3600));let E=ye(s.audioCues);E&&(a("audioCues.pitchJitter",E.pitchJitter,0,.5),a("audioCues.volume",E.volume,0,1));let B=ye(s.rigidBody)??ye(s.physics);B&&B.enabled!==!1&&(a("rigidBody.mass",B.mass,0,1e3),a("rigidBody.restitution",B.restitution,0,1),a("rigidBody.friction",B.friction,0,1),a("rigidBody.linearDamping",B.linearDamping,0,20),a("rigidBody.angularDamping",B.angularDamping,0,20),a("rigidBody.gravityScale",B.gravityScale,-5,5));let I=(b,O)=>{O!=null&&(oi(O)||r("TL203",`Unsafe or disallowed media URL in '${b}' (${JSON.stringify(O)}) on node '${e}' rejected by safeMediaUrl().`,"Use an 'https://' URL or a clean relative path without '..', '\\\\', '%', or custom schemes (e.g. http:, javascript:, file:, data:).","error"))},c=(b,O)=>{O!=null&&(at(O)||r("TL203",`Unsafe or invalid identifier in '${b}' (${JSON.stringify(O)}) on node '${e}' rejected by safeAnchorId().`,"Anchor and bone identifiers must be non-empty strings without control characters or prototype-pollution keys ('__proto__', 'constructor', 'prototype').","error"))};s.splatUrl!==void 0&&s.splatUrl!==null&&I("splatUrl",s.splatUrl),typeof s.audio=="string"?Dt(s.audio.trim())||I("audio",s.audio):p&&(p.src!==void 0?I("audio.src",p.src):p.preset===void 0&&Object.keys(p).some(b=>b.startsWith("on"))&&r("TL201",`userData.xr.audio on node '${e}' contains event keys without 'src'; did you mean 'audioCues'?`,`Use 'audioCues: { onTap: "confirm", onHit: "impact" }' for procedural synth cues, or provide 'audio: { src: "https://..." }' for spatial audio files.`));let k=s.audioEmitter??s.spatialAudio;if(typeof k=="string")Dt(k.trim())||I("audioEmitter",k);else if(m){let b=m.src??m.url??m.uri;b!==void 0&&I("audioEmitter.src",b),typeof m.preset=="string"&&!Dt(m.preset.trim())&&r("TL201",`Unknown audio preset '${m.preset}' in audioEmitter on node '${e}'.`,`Supported ambient presets: ${Cr.join(", ")}.`)}let K=(b,O)=>{if(O==null||O==="")return;let X=typeof O=="string"?O.trim():"";(!X||!/^[A-Za-z0-9_.:-]{1,64}$/.test(X)||ki.has(X))&&r("TL203",`Unsafe or invalid identifier in '${b}' (${JSON.stringify(O)}) on node '${e}' rejected by safeSimId().`,"Simulation group/tag IDs must be 1-64 characters of [A-Za-z0-9_.:-] and must not use prototype-pollution keys ('__proto__', 'constructor', 'prototype').","error")},A=ye(s.integrity);if(A&&A.group!==void 0&&K("integrity.group",A.group),j&&j.watchGroups!==void 0){let b=Array.isArray(j.watchGroups)?j.watchGroups:[j.watchGroups];for(let O=0;O<b.length;O++)K(`zone.watchGroups[${O}]`,b[O])}L&&L.tag!==void 0&&K("objective.tag",L.tag);let z=ye(s.anchor);z&&z.id!==void 0&&c("anchor.id",z.id);let S=ye(s.anchorPersist);if(S&&S.id!==void 0&&c("anchorPersist.id",S.id),g&&g.enabled!==!1){c("ik.root",g.root),c("ik.effector",g.effector),g.mid!==void 0&&c("ik.mid",g.mid),g.target!==void 0&&!Array.isArray(g.target)&&c("ik.target",g.target);let b=g.pole??g.poleTarget;b!==void 0&&!Array.isArray(b)&&c("ik.pole",b)}return i}function Fi(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!ki.has(e)?e:void 0}function li(t,e,i){return typeof t=="string"&&e.includes(t)?t:i}var So=["third-person","first-person","top-down","fixed"],Ao=["idle","walk","run","jump"];function Po(t){if(!t)return null;let e=ye(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let i=ae(e.radius,.05,5,.35),r=ye(e.clips)??{},s={};for(let a of Ao){let o=Qe(r[a],128);o&&(s[a]=o)}return{speed:ae(e.speed,.1,20,4),runMultiplier:ae(e.runMultiplier,1,4,1.6),jumpVelocity:ae(e.jumpVelocity,0,30,5.5),gravity:ae(e.gravity,0,50,15),radius:i,height:ae(e.height,i*2,10,Math.max(1.4,i*2)),cameraMode:li(e.cameraMode,So,"third-person"),cameraDistance:ae(e.cameraDistance,.5,50,3.5),cameraHeight:ae(e.cameraHeight,-10,50,1.8),clips:s}}var Do=["patrol","chase","flee","wander","follow"],No=32,$i="user";function Ro(t){if(!t)return null;let e=ye(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let i=li(e.mode,Do,"wander"),r=e.target,s=r==="camera"||r===$i?$i:Qe(r,256)??"";!s&&(i==="chase"||i==="flee"||i==="follow")&&(s=$i);let a=n=>ae(n,-1e4,1e4,0),o=Array.isArray(e.waypoints)?e.waypoints.filter(st).slice(0,No).map(n=>[a(n[0]),a(n[1]),a(n[2])]):[];return{mode:i,target:s,speed:ae(e.speed,.1,20,2),turnSpeed:ae(e.turnSpeed,.1,50,6),sightRadius:ae(e.sightRadius,0,100,6),stopDistance:ae(e.stopDistance,.01,10,.6),separationRadius:ae(e.separationRadius,0,10,.8),waypoints:o,loopWaypoints:e.loopWaypoints!==!1}}function Eo(t){if(!t)return null;let e=ye(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let i=ae(e.max,1,1e6,100);return{max:i,current:ae(e.current,0,i,i),group:Fi(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(ae(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:ae(e.scoreValue,-1e6,1e6,0),contactAmount:ae(e.contactAmount,0,1e6,0)}}var Lo=16;function zo(t){if(!t)return null;let e=ye(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let i=li(e.shape,["box","sphere"],"box"),r=e.size,s=l=>ae(l,.01,1e3,1),a=st(r)?[s(r[0]),s(r[1]),s(r[2])]:typeof r=="number"?[s(r),s(r),s(r)]:[1,1,1],o=ae(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),n=e.watchGroups,u=[...new Set((Array.isArray(n)?n:n===void 0?[]:[n]).map(Fi).filter(l=>l!==void 0))].slice(0,Lo),d={shape:i,size:a,radius:o,watchGroups:u},h=Vt(e.color,"");return h?{...d,color:h}:d}var ko=32;function Co(t){let e=ye(t)??(typeof t=="string"?{template:t}:null),i=Qe(e?.template,256)?.trim();return!e||!i||e.enabled===!1?null:{template:i,intervalSec:ae(e.intervalSec,.05,3600,3),maxActive:Math.round(ae(e.maxActive,1,ko,8)),totalCount:Math.round(ae(e.totalCount,0,1e4,0)),spawnRadius:ae(e.spawnRadius,0,100,0)}}var Io=["pickup","checkpoint","time-bonus","restore","key"];function Uo(t){if(!t)return null;let e=ye(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let i=li(e.type,Io,"pickup"),r=i==="pickup";return{type:i,amount:ae(e.amount??e.points,-1e6,1e6,10),tag:Fi(e.tag)??"",radius:ae(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(ae(e.order,0,1e3,0)),spinSpeed:ae(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:ae(e.bobAmplitude,0,5,r?.08:0),respawnSec:ae(e.respawnSec,0,3600,0)}}var Fo=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],$o=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function Oo(t){let e=ye(t);if(!e)return null;let i={};for(let r of $o){let s=e[r];typeof s=="string"&&Fo.includes(s)&&(i[r]=s)}return Object.keys(i).length===0?null:{cues:i,pitchJitter:ae(e.pitchJitter,0,.5,.08),volume:ae(e.volume,0,1,1),spatial:e.spatial!==!1}}var Hr=["dynamic","static","kinematic"],Bo=["auto","box","sphere","cylinder"];function Wr(t,e,i,r=[0,0,0]){return st(t)?[ae(t[0],e,i,r[0]),ae(t[1],e,i,r[1]),ae(t[2],e,i,r[2])]:r}function jo(t){if(t==null||t===!1)return null;if(typeof t=="string"){if(!Hr.includes(t))return null;let n=t;return{body:n,shape:"auto",mass:n==="dynamic"?1:0,restitution:.35,friction:.5,linearDamping:.05,angularDamping:.1,gravityScale:1,velocity:[0,0,0],angularVelocity:[0,0,0],lockRotation:!1}}let e=t===!0?{}:ye(t);if(!e||e.enabled===!1)return null;let i=e.body??e.type??e.mode,r=typeof i=="string"&&Hr.includes(i)?i:"dynamic",s=e.shape??e.collider,a=typeof s=="string"&&Bo.includes(s)?s:"auto",o=r==="dynamic"?ae(e.mass,.01,1e3,1):0;return{body:r,shape:a,mass:o,restitution:ae(e.restitution??e.bounciness,0,1,.35),friction:ae(e.friction,0,1,.5),linearDamping:ae(e.linearDamping??e.damping,0,20,.05),angularDamping:ae(e.angularDamping,0,20,.1),gravityScale:ae(e.gravityScale,-5,5,1),velocity:Wr(e.velocity,-200,200),angularVelocity:Wr(e.angularVelocity,-100,100),lockRotation:e.lockRotation===!0}}var Vo={normalize(t,e){let i=t.character??t.player??t.avatar??t.controller,r=i!=null&&i!==!1&&(typeof t.speed=="number"||typeof t.height=="number"||typeof t.radius=="number")?{speed:t.speed,height:t.height,radius:t.radius,...typeof i=="string"?{cameraMode:i}:typeof i=="object"?i:{}}:i,s=Po(r);s&&(e.character=s);let a=Ro(t.agent??t.ai??t.npc??t.enemy??t.bot??t.steering);a&&(e.agent=a);let o=Eo(t.integrity??t.health??t.hp??t.hitpoints);o&&(e.integrity=o);let n=t.zone??t.trigger??t.hitbox??t.sensor??t.hazard,u=n!=null&&n!==!1&&typeof t.radius=="number"?{radius:t.radius,...typeof n=="string"?{shape:n}:typeof n=="object"?n:{}}:n,d=zo(u);d&&(e.zone=d);let h=Co(t.spawner??t.spawn);h&&(e.spawner=h);let l=Uo(t.objective??t.goal??t.quest??t.collectible??t.pickup);l&&(e.objective=l);let p=Oo(t.audioCues??t.sfx);p&&(e.audioCues=p);let m=t.physics,y=typeof t.mass=="number"||typeof t.restitution=="number"||typeof t.bounciness=="number"||typeof t.friction=="number",x=t.rigidBody??t.rigidbody??(m==="kinematic"||m===!0||typeof m=="object"&&m!==null||typeof m=="string"&&y?m:m===void 0&&typeof t.mass=="number"?!0:void 0),w=y&&x!==void 0&&x!==null&&x!==!1?{mass:t.mass,restitution:t.restitution??t.bounciness,friction:t.friction,...typeof x=="string"?{body:x}:typeof x=="object"?x:{}}:x,v=jo(w);v&&(e.rigidBody=v,!e.physics&&(v.body==="dynamic"||v.body==="static")&&(e.physics=v.body)),(t.collidable===!0||t.collides===!0||t.collider===!0||t.solid===!0||t.obstacle===!0)&&(e.collidable=!0)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(i=>[...i])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.rigidBody&&(e.rigidbody={type:t.rigidBody.body,...t.rigidBody,velocity:[...t.rigidBody.velocity],angularVelocity:[...t.rigidBody.angularVelocity]}),t.collidable&&(e.collidable={enabled:!0})},usd(t,e,i){if(t.character){i.character=!0,e("character",{...t.character,clips:void 0});for(let[r,s]of Object.entries(t.character.clips))i["characterClip"+r[0].toUpperCase()+r.slice(1)]=s}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),i.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,s)=>{i[`agentWaypoint${s}`]=[r[0],r[1],r[2]]})),t.integrity&&(i.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.rigidBody&&(i.rigidBody=!0,i.physics=t.rigidBody.body,e("rigidBody",t.rigidBody)),t.collidable&&(i.collidable=!0)}};function Go(){bo(Vo)}var ot=class ra{constructor(e=0,i=0){this.x=Number(e),this.y=Number(i)}set(e,i){return this.x=Number(e),this.y=Number(i),this}clone(){return new ra(this.x,this.y)}copy(e){return this.set(e.x,e.y)}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}},ve=class sa{constructor(e=0,i=0,r=0){this.x=Number(e),this.y=Number(i),this.z=Number(r)}set(e,i,r){return this.x=Number(e),this.y=Number(i),this.z=Number(r),this}clone(){return new sa(this.x,this.y,this.z)}copy(e){return this.set(e.x,e.y,e.z)}add(e){return this.addVectors(this,e)}addVectors(e,i){return this.set(e.x+i.x,e.y+i.y,e.z+i.z)}sub(e){return this.subVectors(this,e)}subVectors(e,i){return this.set(e.x-i.x,e.y-i.y,e.z-i.z)}multiplyScalar(e){return this.set(this.x*e,this.y*e,this.z*e)}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.set(this.x+e.x*i,this.y+e.y*i,this.z+e.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5?this.multiplyScalar(1/e):this}cross(e){return this.crossVectors(this,e)}crossVectors(e,i){let r=e.x,s=e.y,a=e.z,o=i.x,n=i.y,u=i.z;return this.set(s*u-a*n,a*o-r*u,r*n-s*o)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,i){return this.lerpVectors(this,e,i)}lerpVectors(e,i,r){return this.x=e.x+(i.x-e.x)*r,this.y=e.y+(i.y-e.y)*r,this.z=e.z+(i.z-e.z)*r,this}applyMatrix4(e){let i=this.x,r=this.y,s=this.z,a=e.elements,o=1/(a[3]*i+a[7]*r+a[11]*s+a[15]);return this.x=(a[0]*i+a[4]*r+a[8]*s+a[12])*o,this.y=(a[1]*i+a[5]*r+a[9]*s+a[13])*o,this.z=(a[2]*i+a[6]*r+a[10]*s+a[14])*o,this}},qr=class{constructor(t=0,e=0,i=0,r=1){this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r)}set(t,e,i,r){return this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r),this}},Oi=class aa{constructor(e=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,i,r,s=this.order){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.order)}clone(){return new aa(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},ui=class oa{constructor(e=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,i,r,s){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.w)}clone(){return new oa(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(e,i=!0){let r=e.x,s=e.y,a=e.z,o=Math.cos(r/2),n=Math.cos(s/2),u=Math.cos(a/2),d=Math.sin(r/2),h=Math.sin(s/2),l=Math.sin(a/2);return this._x=d*n*u+o*h*l,this._y=o*h*u-d*n*l,this._z=o*n*l+d*h*u,this._w=o*n*u-d*h*l,i&&this._onChangeCallback?.(),this}setFromAxisAngle(e,i){let r=i/2,s=Math.sin(r);return this.set(e.x*s,e.y*s,e.z*s,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,i){let r=e.dot(i)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,i){let r=e.x,s=e.y,a=e.z,o=e.w,n=i.x,u=i.y,d=i.z,h=i.w;return this._x=r*h+o*n+s*d-a*u,this._y=s*h+o*u+a*n-r*d,this._z=a*h+o*d+r*u-s*n,this._w=o*h-r*n-s*u-a*d,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},pt=class na{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 na;return e.copy(this),e}compose(e,i,r){return Ti(this.elements,[i.x,i.y,i.z,i.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,i){return je(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return Jt(this.elements,[e.x,e.y,e.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let i=new ve(0,0,0),r=new ve(1,1,1);return this.compose(i,e,r)}makeTranslation(e,i,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(e,i,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Xr=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 mt(this.elements,t.elements),this}},We=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,hi=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Kr={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},nt=class la{constructor(e,i,r){this.r=1,this.g=1,this.b=1,e!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(e,i,r):this.set(e))}set(e){return typeof e=="number"?this.setHex(e):typeof e=="string"?this.setStyle(e):(e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b)),this)}setStyle(e){let i=e.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in Kr)this.setHex(Kr[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=a=>We(Math.max(0,Math.min(1,(parseFloat(a)||0)/(a.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(e,i,r){if(e=((Number(e)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let n=We(r);return this.setRGB(n,n,n)}let s=r<=.5?r*(1+i):r+i-r*i,a=2*r-s,o=n=>(n<0&&(n+=1),n>1&&(n-=1),n<1/6?a+(s-a)*6*n:n<1/2?s:n<2/3?a+(s-a)*6*(2/3-n):a);return this.setRGB(We(o(e+1/3)),We(o(e)),We(o(e-1/3)))}lerp(e,i){return this.lerpColors(this,e,i)}lerpColors(e,i,r){let s=Number(r)||0;return this.setRGB(e.r+(i.r-e.r)*s,e.g+(i.g-e.g)*s,e.b+(i.b-e.b)*s)}multiplyScalar(e){let i=Number(e)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.setRGB(We((i>>16&255)/255),We((i>>8&255)/255),We((i&255)/255))}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(We(this.r),We(this.g),We(this.b))}convertLinearToSRGB(){return this.setRGB(hi(this.r),hi(this.g),hi(this.b))}getHex(){let e=i=>Math.round(hi(Math.max(0,Math.min(1,i)))*255);return e(this.r)<<16|e(this.g)<<8|e(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.setRGB(e.r,e.g,e.b)}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new la(this.r,this.g,this.b)}},Yr={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,i)=>Math.max(e,Math.min(i,t)),lerp:(t,e,i)=>t+(e-t)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},Oe=class ua{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);if(Array.isArray(e)){let s=globalThis.__three_live_native_f32_array__;this.array=typeof s=="function"?s(e):new Float32Array(e)}else this.array=e;this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,i){return this.array[e*this.itemSize]=i,this.needsUpdate=!0,this}setY(e,i){return this.array[e*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(e,i){return this.array[e*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(e,i,r,s){let a=e*this.itemSize;return this.array[a]=i,this.array[a+1]=r,this.array[a+2]=s,this.needsUpdate=!0,this}setUsage(e){return this}clone(){let e=this.array?.constructor||Float32Array;return new ua(new e(this.array),this.itemSize)}},Zr=class extends Oe{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},Jr=class extends Oe{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},Qr=class extends Oe{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},Ie=class ha{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(e,i){return this.attributes[e]=i,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof Oe)this.index=e;else if(Array.isArray(e)){let i=globalThis.__three_live_native_index_array__;if(typeof i=="function")this.index=new Oe(i(e),1);else{let r=0;for(let s of e)s>r&&(r=s);this.index=new Oe(new(r>65535?Uint32Array:Uint16Array)(e),1)}}else e&&e.buffer&&(this.index=new Oe(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=globalThis.__three_live_native_compute_vertex_normals__;if(typeof i=="function"){let u=i(e.array,this.index?.array);return this.setAttribute("normal",new Oe(u,3)),this}let r=e.count,s=e.array,a=new Float32Array(r*3),o=this.index?.array,n=o?o.length:r;for(let u=0;u<n;u+=3){let d=(o?o[u]:u)*3,h=(o?o[u+1]:u+1)*3,l=(o?o[u+2]:u+2)*3,p=s[h],m=s[h+1],y=s[h+2],x=s[l]-p,w=s[l+1]-m,v=s[l+2]-y,_=s[d]-p,f=s[d+1]-m,g=s[d+2]-y,T=w*g-v*f,R=v*_-x*g,U=x*f-w*_;a[d]+=T,a[d+1]+=R,a[d+2]+=U,a[h]+=T,a[h+1]+=R,a[h+2]+=U,a[l]+=T,a[l+1]+=R,a[l+2]+=U}for(let u=0;u<r*3;u+=3){let d=a[u],h=a[u+1],l=a[u+2],p=Math.hypot(d,h,l)||1;a[u]=d/p,a[u+1]=h/p,a[u+2]=l/p}return this.setAttribute("normal",new Oe(a,3)),this}setFromBuffers(e,i,r,s){this.setAttribute("position",new Oe(e,3)),this.setAttribute("normal",new Oe(i,3)),this.setAttribute("uv",new Oe(r,2)),this.setIndex(s)}setFromPoints(e){let i=[];if(Array.isArray(e))for(let r of e)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new Oe(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new ve(1/0,1/0,1/0),r=new ve(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let s=0;s<e.count;s++){let a=e.getX(s),o=e.getY(s),n=e.getZ(s);a<i.x&&(i.x=a),o<i.y&&(i.y=o),n<i.z&&(i.z=n),a>r.x&&(r.x=a),o>r.y&&(r.y=o),n>r.z&&(r.z=n)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return this.translate(-(e.min.x+e.max.x)*.5,-(e.min.y+e.max.y)*.5,-(e.min.z+e.max.z)*.5)}_xform(e,i){let r=this.attributes.position;if(r){let s=r.array;for(let a=0;a<s.length;a+=3)e(s,a);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(e=0,i=0,r=0){return this._xform((s,a)=>{s[a]+=e,s[a+1]+=i,s[a+2]+=r})}scale(e=1,i=1,r=1){return this._xform((s,a)=>{s[a]*=e,s[a+1]*=i,s[a+2]*=r},!0)}_rot(e,i,r){let s=Math.cos(r),a=Math.sin(r);for(let o of[this.attributes.position,this.attributes.normal]){if(!o)continue;let n=o.array;for(let u=0;u<n.length;u+=3){let d=n[u+e],h=n[u+i];n[u+e]=d*s-h*a,n[u+i]=d*a+h*s}o.needsUpdate=!0}return this}rotateX(e){return this._rot(1,2,e)}rotateY(e){return this._rot(2,0,e)}rotateZ(e){return this._rot(0,1,e)}applyMatrix4(e){let i=this.attributes.position;if(i&&e?.elements){let r=new ve;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(e),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let e=new ha;e.name=this.name;for(let i of Object.keys(this.attributes))e.attributes[i]=this.attributes[i].clone();return this.index&&(e.index=this.index.clone()),e}dispose(){}},Bi=class extends Ie{constructor(t=1,e=1,i=1){super();{let h=globalThis.__three_live_native_box__;if(typeof h=="function"){let l=h(t,e,i);this.setFromBuffers(l.positions,l.normals,l.uvs,l.indices);return}}let r=t/2,s=e/2,a=i/2,o=[-r,-s,a,r,-s,a,r,s,a,-r,s,a,r,-s,-a,-r,-s,-a,-r,s,-a,r,s,-a,-r,s,a,r,s,a,r,s,-a,-r,s,-a,-r,-s,-a,r,-s,-a,r,-s,a,-r,-s,a,r,-s,a,r,-s,-a,r,s,-a,r,s,a,-r,-s,-a,-r,-s,a,-r,s,a,-r,s,-a],n=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],u=[],d=[];for(let h=0;h<6;h++){let l=h*4;u.push(0,0,1,0,1,1,0,1),d.push(l,l+1,l+2,l,l+2,l+3)}this.setFromBuffers(o,n,u,d)}},es=class extends Ie{constructor(t=1,e=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));{let u=globalThis.__three_live_native_plane__;if(typeof u=="function"){let d=u(t,e,i,r);this.setFromBuffers(d.positions,d.normals,d.uvs,d.indices);return}}let s=[],a=[],o=[],n=[];for(let u=0;u<=r;u++){let d=u/r;for(let h=0;h<=i;h++){let l=h/i;if(s.push((l-.5)*t,(.5-d)*e,0),a.push(0,0,1),o.push(l,1-d),u>0&&h>0){let p=(i+1)*u+h-1,m=p-(i+1);n.push(m,p,m+1,p,p+1,m+1)}}}this.setFromBuffers(s,a,o,n)}},ts=class extends Ie{constructor(t=1,e=16,i=12,r=0,s=Math.PI*2,a=0,o=Math.PI){if(super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i)),!r&&!a&&Math.abs(s-Math.PI*2)<1e-4&&Math.abs(o-Math.PI)<1e-4){let p=globalThis.__three_live_native_sphere__;if(typeof p=="function"){let m=p(t,e,i);this.setFromBuffers(m.positions,m.normals,m.uvs,m.indices);return}}let n=[],u=[],d=[],h=[],l=Math.min(a+o,Math.PI);for(let p=0;p<=i;p++){let m=p/i,y=a+m*o;for(let x=0;x<=e;x++){let w=x/e,v=r+w*s,_=-Math.cos(v)*Math.sin(y),f=Math.cos(y),g=Math.sin(v)*Math.sin(y);if(n.push(t*_,t*f,t*g),u.push(_,f,g),d.push(w,1-m),p>0&&x>0){let T=(e+1)*p+x,R=T-(e+1),U=R-1,j=T-1;(p!==1||a>0)&&h.push(R,U,T),(p!==i||l<Math.PI)&&h.push(U,j,T)}}}this.setFromBuffers(n,u,d,h)}},ji=class extends Ie{constructor(t=1,e=1,i=1,r=16,s=1,a=!1,o=0,n=Math.PI*2){if(super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1)),s===1&&!a&&!o&&Math.abs(n-Math.PI*2)<1e-4){let w=globalThis.__three_live_native_cylinder__;if(typeof w=="function"){let v=w(t,e,i,r);this.setFromBuffers(v.positions,v.normals,v.uvs,v.indices);return}}let u=[],d=[],h=[],l=[],p=i/2,m=(e-t)/(i||1),y=r+1;for(let w=0;w<=s;w++){let v=w/s,_=v*(e-t)+t,f=p-v*i;for(let g=0;g<=r;g++){let T=g/r,R=o+T*n,U=Math.sin(R),j=Math.cos(R),$=Math.hypot(U,m,j)||1;if(u.push(_*U,f,_*j),d.push(U/$,m/$,j/$),h.push(T,1-v),w<s&&g<r){let L=w*y+g,E=L+y;l.push(L,E,L+1,E,E+1,L+1)}}}let x=(w,v)=>{if(a||w<=0)return;let _=v*p,f=u.length/3;u.push(0,_,0),d.push(0,v,0),h.push(.5,.5);let g=f+1;for(let T=0;T<=r;T++){let R=o+T/r*n,U=Math.sin(R),j=Math.cos(R);u.push(w*U,_,w*j),d.push(0,v,0),h.push(j*.5+.5,.5+v*U*.5),T<r&&l.push(f,g+T+(v>0?0:1),g+T+(v>0?1:0))}};x(t,1),x(e,-1),this.setFromBuffers(u,d,h,l)}},is=class extends ji{constructor(t=1,e=1,i=16,r=1,s=!1,a=0,o=Math.PI*2){super(0,t,e,i,r,s,a,o)}},rs=class extends Ie{constructor(t=1,e=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));{let d=globalThis.__three_live_native_torus__;if(typeof d=="function"){let h=d(t,e,i,r,s);this.setFromBuffers(h.positions,h.normals,h.uvs,h.indices);return}}let a=[],o=[],n=[],u=[];for(let d=0;d<=i;d++){let h=d/i*Math.PI*2,l=Math.cos(h),p=Math.sin(h);for(let m=0;m<=r;m++){let y=m/r*s,x=Math.cos(y),w=Math.sin(y);if(a.push((t+e*l)*x,(t+e*l)*w,e*p),o.push(l*x,l*w,p),n.push(m/r,d/i),d>0&&m>0){let v=(r+1)*d+m-1,_=v-(r+1);u.push(v,_,v+1,_,_+1,v+1)}}}this.setFromBuffers(a,o,n,u)}};function ss(t,e,i,r,s){let a=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),o=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),n=Number(r)||.1,u=[],d=[],h=[],l=[],p=[],m=new ve,y=new ve,x=new ve;for(let v=0;v<=a;v++){let _=new ve;s(v/a,_),p.push(_)}let w=o+1;for(let v=0;v<=a;v++){let _=v/a,f=p[v];m.subVectors(p[Math.min(a,v+1)],p[Math.max(0,v-1)]).normalize(),v===0&&y.set(Math.abs(m.y)>.9?1:0,Math.abs(m.y)>.9?0:1,0),x.crossVectors(m,y).normalize(),y.crossVectors(x,m).normalize();for(let g=0;g<=o;g++){let T=g/o*Math.PI*2,R=-Math.cos(T),U=Math.sin(T),j=R*y.x+U*x.x,$=R*y.y+U*x.y,L=R*y.z+U*x.z;if(u.push(f.x+n*j,f.y+n*$,f.z+n*L),d.push(j,$,L),h.push(_,g/o),v>0&&g>0){let E=w*(v-1)+g-1,B=E+w;l.push(E,B,E+1,B,B+1,E+1)}}}t.setFromBuffers(u,d,h,l)}var as=class extends Ie{constructor(t=1,e=.4,i=64,r=8,s=2,a=3){super(),i=Math.floor(i),r=Math.floor(r);{let o=globalThis.__three_live_native_torus_knot__;if(typeof o=="function"){let n=o(t,e,i,r,s,a);this.setFromBuffers(n.positions,n.normals,n.uvs,n.indices);return}}ss(this,i,r,e,(o,n)=>{let u=o*s*Math.PI*2,d=a/s*u,h=t*(2+Math.cos(d))*.5;n.set(h*Math.cos(u),h*Math.sin(u),t*Math.sin(d)*.5)})}},Mt=class{getPoint(t,e=new ve){return e}getPointAt(t,e=new ve){return this.getPoint(t,e)}getTangent(t,e=new ve){return e.subVectors(this.getPoint(Math.min(1,t+.001)),this.getPoint(Math.max(0,t-.001))).normalize()}getPoints(t=5){let e=Math.max(1,Math.min(512,Math.floor(Number(t)||5))),i=[];for(let r=0;r<=e;r++)i.push(this.getPoint(r/e));return i}getSpacedPoints(t=5){return this.getPoints(t)}},os=class extends Mt{constructor(t=new ve,e=new ve){super(),this.v1=t,this.v2=e}getPoint(t,e=new ve){return e.lerpVectors(this.v1,this.v2,t)}},ns=class extends Mt{constructor(t=new ve,e=new ve,i=new ve){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new ve){return e.lerpVectors(this.v0,this.v1,t).lerp(new ve().lerpVectors(this.v1,this.v2,t),t)}},ls=class extends Mt{constructor(t=new ve,e=new ve,i=new ve,r=new ve){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new ve){let i=new ve().lerpVectors(this.v0,this.v1,t),r=new ve().lerpVectors(this.v1,this.v2,t),s=new ve().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(s,t),t)}},us=class extends Mt{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new ve){let i=this.points,r=i.length;if(!r)return e.set(0,0,0);if(r===1)return e.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(t)||0)),a=Math.floor(s),o=s-a;!this.closed&&a>=r-1&&(a=r-2,o=1);let n=x=>i[this.closed?(x%r+r)%r:Math.max(0,Math.min(r-1,x))],u=n(a-1),d=n(a),h=n(a+1),l=n(a+2),p=o*o,m=p*o,y=(x,w,v,_)=>.5*(2*w+(v-x)*o+(2*x-5*w+4*v-_)*p+(3*w-x-3*v+_)*m);return e.set(y(u.x,d.x,h.x,l.x),y(u.y,d.y,h.y,l.y),y(u.z,d.z,h.z,l.z))}},Vi=class extends Ie{constructor(t=[new ot(0,-.5),new ot(.5,0),new ot(0,.5)],e=12,i=0,r=Math.PI*2){super();let s=Array.isArray(t)&&t.length>=2?t:[new ot(.2,0),new ot(.2,.5)],a=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),o=[],n=[],u=[],d=[],h=s.length;for(let l=0;l<=a;l++){let p=l/a,m=i+p*r,y=Math.sin(m),x=Math.cos(m),w=l*h;for(let v=0;v<h;v++){let _=s[v],f=Number(_?.x)||0,g=Number(_?.y)||0;o.push(f*y,g,f*x);let T=s[Math.max(0,v-1)],R=s[Math.min(h-1,v+1)],U=(Number(R?.x)||0)-(Number(T?.x)||0),j=(Number(R?.y)||0)-(Number(T?.y)||0),$=Math.hypot(j,U)||1;if(n.push(j/$*y,-U/$,j/$*x),u.push(p,v/(h-1)),l<a&&v<h-1){let L=w+v,E=L+h;d.push(L,E,L+1,E,E+1,L+1)}}}this.setFromBuffers(o,n,u,d)}},hs=class extends Ie{constructor(t,e=64,i=1,r=8,s=!1){super(),ss(this,e,r,i,(a,o)=>{let n=t?.getPointAt??t?.getPoint;if(typeof n=="function"){let u=n.call(t,a,o);u&&u!==o&&o.copy(u)}else o.set(0,a,0)})}},ci="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",di=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new ot(1,1),this.offset=new ot(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},cs=class extends di{constructor(t=null,e=1,i=1,r=1023,s=1009,a,o=1001,n=1001,u=1003,d=1003,h=1,l=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let p=Number(e),m=Number(i),y=t&&typeof t.length=="number"?t:null;this.width=p,this.height=m,this.image={data:y,width:p,height:m},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(o)||1001,this.wrapT=Number(n)||1001,this.magFilter=Number(u)||1003,this.minFilter=Number(d)||1003,this.colorSpace=l||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(t){t&&this._bake()}_bake(){let t=this.image,e=t?.data,i=Number(t?.width??this.width),r=Number(t?.height??this.height);if(!e||!e.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),a=Math.max(1,r|0),o=s*a,n=this.format,u=n===1021||n===1024||n===1028||e.length===o?1:n===1025||n===1030||e.length===o*2?2:n===1022||e.length===o*3?3:4,d=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,h=Math.min(s,48),l=Math.min(a,48),p=(this.flipY?257:1)^this.colorSpace.length^e.length,m=Math.max(1,e.length>>6|0);for(let B=0;B<e.length;B+=m)p=Math.imul(p^(e[B]*256|0),16777619)|0;if(p===this._sig&&this.source)return;this._sig=p;let y=l*(1+h*4),x=new Uint8Array(68+y),w=new DataView(x.buffer);w.setUint32(0,2303741511),w.setUint32(4,218765834),w.setUint32(8,13),w.setUint32(12,1229472850),w.setUint32(16,h),w.setUint32(20,l),x[24]=8,x[25]=6,w.setUint32(29,Li(x.subarray(12,29))),w.setUint32(33,y+11),w.setUint32(37,1229209940),x[41]=120,x[42]=1,x[43]=1,w.setUint16(44,y,!0),w.setUint16(46,~y&65535,!0);let v=48,_=1,f=0,g=0,T=0,R=0,U=0,j=B=>{if(!Number.isFinite(B))return 0;let I=d&&B<=1?B*255:B;return I>0?I<255?I+.5|0:255:0};for(let B=0;B<l;B++){let I=B*a/l|0,c=this.flipY?a-1-I:I;x[v++]=0,f+=_;for(let k=0;k<h;k++){let K=(c*s+(k*s/h|0))*u,A=n===1021?255:j(e[K]??0),z=u>=3||n===1030?j(e[K+1]??0):A,S=u>=3?j(e[K+2]??0):n===1030?0:A,b=u===4?j(e[K+3]??255):n===1021?j(e[K]??255):n===1025?j(e[K+1]??255):255;x[v++]=A,_+=A,f+=_,x[v++]=z,_+=z,f+=_,x[v++]=S,_+=S,f+=_,x[v++]=b,_+=b,f+=_,g+=A,T+=z,R+=S,U+=b}_%=65521,f%=65521}w.setUint32(v,(f<<16|_)>>>0),w.setUint32(v+4,Li(x.subarray(37,v+4))),w.setUint32(v+12,1229278788),w.setUint32(v+16,2923585666);let $=h*l*255,L=this.colorSpace==="srgb-linear";this.avgColor=[L?g/$:We(g/$),L?T/$:We(T/$),L?R/$:We(R/$),U/$];let E=["data:image/png;base64,"];for(let B=0;B<x.length;B+=3){let I=x[B]<<16|(x[B+1]??0)<<8|(x[B+2]??0);E.push(ci[I>>18&63]+ci[I>>12&63]+(B+1<x.length?ci[I>>6&63]:"=")+(B+2<x.length?ci[I&63]:"="))}this.source=E.join("")}},ds=class{load(t,e){let i=new di(t);return e?.(i),i}};function Ge(t,e){return t!==void 0?Number(t):e}function Gi(t,e){return t!==void 0?!!t:e}var Xe=class{constructor(t={}){this.name=t.name||"",this.color=new nt(t.color??16777215),this.emissive=new nt(t.emissive??0),this.emissiveIntensity=Ge(t.emissiveIntensity,1),this.roughness=Ge(t.roughness,.5),this.metalness=Ge(t.metalness,0),this.opacity=Ge(t.opacity,1),this.transparent=Gi(t.transparent,!1),this.wireframe=Gi(t.wireframe,!1),this.side=Ge(t.side,2),this.doubleSided=Gi(t.doubleSided,!0),this.map=t.map||null;for(let e of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])t[e]&&(this[e]=t[e]);this.clearcoat=Ge(t.clearcoat,0),this.clearcoatRoughness=Ge(t.clearcoatRoughness,0),this.sheen=Ge(t.sheen,0),this.sheenColor=new nt(t.sheenColor??0),this.sheenRoughness=Ge(t.sheenRoughness,0),this.transmission=Ge(t.transmission,0),this.thickness=Ge(t.thickness,0),this.attenuationColor=new nt(t.attenuationColor??16777215),this.attenuationDistance=Ge(t.attenuationDistance,1/0),this.ior=Ge(t.ior,1.5),this.dispersion=Ge(t.dispersion,0),this.iridescence=Ge(t.iridescence,0),this.iridescenceIOR=Ge(t.iridescenceIOR,1.3)}dispose(){}},Nt=class extends Xe{},ps=class extends Xe{},fs=class extends Xe{},ms=class extends Xe{},gs=class extends Xe{},Ye=class ca{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 ve,this.rotation=new Oi,this.quaternion=new ui,this.scale=new ve(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,i=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),s=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(i,r,s)})}add(...e){for(let i of e)i&&i instanceof ca&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...e){for(let i of e){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(e){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),e(s);let a=s.children;if(Array.isArray(a))for(let o=a.length-1;o>=0;o--)r.push(a[o])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){this.traverse(i=>{Hi(i),(i.matrixAutoUpdate||e)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(e,i,r){let s=typeof e=="object"?e:new ve(e,i,r);this.target instanceof ve?this.target.copy(s):this.target?.position instanceof ve&&this.target.position.copy(s),this.updateMatrixWorld(!0);let a=new pt;a.lookAt(this.position,s,new ve(0,1,0));let o=a.elements,n=o[0],u=o[4],d=o[8],h=o[1],l=o[5],p=o[9],m=o[2],y=o[6],x=o[10],w=n+l+x;if(w>0){let v=.5/Math.sqrt(w+1);this.quaternion.set((y-p)*v,(d-m)*v,(h-u)*v,.25/v)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new pt().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new ve(1,0,0),e)}translateY(e){return this.translateOnAxis(new ve(0,1,0),e)}translateZ(e){return this.translateOnAxis(new ve(0,0,1),e)}rotateX(e){return this.rotation.x+=e,this}rotateY(e){return this.rotation.y+=e,this}rotateZ(e){return this.rotation.z+=e,this}_chain(){let e=[];for(let i=this;i&&e.length<64;i=i.parent)e.push(i);return e}_syncWorld(){let e=this._chain();for(let i=e.length-1;i>=0;i--){let r=e[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(e=new ve){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new ve){let i=this._syncWorld();return e.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(e=new ve){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new ui){let i=this._chain();e.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)e.multiply(i[r].quaternion);return e}clone(e=!0){let i=this instanceof zt?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof yt?new yt(this.geometry,this.material):new this.constructor;i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,i.castShadow=this.castShadow,i.receiveShadow=this.receiveShadow;try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(e)for(let r of this.children)i.add(r.clone(!0));return i}},ys=class extends Ye{},yt=class extends Ye{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof Ie?t:t?(vt("unsupported geometry","BoxGeometry"),new Bi(.5,.5,.5)):new Ie,this.material=i instanceof Xe?i:i?(vt("unsupported material","MeshStandardMaterial"),new Nt({color:13421772})):new Nt}};function Hi(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=Re().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var Ht=1e4,pi=class extends yt{constructor(t,e,i=1){super(t,e),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>Ht)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Ht})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let a=0;a<this.count;a++){let o=a*16;s[o]=1,s[o+5]=1,s[o+10]=1,s[o+15]=1}this.instanceMatrix=new Oe(s,16)}setMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let a=0;a<16;a++){let o=Number(e.elements[a]);r[s+a]=Number.isFinite(o)?o:a%5===0?1:0}}getMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let a=0;a<16;a++)e.elements[a]=r[s+a]}setColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let a=new Float32Array(this.count*3);a.fill(1),this.instanceColor=new Oe(a,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(e.r)?e.r:1,r[s+1]=Number.isFinite(e.g)?e.g:1,r[s+2]=Number.isFinite(e.b)?e.b:1}getColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){e.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;e.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Rt=class extends Ye{constructor(t=16777215,e=1){super(),this.color=new nt(t),this.intensity=Number(e),this.type="directional"}},Wi=class extends Rt{constructor(t,e){super(t,e),this.type="ambient"}},qi=class extends Rt{constructor(t,e){super(t,e),this.target=new Ye,this.type="directional"}},fi=class extends Rt{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},Xi=class extends Ye{},mi=class extends Xi{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new ve(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},Wt=class extends Ye{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return bt.validate(this),jt(this)}toGLB(){return bt.validate(this),ei(this)}toUSDZ(){return bt.validate(this),ai(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof yt){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},Ki=jt,Yi=ei,bs=ai,bt=class{static validate(t){let e=0,i=0,r=0,s=new Set,a=(n,u,d)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${n} (${u}). Found: ${d}`)},o=(n,u)=>{if(!Number.isFinite(u))throw new Error(`SecurityError: Scene reports a non-finite ${n} count (${String(u)}), which cannot be bounds-checked.`);return u};t.traverse(n=>{if(Hi(n),n instanceof yt||n.geometry?.attributes?.position?.count){if(r++,r>1e3&&a("MESHES",1e3,r),n instanceof pi){let d=o("instance",n.count);(d<0||d>Ht)&&a("INSTANCES",Ht,d)}let u=n.geometry;if(u){let d=0;if(u.attributes.position&&(d=o("vertex",u.attributes.position.count),e+=d,e>1e5&&a("VERTICES",1e5,e)),u.index){let h=o("index",u.index.count);i+=h,i>3e5&&a("INDICES",3e5,i);let l=u.index.array;if(l&&d>0){let p=Math.min(h,l.length);for(let m=0;m<p;m++){let y=l[m];if(!Number.isFinite(y)||y<0||y>=d)throw new Error(`SecurityError: Index buffer value (${String(y)}) out of vertex bounds [0, ${d}).`)}}}}if(n.material){let d=n.material;for(let h of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])d[h]&&s.add(d[h])}}}),s.size>16&&a("TEXTURES",16,s.size);for(let n of s){let u=n,d=u.image,h=Number(d?.width??u.width??0)||0,l=Number(d?.height??u.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(l)||h>2048||l>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(h,l))}}},xs=class{constructor(t={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let e=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||e,this.containerId=t.containerId||""}setSize(t,e){return this}setPixelRatio(t){return this}setClearColor(t,e=1){let i=new nt(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,e),this}clear(){return this}dispose(){}render(t,e){if(this.isSandboxed){bt.validate(t);let r=(s,a)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(a&&a.length?self.postMessage(s,a):self.postMessage(s))};if(this.hasInitialModelRendered){let s=t.getMeshTransforms(),a={};for(let[o,n]of s.entries())a[o]=Array.from(n);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let s=Ki(t),a=Yi(t),o=(s.lights||[]).map(n=>({type:n.type,color:n.color,intensity:n.intensity,position:n.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:o,camera:e?{fov:e.fov||60,position:[e.position.x,e.position.y,e.position.z]}:void 0},[a.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(t.getMeshTransforms()):(i.loadModel(t.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function vs(){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 Ms=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=vs(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let e=vs();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function Ho(){}var Et=new Proxy(Ho,{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:Et},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Et,construct:()=>Et}),ws=(()=>{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 gi(){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 i=t.trim();if(!i)return!1;try{let r=new URL(i,gi());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 _s,qt;function Ts(t){if(!Lt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let e=globalThis.trustedTypes;if(!e||typeof e.createPolicy!="function")return t;if(qt===void 0||_s!==e){_s=e;try{qt=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Lt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{qt=null}}return qt?qt.createScriptURL(t):t}function Wo(t){Re().sandboxEngineSrc=t}function Zi(){let t=Re().sandboxEngineSrc;if(t)return t;if(ws)return ws;try{if(typeof document>"u")return null;let e=gi(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let a=new URL(s,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(a)&&Lt(s,{requireSameOrigin:!0}))return s}}catch{}return null}function Ji(t,e){if(!Lt(t))throw new Error(`SecurityError: Refusing to load ${e} from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,gi()).href}function qo(){let t=Zi();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.");return Ji(t,"sandbox engine")}function Xo(t){Re().sandboxIframeSrc=t}function Ss(){let t=Re().sandboxIframeSrc;if(t)return t;let e=Zi();if(!e||!Lt(e))return null;let i=new URL(e,gi());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function Ko(){let t=Ss();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.");return Ji(t,"sandbox iframe")}function Yo(t){Re().allowClientScripts=t}function As(){return!!Re().allowClientScripts}function Zo(t){return Ji(t,"procedural scene script")}var Jo=["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 Qo(t,e){let i=self,r=t.nonce,s=t.engineSrc,a=t.allowedScriptUrl,o=t.allowClientScripts,n=t.revoked,u=i.postMessage.bind(i);function d(f){u({type:"ERROR",nonce:r,message:String(f)})}let h=typeof i.importScripts=="function"?i.importScripts.bind(i):null,l=a,p=null;try{let f=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let g={createScriptURL:function(R){if(R!==s&&(!a||R!==a))throw new TypeError("Disallowed worker importScripts URL");return R}};o&&(g.createScript=function(R){return String(R)});let T=i.trustedTypes.createPolicy("three-live#worker-boot",g);f=T.createScriptURL(s),a&&(l=T.createScriptURL(a)),o&&typeof T.createScript=="function"&&(p=T.createScript.bind(T))}catch{}h(f)}catch(f){d('Sandbox failed to load the Three-Live engine from "'+s+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(f&&f.message||f));return}let m=i.THREE;if(!m||typeof m.Scene!="function"){d('Sandbox loaded "'+s+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(e)){let f=i.__THREE_LIVE_REGISTRY__;for(let g=0;g<e.length;g++)if(typeof e[g]=="function")try{e[g](m,f)}catch{}}function y(f,g,T){let R=i;for(;R&&R!==Object.prototype;){if(!T&&R!==i)try{delete R[f]}catch{}if(!T||R===i||Object.prototype.hasOwnProperty.call(R,f))try{Object.defineProperty(R,f,T?{value:g,writable:!1,configurable:!1}:{value:g,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}for(let f=0;f<n.length;f++)y(n[f],void 0);y("performance",Object.freeze({now:function(){return Date.now()}}));let x=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],w=!1;function v(f,g){if(f.type==="3D_MODEL_READY"){if(w)return;w=!0}f.nonce=r,g&&g.length?u(f,g):u(f)}y("postMessage",function(f,g){if(!f||x.indexOf(f.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+x.join(", ")+").");v(f,g)},!0);let _=!1;i.onmessage=function(f){let g=f&&f.data;if(!(!g||g.nonce!==r)&&!(g.type!=="EXECUTE"&&g.type!=="EXECUTE_URL")&&!_){_=!0;try{let T=new m.Scene,R=new m.PerspectiveCamera(60,1,.1,1e3),U=new m.WebGLRenderer({isSandboxed:!0});if(g.type==="EXECUTE_URL"){if(!a||g.scriptUrl!==a||typeof h!="function"){d("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let j=l||a,$=h;if(h=null,l=null,i.THREE=m,i.scene=T,i.camera=R,i.renderer=U,$(j),typeof i.__THREE_LIVE_SCENE__=="function"){let L=i.__THREE_LIVE_SCENE__(m,T,R,U);L&&typeof L.toGLB=="function"&&(T=L)}else i.scene&&typeof i.scene.toGLB=="function"&&(T=i.scene)}else{if(!o){d("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let j=p?(0,eval)(p(`(function (THREE, scene, camera, renderer) {
|
|
366
|
+
`,surfaceConnections:b,surfaceInputsUsda:T,usesTime:r.usesTime}}function Ce(t,e,i,r){let s=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(i,s))}function ai(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function Ge(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function yi(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function hl(t){let e=Ge(t);if(!e||e.lazy===!1)return null;let i=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=i!=="head";return{mode:i,lazy:!0,distance:Ce(e.distance,.1,10,r?.15:1),deadzoneDeg:Ce(e.deadzoneDeg,0,90,r?0:15),stiffness:Ce(e.stiffness,.5,40,6),height:Ce(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function ul(t){let e=Ge(t);if(!e)return null;let i=e.target;return{target:ai(i)?[i[0],i[1],i[2]]:typeof i=="string"&&i.length>0&&i.length<=256?i:[0,0,0],radius:Ce(e.radius,.01,50,.5),speed:Ce(e.speed,-20,20,.5),height:Ce(e.height,-10,10,0),phase:Ce(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function cl(t){if(!t)return null;let e=Ge(t)??{},i=Ce(e.minScale??e.min,.001,1e3,.1),r=Ce(e.maxScale??e.max,i,1e3,Math.max(i,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:i,maxScale:r}}var As=2e3,fl={rain:600,snow:400,sparks:300,confetti:300};function pl(t){let e=Ge(t);if(!e)return null;let i=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,s=f=>Ce(f,.05,50,2),a=ai(r)?[s(r[0]),s(r[1]),s(r[2])]:typeof r=="number"?[s(r),s(r),s(r)]:[2,2,2];return{preset:i,count:Math.round(Ce(e.count,1,As,fl[i])),area:a,speed:Ce(e.speed,.05,10,1)}}var ml=4e3;function dl(t){if(!t)return null;let e=Ge(t)??{};return{prompt:yi(e.prompt,ml)??"What is this?",holdMs:Ce(e.holdMs,100,5e3,600)}}function gl(t){if(!t)return null;let e=Ge(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function Dr(t){let e=yi(t,4096)?.trim();if(!(!e||/[\x00-\x20\\%]/.test(e))){if(/^https:\/\/[^/]/i.test(e))return e;if(!(e.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)))return e.split(/[/?#]/).includes("..")?void 0:e}}function yl(t){let e=typeof t=="string"?{src:t}:Ge(t),i=Dr(e?.src);return!e||!i?null:{src:i,refDistance:Ce(e.refDistance,.01,1e3,1),loop:e.loop===!0}}var Ts=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],bl=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Ns=new Set(Ts),xl=new Set(bl);function qi(t){return!!(t&&(Ns.has(t)||xl.has(t)))}function Cs(t){if(!t)return null;let e=null;if(typeof t=="string"){let T=t.trim();if(!T)return null;e=qi(T)?{preset:T}:{src:T}}else e=Ge(t);if(!e||e.enabled===!1)return null;let i=yi(e.preset,32)?.trim(),r=qi(i)?i:void 0,s=Dr(e.src??e.url??e.uri);if(!r&&!s)return null;let a=!r||Ns.has(r),f=e.type==="global"||e.positional===!1?"global":"positional",c=Ce(e.volume??e.gain,0,2,.6),h=Ce(e.pitch??e.playbackRate,.25,4,1),C=typeof e.loop=="boolean"?e.loop:a,d=typeof e.autoplay=="boolean"?e.autoplay:typeof e.autoPlay=="boolean"?e.autoPlay:!0,p=e.distanceModel==="linear"||e.distanceModel==="exponential"?e.distanceModel:"inverse",m=Ce(e.refDistance,.05,100,1),y=Ce(e.maxDistance,m,500,Math.max(m,25)),z=Ce(e.rolloffFactor,0,10,1),E=Ce(e.coneInnerAngle,0,360,360),_=Ce(e.coneOuterAngle,E,360,Math.max(E,360)),b=Ce(e.coneOuterGain,0,1,0),$=e.playOnSelect===!0||e.playOnTap===!0;return{...r?{preset:r}:{},...s?{src:s}:{},type:f,volume:c,pitch:h,loop:C,autoplay:d,distanceModel:p,refDistance:m,maxDistance:y,rolloffFactor:z,coneInnerAngle:E,coneOuterAngle:_,coneOuterGain:b,playOnSelect:$}}function ar(t,e){let i=yi(t,16)?.trim();if(!i)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(i);return r?`#${r[1].toLowerCase()}`:e}var vl=new Set(["m","cm","mm","in","ft-in","auto"]),Ps=["x","y","z"];function Ml(t){if(!t)return null;let e=Ge(t);if(e&&e.enabled===!1)return null;let i=e?.unit,r=typeof i=="string"&&vl.has(i)?i:"auto",s=e?.axes,a=new Set(Array.isArray(s)?s.filter(c=>typeof c=="string"):typeof s=="string"?s.split(""):[]),f=Ps.filter(c=>a.has(c));return{enabled:!0,unit:r,axes:f.length>0?f:[...Ps],color:ar(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var wl=new Set(["none","floor","wall","ceiling","any"]);function _l(t){if(!t)return null;let e=Ge(t)??{},i=e.grid,r=f=>Ce(f,.001,100,.1),s=ai(i)?[r(i[0]),r(i[1]),r(i[2])]:typeof i=="number"&&Number.isFinite(i)&&i>0?[r(i),r(i),r(i)]:null,a=e.surface;return{grid:s,angleDeg:Ce(e.angleDeg,0,180,0),surface:typeof a=="string"&&wl.has(a)?a:"none",socketTag:yi(e.socketTag,128)??"",radius:Ce(e.radius,.01,2,.15)}}function Sl(t){let e=typeof t=="string"?{tag:t}:Ge(t),i=yi(e?.tag,128);return!e||!i?null:{tag:i,radius:Ce(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:ar(e.highlightColor,"#22c55e")}}function Al(t){if(!t)return null;let e=Ge(t);if(e&&e.enabled===!1)return null;let i=e?.action;return{enabled:!0,dwellMs:Math.round(Ce(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:i==="ask"?"ask":"select"}}function Tl(t){if(!t)return null;let e=Ge(t);if(e&&e.enabled===!1)return null;let i=e?.direction??e?.offset,r=null,s;if(ai(i)){let f=Math.hypot(i[0],i[1],i[2]);f>1e-8&&(r=[i[0]/f,i[1]/f,i[2]/f],e?.direction===void 0&&e?.offset!==void 0&&(s=f))}let a=typeof e?.distance=="number"&&Number.isFinite(e.distance)?e.distance:s;return typeof a=="number"&&a<0&&r&&(r=[-r[0],-r[1],-r[2]]),{enabled:!0,direction:r,distance:Ce(typeof a=="number"?Math.abs(a):void 0,0,10,.35),layer:Math.round(Ce(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var dn=new Set(["__proto__","constructor","prototype"]);function bi(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||dn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function gn(t){let e=Ge(t);if(!e||e.persist===!1)return null;let i=bi(e.id);return e.persist!==!0&&!i?null:i?{id:i,persist:!0}:{persist:!0}}function Nl(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function Cl(t){let e=typeof t=="string"?{text:t}:Ge(t),i=yi(e?.text??e?.value,256);if(!e||!i)return null;let r=Ce(e.size,.005,10,.12);return{text:i,size:r,depth:Ce(e.depth??e.height,.001,5,r*.2),color:ar(e.color,"#ffffff")}}function Pl(t){if(!t||typeof t=="number"&&!(t>0&&Number.isFinite(t)))return null;let e=t===!0?{}:typeof t=="number"?{strength:t}:Ge(t);if(!e||e.enabled===!1)return null;let i=Ce(e.strength??e.intensity,0,5,.35);return i>0?{enabled:!0,strength:i,threshold:Ce(e.threshold,0,4,.8),radius:Ce(e.radius,0,2,.5)}:null}function Ll(t){if(!t)return null;let e=t===!0?{}:typeof t=="string"?{color:t}:Ge(t);if(!e||e.enabled===!1)return null;let i=e.thickness??e.width;return{enabled:!0,color:ar(e.color,"#38bdf8"),thickness:Ce(typeof i=="number"&&i>0&&i<.25?Math.max(1.5,i*140):i,.5,20,3),pulse:e.pulse===!0}}function Dl(t){let e=Ge(t);if(!e||e.enabled===!1)return null;let i=bi(e.root),r=bi(e.effector);if(!i||!r)return null;let s=bi(e.mid),a=e.target,f;if(ai(a))f=[Ce(a[0],-1e3,1e3,0),Ce(a[1],-1e3,1e3,0),Ce(a[2],-1e3,1e3,0)];else{let d=bi(a);if(!d)return null;f=d}let c=e.pole??e.poleTarget,h=ai(c)?[Ce(c[0],-1e3,1e3,0),Ce(c[1],-1e3,1e3,0),Ce(c[2],-1e3,1e3,0)]:bi(c),C=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||s?"two-bone":"fabrik";return{root:i,...s?{mid:s}:{},effector:r,target:f,...h?{pole:h}:{},solver:C,iterations:Math.round(Ce(e.iterations,1,32,8)),tolerance:Ce(e.tolerance,1e-5,.1,.001),weight:Ce(e.weight,0,1,1)}}function $l(t){if(!t)return null;let e=t===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(t)?{distances:t}:Ge(t);if(!e||e.enabled===!1)return null;let i=Ce(e.hysteresis,0,.5,.05),r=[],s;if(Array.isArray(e.levels)&&e.levels.length>0){let h=e.levels.slice(0,8);for(let d=0;d<h.length;d++){let p=Ge(h[d]);if(!p)continue;let m=Ce(p.distance,0,1e4,d===0?0:d*4),y=typeof p.hysteresis=="number"?Ce(p.hysteresis,0,.5,i):void 0,z=typeof p.ratio=="number"?Ce(p.ratio,.05,1,.5):void 0,E=typeof p.childIndex=="number"&&Number.isFinite(p.childIndex)?Math.max(0,Math.round(p.childIndex)):void 0,_=bi(p.node);r.push({distance:m,...y!==void 0?{hysteresis:y}:{},...z!==void 0?{ratio:z}:{},...E!==void 0?{childIndex:E}:{},..._?{node:_}:{}})}r.sort((d,p)=>d.distance-p.distance),r.length>0&&r[0].distance>0&&r.unshift({distance:0,childIndex:0});let C=0;r=r.slice(0,8).map((d,p)=>{let m=p===0?0:Math.max(C,d.distance);return C=m,{...d,distance:m,childIndex:d.childIndex??p}})}if(Array.isArray(e.ratios)&&e.ratios.length>0){let h=[];for(let C of e.ratios.slice(0,7))typeof C=="number"&&h.push(Ce(C,.05,1,.5));h.length>0&&(s=h)}if(r.length===0){let h=Array.isArray(e.distances)?e.distances:[],C=[];for(let p of h.slice(0,8))typeof p=="number"&&C.push(Ce(p,0,1e4,4));if(C.length===0&&s&&s.length>0)for(let p=0;p<s.length;p++)C.push((p+1)*4);if(C.length===0&&e.cullDistance===void 0)return null;C.length===0||C[0]>0?C.unshift(0):s&&s.length===C.length&&s[0]===1&&(s=s.slice(1));let d=0;for(let p=0;p<Math.min(8,C.length);p++){let m=p===0?0:Math.max(d,C[p]);d=m;let y=p>0&&s?s[p-1]:void 0;r.push({distance:m,childIndex:p,...y!==void 0?{ratio:y}:{}})}}else if(!s){let h=[];for(let C=1;C<r.length;C++)typeof r[C].ratio=="number"&&h.push(r[C].ratio);h.length>0&&(s=h)}let a=r.map(h=>h.distance),f=a[a.length-1]??0,c=e.cullDistance!==void 0&&e.cullDistance!==null&&e.cullDistance!==!1?Ce(e.cullDistance,Math.max(1,f),1e4,100):void 0;return{levels:r,distances:a,...s?{ratios:s}:{},hysteresis:i,...c!==void 0?{cullDistance:c}:{}}}var Ls=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),zl=new Set(["capsule","cylindrical","spherical"]),Xi=[];function kl(t){Xi.includes(t)||Xi.push(t)}function $r(t){let e=Ge(t);if(!e)return null;let i=Array.isArray(e.traits)?e.traits:[],r=V=>i.includes(V),s={},a=e.grab??e.grabbable;a==="1-hand"||a==="2-hand"?s.grab=a:(a===!0||e.draggable===!0||e.movable===!0||e.interactable===!0||e.interactive===!0||r("grab"))&&(s.grab="2-hand"),s.grab&&(s.grabbable=!0);let f=e.scale??e.scalable;if(f||r("scale")){let V=Ge(f)??{},Y=Ce(V.min,.001,1e3,.05);s.scale={min:Y,max:Ce(V.max,Y,1e3,Math.max(Y,5))},s.scalable=!0}let c=e.billboard;typeof c=="string"&&zl.has(c)?s.billboard=c:(c===!0||r("billboard"))&&(s.billboard="capsule");let h=e.follow,C=typeof h=="string"?h:Ge(h)?.mode;if(typeof h=="string"?h:Ge(h)?.lazy===!1)s.follow=C==="hand-left"||C==="hand-right"?C:"head";else{let V=hl(h);V&&(s.follow=V)}let d=e.anchor??(e.floor===!0||e.ground===!0?"floor":void 0);if(typeof d=="string"&&Ls.has(d))s.anchor=d;else{let V=Ge(d)?.target;typeof V=="string"&&Ls.has(V)&&(s.anchor=V);let Y=gn(d)??gn(e.anchorPersist);Y&&(s.anchorPersist=Y)}if(!s.anchorPersist){let V=gn(e.anchorPersist)??(s.anchor&&e.persist===!0?{persist:!0,...bi(e.id)?{id:bi(e.id)}:{}}:null);V&&(s.anchorPersist=V)}(e.physics==="dynamic"||e.physics==="static")&&(s.physics=e.physics);let p=ul(e.orbit??(typeof e.radius=="number"&&(typeof e.speed=="number"||e.target!==void 0)&&e.character===void 0&&e.agent===void 0&&e.zone===void 0&&e.objective===void 0&&e.snapTo===void 0&&e.snapSocket===void 0?e:void 0));p&&(s.orbit=p);let m=cl(e.handles??e.resizable??e.scaleLimits);m&&(s.handles=m);let y=pl(e.particles??e.emitter);y&&(s.particles=y);let z=dl(e.holdToAsk);z&&(s.holdToAsk=z);let E=gl(e.worldUnderstanding);E&&(s.worldUnderstanding=E);let _=Dr(e.splatUrl);_&&(s.splatUrl=_),(e.splatQuality==="high"||e.splatQuality==="standard")&&(s.splatQuality=e.splatQuality);let b=yi(e.spatialSlot);b&&(s.spatialSlot=b);let $=typeof e.audio=="string"&&qi(e.audio.trim())?null:yl(e.audio);$&&(s.audio=$);let T=e.audioEmitter??e.spatialAudio??e.positionalAudio??e.sound??e.panner;if(T!==void 0){let V=Cs(T);V&&(s.audioEmitter=V)}else if(e.audio!==void 0){let V=Ge(e.audio),Y=!!(V&&("preset"in V||"type"in V||"positional"in V||"volume"in V||"gain"in V||"pitch"in V||"playbackRate"in V||"autoplay"in V||"autoPlay"in V||"distanceModel"in V||"maxDistance"in V||"rolloffFactor"in V||"coneInnerAngle"in V||"coneOuterAngle"in V||"coneOuterGain"in V||"playOnSelect"in V||"playOnTap"in V));if(!$||Y){let Z=Cs(e.audio);Z&&(s.audioEmitter=Z)}}let M=Ml(e.dimensions??e.measure??e.measurement??e.ruler);M&&(s.dimensions=M);let N=_l(e.snapTo??e.snap??e.magnetic);N&&(s.snapTo=N);let k=Sl(e.snapSocket);k&&(s.snapSocket=k);let A=Al(e.gaze??e.dwell);A&&(s.gaze=A);let S=Tl(e.explode??e.exploded??e.disassemble);S&&(s.explode=S);let w=Nl(e.navigable??(e.walkable!==void 0?e.walkable?"walkable":"blocked":e.teleport===!0?"walkable":void 0));w&&(s.navigable=w);let v=Cl(e.text??e.label??e.title??e.caption??e.spatialLabel);v&&(s.text=v);let P=Pl(e.bloom??e.glow);P&&(s.bloom=P);let H=Ll(e.outline);H&&(s.outline=H);let G=Dl(e.ik);G&&(s.ik=G);let x=$l(e.lod??e.levelOfDetail??e.detail??e.decimate??e.simplify);x&&(s.lod=x),typeof e.sync=="boolean"&&(s.sync=e.sync),e.pointerEvents==="none"&&(s.pointerEvents="none");for(let V of Xi)V.normalize(e,s);return Object.keys(s).length>0?s:null}var Ds=1;function $s(t){let e={schemaVersion:Ds};if(t.grab&&(e.interactable={mode:t.grab},e.movable={systemMovable:!0,scaleInZ:!!t.scale,minScale:t.scale?.min??.05,maxScale:t.scale?.max??5}),t.billboard&&(e.billboard={mode:t.billboard}),typeof t.follow=="string"?e.follow={target:t.follow,lazy:!1}:t.follow&&(e.follow={target:t.follow.mode,lazy:!0,distance:t.follow.distance,deadzoneDeg:t.follow.deadzoneDeg,stiffness:t.follow.stiffness,height:t.follow.height,faceUser:t.follow.faceUser}),t.anchor||t.anchorPersist){let i={};t.anchor&&(i.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",i.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(i.persist=t.anchorPersist.persist,t.anchorPersist.id&&(i.id=t.anchorPersist.id)),e.anchor=i}t.physics&&(e.rigidbody={type:t.physics}),t.orbit&&(e.orbit={...t.orbit}),t.handles&&(e.resizable={...t.handles}),t.particles&&(e.particles={...t.particles}),t.holdToAsk&&(e.holdToAsk={...t.holdToAsk}),t.worldUnderstanding&&(e.worldUnderstanding={...t.worldUnderstanding}),t.splatUrl&&(e.splat=t.splatQuality?{url:t.splatUrl,quality:t.splatQuality}:{url:t.splatUrl}),t.spatialSlot&&(e.spatialPanel={slot:t.spatialSlot}),t.audio&&(e.spatialAudio={...t.audio}),t.audioEmitter&&(e.audioEmitter={...t.audioEmitter}),t.dimensions&&(e.dimensions={...t.dimensions,axes:[...t.dimensions.axes]}),t.snapTo&&(e.snapTo={...t.snapTo,grid:t.snapTo.grid?[...t.snapTo.grid]:null}),t.snapSocket&&(e.snapSocket={...t.snapSocket}),t.gaze&&(e.gaze={...t.gaze}),t.explode&&(e.explode={...t.explode,direction:t.explode.direction?[...t.explode.direction]:null}),t.navigable&&(e.navigable={mode:t.navigable}),t.text&&(e.text3d={...t.text}),t.bloom&&(e.bloom={...t.bloom}),t.outline&&(e.outline={...t.outline}),t.ik&&(e.ik={...t.ik,...Array.isArray(t.ik.target)?{target:[...t.ik.target]}:{},...Array.isArray(t.ik.pole)?{pole:[...t.ik.pole]}:{}}),t.lod&&(e.lod={distances:[...t.lod.distances],...t.lod.ratios?{ratios:[...t.lod.ratios]}:{},hysteresis:t.lod.hysteresis,...t.lod.cullDistance!==void 0?{cullDistance:t.lod.cullDistance}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let i of Xi)i.sceneCore(t,e);return e}function El(t){let e={schemaVersion:Ds},i=(r,s)=>{for(let[a,f]of Object.entries(s)){let c=r+a[0].toUpperCase()+a.slice(1);typeof f=="string"||typeof f=="number"||typeof f=="boolean"?e[c]=f:ai(f)&&(e[c]=[f[0],f[1],f[2]])}};t.grab&&(e.grab=t.grab),t.scale&&i("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,i("follow",{...t.follow,mode:void 0})),t.anchor&&(e.anchor=t.anchor),t.anchorPersist&&(e.anchorPersist=t.anchorPersist.persist,t.anchorPersist.id&&(e.anchorId=t.anchorPersist.id)),t.physics&&(e.physics=t.physics),t.orbit&&i("orbit",t.orbit),t.handles&&(e.handles=!0,i("handles",t.handles)),t.particles&&i("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,i("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&i("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&i("audio",t.audio),t.audioEmitter&&i("audioEmitter",t.audioEmitter),t.dimensions&&i("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,i("snapTo",t.snapTo)),t.snapSocket&&i("snapSocket",t.snapSocket),t.gaze&&i("gaze",t.gaze),t.explode&&i("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&i("text",t.text),t.bloom&&i("bloom",t.bloom),t.outline&&i("outline",t.outline),t.ik&&i("ik",t.ik),t.lod&&(e.lodEnabled=!0,e.lodHysteresis=t.lod.hysteresis,e.lodDistances=t.lod.distances.join(","),t.lod.ratios&&(e.lodRatios=t.lod.ratios.join(",")),t.lod.cullDistance!==void 0&&(e.lodCullDistance=t.lod.cullDistance)),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of Xi)r.usd(t,i,e);return e}function Fl(t,e){let i=$r(e);if(!i)return;let r={...t.extras?.xr,...i};i.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,i.physics===void 0&&typeof r.physics=="object"&&delete r.physics,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:zs(i),ANDROID_xr_scenecore:$s(i)}}function zs(t){let e={};return t.grab&&(e.grabbable={cursor:!0,hand:!0}),t.billboard&&(e.billboard={onlyY:t.billboard!=="spherical"}),e}function Rl(t,e){let i=$r(t),r=[];if(!i)return r;for(let[s,a]of Object.entries(El(i)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(s)&&(typeof a=="boolean"?r.push(`bool ${s} = ${a}`):typeof a=="number"?Number.isFinite(a)&&r.push(`double ${s} = ${a}`):typeof a=="string"?r.push(`string ${s} = "${e(a)}"`):a.length===3&&a.every(f=>Number.isFinite(f))&&r.push(`double3 ${s} = (${a.join(", ")})`));return r}var Il=t=>{let e=$r(t);return e?Xi.map(i=>i.usdPrims?.(e)??"").join(""):""};function Ul(){try{Object.defineProperty(mt(),"xrTraitSerializer",{value:Object.freeze({gltfNode:Fl,usdLines:Rl,usdPrims:Il}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var yn=new Set(["grab","scale","billboard","follow","anchor","anchorPersist","physics","orbit","handles","particles","holdToAsk","worldUnderstanding","splatUrl","splatQuality","spatialSlot","audio","audioEmitter","spatialAudio","dimensions","snapTo","snapSocket","gaze","explode","navigable","text","bloom","outline","ik","lod","sync","pointerEvents","character","agent","integrity","zone","spawner","objective","audioCues","rigidBody","joint","collidable","material","traits","schemaVersion"]),zr={constraint:{target:"joint",hint:`Use 'joint: { type: "hinge" | "slider" | "spring" | "ball" }' instead of 'constraint'.`},rigidbody:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", mass: 1, restitution: 0.35 }' or 'physics' instead of 'rigidbody'.`},levelofdetail:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'levelOfDetail'."},detail:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'detail'."},decimate:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'decimate'."},simplify:{target:"lod",hint:"Use 'lod: { distances: [3, 8], ratios: [0.5, 0.2] }' instead of 'simplify'."},grabbable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'grabbable'.`},draggable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'draggable'.`},movable:{target:"grab",hint:`Use 'grab: true' or 'grab: "1-hand" | "2-hand"' instead of 'movable'.`},interactable:{target:"grab",hint:"Use 'grab: true' or 'userData.interactivity' instead of 'interactable'."},scalable:{target:"scale",hint:"Use 'scale: { min: 0.05, max: 5 }' instead of 'scalable'."},resizable:{target:"handles",hint:"Use 'handles: true' or 'scale: { min, max }' instead of 'resizable'."},health:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'health'.`},hp:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'hp'.`},hitpoints:{target:"integrity",hint:`Use 'integrity: { max: 100, group: "..." }' instead of 'hitpoints'.`},damage:{target:"integrity",hint:"Use 'integrity: { contactAmount: ... }' instead of 'damage'."},team:{target:"integrity",hint:`Use 'integrity: { group: "..." }' instead of 'team'.`},faction:{target:"integrity",hint:`Use 'integrity: { group: "..." }' instead of 'faction'.`},collides:{target:"collidable",hint:`Use 'collidable: true' or 'physics: "static" | "dynamic"' instead of 'collides'.`},collider:{target:"collidable",hint:`Use 'collidable: true' or 'physics: "static" | "dynamic"' instead of 'collider'.`},solid:{target:"collidable",hint:"Use 'collidable: true' instead of 'solid'."},obstacle:{target:"collidable",hint:"Use 'collidable: true' instead of 'obstacle'."},walkable:{target:"navigable",hint:`Use 'navigable: "walkable"' instead of 'walkable'.`},floor:{target:"anchor",hint:`Use 'anchor: "floor"' or 'navigable: "walkable"' instead of 'floor'.`},ground:{target:"anchor",hint:`Use 'anchor: "floor"' or 'navigable: "walkable"' instead of 'ground'.`},teleport:{target:"navigable",hint:`Use 'navigable: "walkable"' instead of 'teleport'.`},sound:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", refDistance: 1 }' or 'audio' instead of 'sound'.`},positionalaudio:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", refDistance: 1 }' instead of 'positionalAudio'.`},panner:{target:"audioEmitter",hint:`Use 'audioEmitter: { preset: "hum", coneInnerAngle: 90 }' instead of 'panner'.`},sfx:{target:"audioCues",hint:`Use 'audioCues: { onTap: "confirm" }' instead of 'sfx'.`},measure:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measure'."},interactive:{target:"grab",hint:"Use 'grab: true' instead of 'interactive'."},scaleLimits:{target:"handles",hint:"Use 'handles: { minScale, maxScale }' instead of 'scaleLimits'."},scalelimits:{target:"handles",hint:"Use 'handles: { minScale, maxScale }' instead of 'scaleLimits'."},spatialLabel:{target:"text",hint:`Use 'text: "..."' instead of 'spatialLabel'.`},spatiallabel:{target:"text",hint:`Use 'text: "..."' instead of 'spatialLabel'.`},measurement:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measurement'."},ruler:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'ruler'."},snap:{target:"snapTo",hint:"Use 'snapTo' or 'snapSocket' instead of 'snap'."},magnetic:{target:"snapTo",hint:"Use 'snapTo' or 'snapSocket' instead of 'magnetic'."},dwell:{target:"gaze",hint:"Use 'gaze: { dwellMs: 1200 }' instead of 'dwell'."},exploded:{target:"explode",hint:"Use 'explode: { distance: 0.35, layer: 1 }' instead of 'exploded'."},disassemble:{target:"explode",hint:"Use 'explode: true' instead of 'disassemble'."},label:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'label'.`},title:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'title'.`},caption:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'caption'.`},mass:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", mass: 1 }' instead of top-level 'mass'.`},restitution:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", restitution: 0.35 }' instead of top-level 'restitution'.`},bounciness:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", restitution: 0.35 }' instead of 'bounciness'.`},friction:{target:"rigidBody",hint:`Use 'rigidBody: { body: "dynamic", friction: 0.5 }' instead of top-level 'friction'.`},glow:{target:"bloom",hint:"Use 'bloom: { strength: 0.5 }' or 'outline' instead of 'glow'."},emissive:{target:"bloom",hint:"Use 'bloom: { strength: 0.5 }' on userData.xr or material.emissive."},ai:{target:"agent",hint:`Use 'agent: { mode: "patrol" | "chase" | "wander" }' instead of 'ai'.`},npc:{target:"agent",hint:`Use 'agent: { mode: "wander" }' instead of 'npc'.`},enemy:{target:"agent",hint:`Use 'agent: { mode: "chase" }' and 'integrity: { group: "enemy" }' instead of 'enemy'.`},bot:{target:"agent",hint:`Use 'agent: { mode: "patrol" }' instead of 'bot'.`},steering:{target:"agent",hint:"Use 'agent' instead of 'steering'."},player:{target:"character",hint:`Use 'character: { speed: 4, cameraMode: "third-person" }' instead of 'player'.`},avatar:{target:"character",hint:"Use 'character: true' instead of 'avatar'."},controller:{target:"character",hint:"Use 'character: true' instead of 'controller'."},trigger:{target:"zone",hint:`Use 'zone: { shape: "box", size: [1, 1, 1] }' instead of 'trigger'.`},hitbox:{target:"zone",hint:"Use 'zone' or 'integrity' instead of 'hitbox'."},sensor:{target:"zone",hint:"Use 'zone' instead of 'sensor'."},hazard:{target:"zone",hint:`Use 'zone: { shape: "box", watchGroups: ["player"] }' instead of 'hazard'.`},persist:{target:"anchorPersist",hint:`Use 'anchor: { target: "wall", persist: true }' or 'anchorPersist: { persist: true }' instead of top-level 'persist'.`},spawn:{target:"spawner",hint:`Use 'spawner: { template: "..." }' instead of 'spawn'.`},emitter:{target:"particles",hint:`Use 'particles: { preset: "sparks" }' or 'spawner' instead of 'emitter'.`},goal:{target:"objective",hint:`Use 'objective: { type: "pickup" | "checkpoint" }' instead of 'goal'.`},quest:{target:"objective",hint:"Use 'objective' instead of 'quest'."},collectible:{target:"objective",hint:`Use 'objective: { type: "pickup" }' instead of 'collectible'.`},pickup:{target:"objective",hint:`Use 'objective: { type: "pickup" }' instead of 'pickup'.`}};function Ol(t,e){let i=t.length,r=e.length,s=Array.from({length:r+1},(a,f)=>f);for(let a=1;a<=i;a++){let f=s[0];s[0]=a;for(let c=1;c<=r;c++){let h=s[c];s[c]=t[a-1]===e[c-1]?f:1+Math.min(f,s[c],s[c-1]),f=h}}return s[r]}var ks=null;function Es(t){let e=t.toLowerCase(),i=null,r=4,s=ks??(ks=Array.from(yn));for(let a=0;a<s.length;a++){let f=s[a];if(f==="traits")continue;let c=Ol(e,f.toLowerCase());c<r&&(r=c,i=f)}return i}function Bl(t,e="unnamed"){let i=[];if(t==null)return i;let r=(L,ee,ae,be="warning")=>i.push({code:L,severity:be,node:e,message:ee,hint:ae}),s=Ge(t);if(!s)return r("TL201",`userData.xr on node '${e}' must be a plain object.`,"Assign an object such as mesh.userData.xr = { grab: true }."),i;for(let L of Object.keys(s)){if(yn.has(L))continue;let ee=zr[L]??zr[L.toLowerCase()];if(ee)r("TL201",`Unrecognized key '${L}' in userData.xr on node '${e}' (auto-normalized to '${ee.target}'); did you mean '${ee.target}'?`,ee.hint,"info");else if((L==="radius"||L==="speed"||L==="target")&&typeof s.radius=="number"&&(typeof s.speed=="number"||s.target!==void 0)&&s.character===void 0&&s.player===void 0&&s.avatar===void 0&&s.controller===void 0)r("TL201",`Top-level '${L}' in userData.xr on node '${e}' auto-normalized to 'orbit.${L}'.`,"Use 'orbit: { target, radius, speed }' instead of top-level orbit properties.","info");else if((L==="speed"||L==="height"||L==="radius")&&(s.character!==void 0||s.player!==void 0||s.avatar!==void 0||s.controller!==void 0))r("TL201",`Top-level '${L}' in userData.xr on node '${e}' auto-normalized to 'character.${L}'.`,"Use 'character: { speed, height, radius }' instead of top-level character properties.","info");else if(L==="radius"&&(s.zone!==void 0||s.trigger!==void 0||s.hitbox!==void 0||s.sensor!==void 0||s.hazard!==void 0))r("TL201",`Top-level 'radius' in userData.xr on node '${e}' auto-normalized to 'zone.radius'.`,`Use 'zone: { shape: "sphere", radius }' instead of top-level 'radius'.`,"info");else{let ae=Es(L);r("TL201",ae?`Unknown key '${L}' on node '${e}'; did you mean '${ae}'?`:`Unknown key '${L}' in userData.xr on node '${e}'.`,ae?`Replace '${L}' with '${ae}'.`:"Supported userData.xr traits include: grab, scale, billboard, follow, anchor, physics, orbit, handles, particles, holdToAsk, audio, dimensions, snapTo, snapSocket, gaze, explode, navigable, text, bloom, outline, ik, character, agent, integrity, zone, spawner, objective, audioCues, collidable.")}}if(Array.isArray(s.traits)){for(let L of s.traits)if(typeof L=="string"&&!yn.has(L)){let ee=zr[L]??zr[L.toLowerCase()],ae=ee?.target??Es(L);r("TL201",ae?`Unknown trait '${L}' in userData.xr.traits on node '${e}'; did you mean '${ae}'?`:`Unknown trait '${L}' in userData.xr.traits on node '${e}'.`,ee?.hint??(ae?`Use '${ae}' instead of '${L}'.`:"Use canonical trait keys on userData.xr directly."))}}let a=(L,ee,ae,be)=>{if(typeof ee=="number"){if(!Number.isFinite(ee)){r("TL202",`Numeric trait parameter '${L}' on node '${e}' is non-finite (${ee}); clamped to default.`,`Provide a finite number in [${ae}, ${be}] for '${L}'.`);return}if(ee<ae||ee>be){let Ne=Math.max(ae,Math.min(be,ee));r("TL202",`Numeric trait parameter '${L}' (${ee}) on node '${e}' is out of range [${ae}, ${be}]; clamped to ${Ne}.`,`Keep '${L}' within [${ae}, ${be}].`)}}},f=Ge(s.material);if(f&&f.prompt!==void 0&&f.prompt!==null){let L=f.prompt,ee=typeof L=="string"?L.replace(/[\u0000-\u0020\u007f]+/g," ").replace(/^ | $/g,""):"";ee.length===0?r("TL206",`userData.xr.material.prompt on node '${e}' must be a non-empty string; ignored.`,"Describe the surface, e.g. prompt: 'weathered temple stone with moss'."):ee.length>500?r("TL206",`userData.xr.material.prompt on node '${e}' is ${ee.length} characters (max 500); ignored.`,"Shorten the prompt to at most 500 characters.","error"):f.preset===void 0&&f.type===void 0&&r("TL206",`userData.xr.material on node '${e}' has a prompt but no preset; until its texture pack entry exists it renders the plain material color.`,"Add an offline fallback such as preset: 'brick' (any THREE.ProceduralTexture preset).");let ae=f.size;if(typeof ae=="number"&&ae!==256&&ae!==512&&ae!==1024){let be=Number.isFinite(ae)?ae<=384?256:ae<=768?512:1024:512;r("TL202",`userData.xr.material.size (${ae}) on node '${e}' is not 256, 512, or 1024; the AI texture uses ${be}.`,"Use size: 256, 512, or 1024 for AI textures.","info")}}let c=Ge(s.scale);if(c){a("scale.min",c.min,.001,1e3);let L=Ce(c.min,.001,1e3,.05);a("scale.max",c.max,L,1e3)}let h=Ge(s.follow);h&&h.lazy!==!1&&(a("follow.distance",h.distance,.1,10),a("follow.deadzoneDeg",h.deadzoneDeg,0,90),a("follow.stiffness",h.stiffness,.5,40),a("follow.height",h.height,-2,2));let C=Ge(s.orbit);C&&(a("orbit.radius",C.radius,.01,50),a("orbit.speed",C.speed,-20,20),a("orbit.height",C.height,-10,10),a("orbit.phase",C.phase,-1e6,1e6));let d=Ge(s.handles);if(d){a("handles.minScale",d.minScale,.001,1e3);let L=Ce(d.minScale,.001,1e3,.1);a("handles.maxScale",d.maxScale,L,1e3)}let p=Ge(s.particles);if(p){if(a("particles.count",p.count,1,As),a("particles.speed",p.speed,.05,10),typeof p.area=="number")a("particles.area",p.area,.05,50);else if(Array.isArray(p.area))for(let L=0;L<Math.min(3,p.area.length);L++)a(`particles.area[${L}]`,p.area[L],.05,50)}let m=Ge(s.holdToAsk);m&&a("holdToAsk.holdMs",m.holdMs,100,5e3);let y=Ge(s.audio);y&&a("audio.refDistance",y.refDistance,.01,1e3);let z=Ge(s.audioEmitter)??Ge(s.spatialAudio)??(y&&!y.src?y:null);if(z&&z.enabled!==!1){a("audioEmitter.volume",z.volume??z.gain,0,2),a("audioEmitter.pitch",z.pitch??z.playbackRate,.25,4),a("audioEmitter.refDistance",z.refDistance,.05,100);let L=Ce(z.refDistance,.05,100,1);a("audioEmitter.maxDistance",z.maxDistance,L,500),a("audioEmitter.rolloffFactor",z.rolloffFactor,0,10),a("audioEmitter.coneInnerAngle",z.coneInnerAngle,0,360);let ee=Ce(z.coneInnerAngle,0,360,360);a("audioEmitter.coneOuterAngle",z.coneOuterAngle,ee,360),a("audioEmitter.coneOuterGain",z.coneOuterGain,0,1)}let E=Ge(s.snapTo);if(E){if(a("snapTo.angleDeg",E.angleDeg,0,180),a("snapTo.radius",E.radius,.01,2),typeof E.grid=="number"&&E.grid>0)a("snapTo.grid",E.grid,.001,100);else if(Array.isArray(E.grid))for(let L=0;L<Math.min(3,E.grid.length);L++)a(`snapTo.grid[${L}]`,E.grid[L],.001,100)}let _=Ge(s.snapSocket);_&&a("snapSocket.radius",_.radius,.01,2);let b=Ge(s.gaze);b&&b.enabled!==!1&&a("gaze.dwellMs",b.dwellMs,250,1e4);let $=Ge(s.explode);$&&$.enabled!==!1&&(a("explode.distance",$.distance,-10,10),a("explode.layer",$.layer,1,10));let T=Ge(s.text);if(T&&(a("text.size",T.size,.005,10),a("text.depth",T.depth??T.height,.001,5)),typeof s.bloom=="number"&&s.bloom>0)a("bloom",s.bloom,0,5);else{let L=Ge(s.bloom);L&&L.enabled!==!1&&(a("bloom.strength",L.strength??L.intensity,0,5),a("bloom.threshold",L.threshold,0,4),a("bloom.radius",L.radius,0,2))}let M=Ge(s.outline);if(M&&M.enabled!==!1){let L=M.thickness??M.width;typeof L=="number"&&!(L>0&&L<.25)&&a("outline.thickness",L,.5,20)}let N=Ge(s.ik);N&&N.enabled!==!1&&(a("ik.iterations",N.iterations,1,32),a("ik.tolerance",N.tolerance,1e-5,.1),a("ik.weight",N.weight,0,1));let k=Ge(s.lod);if(k&&k.enabled!==!1){if(a("lod.hysteresis",k.hysteresis,0,.5),k.cullDistance!==void 0&&k.cullDistance!==null&&k.cullDistance!==!1&&a("lod.cullDistance",k.cullDistance,1,1e4),Array.isArray(k.distances)){let L=-1/0;for(let ee=0;ee<Math.min(8,k.distances.length);ee++){let ae=k.distances[ee];a(`lod.distances[${ee}]`,ae,0,1e4),typeof ae=="number"&&Number.isFinite(ae)&&(ae<L&&r("TL202",`lod.distances[${ee}] (${ae}) on node '${e}' is less than previous distance (${L}); clamped to monotonic order.`,"Sort lod.distances in non-decreasing order (e.g. [3, 8])."),L=Math.max(L,ae))}}if(Array.isArray(k.ratios))for(let L=0;L<Math.min(7,k.ratios.length);L++)a(`lod.ratios[${L}]`,k.ratios[L],.05,1)}let A=Ge(s.character);if(A&&A.enabled!==!1){a("character.speed",A.speed,.1,20),a("character.runMultiplier",A.runMultiplier,1,4),a("character.jumpVelocity",A.jumpVelocity,0,30),a("character.gravity",A.gravity,0,50),a("character.radius",A.radius,.05,5);let L=Ce(A.radius,.05,5,.35);a("character.height",A.height,L*2,10),a("character.cameraDistance",A.cameraDistance,.5,50),a("character.cameraHeight",A.cameraHeight,-10,50)}let S=Ge(s.agent);if(S&&S.enabled!==!1&&(a("agent.speed",S.speed,.1,20),a("agent.turnSpeed",S.turnSpeed,.1,50),a("agent.sightRadius",S.sightRadius,0,100),a("agent.stopDistance",S.stopDistance,.01,10),a("agent.separationRadius",S.separationRadius,0,10)),typeof s.integrity=="number")a("integrity.max",s.integrity,1,1e6);else{let L=Ge(s.integrity);if(L&&L.enabled!==!1){a("integrity.max",L.max,1,1e6);let ee=Ce(L.max,1,1e6,100);a("integrity.current",L.current,0,ee),a("integrity.cooldownMs",L.cooldownMs,0,1e4),a("integrity.scoreValue",L.scoreValue,-1e6,1e6),a("integrity.contactAmount",L.contactAmount,0,1e6)}}let w=Ge(s.zone);if(w&&w.enabled!==!1){if(a("zone.radius",w.radius,.01,1e3),typeof w.size=="number")a("zone.size",w.size,.01,1e3);else if(Array.isArray(w.size))for(let L=0;L<Math.min(3,w.size.length);L++)a(`zone.size[${L}]`,w.size[L],.01,1e3)}let v=Ge(s.spawner);v&&v.enabled!==!1&&(a("spawner.intervalSec",v.intervalSec,.05,3600),a("spawner.maxActive",v.maxActive,1,32),a("spawner.totalCount",v.totalCount,0,1e4),a("spawner.spawnRadius",v.spawnRadius,0,100));let P=Ge(s.objective);P&&P.enabled!==!1&&(a("objective.amount",P.amount??P.points,-1e6,1e6),a("objective.radius",P.radius,.05,50),a("objective.order",P.order,0,1e3),a("objective.spinSpeed",P.spinSpeed,-50,50),a("objective.bobAmplitude",P.bobAmplitude,0,5),a("objective.respawnSec",P.respawnSec,0,3600));let H=Ge(s.audioCues);H&&(a("audioCues.pitchJitter",H.pitchJitter,0,.5),a("audioCues.volume",H.volume,0,1));let G=Ge(s.rigidBody)??Ge(s.physics);G&&G.enabled!==!1&&(a("rigidBody.mass",G.mass,0,1e3),a("rigidBody.restitution",G.restitution,0,1),a("rigidBody.friction",G.friction,0,1),a("rigidBody.linearDamping",G.linearDamping,0,20),a("rigidBody.angularDamping",G.angularDamping,0,20),a("rigidBody.gravityScale",G.gravityScale,-5,5));let x=Ge(s.joint??s.constraint);if(x&&x.enabled!==!1){a("joint.stiffness",x.stiffness,0,1e4),a("joint.damping",x.damping,0,1e3),a("joint.restLength",x.restLength,0,100),a("joint.motorSpeed",x.motorSpeed,-100,100),a("joint.motorMaxForce",x.motorMaxForce,0,1e4);let L=String(x.type??"hinge").toLowerCase(),ee=L==="hinge"||L==="revolute"||L==="ball"||L==="spherical",ae=ee?-360:L==="spring"||L==="distance"?0:-100,be=ee?360:100;Array.isArray(x.limits)&&(a("joint.limits[0]",x.limits[0],ae,be),a("joint.limits[1]",x.limits[1],ae,be))}let V=(L,ee)=>{ee!=null&&(Dr(ee)||r("TL203",`Unsafe or disallowed media URL in '${L}' (${JSON.stringify(ee)}) on node '${e}' rejected by safeMediaUrl().`,"Use an 'https://' URL or a clean relative path without '..', '\\\\', '%', or custom schemes (e.g. http:, javascript:, file:, data:).","error"))},Y=(L,ee)=>{ee!=null&&(bi(ee)||r("TL203",`Unsafe or invalid identifier in '${L}' (${JSON.stringify(ee)}) on node '${e}' rejected by safeAnchorId().`,"Anchor and bone identifiers must be non-empty strings without control characters or prototype-pollution keys ('__proto__', 'constructor', 'prototype').","error"))};s.splatUrl!==void 0&&s.splatUrl!==null&&V("splatUrl",s.splatUrl),typeof s.audio=="string"?qi(s.audio.trim())||V("audio",s.audio):y&&(y.src!==void 0?V("audio.src",y.src):y.preset===void 0&&Object.keys(y).some(L=>L.startsWith("on"))&&r("TL201",`userData.xr.audio on node '${e}' contains event keys without 'src'; did you mean 'audioCues'?`,`Use 'audioCues: { onTap: "confirm", onHit: "impact" }' for procedural synth cues, or provide 'audio: { src: "https://..." }' for spatial audio files.`));let Z=s.audioEmitter??s.spatialAudio;if(typeof Z=="string")qi(Z.trim())||V("audioEmitter",Z);else if(z){let L=z.src??z.url??z.uri;L!==void 0&&V("audioEmitter.src",L),typeof z.preset=="string"&&!qi(z.preset.trim())&&r("TL201",`Unknown audio preset '${z.preset}' in audioEmitter on node '${e}'.`,`Supported ambient presets: ${Ts.join(", ")}.`)}let q=(L,ee)=>{if(ee==null||ee==="")return;let ae=typeof ee=="string"?ee.trim():"";(!ae||!/^[A-Za-z0-9_.:-]{1,64}$/.test(ae)||dn.has(ae))&&r("TL203",`Unsafe or invalid identifier in '${L}' (${JSON.stringify(ee)}) on node '${e}' rejected by safeSimId().`,"Simulation group/tag IDs must be 1-64 characters of [A-Za-z0-9_.:-] and must not use prototype-pollution keys ('__proto__', 'constructor', 'prototype').","error")},X=Ge(s.integrity);if(X&&X.group!==void 0&&q("integrity.group",X.group),w&&w.watchGroups!==void 0){let L=Array.isArray(w.watchGroups)?w.watchGroups:[w.watchGroups];for(let ee=0;ee<L.length;ee++)q(`zone.watchGroups[${ee}]`,L[ee])}P&&P.tag!==void 0&&q("objective.tag",P.tag);let F=Ge(s.anchor);F&&F.id!==void 0&&Y("anchor.id",F.id);let Q=Ge(s.anchorPersist);if(Q&&Q.id!==void 0&&Y("anchorPersist.id",Q.id),N&&N.enabled!==!1){Y("ik.root",N.root),Y("ik.effector",N.effector),N.mid!==void 0&&Y("ik.mid",N.mid),N.target!==void 0&&!Array.isArray(N.target)&&Y("ik.target",N.target);let L=N.pole??N.poleTarget;L!==void 0&&!Array.isArray(L)&&Y("ik.pole",L)}if(x&&x.enabled!==!1){let L=x.target??x.connectedBody??x.parent;L!=null&&L!==""&&Y("joint.target",L)}return i}function bn(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!dn.has(e)?e:void 0}function kr(t,e,i){return typeof t=="string"&&e.includes(t)?t:i}var jl=["third-person","first-person","top-down","fixed"],Vl=["idle","walk","run","jump"];function Hl(t){if(!t)return null;let e=Ge(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let i=Ce(e.radius,.05,5,.35),r=Ge(e.clips)??{},s={};for(let a of Vl){let f=yi(r[a],128);f&&(s[a]=f)}return{speed:Ce(e.speed,.1,20,4),runMultiplier:Ce(e.runMultiplier,1,4,1.6),jumpVelocity:Ce(e.jumpVelocity,0,30,5.5),gravity:Ce(e.gravity,0,50,15),radius:i,height:Ce(e.height,i*2,10,Math.max(1.4,i*2)),cameraMode:kr(e.cameraMode,jl,"third-person"),cameraDistance:Ce(e.cameraDistance,.5,50,3.5),cameraHeight:Ce(e.cameraHeight,-10,50,1.8),clips:s}}var Gl=["patrol","chase","flee","wander","follow"],Wl=32,xn="user";function ql(t){if(!t)return null;let e=Ge(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let i=kr(e.mode,Gl,"wander"),r=e.target,s=r==="camera"||r===xn?xn:yi(r,256)??"";!s&&(i==="chase"||i==="flee"||i==="follow")&&(s=xn);let a=c=>Ce(c,-1e4,1e4,0),f=Array.isArray(e.waypoints)?e.waypoints.filter(ai).slice(0,Wl).map(c=>[a(c[0]),a(c[1]),a(c[2])]):[];return{mode:i,target:s,speed:Ce(e.speed,.1,20,2),turnSpeed:Ce(e.turnSpeed,.1,50,6),sightRadius:Ce(e.sightRadius,0,100,6),stopDistance:Ce(e.stopDistance,.01,10,.6),separationRadius:Ce(e.separationRadius,0,10,.8),waypoints:f,loopWaypoints:e.loopWaypoints!==!1}}function Xl(t){if(!t)return null;let e=Ge(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let i=Ce(e.max,1,1e6,100);return{max:i,current:Ce(e.current,0,i,i),group:bn(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(Ce(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:Ce(e.scoreValue,-1e6,1e6,0),contactAmount:Ce(e.contactAmount,0,1e6,0)}}var Yl=16;function Jl(t){if(!t)return null;let e=Ge(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let i=kr(e.shape,["box","sphere"],"box"),r=e.size,s=p=>Ce(p,.01,1e3,1),a=ai(r)?[s(r[0]),s(r[1]),s(r[2])]:typeof r=="number"?[s(r),s(r),s(r)]:[1,1,1],f=Ce(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),c=e.watchGroups,h=[...new Set((Array.isArray(c)?c:c===void 0?[]:[c]).map(bn).filter(p=>p!==void 0))].slice(0,Yl),C={shape:i,size:a,radius:f,watchGroups:h},d=ar(e.color,"");return d?{...C,color:d}:C}var Zl=32;function Ql(t){let e=Ge(t)??(typeof t=="string"?{template:t}:null),i=yi(e?.template,256)?.trim();return!e||!i||e.enabled===!1?null:{template:i,intervalSec:Ce(e.intervalSec,.05,3600,3),maxActive:Math.round(Ce(e.maxActive,1,Zl,8)),totalCount:Math.round(Ce(e.totalCount,0,1e4,0)),spawnRadius:Ce(e.spawnRadius,0,100,0)}}var Kl=["pickup","checkpoint","time-bonus","restore","key"];function eh(t){if(!t)return null;let e=Ge(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let i=kr(e.type,Kl,"pickup"),r=i==="pickup";return{type:i,amount:Ce(e.amount??e.points,-1e6,1e6,10),tag:bn(e.tag)??"",radius:Ce(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(Ce(e.order,0,1e3,0)),spinSpeed:Ce(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:Ce(e.bobAmplitude,0,5,r?.08:0),respawnSec:Ce(e.respawnSec,0,3600,0)}}var th=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],ih=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function rh(t){let e=Ge(t);if(!e)return null;let i={};for(let r of ih){let s=e[r];typeof s=="string"&&th.includes(s)&&(i[r]=s)}return Object.keys(i).length===0?null:{cues:i,pitchJitter:Ce(e.pitchJitter,0,.5,.08),volume:Ce(e.volume,0,1,1),spatial:e.spatial!==!1}}var Fs=["dynamic","static","kinematic"],nh=["auto","box","sphere","cylinder"];function vn(t,e,i,r=[0,0,0]){return ai(t)?[Ce(t[0],e,i,r[0]),Ce(t[1],e,i,r[1]),Ce(t[2],e,i,r[2])]:r}function sh(t){if(t==null||t===!1)return null;if(typeof t=="string"){if(!Fs.includes(t))return null;let c=t;return{body:c,shape:"auto",mass:c==="dynamic"?1:0,restitution:.35,friction:.5,linearDamping:.05,angularDamping:.1,gravityScale:1,velocity:[0,0,0],angularVelocity:[0,0,0],lockRotation:!1}}let e=t===!0?{}:Ge(t);if(!e||e.enabled===!1)return null;let i=e.body??e.type??e.mode,r=typeof i=="string"&&Fs.includes(i)?i:"dynamic",s=e.shape??e.collider,a=typeof s=="string"&&nh.includes(s)?s:"auto",f=r==="dynamic"?Ce(e.mass,.01,1e3,1):0;return{body:r,shape:a,mass:f,restitution:Ce(e.restitution??e.bounciness,0,1,.35),friction:Ce(e.friction,0,1,.5),linearDamping:Ce(e.linearDamping??e.damping,0,20,.05),angularDamping:Ce(e.angularDamping,0,20,.1),gravityScale:Ce(e.gravityScale,-5,5,1),velocity:vn(e.velocity,-200,200),angularVelocity:vn(e.angularVelocity,-100,100),lockRotation:e.lockRotation===!0}}var ah={hinge:"hinge",revolute:"hinge",slider:"slider",prismatic:"slider",spring:"spring",distance:"spring",ball:"ball",spherical:"ball"},oh={x:[1,0,0],"+x":[1,0,0],"-x":[-1,0,0],y:[0,1,0],"+y":[0,1,0],"-y":[0,-1,0],z:[0,0,1],"+z":[0,0,1],"-z":[0,0,-1]};function lh(t,e){if(typeof t=="string"){let r=oh[t.trim().toLowerCase()];return r?[...r]:[...e]}let i=ai(t)?Math.hypot(t[0],t[1],t[2]):0;return i>1e-6&&ai(t)?[t[0]/i,t[1]/i,t[2]/i]:[...e]}function hh(t){if(!t||t==="none")return null;let e=t===!0?{}:typeof t=="string"?{type:t}:Ge(t);if(!e||e.enabled===!1)return null;let i=e.type??e.kind??e.mode,r=typeof i=="string"?ah[i.trim().toLowerCase()]:"hinge";if(!r)return null;let s=e.target??e.connectedBody??e.parent,a=typeof s=="string"&&s.trim().toLowerCase()==="world"?"":bi(s)??"",f=vn(e.anchor??e.pivot,-100,100,[0,0,0]),c=lh(e.axis,r==="slider"?[0,0,1]:r==="spring"?[0,-1,0]:[0,1,0]),h=r==="hinge"||r==="ball",C=h?-360:r==="spring"?0:-100,d=h?360:100,p=e.limits,m=Array.isArray(p)&&p.length>=2?p[0]:e.min??(h?e.minAngle:e.minDistance),y=Array.isArray(p)&&p.length>=2?p[1]:e.max??(h?e.maxAngle:e.maxDistance),z=Array.isArray(p)?p.length>=2&&Number.isFinite(p[0])&&Number.isFinite(p[1]):typeof m=="number"&&Number.isFinite(m)||typeof y=="number"&&Number.isFinite(y),E=Ce(m,C,d,C),_=Ce(y,C,d,d),b=z?[Math.min(E,_),Math.max(E,_)]:null,$=Ce(e.motorSpeed,-100,100,0);return{type:r,target:a,anchor:f,axis:c,limits:b,stiffness:Ce(e.stiffness,0,1e4,r==="spring"?40:0),damping:Ce(e.damping,0,1e3,r==="spring"?4:.5),restLength:Ce(e.restLength,0,100,0),motorSpeed:$,motorMaxForce:Ce(e.motorMaxForce??e.maxMotorForce,0,1e4,$!==0?50:0)}}var uh={normalize(t,e){let i=t.character??t.player??t.avatar??t.controller,r=i!=null&&i!==!1&&(typeof t.speed=="number"||typeof t.height=="number"||typeof t.radius=="number")?{speed:t.speed,height:t.height,radius:t.radius,...typeof i=="string"?{cameraMode:i}:typeof i=="object"?i:{}}:i,s=Hl(r);s&&(e.character=s);let a=ql(t.agent??t.ai??t.npc??t.enemy??t.bot??t.steering);a&&(e.agent=a);let f=Xl(t.integrity??t.health??t.hp??t.hitpoints);f&&(e.integrity=f);let c=t.zone??t.trigger??t.hitbox??t.sensor??t.hazard,h=c!=null&&c!==!1&&typeof t.radius=="number"?{radius:t.radius,...typeof c=="string"?{shape:c}:typeof c=="object"?c:{}}:c,C=Jl(h);C&&(e.zone=C);let d=Ql(t.spawner??t.spawn);d&&(e.spawner=d);let p=eh(t.objective??t.goal??t.quest??t.collectible??t.pickup);p&&(e.objective=p);let m=rh(t.audioCues??t.sfx);m&&(e.audioCues=m);let y=t.physics,z=typeof t.mass=="number"||typeof t.restitution=="number"||typeof t.bounciness=="number"||typeof t.friction=="number",E=t.rigidBody??t.rigidbody??(y==="kinematic"||y===!0||typeof y=="object"&&y!==null||typeof y=="string"&&z?y:y===void 0&&typeof t.mass=="number"?!0:void 0),_=z&&E!==void 0&&E!==null&&E!==!1?{mass:t.mass,restitution:t.restitution??t.bounciness,friction:t.friction,...typeof E=="string"?{body:E}:typeof E=="object"?E:{}}:E,b=sh(_);b&&(e.rigidBody=b,!e.physics&&(b.body==="dynamic"||b.body==="static")&&(e.physics=b.body)),(t.collidable===!0||t.collides===!0||t.collider===!0||t.solid===!0||t.obstacle===!0)&&(e.collidable=!0);let $=hh(t.joint??t.constraint);$&&(e.joint=$)},sceneCore(t,e){t.character&&(e.character={...t.character,clips:{...t.character.clips}}),t.agent&&(e.agent={...t.agent,waypoints:t.agent.waypoints.map(i=>[...i])}),t.integrity&&(e.integrity={...t.integrity}),t.zone&&(e.zone={...t.zone,size:[...t.zone.size],watchGroups:[...t.zone.watchGroups]}),t.spawner&&(e.spawner={...t.spawner}),t.objective&&(e.objective={...t.objective}),t.audioCues&&(e.audioCues={...t.audioCues,cues:{...t.audioCues.cues}}),t.rigidBody&&(e.rigidbody={type:t.rigidBody.body,...t.rigidBody,velocity:[...t.rigidBody.velocity],angularVelocity:[...t.rigidBody.angularVelocity]}),t.collidable&&(e.collidable={enabled:!0}),t.joint&&(e.joint={...t.joint,anchor:[...t.joint.anchor],axis:[...t.joint.axis],limits:t.joint.limits?[...t.joint.limits]:null})},usd(t,e,i){if(t.character){i.character=!0,e("character",{...t.character,clips:void 0});for(let[r,s]of Object.entries(t.character.clips))i["characterClip"+r[0].toUpperCase()+r.slice(1)]=s}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),i.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,s)=>{i[`agentWaypoint${s}`]=[r[0],r[1],r[2]]})),t.integrity&&(i.integrity=!0,e("integrity",t.integrity)),t.zone&&e("zone",{...t.zone,watchGroups:t.zone.watchGroups.join(",")}),t.spawner&&e("spawner",t.spawner),t.objective&&e("objective",t.objective),t.audioCues&&(e("audioCues",{...t.audioCues,cues:void 0}),e("audioCues",t.audioCues.cues)),t.rigidBody&&(i.rigidBody=!0,i.physics=t.rigidBody.body,e("rigidBody",t.rigidBody)),t.collidable&&(i.collidable=!0),t.joint&&(i.joint=t.joint.type,e("joint",{...t.joint,type:void 0,limits:void 0}),t.joint.limits&&(i.jointMin=t.joint.limits[0],i.jointMax=t.joint.limits[1]))},usdPrims(t){let e=t.joint;if(!e)return"";let i={hinge:"PhysicsRevoluteJoint",slider:"PhysicsPrismaticJoint",spring:"PhysicsDistanceJoint",ball:"PhysicsSphericalJoint"},[r,s,a]=e.axis,f=Math.abs(r)>=Math.abs(s)&&Math.abs(r)>=Math.abs(a)?"X":Math.abs(a)>=Math.abs(s)?"Z":"Y",c=`point3f physics:localPos0 = (${e.anchor.join(", ")})
|
|
367
|
+
`;if(e.type==="hinge"||e.type==="slider")c+=`uniform token physics:axis = "${f}"
|
|
368
|
+
`,e.limits&&(c+=`float physics:lowerLimit = ${e.limits[0]}
|
|
369
|
+
float physics:upperLimit = ${e.limits[1]}
|
|
370
|
+
`);else if(e.limits){let[h,C]=e.limits,d=Math.max(Math.abs(h),Math.abs(C));c+=e.type==="spring"?`float physics:minDistance = ${h}
|
|
371
|
+
float physics:maxDistance = ${C}
|
|
372
|
+
`:`float physics:coneAngle0Limit = ${d}
|
|
373
|
+
float physics:coneAngle1Limit = ${d}
|
|
374
|
+
`}return`def ${i[e.type]} "Joint"
|
|
375
|
+
{
|
|
376
|
+
${c}}
|
|
377
|
+
`}};function ch(){kl(uh)}var Jt=class to{constructor(e=0,i=0){this.x=Number(e),this.y=Number(i)}set(e,i){return this.x=Number(e),this.y=Number(i),this}clone(){return new to(this.x,this.y)}copy(e){return this.set(e.x,e.y)}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}get width(){return this.x}set width(e){this.x=Number(e)}get height(){return this.y}set height(e){this.y=Number(e)}},Qe=class io{constructor(e=0,i=0,r=0){this.x=Number(e),this.y=Number(i),this.z=Number(r)}set(e,i,r){return this.x=Number(e),this.y=Number(i),this.z=Number(r),this}clone(){return new io(this.x,this.y,this.z)}copy(e){return this.set(e.x,e.y,e.z)}add(e){return this.addVectors(this,e)}addVectors(e,i){return this.set(e.x+i.x,e.y+i.y,e.z+i.z)}sub(e){return this.subVectors(this,e)}subVectors(e,i){return this.set(e.x-i.x,e.y-i.y,e.z-i.z)}multiplyScalar(e){return this.set(this.x*e,this.y*e,this.z*e)}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.set(this.x+e.x*i,this.y+e.y*i,this.z+e.z*i)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5?this.multiplyScalar(1/e):this}cross(e){return this.crossVectors(this,e)}crossVectors(e,i){let r=e.x,s=e.y,a=e.z,f=i.x,c=i.y,h=i.z;return this.set(s*h-a*c,a*f-r*h,r*c-s*f)}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,i){return this.lerpVectors(this,e,i)}lerpVectors(e,i,r){return this.x=e.x+(i.x-e.x)*r,this.y=e.y+(i.y-e.y)*r,this.z=e.z+(i.z-e.z)*r,this}applyMatrix4(e){let i=this.x,r=this.y,s=this.z,a=e.elements,f=1/(a[3]*i+a[7]*r+a[11]*s+a[15]);return this.x=(a[0]*i+a[4]*r+a[8]*s+a[12])*f,this.y=(a[1]*i+a[5]*r+a[9]*s+a[13])*f,this.z=(a[2]*i+a[6]*r+a[10]*s+a[14])*f,this}},Rs=class{constructor(t=0,e=0,i=0,r=1){this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r)}set(t,e,i,r){return this.x=Number(t),this.y=Number(e),this.z=Number(i),this.w=Number(r),this}},Mn=class ro{constructor(e=0,i=0,r=0,s="XYZ"){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=s}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,i,r,s=this.order){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this.order=s,this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.order)}clone(){return new ro(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Er=class no{constructor(e=0,i=0,r=0,s=1){this._onChangeCallback=null,this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(s)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,i,r,s){return this._x=Number(e),this._y=Number(i),this._z=Number(r),this._w=Number(s),this._onChangeCallback?.(),this}copy(e){return this.set(e.x,e.y,e.z,e.w)}clone(){return new no(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(e,i=!0){let r=e.x,s=e.y,a=e.z,f=Math.cos(r/2),c=Math.cos(s/2),h=Math.cos(a/2),C=Math.sin(r/2),d=Math.sin(s/2),p=Math.sin(a/2);return this._x=C*c*h+f*d*p,this._y=f*d*h-C*c*p,this._z=f*c*p+C*d*h,this._w=f*c*h-C*d*p,i&&this._onChangeCallback?.(),this}setFromAxisAngle(e,i){let r=i/2,s=Math.sin(r);return this.set(e.x*s,e.y*s,e.z*s,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,i){let r=e.dot(i)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*i.z-e.z*i.y,e.z*i.x-e.x*i.z,e.x*i.y-e.y*i.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,i){let r=e.x,s=e.y,a=e.z,f=e.w,c=i.x,h=i.y,C=i.z,d=i.w;return this._x=r*d+f*c+s*C-a*h,this._y=s*d+f*h+a*c-r*C,this._z=a*d+f*C+r*h-s*c,this._w=f*d-r*c-s*h-a*C,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},Ti=class so{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 so;return e.copy(this),e}compose(e,i,r){return tn(this.elements,[i.x,i.y,i.z,i.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,i){return Et(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return en(this.elements,[e.x,e.y,e.z],[i.x,i.y,i.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let i=new Qe(0,0,0),r=new Qe(1,1,1);return this.compose(i,e,r)}makeTranslation(e,i,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(i),this.elements[14]=Number(r),this}makeScale(e,i,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(i),this.elements[10]=Number(r),this}},Is=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 zi(this.elements,t.elements),this}},Vt=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,Fr=t=>t<=.0031308?t*12.92:1.055*t**(1/2.4)-.055,Us={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},_i=class ao{constructor(e,i,r){this.r=1,this.g=1,this.b=1,e!==void 0&&(i!==void 0&&r!==void 0?this.setRGB(e,i,r):this.set(e))}set(e){return typeof e=="number"?this.setHex(e):typeof e=="string"?this.setStyle(e):(e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b)),this)}setStyle(e){let i=e.trim().toLowerCase();if(i[0]==="#"){let r=i.slice(1);r.length===3||r.length===4?r=r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r.length===8&&(r=r.slice(0,6));let s=parseInt(r,16);r.length===6&&!Number.isNaN(s)&&this.setHex(s)}else if(i in Us)this.setHex(Us[i]);else if(i.startsWith("hsl")){let r=/^hsla?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);r&&r.length>=3&&this.setHSL((parseFloat(r[0])||0)/360,(parseFloat(r[1])||0)/100,(parseFloat(r[2])||0)/100)}else{let r=/^rgba?\(([^)]+)\)$/.exec(i)?.[1].trim().split(/[\s,/]+/);if(r&&r.length>=3){let s=a=>Vt(Math.max(0,Math.min(1,(parseFloat(a)||0)/(a.endsWith("%")?100:255))));this.setRGB(s(r[0]),s(r[1]),s(r[2]))}}return this}setHSL(e,i,r){if(e=((Number(e)||0)%1+1)%1,i=Math.max(0,Math.min(1,Number(i)||0)),r=Math.max(0,Math.min(1,Number(r)||0)),i===0){let c=Vt(r);return this.setRGB(c,c,c)}let s=r<=.5?r*(1+i):r+i-r*i,a=2*r-s,f=c=>(c<0&&(c+=1),c>1&&(c-=1),c<1/6?a+(s-a)*6*c:c<1/2?s:c<2/3?a+(s-a)*6*(2/3-c):a);return this.setRGB(Vt(f(e+1/3)),Vt(f(e)),Vt(f(e-1/3)))}lerp(e,i){return this.lerpColors(this,e,i)}lerpColors(e,i,r){let s=Number(r)||0;return this.setRGB(e.r+(i.r-e.r)*s,e.g+(i.g-e.g)*s,e.b+(i.b-e.b)*s)}multiplyScalar(e){let i=Number(e)||0;return this.setRGB(this.r*i,this.g*i,this.b*i)}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.setRGB(Vt((i>>16&255)/255),Vt((i>>8&255)/255),Vt((i&255)/255))}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.setRGB(Vt(this.r),Vt(this.g),Vt(this.b))}convertLinearToSRGB(){return this.setRGB(Fr(this.r),Fr(this.g),Fr(this.b))}getHex(){let e=i=>Math.round(Fr(Math.max(0,Math.min(1,i)))*255);return e(this.r)<<16|e(this.g)<<8|e(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.setRGB(e.r,e.g,e.b)}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new ao(this.r,this.g,this.b)}},Rr=1234567,Os={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,i)=>Math.max(e,Math.min(i,t)),lerp:(t,e,i)=>t+(e-t)*i,generateUUID:()=>Math.random().toString(36).substring(2,15),randInt:(t,e)=>t+Math.floor(Math.random()*(e-t+1)),randFloat:(t,e)=>t+Math.random()*(e-t),randFloatSpread:t=>t*(.5-Math.random()),seededRandom:t=>{t!==void 0&&(Rr=Number.isFinite(t)?t|0:0);let e=Rr=Rr+1831565813|0;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}},$t=class oo{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);if(Array.isArray(e)){let s=globalThis.__three_live_native_f32_array__;this.array=typeof s=="function"?s(e):new Float32Array(e)}else this.array=e;this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.itemSize>=2?this.array[e*this.itemSize+1]:0}getZ(e){return this.itemSize>=3?this.array[e*this.itemSize+2]:0}setX(e,i){return this.array[e*this.itemSize]=i,this.needsUpdate=!0,this}setY(e,i){return this.array[e*this.itemSize+1]=i,this.needsUpdate=!0,this}setZ(e,i){return this.array[e*this.itemSize+2]=i,this.needsUpdate=!0,this}setXYZ(e,i,r,s){let a=e*this.itemSize;return this.array[a]=i,this.array[a+1]=r,this.array[a+2]=s,this.needsUpdate=!0,this}setUsage(e){return this}clone(){let e=this.array?.constructor||Float32Array;return new oo(new e(this.array),this.itemSize)}},Bs=class extends $t{constructor(t,e){super(t instanceof Float32Array||Array.isArray(t)?t:new Float32Array(t),e)}},js=class extends $t{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},Vs=class extends $t{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},Pt=class lo{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(e,i){return this.attributes[e]=i,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof $t)this.index=e;else if(Array.isArray(e)){let i=globalThis.__three_live_native_index_array__;if(typeof i=="function")this.index=new $t(i(e),1);else{let r=0;for(let s of e)s>r&&(r=s);this.index=new $t(new(r>65535?Uint32Array:Uint16Array)(e),1)}}else e&&e.buffer&&(this.index=new $t(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=globalThis.__three_live_native_compute_vertex_normals__;if(typeof i=="function"){let h=i(e.array,this.index?.array);return this.setAttribute("normal",new $t(h,3)),this}let r=e.count,s=e.array,a=new Float32Array(r*3),f=this.index?.array,c=f?f.length:r;for(let h=0;h<c;h+=3){let C=(f?f[h]:h)*3,d=(f?f[h+1]:h+1)*3,p=(f?f[h+2]:h+2)*3,m=s[d],y=s[d+1],z=s[d+2],E=s[p]-m,_=s[p+1]-y,b=s[p+2]-z,$=s[C]-m,T=s[C+1]-y,M=s[C+2]-z,N=_*M-b*T,k=b*$-E*M,A=E*T-_*$;a[C]+=N,a[C+1]+=k,a[C+2]+=A,a[d]+=N,a[d+1]+=k,a[d+2]+=A,a[p]+=N,a[p+1]+=k,a[p+2]+=A}for(let h=0;h<r*3;h+=3){let C=a[h],d=a[h+1],p=a[h+2],m=Math.hypot(C,d,p)||1;a[h]=C/m,a[h+1]=d/m,a[h+2]=p/m}return this.setAttribute("normal",new $t(a,3)),this}setFromBuffers(e,i,r,s){this.setAttribute("position",new $t(e,3)),this.setAttribute("normal",new $t(i,3)),this.setAttribute("uv",new $t(r,2)),this.setIndex(s)}setFromPoints(e){let i=[];if(Array.isArray(e))for(let r of e)i.push(Number(r?.x)||0,Number(r?.y)||0,Number(r?.z)||0);return this.setAttribute("position",new $t(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new Qe(1/0,1/0,1/0),r=new Qe(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let s=0;s<e.count;s++){let a=e.getX(s),f=e.getY(s),c=e.getZ(s);a<i.x&&(i.x=a),f<i.y&&(i.y=f),c<i.z&&(i.z=c),a>r.x&&(r.x=a),f>r.y&&(r.y=f),c>r.z&&(r.z=c)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return e.max.x<e.min.x?this:this.translate(-(e.min.x+e.max.x)*.5,-(e.min.y+e.max.y)*.5,-(e.min.z+e.max.z)*.5)}_xform(e,i){let r=this.attributes.position;if(r){let s=r.array;for(let a=0;a<s.length;a+=3)e(s,a);r.needsUpdate=!0,i&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(e=0,i=0,r=0){return this._xform((s,a)=>{s[a]+=e,s[a+1]+=i,s[a+2]+=r})}scale(e=1,i=1,r=1){return this._xform((s,a)=>{s[a]*=e,s[a+1]*=i,s[a+2]*=r},!0)}_rot(e,i,r){let s=Math.cos(r),a=Math.sin(r);for(let f of[this.attributes.position,this.attributes.normal]){if(!f)continue;let c=f.array;for(let h=0;h<c.length;h+=3){let C=c[h+e],d=c[h+i];c[h+e]=C*s-d*a,c[h+i]=C*a+d*s}f.needsUpdate=!0}return this}rotateX(e){return this._rot(1,2,e)}rotateY(e){return this._rot(2,0,e)}rotateZ(e){return this._rot(0,1,e)}applyMatrix4(e){let i=this.attributes.position;if(i&&e?.elements){let r=new Qe;for(let s=0;s<i.count;s++)r.set(i.getX(s),i.getY(s),i.getZ(s)).applyMatrix4(e),i.setXYZ(s,r.x,r.y,r.z);this.computeVertexNormals()}return this}clone(){let e=new lo;e.name=this.name;for(let i of Object.keys(this.attributes))e.attributes[i]=this.attributes[i].clone();return this.index&&(e.index=this.index.clone()),e}dispose(){}},wn=class extends Pt{constructor(t=1,e=1,i=1){super();{let d=globalThis.__three_live_native_box__;if(typeof d=="function"){let p=d(t,e,i);this.setFromBuffers(p.positions,p.normals,p.uvs,p.indices);return}}let r=t/2,s=e/2,a=i/2,f=[-r,-s,a,r,-s,a,r,s,a,-r,s,a,r,-s,-a,-r,-s,-a,-r,s,-a,r,s,-a,-r,s,a,r,s,a,r,s,-a,-r,s,-a,-r,-s,-a,r,-s,-a,r,-s,a,-r,-s,a,r,-s,a,r,-s,-a,r,s,-a,r,s,a,-r,-s,-a,-r,-s,a,-r,s,a,-r,s,-a],c=[],h=[],C=[];for(let d=0;d<6;d++){let p=d*4,m=2-(d>>1),y=d&1?-1:1;for(let z=0;z<4;z++)c.push(m===0?y:0,m===1?y:0,m===2?y:0);h.push(0,0,1,0,1,1,0,1),C.push(p,p+1,p+2,p,p+2,p+3)}this.setFromBuffers(f,c,h,C)}},Hs=class extends Pt{constructor(t=1,e=1,i=1,r=1){super(),i=Math.max(1,Math.floor(i)),r=Math.max(1,Math.floor(r));{let h=globalThis.__three_live_native_plane__;if(typeof h=="function"){let C=h(t,e,i,r);this.setFromBuffers(C.positions,C.normals,C.uvs,C.indices);return}}let s=[],a=[],f=[],c=[];for(let h=0;h<=r;h++){let C=h/r;for(let d=0;d<=i;d++){let p=d/i;if(s.push((p-.5)*t,(.5-C)*e,0),a.push(0,0,1),f.push(p,1-C),h>0&&d>0){let m=(i+1)*h+d-1,y=m-(i+1);c.push(y,m,y+1,m,m+1,y+1)}}}this.setFromBuffers(s,a,f,c)}},Gs=class extends Pt{constructor(t=1,e=16,i=12,r=0,s=Math.PI*2,a=0,f=Math.PI){if(super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i)),!r&&!a&&Math.abs(s-Math.PI*2)<1e-4&&Math.abs(f-Math.PI)<1e-4){let m=globalThis.__three_live_native_sphere__;if(typeof m=="function"){let y=m(t,e,i);this.setFromBuffers(y.positions,y.normals,y.uvs,y.indices);return}}let c=[],h=[],C=[],d=[],p=Math.min(a+f,Math.PI);for(let m=0;m<=i;m++){let y=m/i,z=a+y*f;for(let E=0;E<=e;E++){let _=E/e,b=r+_*s,$=-Math.cos(b)*Math.sin(z),T=Math.cos(z),M=Math.sin(b)*Math.sin(z);if(c.push(t*$,t*T,t*M),h.push($,T,M),C.push(_,1-y),m>0&&E>0){let N=(e+1)*m+E,k=N-(e+1),A=k-1,S=N-1;(m!==1||a>0)&&d.push(k,A,N),(m!==i||p<Math.PI)&&d.push(A,S,N)}}}this.setFromBuffers(c,h,C,d)}},_n=class extends Pt{constructor(t=1,e=1,i=1,r=16,s=1,a=!1,f=0,c=Math.PI*2){if(super(),r=Math.max(3,Math.floor(r)),s=Math.max(1,Math.floor(Number(s)||1)),s===1&&!a&&!f&&Math.abs(c-Math.PI*2)<1e-4){let _=globalThis.__three_live_native_cylinder__;if(typeof _=="function"){let b=_(t,e,i,r);this.setFromBuffers(b.positions,b.normals,b.uvs,b.indices);return}}let h=[],C=[],d=[],p=[],m=i/2,y=(e-t)/(i||1),z=r+1;for(let _=0;_<=s;_++){let b=_/s,$=b*(e-t)+t,T=m-b*i;for(let M=0;M<=r;M++){let N=M/r,k=f+N*c,A=Math.sin(k),S=Math.cos(k),w=Math.hypot(A,y,S)||1;if(h.push($*A,T,$*S),C.push(A/w,y/w,S/w),d.push(N,1-b),_<s&&M<r){let v=_*z+M,P=v+z;p.push(v,P,v+1,P,P+1,v+1)}}}let E=(_,b)=>{if(a||_<=0)return;let $=b*m,T=h.length/3;h.push(0,$,0),C.push(0,b,0),d.push(.5,.5);let M=T+1;for(let N=0;N<=r;N++){let k=f+N/r*c,A=Math.sin(k),S=Math.cos(k);h.push(_*A,$,_*S),C.push(0,b,0),d.push(S*.5+.5,.5+b*A*.5),N<r&&p.push(T,M+N+(b>0?0:1),M+N+(b>0?1:0))}};E(t,1),E(e,-1),this.setFromBuffers(h,C,d,p)}},Ws=class extends _n{constructor(t=1,e=1,i=16,r=1,s=!1,a=0,f=Math.PI*2){super(0,t,e,i,r,s,a,f)}},qs=class extends Pt{constructor(t=1,e=.4,i=12,r=48,s=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),r=Math.max(3,Math.floor(r));{let C=globalThis.__three_live_native_torus__;if(typeof C=="function"){let d=C(t,e,i,r,s);this.setFromBuffers(d.positions,d.normals,d.uvs,d.indices);return}}let a=[],f=[],c=[],h=[];for(let C=0;C<=i;C++){let d=C/i*Math.PI*2,p=Math.cos(d),m=Math.sin(d);for(let y=0;y<=r;y++){let z=y/r*s,E=Math.cos(z),_=Math.sin(z);if(a.push((t+e*p)*E,(t+e*p)*_,e*m),f.push(p*E,p*_,m),c.push(y/r,C/i),C>0&&y>0){let b=(r+1)*C+y-1,$=b-(r+1);h.push(b,$,b+1,$,$+1,b+1)}}}this.setFromBuffers(a,f,c,h)}};function Xs(t,e,i,r,s){let a=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),f=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),c=Number(r)||.1,h=[],C=[],d=[],p=[],m=[],y=new Qe,z=new Qe,E=new Qe;for(let b=0;b<=a;b++){let $=new Qe;s(b/a,$),m.push($)}let _=f+1;for(let b=0;b<=a;b++){let $=b/a,T=m[b];y.subVectors(m[Math.min(a,b+1)],m[Math.max(0,b-1)]).normalize(),b===0&&z.set(Math.abs(y.y)>.9?1:0,Math.abs(y.y)>.9?0:1,0),E.crossVectors(y,z).normalize(),z.crossVectors(E,y).normalize();for(let M=0;M<=f;M++){let N=M/f*Math.PI*2,k=-Math.cos(N),A=Math.sin(N),S=k*z.x+A*E.x,w=k*z.y+A*E.y,v=k*z.z+A*E.z;if(h.push(T.x+c*S,T.y+c*w,T.z+c*v),C.push(S,w,v),d.push($,M/f),b>0&&M>0){let P=_*(b-1)+M-1,H=P+_;p.push(P,H,P+1,H,H+1,P+1)}}}t.setFromBuffers(h,C,d,p)}var Ys=class extends Pt{constructor(t=1,e=.4,i=64,r=8,s=2,a=3){super(),i=Math.floor(i),r=Math.floor(r);{let f=globalThis.__three_live_native_torus_knot__;if(typeof f=="function"){let c=f(t,e,i,r,s,a);this.setFromBuffers(c.positions,c.normals,c.uvs,c.indices);return}}Xs(this,i,r,e,(f,c)=>{let h=f*s*Math.PI*2,C=a/s*h,d=t*(2+Math.cos(C))*.5;c.set(d*Math.cos(h),d*Math.sin(h),t*Math.sin(C)*.5)})}},Bi=class{getPoint(t,e=new Qe){return e}getPointAt(t,e=new Qe){return this.getPoint(t,e)}getTangent(t,e=new Qe){return e.subVectors(this.getPoint(Math.min(1,t+.001)),this.getPoint(Math.max(0,t-.001))).normalize()}getPoints(t=5){let e=Math.max(1,Math.min(512,Math.floor(Number(t)||5))),i=[];for(let r=0;r<=e;r++)i.push(this.getPoint(r/e));return i}getSpacedPoints(t=5){return this.getPoints(t)}},Js=class extends Bi{constructor(t=new Qe,e=new Qe){super(),this.v1=t,this.v2=e}getPoint(t,e=new Qe){return e.lerpVectors(this.v1,this.v2,t)}},Zs=class extends Bi{constructor(t=new Qe,e=new Qe,i=new Qe){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Qe){return e.lerpVectors(this.v0,this.v1,t).lerp(new Qe().lerpVectors(this.v1,this.v2,t),t)}},Qs=class extends Bi{constructor(t=new Qe,e=new Qe,i=new Qe,r=new Qe){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new Qe){let i=new Qe().lerpVectors(this.v0,this.v1,t),r=new Qe().lerpVectors(this.v1,this.v2,t),s=new Qe().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(s,t),t)}},Ks=class extends Bi{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new Qe){let i=this.points,r=i.length;if(!r)return e.set(0,0,0);if(r===1)return e.copy(i[0]);let s=(this.closed?r:r-1)*Math.max(0,Math.min(1,Number(t)||0)),a=Math.floor(s),f=s-a;!this.closed&&a>=r-1&&(a=r-2,f=1);let c=E=>i[this.closed?(E%r+r)%r:Math.max(0,Math.min(r-1,E))],h=c(a-1),C=c(a),d=c(a+1),p=c(a+2),m=f*f,y=m*f,z=(E,_,b,$)=>.5*(2*_+(b-E)*f+(2*E-5*_+4*b-$)*m+(3*_-E-3*b+$)*y);return e.set(z(h.x,C.x,d.x,p.x),z(h.y,C.y,d.y,p.y),z(h.z,C.z,d.z,p.z))}},Sn=class extends Pt{constructor(t=[new Jt(0,-.5),new Jt(.5,0),new Jt(0,.5)],e=12,i=0,r=Math.PI*2){super();let s=Array.isArray(t)&&t.length>=2?t:[new Jt(.2,0),new Jt(.2,.5)],a=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),f=[],c=[],h=[],C=[],d=s.length;for(let p=0;p<=a;p++){let m=p/a,y=i+m*r,z=Math.sin(y),E=Math.cos(y),_=p*d;for(let b=0;b<d;b++){let $=s[b],T=Number($?.x)||0,M=Number($?.y)||0;f.push(T*z,M,T*E);let N=s[Math.max(0,b-1)],k=s[Math.min(d-1,b+1)],A=(Number(k?.x)||0)-(Number(N?.x)||0),S=(Number(k?.y)||0)-(Number(N?.y)||0),w=Math.hypot(S,A)||1;if(c.push(S/w*z,-A/w,S/w*E),h.push(m,b/(d-1)),p<a&&b<d-1){let v=_+b,P=v+d;C.push(v,P,v+1,P,P+1,v+1)}}}this.setFromBuffers(f,c,h,C)}},ea=class extends Pt{constructor(t,e=64,i=1,r=8,s=!1){super(),Xs(this,e,r,i,(a,f)=>{let c=t?.getPointAt??t?.getPoint;if(typeof c=="function"){let h=c.call(t,a,f);h&&h!==f&&f.copy(h)}else f.set(0,a,0)})}},Ir="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ur=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new Jt(1,1),this.offset=new Jt(0,0),this.image=null,this.width=0,this.height=0,this.source=t,t&&typeof t=="object"&&(this.image=t)}dispose(){}},ta=class extends Ur{constructor(t=null,e=1,i=1,r=1023,s=1009,a,f=1001,c=1001,h=1003,C=1003,d=1,p=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let m=Number(e),y=Number(i),z=t&&typeof t.length=="number"?t:null;this.width=m,this.height=y,this.image={data:z,width:m,height:y},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(f)||1001,this.wrapT=Number(c)||1001,this.magFilter=Number(h)||1003,this.minFilter=Number(C)||1003,this.colorSpace=p||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(t){t&&this._bake()}_bake(){let t=this.image,e=t?.data,i=Number(t?.width??this.width),r=Number(t?.height??this.height);if(!e||!e.length||!(i>0&&r>0)||i>2048||r>2048){this.source="";return}let s=Math.max(1,i|0),a=Math.max(1,r|0),f=s*a,c=this.format,h=c===1021||c===1024||c===1028||e.length===f?1:c===1025||c===1030||e.length===f*2?2:c===1022||e.length===f*3?3:4,C=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,d=Math.min(s,64),p=Math.min(a,64),m=(this.flipY?257:1)^this.colorSpace.length^e.length,y=Math.max(1,e.length>>6|0);for(let H=0;H<e.length;H+=y)m=Math.imul(m^(e[H]*256|0),16777619)|0;if(m===this._sig&&this.source)return;this._sig=m;let z=p*(1+d*4),E=new Uint8Array(68+z),_=new DataView(E.buffer);_.setUint32(0,2303741511),_.setUint32(4,218765834),_.setUint32(8,13),_.setUint32(12,1229472850),_.setUint32(16,d),_.setUint32(20,p),E[24]=8,E[25]=6,_.setUint32(29,cn(E.subarray(12,29))),_.setUint32(33,z+11),_.setUint32(37,1229209940),E[41]=120,E[42]=1,E[43]=1,_.setUint16(44,z,!0),_.setUint16(46,~z&65535,!0);let b=48,$=1,T=0,M=0,N=0,k=0,A=0,S=H=>{if(!Number.isFinite(H))return 0;let G=C&&H<=1?H*255:H;return G>0?G<255?G+.5|0:255:0};for(let H=0;H<p;H++){let G=H*a/p|0,x=this.flipY?a-1-G:G;E[b++]=0,T+=$;for(let V=0;V<d;V++){let Y=(x*s+(V*s/d|0))*h,Z=c===1021?255:S(e[Y]??0),q=h>=3||c===1030?S(e[Y+1]??0):Z,X=h>=3?S(e[Y+2]??0):c===1030?0:Z,F=h===4?S(e[Y+3]??255):c===1021?S(e[Y]??255):c===1025?S(e[Y+1]??255):255;E[b++]=Z,$+=Z,T+=$,E[b++]=q,$+=q,T+=$,E[b++]=X,$+=X,T+=$,E[b++]=F,$+=F,T+=$,M+=Z,N+=q,k+=X,A+=F}$%=65521,T%=65521}_.setUint32(b,(T<<16|$)>>>0),_.setUint32(b+4,cn(E.subarray(37,b+4))),_.setUint32(b+12,1229278788),_.setUint32(b+16,2923585666);let w=d*p*255,v=this.colorSpace==="srgb-linear";this.avgColor=[v?M/w:Vt(M/w),v?N/w:Vt(N/w),v?k/w:Vt(k/w),A/w];let P=["data:image/png;base64,"];for(let H=0;H<E.length;H+=3){let G=E[H]<<16|(E[H+1]??0)<<8|(E[H+2]??0);P.push(Ir[G>>18&63]+Ir[G>>12&63]+(H+1<E.length?Ir[G>>6&63]:"=")+(H+2<E.length?Ir[G&63]:"="))}this.source=P.join("")}},ia=class{load(t,e){let i=new Ur(t);return e?.(i),i}};function Lt(t,e){return t!==void 0?Number(t):e}function An(t,e){return t!==void 0?!!t:e}var Zt=class{constructor(t={}){this.name=t.name||"",this.color=new _i(t.color??16777215),this._em=t.emissive!==void 0,this.emissive=new _i(t.emissive??0),this.emissiveIntensity=Lt(t.emissiveIntensity,1),this.roughness=Lt(t.roughness,t.roughnessMap?1:.5),this.metalness=Lt(t.metalness,t.metalnessMap?1:0),this.opacity=Lt(t.opacity,1),this.transparent=An(t.transparent,!1),this.wireframe=An(t.wireframe,!1),this.side=Lt(t.side,2),this.doubleSided=An(t.doubleSided,!0),this.map=t.map||null,this.normalMap=t.normalMap||null;let e=t.normalScale;this.normalScale=typeof e=="number"?new Jt(e,e):new Jt(Lt(e?.x,1),Lt(e?.y,1)),this.roughnessMap=t.roughnessMap||null,this.metalnessMap=t.metalnessMap||null,this.emissiveMap=t.emissiveMap||null,this.aoMap=t.aoMap||null,this.aoMapIntensity=Lt(t.aoMapIntensity,1),this.bumpMap=t.bumpMap||null,this.bumpScale=Lt(t.bumpScale,1),this.clearcoat=Lt(t.clearcoat,0),this.clearcoatRoughness=Lt(t.clearcoatRoughness,0),this.sheen=Lt(t.sheen,0),this.sheenColor=new _i(t.sheenColor??0),this.sheenRoughness=Lt(t.sheenRoughness,0),this.transmission=Lt(t.transmission,0),this.thickness=Lt(t.thickness,0),this.attenuationColor=new _i(t.attenuationColor??16777215),this.attenuationDistance=Lt(t.attenuationDistance,1/0),this.ior=Lt(t.ior,1.5),this.dispersion=Lt(t.dispersion,0),this.iridescence=Lt(t.iridescence,0),this.iridescenceIOR=Lt(t.iridescenceIOR,1.3)}dispose(){}},Yi=class extends Zt{},ra=class extends Zt{},na=class extends Zt{},sa=class extends Zt{},aa=class extends Zt{},oi=class ho{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this._castShd=!1,this._castShdSet=!1,this._recvShd=!1,this._recvShdSet=!1,this.parent=null,this.children=[],this.userData={},this.position=new Qe,this.rotation=new Mn,this.quaternion=new Er,this.scale=new Qe(1,1,1),this.matrix=new Ti,this.matrixWorld=new Ti,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,i=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),s=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(i,r,s)})}get castShadow(){return this._castShd}set castShadow(e){this._castShd=!!e,this._castShdSet=!0}get receiveShadow(){return this._recvShd}set receiveShadow(e){this._recvShd=!!e,this._recvShdSet=!0}add(...e){for(let i of e)i&&i instanceof ho&&(i.parent&&i.parent.remove(i),i.parent=this,this.children.push(i));return this}remove(...e){for(let i of e){let r=this.children.indexOf(i);r!==-1&&(i.parent=null,this.children.splice(r,1))}return this}traverse(e){let i=new Set,r=[this];for(;r.length>0;){let s=r.pop();if(!s||typeof s!="object"||i.has(s))continue;i.add(s),e(s);let a=s.children;if(Array.isArray(a))for(let f=a.length-1;f>=0;f--)r.push(a[f])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){this.traverse(i=>{Tn(i),(i.matrixAutoUpdate||e)&&i.updateMatrix?.(),i.parent&&i.parent.matrixWorld?i.matrixWorld?.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrix&&i.matrixWorld?.copy(i.matrix)})}lookAt(e,i,r){let s=typeof e=="object"?e:new Qe(e,i,r);this.target instanceof Qe?this.target.copy(s):this.target?.position instanceof Qe&&this.target.position.copy(s),this.updateMatrixWorld(!0);let a=new Ti;a.lookAt(this.position,s,new Qe(0,1,0));let f=a.elements,c=f[0],h=f[4],C=f[8],d=f[1],p=f[5],m=f[9],y=f[2],z=f[6],E=f[10],_=c+p+E;if(_>0){let b=.5/Math.sqrt(_+1);this.quaternion.set((z-m)*b,(C-y)*b,(d-h)*b,.25/b)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new Ti().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new Qe(1,0,0),e)}translateY(e){return this.translateOnAxis(new Qe(0,1,0),e)}translateZ(e){return this.translateOnAxis(new Qe(0,0,1),e)}rotateX(e){return this.rotation.x+=e,this}rotateY(e){return this.rotation.y+=e,this}rotateZ(e){return this.rotation.z+=e,this}_chain(){let e=[];for(let i=this;i&&e.length<64;i=i.parent)e.push(i);return e}_syncWorld(){let e=this._chain();for(let i=e.length-1;i>=0;i--){let r=e[i];r.updateMatrix?.(),r.parent?.matrixWorld?r.matrixWorld.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrixWorld?.copy(r.matrix)}return this.matrixWorld.elements}getWorldPosition(e=new Qe){let i=this._syncWorld();return e.set(i[12],i[13],i[14])}getWorldScale(e=new Qe){let i=this._syncWorld();return e.set(Math.hypot(i[0],i[1],i[2]),Math.hypot(i[4],i[5],i[6]),Math.hypot(i[8],i[9],i[10]))}getWorldDirection(e=new Qe){let i=this._syncWorld();return e.set(i[8],i[9],i[10]).normalize()}getWorldQuaternion(e=new Er){let i=this._chain();e.set(0,0,0,1);for(let r=i.length-1;r>=0;r--)e.multiply(i[r].quaternion);return e}clone(e=!0){let i=typeof this._cloneCustom=="function"?this._cloneCustom():this instanceof Qi?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof Ei?new Ei(this.geometry,this.material):new this.constructor;if(this instanceof Ni){i.color.copy(this.color),i.intensity=this.intensity,i.shadow.copy(this.shadow);let r=this.target;r?.position&&i.target?.position&&i.target.position.copy(r.position),this instanceof Xr&&i.groundColor.copy(this.groundColor)}i.name=this.name,i.position.copy(this.position),i.quaternion.copy(this.quaternion),i.scale.copy(this.scale),i.visible=this.visible,this._castShdSet&&(i.castShadow=this.castShadow),this._recvShdSet&&(i.receiveShadow=this.receiveShadow);try{i.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{i.userData={...this.userData||{}}}if(e)for(let r of this.children)i.add(r.clone(!0));return i}},oa=class extends oi{},Ei=class extends oi{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof Pt?t:t?(Ci("unsupported geometry","BoxGeometry"),new wn(.5,.5,.5)):new Pt,this.material=i instanceof Zt?i:i?(Ci("unsupported material","MeshStandardMaterial"),new Yi({color:13421772})):new Yi}};function Tn(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=mt().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var or=1e4,Or=class extends Ei{constructor(t,e,i=1){super(t,e),this.instanceColor=null,this.isInstancedMesh=!0;let r=Number(i);if(!Number.isFinite(r)||r<0||r>or)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${or})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let a=0;a<this.count;a++){let f=a*16;s[f]=1,s[f+5]=1,s[f+10]=1,s[f+15]=1}this.instanceMatrix=new $t(s,16)}setMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let a=0;a<16;a++){let f=Number(e.elements[a]);r[s+a]=Number.isFinite(f)?f:a%5===0?1:0}}getMatrixAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e||!e.elements)return;let r=this.instanceMatrix.array,s=i*16;if(!(s+16>r.length))for(let a=0;a<16;a++)e.elements[a]=r[s+a]}setColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let a=new Float32Array(this.count*3);a.fill(1),this.instanceColor=new $t(a,3)}let r=this.instanceColor.array,s=i*3;r[s]=Number.isFinite(e.r)?e.r:1,r[s+1]=Number.isFinite(e.g)?e.g:1,r[s+2]=Number.isFinite(e.b)?e.b:1}getColorAt(t,e){let i=Math.floor(Number(t));if(!Number.isFinite(i)||i<0||i>=this.count||!e)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){e.setRGB(1,1,1);return}let r=this.instanceColor.array,s=i*3;e.setRGB(r[s],r[s+1],r[s+2])}dispose(){}},Nn=class uo{constructor(){this.mapSize=new Jt(1024,1024),this.bias=-5e-4,this.normalBias=.015,this.radius=1.5,this.camera={near:.1,far:100,left:-5,right:5,top:5,bottom:-5,fov:50,updateProjectionMatrix:()=>{}}}copy(e){return this.mapSize.copy(e.mapSize),this.bias=Number(e.bias),this.normalBias=Number(e.normalBias),this.radius=Number(e.radius),this}clone(){return new uo().copy(this)}},Ni=class extends oi{constructor(t=16777215,e=1){super(),this.isLight=!0,this.shadow=new Nn,this.color=new _i(t),this.intensity=Number(e),this.type="directional"}},Cn=class extends Ni{constructor(t,e){super(t,e),this.type="ambient"}},Pn=class extends Ni{constructor(t,e){super(t,e),this.target=new oi,this.type="directional"}},Br=class extends Ni{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},Ln=class extends oi{},jr=class extends Ln{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new Qe(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},lr=class extends oi{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return Fi.validate(this),ir(this)}toGLB(){return Fi.validate(this),Nr(this)}toUSDZ(){return Fi.validate(this),Lr(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof Ei){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},Dn=ir,$n=Nr,la=Lr;mt().makePngDeflater=is;var Fi=class{static validate(t){let e=0,i=0,r=0,s=new Set,a=(c,h,C)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${c} (${h}). Found: ${C}`)},f=(c,h)=>{if(!Number.isFinite(h))throw new Error(`SecurityError: Scene reports a non-finite ${c} count (${String(h)}), which cannot be bounds-checked.`);return h};t.traverse(c=>{if(Tn(c),c instanceof Ei||c.geometry?.attributes?.position?.count){if(r++,r>1e3&&a("MESHES",1e3,r),c instanceof Or){let C=f("instance",c.count);(C<0||C>or)&&a("INSTANCES",or,C)}let h=c.geometry;if(h){let C=0;if(h.attributes.position&&(C=f("vertex",h.attributes.position.count),e+=C,e>1e5&&a("VERTICES",1e5,e)),h.index){let d=f("index",h.index.count);i+=d,i>3e5&&a("INDICES",3e5,i);let p=h.index.array;if(p&&C>0){let m=Math.min(d,p.length);for(let y=0;y<m;y++){let z=p[y];if(!Number.isFinite(z)||z<0||z>=C)throw new Error(`SecurityError: Index buffer value (${String(z)}) out of vertex bounds [0, ${C}).`)}}}}if(c.material){let C=c.material;for(let d of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap","bumpMap"])C[d]&&s.add(C[d])}}}),s.size>16&&a("TEXTURES",16,s.size);for(let c of s){let h=c,C=h.image,d=Number(C?.width??h.width??0)||0,p=Number(C?.height??h.height??0)||0;(!Number.isFinite(d)||!Number.isFinite(p)||d>2048||p>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(d,p))}}},ha=class{constructor(t={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=t.canvas||(typeof document<"u"?document.createElement("canvas"):{}),t.viewer&&(this.boundViewer=t.viewer),t.container?.threeLiveViewer&&(this.boundViewer=t.container.threeLiveViewer),t.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=t.canvas.parentElement.threeLiveViewer);let e=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=t.isSandboxed||e,this.containerId=t.containerId||""}setSize(t,e){return this}setPixelRatio(t){return this}setClearColor(t,e=1){let i=new _i(t);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(i.r,i.g,i.b,e),this}clear(){return this}dispose(){}render(t,e){if(this.isSandboxed){Fi.validate(t);let r=(s,a)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(a&&a.length?self.postMessage(s,a):self.postMessage(s))};if(this.hasInitialModelRendered){let s=t.getMeshTransforms(),a={};for(let[f,c]of s.entries())a[f]=Array.from(c);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let s=Dn(t),a=$n(t),f=(s.lights||[]).map(c=>({type:c.type,color:c.color,intensity:c.intensity,position:c.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:f,camera:e?{fov:e.fov||60,position:[e.position.x,e.position.y,e.position.z]}:void 0},[a.buffer])}return}let i=this.boundViewer;!i&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(i=this.domElement.parentElement.threeLiveViewer,this.boundViewer=i),!i&&typeof window<"u"&&(i=window.__three_live_active_viewer__,this.boundViewer=i),i&&typeof i.loadModel=="function"&&(i._hasThreeLiveModelLoaded?typeof i.updateMeshTransforms=="function"&&i.updateMeshTransforms(t.getMeshTransforms()):(i.loadModel(t.toCanvas3D()),i._hasThreeLiveModelLoaded=!0))}};function ua(){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 ca=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=ua(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running&&this.start(),this.running){let e=ua();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}};function fh(){}var Ji=new Proxy(fh,{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:Ji},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ji,construct:()=>Ji}),fa=(()=>{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 Vr(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function Zi(t,e){if(!t||typeof t!="string")return!1;let i=t.trim();if(!i)return!1;try{let r=new URL(i,Vr());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 pa,hr;function ma(t){if(!Zi(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let e=globalThis.trustedTypes;if(!e||typeof e.createPolicy!="function")return t;if(hr===void 0||pa!==e){pa=e;try{hr=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Zi(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{hr=null}}return hr?hr.createScriptURL(t):t}function ph(t){mt().sandboxEngineSrc=t}function zn(){let t=mt().sandboxEngineSrc;if(t)return t;if(fa)return fa;try{if(typeof document>"u")return null;let e=Vr(),i=Array.from(document.querySelectorAll("script[src]"));for(let r of i){let s=r.src;if(!s)continue;let a=new URL(s,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(a)&&Zi(s,{requireSameOrigin:!0}))return s}}catch{}return null}function kn(t,e){if(!Zi(t))throw new Error(`SecurityError: Disallowed ${e} URL "${t}" (http:, https:, or blob: required).`);return new URL(t,Vr()).href}function mh(){let t=zn();if(!t)throw new Error("SecurityError: Could not locate Three-Live bundle URL for worker sandbox; set ThreeLiveElement.sandboxEngineSrc explicitly.");return kn(t,"sandbox engine")}function dh(t){mt().sandboxIframeSrc=t}function da(){let t=mt().sandboxIframeSrc;if(t)return t;let e=zn();if(!e||!Zi(e))return null;let i=new URL(e,Vr());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function gh(){let t=da();if(!t)throw new Error("SecurityError: Could not locate three-live-sandbox.html; set ThreeLiveElement.sandboxIframeSrc explicitly.");return kn(t,"sandbox iframe")}function yh(t){mt().allowClientScripts=t}function ga(){return!!mt().allowClientScripts}function bh(t){return kn(t,"procedural scene script")}var xh="fetch XMLHttpRequest WebSocket WebSocketStream WebTransport EventSource importScripts Request Response Headers navigator WorkerNavigator WorkerLocation RTCPeerConnection RTCDataChannel FontFace FontFaceSet fonts PerformanceObserver ReportingObserver indexedDB IDBFactory caches CacheStorage Cache cookieStore StorageManager FileSystemHandle Worker SharedWorker ServiceWorker ServiceWorkerContainer ServiceWorkerRegistration registration clients BroadcastChannel MessageChannel MessagePort createImageBitmap OffscreenCanvas WebAssembly WorkerGlobalScope DedicatedWorkerGlobalScope trustedTypes TrustedTypePolicyFactory SharedArrayBuffer Atomics".split(" ");function vh(t,e,i){let r=self,s=t.nonce,a=t.engineSrc,f=t.allowedScriptUrl,c=t.allowClientScripts,h=t.revoked,C=r.postMessage.bind(r),d=null;try{d=i?i(r.CompressionStream):null}catch{}let p=null;function m(A,S){let w=()=>S&&S.length?C(A,S):C(A);p?p=p.then(w,w):w()}function y(A){m({type:"ERROR",nonce:s,message:String(A)})}let z=typeof r.importScripts=="function"?r.importScripts.bind(r):null,E=f,_=null;try{let A=a;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let S={createScriptURL:function(v){if(v!==a&&(!f||v!==f))throw new TypeError("Disallowed worker importScripts URL");return v}};c&&(S.createScript=function(v){return String(v)});let w=r.trustedTypes.createPolicy("three-live#worker-boot",S);A=w.createScriptURL(a),f&&(E=w.createScriptURL(f)),c&&typeof w.createScript=="function"&&(_=w.createScript.bind(w))}catch{}z(A)}catch(A){y('Sandbox failed to load "'+a+'" (must be an IIFE bundle like three-live.min.js): '+(A&&A.message||A));return}let b=r.THREE;if(!b||typeof b.Scene!="function"){y('Sandbox "'+a+'" did not install THREE; point sandboxEngineSrc at three-live.min.js.');return}if(Array.isArray(e)){let A=r.__THREE_LIVE_REGISTRY__;for(let S=0;S<e.length;S++)if(typeof e[S]=="function")try{e[S](b,A)}catch{}}function $(A,S,w){let v=r;for(;v&&v!==Object.prototype;){if(!w&&v!==r)try{delete v[A]}catch{}if(!w||v===r||Object.prototype.hasOwnProperty.call(v,A))try{Object.defineProperty(v,A,w?{value:S,writable:!1,configurable:!1}:{value:S,writable:!1,configurable:!1,enumerable:!1})}catch{}try{v=Object.getPrototypeOf(v)}catch{break}}}for(let A=0;A<h.length;A++)$(h[A],void 0);$("performance",Object.freeze({now:function(){return Date.now()}}));let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],M=!1;function N(A,S){if(A.type==="3D_MODEL_READY"){if(M)return;M=!0}if(A.nonce=s,A.type==="3D_MODEL_READY"&&d&&A.glbBuffer instanceof ArrayBuffer){let w=A.glbBuffer;p=(p||Promise.resolve()).then(()=>d.glb(new Uint8Array(w))).then(v=>{v.buffer!==w&&(A.glbBuffer=v.byteOffset===0&&v.byteLength===v.buffer.byteLength?v.buffer:v.slice().buffer),C(A,[A.glbBuffer])},()=>C(A,[w]));return}S&&S.length?m(A,S):m(A)}$("postMessage",function(A,S){if(!A||T.indexOf(A.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");N(A,S)},!0);let k=!1;r.onmessage=function(A){let S=A&&A.data;if(!S||S.nonce!==s||S.type!=="EXECUTE"&&S.type!=="EXECUTE_URL"||k)return;k=!0;let w=S.texturePack;if(w&&typeof w=="object"){let v=Object.create(null),P=0;for(let H of Object.keys(w)){let G=w[H],x=G&&G.size;P<64&&/^[0-9a-f]{16}$/.test(H)&&(x===256||x===512||x===1024)&&G.rgba instanceof Uint8Array&&G.rgba.length===x*x*4&&(v[H]=Object.freeze({size:x,rgba:G.rgba}),P++)}r.__three_live_texture_pack__=Object.freeze(v)}try{let v=new b.Scene,P=new b.PerspectiveCamera(60,1,.1,1e3),H=new b.WebGLRenderer({isSandboxed:!0});if(S.type==="EXECUTE_URL"){if(!f||S.scriptUrl!==f||typeof z!="function"){y("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let G=E||f,x=z;if(z=null,E=null,r.THREE=b,r.scene=v,r.camera=P,r.renderer=H,x(G),typeof r.__THREE_LIVE_SCENE__=="function"){let V=r.__THREE_LIVE_SCENE__(b,v,P,H);V&&typeof V.toGLB=="function"&&(v=V)}else r.scene&&typeof r.scene.toGLB=="function"&&(v=r.scene)}else{if(!c){y("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let G=_?(0,eval)(_(`(function (THREE, scene, camera, renderer) {
|
|
370
378
|
return (function () {
|
|
371
|
-
`+
|
|
379
|
+
`+S.script+`
|
|
372
380
|
;
|
|
373
381
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
374
382
|
})();
|
|
375
383
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
376
|
-
`+
|
|
384
|
+
`+S.script+`
|
|
377
385
|
;
|
|
378
386
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
379
|
-
})();`);p=null;let $=j(m,T,R,U);$&&typeof $.toGLB=="function"&&(T=$)}if(!w){m.SceneQuotaValidator&&m.SceneQuotaValidator.validate(T);let j=T.toGLB(),$=j instanceof ArrayBuffer?j:j.buffer.slice(j.byteOffset,j.byteOffset+j.byteLength);v({type:"3D_MODEL_READY",glbBuffer:$},[$])}u({type:"DONE",nonce:r})}catch(T){d(T&&T.message||T)}}},u({type:"READY",nonce:r})}function Qi(t,e,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,a={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:s,revoked:Jo},o=(Re().workerExtensionInstallers??[]).map(n=>`(${n.toString()})`).join(",");return`'use strict';(${Qo.toString()})(${JSON.stringify(a)},[${o}]);`}function Ps(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 xt=0;function Ds(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function en(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var tn=1024,rn=256;function Ns(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let i=t[e];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function er(t,e){if(!t||typeof t!="object")return null;let i=t;if(i.nonce!==e)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,tn)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!Ns(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let a=Object.create(null),o=r;for(let n of s){if(n.length>rn||n==="__proto__"||n==="constructor"||n==="prototype")return null;let u=o[n];if(!Ns(u))return null;a[n]=u}return{type:"3D_UPDATE_TRANSFORMS",transforms:a}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function sn(t){let e=en(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Rs(t,e,i,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":i();return;case"ERROR":i(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function an(t,e,i,r){let s=Ds(),a=Qi(e,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o=document.createElement("iframe");o.setAttribute("sandbox","allow-scripts"),o.setAttribute("aria-hidden","true"),o.tabIndex=-1,o.style.display="none",o.src=i,xt++;let n=!1,u=!1,d={modelDispatched:!1},h,l=()=>{if(n||u)return;let x=o.contentWindow;!x||typeof x.postMessage!="function"||(u=!0,x.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:a,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:a,script:t.script},"*"))},p=()=>{},m=x=>{if(n||!o.contentWindow||x.source!==o.contentWindow)return;let w=x.data;if(w&&typeof w=="object"&&w.type==="IFRAME_READY"){l();return}let v=er(w,s);v&&Rs(v,r,p,d)};p=()=>{n||(n=!0,h!==void 0&&clearTimeout(h),xt=Math.max(0,xt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",m),typeof o.remove=="function"?o.remove():o.parentNode&&o.parentNode.removeChild(o))},h=setTimeout(()=>{n||(p(),Ps(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",m),o.onload=()=>{l()},o.onerror=()=>{p(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let y=document.body||document.documentElement;if(!y||typeof y.appendChild!="function"){p();let x=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(x),x}return y.appendChild(o),{terminate:p}}function Es(t,e,i,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(xt>=32)return r(`SecurityError: ${xt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let s;try{s=qo()}catch(p){let m=p instanceof Error?p.message:String(p);return r(m,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let p;try{p=Ko()}catch(m){let y=m instanceof Error?m.message:String(m);return r(y,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(an(t,s,p,i))}catch(m){return Promise.reject(m)}}let a=Ds(),o=Qi(s,a,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),n;try{let p=new Blob([o],{type:"application/javascript"}),m=URL.createObjectURL(p);try{let y=Ts(m);n=new Worker(y)}finally{URL.revokeObjectURL(m)}}catch(p){let m=p instanceof Error?p.message:String(p);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${m}`,"Security Error: Failed to start Worker sandbox.")}xt++;let u=!1,d={modelDispatched:!1},h,l=()=>{u||(u=!0,h!==void 0&&clearTimeout(h),xt=Math.max(0,xt-1),n.terminate())};return h=setTimeout(()=>{u||(l(),Ps(i))},3e3),n.onmessage=p=>{let m=er(p.data,a);m&&Rs(m,i,l,d)},n.onerror=p=>{l(),i.onError?.(new Error(`Worker execution error: ${p.message}`))},t.kind==="url"?n.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:a}):n.postMessage({type:"EXECUTE",script:t.script,nonce:a}),Promise.resolve({terminate:l})}function Ls(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 zs=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},ks={execute(t,e,i,r){let s=zs(i),a=Ls(e,s);if(a)return a;try{sn(t)}catch(o){let n=o instanceof Error?o.message:String(o);return s(n,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??As()?Es({kind:"script",script:t},e,i,s):s(ba,xa)},executeUrl(t,e,i){let r=zs(i),s=Ls(e,r);if(s)return s;let a;try{a=Zo(t)}catch(o){let n=o instanceof Error?o.message:String(o);return r(n,"Security Error: disallowed scene script URL.")}return Es({kind:"url",scriptUrl:a},e,i,r)}},yi=new Set;function vt(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;yi.has(i)||(yi.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function tr(){return Array.from(yi)}function ir(){yi.clear()}var rr=class extends Nt{constructor(t={}){vt("ShaderMaterial","MeshStandardMaterial");let e=t.uniforms||{},i=e.color?.value??e.uColor?.value??e.diffuse?.value??t.color;super({color:i!==void 0?i:8421504,opacity:e.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=e}},Cs=rr,wt=class extends Ie{constructor(t=[],e=[],i=1,r=0){super();let s=Number(i)||1,a=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),o=a+1,n=[],u=[],d=[],h=[],l=new ve,p=new ve,m=new ve,y=(v,_)=>_.set(t[v*3]||0,t[v*3+1]||0,t[v*3+2]||0),x=(v,_)=>{let f=v.clone().normalize();n.push(f.x*s,f.y*s,f.z*s),u.push(_.x,_.y,_.z),d.push(Math.atan2(f.z,-f.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,f.y)))/Math.PI)},w=(v,_,f)=>{let g=n.length/3,T=a===0?new ve().subVectors(f,_).cross(new ve().subVectors(v,_)).normalize():null;x(v,T||v.clone().normalize()),x(_,T||_.clone().normalize()),x(f,T||f.clone().normalize()),h.push(g,g+1,g+2)};for(let v=0;v<e.length;v+=3){y(e[v],l),y(e[v+1],p),y(e[v+2],m);let _=[];for(let f=0;f<=o;f++){_[f]=[];let g=l.clone().lerp(m,f/o),T=p.clone().lerp(m,f/o),R=o-f;for(let U=0;U<=R;U++)_[f][U]=R===0?g.clone():g.clone().lerp(T,U/R)}for(let f=0;f<o;f++)for(let g=0;g<2*(o-f)-1;g++){let T=g>>1;(g&1)===0?w(_[f][T+1],_[f+1][T],_[f][T]):w(_[f][T+1],_[f+1][T+1],_[f+1][T])}}this.setFromBuffers(n,u,d,h)}},on=wt,Is=class extends wt{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e)}},bi=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Us=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],Fs=class extends wt{constructor(t=1,e=0){super(bi,Us,t,e)}},Ee=(1+Math.sqrt(5))/2,$s=class extends wt{constructor(t=1,e=0){super([-1,Ee,0,1,Ee,0,-1,-Ee,0,1,-Ee,0,0,-1,Ee,0,1,Ee,0,-1,-Ee,0,1,-Ee,Ee,0,-1,Ee,0,1,-Ee,0,-1,-Ee,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],t,e)}},Ze=1/Ee,Os=class extends wt{constructor(t=1,e=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-Ze,-Ee,0,-Ze,Ee,0,Ze,-Ee,0,Ze,Ee,-Ze,-Ee,0,-Ze,Ee,0,Ze,-Ee,0,Ze,Ee,0,-Ee,0,-Ze,Ee,0,-Ze,-Ee,0,Ze,Ee,0,Ze],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e)}},Bs=class extends Vi{constructor(t=1,e=1,i=4,r=8){let s=Math.max(1e-4,Number(t)||1),a=Math.max(0,Number.isFinite(Number(e))?Number(e):1)*.5,o=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),n=[];for(let u=-1;u<=1;u+=2)for(let d=0;d<=o;d++){if(u>0&&d===0&&a===0)continue;let h=(u<0?d/o-1:d/o)*(Math.PI/2);n.push(new ot(Math.max(0,Math.cos(h)*s),u*a+Math.sin(h)*s))}super(n,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},sr=class extends Ie{constructor(t=.5,e=1,i=32,r=1,s=0,a=Math.PI*2){super();let o=Math.max(1e-4,Number(e)||1),n=Number(t),u=Number.isFinite(n)?Math.max(0,n):o*.5,d=Math.max(o,u),h=Math.min(d*.999,Math.min(o,u)),l=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),p=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),m=Number.isFinite(Number(s))?Number(s):0,y=Number.isFinite(Number(a))?Number(a):Math.PI*2,x=[],w=[],v=[],_=[];for(let f=0;f<=p;f++){let g=h+f/p*(d-h);for(let T=0;T<=l;T++){let R=m+T/l*y,U=Math.cos(R),j=Math.sin(R);if(x.push(g*U,g*j,0),w.push(0,0,1),v.push(g/d*U*.5+.5,g/d*j*.5+.5),f<p&&T<l){let $=f*(l+1)+T,L=$+l+1;g>1e-6&&_.push($,L,$+1),_.push(L,L+1,$+1)}}}this.setFromBuffers(x,w,v,_)}},js=class extends sr{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},ar=class extends Xe{constructor(t={}){super({roughness:.35,metalness:.1,side:2,...t});let e=Number(t.size);this.size=Number.isFinite(e)?Math.max(.002,Math.min(2,e)):.05,this.sizeAttenuation=t.sizeAttenuation!==!1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},xi=class extends Xe{constructor(t={}){super({roughness:.4,metalness:.1,side:2,...t});let e=Number(t.linewidth);this.linewidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},Vs=class extends xi{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function Gs(t,e){let i=t?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=t?.index?.array,a=Math.min(8192,Math.floor((s?s.length:i.count)/3)),o=p=>`${Math.round((r[p*3]||0)*1e4)},${Math.round((r[p*3+1]||0)*1e4)},${Math.round((r[p*3+2]||0)*1e4)}`,n=e===void 0,u=n?1:Math.cos(e*Math.PI/180),d={},h=[],l=(p,m)=>h.push(r[p*3]||0,r[p*3+1]||0,r[p*3+2]||0,r[m*3]||0,r[m*3+1]||0,r[m*3+2]||0);for(let p=0;p<a;p++){let m=s?s[p*3]:p*3,y=s?s[p*3+1]:p*3+1,x=s?s[p*3+2]:p*3+2,w=r[m*3]||0,v=r[m*3+1]||0,_=r[m*3+2]||0,f=(r[y*3]||0)-w,g=(r[y*3+1]||0)-v,T=(r[y*3+2]||0)-_,R=(r[x*3]||0)-w,U=(r[x*3+1]||0)-v,j=(r[x*3+2]||0)-_,$=g*j-T*U,L=T*R-f*j,E=f*U-g*R,B=Math.hypot($,L,E);if(!n&&B<1e-8)continue;B>0&&($/=B,L/=B,E/=B);let I=[m,y,x];for(let c=0;c<3;c++){let k=I[c],K=I[(c+1)%3],A=o(k),z=o(K);if(A===z)continue;let S=A<z?`${A}|${z}`:`${z}|${A}`,b=d[S];b?b.m||(b.m=1,b.nx*$+b.ny*L+b.nz*E<=u&&l(k,K)):(d[S]={va:k,vb:K,nx:$,ny:L,nz:E,m:n?1:0},n&&l(k,K))}}if(!n){let p=Object.keys(d);for(let m=0;m<p.length;m++){let y=d[p[m]];y&&!y.m&&l(y.va,y.vb)}}return new Float32Array(h)}var Hs=class extends Ie{constructor(t){super(),this.setAttribute("position",new Oe(Gs(t),3)),this.__isSegmentPairs=!0}},Ws=class extends Ie{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new Oe(Gs(t,i),3)),this.__isSegmentPairs=!0}};function nn(t,e,i=1){let r=new Ie;r.__baked=!0;let s=t?.attributes?.position;if(!s?.array||s.count<2)return r;let a=s.array,o=t.index?.array,n=t.__isSegmentPairs?"segments":e,u=o?o.length:s.count,d=Math.min(4096,Math.max(0,n==="segments"?Math.floor(u/2):n==="loop"&&u>=3?u:u-1));if(d===0)return r;t.computeBoundingBox();let h=t.boundingBox,l=h&&h.max.distanceTo(h.min)||1,p=Math.max(.0015,Math.min(.025,l*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),m=[],y=[],x=[],w=[];for(let v=0;v<d;v++){let _=n==="segments"?v*2:v,f=n==="segments"?v*2+1:(v+1)%u,g=o?o[_]:_,T=o?o[f]:f,R=a[g*3]||0,U=a[g*3+1]||0,j=a[g*3+2]||0,$=(a[T*3]||0)-R,L=(a[T*3+1]||0)-U,E=(a[T*3+2]||0)-j,B=Math.hypot($,L,E);if(B<1e-6)continue;let I=$/B,c=L/B,k=E/B,K=(Math.abs(c)<.9?Math.hypot(k,I):Math.hypot(k,c))||1,A=Math.abs(c)<.9?k/K:0,z=Math.abs(c)<.9?0:-k/K,S=Math.abs(c)<.9?-I/K:c/K,b=c*S-k*z,O=k*A-I*S,X=I*z-c*A,te=m.length/3,re=[[A,z,S],[b,O,X],[-A,-z,-S],[-b,-O,-X]];for(let Z=0;Z<2;Z++){let ne=R+Z*$,pe=U+Z*L,xe=j+Z*E;for(let ie=0;ie<4;ie++){let he=re[ie];m.push(ne+he[0]*p,pe+he[1]*p,xe+he[2]*p),y.push(he[0],he[1],he[2]),x.push(ie/4,Z)}}for(let Z=0;Z<4;Z++){let ne=(Z+1)%4;w.push(te+Z,te+ne,te+4+ne,te+Z,te+4+ne,te+4+Z)}}return m.length>0&&r.setFromBuffers(m,y,x,w),r}function ln(t,e=.05){let i=new Ie;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,a=r.count,o=Math.min(a,5e3),n=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),u=[],d=[],h=[],l=[];for(let p=0;p<o;p++){let m=a<=5e3?p:Math.floor(p*a/o),y=s[m*3]||0,x=s[m*3+1]||0,w=s[m*3+2]||0,v=p*6;for(let _=0;_<6;_++){let f=bi[_*3],g=bi[_*3+1],T=bi[_*3+2];u.push(y+f*n,x+g*n,w+T*n),d.push(f,g,T),h.push(.5,.5)}for(let _=0;_<24;_++)l.push(v+Us[_])}return i.setFromBuffers(u,d,h,l),i}var zt=class extends yt{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},s=e instanceof Xe?e:i==="points"?new ar(r):new xi(r),a=t instanceof Ie?t:new Ie;super(a,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=a}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let t=this._lineMode==="points";if(t){let e=this._sourceGeo?.attributes?.color;if(e?.array&&e.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=e.array,r=Math.min(e.count,64),s=0,a=0,o=0;for(let n=0;n<r;n++)s+=i[n*3]||0,a+=i[n*3+1]||0,o+=i[n*3+2]||0;this.material.color.setRGB(s/r,a/r,o/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?ln(this._sourceGeo,this.material?.size??.05):nn(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},qs=class extends zt{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},Xs=class extends zt{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Ks=class extends zt{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},vi=class extends fi{constructor(t,e,i=0,r=Math.PI/3,s=0,a=2){super(t,e,i,a),this.target=new Ye,this.type="spot";let o=Number(r);this.angle=Number.isFinite(o)?Math.max(.01,Math.min(Math.PI/2,o)):Math.PI/3;let n=Number(s);this.penumbra=Number.isFinite(n)?Math.max(0,Math.min(1,n)):0}},or=class extends Wi{constructor(t,e,i){vt("HemisphereLight","AmbientLight"),super(t,i),this.groundColor=new nt(e??4473924)}},Ys=or,Zs={Vector2:ot,Vector3:ve,Vector4:qr,Euler:Oi,Quaternion:ui,Matrix4:pt,Matrix3:Xr,Color:nt,MathUtils:Yr,BufferAttribute:Oe,Float32BufferAttribute:Zr,Uint16BufferAttribute:Jr,Uint32BufferAttribute:Qr,BufferGeometry:Ie,BoxGeometry:Bi,PlaneGeometry:es,SphereGeometry:ts,CylinderGeometry:ji,ConeGeometry:is,TorusGeometry:rs,TorusKnotGeometry:as,Curve:Mt,Curve3:Mt,LineCurve3:os,QuadraticBezierCurve3:ns,CubicBezierCurve3:ls,CatmullRomCurve3:us,LatheGeometry:Vi,TubeGeometry:hs,PolyhedronGeometry:wt,IcosahedronGeometry:$s,OctahedronGeometry:Fs,DodecahedronGeometry:Os,TetrahedronGeometry:Is,CapsuleGeometry:Bs,RingGeometry:sr,CircleGeometry:js,WireframeGeometry:Hs,EdgesGeometry:Ws,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:di,DataTexture:cs,TextureLoader:ds,Material:Xe,MeshStandardMaterial:Nt,MeshBasicMaterial:ps,MeshLambertMaterial:fs,MeshPhongMaterial:ms,MeshPhysicalMaterial:gs,PointsMaterial:ar,LineBasicMaterial:xi,LineDashedMaterial:Vs,ShaderMaterial:rr,RawShaderMaterial:Cs,Object3D:Ye,Group:ys,Mesh:yt,InstancedMesh:pi,Line:zt,LineLoop:qs,LineSegments:Xs,Points:Ks,Light:Rt,AmbientLight:Wi,DirectionalLight:qi,PointLight:fi,SpotLight:vi,HemisphereLight:or,RectAreaLight:Ys,Camera:Xi,PerspectiveCamera:mi,Scene:Wt,WebGLRenderer:xs,Clock:Ms,SceneQuotaValidator:bt,exportSceneToCanvas3D:Ki,exportSceneToGLB:Yi,exportSceneToUSDZ:bs,generateUSDZ:zr,glbToUSDZ:zi,sceneToCanvas3D:jt,sceneToGLB:ei,sceneToUSDZ:ai,authorScriptRunner:ks,getAuthorWarnings:tr,clearAuthorWarnings:ir};Object.freeze(bt),Object.freeze(bt.prototype),Object.freeze(Wt.prototype),Object.freeze(Zs);var lt=new Proxy(Zs,{get:(t,e)=>{if(e in t)return t[e];let i=Re().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&vt(`THREE.${e}`,"no-op proxy"),Et)},has:(t,e)=>{if(e in t)return!0;let i=Re().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Mi=Re();if(Mi.threeNamespace=lt,Mi.workerExtensionInstallers)for(let t of Mi.workerExtensionInstallers)t(lt,Mi);var Xt={name:"three_author",THREE:lt},un=Xt,_e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof _e.THREE>"u"&&(_e.THREE=lt),typeof _e.requestAnimationFrame!="function"&&(_e.requestAnimationFrame=t=>(typeof t=="function"&&typeof _e.__three_live_raf_cb__!="function"&&(_e.__three_live_raf_cb__=t),_e.__three_live_in_step__||vt("requestAnimationFrame","single-frame static evaluation"),0)),typeof _e.cancelAnimationFrame!="function"&&(_e.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=lt,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=Xt,t.ThreeLivePlugins.three_author=Xt,t.ThreeLivePlugins["three-author"]=Xt}{wo(),Go(),wa(lt,Re()),cr(lt,Re()),dr(lt,Re());let t=new Wt,e=new mi(45,1,.1,1e3);e.position.set(0,2,5),_e.scene=t,_e.camera=e,typeof _e.window>"u"&&(_e.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof _e.document>"u"&&(_e.document={createElement:()=>({getContext:()=>Et,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(_e,"__three_live_reset_scene__",{value:function(){ir(),delete _e.__three_live_sim_time_ms__,delete _e.__three_live_raf_cb__,delete _e.__three_live_in_step__,delete _e.__three_live_interactivity_fired__,t=new Wt,e=new mi(45,1,.1,1e3),e.position.set(0,2,5),_e.scene=t,_e.camera=e},writable:!1,configurable:!1}),Object.defineProperty(_e,"__three_live_step_js__",{value:function(o,n){_e.__three_live_sim_time_ms__=o*1e3,_e.__three_live_in_step__=!0;try{let u=!_e.__three_live_interactivity_fired__&&o>=.15;u&&(_e.__three_live_interactivity_fired__=!0);let d=new Set;if(_e.scene?.traverse?.(h=>{let l=h?.userData?.interactivity;if(!(!l||typeof l!="object"||d.has(l))){if(d.add(l),u){for(let p of[l.onSelect,l.onClick,l.toggle,l.onActivate])if(typeof p=="function"){try{p.call(l,h)}catch{}break}}if(typeof l.update=="function")try{l.update(n,o)}catch{}}}),typeof _e.animate=="function"){let h=!!_e.__three_live_animate_takes_dt__;if(!h){let l=String(_e.animate).match(/^(?:function\s*\w*\s*\(\s*([^,)=]*)|\(\s*([^,)=]*)|([a-zA-Z_$][\w$]*)\s*=>)/),p=((l?.[1]||l?.[2]||l?.[3])??"").trim().toLowerCase();h=p==="dt"||p==="delta"||p==="deltatime"||p==="step"}h?_e.animate(n,o):_e.animate(o,n)}else typeof _e.__three_live_raf_cb__=="function"&&_e.__three_live_raf_cb__(o*1e3)}finally{_e.__three_live_in_step__=!1}},writable:!1,configurable:!1});let i=function(o){if(o==null)return null;let n=2e4,u=0,d=new Set,h=(l,p)=>{if(--n<0||p>32)return;if(l===null||typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number")return Number.isFinite(l)?l:void 0;if(l instanceof Ye)return l.name||(l.name=`Node_ref_${++u}`),l.name;if(l instanceof ve)return[Number.isFinite(l.x)?l.x:0,Number.isFinite(l.y)?l.y:0,Number.isFinite(l.z)?l.z:0];if(l instanceof nt)return`#${l.getHex().toString(16).padStart(6,"0")}`;if(typeof l!="object"||d.has(l))return;d.add(l);let m;if(Array.isArray(l)){m=[];for(let y of l)m.push(h(y,p+1)??null)}else{m={};for(let y of Object.keys(l)){if(y==="__proto__"||y==="prototype"||y==="constructor")continue;let x=h(l[y],p+1);x!==void 0&&(m[y]=x)}}return d.delete(l),m};try{return h(o,0)??null}catch{return null}},r=15*1024,s=1e3*4,a=function(o){let n=Ii(o);if(!n)return{};let u=JSON.stringify({...o,...n});return u.length>r&&(vt(`userData.xr larger than ${r} characters`,"canonical XR traits only"),u=JSON.stringify(n)),{xr_normalized_json:u,xr_scenecore_json:JSON.stringify(Br(n)),xr_hubs_json:JSON.stringify(jr(n))}};Object.defineProperty(_e,"__three_live_extract_scene_raw__",{value:function(){let o=[],n=[],u=[],d=[];function h(c){if(!c)return null;let k=d.indexOf(c);if(k===-1){d.push(c);let K="";c.map&&(typeof c.map=="string"?K=c.map:typeof c.map.source=="string"&&c.map.source?K=c.map.source:typeof c.map.image=="string"&&(K=c.map.image)),n.push({name:c.name||`Material_${n.length}`,base_color:[c.color.r,c.color.g,c.color.b,c.opacity!==void 0?c.opacity:1],metallic:c.metalness!==void 0?c.metalness:0,roughness:c.roughness!==void 0?c.roughness:.5,double_sided:c.side===2||c.doubleSided,base_color_texture:K||null,clearcoat:c.clearcoat||0,clearcoat_roughness:c.clearcoatRoughness||0,transmission:c.transmission||0,ior:c.ior!==void 0?c.ior:1.5,thickness:c.thickness||0}),k=n.length-1}return k}let l=(c,k)=>typeof c=="number"&&Number.isFinite(c)?c:k,p=[],m=[],y=[],x=!1,w=_e.scene||t,v=new pt().compose({x:l(w.position?.x,0),y:l(w.position?.y,0),z:l(w.position?.z,0)},{x:l(w.quaternion?.x,0),y:l(w.quaternion?.y,0),z:l(w.quaternion?.z,0),w:l(w.quaternion?.w,1)},{x:l(w.scale?.x,1),y:l(w.scale?.y,1),z:l(w.scale?.z,1)}),_=new Set([w]);{let c=new Set([w]),k=Array.isArray(w.children)?[...w.children]:[],K=0;for(;k.length>0&&K<=s;){let A=k.pop();if(!(!(A instanceof Ye)||c.has(A))&&(c.add(A),K++,Array.isArray(A.children)))for(let z of A.children)k.push(z)}if(K>s)return{meshes:[],nodes:new Array(K),materials:[],lights:[]}}let f=[],g=(c,k)=>{let K=Array.isArray(c.children)?c.children:[];for(let A=K.length-1;A>=0;A--)f.push([K[A],k])};g(w,-1);let T=c=>{let k=[];for(let A=c;A>=0&&k.length<=p.length;A=p[A].parent)k.push(A);let K=v.clone();for(let A=k.length-1;A>=0;A--){let z=p[k[A]];K.multiply(new pt().compose({x:z.translation[0],y:z.translation[1],z:z.translation[2]},{x:z.rotation[0],y:z.rotation[1],z:z.rotation[2],w:z.rotation[3]},{x:z.scale[0],y:z.scale[1],z:z.scale[2]}))}return K};for(;f.length>0;){let[c,k]=f.pop();if(!(c instanceof Ye)||_.has(c))continue;_.add(c);let K=[l(c.position?.x,0),l(c.position?.y,0),l(c.position?.z,0)],A=[l(c.quaternion?.x,0),l(c.quaternion?.y,0),l(c.quaternion?.z,0),l(c.quaternion?.w,1)],z=[l(c.scale?.x,1),l(c.scale?.y,1),l(c.scale?.z,1)];Hi(c);let S=-1,b=c.geometry,O=b?.attributes?.position;if(O&&O.array&&O.count>0){S=o.length;let xe=null,ie=c.userData?.variants;if(ie&&typeof ie=="object"){let he=new Map;for(let ee of Object.keys(ie)){if(!ee||ee==="__proto__"||ee==="constructor"||ee==="prototype")continue;let le=ie[ee],ue=le instanceof Xe?le:le&&typeof le=="object"?new Nt(le):null;if(!ue)continue;let J=m.indexOf(ee);if(J===-1&&m.length<256&&(J=m.length,m.push(ee)),J===-1)continue;let se=h(ue);if(se!==null){let P=he.get(se);P||(P=[],he.set(se,P)),P.push(J)}}if(he.size>0){let ee=[];for(let[le,ue]of he.entries())ee.push({material:le,variants:ue});xe=JSON.stringify({mappings:ee})}}o.push({name:c.name||`Mesh_${o.length}`,raw_positions:O.array,raw_normals:b.attributes.normal?b.attributes.normal.array:null,raw_uvs:b.attributes.uv?b.attributes.uv.array:null,raw_indices:b.index?b.index.array:null,vertex_count:O.count,material_index:h(c.material instanceof Xe?c.material:null),variant_mappings_json:xe})}let X=i(c.userData?.xr),te=!!c.userData?.xr&&X!==null,re=i(c.userData?.interactivity),Z=p.length,ne=c instanceof pi&&c.count>0&&c.instanceMatrix?.array,pe=[];if(re&&typeof re=="object")for(let xe of["onSelect","onHoverIn","onHoverOut","onStart","onReceive"])re[xe]&&pe.push(xe);if(p.push({name:typeof c.name=="string"?c.name.slice(0,1024):"",parent:k,translation:K,rotation:A,scale:z,mesh:S,visible:c.visible!==!1,xr_traits_json:te?JSON.stringify(X):null,interactivity_events_json:pe.length>0?JSON.stringify(pe):null,interactivity_raw_json:re?JSON.stringify(re):null,...te?a(X):{},...ne?{instance_matrices:c.instanceMatrix.array.subarray(0,c.count*16),instance_colors:c.instanceColor?.array?c.instanceColor.array.subarray(0,c.count*3):null}:{}}),y.push(re),re&&(x=!0),p.length>s)break;if(c instanceof Rt){let xe=T(Z).elements,ie=l(xe[12],0),he=l(xe[13],0),ee=l(xe[14],0),le={light_type:c.type,color:[c.color.r,c.color.g,c.color.b],intensity:c.intensity,position:[ie,he,ee]};if(c instanceof vi||c instanceof qi){let ue=c.target,J=l(ue?.position?.x,0),se=l(ue?.position?.y,0),P=l(ue?.position?.z,0);if(ue?.parent){let M=[];for(let N=ue;N&&N!==w&&M.length<64;N=N.parent)M.push(N);let D=new pt;for(let N=M.length-1;N>=0;N--){let C=M[N];C.updateMatrix(),D.multiply(C.matrix)}J=l(D.elements[12],J),se=l(D.elements[13],se),P=l(D.elements[14],P)}if(c instanceof vi){let M=J-ie,D=se-he,N=P-ee,C=Math.hypot(M,D,N);C>1e-6?(M/=C,D/=C,N/=C):(M=0,D=-1,N=0),le.direction=[M,D,N];let H=Math.max(.01,Math.min(Math.PI/2,l(c.angle,Math.PI/3))),V=Math.max(0,Math.min(1,l(c.penumbra,0)));le.outer_cone_angle=H,le.inner_cone_angle=Math.max(0,H*(1-V)),le.range=Math.max(0,l(c.distance,0))}else le.position=[ie-J,he-se,ee-P]}else c instanceof fi&&(le.range=Math.max(0,l(c.distance,0)));u.push(le)}g(c,Z)}let R=[],U=(c,k,K,A,z="warning")=>{R.push(A?{code:c,severity:z,node:A,message:k,hint:K}:{code:c,severity:z,message:k,hint:K})};for(let c of tr()){let[k,K]=c.includes("ShaderMaterial")||c.includes("RawShaderMaterial")||c.includes("unsupported material")?["TL101","Use THREE.MeshStandardMaterial({ color, metalness, roughness }) instead of custom GLSL shaders."]:c.includes("requestAnimationFrame")?["TL104","Static exports evaluate a single frame; use userData.xr.orbit, userData.interactivity, or define function animate(t) for time-stepped rendering."]:c.includes("Controls")?["TL106","Remove THREE.OrbitControls; <three-live camera-controls> and <xr-live> provide built-in camera controls."]:c.includes("EffectComposer")||c.includes("Pass")?["TL107",'Use <three-live bloom="0.5" outline-selected> or mesh.userData.xr = { bloom, outline } instead of EffectComposer passes.']:/THREE\.[A-Za-z0-9_]*Loader\b/.test(c)?["TL103","Load external models via <three-live src='...'> or <xr-anchor src='...'>; camera controls and post-processing are managed by the host viewer."]:/THREE\.(?:Points|Line|Sprite)/.test(c)?["TL102","glTF mesh export requires triangle surface meshes (THREE.Mesh or THREE.InstancedMesh). Replace Points/Sprite with InstancedMesh + SphereGeometry, and replace Line/LineSegments with TubeGeometry or CylinderGeometry."]:/THREE\.(?:Canvas|Data|Video|Framebuffer)Texture/.test(c)?["TL102","Procedural DOM/pixel textures cannot run in the headless sandbox; use MeshPhysicalMaterial PBR properties, vertex colors, or THREE.TextGeometry / userData.text."]:c.includes("larger than")?["TL105","Keep per-node userData.xr metadata under 15 KB."]:["TL102","Use supported geometries (Box, Sphere, Cylinder, Cone, Torus, TorusKnot, Plane, Lathe, Tube, Extrude, Shape, TextGeometry, CSG, or BufferGeometry) and DirectionalLight / PointLight / AmbientLight."];U(k,c,K)}let j=new Set;for(let c of p)typeof c.name=="string"&&c.name.trim().length>0&&j.add(c.name);for(let c=0;c<p.length;c++){let k=p[c],K=typeof k.name=="string"&&k.name.trim().length>0?k.name:"",A=K||k.mesh>=0&&o[k.mesh]?.name||`Node_${c}`;!K&&j.has(A)&&(A=`Node_${c}`);let z=y[c],S=null;if(k.xr_traits_json)try{S=JSON.parse(k.xr_traits_json)}catch{S=null}if((S||z)&&!K&&(k.name=A,j.add(A),U("TL205",`Interactive node '${A}' is missing an explicit mesh.name (auto-named '${A}').`,"Assign a unique mesh.name = '...' so raycasting, meshclick, and WebMCP tools can target it.",A,"info")),S!==null){for(let O of To(S,A))R.push(O);let b=(O,X)=>{typeof X=="string"&&X.trim().length>0&&!j.has(X)&&U("TL204",`userData.xr.${O} on node '${A}' references target node '${X}', which does not exist in scene.`,`Ensure a node with mesh.name = '${X}' is added to scene via scene.add().`,A)};if(S.orbit&&typeof S.orbit=="object"&&b("orbit.target",S.orbit.target),typeof S.spawner=="string"?b("spawner.template",S.spawner):S.spawner&&typeof S.spawner=="object"&&b("spawner.template",S.spawner.template),S.agent&&typeof S.agent=="object"){let O=S.agent.target;O!=="user"&&O!=="camera"&&b("agent.target",O)}if(S.ik&&typeof S.ik=="object"&&S.ik.enabled!==!1){b("ik.root",S.ik.root),b("ik.mid",S.ik.mid),b("ik.effector",S.ik.effector),Array.isArray(S.ik.target)||b("ik.target",S.ik.target);let O=S.ik.pole??S.ik.poleTarget;Array.isArray(O)||b("ik.pole",O)}}if(z&&typeof z=="object"){let b=new Set(["onSelect","onHoverIn","onHoverOut","onStart","onReceive"]),O=new Set(["interpolate","toggleTransform","setProperty","toggleVisibility","cycleMaterialColor","playAnimation","stopAnimation","sendEvent"]),X=(re,Z)=>{let ne=Array.isArray(re)?re:[re];for(let pe of ne){if(!pe||typeof pe!="object")continue;let xe=pe.action;typeof xe=="string"&&!O.has(xe)&&U("TL201",`Unrecognized action '${xe}' in userData.interactivity.${Z} on node '${A}'.`,"Supported interactivity actions: interpolate, toggleTransform, setProperty, toggleVisibility, cycleMaterialColor, playAnimation, stopAnimation, sendEvent.",A);let ie=pe.target;typeof ie=="string"&&ie.length>0&&!j.has(ie)&&U("TL204",`userData.interactivity.${Z} on node '${A}' references target node '${ie}', which does not exist in scene.`,`Ensure a node with mesh.name = '${ie}' is added to scene via scene.add().`,A);let he=pe.targetNode;typeof he=="number"&&(he<0||he>=p.length)&&U("TL204",`userData.interactivity.${Z} on node '${A}' references out-of-range targetNode ${he} (scene has ${p.length} nodes).`,"Prefer referencing nodes by name via target: '<nodeName>'.",A)}},te=z;for(let re of Object.keys(te))if(!b.has(re)){let Z=re.toLowerCase(),ne=Z==="onclick"||Z==="ontap"||Z==="onpointerdown"?"onSelect":Z==="onhover"||Z==="onmouseenter"?"onHoverIn":Z==="onmouseleave"?"onHoverOut":null;U("TL201",ne?`Unrecognized trigger '${re}' in userData.interactivity on node '${A}'; did you mean '${ne}'?`:`Unrecognized trigger '${re}' in userData.interactivity on node '${A}'.`,"Supported interactivity triggers: onSelect, onHoverIn, onHoverOut, onStart, onReceive.",A)}for(let re of["onSelect","onHoverIn","onHoverOut","onStart"])te[re]&&X(te[re],re);if(te.onReceive&&typeof te.onReceive=="object")for(let[re,Z]of Object.entries(te.onReceive))X(Z,`onReceive.${re}`)}}let $=(c,k)=>c.every((K,A)=>K===k[A]),L=i({interactivity:w.userData?.interactivity,gltfExtensions:{KHR_interactivity:w.userData?.gltfExtensions?.KHR_interactivity}}),E=!!(L?.interactivity??L?.gltfExtensions?.KHR_interactivity),B=null;(x||E)&&(B=ur(p.map((c,k)=>({name:c.name,...c.mesh>=0?{mesh:c.mesh}:{},...$(c.translation,[0,0,0])?{}:{translation:c.translation},...$(c.rotation,[0,0,0,1])?{}:{rotation:c.rotation},...$(c.scale,[1,1,1])?{}:{scale:c.scale},extras:y[k]?{interactivity:y[k]}:void 0})),o.map(c=>({primitives:[{material:c.material_index??0}]})),L??void 0));let I=_e.camera||e;return{meshes:o,nodes:p,materials:n,lights:u,interactivity_json:B?JSON.stringify(B):null,variants_json:m.length>0?JSON.stringify({variants:m.map(c=>({name:c}))}):null,diagnostics_json:R.length>0?JSON.stringify(R):null,camera:{fov:I.fov||45,position:I.position?[I.position.x,I.position.y,I.position.z]:[0,2,5],target:I.target?[I.target.x,I.target.y,I.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var hn=lt;return ya(lr)})();
|
|
387
|
+
})();`);_=null;let x=G(b,v,P,H);x&&typeof x.toGLB=="function"&&(v=x)}if(!M){b.SceneQuotaValidator&&b.SceneQuotaValidator.validate(v);let G=v.toGLB(),x=G instanceof ArrayBuffer?G:G.buffer.slice(G.byteOffset,G.byteOffset+G.byteLength);N({type:"3D_MODEL_READY",glbBuffer:x},[x])}m({type:"DONE",nonce:s})}catch(v){y(v&&v.message||v)}},m({type:"READY",nonce:s})}function En(t,e,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,a={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:s,revoked:xh},f=(mt().workerExtensionInstallers??[]).map(c=>`(${c.toString()})`).join(",");return`'use strict';(${vh.toString()})(${JSON.stringify(a)},[${f}],(${is.toString()}));`}function ya(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 Ri=0;function ba(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Mh(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var wh=1024,_h=256;function xa(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let i=t[e];if(typeof i!="number"||!Number.isFinite(i))return!1}return!0}function Fn(t,e){if(!t||typeof t!="object")return null;let i=t;if(i.nonce!==e)return null;switch(i.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof i.message=="string"?i.message:String(i.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,wh)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!xa(s))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:r}}if(r&&typeof r=="object"){let s=Object.keys(r);if(s.length>1e3)return null;let a=Object.create(null),f=r;for(let c of s){if(c.length>_h||c==="__proto__"||c==="constructor"||c==="prototype")return null;let h=f[c];if(!xa(h))return null;a[c]=h}return{type:"3D_UPDATE_TRANSFORMS",transforms:a}}return null}case"3D_MODEL_READY":{let r=i.glbBuffer;return!(r instanceof ArrayBuffer)||r.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:r}}default:return null}}function Sh(t){let e=Mh(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function va(t,e,i,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":i();return;case"ERROR":i(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function Ah(t,e,i,r){let s=ba(),a=En(e,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),f=document.createElement("iframe");f.setAttribute("sandbox","allow-scripts"),f.setAttribute("aria-hidden","true"),f.tabIndex=-1,f.style.display="none",f.src=i,Ri++;let c=!1,h=!1,C={modelDispatched:!1},d,p=()=>{if(c||h)return;let E=f.contentWindow;!E||typeof E.postMessage!="function"||(h=!0,E.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:a,scriptUrl:t.scriptUrl,texturePack:t.texturePack??null}:{type:"SANDBOX_RUN",nonce:s,workerSource:a,script:t.script,texturePack:t.texturePack??null},"*"))},m=()=>{},y=E=>{if(c||!f.contentWindow||E.source!==f.contentWindow)return;let _=E.data;if(_&&typeof _=="object"&&_.type==="IFRAME_READY"){p();return}let b=Fn(_,s);b&&va(b,r,m,C)};m=()=>{c||(c=!0,d!==void 0&&clearTimeout(d),Ri=Math.max(0,Ri-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",y),typeof f.remove=="function"?f.remove():f.parentNode&&f.parentNode.removeChild(f))},d=setTimeout(()=>{c||(m(),ya(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",y),f.onload=()=>{p()},f.onerror=()=>{m(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let z=document.body||document.documentElement;if(!z||typeof z.appendChild!="function"){m();let E=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(E),E}return z.appendChild(f),{terminate:m}}function Ma(t,e,i,r){if(e==="worker"&&typeof Worker>"u")return r("SecurityError: Web Workers are unavailable for sandboxed execution.","Security Error: Web Workers unavailable.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("SecurityError: DOM unavailable for iframe sandbox execution.","Security Error: DOM unavailable for iframe sandbox.");if(Ri>=32)return r(`SecurityError: ${Ri} workers running, meeting SECURITY_3D_MAX_CONCURRENT_TASKS (32).`,"Security Error: too many concurrent sandboxed scripts.");let s;try{s=mh()}catch(m){let y=m instanceof Error?m.message:String(m);return r(y,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let m;try{m=gh()}catch(y){let z=y instanceof Error?y.message:String(y);return r(z,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Ah(t,s,m,i))}catch(y){return Promise.reject(y)}}let a=ba(),f=En(s,a,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),c;try{let m=new Blob([f],{type:"application/javascript"}),y=URL.createObjectURL(m);try{let z=ma(y);c=new Worker(z)}finally{URL.revokeObjectURL(y)}}catch(m){let y=m instanceof Error?m.message:String(m);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${y}`,"Security Error: Failed to start Worker sandbox.")}Ri++;let h=!1,C={modelDispatched:!1},d,p=()=>{h||(h=!0,d!==void 0&&clearTimeout(d),Ri=Math.max(0,Ri-1),c.terminate())};return d=setTimeout(()=>{h||(p(),ya(i))},3e3),c.onmessage=m=>{let y=Fn(m.data,a);y&&va(y,i,p,C)},c.onerror=m=>{p(),i.onError?.(new Error(`Worker execution error: ${m.message}`))},t.kind==="url"?c.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:a,texturePack:t.texturePack??null}):c.postMessage({type:"EXECUTE",script:t.script,nonce:a,texturePack:t.texturePack??null}),Promise.resolve({terminate:p})}function wa(t,e){return t!=="worker"&&t!=="iframe"?e(`SecurityError: Unsupported sandbox="${t}"; require "worker" or "iframe".`,`Security Error: sandbox="${t}" is not permitted.`):null}var _a=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},Sa={execute(t,e,i,r){let s=_a(i),a=wa(e,s);if(a)return a;try{Sh(t)}catch(f){let c=f instanceof Error?f.message:String(f);return s(c,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??ga()?Ma({kind:"script",script:t,texturePack:r?.texturePack},e,i,s):s(bo,xo)},executeUrl(t,e,i,r){let s=_a(i),a=wa(e,s);if(a)return a;let f;try{f=bh(t)}catch(c){let h=c instanceof Error?c.message:String(c);return s(h,"Security Error: disallowed scene script URL.")}return Ma({kind:"url",scriptUrl:f,texturePack:r?.texturePack},e,i,s)}},Hr=new Set;function Ci(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;Hr.has(i)||(Hr.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function Rn(){return Array.from(Hr)}function In(){Hr.clear()}var Un=class extends Yi{constructor(t={}){Ci("ShaderMaterial","MeshStandardMaterial");let e=t.uniforms||{},i=e.color?.value??e.uColor?.value??e.diffuse?.value??t.color;super({color:i!==void 0?i:8421504,opacity:e.opacity?.value??t.opacity??1,transparent:!!t.transparent,wireframe:!!t.wireframe,side:t.side}),this.uniforms=e}},Aa=Un,ji=class extends Pt{constructor(t=[],e=[],i=1,r=0){super();let s=Number(i)||1,a=Math.max(0,Math.min(7,Math.floor(Number(r)||0))),f=a+1,c=[],h=[],C=[],d=[],p=new Qe,m=new Qe,y=new Qe,z=(b,$)=>$.set(t[b*3]||0,t[b*3+1]||0,t[b*3+2]||0),E=(b,$)=>{let T=b.clone().normalize();c.push(T.x*s,T.y*s,T.z*s),h.push($.x,$.y,$.z),C.push(Math.atan2(T.z,-T.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,T.y)))/Math.PI)},_=(b,$,T)=>{let M=c.length/3,N=a===0?new Qe().subVectors(T,$).cross(new Qe().subVectors(b,$)).normalize():null;E(b,N||b.clone().normalize()),E($,N||$.clone().normalize()),E(T,N||T.clone().normalize()),d.push(M,M+1,M+2)};for(let b=0;b<e.length;b+=3){z(e[b],p),z(e[b+1],m),z(e[b+2],y);let $=[];for(let T=0;T<=f;T++){$[T]=[];let M=p.clone().lerp(y,T/f),N=m.clone().lerp(y,T/f),k=f-T;for(let A=0;A<=k;A++)$[T][A]=k===0?M.clone():M.clone().lerp(N,A/k)}for(let T=0;T<f;T++)for(let M=0;M<2*(f-T)-1;M++){let N=M>>1;(M&1)===0?_($[T][N+1],$[T+1][N],$[T][N]):_($[T][N+1],$[T+1][N+1],$[T+1][N])}}this.setFromBuffers(c,h,C,d)}},Th=ji,Ta=class extends ji{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e)}},On=t=>Array.from(t,e=>parseInt(e,36)),Gr=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Na=On("024043035052125153134142"),Ca=class extends ji{constructor(t=1,e=0){super(Gr,Na,t,e)}},Mt=(1+Math.sqrt(5))/2,Pa=class extends ji{constructor(t=1,e=0){super([-1,Mt,0,1,Mt,0,-1,-Mt,0,1,-Mt,0,0,-1,Mt,0,1,Mt,0,-1,-Mt,0,1,-Mt,Mt,0,-1,Mt,0,1,-Mt,0,-1,-Mt,0,1],On("0b505101707a0ab1595b4ba2a7671839434232636838949524b62a867981"),t,e)}},li=1/Mt,La=class extends ji{constructor(t=1,e=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-li,-Mt,0,-li,Mt,0,li,-Mt,0,li,Mt,-li,-Mt,0,-li,Mt,0,li,-Mt,0,li,Mt,0,-Mt,0,-li,Mt,0,-li,-Mt,0,li,Mt,0,li],On("3b737f3fd7jh7h676fh48h8aha680g8g282a0c101i0ig6a262d6df2gi2i323di19i9bib34ec4c0408b95b5jbj7j5eje4j4h1ce1e5159"),t,e)}},Da=class extends Sn{constructor(t=1,e=1,i=4,r=8){let s=Math.max(1e-4,Number(t)||1),a=Math.max(0,Number.isFinite(Number(e))?Number(e):1)*.5,f=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),c=[];for(let h=-1;h<=1;h+=2)for(let C=0;C<=f;C++){if(h>0&&C===0&&a===0)continue;let d=(h<0?C/f-1:C/f)*(Math.PI/2);c.push(new Jt(Math.max(0,Math.cos(d)*s),h*a+Math.sin(d)*s))}super(c,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},Bn=class extends Pt{constructor(t=.5,e=1,i=32,r=1,s=0,a=Math.PI*2){super();let f=Math.max(1e-4,Number(e)||1),c=Number(t),h=Number.isFinite(c)?Math.max(0,c):f*.5,C=Math.max(f,h),d=Math.min(C*.999,Math.min(f,h)),p=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),m=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),y=Number.isFinite(Number(s))?Number(s):0,z=Number.isFinite(Number(a))?Number(a):Math.PI*2,E=[],_=[],b=[],$=[];for(let T=0;T<=m;T++){let M=d+T/m*(C-d);for(let N=0;N<=p;N++){let k=y+N/p*z,A=Math.cos(k),S=Math.sin(k);if(E.push(M*A,M*S,0),_.push(0,0,1),b.push(M/C*A*.5+.5,M/C*S*.5+.5),T<m&&N<p){let w=T*(p+1)+N,v=w+p+1;M>1e-6&&$.push(w,v,w+1),$.push(v,v+1,w+1)}}}this.setFromBuffers(E,_,b,$)}},$a=class extends Bn{constructor(t=1,e=32,i=0,r=Math.PI*2){super(0,t,e,1,i,r)}},jn=class extends Zt{constructor(t={}){super({roughness:.35,metalness:.1,side:2,...t});let e=Number(t.size);this.size=Number.isFinite(e)?Math.max(.002,Math.min(2,e)):.05,this.sizeAttenuation=t.sizeAttenuation!==!1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},Wr=class extends Zt{constructor(t={}){super({roughness:.4,metalness:.1,side:2,...t});let e=Number(t.linewidth);this.linewidth=Number.isFinite(e)?Math.max(.5,Math.min(20,e)):1,t.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},za=class extends Wr{constructor(t={}){super(t),this.dashSize=Number(t.dashSize)||3,this.gapSize=Number(t.gapSize)||1,this.scale=Number(t.scale)||1}};function ka(t,e){let i=t?.attributes?.position;if(!i?.array||i.count<3)return new Float32Array(0);let r=i.array,s=t?.index?.array,a=Math.min(8192,Math.floor((s?s.length:i.count)/3)),f=m=>`${Math.round((r[m*3]||0)*1e4)},${Math.round((r[m*3+1]||0)*1e4)},${Math.round((r[m*3+2]||0)*1e4)}`,c=e===void 0,h=c?1:Math.cos(e*Math.PI/180),C={},d=[],p=(m,y)=>d.push(r[m*3]||0,r[m*3+1]||0,r[m*3+2]||0,r[y*3]||0,r[y*3+1]||0,r[y*3+2]||0);for(let m=0;m<a;m++){let y=s?s[m*3]:m*3,z=s?s[m*3+1]:m*3+1,E=s?s[m*3+2]:m*3+2,_=r[y*3]||0,b=r[y*3+1]||0,$=r[y*3+2]||0,T=(r[z*3]||0)-_,M=(r[z*3+1]||0)-b,N=(r[z*3+2]||0)-$,k=(r[E*3]||0)-_,A=(r[E*3+1]||0)-b,S=(r[E*3+2]||0)-$,w=M*S-N*A,v=N*k-T*S,P=T*A-M*k,H=Math.hypot(w,v,P);if(!c&&H<1e-8)continue;H>0&&(w/=H,v/=H,P/=H);let G=[y,z,E];for(let x=0;x<3;x++){let V=G[x],Y=G[(x+1)%3],Z=f(V),q=f(Y);if(Z===q)continue;let X=Z<q?`${Z}|${q}`:`${q}|${Z}`,F=C[X];F?F.m||(F.m=1,F.nx*w+F.ny*v+F.nz*P<=h&&p(V,Y)):(C[X]={va:V,vb:Y,nx:w,ny:v,nz:P,m:c?1:0},c&&p(V,Y))}}if(!c){let m=Object.keys(C);for(let y=0;y<m.length;y++){let z=C[m[y]];z&&!z.m&&p(z.va,z.vb)}}return new Float32Array(d)}var Ea=class extends Pt{constructor(t){super(),this.setAttribute("position",new $t(ka(t),3)),this.__isSegmentPairs=!0}},Fa=class extends Pt{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new $t(ka(t,i),3)),this.__isSegmentPairs=!0}};function Nh(t,e,i=1){let r=new Pt;r.__baked=!0;let s=t?.attributes?.position;if(!s?.array||s.count<2)return r;let a=s.array,f=t.index?.array,c=t.__isSegmentPairs?"segments":e,h=f?f.length:s.count,C=Math.min(4096,Math.max(0,c==="segments"?Math.floor(h/2):c==="loop"&&h>=3?h:h-1));if(C===0)return r;t.computeBoundingBox();let d=t.boundingBox,p=d&&d.max.x>=d.min.x&&d.max.distanceTo(d.min)||1,m=Math.max(.0015,Math.min(.025,p*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),y=[],z=[],E=[],_=[];for(let b=0;b<C;b++){let $=c==="segments"?b*2:b,T=c==="segments"?b*2+1:(b+1)%h,M=f?f[$]:$,N=f?f[T]:T,k=a[M*3]||0,A=a[M*3+1]||0,S=a[M*3+2]||0,w=(a[N*3]||0)-k,v=(a[N*3+1]||0)-A,P=(a[N*3+2]||0)-S,H=Math.hypot(w,v,P);if(H<1e-6)continue;let G=w/H,x=v/H,V=P/H,Y=(Math.abs(x)<.9?Math.hypot(V,G):Math.hypot(V,x))||1,Z=Math.abs(x)<.9?V/Y:0,q=Math.abs(x)<.9?0:-V/Y,X=Math.abs(x)<.9?-G/Y:x/Y,F=x*X-V*q,Q=V*Z-G*X,L=G*q-x*Z,ee=y.length/3,ae=[[Z,q,X],[F,Q,L],[-Z,-q,-X],[-F,-Q,-L]];for(let be=0;be<2;be++){let Ne=k+be*w,De=A+be*v,Be=S+be*P;for(let je=0;je<4;je++){let Ve=ae[je];y.push(Ne+Ve[0]*m,De+Ve[1]*m,Be+Ve[2]*m),z.push(Ve[0],Ve[1],Ve[2]),E.push(je/4,be)}}for(let be=0;be<4;be++){let Ne=(be+1)%4;_.push(ee+be,ee+Ne,ee+4+Ne,ee+be,ee+4+Ne,ee+4+be)}}return y.length>0&&r.setFromBuffers(y,z,E,_),r}function Ch(t,e=.05){let i=new Pt;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,a=r.count,f=Math.min(a,5e3),c=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),h=[],C=[],d=[],p=[];for(let m=0;m<f;m++){let y=a<=5e3?m:Math.floor(m*a/f),z=s[y*3]||0,E=s[y*3+1]||0,_=s[y*3+2]||0,b=m*6;for(let $=0;$<6;$++){let T=Gr[$*3],M=Gr[$*3+1],N=Gr[$*3+2];h.push(z+T*c,E+M*c,_+N*c),C.push(T,M,N),d.push(.5,.5)}for(let $=0;$<24;$++)p.push(b+Na[$])}return i.setFromBuffers(h,C,d,p),i}var Qi=class extends Ei{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},s=e instanceof Zt?e:i==="points"?new jn(r):new Wr(r),a=t instanceof Pt?t:new Pt;super(a,s),this.isLine=!0,this._lineMode=i,this._sourceGeo=a}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let t=this._lineMode==="points";if(t){let e=this._sourceGeo?.attributes?.color;if(e?.array&&e.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let i=e.array,r=Math.min(e.count,64),s=0,a=0,f=0;for(let c=0;c<r;c++)s+=i[c*3]||0,a+=i[c*3+1]||0,f+=i[c*3+2]||0;this.material.color.setRGB(s/r,a/r,f/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?Ch(this._sourceGeo,this.material?.size??.05):Nh(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Ra=class extends Qi{constructor(t,e){super(t,e,"loop"),this.isLineLoop=!0}},Ia=class extends Qi{constructor(t,e){super(t,e,"segments"),this.isLineSegments=!0}},Ua=class extends Qi{constructor(t,e){super(t,e,"points"),this.isPoints=!0}},qr=class extends Br{constructor(t,e,i=0,r=Math.PI/3,s=0,a=2){super(t,e,i,a),this.target=new oi,this.type="spot";let f=Number(r);this.angle=Number.isFinite(f)?Math.max(.01,Math.min(Math.PI/2,f)):Math.PI/3;let c=Number(s);this.penumbra=Number.isFinite(c)?Math.max(0,Math.min(1,c)):0}},Xr=class extends Ni{constructor(t,e,i){super(t,i),this.type="hemisphere",this.groundColor=new _i(e??4473924),this.position.set(0,1,0)}},Oa=class extends Cn{constructor(t,e){Ci("RectAreaLight","AmbientLight"),super(t,e)}},Ba={Vector2:Jt,Vector3:Qe,Vector4:Rs,Euler:Mn,Quaternion:Er,Matrix4:Ti,Matrix3:Is,Color:_i,MathUtils:Os,BufferAttribute:$t,Float32BufferAttribute:Bs,Uint16BufferAttribute:js,Uint32BufferAttribute:Vs,BufferGeometry:Pt,BoxGeometry:wn,PlaneGeometry:Hs,SphereGeometry:Gs,CylinderGeometry:_n,ConeGeometry:Ws,TorusGeometry:qs,TorusKnotGeometry:Ys,Curve:Bi,Curve3:Bi,LineCurve3:Js,QuadraticBezierCurve3:Zs,CubicBezierCurve3:Qs,CatmullRomCurve3:Ks,LatheGeometry:Sn,TubeGeometry:ea,PolyhedronGeometry:ji,IcosahedronGeometry:Pa,OctahedronGeometry:Ca,DodecahedronGeometry:La,TetrahedronGeometry:Ta,CapsuleGeometry:Da,RingGeometry:Bn,CircleGeometry:$a,WireframeGeometry:Ea,EdgesGeometry:Fa,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,BasicShadowMap:0,PCFShadowMap:1,PCFSoftShadowMap:2,VSMShadowMap:3,Texture:Ur,DataTexture:ta,TextureLoader:ia,Material:Zt,MeshStandardMaterial:Yi,MeshBasicMaterial:ra,MeshLambertMaterial:na,MeshPhongMaterial:sa,MeshPhysicalMaterial:aa,PointsMaterial:jn,LineBasicMaterial:Wr,LineDashedMaterial:za,ShaderMaterial:Un,RawShaderMaterial:Aa,Object3D:oi,Group:oa,Mesh:Ei,InstancedMesh:Or,Line:Qi,LineLoop:Ra,LineSegments:Ia,Points:Ua,LightShadow:Nn,Light:Ni,AmbientLight:Cn,DirectionalLight:Pn,PointLight:Br,SpotLight:qr,HemisphereLight:Xr,RectAreaLight:Oa,Camera:Ln,PerspectiveCamera:jr,Scene:lr,WebGLRenderer:ha,Clock:ca,SceneQuotaValidator:Fi,exportSceneToCanvas3D:Dn,exportSceneToGLB:$n,exportSceneToUSDZ:la,generateUSDZ:ws,glbToUSDZ:fn,sceneToCanvas3D:ir,sceneToGLB:Nr,sceneToUSDZ:Lr,authorScriptRunner:Sa,warnUnsupported:Ci,getAuthorWarnings:Rn,clearAuthorWarnings:In};Object.freeze(Fi),Object.freeze(Fi.prototype),Object.freeze(lr.prototype),Object.freeze(Ba);var hi=new Proxy(Ba,{get:(t,e)=>{if(e in t)return t[e];let i=mt().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&Ci(`THREE.${e}`,"no-op proxy"),Ji)},has:(t,e)=>{if(e in t)return!0;let i=mt().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),Yr=mt();if(Yr.threeNamespace=hi,Yr.workerExtensionInstallers)for(let t of Yr.workerExtensionInstallers)t(hi,Yr);var ur={name:"three_author",THREE:hi},Ph=ur,at=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof at.THREE>"u"&&(at.THREE=hi),typeof at.requestAnimationFrame!="function"&&(at.requestAnimationFrame=t=>(typeof t=="function"&&typeof at.__three_live_raf_cb__!="function"&&(at.__three_live_raf_cb__=t),at.__three_live_in_step__||Ci("requestAnimationFrame","single-frame static evaluation"),0)),typeof at.cancelAnimationFrame!="function"&&(at.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=hi,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=ur,t.ThreeLivePlugins.three_author=ur,t.ThreeLivePlugins["three-author"]=ur}{Ul(),ch(),wo(hi,mt()),es(hi,mt()),ts(hi,mt()),Ao(hi,mt()),Xo(hi,mt()),mt().tslUsdzSerializer=ll;let t=new lr,e=new jr(45,1,.1,1e3);e.position.set(0,2,5),at.scene=t,at.camera=e,typeof at.window>"u"&&(at.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof at.document>"u"&&(at.document={createElement:()=>({getContext:()=>Ji,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(at,"__three_live_reset_scene__",{value:function(){In(),Rr=1234567,delete at.__three_live_sim_time_ms__,delete at.__three_live_raf_cb__,delete at.__three_live_in_step__,delete at.__three_live_interactivity_fired__,t=new lr,e=new jr(45,1,.1,1e3),e.position.set(0,2,5),at.scene=t,at.camera=e},writable:!1,configurable:!1}),Object.defineProperty(at,"__three_live_step_js__",{value:function(f,c){at.__three_live_sim_time_ms__=f*1e3,at.__three_live_in_step__=!0;try{let h=!at.__three_live_interactivity_fired__&&f>=.15;h&&(at.__three_live_interactivity_fired__=!0);let C=new Set;if(at.scene?.traverse?.(d=>{let p=d?.userData?.interactivity;if(!(!p||typeof p!="object"||C.has(p))){if(C.add(p),h){for(let m of[p.onSelect,p.onClick,p.toggle,p.onActivate])if(typeof m=="function"){try{m.call(p,d)}catch{}break}}if(typeof p.update=="function")try{p.update(c,f)}catch{}}}),typeof at.animate=="function"){let d=!!at.__three_live_animate_takes_dt__;if(!d){let p=String(at.animate).match(/^(?:function\s*\w*\s*\(\s*([^,)=]*)|\(\s*([^,)=]*)|([a-zA-Z_$][\w$]*)\s*=>)/),m=((p?.[1]||p?.[2]||p?.[3])??"").trim().toLowerCase();d=m==="dt"||m==="delta"||m==="deltatime"||m==="step"}d?at.animate(c,f):at.animate(f,c)}else typeof at.__three_live_raf_cb__=="function"&&at.__three_live_raf_cb__(f*1e3)}finally{at.__three_live_in_step__=!1}},writable:!1,configurable:!1});let i=function(f){if(f==null)return null;let c=2e4,h=0,C=new Set,d=(p,m)=>{if(--c<0||m>32)return;if(p===null||typeof p=="string"||typeof p=="boolean")return p;if(typeof p=="number")return Number.isFinite(p)?p:void 0;if(p instanceof oi)return p.name||(p.name=`Node_ref_${++h}`),p.name;if(p instanceof Qe)return[Number.isFinite(p.x)?p.x:0,Number.isFinite(p.y)?p.y:0,Number.isFinite(p.z)?p.z:0];if(p instanceof _i)return`#${p.getHex().toString(16).padStart(6,"0")}`;if(typeof p!="object"||C.has(p))return;C.add(p);let y;if(Array.isArray(p)){y=[];for(let z of p)y.push(d(z,m+1)??null)}else{y={};for(let z of Object.keys(p)){if(z==="__proto__"||z==="prototype"||z==="constructor")continue;let E=d(p[z],m+1);E!==void 0&&(y[z]=E)}}return C.delete(p),y};try{return d(f,0)??null}catch{return null}},r=15*1024,s=1e3*4,a=function(f){let c=$r(f);if(!c)return{};let h=JSON.stringify({...f,...c});return h.length>r&&(Ci(`userData.xr larger than ${r} characters`,"canonical XR traits only"),h=JSON.stringify(c)),{xr_normalized_json:h,xr_scenecore_json:JSON.stringify($s(c)),xr_hubs_json:JSON.stringify(zs(c))}};Object.defineProperty(at,"__three_live_extract_scene_raw__",{value:function(){let f=[],c=[],h=[],C=[];function d(x){if(!x)return null;let V=C.indexOf(x);if(V===-1){C.push(x);let Y=Ie=>{if(!Ie)return"";if(typeof Ie=="string")return Ie;let Me=Ie;return typeof Me.source=="string"&&Me.source?Me.source:typeof Me.image=="string"?Me.image:""},Z=Y(x.map),q=x._packPbr?.(),X=q?.mrUri||Y(x.roughnessMap||x.metalnessMap),F=q?.normUri||Y(x.normalMap),Q=x.normalScale,L=typeof Q=="number"?Q:Q&&typeof Q=="object"?(Number(Q.x??1)+Number(Q.y??1))*.5:1,ee=q?.normUri?q.normScale??1:Number.isFinite(L)?Math.max(0,L):1,ae=Y(x.aoMap),be=Number(x.aoMapIntensity),Ne=Number.isFinite(be)?Math.max(0,Math.min(1,be)):1,De=Y(x.emissiveMap),Be=Number.isFinite(x.emissiveIntensity)?Math.max(0,x.emissiveIntensity):1,je=x.emissive.r>0||x.emissive.g>0||x.emissive.b>0?[x.emissive.r*Be,x.emissive.g*Be,x.emissive.b*Be]:De&&!x._em?[Be,Be,Be]:[0,0,0],Ve=x._serializeTslGraph?.();c.push({name:x.name||`Material_${c.length}`,base_color:[x.color.r,x.color.g,x.color.b,x.opacity!==void 0?x.opacity:1],metallic:x.metalness!==void 0?x.metalness:0,roughness:x.roughness!==void 0?x.roughness:.5,double_sided:x.side===2||x.doubleSided,alpha_blend:!!(x.transparent||(x.opacity??1)<1),base_color_texture:Z||null,metallic_roughness_texture:X||null,normal_texture:F||null,normal_scale:ee,emissive_factor:je,emissive_texture:De||null,occlusion_texture:ae||null,occlusion_strength:Ne,clearcoat:x.clearcoat||0,clearcoat_roughness:x.clearcoatRoughness||0,transmission:x.transmission||0,ior:x.ior!==void 0?x.ior:1.5,thickness:x.thickness||0,tsl_json:Ve?JSON.stringify(Ve):null}),V=c.length-1}return V}let p=(x,V)=>typeof x=="number"&&Number.isFinite(x)?x:V,m=[],y=[],z=[],E=!1,_=at.scene||t,b=new Ti().compose({x:p(_.position?.x,0),y:p(_.position?.y,0),z:p(_.position?.z,0)},{x:p(_.quaternion?.x,0),y:p(_.quaternion?.y,0),z:p(_.quaternion?.z,0),w:p(_.quaternion?.w,1)},{x:p(_.scale?.x,1),y:p(_.scale?.y,1),z:p(_.scale?.z,1)}),$=new Set([_]);{let x=new Set([_]),V=Array.isArray(_.children)?[..._.children]:[],Y=0;for(;V.length>0&&Y<=s;){let Z=V.pop();if(!(!(Z instanceof oi)||x.has(Z))&&(x.add(Z),Y++,Array.isArray(Z.children)))for(let q of Z.children)V.push(q)}if(Y>s)return{meshes:[],nodes:new Array(Y),materials:[],lights:[]}}let T=[],M=(x,V)=>{let Y=Array.isArray(x.children)?x.children:[];for(let Z=Y.length-1;Z>=0;Z--)T.push([Y[Z],V])};M(_,-1);let N=x=>{let V=[];for(let Z=x;Z>=0&&V.length<=m.length;Z=m[Z].parent)V.push(Z);let Y=b.clone();for(let Z=V.length-1;Z>=0;Z--){let q=m[V[Z]];Y.multiply(new Ti().compose({x:q.translation[0],y:q.translation[1],z:q.translation[2]},{x:q.rotation[0],y:q.rotation[1],z:q.rotation[2],w:q.rotation[3]},{x:q.scale[0],y:q.scale[1],z:q.scale[2]}))}return Y};for(;T.length>0;){let[x,V]=T.pop();if(!(x instanceof oi)||$.has(x))continue;$.add(x);let Y=[p(x.position?.x,0),p(x.position?.y,0),p(x.position?.z,0)],Z=[p(x.quaternion?.x,0),p(x.quaternion?.y,0),p(x.quaternion?.z,0),p(x.quaternion?.w,1)],q=[p(x.scale?.x,1),p(x.scale?.y,1),p(x.scale?.z,1)];Tn(x);let X=-1,F=x.geometry,Q=F?.attributes?.position;if(Q&&Q.array&&Q.count>0){X=f.length;let Be=null,je=x.userData?.variants;if(je&&typeof je=="object"){let Ve=new Map;for(let Ie of Object.keys(je)){if(!Ie||Ie==="__proto__"||Ie==="constructor"||Ie==="prototype")continue;let Me=je[Ie],ze=Me instanceof Zt?Me:Me&&typeof Me=="object"?new Yi(Me):null;if(!ze)continue;let Se=y.indexOf(Ie);if(Se===-1&&y.length<256&&(Se=y.length,y.push(Ie)),Se===-1)continue;let He=d(ze);if(He!==null){let J=Ve.get(He);J||(J=[],Ve.set(He,J)),J.push(Se)}}if(Ve.size>0){let Ie=[];for(let[Me,ze]of Ve.entries())Ie.push({material:Me,variants:ze});Be=JSON.stringify({mappings:Ie})}}f.push({name:x.name||`Mesh_${f.length}`,raw_positions:Q.array,raw_normals:F.attributes.normal?F.attributes.normal.array:null,raw_uvs:F.attributes.uv?F.attributes.uv.array:null,raw_indices:F.index?F.index.array:null,vertex_count:Q.count,material_index:d(x.material instanceof Zt?x.material:null),variant_mappings_json:Be})}let L=jo(i(x.userData?.xr),x),ee=!!x.userData?.xr&&L!==null,ae=i(x.userData?.interactivity),be=m.length,Ne=x instanceof Or&&x.count>0&&x.instanceMatrix?.array,De=[];if(ae&&typeof ae=="object")for(let Be of["onSelect","onHoverIn","onHoverOut","onStart","onReceive"])ae[Be]&&De.push(Be);if(m.push({name:typeof x.name=="string"?x.name.slice(0,1024):"",parent:V,translation:Y,rotation:Z,scale:q,mesh:X,visible:x.visible!==!1,...x instanceof Ni||!x._castShdSet&&!x._recvShdSet?{}:{cast_shadow:!!x.castShadow,receive_shadow:x._recvShdSet?!!x.receiveShadow:!!(x.receiveShadow||x.castShadow)},xr_traits_json:ee?JSON.stringify(L):null,interactivity_events_json:De.length>0?JSON.stringify(De):null,interactivity_raw_json:ae?JSON.stringify(ae):null,...ee?a(L):{},...Ne?{instance_matrices:x.instanceMatrix.array.subarray(0,x.count*16),instance_colors:x.instanceColor?.array?x.instanceColor.array.subarray(0,x.count*3):null}:{}}),z.push(ae),ae&&(E=!0),m.length>s)break;if(x instanceof Ni){let Be=N(be).elements,je=p(Be[12],0),Ve=p(Be[13],0),Ie=p(Be[14],0),Me={light_type:x.type,color:[x.color.r,x.color.g,x.color.b],intensity:x.intensity,position:[je,Ve,Ie]};if(x instanceof qr||x instanceof Pn){let ze=x.target,Se=p(ze?.position?.x,0),He=p(ze?.position?.y,0),J=p(ze?.position?.z,0);if(ze?.parent){let j=[];for(let O=ze;O&&O!==_&&j.length<64;O=O.parent)j.push(O);let I=new Ti;for(let O=j.length-1;O>=0;O--){let K=j[O];K.updateMatrix(),I.multiply(K.matrix)}Se=p(I.elements[12],Se),He=p(I.elements[13],He),J=p(I.elements[14],J)}if(x instanceof qr){let j=Se-je,I=He-Ve,O=J-Ie,K=Math.hypot(j,I,O);K>1e-6?(j/=K,I/=K,O/=K):(j=0,I=-1,O=0),Me.direction=[j,I,O];let ie=Math.max(.01,Math.min(Math.PI/2,p(x.angle,Math.PI/3))),he=Math.max(0,Math.min(1,p(x.penumbra,0)));Me.outer_cone_angle=ie,Me.inner_cone_angle=Math.max(0,ie*(1-he)),Me.range=Math.max(0,p(x.distance,0))}else{let j=je-Se,I=Ve-He,O=Ie-J,K=Math.hypot(j,I,O);Me.position=[j,I,O],Me.direction=K>1e-6?[j/K,I/K,O/K]:[0,1,0]}}else x instanceof Br?Me.range=Math.max(0,p(x.distance,0)):x instanceof Xr&&(Me.ground_color=[x.groundColor.r,x.groundColor.g,x.groundColor.b]);if(x.castShadow&&(x.type==="directional"||x.type==="spot"||x.type==="point")){let ze=x.shadow,Se=Math.max(256,Math.min(2048,Math.round(p(ze?.mapSize?.x??ze?.mapSize?.width,1024))));Me.node_index=be,Me.shadow={cast:!0,map_size:Se<=384?256:Se<=768?512:Se<=1536?1024:2048,bias:Math.max(-.05,Math.min(.05,p(ze?.bias,-5e-4))),normal_bias:Math.max(0,Math.min(.2,p(ze?.normalBias,.015))),radius:Math.max(0,Math.min(8,p(ze?.radius,1.5)))}}h.push(Me)}M(x,be)}let k=[],A=(x,V,Y,Z,q="warning")=>{k.push(Z?{code:x,severity:q,node:Z,message:V,hint:Y}:{code:x,severity:q,message:V,hint:Y})};for(let x of Rn()){let V=/\[(TL50[1-4])\]/.exec(x),[Y,Z]=V?[V[1],V[1]==="TL504"?"Three-Live TSL requires loop-free acyclic expressions; replace TSL.Loop/While with fixed unrolled octaves.":V[1]==="TL503"?"Do not wire fragment-only nodes (viewDirection, fresnel, bumpFromHeight) into positionNode.":V[1]==="TL502"?"Keep TSL materials within <= 128 SSA nodes and <= 16 uniforms.":"Ensure TSL expressions use valid types and swizzle masks on THREE.MeshStandardNodeMaterial."]:x.includes("ShaderMaterial")||x.includes("RawShaderMaterial")||x.includes("unsupported material")?["TL101","Use THREE.MeshStandardMaterial({ color, metalness, roughness }) or THREE.MeshStandardNodeMaterial with THREE.TSL instead of custom GLSL shaders."]:x.includes("requestAnimationFrame")?["TL104","Static exports evaluate a single frame; use userData.xr.orbit, userData.interactivity, or define function animate(t) for time-stepped rendering."]:x.includes("Controls")?["TL106","Remove THREE.OrbitControls; <three-live camera-controls> and <xr-live> provide built-in camera controls."]:x.includes("EffectComposer")||x.includes("Pass")?["TL107",'Use <three-live bloom="0.5" outline-selected> or mesh.userData.xr = { bloom, outline } instead of EffectComposer passes.']:/THREE\.[A-Za-z0-9_]*Loader\b/.test(x)?["TL103","Load external models via <three-live src='...'> or <xr-anchor src='...'>; camera controls and post-processing are managed by the host viewer."]:/THREE\.(?:Video|Framebuffer)Texture/.test(x)?["TL102","Live DOM video/framebuffer textures cannot run in the headless sandbox; use THREE.CanvasTexture or THREE.DataTexture instead."]:x.includes("larger than")?["TL105","Keep per-node userData.xr metadata under 15 KB."]:["TL102","Use supported geometries (Box, Sphere, Cylinder, Cone, Torus, TorusKnot, Plane, Lathe, Tube, Extrude, Shape, TextGeometry, CSG, or BufferGeometry) and DirectionalLight / PointLight / SpotLight / AmbientLight / HemisphereLight."];A(Y,x,Z)}let S=new Set;for(let x of m)typeof x.name=="string"&&x.name.trim().length>0&&S.add(x.name);for(let x=0;x<m.length;x++){let V=m[x],Y=typeof V.name=="string"&&V.name.trim().length>0?V.name:"",Z=Y||V.mesh>=0&&f[V.mesh]?.name||`Node_${x}`;!Y&&S.has(Z)&&(Z=`Node_${x}`);let q=z[x],X=null;if(V.xr_traits_json)try{X=JSON.parse(V.xr_traits_json)}catch{X=null}if((X||q)&&!Y&&(V.name=Z,S.add(Z),A("TL205",`Interactive node '${Z}' is missing an explicit mesh.name (auto-named '${Z}').`,"Assign a unique mesh.name = '...' so raycasting, meshclick, and WebMCP tools can target it.",Z,"info")),X!==null){for(let L of Bl(X,Z))k.push(L);let F=(L,ee)=>{typeof ee=="string"&&ee.trim().length>0&&!S.has(ee)&&A("TL204",`userData.xr.${L} on node '${Z}' references target node '${ee}', which does not exist in scene.`,`Ensure a node with mesh.name = '${ee}' is added to scene via scene.add().`,Z)};if(X.orbit&&typeof X.orbit=="object"&&F("orbit.target",X.orbit.target),typeof X.spawner=="string"?F("spawner.template",X.spawner):X.spawner&&typeof X.spawner=="object"&&F("spawner.template",X.spawner.template),X.agent&&typeof X.agent=="object"){let L=X.agent.target;L!=="user"&&L!=="camera"&&F("agent.target",L)}if(X.ik&&typeof X.ik=="object"&&X.ik.enabled!==!1){F("ik.root",X.ik.root),F("ik.mid",X.ik.mid),F("ik.effector",X.ik.effector),Array.isArray(X.ik.target)||F("ik.target",X.ik.target);let L=X.ik.pole??X.ik.poleTarget;Array.isArray(L)||F("ik.pole",L)}let Q=X.joint??X.constraint;if(Q&&typeof Q=="object"&&Q.enabled!==!1){let L=Q.target??Q.connectedBody??Q.parent;typeof L=="string"&&L.trim().toLowerCase()!=="world"&&F("joint.target",L)}}if(q&&typeof q=="object"){let F=new Set(["onSelect","onHoverIn","onHoverOut","onStart","onReceive"]),Q=new Set(["interpolate","toggleTransform","setProperty","toggleVisibility","cycleMaterialColor","playAnimation","stopAnimation","sendEvent"]),L=(ae,be)=>{let Ne=Array.isArray(ae)?ae:[ae];for(let De of Ne){if(!De||typeof De!="object")continue;let Be=De.action;typeof Be=="string"&&!Q.has(Be)&&A("TL201",`Unrecognized action '${Be}' in userData.interactivity.${be} on node '${Z}'.`,"Supported interactivity actions: interpolate, toggleTransform, setProperty, toggleVisibility, cycleMaterialColor, playAnimation, stopAnimation, sendEvent.",Z);let je=De.target;typeof je=="string"&&je.length>0&&!S.has(je)&&A("TL204",`userData.interactivity.${be} on node '${Z}' references target node '${je}', which does not exist in scene.`,`Ensure a node with mesh.name = '${je}' is added to scene via scene.add().`,Z);let Ve=De.targetNode;typeof Ve=="number"&&(Ve<0||Ve>=m.length)&&A("TL204",`userData.interactivity.${be} on node '${Z}' references out-of-range targetNode ${Ve} (scene has ${m.length} nodes).`,"Prefer referencing nodes by name via target: '<nodeName>'.",Z)}},ee=q;for(let ae of Object.keys(ee))if(!F.has(ae)){let be=ae.toLowerCase(),Ne=be==="onclick"||be==="ontap"||be==="onpointerdown"?"onSelect":be==="onhover"||be==="onmouseenter"?"onHoverIn":be==="onmouseleave"?"onHoverOut":null;A("TL201",Ne?`Unrecognized trigger '${ae}' in userData.interactivity on node '${Z}'; did you mean '${Ne}'?`:`Unrecognized trigger '${ae}' in userData.interactivity on node '${Z}'.`,"Supported interactivity triggers: onSelect, onHoverIn, onHoverOut, onStart, onReceive.",Z)}for(let ae of["onSelect","onHoverIn","onHoverOut","onStart"])ee[ae]&&L(ee[ae],ae);if(ee.onReceive&&typeof ee.onReceive=="object")for(let[ae,be]of Object.entries(ee.onReceive))L(be,`onReceive.${ae}`)}}let w=(x,V)=>x.every((Y,Z)=>Y===V[Z]),v=i({interactivity:_.userData?.interactivity,gltfExtensions:{KHR_interactivity:_.userData?.gltfExtensions?.KHR_interactivity}}),P=!!(v?.interactivity??v?.gltfExtensions?.KHR_interactivity),H=null;(E||P)&&(H=Jn(m.map((x,V)=>({name:x.name,...x.mesh>=0?{mesh:x.mesh}:{},...w(x.translation,[0,0,0])?{}:{translation:x.translation},...w(x.rotation,[0,0,0,1])?{}:{rotation:x.rotation},...w(x.scale,[1,1,1])?{}:{scale:x.scale},extras:z[V]?{interactivity:z[V]}:void 0})),f.map(x=>({primitives:[{material:x.material_index??0}]})),v??void 0));let G=at.camera||e;return{meshes:f,nodes:m,materials:c,lights:h,interactivity_json:H?JSON.stringify(H):null,variants_json:y.length>0?JSON.stringify({variants:y.map(x=>({name:x}))}):null,diagnostics_json:k.length>0?JSON.stringify(k):null,camera:{fov:G.fov||45,position:G.position?[G.position.x,G.position.y,G.position.z]:[0,2,5],target:G.target?[G.target.x,G.target.y,G.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var Lh=hi;return yo(Yn)})();
|