three-live 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/three-author-engine.js +89 -62
- package/dist/three-author.cjs +86 -59
- package/dist/three-author.d.ts +1 -0
- package/dist/three-author.js +86 -59
- package/dist/three-convert.cjs +79 -52
- package/dist/three-convert.d.ts +1 -0
- package/dist/three-convert.js +80 -53
- package/dist/three-live-animation.d.ts +1 -0
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +1 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +2 -2
- package/dist/three-live-element.d.ts +1 -0
- package/dist/three-live-element.js +2 -2
- package/dist/three-live-full.cjs +94 -67
- package/dist/three-live-full.js +102 -75
- package/dist/three-live-full.min.js +95 -68
- package/dist/three-live-studio.d.ts +1 -0
- package/dist/three-live-viewer.cjs +2 -2
- package/dist/three-live-viewer.d.ts +1 -0
- package/dist/three-live-viewer.js +2 -2
- package/dist/three-live-viewer.min.js +2 -2
- package/dist/three-live.cjs +85 -58
- package/dist/three-live.js +85 -58
- package/dist/three-live.min.js +85 -58
- package/dist/three-view.d.ts +1 -0
- package/dist/three-xr.cjs +80 -53
- package/dist/three-xr.d.ts +1 -0
- package/dist/three-xr.js +83 -56
- package/package.json +19 -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 xi=Object.defineProperty,xa=Object.getOwnPropertyDescriptor,va=Object.getOwnPropertyNames,Ma=Object.prototype.hasOwnProperty,wa=(t,e)=>{for(var i in e)xi(t,i,{get:e[i],enumerable:!0})},Ta=(t,e,i,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of va(e))!Ma.call(t,s)&&s!==i&&xi(t,s,{get:()=>e[s],enumerable:!(r=xa(e,s))||r.enumerable});return t},Sa=t=>Ta(xi({},"__esModule",{value:!0}),t),lr={};wa(lr,{AmbientLight:()=>Wi,BoxGeometry:()=>Bi,BufferAttribute:()=>Be,BufferGeometry:()=>ke,Camera:()=>Xi,CapsuleGeometry:()=>Bs,CatmullRomCurve3:()=>hs,CircleGeometry:()=>js,Clock:()=>Ms,Color:()=>it,ConeGeometry:()=>is,CubicBezierCurve3:()=>ls,Curve3:()=>St,CylinderGeometry:()=>ji,DataTexture:()=>cs,DirectionalLight:()=>qi,DodecahedronGeometry:()=>$s,EdgesGeometry:()=>Ws,Euler:()=>Oi,Float32BufferAttribute:()=>Yr,Group:()=>ys,HemisphereLight:()=>or,IcosahedronGeometry:()=>Os,InstancedMesh:()=>ui,LatheGeometry:()=>Vi,Light:()=>Nt,Line:()=>zt,LineBasicMaterial:()=>gi,LineCurve3:()=>os,LineDashedMaterial:()=>Vs,LineLoop:()=>qs,LineSegments:()=>Xs,MAX_INSTANCES_PER_MESH:()=>Wt,Material:()=>Xe,MathUtils:()=>Zr,Matrix3:()=>Xr,Matrix4:()=>nt,Mesh:()=>dt,MeshBasicMaterial:()=>ps,MeshLambertMaterial:()=>ms,MeshPhongMaterial:()=>fs,MeshPhysicalMaterial:()=>gs,MeshStandardMaterial:()=>Dt,Object3D:()=>Ke,OctahedronGeometry:()=>Is,PerspectiveCamera:()=>di,PlaneGeometry:()=>es,PointLight:()=>ci,Points:()=>Ks,PointsMaterial:()=>ar,PolyhedronFallbackGeometry:()=>pn,PolyhedronGeometry:()=>At,QuadraticBezierCurve3:()=>ns,Quaternion:()=>$i,RawShaderMaterial:()=>ks,RectAreaLight:()=>Zs,RingGeometry:()=>sr,Scene:()=>qt,SceneQuotaValidator:()=>pt,ShaderMaterial:()=>rr,SphereGeometry:()=>ts,SpotLight:()=>yi,THREE:()=>rt,TetrahedronGeometry:()=>Us,Texture:()=>hi,TextureLoader:()=>ds,TorusGeometry:()=>rs,TorusKnotGeometry:()=>as,TubeGeometry:()=>us,Uint16BufferAttribute:()=>Qr,Uint32BufferAttribute:()=>Jr,Vector2:()=>tt,Vector3:()=>xe,Vector4:()=>qr,WebGLRenderer:()=>xs,WireframeGeometry:()=>Hs,authorScriptRunner:()=>zs,buildSandboxWorkerSource:()=>Ji,clearAuthorWarnings:()=>ir,default:()=>yn,exportSceneToCanvas3D:()=>Ki,exportSceneToGLB:()=>Zi,exportSceneToUSDZ:()=>bs,generateUSDZ:()=>Lr,getAllowClientScripts:()=>_s,getAuthorWarnings:()=>tr,getSandboxEngineSrc:()=>Yi,getSandboxIframeSrc:()=>As,glbToUSDZ:()=>Ri,isAllowedSandboxEngineUrl:()=>Lt,noopProxy:()=>Rt,sceneToCanvas3D:()=>Vt,sceneToGLB:()=>ei,sceneToUSDZ:()=>ri,setAllowClientScripts:()=>sn,setSandboxEngineSrc:()=>Jo,setSandboxIframeSrc:()=>tn,threeAuthorPlugin:()=>Kt,threeMicroPlugin:()=>gn,toTrustedWorkerScriptURL:()=>Ss,validateSandboxWorkerMessage:()=>er,warnUnsupported:()=>ft});function hr(t,e,i){let r=[],s=new Map,a=[],l=[],o=[],c=new Map,d=g=>{let y=s.get(g);return y===void 0&&(y=r.length,r.push({op:g}),s.set(g,y)),y},u=g=>{let y=c.get(g);return y===void 0&&(y=o.length,o.push({id:g}),c.set(g,y)),y},n=(g,y={})=>a.push({declaration:d(g),...y})-1,f=(g,y,M)=>l.push({id:g,type:y,value:M})-1,p=g=>({node:g,socket:"value"}),m=i?.interactivity??i?.gltfExtensions?.KHR_interactivity;if(m&&typeof m=="object"){let g=Array.isArray(m.graphs)?m.graphs[m.graph??0]:m;if(g&&Array.isArray(g.nodes)){let y=Array.isArray(g.declarations)?g.declarations:[];for(let M of y)M?.op&&d(M.op);Array.isArray(g.variables)&&l.push(...g.variables);for(let M of g.events||[])M?.id&&u(M.id);for(let M of g.nodes){if(!M||typeof M!="object")continue;let P=M.op||(typeof M.declaration=="number"?y[M.declaration]?.op:"");a.push(P?{...M,declaration:d(P)}:{...M})}}}let b=(g,y,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,y)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,y)}/${M}`:M==="visible"?`/nodes/${g}/extensions/KHR_node_visibility/visible`:`/nodes/${g}/${M}`,x=new Map;t.forEach((g,y)=>{typeof g?.name=="string"&&!x.has(g.name)&&x.set(g.name,y)});let T=(g,y)=>typeof g.target=="string"&&x.has(g.target)?x.get(g.target):typeof g.targetNode=="number"?g.targetNode:y,v=g=>{let y=t[g];return(typeof y?.mesh=="number"?e[y.mesh]?.primitives?.[0]?.material:0)??0};for(let g=0;g<t.length;g++){let y=t[g],M=y?.extras?.interactivity;if(!M||typeof M!="object")continue;let P=(typeof y.mesh=="number"?e[y.mesh]?.primitives?.[0]?.material:0)??0,j=V=>{let z=Array.isArray(V)?V:[V],L=[];for(let N=0;N<z.length;N++){let h=z[N];if(!h||typeof h!="object")continue;let k=h.action||"interpolate",X=typeof h.duration=="number"?h.duration:.35;if(k==="toggleTransform"){let A=h.property==="rotation"||h.property==="scale"?h.property:"translation",I=A==="rotation"?y.rotation||[0,0,0,1]:A==="scale"?y.scale||[1,1,1]:y.translation||[0,0,0],C=`/nodes/${g}/${A}`,w=f(`__toggle_${g}_${N}`,"bool",!1),$=n("variable/get",{configuration:{variable:w}}),Z=n("math/not",{values:{a:p($)}}),ie=n("variable/set",{configuration:{variable:w},values:{value:p(Z)}}),ee=n("pointer/interpolate",{configuration:{pointer:C},values:{value:{value:Array.isArray(h.to)?h.to:I},duration:{value:X}}}),K=n("pointer/interpolate",{configuration:{pointer:C},values:{value:{value:Array.isArray(h.from)?h.from:I},duration:{value:X}}});a[ie].flows={out:{node:n("flow/branch",{values:{condition:p($)},flows:{true:{node:ee},false:{node:K}}})}},L.push(ie)}else if(k==="interpolate"){let A=h.to??h.value;if(A===void 0)continue;let I={value:{value:A},duration:{value:X}};h.from!==void 0&&(I.from={value:h.from}),L.push(n("pointer/interpolate",{configuration:{pointer:typeof h.pointer=="string"?h.pointer:b(T(h,g),v(T(h,g)),h.property)},values:I}))}else if(k==="setProperty"){if(h.value===void 0)continue;L.push(n("pointer/set",{configuration:{pointer:typeof h.pointer=="string"?h.pointer:b(T(h,g),v(T(h,g)),h.property)},values:{value:{value:h.value}}}))}else if(k==="toggleVisibility"){let A=T(h,g),I=f(`__vis_${A}_${N}`,"bool",!0),C=n("variable/get",{configuration:{variable:I}}),w=n("math/not",{values:{a:p(C)}}),$=n("variable/set",{configuration:{variable:I},values:{value:p(w)}});a[$].flows={out:{node:n("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:p(C)}})}},L.push($)}else if(k==="cycleMaterialColor"&&Array.isArray(h.colors)&&h.colors.length>0){let A=typeof h.duration=="number"?h.duration:.25,I=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,C=f(`__color_idx_${g}_${N}`,"int",0),w=n("variable/get",{configuration:{variable:C}}),$=n("math/add",{values:{a:p(w),b:{value:1}}}),Z=n("math/rem",{values:{a:p($),b:{value:h.colors.length}}}),ie=n("variable/set",{configuration:{variable:C},values:{value:p(Z)}}),ee={};for(let K=0;K<h.colors.length;K++){let ne=h.colors[K],re=Array.isArray(ne)&&ne.length>=3?[ne[0],ne[1],ne[2],ne[3]??1]:[1,1,1,1];ee[String(K)]={node:A>0?n("pointer/interpolate",{configuration:{pointer:I},values:{value:{value:re},duration:{value:A}}}):n("pointer/set",{configuration:{pointer:I},values:{value:{value:re}}})}}a[ie].flows={out:{node:n("flow/switch",{values:{selection:p(w)},flows:ee})}},L.push(ie)}else if(k==="playAnimation")L.push(n("animation/start",{configuration:{animation:h.animation??h.clip??0}}));else if(k==="stopAnimation")L.push(n("animation/stop"));else if(k==="sendEvent"){let A={};for(let[I,C]of Object.entries(h.values||{}))A[I]={value:C};L.push(n("event/send",{configuration:{event:u(String(h.event??h.id??"custom"))},values:A}))}}if(!L.length)return null;if(L.length===1)return L[0];let O={};return L.forEach((N,h)=>{O[String(h)]={node:N}}),n("flow/sequence",{flows:O})},H=(V,z,L)=>{let O=j(z);O!==null&&n(V,{...L?{configuration:L}:{},flows:{out:{node:O}}})};if(M.onSelect&&H("pointer/onSelect",M.onSelect,{nodeIndex:g}),M.onHoverIn&&H("pointer/onHoverIn",M.onHoverIn,{nodeIndex:g}),M.onHoverOut&&H("pointer/onHoverOut",M.onHoverOut,{nodeIndex:g}),M.onStart&&H("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[V,z]of Object.entries(M.onReceive))H("event/receive",z,{event:u(V)})}return a.length?{graphs:[{declarations:r,nodes:a,variables:l,events:o}],graph:0}:null}var Aa='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).',_a="Security Error: client-side scripts require allow-client-scripts opt-in.",Zt="__THREE_LIVE_REGISTRY__";function De(){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 ze=De().plugins;function Pa(t){let e=De().plugins;e.some(i=>i.name===t.name)||e.push(t),t.onRegister?.()}function Ca(){return De().plugins}function Ea(t,e){if(!t||!t.BufferGeometry)return null;let i=t.Vector2,r=t.Vector3,s=t.Quaternion,a=t.Matrix4,l=t.Matrix3,o=t.Color,c=t.BufferAttribute,d=t.BufferGeometry,u=t.Material,n=t.MeshStandardMaterial,f=t.Mesh,p=8192,m=2048,b=128,x=4096,T=(_,S)=>{let D=_==null?NaN:Number(_);return Number.isFinite(D)?D:S};class v{constructor(S){this.currentPoint=new i(0,0),this.segments=[],Array.isArray(S)&&S.length>0&&this.fromPoints(S)}fromPoints(S){if(!S.length)return this;this.moveTo(S[0].x,S[0].y);for(let D=1;D<S.length;D++)this.lineTo(S[D].x,S[D].y);return this}moveTo(S,D){let R=Number(S)||0,E=Number(D)||0;return this.currentPoint.set(R,E),this.segments.push({type:"move",pts:[R,E]}),this}lineTo(S,D){let R=Number(S)||0,E=Number(D)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(R,E),this.segments.push({type:"line",pts:[R,E]}),this}quadraticCurveTo(S,D,R,E){let F=this.currentPoint.x,q=this.currentPoint.y,B=Number(S)||0,G=Number(D)||0,U=Number(R)||0,Y=Number(E)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[F,q]}),this.currentPoint.set(U,Y),this.segments.push({type:"quad",pts:[F,q,B,G,U,Y]}),this}bezierCurveTo(S,D,R,E,F,q){let B=this.currentPoint.x,G=this.currentPoint.y,U=Number(S)||0,Y=Number(D)||0,J=Number(R)||0,W=Number(E)||0,oe=Number(F)||0,ce=Number(q)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[B,G]}),this.currentPoint.set(oe,ce),this.segments.push({type:"cubic",pts:[B,G,U,Y,J,W,oe,ce]}),this}absarc(S,D,R,E,F,q=!1){return this.absellipse(S,D,R,R,E,F,q,0)}arc(S,D,R,E,F,q=!1){return this.absarc(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(D)||0),R,E,F,q)}absellipse(S,D,R,E,F,q,B=!1,G=0){let U=Number(S)||0,Y=Number(D)||0,J=Math.max(0,Number(R)||0),W=Math.max(0,Number(E)||0),oe=Number(F)||0,ce=Number(q)||0,me=B?1:0,de=Number(G)||0;this.segments.push({type:"arc",pts:[U,Y,J,W,oe,ce,me,de]});let fe=Math.cos(de),ye=Math.sin(de),we=J*Math.cos(ce),be=W*Math.sin(ce);return this.currentPoint.set(U+we*fe-be*ye,Y+we*ye+be*fe),this}ellipse(S,D,R,E,F,q,B=!1,G=0){return this.absellipse(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(D)||0),R,E,F,q,B,G)}closePath(){if(this.segments.length>0){let S=this.segments[0],D=0,R=0;if(S.type==="arc"){let E=S.pts[0],F=S.pts[1],q=S.pts[2],B=S.pts[3],G=S.pts[4],U=S.pts[7],Y=Math.cos(U),J=Math.sin(U),W=q*Math.cos(G),oe=B*Math.sin(G);D=E+W*Y-oe*J,R=F+W*J+oe*Y}else D=S.pts[0],R=S.pts[1];Math.hypot(this.currentPoint.x-D,this.currentPoint.y-R)>1e-6&&this.lineTo(D,R)}return this}getPoints(S=12){let D=Math.max(1,Math.min(128,Math.floor(Number(S)||12))),R=[],E=(F,q)=>{if(R.length>0){let B=R[R.length-1];if(Math.hypot(B.x-F,B.y-q)<1e-6)return}R.push(new i(F,q))};for(let F of this.segments){let q=F.pts;if(F.type==="move"||F.type==="line")E(q[0],q[1]);else if(F.type==="quad"){let B=q[0],G=q[1],U=q[2],Y=q[3],J=q[4],W=q[5];E(B,G);for(let oe=1;oe<=D;oe++){let ce=oe/D,me=1-ce;E(me*me*B+2*me*ce*U+ce*ce*J,me*me*G+2*me*ce*Y+ce*ce*W)}}else if(F.type==="cubic"){let B=q[0],G=q[1],U=q[2],Y=q[3],J=q[4],W=q[5],oe=q[6],ce=q[7];E(B,G);for(let me=1;me<=D;me++){let de=me/D,fe=1-de,ye=fe*fe,we=de*de;E(ye*fe*B+3*ye*de*U+3*fe*we*J+we*de*oe,ye*fe*G+3*ye*de*Y+3*fe*we*W+we*de*ce)}}else if(F.type==="arc"){let B=q[0],G=q[1],U=q[2],Y=q[3],J=q[4],W=q[5],oe=q[6]!==0,ce=q[7],me=Math.PI*2,de=W-J,fe=Math.abs(de)<1e-9;for(;de<0;)de+=me;for(;de>me;)de-=me;de<1e-9&&(de=fe?0:me),oe&&!fe&&(de=de===me?-me:de-me);let ye=Math.cos(ce),we=Math.sin(ce),be=Math.max(2,D);for(let _e=0;_e<=be;_e++){let Te=_e/be,Ae=J+Te*de,Ce=U*Math.cos(Ae),Ee=Y*Math.sin(Ae);E(B+Ce*ye-Ee*we,G+Ce*we+Ee*ye)}}}if(R.length>2){let F=R[0],q=R[R.length-1];Math.hypot(F.x-q.x,F.y-q.y)<1e-6&&R.pop()}return R}getSpacedPoints(S=12){return this.getPoints(S)}clone(){let S=new this.constructor;return S.currentPoint.copy(this.currentPoint),S.segments=this.segments.map(D=>({type:D.type,pts:[...D.pts]})),Array.isArray(this.holes)&&(S.holes=this.holes.map(D=>D.clone())),S}}class g extends v{constructor(S){super(S),this.holes=[]}extractPoints(S=12){return{shape:this.getPoints(S),holes:this.holes.map(D=>D.getPoints(S))}}}function y(_){let S=0,D=_.length;for(let R=0,E=D-1;R<D;E=R++)S+=_[E].x*_[R].y-_[R].x*_[E].y;return S*.5}function M(_,S,D,R,E,F,q,B){let G=q-D,U=B-R,Y=E-D,J=F-R,W=_-D,oe=S-R,ce=G*G+U*U,me=G*Y+U*J,de=G*W+U*oe,fe=Y*Y+J*J,ye=Y*W+J*oe,we=ce*fe-me*me;if(Math.abs(we)<1e-12)return!1;let be=1/we,_e=(fe*de-me*ye)*be,Te=(ce*ye-me*de)*be;return _e>=-1e-7&&Te>=-1e-7&&_e+Te<=1.0000001}function P(_,S){let D=_.slice();y(D)<0&&D.reverse();let R=D.map(G=>new i(G.x,G.y)),E=D.map((G,U)=>U),F=[];for(let G of S){if(!G||G.length<3)continue;let U=G.slice();y(U)>0&&U.reverse();let Y=[],J=-1/0,W=0;for(let oe=0;oe<U.length;oe++){let ce=U[oe],me=R.length;R.push(new i(ce.x,ce.y)),Y.push(me),ce.x>J&&(J=ce.x,W=oe)}F.push({pts:U,indices:Y,maxX:J,maxIdx:W})}F.sort((G,U)=>U.maxX-G.maxX);let q=(G,U,Y)=>(U.x-G.x)*(Y.y-G.y)-(U.y-G.y)*(Y.x-G.x),B=(G,U,Y)=>{for(let J=0;J<Y.length;J++){let W=Y[J],oe=Y[(J+1)%Y.length];if(q(G,U,W)*q(G,U,oe)<0&&q(W,oe,G)*q(W,oe,U)<0)return!0}return!1};for(let G of F){let U=G.pts[G.maxIdx],Y=U.x,J=E.length,W=E.map(fe=>R[fe]),oe=fe=>Math.hypot(W[fe].x-Y,W[fe].y-U.y),ce=W.map((fe,ye)=>ye).sort((fe,ye)=>+(W[fe].x<Y)-+(W[ye].x<Y)||oe(fe)-oe(ye)),me=ce[0];for(let fe of ce){let ye=W[fe],we=W[(fe+J-1)%J],be=W[(fe+1)%J],_e=q(ye,be,U)>=0,Te=q(we,ye,U)>=0;if((q(we,ye,be)>=0?_e&&Te:_e||Te)&&!B(U,ye,W)&&!F.some(Ae=>B(U,ye,Ae.pts))){me=fe;break}}let de=[];for(let fe=0;fe<=me;fe++)de.push(E[fe]);for(let fe=0;fe<=G.indices.length;fe++){let ye=G.indices[(G.maxIdx+fe)%G.indices.length];de.push(ye)}for(let fe=me;fe<E.length;fe++)de.push(E[fe]);E=de}return{merged:E.map(G=>R[G]),mergedIndices:E,allVertices:R}}function j(_,S){let D=[],R=_.slice();if(R.length<3)return D;let E=R.length*R.length+64,F=0;for(;R.length>2&&E-- >0;){let q=R.length,B=R[(F+q-1)%q],G=R[F%q],U=R[(F+1)%q],Y=S[B],J=S[G],W=S[U];if((J.x-Y.x)*(W.y-Y.y)-(J.y-Y.y)*(W.x-Y.x)>1e-9){let oe=!0;for(let ce=0;ce<q;ce++){let me=R[ce];if(me===B||me===G||me===U)continue;let de=S[me];if(M(de.x,de.y,Y.x,Y.y,J.x,J.y,W.x,W.y)&&Math.hypot(de.x-Y.x,de.y-Y.y)>=1e-6&&Math.hypot(de.x-J.x,de.y-J.y)>=1e-6&&Math.hypot(de.x-W.x,de.y-W.y)>=1e-6){oe=!1;break}}if(oe){D.push([B,G,U]),R.splice(F%q,1),F=Math.max(0,F%q-1);continue}}F++,F>=q*2&&(D.push([B,G,U]),R.splice((F-1)%q,1),F=0)}return D}function H(_,S){let D=_ instanceof g?_.extractPoints(S):{shape:_.getPoints(S),holes:[]},R=D.shape.length;for(let E of D.holes)R+=E.length;if(R>x)throw new RangeError(`SecurityError: shape point count (${R}) exceeds MAX_SHAPE_POINTS (${x})`);return D}class V extends d{constructor(S=new g,D=12){super();let R=Array.isArray(S)?S:[S],E=[],F=[],q=[],B=[];for(let G of R){if(!(G instanceof v))continue;let U=H(G,D);if(U.shape.length<3)continue;let{mergedIndices:Y,allVertices:J}=P(U.shape,U.holes),W=j(Y,J),oe=E.length/3,ce=1/0,me=1/0,de=-1/0,fe=-1/0;for(let be of J)be.x<ce&&(ce=be.x),be.y<me&&(me=be.y),be.x>de&&(de=be.x),be.y>fe&&(fe=be.y);let ye=Math.max(1e-6,de-ce),we=Math.max(1e-6,fe-me);for(let be of J)E.push(be.x,be.y,0),F.push(0,0,1),q.push((be.x-ce)/ye,(be.y-me)/we);for(let[be,_e,Te]of W)B.push(oe+be,oe+_e,oe+Te)}z(this,E,F,q,B)}}function z(_,S,D,R,E){return _.setAttribute("position",new c(S,3)),_.setAttribute("normal",new c(D,3)),_.setAttribute("uv",new c(R,2)),_.setIndex(E),_}function L(_){let S=_.length,D=[];for(let R=0;R<S;R++){let E=_[(R+S-1)%S],F=_[R],q=_[(R+1)%S],B=F.x-E.x,G=F.y-E.y,U=Math.hypot(B,G)||1;B/=U,G/=U;let Y=q.x-F.x,J=q.y-F.y,W=Math.hypot(Y,J)||1;Y/=W,J/=W;let oe=G,ce=-B,me=J,de=-Y,fe=oe+me,ye=ce+de,we=Math.hypot(fe,ye);if(we>1e-6){fe/=we,ye/=we;let be=Math.max(.35,fe*oe+ye*ce);D.push(new i(fe/be,ye/be))}else D.push(new i(oe,ce))}return D}class O extends d{constructor(S=new g,D={}){super();let R=Array.isArray(S)?S:[S],E=Math.max(1,Math.min(64,Math.floor(T(D.curveSegments,12)))),F=T(D.depth??D.amount,1),q=Math.max(1,Math.min(32,Math.floor(T(D.steps,1)))),B=!!(D.bevelEnabled??!1),G=B?Math.max(0,T(D.bevelThickness,.06)):0,U=B?Math.max(0,T(D.bevelSize,G*.8)):0,Y=B?T(D.bevelOffset,0):0,J=B?Math.max(1,Math.min(8,Math.floor(T(D.bevelSegments,2)))):0,W=[],oe=[],ce=[],me=[];for(let de of R){if(!(de instanceof v))continue;let fe=H(de,E);if(fe.shape.length<3)continue;let ye=fe.shape.slice();y(ye)<0&&ye.reverse();let we=[];for(let ve of fe.holes){if(ve.length<3)continue;let Se=ve.slice();y(Se)>0&&Se.reverse(),we.push(Se)}let{mergedIndices:be,allVertices:_e}=P(ye,we),Te=j(be,_e),Ae=[ye,...we],Ce=[];for(let ve of Ae){let Se=L(ve);for(let Re of Se)Ce.push(Re)}let Ee=1/0,je=1/0,$e=-1/0,Ye=-1/0;for(let ve of _e)ve.x<Ee&&(Ee=ve.x),ve.y<je&&(je=ve.y),ve.x>$e&&($e=ve.x),ve.y>Ye&&(Ye=ve.y);let Ge=Math.max(1e-6,$e-Ee),st=Math.max(1e-6,Ye-je),kt=-G,Ut=F+G,gt=W.length/3;for(let ve=0;ve<_e.length;ve++){let Se=_e[ve],Re=Ce[ve]??new i(0,0),Ue=Se.x+Re.x*Y,Fe=Se.y+Re.y*Y;W.push(Ue,Fe,kt),oe.push(0,0,-1),ce.push((Ue-Ee)/Ge,(Fe-je)/st)}for(let[ve,Se,Re]of Te)me.push(gt+ve,gt+Re,gt+Se);let yt=W.length/3;for(let ve=0;ve<_e.length;ve++){let Se=_e[ve],Re=Ce[ve]??new i(0,0),Ue=Se.x+Re.x*Y,Fe=Se.y+Re.y*Y;W.push(Ue,Fe,Ut),oe.push(0,0,1),ce.push((Ue-Ee)/Ge,(Fe-je)/st)}for(let[ve,Se,Re]of Te)me.push(yt+ve,yt+Se,yt+Re);let He=[];if(B&&J>0)for(let ve=0;ve<J;ve++){let Se=ve/J*Math.PI/2;He.push({z:-G*Math.cos(Se),expand:Y+U*Math.sin(Se)})}for(let ve=0;ve<=q;ve++){let Se=ve/q;He.push({z:Se*F,expand:Y+U})}if(B&&J>0)for(let ve=1;ve<=J;ve++){let Se=ve/J*Math.PI/2;He.push({z:F+G*Math.sin(Se),expand:Y+U*Math.cos(Se)})}let at=0;for(let ve of Ae){let Se=ve.length;for(let Re=0;Re<He.length-1;Re++){let Ue=He[Re],Fe=He[Re+1];for(let qe=0;qe<Se;qe++){let lt=(qe+1)%Se,bt=ve[qe],xt=ve[lt],vt=Ce[at+qe],Mt=Ce[at+lt],wt=bt.x+vt.x*Ue.expand,Tt=bt.y+vt.y*Ue.expand,_t=xt.x+Mt.x*Ue.expand,ht=xt.y+Mt.y*Ue.expand,bn=xt.x+Mt.x*Fe.expand,xn=xt.y+Mt.y*Fe.expand,Qs=bt.x+vt.x*Fe.expand,Js=bt.y+vt.y*Fe.expand,ea=_t-wt,ta=ht-Tt,ia=0,ra=Qs-wt,sa=Js-Tt,aa=Fe.z-Ue.z,Ft=ta*aa-ia*sa,It=ia*ra-ea*aa,Ot=ea*sa-ta*ra,nr=Math.hypot(Ft,It,Ot)||1;Ft/=nr,It/=nr,Ot/=nr;let $t=W.length/3;W.push(wt,Tt,Ue.z,_t,ht,Ue.z,bn,xn,Fe.z,Qs,Js,Fe.z),oe.push(Ft,It,Ot,Ft,It,Ot,Ft,It,Ot,Ft,It,Ot);let oa=qe/Se,na=(qe+1)/Se,la=Re/(He.length-1),ha=(Re+1)/(He.length-1);ce.push(oa,la,na,la,na,ha,oa,ha),me.push($t,$t+1,$t+2,$t,$t+2,$t+3)}}at+=Se}}z(this,W,oe,ce,me)}}function N(_){return{x:_.x,y:_.y,z:_.z,nx:_.nx,ny:_.ny,nz:_.nz,u:_.u,v:_.v}}function h(_){return{x:_.x,y:_.y,z:_.z,nx:-_.nx,ny:-_.ny,nz:-_.nz,u:_.u,v:_.v}}function k(_,S,D){let R=_.nx+(S.nx-_.nx)*D,E=_.ny+(S.ny-_.ny)*D,F=_.nz+(S.nz-_.nz)*D,q=Math.hypot(R,E,F)||1;return{x:_.x+(S.x-_.x)*D,y:_.y+(S.y-_.y)*D,z:_.z+(S.z-_.z)*D,nx:R/q,ny:E/q,nz:F/q,u:_.u+(S.u-_.u)*D,v:_.v+(S.v-_.v)*D}}function X(_){if(_.length<3)return null;let S=_[0],D=_[1],R=_[2],E=D.x-S.x,F=D.y-S.y,q=D.z-S.z,B=R.x-S.x,G=R.y-S.y,U=R.z-S.z,Y=F*U-q*G,J=q*B-E*U,W=E*G-F*B,oe=Math.hypot(Y,J,W);if(oe<1e-9)return null;Y/=oe,J/=oe,W/=oe;let ce=Y*S.x+J*S.y+W*S.z;return{vertices:_,nx:Y,ny:J,nz:W,w:ce}}function A(_){_.vertices.reverse();for(let S=0;S<_.vertices.length;S++)_.vertices[S]=h(_.vertices[S]);_.nx=-_.nx,_.ny=-_.ny,_.nz=-_.nz,_.w=-_.w}let I=1e-5,C=0,w=1,$=2,Z=3;function ie(_,S,D,R,E,F,q,B,G){let U=0,Y=[];for(let J=0;J<E.vertices.length;J++){let W=E.vertices[J],oe=_*W.x+S*W.y+D*W.z-R,ce=oe<-I?$:oe>I?w:C;U|=ce,Y.push(ce)}switch(U){case C:{_*E.nx+S*E.ny+D*E.nz>0?F.push(E):q.push(E);break}case w:B.push(E);break;case $:G.push(E);break;case Z:{let J=[],W=[],oe=E.vertices.length;for(let ye=0;ye<oe;ye++){let we=(ye+1)%oe,be=Y[ye],_e=Y[we],Te=E.vertices[ye],Ae=E.vertices[we];if(be!==$&&J.push(Te),be!==w&&W.push(be!==$?N(Te):Te),(be|_e)===Z){let Ce=Ae.x-Te.x,Ee=Ae.y-Te.y,je=Ae.z-Te.z,$e=_*Ce+S*Ee+D*je,Ye=Math.abs($e)>1e-12?(R-(_*Te.x+S*Te.y+D*Te.z))/$e:.5,Ge=k(Te,Ae,Math.max(0,Math.min(1,Ye)));J.push(Ge),W.push(N(Ge))}}let{nx:ce,ny:me,nz:de,w:fe}=E;J.length>=3&&B.push({vertices:J,nx:ce,ny:me,nz:de,w:fe}),W.length>=3&&G.push({vertices:W,nx:ce,ny:me,nz:de,w:fe});break}default:break}}class ee{constructor(S,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,S&&S.length>0&&this.build(S,D)}invert(){for(let D=0;D<this.polygons.length;D++)A(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 S=this.front;this.front=this.back,this.back=S}clipPolygons(S,D=0){if(!this.hasPlane||S.length===0)return S.slice();if(D>=m)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${m})`);let R=[],E=[];for(let F=0;F<S.length;F++)ie(this.nx,this.ny,this.nz,this.w,S[F],R,E,R,E);return this.front&&R.length>0&&(R=this.front.clipPolygons(R,D+1)),this.back?E=E.length>0?this.back.clipPolygons(E,D+1):[]:E=[],R.concat(E)}clipTo(S,D=0){this.polygons.length>0&&(this.polygons=S.clipPolygons(this.polygons,0)),D<m&&(this.front&&this.front.clipTo(S,D+1),this.back&&this.back.clipTo(S,D+1))}allPolygons(S=[]){for(let D=0;D<this.polygons.length;D++)S.push(this.polygons[D]);return this.front&&this.front.allPolygons(S),this.back&&this.back.allPolygons(S),S}build(S,D=0){if(!S.length)return;if(!this.hasPlane){let F=S[S.length>>1];this.nx=F.nx,this.ny=F.ny,this.nz=F.nz,this.w=F.w,this.hasPlane=!0}if(D>=m)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${m})`);let R=[],E=[];for(let F=0;F<S.length;F++)ie(this.nx,this.ny,this.nz,this.w,S[F],this.polygons,this.polygons,R,E);R.length>0&&(this.front||(this.front=new ee),this.front.build(R,D+1)),E.length>0&&(this.back||(this.back=new ee),this.back.build(E,D+1))}}function K(_,S){if(!S&&_._csgPolygons)return _._csgPolygons;let D=_.attributes.position;if(!D||D.count===0)return[];let R=_.attributes.normal,E=_.attributes.uv,F=_.index?_.index.array:null,q=Math.floor(F?F.length/3:D.count/3);if(q>p)throw new RangeError(`SecurityError: CSG input triangle count (${q}) exceeds MAX_CSG_TRIANGLES (${p})`);let B=S?S.elements:null,G=B?B[0]*(B[5]*B[10]-B[9]*B[6])-B[4]*(B[1]*B[10]-B[9]*B[2])+B[8]*(B[1]*B[6]-B[5]*B[2])<0:!1,U=B?new l().getNormalMatrix(S).elements:null,Y=W=>{let oe=D.getX(W),ce=D.getY(W),me=D.getZ(W),de=R?R.getX(W):NaN,fe=R?R.getY(W):NaN,ye=R?R.getZ(W):NaN;if(B&&U){let _e=B[0]*oe+B[4]*ce+B[8]*me+B[12],Te=B[1]*oe+B[5]*ce+B[9]*me+B[13],Ae=B[2]*oe+B[6]*ce+B[10]*me+B[14];oe=_e,ce=Te,me=Ae;let Ce=U[0]*de+U[3]*fe+U[6]*ye,Ee=U[1]*de+U[4]*fe+U[7]*ye,je=U[2]*de+U[5]*fe+U[8]*ye,$e=Math.hypot(Ce,Ee,je)||1;de=Ce/$e,fe=Ee/$e,ye=je/$e}let we=E?E.getX(W):0,be=E?E.getY(W):0;return{x:oe,y:ce,z:me,nx:de,ny:fe,nz:ye,u:we,v:be}},J=[];for(let W=0;W<q;W++){let oe=F?F[W*3]:W*3,ce=F?F[W*3+1]:W*3+1,me=F?F[W*3+2]:W*3+2,de=X(G?[Y(oe),Y(me),Y(ce)]:[Y(oe),Y(ce),Y(me)]);de&&J.push(de)}return J}function ne(_){let S=[],D=[],R=[],E=[];for(let q of _){let B=q.vertices;if(B.length<3)continue;let G=S.length/3;for(let U of B)S.push(U.x,U.y,U.z),Number.isFinite(U.nx)&&U.nx*U.nx+U.ny*U.ny+U.nz*U.nz>.5?D.push(U.nx,U.ny,U.nz):D.push(q.nx,q.ny,q.nz),R.push(U.u,U.v);for(let U=1;U<B.length-1;U++)E.push(G,G+U,G+U+1)}let F=z(new d,S,D,R,E);return F._csgPolygons=_,F}function re(_,S,D){if(_.length+S.length>p)throw new RangeError(`SecurityError: Combined CSG triangle count (${_.length+S.length}) exceeds MAX_CSG_TRIANGLES (${p})`);if(_.length===0)return D==="union"?S:[];if(S.length===0)return D==="intersect"?[]:_;let R=1/0,E=1/0,F=1/0,q=-1/0,B=-1/0,G=-1/0;for(let oe=0;oe<S.length;oe++){let ce=S[oe].vertices;for(let me=0;me<ce.length;me++){let de=ce[me];de.x<R&&(R=de.x),de.y<E&&(E=de.y),de.z<F&&(F=de.z),de.x>q&&(q=de.x),de.y>B&&(B=de.y),de.z>G&&(G=de.z)}}R-=1e-4,E-=1e-4,F-=1e-4,q+=1e-4,B+=1e-4,G+=1e-4;let U=[],Y=[];for(let oe=0;oe<_.length;oe++){let ce=_[oe],me=ce.vertices,de=1/0,fe=1/0,ye=1/0,we=-1/0,be=-1/0,_e=-1/0;for(let Te=0;Te<me.length;Te++){let Ae=me[Te];Ae.x<de&&(de=Ae.x),Ae.y<fe&&(fe=Ae.y),Ae.z<ye&&(ye=Ae.z),Ae.x>we&&(we=Ae.x),Ae.y>be&&(be=Ae.y),Ae.z>_e&&(_e=Ae.z)}we<R||de>q||be<E||fe>B||_e<F||ye>G?Y.push(ce):U.push(ce)}if(U.length===0)return D==="union"?_.concat(S):D==="subtract"?_:[];let J=new ee(U),W=new ee(S);return D==="union"?(J.clipTo(W),W.clipTo(J),W.invert(),W.clipTo(J),W.invert(),J.build(W.allPolygons()),Y.concat(J.allPolygons())):D==="subtract"?(J.invert(),J.clipTo(W),W.clipTo(J),W.invert(),W.clipTo(J),W.invert(),J.build(W.allPolygons()),J.invert(),Y.concat(J.allPolygons())):(J.invert(),W.clipTo(J),W.invert(),J.clipTo(W),W.clipTo(J),J.build(W.allPolygons()),J.invert(),J.allPolygons())}function he(_,S,D,R=null,E=null){{let B=globalThis.__three_live_native_csg_boolean__;if(typeof B=="function"&&_?.attributes?.position?.array&&S?.attributes?.position?.array){let G=D==="subtract"?0:D==="union"?1:2,U=B(_.attributes.position.array,_.attributes.normal?_.attributes.normal.array:null,_.attributes.uv?_.attributes.uv.array:null,_.index?_.index.array:null,R?R.elements:null,S.attributes.position.array,S.attributes.normal?S.attributes.normal.array:null,S.attributes.uv?S.attributes.uv.array:null,S.index?S.index.array:null,E?E.elements:null,G);if(U)return z(new d,U.positions,U.normals,U.uvs,U.indices)}}let F=K(_,R),q=K(S,E);return ne(re(F,q,D))}function Q(_,S,D){let R=_ instanceof f||!!_?.isMesh,E=S instanceof f||!!S?.isMesh,F=R?_.geometry:_,q=E?S.geometry:S,B=null;if(E)if(S.updateMatrix(),R){_.updateMatrix();let J=new a().makeScale(1/(_.scale.x||1),1/(_.scale.y||1),1/(_.scale.z||1)),W=Math.hypot(_.quaternion.x,_.quaternion.y,_.quaternion.z,_.quaternion.w)||1,oe=new a().compose(new r(0,0,0),new s(-_.quaternion.x/W,-_.quaternion.y/W,-_.quaternion.z/W,_.quaternion.w/W),new r(1,1,1)),ce=new a().makeTranslation(-_.position.x,-_.position.y,-_.position.z);B=J.multiply(oe).multiply(ce).multiply(S.matrix)}else B=S.matrix;let G=he(F,q,D,null,B),U=R?_.material:new n,Y=new f(G,U);return R&&(Y.position.copy(_.position),Y.quaternion.copy(_.quaternion),Y.scale.copy(_.scale),Y.name=_.name),Y}let ae={toGeometry:he,subtract(_,S){return Q(_,S,"subtract")},union(_,S){return Q(_,S,"union")},intersect(_,S){return Q(_,S,"intersect")}},te={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 pe extends d{constructor(S="",D={}){super();let R=String(S??"").slice(0,b),E=Math.max(.005,Math.min(100,T(D.size,.2))),F=!!(D.bevelEnabled??!1),q=F?Math.max(0,Math.min(2,T(D.bevelThickness,E*.04))):0,B=F?Math.max(0,Math.min(2,T(D.bevelSize,E*.03))):0,G=Math.max(.001,Math.min(20,T(D.depth??D.height,E*.2)))+q*2,U=E*.085+B,Y=E*.68,J=E*.82,W=[],oe=[],ce=[],me=[],de=(we,be,_e,Te,Ae,Ce,Ee)=>{let je=_e-we,$e=Te-be,Ye=Math.hypot(je,$e),Ge=1,st=0;Ye>1e-6&&(Ge=je/Ye,st=$e/Ye);let kt=-st*Ae,Ut=Ge*Ae,gt=Ge*Ae*.6,yt=st*Ae*.6,He=we-gt+kt,at=be-yt+Ut,ve=we-gt-kt,Se=be-yt-Ut,Re=_e+gt-kt,Ue=Te+yt-Ut,Fe=_e+gt+kt,qe=Te+yt+Ut,lt=(bt,xt,vt,Mt,wt,Tt,_t)=>{let ht=W.length/3;W.push(bt[0],bt[1],bt[2],xt[0],xt[1],xt[2],vt[0],vt[1],vt[2],Mt[0],Mt[1],Mt[2]),oe.push(wt,Tt,_t,wt,Tt,_t,wt,Tt,_t,wt,Tt,_t),ce.push(0,0,1,0,1,1,0,1),me.push(ht,ht+1,ht+2,ht,ht+2,ht+3)};lt([He,at,Ee],[ve,Se,Ee],[Re,Ue,Ee],[Fe,qe,Ee],0,0,1),lt([ve,Se,Ce],[He,at,Ce],[Fe,qe,Ce],[Re,Ue,Ce],0,0,-1),lt([He,at,Ce],[ve,Se,Ce],[ve,Se,Ee],[He,at,Ee],-Ge,-st,0),lt([Re,Ue,Ce],[Fe,qe,Ce],[Fe,qe,Ee],[Re,Ue,Ee],Ge,st,0),lt([ve,Se,Ce],[Re,Ue,Ce],[Re,Ue,Ee],[ve,Se,Ee],st,-Ge,0),lt([Fe,qe,Ce],[He,at,Ce],[He,at,Ee],[Fe,qe,Ee],-st,Ge,0)},fe=0,ye=0;for(let we=0;we<R.length;we++){let be=R[we];if(be===`
|
|
17
|
-
`){fe=0,ye-=E*1.35;continue}if(be===" "||be===" "){fe+=J*(be===" "?.75:3);continue}if(be==="\r")continue;let _e=be.toUpperCase(),Te=be!==_e&&be>="a"&&be<="z",Ae=te[_e]??te["?"],Ce=Te?E*.76:E,Ee=Te?Y*.88:Y;for(let je of Ae)for(let $e=0;$e<je.length-1;$e++){let Ye=je[$e],Ge=je[$e+1];de(fe+Ye[0]*Ee,ye+Ye[1]*Ce,fe+Ge[0]*Ee,ye+Ge[1]*Ce,U,-G*.5,G*.5)}fe+=Te?J*.88:J}z(this,W,oe,ce,me),D.center!==!1?this.center():this.computeBoundingBox()}}function ue(_){if(!_)return;let S=_,D=_.userData?.xr?.text??_.userData?.xr?.label??_.userData?.xr?.title??_.userData?.xr?.caption??_.userData?.xr?.spatialLabel;if(D!=null&&D!==!1){let E=S.geometry?.attributes?.position;if((!E||E.count===0)&&_.userData._textApplied!==!0){let F="",q=.08,B=.015,G;if(typeof D=="string"||typeof D=="number")F=String(D);else if(typeof D=="object"){let U=D;F=String(U.text??U.value??""),U.size!==void 0&&(q=Number(U.size)||.08),(U.depth!==void 0||U.height!==void 0)&&(B=Number(U.depth??U.height)||q*.2),(typeof U.color=="string"||typeof U.color=="number")&&(G=U.color)}F.trim().length>0&&(S.geometry=new pe(F,{size:q,depth:B}),_.userData._textApplied=!0,S.material instanceof u?G!==void 0&&_.userData._autoTextColorApplied!==!0&&(S.material.color=new o(G),_.userData._autoTextColorApplied=!0):S.material=new n({color:G??16317180}))}}let R=_.userData?.csg;if(R&&typeof R=="object"&&_.userData._csgApplied!==!0&&S.geometry instanceof d&&S.geometry.attributes.position?.count>0){_.userData._csgApplied=!0;let E=Array.isArray(R)?R:[R],F=S.geometry;for(let q of E){if(!q||typeof q!="object")continue;let B=q,G=String(B.op??B.operation??"subtract"),U=G==="union"||G==="intersect"?G:"subtract",Y=B.target??B.mesh??B.geometry;if(Y instanceof f||Y instanceof d)try{let J=U==="union"?ae.union(S,Y):U==="intersect"?ae.intersect(S,Y):ae.subtract(S,Y);S.geometry!==F&&S.geometry.dispose?.(),S.geometry=J.geometry}catch(J){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",J)}}}}let le={Path:v,Shape:g,ShapeGeometry:V,ExtrudeGeometry:O,TextGeometry:pe,CSG:ae,MAX_CSG_TRIANGLES:p,MAX_BSP_DEPTH:m,MAX_TEXT_GEOMETRY_CHARS:b,MAX_SHAPE_POINTS:x,materializeDeclarativeGeometry:ue};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,le),e._cadMaterialize=ue,e.materializeDeclarativeGeometry=_=>{e._cadMaterialize?.(_),e._lodMaterialize?.(_)}),le}function Le(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function vi(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 l=1/(r-s);return t[10]=(s+r)*l,t[14]=2*s*r*l,t}function Yt(t,e,i,r){let[s,a,l]=e,[o,c,d]=r,[u,n,f]=i,p=s-u,m=a-n,b=l-f,x=Math.hypot(p,m,b);x<=1e-5?(p=0,m=0,b=1):(p/=x,m/=x,b/=x);let T=c*b-d*m,v=d*p-o*b,g=o*m-c*p;x=Math.hypot(T,v,g),x<=1e-5?(T=0,v=0,g=0):(T/=x,v/=x,g/=x);let y=m*g-b*v,M=b*T-p*g,P=p*v-m*T;return x=Math.hypot(y,M,P),x<=1e-5?(y=0,M=0,P=0):(y/=x,M/=x,P/=x),t[0]=T,t[1]=y,t[2]=p,t[3]=0,t[4]=v,t[5]=M,t[6]=m,t[7]=0,t[8]=g,t[9]=P,t[10]=b,t[11]=0,t[12]=-(T*s+v*a+g*l),t[13]=-(y*s+M*a+P*l),t[14]=-(p*s+m*a+b*l),t[15]=1,t}function Oe(t,e,i){let r=e[0],s=e[1],a=e[2],l=e[3],o=e[4],c=e[5],d=e[6],u=e[7],n=e[8],f=e[9],p=e[10],m=e[11],b=e[12],x=e[13],T=e[14],v=e[15],g=i[0],y=i[1],M=i[2],P=i[3];return t[0]=g*r+y*o+M*n+P*b,t[1]=g*s+y*c+M*f+P*x,t[2]=g*a+y*d+M*p+P*T,t[3]=g*l+y*u+M*m+P*v,g=i[4],y=i[5],M=i[6],P=i[7],t[4]=g*r+y*o+M*n+P*b,t[5]=g*s+y*c+M*f+P*x,t[6]=g*a+y*d+M*p+P*T,t[7]=g*l+y*u+M*m+P*v,g=i[8],y=i[9],M=i[10],P=i[11],t[8]=g*r+y*o+M*n+P*b,t[9]=g*s+y*c+M*f+P*x,t[10]=g*a+y*d+M*p+P*T,t[11]=g*l+y*u+M*m+P*v,g=i[12],y=i[13],M=i[14],P=i[15],t[12]=g*r+y*o+M*n+P*b,t[13]=g*s+y*c+M*f+P*x,t[14]=g*a+y*d+M*p+P*T,t[15]=g*l+y*u+M*m+P*v,t}function Mi(t,e,i,r){let s=e[0],a=e[1],l=e[2],o=e[3],c=s+s,d=a+a,u=l+l,n=s*c,f=s*d,p=s*u,m=a*d,b=a*u,x=l*u,T=o*c,v=o*d,g=o*u,y=r[0],M=r[1],P=r[2];return t[0]=(1-(m+x))*y,t[1]=(f+g)*y,t[2]=(p-v)*y,t[3]=0,t[4]=(f-g)*M,t[5]=(1-(n+x))*M,t[6]=(b+T)*M,t[7]=0,t[8]=(p+v)*P,t[9]=(b-T)*P,t[10]=(1-(n+m))*P,t[11]=0,t[12]=i[0],t[13]=i[1],t[14]=i[2],t[15]=1,t}function ut(t,e,i=0){let r=e[0],s=e[1],a=e[2],l=e[4],o=e[5],c=e[6],d=e[8],u=e[9],n=e[10],f=n*o-c*u,p=-n*l+c*d,m=u*l-o*d,b=r*f+s*p+a*m;return!b||i>0&&(!Number.isFinite(b)||Math.abs(b)<=i)||(b=1/b,t[0]=f*b,t[1]=p*b,t[2]=m*b,t[3]=(-n*s+a*u)*b,t[4]=(n*r-a*d)*b,t[5]=(-u*r+s*d)*b,t[6]=(c*s-a*o)*b,t[7]=(-c*r+a*l)*b,t[8]=(o*r-s*l)*b),t}function Da(t,e){let i=e[0],r=e[1],s=e[2],a=e[3],l=e[4],o=e[5],c=e[6],d=e[7],u=e[8],n=e[9],f=e[10],p=e[11],m=e[12],b=e[13],x=e[14],T=e[15],v=i*o-r*l,g=i*c-s*l,y=i*d-a*l,M=r*c-s*o,P=r*d-a*o,j=s*d-a*c,H=u*b-n*m,V=u*x-f*m,z=u*T-p*m,L=n*x-f*b,O=n*T-p*b,N=f*T-p*x,h=v*N-g*O+y*L+M*z-P*V+j*H;return h?(h=1/h,t[0]=(o*N-c*O+d*L)*h,t[1]=(s*O-r*N-a*L)*h,t[2]=(b*j-x*P+T*M)*h,t[3]=(f*P-n*j-p*M)*h,t[4]=(c*z-l*N-d*V)*h,t[5]=(i*N-s*z+a*V)*h,t[6]=(x*y-m*j-T*g)*h,t[7]=(u*j-f*y+p*g)*h,t[8]=(l*O-o*z+d*H)*h,t[9]=(r*z-i*O-a*H)*h,t[10]=(m*P-b*y+T*v)*h,t[11]=(n*y-u*P-p*v)*h,t[12]=(o*V-l*L-c*H)*h,t[13]=(i*L-r*V+s*H)*h,t[14]=(b*g-m*M-x*v)*h,t[15]=(u*M-n*g+f*v)*h,t):null}function ur(t,e,i,r,s){let a=s[0]*e+s[4]*i+s[8]*r+s[12],l=s[1]*e+s[5]*i+s[9]*r+s[13],o=s[2]*e+s[6]*i+s[10]*r+s[14],c=s[3]*e+s[7]*i+s[11]*r+s[15],d=c!==0?1/c:1;t[0]=a*d,t[1]=l*d,t[2]=o*d}function Na(t,e,i,r,s,a,l,o,c,d,u,n,f,p,m,b,x=0){let T=d-l,v=u-o,g=n-c,y=f-l,M=p-o,P=m-c,j=s*P-a*M,H=a*y-r*P,V=r*M-s*y,z=T*j+v*H+g*V;if(z>-1e-7&&z<1e-7)return!1;let L=1/z,O=t-l,N=e-o,h=i-c,k=L*(O*j+N*H+h*V);if(k<-x||k>1+x)return!1;let X=N*g-h*v,A=h*T-O*g,I=O*v-N*T,C=L*(r*X+s*A+a*I);if(C<-x||k+C>1+x)return!1;let w=L*(y*X+M*A+P*I);if(w>1e-4&&w<b.distance){b.distance=w,b.point=[t+r*w,e+s*w,i+a*w];let $=v*P-g*M,Z=g*y-T*P,ie=T*M-v*y,ee=Math.hypot($,Z,ie)||1;return b.normal=[$/ee,Z/ee,ie/ee],!0}return!1}function Ra(t,e){let i=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<i;u++)r.push(Le());if(i===0)return r;let s=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let n of u.children)s.add(n);let a=new Set,l=128,o=(u,n,f=0)=>{if(f>l||u<0||u>=i||a.has(u))return;a.add(u);let p=t.nodes[u];if(!p)return;let m=Le();if(e&&e[u])m.set(e[u]);else if(p.matrix&&p.matrix.length===16)m.set(p.matrix);else{let x=p.translation||[0,0,0],T=p.rotation||[0,0,0,1],v=p.scale||[1,1,1];Mi(m,T,x,v)}let b=r[u];if(n?Oe(b,n,m):b.set(m),Array.isArray(p.children))for(let x of p.children)typeof x=="number"&&o(x,b,f+1)},c=[],d=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(d&&Array.isArray(d.nodes))c.push(...d.nodes);else for(let u=0;u<i;u++)s.has(u)||c.push(u);for(let u of c)o(u,null);for(let u=0;u<i;u++)!s.has(u)&&!c.includes(u)&&o(u,null);return r}function cr(t,e){function i(c,d,u,n){let f=typeof c=="number"?c:Number(c);return Number.isFinite(f)?Math.max(d,Math.min(u,f)):n}function r(c,d){let u=c[0]*d[0]+c[1]*d[1]+c[2]*d[2]+1;if(u<1e-6){if(Math.abs(c[0])>Math.abs(c[2])){let x=Math.hypot(c[1],c[0])||1;return[-c[1]/x,c[0]/x,0,0]}let b=Math.hypot(c[2],c[1])||1;return[0,-c[2]/b,c[1]/b,0]}let n=c[1]*d[2]-c[2]*d[1],f=c[2]*d[0]-c[0]*d[2],p=c[0]*d[1]-c[1]*d[0],m=Math.hypot(n,f,p,u)||1;return[n/m,f/m,p/m,u/m]}function s(c,d,u,n,f){let p=d[0]-c[0],m=d[1]-c[1],b=d[2]-c[2],x=Math.hypot(p,m,b),T=u[0]-d[0],v=u[1]-d[1],g=u[2]-d[2],y=Math.hypot(T,v,g);if(x<1e-6||y<1e-6)return{rootPos:[c[0],c[1],c[2]],midPos:[d[0],d[1],d[2]],effectorPos:[u[0],u[1],u[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let M=[p/x,m/x,b/x],P=[T/y,v/y,g/y],j=n[0]-c[0],H=n[1]-c[1],V=n[2]-c[2],z=Math.hypot(j,H,V),L=z>1e-6?[j/z,H/z,V/z]:M,O=Math.abs(x-y)+1e-5,N=Math.max(O,x+y-1e-5),h=Math.max(O,Math.min(N,z>1e-6?z:O)),k=i((x*x+h*h-y*y)/(2*x*h),-1,1,1),X=Math.sqrt(Math.max(0,1-k*k)),A=f?f[0]-c[0]:p,I=f?f[1]-c[1]:m,C=f?f[2]-c[2]:b,w=A*L[0]+I*L[1]+C*L[2],$=A-L[0]*w,Z=I-L[1]*w,ie=C-L[2]*w,ee=Math.hypot($,Z,ie);if(ee<=1e-6){let _=Math.abs(L[1])<.99?0:1,S=Math.abs(L[1])<.99?1:0,D=0;$=L[1]*D-L[2]*S,Z=L[2]*_-L[0]*D,ie=L[0]*S-L[1]*_,ee=Math.hypot($,Z,ie)||1}let K=[$/ee,Z/ee,ie/ee],ne=[c[0]+L[0]*(x*k)+K[0]*(x*X),c[1]+L[1]*(x*k)+K[1]*(x*X),c[2]+L[2]*(x*k)+K[2]*(x*X)],re=[c[0]+L[0]*h,c[1]+L[1]*h,c[2]+L[2]*h],he=re[0]-ne[0],Q=re[1]-ne[1],ae=re[2]-ne[2],te=Math.hypot(he,Q,ae),pe=te>1e-6?[he/te,Q/te,ae/te]:L,ue=[ne[0]+pe[0]*y,ne[1]+pe[1]*y,ne[2]+pe[2]*y],le=[(ne[0]-c[0])/x,(ne[1]-c[1])/x,(ne[2]-c[2])/x];return{rootPos:[c[0],c[1],c[2]],midPos:ne,effectorPos:ue,rootRotation:r(M,le),midRotation:r(P,pe)}}function a(c,d,u=8,n=.001){let f=c.length;if(f<2)return{positions:c.map(z=>[z[0],z[1],z[2]]),rotations:[],iterations:0};let p=c.map(z=>[z[0],z[1],z[2]]),m=[],b=[],x=0;for(let z=0;z<f-1;z++){let L=p[z+1][0]-p[z][0],O=p[z+1][1]-p[z][1],N=p[z+1][2]-p[z][2],h=Math.hypot(L,O,N);m.push(h),x+=h,b.push(h>1e-6?[L/h,O/h,N/h]:[0,1,0])}let T=[p[0][0],p[0][1],p[0][2]],v=Math.round(i(u,1,32,8)),g=i(n,1e-5,.1,.001),y=d[0]-T[0],M=d[1]-T[1],P=d[2]-T[2],j=Math.hypot(y,M,P),H=0;if(j>=x&&x>1e-6){let z=j>1e-6?[y/j,M/j,P/j]:b[0];p[0]=[T[0],T[1],T[2]];for(let L=0;L<f-1;L++){let O=m[L];p[L+1]=[p[L][0]+z[0]*O,p[L][1]+z[1]*O,p[L][2]+z[2]*O]}H=1}else for(let z=1;z<=v;z++){let L=p[f-1];if(Math.hypot(L[0]-d[0],L[1]-d[1],L[2]-d[2])<=g)break;H=z;let O=(N,h,k,X,A)=>{let I=h[0]-N[0],C=h[1]-N[1],w=h[2]-N[2],$=Math.hypot(I,C,w);if($>1e-6){let Z=k/$;return[N[0]+I*Z,N[1]+C*Z,N[2]+w*Z]}return[N[0]+X[0]*k*A,N[1]+X[1]*k*A,N[2]+X[2]*k*A]};p[f-1]=[d[0],d[1],d[2]];for(let N=f-2;N>=0;N--)p[N]=O(p[N+1],p[N],m[N],b[N],-1);p[0]=[T[0],T[1],T[2]];for(let N=0;N<f-1;N++)p[N+1]=O(p[N],p[N+1],m[N],b[N],1)}let V=[];for(let z=0;z<f-1;z++){let L=p[z+1][0]-p[z][0],O=p[z+1][1]-p[z][1],N=p[z+1][2]-p[z][2],h=Math.hypot(L,O,N),k=h>1e-6?[L/h,O/h,N/h]:b[z];V.push(r(b[z],k))}return{positions:p,rotations:V,iterations:H}}function l(c){if(!c||typeof c!="object"||Array.isArray(c))return null;let d=c;if(d.enabled===!1)return null;let u=g=>{if(typeof g!="string")return;let y=g.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(y)?y:void 0},n=g=>Array.isArray(g)&&g.length===3&&g.every(y=>typeof y=="number"&&Number.isFinite(y))?[i(g[0],-1e3,1e3,0),i(g[1],-1e3,1e3,0),i(g[2],-1e3,1e3,0)]:void 0,f=u(d.root),p=u(d.effector);if(!f||!p)return null;let m=u(d.mid),b=n(d.target)??u(d.target);if(!b)return null;let x=d.pole??d.poleTarget,T=n(x)??u(x),v=d.solver==="fabrik"?"fabrik":d.solver==="two-bone"||m?"two-bone":"fabrik";return{root:f,...m?{mid:m}:{},effector:p,target:b,...T?{pole:T}:{},solver:v,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 o=Object.freeze({solveTwoBone:s,solveFABRIK:a,parseIKTrait:l});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=o),{clampNum:i,parseIKTrait:l,quatFromUnitVectors:r,solveTwoBoneIK:s,solveFABRIK:a,IKSolver:o}}var Pt=cr(),vn=Pt.clampNum,Mn=Pt.parseIKTrait,wn=Pt.quatFromUnitVectors,Tn=Pt.solveTwoBoneIK,Sn=Pt.solveFABRIK,An=Pt.IKSolver;function dr(t,e){let i=(u,n,f,p)=>{let m=typeof u=="number"?u:Number(u);return Number.isFinite(m)?Math.max(n,Math.min(f,m)):p};function r(u,n,f=0,p=.05,m){if(!u||!u.length)return-1;let b=u[0]>0?[0,...u]:u,x=Number.isFinite(n)?Math.max(0,n):0,T=Number.isFinite(p)?Math.max(0,Math.min(.5,p)):.05;if(typeof m=="number"&&Number.isFinite(m)&&m>0){let y=f===-1?m*(1-T):m*(1+T);if(x>y)return-1}let v=0;for(let y=b.length-1;y>=1;y--)if(x>=b[y]){v=y;break}if(f<0||f>=b.length||f===v)return v;if(v>f){let y=f;for(let M=f+1;M<=v&&x>=b[M]*(1+T);M++)y=M;return y}let g=f;for(let y=f;y>v&&x<b[y]*(1-T);y--)g=y-1;return g}function s(u){if(!u)return null;let n=u===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(u)?{distances:u}:typeof u=="object"?u:null;if(!n||n.enabled===!1)return null;let f=i(n.hysteresis,0,.5,.05),p=[],m;if(Array.isArray(n.levels)&&n.levels.length>0){let v=n.levels.slice(0,8);for(let y=0;y<v.length;y++){let M=v[y];if(!M||typeof M!="object"||Array.isArray(M))continue;let P=M,j=i(P.distance,0,1e4,y===0?0:y*4),H=typeof P.hysteresis=="number"?i(P.hysteresis,0,.5,f):void 0,V=typeof P.ratio=="number"?i(P.ratio,.05,1,.5):void 0,z=typeof P.childIndex=="number"&&Number.isFinite(P.childIndex)?Math.max(0,Math.round(P.childIndex)):void 0,L=typeof P.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(P.node.trim())?P.node.trim().slice(0,64):void 0;p.push({distance:j,...H!==void 0?{hysteresis:H}:{},...V!==void 0?{ratio:V}:{},...z!==void 0?{childIndex:z}:{},...L?{node:L}:{}})}p.sort((y,M)=>y.distance-M.distance),p.length>0&&p[0].distance>0&&p.unshift({distance:0,childIndex:0});let g=0;p=p.slice(0,8).map((y,M)=>{let P=M===0?0:Math.max(g,y.distance);return g=P,{...y,distance:P,childIndex:y.childIndex??M}})}if(Array.isArray(n.ratios)&&n.ratios.length>0){let v=[];for(let g of n.ratios.slice(0,7))typeof g=="number"&&v.push(i(g,.05,1,.5));v.length>0&&(m=v)}if(p.length===0){let v=Array.isArray(n.distances)?n.distances:[],g=[];for(let M of v.slice(0,8))typeof M=="number"&&g.push(i(M,0,1e4,4));if(g.length===0&&m&&m.length>0)for(let M=0;M<m.length;M++)g.push((M+1)*4);if(g.length===0&&n.cullDistance===void 0)return null;g.length===0||g[0]>0?g.unshift(0):m&&m.length===g.length&&m[0]===1&&(m=m.slice(1));let y=0;for(let M=0;M<Math.min(8,g.length);M++){let P=M===0?0:Math.max(y,g[M]);y=P;let j=M>0&&m?m[M-1]:void 0;p.push({distance:P,childIndex:M,...j!==void 0?{ratio:j}:{}})}}else if(!m){let v=[];for(let g=1;g<p.length;g++)typeof p[g].ratio=="number"&&v.push(p[g].ratio);v.length>0&&(m=v)}let b=p.map(v=>v.distance),x=b[b.length-1]??0,T=n.cullDistance!==void 0&&n.cullDistance!==null&&n.cullDistance!==!1?i(n.cullDistance,Math.max(1,x),1e4,100):void 0;return{levels:p,distances:b,...m?{ratios:m}:{},hysteresis:f,...T!==void 0?{cullDistance:T}:{}}}function a(u,n){let f=u?.attributes?.position;if(!f||!f.array||f.count<3)return u;let p=i(n,.05,1,.5),m=f.array,b=f.count,x=u.attributes?.normal?.array,T=u.attributes?.uv?.array,v=u.index?.array,g=Math.floor((v?v.length:b)/3);if(g<1)return u;let y=Math.max(1,Math.min(g,Math.round(g*p))),M=1/0,P=1/0,j=1/0,H=-1/0,V=-1/0,z=-1/0;for(let ee=0;ee<b;ee++){let K=m[ee*3],ne=m[ee*3+1],re=m[ee*3+2];K<M&&(M=K),ne<P&&(P=ne),re<j&&(j=re),K>H&&(H=K),ne>V&&(V=ne),re>z&&(z=re)}let L=Math.max(1e-5,H-M),O=Math.max(1e-5,V-P),N=Math.max(1e-5,z-j),h=Math.max(L,O,N),k=ee=>{let K=Math.max(1,Math.round(L/h*ee)),ne=Math.max(1,Math.round(O/h*ee)),re=Math.max(1,Math.round(N/h*ee)),he=new Map,Q=new Int32Array(b),ae=[],te=[],pe=[],ue=[];for(let E=0;E<b;E++){let F=m[E*3],q=m[E*3+1],B=m[E*3+2],G=Math.min(K-1,Math.max(0,Math.floor((F-M)/L*K))),U=Math.min(ne-1,Math.max(0,Math.floor((q-P)/O*ne))),Y=Math.min(re-1,Math.max(0,Math.floor((B-j)/N*re))),J=G+U*K+Y*K*ne,W=he.get(J);W===void 0?(W=ue.length,he.set(J,W),ae.push(F,q,B),x&&te.push(x[E*3],x[E*3+1],x[E*3+2]),T&&pe.push(T[E*2],T[E*2+1]),ue.push(1)):(ae[W*3]+=F,ae[W*3+1]+=q,ae[W*3+2]+=B,x&&(te[W*3]+=x[E*3],te[W*3+1]+=x[E*3+1],te[W*3+2]+=x[E*3+2]),ue[W]++),Q[E]=W}let le=[],_=new Set;for(let E=0;E<g;E++){let F=v?v[E*3]:E*3,q=v?v[E*3+1]:E*3+1,B=v?v[E*3+2]:E*3+2,G=Q[F],U=Q[q],Y=Q[B];if(G===U||U===Y||Y===G)continue;let J=Math.min(G,U,Y),W=Math.max(G,U,Y),oe=G+U+Y-J-W,ce=`${J}_${oe}_${W}`;_.has(ce)||(_.add(ce),le.push(G,U,Y))}let S=ue.length,D=new Float32Array(S*3),R=x?new Float32Array(S*3):null;for(let E=0;E<S;E++){let F=1/ue[E];if(D[E*3]=ae[E*3]*F,D[E*3+1]=ae[E*3+1]*F,D[E*3+2]=ae[E*3+2]*F,R){let q=te[E*3],B=te[E*3+1],G=te[E*3+2],U=Math.hypot(q,B,G)||1;R[E*3]=q/U,R[E*3+1]=B/U,R[E*3+2]=G/U}}return{pos:D,norm:R,uv:T?new Float32Array(pe):null,tris:le,triCount:le.length/3,vertCount:S}},X=Math.max(2,Math.round(Math.sqrt(y/4))),A=k(X);if(A.triCount>y*1.25&&X>2){let ee=Math.max(2,Math.round(X*Math.sqrt(y/A.triCount)));if(ee!==X){let K=k(ee);K.triCount>=Math.min(4,y)&&(A=K)}}else if(A.triCount<Math.min(4,y)){let ee=k(Math.max(X*2,8));ee.triCount>A.triCount&&(A=ee)}let I=A.tris;if(p<1&&A.triCount>y){let ee=[],K=A.triCount/y;for(let ne=0;ne<y;ne++){let re=Math.min(A.triCount-1,Math.floor(ne*K));ee.push(A.tris[re*3],A.tris[re*3+1],A.tris[re*3+2])}I=ee}if(I.length<3){I=[];for(let ee=0;ee<y*3;ee++)I.push(v?v[ee]:ee);A={pos:m.slice(),norm:x?x.slice():null,uv:T?T.slice():null,tris:I,triCount:y,vertCount:b}}let C=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),w=C?.BufferGeometry??u.constructor,$=C?.BufferAttribute??f.constructor,Z=new w;Z.setAttribute("position",new $(A.pos,3)),A.norm&&Z.setAttribute("normal",new $(A.norm,3)),A.uv&&Z.setAttribute("uv",new $(A.uv,2));let ie=A.vertCount>65535?new Uint32Array(I):new Uint16Array(I);return typeof Z.setIndex=="function"?Z.setIndex(new $(ie,1)):Z.index=new $(ie,1),Z}let l=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(...u){for(let n of u)n&&(n.parent=this,this.children.push(n));return this}};class o extends l{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(n,f=0,p=.05){if(!n)return this;let m=Math.max(0,Number.isFinite(Number(f))?Number(f):0),b=i(p,0,.5,.05),x=this.levels.length;for(let g=0;g<this.levels.length;g++)if(m<this.levels[g].distance){x=g;break}this.levels.splice(x,0,{object:n,distance:m,hysteresis:b}),this.add(n);let T=this.levels.map(g=>g.object),v=this.children.filter(g=>!T.includes(g));this.children=[...T,...v];for(let g=0;g<this.levels.length;g++)this.levels[g].object.visible=g===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(n){if(!this.levels.length)return null;let f=r(this.levels.map(p=>p.distance),n,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return f>=0&&f<this.levels.length?this.levels[f].object:null}update(n){if(this.levels.length===0||!n)return;let f=n.position??{x:0,y:0,z:0},p=this.position??{x:0,y:0,z:0},m=Math.hypot((Number(f.x)||0)-(Number(p.x)||0),(Number(f.y)||0)-(Number(p.y)||0),(Number(f.z)||0)-(Number(p.z)||0)),b=r(this.levels.map(x=>x.distance),m,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=b;for(let x=0;x<this.levels.length;x++)this.levels[x].object.visible=x===b}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let n=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((f,p)=>({distance:f.distance,hysteresis:f.hysteresis,childIndex:p,...f.object?.name?{node:f.object.name}:{}})),distances:this.levels.map(f=>f.distance),hysteresis:this.levels[0]?.hysteresis??.05,...n!==void 0?{cullDistance:n}:{}}}}function c(u){if(!u||u._lodMaterialized||!u.userData?.xr?.lod||u.isLOD||Array.isArray(u.children)&&u.children.length>0)return;let n=u.geometry?.attributes?.position;if(!n||!n.array||n.count<3)return;let f=s(u.userData.xr.lod);if(!f||f.levels.length<2)return;u._lodMaterialized=!0;let p=u.geometry;u._lodOriginalGeometry=p;let m=t??e?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),b=m?.Mesh??u.constructor,x=m?.BufferGeometry??p.constructor,T=typeof u.name=="string"&&u.name.trim()?u.name.trim():"Mesh",v=new b(p,u.material);v.name=`${T}_LOD0`,v.visible=!0,v.castShadow=!!u.castShadow,v.receiveShadow=!!u.receiveShadow,u.add(v);for(let g=1;g<f.levels.length;g++){let y=f.levels[g].ratio??f.ratios?.[g-1]??Math.max(.05,Math.pow(.5,g)),M=a(p,y),P=new b(M,u.material);P.name=`${T}_LOD${g}`,P.visible=!1,P.castShadow=!!u.castShadow,P.receiveShadow=!!u.receiveShadow,u.add(P)}u.geometry=new x,u.userData.xr.lod={...f,levels:f.levels.map((g,y)=>({...g,childIndex:y,node:`${T}_LOD${y}`}))}}let d={LOD:o,decimateGeometry:a,selectLodLevelIndex:r,parseLod:s,materializeLodGeometry:c};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,{LOD:o,decimateGeometry:a}),e._lodMaterialize=c,e.materializeDeclarativeGeometry=u=>{e._cadMaterialize?.(u),e._lodMaterialize?.(u)}),d}var Bt=dr(),_n=Bt.decimateGeometry,Pn=Bt.selectLodLevelIndex,Cn=Bt.parseLod,En=Bt.materializeLodGeometry,Dn=Bt.LOD,La={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 l=i.componentType??5126,o=La[l];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let c=o*r,d=s.byteStride&&s.byteStride>0?s.byteStride:c,u=(s.byteOffset||0)+(i.byteOffset||0);if(!Number.isInteger(u)||u<0||d<c||u+(a-1)*d+c>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(l===5126&&d===c&&u%4===0)return new Float32Array(e,u,a*r);let n=new DataView(e),f=i.normalized===!0,p=new Float32Array(a*r);for(let m=0;m<a;m++){let b=u+m*d;for(let x=0;x<r;x++){let T=b+x*o,v;switch(l){case 5126:v=n.getFloat32(T,!0);break;case 5120:v=n.getInt8(T),f&&(v=Math.max(v/127,-1));break;case 5121:v=n.getUint8(T),f&&(v/=255);break;case 5122:v=n.getInt16(T,!0),f&&(v=Math.max(v/32767,-1));break;case 5123:v=n.getUint16(T,!0),f&&(v/=65535);break;default:v=n.getUint32(T,!0),f&&(v/=4294967295)}p[m*r+x]=v}}return p}function za(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),l=Number(e.rotation??0)||0,o=Math.cos(l),c=Math.sin(l),d=(Number.isFinite(s)?s:1)*o,u=(Number.isFinite(s)?s:1)*c,n=-(Number.isFinite(a)?a:1)*c,f=(Number.isFinite(a)?a:1)*o;for(let p=0;p+1<t.length;p+=2){let m=t[p],b=t[p+1];t[p]=d*m+u*b+i,t[p+1]=n*m+f*b+r}}function wi(t,e,i,r=!0){let s=[],a=null;try{for(let[l,o]of[[35633,e],[35632,i]]){let c=t.createShader(l);if(!c){if(r)throw new Error("Shader allocation failed");return null}if(s.push(c),t.shaderSource(c,o),t.compileShader(c),t.getShaderParameter&&!t.getShaderParameter(c,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(c)}`);return null}}if(a=t.createProgram(),!a){if(r)throw new Error("Program allocation failed");return null}for(let l of s)t.attachShader(a,l);if(t.linkProgram(a),t.getProgramParameter&&!t.getProgramParameter(a,35714)){let l=r?t.getProgramInfoLog(a):null;if(t.deleteProgram?.(a),a=null,r)throw new Error(`Program link error: ${l}`);return null}return a}finally{for(let l of s)a&&t.detachShader?.(a,l),t.deleteShader?.(l)}}var mr=["neutral","reinhard","none","aces","agx"];function Ti(t){let e=String(t??"").trim().toLowerCase();return mr.includes(e)?e:"neutral"}function ka(t){return mr.indexOf(Ti(t))}function Ua(t){return new TextDecoder().decode(t)}var fr=De().decoders;function Fa(t,e){fr.set(t.toLowerCase(),e)}function Ct(t){return fr.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 f=i.getUint8(0);throw f===123||f===32||f===10||f===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let s=i.getUint32(4,!0);if(s!==2)throw new Error(`Unsupported GLB version: ${s}`);let a=i.getUint32(8,!0),l=12,o=null,c=null;for(;l+8<=a&&l+8<=e.byteLength;){let f=i.getUint32(l,!0),p=i.getUint32(l+4,!0),m=l+8;if(m+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${m+f} bytes, buffer has ${e.byteLength}`);if(p===1313821514){let b=new Uint8Array(e,m,f),x=Ua(b);o=JSON.parse(x,(T,v)=>T==="__proto__"||T==="constructor"||T==="prototype"?void 0:v)}else p===5130562&&(c=e.slice(m,m+f));l=m+f}if(!o)throw new Error("Missing JSON chunk in GLB");let d=o.extensionsRequired||[];if(d.includes("KHR_draco_mesh_compression")&&!Ct("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let f of["EXT_meshopt_compression","KHR_meshopt_compression"])if(d.includes(f)&&!Ct("meshopt"))throw new Error(`Model requires ${f}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(d.includes("KHR_texture_basisu")&&!Ct("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=c||new ArrayBuffer(0),n={gltf:o,bin:u,animations:[]};for(let f of ze)f.onParseGLB?.(n);return n}function Ia(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 Qt(t){if(Ia(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 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
|
|
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
|
+
}`,La=`#version 300 es
|
|
53
53
|
precision highp float;
|
|
54
54
|
in vec3 vNormal,vWorldPos;
|
|
55
55
|
in vec2 vUV;
|
|
@@ -240,19 +240,19 @@ color=applyToneMapping(color,uToneMapping);
|
|
|
240
240
|
float outAlpha=base.a;
|
|
241
241
|
/*XRD_O*/
|
|
242
242
|
fragColor=vec4(color,outAlpha);
|
|
243
|
-
}
|
|
243
|
+
}`,za=`#version 300 es
|
|
244
244
|
layout(location=0) in vec3 aPosition;
|
|
245
245
|
uniform mat4 uMVP;
|
|
246
|
-
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,
|
|
246
|
+
void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,ka=`#version 300 es
|
|
247
247
|
precision highp float;
|
|
248
248
|
uniform vec4 uColorId;
|
|
249
249
|
out vec4 fragColor;
|
|
250
|
-
void main(){fragColor=uColorId;}`;function Si(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=De().xrDepthShader;return{fs:Oa.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...br,...t.uniformNames]:br}}function ja(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 Ai(t,e,i,r,s,a,l,o){if(r===void 0||!e.accessors?.[r])return null;let c=pr(e,i,e.accessors[r],a);if(!c)return null;o&&(c=c.slice(),za(c,o));let d=t.createBuffer();return l.push(d),t.bindBuffer(34962,d),t.bufferData(34962,c,35044),t.enableVertexAttribArray(s),t.vertexAttribPointer(s,a,5126,!1,0,0),c}function _i(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,l=!1;for(let c of ze)if(c.onResolveShader){let d=c.onResolveShader(e,i,s,a);d&&(s=d.vs,a=d.fs,l=!0)}let o=l?wi(t,s,a):null;return{program:o,uniforms:o?Si(t,o,r.uniforms):null}}function Va(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,l=new Float32Array(s*20);for(let c=0;c<s;c++)l.set(r.subarray(c*16,c*16+16),c*20),l[c*20+16]=a?a[c*3]:1,l[c*20+17]=a?a[c*3+1]:1,l[c*20+18]=a?a[c*3+2]:1,l[c*20+19]=1;let o=t.createBuffer();i.push(o),t.bindBuffer(34962,o),t.bufferData(34962,l,35044);for(let c=0;c<5;c++)t.enableVertexAttribArray(8+c),t.vertexAttribPointer(8+c,4,5126,!1,80,c*16),t.vertexAttribDivisor(8+c,1);return!0}function Ga(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 Nn=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 Jt(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=l=>l!==void 0&&e[l.index]?e[l.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 Tr(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 l of a.primitives){if(l.vao&&t.deleteVertexArray(l.vao),l.buffers)for(let c of l.buffers)t.deleteBuffer(c);s(l.texture),s(l.metallicRoughnessTexture),s(l.normalTexture),s(l.occlusionTexture);let o=new Set;l.customProgram&&o.add(l.customProgram);for(let c of l.programCache?.values()??[])c.program&&o.add(c.program);for(let c of o)t.deleteProgram(c)}if(i)for(let a of i)s(a)}function Sr(t,e,i=Mr,r){let s={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Ha(t,e,i,r,s)}catch(a){let l=s.mesh&&!s.meshes.includes(s.mesh)?[...s.meshes,s.mesh]:s.meshes;Tr(t,l,s.gpuTextures),s.vao&&t.deleteVertexArray(s.vao);for(let o of s.buffers)t.deleteBuffer(o);throw a}}function Ha(t,e,i,r,s){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:a}=e,l=Ct("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(a,e);let o=e.bin,c=[];s.meshes=c;let d=[],u=a.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((N,h)=>{d.push(typeof N?.name=="string"&&N.name?N.name:`Variant_${h}`)});let n=Ra(a),f=[];if(Array.isArray(a.nodes))for(let N=0;N<a.nodes.length;N++){let h=a.nodes[N];h.mesh!==void 0&&a.meshes&&a.meshes[h.mesh]&&f.push({node:h,nodeIdx:N,meshIdx:h.mesh})}let p=f.length>0?f:(a.meshes||[]).map((N,h)=>({node:N,nodeIdx:-1,meshIdx:h})),m=[],b=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(b)for(let N of b)m.push({...N,type:N.type||N.light_type||"point",innerConeAngle:N.innerConeAngle??N.inner_cone_angle,outerConeAngle:N.outerConeAngle??N.outer_cone_angle});else if(a.extensions?.KHR_lights_punctual?.lights){let N=a.extensions.KHR_lights_punctual.lights;for(let h of N){let k=h.type==="directional"?"directional":h.type==="point"?"point":h.type==="spot"?"spot":"ambient";m.push({type:k,color:h.color||[1,1,1],intensity:h.intensity!==void 0?h.intensity:1})}}if(m.length===0&&(m.push({type:"ambient",color:[1,1,1],intensity:.35}),m.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),p.length>i.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${i.maxMeshes}). Found: ${p.length}`);let x=[];if(s.gpuTextures=x,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 N=0;N<a.textures.length;N++){let h=a.textures[N],k=a.images[h.source];if(k){let X=t.createTexture();t.bindTexture(3553,X),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=I=>{t.bindTexture(3553,X),t.texImage2D(3553,0,6408,6408,5121,I),t.generateMipmap(3553),r?.()};if(k.bufferView!==void 0){let I=a.bufferViews[k.bufferView],C=I.byteOffset||0,w=new Blob([o.slice(C,C+I.byteLength)],{type:k.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(w).then(A).catch(()=>{})}else if(k.uri){let I=ja(k.uri);if(I){let C=new Image;C.crossOrigin="anonymous",C.referrerPolicy="no-referrer",C.onload=()=>A(C),C.src=I}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",k.uri)}x.push(X)}else x.push(null)}}let T=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],g=0,y=0;for(let N=0;N<p.length;N++){let h=p[N],k=a.meshes[h.meshIdx],X=h.nodeIdx>=0?n[h.nodeIdx]:Le(),A=new Float32Array(9);ut(A,X);let I={name:h.node.name||k.name||`Mesh_${h.meshIdx}`,nodeIndex:h.nodeIdx,transform:X,normalMatrix:A,primitives:[],extras:h.node.extras||k.extras,...h.node?.visible===!1||h.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};s.mesh=I;let C=h.node?.extensions?.EXT_mesh_gpu_instancing;if(C&&C.attributes&&typeof C.attributes=="object"){let w=C.attributes,$=w.TRANSLATION!==void 0?a.accessors?.[w.TRANSLATION]:null,Z=w.ROTATION!==void 0?a.accessors?.[w.ROTATION]:null,ie=w.SCALE!==void 0?a.accessors?.[w.SCALE]:null,ee=w._COLOR_0!==void 0?a.accessors?.[w._COLOR_0]:null,K=Number($?.count??Z?.count??ie?.count??0);if(!Number.isFinite(K)||K<0||K>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${K}`);if(K>0){let ne=(le,_)=>{if(!le||le.bufferView===void 0||!a.bufferViews?.[le.bufferView])return null;let S=le.componentType??5126,D=E=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${E})`),null);if(S!==5120&&S!==5121&&S!==5122&&S!==5123&&S!==5126)return D(`componentType ${S}`);if(!(Number(le.count)>=K))return D(`count ${le.count} < ${K}`);let R=null;try{R=pr(a,o,{...le,count:K},_)}catch{return D("out of bounds")}return!R||!R.every(Number.isFinite)?D("non-finite value"):R},re=ne($,3),he=ne(Z,4),Q=ne(ie,3),ae=ee?.type==="VEC4"?4:3,te=ne(ee,ae),pe=new Float32Array(K*16),ue=Le();for(let le=0;le<K;le++){let _=re?[re[le*3],re[le*3+1],re[le*3+2]]:[0,0,0],S=he?[he[le*4],he[le*4+1],he[le*4+2],he[le*4+3]]:[0,0,0,1],D=Q?[Q[le*3],Q[le*3+1],Q[le*3+2]]:[1,1,1];Mi(ue,S,_,D),pe.set(ue,le*16)}if(I.instanceMatrices=pe,te){let le=new Float32Array(K*3);for(let _=0;_<K;_++)le[_*3]=te[_*ae],le[_*3+1]=te[_*ae+1],le[_*3+2]=te[_*ae+2];I.instanceColors=le}}}for(let w of k.primitives||[]){if(w.extensions?.KHR_draco_mesh_compression){let R=Ct("draco");R&&R.decodePrimitive(a,w,o)}let $=[],Z=t.createVertexArray();s.vao=Z,s.buffers=$,t.bindVertexArray(Z);let ie=Va(t,I,$),ee=a.accessors[w.attributes.POSITION],K=Number(ee?.count??0);if(!Number.isFinite(K)||K<0||g+K>i.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${i.maxVertices}).`);if(g+=K,ee?.min&&ee?.max){let R=E=>{for(let F=0;F<3;F++){let q=E[12+F],B=E[12+F];for(let G=0;G<3;G++){let U=E[G*4+F]*ee.min[G],Y=E[G*4+F]*ee.max[G];q+=U<Y?U:Y,B+=U>Y?U:Y}q<T[F]&&(T[F]=q),B>v[F]&&(v[F]=B)}};if(I.instanceMatrices&&I.instanceMatrices.length>=16){let E=I.instanceMatrices.length>>4,F=Le();for(let q=0;q<E;q++){let B=I.instanceMatrices.subarray(q*16,q*16+16);Oe(F,X,B),R(F)}}else R(X)}let ne=Ai(t,a,o,w.attributes.POSITION,0,3,$);Ai(t,a,o,w.attributes.NORMAL,1,3,$),Ai(t,a,o,w.attributes.TEXCOORD_0,2,2,$,Ga(a,w));let re=0,he=5123,Q=null;if(w.indices!==void 0){let R=a.accessors[w.indices],E=(a.bufferViews[R.bufferView].byteOffset||0)+(R.byteOffset||0);if(re=Number(R.count??0),!Number.isFinite(re)||re<0||y+re>i.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${i.maxIndices}).`);y+=re,he=R.componentType===5125?5125:5123;let F=t.createBuffer();$.push(F),t.bindBuffer(34963,F),R.componentType===5125?Q=new Uint32Array(o,E,R.count):R.componentType===5121?Q=Uint16Array.from(new Uint8Array(o,E,R.count)):Q=E%2===0?new Uint16Array(o,E,R.count):new Uint16Array(o.slice(E,E+R.count*2)),t.bufferData(34963,Q,35044)}else re=ee.count;let ae={};for(let R of ze)if(R.onBuildPrimitiveVAO){let E=R.onBuildPrimitiveVAO(t,Z,w,a,o);E&&(ae[R.name]=E)}t.bindVertexArray(null);let te=a.materials&&w.material!==void 0?a.materials[w.material]:null,{program:pe,uniforms:ue}=vr(t,w,te),le=wr(te,x),_=!!(te?.extensions?.KHR_materials_transmission||ae.materials?.isTransmissive),S=w.extensions?.KHR_materials_variants?.mappings,D=Array.isArray(S)?S.filter(R=>R&&typeof R.material=="number"&&Array.isArray(R.variants)).map(R=>({material:R.material|0,variants:R.variants.map(E=>Number(E)|0)})):void 0;I.primitives.push({vao:Z,instanced:ie,indexCount:re,indexType:he,...le,positions:ne,indices:Q,buffers:$,materialIndex:w.material,defaultMaterialIndex:w.material,variantMappings:D,primitiveDef:w,programCache:new Map([[w.material??-1,{program:pe,uniforms:ue}]]),pluginData:ae,customProgram:pe,customUniforms:ue,isTransmissive:_})}c.push(I)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let M=[(T[0]+v[0])/2,(T[1]+v[1])/2,(T[2]+v[2])/2],P=v[0]-T[0],j=v[1]-T[1],H=v[2]-T[2],V=Math.max(Math.hypot(P,j,H)/2,.5),z=[T[0],T[1],T[2]],L=[v[0],v[1],v[2]],O=e.animations;if(!O){for(let N of ze)if(N.onParseGLB?.(e),e.animations){O=e.animations;break}}return O||(O=[]),{meshes:c,bounds:{center:M,radius:V,min:z,max:L},lights:m,animations:O,worldMatrices:n,gpuTextures:x,availableVariants:d}}function jt(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 Ar=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=Le(),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=Le(),this.viewMatrix=Le(),this.activeViewMatrix=null,this.modelMatrix=Le(),this.mvpMatrix=Le(),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:Le(),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 o=t.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",t.prepend(o)),r=o}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=_i(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=Ti(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=r.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(t,e){Fa(t,e)}static getDecoder(t){return Ct(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=wi(t,yr,e.fs),this.pickProg=wi(t,$a,Ba),this.uRender=Si(t,this.renderProg,e.uniforms),this.uPick=Si(t,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let t=this.gl;this.contextLost=!1,this.initGlState();for(let e of ze)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:l,gpuTextures:o,availableVariants:c}=Sr(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=l||[],this.gpuTextures=o||[],this.availableVariants=c||[],this.gltf=t.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(t.gltf?.nodes))for(let n of t.gltf.nodes)this.initialNodeTransforms.push({t:n.translation?[n.translation[0],n.translation[1],n.translation[2]]:[0,0,0],r:n.rotation?[n.rotation[0],n.rotation[1],n.rotation[2],n.rotation[3]]:[0,0,0,1],s:n.scale?[n.scale[0],n.scale[1],n.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let n of ze)n.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=_i(d));let u=t.environmentIntensity??t.gltf?.extras?.environmentIntensity??t.gltf?.asset?.extras?.environmentIntensity;u!==void 0&&(this.envIntensity=Math.max(0,Number(u)||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 ze)t.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(t){this.loadGLBData(Qt(t))}setBackdropGLB(t,e){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!t){this.update(0),this.render();return}let i=Qt(t),{meshes:r}=Sr(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],ut(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),ut(i.normalMatrix,i.transform))}}bindLights(t=this.uRender){let e=this.gl,i=[.28,.28,.28],r=[],s=[],a=[],l=[],o=[],c=[];for(let d of this.lights){let u=d.color||[1,1,1],n=d.intensity!==void 0?d.intensity:1;if(d.type==="ambient")i=[u[0]*n,u[1]*n,u[2]*n];else if(d.type==="directional"&&r.length<6){let f=d.direction||[.5,1,.8];r.push(f[0],f[1],f[2]),s.push(u[0]*n,u[1]*n,u[2]*n)}else if((d.type==="point"||d.type==="spot")&&a.length<6){let f=d.position||[0,0,0];if(a.push(f[0],f[1],f[2]),l.push(u[0]*n,u[1]*n,u[2]*n),d.type==="spot"){let p=d.direction||[0,-1,0],m=Math.max(.01,Math.min(Math.PI/2,d.outerConeAngle??Math.PI/3)),b=Math.max(0,Math.min(m-1e-4,d.innerConeAngle??0));o.push(p[0],p[1],p[2]),c.push(Math.cos(b),Math.cos(m))}else o.push(0,-1,0),c.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,l),t.uPointLightSpotDir&&e.uniform3fv(t.uPointLightSpotDir,o),t.uPointLightSpotCone&&e.uniform2fv(t.uPointLightSpotCone,c)),e.uniform1f(t.uEnvIntensity,this.envIntensity)}setExposure(t){this.exposure=_i(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=Ti(t)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(t){for(let e of ze)if(e.setEnvironmentImage){await e.setEnvironmentImage(this,t);return}}async setSkyboxImage(t){for(let e of ze)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(u=>u.materialIndex===i||t.length===1&&u.materialIndex===void 0)),s=r[0],a=s?[...s.baseColor]:e.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=s?s.metallic:e.pbrMetallicRoughness?.metallicFactor??.1,o=s?s.roughness:e.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:a,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:d=>{let u=[d[0],d[1],d[2],d[3]??1];c.baseColorFactor=u,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.baseColorFactor=u);for(let n of r)n.baseColor=u;this.render()},setMetallicFactor:d=>{c.metallicFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.metallicFactor=d);for(let u of r)u.metallic=d;this.render()},setRoughnessFactor:d=>{c.roughnessFactor=d,e.pbrMetallicRoughness&&(e.pbrMetallicRoughness.roughnessFactor=d);for(let u of r)u.roughness=d;this.render()}};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 l=a.defaultMaterialIndex;if(!e&&Array.isArray(a.variantMappings)){for(let c of a.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(i)){l=c.material;break}}let o=l!==void 0?r[l]:void 0;a.materialIndex=o?l:void 0,Object.assign(a,wr(o,this.gpuTextures)),this.applyPrimitiveProgram(a,a.materialIndex,o??null)}return!0}applyPrimitiveProgram(t,e,i){if(!this.gl||!t.primitiveDef)return;t.programCache??(t.programCache=new Map);let r=e??-1,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 ze)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=Le();Oe(i,this.projMatrix,this.viewMatrix);let[r,s,a]=t,l=e?e[0]:0,o=e?e[1]:0,c=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&&(l=d[0]*e[0]+d[4]*e[1]+d[8]*e[2],o=d[1]*e[0]+d[5]*e[1]+d[9]*e[2],c=d[2]*e[0]+d[6]*e[1]+d[10]*e[2]));let u=i[0]*r+i[4]*s+i[8]*a+i[12],n=i[1]*r+i[5]*s+i[9]*a+i[13],f=i[2]*r+i[6]*s+i[10]*a+i[14],p=i[3]*r+i[7]*s+i[11]*a+i[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let m=u/p,b=n/p,x=f/p,T=this.canvas.getBoundingClientRect(),v=T.width||this.canvas.clientWidth||this.canvas.width||300,g=T.height||this.canvas.clientHeight||this.canvas.height||150,y=(m*.5+.5)*v,M=(-b*.5+.5)*g,P=m>=-1.1&&m<=1.1&&b>=-1.1&&b<=1.1&&x>=-1&&x<=1;if(P&&e){let[j,H,V]=jt(this),z=[r-j,s-H,a-V];l*z[0]+o*z[1]+c*z[2]>.05&&(P=!1)}return{x:y,y:M,z:x,visible:P}}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 l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],c=this.customTarget?[...this.customTarget]:[...this.bounds.center],d=this.currDistance/Math.max(t.clientHeight||300,1)*1.5;c[0]+=(-s*l[0]+a*o[0])*d,c[1]+=(-s*l[1]+a*o[1])*d,c[2]+=(-s*l[2]+a*o[2])*d,this.customTarget=c}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,l=r.width>0?Math.floor((t-r.left)*(s/r.width)):Math.floor(t),o=r.height>0?Math.floor((e-r.top)*(a/r.height)):Math.floor(e);return this.performMeshPick(l,o,!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 l=Le();Oe(l,this.projMatrix,this.viewMatrix);let o=[],c=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 M=0;M<this.meshes.length;M++){let P=this.meshes[M];if(P.visible===!1||P.isPluginMesh)continue;let j=M+1,H=(j&255)/255,V=(j>>8&255)/255,z=(j>>16&255)/255;r.uniform4f(this.uPick.uColorId,H,V,z,1),Oe(this.modelMatrix,this.modelRootMatrix,P.transform);let L=P.instanceMatrices;if(L&&L.length>=16){let O=L.length>>4,N=Le();for(let h of P.primitives){r.bindVertexArray(h.vao);for(let k=0;k<O;k++)Oe(N,this.modelMatrix,L.subarray(k*16,k*16+16)),Oe(this.mvpMatrix,l,N),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),Jt(r,h)}}else{Oe(this.mvpMatrix,l,this.modelMatrix),r.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let O of P.primitives)r.bindVertexArray(O.vao),Jt(r,O)}}let g=new Uint8Array(4);r.readPixels(c,d,1,1,6408,5121,g),r.bindFramebuffer(36160,null);let y=g[0]+(g[1]<<8)+(g[2]<<16);y>0&&y<=this.meshes.length&&(o=[this.meshes[y-1]])}o.length===0&&(o=this.meshes.filter(g=>g.visible!==!1));let u=null,n=1/0,f=[0,0,0],p=[0,1,0],[m,b,x]=jt(this),T=Le();for(let g of o){Oe(T,this.modelRootMatrix,g.transform);let y=g.instanceMatrices,M=y&&y.length>=16?y.length>>4:1;for(let P=0;P<M;P++){y&&y.length>=16?Oe(this.modelMatrix,T,y.subarray(P*16,P*16+16)):this.modelMatrix.set(T),Oe(this.mvpMatrix,l,this.modelMatrix);let j=Le();if(!Da(j,this.mvpMatrix))continue;let H=(c+.5)/s*2-1,V=(d+.5)/a*2-1,z=[0,0,0],L=[0,0,0];ur(z,H,V,-1,j),ur(L,H,V,1,j);let O=L[0]-z[0],N=L[1]-z[1],h=L[2]-z[2],k=Math.hypot(O,N,h)||1,X=O/k,A=N/k,I=h/k,C={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((w=>{for(let $ of g.primitives){if(!$.positions)continue;let Z=$.positions,ie=$.indices,ee=Math.floor(ie?ie.length/3:Z.length/9);for(let K=0;K<ee;K++){let ne=ie?ie[K*3]:K*3,re=ie?ie[K*3+1]:K*3+1,he=ie?ie[K*3+2]:K*3+2;Na(z[0],z[1],z[2],X,A,I,Z[ne*3],Z[ne*3+1],Z[ne*3+2],Z[re*3],Z[re*3+1],Z[re*3+2],Z[he*3],Z[he*3+1],Z[he*3+2],C,w)}}})(1e-4),isFinite(C.distance)){let w=C.point[0],$=C.point[1],Z=C.point[2],ie=this.modelMatrix,ee=ie[0]*w+ie[4]*$+ie[8]*Z+ie[12],K=ie[1]*w+ie[5]*$+ie[9]*Z+ie[13],ne=ie[2]*w+ie[6]*$+ie[10]*Z+ie[14],re=ee-m,he=K-b,Q=ne-x,ae=Math.hypot(re,he,Q);if(ae<n){ut(this.normalMatrix,this.modelMatrix);let te=this.normalMatrix,pe=C.normal[0],ue=C.normal[1],le=C.normal[2],_=te[0]*pe+te[3]*ue+te[6]*le,S=te[1]*pe+te[4]*ue+te[7]*le,D=te[2]*pe+te[5]*ue+te[8]*le,R=Math.hypot(_,S,D)||1;_/=R,S/=R,D/=R,_*re+S*he+D*Q>0&&(_=-_,S=-S,D=-D),u=g,n=Math.round(ae*1e3)/1e3,f=[Math.round(ee*1e3)/1e3,Math.round(K*1e3)/1e3,Math.round(ne*1e3)/1e3],p=[Math.round(_*1e3)/1e3,Math.round(S*1e3)/1e3,Math.round(D*1e3)/1e3]}}}}if(!u)return null;let v={meshIndex:this.meshes.indexOf(u),meshName:u.name,nodeIndex:u.nodeIndex,distance:n,hitPoint:f,normal:p,screenX:t,screenY:e};if(i){for(let g of ze)g.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(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,l=(s+.5)/a*2-1;return Math.floor((l*.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);vi(this.projMatrix,this.fov,t,.1,e);let i=this.customTarget||this.bounds.center;Yt(this.viewMatrix,jt(this),i,[0,1,0]),Oe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ut(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 ze)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 ze)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 ze)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 ze)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 l=t?.transform?.inverse?.matrix||this.viewMatrix,o=t?.projectionMatrix||this.projMatrix,c=t?.transform?.position,d=c?[c.x,c.y,c.z]:[0,1.6,0];e?this.modelRootMatrix.set(e):i&&e&&this.modelRootMatrix.set(e),this.render({viewMatrix:l,projMatrix:o,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 v=Math.max(2,this.canvas.width||2),g=Math.max(1,this.canvas.height||1),y=Math.max(1,Math.floor(v*.5)),M=Math.max(1,v-y),P=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),j=this.customTarget||this.bounds.center,[H,V,z]=jt(this),L=Math.cos(this.currTheta),O=-Math.sin(this.currTheta),N=.032,h=Le(),k=Le(),X=[H-L*N,V,z-O*N],A=[j[0]-L*N*.25,j[1],j[2]-O*N*.25];vi(h,this.fov,y/g,.1,P),Yt(k,X,A,[0,1,0]);let I=Le(),C=Le(),w=[H+L*N,V,z+O*N],$=[j[0]+L*N*.25,j[1],j[2]+O*N*.25];vi(I,this.fov,M/g,.1,P),Yt(C,w,$,[0,1,0]),this.render({viewMatrix:k,projMatrix:h,eyePos:X,viewport:[0,0,y,g],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:C,projMatrix:I,eyePos:w,viewport:[y,0,M,g],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,g);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 l=Le(),o=t?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,Oe(l,t?.projMatrix??this.projMatrix,o);let c=De().xrDepthShader,d=ka(this.toneMapping),[u,n,f]=t?t.eyePos:jt(this);for(let v of ze)v.onBeforeDrawScene?.(this,e,l,[u,n,f],d);let p=t?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let m=t?.eye||"none",b=!1,x=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,T=v=>{for(let g=0;g<x.length;g++){let y=x[g];if(y.visible===!1)continue;let M=this.selectedMeshName!==""&&y.name===this.selectedMeshName;g<p||y.worldSpace===!0||y.name==="__xr_reticle__"?this.modelMatrix.set(y.transform):Oe(this.modelMatrix,this.modelRootMatrix,y.transform),Oe(this.mvpMatrix,l,this.modelMatrix),ut(y.normalMatrix,this.modelMatrix);let P=y.extras?.xr?.stereo||y.userData?.xr?.stereo,j=0,H=0,V=1,z=1;P==="sbs"?(V=.5,j=m==="right"?.5:0):P==="ou"&&(z=.5,H=m==="right"?.5:0);for(let L of y.primitives){let O=!!L.isTransmissive;if(!v&&O){b=!0;continue}if(v&&!O)continue;let N=L.customProgram||this.renderProg,h=L.customUniforms||this.uRender;e.useProgram(N),e.vertexAttrib3f(3,0,0,0),h.uInstanced&&e.uniform1i(h.uInstanced,0),e.uniform1i(h.uToneMapping,d),e.uniform1f(h.uEnvIntensity,this.envIntensity),h.uExposure&&e.uniform1f(h.uExposure,this.exposure),e.uniform3f(h.uCameraPos,u,n,f),e.uniform1f(h.uEmissive,M?1:0),e.uniformMatrix4fv(h.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(h.uModel,!1,this.modelMatrix),e.uniformMatrix3fv(h.uNormalMatrix,!1,y.normalMatrix),h.uUvTransform&&e.uniform4f(h.uUvTransform,j,H,V,z),h.uViewportSize&&e.uniform2f(h.uViewportSize,Math.max(1,s),Math.max(1,a)),c?.bind(e,h,this.xrDepthState,o,[i,r,Math.max(1,s),Math.max(1,a)]),this.environmentTexture?(e.activeTexture(33988),e.bindTexture(3553,this.environmentTexture),e.uniform1i(h.uEnvironmentMap,4),e.uniform1i(h.uHasEnvironmentMap,1)):e.uniform1i(h.uHasEnvironmentMap,0),this.bindLights(h),h.uSectionEnabled&&e.uniform1i(h.uSectionEnabled,0);for(let X of ze)X.onBeforeDrawPrimitive?.(e,N,L,y,this.worldMatrices||[],this.gltf);e.uniform4fv(h.uBaseColor,L.baseColor),e.uniform1f(h.uMetallic,L.metallic),e.uniform1f(h.uRoughness,L.roughness),h.uClearcoat&&e.uniform2f(h.uClearcoat,L.clearcoat??0,L.clearcoatRoughness??.04),L.texture?(e.activeTexture(33984),e.bindTexture(3553,L.texture),e.uniform1i(h.uBaseColorTexture,0),e.uniform1i(h.uHasTexture,1)):e.uniform1i(h.uHasTexture,0),L.metallicRoughnessTexture?(e.activeTexture(33985),e.bindTexture(3553,L.metallicRoughnessTexture),e.uniform1i(h.uMetallicRoughnessTexture,1),e.uniform1i(h.uHasMetallicRoughnessTexture,1)):e.uniform1i(h.uHasMetallicRoughnessTexture,0),L.normalTexture?(e.activeTexture(33986),e.bindTexture(3553,L.normalTexture),e.uniform1i(h.uNormalTexture,2),e.uniform1i(h.uHasNormalTexture,1),e.uniform1f(h.uNormalScale,L.normalScale)):e.uniform1i(h.uHasNormalTexture,0),L.occlusionTexture?(e.activeTexture(33987),e.bindTexture(3553,L.occlusionTexture),e.uniform1i(h.uOcclusionTexture,3),e.uniform1i(h.uHasOcclusionTexture,1),e.uniform1f(h.uOcclusionStrength,L.occlusionStrength)):e.uniform1i(h.uHasOcclusionTexture,0),e.bindVertexArray(L.vao);let k=y.instanceMatrices;if(L.instanceCount!==void 0)e.drawElementsInstanced(4,L.indexCount,L.indexType,0,L.instanceCount);else if(k&&k.length>=16&&L.instanced&&h.uInstanced&&h.uViewProj){let X=k.length>>4;e.uniform1i(h.uInstanced,1),e.uniformMatrix4fv(h.uViewProj,!1,l),L.indices?e.drawElementsInstanced(4,L.indexCount,L.indexType,0,X):e.drawArraysInstanced(4,0,L.indexCount,X),e.uniform1i(h.uInstanced,0)}else if(k&&k.length>=16){let X=k.length>>4,A=y.instanceColors,I=Le(),C=new Float32Array(9),w=[L.baseColor[0],L.baseColor[1],L.baseColor[2],L.baseColor[3]];for(let $=0;$<X;$++)Oe(I,this.modelMatrix,k.subarray($*16,$*16+16)),Oe(this.mvpMatrix,l,I),ut(C,I),e.uniformMatrix4fv(h.uMVP,!1,this.mvpMatrix),e.uniformMatrix4fv(h.uModel,!1,I),e.uniformMatrix3fv(h.uNormalMatrix,!1,C),A&&(w[0]=L.baseColor[0]*A[$*3],w[1]=L.baseColor[1]*A[$*3+1],w[2]=L.baseColor[2]*A[$*3+2],w[3]=L.baseColor[3],e.uniform4fv(h.uBaseColor,w)),Jt(e,L)}else Jt(e,L)}}};if(T(!1),b){for(let v of ze)v.onBeforeTransmissivePass?.(e,this);T(!0)}for(let v of ze)v.onAfterRender?.(e,this,l,t?.eye??"none",[i,r,s,a],t?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(t,e){Tr(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 ze)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()}};Ar.registerPlugin=Pa,Ar.getRegisteredPlugins=Ca;function Wa(t){return t+3&-4}var Me=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function _r(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,l,o,,c,d,u,,n,f,p]=Array.from({length:15},(C,w)=>Me(t[e+w],w%5===0?1:0)),m=Math.hypot(i,r,s),b=Math.hypot(a,l,o),x=Math.hypot(c,d,u);i*(l*u-d*o)-a*(r*u-d*s)+c*(r*o-l*s)<0&&(m=-m);let T=Math.abs(m)>1e-8?1/m:0,v=Math.abs(b)>1e-8?1/b:0,g=Math.abs(x)>1e-8?1/x:0,y=i*T,M=r*T,P=s*T,j=a*v,H=l*v,V=o*v,z=c*g,L=d*g,O=u*g,N=y+H+O,h=0,k=0,X=0,A=1;if(N>0){let C=.5/Math.sqrt(N+1);A=.25/C,h=(V-L)*C,k=(z-P)*C,X=(M-j)*C}else if(y>H&&y>O){let C=2*Math.sqrt(Math.max(0,1+y-H-O));C>1e-8&&(A=(V-L)/C,h=.25*C,k=(j+M)/C,X=(z+P)/C)}else if(H>O){let C=2*Math.sqrt(Math.max(0,1+H-y-O));C>1e-8&&(A=(z-P)/C,h=(j+M)/C,k=.25*C,X=(V+L)/C)}else{let C=2*Math.sqrt(Math.max(0,1+O-y-H));C>1e-8&&(A=(M-j)/C,h=(z+P)/C,k=(V+L)/C,X=.25*C)}let I=Math.hypot(h,k,X,A);return I>1e-8&&Number.isFinite(I)?(h/=I,k/=I,X/=I,A/=I):(h=0,k=0,X=0,A=1),{t:[n,f,p],r:[h,k,X,A],s:[m,b,x]}}function qa(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 ct=(t,e,i,r)=>typeof t=="number"&&Number.isFinite(t)?Math.max(e,Math.min(i,t)):r;function Cr(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:ct(i.volume,0,2,.6),loop:typeof i.loop=="boolean"?i.loop:!0,isGlobal:i.type==="global"||i.positional===!1}}function Vt(t,e){return Er(t,e)[0]}function Er(t,e){t.updateMatrixWorld(!0);let i=[],r=0,s=[],a=[],l=[],o=[],c=new Set,d=[],u=[],n=new Map,f=[],p=[],m=[],b=new Map,x=[],T=[];function v(A){let I=n.get(A);if(I!==void 0)return I;I=u.length,n.set(A,I);let C=A,w=C.color?.r??.8,$=C.color?.g??.8,Z=C.color?.b??.8,ie=C.opacity??1,ee={baseColorFactor:[w,$,Z,ie],metallicFactor:C.metalness??0,roughnessFactor:C.roughness??.5},K={};if(C.map){let he="";typeof C.map=="string"?he=C.map:typeof C.map.source=="string"?he=C.map.source:typeof C.map.image=="string"&&(he=C.map.image);let Q=he.trim(),ae=Q&&!/[\x00-\x1f\x7f\\]|\.\./.test(Q)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(Q)||!Q.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(Q))?Q:null;if(ae){let pe=b.get(ae);if(pe===void 0){let ue=f.length;f.push({uri:ae}),p.length===0&&p.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),pe=m.length,m.push({sampler:0,source:ue}),b.set(ae,pe)}ee.baseColorTexture={index:pe}}let te=C.map.avgColor;Array.isArray(te)&&te.length>=3&&(K.avgColor=[te[0],te[1],te[2]])}let ne={name:C.name||"",pbrMetallicRoughness:ee,doubleSided:C.side===2||!!C.doubleSided,...Object.keys(K).length>0?{extras:K}:{}};if(C.emissive&&(C.emissive.r>0||C.emissive.g>0||C.emissive.b>0)){let he=C.emissiveIntensity??1;ne.emissiveFactor=[C.emissive.r*he,C.emissive.g*he,C.emissive.b*he]}let re={};return C.clearcoat&&C.clearcoat>0&&(re.KHR_materials_clearcoat={clearcoatFactor:C.clearcoat,clearcoatRoughnessFactor:C.clearcoatRoughness||0}),C.sheen&&C.sheen>0&&(re.KHR_materials_sheen={sheenColorFactor:C.sheenColor?[C.sheenColor.r,C.sheenColor.g,C.sheenColor.b]:[1,1,1],sheenRoughnessFactor:C.sheenRoughness||0}),C.transmission&&C.transmission>0&&(re.KHR_materials_transmission={transmissionFactor:C.transmission}),C.thickness&&C.thickness>0&&(re.KHR_materials_volume={thicknessFactor:C.thickness,attenuationDistance:C.attenuationDistance??1/0,attenuationColor:C.attenuationColor?[C.attenuationColor.r,C.attenuationColor.g,C.attenuationColor.b]:[1,1,1]}),C.ior!==void 0&&C.ior!==1.5&&(re.KHR_materials_ior={ior:C.ior}),C.dispersion&&C.dispersion>0&&(re.KHR_materials_dispersion={dispersion:C.dispersion}),C.iridescence&&C.iridescence>0&&(re.KHR_materials_iridescence={iridescenceFactor:C.iridescence,iridescenceIor:C.iridescenceIOR??1.3}),Object.keys(re).length>0&&(ne.extensions=re),u.push(ne),I}function g(A,I){let C=new Uint8Array(A.buffer,A.byteOffset,A.byteLength),w=Wa(C.byteLength),$=new Uint8Array(w);$.set(C),i.push($);let Z=s.length;return s.push({buffer:0,byteOffset:r,byteLength:C.byteLength,target:I}),r+=w,Z}function y(A,I,C,w,$,Z,ie){let ee=g(A,C),K=a.length,ne={bufferView:ee,byteOffset:0,componentType:w,count:$,type:I};return Z&&(ne.min=Z),ie&&(ne.max=ie),a.push(ne),K}t.traverse(A=>{if(A.isLight||A.color&&A.intensity!==void 0){let I=A.matrixWorld?.elements,C=Me(I?I[12]:A.position?.x,0),w=Me(I?I[13]:A.position?.y,0),$=Me(I?I[14]:A.position?.z,0),Z=A.target,ie=Z?.parent?Z?.matrixWorld?.elements:void 0,ee=Me(ie?ie[12]:Z?.position?.x,0),K=Me(ie?ie[13]:Z?.position?.y,0),ne=Me(ie?ie[14]:Z?.position?.z,0),re=ee-C,he=K-w,Q=ne-$,ae=Math.hypot(re,he,Q),te=Math.max(.01,Math.min(Math.PI/2,Me(A.angle,Math.PI/3))),pe=Math.max(0,Math.min(1,Me(A.penumbra,0)));T.push({type:A.type,color:[A.color.r,A.color.g,A.color.b],intensity:A.intensity,position:[C,w,$],...A.type==="spot"?{direction:ae>1e-6?[re/ae,he/ae,Q/ae]:[0,-1,0],outerConeAngle:te,innerConeAngle:Math.max(0,te*(1-pe)),range:Math.max(0,Me(A.distance,0))}:A.type==="point"?{range:Math.max(0,Me(A.distance,0))}:{}})}});let M=[],P=new Set([t]),j=[];if(Array.isArray(t.children))for(let A=t.children.length-1;A>=0;A--)j.push({obj:t.children[A],parentKids:M});for(;j.length>0;){let{obj:A,parentKids:I}=j.pop();if(!A||typeof A!="object"||P.has(A))continue;P.add(A),A._bakeAuthorGeometry?.(),De().materializeDeclarativeGeometry?.(A);let C=!!(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)),w={name:A.name||(C?`Node_${o.length}`:"")},$=Me(A.position?.x,0),Z=Me(A.position?.y,0),ie=Me(A.position?.z,0),ee=Me(A.quaternion?.x,0),K=Me(A.quaternion?.y,0),ne=Me(A.quaternion?.z,0),re=Me(A.quaternion?.w,1),he=Me(A.scale?.x,1),Q=Me(A.scale?.y,1),ae=Me(A.scale?.z,1);if(($||Z||ie)&&(w.translation=[$,Z,ie]),(ee||K||ne||re!==1)&&(w.rotation=[ee,K,ne,re]),(he!==1||Q!==1||ae!==1)&&(w.scale=[he,Q,ae]),A.visible===!1&&(w.extensions={...w.extensions||{},KHR_node_visibility:{visible:!1}},c.add("KHR_node_visibility")),A.userData&&Object.keys(A.userData).length>0&&(w.extras=JSON.parse(JSON.stringify(A.userData,(ue,le)=>{if(!(ue==="__proto__"||ue==="prototype"||ue==="constructor"))return typeof le=="function"?void 0:le})),A.userData.xr)){let ue=qa(A.userData.xr);w.extensions={...w.extensions||{},MOZ_hubs_components:ue,ANDROID_xr_scenecore:ue},De().xrTraitSerializer?.gltfNode(w,A.userData.xr),c.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(A.geometry){let ue=A.geometry,le=ue.attributes.position;if(le&&le.count>0){let _=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let B=0;B<le.count;B++){let G=le.getX(B),U=le.getY(B),Y=le.getZ(B);G<_[0]&&(_[0]=G),G>S[0]&&(S[0]=G),U<_[1]&&(_[1]=U),U>S[1]&&(S[1]=U),Y<_[2]&&(_[2]=Y),Y>S[2]&&(S[2]=Y)}let D={attributes:{POSITION:y(le.array,"VEC3",34962,5126,le.count,_,S)}};if(ue.attributes.normal&&(D.attributes.NORMAL=y(ue.attributes.normal.array,"VEC3",34962,5126,ue.attributes.normal.count)),ue.attributes.uv&&(D.attributes.TEXCOORD_0=y(ue.attributes.uv.array,"VEC2",34962,5126,ue.attributes.uv.count)),ue.index){let B=ue.index.array instanceof Uint32Array;D.indices=y(ue.index.array,"SCALAR",34963,B?5125:5123,ue.index.count)}let R=Array.isArray(A.material)?A.material[0]:A.material;R&&(D.material=v(R));let E=A.userData?.variants;if(E&&typeof E=="object"){let B=new Map;for(let G of Object.keys(E)){if(!G||G==="__proto__"||G==="constructor"||G==="prototype")continue;let U=E[G];if(!U||typeof U!="object")continue;let Y=x.indexOf(G);if(Y===-1&&x.length<256&&(Y=x.length,x.push(G)),Y===-1)continue;let J=v(U),W=B.get(J);W||(W=[],B.set(J,W)),W.push(Y)}if(B.size>0){let G=[];for(let[U,Y]of B.entries())G.push({material:U,variants:Y});D.extensions={...D.extensions||{},KHR_materials_variants:{mappings:G}},c.add("KHR_materials_variants")}}let F=A;if(F.isInstancedMesh&&typeof F.count=="number"&&F.count>0&&F.instanceMatrix?.array){let B=Math.min(1e4,Math.floor(F.count)),G=F.instanceMatrix.array,U=new Float32Array(B*3),Y=new Float32Array(B*4),J=new Float32Array(B*3);for(let oe=0;oe<B;oe++){let{t:ce,r:me,s:de}=Pr(G,oe*16);U[oe*3]=ce[0],U[oe*3+1]=ce[1],U[oe*3+2]=ce[2],Y[oe*4]=me[0],Y[oe*4+1]=me[1],Y[oe*4+2]=me[2],Y[oe*4+3]=me[3],J[oe*3]=de[0],J[oe*3+1]=de[1],J[oe*3+2]=de[2]}let W={TRANSLATION:y(U,"VEC3",0,5126,B),ROTATION:y(Y,"VEC4",0,5126,B),SCALE:y(J,"VEC3",0,5126,B)};if(F.instanceColor?.array&&F.instanceColor.array.length>=B*3){let oe=new Float32Array(F.instanceColor.array.subarray(0,B*3));W._COLOR_0=y(oe,"VEC3",0,5126,B)}w.extensions={...w.extensions||{},EXT_mesh_gpu_instancing:{attributes:W}},c.add("EXT_mesh_gpu_instancing")}let q=l.length;l.push({primitives:[D],name:A.name,...w.extras?{extras:w.extras}:{}}),w.mesh=q}}let te=o.length;o.push(w),d.push(A),I.push(te);let pe=A.children;if(Array.isArray(pe)&&pe.length>0){let ue=[];w.children=ue;for(let le=pe.length-1;le>=0;le--)j.push({obj:pe[le],parentKids:ue})}}for(let A=0;A<o.length;A++){let I=o[A];I.children&&I.children.length===0?delete I.children:I.children&&I.children.length>0&&(I.extras?.xr?.lod||I.extensions?.ANDROID_xr_scenecore?.lod||d[A]?.isLOD)&&(I.extensions={...I.extensions||{},MSFT_lod:{ids:[...I.children]}},c.add("MSFT_lod"))}let H=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),V=[];if(typeof H=="function"&&d.length>0){let A=e?.duration??4,I=e?.fps??15,C=Math.max(2,Math.round(A*I)+1),w=new Float32Array(C),$=d.map(Q=>[Me(Q.position?.x,0),Me(Q.position?.y,0),Me(Q.position?.z,0),Me(Q.quaternion?.x,0),Me(Q.quaternion?.y,0),Me(Q.quaternion?.z,0),Me(Q.quaternion?.w,1),Me(Q.scale?.x,1),Me(Q.scale?.y,1),Me(Q.scale?.z,1)]),Z=d.map(()=>new Float32Array(C*3)),ie=d.map(()=>new Float32Array(C*4)),ee=d.map(()=>new Float32Array(C*3));for(let Q=0;Q<C;Q++){let ae=Q/(C-1)*A;w[Q]=ae;try{H(ae)}catch{}for(let te=0;te<d.length;te++){let pe=d[te];Z[te][Q*3]=Me(pe.position?.x,0),Z[te][Q*3+1]=Me(pe.position?.y,0),Z[te][Q*3+2]=Me(pe.position?.z,0);let ue=Me(pe.quaternion?.x,0),le=Me(pe.quaternion?.y,0),_=Me(pe.quaternion?.z,0),S=Me(pe.quaternion?.w,1),D=Math.hypot(ue,le,_,S)||1;if(ue/=D,le/=D,_/=D,S/=D,Q>0){let R=(Q-1)*4,E=ie[te];E[R]*ue+E[R+1]*le+E[R+2]*_+E[R+3]*S<0&&(ue=-ue,le=-le,_=-_,S=-S)}ie[te][Q*4]=ue,ie[te][Q*4+1]=le,ie[te][Q*4+2]=_,ie[te][Q*4+3]=S,ee[te][Q*3]=Me(pe.scale?.x,1),ee[te][Q*3+1]=Me(pe.scale?.y,1),ee[te][Q*3+2]=Me(pe.scale?.z,1)}}for(let Q=0;Q<d.length;Q++){let ae=d[Q],te=$[Q];ae.position?.set(te[0],te[1],te[2]),ae.quaternion?.set(te[3],te[4],te[5],te[6]),ae.scale?.set(te[7],te[8],te[9])}t.updateMatrixWorld(!0);let K=null,ne=()=>(K===null&&(K=y(w,"SCALAR",0,5126,C,[0],[A])),K),re=[],he=[];for(let Q=0;Q<d.length;Q++){let ae=$[Q],te=(ue,le,_)=>ue.some((S,D)=>Math.abs(S-ae[_+D%le])>1e-4),pe=(ue,le,_,S)=>{ue&&he.push({sampler:re.push({input:ne(),interpolation:"LINEAR",output:y(le,_,0,5126,C)})-1,target:{node:Q,path:S}})};pe(te(Z[Q],3,0),Z[Q],"VEC3","translation"),pe(te(ie[Q],4,3),ie[Q],"VEC4","rotation"),pe(te(ee[Q],3,7),ee[Q],"VEC3","scale")}he.length>0&&V.push({name:"ProceduralLoop",samplers:re,channels:he})}let z=hr(o,l,t.userData),L=[],O=[],N=[];for(let A=0;A<o.length;A++){let I=o[A],C=Cr(I.extras?.xr);if(!C)continue;let{ae:w,src:$,preset:Z,volume:ie,loop:ee,isGlobal:K}=C,ne=I.name||`Node_${A}`,re=O.length;O.push({name:`${ne}_source`,gain:ie,loop:ee,autoPlay:typeof w.autoplay=="boolean"?w.autoplay:!0,...$!==void 0?{audio:L.push({uri:$})-1}:{},...Z?{extras:{preset:Z,pitch:ct(w.pitch,.25,4,1)}}:{}});let he=N.length,Q=ct(w.refDistance,.05,100,1),ae=ct(w.coneInnerAngle,0,360,360),te=ct(w.coneOuterAngle,ae,360,360);N.push({name:`${ne}_emitter`,type:K?"global":"positional",gain:ie,sources:[re],...K?{}:{positional:{distanceModel:w.distanceModel==="linear"||w.distanceModel==="exponential"?w.distanceModel:"inverse",refDistance:Q,maxDistance:ct(w.maxDistance,Q,500,Math.max(Q,25)),rolloffFactor:ct(w.rolloffFactor,0,10,1),coneInnerAngle:+(ae*Math.PI/180).toFixed(6),coneOuterAngle:+(te*Math.PI/180).toFixed(6),coneOuterGain:ct(w.coneOuterGain,0,1,0)}}}),I.extensions={...I.extensions||{},KHR_audio_emitter:{emitter:he}},c.add("KHR_audio_emitter")}let h={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:M}],scene:0,nodes:o,meshes:l,materials:u,...f.length>0?{images:f}:{},...p.length>0?{samplers:p}:{},...m.length>0?{textures:m}:{},accessors:a,bufferViews:s,buffers:[{byteLength:r}],...V.length>0?{animations:V}:{},...z||c.size>0?{extensionsUsed:[...z?["KHR_interactivity"]:[],...c]}:{},...z||x.length>0||N.length>0?{extensions:{...z?{KHR_interactivity:z}:{},...x.length>0?{KHR_materials_variants:{variants:x.map(A=>({name:A}))}}:{},...N.length>0?{KHR_audio_emitter:{...L.length>0?{audio:L}:{},sources:O,emitters:N}}:{}}}:{}},k=new Uint8Array(r),X=0;for(let A of i)k.set(A,X),X+=A.byteLength;return[{gltf:h,bin:k.buffer,lights:T,environmentIntensity:t.environmentIntensity},d]}function Pi(t){return new TextEncoder().encode(t)}function ei(t,e){let{gltf:i,bin:r}=Vt(t,e),s=JSON.stringify(i),a=Pi(s),l=(4-a.byteLength%4)%4,o=a.byteLength+l,c=20+o+8+r.byteLength,d=new Uint8Array(c),u=new DataView(d.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,c,!0),u.setUint32(12,o,!0),u.setUint32(16,1313821514,!0),d.set(a,20);for(let f=0;f<l;f++)d[20+a.byteLength+f]=32;let n=20+o;return u.setUint32(n,r.byteLength,!0),u.setUint32(n+4,5130562,!0),d.set(new Uint8Array(r),n+8),d}function Xa(t,e){let[i,r]=Er(t,e);return Ci(i,r)}function Ci(t,e){let i=[],r=t.gltf,s=De().decoders.get("meshopt");s&&typeof s.decodeBufferViews=="function"&&s.decodeBufferViews(r,t);let a=t.bin,l=a instanceof ArrayBuffer?a:a.buffer.slice(a.byteOffset,a.byteOffset+a.byteLength),o=r.accessors||[],c=r.bufferViews||[],d=r.materials||[],u=r.meshes||[],n=r.nodes||[],f=new Set,p=d.map((x,T)=>_r(f,ti(x?.name,`Material_${T}`)));function m(x){let T=o[x];if(!T)throw new Error(`Accessor ${x} not found`);let v=c[T.bufferView||0],g=(v.byteOffset||0)+(T.byteOffset||0),y=v.byteLength||0;return{acc:T,buffer:l.slice(g,g+y)}}function b(x,T,v,g){let y=[],M=u[x];if(!M)return y;let P=M.primitives||[];for(let j=0;j<P.length;j++){let H=P[j],V=H.attributes?.POSITION;if(V===void 0)continue;let{acc:z,buffer:L}=m(V),O=new Float32Array(L,0,z.count*3),N,h=H.attributes?.NORMAL;if(h!==void 0){let{acc:re,buffer:he}=m(h),Q=new Float32Array(he,0,re.count*3);N=new Float32Array(Q.length);for(let ae=0;ae<re.count;ae++){let te=Q[ae*3],pe=Q[ae*3+1],ue=Q[ae*3+2],le=Math.hypot(te,pe,ue)||1;N[ae*3]=te/le,N[ae*3+1]=pe/le,N[ae*3+2]=ue/le}}let k,X=H.attributes?.TEXCOORD_0;if(X!==void 0){let{acc:re,buffer:he}=m(X);k=new Float32Array(he,0,re.count*2)}let A;if(H.indices!==void 0){let{acc:re,buffer:he}=m(H.indices);A=re.componentType===5125?new Uint32Array(he,0,re.count):new Uint16Array(he,0,re.count);let Q=z.count;for(let ae of A)if(ae>=Q)throw new Error(`SecurityError: Index buffer value (${ae}) out of vertex bounds [0, ${Q}).`)}else{let re=z.count;A=re>65535?new Uint32Array(re):new Uint16Array(re);for(let he=0;he<re;he++)A[he]=he}let I="DefaultMaterial",C=[.8,.8,.8],w=.5,$=0,Z=0,ie=0,ee=1.5,K=1,ne=[0,0,0];if(H.material!==void 0&&d[H.material]){let re=d[H.material];I=p[H.material]||`Material_${H.material}`;let he=re.pbrMetallicRoughness||{},Q=(ue,le)=>Array.isArray(ue)&&ue.length>=3?[ue[0],ue[1],ue[2]]:le;C=Q(he.baseColorFactor,[1,1,1]);let ae=re.extras?.avgColor;Array.isArray(ae)&&ae.length>=3&&(C=[C[0]*ae[0],C[1]*ae[1],C[2]*ae[2]]);let te=Array.isArray(he.baseColorFactor)&&typeof he.baseColorFactor[3]=="number"?he.baseColorFactor[3]:1;typeof he.roughnessFactor=="number"&&(w=he.roughnessFactor),typeof he.metallicFactor=="number"&&($=he.metallicFactor),ne=Q(re.emissiveFactor,[0,0,0]);let pe=re.extensions||{};pe.KHR_materials_clearcoat&&(Z=pe.KHR_materials_clearcoat.clearcoatFactor??0,ie=pe.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof pe.KHR_materials_ior?.ior=="number"&&(ee=pe.KHR_materials_ior.ior),K=te*(1-(pe.KHR_materials_transmission?.transmissionFactor??0))}y.push({name:P.length>1?`${T}_p${j}`:T,positions:O,indices:A,normals:N,uvs:k,materialName:I,color:C,roughness:w,metallic:$,clearcoat:Z,clearcoatRoughness:ie,ior:ee,opacity:K,emissiveColor:ne,xrTraits:v||M.extras?.xr,...g?{invisible:!0}:{}})}return y}if(n.length>0){let x=new Float32Array(0),T=new Uint16Array(0),v=(O,N)=>{if(O===void 0)return null;let{acc:h,buffer:k}=m(O);return new Float32Array(k,0,h.count*N)},g=(O,N)=>Array.isArray(O)&&O.length>=3?[Me(O[0],N),Me(O[1],N),Me(O[2],N)]:[N,N,N],y=(O,N,h)=>O&&O.length>=(N+1)*3?[O[N*3],O[N*3+1],O[N*3+2]]:h,M=(O,N,h)=>O&&O.length>=(N+1)*4?[O[N*4],O[N*4+1],O[N*4+2],O[N*4+3]]:h,P=new Map,j=r.animations?.[0];if(j&&Array.isArray(j.channels)&&Array.isArray(j.samplers))for(let O of j.channels){let N=j.samplers[O?.sampler],h=O?.target?.node,k=O?.target?.path;if(!N||typeof h!="number"||N.input===void 0)continue;let X=P.get(h);X||(X={input:N.input},P.set(h,X)),k==="translation"?X.t=N.output:k==="rotation"?X.r=N.output:k==="scale"&&(X.s=N.output)}let H=r.scenes?.[r.scene??0]?.nodes??[];if(!Array.isArray(H)||H.length===0){let O=new Set;for(let N of n)if(Array.isArray(N?.children))for(let h of N.children)O.add(h);H=[];for(let N=0;N<n.length;N++)O.has(N)||H.push(N);H.length===0&&(H=[0])}let V=new Set,z=[],L=(O,N)=>{if(Array.isArray(O))for(let h=O.length-1;h>=0;h--)z.push({idx:O[h],out:N})};for(L(H,i);z.length>0;){let{idx:O,out:N}=z.pop();if(typeof O!="number"||O<0||O>=n.length||V.has(O))continue;V.add(O);let h=n[O];if(!h)continue;let k=[0,0,0],X=[0,0,0,1],A=[1,1,1];if(Array.isArray(h.matrix)&&h.matrix.length===16){let K=Pr(h.matrix);k=K.t,X=K.r,A=K.s}else k=g(h.translation,0),Array.isArray(h.rotation)&&h.rotation.length>=4&&(X=[Me(h.rotation[0],0),Me(h.rotation[1],0),Me(h.rotation[2],0),Me(h.rotation[3],1)]),A=g(h.scale,1);let I,C=P.get(O);if(C){let K=v(C.input,1);if(K&&K.length>0){let ne=v(C.t,3),re=v(C.r,4),he=v(C.s,3),Q=Array.from(K),ae=[],te=[],pe=[];for(let ue=0;ue<K.length;ue++)ae.push(y(ne,ue,k)),te.push(M(re,ue,X)),pe.push(y(he,ue,A));I={times:Q,translations:ae,rotations:te,scales:pe}}}let w=Array.isArray(h.children)?h.children:[],$=typeof h.mesh=="number"&&h.mesh>=0&&h.mesh<u.length,Z=e?.[O]?.userData?.xr??h.extras?.xr;if(!$&&w.length===0&&(h.camera!==void 0||h.extensions?.KHR_lights_punctual||!h.name&&!h.extras&&!Z&&!I))continue;let ie=(K,ne,re)=>({name:K,positions:x,indices:T,isXform:!0,xrTraits:Z,timeSamples:I,translation:k,rotation:X,scale:A,children:ne,...re?{invisible:!0}:{}}),ee=h.visible===!1||h.extensions?.KHR_node_visibility?.visible===!1||e?.[O]?.visible===!1;if($){let K=h.name||u[h.mesh]?.name||`Mesh_${O}`,ne=b(h.mesh,K,Z,ee),re=h.extensions?.EXT_mesh_gpu_instancing?.attributes;if(re&&typeof re=="object"&&ne.length>0){let he=v(re.TRANSLATION,3),Q=v(re.ROTATION,4),ae=v(re.SCALE,3),te=v(re._COLOR_0,3),pe=Math.min(1e3,he?he.length/3:Q?Q.length/4:ae?ae.length/3:0);if(pe>0){let ue=[];for(let le=0;le<pe;le++){let _=y(he,le,[0,0,0]),S=M(Q,le,[0,0,0,1]),D=y(ae,le,[1,1,1]);for(let R of ne){let E=R.color||[.8,.8,.8],F=te&&te.length>=(le+1)*3;ue.push({...R,name:`${R.name}_${le}`,materialName:F?`${R.materialName}_inst_${le}`:R.materialName,color:F?[E[0]*te[le*3],E[1]*te[le*3+1],E[2]*te[le*3+2]]:R.color,translation:_,rotation:S,scale:D})}}L(w,ue),N.push(ie(K,ue,ee));continue}}if(ne.length===1)ne[0].translation=k,ne[0].rotation=X,ne[0].scale=A,ne[0].timeSamples=I,w.length>0&&(ne[0].children=[],L(w,ne[0].children)),N.push(ne[0]);else{let he=[...ne];L(w,he),N.push(ie(K,he,ee))}}else{let K=[];L(w,K),N.push(ie(h.name||`Group_${O}`,K,ee))}}}else for(let x=0;x<u.length;x++){let T=u[x].name||`Mesh_${x}`;i.push(...b(x,T,u[x].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 Ei(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Ie(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 ot=(t,e,i)=>`(${Ie(t)}, ${Ie(e)}, ${Ie(i)})`,Dr=(t,e,i,r)=>`(${Ie(t)}, ${Ie(e)}, ${Ie(i)}, ${Ie(r)})`;function Nr(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]=ot(t[r*3],t[r*3+1],t[r*3+2]);return i.join(", ")}function Ka(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]=`(${Ie(t[r*2])}, ${Ie(1-t[r*2+1])})`;return i.join(", ")}function Za(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function Di(t){let e=new Map,i=0,r=null,s=[...t];for(;s.length>0;){let m=s.pop();if(!m.isXform&&m.positions&&m.positions.length>0){let b=ti(m.materialName,"DefaultMaterial");e.has(b)||e.set(b,{color:m.color||[.8,.8,.8],roughness:m.roughness??.5,metallic:m.metallic??0,clearcoat:m.clearcoat??0,clearcoatRoughness:m.clearcoatRoughness??0,ior:m.ior??1.5,opacity:m.opacity??1,emissiveColor:m.emissiveColor||[0,0,0]})}if(m.timeSamples&&m.timeSamples.times.length>0){let b=m.timeSamples.times[m.timeSamples.times.length-1];b>i&&(i=b)}if(m.xrTraits?.anchor&&!r&&(r=m.xrTraits.anchor==="vertical"||m.xrTraits.anchor==="wall"?"vertical":"horizontal"),m.children)for(let b=m.children.length-1;b>=0;b--)s.push(m.children[b])}let a="";i>0&&(a=`startTimeCode = 0
|
|
251
|
-
endTimeCode = ${
|
|
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 = ${$e(i)}
|
|
252
252
|
timeCodesPerSecond = 1.0
|
|
253
|
-
`);let
|
|
253
|
+
`);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
|
|
254
254
|
uniform token preliminary:planeAnchoring:alignment = "${r}"
|
|
255
|
-
`);let
|
|
255
|
+
`);let n=`#usda 1.0
|
|
256
256
|
(
|
|
257
257
|
defaultPrim = "Root"
|
|
258
258
|
metersPerUnit = 1.0
|
|
@@ -263,90 +263,117 @@ def Xform "Root" (
|
|
|
263
263
|
kind = "component"
|
|
264
264
|
)
|
|
265
265
|
{
|
|
266
|
-
${
|
|
266
|
+
${o}def Scope "Materials"
|
|
267
267
|
{
|
|
268
|
-
`;for(let[
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
`),
|
|
273
|
-
`),
|
|
268
|
+
`;for(let[y,x]of e.entries()){let[w,v,_]=x.color,[f,g,T]=x.emissiveColor,R=`/Root/Materials/${y}`,[U,j,$,L,E]=x.textures||[],B=(A,z)=>`.connect = <${R}/${A}.outputs:${z}>`,I=U?`color3f inputs:diffuseColor${B("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${dt(w,v,_)}`,c=j?`float inputs:metallic${B("MetallicRoughnessTexture","b")}
|
|
269
|
+
float inputs:roughness${B("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${$e(x.metallic)}
|
|
270
|
+
float inputs:roughness = ${$e(x.roughness)}`,k="";x.clearcoat>0&&(k+=`float inputs:clearcoat = ${$e(x.clearcoat)}
|
|
271
|
+
`,k+=`float inputs:clearcoatRoughness = ${$e(x.clearcoatRoughness)}
|
|
272
|
+
`),x.ior!==1.5&&(k+=`float inputs:ior = ${$e(x.ior)}
|
|
273
|
+
`),x.opacity<1&&(k+=`float inputs:opacity = ${$e(x.opacity)}
|
|
274
|
+
`),L?k+=`color3f inputs:emissiveColor${B("EmissiveTexture","rgb")}
|
|
275
|
+
`:(f>0||g>0||T>0)&&(k+=`color3f inputs:emissiveColor = ${dt(f,g,T)}
|
|
276
|
+
`),$&&(k+=`normal3f inputs:normal${B("NormalTexture","rgb")}
|
|
277
|
+
`),E&&(k+=`float inputs:occlusion${B("OcclusionTexture","r")}
|
|
278
|
+
`);let K="";if(U||j||$||L||E){K+=`def Shader "PrimvarReader"
|
|
279
|
+
{
|
|
280
|
+
uniform token info:id = "UsdPrimvarReader_float2"
|
|
281
|
+
string inputs:varname = "st"
|
|
282
|
+
float2 outputs:result
|
|
283
|
+
}
|
|
284
|
+
`;let A=(z,S,b,O)=>{if(!S)return;let X=S.scale?`float4 inputs:scale = ${ri(S.scale[0],S.scale[1],S.scale[2],S.scale[3])}
|
|
285
|
+
`:"",te=S.bias?`float4 inputs:bias = ${ri(S.bias[0],S.bias[1],S.bias[2],S.bias[3])}
|
|
286
|
+
`:"";K+=`def Shader "${z}"
|
|
287
|
+
{
|
|
288
|
+
uniform token info:id = "UsdUVTexture"
|
|
289
|
+
asset inputs:file = @${ii(S.file)}@
|
|
290
|
+
float2 inputs:st${B("PrimvarReader","result")}
|
|
291
|
+
token inputs:sourceColorSpace = "${b}"
|
|
292
|
+
token inputs:wrapS = "${S.wrapS||"repeat"}"
|
|
293
|
+
token inputs:wrapT = "${S.wrapT||"repeat"}"
|
|
294
|
+
${X}${te}${O}}
|
|
295
|
+
`};A("DiffuseTexture",U,"sRGB",`float3 outputs:rgb
|
|
296
|
+
`),A("MetallicRoughnessTexture",j,"raw",`float outputs:g
|
|
297
|
+
float outputs:b
|
|
298
|
+
`),A("NormalTexture",$,"raw",`float3 outputs:rgb
|
|
299
|
+
`),A("EmissiveTexture",L,"sRGB",`float3 outputs:rgb
|
|
300
|
+
`),A("OcclusionTexture",E,"raw",`float outputs:r
|
|
301
|
+
`)}n+=`def Material "${y}"
|
|
274
302
|
{
|
|
275
303
|
def Shader "PBRShader"
|
|
276
304
|
{
|
|
277
305
|
uniform token info:id = "UsdPreviewSurface"
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
${P}token outputs:surface
|
|
282
|
-
}
|
|
283
|
-
token outputs:surface.connect = </Root/Materials/${m}/PBRShader.outputs:surface>
|
|
306
|
+
${I}
|
|
307
|
+
${c}
|
|
308
|
+
${k}token outputs:surface
|
|
284
309
|
}
|
|
285
|
-
|
|
310
|
+
token outputs:surface${B("PBRShader","surface")}
|
|
311
|
+
${K}}
|
|
312
|
+
`}n+=`}
|
|
286
313
|
def Scope "Meshes"
|
|
287
314
|
{
|
|
288
|
-
`;let
|
|
315
|
+
`;let u=(y,x,w)=>{let v=[];x&&v.push('"MaterialBindingAPI"');let _=!!(y?.rigidBody&&y.rigidBody!=="none"&&(typeof y.rigidBody!="object"||y.rigidBody.enabled!==!1)),f=!!(y?.physics&&y.physics!=="none"||_);f&&v.push(..._?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let g=[];if(v.length>0&&g.push(`prepend apiSchemas = [${v.join(", ")}]`),y){let $=Re().xrTraitSerializer?.usdLines(y,ii)??[];if(!$.length)for(let L of["grab","billboard","follow","anchor","physics"]){let E=L==="follow"&&typeof y.follow=="object"?y.follow.mode??"head":y[L];E!==void 0&&$.push(`string ${L} = "${ii(E)}"`)}$.length>0&&g.push(`customData = {
|
|
289
316
|
dictionary xr = {
|
|
290
|
-
${
|
|
317
|
+
${$.join(`
|
|
291
318
|
`)}
|
|
292
319
|
}
|
|
293
|
-
}`)}let
|
|
294
|
-
${
|
|
320
|
+
}`)}let T=g.length>0?` (
|
|
321
|
+
${g.join(`
|
|
295
322
|
`)}
|
|
296
|
-
)`:"",
|
|
297
|
-
`:"";if(
|
|
298
|
-
bool physics:kinematicEnabled = ${
|
|
323
|
+
)`:"",R=w?`uniform token visibility = "invisible"
|
|
324
|
+
`:"";if(f){let $=y?.rigidBody??y?.physics,L=$?.body??$?.mode??$;R+=`bool physics:rigidBodyEnabled = true
|
|
325
|
+
bool physics:kinematicEnabled = ${L==="static"||L==="kinematic"}
|
|
299
326
|
bool physics:collisionEnabled = true
|
|
300
|
-
|
|
301
|
-
`)}let
|
|
327
|
+
`,$?.mass>0&&Number.isFinite($.mass)&&(R+=`float physics:mass = ${$e($.mass)}
|
|
328
|
+
`)}let U=Dr(y),j=U?`def SpatialAudio "AudioEmitter"
|
|
302
329
|
{
|
|
303
|
-
${
|
|
304
|
-
`:""}uniform token inputs:auralMode = "${
|
|
305
|
-
uniform token inputs:playbackMode = "${
|
|
306
|
-
double gain = ${
|
|
330
|
+
${U.src?`asset inputs:file = @${ii(U.src)}@
|
|
331
|
+
`:""}uniform token inputs:auralMode = "${U.isGlobal?"nonSpatial":"spatial"}"
|
|
332
|
+
uniform token inputs:playbackMode = "${U.loop?"loopFromStart":"onceFromStart"}"
|
|
333
|
+
double gain = ${$e(U.volume)}
|
|
307
334
|
}
|
|
308
|
-
`:"";return{header:
|
|
309
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
310
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
335
|
+
`:"";return{header:T,body:R,tail:j}},d=y=>{if(y.timeSamples&&y.timeSamples.times.length>0){let g=y.timeSamples,T=($,L,E)=>g.times.map((B,I)=>`${$e(B)}: ${E($?.[I]||L)}`).join(", "),R=T(g.translations,[0,0,0],$=>dt($[0],$[1],$[2])),U=T(g.rotations,[0,0,0,1],$=>{let L=Math.hypot($[0],$[1],$[2],$[3])||1;return ri($[3]/L,$[0]/L,$[1]/L,$[2]/L)}),j=T(g.scales,[1,1,1],$=>dt($[0],$[1],$[2]));return`double3 xformOp:translate.timeSamples = { ${R} }
|
|
336
|
+
quatf xformOp:orient.timeSamples = { ${U} }
|
|
337
|
+
double3 xformOp:scale.timeSamples = { ${j} }
|
|
311
338
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
312
|
-
`}let
|
|
313
|
-
`,
|
|
314
|
-
`,
|
|
315
|
-
`,
|
|
316
|
-
`),
|
|
317
|
-
int[] faceVertexCounts = [${
|
|
318
|
-
int[] faceVertexIndices = [${
|
|
319
|
-
point3f[] points = [${
|
|
320
|
-
`;return
|
|
339
|
+
`}let x=[],w="",v=y.translation;v&&(Math.abs(v[0])>1e-7||Math.abs(v[1])>1e-7||Math.abs(v[2])>1e-7)&&(w+=`double3 xformOp:translate = ${dt(v[0],v[1],v[2])}
|
|
340
|
+
`,x.push('"xformOp:translate"'));let _=y.rotation;if(_){let g=Math.hypot(_[0],_[1],_[2],_[3])||1,T=_[0]/g,R=_[1]/g,U=_[2]/g,j=_[3]/g;(1-Math.abs(j)>1e-7||Math.hypot(T,R,U)>1e-7)&&(w+=`quatf xformOp:orient = ${ri(j,T,R,U)}
|
|
341
|
+
`,x.push('"xformOp:orient"'))}let f=y.scale;return f&&(Math.abs(f[0]-1)>1e-7||Math.abs(f[1]-1)>1e-7||Math.abs(f[2]-1)>1e-7)&&(w+=`float3 xformOp:scale = ${dt(f[0],f[1],f[2])}
|
|
342
|
+
`,x.push('"xformOp:scale"')),x.length>0&&(w+=`uniform token[] xformOpOrder = [${x.join(", ")}]
|
|
343
|
+
`),w},h=y=>{let x=y.positions.length/3,w=1/0,v=1/0,_=1/0,f=-1/0,g=-1/0,T=-1/0;for(let L=0;L<x;L++){let E=y.positions[L*3],B=y.positions[L*3+1],I=y.positions[L*3+2];E<w&&(w=E),E>f&&(f=E),B<v&&(v=B),B>g&&(g=B),I<_&&(_=I),I>T&&(T=I)}isFinite(w)||(w=v=_=-1,f=g=T=1);let R=Math.floor(y.indices.length/3),U=ti(y.materialName,"DefaultMaterial"),j=R>0?R===1?"3":"3, ".repeat(R-1)+"3":"",$=`float3[] extent = [${dt(w,v,_)}, ${dt(f,g,T)}]
|
|
344
|
+
int[] faceVertexCounts = [${j}]
|
|
345
|
+
int[] faceVertexIndices = [${Va(y.indices)}]
|
|
346
|
+
point3f[] points = [${Er(y.positions)}]
|
|
347
|
+
`;return y.normals&&y.normals.length===y.positions.length&&($+=`normal3f[] normals = [${Er(y.normals)}] (
|
|
321
348
|
interpolation = "vertex"
|
|
322
349
|
)
|
|
323
|
-
`),
|
|
350
|
+
`),y.uvs&&y.uvs.length===x*2&&($+=`texCoord2f[] primvars:st = [${ja(y.uvs,x)}] (
|
|
324
351
|
interpolation = "vertex"
|
|
325
352
|
)
|
|
326
|
-
`)
|
|
327
|
-
|
|
328
|
-
`;continue}let{node:
|
|
353
|
+
`),$+=`rel material:binding = </Root/Materials/${U}>
|
|
354
|
+
`,$},l=new Set,p=[];for(let y=t.length-1;y>=0;y--)p.push({node:t[y],siblings:l});let m=0;for(;p.length>0;){let y=p.pop();if(y.close){n+=`}
|
|
355
|
+
`;continue}let{node:x,siblings:w}=y,v=!!(x.isXform||x.positions.length===0),_=Ar(w,ti(x.name,v?`Group_${m}`:`Mesh_${m}`));m++;let f=x.children||[];if(v){let g=u(x.xrTraits,!1,x.invisible);n+=`def Xform "${_}"${g.header}
|
|
329
356
|
{
|
|
330
|
-
${
|
|
357
|
+
${g.body}${d(x)}${g.tail}`,p.push({close:!0});let T=new Set;for(let R=f.length-1;R>=0;R--)p.push({node:f[R],siblings:T})}else if(f.length>0){let g=u(x.xrTraits,!1,x.invisible),T=`${_}_mesh`;n+=`def Xform "${_}"${g.header}
|
|
331
358
|
{
|
|
332
|
-
${
|
|
359
|
+
${g.body}${d(x)}${g.tail}`,n+=`def Mesh "${T}" (
|
|
333
360
|
prepend apiSchemas = ["MaterialBindingAPI"]
|
|
334
361
|
)
|
|
335
362
|
{
|
|
336
|
-
${
|
|
337
|
-
`,
|
|
363
|
+
${h(x)}}
|
|
364
|
+
`,p.push({close:!0});let R=new Set([T]);for(let U=f.length-1;U>=0;U--)p.push({node:f[U],siblings:R})}else{let g=u(x.xrTraits,!0,x.invisible);n+=`def Mesh "${_}"${g.header}
|
|
338
365
|
{
|
|
339
|
-
${
|
|
340
|
-
`}}return
|
|
366
|
+
${g.body}${d(x)}${h(x)}${g.tail}}
|
|
367
|
+
`}}return n+=`}
|
|
341
368
|
}
|
|
342
|
-
`,o}function Ya(t,e){if(t&&typeof t.traverse=="function"){let s=Xa(t,e);return Di(s)}let i=Qt(t),r=Ci(i);return Di(r)}var ii=null;function Ni(t){{let i=globalThis.__three_live_native_crc32__;if(typeof i=="function")return i(t)}if(!ii){ii=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;ii[i]=r}}let e=4294967295;for(let i=0;i<t.length;i++)e=ii[(e^t[i])&255]^e>>>8;return(e^4294967295)>>>0}function Qa(t){{let u=globalThis.__three_live_native_build_usdz_zip__;if(typeof u=="function")return u(t)}let e=[],i=0,r=[];for(let u of t){let n=Pi(u.filename),f=Ni(u.data),p=u.data.length,m=30+n.length,b=(i+m)%64,x=b!==0?64-b:0,T=new Uint8Array(m+x),v=new DataView(T.buffer);v.setUint32(0,67324752,!0),v.setUint16(4,20,!0),v.setUint32(14,f,!0),v.setUint32(18,p,!0),v.setUint32(22,p,!0),v.setUint16(26,n.length,!0),v.setUint16(28,x,!0),T.set(n,30),e.push({offset:i,size:p,crc:f,filenameBytes:n,entry:u}),r.push(T,u.data),i+=T.length+u.data.length}let s=i;for(let u of e){let n=new Uint8Array(46+u.filenameBytes.length),f=new DataView(n.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint32(16,u.crc,!0),f.setUint32(20,u.size,!0),f.setUint32(24,u.size,!0),f.setUint16(28,u.filenameBytes.length,!0),f.setUint32(42,u.offset,!0),n.set(u.filenameBytes,46),r.push(n),i+=n.length}let a=i-s,l=new Uint8Array(22),o=new DataView(l.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,e.length,!0),o.setUint16(10,e.length,!0),o.setUint32(12,a,!0),o.setUint32(16,s,!0),r.push(l),i+=22;let c=new Uint8Array(i),d=0;for(let u of r)c.set(u,d),d+=u.length;return c}var Rr=t=>Qa([{filename:"model.usda",data:Pi(t)}]);function ri(t){return Rr(Ya(t))}function Ri(t){return Rr(Di(Ci(Qt(t))))}function Lr(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():Ri(t)}function se(t,e,i,r){let s=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(i,s))}function Je(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 Qe(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function Ja(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:se(e.distance,.1,10,r?.15:1),deadzoneDeg:se(e.deadzoneDeg,0,90,r?0:15),stiffness:se(e.stiffness,.5,40,6),height:se(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function eo(t){let e=ge(t);if(!e)return null;let i=e.target;return{target:Je(i)?[i[0],i[1],i[2]]:typeof i=="string"&&i.length>0&&i.length<=256?i:[0,0,0],radius:se(e.radius,.01,50,.5),speed:se(e.speed,-20,20,.5),height:se(e.height,-10,10,0),phase:se(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function to(t){if(!t)return null;let e=ge(t)??{},i=se(e.minScale??e.min,.001,1e3,.1),r=se(e.maxScale??e.max,i,1e3,Math.max(i,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:i,maxScale:r}}var zr=2e3,io={rain:600,snow:400,sparks:300,confetti:300};function ro(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=l=>se(l,.05,50,2),a=Je(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(se(e.count,1,zr,io[i])),area:a,speed:se(e.speed,.05,10,1)}}var so=4e3;function ao(t){if(!t)return null;let e=ge(t)??{};return{prompt:Qe(e.prompt,so)??"What is this?",holdMs:se(e.holdMs,100,5e3,600)}}function oo(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 si(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 no(t){let e=typeof t=="string"?{src:t}:ge(t),i=si(e?.src);return!e||!i?null:{src:i,refDistance:se(e.refDistance,.01,1e3,1),loop:e.loop===!0}}var kr=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],lo=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Ur=new Set(kr),ho=new Set(lo);function Et(t){return!!(t&&(Ur.has(t)||ho.has(t)))}function Fr(t){if(!t)return null;let e=null;if(typeof t=="string"){let g=t.trim();if(!g)return null;e=Et(g)?{preset:g}:{src:g}}else e=ge(t);if(!e||e.enabled===!1)return null;let i=Qe(e.preset,32)?.trim(),r=Et(i)?i:void 0,s=si(e.src??e.url??e.uri);if(!r&&!s)return null;let a=!r||Ur.has(r),l=e.type==="global"||e.positional===!1?"global":"positional",o=se(e.volume??e.gain,0,2,.6),c=se(e.pitch??e.playbackRate,.25,4,1),d=typeof e.loop=="boolean"?e.loop:a,u=typeof e.autoplay=="boolean"?e.autoplay:typeof e.autoPlay=="boolean"?e.autoPlay:!0,n=e.distanceModel==="linear"||e.distanceModel==="exponential"?e.distanceModel:"inverse",f=se(e.refDistance,.05,100,1),p=se(e.maxDistance,f,500,Math.max(f,25)),m=se(e.rolloffFactor,0,10,1),b=se(e.coneInnerAngle,0,360,360),x=se(e.coneOuterAngle,b,360,Math.max(b,360)),T=se(e.coneOuterGain,0,1,0),v=e.playOnSelect===!0||e.playOnTap===!0;return{...r?{preset:r}:{},...s?{src:s}:{},type:l,volume:o,pitch:c,loop:d,autoplay:u,distanceModel:n,refDistance:f,maxDistance:p,rolloffFactor:m,coneInnerAngle:b,coneOuterAngle:x,coneOuterGain:T,playOnSelect:v}}function Gt(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 uo=new Set(["m","cm","mm","in","ft-in","auto"]),Ir=["x","y","z"];function co(t){if(!t)return null;let e=ge(t);if(e&&e.enabled===!1)return null;let i=e?.unit,r=typeof i=="string"&&uo.has(i)?i:"auto",s=e?.axes,a=new Set(Array.isArray(s)?s.filter(o=>typeof o=="string"):typeof s=="string"?s.split(""):[]),l=Ir.filter(o=>a.has(o));return{enabled:!0,unit:r,axes:l.length>0?l:[...Ir],color:Gt(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var po=new Set(["none","floor","wall","ceiling","any"]);function mo(t){if(!t)return null;let e=ge(t)??{},i=e.grid,r=l=>se(l,.001,100,.1),s=Je(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:se(e.angleDeg,0,180,0),surface:typeof a=="string"&&po.has(a)?a:"none",socketTag:Qe(e.socketTag,128)??"",radius:se(e.radius,.01,2,.15)}}function fo(t){let e=typeof t=="string"?{tag:t}:ge(t),i=Qe(e?.tag,128);return!e||!i?null:{tag:i,radius:se(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:Gt(e.highlightColor,"#22c55e")}}function go(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(se(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:i==="ask"?"ask":"select"}}function yo(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(Je(i)){let l=Math.hypot(i[0],i[1],i[2]);l>1e-8&&(r=[i[0]/l,i[1]/l,i[2]/l],e?.direction===void 0&&e?.offset!==void 0&&(s=l))}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:se(typeof a=="number"?Math.abs(a):void 0,0,10,.35),layer:Math.round(se(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var Li=new Set(["__proto__","constructor","prototype"]);function et(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||Li.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function zi(t){let e=ge(t);if(!e||e.persist===!1)return null;let i=et(e.id);return e.persist!==!0&&!i?null:i?{id:i,persist:!0}:{persist:!0}}function bo(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function xo(t){let e=typeof t=="string"?{text:t}:ge(t),i=Qe(e?.text??e?.value,256);if(!e||!i)return null;let r=se(e.size,.005,10,.12);return{text:i,size:r,depth:se(e.depth??e.height,.001,5,r*.2),color:Gt(e.color,"#ffffff")}}function vo(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=se(e.strength??e.intensity,0,5,.35);return i>0?{enabled:!0,strength:i,threshold:se(e.threshold,0,4,.8),radius:se(e.radius,0,2,.5)}:null}function Mo(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:Gt(e.color,"#38bdf8"),thickness:se(typeof i=="number"&&i>0&&i<.25?Math.max(1.5,i*140):i,.5,20,3),pulse:e.pulse===!0}}function wo(t){let e=ge(t);if(!e||e.enabled===!1)return null;let i=et(e.root),r=et(e.effector);if(!i||!r)return null;let s=et(e.mid),a=e.target,l;if(Je(a))l=[se(a[0],-1e3,1e3,0),se(a[1],-1e3,1e3,0),se(a[2],-1e3,1e3,0)];else{let u=et(a);if(!u)return null;l=u}let o=e.pole??e.poleTarget,c=Je(o)?[se(o[0],-1e3,1e3,0),se(o[1],-1e3,1e3,0),se(o[2],-1e3,1e3,0)]:et(o),d=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||s?"two-bone":"fabrik";return{root:i,...s?{mid:s}:{},effector:r,target:l,...c?{pole:c}:{},solver:d,iterations:Math.round(se(e.iterations,1,32,8)),tolerance:se(e.tolerance,1e-5,.1,.001),weight:se(e.weight,0,1,1)}}function To(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=se(e.hysteresis,0,.5,.05),r=[],s;if(Array.isArray(e.levels)&&e.levels.length>0){let c=e.levels.slice(0,8);for(let u=0;u<c.length;u++){let n=ge(c[u]);if(!n)continue;let f=se(n.distance,0,1e4,u===0?0:u*4),p=typeof n.hysteresis=="number"?se(n.hysteresis,0,.5,i):void 0,m=typeof n.ratio=="number"?se(n.ratio,.05,1,.5):void 0,b=typeof n.childIndex=="number"&&Number.isFinite(n.childIndex)?Math.max(0,Math.round(n.childIndex)):void 0,x=et(n.node);r.push({distance:f,...p!==void 0?{hysteresis:p}:{},...m!==void 0?{ratio:m}:{},...b!==void 0?{childIndex:b}:{},...x?{node:x}:{}})}r.sort((u,n)=>u.distance-n.distance),r.length>0&&r[0].distance>0&&r.unshift({distance:0,childIndex:0});let d=0;r=r.slice(0,8).map((u,n)=>{let f=n===0?0:Math.max(d,u.distance);return d=f,{...u,distance:f,childIndex:u.childIndex??n}})}if(Array.isArray(e.ratios)&&e.ratios.length>0){let c=[];for(let d of e.ratios.slice(0,7))typeof d=="number"&&c.push(se(d,.05,1,.5));c.length>0&&(s=c)}if(r.length===0){let c=Array.isArray(e.distances)?e.distances:[],d=[];for(let n of c.slice(0,8))typeof n=="number"&&d.push(se(n,0,1e4,4));if(d.length===0&&s&&s.length>0)for(let n=0;n<s.length;n++)d.push((n+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 u=0;for(let n=0;n<Math.min(8,d.length);n++){let f=n===0?0:Math.max(u,d[n]);u=f;let p=n>0&&s?s[n-1]:void 0;r.push({distance:f,childIndex:n,...p!==void 0?{ratio:p}:{}})}}else if(!s){let c=[];for(let d=1;d<r.length;d++)typeof r[d].ratio=="number"&&c.push(r[d].ratio);c.length>0&&(s=c)}let a=r.map(c=>c.distance),l=a[a.length-1]??0,o=e.cullDistance!==void 0&&e.cullDistance!==null&&e.cullDistance!==!1?se(e.cullDistance,Math.max(1,l),1e4,100):void 0;return{levels:r,distances:a,...s?{ratios:s}:{},hysteresis:i,...o!==void 0?{cullDistance:o}:{}}}var Or=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),So=new Set(["capsule","cylindrical","spherical"]),Ht=[];function Ao(t){Ht.includes(t)||Ht.push(t)}function ki(t){let e=ge(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 l=e.scale??e.scalable;if(l||r("scale")){let k=ge(l)??{},X=se(k.min,.001,1e3,.05);s.scale={min:X,max:se(k.max,X,1e3,Math.max(X,5))},s.scalable=!0}let o=e.billboard;typeof o=="string"&&So.has(o)?s.billboard=o:(o===!0||r("billboard"))&&(s.billboard="capsule");let c=e.follow,d=typeof c=="string"?c:ge(c)?.mode;if(typeof c=="string"?c:ge(c)?.lazy===!1)s.follow=d==="hand-left"||d==="hand-right"?d:"head";else{let k=Ja(c);k&&(s.follow=k)}let u=e.anchor??(e.floor===!0||e.ground===!0?"floor":void 0);if(typeof u=="string"&&Or.has(u))s.anchor=u;else{let k=ge(u)?.target;typeof k=="string"&&Or.has(k)&&(s.anchor=k);let X=zi(u)??zi(e.anchorPersist);X&&(s.anchorPersist=X)}if(!s.anchorPersist){let k=zi(e.anchorPersist)??(s.anchor&&e.persist===!0?{persist:!0,...et(e.id)?{id:et(e.id)}:{}}:null);k&&(s.anchorPersist=k)}(e.physics==="dynamic"||e.physics==="static")&&(s.physics=e.physics);let n=eo(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));n&&(s.orbit=n);let f=to(e.handles??e.resizable??e.scaleLimits);f&&(s.handles=f);let p=ro(e.particles??e.emitter);p&&(s.particles=p);let m=ao(e.holdToAsk);m&&(s.holdToAsk=m);let b=oo(e.worldUnderstanding);b&&(s.worldUnderstanding=b);let x=si(e.splatUrl);x&&(s.splatUrl=x),(e.splatQuality==="high"||e.splatQuality==="standard")&&(s.splatQuality=e.splatQuality);let T=Qe(e.spatialSlot);T&&(s.spatialSlot=T);let v=typeof e.audio=="string"&&Et(e.audio.trim())?null:no(e.audio);v&&(s.audio=v);let g=e.audioEmitter??e.spatialAudio??e.positionalAudio??e.sound??e.panner;if(g!==void 0){let k=Fr(g);k&&(s.audioEmitter=k)}else if(e.audio!==void 0){let k=ge(e.audio),X=!!(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(!v||X){let A=Fr(e.audio);A&&(s.audioEmitter=A)}}let y=co(e.dimensions??e.measure??e.measurement??e.ruler);y&&(s.dimensions=y);let M=mo(e.snapTo??e.snap??e.magnetic);M&&(s.snapTo=M);let P=fo(e.snapSocket);P&&(s.snapSocket=P);let j=go(e.gaze??e.dwell);j&&(s.gaze=j);let H=yo(e.explode??e.exploded??e.disassemble);H&&(s.explode=H);let V=bo(e.navigable??(e.walkable!==void 0?e.walkable?"walkable":"blocked":e.teleport===!0?"walkable":void 0));V&&(s.navigable=V);let z=xo(e.text??e.label??e.title??e.caption??e.spatialLabel);z&&(s.text=z);let L=vo(e.bloom??e.glow);L&&(s.bloom=L);let O=Mo(e.outline);O&&(s.outline=O);let N=wo(e.ik);N&&(s.ik=N);let h=To(e.lod??e.levelOfDetail??e.detail??e.decimate??e.simplify);h&&(s.lod=h),typeof e.sync=="boolean"&&(s.sync=e.sync),e.pointerEvents==="none"&&(s.pointerEvents="none");for(let k of Ht)k.normalize(e,s);return Object.keys(s).length>0?s:null}var $r=1;function Br(t){let e={schemaVersion:$r};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 Ht)i.sceneCore(t,e);return e}function _o(t){let e={schemaVersion:$r},i=(r,s)=>{for(let[a,l]of Object.entries(s)){let o=r+a[0].toUpperCase()+a.slice(1);typeof l=="string"||typeof l=="number"||typeof l=="boolean"?e[o]=l:Je(l)&&(e[o]=[l[0],l[1],l[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 Ht)r.usd(t,i,e);return e}function Po(t,e){let i=ki(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 Co(t,e){let i=ki(t),r=[];if(!i)return r;for(let[s,a]of Object.entries(_o(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(l=>Number.isFinite(l))&&r.push(`double3 ${s} = (${a.join(", ")})`));return r}function Eo(){try{Object.defineProperty(De(),"xrTraitSerializer",{value:Object.freeze({gltfNode:Po,usdLines:Co}),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"]),ai={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 Do(t,e){let i=t.length,r=e.length,s=Array.from({length:r+1},(a,l)=>l);for(let a=1;a<=i;a++){let l=s[0];s[0]=a;for(let o=1;o<=r;o++){let c=s[o];s[o]=t[a-1]===e[o-1]?l:1+Math.min(l,s[o],s[o-1]),l=c}}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 l=s[a];if(l==="traits")continue;let o=Do(e,l.toLowerCase());o<r&&(r=o,i=l)}return i}function No(t,e="unnamed"){let i=[];if(t==null)return i;let r=(w,$,Z,ie="warning")=>i.push({code:w,severity:ie,node:e,message:$,hint:Z}),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 w of Object.keys(s)){if(Ui.has(w))continue;let $=ai[w]??ai[w.toLowerCase()];if($)r("TL201",`Unrecognized key '${w}' in userData.xr on node '${e}' (auto-normalized to '${$.target}'); did you mean '${$.target}'?`,$.hint,"info");else if((w==="radius"||w==="speed"||w==="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 '${w}' in userData.xr on node '${e}' auto-normalized to 'orbit.${w}'.`,"Use 'orbit: { target, radius, speed }' instead of top-level orbit properties.","info");else if((w==="speed"||w==="height"||w==="radius")&&(s.character!==void 0||s.player!==void 0||s.avatar!==void 0||s.controller!==void 0))r("TL201",`Top-level '${w}' in userData.xr on node '${e}' auto-normalized to 'character.${w}'.`,"Use 'character: { speed, height, radius }' instead of top-level character properties.","info");else if(w==="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 Z=Gr(w);r("TL201",Z?`Unknown key '${w}' on node '${e}'; did you mean '${Z}'?`:`Unknown key '${w}' in userData.xr on node '${e}'.`,Z?`Replace '${w}' with '${Z}'.`:"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 w of s.traits)if(typeof w=="string"&&!Ui.has(w)){let $=ai[w]??ai[w.toLowerCase()],Z=$?.target??Gr(w);r("TL201",Z?`Unknown trait '${w}' in userData.xr.traits on node '${e}'; did you mean '${Z}'?`:`Unknown trait '${w}' in userData.xr.traits on node '${e}'.`,$?.hint??(Z?`Use '${Z}' instead of '${w}'.`:"Use canonical trait keys on userData.xr directly."))}}let a=(w,$,Z,ie)=>{if(typeof $=="number"){if(!Number.isFinite($)){r("TL202",`Numeric trait parameter '${w}' on node '${e}' is non-finite (${$}); clamped to default.`,`Provide a finite number in [${Z}, ${ie}] for '${w}'.`);return}if($<Z||$>ie){let ee=Math.max(Z,Math.min(ie,$));r("TL202",`Numeric trait parameter '${w}' (${$}) on node '${e}' is out of range [${Z}, ${ie}]; clamped to ${ee}.`,`Keep '${w}' within [${Z}, ${ie}].`)}}},l=ge(s.scale);if(l){a("scale.min",l.min,.001,1e3);let w=se(l.min,.001,1e3,.05);a("scale.max",l.max,w,1e3)}let o=ge(s.follow);o&&o.lazy!==!1&&(a("follow.distance",o.distance,.1,10),a("follow.deadzoneDeg",o.deadzoneDeg,0,90),a("follow.stiffness",o.stiffness,.5,40),a("follow.height",o.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 w=se(d.minScale,.001,1e3,.1);a("handles.maxScale",d.maxScale,w,1e3)}let u=ge(s.particles);if(u){if(a("particles.count",u.count,1,zr),a("particles.speed",u.speed,.05,10),typeof u.area=="number")a("particles.area",u.area,.05,50);else if(Array.isArray(u.area))for(let w=0;w<Math.min(3,u.area.length);w++)a(`particles.area[${w}]`,u.area[w],.05,50)}let n=ge(s.holdToAsk);n&&a("holdToAsk.holdMs",n.holdMs,100,5e3);let f=ge(s.audio);f&&a("audio.refDistance",f.refDistance,.01,1e3);let p=ge(s.audioEmitter)??ge(s.spatialAudio)??(f&&!f.src?f:null);if(p&&p.enabled!==!1){a("audioEmitter.volume",p.volume??p.gain,0,2),a("audioEmitter.pitch",p.pitch??p.playbackRate,.25,4),a("audioEmitter.refDistance",p.refDistance,.05,100);let w=se(p.refDistance,.05,100,1);a("audioEmitter.maxDistance",p.maxDistance,w,500),a("audioEmitter.rolloffFactor",p.rolloffFactor,0,10),a("audioEmitter.coneInnerAngle",p.coneInnerAngle,0,360);let $=se(p.coneInnerAngle,0,360,360);a("audioEmitter.coneOuterAngle",p.coneOuterAngle,$,360),a("audioEmitter.coneOuterGain",p.coneOuterGain,0,1)}let m=ge(s.snapTo);if(m){if(a("snapTo.angleDeg",m.angleDeg,0,180),a("snapTo.radius",m.radius,.01,2),typeof m.grid=="number"&&m.grid>0)a("snapTo.grid",m.grid,.001,100);else if(Array.isArray(m.grid))for(let w=0;w<Math.min(3,m.grid.length);w++)a(`snapTo.grid[${w}]`,m.grid[w],.001,100)}let b=ge(s.snapSocket);b&&a("snapSocket.radius",b.radius,.01,2);let x=ge(s.gaze);x&&x.enabled!==!1&&a("gaze.dwellMs",x.dwellMs,250,1e4);let T=ge(s.explode);T&&T.enabled!==!1&&(a("explode.distance",T.distance,-10,10),a("explode.layer",T.layer,1,10));let v=ge(s.text);if(v&&(a("text.size",v.size,.005,10),a("text.depth",v.depth??v.height,.001,5)),typeof s.bloom=="number"&&s.bloom>0)a("bloom",s.bloom,0,5);else{let w=ge(s.bloom);w&&w.enabled!==!1&&(a("bloom.strength",w.strength??w.intensity,0,5),a("bloom.threshold",w.threshold,0,4),a("bloom.radius",w.radius,0,2))}let g=ge(s.outline);if(g&&g.enabled!==!1){let w=g.thickness??g.width;typeof w=="number"&&!(w>0&&w<.25)&&a("outline.thickness",w,.5,20)}let y=ge(s.ik);y&&y.enabled!==!1&&(a("ik.iterations",y.iterations,1,32),a("ik.tolerance",y.tolerance,1e-5,.1),a("ik.weight",y.weight,0,1));let M=ge(s.lod);if(M&&M.enabled!==!1){if(a("lod.hysteresis",M.hysteresis,0,.5),M.cullDistance!==void 0&&M.cullDistance!==null&&M.cullDistance!==!1&&a("lod.cullDistance",M.cullDistance,1,1e4),Array.isArray(M.distances)){let w=-1/0;for(let $=0;$<Math.min(8,M.distances.length);$++){let Z=M.distances[$];a(`lod.distances[${$}]`,Z,0,1e4),typeof Z=="number"&&Number.isFinite(Z)&&(Z<w&&r("TL202",`lod.distances[${$}] (${Z}) on node '${e}' is less than previous distance (${w}); clamped to monotonic order.`,"Sort lod.distances in non-decreasing order (e.g. [3, 8])."),w=Math.max(w,Z))}}if(Array.isArray(M.ratios))for(let w=0;w<Math.min(7,M.ratios.length);w++)a(`lod.ratios[${w}]`,M.ratios[w],.05,1)}let P=ge(s.character);if(P&&P.enabled!==!1){a("character.speed",P.speed,.1,20),a("character.runMultiplier",P.runMultiplier,1,4),a("character.jumpVelocity",P.jumpVelocity,0,30),a("character.gravity",P.gravity,0,50),a("character.radius",P.radius,.05,5);let w=se(P.radius,.05,5,.35);a("character.height",P.height,w*2,10),a("character.cameraDistance",P.cameraDistance,.5,50),a("character.cameraHeight",P.cameraHeight,-10,50)}let j=ge(s.agent);if(j&&j.enabled!==!1&&(a("agent.speed",j.speed,.1,20),a("agent.turnSpeed",j.turnSpeed,.1,50),a("agent.sightRadius",j.sightRadius,0,100),a("agent.stopDistance",j.stopDistance,.01,10),a("agent.separationRadius",j.separationRadius,0,10)),typeof s.integrity=="number")a("integrity.max",s.integrity,1,1e6);else{let w=ge(s.integrity);if(w&&w.enabled!==!1){a("integrity.max",w.max,1,1e6);let $=se(w.max,1,1e6,100);a("integrity.current",w.current,0,$),a("integrity.cooldownMs",w.cooldownMs,0,1e4),a("integrity.scoreValue",w.scoreValue,-1e6,1e6),a("integrity.contactAmount",w.contactAmount,0,1e6)}}let H=ge(s.zone);if(H&&H.enabled!==!1){if(a("zone.radius",H.radius,.01,1e3),typeof H.size=="number")a("zone.size",H.size,.01,1e3);else if(Array.isArray(H.size))for(let w=0;w<Math.min(3,H.size.length);w++)a(`zone.size[${w}]`,H.size[w],.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 z=ge(s.objective);z&&z.enabled!==!1&&(a("objective.amount",z.amount??z.points,-1e6,1e6),a("objective.radius",z.radius,.05,50),a("objective.order",z.order,0,1e3),a("objective.spinSpeed",z.spinSpeed,-50,50),a("objective.bobAmplitude",z.bobAmplitude,0,5),a("objective.respawnSec",z.respawnSec,0,3600));let L=ge(s.audioCues);L&&(a("audioCues.pitchJitter",L.pitchJitter,0,.5),a("audioCues.volume",L.volume,0,1));let O=ge(s.rigidBody)??ge(s.physics);O&&O.enabled!==!1&&(a("rigidBody.mass",O.mass,.01,1e3),a("rigidBody.restitution",O.restitution,0,1),a("rigidBody.friction",O.friction,0,1),a("rigidBody.linearDamping",O.linearDamping,0,20),a("rigidBody.angularDamping",O.angularDamping,0,20),a("rigidBody.gravityScale",O.gravityScale,-5,5));let N=(w,$)=>{$!=null&&(si($)||r("TL203",`Unsafe or disallowed media URL in '${w}' (${JSON.stringify($)}) 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"))},h=(w,$)=>{$!=null&&(et($)||r("TL203",`Unsafe or invalid identifier in '${w}' (${JSON.stringify($)}) 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&&N("splatUrl",s.splatUrl),typeof s.audio=="string"?Et(s.audio.trim())||N("audio",s.audio):f&&(f.src!==void 0?N("audio.src",f.src):f.preset===void 0&&Object.keys(f).some(w=>w.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")Et(k.trim())||N("audioEmitter",k);else if(p){let w=p.src??p.url??p.uri;w!==void 0&&N("audioEmitter.src",w),typeof p.preset=="string"&&!Et(p.preset.trim())&&r("TL201",`Unknown audio preset '${p.preset}' in audioEmitter on node '${e}'.`,`Supported ambient presets: ${kr.join(", ")}.`)}let X=(w,$)=>{if($==null||$==="")return;let Z=typeof $=="string"?$.trim():"";(!Z||!/^[A-Za-z0-9_.:-]{1,64}$/.test(Z)||Li.has(Z))&&r("TL203",`Unsafe or invalid identifier in '${w}' (${JSON.stringify($)}) 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=ge(s.integrity);if(A&&A.group!==void 0&&X("integrity.group",A.group),H&&H.watchGroups!==void 0){let w=Array.isArray(H.watchGroups)?H.watchGroups:[H.watchGroups];for(let $=0;$<w.length;$++)X(`zone.watchGroups[${$}]`,w[$])}z&&z.tag!==void 0&&X("objective.tag",z.tag);let I=ge(s.anchor);I&&I.id!==void 0&&h("anchor.id",I.id);let C=ge(s.anchorPersist);if(C&&C.id!==void 0&&h("anchorPersist.id",C.id),y&&y.enabled!==!1){h("ik.root",y.root),h("ik.effector",y.effector),y.mid!==void 0&&h("ik.mid",y.mid),y.target!==void 0&&!Array.isArray(y.target)&&h("ik.target",y.target);let w=y.pole??y.poleTarget;w!==void 0&&!Array.isArray(w)&&h("ik.pole",w)}return i}function Fi(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!Li.has(e)?e:void 0}function oi(t,e,i){return typeof t=="string"&&e.includes(t)?t:i}var Ro=["third-person","first-person","top-down","fixed"],Lo=["idle","walk","run","jump"];function zo(t){if(!t)return null;let e=ge(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let i=se(e.radius,.05,5,.35),r=ge(e.clips)??{},s={};for(let a of Lo){let l=Qe(r[a],128);l&&(s[a]=l)}return{speed:se(e.speed,.1,20,4),runMultiplier:se(e.runMultiplier,1,4,1.6),jumpVelocity:se(e.jumpVelocity,0,30,5.5),gravity:se(e.gravity,0,50,15),radius:i,height:se(e.height,i*2,10,Math.max(1.4,i*2)),cameraMode:oi(e.cameraMode,Ro,"third-person"),cameraDistance:se(e.cameraDistance,.5,50,3.5),cameraHeight:se(e.cameraHeight,-10,50,1.8),clips:s}}var ko=["patrol","chase","flee","wander","follow"],Uo=32,Ii="user";function Fo(t){if(!t)return null;let e=ge(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let i=oi(e.mode,ko,"wander"),r=e.target,s=r==="camera"||r===Ii?Ii:Qe(r,256)??"";!s&&(i==="chase"||i==="flee"||i==="follow")&&(s=Ii);let a=o=>se(o,-1e4,1e4,0),l=Array.isArray(e.waypoints)?e.waypoints.filter(Je).slice(0,Uo).map(o=>[a(o[0]),a(o[1]),a(o[2])]):[];return{mode:i,target:s,speed:se(e.speed,.1,20,2),turnSpeed:se(e.turnSpeed,.1,50,6),sightRadius:se(e.sightRadius,0,100,6),stopDistance:se(e.stopDistance,.01,10,.6),separationRadius:se(e.separationRadius,0,10,.8),waypoints:l,loopWaypoints:e.loopWaypoints!==!1}}function Io(t){if(!t)return null;let e=ge(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let i=se(e.max,1,1e6,100);return{max:i,current:se(e.current,0,i,i),group:Fi(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(se(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:se(e.scoreValue,-1e6,1e6,0),contactAmount:se(e.contactAmount,0,1e6,0)}}var Oo=16;function $o(t){if(!t)return null;let e=ge(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let i=oi(e.shape,["box","sphere"],"box"),r=e.size,s=n=>se(n,.01,1e3,1),a=Je(r)?[s(r[0]),s(r[1]),s(r[2])]:typeof r=="number"?[s(r),s(r),s(r)]:[1,1,1],l=se(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),o=e.watchGroups,c=[...new Set((Array.isArray(o)?o:o===void 0?[]:[o]).map(Fi).filter(n=>n!==void 0))].slice(0,Oo),d={shape:i,size:a,radius:l,watchGroups:c},u=Gt(e.color,"");return u?{...d,color:u}:d}var Bo=32;function jo(t){let e=ge(t)??(typeof t=="string"?{template:t}:null),i=Qe(e?.template,256)?.trim();return!e||!i||e.enabled===!1?null:{template:i,intervalSec:se(e.intervalSec,.05,3600,3),maxActive:Math.round(se(e.maxActive,1,Bo,8)),totalCount:Math.round(se(e.totalCount,0,1e4,0)),spawnRadius:se(e.spawnRadius,0,100,0)}}var Vo=["pickup","checkpoint","time-bonus","restore","key"];function Go(t){if(!t)return null;let e=ge(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let i=oi(e.type,Vo,"pickup"),r=i==="pickup";return{type:i,amount:se(e.amount??e.points,-1e6,1e6,10),tag:Fi(e.tag)??"",radius:se(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(se(e.order,0,1e3,0)),spinSpeed:se(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:se(e.bobAmplitude,0,5,r?.08:0),respawnSec:se(e.respawnSec,0,3600,0)}}var Ho=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Wo=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function qo(t){let e=ge(t);if(!e)return null;let i={};for(let r of Wo){let s=e[r];typeof s=="string"&&Ho.includes(s)&&(i[r]=s)}return Object.keys(i).length===0?null:{cues:i,pitchJitter:se(e.pitchJitter,0,.5,.08),volume:se(e.volume,0,1,1),spatial:e.spatial!==!1}}var Hr=["dynamic","static","kinematic"],Xo=["auto","box","sphere","cylinder"];function Wr(t,e,i,r=[0,0,0]){return Je(t)?[se(t[0],e,i,r[0]),se(t[1],e,i,r[1]),se(t[2],e,i,r[2])]:r}function Ko(t){if(t==null||t===!1)return null;if(typeof t=="string"){if(!Hr.includes(t))return null;let o=t;return{body:o,shape:"auto",mass:o==="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"&&Hr.includes(i)?i:"dynamic",s=e.shape??e.collider,a=typeof s=="string"&&Xo.includes(s)?s:"auto",l=r==="dynamic"?se(e.mass,.01,1e3,1):0;return{body:r,shape:a,mass:l,restitution:se(e.restitution??e.bounciness,0,1,.35),friction:se(e.friction,0,1,.5),linearDamping:se(e.linearDamping??e.damping,0,20,.05),angularDamping:se(e.angularDamping,0,20,.1),gravityScale:se(e.gravityScale,-5,5,1),velocity:Wr(e.velocity,-200,200),angularVelocity:Wr(e.angularVelocity,-100,100),lockRotation:e.lockRotation===!0}}var Zo={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=zo(r);s&&(e.character=s);let a=Fo(t.agent??t.ai??t.npc??t.enemy??t.bot??t.steering);a&&(e.agent=a);let l=Io(t.integrity??t.health??t.hp??t.hitpoints);l&&(e.integrity=l);let o=t.zone??t.trigger??t.hitbox??t.sensor??t.hazard,c=o!=null&&o!==!1&&typeof t.radius=="number"?{radius:t.radius,...typeof o=="string"?{shape:o}:typeof o=="object"?o:{}}:o,d=$o(c);d&&(e.zone=d);let u=jo(t.spawner??t.spawn);u&&(e.spawner=u);let n=Go(t.objective??t.goal??t.quest??t.collectible??t.pickup);n&&(e.objective=n);let f=qo(t.audioCues??t.sfx);f&&(e.audioCues=f);let p=t.physics,m=typeof t.mass=="number"||typeof t.restitution=="number"||typeof t.bounciness=="number"||typeof t.friction=="number",b=t.rigidBody??t.rigidbody??(p==="kinematic"||p===!0||typeof p=="object"&&p!==null||typeof p=="string"&&m?p:p===void 0&&typeof t.mass=="number"?!0:void 0),x=m&&b!==void 0&&b!==null&&b!==!1?{mass:t.mass,restitution:t.restitution??t.bounciness,friction:t.friction,...typeof b=="string"?{body:b}:typeof b=="object"?b:{}}:b,T=Ko(x);T&&(e.rigidBody=T,!e.physics&&(T.body==="dynamic"||T.body==="static")&&(e.physics=T.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 Yo(){Ao(Zo)}var tt=class ua{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 ua(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e)}},xe=class ca{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 ca(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,i){return this.x=e.x+i.x,this.y=e.y+i.y,this.z=e.z+i.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,i){return this.x=e.x-i.x,this.y=e.y-i.y,this.z=e.z-i.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}divideScalar(e){return this.multiplyScalar(e?1/e:0)}setScalar(e){return this.set(e,e,e)}addScaledVector(e,i){return this.x+=e.x*i,this.y+=e.y*i,this.z+=e.z*i,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let i=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,s=this.x*e.y-this.y*e.x;return this.x=i,this.y=r,this.z=s,this}crossVectors(e,i){let r=e.x,s=e.y,a=e.z,l=i.x,o=i.y,c=i.z;return this.x=s*c-a*o,this.y=a*l-r*c,this.z=r*o-s*l,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,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,l=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])*l,this.y=(a[1]*i+a[5]*r+a[9]*s+a[13])*l,this.z=(a[2]*i+a[6]*r+a[10]*s+a[14])*l,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 da{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._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new da(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},$i=class pa{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._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new pa(this._x,this._y,this._z,this._w)}setFromEuler(e,i=!0){let r=e.x,s=e.y,a=e.z,l=Math.cos(r/2),o=Math.cos(s/2),c=Math.cos(a/2),d=Math.sin(r/2),u=Math.sin(s/2),n=Math.sin(a/2);return this._x=d*o*c+l*u*n,this._y=l*u*c-d*o*n,this._z=l*o*n+d*u*c,this._w=l*o*c-d*u*n,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,l=e.w,o=i.x,c=i.y,d=i.z,u=i.w;return this._x=r*u+l*o+s*d-a*c,this._y=s*u+l*c+a*o-r*d,this._z=a*u+l*d+r*c-s*o,this._w=l*u-r*o-s*c-a*d,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},nt=class ma{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 ma;return e.copy(this),e}compose(e,i,r){return Mi(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 Oe(this.elements,e.elements,i.elements),this}lookAt(e,i,r){return Yt(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 xe(0,0,0),r=new xe(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 ut(this.elements,t.elements),this}},We=t=>t<=.04045?t/12.92:((t+.055)/1.055)**2.4,ni=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},it=class fa{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 o=We(r);return this.setRGB(o,o,o)}let s=r<=.5?r*(1+i):r+i-r*i,a=2*r-s,l=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?a+(s-a)*6*o:o<1/2?s:o<2/3?a+(s-a)*6*(2/3-o):a);return this.setRGB(We(l(e+1/3)),We(l(e)),We(l(e-1/3)))}lerp(e,i){let r=Number(i)||0;return this.r+=(e.r-this.r)*r,this.g+=(e.g-this.g)*r,this.b+=(e.b-this.b)*r,this}lerpColors(e,i,r){let s=Number(r)||0;return this.r=e.r+(i.r-e.r)*s,this.g=e.g+(i.g-e.g)*s,this.b=e.b+(i.b-e.b)*s,this}multiplyScalar(e){let i=Number(e)||0;return this.r*=i,this.g*=i,this.b*=i,this}setScalar(e){let i=Number(e)||0;return this.setRGB(i,i,i)}setHex(e){let i=Math.floor(e);return this.r=We((i>>16&255)/255),this.g=We((i>>8&255)/255),this.b=We((i&255)/255),this}setRGB(e,i,r){return this.r=Number(e),this.g=Number(i),this.b=Number(r),this}convertSRGBToLinear(){return this.r=We(this.r),this.g=We(this.g),this.b=We(this.b),this}convertLinearToSRGB(){return this.r=ni(this.r),this.g=ni(this.g),this.b=ni(this.b),this}getHex(){let e=i=>Math.round(ni(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.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new fa(this.r,this.g,this.b)}},Zr={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)},Be=class ga{constructor(e,i){if(this.needsUpdate=!1,typeof i!="number"||!Number.isInteger(i)||i<1||i>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(i)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=i;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/i)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.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 ga(new e(this.array),this.itemSize)}},Yr=class extends Be{constructor(t,e){super(t instanceof Float32Array?t:new Float32Array(t),e)}},Qr=class extends Be{constructor(t,e){super(t instanceof Uint16Array?t:new Uint16Array(t),e)}},Jr=class extends Be{constructor(t,e){super(t instanceof Uint32Array?t:new Uint32Array(t),e)}},ke=class ya{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 Be)this.index=e;else if(Array.isArray(e)){let i=0;for(let r of e)r>i&&(i=r);this.index=new Be(new(i>65535?Uint32Array:Uint16Array)(e),1)}else e&&e.buffer&&(this.index=new Be(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let i=e.count,r=new Float32Array(i*3),s=new xe,a=new xe,l=new xe,o=new xe,c=new xe,d=this.index?.array,u=d?d.length:i;for(let n=0;n<u;n+=3){let f=d?d[n]:n,p=d?d[n+1]:n+1,m=d?d[n+2]:n+2;s.set(e.getX(f),e.getY(f),e.getZ(f)),a.set(e.getX(p),e.getY(p),e.getZ(p)),l.set(e.getX(m),e.getY(m),e.getZ(m)),o.subVectors(l,a),c.subVectors(s,a),o.cross(c).normalize();for(let b of[f,p,m])r[b*3]+=o.x,r[b*3+1]+=o.y,r[b*3+2]+=o.z}for(let n=0;n<i;n++){let f=r[n*3],p=r[n*3+1],m=r[n*3+2],b=Math.hypot(f,p,m)||1;r[n*3]=f/b,r[n*3+1]=p/b,r[n*3+2]=m/b}return this.setAttribute("normal",new Be(r,3)),this}setFromBuffers(e,i,r,s){this.setAttribute("position",new Be(e,3)),this.setAttribute("normal",new Be(i,3)),this.setAttribute("uv",new Be(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 Be(i,3))}computeBoundingBox(){let e=this.attributes.position,i=new xe(1/0,1/0,1/0),r=new xe(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let s=0;s<e.count;s++){let a=e.getX(s),l=e.getY(s),o=e.getZ(s);a<i.x&&(i.x=a),l<i.y&&(i.y=l),o<i.z&&(i.z=o),a>r.x&&(r.x=a),l>r.y&&(r.y=l),o>r.z&&(r.z=o)}else i.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:i,max:r},this.boundingBox}center(){let e=this.computeBoundingBox();return 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 l of[this.attributes.position,this.attributes.normal]){if(!l)continue;let o=l.array;for(let c=0;c<o.length;c+=3){let d=o[c+e],u=o[c+i];o[c+e]=d*s-u*a,o[c+i]=d*a+u*s}l.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 xe;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 ya;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 ke{constructor(t=1,e=1,i=1){super();{let u=globalThis.__three_live_native_box__;if(typeof u=="function"){let n=u(t,e,i);this.setFromBuffers(n.positions,n.normals,n.uvs,n.indices);return}}let r=t/2,s=e/2,a=i/2,l=[-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],o=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],c=[],d=[];for(let u=0;u<6;u++){let n=u*4;c.push(0,0,1,0,1,1,0,1),d.push(n,n+1,n+2,n,n+2,n+3)}this.setFromBuffers(l,o,c,d)}},es=class extends ke{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 c=globalThis.__three_live_native_plane__;if(typeof c=="function"){let d=c(t,e,i,r);this.setFromBuffers(d.positions,d.normals,d.uvs,d.indices);return}}let s=[],a=[],l=[],o=[];for(let c=0;c<=r;c++){let d=c/r;for(let u=0;u<=i;u++){let n=u/i;if(s.push((n-.5)*t,(.5-d)*e,0),a.push(0,0,1),l.push(n,1-d),c>0&&u>0){let f=(i+1)*c+u-1,p=f-(i+1);o.push(p,f,p+1,f,f+1,p+1)}}}this.setFromBuffers(s,a,l,o)}},ts=class extends ke{constructor(t=1,e=16,i=12){super(),e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));{let o=globalThis.__three_live_native_sphere__;if(typeof o=="function"){let c=o(t,e,i);this.setFromBuffers(c.positions,c.normals,c.uvs,c.indices);return}}let r=[],s=[],a=[],l=[];for(let o=0;o<=i;o++){let c=o/i;for(let d=0;d<=e;d++){let u=d/e,n=u*Math.PI*2,f=c*Math.PI,p=-Math.cos(n)*Math.sin(f),m=Math.cos(f),b=Math.sin(n)*Math.sin(f);if(r.push(t*p,t*m,t*b),s.push(p,m,b),a.push(u,1-c),o>0&&d>0){let x=(e+1)*o+d,T=x-(e+1),v=T-1,g=x-1;o!==1&&l.push(T,v,x),o!==i&&l.push(v,g,x)}}}this.setFromBuffers(r,s,a,l)}},ji=class extends ke{constructor(t=1,e=1,i=1,r=16){super(),r=Math.max(3,Math.floor(r));{let u=globalThis.__three_live_native_cylinder__;if(typeof u=="function"){let n=u(t,e,i,r);this.setFromBuffers(n.positions,n.normals,n.uvs,n.indices);return}}let s=[],a=[],l=[],o=[],c=i/2;for(let u=0;u<=1;u++){let n=u,f=u===0?t:e,p=u===0?c:-c;for(let m=0;m<=r;m++){let b=m/r,x=b*Math.PI*2,T=Math.sin(x),v=Math.cos(x);s.push(f*T,p,f*v),a.push(T,0,v),l.push(b,1-n)}}for(let u=0;u<r;u++){let n=u,f=u+r+1,p=u+r+2,m=u+1;o.push(n,f,m,f,p,m)}let d=(u,n)=>{if(u<=0)return;let f=n*c,p=s.length/3;s.push(0,f,0),a.push(0,n,0),l.push(.5,.5);let m=s.length/3;for(let b=0;b<=r;b++){let x=b/r*Math.PI*2,T=Math.sin(x),v=Math.cos(x);s.push(u*T,f,u*v),a.push(0,n,0),l.push(v*.5+.5,.5+n*T*.5)}for(let b=0;b<r;b++)o.push(p,m+b+(n>0?0:1),m+b+(n>0?1:0))};d(t,1),d(e,-1),this.setFromBuffers(s,a,l,o)}},is=class extends ji{constructor(t=1,e=1,i=16){super(0,t,e,i)}},rs=class extends ke{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 u=d(t,e,i,r,s);this.setFromBuffers(u.positions,u.normals,u.uvs,u.indices);return}}let a=[],l=[],o=[],c=[];for(let d=0;d<=i;d++){let u=d/i*Math.PI*2,n=Math.cos(u),f=Math.sin(u);for(let p=0;p<=r;p++){let m=p/r*s,b=Math.cos(m),x=Math.sin(m);if(a.push((t+e*n)*b,(t+e*n)*x,e*f),l.push(n*b,n*x,f),o.push(p/r,d/i),d>0&&p>0){let T=(r+1)*d+p-1,v=T-(r+1);c.push(T,v,T+1,v,v+1,T+1)}}}this.setFromBuffers(a,l,o,c)}};function ss(t,e,i,r,s){let a=Math.max(2,Math.min(256,Math.floor(Number(e)||64))),l=Math.max(3,Math.min(64,Math.floor(Number(i)||8))),o=Number(r)||.1,c=[],d=[],u=[],n=[],f=new xe,p=new xe,m=new xe,b=new xe,x=new xe;for(let v=0;v<=a;v++){let g=v/a;s(Math.max(0,g-.001),f),s(Math.min(1,g+.001),p),m.subVectors(p,f).normalize(),v===0&&b.set(Math.abs(m.y)>.9?1:0,Math.abs(m.y)>.9?0:1,0),x.crossVectors(m,b).normalize(),b.crossVectors(x,m).normalize(),s(g,f);for(let y=0;y<=l;y++){let M=y/l*Math.PI*2,P=-o*Math.cos(M),j=o*Math.sin(M),H=P*b.x+j*x.x,V=P*b.y+j*x.y,z=P*b.z+j*x.z;c.push(f.x+H,f.y+V,f.z+z);let L=Math.hypot(H,V,z)||1;d.push(H/L,V/L,z/L),u.push(g,y/l)}}let T=l+1;for(let v=1;v<=a;v++){let g=T*(v-1),y=g+T;for(let M=1;M<=l;M++){let P=g+M-1,j=y+M-1;n.push(P,j,g+M,j,y+M,g+M)}}t.setFromBuffers(c,d,u,n)}var as=class extends ke{constructor(t=1,e=.4,i=64,r=8,s=2,a=3){super(),i=Math.floor(i),r=Math.floor(r);{let l=globalThis.__three_live_native_torus_knot__;if(typeof l=="function"){let o=l(t,e,i,r,s,a);this.setFromBuffers(o.positions,o.normals,o.uvs,o.indices);return}}ss(this,i,r,e,(l,o)=>{let c=l*s*Math.PI*2,d=a/s*c,u=t*(2+Math.cos(d))*.5;o.set(u*Math.cos(c),u*Math.sin(c),t*Math.sin(d)*.5)})}},St=class{getPoint(t,e=new xe){return e}getPointAt(t,e=new xe){return this.getPoint(t,e)}getTangent(t,e=new xe){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 St{constructor(t=new xe,e=new xe){super(),this.v1=t,this.v2=e}getPoint(t,e=new xe){return e.lerpVectors(this.v1,this.v2,t)}},ns=class extends St{constructor(t=new xe,e=new xe,i=new xe){super(),this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new xe){return e.lerpVectors(this.v0,this.v1,t).lerp(new xe().lerpVectors(this.v1,this.v2,t),t)}},ls=class extends St{constructor(t=new xe,e=new xe,i=new xe,r=new xe){super(),this.v0=t,this.v1=e,this.v2=i,this.v3=r}getPoint(t,e=new xe){let i=new xe().lerpVectors(this.v0,this.v1,t),r=new xe().lerpVectors(this.v1,this.v2,t),s=new xe().lerpVectors(this.v2,this.v3,t);return e.lerpVectors(i.lerp(r,t),r.lerp(s,t),t)}},hs=class extends St{constructor(t=[],e=!1){super(),this.points=Array.isArray(t)?t:[],this.closed=!!e}getPoint(t,e=new xe){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),l=s-a;!this.closed&&a>=r-1&&(a=r-2,l=1);let o=b=>i[this.closed?(b%r+r)%r:Math.max(0,Math.min(r-1,b))],c=o(a-1),d=o(a),u=o(a+1),n=o(a+2),f=l*l,p=f*l,m=(b,x,T,v)=>.5*(2*x+(T-b)*l+(2*b-5*x+4*T-v)*f+(3*x-b-3*T+v)*p);return e.set(m(c.x,d.x,u.x,n.x),m(c.y,d.y,u.y,n.y),m(c.z,d.z,u.z,n.z))}},Vi=class extends ke{constructor(t=[new tt(0,-.5),new tt(.5,0),new tt(0,.5)],e=12,i=0,r=Math.PI*2){super();let s=Array.isArray(t)&&t.length>=2?t:[new tt(.2,0),new tt(.2,.5)],a=Math.max(3,Math.min(128,Math.floor(Number(e)||12))),l=[],o=[],c=[],d=[],u=s.length;for(let n=0;n<=a;n++){let f=n/a,p=i+f*r,m=Math.sin(p),b=Math.cos(p);for(let x=0;x<u;x++){let T=s[x],v=Number(T?.x)||0,g=Number(T?.y)||0;l.push(v*m,g,v*b);let y=s[Math.max(0,x-1)],M=s[Math.min(u-1,x+1)],P=(Number(M?.x)||0)-(Number(y?.x)||0),j=(Number(M?.y)||0)-(Number(y?.y)||0),H=Math.hypot(j,P)||1;o.push(j/H*m,-P/H,j/H*b),c.push(f,x/(u-1))}}for(let n=0;n<a;n++){let f=n*u;for(let p=0;p<u-1;p++){let m=f+p,b=f+u+p;d.push(m,b,m+1,b,b+1,m+1)}}this.setFromBuffers(l,o,c,d)}},us=class extends ke{constructor(t,e=64,i=1,r=8,s=!1){super(),ss(this,e,r,i,(a,l)=>{let o=t?.getPointAt??t?.getPoint;if(typeof o=="function"){let c=o.call(t,a,l);c&&c!==l&&l.copy(c)}else l.set(0,a,0)})}},li="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",hi=class{constructor(t=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new tt(1,1),this.offset=new tt(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 hi{constructor(t=null,e=1,i=1,r=1023,s=1009,a,l=1001,o=1001,c=1003,d=1003,u=1,n=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1;let f=Number(e),p=Number(i),m=t&&typeof t.length=="number"?t:null;this.width=f,this.height=p,this.image={data:m,width:f,height:p},this.format=Number(r)||1023,this.type=Number(s)||1009,this.wrapS=Number(l)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(c)||1003,this.minFilter=Number(d)||1003,this.colorSpace=n||"",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),l=s*a,o=this.format,c=o===1021||o===1024||o===1028||e.length===l?1:o===1025||o===1030||e.length===l*2?2:o===1022||e.length===l*3?3:4,d=this.type===1015||this.type===1016||e instanceof Float32Array||e instanceof Float64Array,u=Math.min(s,96),n=Math.min(a,96),f=n*(1+u*4),p=new Uint8Array(68+f),m=new DataView(p.buffer);m.setUint32(0,2303741511),m.setUint32(4,218765834),m.setUint32(8,13),m.setUint32(12,1229472850),m.setUint32(16,u),m.setUint32(20,n),p[24]=8,p[25]=6,m.setUint32(29,Ni(p.subarray(12,29))),m.setUint32(33,f+11),m.setUint32(37,1229209940),p[41]=120,p[42]=1,p[43]=1,m.setUint16(44,f,!0),m.setUint16(46,~f&65535,!0);let b=48,x=1,T=0,v=0,g=0,y=0,M=0,P=z=>{if(!Number.isFinite(z))return 0;let L=d&&z<=1?z*255:z;return L>0?L<255?L+.5|0:255:0};for(let z=0;z<n;z++){let L=z*a/n|0,O=this.flipY?a-1-L:L;p[b++]=0,T+=x;for(let N=0;N<u;N++){let h=(O*s+(N*s/u|0))*c,k=o===1021?255:P(e[h]??0),X=c>=3||o===1030?P(e[h+1]??0):k,A=c>=3?P(e[h+2]??0):o===1030?0:k,I=c===4?P(e[h+3]??255):o===1021?P(e[h]??255):o===1025?P(e[h+1]??255):255;p[b++]=k,x+=k,T+=x,p[b++]=X,x+=X,T+=x,p[b++]=A,x+=A,T+=x,p[b++]=I,x+=I,T+=x,v+=k,g+=X,y+=A,M+=I}x%=65521,T%=65521}m.setUint32(b,(T<<16|x)>>>0),m.setUint32(b+4,Ni(p.subarray(37,b+4))),m.setUint32(b+12,1229278788),m.setUint32(b+16,2923585666);let j=u*n*255,H=this.colorSpace==="srgb-linear";this.avgColor=[H?v/j:We(v/j),H?g/j:We(g/j),H?y/j:We(y/j),M/j];let V=["data:image/png;base64,"];for(let z=0;z<p.length;z+=3){let L=p[z]<<16|(p[z+1]??0)<<8|(p[z+2]??0);V.push(li[L>>18&63]+li[L>>12&63]+(z+1<p.length?li[L>>6&63]:"=")+(z+2<p.length?li[L&63]:"="))}this.source=V.join("")}},ds=class{load(t,e){let i=new hi(t);return e?.(i),i}};function Ve(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 it(t.color!==void 0?t.color:16777215),this.emissive=new it(t.emissive!==void 0?t.emissive:0),this.emissiveIntensity=Ve(t.emissiveIntensity,1),this.roughness=Ve(t.roughness,.5),this.metalness=Ve(t.metalness,0),this.opacity=Ve(t.opacity,1),this.transparent=Gi(t.transparent,!1),this.wireframe=Gi(t.wireframe,!1),this.side=Ve(t.side,2),this.doubleSided=Gi(t.doubleSided,!0),this.map=t.map||null,this.clearcoat=Ve(t.clearcoat,0),this.clearcoatRoughness=Ve(t.clearcoatRoughness,0),this.sheen=Ve(t.sheen,0),this.sheenColor=new it(t.sheenColor!==void 0?t.sheenColor:0),this.sheenRoughness=Ve(t.sheenRoughness,0),this.transmission=Ve(t.transmission,0),this.thickness=Ve(t.thickness,0),this.attenuationColor=new it(t.attenuationColor!==void 0?t.attenuationColor:16777215),this.attenuationDistance=Ve(t.attenuationDistance,1/0),this.ior=Ve(t.ior,1.5),this.dispersion=Ve(t.dispersion,0),this.iridescence=Ve(t.iridescence,0),this.iridescenceIOR=Ve(t.iridescenceIOR,1.3)}dispose(){}},Dt=class extends Xe{},ps=class extends Xe{},ms=class extends Xe{},fs=class extends Xe{},gs=class extends Xe{},Ke=class ba{constructor(){this.name="",this.matrixAutoUpdate=!0,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.parent=null,this.children=[],this.userData={},this.position=new xe,this.rotation=new Oi,this.quaternion=new $i,this.scale=new xe(1,1,1),this.matrix=new nt,this.matrixWorld=new nt,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 ba&&(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 l=a.length-1;l>=0;l--)r.push(a[l])}}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 xe(e,i,r);this.target instanceof xe?this.target.copy(s):this.target?.position instanceof xe&&this.target.position.copy(s),this.updateMatrixWorld(!0);let a=new nt;a.lookAt(this.position,s,new xe(0,1,0));let l=a.elements,o=l[0],c=l[4],d=l[8],u=l[1],n=l[5],f=l[9],p=l[2],m=l[6],b=l[10],x=o+n+b;if(x>0){let T=.5/Math.sqrt(x+1);this.quaternion.set((m-f)*T,(d-p)*T,(u-c)*T,.25/T)}}translateOnAxis(e,i){let r=e.clone().applyMatrix4(new nt().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(i);return this.position.add(r),this}translateX(e){return this.translateOnAxis(new xe(1,0,0),e)}translateY(e){return this.translateOnAxis(new xe(0,1,0),e)}translateZ(e){return this.translateOnAxis(new xe(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}clone(e=!0){let i=this instanceof zt?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof dt?new dt(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 Ke{},dt=class extends Ke{constructor(t,e){super(),this.isMesh=!0;let i=Array.isArray(e)?e[0]:e;this.geometry=t instanceof ke?t:t?(ft("unsupported geometry","BoxGeometry"),new Bi(.5,.5,.5)):new ke,this.material=i instanceof Xe?i:i?(ft("unsupported material","MeshStandardMaterial"),new Dt({color:13421772})):new Dt}};function Hi(t){typeof t?._bakeAuthorGeometry=="function"&&t._bakeAuthorGeometry();let e=De().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var Wt=1e4,ui=class extends dt{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>Wt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Wt})`);this.count=Math.floor(r);let s=new Float32Array(this.count*16);for(let a=0;a<this.count;a++){let l=a*16;s[l]=1,s[l+5]=1,s[l+10]=1,s[l+15]=1}this.instanceMatrix=new Be(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 l=Number(e.elements[a]);r[s+a]=Number.isFinite(l)?l: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 Be(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(){}},Nt=class extends Ke{constructor(t=16777215,e=1){super(),this.color=new it(t),this.intensity=Number(e),this.type="directional"}},Wi=class extends Nt{constructor(t,e){super(t,e),this.type="ambient"}},qi=class extends Nt{constructor(t,e){super(t,e),this.target=new Ke,this.type="directional"}},ci=class extends Nt{constructor(t,e,i=0,r=2){super(t,e),this.type="point",this.distance=i,this.decay=r}},Xi=class extends Ke{},di=class extends Xi{constructor(t=45,e=1,i=.1,r=1e3){super(),this.target=new xe(0,0,0),this.fov=Number(t),this.aspect=Number(e),this.near=Number(i),this.far=Number(r)}},qt=class extends Ke{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return pt.validate(this),Vt(this)}toGLB(){return pt.validate(this),ei(this)}toUSDZ(){return pt.validate(this),ri(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let t=new Map,e=0;return this.traverse(i=>{if(i instanceof dt){let r=new Float32Array(i.matrixWorld.elements);t.set(e,r),i.name&&t.set(i.name,r),e++}}),t}},Ki=Vt,Zi=ei,bs=ri,pt=class{static validate(t){let e=0,i=0,r=0,s=new Set,a=(o,c,d)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${c}). Found: ${d}`)},l=(o,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(c)}), which cannot be bounds-checked.`);return c};t.traverse(o=>{if(Hi(o),o instanceof dt||o.geometry?.attributes?.position?.count){if(r++,r>1e3&&a("MESHES",1e3,r),o instanceof ui){let d=l("instance",o.count);(d<0||d>Wt)&&a("INSTANCES",Wt,d)}let c=o.geometry;if(c){let d=0;if(c.attributes.position&&(d=l("vertex",c.attributes.position.count),e+=d,e>1e5&&a("VERTICES",1e5,e)),c.index){let u=l("index",c.index.count);i+=u,i>3e5&&a("INDICES",3e5,i);let n=c.index.array;if(n&&d>0){let f=Math.min(u,n.length);for(let p=0;p<f;p++){let m=n[p];if(!Number.isFinite(m)||m<0||m>=d)throw new Error(`SecurityError: Index buffer value (${String(m)}) out of vertex bounds [0, ${d}).`)}}}}if(o.material){let d=o.material;d.map&&s.add(d.map),d.normalMap&&s.add(d.normalMap),d.roughnessMap&&s.add(d.roughnessMap)}}}),s.size>16&&a("TEXTURES",16,s.size);for(let o of s){let c=o,d=c.image,u=Number(d?.width??c.width??0)||0,n=Number(d?.height??c.height??0)||0;(!Number.isFinite(u)||!Number.isFinite(n)||u>2048||n>2048)&&a("TEXTURE_DIMENSION",2048,Math.max(u,n))}}},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 it(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){pt.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[l,o]of s.entries())a[l]=Array.from(o);r({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:a})}else{this.hasInitialModelRendered=!0;let s=Ki(t),a=Zi(t),l=(s.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));r({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:a.buffer,dynamicLights:l,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 Qo(){}var Rt=new Proxy(Qo,{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:Rt},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Rt,construct:()=>Rt}),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 pi(){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,pi());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 Ts,Xt;function Ss(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(Xt===void 0||Ts!==e){Ts=e;try{Xt=e.createPolicy("three-live#worker",{createScriptURL:i=>{if(!Lt(i))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${i}".`);return i}})}catch{Xt=null}}return Xt?Xt.createScriptURL(t):t}function Jo(t){De().sandboxEngineSrc=t}function Yi(){let t=De().sandboxEngineSrc;if(t)return t;if(ws)return ws;try{if(typeof document>"u")return null;let e=pi(),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 Qi(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,pi()).href}function en(){let t=Yi();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 Qi(t,"sandbox engine")}function tn(t){De().sandboxIframeSrc=t}function As(){let t=De().sandboxIframeSrc;if(t)return t;let e=Yi();if(!e||!Lt(e))return null;let i=new URL(e,pi());return i.protocol==="blob:"?null:new URL("three-live-sandbox.html",i).href}function rn(){let t=As();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 Qi(t,"sandbox iframe")}function sn(t){De().allowClientScripts=t}function _s(){return!!De().allowClientScripts}function an(t){return Qi(t,"procedural scene script")}var on=["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 nn(t,e){let i=self,r=t.nonce,s=t.engineSrc,a=t.allowedScriptUrl,l=t.allowClientScripts,o=t.revoked,c=i.postMessage.bind(i);function d(g){c({type:"ERROR",nonce:r,message:String(g)})}let u=typeof i.importScripts=="function"?i.importScripts.bind(i):null,n=a,f=null;try{let g=s;if(typeof i.trustedTypes<"u"&&i.trustedTypes&&typeof i.trustedTypes.createPolicy=="function")try{let y={createScriptURL:function(P){if(P!==s&&(!a||P!==a))throw new TypeError("Disallowed worker importScripts URL");return P}};l&&(y.createScript=function(P){return String(P)});let M=i.trustedTypes.createPolicy("three-live#worker-boot",y);g=M.createScriptURL(s),a&&(n=M.createScriptURL(a)),l&&typeof M.createScript=="function"&&(f=M.createScript.bind(M))}catch{}u(g)}catch(g){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: '+(g&&g.message||g));return}let p=i.THREE;if(!p||typeof p.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 g=i.__THREE_LIVE_REGISTRY__;for(let y=0;y<e.length;y++)if(typeof e[y]=="function")try{e[y](p,g)}catch{}}function m(g,y,M){let P=i;for(;P&&P!==Object.prototype;){if(!M&&P!==i)try{delete P[g]}catch{}if(!M||P===i||Object.prototype.hasOwnProperty.call(P,g))try{Object.defineProperty(P,g,M?{value:y,writable:!1,configurable:!1}:{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{P=Object.getPrototypeOf(P)}catch{break}}}for(let g=0;g<o.length;g++)m(o[g],void 0);m("performance",Object.freeze({now:function(){return Date.now()}}));let b=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function T(g,y){if(g.type==="3D_MODEL_READY"){if(x)return;x=!0}g.nonce=r,y&&y.length?c(g,y):c(g)}m("postMessage",function(g,y){if(!g||b.indexOf(g.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+b.join(", ")+").");T(g,y)},!0);let v=!1;i.onmessage=function(g){let y=g&&g.data;if(!(!y||y.nonce!==r)&&!(y.type!=="EXECUTE"&&y.type!=="EXECUTE_URL")&&!v){v=!0;try{let M=new p.Scene,P=new p.PerspectiveCamera(60,1,.1,1e3),j=new p.WebGLRenderer({isSandboxed:!0});if(y.type==="EXECUTE_URL"){if(!a||y.scriptUrl!==a||typeof u!="function"){d("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let H=n||a,V=u;if(u=null,n=null,i.THREE=p,i.scene=M,i.camera=P,i.renderer=j,V(H),typeof i.__THREE_LIVE_SCENE__=="function"){let z=i.__THREE_LIVE_SCENE__(p,M,P,j);z&&typeof z.toGLB=="function"&&(M=z)}else i.scene&&typeof i.scene.toGLB=="function"&&(M=i.scene)}else{if(!l){d("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let H=f?(0,eval)(f(`(function (THREE, scene, camera, renderer) {
|
|
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) {
|
|
343
370
|
return (function () {
|
|
344
|
-
`+
|
|
371
|
+
`+g.script+`
|
|
345
372
|
;
|
|
346
373
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
347
374
|
})();
|
|
348
375
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
349
|
-
`+
|
|
376
|
+
`+g.script+`
|
|
350
377
|
;
|
|
351
378
|
return typeof scene === "object" && scene ? scene : undefined;
|
|
352
|
-
})();`);f=null;let V=H(p,M,P,j);V&&typeof V.toGLB=="function"&&(M=V)}if(!x){p.SceneQuotaValidator&&p.SceneQuotaValidator.validate(M);let H=M.toGLB(),V=H instanceof ArrayBuffer?H:H.buffer.slice(H.byteOffset,H.byteOffset+H.byteLength);T({type:"3D_MODEL_READY",glbBuffer:V},[V])}c({type:"DONE",nonce:r})}catch(M){d(M&&M.message||M)}}},c({type:"READY",nonce:r})}function Ji(t,e,i){let r=i?.allowedScriptUrl??null,s=i?.allowClientScripts??r===null,a={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:s,revoked:on},l=(De().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${nn.toString()})(${JSON.stringify(a)},[${l}]);`}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 mt=0;function Cs(){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 ln(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var hn=1024,un=256;function Es(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,hn)};case"3D_UPDATE_TRANSFORMS":{let r=i.transforms;if(Array.isArray(r)){if(r.length>1e3)return null;for(let s of r)if(!Es(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),l=r;for(let o of s){if(o.length>un||o==="__proto__"||o==="constructor"||o==="prototype")return null;let c=l[o];if(!Es(c))return null;a[o]=c}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 cn(t){let e=ln(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ds(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 dn(t,e,i,r){let s=Cs(),a=Ji(e,s,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l=document.createElement("iframe");l.setAttribute("sandbox","allow-scripts"),l.setAttribute("aria-hidden","true"),l.tabIndex=-1,l.style.display="none",l.src=i,mt++;let o=!1,c=!1,d={modelDispatched:!1},u,n=()=>{if(o||c)return;let b=l.contentWindow;!b||typeof b.postMessage!="function"||(c=!0,b.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:s,workerSource:a,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:s,workerSource:a,script:t.script},"*"))},f=()=>{},p=b=>{if(o||!l.contentWindow||b.source!==l.contentWindow)return;let x=b.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){n();return}let T=er(x,s);T&&Ds(T,r,f,d)};f=()=>{o||(o=!0,u!==void 0&&clearTimeout(u),mt=Math.max(0,mt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",p),typeof l.remove=="function"?l.remove():l.parentNode&&l.parentNode.removeChild(l))},u=setTimeout(()=>{o||(f(),Ps(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",p),l.onload=()=>{n()},l.onerror=()=>{f(),r.onError?.(new Error(`Sandbox iframe failed to load "${i}". Verify that three-live-sandbox.html is served at that URL.`))};let m=document.body||document.documentElement;if(!m||typeof m.appendChild!="function"){f();let b=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(b),b}return m.appendChild(l),{terminate:f}}function Ns(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(mt>=32)return r(`SecurityError: ${mt} 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=en()}catch(f){let p=f instanceof Error?f.message:String(f);return r(p,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let f;try{f=rn()}catch(p){let m=p instanceof Error?p.message:String(p);return r(m,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(dn(t,s,f,i))}catch(p){return Promise.reject(p)}}let a=Cs(),l=Ji(s,a,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let f=new Blob([l],{type:"application/javascript"}),p=URL.createObjectURL(f);try{let m=Ss(p);o=new Worker(m)}finally{URL.revokeObjectURL(p)}}catch(f){let p=f instanceof Error?f.message:String(f);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${p}`,"Security Error: Failed to start Worker sandbox.")}mt++;let c=!1,d={modelDispatched:!1},u,n=()=>{c||(c=!0,u!==void 0&&clearTimeout(u),mt=Math.max(0,mt-1),o.terminate())};return u=setTimeout(()=>{c||(n(),Ps(i))},3e3),o.onmessage=f=>{let p=er(f.data,a);p&&Ds(p,i,n,d)},o.onerror=f=>{n(),i.onError?.(new Error(`Worker execution error: ${f.message}`))},t.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:a}):o.postMessage({type:"EXECUTE",script:t.script,nonce:a}),Promise.resolve({terminate:n})}function Rs(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 Ls=t=>(e,i)=>{let r=new Error(e);return t.onError?.(r),i&&t.onToast?.(i),Promise.reject(r)},zs={execute(t,e,i,r){let s=Ls(i),a=Rs(e,s);if(a)return a;try{cn(t)}catch(l){let o=l instanceof Error?l.message:String(l);return s(o,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??_s()?Ns({kind:"script",script:t},e,i,s):s(Aa,_a)},executeUrl(t,e,i){let r=Ls(i),s=Rs(e,r);if(s)return s;let a;try{a=an(t)}catch(l){let o=l instanceof Error?l.message:String(l);return r(o,"Security Error: disallowed scene script URL.")}return Ns({kind:"url",scriptUrl:a},e,i,r)}},mi=new Set;function ft(t,e){let i=`[three-live] ${t} is unsupported; degraded to ${e}.`;mi.has(i)||(mi.add(i),typeof console<"u"&&typeof console.warn=="function"&&console.warn(i))}function tr(){return Array.from(mi)}function ir(){mi.clear()}var rr=class extends Dt{constructor(t={}){ft("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}},ks=rr,At=class extends ke{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))),l=a+1,o=[],c=[],d=[],u=[],n=new xe,f=new xe,p=new xe,m=(T,v)=>v.set(t[T*3]||0,t[T*3+1]||0,t[T*3+2]||0),b=(T,v)=>{let g=T.clone().normalize();o.push(g.x*s,g.y*s,g.z*s),c.push(v.x,v.y,v.z),d.push(Math.atan2(g.z,-g.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,g.y)))/Math.PI)},x=(T,v,g)=>{let y=o.length/3,M=a===0?new xe().subVectors(g,v).cross(new xe().subVectors(T,v)).normalize():null;b(T,M||T.clone().normalize()),b(v,M||v.clone().normalize()),b(g,M||g.clone().normalize()),u.push(y,y+1,y+2)};for(let T=0;T<e.length;T+=3){m(e[T],n),m(e[T+1],f),m(e[T+2],p);let v=[];for(let g=0;g<=l;g++){v[g]=[];let y=n.clone().lerp(p,g/l),M=f.clone().lerp(p,g/l),P=l-g;for(let j=0;j<=P;j++)v[g][j]=P===0?y.clone():y.clone().lerp(M,j/P)}for(let g=0;g<l;g++)for(let y=0;y<2*(l-g)-1;y++){let M=y>>1;(y&1)===0?x(v[g][M+1],v[g+1][M],v[g][M]):x(v[g][M+1],v[g+1][M+1],v[g+1][M])}}this.setFromBuffers(o,c,d,u)}},pn=At,Us=class extends At{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)}},fi=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],Fs=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],Is=class extends At{constructor(t=1,e=0){super(fi,Fs,t,e)}},Ne=(1+Math.sqrt(5))/2,Os=class extends At{constructor(t=1,e=0){super([-1,Ne,0,1,Ne,0,-1,-Ne,0,1,-Ne,0,0,-1,Ne,0,1,Ne,0,-1,-Ne,0,1,-Ne,Ne,0,-1,Ne,0,1,-Ne,0,-1,-Ne,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/Ne,$s=class extends At{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,-Ne,0,-Ze,Ne,0,Ze,-Ne,0,Ze,Ne,-Ze,-Ne,0,-Ze,Ne,0,Ze,-Ne,0,Ze,Ne,0,-Ne,0,-Ze,Ne,0,-Ze,-Ne,0,Ze,Ne,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,l=Math.max(2,Math.min(64,Math.floor(Number(i)||4))),o=[];for(let c=-1;c<=1;c+=2)for(let d=0;d<=l;d++){if(c>0&&d===0&&a===0)continue;let u=(c<0?d/l-1:d/l)*(Math.PI/2);o.push(new tt(Math.max(0,Math.cos(u)*s),c*a+Math.sin(u)*s))}super(o,Math.max(4,Math.min(128,Math.floor(Number(r)||8))))}},sr=class extends ke{constructor(t=.5,e=1,i=32,r=1,s=0,a=Math.PI*2){super();let l=Math.max(1e-4,Number(e)||1),o=Number(t),c=Number.isFinite(o)?Math.max(0,o):l*.5,d=Math.max(l,c),u=Math.min(d*.999,Math.min(l,c)),n=Math.max(3,Math.min(256,Math.floor(Number(i)||32))),f=Math.max(1,Math.min(64,Math.floor(Number(r)||1))),p=Number.isFinite(Number(s))?Number(s):0,m=Number.isFinite(Number(a))?Number(a):Math.PI*2,b=[],x=[],T=[],v=[];for(let g=0;g<=f;g++){let y=u+g/f*(d-u);for(let M=0;M<=n;M++){let P=p+M/n*m,j=Math.cos(P),H=Math.sin(P);if(b.push(y*j,y*H,0),x.push(0,0,1),T.push(y/d*j*.5+.5,y/d*H*.5+.5),g<f&&M<n){let V=g*(n+1)+M,z=V+n+1;y>1e-6&&v.push(V,z,V+1),v.push(z,z+1,V+1)}}}this.setFromBuffers(b,x,T,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)}},gi=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 gi{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)),l=f=>`${Math.round((r[f*3]||0)*1e4)},${Math.round((r[f*3+1]||0)*1e4)},${Math.round((r[f*3+2]||0)*1e4)}`,o=e===void 0,c=o?1:Math.cos(e*Math.PI/180),d={},u=[],n=(f,p)=>u.push(r[f*3]||0,r[f*3+1]||0,r[f*3+2]||0,r[p*3]||0,r[p*3+1]||0,r[p*3+2]||0);for(let f=0;f<a;f++){let p=s?s[f*3]:f*3,m=s?s[f*3+1]:f*3+1,b=s?s[f*3+2]:f*3+2,x=r[p*3]||0,T=r[p*3+1]||0,v=r[p*3+2]||0,g=(r[m*3]||0)-x,y=(r[m*3+1]||0)-T,M=(r[m*3+2]||0)-v,P=(r[b*3]||0)-x,j=(r[b*3+1]||0)-T,H=(r[b*3+2]||0)-v,V=y*H-M*j,z=M*P-g*H,L=g*j-y*P,O=Math.hypot(V,z,L);if(!o&&O<1e-8)continue;O>0&&(V/=O,z/=O,L/=O);let N=[p,m,b];for(let h=0;h<3;h++){let k=N[h],X=N[(h+1)%3],A=l(k),I=l(X);if(A===I)continue;let C=A<I?`${A}|${I}`:`${I}|${A}`,w=d[C];w?w.m||(w.m=1,w.nx*V+w.ny*z+w.nz*L<=c&&n(k,X)):(d[C]={va:k,vb:X,nx:V,ny:z,nz:L,m:o?1:0},o&&n(k,X))}}if(!o){let f=Object.keys(d);for(let p=0;p<f.length;p++){let m=d[f[p]];m&&!m.m&&n(m.va,m.vb)}}return new Float32Array(u)}var Hs=class extends ke{constructor(t){super(),this.setAttribute("position",new Be(Gs(t),3)),this.__isSegmentPairs=!0}},Ws=class extends ke{constructor(t,e=1){super();let i=Number.isFinite(Number(e))?Number(e):1;this.setAttribute("position",new Be(Gs(t,i),3)),this.__isSegmentPairs=!0}};function mn(t,e,i=1){let r=new ke;r.__baked=!0;let s=t?.attributes?.position;if(!s?.array||s.count<2)return r;let a=s.array,l=t.index?.array,o=t.__isSegmentPairs?"segments":e,c=l?l.length:s.count,d=Math.min(4096,Math.max(0,o==="segments"?Math.floor(c/2):o==="loop"&&c>=3?c:c-1));if(d===0)return r;t.computeBoundingBox();let u=t.boundingBox,n=u&&u.max.distanceTo(u.min)||1,f=Math.max(.0015,Math.min(.025,n*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(i)||1))),p=[],m=[],b=[],x=[];for(let T=0;T<d;T++){let v=o==="segments"?T*2:T,g=o==="segments"?T*2+1:(T+1)%c,y=l?l[v]:v,M=l?l[g]:g,P=a[y*3]||0,j=a[y*3+1]||0,H=a[y*3+2]||0,V=(a[M*3]||0)-P,z=(a[M*3+1]||0)-j,L=(a[M*3+2]||0)-H,O=Math.hypot(V,z,L);if(O<1e-6)continue;let N=V/O,h=z/O,k=L/O,X=(Math.abs(h)<.9?Math.hypot(k,N):Math.hypot(k,h))||1,A=Math.abs(h)<.9?k/X:0,I=Math.abs(h)<.9?0:-k/X,C=Math.abs(h)<.9?-N/X:h/X,w=h*C-k*I,$=k*A-N*C,Z=N*I-h*A,ie=p.length/3,ee=[[A,I,C],[w,$,Z],[-A,-I,-C],[-w,-$,-Z]];for(let K=0;K<2;K++){let ne=P+K*V,re=j+K*z,he=H+K*L;for(let Q=0;Q<4;Q++){let ae=ee[Q];p.push(ne+ae[0]*f,re+ae[1]*f,he+ae[2]*f),m.push(ae[0],ae[1],ae[2]),b.push(Q/4,K)}}for(let K=0;K<4;K++){let ne=(K+1)%4;x.push(ie+K,ie+ne,ie+4+ne,ie+K,ie+4+ne,ie+4+K)}}return p.length>0&&r.setFromBuffers(p,m,b,x),r}function fn(t,e=.05){let i=new ke;i.__baked=!0;let r=t?.attributes?.position;if(!r?.array||r.count<1)return i;let s=r.array,a=r.count,l=Math.min(a,5e3),o=Math.max(.003,Math.min(.25,(Number(e)||.05)*.6)),c=[],d=[],u=[],n=[];for(let f=0;f<l;f++){let p=a<=5e3?f:Math.floor(f*a/l),m=s[p*3]||0,b=s[p*3+1]||0,x=s[p*3+2]||0,T=f*6;for(let v=0;v<6;v++){let g=fi[v*3],y=fi[v*3+1],M=fi[v*3+2];c.push(m+g*o,b+y*o,x+M*o),d.push(g,y,M),u.push(.5,.5)}for(let v=0;v<24;v++)n.push(T+Fs[v])}return i.setFromBuffers(c,d,u,n),i}var zt=class extends dt{constructor(t,e,i="strip"){let r=e&&typeof e=="object"?e:{},s=e instanceof Xe?e:i==="points"?new ar(r):new gi(r),a=t instanceof ke?t:new ke;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,l=0;for(let o=0;o<r;o++)s+=i[o*3]||0,a+=i[o*3+1]||0,l+=i[o*3+2]||0;this.material.color.setRGB(s/r,a/r,l/r)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(t?1:2)&&(this.geometry=t?fn(this._sourceGeo,this.material?.size??.05):mn(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}},yi=class extends ci{constructor(t,e,i=0,r=Math.PI/3,s=0,a=2){super(t,e,i,a),this.target=new Ke,this.type="spot";let l=Number(r);this.angle=Number.isFinite(l)?Math.max(.01,Math.min(Math.PI/2,l)):Math.PI/3;let o=Number(s);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},or=class extends Wi{constructor(t,e,i){ft("HemisphereLight","AmbientLight"),super(t,i),this.groundColor=new it(e??4473924)}},Zs=or,Ys={Vector2:tt,Vector3:xe,Vector4:qr,Euler:Oi,Quaternion:$i,Matrix4:nt,Matrix3:Xr,Color:it,MathUtils:Zr,BufferAttribute:Be,Float32BufferAttribute:Yr,Uint16BufferAttribute:Qr,Uint32BufferAttribute:Jr,BufferGeometry:ke,BoxGeometry:Bi,PlaneGeometry:es,SphereGeometry:ts,CylinderGeometry:ji,ConeGeometry:is,TorusGeometry:rs,TorusKnotGeometry:as,Curve:St,Curve3:St,LineCurve3:os,QuadraticBezierCurve3:ns,CubicBezierCurve3:ls,CatmullRomCurve3:hs,LatheGeometry:Vi,TubeGeometry:us,PolyhedronGeometry:At,IcosahedronGeometry:Os,OctahedronGeometry:Is,DodecahedronGeometry:$s,TetrahedronGeometry:Us,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:hi,DataTexture:cs,TextureLoader:ds,Material:Xe,MeshStandardMaterial:Dt,MeshBasicMaterial:ps,MeshLambertMaterial:ms,MeshPhongMaterial:fs,MeshPhysicalMaterial:gs,PointsMaterial:ar,LineBasicMaterial:gi,LineDashedMaterial:Vs,ShaderMaterial:rr,RawShaderMaterial:ks,Object3D:Ke,Group:ys,Mesh:dt,InstancedMesh:ui,Line:zt,LineLoop:qs,LineSegments:Xs,Points:Ks,Light:Nt,AmbientLight:Wi,DirectionalLight:qi,PointLight:ci,SpotLight:yi,HemisphereLight:or,RectAreaLight:Zs,Camera:Xi,PerspectiveCamera:di,Scene:qt,WebGLRenderer:xs,Clock:Ms,SceneQuotaValidator:pt,exportSceneToCanvas3D:Ki,exportSceneToGLB:Zi,exportSceneToUSDZ:bs,generateUSDZ:Lr,glbToUSDZ:Ri,sceneToCanvas3D:Vt,sceneToGLB:ei,sceneToUSDZ:ri,authorScriptRunner:zs,getAuthorWarnings:tr,clearAuthorWarnings:ir};Object.freeze(pt),Object.freeze(pt.prototype),Object.freeze(qt.prototype),Object.freeze(Ys);var rt=new Proxy(Ys,{get:(t,e)=>{if(e in t)return t[e];let i=De().authorNamespace;return i&&typeof e=="string"&&e in i?i[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&ft(`THREE.${e}`,"no-op proxy"),Rt)},has:(t,e)=>{if(e in t)return!0;let i=De().authorNamespace;return!!(i&&typeof e=="string"&&e in i)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),bi=De();if(bi.threeNamespace=rt,bi.workerExtensionInstallers)for(let t of bi.workerExtensionInstallers)t(rt,bi);var Kt={name:"three_author",THREE:rt},gn=Kt,Pe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof Pe.THREE>"u"&&(Pe.THREE=rt),typeof Pe.requestAnimationFrame!="function"&&(Pe.requestAnimationFrame=t=>(typeof t=="function"&&typeof Pe.__three_live_raf_cb__!="function"&&(Pe.__three_live_raf_cb__=t),Pe.__three_live_in_step__||ft("requestAnimationFrame","single-frame static evaluation"),0)),typeof Pe.cancelAnimationFrame!="function"&&(Pe.cancelAnimationFrame=()=>{}),typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=rt,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=Kt,t.ThreeLivePlugins.three_author=Kt,t.ThreeLivePlugins["three-author"]=Kt}{Eo(),Yo(),Ea(rt,De()),cr(rt,De()),dr(rt,De());let t=new qt,e=new di(45,1,.1,1e3);e.position.set(0,2,5),Pe.scene=t,Pe.camera=e,typeof Pe.window>"u"&&(Pe.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Pe.document>"u"&&(Pe.document={createElement:()=>({getContext:()=>Rt,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Pe,"__three_live_reset_scene__",{value:function(){ir(),delete Pe.__three_live_sim_time_ms__,delete Pe.__three_live_raf_cb__,delete Pe.__three_live_in_step__,t=new qt,e=new di(45,1,.1,1e3),e.position.set(0,2,5),Pe.scene=t,Pe.camera=e},writable:!1,configurable:!1}),Object.defineProperty(Pe,"__three_live_step_js__",{value:function(l,o){Pe.__three_live_sim_time_ms__=l*1e3,Pe.__three_live_in_step__=!0;try{typeof Pe.animate=="function"?Pe.animate(l,o):typeof Pe.__three_live_raf_cb__=="function"&&Pe.__three_live_raf_cb__(l*1e3)}finally{Pe.__three_live_in_step__=!1}},writable:!1,configurable:!1});let i=function(l){if(l==null)return null;let o=2e4,c=0,d=new Set,u=(n,f)=>{if(--o<0||f>32)return;if(n===null||typeof n=="string"||typeof n=="boolean")return n;if(typeof n=="number")return Number.isFinite(n)?n:void 0;if(n instanceof Ke)return n.name||(n.name=`Node_ref_${++c}`),n.name;if(n instanceof xe)return[Number.isFinite(n.x)?n.x:0,Number.isFinite(n.y)?n.y:0,Number.isFinite(n.z)?n.z:0];if(n instanceof it)return`#${n.getHex().toString(16).padStart(6,"0")}`;if(typeof n!="object"||d.has(n))return;d.add(n);let p;if(Array.isArray(n)){p=[];for(let m of n)p.push(u(m,f+1)??null)}else{p={};for(let m of Object.keys(n)){if(m==="__proto__"||m==="prototype"||m==="constructor")continue;let b=u(n[m],f+1);b!==void 0&&(p[m]=b)}}return d.delete(n),p};try{return u(l,0)??null}catch{return null}},r=15*1024,s=1e3*4,a=function(l){let o=ki(l);if(!o)return{};let c=JSON.stringify({...l,...o});return c.length>r&&(ft(`userData.xr larger than ${r} characters`,"canonical XR traits only"),c=JSON.stringify(o)),{xr_normalized_json:c,xr_scenecore_json:JSON.stringify(Br(o)),xr_hubs_json:JSON.stringify(jr(o))}};Object.defineProperty(Pe,"__three_live_extract_scene_raw__",{value:function(){let l=[],o=[],c=[],d=[];function u(h){if(!h)return null;let k=d.indexOf(h);if(k===-1){d.push(h);let X="";h.map&&(typeof h.map=="string"?X=h.map:typeof h.map.source=="string"&&h.map.source?X=h.map.source:typeof h.map.image=="string"&&(X=h.map.image)),o.push({name:h.name||`Material_${o.length}`,base_color:[h.color.r,h.color.g,h.color.b,h.opacity!==void 0?h.opacity:1],metallic:h.metalness!==void 0?h.metalness:0,roughness:h.roughness!==void 0?h.roughness:.5,double_sided:h.side===2||h.doubleSided,base_color_texture:X||null,clearcoat:h.clearcoat||0,clearcoat_roughness:h.clearcoatRoughness||0,transmission:h.transmission||0,ior:h.ior!==void 0?h.ior:1.5,thickness:h.thickness||0}),k=o.length-1}return k}let n=(h,k)=>typeof h=="number"&&Number.isFinite(h)?h:k,f=[],p=[],m=[],b=!1,x=Pe.scene||t,T=new nt().compose({x:n(x.position?.x,0),y:n(x.position?.y,0),z:n(x.position?.z,0)},{x:n(x.quaternion?.x,0),y:n(x.quaternion?.y,0),z:n(x.quaternion?.z,0),w:n(x.quaternion?.w,1)},{x:n(x.scale?.x,1),y:n(x.scale?.y,1),z:n(x.scale?.z,1)}),v=new Set([x]);{let h=new Set([x]),k=Array.isArray(x.children)?[...x.children]:[],X=0;for(;k.length>0&&X<=s;){let A=k.pop();if(!(!(A instanceof Ke)||h.has(A))&&(h.add(A),X++,Array.isArray(A.children)))for(let I of A.children)k.push(I)}if(X>s)return{meshes:[],nodes:new Array(X),materials:[],lights:[]}}let g=[],y=(h,k)=>{let X=Array.isArray(h.children)?h.children:[];for(let A=X.length-1;A>=0;A--)g.push([X[A],k])};y(x,-1);let M=h=>{let k=[];for(let A=h;A>=0&&k.length<=f.length;A=f[A].parent)k.push(A);let X=T.clone();for(let A=k.length-1;A>=0;A--){let I=f[k[A]];X.multiply(new nt().compose({x:I.translation[0],y:I.translation[1],z:I.translation[2]},{x:I.rotation[0],y:I.rotation[1],z:I.rotation[2],w:I.rotation[3]},{x:I.scale[0],y:I.scale[1],z:I.scale[2]}))}return X};for(;g.length>0;){let[h,k]=g.pop();if(!(h instanceof Ke)||v.has(h))continue;v.add(h);let X=[n(h.position?.x,0),n(h.position?.y,0),n(h.position?.z,0)],A=[n(h.quaternion?.x,0),n(h.quaternion?.y,0),n(h.quaternion?.z,0),n(h.quaternion?.w,1)],I=[n(h.scale?.x,1),n(h.scale?.y,1),n(h.scale?.z,1)];Hi(h);let C=-1,w=h.geometry,$=w?.attributes?.position;if($&&$.array&&$.count>0){C=l.length;let he=null,Q=h.userData?.variants;if(Q&&typeof Q=="object"){let ae=new Map;for(let te of Object.keys(Q)){if(!te||te==="__proto__"||te==="constructor"||te==="prototype")continue;let pe=Q[te],ue=pe instanceof Xe?pe:pe&&typeof pe=="object"?new Dt(pe):null;if(!ue)continue;let le=p.indexOf(te);if(le===-1&&p.length<256&&(le=p.length,p.push(te)),le===-1)continue;let _=u(ue);if(_!==null){let S=ae.get(_);S||(S=[],ae.set(_,S)),S.push(le)}}if(ae.size>0){let te=[];for(let[pe,ue]of ae.entries())te.push({material:pe,variants:ue});he=JSON.stringify({mappings:te})}}l.push({name:h.name||`Mesh_${l.length}`,raw_positions:$.array,raw_normals:w.attributes.normal?w.attributes.normal.array:null,raw_uvs:w.attributes.uv?w.attributes.uv.array:null,raw_indices:w.index?w.index.array:null,vertex_count:$.count,material_index:u(h.material instanceof Xe?h.material:null),variant_mappings_json:he})}let Z=i(h.userData?.xr),ie=!!h.userData?.xr&&Z!==null,ee=i(h.userData?.interactivity),K=f.length,ne=h instanceof ui&&h.count>0&&h.instanceMatrix?.array,re=[];if(ee&&typeof ee=="object")for(let he of["onSelect","onHoverIn","onHoverOut","onStart","onReceive"])ee[he]&&re.push(he);if(f.push({name:typeof h.name=="string"?h.name.slice(0,1024):"",parent:k,translation:X,rotation:A,scale:I,mesh:C,visible:h.visible!==!1,xr_traits_json:ie?JSON.stringify(Z):null,interactivity_events_json:re.length>0?JSON.stringify(re):null,interactivity_raw_json:ee?JSON.stringify(ee):null,...ie?a(Z):{},...ne?{instance_matrices:h.instanceMatrix.array.subarray(0,h.count*16),instance_colors:h.instanceColor?.array?h.instanceColor.array.subarray(0,h.count*3):null}:{}}),m.push(ee),ee&&(b=!0),f.length>s)break;if(h instanceof Nt){let he=M(K).elements,Q=n(he[12],0),ae=n(he[13],0),te=n(he[14],0),pe={light_type:h.type,color:[h.color.r,h.color.g,h.color.b],intensity:h.intensity,position:[Q,ae,te]};if(h instanceof yi||h instanceof qi){let ue=h.target,le=n(ue?.position?.x,0),_=n(ue?.position?.y,0),S=n(ue?.position?.z,0);if(ue?.parent){let D=[];for(let E=ue;E&&E!==x&&D.length<64;E=E.parent)D.push(E);let R=new nt;for(let E=D.length-1;E>=0;E--){let F=D[E];F.updateMatrix(),R.multiply(F.matrix)}le=n(R.elements[12],le),_=n(R.elements[13],_),S=n(R.elements[14],S)}if(h instanceof yi){let D=le-Q,R=_-ae,E=S-te,F=Math.hypot(D,R,E);F>1e-6?(D/=F,R/=F,E/=F):(D=0,R=-1,E=0),pe.direction=[D,R,E];let q=Math.max(.01,Math.min(Math.PI/2,n(h.angle,Math.PI/3))),B=Math.max(0,Math.min(1,n(h.penumbra,0)));pe.outer_cone_angle=q,pe.inner_cone_angle=Math.max(0,q*(1-B)),pe.range=Math.max(0,n(h.distance,0))}else pe.position=[Q-le,ae-_,te-S]}else h instanceof ci&&(pe.range=Math.max(0,n(h.distance,0)));c.push(pe)}y(h,K)}let P=[],j=(h,k,X,A,I="warning")=>{P.push(A?{code:h,severity:I,node:A,message:k,hint:X}:{code:h,severity:I,message:k,hint:X})};for(let h of tr()){let[k,X]=h.includes("ShaderMaterial")||h.includes("RawShaderMaterial")||h.includes("unsupported material")?["TL101","Use THREE.MeshStandardMaterial({ color, metalness, roughness }) instead of custom GLSL shaders."]:h.includes("requestAnimationFrame")?["TL104","Static exports evaluate a single frame; use userData.xr.orbit, userData.interactivity, or define function animate(t) for time-stepped rendering."]:h.includes("Controls")?["TL106","Remove THREE.OrbitControls; <three-live camera-controls> and <xr-live> provide built-in camera controls."]:h.includes("EffectComposer")||h.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(h)?["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(h)?["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(h)?["TL102","Procedural DOM/pixel textures cannot run in the headless sandbox; use MeshPhysicalMaterial PBR properties, vertex colors, or THREE.TextGeometry / userData.text."]:h.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."];j(k,h,X)}let H=new Set;for(let h of f)typeof h.name=="string"&&h.name.trim().length>0&&H.add(h.name);for(let h=0;h<f.length;h++){let k=f[h],X=typeof k.name=="string"&&k.name.trim().length>0?k.name:"",A=X||k.mesh>=0&&l[k.mesh]?.name||`Node_${h}`;!X&&H.has(A)&&(A=`Node_${h}`);let I=m[h],C=null;if(k.xr_traits_json)try{C=JSON.parse(k.xr_traits_json)}catch{C=null}if((C||I)&&!X&&(k.name=A,H.add(A),j("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")),C!==null){for(let $ of No(C,A))P.push($);let w=($,Z)=>{typeof Z=="string"&&Z.trim().length>0&&!H.has(Z)&&j("TL204",`userData.xr.${$} on node '${A}' references target node '${Z}', which does not exist in scene.`,`Ensure a node with mesh.name = '${Z}' is added to scene via scene.add().`,A)};if(C.orbit&&typeof C.orbit=="object"&&w("orbit.target",C.orbit.target),typeof C.spawner=="string"?w("spawner.template",C.spawner):C.spawner&&typeof C.spawner=="object"&&w("spawner.template",C.spawner.template),C.agent&&typeof C.agent=="object"){let $=C.agent.target;$!=="user"&&$!=="camera"&&w("agent.target",$)}if(C.ik&&typeof C.ik=="object"&&C.ik.enabled!==!1){w("ik.root",C.ik.root),w("ik.mid",C.ik.mid),w("ik.effector",C.ik.effector),Array.isArray(C.ik.target)||w("ik.target",C.ik.target);let $=C.ik.pole??C.ik.poleTarget;Array.isArray($)||w("ik.pole",$)}}if(I&&typeof I=="object"){let w=new Set(["onSelect","onHoverIn","onHoverOut","onStart","onReceive"]),$=new Set(["interpolate","toggleTransform","setProperty","toggleVisibility","cycleMaterialColor","playAnimation","stopAnimation","sendEvent"]),Z=(ee,K)=>{let ne=Array.isArray(ee)?ee:[ee];for(let re of ne){if(!re||typeof re!="object")continue;let he=re.action;typeof he=="string"&&!$.has(he)&&j("TL201",`Unrecognized action '${he}' in userData.interactivity.${K} on node '${A}'.`,"Supported interactivity actions: interpolate, toggleTransform, setProperty, toggleVisibility, cycleMaterialColor, playAnimation, stopAnimation, sendEvent.",A);let Q=re.target;typeof Q=="string"&&Q.length>0&&!H.has(Q)&&j("TL204",`userData.interactivity.${K} on node '${A}' references target node '${Q}', which does not exist in scene.`,`Ensure a node with mesh.name = '${Q}' is added to scene via scene.add().`,A);let ae=re.targetNode;typeof ae=="number"&&(ae<0||ae>=f.length)&&j("TL204",`userData.interactivity.${K} on node '${A}' references out-of-range targetNode ${ae} (scene has ${f.length} nodes).`,"Prefer referencing nodes by name via target: '<nodeName>'.",A)}},ie=I;for(let ee of Object.keys(ie))if(!w.has(ee)){let K=ee.toLowerCase(),ne=K==="onclick"||K==="ontap"||K==="onpointerdown"?"onSelect":K==="onhover"||K==="onmouseenter"?"onHoverIn":K==="onmouseleave"?"onHoverOut":null;j("TL201",ne?`Unrecognized trigger '${ee}' in userData.interactivity on node '${A}'; did you mean '${ne}'?`:`Unrecognized trigger '${ee}' in userData.interactivity on node '${A}'.`,"Supported interactivity triggers: onSelect, onHoverIn, onHoverOut, onStart, onReceive.",A)}for(let ee of["onSelect","onHoverIn","onHoverOut","onStart"])ie[ee]&&Z(ie[ee],ee);if(ie.onReceive&&typeof ie.onReceive=="object")for(let[ee,K]of Object.entries(ie.onReceive))Z(K,`onReceive.${ee}`)}}let V=(h,k)=>h.every((X,A)=>X===k[A]),z=i({interactivity:x.userData?.interactivity,gltfExtensions:{KHR_interactivity:x.userData?.gltfExtensions?.KHR_interactivity}}),L=!!(z?.interactivity??z?.gltfExtensions?.KHR_interactivity),O=null;(b||L)&&(O=hr(f.map((h,k)=>({name:h.name,...h.mesh>=0?{mesh:h.mesh}:{},...V(h.translation,[0,0,0])?{}:{translation:h.translation},...V(h.rotation,[0,0,0,1])?{}:{rotation:h.rotation},...V(h.scale,[1,1,1])?{}:{scale:h.scale},extras:m[k]?{interactivity:m[k]}:void 0})),l.map(h=>({primitives:[{material:h.material_index??0}]})),z??void 0));let N=Pe.camera||e;return{meshes:l,nodes:f,materials:o,lights:c,interactivity_json:O?JSON.stringify(O):null,variants_json:p.length>0?JSON.stringify({variants:p.map(h=>({name:h}))}):null,diagnostics_json:P.length>0?JSON.stringify(P):null,camera:{fov:N.fov||45,position:N.position?[N.position.x,N.position.y,N.position.z]:[0,2,5],target:N.target?[N.target.x,N.target.y,N.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var yn=rt;return Sa(lr)})();
|
|
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)})();
|