three-live 1.2.4 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/three-author-engine.js +28 -26
- package/dist/three-author.cjs +29 -27
- package/dist/three-author.d.ts +22 -0
- package/dist/three-author.js +29 -27
- package/dist/three-convert.cjs +21 -19
- package/dist/three-convert.d.ts +22 -0
- package/dist/three-convert.js +21 -19
- package/dist/three-live-animation.cjs +4 -4
- package/dist/three-live-animation.d.ts +22 -0
- package/dist/three-live-animation.js +4 -4
- package/dist/three-live-animation.min.js +4 -4
- package/dist/three-live-cad.cjs +2 -2
- package/dist/three-live-cad.d.ts +22 -0
- package/dist/three-live-cad.js +2 -2
- package/dist/three-live-cad.min.js +2 -2
- package/dist/three-live-element.cjs +5 -3
- package/dist/three-live-element.d.ts +22 -0
- package/dist/three-live-element.js +5 -3
- package/dist/three-live-full.cjs +48 -46
- package/dist/three-live-full.js +47 -45
- package/dist/three-live-full.min.js +48 -46
- package/dist/three-live-studio.cjs +10 -10
- package/dist/three-live-studio.d.ts +22 -0
- package/dist/three-live-studio.js +10 -10
- package/dist/three-live-studio.min.js +10 -10
- package/dist/three-live-viewer.cjs +5 -3
- package/dist/three-live-viewer.d.ts +22 -0
- package/dist/three-live-viewer.js +5 -3
- package/dist/three-live-viewer.min.js +5 -3
- package/dist/three-live.cjs +23 -21
- package/dist/three-live.js +25 -23
- package/dist/three-live.min.js +23 -21
- package/dist/three-view.cjs +8 -6
- package/dist/three-view.d.ts +22 -0
- package/dist/three-view.js +8 -6
- package/dist/three-xr.cjs +24 -22
- package/dist/three-xr.d.ts +22 -0
- package/dist/three-xr.js +24 -22
- package/package.json +1 -1
|
@@ -14,9 +14,10 @@
|
|
|
14
14
|
* See the License for the specific language governing permissions and
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
|
-
"use strict";var ThreeEngine=(()=>{var Kn=Object.defineProperty;var Di=Object.getOwnPropertyDescriptor;var Li=Object.getOwnPropertyNames;var Pi=Object.prototype.hasOwnProperty;var Ni=(t,e)=>{for(var n in e)Kn(t,n,{get:e[n],enumerable:!0})},Ui=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Li(e))!Pi.call(t,i)&&i!==n&&Kn(t,i,{get:()=>e[i],enumerable:!(r=Di(e,i))||r.enumerable});return t};var Oi=t=>Ui(Kn({},"__esModule",{value:!0}),t);var ls={};Ni(ls,{AmbientLight:()=>Jt,BoxGeometry:()=>Kt,BufferAttribute:()=>ge,BufferGeometry:()=>Ke,Camera:()=>tn,CapsuleGeometry:()=>$n,CircleGeometry:()=>jn,Clock:()=>Fn,Color:()=>Ze,ConeGeometry:()=>En,CylinderGeometry:()=>pt,DirectionalLight:()=>Un,DodecahedronGeometry:()=>Gn,Euler:()=>Wt,Float32BufferAttribute:()=>Mn,Group:()=>Nn,HemisphereLight:()=>rn,IcosahedronGeometry:()=>Vn,InstancedMesh:()=>Ft,Light:()=>yt,MAX_INSTANCES_PER_MESH:()=>Qt,Material:()=>qe,MathUtils:()=>gi,Matrix3:()=>Tn,Matrix4:()=>it,Mesh:()=>Mt,MeshBasicMaterial:()=>kn,MeshLambertMaterial:()=>Dn,MeshPhongMaterial:()=>Ln,MeshPhysicalMaterial:()=>Pn,MeshStandardMaterial:()=>bt,Object3D:()=>je,OctahedronGeometry:()=>Bn,PerspectiveCamera:()=>zt,PlaneGeometry:()=>Rn,PointLight:()=>en,PolyhedronFallbackGeometry:()=>At,Quaternion:()=>Yt,RawShaderMaterial:()=>Ei,RectAreaLight:()=>_i,RingGeometry:()=>Xn,Scene:()=>St,SceneQuotaValidator:()=>tt,ShaderMaterial:()=>nn,SphereGeometry:()=>qt,SpotLight:()=>Wn,THREE:()=>ot,TetrahedronGeometry:()=>Hn,Texture:()=>Zt,TextureLoader:()=>In,TorusGeometry:()=>_n,TorusKnotGeometry:()=>Cn,Uint16BufferAttribute:()=>Sn,Uint32BufferAttribute:()=>An,Vector2:()=>vn,Vector3:()=>Pe,Vector4:()=>wn,WebGLRenderer:()=>On,authorScriptRunner:()=>Ri,buildSandboxWorkerSource:()=>gr,clearAuthorWarnings:()=>wr,default:()=>us,exportSceneToCanvas3D:()=>pr,exportSceneToGLB:()=>br,exportSceneToUSDZ:()=>xi,generateUSDZ:()=>sr,getAllowClientScripts:()=>Ti,getAuthorWarnings:()=>vr,getSandboxEngineSrc:()=>yr,getSandboxIframeSrc:()=>wi,glbToUSDZ:()=>mn,isAllowedSandboxEngineUrl:()=>gt,noopProxy:()=>Ot,sceneToCanvas3D:()=>Nt,sceneToGLB:()=>Ht,sceneToUSDZ:()=>Ut,setAllowClientScripts:()=>Jo,setSandboxEngineSrc:()=>Ko,setSandboxIframeSrc:()=>Zo,threeAuthorPlugin:()=>jt,threeMicroPlugin:()=>cs,toTrustedWorkerScriptURL:()=>vi,validateSandboxWorkerMessage:()=>xr,warnUnsupported:()=>We});function on(t,e,n){let r=[],i=new Map,o=[],s=[],l=[],a=new Map,c=b=>{let _=i.get(b);return _===void 0&&(_=r.length,r.push({op:b}),i.set(b,_)),_},u=b=>{let _=a.get(b);return _===void 0&&(_=l.length,l.push({id:b}),a.set(b,_)),_},f=(b,_={})=>o.push({declaration:c(b),..._})-1,h=(b,_,S)=>s.push({id:b,type:_,value:S})-1,d=b=>({node:b,socket:"value"}),y=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(y&&typeof y=="object"){let b=Array.isArray(y.graphs)?y.graphs[y.graph??0]:y;if(b&&Array.isArray(b.nodes)){let _=Array.isArray(b.declarations)?b.declarations:[];for(let S of _)S?.op&&c(S.op);Array.isArray(b.variables)&&s.push(...b.variables);for(let S of b.events||[])S?.id&&u(S.id);for(let S of b.nodes){if(!S||typeof S!="object")continue;let U=S.op||(typeof S.declaration=="number"?_[S.declaration]?.op:"");o.push(U?{...S,declaration:c(U)}:{...S})}}}let x=(b,_,S="translation")=>S==="baseColorFactor"||S==="metallicFactor"||S==="roughnessFactor"?`/materials/${Math.max(0,_)}/pbrMetallicRoughness/${S}`:S==="emissiveFactor"||S==="alphaCutoff"?`/materials/${Math.max(0,_)}/${S}`:S==="visible"?`/nodes/${b}/extensions/KHR_node_visibility/visible`:`/nodes/${b}/${S}`,T=new Map;t.forEach((b,_)=>{typeof b?.name=="string"&&!T.has(b.name)&&T.set(b.name,_)});let D=(b,_)=>typeof b.target=="string"&&T.has(b.target)?T.get(b.target):typeof b.targetNode=="number"?b.targetNode:_,V=b=>{let _=t[b];return(typeof _?.mesh=="number"?e[_.mesh]?.primitives?.[0]?.material:0)??0};for(let b=0;b<t.length;b++){let _=t[b],S=_?.extras?.interactivity;if(!S||typeof S!="object")continue;let U=(typeof _.mesh=="number"?e[_.mesh]?.primitives?.[0]?.material:0)??0,z=E=>{let R=Array.isArray(E)?E:[E],g=[];for(let P=0;P<R.length;P++){let v=R[P];if(!v||typeof v!="object")continue;let p=v.action||"interpolate",m=typeof v.duration=="number"?v.duration:.35;if(p==="toggleTransform"){let L=v.property==="rotation"||v.property==="scale"?v.property:"translation",W=L==="rotation"?_.rotation||[0,0,0,1]:L==="scale"?_.scale||[1,1,1]:_.translation||[0,0,0],G=`/nodes/${b}/${L}`,K=h(`__toggle_${b}_${P}`,"bool",!1),k=f("variable/get",{configuration:{variable:K}}),ee=f("math/not",{values:{a:d(k)}}),Q=f("variable/set",{configuration:{variable:K},values:{value:d(ee)}}),q=f("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:Array.isArray(v.to)?v.to:W},duration:{value:m}}}),ae=f("pointer/interpolate",{configuration:{pointer:G},values:{value:{value:Array.isArray(v.from)?v.from:W},duration:{value:m}}});o[Q].flows={out:{node:f("flow/branch",{values:{condition:d(k)},flows:{true:{node:q},false:{node:ae}}})}},g.push(Q)}else if(p==="interpolate"){let L=v.to??v.value;if(L===void 0)continue;let W={value:{value:L},duration:{value:m}};v.from!==void 0&&(W.from={value:v.from}),g.push(f("pointer/interpolate",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:x(D(v,b),V(D(v,b)),v.property)},values:W}))}else if(p==="setProperty"){if(v.value===void 0)continue;g.push(f("pointer/set",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:x(D(v,b),V(D(v,b)),v.property)},values:{value:{value:v.value}}}))}else if(p==="toggleVisibility"){let L=D(v,b),W=h(`__vis_${L}_${P}`,"bool",!0),G=f("variable/get",{configuration:{variable:W}}),K=f("math/not",{values:{a:d(G)}}),k=f("variable/set",{configuration:{variable:W},values:{value:d(K)}});o[k].flows={out:{node:f("pointer/set",{configuration:{pointer:`/nodes/${L}/extensions/KHR_node_visibility/visible`},values:{value:d(G)}})}},g.push(k)}else if(p==="cycleMaterialColor"&&Array.isArray(v.colors)&&v.colors.length>0){let L=typeof v.duration=="number"?v.duration:.25,W=`/materials/${Math.max(0,U)}/pbrMetallicRoughness/baseColorFactor`,G=h(`__color_idx_${b}_${P}`,"int",0),K=f("variable/get",{configuration:{variable:G}}),k=f("math/add",{values:{a:d(K),b:{value:1}}}),ee=f("math/rem",{values:{a:d(k),b:{value:v.colors.length}}}),Q=f("variable/set",{configuration:{variable:G},values:{value:d(ee)}}),q={};for(let ae=0;ae<v.colors.length;ae++){let O=v.colors[ae],te=Array.isArray(O)&&O.length>=3?[O[0],O[1],O[2],O[3]??1]:[1,1,1,1];q[String(ae)]={node:L>0?f("pointer/interpolate",{configuration:{pointer:W},values:{value:{value:te},duration:{value:L}}}):f("pointer/set",{configuration:{pointer:W},values:{value:{value:te}}})}}o[Q].flows={out:{node:f("flow/switch",{values:{selection:d(K)},flows:q})}},g.push(Q)}else if(p==="playAnimation")g.push(f("animation/start",{configuration:{animation:v.animation??v.clip??0}}));else if(p==="stopAnimation")g.push(f("animation/stop"));else if(p==="sendEvent"){let L={};for(let[W,G]of Object.entries(v.values||{}))L[W]={value:G};g.push(f("event/send",{configuration:{event:u(String(v.event??v.id??"custom"))},values:L}))}}if(!g.length)return null;if(g.length===1)return g[0];let M={};return g.forEach((P,v)=>{M[String(v)]={node:P}}),f("flow/sequence",{flows:M})},I=(E,R,g)=>{let M=z(R);M!==null&&f(E,{...g?{configuration:g}:{},flows:{out:{node:M}}})};if(S.onSelect&&I("pointer/onSelect",S.onSelect,{nodeIndex:b}),S.onHoverIn&&I("pointer/onHoverIn",S.onHoverIn,{nodeIndex:b}),S.onHoverOut&&I("pointer/onHoverOut",S.onHoverOut,{nodeIndex:b}),S.onStart&&I("event/onStart",S.onStart),S.onReceive&&typeof S.onReceive=="object")for(let[E,R]of Object.entries(S.onReceive))I("event/receive",R,{event:u(E)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:s,events:l}],graph:0}:null}var Pr='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).',Nr="Security Error: client-side scripts require allow-client-scripts opt-in.";var sn="__THREE_LIVE_REGISTRY__";function ke(){let t=typeof globalThis<"u"?globalThis:{};if(!t[sn]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,sn,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[sn]=e}}return t[sn]}var Oe=ke().plugins;function Ur(t){let e=ke().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function Or(){return ke().plugins}function Fr(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,s=t.Matrix3,l=t.Color,a=t.BufferAttribute,c=t.BufferGeometry,u=t.Material,f=t.MeshStandardMaterial,h=t.Mesh,d=8192,y=2048,x=128,T=4096,D=(C,w)=>{let A=C==null?NaN:Number(C);return Number.isFinite(A)?A:w};class V{constructor(w){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(w)&&w.length>0&&this.fromPoints(w)}fromPoints(w){if(!w.length)return this;this.moveTo(w[0].x,w[0].y);for(let A=1;A<w.length;A++)this.lineTo(w[A].x,w[A].y);return this}moveTo(w,A){let N=Number(w)||0,F=Number(A)||0;return this.currentPoint.set(N,F),this.segments.push({type:"move",pts:[N,F]}),this}lineTo(w,A){let N=Number(w)||0,F=Number(A)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(N,F),this.segments.push({type:"line",pts:[N,F]}),this}quadraticCurveTo(w,A,N,F){let B=this.currentPoint.x,$=this.currentPoint.y,X=Number(w)||0,Y=Number(A)||0,H=Number(N)||0,J=Number(F)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[B,$]}),this.currentPoint.set(H,J),this.segments.push({type:"quad",pts:[B,$,X,Y,H,J]}),this}bezierCurveTo(w,A,N,F,B,$){let X=this.currentPoint.x,Y=this.currentPoint.y,H=Number(w)||0,J=Number(A)||0,Z=Number(N)||0,j=Number(F)||0,ie=Number(B)||0,oe=Number($)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[X,Y]}),this.currentPoint.set(ie,oe),this.segments.push({type:"cubic",pts:[X,Y,H,J,Z,j,ie,oe]}),this}absarc(w,A,N,F,B,$=!1){return this.absellipse(w,A,N,N,F,B,$,0)}arc(w,A,N,F,B,$=!1){return this.absarc(this.currentPoint.x+(Number(w)||0),this.currentPoint.y+(Number(A)||0),N,F,B,$)}absellipse(w,A,N,F,B,$,X=!1,Y=0){let H=Number(w)||0,J=Number(A)||0,Z=Math.max(0,Number(N)||0),j=Math.max(0,Number(F)||0),ie=Number(B)||0,oe=Number($)||0,ce=X?1:0,se=Number(Y)||0;this.segments.push({type:"arc",pts:[H,J,Z,j,ie,oe,ce,se]});let ne=Math.cos(se),fe=Math.sin(se),ye=Z*Math.cos(oe),me=j*Math.sin(oe);return this.currentPoint.set(H+ye*ne-me*fe,J+ye*fe+me*ne),this}ellipse(w,A,N,F,B,$,X=!1,Y=0){return this.absellipse(this.currentPoint.x+(Number(w)||0),this.currentPoint.y+(Number(A)||0),N,F,B,$,X,Y)}closePath(){if(this.segments.length>0){let w=this.segments[0],A=0,N=0;if(w.type==="arc"){let F=w.pts[0],B=w.pts[1],$=w.pts[2],X=w.pts[3],Y=w.pts[4],H=w.pts[7],J=Math.cos(H),Z=Math.sin(H),j=$*Math.cos(Y),ie=X*Math.sin(Y);A=F+j*J-ie*Z,N=B+j*Z+ie*J}else A=w.pts[0],N=w.pts[1];Math.hypot(this.currentPoint.x-A,this.currentPoint.y-N)>1e-6&&this.lineTo(A,N)}return this}getPoints(w=12){let A=Math.max(1,Math.min(128,Math.floor(Number(w)||12))),N=[],F=(B,$)=>{if(N.length>0){let X=N[N.length-1];if(Math.hypot(X.x-B,X.y-$)<1e-6)return}N.push(new n(B,$))};for(let B of this.segments){let $=B.pts;if(B.type==="move"||B.type==="line")F($[0],$[1]);else if(B.type==="quad"){let X=$[0],Y=$[1],H=$[2],J=$[3],Z=$[4],j=$[5];F(X,Y);for(let ie=1;ie<=A;ie++){let oe=ie/A,ce=1-oe;F(ce*ce*X+2*ce*oe*H+oe*oe*Z,ce*ce*Y+2*ce*oe*J+oe*oe*j)}}else if(B.type==="cubic"){let X=$[0],Y=$[1],H=$[2],J=$[3],Z=$[4],j=$[5],ie=$[6],oe=$[7];F(X,Y);for(let ce=1;ce<=A;ce++){let se=ce/A,ne=1-se,fe=ne*ne,ye=se*se;F(fe*ne*X+3*fe*se*H+3*ne*ye*Z+ye*se*ie,fe*ne*Y+3*fe*se*J+3*ne*ye*j+ye*se*oe)}}else if(B.type==="arc"){let X=$[0],Y=$[1],H=$[2],J=$[3],Z=$[4],j=$[5],ie=$[6]!==0,oe=$[7],ce=Math.PI*2,se=j-Z,ne=Math.abs(se)<1e-9;for(;se<0;)se+=ce;for(;se>ce;)se-=ce;se<1e-9&&(se=ne?0:ce),ie&&!ne&&(se=se===ce?-ce:se-ce);let fe=Math.cos(oe),ye=Math.sin(oe),me=Math.max(2,A);for(let Se=0;Se<=me;Se++){let we=Se/me,Ae=Z+we*se,_e=H*Math.cos(Ae),Ie=J*Math.sin(Ae);F(X+_e*fe-Ie*ye,Y+_e*ye+Ie*fe)}}}if(N.length>2){let B=N[0],$=N[N.length-1];Math.hypot(B.x-$.x,B.y-$.y)<1e-6&&N.pop()}return N}getSpacedPoints(w=12){return this.getPoints(w)}}class b extends V{constructor(w){super(w),this.holes=[]}extractPoints(w=12){return{shape:this.getPoints(w),holes:this.holes.map(A=>A.getPoints(w))}}}function _(C){let w=0,A=C.length;for(let N=0,F=A-1;N<A;F=N++)w+=C[F].x*C[N].y-C[N].x*C[F].y;return w*.5}function S(C,w,A,N,F,B,$,X){let Y=$-A,H=X-N,J=F-A,Z=B-N,j=C-A,ie=w-N,oe=Y*Y+H*H,ce=Y*J+H*Z,se=Y*j+H*ie,ne=J*J+Z*Z,fe=J*j+Z*ie,ye=oe*ne-ce*ce;if(Math.abs(ye)<1e-12)return!1;let me=1/ye,Se=(ne*se-ce*fe)*me,we=(oe*fe-ce*se)*me;return Se>=-1e-7&&we>=-1e-7&&Se+we<=1+1e-7}function U(C,w){let A=C.slice();_(A)<0&&A.reverse();let N=A.map(Y=>new n(Y.x,Y.y)),F=A.map((Y,H)=>H),B=[];for(let Y of w){if(!Y||Y.length<3)continue;let H=Y.slice();_(H)>0&&H.reverse();let J=[],Z=-1/0,j=0;for(let ie=0;ie<H.length;ie++){let oe=H[ie],ce=N.length;N.push(new n(oe.x,oe.y)),J.push(ce),oe.x>Z&&(Z=oe.x,j=ie)}B.push({pts:H,indices:J,maxX:Z,maxIdx:j})}B.sort((Y,H)=>H.maxX-Y.maxX);let $=(Y,H,J)=>(H.x-Y.x)*(J.y-Y.y)-(H.y-Y.y)*(J.x-Y.x),X=(Y,H,J)=>{for(let Z=0;Z<J.length;Z++){let j=J[Z],ie=J[(Z+1)%J.length];if($(Y,H,j)*$(Y,H,ie)<0&&$(j,ie,Y)*$(j,ie,H)<0)return!0}return!1};for(let Y of B){let H=Y.pts[Y.maxIdx],J=H.x,Z=F.length,j=F.map(ne=>N[ne]),ie=ne=>Math.hypot(j[ne].x-J,j[ne].y-H.y),oe=j.map((ne,fe)=>fe).sort((ne,fe)=>+(j[ne].x<J)-+(j[fe].x<J)||ie(ne)-ie(fe)),ce=oe[0];for(let ne of oe){let fe=j[ne],ye=j[(ne+Z-1)%Z],me=j[(ne+1)%Z],Se=$(fe,me,H)>=0,we=$(ye,fe,H)>=0;if(($(ye,fe,me)>=0?Se&&we:Se||we)&&!X(H,fe,j)&&!B.some(_e=>X(H,fe,_e.pts))){ce=ne;break}}let se=[];for(let ne=0;ne<=ce;ne++)se.push(F[ne]);for(let ne=0;ne<=Y.indices.length;ne++){let fe=Y.indices[(Y.maxIdx+ne)%Y.indices.length];se.push(fe)}for(let ne=ce;ne<F.length;ne++)se.push(F[ne]);F=se}return{merged:F.map(Y=>N[Y]),mergedIndices:F,allVertices:N}}function z(C,w){let A=[],N=C.slice();if(N.length<3)return A;let F=N.length*N.length+64,B=0;for(;N.length>2&&F-- >0;){let $=N.length,X=N[(B+$-1)%$],Y=N[B%$],H=N[(B+1)%$],J=w[X],Z=w[Y],j=w[H];if((Z.x-J.x)*(j.y-J.y)-(Z.y-J.y)*(j.x-J.x)>1e-9){let oe=!0;for(let ce=0;ce<$;ce++){let se=N[ce];if(se===X||se===Y||se===H)continue;let ne=w[se];if(S(ne.x,ne.y,J.x,J.y,Z.x,Z.y,j.x,j.y)&&Math.hypot(ne.x-J.x,ne.y-J.y)>=1e-6&&Math.hypot(ne.x-Z.x,ne.y-Z.y)>=1e-6&&Math.hypot(ne.x-j.x,ne.y-j.y)>=1e-6){oe=!1;break}}if(oe){A.push([X,Y,H]),N.splice(B%$,1),B=Math.max(0,B%$-1);continue}}B++,B>=$*2&&(A.push([X,Y,H]),N.splice((B-1)%$,1),B=0)}return A}function I(C,w){let A=C instanceof b?C.extractPoints(w):{shape:C.getPoints(w),holes:[]},N=A.shape.length;for(let F of A.holes)N+=F.length;if(N>T)throw new RangeError(`SecurityError: shape point count (${N}) exceeds MAX_SHAPE_POINTS (${T})`);return A}class E extends c{constructor(w=new b,A=12){super();let N=Array.isArray(w)?w:[w],F=[],B=[],$=[],X=[];for(let Y of N){if(!(Y instanceof V))continue;let H=I(Y,A);if(H.shape.length<3)continue;let{mergedIndices:J,allVertices:Z}=U(H.shape,H.holes),j=z(J,Z),ie=F.length/3,oe=1/0,ce=1/0,se=-1/0,ne=-1/0;for(let me of Z)me.x<oe&&(oe=me.x),me.y<ce&&(ce=me.y),me.x>se&&(se=me.x),me.y>ne&&(ne=me.y);let fe=Math.max(1e-6,se-oe),ye=Math.max(1e-6,ne-ce);for(let me of Z)F.push(me.x,me.y,0),B.push(0,0,1),$.push((me.x-oe)/fe,(me.y-ce)/ye);for(let[me,Se,we]of j)X.push(ie+me,ie+Se,ie+we)}this.setAttribute("position",new a(R(F),3)),this.setAttribute("normal",new a(R(B),3)),this.setAttribute("uv",new a(R($),2)),this.setIndex(X)}}function R(C){let w=C.length,A=new Float32Array(w);for(let N=0;N<w;N++)A[N]=C[N];return A}function g(C){let w=C.length,A=[];for(let N=0;N<w;N++){let F=C[(N+w-1)%w],B=C[N],$=C[(N+1)%w],X=B.x-F.x,Y=B.y-F.y,H=Math.hypot(X,Y)||1;X/=H,Y/=H;let J=$.x-B.x,Z=$.y-B.y,j=Math.hypot(J,Z)||1;J/=j,Z/=j;let ie=Y,oe=-X,ce=Z,se=-J,ne=ie+ce,fe=oe+se,ye=Math.hypot(ne,fe);if(ye>1e-6){ne/=ye,fe/=ye;let me=Math.max(.35,ne*ie+fe*oe);A.push(new n(ne/me,fe/me))}else A.push(new n(ie,oe))}return A}class M extends c{constructor(w=new b,A={}){super();let N=Array.isArray(w)?w:[w],F=Math.max(1,Math.min(64,Math.floor(D(A.curveSegments,12)))),B=D(A.depth??A.amount,1),$=Math.max(1,Math.min(32,Math.floor(D(A.steps,1)))),X=!!(A.bevelEnabled??!1),Y=X?Math.max(0,D(A.bevelThickness,.06)):0,H=X?Math.max(0,D(A.bevelSize,Y*.8)):0,J=X?D(A.bevelOffset,0):0,Z=X?Math.max(1,Math.min(8,Math.floor(D(A.bevelSegments,2)))):0,j=[],ie=[],oe=[],ce=[];for(let se of N){if(!(se instanceof V))continue;let ne=I(se,F);if(ne.shape.length<3)continue;let fe=ne.shape.slice();_(fe)<0&&fe.reverse();let ye=[];for(let be of ne.holes){if(be.length<3)continue;let Re=be.slice();_(Re)>0&&Re.reverse(),ye.push(Re)}let{mergedIndices:me,allVertices:Se}=U(fe,ye),we=z(me,Se),Ae=[fe,...ye],_e=[];for(let be of Ae){let Re=g(be);for(let Ce of Re)_e.push(Ce)}let Ie=1/0,ze=1/0,Fe=-1/0,Ye=-1/0;for(let be of Se)be.x<Ie&&(Ie=be.x),be.y<ze&&(ze=be.y),be.x>Fe&&(Fe=be.x),be.y>Ye&&(Ye=be.y);let Ve=Math.max(1e-6,Fe-Ie),Qe=Math.max(1e-6,Ye-ze),Rt=-Y,Et=B+Y,st=j.length/3;for(let be=0;be<Se.length;be++){let Re=Se[be],Ce=_e[be]??new n(0,0),Ne=Re.x+Ce.x*J,Ue=Re.y+Ce.y*J;j.push(Ne,Ue,Rt),ie.push(0,0,-1),oe.push((Ne-Ie)/Ve,(Ue-ze)/Qe)}for(let[be,Re,Ce]of we)ce.push(st+be,st+Ce,st+Re);let at=j.length/3;for(let be=0;be<Se.length;be++){let Re=Se[be],Ce=_e[be]??new n(0,0),Ne=Re.x+Ce.x*J,Ue=Re.y+Ce.y*J;j.push(Ne,Ue,Et),ie.push(0,0,1),oe.push((Ne-Ie)/Ve,(Ue-ze)/Qe)}for(let[be,Re,Ce]of we)ce.push(at+be,at+Re,at+Ce);let Ge=[];if(X&&Z>0)for(let be=0;be<Z;be++){let Ce=be/Z*Math.PI/2;Ge.push({z:-Y*Math.cos(Ce),expand:J+H*Math.sin(Ce)})}for(let be=0;be<=$;be++){let Re=be/$;Ge.push({z:Re*B,expand:J+H})}if(X&&Z>0)for(let be=1;be<=Z;be++){let Ce=be/Z*Math.PI/2;Ge.push({z:B+Y*Math.sin(Ce),expand:J+H*Math.cos(Ce)})}let Je=0;for(let be of Ae){let Re=be.length;for(let Ce=0;Ce<Ge.length-1;Ce++){let Ne=Ge[Ce],Ue=Ge[Ce+1];for(let He=0;He<Re;He++){let nt=(He+1)%Re,ct=be[He],ut=be[nt],lt=_e[Je+He],ht=_e[Je+nt],ft=ct.x+lt.x*Ne.expand,mt=ct.y+lt.y*Ne.expand,xt=ut.x+ht.x*Ne.expand,rt=ut.y+ht.y*Ne.expand,Ii=ut.x+ht.x*Ue.expand,ki=ut.y+ht.y*Ue.expand,Tr=ct.x+lt.x*Ue.expand,Mr=ct.y+lt.y*Ue.expand,Sr=xt-ft,Ar=rt-mt,Rr=0,Er=Tr-ft,_r=Mr-mt,Cr=Ue.z-Ne.z,_t=Ar*Cr-Rr*_r,Ct=Rr*Er-Sr*Cr,It=Sr*_r-Ar*Er,Yn=Math.hypot(_t,Ct,It)||1;_t/=Yn,Ct/=Yn,It/=Yn;let kt=j.length/3;j.push(ft,mt,Ne.z,xt,rt,Ne.z,Ii,ki,Ue.z,Tr,Mr,Ue.z),ie.push(_t,Ct,It,_t,Ct,It,_t,Ct,It,_t,Ct,It);let Ir=He/Re,kr=(He+1)/Re,Dr=Ce/(Ge.length-1),Lr=(Ce+1)/(Ge.length-1);oe.push(Ir,Dr,kr,Dr,kr,Lr,Ir,Lr),ce.push(kt,kt+1,kt+2,kt,kt+2,kt+3)}}Je+=Re}}this.setAttribute("position",new a(R(j),3)),this.setAttribute("normal",new a(R(ie),3)),this.setAttribute("uv",new a(R(oe),2)),this.setIndex(ce)}}function P(C){return{x:C.x,y:C.y,z:C.z,nx:C.nx,ny:C.ny,nz:C.nz,u:C.u,v:C.v}}function v(C){return{x:C.x,y:C.y,z:C.z,nx:-C.nx,ny:-C.ny,nz:-C.nz,u:C.u,v:C.v}}function p(C,w,A){let N=C.nx+(w.nx-C.nx)*A,F=C.ny+(w.ny-C.ny)*A,B=C.nz+(w.nz-C.nz)*A,$=Math.hypot(N,F,B)||1;return{x:C.x+(w.x-C.x)*A,y:C.y+(w.y-C.y)*A,z:C.z+(w.z-C.z)*A,nx:N/$,ny:F/$,nz:B/$,u:C.u+(w.u-C.u)*A,v:C.v+(w.v-C.v)*A}}function m(C){if(C.length<3)return null;let w=C[0],A=C[1],N=C[2],F=A.x-w.x,B=A.y-w.y,$=A.z-w.z,X=N.x-w.x,Y=N.y-w.y,H=N.z-w.z,J=B*H-$*Y,Z=$*X-F*H,j=F*Y-B*X,ie=Math.hypot(J,Z,j);if(ie<1e-9)return null;J/=ie,Z/=ie,j/=ie;let oe=J*w.x+Z*w.y+j*w.z;return{vertices:C,nx:J,ny:Z,nz:j,w:oe}}function L(C){C.vertices.reverse();for(let w=0;w<C.vertices.length;w++)C.vertices[w]=v(C.vertices[w]);C.nx=-C.nx,C.ny=-C.ny,C.nz=-C.nz,C.w=-C.w}let W=1e-5,G=0,K=1,k=2,ee=3;function Q(C,w,A,N,F,B,$,X,Y){let H=0,J=[];for(let Z=0;Z<F.vertices.length;Z++){let j=F.vertices[Z],ie=C*j.x+w*j.y+A*j.z-N,oe=ie<-W?k:ie>W?K:G;H|=oe,J.push(oe)}switch(H){case G:{C*F.nx+w*F.ny+A*F.nz>0?B.push(F):$.push(F);break}case K:X.push(F);break;case k:Y.push(F);break;case ee:{let Z=[],j=[],ie=F.vertices.length;for(let fe=0;fe<ie;fe++){let ye=(fe+1)%ie,me=J[fe],Se=J[ye],we=F.vertices[fe],Ae=F.vertices[ye];if(me!==k&&Z.push(we),me!==K&&j.push(me!==k?P(we):we),(me|Se)===ee){let _e=Ae.x-we.x,Ie=Ae.y-we.y,ze=Ae.z-we.z,Fe=C*_e+w*Ie+A*ze,Ye=Math.abs(Fe)>1e-12?(N-(C*we.x+w*we.y+A*we.z))/Fe:.5,Ve=p(we,Ae,Math.max(0,Math.min(1,Ye)));Z.push(Ve),j.push(P(Ve))}}let{nx:oe,ny:ce,nz:se,w:ne}=F;Z.length>=3&&X.push({vertices:Z,nx:oe,ny:ce,nz:se,w:ne}),j.length>=3&&Y.push({vertices:j,nx:oe,ny:ce,nz:se,w:ne});break}default:break}}class q{constructor(w,A=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,w&&w.length>0&&this.build(w,A)}invert(){for(let A=0;A<this.polygons.length;A++)L(this.polygons[A]);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 w=this.front;this.front=this.back,this.back=w}clipPolygons(w,A=0){if(!this.hasPlane||w.length===0)return w.slice();if(A>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let N=[],F=[];for(let B=0;B<w.length;B++)Q(this.nx,this.ny,this.nz,this.w,w[B],N,F,N,F);return this.front&&N.length>0&&(N=this.front.clipPolygons(N,A+1)),this.back?F=F.length>0?this.back.clipPolygons(F,A+1):[]:F=[],N.concat(F)}clipTo(w,A=0){this.polygons.length>0&&(this.polygons=w.clipPolygons(this.polygons,0)),A<y&&(this.front&&this.front.clipTo(w,A+1),this.back&&this.back.clipTo(w,A+1))}allPolygons(w=[]){for(let A=0;A<this.polygons.length;A++)w.push(this.polygons[A]);return this.front&&this.front.allPolygons(w),this.back&&this.back.allPolygons(w),w}build(w,A=0){if(!w.length)return;if(!this.hasPlane){let B=w[w.length>>1];this.nx=B.nx,this.ny=B.ny,this.nz=B.nz,this.w=B.w,this.hasPlane=!0}if(A>=y)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${y})`);let N=[],F=[];for(let B=0;B<w.length;B++)Q(this.nx,this.ny,this.nz,this.w,w[B],this.polygons,this.polygons,N,F);N.length>0&&(this.front||(this.front=new q),this.front.build(N,A+1)),F.length>0&&(this.back||(this.back=new q),this.back.build(F,A+1))}}function ae(C,w){if(!w&&C._csgPolygons)return C._csgPolygons;let A=C.attributes.position;if(!A||A.count===0)return[];let N=C.attributes.normal,F=C.attributes.uv,B=C.index?C.index.array:null,$=Math.floor(B?B.length/3:A.count/3);if($>d)throw new RangeError(`SecurityError: CSG input triangle count (${$}) exceeds MAX_CSG_TRIANGLES (${d})`);let X=w?w.elements:null,Y=X?X[0]*(X[5]*X[10]-X[9]*X[6])-X[4]*(X[1]*X[10]-X[9]*X[2])+X[8]*(X[1]*X[6]-X[5]*X[2])<0:!1,H=X?new s().getNormalMatrix(w).elements:null,J=j=>{let ie=A.getX(j),oe=A.getY(j),ce=A.getZ(j),se=N?N.getX(j):NaN,ne=N?N.getY(j):NaN,fe=N?N.getZ(j):NaN;if(X&&H){let Se=X[0]*ie+X[4]*oe+X[8]*ce+X[12],we=X[1]*ie+X[5]*oe+X[9]*ce+X[13],Ae=X[2]*ie+X[6]*oe+X[10]*ce+X[14];ie=Se,oe=we,ce=Ae;let _e=H[0]*se+H[3]*ne+H[6]*fe,Ie=H[1]*se+H[4]*ne+H[7]*fe,ze=H[2]*se+H[5]*ne+H[8]*fe,Fe=Math.hypot(_e,Ie,ze)||1;se=_e/Fe,ne=Ie/Fe,fe=ze/Fe}let ye=F?F.getX(j):0,me=F?F.getY(j):0;return{x:ie,y:oe,z:ce,nx:se,ny:ne,nz:fe,u:ye,v:me}},Z=[];for(let j=0;j<$;j++){let ie=B?B[j*3]:j*3,oe=B?B[j*3+1]:j*3+1,ce=B?B[j*3+2]:j*3+2,se=m(Y?[J(ie),J(ce),J(oe)]:[J(ie),J(oe),J(ce)]);se&&Z.push(se)}return Z}function O(C){let w=[],A=[],N=[],F=[];for(let $ of C){let X=$.vertices;if(X.length<3)continue;let Y=w.length/3;for(let H of X)w.push(H.x,H.y,H.z),Number.isFinite(H.nx)&&H.nx*H.nx+H.ny*H.ny+H.nz*H.nz>.5?A.push(H.nx,H.ny,H.nz):A.push($.nx,$.ny,$.nz),N.push(H.u,H.v);for(let H=1;H<X.length-1;H++)F.push(Y,Y+H,Y+H+1)}let B=new c;return B.setAttribute("position",new a(R(w),3)),B.setAttribute("normal",new a(R(A),3)),B.setAttribute("uv",new a(R(N),2)),B.setIndex(F),B._csgPolygons=C,B}function te(C,w,A){if(C.length+w.length>d)throw new RangeError(`SecurityError: Combined CSG triangle count (${C.length+w.length}) exceeds MAX_CSG_TRIANGLES (${d})`);if(C.length===0)return A==="union"?w:[];if(w.length===0)return A==="intersect"?[]:C;let N=1/0,F=1/0,B=1/0,$=-1/0,X=-1/0,Y=-1/0;for(let ie=0;ie<w.length;ie++){let oe=w[ie].vertices;for(let ce=0;ce<oe.length;ce++){let se=oe[ce];se.x<N&&(N=se.x),se.y<F&&(F=se.y),se.z<B&&(B=se.z),se.x>$&&($=se.x),se.y>X&&(X=se.y),se.z>Y&&(Y=se.z)}}N-=1e-4,F-=1e-4,B-=1e-4,$+=1e-4,X+=1e-4,Y+=1e-4;let H=[],J=[];for(let ie=0;ie<C.length;ie++){let oe=C[ie],ce=oe.vertices,se=1/0,ne=1/0,fe=1/0,ye=-1/0,me=-1/0,Se=-1/0;for(let we=0;we<ce.length;we++){let Ae=ce[we];Ae.x<se&&(se=Ae.x),Ae.y<ne&&(ne=Ae.y),Ae.z<fe&&(fe=Ae.z),Ae.x>ye&&(ye=Ae.x),Ae.y>me&&(me=Ae.y),Ae.z>Se&&(Se=Ae.z)}ye<N||se>$||me<F||ne>X||Se<B||fe>Y?J.push(oe):H.push(oe)}if(H.length===0)return A==="union"?C.concat(w):A==="subtract"?C:[];let Z=new q(H),j=new q(w);return A==="union"?(Z.clipTo(j),j.clipTo(Z),j.invert(),j.clipTo(Z),j.invert(),Z.build(j.allPolygons()),J.concat(Z.allPolygons())):A==="subtract"?(Z.invert(),Z.clipTo(j),j.clipTo(Z),j.invert(),j.clipTo(Z),j.invert(),Z.build(j.allPolygons()),Z.invert(),J.concat(Z.allPolygons())):(Z.invert(),j.clipTo(Z),j.invert(),Z.clipTo(j),j.clipTo(Z),Z.build(j.allPolygons()),Z.invert(),Z.allPolygons())}function ue(C,w,A,N=null,F=null){let B=ae(C,N),$=ae(w,F);return O(te(B,$,A))}function le(C,w,A){let N=C instanceof h||!!C?.isMesh,F=w instanceof h||!!w?.isMesh,B=N?C.geometry:C,$=F?w.geometry:w,X=null;if(F)if(w.updateMatrix(),N){C.updateMatrix();let Z=new o().makeScale(1/(C.scale.x||1),1/(C.scale.y||1),1/(C.scale.z||1)),j=Math.hypot(C.quaternion.x,C.quaternion.y,C.quaternion.z,C.quaternion.w)||1,ie=new o().compose(new r(0,0,0),new i(-C.quaternion.x/j,-C.quaternion.y/j,-C.quaternion.z/j,C.quaternion.w/j),new r(1,1,1)),oe=new o().makeTranslation(-C.position.x,-C.position.y,-C.position.z);X=Z.multiply(ie).multiply(oe).multiply(w.matrix)}else X=w.matrix;let Y=ue(B,$,A,null,X),H=N?C.material:new f,J=new h(Y,H);return N&&(J.position.copy(C.position),J.quaternion.copy(C.quaternion),J.scale.copy(C.scale),J.name=C.name),J}let he={toGeometry:ue,subtract(C,w){return le(C,w,"subtract")},union(C,w){return le(C,w,"union")},intersect(C,w){return le(C,w,"intersect")}},ve={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 Me extends c{constructor(w="",A={}){super();let N=String(w??"").slice(0,x),F=Math.max(.005,Math.min(100,D(A.size,.2))),B=!!(A.bevelEnabled??!1),$=B?Math.max(0,Math.min(2,D(A.bevelThickness,F*.04))):0,X=B?Math.max(0,Math.min(2,D(A.bevelSize,F*.03))):0,Y=Math.max(.001,Math.min(20,D(A.depth??A.height,F*.2)))+$*2,H=F*.085+X,J=F*.68,Z=F*.82,j=[],ie=[],oe=[],ce=[],se=(ye,me,Se,we,Ae,_e,Ie)=>{let ze=Se-ye,Fe=we-me,Ye=Math.hypot(ze,Fe),Ve=1,Qe=0;Ye>1e-6&&(Ve=ze/Ye,Qe=Fe/Ye);let Rt=-Qe*Ae,Et=Ve*Ae,st=Ve*Ae*.6,at=Qe*Ae*.6,Ge=ye-st+Rt,Je=me-at+Et,be=ye-st-Rt,Re=me-at-Et,Ce=Se+st-Rt,Ne=we+at-Et,Ue=Se+st+Rt,He=we+at+Et,nt=(ct,ut,lt,ht,ft,mt,xt)=>{let rt=j.length/3;j.push(ct[0],ct[1],ct[2],ut[0],ut[1],ut[2],lt[0],lt[1],lt[2],ht[0],ht[1],ht[2]),ie.push(ft,mt,xt,ft,mt,xt,ft,mt,xt,ft,mt,xt),oe.push(0,0,1,0,1,1,0,1),ce.push(rt,rt+1,rt+2,rt,rt+2,rt+3)};nt([Ge,Je,Ie],[be,Re,Ie],[Ce,Ne,Ie],[Ue,He,Ie],0,0,1),nt([be,Re,_e],[Ge,Je,_e],[Ue,He,_e],[Ce,Ne,_e],0,0,-1),nt([Ge,Je,_e],[be,Re,_e],[be,Re,Ie],[Ge,Je,Ie],-Ve,-Qe,0),nt([Ce,Ne,_e],[Ue,He,_e],[Ue,He,Ie],[Ce,Ne,Ie],Ve,Qe,0),nt([be,Re,_e],[Ce,Ne,_e],[Ce,Ne,Ie],[be,Re,Ie],Qe,-Ve,0),nt([Ue,He,_e],[Ge,Je,_e],[Ge,Je,Ie],[Ue,He,Ie],-Qe,Ve,0)},ne=0,fe=0;for(let ye=0;ye<N.length;ye++){let me=N[ye];if(me===`
|
|
18
|
-
`){ne=0,fe-=F*1.35;continue}if(me===" "||me===" "){ne+=Z*(me===" "?.75:3);continue}if(me==="\r")continue;let Se=me.toUpperCase(),we=me!==Se&&me>="a"&&me<="z",Ae=ve[Se]??ve["?"],_e=we?F*.76:F,Ie=we?J*.88:J;for(let ze of Ae)for(let Fe=0;Fe<ze.length-1;Fe++){let Ye=ze[Fe],Ve=ze[Fe+1];se(ne+Ye[0]*Ie,fe+Ye[1]*_e,ne+Ve[0]*Ie,fe+Ve[1]*_e,H,-Y*.5,Y*.5)}ne+=we?Z*.88:Z}this.setAttribute("position",new a(R(j),3)),this.setAttribute("normal",new a(R(ie),3)),this.setAttribute("uv",new a(R(oe),2)),this.setIndex(ce),A.center!==!1?this.center():this.computeBoundingBox()}}function pe(C){if(!C)return;let w=C,A=C.userData?.xr?.text;if(A!=null&&A!==!1){let F=w.geometry?.attributes?.position;if((!F||F.count===0)&&C.userData._textApplied!==!0){let B="",$=.08,X=.015,Y;if(typeof A=="string"||typeof A=="number")B=String(A);else if(typeof A=="object"){let H=A;B=String(H.text??H.value??""),H.size!==void 0&&($=Number(H.size)||.08),(H.depth!==void 0||H.height!==void 0)&&(X=Number(H.depth??H.height)||$*.2),(typeof H.color=="string"||typeof H.color=="number")&&(Y=H.color)}B.trim().length>0&&(w.geometry=new Me(B,{size:$,depth:X}),C.userData._textApplied=!0,w.material instanceof u?Y!==void 0&&C.userData._autoTextColorApplied!==!0&&(w.material.color=new l(Y),C.userData._autoTextColorApplied=!0):w.material=new f({color:Y??16317180}))}}let N=C.userData?.csg;if(N&&typeof N=="object"&&C.userData._csgApplied!==!0&&w.geometry instanceof c&&w.geometry.attributes.position?.count>0){C.userData._csgApplied=!0;let F=Array.isArray(N)?N:[N],B=w.geometry;for(let $ of F){if(!$||typeof $!="object")continue;let X=$,Y=String(X.op??X.operation??"subtract"),H=Y==="union"||Y==="intersect"?Y:"subtract",J=X.target??X.mesh??X.geometry;if(J instanceof h||J instanceof c)try{let Z=H==="union"?he.union(w,J):H==="intersect"?he.intersect(w,J):he.subtract(w,J);w.geometry!==B&&w.geometry.dispose?.(),w.geometry=Z.geometry}catch(Z){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",Z)}}}}let xe={Path:V,Shape:b,ShapeGeometry:E,ExtrudeGeometry:M,TextGeometry:Me,CSG:he,MAX_CSG_TRIANGLES:d,MAX_BSP_DEPTH:y,MAX_TEXT_GEOMETRY_CHARS:x,MAX_SHAPE_POINTS:T,materializeDeclarativeGeometry:pe};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,xe),e.materializeDeclarativeGeometry=pe),xe}function De(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function an(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let s=1/(r-i);return t[10]=(i+r)*s,t[14]=2*i*r*s,t}function Dt(t,e,n,r){let[i,o,s]=e,[l,a,c]=r,[u,f,h]=n,d=i-u,y=o-f,x=s-h,T=Math.hypot(d,y,x);T<=1e-5?(d=0,y=0,x=1):(d/=T,y/=T,x/=T);let D=a*x-c*y,V=c*d-l*x,b=l*y-a*d;T=Math.hypot(D,V,b),T<=1e-5?(D=0,V=0,b=0):(D/=T,V/=T,b/=T);let _=y*b-x*V,S=x*D-d*b,U=d*V-y*D;return T=Math.hypot(_,S,U),T<=1e-5?(_=0,S=0,U=0):(_/=T,S/=T,U/=T),t[0]=D,t[1]=_,t[2]=d,t[3]=0,t[4]=V,t[5]=S,t[6]=y,t[7]=0,t[8]=b,t[9]=U,t[10]=x,t[11]=0,t[12]=-(D*i+V*o+b*s),t[13]=-(_*i+S*o+U*s),t[14]=-(d*i+y*o+x*s),t[15]=1,t}function Le(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],l=e[4],a=e[5],c=e[6],u=e[7],f=e[8],h=e[9],d=e[10],y=e[11],x=e[12],T=e[13],D=e[14],V=e[15],b=n[0],_=n[1],S=n[2],U=n[3];return t[0]=b*r+_*l+S*f+U*x,t[1]=b*i+_*a+S*h+U*T,t[2]=b*o+_*c+S*d+U*D,t[3]=b*s+_*u+S*y+U*V,b=n[4],_=n[5],S=n[6],U=n[7],t[4]=b*r+_*l+S*f+U*x,t[5]=b*i+_*a+S*h+U*T,t[6]=b*o+_*c+S*d+U*D,t[7]=b*s+_*u+S*y+U*V,b=n[8],_=n[9],S=n[10],U=n[11],t[8]=b*r+_*l+S*f+U*x,t[9]=b*i+_*a+S*h+U*T,t[10]=b*o+_*c+S*d+U*D,t[11]=b*s+_*u+S*y+U*V,b=n[12],_=n[13],S=n[14],U=n[15],t[12]=b*r+_*l+S*f+U*x,t[13]=b*i+_*a+S*h+U*T,t[14]=b*o+_*c+S*d+U*D,t[15]=b*s+_*u+S*y+U*V,t}function vt(t,e,n,r){let i=e[0],o=e[1],s=e[2],l=e[3],a=i+i,c=o+o,u=s+s,f=i*a,h=i*c,d=i*u,y=o*c,x=o*u,T=s*u,D=l*a,V=l*c,b=l*u,_=r[0],S=r[1],U=r[2];return t[0]=(1-(y+T))*_,t[1]=(h+b)*_,t[2]=(d-V)*_,t[3]=0,t[4]=(h-b)*S,t[5]=(1-(f+T))*S,t[6]=(x+D)*S,t[7]=0,t[8]=(d+V)*U,t[9]=(x-D)*U,t[10]=(1-(f+y))*U,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function $e(t,e){let n=e[0],r=e[1],i=e[2],o=e[4],s=e[5],l=e[6],a=e[8],c=e[9],u=e[10],f=u*s-l*c,h=-u*o+l*a,d=c*o-s*a,y=n*f+r*h+i*d;return y&&(y=1/y,t[0]=f*y,t[1]=h*y,t[2]=d*y,t[3]=(-u*r+i*c)*y,t[4]=(u*n-i*a)*y,t[5]=(-c*n+r*a)*y,t[6]=(l*r-i*s)*y,t[7]=(-l*n+i*o)*y,t[8]=(s*n-r*o)*y),t}function zr(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],l=e[5],a=e[6],c=e[7],u=e[8],f=e[9],h=e[10],d=e[11],y=e[12],x=e[13],T=e[14],D=e[15],V=n*l-r*s,b=n*a-i*s,_=n*c-o*s,S=r*a-i*l,U=r*c-o*l,z=i*c-o*a,I=u*x-f*y,E=u*T-h*y,R=u*D-d*y,g=f*T-h*x,M=f*D-d*x,P=h*D-d*T,v=V*P-b*M+_*g+S*R-U*E+z*I;return v?(v=1/v,t[0]=(l*P-a*M+c*g)*v,t[1]=(i*M-r*P-o*g)*v,t[2]=(x*z-T*U+D*S)*v,t[3]=(h*U-f*z-d*S)*v,t[4]=(a*R-s*P-c*E)*v,t[5]=(n*P-i*R+o*E)*v,t[6]=(T*_-y*z-D*b)*v,t[7]=(u*z-h*_+d*b)*v,t[8]=(s*M-l*R+c*I)*v,t[9]=(r*R-n*M-o*I)*v,t[10]=(y*U-x*_+D*V)*v,t[11]=(f*_-u*U-d*V)*v,t[12]=(l*E-s*g-a*I)*v,t[13]=(n*g-r*E+i*I)*v,t[14]=(x*b-y*S-T*V)*v,t[15]=(u*S-f*b+h*V)*v,t):null}function qn(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],s=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],a=i[3]*e+i[7]*n+i[11]*r+i[15],c=a!==0?1/a:1;t[0]=o*c,t[1]=s*c,t[2]=l*c}function Vr(t,e,n,r,i,o,s,l,a,c,u,f,h,d,y,x,T=0){let D=c-s,V=u-l,b=f-a,_=h-s,S=d-l,U=y-a,z=i*U-o*S,I=o*_-r*U,E=r*S-i*_,R=D*z+V*I+b*E;if(R>-1e-7&&R<1e-7)return!1;let g=1/R,M=t-s,P=e-l,v=n-a,p=g*(M*z+P*I+v*E);if(p<-T||p>1+T)return!1;let m=P*b-v*V,L=v*D-M*b,W=M*V-P*D,G=g*(r*m+i*L+o*W);if(G<-T||p+G>1+T)return!1;let K=g*(_*m+S*L+U*W);if(K>1e-4&&K<x.distance){x.distance=K,x.point=[t+r*K,e+i*K,n+o*K];let k=V*U-b*S,ee=b*_-D*U,Q=D*S-V*_,q=Math.hypot(k,ee,Q)||1;return x.normal=[k/q,ee/q,Q/q],!0}return!1}function cn(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(De());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let f of u.children)i.add(f);let o=new Set,s=128,l=(u,f,h=0)=>{if(h>s||u<0||u>=n||o.has(u))return;o.add(u);let d=t.nodes[u];if(!d)return;let y=De();if(e&&e[u])y.set(e[u]);else if(d.matrix&&d.matrix.length===16)y.set(d.matrix);else{let T=d.translation||[0,0,0],D=d.rotation||[0,0,0,1],V=d.scale||[1,1,1];vt(y,D,T,V)}let x=r[u];if(f?Le(x,f,y):x.set(y),Array.isArray(d.children))for(let T of d.children)typeof T=="number"&&l(T,x,h+1)},a=[],c=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(c&&Array.isArray(c.nodes))a.push(...c.nodes);else for(let u=0;u<n;u++)i.has(u)||a.push(u);for(let u of a)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!a.includes(u)&&l(u,null);return r}function Zn(t,e){function n(a,c,u,f){let h=typeof a=="number"?a:Number(a);return Number.isFinite(h)?Math.max(c,Math.min(u,h)):f}function r(a,c){let f=a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+1;if(f<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let D=Math.hypot(a[1],a[0])||1;return[-a[1]/D,a[0]/D,0,0]}let T=Math.hypot(a[2],a[1])||1;return[0,-a[2]/T,a[1]/T,0]}let h=a[1]*c[2]-a[2]*c[1],d=a[2]*c[0]-a[0]*c[2],y=a[0]*c[1]-a[1]*c[0],x=Math.hypot(h,d,y,f)||1;return[h/x,d/x,y/x,f/x]}function i(a,c,u,f,h){let d=c[0]-a[0],y=c[1]-a[1],x=c[2]-a[2],T=Math.hypot(d,y,x),D=u[0]-c[0],V=u[1]-c[1],b=u[2]-c[2],_=Math.hypot(D,V,b);if(T<1e-6||_<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[c[0],c[1],c[2]],effectorPos:[u[0],u[1],u[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let S=[d/T,y/T,x/T],U=[D/_,V/_,b/_],z=f[0]-a[0],I=f[1]-a[1],E=f[2]-a[2],R=Math.hypot(z,I,E),g=R>1e-6?[z/R,I/R,E/R]:S,M=Math.abs(T-_)+1e-5,P=Math.max(M,T+_-1e-5),v=Math.max(M,Math.min(P,R>1e-6?R:M)),p=n((T*T+v*v-_*_)/(2*T*v),-1,1,1),m=Math.sqrt(Math.max(0,1-p*p)),L=h?h[0]-a[0]:d,W=h?h[1]-a[1]:y,G=h?h[2]-a[2]:x,K=L*g[0]+W*g[1]+G*g[2],k=L-g[0]*K,ee=W-g[1]*K,Q=G-g[2]*K,q=Math.hypot(k,ee,Q);if(q<=1e-6){let C=Math.abs(g[1])<.99?0:1,w=Math.abs(g[1])<.99?1:0,A=0;k=g[1]*A-g[2]*w,ee=g[2]*C-g[0]*A,Q=g[0]*w-g[1]*C,q=Math.hypot(k,ee,Q)||1}let ae=[k/q,ee/q,Q/q],O=[a[0]+g[0]*(T*p)+ae[0]*(T*m),a[1]+g[1]*(T*p)+ae[1]*(T*m),a[2]+g[2]*(T*p)+ae[2]*(T*m)],te=[a[0]+g[0]*v,a[1]+g[1]*v,a[2]+g[2]*v],ue=te[0]-O[0],le=te[1]-O[1],he=te[2]-O[2],ve=Math.hypot(ue,le,he),Me=ve>1e-6?[ue/ve,le/ve,he/ve]:g,pe=[O[0]+Me[0]*_,O[1]+Me[1]*_,O[2]+Me[2]*_],xe=[(O[0]-a[0])/T,(O[1]-a[1])/T,(O[2]-a[2])/T];return{rootPos:[a[0],a[1],a[2]],midPos:O,effectorPos:pe,rootRotation:r(S,xe),midRotation:r(U,Me)}}function o(a,c,u=8,f=.001){let h=a.length;if(h<2)return{positions:a.map(R=>[R[0],R[1],R[2]]),rotations:[],iterations:0};let d=a.map(R=>[R[0],R[1],R[2]]),y=[],x=[],T=0;for(let R=0;R<h-1;R++){let g=d[R+1][0]-d[R][0],M=d[R+1][1]-d[R][1],P=d[R+1][2]-d[R][2],v=Math.hypot(g,M,P);y.push(v),T+=v,x.push(v>1e-6?[g/v,M/v,P/v]:[0,1,0])}let D=[d[0][0],d[0][1],d[0][2]],V=Math.round(n(u,1,32,8)),b=n(f,1e-5,.1,.001),_=c[0]-D[0],S=c[1]-D[1],U=c[2]-D[2],z=Math.hypot(_,S,U),I=0;if(z>=T&&T>1e-6){let R=z>1e-6?[_/z,S/z,U/z]:x[0];d[0]=[D[0],D[1],D[2]];for(let g=0;g<h-1;g++){let M=y[g];d[g+1]=[d[g][0]+R[0]*M,d[g][1]+R[1]*M,d[g][2]+R[2]*M]}I=1}else for(let R=1;R<=V;R++){let g=d[h-1];if(Math.hypot(g[0]-c[0],g[1]-c[1],g[2]-c[2])<=b)break;I=R;let P=(v,p,m,L,W)=>{let G=p[0]-v[0],K=p[1]-v[1],k=p[2]-v[2],ee=Math.hypot(G,K,k);if(ee>1e-6){let Q=m/ee;return[v[0]+G*Q,v[1]+K*Q,v[2]+k*Q]}return[v[0]+L[0]*m*W,v[1]+L[1]*m*W,v[2]+L[2]*m*W]};d[h-1]=[c[0],c[1],c[2]];for(let v=h-2;v>=0;v--)d[v]=P(d[v+1],d[v],y[v],x[v],-1);d[0]=[D[0],D[1],D[2]];for(let v=0;v<h-1;v++)d[v+1]=P(d[v],d[v+1],y[v],x[v],1)}let E=[];for(let R=0;R<h-1;R++){let g=d[R+1][0]-d[R][0],M=d[R+1][1]-d[R][1],P=d[R+1][2]-d[R][2],v=Math.hypot(g,M,P),p=v>1e-6?[g/v,M/v,P/v]:x[R];E.push(r(x[R],p))}return{positions:d,rotations:E,iterations:I}}function s(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let c=a;if(c.enabled===!1)return null;let u=b=>{if(typeof b!="string")return;let _=b.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(_)?_:void 0},f=b=>Array.isArray(b)&&b.length===3&&b.every(_=>typeof _=="number"&&Number.isFinite(_))?[n(b[0],-1e3,1e3,0),n(b[1],-1e3,1e3,0),n(b[2],-1e3,1e3,0)]:void 0,h=u(c.root),d=u(c.effector);if(!h||!d)return null;let y=u(c.mid),x=f(c.target)??u(c.target);if(!x)return null;let T=c.pole??c.poleTarget,D=f(T)??u(T),V=c.solver==="fabrik"?"fabrik":c.solver==="two-bone"||y?"two-bone":"fabrik";return{root:h,...y?{mid:y}:{},effector:d,target:x,...D?{pole:D}:{},solver:V,iterations:Math.round(n(c.iterations,1,32,8)),tolerance:n(c.tolerance,1e-5,.1,.001),weight:n(c.weight,0,1,1)}}let l=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:s});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=l),{clampNum:n,parseIKTrait:s,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:l}}var Lt=Zn(),ys=Lt.clampNum,gs=Lt.parseIKTrait,xs=Lt.quatFromUnitVectors,vs=Lt.solveTwoBoneIK,ws=Lt.solveFABRIK,Ts=Lt.IKSolver;var Fi={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Qn(t,e,n,r){if(!n||n.bufferView===void 0)return null;let i=t.bufferViews?.[n.bufferView];if(!i)return null;let o=Number(n.count??0);if(!Number.isInteger(o)||o<=0)return null;let s=n.componentType??5126,l=Fi[s];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${s}`);let a=l*r,c=i.byteStride&&i.byteStride>0?i.byteStride:a,u=(i.byteOffset||0)+(n.byteOffset||0);if(!Number.isInteger(u)||u<0||c<a||u+(o-1)*c+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(s===5126&&c===a&&u%4===0)return new Float32Array(e,u,o*r);let f=new DataView(e),h=n.normalized===!0,d=new Float32Array(o*r);for(let y=0;y<o;y++){let x=u+y*c;for(let T=0;T<r;T++){let D=x+T*l,V;switch(s){case 5126:V=f.getFloat32(D,!0);break;case 5120:V=f.getInt8(D),h&&(V=Math.max(V/127,-1));break;case 5121:V=f.getUint8(D),h&&(V/=255);break;case 5122:V=f.getInt16(D,!0),h&&(V=Math.max(V/32767,-1));break;case 5123:V=f.getUint16(D,!0),h&&(V/=65535);break;default:V=f.getUint32(D,!0),h&&(V/=4294967295)}d[y*r+T]=V}}return d}function Br(t,e){let n=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),o=Number(e.scale?.[1]??1),s=Number(e.rotation??0)||0,l=Math.cos(s),a=Math.sin(s),c=(Number.isFinite(i)?i:1)*l,u=(Number.isFinite(i)?i:1)*a,f=-(Number.isFinite(o)?o:1)*a,h=(Number.isFinite(o)?o:1)*l;for(let d=0;d+1<t.length;d+=2){let y=t[d],x=t[d+1];t[d]=c*y+u*x+n,t[d+1]=f*y+h*x+r}}var Xr=["neutral","reinhard","none","aces","agx"];function tr(t){let e=String(t??"").trim().toLowerCase();return Xr.includes(e)?e:"neutral"}function zi(t){return Xr.indexOf(tr(t))}function Vi(t){return new TextDecoder().decode(t)}var jr=ke().decoders;function Bi(t,e){jr.set(t.toLowerCase(),e)}function Pt(t){return jr.get(t.toLowerCase())}function Wr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let h=n.getUint8(0);throw h===123||h===32||h===10||h===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),s=12,l=null,a=null;for(;s+8<=o&&s+8<=e.byteLength;){let h=n.getUint32(s,!0),d=n.getUint32(s+4,!0),y=s+8;if(y+h>e.byteLength)throw new Error(`Truncated GLB chunk: required ${y+h} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let x=new Uint8Array(e,y,h),T=Vi(x);l=JSON.parse(T,(D,V)=>D==="__proto__"||D==="constructor"||D==="prototype"?void 0:V)}else d===5130562&&(a=e.slice(y,y+h));s=y+h}if(!l)throw new Error("Missing JSON chunk in GLB");let c=l.extensionsRequired||[];if(c.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 h of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(h)&&!Pt("meshopt"))throw new Error(`Model requires ${h}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!Pt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),f={gltf:l,bin:u,animations:[]};for(let h of Oe)h.onParseGLB?.(f);return f}function Gi(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 Gt(t){if(Gi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return Wr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Yr=`#version 300 es
|
|
19
|
-
layout(location=0) in vec3
|
|
17
|
+
"use strict";var ThreeEngine=(()=>{var Kn=Object.defineProperty;var Di=Object.getOwnPropertyDescriptor;var Li=Object.getOwnPropertyNames;var Pi=Object.prototype.hasOwnProperty;var Ni=(t,e)=>{for(var n in e)Kn(t,n,{get:e[n],enumerable:!0})},Ui=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Li(e))!Pi.call(t,i)&&i!==n&&Kn(t,i,{get:()=>e[i],enumerable:!(r=Di(e,i))||r.enumerable});return t};var Oi=t=>Ui(Kn({},"__esModule",{value:!0}),t);var ls={};Ni(ls,{AmbientLight:()=>Jt,BoxGeometry:()=>Kt,BufferAttribute:()=>Be,BufferGeometry:()=>Ye,Camera:()=>tn,CapsuleGeometry:()=>$n,CircleGeometry:()=>jn,Clock:()=>Fn,Color:()=>Ze,ConeGeometry:()=>_n,CylinderGeometry:()=>pt,DirectionalLight:()=>Un,DodecahedronGeometry:()=>Gn,Euler:()=>Wt,Float32BufferAttribute:()=>wn,Group:()=>Nn,HemisphereLight:()=>rn,IcosahedronGeometry:()=>Vn,InstancedMesh:()=>Ft,Light:()=>yt,MAX_INSTANCES_PER_MESH:()=>Qt,Material:()=>Ke,MathUtils:()=>gi,Matrix3:()=>Mn,Matrix4:()=>it,Mesh:()=>Mt,MeshBasicMaterial:()=>kn,MeshLambertMaterial:()=>Dn,MeshPhongMaterial:()=>Ln,MeshPhysicalMaterial:()=>Pn,MeshStandardMaterial:()=>bt,Object3D:()=>Xe,OctahedronGeometry:()=>Bn,PerspectiveCamera:()=>zt,PlaneGeometry:()=>En,PointLight:()=>en,PolyhedronFallbackGeometry:()=>St,Quaternion:()=>Yt,RawShaderMaterial:()=>_i,RectAreaLight:()=>Ri,RingGeometry:()=>Xn,Scene:()=>wt,SceneQuotaValidator:()=>tt,ShaderMaterial:()=>nn,SphereGeometry:()=>qt,SpotLight:()=>Wn,THREE:()=>ot,TetrahedronGeometry:()=>Hn,Texture:()=>Zt,TextureLoader:()=>In,TorusGeometry:()=>Rn,TorusKnotGeometry:()=>Cn,Uint16BufferAttribute:()=>Sn,Uint32BufferAttribute:()=>An,Vector2:()=>vn,Vector3:()=>Le,Vector4:()=>Tn,WebGLRenderer:()=>On,authorScriptRunner:()=>Ei,buildSandboxWorkerSource:()=>gr,clearAuthorWarnings:()=>Tr,default:()=>us,exportSceneToCanvas3D:()=>pr,exportSceneToGLB:()=>br,exportSceneToUSDZ:()=>xi,generateUSDZ:()=>or,getAllowClientScripts:()=>Mi,getAuthorWarnings:()=>vr,getSandboxEngineSrc:()=>yr,getSandboxIframeSrc:()=>Ti,glbToUSDZ:()=>dn,isAllowedSandboxEngineUrl:()=>gt,noopProxy:()=>Ot,sceneToCanvas3D:()=>Pt,sceneToGLB:()=>Ht,sceneToUSDZ:()=>Nt,setAllowClientScripts:()=>Jo,setSandboxEngineSrc:()=>Ko,setSandboxIframeSrc:()=>Zo,threeAuthorPlugin:()=>jt,threeMicroPlugin:()=>cs,toTrustedWorkerScriptURL:()=>vi,validateSandboxWorkerMessage:()=>xr,warnUnsupported:()=>je});function on(t,e,n){let r=[],i=new Map,o=[],s=[],l=[],a=new Map,c=p=>{let E=i.get(p);return E===void 0&&(E=r.length,r.push({op:p}),i.set(p,E)),E},u=p=>{let E=a.get(p);return E===void 0&&(E=l.length,l.push({id:p}),a.set(p,E)),E},m=(p,E={})=>o.push({declaration:c(p),...E})-1,f=(p,E,_)=>s.push({id:p,type:E,value:_})-1,d=p=>({node:p,socket:"value"}),g=n?.interactivity??n?.gltfExtensions?.KHR_interactivity;if(g&&typeof g=="object"){let p=Array.isArray(g.graphs)?g.graphs[g.graph??0]:g;if(p&&Array.isArray(p.nodes)){let E=Array.isArray(p.declarations)?p.declarations:[];for(let _ of E)_?.op&&c(_.op);Array.isArray(p.variables)&&s.push(...p.variables);for(let _ of p.events||[])_?.id&&u(_.id);for(let _ of p.nodes){if(!_||typeof _!="object")continue;let P=_.op||(typeof _.declaration=="number"?E[_.declaration]?.op:"");o.push(P?{..._,declaration:c(P)}:{..._})}}}let y=(p,E,_="translation")=>_==="baseColorFactor"||_==="metallicFactor"||_==="roughnessFactor"?`/materials/${Math.max(0,E)}/pbrMetallicRoughness/${_}`:_==="emissiveFactor"||_==="alphaCutoff"?`/materials/${Math.max(0,E)}/${_}`:_==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${_}`,M=new Map;t.forEach((p,E)=>{typeof p?.name=="string"&&!M.has(p.name)&&M.set(p.name,E)});let L=(p,E)=>typeof p.target=="string"&&M.has(p.target)?M.get(p.target):typeof p.targetNode=="number"?p.targetNode:E,G=p=>{let E=t[p];return(typeof E?.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<t.length;p++){let E=t[p],_=E?.extras?.interactivity;if(!_||typeof _!="object")continue;let P=(typeof E.mesh=="number"?e[E.mesh]?.primitives?.[0]?.material:0)??0,z=C=>{let I=Array.isArray(C)?C:[C],b=[];for(let N=0;N<I.length;N++){let v=I[N];if(!v||typeof v!="object")continue;let D=v.action||"interpolate",h=typeof v.duration=="number"?v.duration:.35;if(D==="toggleTransform"){let A=v.property==="rotation"||v.property==="scale"?v.property:"translation",$=A==="rotation"?E.rotation||[0,0,0,1]:A==="scale"?E.scale||[1,1,1]:E.translation||[0,0,0],V=`/nodes/${p}/${A}`,K=f(`__toggle_${p}_${N}`,"bool",!1),k=m("variable/get",{configuration:{variable:K}}),ee=m("math/not",{values:{a:d(k)}}),Q=m("variable/set",{configuration:{variable:K},values:{value:d(ee)}}),q=m("pointer/interpolate",{configuration:{pointer:V},values:{value:{value:Array.isArray(v.to)?v.to:$},duration:{value:h}}}),ae=m("pointer/interpolate",{configuration:{pointer:V},values:{value:{value:Array.isArray(v.from)?v.from:$},duration:{value:h}}});o[Q].flows={out:{node:m("flow/branch",{values:{condition:d(k)},flows:{true:{node:q},false:{node:ae}}})}},b.push(Q)}else if(D==="interpolate"){let A=v.to??v.value;if(A===void 0)continue;let $={value:{value:A},duration:{value:h}};v.from!==void 0&&($.from={value:v.from}),b.push(m("pointer/interpolate",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:y(L(v,p),G(L(v,p)),v.property)},values:$}))}else if(D==="setProperty"){if(v.value===void 0)continue;b.push(m("pointer/set",{configuration:{pointer:typeof v.pointer=="string"?v.pointer:y(L(v,p),G(L(v,p)),v.property)},values:{value:{value:v.value}}}))}else if(D==="toggleVisibility"){let A=L(v,p),$=f(`__vis_${A}_${N}`,"bool",!0),V=m("variable/get",{configuration:{variable:$}}),K=m("math/not",{values:{a:d(V)}}),k=m("variable/set",{configuration:{variable:$},values:{value:d(K)}});o[k].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${A}/extensions/KHR_node_visibility/visible`},values:{value:d(V)}})}},b.push(k)}else if(D==="cycleMaterialColor"&&Array.isArray(v.colors)&&v.colors.length>0){let A=typeof v.duration=="number"?v.duration:.25,$=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,V=f(`__color_idx_${p}_${N}`,"int",0),K=m("variable/get",{configuration:{variable:V}}),k=m("math/add",{values:{a:d(K),b:{value:1}}}),ee=m("math/rem",{values:{a:d(k),b:{value:v.colors.length}}}),Q=m("variable/set",{configuration:{variable:V},values:{value:d(ee)}}),q={};for(let ae=0;ae<v.colors.length;ae++){let F=v.colors[ae],te=Array.isArray(F)&&F.length>=3?[F[0],F[1],F[2],F[3]??1]:[1,1,1,1];q[String(ae)]={node:A>0?m("pointer/interpolate",{configuration:{pointer:$},values:{value:{value:te},duration:{value:A}}}):m("pointer/set",{configuration:{pointer:$},values:{value:{value:te}}})}}o[Q].flows={out:{node:m("flow/switch",{values:{selection:d(K)},flows:q})}},b.push(Q)}else if(D==="playAnimation")b.push(m("animation/start",{configuration:{animation:v.animation??v.clip??0}}));else if(D==="stopAnimation")b.push(m("animation/stop"));else if(D==="sendEvent"){let A={};for(let[$,V]of Object.entries(v.values||{}))A[$]={value:V};b.push(m("event/send",{configuration:{event:u(String(v.event??v.id??"custom"))},values:A}))}}if(!b.length)return null;if(b.length===1)return b[0];let T={};return b.forEach((N,v)=>{T[String(v)]={node:N}}),m("flow/sequence",{flows:T})},R=(C,I,b)=>{let T=z(I);T!==null&&m(C,{...b?{configuration:b}:{},flows:{out:{node:T}}})};if(_.onSelect&&R("pointer/onSelect",_.onSelect,{nodeIndex:p}),_.onHoverIn&&R("pointer/onHoverIn",_.onHoverIn,{nodeIndex:p}),_.onHoverOut&&R("pointer/onHoverOut",_.onHoverOut,{nodeIndex:p}),_.onStart&&R("event/onStart",_.onStart),_.onReceive&&typeof _.onReceive=="object")for(let[C,I]of Object.entries(_.onReceive))R("event/receive",I,{event:u(C)})}return o.length?{graphs:[{declarations:r,nodes:o,variables:s,events:l}],graph:0}:null}var Pr='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).',Nr="Security Error: client-side scripts require allow-client-scripts opt-in.";var sn="__THREE_LIVE_REGISTRY__";function Ie(){let t=typeof globalThis<"u"?globalThis:{};if(!t[sn]){let e={plugins:[],decoders:new Map};try{Object.defineProperty(t,sn,{value:e,writable:!1,configurable:!1,enumerable:!1})}catch{t[sn]=e}}return t[sn]}var Ue=Ie().plugins;function Ur(t){let e=Ie().plugins;e.some(n=>n.name===t.name)||e.push(t),t.onRegister?.()}function Or(){return Ie().plugins}function Fr(t,e){if(!t||!t.BufferGeometry)return null;let n=t.Vector2,r=t.Vector3,i=t.Quaternion,o=t.Matrix4,s=t.Matrix3,l=t.Color,a=t.BufferAttribute,c=t.BufferGeometry,u=t.Material,m=t.MeshStandardMaterial,f=t.Mesh,d=8192,g=2048,y=128,M=4096,L=(S,x)=>{let w=S==null?NaN:Number(S);return Number.isFinite(w)?w:x};class G{constructor(x){this.currentPoint=new n(0,0),this.segments=[],Array.isArray(x)&&x.length>0&&this.fromPoints(x)}fromPoints(x){if(!x.length)return this;this.moveTo(x[0].x,x[0].y);for(let w=1;w<x.length;w++)this.lineTo(x[w].x,x[w].y);return this}moveTo(x,w){let U=Number(x)||0,O=Number(w)||0;return this.currentPoint.set(U,O),this.segments.push({type:"move",pts:[U,O]}),this}lineTo(x,w){let U=Number(x)||0,O=Number(w)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(U,O),this.segments.push({type:"line",pts:[U,O]}),this}quadraticCurveTo(x,w,U,O){let H=this.currentPoint.x,X=this.currentPoint.y,j=Number(x)||0,Y=Number(w)||0,B=Number(U)||0,J=Number(O)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[H,X]}),this.currentPoint.set(B,J),this.segments.push({type:"quad",pts:[H,X,j,Y,B,J]}),this}bezierCurveTo(x,w,U,O,H,X){let j=this.currentPoint.x,Y=this.currentPoint.y,B=Number(x)||0,J=Number(w)||0,Z=Number(U)||0,W=Number(O)||0,re=Number(H)||0,oe=Number(X)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[j,Y]}),this.currentPoint.set(re,oe),this.segments.push({type:"cubic",pts:[j,Y,B,J,Z,W,re,oe]}),this}absarc(x,w,U,O,H,X=!1){return this.absellipse(x,w,U,U,O,H,X,0)}arc(x,w,U,O,H,X=!1){return this.absarc(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(w)||0),U,O,H,X)}absellipse(x,w,U,O,H,X,j=!1,Y=0){let B=Number(x)||0,J=Number(w)||0,Z=Math.max(0,Number(U)||0),W=Math.max(0,Number(O)||0),re=Number(H)||0,oe=Number(X)||0,ce=j?1:0,se=Number(Y)||0;this.segments.push({type:"arc",pts:[B,J,Z,W,re,oe,ce,se]});let ne=Math.cos(se),fe=Math.sin(se),ye=Z*Math.cos(oe),me=W*Math.sin(oe);return this.currentPoint.set(B+ye*ne-me*fe,J+ye*fe+me*ne),this}ellipse(x,w,U,O,H,X,j=!1,Y=0){return this.absellipse(this.currentPoint.x+(Number(x)||0),this.currentPoint.y+(Number(w)||0),U,O,H,X,j,Y)}closePath(){if(this.segments.length>0){let x=this.segments[0],w=0,U=0;if(x.type==="arc"){let O=x.pts[0],H=x.pts[1],X=x.pts[2],j=x.pts[3],Y=x.pts[4],B=x.pts[7],J=Math.cos(B),Z=Math.sin(B),W=X*Math.cos(Y),re=j*Math.sin(Y);w=O+W*J-re*Z,U=H+W*Z+re*J}else w=x.pts[0],U=x.pts[1];Math.hypot(this.currentPoint.x-w,this.currentPoint.y-U)>1e-6&&this.lineTo(w,U)}return this}getPoints(x=12){let w=Math.max(1,Math.min(128,Math.floor(Number(x)||12))),U=[],O=(H,X)=>{if(U.length>0){let j=U[U.length-1];if(Math.hypot(j.x-H,j.y-X)<1e-6)return}U.push(new n(H,X))};for(let H of this.segments){let X=H.pts;if(H.type==="move"||H.type==="line")O(X[0],X[1]);else if(H.type==="quad"){let j=X[0],Y=X[1],B=X[2],J=X[3],Z=X[4],W=X[5];O(j,Y);for(let re=1;re<=w;re++){let oe=re/w,ce=1-oe;O(ce*ce*j+2*ce*oe*B+oe*oe*Z,ce*ce*Y+2*ce*oe*J+oe*oe*W)}}else if(H.type==="cubic"){let j=X[0],Y=X[1],B=X[2],J=X[3],Z=X[4],W=X[5],re=X[6],oe=X[7];O(j,Y);for(let ce=1;ce<=w;ce++){let se=ce/w,ne=1-se,fe=ne*ne,ye=se*se;O(fe*ne*j+3*fe*se*B+3*ne*ye*Z+ye*se*re,fe*ne*Y+3*fe*se*J+3*ne*ye*W+ye*se*oe)}}else if(H.type==="arc"){let j=X[0],Y=X[1],B=X[2],J=X[3],Z=X[4],W=X[5],re=X[6]!==0,oe=X[7],ce=Math.PI*2,se=W-Z,ne=Math.abs(se)<1e-9;for(;se<0;)se+=ce;for(;se>ce;)se-=ce;se<1e-9&&(se=ne?0:ce),re&&!ne&&(se=se===ce?-ce:se-ce);let fe=Math.cos(oe),ye=Math.sin(oe),me=Math.max(2,w);for(let we=0;we<=me;we++){let ve=we/me,Se=Z+ve*se,_e=B*Math.cos(Se),Ce=J*Math.sin(Se);O(j+_e*fe-Ce*ye,Y+_e*ye+Ce*fe)}}}if(U.length>2){let H=U[0],X=U[U.length-1];Math.hypot(H.x-X.x,H.y-X.y)<1e-6&&U.pop()}return U}getSpacedPoints(x=12){return this.getPoints(x)}}class p extends G{constructor(x){super(x),this.holes=[]}extractPoints(x=12){return{shape:this.getPoints(x),holes:this.holes.map(w=>w.getPoints(x))}}}function E(S){let x=0,w=S.length;for(let U=0,O=w-1;U<w;O=U++)x+=S[O].x*S[U].y-S[U].x*S[O].y;return x*.5}function _(S,x,w,U,O,H,X,j){let Y=X-w,B=j-U,J=O-w,Z=H-U,W=S-w,re=x-U,oe=Y*Y+B*B,ce=Y*J+B*Z,se=Y*W+B*re,ne=J*J+Z*Z,fe=J*W+Z*re,ye=oe*ne-ce*ce;if(Math.abs(ye)<1e-12)return!1;let me=1/ye,we=(ne*se-ce*fe)*me,ve=(oe*fe-ce*se)*me;return we>=-1e-7&&ve>=-1e-7&&we+ve<=1+1e-7}function P(S,x){let w=S.slice();E(w)<0&&w.reverse();let U=w.map(Y=>new n(Y.x,Y.y)),O=w.map((Y,B)=>B),H=[];for(let Y of x){if(!Y||Y.length<3)continue;let B=Y.slice();E(B)>0&&B.reverse();let J=[],Z=-1/0,W=0;for(let re=0;re<B.length;re++){let oe=B[re],ce=U.length;U.push(new n(oe.x,oe.y)),J.push(ce),oe.x>Z&&(Z=oe.x,W=re)}H.push({pts:B,indices:J,maxX:Z,maxIdx:W})}H.sort((Y,B)=>B.maxX-Y.maxX);let X=(Y,B,J)=>(B.x-Y.x)*(J.y-Y.y)-(B.y-Y.y)*(J.x-Y.x),j=(Y,B,J)=>{for(let Z=0;Z<J.length;Z++){let W=J[Z],re=J[(Z+1)%J.length];if(X(Y,B,W)*X(Y,B,re)<0&&X(W,re,Y)*X(W,re,B)<0)return!0}return!1};for(let Y of H){let B=Y.pts[Y.maxIdx],J=B.x,Z=O.length,W=O.map(ne=>U[ne]),re=ne=>Math.hypot(W[ne].x-J,W[ne].y-B.y),oe=W.map((ne,fe)=>fe).sort((ne,fe)=>+(W[ne].x<J)-+(W[fe].x<J)||re(ne)-re(fe)),ce=oe[0];for(let ne of oe){let fe=W[ne],ye=W[(ne+Z-1)%Z],me=W[(ne+1)%Z],we=X(fe,me,B)>=0,ve=X(ye,fe,B)>=0;if((X(ye,fe,me)>=0?we&&ve:we||ve)&&!j(B,fe,W)&&!H.some(_e=>j(B,fe,_e.pts))){ce=ne;break}}let se=[];for(let ne=0;ne<=ce;ne++)se.push(O[ne]);for(let ne=0;ne<=Y.indices.length;ne++){let fe=Y.indices[(Y.maxIdx+ne)%Y.indices.length];se.push(fe)}for(let ne=ce;ne<O.length;ne++)se.push(O[ne]);O=se}return{merged:O.map(Y=>U[Y]),mergedIndices:O,allVertices:U}}function z(S,x){let w=[],U=S.slice();if(U.length<3)return w;let O=U.length*U.length+64,H=0;for(;U.length>2&&O-- >0;){let X=U.length,j=U[(H+X-1)%X],Y=U[H%X],B=U[(H+1)%X],J=x[j],Z=x[Y],W=x[B];if((Z.x-J.x)*(W.y-J.y)-(Z.y-J.y)*(W.x-J.x)>1e-9){let oe=!0;for(let ce=0;ce<X;ce++){let se=U[ce];if(se===j||se===Y||se===B)continue;let ne=x[se];if(_(ne.x,ne.y,J.x,J.y,Z.x,Z.y,W.x,W.y)&&Math.hypot(ne.x-J.x,ne.y-J.y)>=1e-6&&Math.hypot(ne.x-Z.x,ne.y-Z.y)>=1e-6&&Math.hypot(ne.x-W.x,ne.y-W.y)>=1e-6){oe=!1;break}}if(oe){w.push([j,Y,B]),U.splice(H%X,1),H=Math.max(0,H%X-1);continue}}H++,H>=X*2&&(w.push([j,Y,B]),U.splice((H-1)%X,1),H=0)}return w}function R(S,x){let w=S instanceof p?S.extractPoints(x):{shape:S.getPoints(x),holes:[]},U=w.shape.length;for(let O of w.holes)U+=O.length;if(U>M)throw new RangeError(`SecurityError: shape point count (${U}) exceeds MAX_SHAPE_POINTS (${M})`);return w}class C extends c{constructor(x=new p,w=12){super();let U=Array.isArray(x)?x:[x],O=[],H=[],X=[],j=[];for(let Y of U){if(!(Y instanceof G))continue;let B=R(Y,w);if(B.shape.length<3)continue;let{mergedIndices:J,allVertices:Z}=P(B.shape,B.holes),W=z(J,Z),re=O.length/3,oe=1/0,ce=1/0,se=-1/0,ne=-1/0;for(let me of Z)me.x<oe&&(oe=me.x),me.y<ce&&(ce=me.y),me.x>se&&(se=me.x),me.y>ne&&(ne=me.y);let fe=Math.max(1e-6,se-oe),ye=Math.max(1e-6,ne-ce);for(let me of Z)O.push(me.x,me.y,0),H.push(0,0,1),X.push((me.x-oe)/fe,(me.y-ce)/ye);for(let[me,we,ve]of W)j.push(re+me,re+we,re+ve)}I(this,O,H,X,j)}}function I(S,x,w,U,O){return S.setAttribute("position",new a(x,3)),S.setAttribute("normal",new a(w,3)),S.setAttribute("uv",new a(U,2)),S.setIndex(O),S}function b(S){let x=S.length,w=[];for(let U=0;U<x;U++){let O=S[(U+x-1)%x],H=S[U],X=S[(U+1)%x],j=H.x-O.x,Y=H.y-O.y,B=Math.hypot(j,Y)||1;j/=B,Y/=B;let J=X.x-H.x,Z=X.y-H.y,W=Math.hypot(J,Z)||1;J/=W,Z/=W;let re=Y,oe=-j,ce=Z,se=-J,ne=re+ce,fe=oe+se,ye=Math.hypot(ne,fe);if(ye>1e-6){ne/=ye,fe/=ye;let me=Math.max(.35,ne*re+fe*oe);w.push(new n(ne/me,fe/me))}else w.push(new n(re,oe))}return w}class T extends c{constructor(x=new p,w={}){super();let U=Array.isArray(x)?x:[x],O=Math.max(1,Math.min(64,Math.floor(L(w.curveSegments,12)))),H=L(w.depth??w.amount,1),X=Math.max(1,Math.min(32,Math.floor(L(w.steps,1)))),j=!!(w.bevelEnabled??!1),Y=j?Math.max(0,L(w.bevelThickness,.06)):0,B=j?Math.max(0,L(w.bevelSize,Y*.8)):0,J=j?L(w.bevelOffset,0):0,Z=j?Math.max(1,Math.min(8,Math.floor(L(w.bevelSegments,2)))):0,W=[],re=[],oe=[],ce=[];for(let se of U){if(!(se instanceof G))continue;let ne=R(se,O);if(ne.shape.length<3)continue;let fe=ne.shape.slice();E(fe)<0&&fe.reverse();let ye=[];for(let be of ne.holes){if(be.length<3)continue;let Ae=be.slice();E(Ae)>0&&Ae.reverse(),ye.push(Ae)}let{mergedIndices:me,allVertices:we}=P(fe,ye),ve=z(me,we),Se=[fe,...ye],_e=[];for(let be of Se){let Ae=b(be);for(let Re of Ae)_e.push(Re)}let Ce=1/0,Fe=1/0,Oe=-1/0,We=-1/0;for(let be of we)be.x<Ce&&(Ce=be.x),be.y<Fe&&(Fe=be.y),be.x>Oe&&(Oe=be.x),be.y>We&&(We=be.y);let ze=Math.max(1e-6,Oe-Ce),Qe=Math.max(1e-6,We-Fe),At=-Y,Et=H+Y,st=W.length/3;for(let be=0;be<we.length;be++){let Ae=we[be],Re=_e[be]??new n(0,0),Pe=Ae.x+Re.x*J,Ne=Ae.y+Re.y*J;W.push(Pe,Ne,At),re.push(0,0,-1),oe.push((Pe-Ce)/ze,(Ne-Fe)/Qe)}for(let[be,Ae,Re]of ve)ce.push(st+be,st+Re,st+Ae);let at=W.length/3;for(let be=0;be<we.length;be++){let Ae=we[be],Re=_e[be]??new n(0,0),Pe=Ae.x+Re.x*J,Ne=Ae.y+Re.y*J;W.push(Pe,Ne,Et),re.push(0,0,1),oe.push((Pe-Ce)/ze,(Ne-Fe)/Qe)}for(let[be,Ae,Re]of ve)ce.push(at+be,at+Ae,at+Re);let Ge=[];if(j&&Z>0)for(let be=0;be<Z;be++){let Re=be/Z*Math.PI/2;Ge.push({z:-Y*Math.cos(Re),expand:J+B*Math.sin(Re)})}for(let be=0;be<=X;be++){let Ae=be/X;Ge.push({z:Ae*H,expand:J+B})}if(j&&Z>0)for(let be=1;be<=Z;be++){let Re=be/Z*Math.PI/2;Ge.push({z:H+Y*Math.sin(Re),expand:J+B*Math.cos(Re)})}let Je=0;for(let be of Se){let Ae=be.length;for(let Re=0;Re<Ge.length-1;Re++){let Pe=Ge[Re],Ne=Ge[Re+1];for(let He=0;He<Ae;He++){let nt=(He+1)%Ae,ct=be[He],ut=be[nt],lt=_e[Je+He],ht=_e[Je+nt],ft=ct.x+lt.x*Pe.expand,mt=ct.y+lt.y*Pe.expand,xt=ut.x+ht.x*Pe.expand,rt=ut.y+ht.y*Pe.expand,Ii=ut.x+ht.x*Ne.expand,ki=ut.y+ht.y*Ne.expand,Mr=ct.x+lt.x*Ne.expand,wr=ct.y+lt.y*Ne.expand,Sr=xt-ft,Ar=rt-mt,Er=0,_r=Mr-ft,Rr=wr-mt,Cr=Ne.z-Pe.z,_t=Ar*Cr-Er*Rr,Rt=Er*_r-Sr*Cr,Ct=Sr*Rr-Ar*_r,Yn=Math.hypot(_t,Rt,Ct)||1;_t/=Yn,Rt/=Yn,Ct/=Yn;let It=W.length/3;W.push(ft,mt,Pe.z,xt,rt,Pe.z,Ii,ki,Ne.z,Mr,wr,Ne.z),re.push(_t,Rt,Ct,_t,Rt,Ct,_t,Rt,Ct,_t,Rt,Ct);let Ir=He/Ae,kr=(He+1)/Ae,Dr=Re/(Ge.length-1),Lr=(Re+1)/(Ge.length-1);oe.push(Ir,Dr,kr,Dr,kr,Lr,Ir,Lr),ce.push(It,It+1,It+2,It,It+2,It+3)}}Je+=Ae}}I(this,W,re,oe,ce)}}function N(S){return{x:S.x,y:S.y,z:S.z,nx:S.nx,ny:S.ny,nz:S.nz,u:S.u,v:S.v}}function v(S){return{x:S.x,y:S.y,z:S.z,nx:-S.nx,ny:-S.ny,nz:-S.nz,u:S.u,v:S.v}}function D(S,x,w){let U=S.nx+(x.nx-S.nx)*w,O=S.ny+(x.ny-S.ny)*w,H=S.nz+(x.nz-S.nz)*w,X=Math.hypot(U,O,H)||1;return{x:S.x+(x.x-S.x)*w,y:S.y+(x.y-S.y)*w,z:S.z+(x.z-S.z)*w,nx:U/X,ny:O/X,nz:H/X,u:S.u+(x.u-S.u)*w,v:S.v+(x.v-S.v)*w}}function h(S){if(S.length<3)return null;let x=S[0],w=S[1],U=S[2],O=w.x-x.x,H=w.y-x.y,X=w.z-x.z,j=U.x-x.x,Y=U.y-x.y,B=U.z-x.z,J=H*B-X*Y,Z=X*j-O*B,W=O*Y-H*j,re=Math.hypot(J,Z,W);if(re<1e-9)return null;J/=re,Z/=re,W/=re;let oe=J*x.x+Z*x.y+W*x.z;return{vertices:S,nx:J,ny:Z,nz:W,w:oe}}function A(S){S.vertices.reverse();for(let x=0;x<S.vertices.length;x++)S.vertices[x]=v(S.vertices[x]);S.nx=-S.nx,S.ny=-S.ny,S.nz=-S.nz,S.w=-S.w}let $=1e-5,V=0,K=1,k=2,ee=3;function Q(S,x,w,U,O,H,X,j,Y){let B=0,J=[];for(let Z=0;Z<O.vertices.length;Z++){let W=O.vertices[Z],re=S*W.x+x*W.y+w*W.z-U,oe=re<-$?k:re>$?K:V;B|=oe,J.push(oe)}switch(B){case V:{S*O.nx+x*O.ny+w*O.nz>0?H.push(O):X.push(O);break}case K:j.push(O);break;case k:Y.push(O);break;case ee:{let Z=[],W=[],re=O.vertices.length;for(let fe=0;fe<re;fe++){let ye=(fe+1)%re,me=J[fe],we=J[ye],ve=O.vertices[fe],Se=O.vertices[ye];if(me!==k&&Z.push(ve),me!==K&&W.push(me!==k?N(ve):ve),(me|we)===ee){let _e=Se.x-ve.x,Ce=Se.y-ve.y,Fe=Se.z-ve.z,Oe=S*_e+x*Ce+w*Fe,We=Math.abs(Oe)>1e-12?(U-(S*ve.x+x*ve.y+w*ve.z))/Oe:.5,ze=D(ve,Se,Math.max(0,Math.min(1,We)));Z.push(ze),W.push(N(ze))}}let{nx:oe,ny:ce,nz:se,w:ne}=O;Z.length>=3&&j.push({vertices:Z,nx:oe,ny:ce,nz:se,w:ne}),W.length>=3&&Y.push({vertices:W,nx:oe,ny:ce,nz:se,w:ne});break}default:break}}class q{constructor(x,w=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,x&&x.length>0&&this.build(x,w)}invert(){for(let w=0;w<this.polygons.length;w++)A(this.polygons[w]);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 x=this.front;this.front=this.back,this.back=x}clipPolygons(x,w=0){if(!this.hasPlane||x.length===0)return x.slice();if(w>=g)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${g})`);let U=[],O=[];for(let H=0;H<x.length;H++)Q(this.nx,this.ny,this.nz,this.w,x[H],U,O,U,O);return this.front&&U.length>0&&(U=this.front.clipPolygons(U,w+1)),this.back?O=O.length>0?this.back.clipPolygons(O,w+1):[]:O=[],U.concat(O)}clipTo(x,w=0){this.polygons.length>0&&(this.polygons=x.clipPolygons(this.polygons,0)),w<g&&(this.front&&this.front.clipTo(x,w+1),this.back&&this.back.clipTo(x,w+1))}allPolygons(x=[]){for(let w=0;w<this.polygons.length;w++)x.push(this.polygons[w]);return this.front&&this.front.allPolygons(x),this.back&&this.back.allPolygons(x),x}build(x,w=0){if(!x.length)return;if(!this.hasPlane){let H=x[x.length>>1];this.nx=H.nx,this.ny=H.ny,this.nz=H.nz,this.w=H.w,this.hasPlane=!0}if(w>=g)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${g})`);let U=[],O=[];for(let H=0;H<x.length;H++)Q(this.nx,this.ny,this.nz,this.w,x[H],this.polygons,this.polygons,U,O);U.length>0&&(this.front||(this.front=new q),this.front.build(U,w+1)),O.length>0&&(this.back||(this.back=new q),this.back.build(O,w+1))}}function ae(S,x){if(!x&&S._csgPolygons)return S._csgPolygons;let w=S.attributes.position;if(!w||w.count===0)return[];let U=S.attributes.normal,O=S.attributes.uv,H=S.index?S.index.array:null,X=Math.floor(H?H.length/3:w.count/3);if(X>d)throw new RangeError(`SecurityError: CSG input triangle count (${X}) exceeds MAX_CSG_TRIANGLES (${d})`);let j=x?x.elements:null,Y=j?j[0]*(j[5]*j[10]-j[9]*j[6])-j[4]*(j[1]*j[10]-j[9]*j[2])+j[8]*(j[1]*j[6]-j[5]*j[2])<0:!1,B=j?new s().getNormalMatrix(x).elements:null,J=W=>{let re=w.getX(W),oe=w.getY(W),ce=w.getZ(W),se=U?U.getX(W):NaN,ne=U?U.getY(W):NaN,fe=U?U.getZ(W):NaN;if(j&&B){let we=j[0]*re+j[4]*oe+j[8]*ce+j[12],ve=j[1]*re+j[5]*oe+j[9]*ce+j[13],Se=j[2]*re+j[6]*oe+j[10]*ce+j[14];re=we,oe=ve,ce=Se;let _e=B[0]*se+B[3]*ne+B[6]*fe,Ce=B[1]*se+B[4]*ne+B[7]*fe,Fe=B[2]*se+B[5]*ne+B[8]*fe,Oe=Math.hypot(_e,Ce,Fe)||1;se=_e/Oe,ne=Ce/Oe,fe=Fe/Oe}let ye=O?O.getX(W):0,me=O?O.getY(W):0;return{x:re,y:oe,z:ce,nx:se,ny:ne,nz:fe,u:ye,v:me}},Z=[];for(let W=0;W<X;W++){let re=H?H[W*3]:W*3,oe=H?H[W*3+1]:W*3+1,ce=H?H[W*3+2]:W*3+2,se=h(Y?[J(re),J(ce),J(oe)]:[J(re),J(oe),J(ce)]);se&&Z.push(se)}return Z}function F(S){let x=[],w=[],U=[],O=[];for(let X of S){let j=X.vertices;if(j.length<3)continue;let Y=x.length/3;for(let B of j)x.push(B.x,B.y,B.z),Number.isFinite(B.nx)&&B.nx*B.nx+B.ny*B.ny+B.nz*B.nz>.5?w.push(B.nx,B.ny,B.nz):w.push(X.nx,X.ny,X.nz),U.push(B.u,B.v);for(let B=1;B<j.length-1;B++)O.push(Y,Y+B,Y+B+1)}let H=I(new c,x,w,U,O);return H._csgPolygons=S,H}function te(S,x,w){if(S.length+x.length>d)throw new RangeError(`SecurityError: Combined CSG triangle count (${S.length+x.length}) exceeds MAX_CSG_TRIANGLES (${d})`);if(S.length===0)return w==="union"?x:[];if(x.length===0)return w==="intersect"?[]:S;let U=1/0,O=1/0,H=1/0,X=-1/0,j=-1/0,Y=-1/0;for(let re=0;re<x.length;re++){let oe=x[re].vertices;for(let ce=0;ce<oe.length;ce++){let se=oe[ce];se.x<U&&(U=se.x),se.y<O&&(O=se.y),se.z<H&&(H=se.z),se.x>X&&(X=se.x),se.y>j&&(j=se.y),se.z>Y&&(Y=se.z)}}U-=1e-4,O-=1e-4,H-=1e-4,X+=1e-4,j+=1e-4,Y+=1e-4;let B=[],J=[];for(let re=0;re<S.length;re++){let oe=S[re],ce=oe.vertices,se=1/0,ne=1/0,fe=1/0,ye=-1/0,me=-1/0,we=-1/0;for(let ve=0;ve<ce.length;ve++){let Se=ce[ve];Se.x<se&&(se=Se.x),Se.y<ne&&(ne=Se.y),Se.z<fe&&(fe=Se.z),Se.x>ye&&(ye=Se.x),Se.y>me&&(me=Se.y),Se.z>we&&(we=Se.z)}ye<U||se>X||me<O||ne>j||we<H||fe>Y?J.push(oe):B.push(oe)}if(B.length===0)return w==="union"?S.concat(x):w==="subtract"?S:[];let Z=new q(B),W=new q(x);return w==="union"?(Z.clipTo(W),W.clipTo(Z),W.invert(),W.clipTo(Z),W.invert(),Z.build(W.allPolygons()),J.concat(Z.allPolygons())):w==="subtract"?(Z.invert(),Z.clipTo(W),W.clipTo(Z),W.invert(),W.clipTo(Z),W.invert(),Z.build(W.allPolygons()),Z.invert(),J.concat(Z.allPolygons())):(Z.invert(),W.clipTo(Z),W.invert(),Z.clipTo(W),W.clipTo(Z),Z.build(W.allPolygons()),Z.invert(),Z.allPolygons())}function ue(S,x,w,U=null,O=null){{let j=globalThis.__three_live_native_csg_boolean__;if(typeof j=="function"&&S?.attributes?.position?.array&&x?.attributes?.position?.array){let Y=w==="subtract"?0:w==="union"?1:2,B=j(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,U?U.elements:null,x.attributes.position.array,x.attributes.normal?x.attributes.normal.array:null,x.attributes.uv?x.attributes.uv.array:null,x.index?x.index.array:null,O?O.elements:null,Y);if(B)return I(new c,B.positions,B.normals,B.uvs,B.indices)}}let H=ae(S,U),X=ae(x,O);return F(te(H,X,w))}function le(S,x,w){let U=S instanceof f||!!S?.isMesh,O=x instanceof f||!!x?.isMesh,H=U?S.geometry:S,X=O?x.geometry:x,j=null;if(O)if(x.updateMatrix(),U){S.updateMatrix();let Z=new o().makeScale(1/(S.scale.x||1),1/(S.scale.y||1),1/(S.scale.z||1)),W=Math.hypot(S.quaternion.x,S.quaternion.y,S.quaternion.z,S.quaternion.w)||1,re=new o().compose(new r(0,0,0),new i(-S.quaternion.x/W,-S.quaternion.y/W,-S.quaternion.z/W,S.quaternion.w/W),new r(1,1,1)),oe=new o().makeTranslation(-S.position.x,-S.position.y,-S.position.z);j=Z.multiply(re).multiply(oe).multiply(x.matrix)}else j=x.matrix;let Y=ue(H,X,w,null,j),B=U?S.material:new m,J=new f(Y,B);return U&&(J.position.copy(S.position),J.quaternion.copy(S.quaternion),J.scale.copy(S.scale),J.name=S.name),J}let he={toGeometry:ue,subtract(S,x){return le(S,x,"subtract")},union(S,x){return le(S,x,"union")},intersect(S,x){return le(S,x,"intersect")}},xe={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 Me extends c{constructor(x="",w={}){super();let U=String(x??"").slice(0,y),O=Math.max(.005,Math.min(100,L(w.size,.2))),H=!!(w.bevelEnabled??!1),X=H?Math.max(0,Math.min(2,L(w.bevelThickness,O*.04))):0,j=H?Math.max(0,Math.min(2,L(w.bevelSize,O*.03))):0,Y=Math.max(.001,Math.min(20,L(w.depth??w.height,O*.2)))+X*2,B=O*.085+j,J=O*.68,Z=O*.82,W=[],re=[],oe=[],ce=[],se=(ye,me,we,ve,Se,_e,Ce)=>{let Fe=we-ye,Oe=ve-me,We=Math.hypot(Fe,Oe),ze=1,Qe=0;We>1e-6&&(ze=Fe/We,Qe=Oe/We);let At=-Qe*Se,Et=ze*Se,st=ze*Se*.6,at=Qe*Se*.6,Ge=ye-st+At,Je=me-at+Et,be=ye-st-At,Ae=me-at-Et,Re=we+st-At,Pe=ve+at-Et,Ne=we+st+At,He=ve+at+Et,nt=(ct,ut,lt,ht,ft,mt,xt)=>{let rt=W.length/3;W.push(ct[0],ct[1],ct[2],ut[0],ut[1],ut[2],lt[0],lt[1],lt[2],ht[0],ht[1],ht[2]),re.push(ft,mt,xt,ft,mt,xt,ft,mt,xt,ft,mt,xt),oe.push(0,0,1,0,1,1,0,1),ce.push(rt,rt+1,rt+2,rt,rt+2,rt+3)};nt([Ge,Je,Ce],[be,Ae,Ce],[Re,Pe,Ce],[Ne,He,Ce],0,0,1),nt([be,Ae,_e],[Ge,Je,_e],[Ne,He,_e],[Re,Pe,_e],0,0,-1),nt([Ge,Je,_e],[be,Ae,_e],[be,Ae,Ce],[Ge,Je,Ce],-ze,-Qe,0),nt([Re,Pe,_e],[Ne,He,_e],[Ne,He,Ce],[Re,Pe,Ce],ze,Qe,0),nt([be,Ae,_e],[Re,Pe,_e],[Re,Pe,Ce],[be,Ae,Ce],Qe,-ze,0),nt([Ne,He,_e],[Ge,Je,_e],[Ge,Je,Ce],[Ne,He,Ce],-Qe,ze,0)},ne=0,fe=0;for(let ye=0;ye<U.length;ye++){let me=U[ye];if(me===`
|
|
18
|
+
`){ne=0,fe-=O*1.35;continue}if(me===" "||me===" "){ne+=Z*(me===" "?.75:3);continue}if(me==="\r")continue;let we=me.toUpperCase(),ve=me!==we&&me>="a"&&me<="z",Se=xe[we]??xe["?"],_e=ve?O*.76:O,Ce=ve?J*.88:J;for(let Fe of Se)for(let Oe=0;Oe<Fe.length-1;Oe++){let We=Fe[Oe],ze=Fe[Oe+1];se(ne+We[0]*Ce,fe+We[1]*_e,ne+ze[0]*Ce,fe+ze[1]*_e,B,-Y*.5,Y*.5)}ne+=ve?Z*.88:Z}I(this,W,re,oe,ce),w.center!==!1?this.center():this.computeBoundingBox()}}function pe(S){if(!S)return;let x=S,w=S.userData?.xr?.text;if(w!=null&&w!==!1){let O=x.geometry?.attributes?.position;if((!O||O.count===0)&&S.userData._textApplied!==!0){let H="",X=.08,j=.015,Y;if(typeof w=="string"||typeof w=="number")H=String(w);else if(typeof w=="object"){let B=w;H=String(B.text??B.value??""),B.size!==void 0&&(X=Number(B.size)||.08),(B.depth!==void 0||B.height!==void 0)&&(j=Number(B.depth??B.height)||X*.2),(typeof B.color=="string"||typeof B.color=="number")&&(Y=B.color)}H.trim().length>0&&(x.geometry=new Me(H,{size:X,depth:j}),S.userData._textApplied=!0,x.material instanceof u?Y!==void 0&&S.userData._autoTextColorApplied!==!0&&(x.material.color=new l(Y),S.userData._autoTextColorApplied=!0):x.material=new m({color:Y??16317180}))}}let U=S.userData?.csg;if(U&&typeof U=="object"&&S.userData._csgApplied!==!0&&x.geometry instanceof c&&x.geometry.attributes.position?.count>0){S.userData._csgApplied=!0;let O=Array.isArray(U)?U:[U],H=x.geometry;for(let X of O){if(!X||typeof X!="object")continue;let j=X,Y=String(j.op??j.operation??"subtract"),B=Y==="union"||Y==="intersect"?Y:"subtract",J=j.target??j.mesh??j.geometry;if(J instanceof f||J instanceof c)try{let Z=B==="union"?he.union(x,J):B==="intersect"?he.intersect(x,J):he.subtract(x,J);x.geometry!==H&&x.geometry.dispose?.(),x.geometry=Z.geometry}catch(Z){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",Z)}}}}let ge={Path:G,Shape:p,ShapeGeometry:C,ExtrudeGeometry:T,TextGeometry:Me,CSG:he,MAX_CSG_TRIANGLES:d,MAX_BSP_DEPTH:g,MAX_TEXT_GEOMETRY_CHARS:y,MAX_SHAPE_POINTS:M,materializeDeclarativeGeometry:pe};return e&&typeof e=="object"&&(e.authorNamespace||(e.authorNamespace={}),Object.assign(e.authorNamespace,ge),e.materializeDeclarativeGeometry=pe),ge}function ke(){let t=new Float32Array(16);return t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function an(t,e,n,r,i){let o=1/Math.tan(e/2);t.fill(0),t[0]=o/n,t[5]=o,t[11]=-1;let s=1/(r-i);return t[10]=(i+r)*s,t[14]=2*i*r*s,t}function kt(t,e,n,r){let[i,o,s]=e,[l,a,c]=r,[u,m,f]=n,d=i-u,g=o-m,y=s-f,M=Math.hypot(d,g,y);M<=1e-5?(d=0,g=0,y=1):(d/=M,g/=M,y/=M);let L=a*y-c*g,G=c*d-l*y,p=l*g-a*d;M=Math.hypot(L,G,p),M<=1e-5?(L=0,G=0,p=0):(L/=M,G/=M,p/=M);let E=g*p-y*G,_=y*L-d*p,P=d*G-g*L;return M=Math.hypot(E,_,P),M<=1e-5?(E=0,_=0,P=0):(E/=M,_/=M,P/=M),t[0]=L,t[1]=E,t[2]=d,t[3]=0,t[4]=G,t[5]=_,t[6]=g,t[7]=0,t[8]=p,t[9]=P,t[10]=y,t[11]=0,t[12]=-(L*i+G*o+p*s),t[13]=-(E*i+_*o+P*s),t[14]=-(d*i+g*o+y*s),t[15]=1,t}function De(t,e,n){let r=e[0],i=e[1],o=e[2],s=e[3],l=e[4],a=e[5],c=e[6],u=e[7],m=e[8],f=e[9],d=e[10],g=e[11],y=e[12],M=e[13],L=e[14],G=e[15],p=n[0],E=n[1],_=n[2],P=n[3];return t[0]=p*r+E*l+_*m+P*y,t[1]=p*i+E*a+_*f+P*M,t[2]=p*o+E*c+_*d+P*L,t[3]=p*s+E*u+_*g+P*G,p=n[4],E=n[5],_=n[6],P=n[7],t[4]=p*r+E*l+_*m+P*y,t[5]=p*i+E*a+_*f+P*M,t[6]=p*o+E*c+_*d+P*L,t[7]=p*s+E*u+_*g+P*G,p=n[8],E=n[9],_=n[10],P=n[11],t[8]=p*r+E*l+_*m+P*y,t[9]=p*i+E*a+_*f+P*M,t[10]=p*o+E*c+_*d+P*L,t[11]=p*s+E*u+_*g+P*G,p=n[12],E=n[13],_=n[14],P=n[15],t[12]=p*r+E*l+_*m+P*y,t[13]=p*i+E*a+_*f+P*M,t[14]=p*o+E*c+_*d+P*L,t[15]=p*s+E*u+_*g+P*G,t}function vt(t,e,n,r){let i=e[0],o=e[1],s=e[2],l=e[3],a=i+i,c=o+o,u=s+s,m=i*a,f=i*c,d=i*u,g=o*c,y=o*u,M=s*u,L=l*a,G=l*c,p=l*u,E=r[0],_=r[1],P=r[2];return t[0]=(1-(g+M))*E,t[1]=(f+p)*E,t[2]=(d-G)*E,t[3]=0,t[4]=(f-p)*_,t[5]=(1-(m+M))*_,t[6]=(y+L)*_,t[7]=0,t[8]=(d+G)*P,t[9]=(y-L)*P,t[10]=(1-(m+g))*P,t[11]=0,t[12]=n[0],t[13]=n[1],t[14]=n[2],t[15]=1,t}function $e(t,e,n=0){let r=e[0],i=e[1],o=e[2],s=e[4],l=e[5],a=e[6],c=e[8],u=e[9],m=e[10],f=m*l-a*u,d=-m*s+a*c,g=u*s-l*c,y=r*f+i*d+o*g;return!y||n>0&&(!Number.isFinite(y)||Math.abs(y)<=n)||(y=1/y,t[0]=f*y,t[1]=d*y,t[2]=g*y,t[3]=(-m*i+o*u)*y,t[4]=(m*r-o*c)*y,t[5]=(-u*r+i*c)*y,t[6]=(a*i-o*l)*y,t[7]=(-a*r+o*s)*y,t[8]=(l*r-i*s)*y),t}function zr(t,e){let n=e[0],r=e[1],i=e[2],o=e[3],s=e[4],l=e[5],a=e[6],c=e[7],u=e[8],m=e[9],f=e[10],d=e[11],g=e[12],y=e[13],M=e[14],L=e[15],G=n*l-r*s,p=n*a-i*s,E=n*c-o*s,_=r*a-i*l,P=r*c-o*l,z=i*c-o*a,R=u*y-m*g,C=u*M-f*g,I=u*L-d*g,b=m*M-f*y,T=m*L-d*y,N=f*L-d*M,v=G*N-p*T+E*b+_*I-P*C+z*R;return v?(v=1/v,t[0]=(l*N-a*T+c*b)*v,t[1]=(i*T-r*N-o*b)*v,t[2]=(y*z-M*P+L*_)*v,t[3]=(f*P-m*z-d*_)*v,t[4]=(a*I-s*N-c*C)*v,t[5]=(n*N-i*I+o*C)*v,t[6]=(M*E-g*z-L*p)*v,t[7]=(u*z-f*E+d*p)*v,t[8]=(s*T-l*I+c*R)*v,t[9]=(r*I-n*T-o*R)*v,t[10]=(g*P-y*E+L*G)*v,t[11]=(m*E-u*P-d*G)*v,t[12]=(l*C-s*b-a*R)*v,t[13]=(n*b-r*C+i*R)*v,t[14]=(y*p-g*_-M*G)*v,t[15]=(u*_-m*p+f*G)*v,t):null}function qn(t,e,n,r,i){let o=i[0]*e+i[4]*n+i[8]*r+i[12],s=i[1]*e+i[5]*n+i[9]*r+i[13],l=i[2]*e+i[6]*n+i[10]*r+i[14],a=i[3]*e+i[7]*n+i[11]*r+i[15],c=a!==0?1/a:1;t[0]=o*c,t[1]=s*c,t[2]=l*c}function Vr(t,e,n,r,i,o,s,l,a,c,u,m,f,d,g,y,M=0){let L=c-s,G=u-l,p=m-a,E=f-s,_=d-l,P=g-a,z=i*P-o*_,R=o*E-r*P,C=r*_-i*E,I=L*z+G*R+p*C;if(I>-1e-7&&I<1e-7)return!1;let b=1/I,T=t-s,N=e-l,v=n-a,D=b*(T*z+N*R+v*C);if(D<-M||D>1+M)return!1;let h=N*p-v*G,A=v*L-T*p,$=T*G-N*L,V=b*(r*h+i*A+o*$);if(V<-M||D+V>1+M)return!1;let K=b*(E*h+_*A+P*$);if(K>1e-4&&K<y.distance){y.distance=K,y.point=[t+r*K,e+i*K,n+o*K];let k=G*P-p*_,ee=p*E-L*P,Q=L*_-G*E,q=Math.hypot(k,ee,Q)||1;return y.normal=[k/q,ee/q,Q/q],!0}return!1}function cn(t,e){let n=Array.isArray(t?.nodes)?t.nodes.length:0,r=[];for(let u=0;u<n;u++)r.push(ke());if(n===0)return r;let i=new Set;for(let u of t.nodes)if(Array.isArray(u.children))for(let m of u.children)i.add(m);let o=new Set,s=128,l=(u,m,f=0)=>{if(f>s||u<0||u>=n||o.has(u))return;o.add(u);let d=t.nodes[u];if(!d)return;let g=ke();if(e&&e[u])g.set(e[u]);else if(d.matrix&&d.matrix.length===16)g.set(d.matrix);else{let M=d.translation||[0,0,0],L=d.rotation||[0,0,0,1],G=d.scale||[1,1,1];vt(g,L,M,G)}let y=r[u];if(m?De(y,m,g):y.set(g),Array.isArray(d.children))for(let M of d.children)typeof M=="number"&&l(M,y,f+1)},a=[],c=t.scenes&&t.scenes[t.scene!==void 0?t.scene:0];if(c&&Array.isArray(c.nodes))a.push(...c.nodes);else for(let u=0;u<n;u++)i.has(u)||a.push(u);for(let u of a)l(u,null);for(let u=0;u<n;u++)!i.has(u)&&!a.includes(u)&&l(u,null);return r}function Zn(t,e){function n(a,c,u,m){let f=typeof a=="number"?a:Number(a);return Number.isFinite(f)?Math.max(c,Math.min(u,f)):m}function r(a,c){let m=a[0]*c[0]+a[1]*c[1]+a[2]*c[2]+1;if(m<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let L=Math.hypot(a[1],a[0])||1;return[-a[1]/L,a[0]/L,0,0]}let M=Math.hypot(a[2],a[1])||1;return[0,-a[2]/M,a[1]/M,0]}let f=a[1]*c[2]-a[2]*c[1],d=a[2]*c[0]-a[0]*c[2],g=a[0]*c[1]-a[1]*c[0],y=Math.hypot(f,d,g,m)||1;return[f/y,d/y,g/y,m/y]}function i(a,c,u,m,f){let d=c[0]-a[0],g=c[1]-a[1],y=c[2]-a[2],M=Math.hypot(d,g,y),L=u[0]-c[0],G=u[1]-c[1],p=u[2]-c[2],E=Math.hypot(L,G,p);if(M<1e-6||E<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[c[0],c[1],c[2]],effectorPos:[u[0],u[1],u[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let _=[d/M,g/M,y/M],P=[L/E,G/E,p/E],z=m[0]-a[0],R=m[1]-a[1],C=m[2]-a[2],I=Math.hypot(z,R,C),b=I>1e-6?[z/I,R/I,C/I]:_,T=Math.abs(M-E)+1e-5,N=Math.max(T,M+E-1e-5),v=Math.max(T,Math.min(N,I>1e-6?I:T)),D=n((M*M+v*v-E*E)/(2*M*v),-1,1,1),h=Math.sqrt(Math.max(0,1-D*D)),A=f?f[0]-a[0]:d,$=f?f[1]-a[1]:g,V=f?f[2]-a[2]:y,K=A*b[0]+$*b[1]+V*b[2],k=A-b[0]*K,ee=$-b[1]*K,Q=V-b[2]*K,q=Math.hypot(k,ee,Q);if(q<=1e-6){let S=Math.abs(b[1])<.99?0:1,x=Math.abs(b[1])<.99?1:0,w=0;k=b[1]*w-b[2]*x,ee=b[2]*S-b[0]*w,Q=b[0]*x-b[1]*S,q=Math.hypot(k,ee,Q)||1}let ae=[k/q,ee/q,Q/q],F=[a[0]+b[0]*(M*D)+ae[0]*(M*h),a[1]+b[1]*(M*D)+ae[1]*(M*h),a[2]+b[2]*(M*D)+ae[2]*(M*h)],te=[a[0]+b[0]*v,a[1]+b[1]*v,a[2]+b[2]*v],ue=te[0]-F[0],le=te[1]-F[1],he=te[2]-F[2],xe=Math.hypot(ue,le,he),Me=xe>1e-6?[ue/xe,le/xe,he/xe]:b,pe=[F[0]+Me[0]*E,F[1]+Me[1]*E,F[2]+Me[2]*E],ge=[(F[0]-a[0])/M,(F[1]-a[1])/M,(F[2]-a[2])/M];return{rootPos:[a[0],a[1],a[2]],midPos:F,effectorPos:pe,rootRotation:r(_,ge),midRotation:r(P,Me)}}function o(a,c,u=8,m=.001){let f=a.length;if(f<2)return{positions:a.map(I=>[I[0],I[1],I[2]]),rotations:[],iterations:0};let d=a.map(I=>[I[0],I[1],I[2]]),g=[],y=[],M=0;for(let I=0;I<f-1;I++){let b=d[I+1][0]-d[I][0],T=d[I+1][1]-d[I][1],N=d[I+1][2]-d[I][2],v=Math.hypot(b,T,N);g.push(v),M+=v,y.push(v>1e-6?[b/v,T/v,N/v]:[0,1,0])}let L=[d[0][0],d[0][1],d[0][2]],G=Math.round(n(u,1,32,8)),p=n(m,1e-5,.1,.001),E=c[0]-L[0],_=c[1]-L[1],P=c[2]-L[2],z=Math.hypot(E,_,P),R=0;if(z>=M&&M>1e-6){let I=z>1e-6?[E/z,_/z,P/z]:y[0];d[0]=[L[0],L[1],L[2]];for(let b=0;b<f-1;b++){let T=g[b];d[b+1]=[d[b][0]+I[0]*T,d[b][1]+I[1]*T,d[b][2]+I[2]*T]}R=1}else for(let I=1;I<=G;I++){let b=d[f-1];if(Math.hypot(b[0]-c[0],b[1]-c[1],b[2]-c[2])<=p)break;R=I;let N=(v,D,h,A,$)=>{let V=D[0]-v[0],K=D[1]-v[1],k=D[2]-v[2],ee=Math.hypot(V,K,k);if(ee>1e-6){let Q=h/ee;return[v[0]+V*Q,v[1]+K*Q,v[2]+k*Q]}return[v[0]+A[0]*h*$,v[1]+A[1]*h*$,v[2]+A[2]*h*$]};d[f-1]=[c[0],c[1],c[2]];for(let v=f-2;v>=0;v--)d[v]=N(d[v+1],d[v],g[v],y[v],-1);d[0]=[L[0],L[1],L[2]];for(let v=0;v<f-1;v++)d[v+1]=N(d[v],d[v+1],g[v],y[v],1)}let C=[];for(let I=0;I<f-1;I++){let b=d[I+1][0]-d[I][0],T=d[I+1][1]-d[I][1],N=d[I+1][2]-d[I][2],v=Math.hypot(b,T,N),D=v>1e-6?[b/v,T/v,N/v]:y[I];C.push(r(y[I],D))}return{positions:d,rotations:C,iterations:R}}function s(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let c=a;if(c.enabled===!1)return null;let u=p=>{if(typeof p!="string")return;let E=p.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(E)?E:void 0},m=p=>Array.isArray(p)&&p.length===3&&p.every(E=>typeof E=="number"&&Number.isFinite(E))?[n(p[0],-1e3,1e3,0),n(p[1],-1e3,1e3,0),n(p[2],-1e3,1e3,0)]:void 0,f=u(c.root),d=u(c.effector);if(!f||!d)return null;let g=u(c.mid),y=m(c.target)??u(c.target);if(!y)return null;let M=c.pole??c.poleTarget,L=m(M)??u(M),G=c.solver==="fabrik"?"fabrik":c.solver==="two-bone"||g?"two-bone":"fabrik";return{root:f,...g?{mid:g}:{},effector:d,target:y,...L?{pole:L}:{},solver:G,iterations:Math.round(n(c.iterations,1,32,8)),tolerance:n(c.tolerance,1e-5,.1,.001),weight:n(c.weight,0,1,1)}}let l=Object.freeze({solveTwoBone:i,solveFABRIK:o,parseIKTrait:s});return e&&typeof e=="object"&&(e.authorNamespace=e.authorNamespace||{},e.authorNamespace.IKSolver=l),{clampNum:n,parseIKTrait:s,quatFromUnitVectors:r,solveTwoBoneIK:i,solveFABRIK:o,IKSolver:l}}var Dt=Zn(),ys=Dt.clampNum,gs=Dt.parseIKTrait,xs=Dt.quatFromUnitVectors,vs=Dt.solveTwoBoneIK,Ts=Dt.solveFABRIK,Ms=Dt.IKSolver;function un(t,e,n,r=!0){let i=[],o=null;try{for(let[s,l]of[[35633,e],[35632,n]]){let a=t.createShader(s);if(!a){if(r)throw new Error("Shader allocation failed");return null}if(i.push(a),t.shaderSource(a,l),t.compileShader(a),t.getShaderParameter&&!t.getShaderParameter(a,35713)){if(r)throw new Error(`Shader compile error: ${t.getShaderInfoLog(a)}`);return null}}if(o=t.createProgram(),!o){if(r)throw new Error("Program allocation failed");return null}for(let s of i)t.attachShader(o,s);if(t.linkProgram(o),t.getProgramParameter&&!t.getProgramParameter(o,35714)){let s=r?t.getProgramInfoLog(o):null;if(t.deleteProgram?.(o),o=null,r)throw new Error(`Program link error: ${s}`);return null}return o}finally{for(let s of i)o&&t.detachShader?.(o,s),t.deleteShader?.(s)}}var Fi={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function Qn(t,e,n,r){if(!n||n.bufferView===void 0)return null;let i=t.bufferViews?.[n.bufferView];if(!i)return null;let o=Number(n.count??0);if(!Number.isInteger(o)||o<=0)return null;let s=n.componentType??5126,l=Fi[s];if(!l)throw new RangeError(`glTF accessor has unsupported componentType ${s}`);let a=l*r,c=i.byteStride&&i.byteStride>0?i.byteStride:a,u=(i.byteOffset||0)+(n.byteOffset||0);if(!Number.isInteger(u)||u<0||c<a||u+(o-1)*c+a>e.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${e.byteLength} bytes)`);if(s===5126&&c===a&&u%4===0)return new Float32Array(e,u,o*r);let m=new DataView(e),f=n.normalized===!0,d=new Float32Array(o*r);for(let g=0;g<o;g++){let y=u+g*c;for(let M=0;M<r;M++){let L=y+M*l,G;switch(s){case 5126:G=m.getFloat32(L,!0);break;case 5120:G=m.getInt8(L),f&&(G=Math.max(G/127,-1));break;case 5121:G=m.getUint8(L),f&&(G/=255);break;case 5122:G=m.getInt16(L,!0),f&&(G=Math.max(G/32767,-1));break;case 5123:G=m.getUint16(L,!0),f&&(G/=65535);break;default:G=m.getUint32(L,!0),f&&(G/=4294967295)}d[g*r+M]=G}}return d}function Br(t,e){let n=Number(e.offset?.[0]??0)||0,r=Number(e.offset?.[1]??0)||0,i=Number(e.scale?.[0]??1),o=Number(e.scale?.[1]??1),s=Number(e.rotation??0)||0,l=Math.cos(s),a=Math.sin(s),c=(Number.isFinite(i)?i:1)*l,u=(Number.isFinite(i)?i:1)*a,m=-(Number.isFinite(o)?o:1)*a,f=(Number.isFinite(o)?o:1)*l;for(let d=0;d+1<t.length;d+=2){let g=t[d],y=t[d+1];t[d]=c*g+u*y+n,t[d+1]=m*g+f*y+r}}var $r=["neutral","reinhard","none","aces","agx"];function tr(t){let e=String(t??"").trim().toLowerCase();return $r.includes(e)?e:"neutral"}function zi(t){return $r.indexOf(tr(t))}function Vi(t){return new TextDecoder().decode(t)}var Xr=Ie().decoders;function Bi(t,e){Xr.set(t.toLowerCase(),e)}function Lt(t){return Xr.get(t.toLowerCase())}function jr(t){let e=ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t,n=new DataView(e);if(e.byteLength<12)throw new Error(`Invalid GLB buffer size: ${e.byteLength} bytes`);let r=n.getUint32(0,!0);if(r!==1179937895){let f=n.getUint8(0);throw f===123||f===32||f===10||f===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${r.toString(16)}`)}let i=n.getUint32(4,!0);if(i!==2)throw new Error(`Unsupported GLB version: ${i}`);let o=n.getUint32(8,!0),s=12,l=null,a=null;for(;s+8<=o&&s+8<=e.byteLength;){let f=n.getUint32(s,!0),d=n.getUint32(s+4,!0),g=s+8;if(g+f>e.byteLength)throw new Error(`Truncated GLB chunk: required ${g+f} bytes, buffer has ${e.byteLength}`);if(d===1313821514){let y=new Uint8Array(e,g,f),M=Vi(y);l=JSON.parse(M,(L,G)=>L==="__proto__"||L==="constructor"||L==="prototype"?void 0:G)}else d===5130562&&(a=e.slice(g,g+f));s=g+f}if(!l)throw new Error("Missing JSON chunk in GLB");let c=l.extensionsRequired||[];if(c.includes("KHR_draco_mesh_compression")&&!Lt("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let f of["EXT_meshopt_compression","KHR_meshopt_compression"])if(c.includes(f)&&!Lt("meshopt"))throw new Error(`Model requires ${f}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(c.includes("KHR_texture_basisu")&&!Lt("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let u=a||new ArrayBuffer(0),m={gltf:l,bin:u,animations:[]};for(let f of Ue)f.onParseGLB?.(m);return m}function Gi(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 Gt(t){if(Gi(t))return t;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t))return jr(t);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var Wr=`#version 300 es
|
|
19
|
+
layout(location=0) in vec3 aPos;
|
|
20
|
+
layout(location=3) in vec3 aOff;
|
|
20
21
|
layout(location=1) in vec3 aNormal;
|
|
21
22
|
layout(location=2) in vec2 aUV;
|
|
22
23
|
uniform mat4 uMVP,uModel;
|
|
@@ -39,6 +40,7 @@ mat3 xrNormalMatrix(){return uInstanced==1?transpose(inverse(mat3(xrModel()))):u
|
|
|
39
40
|
out vec3 vNormal,vWorldPos;
|
|
40
41
|
out vec2 vUV;
|
|
41
42
|
void main(){
|
|
43
|
+
vec3 aPosition=aPos+aOff;
|
|
42
44
|
vInstTint=uInstanced==1?aInstColor:vec4(1.0);
|
|
43
45
|
vec3 rawN=uNormalMatrix*aNormal;
|
|
44
46
|
vNormal=length(rawN)>1e-5?normalize(rawN):vec3(0.0);
|
|
@@ -248,7 +250,7 @@ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,Xi=`#version 300 es
|
|
|
248
250
|
precision highp float;
|
|
249
251
|
uniform vec4 uColorId;
|
|
250
252
|
out vec4 fragColor;
|
|
251
|
-
void main(){fragColor=uColorId;}`;function Gr(t,e,n){let r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,35713)){let i=t.getShaderInfoLog(r);throw t.deleteShader(r),new Error(`Shader compile error: ${i}`)}return r}function nr(t,e,n){let r=Gr(t,35633,e),i=Gr(t,35632,n),o=t.createProgram();if(t.attachShader(o,r),t.attachShader(o,i),t.linkProgram(o),!t.getProgramParameter(o,35714)){let s=t.getProgramInfoLog(o);throw t.deleteProgram(o),new Error(`Program link error: ${s}`)}return o}function rr(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var Hr=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Kr(){let t=ke().xrDepthShader;return{fs:Hi.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Hr,...t.uniformNames]:Hr}}function ji(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Jn(t,e,n,r,i,o,s,l){if(r===void 0||!e.accessors?.[r])return null;let a=Qn(e,n,e.accessors[r],o);if(!a)return null;l&&(a=a.slice(),Br(a,l));let c=t.createBuffer();return s.push(c),t.bindBuffer(34962,c),t.bufferData(34962,a,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),a}function er(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function qr(t,e,n){let r=Kr(),i=Yr,o=r.fs,s=!1;for(let a of Oe)if(a.onResolveShader){let c=a.onResolveShader(e,n,i,o);c&&(i=c.vs,o=c.fs,s=!0)}let l=s?nr(t,i,o):null;return{program:l,uniforms:l?rr(t,l,r.uniforms):null}}function Wi(t,e,n){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=e.instanceColors,s=new Float32Array(i*20);for(let a=0;a<i;a++)s.set(r.subarray(a*16,a*16+16),a*20),s[a*20+16]=o?o[a*3]:1,s[a*20+17]=o?o[a*3+1]:1,s[a*20+18]=o?o[a*3+2]:1,s[a*20+19]=1;let l=t.createBuffer();n.push(l),t.bindBuffer(34962,l),t.bufferData(34962,s,35044);for(let a=0;a<5;a++)t.enableVertexAttribArray(8+a),t.vertexAttribPointer(8+a,4,5126,!1,80,a*16),t.vertexAttribDivisor(8+a,1);return!0}function Yi(t,e){let n=t.materials?.[e?.material];if(!n)return null;let r=[n.pbrMetallicRoughness?.baseColorTexture,n.pbrMetallicRoughness?.metallicRoughnessTexture,n.normalTexture,n.occlusionTexture,n.emissiveTexture];for(let i of r){let o=i?.extensions?.KHR_texture_transform;if(o&&typeof o=="object")return o}return null}var _s=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),Zr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function un(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Qr(t,e){let n=t?.pbrMetallicRoughness,r=n?.baseColorFactor,i=t?.extensions?.KHR_materials_clearcoat,o=s=>s!==void 0&&e[s.index]?e[s.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:n?.metallicFactor??.1,roughness:n?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:o(n?.baseColorTexture),metallicRoughnessTexture:o(n?.metallicRoughnessTexture),normalTexture:o(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:o(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Jr(t,e,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),t.deleteTexture(o))};for(let o of e)for(let s of o.primitives){if(s.vao&&t.deleteVertexArray(s.vao),s.buffers)for(let a of s.buffers)t.deleteBuffer(a);i(s.texture),i(s.metallicRoughnessTexture),i(s.normalTexture),i(s.occlusionTexture);let l=new Set;s.customProgram&&l.add(s.customProgram);for(let a of s.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)t.deleteProgram(a)}if(n)for(let o of n)i(o)}function $r(t,e,n=Zr,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Ki(t,e,n,r,i)}catch(o){let s=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Jr(t,s,i.gpuTextures),i.vao&&t.deleteVertexArray(i.vao);for(let l of i.buffers)t.deleteBuffer(l);throw o}}function Ki(t,e,n,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=e,s=Pt("meshopt");s?.decodeBufferViews&&s.decodeBufferViews(o,e);let l=e.bin,a=[];i.meshes=a;let c=[],u=o.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((M,P)=>{c.push(typeof M?.name=="string"&&M.name?M.name:`Variant_${P}`)});let f=cn(o),h=[];if(Array.isArray(o.nodes))for(let M=0;M<o.nodes.length;M++){let P=o.nodes[M];P.mesh!==void 0&&o.meshes&&o.meshes[P.mesh]&&h.push({node:P,nodeIdx:M,meshIdx:P.mesh})}let d=h.length>0?h:(o.meshes||[]).map((M,P)=>({node:M,nodeIdx:-1,meshIdx:P})),y=[];if(Array.isArray(e.lights)&&e.lights.length>0)y.push(...e.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let M=o.extensions.KHR_lights_punctual.lights;for(let P of M){let v=P.type==="directional"?"directional":P.type==="point"?"point":"ambient";y.push({type:v,color:P.color||[1,1,1],intensity:P.intensity!==void 0?P.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]})),d.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${d.length}`);let x=[];if(i.gpuTextures=x,o.textures&&o.images){if(o.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${o.textures.length}`);for(let M=0;M<o.textures.length;M++){let P=o.textures[M],v=o.images[P.source];if(v){let p=t.createTexture();if(t.bindTexture(3553,p),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),v.bufferView!==void 0){let m=o.bufferViews[v.bufferView],L=l.slice(m.byteOffset||0,(m.byteOffset||0)+m.byteLength),W=new Blob([L],{type:v.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(W).then(G=>{t.bindTexture(3553,p),t.texImage2D(3553,0,6408,6408,5121,G),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(v.uri){let m=ji(v.uri);if(m){let L=new Image;L.crossOrigin="anonymous",L.referrerPolicy="no-referrer",L.onload=()=>{t.bindTexture(3553,p),t.texImage2D(3553,0,6408,6408,5121,L),t.generateMipmap(3553),r?.()},L.src=m}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",v.uri)}x.push(p)}else x.push(null)}}let T=[1/0,1/0,1/0],D=[-1/0,-1/0,-1/0],V=0,b=0;for(let M=0;M<d.length;M++){let P=d[M],v=o.meshes[P.meshIdx],p=P.nodeIdx>=0?f[P.nodeIdx]:De(),m=new Float32Array(9);$e(m,p);let L={name:P.node.name||v.name||`Mesh_${P.meshIdx}`,nodeIndex:P.nodeIdx,transform:p,normalMatrix:m,primitives:[],extras:P.node.extras||v.extras};i.mesh=L;let W=P.node?.extensions?.EXT_mesh_gpu_instancing;if(W&&W.attributes&&typeof W.attributes=="object"){let G=W.attributes,K=G.TRANSLATION!==void 0?o.accessors?.[G.TRANSLATION]:null,k=G.ROTATION!==void 0?o.accessors?.[G.ROTATION]:null,ee=G.SCALE!==void 0?o.accessors?.[G.SCALE]:null,Q=G._COLOR_0!==void 0?o.accessors?.[G._COLOR_0]:null,q=Number(K?.count??k?.count??ee?.count??0);if(!Number.isFinite(q)||q<0||q>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${q}`);if(q>0){let ae=(pe,xe)=>{if(!pe||pe.bufferView===void 0||!o.bufferViews?.[pe.bufferView])return null;let C=pe.componentType??5126,w=N=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${N})`),null);if(C!==5120&&C!==5121&&C!==5122&&C!==5123&&C!==5126)return w(`componentType ${C}`);if(!(Number(pe.count)>=q))return w(`count ${pe.count} < ${q}`);let A=null;try{A=Qn(o,l,{...pe,count:q},xe)}catch{return w("out of bounds")}return!A||!A.every(Number.isFinite)?w("non-finite value"):A},O=ae(K,3),te=ae(k,4),ue=ae(ee,3),le=Q?.type==="VEC4"?4:3,he=ae(Q,le),ve=new Float32Array(q*16),Me=De();for(let pe=0;pe<q;pe++){let xe=O?[O[pe*3],O[pe*3+1],O[pe*3+2]]:[0,0,0],C=te?[te[pe*4],te[pe*4+1],te[pe*4+2],te[pe*4+3]]:[0,0,0,1],w=ue?[ue[pe*3],ue[pe*3+1],ue[pe*3+2]]:[1,1,1];vt(Me,C,xe,w),ve.set(Me,pe*16)}if(L.instanceMatrices=ve,he){let pe=new Float32Array(q*3);for(let xe=0;xe<q;xe++)pe[xe*3]=he[xe*le],pe[xe*3+1]=he[xe*le+1],pe[xe*3+2]=he[xe*le+2];L.instanceColors=pe}}}for(let G of v.primitives||[]){if(G.extensions?.KHR_draco_mesh_compression){let A=Pt("draco");A&&A.decodePrimitive(o,G,l)}let K=[],k=t.createVertexArray();i.vao=k,i.buffers=K,t.bindVertexArray(k);let ee=Wi(t,L,K),Q=o.accessors[G.attributes.POSITION],q=Number(Q?.count??0);if(!Number.isFinite(q)||q<0||V+q>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(V+=q,Q?.min&&Q?.max){let A=N=>{for(let F=0;F<3;F++){let B=N[12+F],$=N[12+F];for(let X=0;X<3;X++){let Y=N[X*4+F]*Q.min[X],H=N[X*4+F]*Q.max[X];B+=Y<H?Y:H,$+=Y>H?Y:H}B<T[F]&&(T[F]=B),$>D[F]&&(D[F]=$)}};if(L.instanceMatrices&&L.instanceMatrices.length>=16){let N=L.instanceMatrices.length>>4,F=De();for(let B=0;B<N;B++){let $=L.instanceMatrices.subarray(B*16,B*16+16);Le(F,p,$),A(F)}}else A(p)}let ae=Jn(t,o,l,G.attributes.POSITION,0,3,K);Jn(t,o,l,G.attributes.NORMAL,1,3,K),Jn(t,o,l,G.attributes.TEXCOORD_0,2,2,K,Yi(o,G));let O=0,te=5123,ue=null;if(G.indices!==void 0){let A=o.accessors[G.indices],F=(o.bufferViews[A.bufferView].byteOffset||0)+(A.byteOffset||0);if(O=Number(A.count??0),!Number.isFinite(O)||O<0||b+O>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);b+=O,te=A.componentType===5125?5125||5125:5123||5123;let B=t.createBuffer();K.push(B),t.bindBuffer(34963,B),A.componentType===5125?(ue=new Uint32Array(l,F,A.count),t.bufferData(34963,ue,35044)):A.componentType===5121?(ue=Uint16Array.from(new Uint8Array(l,F,A.count)),t.bufferData(34963,ue,35044)):(ue=F%2===0?new Uint16Array(l,F,A.count):new Uint16Array(l.slice(F,F+A.count*2)),t.bufferData(34963,ue,35044))}else O=Q.count;let le={};for(let A of Oe)if(A.onBuildPrimitiveVAO){let N=A.onBuildPrimitiveVAO(t,k,G,o,l);N&&(le[A.name]=N)}t.bindVertexArray(null);let he=o.materials&&G.material!==void 0?o.materials[G.material]:null,{program:ve,uniforms:Me}=qr(t,G,he),pe=Qr(he,x),xe=!!(he?.extensions?.KHR_materials_transmission||le.materials?.isTransmissive),C=G.extensions?.KHR_materials_variants?.mappings,w=Array.isArray(C)?C.filter(A=>A&&typeof A.material=="number"&&Array.isArray(A.variants)).map(A=>({material:A.material|0,variants:A.variants.map(N=>Number(N)|0)})):void 0;L.primitives.push({vao:k,instanced:ee,indexCount:O,indexType:te,...pe,positions:ae,indices:ue,buffers:K,materialIndex:G.material,defaultMaterialIndex:G.material,variantMappings:w,primitiveDef:G,programCache:new Map([[G.material??-1,{program:ve,uniforms:Me}]]),pluginData:le,customProgram:ve,customUniforms:Me,isTransmissive:xe})}a.push(L)}isFinite(T[0])||(T=[-1,-1,-1]),isFinite(D[0])||(D=[1,1,1]);let _=[(T[0]+D[0])/2,(T[1]+D[1])/2,(T[2]+D[2])/2],S=D[0]-T[0],U=D[1]-T[1],z=D[2]-T[2],I=Math.max(Math.hypot(S,U,z)/2,.5),E=[T[0],T[1],T[2]],R=[D[0],D[1],D[2]],g=e.animations;if(!g){for(let M of Oe)if(M.onParseGLB?.(e),e.animations){g=e.animations;break}}return g||(g=[]),{meshes:a,bounds:{center:_,radius:I,min:E,max:R},lights:y,animations:g,worldMatrices:f,gpuTextures:x,availableVariants:c}}function Bt(t){let e=t.customTarget||t.bounds.center,n=t.currDistance*Math.cos(t.currPhi);return[e[0]+n*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+n*Math.cos(t.currTheta)]}var ln=class{constructor(e,n,r){this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=De();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=De();this.viewMatrix=De();this.activeViewMatrix=null;this.modelMatrix=De();this.mvpMatrix=De();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:De(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=er(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=tr(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){Bi(e,n)}static getDecoder(e){return Pt(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=n=>{n.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,n=Kr();this.renderProg=nr(e,Yr,n.fs),this.pickProg=nr(e,$i,Xi),this.uRender=rr(e,this.renderProg,n.uniforms),this.uPick=rr(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let n of Oe)n.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){this.lastGlbData=e,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:s,worldMatrices:l,gpuTextures:a,availableVariants:c}=$r(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let h of e.gltf.nodes)this.initialNodeTransforms.push({t:h.translation?[h.translation[0],h.translation[1],h.translation[2]]:[0,0,0],r:h.rotation?[h.rotation[0],h.rotation[1],h.rotation[2],h.rotation[3]]:[0,0,0,1],s:h.scale?[h.scale[0],h.scale[1],h.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let h of Oe)h.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=er(u));let f=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;f!==void 0&&(this.envIntensity=Math.max(0,Number(f)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(Wr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Gt(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Gt(e),{meshes:i}=$r(this.gl,r,Zr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],$e(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),$e(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],s=[],l=[];for(let a of this.lights){let c=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(a.type==="directional"&&i.length<6){let f=a.direction||[.5,1,.8];i.push(f[0],f[1],f[2]),o.push(c[0]*u,c[1]*u,c[2]*u)}else if(a.type==="point"&&s.length<6){let f=a.position||[0,0,0];s.push(f[0],f[1],f[2]),l.push(c[0]*u,c[1]*u,c[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(n.uniform3fv(e.uPointLightPos,s),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=er(e)}getExposure(){return this.exposure}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=tr(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of Oe)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of Oe)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(f=>f.materialIndex===r||e.length===1&&f.materialIndex===void 0)),o=i[0],s=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:s,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:u=>{let f=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=f,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=f);for(let h of i)h.baseColor=f;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let f of i)f.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let f of i)f.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let n=this.applyVariantMaterial(e);return n&&this.gl&&this.render(),n}applyVariantMaterial(e){let n=e===null||e==="",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let s of o.primitives){let l=s.defaultMaterialIndex;if(!n&&Array.isArray(s.variantMappings)){for(let c of s.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){l=c.material;break}}let a=l!==void 0?i[l]:void 0;s.materialIndex=a?l:void 0,Object.assign(s,Qr(a,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,n,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=n??-1,o=e.programCache.get(i);o||(o=qr(this.gl,{...e.primitiveDef,material:n},r),e.programCache.set(i,o)),e.customProgram=o.program,e.customUniforms=o.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of Oe)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,n){let r=De();Le(r,this.projMatrix,this.viewMatrix);let[i,o,s]=e,l=n?n[0]:0,a=n?n[1]:0,c=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(l=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],a=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],c=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let f=r[0]*i+r[4]*o+r[8]*s+r[12],h=r[1]*i+r[5]*o+r[9]*s+r[13],d=r[2]*i+r[6]*o+r[10]*s+r[14],y=r[3]*i+r[7]*o+r[11]*s+r[15];if(y<=1e-4)return{x:0,y:0,z:1,visible:!1};let x=f/y,T=h/y,D=d/y,V=this.canvas.getBoundingClientRect(),b=V.width||this.canvas.clientWidth||this.canvas.width||300,_=V.height||this.canvas.clientHeight||this.canvas.height||150,S=(x*.5+.5)*b,U=(-T*.5+.5)*_,z=x>=-1.1&&x<=1.1&&T>=-1.1&&T<=1.1&&D>=-1&&D<=1;if(z&&n){let[I,E,R]=Bt(this),g=[i-I,o-E,s-R];l*g[0]+a*g[1]+c*g[2]>.05&&(z=!1)}return{x:S,y:U,z:D,visible:z}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let s=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*s[0]+o*l[0])*c,a[1]+=(-i*s[1]+o*l[1])*c,a[2]+=(-i*s[2]+o*l[2])*c,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),a=i.height>0?Math.floor((n-i.top)*(s/i.height)):Math.floor(n);return this.performMeshPick(l,a,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=De();Le(l,this.projMatrix,this.viewMatrix);let a=[],c=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(s-1,s-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==s)&&this.resizePickingFbo(o,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let z=0;z<this.meshes.length;z++){let I=this.meshes[z];if(I.visible===!1||I.isPluginMesh)continue;let E=z+1,R=(E&255)/255,g=(E>>8&255)/255,M=(E>>16&255)/255;i.uniform4f(this.uPick.uColorId,R,g,M,1),Le(this.modelMatrix,this.modelRootMatrix,I.transform);let P=I.instanceMatrices;if(P&&P.length>=16){let v=P.length>>4,p=De();for(let m of I.primitives){i.bindVertexArray(m.vao);for(let L=0;L<v;L++)Le(p,this.modelMatrix,P.subarray(L*16,L*16+16)),Le(this.mvpMatrix,l,p),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),un(i,m)}}else{Le(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let v of I.primitives)i.bindVertexArray(v.vao),un(i,v)}}let S=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,S),i.bindFramebuffer(36160,null);let U=S[0]+(S[1]<<8)+(S[2]<<16);U>0&&U<=this.meshes.length&&(a=[this.meshes[U-1]])}a.length===0&&(a=this.meshes.filter(S=>S.visible!==!1));let f=null,h=1/0,d=[0,0,0],y=[0,1,0],[x,T,D]=Bt(this),V=De();for(let S of a){Le(V,this.modelRootMatrix,S.transform);let U=S.instanceMatrices,z=U&&U.length>=16?U.length>>4:1;for(let I=0;I<z;I++){U&&U.length>=16?Le(this.modelMatrix,V,U.subarray(I*16,I*16+16)):this.modelMatrix.set(V),Le(this.mvpMatrix,l,this.modelMatrix);let E=De();if(!zr(E,this.mvpMatrix))continue;let R=(c+.5)/o*2-1,g=(u+.5)/s*2-1,M=[0,0,0],P=[0,0,0];qn(M,R,g,-1,E),qn(P,R,g,1,E);let v=P[0]-M[0],p=P[1]-M[1],m=P[2]-M[2],L=Math.hypot(v,p,m)||1,W=v/L,G=p/L,K=m/L,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Q=>{for(let q of S.primitives){if(!q.positions)continue;let ae=q.positions,O=q.indices,te=Math.floor(O?O.length/3:ae.length/9);for(let ue=0;ue<te;ue++){let le=O?O[ue*3]:ue*3,he=O?O[ue*3+1]:ue*3+1,ve=O?O[ue*3+2]:ue*3+2;Vr(M[0],M[1],M[2],W,G,K,ae[le*3],ae[le*3+1],ae[le*3+2],ae[he*3],ae[he*3+1],ae[he*3+2],ae[ve*3],ae[ve*3+1],ae[ve*3+2],k,Q)}}})(1e-4),isFinite(k.distance)){let Q=k.point[0],q=k.point[1],ae=k.point[2],O=this.modelMatrix,te=O[0]*Q+O[4]*q+O[8]*ae+O[12],ue=O[1]*Q+O[5]*q+O[9]*ae+O[13],le=O[2]*Q+O[6]*q+O[10]*ae+O[14],he=te-x,ve=ue-T,Me=le-D,pe=Math.hypot(he,ve,Me);if(pe<h){$e(this.normalMatrix,this.modelMatrix);let xe=this.normalMatrix,C=k.normal[0],w=k.normal[1],A=k.normal[2],N=xe[0]*C+xe[3]*w+xe[6]*A,F=xe[1]*C+xe[4]*w+xe[7]*A,B=xe[2]*C+xe[5]*w+xe[8]*A,$=Math.hypot(N,F,B)||1;N/=$,F/=$,B/=$,N*he+F*ve+B*Me>0&&(N=-N,F=-F,B=-B),f=S,h=Math.round(pe*1e3)/1e3,d=[Math.round(te*1e3)/1e3,Math.round(ue*1e3)/1e3,Math.round(le*1e3)/1e3],y=[Math.round(N*1e3)/1e3,Math.round(F*1e3)/1e3,Math.round(B*1e3)/1e3]}}}}if(!f)return null;let _={meshIndex:this.meshes.indexOf(f),meshName:f.name,nodeIndex:f.nodeIndex,distance:h,hitPoint:d,normal:y,screenX:e,screenY:n};if(r){for(let S of Oe)S.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(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,s=i?Math.max(1,n-r):r,l=(o+.5)/s*2-1;return Math.floor((l*.5+1)*.5*n)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);an(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center;Dt(this.viewMatrix,Bt(this),r,[0,1,0]),Le(this.mvpMatrix,this.projMatrix,this.viewMatrix),$e(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of Oe)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of Oe)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Oe)s.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of Oe)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let s={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,n,r,i,o=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:l,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:o})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let b=Math.max(2,this.canvas.width||2),_=Math.max(1,this.canvas.height||1),S=Math.max(1,Math.floor(b*.5)),U=Math.max(1,b-S),z=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),I=this.customTarget||this.bounds.center,[E,R,g]=Bt(this),M=Math.cos(this.currTheta),P=-Math.sin(this.currTheta),v=.032,p=De(),m=De(),L=[E-M*v,R,g-P*v],W=[I[0]-M*v*.25,I[1],I[2]-P*v*.25];an(p,this.fov,S/_,.1,z),Dt(m,L,W,[0,1,0]);let G=De(),K=De(),k=[E+M*v,R,g+P*v],ee=[I[0]+M*v*.25,I[1],I[2]+P*v*.25];an(G,this.fov,U/_,.1,z),Dt(K,k,ee,[0,1,0]),this.render({viewMatrix:m,projMatrix:p,eyePos:L,viewport:[0,0,S,_],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:K,projMatrix:G,eyePos:k,viewport:[S,0,U,_],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,b,_);return}let n=this.gl,r=0,i=0,o=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],s=e.viewport[3],n.viewport(r,i,o,s)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let l=De(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,Le(l,e?.projMatrix??this.projMatrix,a);let c=ke().xrDepthShader,u=zi(this.toneMapping),[f,h,d]=e?e.eyePos:Bt(this);for(let b of Oe)b.onBeforeDrawScene?.(this,n,l,[f,h,d],u);let y=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&y===0)return;let x=e?.eye||"none",T=!1,D=y>0?[...this.backdropMeshes,...this.meshes]:this.meshes,V=b=>{for(let _=0;_<D.length;_++){let S=D[_];if(S.visible===!1)continue;let U=this.selectedMeshName!==""&&S.name===this.selectedMeshName;_<y||S.worldSpace===!0||S.name==="__xr_reticle__"?this.modelMatrix.set(S.transform):Le(this.modelMatrix,this.modelRootMatrix,S.transform),Le(this.mvpMatrix,l,this.modelMatrix),$e(S.normalMatrix,this.modelMatrix);let z=S.extras?.xr?.stereo||S.userData?.xr?.stereo,I=0,E=0,R=1,g=1;z==="sbs"?(R=.5,I=x==="right"?.5:0):z==="ou"&&(g=.5,E=x==="right"?.5:0);for(let M of S.primitives){let P=!!M.isTransmissive;if(!b&&P){T=!0;continue}if(b&&!P)continue;let v=M.customProgram||this.renderProg,p=M.customUniforms||this.uRender;n.useProgram(v),n.uniform1i(p.uToneMapping,u),n.uniform1f(p.uEnvIntensity,this.envIntensity),p.uExposure&&n.uniform1f(p.uExposure,this.exposure),n.uniform3f(p.uCameraPos,f,h,d),n.uniform1f(p.uEmissive,U?1:0),n.uniformMatrix4fv(p.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(p.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(p.uNormalMatrix,!1,S.normalMatrix),p.uUvTransform&&n.uniform4f(p.uUvTransform,I,E,R,g),p.uViewportSize&&n.uniform2f(p.uViewportSize,Math.max(1,o),Math.max(1,s)),c?.bind(n,p,this.xrDepthState,a,[r,i,Math.max(1,o),Math.max(1,s)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(p.uEnvironmentMap,4),n.uniform1i(p.uHasEnvironmentMap,1)):n.uniform1i(p.uHasEnvironmentMap,0),this.bindLights(p),p.uSectionEnabled&&n.uniform1i(p.uSectionEnabled,0);for(let L of Oe)L.onBeforeDrawPrimitive?.(n,v,M,S,this.worldMatrices||[],this.gltf);n.uniform4fv(p.uBaseColor,M.baseColor),n.uniform1f(p.uMetallic,M.metallic),n.uniform1f(p.uRoughness,M.roughness),p.uClearcoat&&n.uniform2f(p.uClearcoat,M.clearcoat??0,M.clearcoatRoughness??.04),M.texture?(n.activeTexture(33984),n.bindTexture(3553,M.texture),n.uniform1i(p.uBaseColorTexture,0),n.uniform1i(p.uHasTexture,1)):n.uniform1i(p.uHasTexture,0),M.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,M.metallicRoughnessTexture),n.uniform1i(p.uMetallicRoughnessTexture,1),n.uniform1i(p.uHasMetallicRoughnessTexture,1)):n.uniform1i(p.uHasMetallicRoughnessTexture,0),M.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,M.normalTexture),n.uniform1i(p.uNormalTexture,2),n.uniform1i(p.uHasNormalTexture,1),n.uniform1f(p.uNormalScale,M.normalScale)):n.uniform1i(p.uHasNormalTexture,0),M.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,M.occlusionTexture),n.uniform1i(p.uOcclusionTexture,3),n.uniform1i(p.uHasOcclusionTexture,1),n.uniform1f(p.uOcclusionStrength,M.occlusionStrength)):n.uniform1i(p.uHasOcclusionTexture,0),n.bindVertexArray(M.vao);let m=S.instanceMatrices;if(m&&m.length>=16&&M.instanced&&p.uInstanced&&p.uViewProj){let L=m.length>>4;n.uniform1i(p.uInstanced,1),n.uniformMatrix4fv(p.uViewProj,!1,l),M.indices?n.drawElementsInstanced(4,M.indexCount,M.indexType,0,L):n.drawArraysInstanced(4,0,M.indexCount,L),n.uniform1i(p.uInstanced,0)}else if(m&&m.length>=16){let L=m.length>>4,W=S.instanceColors,G=De(),K=new Float32Array(9),k=[M.baseColor[0],M.baseColor[1],M.baseColor[2],M.baseColor[3]];for(let ee=0;ee<L;ee++)Le(G,this.modelMatrix,m.subarray(ee*16,ee*16+16)),Le(this.mvpMatrix,l,G),$e(K,G),n.uniformMatrix4fv(p.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(p.uModel,!1,G),n.uniformMatrix3fv(p.uNormalMatrix,!1,K),W&&(k[0]=M.baseColor[0]*W[ee*3],k[1]=M.baseColor[1]*W[ee*3+1],k[2]=M.baseColor[2]*W[ee*3+2],k[3]=M.baseColor[3],n.uniform4fv(p.uBaseColor,k)),un(n,M)}else un(n,M)}}};if(V(!1),T){for(let b of Oe)b.onBeforeTransmissivePass?.(n,this);V(!0)}for(let b of Oe)b.onAfterRender?.(n,this,l)}disposeMeshListGpuResources(e,n){Jr(this.gl,e,n)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of Oe)n.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};ln.registerPlugin=Ur,ln.getRegisteredPlugins=Or;function qi(t){return t+3&-4}function Zi(t,e=0){let n=(k,ee)=>typeof k=="number"&&Number.isFinite(k)?k:ee,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),s=n(t[e+0],1),l=n(t[e+1],0),a=n(t[e+2],0),c=n(t[e+4],0),u=n(t[e+5],1),f=n(t[e+6],0),h=n(t[e+8],0),d=n(t[e+9],0),y=n(t[e+10],1),x=Math.hypot(s,l,a),T=Math.hypot(c,u,f),D=Math.hypot(h,d,y);s*(u*y-d*f)-c*(l*y-d*a)+h*(l*f-u*a)<0&&(x=-x);let b=Math.abs(x)>1e-8?1/x:0,_=Math.abs(T)>1e-8?1/T:0,S=Math.abs(D)>1e-8?1/D:0,U=s*b,z=l*b,I=a*b,E=c*_,R=u*_,g=f*_,M=h*S,P=d*S,v=y*S,p=U+R+v,m=0,L=0,W=0,G=1;if(p>0){let k=.5/Math.sqrt(p+1);G=.25/k,m=(g-P)*k,L=(M-I)*k,W=(z-E)*k}else if(U>R&&U>v){let k=2*Math.sqrt(Math.max(0,1+U-R-v));k>1e-8&&(G=(g-P)/k,m=.25*k,L=(E+z)/k,W=(M+I)/k)}else if(R>v){let k=2*Math.sqrt(Math.max(0,1+R-U-v));k>1e-8&&(G=(M-I)/k,m=(E+z)/k,L=.25*k,W=(g+P)/k)}else{let k=2*Math.sqrt(Math.max(0,1+v-U-R));k>1e-8&&(G=(z-E)/k,m=(M+I)/k,L=(g+P)/k,W=.25*k)}let K=Math.hypot(m,L,W,G);return K>1e-8&&Number.isFinite(K)?(m/=K,L/=K,W/=K,G/=K):(m=0,L=0,W=0,G=1),{t:[r,i,o],r:[m,L,W,G],s:[x,T,D]}}function Qi(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function Nt(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],s=[],l=[],a=new Set,c=[],u=[],f=new Map,h=[],d=[];function y(E){let R=f.get(E);if(R!==void 0)return R;R=u.length,f.set(E,R);let g=E,M=g.color?.r??.8,P=g.color?.g??.8,v=g.color?.b??.8,p=g.opacity??1,m={name:g.name||"",pbrMetallicRoughness:{baseColorFactor:[M,P,v,p],metallicFactor:g.metalness??.1,roughnessFactor:g.roughness??.5},doubleSided:g.side===2||!!g.doubleSided};if(g.emissive&&(g.emissive.r>0||g.emissive.g>0||g.emissive.b>0)){let W=g.emissiveIntensity??1;m.emissiveFactor=[g.emissive.r*W,g.emissive.g*W,g.emissive.b*W]}let L={};return g.clearcoat&&g.clearcoat>0&&(L.KHR_materials_clearcoat={clearcoatFactor:g.clearcoat,clearcoatRoughnessFactor:g.clearcoatRoughness||0}),g.sheen&&g.sheen>0&&(L.KHR_materials_sheen={sheenColorFactor:g.sheenColor?[g.sheenColor.r,g.sheenColor.g,g.sheenColor.b]:[1,1,1],sheenRoughnessFactor:g.sheenRoughness||0}),g.transmission&&g.transmission>0&&(L.KHR_materials_transmission={transmissionFactor:g.transmission}),g.thickness&&g.thickness>0&&(L.KHR_materials_volume={thicknessFactor:g.thickness,attenuationDistance:g.attenuationDistance??1/0,attenuationColor:g.attenuationColor?[g.attenuationColor.r,g.attenuationColor.g,g.attenuationColor.b]:[1,1,1]}),g.ior!==void 0&&g.ior!==1.5&&(L.KHR_materials_ior={ior:g.ior}),g.dispersion&&g.dispersion>0&&(L.KHR_materials_dispersion={dispersion:g.dispersion}),g.iridescence&&g.iridescence>0&&(L.KHR_materials_iridescence={iridescenceFactor:g.iridescence,iridescenceIor:g.iridescenceIOR??1.3}),Object.keys(L).length>0&&(m.extensions=L),u.push(m),R}function x(E,R){let g=new Uint8Array(E.buffer,E.byteOffset,E.byteLength),M=qi(g.byteLength),P=new Uint8Array(M);P.set(g),n.push(P);let v=i.length;return i.push({buffer:0,byteOffset:r,byteLength:g.byteLength,target:R}),r+=M,v}function T(E,R,g,M,P,v,p){let m=x(E,g),L=o.length,W={bufferView:m,byteOffset:0,componentType:M,count:P,type:R};return v&&(W.min=v),p&&(W.max=p),o.push(W),L}t.traverse(E=>{(E.isLight||E.color&&E.intensity!==void 0)&&d.push({type:E.type,color:[E.color.r,E.color.g,E.color.b],intensity:E.intensity,position:[E.position.x,E.position.y,E.position.z]})});let D=[];function V(E){let R={name:E.name||""},g=E.position,M=E.quaternion,P=E.scale;if((g.x||g.y||g.z)&&(R.translation=[g.x,g.y,g.z]),(M.x||M.y||M.z||M.w!==1)&&(R.rotation=[M.x,M.y,M.z,M.w]),(P.x!==1||P.y!==1||P.z!==1)&&(R.scale=[P.x,P.y,P.z]),E.userData&&Object.keys(E.userData).length>0&&(R.extras=JSON.parse(JSON.stringify(E.userData,(p,m)=>{if(!(p==="__proto__"||p==="prototype"||p==="constructor"))return typeof m=="function"?void 0:m})),E.userData.xr)){let p=Qi(E.userData.xr);R.extensions={...R.extensions||{},MOZ_hubs_components:p,ANDROID_xr_scenecore:p},ke().xrTraitSerializer?.gltfNode(R,E.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(E.geometry){let p=E.geometry,m=p.attributes.position;if(m&&m.count>0){let L=[1/0,1/0,1/0],W=[-1/0,-1/0,-1/0];for(let q=0;q<m.count;q++){let ae=m.getX(q),O=m.getY(q),te=m.getZ(q);ae<L[0]&&(L[0]=ae),ae>W[0]&&(W[0]=ae),O<L[1]&&(L[1]=O),O>W[1]&&(W[1]=O),te<L[2]&&(L[2]=te),te>W[2]&&(W[2]=te)}let K={attributes:{POSITION:T(m.array,"VEC3",34962,5126,m.count,L,W)}};if(p.attributes.normal&&(K.attributes.NORMAL=T(p.attributes.normal.array,"VEC3",34962,5126,p.attributes.normal.count)),p.attributes.uv&&(K.attributes.TEXCOORD_0=T(p.attributes.uv.array,"VEC2",34962,5126,p.attributes.uv.count)),p.index){let q=p.index.array instanceof Uint32Array;K.indices=T(p.index.array,"SCALAR",34963,q?5125:5123,p.index.count)}E.material&&(K.material=y(E.material));let k=E.userData?.variants;if(k&&typeof k=="object"){let q=new Map;for(let ae of Object.keys(k)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let O=k[ae];if(!O||typeof O!="object")continue;let te=h.indexOf(ae);if(te===-1&&h.length<256&&(te=h.length,h.push(ae)),te===-1)continue;let ue=y(O),le=q.get(ue);le||(le=[],q.set(ue,le)),le.push(te)}if(q.size>0){let ae=[];for(let[O,te]of q.entries())ae.push({material:O,variants:te});K.extensions={...K.extensions||{},KHR_materials_variants:{mappings:ae}},a.add("KHR_materials_variants")}}let ee=E;if(ee.isInstancedMesh&&typeof ee.count=="number"&&ee.count>0&&ee.instanceMatrix?.array){let q=Math.min(1e4,Math.floor(ee.count)),ae=ee.instanceMatrix.array,O=new Float32Array(q*3),te=new Float32Array(q*4),ue=new Float32Array(q*3);for(let he=0;he<q;he++){let{t:ve,r:Me,s:pe}=Zi(ae,he*16);O[he*3]=ve[0],O[he*3+1]=ve[1],O[he*3+2]=ve[2],te[he*4]=Me[0],te[he*4+1]=Me[1],te[he*4+2]=Me[2],te[he*4+3]=Me[3],ue[he*3]=pe[0],ue[he*3+1]=pe[1],ue[he*3+2]=pe[2]}let le={TRANSLATION:T(O,"VEC3",0,5126,q),ROTATION:T(te,"VEC4",0,5126,q),SCALE:T(ue,"VEC3",0,5126,q)};if(ee.instanceColor?.array&&ee.instanceColor.array.length>=q*3){let he=new Float32Array(ee.instanceColor.array.subarray(0,q*3));le._COLOR_0=T(he,"VEC3",0,5126,q)}R.extensions={...R.extensions||{},EXT_mesh_gpu_instancing:{attributes:le}},a.add("EXT_mesh_gpu_instancing")}let Q=s.length;s.push({primitives:[K],name:E.name,...R.extras?{extras:R.extras}:{}}),R.mesh=Q}}let v=l.length;if(l.push(R),c.push(E),E.children.length>0){R.children=[];for(let p of E.children)R.children.push(V(p))}return v}for(let E of t.children)D.push(V(E));let b=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),_=[];if(typeof b=="function"&&c.length>0){let E=e?.duration??4,R=e?.fps??15,g=Math.max(2,Math.round(E*R)+1),M=new Float32Array(g),P=c.map(k=>({px:k.position.x,py:k.position.y,pz:k.position.z,qx:k.quaternion.x,qy:k.quaternion.y,qz:k.quaternion.z,qw:k.quaternion.w,sx:k.scale.x,sy:k.scale.y,sz:k.scale.z})),v=c.map(()=>new Float32Array(g*3)),p=c.map(()=>new Float32Array(g*4)),m=c.map(()=>new Float32Array(g*3));for(let k=0;k<g;k++){let ee=k/(g-1)*E;M[k]=ee;try{b(ee)}catch{}for(let Q=0;Q<c.length;Q++){let q=c[Q];v[Q][k*3]=q.position.x,v[Q][k*3+1]=q.position.y,v[Q][k*3+2]=q.position.z,p[Q][k*4]=q.quaternion.x,p[Q][k*4+1]=q.quaternion.y,p[Q][k*4+2]=q.quaternion.z,p[Q][k*4+3]=q.quaternion.w,m[Q][k*3]=q.scale.x,m[Q][k*3+1]=q.scale.y,m[Q][k*3+2]=q.scale.z}}for(let k=0;k<c.length;k++){let ee=c[k],Q=P[k];ee.position.set(Q.px,Q.py,Q.pz),ee.quaternion.set(Q.qx,Q.qy,Q.qz,Q.qw),ee.scale.set(Q.sx,Q.sy,Q.sz)}t.updateMatrixWorld(!0);let L=null,W=()=>(L===null&&(L=T(M,"SCALAR",0,5126,g,[0],[E])),L),G=[],K=[];for(let k=0;k<c.length;k++){let ee=P[k],Q=!1,q=!1,ae=!1;for(let O=0;O<g;O++)(Math.abs(v[k][O*3]-ee.px)>1e-4||Math.abs(v[k][O*3+1]-ee.py)>1e-4||Math.abs(v[k][O*3+2]-ee.pz)>1e-4)&&(Q=!0),(Math.abs(p[k][O*4]-ee.qx)>1e-4||Math.abs(p[k][O*4+1]-ee.qy)>1e-4||Math.abs(p[k][O*4+2]-ee.qz)>1e-4||Math.abs(p[k][O*4+3]-ee.qw)>1e-4)&&(q=!0),(Math.abs(m[k][O*3]-ee.sx)>1e-4||Math.abs(m[k][O*3+1]-ee.sy)>1e-4||Math.abs(m[k][O*3+2]-ee.sz)>1e-4)&&(ae=!0);if(Q){let O=T(v[k],"VEC3",0,5126,g),te=G.length;G.push({input:W(),interpolation:"LINEAR",output:O}),K.push({sampler:te,target:{node:k,path:"translation"}})}if(q){let O=T(p[k],"VEC4",0,5126,g),te=G.length;G.push({input:W(),interpolation:"LINEAR",output:O}),K.push({sampler:te,target:{node:k,path:"rotation"}})}if(ae){let O=T(m[k],"VEC3",0,5126,g),te=G.length;G.push({input:W(),interpolation:"LINEAR",output:O}),K.push({sampler:te,target:{node:k,path:"scale"}})}}K.length>0&&_.push({name:"ProceduralLoop",samplers:G,channels:K})}let S=on(l,s,t.userData),U={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:D}],scene:0,nodes:l,meshes:s,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],..._.length>0?{animations:_}:{},...S||a.size>0?{extensionsUsed:[...S?["KHR_interactivity"]:[],...a]}:{},...S||h.length>0?{extensions:{...S?{KHR_interactivity:S}:{},...h.length>0?{KHR_materials_variants:{variants:h.map(E=>({name:E}))}}:{}}}:{}},z=new Uint8Array(r),I=0;for(let E of n)z.set(E,I),I+=E.byteLength;return{gltf:U,bin:z.buffer,lights:d,environmentIntensity:t.environmentIntensity}}function fn(t){return new TextEncoder().encode(t)}function Ht(t,e){let{gltf:n,bin:r}=Nt(t,e),i=JSON.stringify(n),o=fn(i),s=(4-o.byteLength%4)%4,l=o.byteLength+s,a=20+l+8+r.byteLength,c=new Uint8Array(a),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,a,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),c.set(o,20);for(let h=0;h<s;h++)c[20+o.byteLength+h]=32;let f=20+l;return u.setUint32(f,r.byteLength,!0),u.setUint32(f+4,5130562,!0),c.set(new Uint8Array(r),f+8),c}function Ji(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let s=o.count,l=new Float32Array(s*3),a=r.matrixWorld.elements;for(let I=0;I<s;I++){let E=o.getX(I),R=o.getY(I),g=o.getZ(I);l[I*3]=a[0]*E+a[4]*R+a[8]*g+a[12],l[I*3+1]=a[1]*E+a[5]*R+a[9]*g+a[13],l[I*3+2]=a[2]*E+a[6]*R+a[10]*g+a[14]}let c;if(i.attributes.normal){let I=i.attributes.normal;c=new Float32Array(s*3);let E=new Float32Array(9);$e(E,a);for(let R=0;R<s;R++){let g=I.getX(R),M=I.getY(R),P=I.getZ(R),v=E[0]*g+E[3]*M+E[6]*P,p=E[1]*g+E[4]*M+E[7]*P,m=E[2]*g+E[5]*M+E[8]*P,L=Math.hypot(v,p,m)||1;c[R*3]=v/L,c[R*3+1]=p/L,c[R*3+2]=m/L}}let u;if(i.attributes.uv){let I=i.attributes.uv;u=new Float32Array(s*2);for(let E=0;E<s;E++)u[E*2]=I.getX(E),u[E*2+1]=I.getY(E)}let f;if(i.index)f=i.index.array;else{f=s>65535?new Uint32Array(s):new Uint16Array(s);for(let I=0;I<s;I++)f[I]=I}let h="DefaultMaterial",d=[.8,.8,.8],y=.5,x=.1,T=0,D=0,V=1.5,b=1,_=[0,0,0];if(r.material){let I=r.material;h=I.name||`Material_${n.length}`,I.color&&(d=[I.color.r,I.color.g,I.color.b]),typeof I.roughness=="number"&&(y=I.roughness),typeof I.metalness=="number"&&(x=I.metalness),typeof I.clearcoat=="number"&&(T=I.clearcoat),typeof I.clearcoatRoughness=="number"&&(D=I.clearcoatRoughness),typeof I.ior=="number"&&(V=I.ior);let E=typeof I.opacity=="number"?I.opacity:1,R=typeof I.transmission=="number"?I.transmission:0;if(b=E*(1-R),I.emissive&&(I.emissive.r>0||I.emissive.g>0||I.emissive.b>0)){let g=I.emissiveIntensity??1;_=[I.emissive.r*g,I.emissive.g*g,I.emissive.b*g]}}let S,U=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 U=="function"){let I=e?.duration??4,E=e?.fps??4,R=Math.max(2,Math.round(I*E)+1),g=[],M=[],P=[],v=[],p=[r.position.x,r.position.y,r.position.z],m=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],L=[r.scale.x,r.scale.y,r.scale.z],W=!1;for(let G=0;G<R;G++){let K=G/(R-1)*I;g.push(K);try{U(K)}catch{}M.push([r.position.x,r.position.y,r.position.z]),P.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),v.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-p[0])>1e-4||Math.abs(r.position.y-p[1])>1e-4||Math.abs(r.position.z-p[2])>1e-4||Math.abs(r.quaternion.x-m[0])>1e-4||Math.abs(r.quaternion.y-m[1])>1e-4||Math.abs(r.quaternion.z-m[2])>1e-4||Math.abs(r.quaternion.w-m[3])>1e-4||Math.abs(r.scale.x-L[0])>1e-4)&&(W=!0)}r.position.set(p[0],p[1],p[2]),r.quaternion.set(m[0],m[1],m[2],m[3]),r.scale.set(L[0],L[1],L[2]),W&&(S={times:g,translations:M,rotations:P,scales:v})}let z=r;if(z.isInstancedMesh&&typeof z.count=="number"&&z.count>0&&z.instanceMatrix?.array){let I=Math.min(1e3,Math.floor(z.count)),E=z.instanceMatrix.array,R=z.instanceColor?.array,g=r.name||`Mesh_${n.length}`,M=new Float32Array(16),P=new Float32Array(9);for(let v=0;v<I;v++){let p=E.subarray(v*16,(v+1)*16);Le(M,a,p);let m=new Float32Array(s*3);for(let K=0;K<s;K++){let k=o.getX(K),ee=o.getY(K),Q=o.getZ(K);m[K*3]=M[0]*k+M[4]*ee+M[8]*Q+M[12],m[K*3+1]=M[1]*k+M[5]*ee+M[9]*Q+M[13],m[K*3+2]=M[2]*k+M[6]*ee+M[10]*Q+M[14]}let L;if(i.attributes.normal){let K=i.attributes.normal;L=new Float32Array(s*3),$e(P,M);for(let k=0;k<s;k++){let ee=K.getX(k),Q=K.getY(k),q=K.getZ(k),ae=P[0]*ee+P[3]*Q+P[6]*q,O=P[1]*ee+P[4]*Q+P[7]*q,te=P[2]*ee+P[5]*Q+P[8]*q,ue=Math.hypot(ae,O,te)||1;L[k*3]=ae/ue,L[k*3+1]=O/ue,L[k*3+2]=te/ue}}let W=d,G=h;R&&R.length>=(v+1)*3&&(W=[d[0]*R[v*3],d[1]*R[v*3+1],d[2]*R[v*3+2]],G=`${h}_inst_${v}`),n.push({name:`${g}_${v}`,positions:m,indices:f,normals:L,uvs:u,materialName:G,color:W,roughness:y,metallic:x,clearcoat:T,clearcoatRoughness:D,ior:V,opacity:b,emissiveColor:_,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:l,indices:f,normals:c,uvs:u,materialName:h,color:d,roughness:y,metallic:x,clearcoat:T,clearcoatRoughness:D,ior:V,opacity:b,emissiveColor:_,xrTraits:r.userData?.xr,timeSamples:S})}}),n}function ni(t){let e=[],n=t.gltf,r=ke().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,t);let i=t.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=n.accessors||[],l=n.bufferViews||[],a=n.materials||[],c=n.meshes||[],u=n.nodes||[];function f(y){let x=s[y];if(!x)throw new Error(`Accessor ${y} not found`);let T=l[x.bufferView||0],D=(T.byteOffset||0)+(x.byteOffset||0),V=T.byteLength||0,b=o.slice(D,D+V);return{acc:x,buffer:b}}let h=new Map;if(u.length>0){let y=cn(n);for(let x=0;x<y.length;x++)h.set(x,y[x])}function d(y,x,T,D){let V=c[y];if(!V)return;let b=new Float32Array(9);$e(b,x);for(let _=0;_<(V.primitives||[]).length;_++){let S=V.primitives[_],U=S.attributes?.POSITION;if(U===void 0)continue;let{acc:z,buffer:I}=f(U),E=new Float32Array(I,0,z.count*3),R=new Float32Array(E.length);for(let O=0;O<z.count;O++){let te=E[O*3],ue=E[O*3+1],le=E[O*3+2];R[O*3]=x[0]*te+x[4]*ue+x[8]*le+x[12],R[O*3+1]=x[1]*te+x[5]*ue+x[9]*le+x[13],R[O*3+2]=x[2]*te+x[6]*ue+x[10]*le+x[14]}let g,M=S.attributes?.NORMAL;if(M!==void 0){let{acc:O,buffer:te}=f(M),ue=new Float32Array(te,0,O.count*3);g=new Float32Array(ue.length);for(let le=0;le<O.count;le++){let he=ue[le*3],ve=ue[le*3+1],Me=ue[le*3+2],pe=b[0]*he+b[3]*ve+b[6]*Me,xe=b[1]*he+b[4]*ve+b[7]*Me,C=b[2]*he+b[5]*ve+b[8]*Me,w=Math.hypot(pe,xe,C)||1;g[le*3]=pe/w,g[le*3+1]=xe/w,g[le*3+2]=C/w}}let P,v=S.attributes?.TEXCOORD_0;if(v!==void 0){let{acc:O,buffer:te}=f(v);P=new Float32Array(te,0,O.count*2)}let p;if(S.indices!==void 0){let{acc:O,buffer:te}=f(S.indices);O.componentType===5125?p=new Uint32Array(te,0,O.count):p=new Uint16Array(te,0,O.count);let ue=z.count;for(let le of p)if(le>=ue)throw new Error(`SecurityError: Index buffer value (${le}) out of vertex bounds [0, ${ue}).`)}else{let O=z.count;p=O>65535?new Uint32Array(O):new Uint16Array(O);for(let te=0;te<O;te++)p[te]=te}let m="DefaultMaterial",L=[.8,.8,.8],W=.5,G=.1,K=0,k=0,ee=1.5,Q=1,q=[0,0,0];if(S.material!==void 0&&a[S.material]){let O=a[S.material];m=O.name||`Material_${S.material}`;let te=O.pbrMetallicRoughness||{},ue=1;Array.isArray(te.baseColorFactor)&&(L=[te.baseColorFactor[0],te.baseColorFactor[1],te.baseColorFactor[2]],typeof te.baseColorFactor[3]=="number"&&(ue=te.baseColorFactor[3])),typeof te.roughnessFactor=="number"&&(W=te.roughnessFactor),typeof te.metallicFactor=="number"&&(G=te.metallicFactor),Array.isArray(O.emissiveFactor)&&O.emissiveFactor.length>=3&&(q=[O.emissiveFactor[0],O.emissiveFactor[1],O.emissiveFactor[2]]);let le=O.extensions||{};le.KHR_materials_clearcoat&&(K=le.KHR_materials_clearcoat.clearcoatFactor??0,k=le.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),le.KHR_materials_ior&&typeof le.KHR_materials_ior.ior=="number"&&(ee=le.KHR_materials_ior.ior);let he=le.KHR_materials_transmission?.transmissionFactor??0;Q=ue*(1-he)}let ae=(V.primitives||[]).length>1?`${T}_p${_}`:T;e.push({name:ae,positions:R,indices:p,normals:g,uvs:P,materialName:m,color:L,roughness:W,metallic:G,clearcoat:K,clearcoatRoughness:k,ior:ee,opacity:Q,emissiveColor:q,xrTraits:D?.xr||V.extras?.xr})}}if(u.length>0)for(let y=0;y<u.length;y++){let x=u[y];if(x.mesh!==void 0&&x.mesh<c.length){let T=h.get(y)||De(),D=x.name||c[x.mesh].name||`Node_${y}`,V=x.extensions?.EXT_mesh_gpu_instancing?.attributes;if(V&&typeof V=="object"){let b=V.TRANSLATION,_=V.ROTATION,S=V.SCALE,U=b!==void 0?(()=>{let{acc:R,buffer:g}=f(b);return new Float32Array(g,0,R.count*3)})():null,z=_!==void 0?(()=>{let{acc:R,buffer:g}=f(_);return new Float32Array(g,0,R.count*4)})():null,I=S!==void 0?(()=>{let{acc:R,buffer:g}=f(S);return new Float32Array(g,0,R.count*3)})():null,E=Math.min(1e3,U?U.length/3:z?z.length/4:I?I.length/3:0);if(E>0){let R=new Float32Array(16),g=new Float32Array(16);for(let M=0;M<E;M++){let P=U?[U[M*3],U[M*3+1],U[M*3+2]]:[0,0,0],v=z?[z[M*4],z[M*4+1],z[M*4+2],z[M*4+3]]:[0,0,0,1],p=I?[I[M*3],I[M*3+1],I[M*3+2]]:[1,1,1];vt(R,v,P,p),Le(g,T,R),d(x.mesh,g,`${D}_${M}`,x.extras)}continue}}d(x.mesh,T,D,x.extras)}}else{let y=De();for(let x=0;x<c.length;x++){let T=c[x].name||`Mesh_${x}`;d(x,y,T,c[x].extras)}}return e}function ir(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function ei(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Te(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function ti(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Te(t[r*3])}, ${Te(t[r*3+1])}, ${Te(t[r*3+2])})`;return n.join(", ")}function eo(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Te(t[r*2])}, ${Te(1-t[r*2+1])})`;return n.join(", ")}function to(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function or(t){let e=new Map;for(let a of t){let c=ir(a.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,r=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let c=a.timeSamples.times[a.timeSamples.times.length-1];c>n&&(n=c)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
253
|
+
void main(){fragColor=uColorId;}`;function nr(t,e,n){let r={};for(let i of n)r[i]=t.getUniformLocation(e,i);return r}var Gr=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function Yr(){let t=Ie().xrDepthShader;return{fs:Hi.replace("/*XRD_U*/",t?.uniformsGLSL||"").replace("/*XRD_O*/",t?.occlusionGLSL||""),uniforms:t?[...Gr,...t.uniformNames]:Gr}}function ji(t){if(typeof t!="string")return null;let e=t.trim();if(!e||/[\x00-\x1f\x7f]/.test(e))return null;let n=e.toLowerCase();return n.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(e)?e:null:n.startsWith("https://")||n.startsWith("blob:")?e:n.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(e)||/(^|[\\/])\.\.([\\/]|$)/.test(e)?null:e}function Jn(t,e,n,r,i,o,s,l){if(r===void 0||!e.accessors?.[r])return null;let a=Qn(e,n,e.accessors[r],o);if(!a)return null;l&&(a=a.slice(),Br(a,l));let c=t.createBuffer();return s.push(c),t.bindBuffer(34962,c),t.bufferData(34962,a,35044),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,o,5126,!1,0,0),a}function er(t){let e=Number(t);return Number.isFinite(e)?Math.max(0,e):1}function Kr(t,e,n){let r=Yr(),i=Wr,o=r.fs,s=!1;for(let a of Ue)if(a.onResolveShader){let c=a.onResolveShader(e,n,i,o);c&&(i=c.vs,o=c.fs,s=!0)}let l=s?un(t,i,o):null;return{program:l,uniforms:l?nr(t,l,r.uniforms):null}}function Wi(t,e,n){let r=e.instanceMatrices;if(!r||r.length<16||typeof t.vertexAttribDivisor!="function"||typeof t.drawElementsInstanced!="function")return!1;let i=r.length>>4,o=e.instanceColors,s=new Float32Array(i*20);for(let a=0;a<i;a++)s.set(r.subarray(a*16,a*16+16),a*20),s[a*20+16]=o?o[a*3]:1,s[a*20+17]=o?o[a*3+1]:1,s[a*20+18]=o?o[a*3+2]:1,s[a*20+19]=1;let l=t.createBuffer();n.push(l),t.bindBuffer(34962,l),t.bufferData(34962,s,35044);for(let a=0;a<5;a++)t.enableVertexAttribArray(8+a),t.vertexAttribPointer(8+a,4,5126,!1,80,a*16),t.vertexAttribDivisor(8+a,1);return!0}function Yi(t,e){let n=t.materials?.[e?.material];if(!n)return null;let r=[n.pbrMetallicRoughness?.baseColorTexture,n.pbrMetallicRoughness?.metallicRoughnessTexture,n.normalTexture,n.occlusionTexture,n.emissiveTexture];for(let i of r){let o=i?.extensions?.KHR_texture_transform;if(o&&typeof o=="object")return o}return null}var Is=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),qr=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ln(t,e){e.indices?t.drawElements(4,e.indexCount,e.indexType,0):t.drawArrays(4,0,e.indexCount)}function Zr(t,e){let n=t?.pbrMetallicRoughness,r=n?.baseColorFactor,i=t?.extensions?.KHR_materials_clearcoat,o=s=>s!==void 0&&e[s.index]?e[s.index]:null;return{baseColor:r?[r[0],r[1],r[2],r[3]??1]:[.8,.8,.8,1],metallic:n?.metallicFactor??.1,roughness:n?.roughnessFactor??.5,clearcoat:i?i.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,i?.clearcoatRoughnessFactor??.04),texture:o(n?.baseColorTexture),metallicRoughnessTexture:o(n?.metallicRoughnessTexture),normalTexture:o(t?.normalTexture),normalScale:t?.normalTexture?.scale??1,occlusionTexture:o(t?.occlusionTexture),occlusionStrength:t?.occlusionTexture?.strength??1,isTransmissive:(t?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function Qr(t,e,n){let r=new Set,i=o=>{o&&!r.has(o)&&(r.add(o),t.deleteTexture(o))};for(let o of e)for(let s of o.primitives){if(s.vao&&t.deleteVertexArray(s.vao),s.buffers)for(let a of s.buffers)t.deleteBuffer(a);i(s.texture),i(s.metallicRoughnessTexture),i(s.normalTexture),i(s.occlusionTexture);let l=new Set;s.customProgram&&l.add(s.customProgram);for(let a of s.programCache?.values()??[])a.program&&l.add(a.program);for(let a of l)t.deleteProgram(a)}if(n)for(let o of n)i(o)}function Hr(t,e,n=qr,r){let i={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return Ki(t,e,n,r,i)}catch(o){let s=i.mesh&&!i.meshes.includes(i.mesh)?[...i.meshes,i.mesh]:i.meshes;Qr(t,s,i.gpuTextures),i.vao&&t.deleteVertexArray(i.vao);for(let l of i.buffers)t.deleteBuffer(l);throw o}}function Ki(t,e,n,r,i){if(!e||!e.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:o}=e,s=Lt("meshopt");s?.decodeBufferViews&&s.decodeBufferViews(o,e);let l=e.bin,a=[];i.meshes=a;let c=[],u=o.extensions?.KHR_materials_variants;u&&Array.isArray(u.variants)&&u.variants.forEach((T,N)=>{c.push(typeof T?.name=="string"&&T.name?T.name:`Variant_${N}`)});let m=cn(o),f=[];if(Array.isArray(o.nodes))for(let T=0;T<o.nodes.length;T++){let N=o.nodes[T];N.mesh!==void 0&&o.meshes&&o.meshes[N.mesh]&&f.push({node:N,nodeIdx:T,meshIdx:N.mesh})}let d=f.length>0?f:(o.meshes||[]).map((T,N)=>({node:T,nodeIdx:-1,meshIdx:N})),g=[];if(Array.isArray(e.lights)&&e.lights.length>0)g.push(...e.lights);else if(o.extensions?.KHR_lights_punctual?.lights){let T=o.extensions.KHR_lights_punctual.lights;for(let N of T){let v=N.type==="directional"?"directional":N.type==="point"?"point":"ambient";g.push({type:v,color:N.color||[1,1,1],intensity:N.intensity!==void 0?N.intensity:1})}}if(g.length===0&&(g.push({type:"ambient",color:[1,1,1],intensity:.35}),g.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>n.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${n.maxMeshes}). Found: ${d.length}`);let y=[];if(i.gpuTextures=y,o.textures&&o.images){if(o.textures.length>n.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${n.maxTextures}). Found: ${o.textures.length}`);for(let T=0;T<o.textures.length;T++){let N=o.textures[T],v=o.images[N.source];if(v){let D=t.createTexture();if(t.bindTexture(3553,D),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),v.bufferView!==void 0){let h=o.bufferViews[v.bufferView],A=l.slice(h.byteOffset||0,(h.byteOffset||0)+h.byteLength),$=new Blob([A],{type:v.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap($).then(V=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,V),t.generateMipmap(3553),r?.()}).catch(()=>{})}else if(v.uri){let h=ji(v.uri);if(h){let A=new Image;A.crossOrigin="anonymous",A.referrerPolicy="no-referrer",A.onload=()=>{t.bindTexture(3553,D),t.texImage2D(3553,0,6408,6408,5121,A),t.generateMipmap(3553),r?.()},A.src=h}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",v.uri)}y.push(D)}else y.push(null)}}let M=[1/0,1/0,1/0],L=[-1/0,-1/0,-1/0],G=0,p=0;for(let T=0;T<d.length;T++){let N=d[T],v=o.meshes[N.meshIdx],D=N.nodeIdx>=0?m[N.nodeIdx]:ke(),h=new Float32Array(9);$e(h,D);let A={name:N.node.name||v.name||`Mesh_${N.meshIdx}`,nodeIndex:N.nodeIdx,transform:D,normalMatrix:h,primitives:[],extras:N.node.extras||v.extras};i.mesh=A;let $=N.node?.extensions?.EXT_mesh_gpu_instancing;if($&&$.attributes&&typeof $.attributes=="object"){let V=$.attributes,K=V.TRANSLATION!==void 0?o.accessors?.[V.TRANSLATION]:null,k=V.ROTATION!==void 0?o.accessors?.[V.ROTATION]:null,ee=V.SCALE!==void 0?o.accessors?.[V.SCALE]:null,Q=V._COLOR_0!==void 0?o.accessors?.[V._COLOR_0]:null,q=Number(K?.count??k?.count??ee?.count??0);if(!Number.isFinite(q)||q<0||q>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${q}`);if(q>0){let ae=(pe,ge)=>{if(!pe||pe.bufferView===void 0||!o.bufferViews?.[pe.bufferView])return null;let S=pe.componentType??5126,x=U=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${U})`),null);if(S!==5120&&S!==5121&&S!==5122&&S!==5123&&S!==5126)return x(`componentType ${S}`);if(!(Number(pe.count)>=q))return x(`count ${pe.count} < ${q}`);let w=null;try{w=Qn(o,l,{...pe,count:q},ge)}catch{return x("out of bounds")}return!w||!w.every(Number.isFinite)?x("non-finite value"):w},F=ae(K,3),te=ae(k,4),ue=ae(ee,3),le=Q?.type==="VEC4"?4:3,he=ae(Q,le),xe=new Float32Array(q*16),Me=ke();for(let pe=0;pe<q;pe++){let ge=F?[F[pe*3],F[pe*3+1],F[pe*3+2]]:[0,0,0],S=te?[te[pe*4],te[pe*4+1],te[pe*4+2],te[pe*4+3]]:[0,0,0,1],x=ue?[ue[pe*3],ue[pe*3+1],ue[pe*3+2]]:[1,1,1];vt(Me,S,ge,x),xe.set(Me,pe*16)}if(A.instanceMatrices=xe,he){let pe=new Float32Array(q*3);for(let ge=0;ge<q;ge++)pe[ge*3]=he[ge*le],pe[ge*3+1]=he[ge*le+1],pe[ge*3+2]=he[ge*le+2];A.instanceColors=pe}}}for(let V of v.primitives||[]){if(V.extensions?.KHR_draco_mesh_compression){let w=Lt("draco");w&&w.decodePrimitive(o,V,l)}let K=[],k=t.createVertexArray();i.vao=k,i.buffers=K,t.bindVertexArray(k);let ee=Wi(t,A,K),Q=o.accessors[V.attributes.POSITION],q=Number(Q?.count??0);if(!Number.isFinite(q)||q<0||G+q>n.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${n.maxVertices}).`);if(G+=q,Q?.min&&Q?.max){let w=U=>{for(let O=0;O<3;O++){let H=U[12+O],X=U[12+O];for(let j=0;j<3;j++){let Y=U[j*4+O]*Q.min[j],B=U[j*4+O]*Q.max[j];H+=Y<B?Y:B,X+=Y>B?Y:B}H<M[O]&&(M[O]=H),X>L[O]&&(L[O]=X)}};if(A.instanceMatrices&&A.instanceMatrices.length>=16){let U=A.instanceMatrices.length>>4,O=ke();for(let H=0;H<U;H++){let X=A.instanceMatrices.subarray(H*16,H*16+16);De(O,D,X),w(O)}}else w(D)}let ae=Jn(t,o,l,V.attributes.POSITION,0,3,K);Jn(t,o,l,V.attributes.NORMAL,1,3,K),Jn(t,o,l,V.attributes.TEXCOORD_0,2,2,K,Yi(o,V));let F=0,te=5123,ue=null;if(V.indices!==void 0){let w=o.accessors[V.indices],O=(o.bufferViews[w.bufferView].byteOffset||0)+(w.byteOffset||0);if(F=Number(w.count??0),!Number.isFinite(F)||F<0||p+F>n.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${n.maxIndices}).`);p+=F,te=w.componentType===5125?5125||5125:5123||5123;let H=t.createBuffer();K.push(H),t.bindBuffer(34963,H),w.componentType===5125?(ue=new Uint32Array(l,O,w.count),t.bufferData(34963,ue,35044)):w.componentType===5121?(ue=Uint16Array.from(new Uint8Array(l,O,w.count)),t.bufferData(34963,ue,35044)):(ue=O%2===0?new Uint16Array(l,O,w.count):new Uint16Array(l.slice(O,O+w.count*2)),t.bufferData(34963,ue,35044))}else F=Q.count;let le={};for(let w of Ue)if(w.onBuildPrimitiveVAO){let U=w.onBuildPrimitiveVAO(t,k,V,o,l);U&&(le[w.name]=U)}t.bindVertexArray(null);let he=o.materials&&V.material!==void 0?o.materials[V.material]:null,{program:xe,uniforms:Me}=Kr(t,V,he),pe=Zr(he,y),ge=!!(he?.extensions?.KHR_materials_transmission||le.materials?.isTransmissive),S=V.extensions?.KHR_materials_variants?.mappings,x=Array.isArray(S)?S.filter(w=>w&&typeof w.material=="number"&&Array.isArray(w.variants)).map(w=>({material:w.material|0,variants:w.variants.map(U=>Number(U)|0)})):void 0;A.primitives.push({vao:k,instanced:ee,indexCount:F,indexType:te,...pe,positions:ae,indices:ue,buffers:K,materialIndex:V.material,defaultMaterialIndex:V.material,variantMappings:x,primitiveDef:V,programCache:new Map([[V.material??-1,{program:xe,uniforms:Me}]]),pluginData:le,customProgram:xe,customUniforms:Me,isTransmissive:ge})}a.push(A)}isFinite(M[0])||(M=[-1,-1,-1]),isFinite(L[0])||(L=[1,1,1]);let E=[(M[0]+L[0])/2,(M[1]+L[1])/2,(M[2]+L[2])/2],_=L[0]-M[0],P=L[1]-M[1],z=L[2]-M[2],R=Math.max(Math.hypot(_,P,z)/2,.5),C=[M[0],M[1],M[2]],I=[L[0],L[1],L[2]],b=e.animations;if(!b){for(let T of Ue)if(T.onParseGLB?.(e),e.animations){b=e.animations;break}}return b||(b=[]),{meshes:a,bounds:{center:E,radius:R,min:C,max:I},lights:g,animations:b,worldMatrices:m,gpuTextures:y,availableVariants:c}}function Bt(t){let e=t.customTarget||t.bounds.center,n=t.currDistance*Math.cos(t.currPhi);return[e[0]+n*Math.sin(t.currTheta),e[1]+t.currDistance*Math.sin(t.currPhi),e[2]+n*Math.cos(t.currTheta)]}var hn=class{constructor(e,n,r){this.supportsInstanceOffsets=!0;this.meshes=[];this.backdropMeshes=[];this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]};this.lights=[];this.modelRootMatrix=ke();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=ke();this.viewMatrix=ke();this.activeViewMatrix=null;this.modelMatrix=ke();this.mvpMatrix=ke();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:ke(),rawValueToMeters:.001,format:0};this.container=e;let i,o;if(n&&typeof n.getContext=="function"?(i=n,o=r):(o=n,i=o?.canvas),!i){let a=e.querySelector("canvas");a||(a=document.createElement("canvas"),a.style.width="100%",a.style.height="100%",a.style.display="block",a.style.touchAction="none",e.prepend(a)),i=a}this.canvas=i,this.opts=o||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=er(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=tr(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,n){Bi(e,n)}static getDecoder(e){return Lt(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=n=>{n.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,n=Yr();this.renderProg=un(e,Wr,n.fs),this.pickProg=un(e,$i,Xi),this.uRender=nr(e,this.renderProg,n.uniforms),this.uPick=nr(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let n of Ue)n.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let n=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=n,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,n,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,n,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,n){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),o=Math.max(1,n);this.pickFboWidth=i,this.pickFboHeight=o,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,o,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,o)}loadGLBData(e,n){this.lastGlbData=e,this.lastLimits=n;let{meshes:r,bounds:i,lights:o,animations:s,worldMatrices:l,gpuTextures:a,availableVariants:c}=Hr(this.gl,e,n,()=>this.render());if(this.disposeMeshGpuResources(),this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=o,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=a||[],this.availableVariants=c||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let f of e.gltf.nodes)this.initialNodeTransforms.push({t:f.translation?[f.translation[0],f.translation[1],f.translation[2]]:[0,0,0],r:f.rotation?[f.rotation[0],f.rotation[1],f.rotation[2],f.rotation[3]]:[0,0,0,1],s:f.scale?[f.scale[0],f.scale[1],f.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let f of Ue)f.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=er(u));let m=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;m!==void 0&&(this.envIntensity=Math.max(0,Number(m)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(jr(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Gt(e))}setBackdropGLB(e,n){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Gt(e),{meshes:i}=Hr(this.gl,r,qr,()=>this.render());if(n)for(let o of i)o.transform[12]+=n[0],o.transform[13]+=n[1],o.transform[14]+=n[2],$e(o.normalMatrix,o.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,n,r,i=1){this.clearColor=[e,n,r,i]}updateMeshTransforms(e){for(let n=0;n<this.meshes.length;n++){let r=this.meshes[n],i;e instanceof Map?i=e.get(r.name)??e.get(n):Array.isArray(e)?i=e[n]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,n)&&(i=e[n])),i&&i.length===16&&(r.transform.set(i),$e(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let n=this.gl,r=[.28,.28,.28],i=[],o=[],s=[],l=[];for(let a of this.lights){let c=a.color||[1,1,1],u=a.intensity!==void 0?a.intensity:1;if(a.type==="ambient")r=[c[0]*u,c[1]*u,c[2]*u];else if(a.type==="directional"&&i.length<6){let m=a.direction||[.5,1,.8];i.push(m[0],m[1],m[2]),o.push(c[0]*u,c[1]*u,c[2]*u)}else if(a.type==="point"&&s.length<6){let m=a.position||[0,0,0];s.push(m[0],m[1],m[2]),l.push(c[0]*u,c[1]*u,c[2]*u)}}i.length===0&&(i.push(.5,1,.8),o.push(1,1,1)),n.uniform3fv(e.uAmbientColor,r),n.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(n.uniform3fv(e.uDirLightDir,i),n.uniform3fv(e.uDirLightColor,o)),n.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(n.uniform3fv(e.uPointLightPos,s),n.uniform3fv(e.uPointLightColor,l)),n.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=er(e)}getExposure(){return this.exposure}setShadow(e,n){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),n!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(n)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=tr(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let n of Ue)if(n.setEnvironmentImage){await n.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let n of Ue)if(n.setSkyboxImage){await n.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,n=this.currPhi,r=this.currDistance;return{theta:e,phi:n,radius:r,toString(){return`${e.toFixed(4)}rad ${n.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((n,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(m=>m.materialIndex===r||e.length===1&&m.materialIndex===void 0)),o=i[0],s=o?[...o.baseColor]:n.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=o?o.metallic:n.pbrMetallicRoughness?.metallicFactor??.1,a=o?o.roughness:n.pbrMetallicRoughness?.roughnessFactor??.5,c={baseColorFactor:s,metallicFactor:l,roughnessFactor:a,setBaseColorFactor:u=>{let m=[u[0],u[1],u[2],u[3]??1];c.baseColorFactor=m,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.baseColorFactor=m);for(let f of i)f.baseColor=m;this.render()},setMetallicFactor:u=>{c.metallicFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.metallicFactor=u);for(let m of i)m.metallic=u;this.render()},setRoughnessFactor:u=>{c.roughnessFactor=u,n.pbrMetallicRoughness&&(n.pbrMetallicRoughness.roughnessFactor=u);for(let m of i)m.roughness=u;this.render()}};return{name:n.name||`Material_${r}`,pbrMetallicRoughness:c}})}playAnimation(e){if(this.animations.length!==0){if(e){let n=this.animations.find(r=>r.name===e);n&&(this.currentClip=n)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let n=this.applyVariantMaterial(e);return n&&this.gl&&this.render(),n}applyVariantMaterial(e){let n=e===null||e==="",r=-1;if(n)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return n;for(let o of this.meshes)for(let s of o.primitives){let l=s.defaultMaterialIndex;if(!n&&Array.isArray(s.variantMappings)){for(let c of s.variantMappings)if(Array.isArray(c.variants)&&c.variants.includes(r)){l=c.material;break}}let a=l!==void 0?i[l]:void 0;s.materialIndex=a?l:void 0,Object.assign(s,Zr(a,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,a??null)}return!0}applyPrimitiveProgram(e,n,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=n??-1,o=e.programCache.get(i);o||(o=Kr(this.gl,{...e.primitiveDef,material:n},r),e.programCache.set(i,o)),e.customProgram=o.program,e.customUniforms=o.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let n of Ue)if(n.evaluateAnimation){n.evaluateAnimation(this,e);return}}setTarget(e,n,r){this.customTarget=[e,n,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let n=Math.max(10,Math.min(90,e));this.fov=n*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let n=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(n,Math.min(r,e))}setCamera(e,n,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),n!==void 0&&(this.targetPhi=this.clampPhi(n*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,n,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),n!==void 0&&(this.initialPhi=this.clampPhi(n*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let o=this.clampDistance(r);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else if(i!==void 0&&i>0){let o=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=o,this.customDistance=!0,this.targetDistance=o,this.currDistance=o}else{this.customDistance=!1;let o=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=o,this.targetDistance=o,this.currDistance=o}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,n){let r=ke();De(r,this.projMatrix,this.viewMatrix);let[i,o,s]=e,l=n?n[0]:0,a=n?n[1]:0,c=n?n[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],o=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],n&&(l=u[0]*n[0]+u[4]*n[1]+u[8]*n[2],a=u[1]*n[0]+u[5]*n[1]+u[9]*n[2],c=u[2]*n[0]+u[6]*n[1]+u[10]*n[2]));let m=r[0]*i+r[4]*o+r[8]*s+r[12],f=r[1]*i+r[5]*o+r[9]*s+r[13],d=r[2]*i+r[6]*o+r[10]*s+r[14],g=r[3]*i+r[7]*o+r[11]*s+r[15];if(g<=1e-4)return{x:0,y:0,z:1,visible:!1};let y=m/g,M=f/g,L=d/g,G=this.canvas.getBoundingClientRect(),p=G.width||this.canvas.clientWidth||this.canvas.width||300,E=G.height||this.canvas.clientHeight||this.canvas.height||150,_=(y*.5+.5)*p,P=(-M*.5+.5)*E,z=y>=-1.1&&y<=1.1&&M>=-1.1&&M<=1.1&&L>=-1&&L<=1;if(z&&n){let[R,C,I]=Bt(this),b=[i-R,o-C,s-I];l*b[0]+a*b[1]+c*b[2]>.05&&(z=!1)}return{x:_,y:P,z:L,visible:z}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas;this.boundContextMenu=n=>{n.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=n=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist=0,this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.isPanning=n.button===2||n.shiftKey||this.activePointers.size===2,e.setPointerCapture(n.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=n=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=this.activePointers.get(n.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},i=n.clientX-r.x,o=n.clientY-r.y;if(this.activePointers.set(n.pointerId,{x:n.clientX,y:n.clientY}),this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.totalDragDist+=Math.hypot(i,o),this.isPanning||n.button===2||n.shiftKey||this.activePointers.size===2){let s=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],l=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],c=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-i*s[0]+o*l[0])*c,a[1]+=(-i*s[1]+o*l[1])*c,a[2]+=(-i*s[2]+o*l[2])*c,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-i*.008),this.targetPhi=this.clampPhi(this.targetPhi+o*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=n=>{this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now(),this.activePointers.delete(n.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(n.pointerId)}catch{}if(this.totalDragDist<5&&n.button===0){let r=e.getBoundingClientRect(),i=Math.floor((n.clientX-r.left)*(e.width/Math.max(r.width,1))),o=Math.floor((n.clientY-r.top)*(e.height/Math.max(r.height,1)));this.performMeshPick(i,o,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=n=>{if(!this.interactive)return;n.preventDefault(),this.lastInteractionTime=typeof performance<"u"?performance.now():Date.now();let r=Math.exp(n.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*r)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=n=>{let r=n.detail||{};r.reset?this.resetCamera():this.setCamera(r.theta,r.phi,r.distance,r.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=n=>{if(!this.interactive)return;let r=typeof performance<"u"?performance.now():Date.now();switch(n.key){case"ArrowLeft":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta-.1),n.preventDefault();break;case"ArrowRight":this.lastInteractionTime=r,this.targetTheta=this.clampTheta(this.targetTheta+.1),n.preventDefault();break;case"ArrowUp":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi+.08),n.preventDefault();break;case"ArrowDown":this.lastInteractionTime=r,this.targetPhi=this.clampPhi(this.targetPhi-.08),n.preventDefault();break;case"+":case"=":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*.9),n.preventDefault();break}case"-":case"_":{this.lastInteractionTime=r,this.targetDistance=this.clampDistance(this.targetDistance*1.1),n.preventDefault();break}case"Home":this.lastInteractionTime=r,this.resetCamera(),n.preventDefault();break}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=this.canvas;this.boundContextLost&&(e.removeEventListener("webglcontextlost",this.boundContextLost),this.boundContextLost=null),this.boundContextRestored&&(e.removeEventListener("webglcontextrestored",this.boundContextRestored),this.boundContextRestored=null),this.boundContextMenu&&(e.removeEventListener("contextmenu",this.boundContextMenu),this.boundContextMenu=null),this.boundPointerDown&&(e.removeEventListener("pointerdown",this.boundPointerDown),this.boundPointerDown=null),this.boundPointerMove&&(e.removeEventListener("pointermove",this.boundPointerMove),this.boundPointerMove=null),this.boundPointerUp&&(e.removeEventListener("pointerup",this.boundPointerUp),this.boundPointerUp=null),this.boundWheel&&(e.removeEventListener("wheel",this.boundWheel),this.boundWheel=null),this.boundKeyDown&&(e.removeEventListener("keydown",this.boundKeyDown),this.boundKeyDown=null),this.boundSetCamera&&(this.container.removeEventListener("setCamera",this.boundSetCamera),this.boundSetCamera=null),this.boundResetCamera&&(this.container.removeEventListener("resetCamera",this.boundResetCamera),this.boundResetCamera=null)}raycastFromScreenPoint(e,n){let r=this.canvas,i=r.getBoundingClientRect(),o=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(o/i.width)):Math.floor(e),a=i.height>0?Math.floor((n-i.top)*(s/i.height)):Math.floor(n);return this.performMeshPick(l,a,!1)}performMeshPick(e,n,r=!0){if(this.meshes.length===0)return null;let i=this.gl,o=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,o);let l=ke();De(l,this.projMatrix,this.viewMatrix);let a=[],c=Math.max(0,Math.min(o-1,e)),u=Math.max(0,Math.min(s-1,s-1-n));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==o||this.pickFboHeight!==s)&&this.resizePickingFbo(o,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,o,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16384|256),i.useProgram(this.pickProg);for(let z=0;z<this.meshes.length;z++){let R=this.meshes[z];if(R.visible===!1||R.isPluginMesh)continue;let C=z+1,I=(C&255)/255,b=(C>>8&255)/255,T=(C>>16&255)/255;i.uniform4f(this.uPick.uColorId,I,b,T,1),De(this.modelMatrix,this.modelRootMatrix,R.transform);let N=R.instanceMatrices;if(N&&N.length>=16){let v=N.length>>4,D=ke();for(let h of R.primitives){i.bindVertexArray(h.vao);for(let A=0;A<v;A++)De(D,this.modelMatrix,N.subarray(A*16,A*16+16)),De(this.mvpMatrix,l,D),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),ln(i,h)}}else{De(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let v of R.primitives)i.bindVertexArray(v.vao),ln(i,v)}}let _=new Uint8Array(4);i.readPixels(c,u,1,1,6408,5121,_),i.bindFramebuffer(36160,null);let P=_[0]+(_[1]<<8)+(_[2]<<16);P>0&&P<=this.meshes.length&&(a=[this.meshes[P-1]])}a.length===0&&(a=this.meshes.filter(_=>_.visible!==!1));let m=null,f=1/0,d=[0,0,0],g=[0,1,0],[y,M,L]=Bt(this),G=ke();for(let _ of a){De(G,this.modelRootMatrix,_.transform);let P=_.instanceMatrices,z=P&&P.length>=16?P.length>>4:1;for(let R=0;R<z;R++){P&&P.length>=16?De(this.modelMatrix,G,P.subarray(R*16,R*16+16)):this.modelMatrix.set(G),De(this.mvpMatrix,l,this.modelMatrix);let C=ke();if(!zr(C,this.mvpMatrix))continue;let I=(c+.5)/o*2-1,b=(u+.5)/s*2-1,T=[0,0,0],N=[0,0,0];qn(T,I,b,-1,C),qn(N,I,b,1,C);let v=N[0]-T[0],D=N[1]-T[1],h=N[2]-T[2],A=Math.hypot(v,D,h)||1,$=v/A,V=D/A,K=h/A,k={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Q=>{for(let q of _.primitives){if(!q.positions)continue;let ae=q.positions,F=q.indices,te=Math.floor(F?F.length/3:ae.length/9);for(let ue=0;ue<te;ue++){let le=F?F[ue*3]:ue*3,he=F?F[ue*3+1]:ue*3+1,xe=F?F[ue*3+2]:ue*3+2;Vr(T[0],T[1],T[2],$,V,K,ae[le*3],ae[le*3+1],ae[le*3+2],ae[he*3],ae[he*3+1],ae[he*3+2],ae[xe*3],ae[xe*3+1],ae[xe*3+2],k,Q)}}})(1e-4),isFinite(k.distance)){let Q=k.point[0],q=k.point[1],ae=k.point[2],F=this.modelMatrix,te=F[0]*Q+F[4]*q+F[8]*ae+F[12],ue=F[1]*Q+F[5]*q+F[9]*ae+F[13],le=F[2]*Q+F[6]*q+F[10]*ae+F[14],he=te-y,xe=ue-M,Me=le-L,pe=Math.hypot(he,xe,Me);if(pe<f){$e(this.normalMatrix,this.modelMatrix);let ge=this.normalMatrix,S=k.normal[0],x=k.normal[1],w=k.normal[2],U=ge[0]*S+ge[3]*x+ge[6]*w,O=ge[1]*S+ge[4]*x+ge[7]*w,H=ge[2]*S+ge[5]*x+ge[8]*w,X=Math.hypot(U,O,H)||1;U/=X,O/=X,H/=X,U*he+O*xe+H*Me>0&&(U=-U,O=-O,H=-H),m=_,f=Math.round(pe*1e3)/1e3,d=[Math.round(te*1e3)/1e3,Math.round(ue*1e3)/1e3,Math.round(le*1e3)/1e3],g=[Math.round(U*1e3)/1e3,Math.round(O*1e3)/1e3,Math.round(H*1e3)/1e3]}}}}if(!m)return null;let E={meshIndex:this.meshes.indexOf(m),meshName:m.name,nodeIndex:m.nodeIndex,distance:f,hitPoint:d,normal:g,screenX:e,screenY:n};if(r){for(let _ of Ue)_.onMeshSelect?.(this,E);this.opts.onMeshClick&&this.opts.onMeshClick(E),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:E}))}return E}mapStereoPickX(e,n){if(!this.stereoSBS||this.xrSessionActive||n<2)return e;let r=Math.max(1,Math.floor(n*.5)),i=e>=r,o=i?e-r:e,s=i?Math.max(1,n-r):r,l=(o+.5)/s*2-1;return Math.floor((l*.5+1)*.5*n)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),n=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);an(this.projMatrix,this.fov,e,.1,n);let r=this.customTarget||this.bounds.center;kt(this.viewMatrix,Bt(this),r,[0,1,0]),De(this.mvpMatrix,this.projMatrix,this.viewMatrix),$e(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),n=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(n.width*e)),i=Math.max(1,Math.floor(n.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let n=this.xrSessionActive;if(this.xrSessionActive=e,n&&!e){this.xrDepthState.enabled=!1;for(let r of Ue)r.onXRSessionEnd?.(this);if(this.lastTime=typeof performance<"u"?performance.now():Date.now(),this.updateTurntableMatrix(),this.isVisible)try{this.resize(),this.syncCameraMatrices(),this.render()}catch(r){this.reportRenderError(r)}}}reportRenderError(e){this.renderErrorReported||(this.renderErrorReported=!0,typeof console<"u"&&console.warn("[three-live] render frame failed:",e))}stepXRUpdate(e){for(let n of Ue)n.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=n=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((n-this.lastTime)/1e3,0),.1);if(this.lastTime=n,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),n=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],o=this.modelRootMatrix;o[0]=e,o[1]=0,o[2]=-n,o[3]=0,o[4]=0,o[5]=1,o[6]=0,o[7]=0,o[8]=n,o[9]=0,o[10]=e,o[11]=0,o[12]=r-(e*r+n*i),o[13]=0,o[14]=i-(-n*r+e*i),o[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Ue)s.onUpdate?.(this,e);let n=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&n-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of Ue)s.onCameraChange?.(this,this.container)}this.currTheta+=(this.targetTheta-this.currTheta)*.12,this.currPhi+=(this.targetPhi-this.currPhi)*.12,this.currDistance+=(this.targetDistance-this.currDistance)*.12,this.syncCameraMatrices();let r=Math.round((this.currTheta*180/Math.PI%360+360)%360),i=Math.round(this.currPhi*180/Math.PI),o=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(o-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=o;let s={theta:r,phi:i,zoom:o,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,n,r,i,o=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,a=e?.projectionMatrix||this.projMatrix,c=e?.transform?.position,u=c?[c.x,c.y,c.z]:[0,1.6,0];n?this.modelRootMatrix.set(n):r&&n&&this.modelRootMatrix.set(n),this.render({viewMatrix:l,projMatrix:a,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:o})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let p=Math.max(2,this.canvas.width||2),E=Math.max(1,this.canvas.height||1),_=Math.max(1,Math.floor(p*.5)),P=Math.max(1,p-_),z=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),R=this.customTarget||this.bounds.center,[C,I,b]=Bt(this),T=Math.cos(this.currTheta),N=-Math.sin(this.currTheta),v=.032,D=ke(),h=ke(),A=[C-T*v,I,b-N*v],$=[R[0]-T*v*.25,R[1],R[2]-N*v*.25];an(D,this.fov,_/E,.1,z),kt(h,A,$,[0,1,0]);let V=ke(),K=ke(),k=[C+T*v,I,b+N*v],ee=[R[0]+T*v*.25,R[1],R[2]+N*v*.25];an(V,this.fov,P/E,.1,z),kt(K,k,ee,[0,1,0]),this.render({viewMatrix:h,projMatrix:D,eyePos:A,viewport:[0,0,_,E],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:K,projMatrix:V,eyePos:k,viewport:[_,0,P,E],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,p,E);return}let n=this.gl,r=0,i=0,o=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],o=e.viewport[2],s=e.viewport[3],n.viewport(r,i,o,s)):n.viewport(0,0,this.canvas.width,this.canvas.height),n.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?n.clearColor(0,0,0,0):n.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),n.clear(16384|256));let l=ke(),a=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=a,De(l,e?.projMatrix??this.projMatrix,a);let c=Ie().xrDepthShader,u=zi(this.toneMapping),[m,f,d]=e?e.eyePos:Bt(this);for(let p of Ue)p.onBeforeDrawScene?.(this,n,l,[m,f,d],u);let g=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&g===0)return;let y=e?.eye||"none",M=!1,L=g>0?[...this.backdropMeshes,...this.meshes]:this.meshes,G=p=>{for(let E=0;E<L.length;E++){let _=L[E];if(_.visible===!1)continue;let P=this.selectedMeshName!==""&&_.name===this.selectedMeshName;E<g||_.worldSpace===!0||_.name==="__xr_reticle__"?this.modelMatrix.set(_.transform):De(this.modelMatrix,this.modelRootMatrix,_.transform),De(this.mvpMatrix,l,this.modelMatrix),$e(_.normalMatrix,this.modelMatrix);let z=_.extras?.xr?.stereo||_.userData?.xr?.stereo,R=0,C=0,I=1,b=1;z==="sbs"?(I=.5,R=y==="right"?.5:0):z==="ou"&&(b=.5,C=y==="right"?.5:0);for(let T of _.primitives){let N=!!T.isTransmissive;if(!p&&N){M=!0;continue}if(p&&!N)continue;let v=T.customProgram||this.renderProg,D=T.customUniforms||this.uRender;n.useProgram(v),n.vertexAttrib3f(3,0,0,0),D.uInstanced&&n.uniform1i(D.uInstanced,0),n.uniform1i(D.uToneMapping,u),n.uniform1f(D.uEnvIntensity,this.envIntensity),D.uExposure&&n.uniform1f(D.uExposure,this.exposure),n.uniform3f(D.uCameraPos,m,f,d),n.uniform1f(D.uEmissive,P?1:0),n.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(D.uModel,!1,this.modelMatrix),n.uniformMatrix3fv(D.uNormalMatrix,!1,_.normalMatrix),D.uUvTransform&&n.uniform4f(D.uUvTransform,R,C,I,b),D.uViewportSize&&n.uniform2f(D.uViewportSize,Math.max(1,o),Math.max(1,s)),c?.bind(n,D,this.xrDepthState,a,[r,i,Math.max(1,o),Math.max(1,s)]),this.environmentTexture?(n.activeTexture(33988),n.bindTexture(3553,this.environmentTexture),n.uniform1i(D.uEnvironmentMap,4),n.uniform1i(D.uHasEnvironmentMap,1)):n.uniform1i(D.uHasEnvironmentMap,0),this.bindLights(D),D.uSectionEnabled&&n.uniform1i(D.uSectionEnabled,0);for(let A of Ue)A.onBeforeDrawPrimitive?.(n,v,T,_,this.worldMatrices||[],this.gltf);n.uniform4fv(D.uBaseColor,T.baseColor),n.uniform1f(D.uMetallic,T.metallic),n.uniform1f(D.uRoughness,T.roughness),D.uClearcoat&&n.uniform2f(D.uClearcoat,T.clearcoat??0,T.clearcoatRoughness??.04),T.texture?(n.activeTexture(33984),n.bindTexture(3553,T.texture),n.uniform1i(D.uBaseColorTexture,0),n.uniform1i(D.uHasTexture,1)):n.uniform1i(D.uHasTexture,0),T.metallicRoughnessTexture?(n.activeTexture(33985),n.bindTexture(3553,T.metallicRoughnessTexture),n.uniform1i(D.uMetallicRoughnessTexture,1),n.uniform1i(D.uHasMetallicRoughnessTexture,1)):n.uniform1i(D.uHasMetallicRoughnessTexture,0),T.normalTexture?(n.activeTexture(33986),n.bindTexture(3553,T.normalTexture),n.uniform1i(D.uNormalTexture,2),n.uniform1i(D.uHasNormalTexture,1),n.uniform1f(D.uNormalScale,T.normalScale)):n.uniform1i(D.uHasNormalTexture,0),T.occlusionTexture?(n.activeTexture(33987),n.bindTexture(3553,T.occlusionTexture),n.uniform1i(D.uOcclusionTexture,3),n.uniform1i(D.uHasOcclusionTexture,1),n.uniform1f(D.uOcclusionStrength,T.occlusionStrength)):n.uniform1i(D.uHasOcclusionTexture,0),n.bindVertexArray(T.vao);let h=_.instanceMatrices;if(T.instanceCount!==void 0)n.drawElementsInstanced(4,T.indexCount,T.indexType,0,T.instanceCount);else if(h&&h.length>=16&&T.instanced&&D.uInstanced&&D.uViewProj){let A=h.length>>4;n.uniform1i(D.uInstanced,1),n.uniformMatrix4fv(D.uViewProj,!1,l),T.indices?n.drawElementsInstanced(4,T.indexCount,T.indexType,0,A):n.drawArraysInstanced(4,0,T.indexCount,A),n.uniform1i(D.uInstanced,0)}else if(h&&h.length>=16){let A=h.length>>4,$=_.instanceColors,V=ke(),K=new Float32Array(9),k=[T.baseColor[0],T.baseColor[1],T.baseColor[2],T.baseColor[3]];for(let ee=0;ee<A;ee++)De(V,this.modelMatrix,h.subarray(ee*16,ee*16+16)),De(this.mvpMatrix,l,V),$e(K,V),n.uniformMatrix4fv(D.uMVP,!1,this.mvpMatrix),n.uniformMatrix4fv(D.uModel,!1,V),n.uniformMatrix3fv(D.uNormalMatrix,!1,K),$&&(k[0]=T.baseColor[0]*$[ee*3],k[1]=T.baseColor[1]*$[ee*3+1],k[2]=T.baseColor[2]*$[ee*3+2],k[3]=T.baseColor[3],n.uniform4fv(D.uBaseColor,k)),ln(n,T)}else ln(n,T)}}};if(G(!1),M){for(let p of Ue)p.onBeforeTransmissivePass?.(n,this);G(!0)}for(let p of Ue)p.onAfterRender?.(n,this,l,e?.eye??"none",[r,i,o,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,n){Qr(this.gl,e,n)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let n of Ue)n.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};hn.registerPlugin=Ur,hn.getRegisteredPlugins=Or;function qi(t){return t+3&-4}function Zi(t,e=0){let n=(k,ee)=>typeof k=="number"&&Number.isFinite(k)?k:ee,r=n(t[e+12],0),i=n(t[e+13],0),o=n(t[e+14],0),s=n(t[e+0],1),l=n(t[e+1],0),a=n(t[e+2],0),c=n(t[e+4],0),u=n(t[e+5],1),m=n(t[e+6],0),f=n(t[e+8],0),d=n(t[e+9],0),g=n(t[e+10],1),y=Math.hypot(s,l,a),M=Math.hypot(c,u,m),L=Math.hypot(f,d,g);s*(u*g-d*m)-c*(l*g-d*a)+f*(l*m-u*a)<0&&(y=-y);let p=Math.abs(y)>1e-8?1/y:0,E=Math.abs(M)>1e-8?1/M:0,_=Math.abs(L)>1e-8?1/L:0,P=s*p,z=l*p,R=a*p,C=c*E,I=u*E,b=m*E,T=f*_,N=d*_,v=g*_,D=P+I+v,h=0,A=0,$=0,V=1;if(D>0){let k=.5/Math.sqrt(D+1);V=.25/k,h=(b-N)*k,A=(T-R)*k,$=(z-C)*k}else if(P>I&&P>v){let k=2*Math.sqrt(Math.max(0,1+P-I-v));k>1e-8&&(V=(b-N)/k,h=.25*k,A=(C+z)/k,$=(T+R)/k)}else if(I>v){let k=2*Math.sqrt(Math.max(0,1+I-P-v));k>1e-8&&(V=(T-R)/k,h=(C+z)/k,A=.25*k,$=(b+N)/k)}else{let k=2*Math.sqrt(Math.max(0,1+v-P-I));k>1e-8&&(V=(z-C)/k,h=(T+R)/k,A=(b+N)/k,$=.25*k)}let K=Math.hypot(h,A,$,V);return K>1e-8&&Number.isFinite(K)?(h/=K,A/=K,$/=K,V/=K):(h=0,A=0,$=0,V=1),{t:[r,i,o],r:[h,A,$,V],s:[y,M,L]}}function Qi(t){let e={};return t.grab&&(e.interactable={mode:typeof t.grab=="string"?t.grab:"2-hand"},e.movable={scaleInZ:!!t.scale,minScale:typeof t.scale=="object"?t.scale.min??.1:.1,maxScale:typeof t.scale=="object"?t.scale.max??10:10}),t.billboard&&(e.billboard={mode:typeof t.billboard=="string"?t.billboard:"capsule"}),t.follow&&(e.follow={target:typeof t.follow=="object"?t.follow.mode??"head":t.follow}),t.anchor&&(e.anchor={plane:t.anchor}),t.physics&&t.physics!=="none"&&(e.rigidbody={type:t.physics}),e}function Pt(t,e){t.updateMatrixWorld(!0);let n=[],r=0,i=[],o=[],s=[],l=[],a=new Set,c=[],u=[],m=new Map,f=[],d=[];function g(C){let I=m.get(C);if(I!==void 0)return I;I=u.length,m.set(C,I);let b=C,T=b.color?.r??.8,N=b.color?.g??.8,v=b.color?.b??.8,D=b.opacity??1,h={name:b.name||"",pbrMetallicRoughness:{baseColorFactor:[T,N,v,D],metallicFactor:b.metalness??.1,roughnessFactor:b.roughness??.5},doubleSided:b.side===2||!!b.doubleSided};if(b.emissive&&(b.emissive.r>0||b.emissive.g>0||b.emissive.b>0)){let $=b.emissiveIntensity??1;h.emissiveFactor=[b.emissive.r*$,b.emissive.g*$,b.emissive.b*$]}let A={};return b.clearcoat&&b.clearcoat>0&&(A.KHR_materials_clearcoat={clearcoatFactor:b.clearcoat,clearcoatRoughnessFactor:b.clearcoatRoughness||0}),b.sheen&&b.sheen>0&&(A.KHR_materials_sheen={sheenColorFactor:b.sheenColor?[b.sheenColor.r,b.sheenColor.g,b.sheenColor.b]:[1,1,1],sheenRoughnessFactor:b.sheenRoughness||0}),b.transmission&&b.transmission>0&&(A.KHR_materials_transmission={transmissionFactor:b.transmission}),b.thickness&&b.thickness>0&&(A.KHR_materials_volume={thicknessFactor:b.thickness,attenuationDistance:b.attenuationDistance??1/0,attenuationColor:b.attenuationColor?[b.attenuationColor.r,b.attenuationColor.g,b.attenuationColor.b]:[1,1,1]}),b.ior!==void 0&&b.ior!==1.5&&(A.KHR_materials_ior={ior:b.ior}),b.dispersion&&b.dispersion>0&&(A.KHR_materials_dispersion={dispersion:b.dispersion}),b.iridescence&&b.iridescence>0&&(A.KHR_materials_iridescence={iridescenceFactor:b.iridescence,iridescenceIor:b.iridescenceIOR??1.3}),Object.keys(A).length>0&&(h.extensions=A),u.push(h),I}function y(C,I){let b=new Uint8Array(C.buffer,C.byteOffset,C.byteLength),T=qi(b.byteLength),N=new Uint8Array(T);N.set(b),n.push(N);let v=i.length;return i.push({buffer:0,byteOffset:r,byteLength:b.byteLength,target:I}),r+=T,v}function M(C,I,b,T,N,v,D){let h=y(C,b),A=o.length,$={bufferView:h,byteOffset:0,componentType:T,count:N,type:I};return v&&($.min=v),D&&($.max=D),o.push($),A}t.traverse(C=>{(C.isLight||C.color&&C.intensity!==void 0)&&d.push({type:C.type,color:[C.color.r,C.color.g,C.color.b],intensity:C.intensity,position:[C.position.x,C.position.y,C.position.z]})});let L=[];function G(C){let I={name:C.name||""},b=C.position,T=C.quaternion,N=C.scale;if((b.x||b.y||b.z)&&(I.translation=[b.x,b.y,b.z]),(T.x||T.y||T.z||T.w!==1)&&(I.rotation=[T.x,T.y,T.z,T.w]),(N.x!==1||N.y!==1||N.z!==1)&&(I.scale=[N.x,N.y,N.z]),C.userData&&Object.keys(C.userData).length>0&&(I.extras=JSON.parse(JSON.stringify(C.userData,(D,h)=>{if(!(D==="__proto__"||D==="prototype"||D==="constructor"))return typeof h=="function"?void 0:h})),C.userData.xr)){let D=Qi(C.userData.xr);I.extensions={...I.extensions||{},MOZ_hubs_components:D,ANDROID_xr_scenecore:D},Ie().xrTraitSerializer?.gltfNode(I,C.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(C.geometry){let D=C.geometry,h=D.attributes.position;if(h&&h.count>0){let A=[1/0,1/0,1/0],$=[-1/0,-1/0,-1/0];for(let q=0;q<h.count;q++){let ae=h.getX(q),F=h.getY(q),te=h.getZ(q);ae<A[0]&&(A[0]=ae),ae>$[0]&&($[0]=ae),F<A[1]&&(A[1]=F),F>$[1]&&($[1]=F),te<A[2]&&(A[2]=te),te>$[2]&&($[2]=te)}let K={attributes:{POSITION:M(h.array,"VEC3",34962,5126,h.count,A,$)}};if(D.attributes.normal&&(K.attributes.NORMAL=M(D.attributes.normal.array,"VEC3",34962,5126,D.attributes.normal.count)),D.attributes.uv&&(K.attributes.TEXCOORD_0=M(D.attributes.uv.array,"VEC2",34962,5126,D.attributes.uv.count)),D.index){let q=D.index.array instanceof Uint32Array;K.indices=M(D.index.array,"SCALAR",34963,q?5125:5123,D.index.count)}C.material&&(K.material=g(C.material));let k=C.userData?.variants;if(k&&typeof k=="object"){let q=new Map;for(let ae of Object.keys(k)){if(!ae||ae==="__proto__"||ae==="constructor"||ae==="prototype")continue;let F=k[ae];if(!F||typeof F!="object")continue;let te=f.indexOf(ae);if(te===-1&&f.length<256&&(te=f.length,f.push(ae)),te===-1)continue;let ue=g(F),le=q.get(ue);le||(le=[],q.set(ue,le)),le.push(te)}if(q.size>0){let ae=[];for(let[F,te]of q.entries())ae.push({material:F,variants:te});K.extensions={...K.extensions||{},KHR_materials_variants:{mappings:ae}},a.add("KHR_materials_variants")}}let ee=C;if(ee.isInstancedMesh&&typeof ee.count=="number"&&ee.count>0&&ee.instanceMatrix?.array){let q=Math.min(1e4,Math.floor(ee.count)),ae=ee.instanceMatrix.array,F=new Float32Array(q*3),te=new Float32Array(q*4),ue=new Float32Array(q*3);for(let he=0;he<q;he++){let{t:xe,r:Me,s:pe}=Zi(ae,he*16);F[he*3]=xe[0],F[he*3+1]=xe[1],F[he*3+2]=xe[2],te[he*4]=Me[0],te[he*4+1]=Me[1],te[he*4+2]=Me[2],te[he*4+3]=Me[3],ue[he*3]=pe[0],ue[he*3+1]=pe[1],ue[he*3+2]=pe[2]}let le={TRANSLATION:M(F,"VEC3",0,5126,q),ROTATION:M(te,"VEC4",0,5126,q),SCALE:M(ue,"VEC3",0,5126,q)};if(ee.instanceColor?.array&&ee.instanceColor.array.length>=q*3){let he=new Float32Array(ee.instanceColor.array.subarray(0,q*3));le._COLOR_0=M(he,"VEC3",0,5126,q)}I.extensions={...I.extensions||{},EXT_mesh_gpu_instancing:{attributes:le}},a.add("EXT_mesh_gpu_instancing")}let Q=s.length;s.push({primitives:[K],name:C.name,...I.extras?{extras:I.extras}:{}}),I.mesh=Q}}let v=l.length;if(l.push(I),c.push(C),C.children.length>0){I.children=[];for(let D of C.children)I.children.push(G(D))}return v}for(let C of t.children)L.push(G(C));let p=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),E=[];if(typeof p=="function"&&c.length>0){let C=e?.duration??4,I=e?.fps??15,b=Math.max(2,Math.round(C*I)+1),T=new Float32Array(b),N=c.map(k=>({px:k.position.x,py:k.position.y,pz:k.position.z,qx:k.quaternion.x,qy:k.quaternion.y,qz:k.quaternion.z,qw:k.quaternion.w,sx:k.scale.x,sy:k.scale.y,sz:k.scale.z})),v=c.map(()=>new Float32Array(b*3)),D=c.map(()=>new Float32Array(b*4)),h=c.map(()=>new Float32Array(b*3));for(let k=0;k<b;k++){let ee=k/(b-1)*C;T[k]=ee;try{p(ee)}catch{}for(let Q=0;Q<c.length;Q++){let q=c[Q];v[Q][k*3]=q.position.x,v[Q][k*3+1]=q.position.y,v[Q][k*3+2]=q.position.z,D[Q][k*4]=q.quaternion.x,D[Q][k*4+1]=q.quaternion.y,D[Q][k*4+2]=q.quaternion.z,D[Q][k*4+3]=q.quaternion.w,h[Q][k*3]=q.scale.x,h[Q][k*3+1]=q.scale.y,h[Q][k*3+2]=q.scale.z}}for(let k=0;k<c.length;k++){let ee=c[k],Q=N[k];ee.position.set(Q.px,Q.py,Q.pz),ee.quaternion.set(Q.qx,Q.qy,Q.qz,Q.qw),ee.scale.set(Q.sx,Q.sy,Q.sz)}t.updateMatrixWorld(!0);let A=null,$=()=>(A===null&&(A=M(T,"SCALAR",0,5126,b,[0],[C])),A),V=[],K=[];for(let k=0;k<c.length;k++){let ee=N[k],Q=!1,q=!1,ae=!1;for(let F=0;F<b;F++)(Math.abs(v[k][F*3]-ee.px)>1e-4||Math.abs(v[k][F*3+1]-ee.py)>1e-4||Math.abs(v[k][F*3+2]-ee.pz)>1e-4)&&(Q=!0),(Math.abs(D[k][F*4]-ee.qx)>1e-4||Math.abs(D[k][F*4+1]-ee.qy)>1e-4||Math.abs(D[k][F*4+2]-ee.qz)>1e-4||Math.abs(D[k][F*4+3]-ee.qw)>1e-4)&&(q=!0),(Math.abs(h[k][F*3]-ee.sx)>1e-4||Math.abs(h[k][F*3+1]-ee.sy)>1e-4||Math.abs(h[k][F*3+2]-ee.sz)>1e-4)&&(ae=!0);if(Q){let F=M(v[k],"VEC3",0,5126,b),te=V.length;V.push({input:$(),interpolation:"LINEAR",output:F}),K.push({sampler:te,target:{node:k,path:"translation"}})}if(q){let F=M(D[k],"VEC4",0,5126,b),te=V.length;V.push({input:$(),interpolation:"LINEAR",output:F}),K.push({sampler:te,target:{node:k,path:"rotation"}})}if(ae){let F=M(h[k],"VEC3",0,5126,b),te=V.length;V.push({input:$(),interpolation:"LINEAR",output:F}),K.push({sampler:te,target:{node:k,path:"scale"}})}}K.length>0&&E.push({name:"ProceduralLoop",samplers:V,channels:K})}let _=on(l,s,t.userData),P={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:t.environmentIntensity}},scenes:[{nodes:L}],scene:0,nodes:l,meshes:s,materials:u,accessors:o,bufferViews:i,buffers:[{byteLength:r}],...E.length>0?{animations:E}:{},..._||a.size>0?{extensionsUsed:[..._?["KHR_interactivity"]:[],...a]}:{},..._||f.length>0?{extensions:{..._?{KHR_interactivity:_}:{},...f.length>0?{KHR_materials_variants:{variants:f.map(C=>({name:C}))}}:{}}}:{}},z=new Uint8Array(r),R=0;for(let C of n)z.set(C,R),R+=C.byteLength;return{gltf:P,bin:z.buffer,lights:d,environmentIntensity:t.environmentIntensity}}function mn(t){return new TextEncoder().encode(t)}function Ht(t,e){let{gltf:n,bin:r}=Pt(t,e),i=JSON.stringify(n),o=mn(i),s=(4-o.byteLength%4)%4,l=o.byteLength+s,a=20+l+8+r.byteLength,c=new Uint8Array(a),u=new DataView(c.buffer);u.setUint32(0,1179937895,!0),u.setUint32(4,2,!0),u.setUint32(8,a,!0),u.setUint32(12,l,!0),u.setUint32(16,1313821514,!0),c.set(o,20);for(let f=0;f<s;f++)c[20+o.byteLength+f]=32;let m=20+l;return u.setUint32(m,r.byteLength,!0),u.setUint32(m+4,5130562,!0),c.set(new Uint8Array(r),m+8),c}function Ji(t,e){t.updateMatrixWorld(!0);let n=[];return t.traverse(r=>{if(r.geometry){let i=r.geometry,o=i.attributes.position;if(!o||o.count===0)return;let s=o.count,l=new Float32Array(s*3),a=r.matrixWorld.elements;for(let R=0;R<s;R++){let C=o.getX(R),I=o.getY(R),b=o.getZ(R);l[R*3]=a[0]*C+a[4]*I+a[8]*b+a[12],l[R*3+1]=a[1]*C+a[5]*I+a[9]*b+a[13],l[R*3+2]=a[2]*C+a[6]*I+a[10]*b+a[14]}let c;if(i.attributes.normal){let R=i.attributes.normal;c=new Float32Array(s*3);let C=new Float32Array(9);$e(C,a);for(let I=0;I<s;I++){let b=R.getX(I),T=R.getY(I),N=R.getZ(I),v=C[0]*b+C[3]*T+C[6]*N,D=C[1]*b+C[4]*T+C[7]*N,h=C[2]*b+C[5]*T+C[8]*N,A=Math.hypot(v,D,h)||1;c[I*3]=v/A,c[I*3+1]=D/A,c[I*3+2]=h/A}}let u;if(i.attributes.uv){let R=i.attributes.uv;u=new Float32Array(s*2);for(let C=0;C<s;C++)u[C*2]=R.getX(C),u[C*2+1]=R.getY(C)}let m;if(i.index)m=i.index.array;else{m=s>65535?new Uint32Array(s):new Uint16Array(s);for(let R=0;R<s;R++)m[R]=R}let f="DefaultMaterial",d=[.8,.8,.8],g=.5,y=.1,M=0,L=0,G=1.5,p=1,E=[0,0,0];if(r.material){let R=r.material;f=R.name||`Material_${n.length}`,R.color&&(d=[R.color.r,R.color.g,R.color.b]),typeof R.roughness=="number"&&(g=R.roughness),typeof R.metalness=="number"&&(y=R.metalness),typeof R.clearcoat=="number"&&(M=R.clearcoat),typeof R.clearcoatRoughness=="number"&&(L=R.clearcoatRoughness),typeof R.ior=="number"&&(G=R.ior);let C=typeof R.opacity=="number"?R.opacity:1,I=typeof R.transmission=="number"?R.transmission:0;if(p=C*(1-I),R.emissive&&(R.emissive.r>0||R.emissive.g>0||R.emissive.b>0)){let b=R.emissiveIntensity??1;E=[R.emissive.r*b,R.emissive.g*b,R.emissive.b*b]}}let _,P=e?.animateCallback||e?.animateFn||(typeof t.userData?.animate=="function"?t.userData.animate:typeof t.__animateFn=="function"?t.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0);if(typeof P=="function"){let R=e?.duration??4,C=e?.fps??4,I=Math.max(2,Math.round(R*C)+1),b=[],T=[],N=[],v=[],D=[r.position.x,r.position.y,r.position.z],h=[r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w],A=[r.scale.x,r.scale.y,r.scale.z],$=!1;for(let V=0;V<I;V++){let K=V/(I-1)*R;b.push(K);try{P(K)}catch{}T.push([r.position.x,r.position.y,r.position.z]),N.push([r.quaternion.x,r.quaternion.y,r.quaternion.z,r.quaternion.w]),v.push([r.scale.x,r.scale.y,r.scale.z]),(Math.abs(r.position.x-D[0])>1e-4||Math.abs(r.position.y-D[1])>1e-4||Math.abs(r.position.z-D[2])>1e-4||Math.abs(r.quaternion.x-h[0])>1e-4||Math.abs(r.quaternion.y-h[1])>1e-4||Math.abs(r.quaternion.z-h[2])>1e-4||Math.abs(r.quaternion.w-h[3])>1e-4||Math.abs(r.scale.x-A[0])>1e-4)&&($=!0)}r.position.set(D[0],D[1],D[2]),r.quaternion.set(h[0],h[1],h[2],h[3]),r.scale.set(A[0],A[1],A[2]),$&&(_={times:b,translations:T,rotations:N,scales:v})}let z=r;if(z.isInstancedMesh&&typeof z.count=="number"&&z.count>0&&z.instanceMatrix?.array){let R=Math.min(1e3,Math.floor(z.count)),C=z.instanceMatrix.array,I=z.instanceColor?.array,b=r.name||`Mesh_${n.length}`,T=new Float32Array(16),N=new Float32Array(9);for(let v=0;v<R;v++){let D=C.subarray(v*16,(v+1)*16);De(T,a,D);let h=new Float32Array(s*3);for(let K=0;K<s;K++){let k=o.getX(K),ee=o.getY(K),Q=o.getZ(K);h[K*3]=T[0]*k+T[4]*ee+T[8]*Q+T[12],h[K*3+1]=T[1]*k+T[5]*ee+T[9]*Q+T[13],h[K*3+2]=T[2]*k+T[6]*ee+T[10]*Q+T[14]}let A;if(i.attributes.normal){let K=i.attributes.normal;A=new Float32Array(s*3),$e(N,T);for(let k=0;k<s;k++){let ee=K.getX(k),Q=K.getY(k),q=K.getZ(k),ae=N[0]*ee+N[3]*Q+N[6]*q,F=N[1]*ee+N[4]*Q+N[7]*q,te=N[2]*ee+N[5]*Q+N[8]*q,ue=Math.hypot(ae,F,te)||1;A[k*3]=ae/ue,A[k*3+1]=F/ue,A[k*3+2]=te/ue}}let $=d,V=f;I&&I.length>=(v+1)*3&&($=[d[0]*I[v*3],d[1]*I[v*3+1],d[2]*I[v*3+2]],V=`${f}_inst_${v}`),n.push({name:`${b}_${v}`,positions:h,indices:m,normals:A,uvs:u,materialName:V,color:$,roughness:g,metallic:y,clearcoat:M,clearcoatRoughness:L,ior:G,opacity:p,emissiveColor:E,xrTraits:r.userData?.xr})}return}n.push({name:r.name||`Mesh_${n.length}`,positions:l,indices:m,normals:c,uvs:u,materialName:f,color:d,roughness:g,metallic:y,clearcoat:M,clearcoatRoughness:L,ior:G,opacity:p,emissiveColor:E,xrTraits:r.userData?.xr,timeSamples:_})}}),n}function ti(t){let e=[],n=t.gltf,r=Ie().decoders.get("meshopt");r&&typeof r.decodeBufferViews=="function"&&r.decodeBufferViews(n,t);let i=t.bin,o=i instanceof ArrayBuffer?i:i.buffer.slice(i.byteOffset,i.byteOffset+i.byteLength),s=n.accessors||[],l=n.bufferViews||[],a=n.materials||[],c=n.meshes||[],u=n.nodes||[];function m(g){let y=s[g];if(!y)throw new Error(`Accessor ${g} not found`);let M=l[y.bufferView||0],L=(M.byteOffset||0)+(y.byteOffset||0),G=M.byteLength||0,p=o.slice(L,L+G);return{acc:y,buffer:p}}let f=new Map;if(u.length>0){let g=cn(n);for(let y=0;y<g.length;y++)f.set(y,g[y])}function d(g,y,M,L){let G=c[g];if(!G)return;let p=new Float32Array(9);$e(p,y);for(let E=0;E<(G.primitives||[]).length;E++){let _=G.primitives[E],P=_.attributes?.POSITION;if(P===void 0)continue;let{acc:z,buffer:R}=m(P),C=new Float32Array(R,0,z.count*3),I=new Float32Array(C.length);for(let F=0;F<z.count;F++){let te=C[F*3],ue=C[F*3+1],le=C[F*3+2];I[F*3]=y[0]*te+y[4]*ue+y[8]*le+y[12],I[F*3+1]=y[1]*te+y[5]*ue+y[9]*le+y[13],I[F*3+2]=y[2]*te+y[6]*ue+y[10]*le+y[14]}let b,T=_.attributes?.NORMAL;if(T!==void 0){let{acc:F,buffer:te}=m(T),ue=new Float32Array(te,0,F.count*3);b=new Float32Array(ue.length);for(let le=0;le<F.count;le++){let he=ue[le*3],xe=ue[le*3+1],Me=ue[le*3+2],pe=p[0]*he+p[3]*xe+p[6]*Me,ge=p[1]*he+p[4]*xe+p[7]*Me,S=p[2]*he+p[5]*xe+p[8]*Me,x=Math.hypot(pe,ge,S)||1;b[le*3]=pe/x,b[le*3+1]=ge/x,b[le*3+2]=S/x}}let N,v=_.attributes?.TEXCOORD_0;if(v!==void 0){let{acc:F,buffer:te}=m(v);N=new Float32Array(te,0,F.count*2)}let D;if(_.indices!==void 0){let{acc:F,buffer:te}=m(_.indices);F.componentType===5125?D=new Uint32Array(te,0,F.count):D=new Uint16Array(te,0,F.count);let ue=z.count;for(let le of D)if(le>=ue)throw new Error(`SecurityError: Index buffer value (${le}) out of vertex bounds [0, ${ue}).`)}else{let F=z.count;D=F>65535?new Uint32Array(F):new Uint16Array(F);for(let te=0;te<F;te++)D[te]=te}let h="DefaultMaterial",A=[.8,.8,.8],$=.5,V=.1,K=0,k=0,ee=1.5,Q=1,q=[0,0,0];if(_.material!==void 0&&a[_.material]){let F=a[_.material];h=F.name||`Material_${_.material}`;let te=F.pbrMetallicRoughness||{},ue=1;Array.isArray(te.baseColorFactor)&&(A=[te.baseColorFactor[0],te.baseColorFactor[1],te.baseColorFactor[2]],typeof te.baseColorFactor[3]=="number"&&(ue=te.baseColorFactor[3])),typeof te.roughnessFactor=="number"&&($=te.roughnessFactor),typeof te.metallicFactor=="number"&&(V=te.metallicFactor),Array.isArray(F.emissiveFactor)&&F.emissiveFactor.length>=3&&(q=[F.emissiveFactor[0],F.emissiveFactor[1],F.emissiveFactor[2]]);let le=F.extensions||{};le.KHR_materials_clearcoat&&(K=le.KHR_materials_clearcoat.clearcoatFactor??0,k=le.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),le.KHR_materials_ior&&typeof le.KHR_materials_ior.ior=="number"&&(ee=le.KHR_materials_ior.ior);let he=le.KHR_materials_transmission?.transmissionFactor??0;Q=ue*(1-he)}let ae=(G.primitives||[]).length>1?`${M}_p${E}`:M;e.push({name:ae,positions:I,indices:D,normals:b,uvs:N,materialName:h,color:A,roughness:$,metallic:V,clearcoat:K,clearcoatRoughness:k,ior:ee,opacity:Q,emissiveColor:q,xrTraits:L?.xr||G.extras?.xr})}}if(u.length>0)for(let g=0;g<u.length;g++){let y=u[g];if(y.mesh!==void 0&&y.mesh<c.length){let M=f.get(g)||ke(),L=y.name||c[y.mesh].name||`Node_${g}`,G=y.extensions?.EXT_mesh_gpu_instancing?.attributes;if(G&&typeof G=="object"){let p=G.TRANSLATION,E=G.ROTATION,_=G.SCALE,P=p!==void 0?(()=>{let{acc:I,buffer:b}=m(p);return new Float32Array(b,0,I.count*3)})():null,z=E!==void 0?(()=>{let{acc:I,buffer:b}=m(E);return new Float32Array(b,0,I.count*4)})():null,R=_!==void 0?(()=>{let{acc:I,buffer:b}=m(_);return new Float32Array(b,0,I.count*3)})():null,C=Math.min(1e3,P?P.length/3:z?z.length/4:R?R.length/3:0);if(C>0){let I=new Float32Array(16),b=new Float32Array(16);for(let T=0;T<C;T++){let N=P?[P[T*3],P[T*3+1],P[T*3+2]]:[0,0,0],v=z?[z[T*4],z[T*4+1],z[T*4+2],z[T*4+3]]:[0,0,0,1],D=R?[R[T*3],R[T*3+1],R[T*3+2]]:[1,1,1];vt(I,v,N,D),De(b,M,I),d(y.mesh,b,`${L}_${T}`,y.extras)}continue}}d(y.mesh,M,L,y.extras)}}else{let g=ke();for(let y=0;y<c.length;y++){let M=c[y].name||`Mesh_${y}`;d(y,g,M,c[y].extras)}}return e}function rr(t,e){if(!t||typeof t!="string")return e;let n=t.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(n)&&(n="_"+n),n||e}function Jr(t){return String(t??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Te(t){if(!Number.isFinite(t)||Math.abs(t)<1e-7)return"0";let e=Number(t.toFixed(5)).toString();return e.indexOf(".")===-1?`${e}.0`:e}function ei(t){{let r=globalThis.__three_live_native_format_usda_points__;if(typeof r=="function")return r(t)}let e=t.length/3,n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Te(t[r*3])}, ${Te(t[r*3+1])}, ${Te(t[r*3+2])})`;return n.join(", ")}function eo(t,e){{let r=globalThis.__three_live_native_format_usda_uvs__;if(typeof r=="function")return r(t)}let n=new Array(e);for(let r=0;r<e;r++)n[r]=`(${Te(t[r*2])}, ${Te(1-t[r*2+1])})`;return n.join(", ")}function to(t){{let e=globalThis.__three_live_native_format_usda_ints__;if(typeof e=="function")return e(t)}return Array.from(t).join(", ")}function ir(t){let e=new Map;for(let a of t){let c=rr(a.materialName,"DefaultMaterial");e.has(c)||e.set(c,{color:a.color||[.8,.8,.8],roughness:a.roughness??.5,metallic:a.metallic??0,clearcoat:a.clearcoat??0,clearcoatRoughness:a.clearcoatRoughness??0,ior:a.ior??1.5,opacity:a.opacity??1,emissiveColor:a.emissiveColor||[0,0,0]})}let n=0,r=null;for(let a of t){if(a.timeSamples&&a.timeSamples.times.length>0){let c=a.timeSamples.times[a.timeSamples.times.length-1];c>n&&(n=c)}a.xrTraits?.anchor&&!r&&(r=a.xrTraits.anchor==="vertical"||a.xrTraits.anchor==="wall"?"vertical":"horizontal")}let i="";n>0&&(i=`startTimeCode = 0
|
|
252
254
|
endTimeCode = ${Te(n)}
|
|
253
255
|
timeCodesPerSecond = 1.0
|
|
254
256
|
`);let o="";r&&(o=`uniform token preliminary:anchoring:type = "plane"
|
|
@@ -266,61 +268,61 @@ kind = "component"
|
|
|
266
268
|
{
|
|
267
269
|
${o}def Scope "Materials"
|
|
268
270
|
{
|
|
269
|
-
`;for(let[a,c]of e.entries()){let[u,f
|
|
270
|
-
`,
|
|
271
|
-
`),c.ior!==1.5&&(
|
|
272
|
-
`),c.opacity<1&&(
|
|
273
|
-
`),(d>0||
|
|
271
|
+
`;for(let[a,c]of e.entries()){let[u,m,f]=c.color,[d,g,y]=c.emissiveColor,M="";c.clearcoat>0&&(M+=`float inputs:clearcoat = ${Te(c.clearcoat)}
|
|
272
|
+
`,M+=`float inputs:clearcoatRoughness = ${Te(c.clearcoatRoughness)}
|
|
273
|
+
`),c.ior!==1.5&&(M+=`float inputs:ior = ${Te(c.ior)}
|
|
274
|
+
`),c.opacity<1&&(M+=`float inputs:opacity = ${Te(c.opacity)}
|
|
275
|
+
`),(d>0||g>0||y>0)&&(M+=`color3f inputs:emissiveColor = (${Te(d)}, ${Te(g)}, ${Te(y)})
|
|
274
276
|
`),s+=`def Material "${a}"
|
|
275
277
|
{
|
|
276
278
|
def Shader "PBRShader"
|
|
277
279
|
{
|
|
278
280
|
uniform token info:id = "UsdPreviewSurface"
|
|
279
|
-
color3f inputs:diffuseColor = (${Te(u)}, ${Te(
|
|
281
|
+
color3f inputs:diffuseColor = (${Te(u)}, ${Te(m)}, ${Te(f)})
|
|
280
282
|
float inputs:metallic = ${Te(c.metallic)}
|
|
281
283
|
float inputs:roughness = ${Te(c.roughness)}
|
|
282
|
-
${
|
|
284
|
+
${M}token outputs:surface
|
|
283
285
|
}
|
|
284
286
|
token outputs:surface.connect = </Root/Materials/${a}/PBRShader.outputs:surface>
|
|
285
287
|
}
|
|
286
288
|
`}s+=`}
|
|
287
289
|
def Scope "Meshes"
|
|
288
290
|
{
|
|
289
|
-
`;let l=new Set;for(let a=0;a<t.length;a++){let c=t[a],u=c.positions.length/3,
|
|
291
|
+
`;let l=new Set;for(let a=0;a<t.length;a++){let c=t[a],u=c.positions.length/3,m=1/0,f=1/0,d=1/0,g=-1/0,y=-1/0,M=-1/0;for(let z=0;z<u;z++){let R=c.positions[z*3],C=c.positions[z*3+1],I=c.positions[z*3+2];R<m&&(m=R),R>g&&(g=R),C<f&&(f=C),C>y&&(y=C),I<d&&(d=I),I>M&&(M=I)}isFinite(m)||(m=f=d=-1,g=y=M=1);let L=Math.floor(c.indices.length/3),G=rr(c.materialName,"DefaultMaterial"),p=rr(c.name,`Mesh_${a}`);l.has(p)&&(p=`${p}_${a}`),l.add(p);let E=L>0?L===1?"3":"3, ".repeat(L-1)+"3":"",_=c.xrTraits,P="";if(_){let z=[];_.physics&&_.physics!=="none"&&z.push('prepend apiSchemas = ["PhysicsBodyAPI", "PhysicsCollisionAPI"]');let R=Ie().xrTraitSerializer?.usdLines(_,Jr)??[];if(!R.length)for(let C of["grab","billboard","follow","anchor","physics"]){let I=C==="follow"&&typeof _.follow=="object"?_.follow.mode??"head":_[C];I!==void 0&&R.push(`string ${C} = "${Jr(I)}"`)}R.length>0&&z.push(`customData = {
|
|
290
292
|
dictionary xr = {
|
|
291
|
-
${
|
|
293
|
+
${R.join(`
|
|
292
294
|
`)}
|
|
293
295
|
}
|
|
294
|
-
}`),z.length>0&&(
|
|
296
|
+
}`),z.length>0&&(P=` (
|
|
295
297
|
${z.join(`
|
|
296
298
|
`)}
|
|
297
|
-
)`)}if(s+=`def Mesh "${
|
|
299
|
+
)`)}if(s+=`def Mesh "${p}"${P}
|
|
298
300
|
{
|
|
299
|
-
`,
|
|
301
|
+
`,_?.physics&&_.physics!=="none"){let z=_.physics==="static"?"true":"false";s+=`bool physics:rigidBodyEnabled = true
|
|
300
302
|
bool physics:kinematicEnabled = ${z}
|
|
301
303
|
bool physics:collisionEnabled = true
|
|
302
|
-
`}if(c.timeSamples&&c.timeSamples.times.length>0){let z=c.timeSamples,
|
|
303
|
-
quatf xformOp:orient.timeSamples = { ${
|
|
304
|
-
double3 xformOp:scale.timeSamples = { ${
|
|
304
|
+
`}if(c.timeSamples&&c.timeSamples.times.length>0){let z=c.timeSamples,R=z.times.map((b,T)=>{let N=z.translations?.[T]||[0,0,0];return`${Te(b)}: (${Te(N[0])}, ${Te(N[1])}, ${Te(N[2])})`}).join(", "),C=z.times.map((b,T)=>{let N=z.rotations?.[T]||[0,0,0,1];return`${Te(b)}: (${Te(N[3])}, ${Te(N[0])}, ${Te(N[1])}, ${Te(N[2])})`}).join(", "),I=z.times.map((b,T)=>{let N=z.scales?.[T]||[1,1,1];return`${Te(b)}: (${Te(N[0])}, ${Te(N[1])}, ${Te(N[2])})`}).join(", ");s+=`double3 xformOp:translate.timeSamples = { ${R} }
|
|
305
|
+
quatf xformOp:orient.timeSamples = { ${C} }
|
|
306
|
+
double3 xformOp:scale.timeSamples = { ${I} }
|
|
305
307
|
uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
|
|
306
|
-
`}s+=`float3[] extent = [(${Te(
|
|
307
|
-
int[] faceVertexCounts = [${
|
|
308
|
+
`}s+=`float3[] extent = [(${Te(m)}, ${Te(f)}, ${Te(d)}), (${Te(g)}, ${Te(y)}, ${Te(M)})]
|
|
309
|
+
int[] faceVertexCounts = [${E}]
|
|
308
310
|
int[] faceVertexIndices = [${to(c.indices)}]
|
|
309
|
-
point3f[] points = [${
|
|
310
|
-
`,c.normals&&c.normals.length===c.positions.length&&(s+=`normal3f[] normals = [${
|
|
311
|
+
point3f[] points = [${ei(c.positions)}]
|
|
312
|
+
`,c.normals&&c.normals.length===c.positions.length&&(s+=`normal3f[] normals = [${ei(c.normals)}] (
|
|
311
313
|
interpolation = "vertex"
|
|
312
314
|
)
|
|
313
315
|
`),c.uvs&&c.uvs.length===u*2&&(s+=`texCoord2f[] primvars:st = [${eo(c.uvs,u)}] (
|
|
314
316
|
interpolation = "vertex"
|
|
315
317
|
)
|
|
316
|
-
`),s+=`rel material:binding = </Root/Materials/${
|
|
318
|
+
`),s+=`rel material:binding = </Root/Materials/${G}>
|
|
317
319
|
}
|
|
318
320
|
`}return s+=`}
|
|
319
321
|
}
|
|
320
|
-
`,s}function no(t,e){if(t&&typeof t.traverse=="function"){let i=Ji(t,e);return or(i)}let n=Gt(t),r=ni(n);return or(r)}var hn=null;function ro(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!hn){hn=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;hn[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=hn[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function ri(t){{let u=globalThis.__three_live_native_build_usdz_zip__;if(typeof u=="function")return u(t)}let e=[],n=0,r=[];for(let u of t){let f=fn(u.filename),h=ro(u.data),d=u.data.length,y=30+f.length,x=n+y,T=0,D=x%64;D!==0&&(T=64-D);let V=new Uint8Array(y+T),b=new DataView(V.buffer);b.setUint32(0,67324752,!0),b.setUint16(4,20,!0),b.setUint16(6,0,!0),b.setUint16(8,0,!0),b.setUint16(10,0,!0),b.setUint16(12,0,!0),b.setUint32(14,h,!0),b.setUint32(18,d,!0),b.setUint32(22,d,!0),b.setUint16(26,f.length,!0),b.setUint16(28,T,!0),V.set(f,30),T>0&&V.fill(0,30+f.length),e.push({offset:n,size:d,crc:h,filenameBytes:f,entry:u}),r.push(V),r.push(u.data),n+=V.length+u.data.length}let i=n;for(let u of e){let f=new Uint8Array(46+u.filenameBytes.length),h=new DataView(f.buffer);h.setUint32(0,33639248,!0),h.setUint16(4,20,!0),h.setUint16(6,20,!0),h.setUint16(8,0,!0),h.setUint16(10,0,!0),h.setUint16(12,0,!0),h.setUint16(14,0,!0),h.setUint32(16,u.crc,!0),h.setUint32(20,u.size,!0),h.setUint32(24,u.size,!0),h.setUint16(28,u.filenameBytes.length,!0),h.setUint16(30,0,!0),h.setUint16(32,0,!0),h.setUint16(34,0,!0),h.setUint16(36,0,!0),h.setUint32(38,0,!0),h.setUint32(42,u.offset,!0),f.set(u.filenameBytes,46),r.push(f),n+=f.length}let o=n-i,s=new Uint8Array(22),l=new DataView(s.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(s),n+=22;let a=new Uint8Array(n),c=0;for(let u of r)a.set(u,c),c+=u.length;return a}function Ut(t){let e=no(t),n=fn(e);return ri([{filename:"model.usda",data:n}])}function mn(t){let e=Gt(t),n=ni(e),r=or(n),i=fn(r);return ri([{filename:"model.usda",data:i}])}function sr(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Ut(t):mn(t)}function re(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function et(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function de(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function Xe(t,e=256){return typeof t=="string"&&t.length>0?t.slice(0,e):void 0}function io(t){let e=de(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:re(e.distance,.1,10,r?.15:1),deadzoneDeg:re(e.deadzoneDeg,0,90,r?0:15),stiffness:re(e.stiffness,.5,40,6),height:re(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function oo(t){let e=de(t);if(!e)return null;let n=e.target;return{target:et(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:re(e.radius,.01,50,.5),speed:re(e.speed,-20,20,.5),height:re(e.height,-10,10,0),phase:re(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function so(t){if(!t)return null;let e=de(t)??{},n=re(e.minScale,.001,1e3,.1),r=re(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var ai=2e3,ao={rain:600,snow:400,sparks:300,confetti:300};function co(t){let e=de(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=s=>re(s,.05,50,2),o=et(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(re(e.count,1,ai,ao[n])),area:o,speed:re(e.speed,.05,10,1)}}var uo=4e3;function lo(t){if(!t)return null;let e=de(t)??{};return{prompt:Xe(e.prompt,uo)??"What is this?",holdMs:re(e.holdMs,100,5e3,600)}}function ho(t){if(!t)return null;let e=de(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function pn(t){let e=Xe(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 fo(t){if(typeof t=="string"){let r=pn(t);return r?{src:r,refDistance:1,loop:!1}:null}let e=de(t),n=pn(e?.src);return!e||!n?null:{src:n,refDistance:re(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function Tt(t,e){let n=Xe(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var mo=new Set(["m","cm","mm","in","ft-in","auto"]),ii=["x","y","z"];function po(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&mo.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(l=>typeof l=="string"):typeof i=="string"?i.split(""):[]),s=ii.filter(l=>o.has(l));return{enabled:!0,unit:r,axes:s.length>0?s:[...ii],color:Tt(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var bo=new Set(["none","floor","wall","ceiling","any"]);function yo(t){if(!t)return null;let e=de(t)??{},n=e.grid,r=s=>re(s,.001,100,.1),i=et(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:re(e.angleDeg,0,180,0),surface:typeof o=="string"&&bo.has(o)?o:"none",socketTag:Xe(e.socketTag,128)??"",radius:re(e.radius,.01,2,.15)}}function go(t){if(typeof t=="string"){let r=Xe(t,128);return r?{tag:r,radius:.15,alignRotation:!0,highlightColor:"#22c55e"}:null}let e=de(t),n=Xe(e?.tag,128);return!e||!n?null:{tag:n,radius:re(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:Tt(e.highlightColor,"#22c55e")}}function xo(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(re(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function vo(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(et(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:re(e?.distance,0,10,.35),layer:Math.round(re(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var bn=new Set(["__proto__","constructor","prototype"]);function wt(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||bn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function ar(t){let e=de(t);if(!e||e.persist===!1)return null;let n=wt(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function wo(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function To(t){if(typeof t=="string"){let s=Xe(t,256);return s?{text:s,size:.12,depth:.02,color:"#ffffff"}:null}let e=de(t);if(!e)return null;let n=Xe(e.text??e.value,256);if(!n)return null;let r=re(e.size,.005,10,.12),i=re(e.depth??e.height,.001,5,r*.2),o=Tt(e.color,"#ffffff");return{text:n,size:r,depth:i,color:o}}function Mo(t){if(t===!1||t===null||t===void 0)return null;if(typeof t=="number")return!Number.isFinite(t)||t<=0?null:{enabled:!0,strength:re(t,0,5,.35),threshold:.8,radius:.5};if(t===!0)return{enabled:!0,strength:.35,threshold:.8,radius:.5};let e=de(t);if(!e||e.enabled===!1)return null;let n=re(e.strength??e.intensity,0,5,.35);return n<=0?null:{enabled:!0,strength:n,threshold:re(e.threshold,0,4,.8),radius:re(e.radius,0,2,.5)}}function So(t){if(!t)return null;if(typeof t=="string")return{enabled:!0,color:Tt(t,"#38bdf8"),thickness:3,pulse:!1};if(t===!0)return{enabled:!0,color:"#38bdf8",thickness:3,pulse:!1};let e=de(t);if(!e||e.enabled===!1)return null;let n=e.thickness??e.width;return{enabled:!0,color:Tt(e.color,"#38bdf8"),thickness:re(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:e.pulse===!0}}function Ao(t){let e=de(t);if(!e||e.enabled===!1)return null;let n=wt(e.root),r=wt(e.effector);if(!n||!r)return null;let i=wt(e.mid),o=e.target,s;if(et(o))s=[re(o[0],-1e3,1e3,0),re(o[1],-1e3,1e3,0),re(o[2],-1e3,1e3,0)];else{let u=wt(o);if(!u)return null;s=u}let l=e.pole??e.poleTarget,a=et(l)?[re(l[0],-1e3,1e3,0),re(l[1],-1e3,1e3,0),re(l[2],-1e3,1e3,0)]:wt(l),c=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||i?"two-bone":"fabrik";return{root:n,...i?{mid:i}:{},effector:r,target:s,...a?{pole:a}:{},solver:c,iterations:Math.round(re(e.iterations,1,32,8)),tolerance:re(e.tolerance,1e-5,.1,.001),weight:re(e.weight,0,1,1)}}var oi=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),Ro=new Set(["capsule","cylindrical","spherical"]),$t=[];function ci(t){$t.includes(t)||$t.push(t)}function yn(t){let e=de(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=P=>n.includes(P),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let s=e.scale??e.scalable;if(s||r("scale")){let P=de(s)??{},v=re(P.min,.001,1e3,.05);i.scale={min:v,max:re(P.max,v,1e3,Math.max(v,5))},i.scalable=!0}let l=e.billboard;typeof l=="string"&&Ro.has(l)?i.billboard=l:(l===!0||r("billboard"))&&(i.billboard="capsule");let a=e.follow,c=typeof a=="string"?a:de(a)?.mode;if(typeof a=="string"?a:de(a)?.lazy===!1)i.follow=c==="hand-left"||c==="hand-right"?c:"head";else{let P=io(a);P&&(i.follow=P)}let u=e.anchor;if(typeof u=="string"&&oi.has(u))i.anchor=u;else{let v=de(u)?.target;typeof v=="string"&&oi.has(v)&&(i.anchor=v);let p=ar(u)??ar(e.anchorPersist);p&&(i.anchorPersist=p)}if(!i.anchorPersist){let P=ar(e.anchorPersist);P&&(i.anchorPersist=P)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let f=oo(e.orbit);f&&(i.orbit=f);let h=so(e.handles);h&&(i.handles=h);let d=co(e.particles);d&&(i.particles=d);let y=lo(e.holdToAsk);y&&(i.holdToAsk=y);let x=ho(e.worldUnderstanding);x&&(i.worldUnderstanding=x);let T=pn(e.splatUrl);T&&(i.splatUrl=T),(e.splatQuality==="high"||e.splatQuality==="standard")&&(i.splatQuality=e.splatQuality);let D=Xe(e.spatialSlot);D&&(i.spatialSlot=D);let V=fo(e.audio);V&&(i.audio=V);let b=po(e.dimensions);b&&(i.dimensions=b);let _=yo(e.snapTo);_&&(i.snapTo=_);let S=go(e.snapSocket);S&&(i.snapSocket=S);let U=xo(e.gaze);U&&(i.gaze=U);let z=vo(e.explode);z&&(i.explode=z);let I=wo(e.navigable);I&&(i.navigable=I);let E=To(e.text);E&&(i.text=E);let R=Mo(e.bloom);R&&(i.bloom=R);let g=So(e.outline);g&&(i.outline=g);let M=Ao(e.ik);M&&(i.ik=M),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let P of $t)P.normalize(e,i);return Object.keys(i).length>0?i:null}function ur(t){let e={};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 n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}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.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]}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of $t)n.sceneCore(t,e);return e}function Eo(t){let e={},n=(r,i)=>{for(let[o,s]of Object.entries(i)){let l=r+o[0].toUpperCase()+o.slice(1);typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[l]=s:et(s)&&(e[l]=[s[0],s[1],s[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("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&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&n("text",t.text),t.bloom&&n("bloom",t.bloom),t.outline&&n("outline",t.outline),t.ik&&n("ik",t.ik),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of $t)r.usd(t,n,e);return e}function _o(t,e){let n=yn(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:lr(n),ANDROID_xr_scenecore:ur(n)}}function lr(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 n=yn(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(Eo(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(s=>Number.isFinite(s))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function ui(){try{Object.defineProperty(ke(),"xrTraitSerializer",{value:Object.freeze({gltfNode:_o,usdLines:Co}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var cr=new Set(["grab","scale","billboard","follow","anchor","anchorPersist","physics","orbit","handles","particles","holdToAsk","worldUnderstanding","splatUrl","splatQuality","spatialSlot","audio","dimensions","snapTo","snapSocket","gaze","explode","navigable","text","bloom","outline","ik","sync","pointerEvents","character","agent","integrity","zone","spawner","objective","audioCues","collidable","traits"]),dn={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:"audio",hint:`Use 'audio: { src: "..." }' or 'audioCues' instead of 'sound'.`},sfx:{target:"audioCues",hint:`Use 'audioCues: { onTap: "confirm" }' instead of 'sfx'.`},measure:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measure'."},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'.`},caption:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'caption'.`},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'."},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 Io(t,e){let n=t.length,r=e.length,i=Array.from({length:r+1},(o,s)=>s);for(let o=1;o<=n;o++){let s=i[0];i[0]=o;for(let l=1;l<=r;l++){let a=i[l];i[l]=t[o-1]===e[l-1]?s:1+Math.min(s,i[l],i[l-1]),s=a}}return i[r]}function si(t){let e=t.toLowerCase(),n=null,r=4;for(let i of cr){if(i==="traits")continue;let o=Io(e,i.toLowerCase());o<r&&(r=o,n=i)}return n}function li(t,e="unnamed"){let n=[];if(t==null)return n;let r=de(t);if(!r)return n.push({code:"TL201",severity:"warning",node:e,message:`userData.xr on node '${e}' must be a plain object.`,hint:"Assign an object such as mesh.userData.xr = { grab: true }."}),n;for(let p of Object.keys(r)){if(cr.has(p))continue;let m=dn[p]??dn[p.toLowerCase()];if(m)n.push({code:"TL201",severity:"warning",node:e,message:`Unrecognized key '${p}' in userData.xr on node '${e}'; did you mean '${m.target}'?`,hint:m.hint});else{let L=si(p);n.push({code:"TL201",severity:"warning",node:e,message:L?`Unknown key '${p}' on node '${e}'; did you mean '${L}'?`:`Unknown key '${p}' in userData.xr on node '${e}'.`,hint:L?`Replace '${p}' with '${L}'.`:"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(r.traits)){for(let p of r.traits)if(typeof p=="string"&&!cr.has(p)){let m=dn[p]??dn[p.toLowerCase()],L=m?.target??si(p);n.push({code:"TL201",severity:"warning",node:e,message:L?`Unknown trait '${p}' in userData.xr.traits on node '${e}'; did you mean '${L}'?`:`Unknown trait '${p}' in userData.xr.traits on node '${e}'.`,hint:m?.hint??(L?`Use '${L}' instead of '${p}'.`:"Use canonical trait keys on userData.xr directly.")})}}let i=(p,m,L,W)=>{if(typeof m=="number"){if(!Number.isFinite(m)){n.push({code:"TL202",severity:"warning",node:e,message:`Numeric trait parameter '${p}' on node '${e}' is non-finite (${m}); clamped to default.`,hint:`Provide a finite number in [${L}, ${W}] for '${p}'.`});return}if(m<L||m>W){let G=Math.max(L,Math.min(W,m));n.push({code:"TL202",severity:"warning",node:e,message:`Numeric trait parameter '${p}' (${m}) on node '${e}' is out of range [${L}, ${W}]; clamped to ${G}.`,hint:`Keep '${p}' within [${L}, ${W}].`})}}},o=de(r.scale);if(o){i("scale.min",o.min,.001,1e3);let p=re(o.min,.001,1e3,.05);i("scale.max",o.max,p,1e3)}let s=de(r.follow);s&&s.lazy!==!1&&(i("follow.distance",s.distance,.1,10),i("follow.deadzoneDeg",s.deadzoneDeg,0,90),i("follow.stiffness",s.stiffness,.5,40),i("follow.height",s.height,-2,2));let l=de(r.orbit);l&&(i("orbit.radius",l.radius,.01,50),i("orbit.speed",l.speed,-20,20),i("orbit.height",l.height,-10,10),i("orbit.phase",l.phase,-1e6,1e6));let a=de(r.handles);if(a){i("handles.minScale",a.minScale,.001,1e3);let p=re(a.minScale,.001,1e3,.1);i("handles.maxScale",a.maxScale,p,1e3)}let c=de(r.particles);if(c){if(i("particles.count",c.count,1,ai),i("particles.speed",c.speed,.05,10),typeof c.area=="number")i("particles.area",c.area,.05,50);else if(Array.isArray(c.area))for(let p=0;p<Math.min(3,c.area.length);p++)i(`particles.area[${p}]`,c.area[p],.05,50)}let u=de(r.holdToAsk);u&&i("holdToAsk.holdMs",u.holdMs,100,5e3);let f=de(r.audio);f&&i("audio.refDistance",f.refDistance,.01,1e3);let h=de(r.snapTo);if(h){if(i("snapTo.angleDeg",h.angleDeg,0,180),i("snapTo.radius",h.radius,.01,2),typeof h.grid=="number"&&h.grid>0)i("snapTo.grid",h.grid,.001,100);else if(Array.isArray(h.grid))for(let p=0;p<Math.min(3,h.grid.length);p++)i(`snapTo.grid[${p}]`,h.grid[p],.001,100)}let d=de(r.snapSocket);d&&i("snapSocket.radius",d.radius,.01,2);let y=de(r.gaze);y&&y.enabled!==!1&&i("gaze.dwellMs",y.dwellMs,250,1e4);let x=de(r.explode);x&&x.enabled!==!1&&(i("explode.distance",x.distance,0,10),i("explode.layer",x.layer,1,10));let T=de(r.text);if(T&&(i("text.size",T.size,.005,10),i("text.depth",T.depth??T.height,.001,5)),typeof r.bloom=="number"&&r.bloom>0)i("bloom",r.bloom,0,5);else{let p=de(r.bloom);p&&p.enabled!==!1&&(i("bloom.strength",p.strength??p.intensity,0,5),i("bloom.threshold",p.threshold,0,4),i("bloom.radius",p.radius,0,2))}let D=de(r.outline);if(D&&D.enabled!==!1){let p=D.thickness??D.width;typeof p=="number"&&!(p>0&&p<.25)&&i("outline.thickness",p,.5,20)}let V=de(r.ik);V&&V.enabled!==!1&&(i("ik.iterations",V.iterations,1,32),i("ik.tolerance",V.tolerance,1e-5,.1),i("ik.weight",V.weight,0,1));let b=de(r.character);if(b&&b.enabled!==!1){i("character.speed",b.speed,.1,20),i("character.runMultiplier",b.runMultiplier,1,4),i("character.jumpVelocity",b.jumpVelocity,0,30),i("character.gravity",b.gravity,0,50),i("character.radius",b.radius,.05,5);let p=re(b.radius,.05,5,.35);i("character.height",b.height,p*2,10),i("character.cameraDistance",b.cameraDistance,.5,50),i("character.cameraHeight",b.cameraHeight,-10,50)}let _=de(r.agent);if(_&&_.enabled!==!1&&(i("agent.speed",_.speed,.1,20),i("agent.turnSpeed",_.turnSpeed,.1,50),i("agent.sightRadius",_.sightRadius,0,100),i("agent.stopDistance",_.stopDistance,.01,10),i("agent.separationRadius",_.separationRadius,0,10)),typeof r.integrity=="number")i("integrity.max",r.integrity,1,1e6);else{let p=de(r.integrity);if(p&&p.enabled!==!1){i("integrity.max",p.max,1,1e6);let m=re(p.max,1,1e6,100);i("integrity.current",p.current,0,m),i("integrity.cooldownMs",p.cooldownMs,0,1e4),i("integrity.scoreValue",p.scoreValue,-1e6,1e6),i("integrity.contactAmount",p.contactAmount,0,1e6)}}let S=de(r.zone);if(S&&S.enabled!==!1){if(i("zone.radius",S.radius,.01,1e3),typeof S.size=="number")i("zone.size",S.size,.01,1e3);else if(Array.isArray(S.size))for(let p=0;p<Math.min(3,S.size.length);p++)i(`zone.size[${p}]`,S.size[p],.01,1e3)}let U=de(r.spawner);U&&U.enabled!==!1&&(i("spawner.intervalSec",U.intervalSec,.05,3600),i("spawner.maxActive",U.maxActive,1,32),i("spawner.totalCount",U.totalCount,0,1e4),i("spawner.spawnRadius",U.spawnRadius,0,100));let z=de(r.objective);z&&z.enabled!==!1&&(i("objective.amount",z.amount??z.points,-1e6,1e6),i("objective.radius",z.radius,.05,50),i("objective.order",z.order,0,1e3),i("objective.spinSpeed",z.spinSpeed,-50,50),i("objective.bobAmplitude",z.bobAmplitude,0,5),i("objective.respawnSec",z.respawnSec,0,3600));let I=de(r.audioCues);I&&(i("audioCues.pitchJitter",I.pitchJitter,0,.5),i("audioCues.volume",I.volume,0,1));let E=(p,m)=>{m!=null&&(pn(m)||n.push({code:"TL203",severity:"error",node:e,message:`Unsafe or disallowed media URL in '${p}' (${JSON.stringify(m)}) on node '${e}' rejected by safeMediaUrl().`,hint:"Use an 'https://' URL or a clean relative path without '..', '\\\\', '%', or custom schemes (e.g. http:, javascript:, file:, data:)."}))},R=(p,m)=>{m!=null&&(wt(m)||n.push({code:"TL203",severity:"error",node:e,message:`Unsafe or invalid identifier in '${p}' (${JSON.stringify(m)}) on node '${e}' rejected by safeAnchorId().`,hint:"Anchor and bone identifiers must be non-empty strings without control characters or prototype-pollution keys ('__proto__', 'constructor', 'prototype')."}))};r.splatUrl!==void 0&&r.splatUrl!==null&&E("splatUrl",r.splatUrl),typeof r.audio=="string"?E("audio",r.audio):f&&(f.src!==void 0?E("audio.src",f.src):Object.keys(f).some(p=>p.startsWith("on"))&&n.push({code:"TL201",severity:"warning",node:e,message:`userData.xr.audio on node '${e}' contains event keys without 'src'; did you mean 'audioCues'?`,hint:`Use 'audioCues: { onTap: "confirm", onHit: "impact" }' for procedural synth cues, or provide 'audio: { src: "https://..." }' for spatial audio files.`}));let g=(p,m)=>{if(m==null||m==="")return;let L=typeof m=="string"?m.trim():"";(!L||!/^[A-Za-z0-9_.:-]{1,64}$/.test(L)||bn.has(L))&&n.push({code:"TL203",severity:"error",node:e,message:`Unsafe or invalid identifier in '${p}' (${JSON.stringify(m)}) on node '${e}' rejected by safeSimId().`,hint:"Simulation group/tag IDs must be 1-64 characters of [A-Za-z0-9_.:-] and must not use prototype-pollution keys ('__proto__', 'constructor', 'prototype')."})},M=de(r.integrity);if(M&&M.group!==void 0&&g("integrity.group",M.group),S&&S.watchGroups!==void 0){let p=Array.isArray(S.watchGroups)?S.watchGroups:[S.watchGroups];for(let m=0;m<p.length;m++)g(`zone.watchGroups[${m}]`,p[m])}z&&z.tag!==void 0&&g("objective.tag",z.tag);let P=de(r.anchor);P&&P.id!==void 0&&R("anchor.id",P.id);let v=de(r.anchorPersist);if(v&&v.id!==void 0&&R("anchorPersist.id",v.id),V&&V.enabled!==!1){R("ik.root",V.root),R("ik.effector",V.effector),V.mid!==void 0&&R("ik.mid",V.mid),V.target!==void 0&&!Array.isArray(V.target)&&R("ik.target",V.target);let p=V.pole??V.poleTarget;p!==void 0&&!Array.isArray(p)&&R("ik.pole",p)}return n}function fr(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!bn.has(e)?e:void 0}function gn(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var ko=["third-person","first-person","top-down","fixed"],Do=["idle","walk","run","jump"];function Lo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=re(e.radius,.05,5,.35),r=de(e.clips)??{},i={};for(let o of Do){let s=Xe(r[o],128);s&&(i[o]=s)}return{speed:re(e.speed,.1,20,4),runMultiplier:re(e.runMultiplier,1,4,1.6),jumpVelocity:re(e.jumpVelocity,0,30,5.5),gravity:re(e.gravity,0,50,15),radius:n,height:re(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:gn(e.cameraMode,ko,"third-person"),cameraDistance:re(e.cameraDistance,.5,50,3.5),cameraHeight:re(e.cameraHeight,-10,50,1.8),clips:i}}var Po=["patrol","chase","flee","wander","follow"],No=32,hr="user";function Uo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=gn(e.mode,Po,"wander"),r=e.target,i=r==="camera"||r===hr?hr:Xe(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=hr);let o=l=>re(l,-1e4,1e4,0),s=Array.isArray(e.waypoints)?e.waypoints.filter(et).slice(0,No).map(l=>[o(l[0]),o(l[1]),o(l[2])]):[];return{mode:n,target:i,speed:re(e.speed,.1,20,2),turnSpeed:re(e.turnSpeed,.1,50,6),sightRadius:re(e.sightRadius,0,100,6),stopDistance:re(e.stopDistance,.01,10,.6),separationRadius:re(e.separationRadius,0,10,.8),waypoints:s,loopWaypoints:e.loopWaypoints!==!1}}function Oo(t){if(!t)return null;let e=de(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=re(e.max,1,1e6,100);return{max:n,current:re(e.current,0,n,n),group:fr(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(re(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:re(e.scoreValue,-1e6,1e6,0),contactAmount:re(e.contactAmount,0,1e6,0)}}var Fo=16;function zo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=gn(e.shape,["box","sphere"],"box"),r=e.size,i=f=>re(f,.01,1e3,1),o=et(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],s=re(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),l=e.watchGroups,a=[...new Set((Array.isArray(l)?l:l===void 0?[]:[l]).map(fr).filter(f=>f!==void 0))].slice(0,Fo),c={shape:n,size:o,radius:s,watchGroups:a},u=Tt(e.color,"");return u?{...c,color:u}:c}var Vo=32;function Bo(t){let e=de(t)??(typeof t=="string"?{template:t}:null),n=Xe(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:re(e.intervalSec,.05,3600,3),maxActive:Math.round(re(e.maxActive,1,Vo,8)),totalCount:Math.round(re(e.totalCount,0,1e4,0)),spawnRadius:re(e.spawnRadius,0,100,0)}}var Go=["pickup","checkpoint","time-bonus","restore","key"];function Ho(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=gn(e.type,Go,"pickup"),r=n==="pickup";return{type:n,amount:re(e.amount??e.points,-1e6,1e6,10),tag:fr(e.tag)??"",radius:re(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(re(e.order,0,1e3,0)),spinSpeed:re(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:re(e.bobAmplitude,0,5,r?.08:0),respawnSec:re(e.respawnSec,0,3600,0)}}var $o=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Xo=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function jo(t){let e=de(t);if(!e)return null;let n={};for(let r of Xo){let i=e[r];typeof i=="string"&&$o.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:re(e.pitchJitter,0,.5,.08),volume:re(e.volume,0,1,1),spatial:e.spatial!==!1}}var Wo={normalize(t,e){let n=Lo(t.character);n&&(e.character=n);let r=Uo(t.agent);r&&(e.agent=r);let i=Oo(t.integrity);i&&(e.integrity=i);let o=zo(t.zone);o&&(e.zone=o);let s=Bo(t.spawner);s&&(e.spawner=s);let l=Ho(t.objective);l&&(e.objective=l);let a=jo(t.audioCues);a&&(e.audioCues=a),t.collidable===!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(n=>[...n])}),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.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.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.collidable&&(n.collidable=!0)}};function hi(){ci(Wo)}var vn=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},Pe=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,s=n.x,l=n.y,a=n.z;return this.x=i*a-o*l,this.y=o*s-r*a,this.z=r*l-i*s,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,s=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*s,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*s,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*s,this}},wn=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},Wt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Yt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,s=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(o/2),c=Math.sin(r/2),u=Math.sin(i/2),f=Math.sin(o/2);return this._x=c*l*a+s*u*f,this._y=s*u*a-c*l*f,this._z=s*l*f+c*u*a,this._w=s*l*a-c*u*f,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback?.(),this}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,s=e.w,l=n.x,a=n.y,c=n.z,u=n.w;return this._x=r*u+s*l+i*c-o*a,this._y=i*u+s*a+o*l-r*c,this._z=o*u+s*c+r*a-i*l,this._w=s*u-r*l-i*a-o*c,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},it=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,r){return vt(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return Le(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return Dt(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new Pe(0,0,0),r=new Pe(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},Tn=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return $e(this.elements,e.elements),this}},Ze=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},gi={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},ge=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},Mn=class extends ge{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Sn=class extends ge{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},An=class extends ge{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Ke=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof ge)this.index=e;else if(Array.isArray(e)){let n=e.length,r=0;for(let o=0;o<n;o++)e[o]>r&&(r=e[o]);let i=r>65535?new Uint32Array(n):new Uint16Array(n);for(let o=0;o<n;o++)i[o]=e[o];this.index=new ge(i,1)}else e&&e.buffer&&(this.index=new ge(e,1));return this}computeVertexNormals(){let e=this.attributes.position;if(!e)return this;let n=e.count,r=new Float32Array(n*3),i=new Pe,o=new Pe,s=new Pe,l=new Pe,a=new Pe;if(this.index){let c=this.index.array;for(let u=0;u<c.length;u+=3){let f=c[u],h=c[u+1],d=c[u+2];i.set(e.getX(f),e.getY(f),e.getZ(f)),o.set(e.getX(h),e.getY(h),e.getZ(h)),s.set(e.getX(d),e.getY(d),e.getZ(d)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let y of[f,h,d])r[y*3]+=l.x,r[y*3+1]+=l.y,r[y*3+2]+=l.z}}else for(let c=0;c<n;c+=3){i.set(e.getX(c),e.getY(c),e.getZ(c)),o.set(e.getX(c+1),e.getY(c+1),e.getZ(c+1)),s.set(e.getX(c+2),e.getY(c+2),e.getZ(c+2)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let u=0;u<3;u++)r[(c+u)*3]=l.x,r[(c+u)*3+1]=l.y,r[(c+u)*3+2]=l.z}for(let c=0;c<n;c++){let u=r[c*3],f=r[c*3+1],h=r[c*3+2],d=Math.hypot(u,f,h)||1;r[c*3]=u/d,r[c*3+1]=f/d,r[c*3+2]=h/d}return this.setAttribute("normal",new ge(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new ge(e instanceof Float32Array?e:new Float32Array(e),3)),this.setAttribute("normal",new ge(n instanceof Float32Array?n:new Float32Array(n),3)),this.setAttribute("uv",new ge(r instanceof Float32Array?r:new Float32Array(r),2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new Pe(1/0,1/0,1/0),r=new Pe(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),s=e.getY(i),l=e.getZ(i);o<n.x&&(n.x=o),s<n.y&&(n.y=s),l<n.z&&(n.z=l),o>r.x&&(r.x=o),s>r.y&&(r.y=s),l>r.z&&(r.z=l)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),n=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let s=0;s<o.count;s++)o.setXYZ(s,o.getX(s)-n,o.getY(s)-r,o.getZ(s)-i);this.computeBoundingBox()}return this}dispose(){}},Kt=class extends Ke{constructor(e=1,n=1,r=1){super();{let f=globalThis.__three_live_native_box__;if(typeof f=="function"){let h=f(e,n,r);this.setFromBuffers(h.positions,h.normals,h.uvs,h.indices);return}}let i=e/2,o=n/2,s=r/2,l=[-i,-o,s,i,-o,s,i,o,s,-i,o,s,i,-o,-s,-i,-o,-s,-i,o,-s,i,o,-s,-i,o,s,i,o,s,i,o,-s,-i,o,-s,-i,-o,-s,i,-o,-s,i,-o,s,-i,-o,s,i,-o,s,i,-o,-s,i,o,-s,i,o,s,-i,-o,-s,-i,-o,s,-i,o,s,-i,o,-s],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],c=[0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,1],u=[];for(let f=0;f<6;f++){let h=f*4;u.push(h,h+1,h+2,h,h+2,h+3)}this.setAttribute("position",new ge(new Float32Array(l),3)),this.setAttribute("normal",new ge(new Float32Array(a),3)),this.setAttribute("uv",new ge(new Float32Array(c),2)),this.setIndex(u)}},Rn=class extends Ke{constructor(e=1,n=1){super();let r=e/2,i=n/2,o=[-r,i,0,r,i,0,-r,-i,0,r,-i,0],s=[0,0,1,0,0,1,0,0,1,0,0,1],l=[0,1,1,1,0,0,1,0],a=[0,2,1,2,3,1];this.setAttribute("position",new ge(new Float32Array(o),3)),this.setAttribute("normal",new ge(new Float32Array(s),3)),this.setAttribute("uv",new ge(new Float32Array(l),2)),this.setIndex(a)}},qt=class extends Ke{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let c=globalThis.__three_live_native_sphere__;if(typeof c=="function"){let u=c(e,n,r);this.setAttribute("position",new ge(u.positions,3)),this.setAttribute("normal",new ge(u.normals,3)),this.setAttribute("uv",new ge(u.uvs,2)),this.setIndex(u.indices);return}}let i=[],o=[],s=[],l=[],a=[];for(let c=0;c<=r;c++){let u=[],f=c/r;for(let h=0;h<=n;h++){let d=h/n,y=d*Math.PI*2,x=f*Math.PI,T=-e*Math.cos(y)*Math.sin(x),D=e*Math.cos(x),V=e*Math.sin(y)*Math.sin(x);i.push(T,D,V);let b=Math.hypot(T,D,V)||1;o.push(T/b,D/b,V/b),s.push(d,1-f),u.push(i.length/3-1)}a.push(u)}for(let c=0;c<r;c++)for(let u=0;u<n;u++){let f=a[c][u+1],h=a[c][u],d=a[c+1][u],y=a[c+1][u+1];c!==0&&l.push(f,h,y),c!==r-1&&l.push(h,d,y)}this.setAttribute("position",new ge(new Float32Array(i),3)),this.setAttribute("normal",new ge(new Float32Array(o),3)),this.setAttribute("uv",new ge(new Float32Array(s),2)),this.setIndex(l)}},pt=class extends Ke{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let u=globalThis.__three_live_native_cylinder__;if(typeof u=="function"){let f=u(e,n,r,i);this.setAttribute("position",new ge(f.positions,3)),this.setAttribute("normal",new ge(f.normals,3)),this.setAttribute("uv",new ge(f.uvs,2)),this.setIndex(f.indices);return}}let o=[],s=[],l=[],a=[],c=r/2;for(let u=0;u<=1;u++){let f=u,h=u===0?e:n,d=u===0?c:-c;for(let y=0;y<=i;y++){let x=y/i,T=x*Math.PI*2,D=Math.sin(T),V=Math.cos(T);o.push(h*D,d,h*V),s.push(D,0,V),l.push(x,1-f)}}for(let u=0;u<i;u++){let f=u,h=u+i+1,d=u+i+2,y=u+1;a.push(f,h,y,h,d,y)}if(e>0){let u=o.length/3;o.push(0,c,0),s.push(0,1,0),l.push(.5,.5);let f=o.length/3;for(let h=0;h<=i;h++){let d=h/i*Math.PI*2,y=Math.sin(d),x=Math.cos(d);o.push(e*y,c,e*x),s.push(0,1,0),l.push(x*.5+.5,y*.5+.5)}for(let h=0;h<i;h++)a.push(u,f+h,f+h+1)}if(n>0){let u=o.length/3;o.push(0,-c,0),s.push(0,-1,0),l.push(.5,.5);let f=o.length/3;for(let h=0;h<=i;h++){let d=h/i*Math.PI*2,y=Math.sin(d),x=Math.cos(d);o.push(n*y,-c,n*x),s.push(0,-1,0),l.push(x*.5+.5,1-(y*.5+.5))}for(let h=0;h<i;h++)a.push(u,f+h+1,f+h)}this.setAttribute("position",new ge(new Float32Array(o),3)),this.setAttribute("normal",new ge(new Float32Array(s),3)),this.setAttribute("uv",new ge(new Float32Array(l),2)),this.setIndex(a)}},En=class extends pt{constructor(e=1,n=1,r=16){super(0,e,n,r)}},_n=class extends Ke{constructor(e=1,n=.4,r=12,i=32){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let o=[],s=[],l=[],a=[];for(let c=0;c<=r;c++){let u=c/r*Math.PI*2;for(let f=0;f<=i;f++){let h=f/i*Math.PI*2,d=(e+n*Math.cos(u))*Math.cos(h),y=(e+n*Math.cos(u))*Math.sin(h),x=n*Math.sin(u);o.push(d,y,x);let T=e*Math.cos(h),D=e*Math.sin(h),V=d-T,b=y-D,_=x,S=Math.hypot(V,b,_)||1;s.push(V/S,b/S,_/S),l.push(f/i,c/r)}}for(let c=1;c<=r;c++)for(let u=1;u<=i;u++){let f=(i+1)*c+u-1,h=(i+1)*(c-1)+u-1,d=(i+1)*(c-1)+u,y=(i+1)*c+u;a.push(f,h,y,h,d,y)}this.setAttribute("position",new ge(new Float32Array(o),3)),this.setAttribute("normal",new ge(new Float32Array(s),3)),this.setAttribute("uv",new ge(new Float32Array(l),2)),this.setIndex(a)}},Cn=class extends Ke{constructor(e=1,n=.4,r=64,i=8,o=2,s=3){super(),r=Math.floor(r),i=Math.floor(i);{let b=globalThis.__three_live_native_torus_knot__;if(typeof b=="function"){let _=b(e,n,r,i,o,s);this.setAttribute("position",new ge(_.positions,3)),this.setAttribute("normal",new ge(_.normals,3)),this.setAttribute("uv",new ge(_.uvs,2)),this.setIndex(_.indices);return}}let l=[],a=[],c=[],u=[],f=new Pe,h=new Pe,d=new Pe,y=new Pe,x=new Pe;function T(b,_){let S=Math.cos(_),U=Math.sin(_),z=s/o*_,I=e*(2+Math.cos(z))*.5;b.set(I*S,I*U,e*Math.sin(z)*.5)}let D=[];for(let b=0;b<=i;++b){let _=b/i*Math.PI*2;D.push(-n*Math.cos(_),n*Math.sin(_),b/i)}for(let b=0;b<=r;++b){let _=b/r,S=_*o*Math.PI*2;T(f,S),T(h,S+.01),d.subVectors(h,f).normalize(),y.addVectors(f,h).normalize(),x.crossVectors(d,y).normalize(),y.crossVectors(x,d).normalize();for(let U=0;U<=i;++U){let z=U*3,I=D[z],E=D[z+1],R=D[z+2],g=I*y.x+E*x.x,M=I*y.y+E*x.y,P=I*y.z+E*x.z;l.push(f.x+g,f.y+M,f.z+P);let v=Math.hypot(g,M,P)||1;a.push(g/v,M/v,P/v),c.push(_,R)}}let V=i+1;for(let b=1;b<=r;b++){let _=V*(b-1),S=_+V;for(let U=1;U<=i;U++){let z=_+(U-1),I=S+(U-1),E=S+U,R=_+U;u.push(z,I,R,I,E,R)}}this.setAttribute("position",new ge(new Float32Array(l),3)),this.setAttribute("normal",new ge(new Float32Array(a),3)),this.setAttribute("uv",new ge(new Float32Array(c),2)),this.setIndex(u)}},Zt=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},In=class{load(e,n){let r=new Zt(e);return n?.(r),r}};function Be(t,e){return t!==void 0?Number(t):e}function mr(t,e){return t!==void 0?!!t:e}var qe=class{constructor(e={}){this.name=e.name||"",this.color=new Ze(e.color!==void 0?e.color:16777215),this.emissive=new Ze(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Be(e.emissiveIntensity,1),this.roughness=Be(e.roughness,.5),this.metalness=Be(e.metalness,.1),this.opacity=Be(e.opacity,1),this.transparent=mr(e.transparent,!1),this.wireframe=mr(e.wireframe,!1),this.side=Be(e.side,2),this.doubleSided=mr(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Be(e.clearcoat,0),this.clearcoatRoughness=Be(e.clearcoatRoughness,0),this.sheen=Be(e.sheen,0),this.sheenColor=new Ze(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Be(e.sheenRoughness,0),this.transmission=Be(e.transmission,0),this.thickness=Be(e.thickness,0),this.attenuationColor=new Ze(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Be(e.attenuationDistance,1/0),this.ior=Be(e.ior,1.5),this.dispersion=Be(e.dispersion,0),this.iridescence=Be(e.iridescence,0),this.iridescenceIOR=Be(e.iridescenceIOR,1.3)}dispose(){}},bt=class extends qe{},kn=class extends qe{},Dn=class extends qe{},Ln=class extends qe{},Pn=class extends qe{},je=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new Pe,this.rotation=new Wt,this.quaternion=new Yt,this.scale=new Pe(1,1,1),this.matrix=new it,this.matrixWorld=new it,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){dr(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new Pe(e,n,r);this.updateMatrixWorld(!0);let o=new it;o.lookAt(this.position,i,new Pe(0,1,0));let s=o.elements,l=s[0],a=s[4],c=s[8],u=s[1],f=s[5],h=s[9],d=s[2],y=s[6],x=s[10],T=l+f+x;if(T>0){let D=.5/Math.sqrt(T+1);this.quaternion.set((y-h)*D,(c-d)*D,(u-a)*D,.25/D)}}},Nn=class extends je{},Mt=class extends je{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Ke?n:n?(We("unsupported geometry","BoxGeometry"),new Kt(.5,.5,.5)):new Ke,this.material=i instanceof qe?i:i?(We("unsupported material","MeshStandardMaterial"),new bt({color:13421772})):new bt}};function dr(t){let e=ke().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var Qt=1e4,Ft=class extends Mt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>Qt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Qt})`);this.count=Math.floor(o);let s=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new ge(s,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);o[s+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++)r.elements[l]=o[s+l]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let l=new Float32Array(this.count*3);l.fill(1),this.instanceColor=new ge(l,3)}let o=this.instanceColor.array,s=i*3;o[s]=Number.isFinite(r.r)?r.r:1,o[s+1]=Number.isFinite(r.g)?r.g:1,o[s+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,s=i*3;r.setRGB(o[s],o[s+1],o[s+2])}dispose(){}},yt=class extends je{constructor(e=16777215,n=1){super(),this.color=new Ze(e),this.intensity=Number(n),this.type="directional"}},Jt=class extends yt{constructor(e,n){super(e,n),this.type="ambient"}},Un=class extends yt{constructor(n,r){super(n,r);this.target=new je;this.type="directional"}},en=class extends yt{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},tn=class extends je{},zt=class extends tn{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Pe(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},St=class extends je{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return tt.validate(this),Nt(this)}toGLB(){return tt.validate(this),Ht(this)}toUSDZ(){return tt.validate(this),Ut(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Mt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},pr=Nt,br=Ht,xi=Ut;var tt=class{static validate(e){let n=0,r=0,i=0,o=new Set,s=(a,c,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${c}). Found: ${u}`)},l=(a,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(c)}), which cannot be bounds-checked.`);return c};e.traverse(a=>{if(dr(a),a instanceof Mt||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),a instanceof Ft){let u=l("instance",a.count);(u<0||u>Qt)&&s("INSTANCES",Qt,u)}let c=a.geometry;if(c){let u=0;if(c.attributes.position&&(u=l("vertex",c.attributes.position.count),n+=u,n>1e5&&s("VERTICES",1e5,n)),c.index){let f=l("index",c.index.count);r+=f,r>3e5&&s("INDICES",3e5,r);let h=c.index.array;if(h&&u>0){let d=Math.min(f,h.length);for(let y=0;y<d;y++){let x=h[y];if(!Number.isFinite(x)||x<0||x>=u)throw new Error(`SecurityError: Index buffer value (${String(x)}) out of vertex bounds [0, ${u}).`)}}}}if(a.material){let u=a.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&s("TEXTURES",16,o.size);for(let a of o){let c=a,u=c.image,f=Number(u?.width??c.width??0)||0,h=Number(u?.height??c.height??0)||0;(!Number.isFinite(f)||!Number.isFinite(h)||f>2048||h>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(f,h))}}},On=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new Ze(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){tt.validate(e);let i=(o,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(o,s):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),s={};for(let[l,a]of o.entries())s[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let o=pr(e),s=br(e),l=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function fi(){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 Fn=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=fi(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=fi();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Yo(){}var Ot=new Proxy(Yo,{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:Ot},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ot,construct:()=>Ot}),mi=(()=>{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 Vt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function gt(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Vt());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 di,Xt;function vi(t){if(!gt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Xt===void 0||di!==n){di=n;try{Xt=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!gt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Xt=null}}return Xt?Xt.createScriptURL(t):t}function Ko(t){ke().sandboxEngineSrc=t}function yr(){let t=ke().sandboxEngineSrc;if(t)return t;if(mi)return mi;try{if(typeof document>"u")return null;let e=Vt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&>(i,{requireSameOrigin:!0}))return i}}catch{}return null}function qo(){let t=yr();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}function Zo(t){ke().sandboxIframeSrc=t}function wi(){let t=ke().sandboxIframeSrc;if(t)return t;let e=yr();if(!e||!gt(e))return null;let n=new URL(e,Vt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Qo(){let t=wi();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}function Jo(t){ke().allowClientScripts=t}function Ti(){return!!ke().allowClientScripts}function es(t){if(!gt(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}var ts=["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 ns(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,s=t.allowClientScripts,l=t.revoked,a=n.postMessage.bind(n);function c(U){a({type:"ERROR",nonce:r,message:String(U)})}let u=typeof n.importScripts=="function"?n.importScripts.bind(n):null,f=o,h=null;try{let U=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let z={createScriptURL:function(E){if(E!==i&&(!o||E!==o))throw new TypeError("Disallowed worker importScripts URL");return E}};s&&(z.createScript=function(E){return String(E)});let I=n.trustedTypes.createPolicy("three-live#worker-boot",z);U=I.createScriptURL(i),o&&(f=I.createScriptURL(o)),s&&typeof I.createScript=="function"&&(h=I.createScript.bind(I))}catch{}u(U)}catch(U){c('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(U&&U.message||U));return}let d=n.THREE;if(!d||typeof d.Scene!="function"){c('Sandbox loaded "'+i+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(e)){let U=n.__THREE_LIVE_REGISTRY__;for(let z=0;z<e.length;z++)if(typeof e[z]=="function")try{e[z](d,U)}catch{}}for(let U=0;U<l.length;U++){let z=l[U],I=n;for(;I&&I!==Object.prototype;){if(I!==n)try{delete I[z]}catch{}try{Object.defineProperty(I,z,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{I=Object.getPrototypeOf(I)}catch{break}}}let y=Object.freeze({now:function(){return Date.now()}}),x=n;for(;x&&x!==Object.prototype;){if(x!==n)try{delete x.performance}catch{}try{Object.defineProperty(x,"performance",{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{x=Object.getPrototypeOf(x)}catch{break}}let T=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],D=!1;function V(U,z){if(U.type==="3D_MODEL_READY"){if(D)return;D=!0}U.nonce=r,z&&z.length?a(U,z):a(U)}let b=function(U,z){if(!U||T.indexOf(U.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+T.join(", ")+").");V(U,z)},_=n;for(;_&&_!==Object.prototype;){if(_===n||Object.prototype.hasOwnProperty.call(_,"postMessage"))try{Object.defineProperty(_,"postMessage",{value:b,writable:!1,configurable:!1})}catch{}try{_=Object.getPrototypeOf(_)}catch{break}}let S=!1;n.onmessage=function(U){let z=U&&U.data;if(!(!z||z.nonce!==r)&&!(z.type!=="EXECUTE"&&z.type!=="EXECUTE_URL")&&!S){S=!0;try{let I=new d.Scene,E=new d.PerspectiveCamera(60,1,.1,1e3),R=new d.WebGLRenderer({isSandboxed:!0});if(z.type==="EXECUTE_URL"){if(!o||z.scriptUrl!==o||typeof u!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let g=f||o,M=u;if(u=null,f=null,n.THREE=d,n.scene=I,n.camera=E,n.renderer=R,M(g),typeof n.__THREE_LIVE_SCENE__=="function"){let P=n.__THREE_LIVE_SCENE__(d,I,E,R);P&&typeof P.toGLB=="function"&&(I=P)}else n.scene&&typeof n.scene.toGLB=="function"&&(I=n.scene)}else{if(!s){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let g=h?(0,eval)(h(`(function (THREE, scene, camera, renderer) {
|
|
322
|
+
`,s}function no(t,e){if(t&&typeof t.traverse=="function"){let i=Ji(t,e);return ir(i)}let n=Gt(t),r=ti(n);return ir(r)}var fn=null;function ro(t){{let n=globalThis.__three_live_native_crc32__;if(typeof n=="function")return n(t)}if(!fn){fn=new Uint32Array(256);for(let n=0;n<256;n++){let r=n;for(let i=0;i<8;i++)r=r&1?3988292384^r>>>1:r>>>1;fn[n]=r}}let e=4294967295;for(let n=0;n<t.length;n++)e=fn[(e^t[n])&255]^e>>>8;return(e^4294967295)>>>0}function ni(t){{let u=globalThis.__three_live_native_build_usdz_zip__;if(typeof u=="function")return u(t)}let e=[],n=0,r=[];for(let u of t){let m=mn(u.filename),f=ro(u.data),d=u.data.length,g=30+m.length,y=n+g,M=0,L=y%64;L!==0&&(M=64-L);let G=new Uint8Array(g+M),p=new DataView(G.buffer);p.setUint32(0,67324752,!0),p.setUint16(4,20,!0),p.setUint16(6,0,!0),p.setUint16(8,0,!0),p.setUint16(10,0,!0),p.setUint16(12,0,!0),p.setUint32(14,f,!0),p.setUint32(18,d,!0),p.setUint32(22,d,!0),p.setUint16(26,m.length,!0),p.setUint16(28,M,!0),G.set(m,30),M>0&&G.fill(0,30+m.length),e.push({offset:n,size:d,crc:f,filenameBytes:m,entry:u}),r.push(G),r.push(u.data),n+=G.length+u.data.length}let i=n;for(let u of e){let m=new Uint8Array(46+u.filenameBytes.length),f=new DataView(m.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint16(8,0,!0),f.setUint16(10,0,!0),f.setUint16(12,0,!0),f.setUint16(14,0,!0),f.setUint32(16,u.crc,!0),f.setUint32(20,u.size,!0),f.setUint32(24,u.size,!0),f.setUint16(28,u.filenameBytes.length,!0),f.setUint16(30,0,!0),f.setUint16(32,0,!0),f.setUint16(34,0,!0),f.setUint16(36,0,!0),f.setUint32(38,0,!0),f.setUint32(42,u.offset,!0),m.set(u.filenameBytes,46),r.push(m),n+=m.length}let o=n-i,s=new Uint8Array(22),l=new DataView(s.buffer);l.setUint32(0,101010256,!0),l.setUint16(4,0,!0),l.setUint16(6,0,!0),l.setUint16(8,e.length,!0),l.setUint16(10,e.length,!0),l.setUint32(12,o,!0),l.setUint32(16,i,!0),l.setUint16(20,0,!0),r.push(s),n+=22;let a=new Uint8Array(n),c=0;for(let u of r)a.set(u,c),c+=u.length;return a}function Nt(t){let e=no(t),n=mn(e);return ni([{filename:"model.usda",data:n}])}function dn(t){let e=Gt(t),n=ti(e),r=ir(n),i=mn(r);return ni([{filename:"model.usda",data:i}])}function or(t){return t&&typeof t.toUSDZ=="function"?t.toUSDZ():t&&typeof t.traverse=="function"?Nt(t):dn(t)}function ie(t,e,n,r){let i=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.max(e,Math.min(n,i))}function et(t){return Array.isArray(t)&&t.length>=3&&Number.isFinite(t[0])&&Number.isFinite(t[1])&&Number.isFinite(t[2])}function de(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 io(t){let e=de(t);if(!e||e.lazy===!1)return null;let n=e.mode==="hand-left"||e.mode==="hand-right"?e.mode:"head",r=n!=="head";return{mode:n,lazy:!0,distance:ie(e.distance,.1,10,r?.15:1),deadzoneDeg:ie(e.deadzoneDeg,0,90,r?0:15),stiffness:ie(e.stiffness,.5,40,6),height:ie(e.height,-2,2,r?.12:-.1),faceUser:e.faceUser!==!1,snapOnStart:e.snapOnStart!==!1}}function oo(t){let e=de(t);if(!e)return null;let n=e.target;return{target:et(n)?[n[0],n[1],n[2]]:typeof n=="string"&&n.length>0&&n.length<=256?n:[0,0,0],radius:ie(e.radius,.01,50,.5),speed:ie(e.speed,-20,20,.5),height:ie(e.height,-10,10,0),phase:ie(e.phase,-1e6,1e6,0),faceCenter:e.faceCenter===!0}}function so(t){if(!t)return null;let e=de(t)??{},n=ie(e.minScale,.001,1e3,.1),r=ie(e.maxScale,n,1e3,Math.max(n,10));return{rotateAxis:e.rotateAxis==="none"?"none":"y",minScale:n,maxScale:r}}var si=2e3,ao={rain:600,snow:400,sparks:300,confetti:300};function co(t){let e=de(t);if(!e)return null;let n=e.preset==="snow"||e.preset==="sparks"||e.preset==="confetti"?e.preset:"rain",r=e.area,i=s=>ie(s,.05,50,2),o=et(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[2,2,2];return{preset:n,count:Math.round(ie(e.count,1,si,ao[n])),area:o,speed:ie(e.speed,.05,10,1)}}var uo=4e3;function lo(t){if(!t)return null;let e=de(t)??{};return{prompt:qe(e.prompt,uo)??"What is this?",holdMs:ie(e.holdMs,100,5e3,600)}}function ho(t){if(!t)return null;let e=de(t)??{};return{planes:e.planes!==!1,meshes:e.meshes===!0,reticle:e.reticle===!0,objects:e.objects===!0}}function cr(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 fo(t){let e=typeof t=="string"?{src:t}:de(t),n=cr(e?.src);return!e||!n?null:{src:n,refDistance:ie(e.refDistance,.01,1e3,1),loop:e.loop===!0}}function Ut(t,e){let n=qe(t,16)?.trim();if(!n)return e;let r=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(n);return r?`#${r[1].toLowerCase()}`:e}var mo=new Set(["m","cm","mm","in","ft-in","auto"]),ri=["x","y","z"];function po(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.unit,r=typeof n=="string"&&mo.has(n)?n:"auto",i=e?.axes,o=new Set(Array.isArray(i)?i.filter(l=>typeof l=="string"):typeof i=="string"?i.split(""):[]),s=ri.filter(l=>o.has(l));return{enabled:!0,unit:r,axes:s.length>0?s:[...ri],color:Ut(e?.color,"#38bdf8"),showOnSelect:e?.showOnSelect===!0}}var bo=new Set(["none","floor","wall","ceiling","any"]);function yo(t){if(!t)return null;let e=de(t)??{},n=e.grid,r=s=>ie(s,.001,100,.1),i=et(n)?[r(n[0]),r(n[1]),r(n[2])]:typeof n=="number"&&Number.isFinite(n)&&n>0?[r(n),r(n),r(n)]:null,o=e.surface;return{grid:i,angleDeg:ie(e.angleDeg,0,180,0),surface:typeof o=="string"&&bo.has(o)?o:"none",socketTag:qe(e.socketTag,128)??"",radius:ie(e.radius,.01,2,.15)}}function go(t){let e=typeof t=="string"?{tag:t}:de(t),n=qe(e?.tag,128);return!e||!n?null:{tag:n,radius:ie(e.radius,.01,2,.15),alignRotation:e.alignRotation!==!1,highlightColor:Ut(e.highlightColor,"#22c55e")}}function xo(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.action;return{enabled:!0,dwellMs:Math.round(ie(e?.dwellMs,250,1e4,1200)),repeat:e?.repeat===!0,action:n==="ask"?"ask":"select"}}function vo(t){if(!t)return null;let e=de(t);if(e&&e.enabled===!1)return null;let n=e?.direction,r=null;if(et(n)){let i=Math.hypot(n[0],n[1],n[2]);i>1e-8&&(r=[n[0]/i,n[1]/i,n[2]/i])}return{enabled:!0,direction:r,distance:ie(e?.distance,0,10,.35),layer:Math.round(ie(e?.layer,1,10,1)),leaderLine:e?.leaderLine!==!1}}var bn=new Set(["__proto__","constructor","prototype"]);function Tt(t){if(typeof t!="string")return;let e=t.trim().slice(0,128);if(!(!e||bn.has(e)||/[\x00-\x1f\x7f]/.test(e)))return e}function sr(t){let e=de(t);if(!e||e.persist===!1)return null;let n=Tt(e.id);return e.persist!==!0&&!n?null:n?{id:n,persist:!0}:{persist:!0}}function To(t){return t===!0||t==="walkable"?"walkable":t===!1||t==="blocked"?"blocked":null}function Mo(t){let e=typeof t=="string"?{text:t}:de(t),n=qe(e?.text??e?.value,256);if(!e||!n)return null;let r=ie(e.size,.005,10,.12);return{text:n,size:r,depth:ie(e.depth??e.height,.001,5,r*.2),color:Ut(e.color,"#ffffff")}}function wo(t){if(!t||typeof t=="number"&&!(t>0&&Number.isFinite(t)))return null;let e=t===!0?{}:typeof t=="number"?{strength:t}:de(t);if(!e||e.enabled===!1)return null;let n=ie(e.strength??e.intensity,0,5,.35);return n>0?{enabled:!0,strength:n,threshold:ie(e.threshold,0,4,.8),radius:ie(e.radius,0,2,.5)}:null}function So(t){if(!t)return null;let e=t===!0?{}:typeof t=="string"?{color:t}:de(t);if(!e||e.enabled===!1)return null;let n=e.thickness??e.width;return{enabled:!0,color:Ut(e.color,"#38bdf8"),thickness:ie(typeof n=="number"&&n>0&&n<.25?Math.max(1.5,n*140):n,.5,20,3),pulse:e.pulse===!0}}function Ao(t){let e=de(t);if(!e||e.enabled===!1)return null;let n=Tt(e.root),r=Tt(e.effector);if(!n||!r)return null;let i=Tt(e.mid),o=e.target,s;if(et(o))s=[ie(o[0],-1e3,1e3,0),ie(o[1],-1e3,1e3,0),ie(o[2],-1e3,1e3,0)];else{let u=Tt(o);if(!u)return null;s=u}let l=e.pole??e.poleTarget,a=et(l)?[ie(l[0],-1e3,1e3,0),ie(l[1],-1e3,1e3,0),ie(l[2],-1e3,1e3,0)]:Tt(l),c=e.solver==="fabrik"?"fabrik":e.solver==="two-bone"||i?"two-bone":"fabrik";return{root:n,...i?{mid:i}:{},effector:r,target:s,...a?{pole:a}:{},solver:c,iterations:Math.round(ie(e.iterations,1,32,8)),tolerance:ie(e.tolerance,1e-5,.1,.001),weight:ie(e.weight,0,1,1)}}var ii=new Set(["horizontal","vertical","floor","wall","ceiling","table"]),Eo=new Set(["capsule","cylindrical","spherical"]),$t=[];function ai(t){$t.includes(t)||$t.push(t)}function yn(t){let e=de(t);if(!e)return null;let n=Array.isArray(e.traits)?e.traits:[],r=N=>n.includes(N),i={},o=e.grab;o==="1-hand"||o==="2-hand"?i.grab=o:(o===!0||e.grabbable===!0||r("grab"))&&(i.grab="2-hand"),i.grab&&(i.grabbable=!0);let s=e.scale??e.scalable;if(s||r("scale")){let N=de(s)??{},v=ie(N.min,.001,1e3,.05);i.scale={min:v,max:ie(N.max,v,1e3,Math.max(v,5))},i.scalable=!0}let l=e.billboard;typeof l=="string"&&Eo.has(l)?i.billboard=l:(l===!0||r("billboard"))&&(i.billboard="capsule");let a=e.follow,c=typeof a=="string"?a:de(a)?.mode;if(typeof a=="string"?a:de(a)?.lazy===!1)i.follow=c==="hand-left"||c==="hand-right"?c:"head";else{let N=io(a);N&&(i.follow=N)}let u=e.anchor;if(typeof u=="string"&&ii.has(u))i.anchor=u;else{let v=de(u)?.target;typeof v=="string"&&ii.has(v)&&(i.anchor=v);let D=sr(u)??sr(e.anchorPersist);D&&(i.anchorPersist=D)}if(!i.anchorPersist){let N=sr(e.anchorPersist);N&&(i.anchorPersist=N)}(e.physics==="dynamic"||e.physics==="static")&&(i.physics=e.physics);let m=oo(e.orbit);m&&(i.orbit=m);let f=so(e.handles);f&&(i.handles=f);let d=co(e.particles);d&&(i.particles=d);let g=lo(e.holdToAsk);g&&(i.holdToAsk=g);let y=ho(e.worldUnderstanding);y&&(i.worldUnderstanding=y);let M=cr(e.splatUrl);M&&(i.splatUrl=M),(e.splatQuality==="high"||e.splatQuality==="standard")&&(i.splatQuality=e.splatQuality);let L=qe(e.spatialSlot);L&&(i.spatialSlot=L);let G=fo(e.audio);G&&(i.audio=G);let p=po(e.dimensions);p&&(i.dimensions=p);let E=yo(e.snapTo);E&&(i.snapTo=E);let _=go(e.snapSocket);_&&(i.snapSocket=_);let P=xo(e.gaze);P&&(i.gaze=P);let z=vo(e.explode);z&&(i.explode=z);let R=To(e.navigable);R&&(i.navigable=R);let C=Mo(e.text);C&&(i.text=C);let I=wo(e.bloom);I&&(i.bloom=I);let b=So(e.outline);b&&(i.outline=b);let T=Ao(e.ik);T&&(i.ik=T),typeof e.sync=="boolean"&&(i.sync=e.sync),e.pointerEvents==="none"&&(i.pointerEvents="none");for(let N of $t)N.normalize(e,i);return Object.keys(i).length>0?i:null}var ci=1;function ur(t){let e={schemaVersion:ci};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 n={};t.anchor&&(n.planeType=t.anchor==="vertical"||t.anchor==="wall"?"VERTICAL":"HORIZONTAL",n.semanticType=t.anchor.toUpperCase()),t.anchorPersist&&(n.persist=t.anchorPersist.persist,t.anchorPersist.id&&(n.id=t.anchorPersist.id)),e.anchor=n}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.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]}:{}}),typeof t.sync=="boolean"&&(e.sync={enabled:t.sync});for(let n of $t)n.sceneCore(t,e);return e}function _o(t){let e={schemaVersion:ci},n=(r,i)=>{for(let[o,s]of Object.entries(i)){let l=r+o[0].toUpperCase()+o.slice(1);typeof s=="string"||typeof s=="number"||typeof s=="boolean"?e[l]=s:et(s)&&(e[l]=[s[0],s[1],s[2]])}};t.grab&&(e.grab=t.grab),t.scale&&n("scale",t.scale),t.billboard&&(e.billboard=t.billboard),typeof t.follow=="string"?e.follow=t.follow:t.follow&&(e.follow=t.follow.mode,n("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&&n("orbit",t.orbit),t.handles&&(e.handles=!0,n("handles",t.handles)),t.particles&&n("particles",t.particles),t.holdToAsk&&(e.holdToAsk=!0,n("holdToAsk",t.holdToAsk)),t.worldUnderstanding&&n("worldUnderstanding",t.worldUnderstanding),t.splatUrl&&(e.splatUrl=t.splatUrl),t.splatQuality&&(e.splatQuality=t.splatQuality),t.spatialSlot&&(e.spatialSlot=t.spatialSlot),t.audio&&n("audio",t.audio),t.dimensions&&n("dimensions",{...t.dimensions,axes:t.dimensions.axes.join("")}),t.snapTo&&(e.snapTo=!0,n("snapTo",t.snapTo)),t.snapSocket&&n("snapSocket",t.snapSocket),t.gaze&&n("gaze",t.gaze),t.explode&&n("explode",t.explode),t.navigable&&(e.navigable=t.navigable),t.text&&n("text",t.text),t.bloom&&n("bloom",t.bloom),t.outline&&n("outline",t.outline),t.ik&&n("ik",t.ik),typeof t.sync=="boolean"&&(e.sync=t.sync),t.pointerEvents&&(e.pointerEvents=t.pointerEvents);for(let r of $t)r.usd(t,n,e);return e}function Ro(t,e){let n=yn(e);if(!n)return;let r={...t.extras?.xr,...n};n.anchor===void 0&&typeof r.anchor=="object"&&delete r.anchor,t.extras={...t.extras,xr:r},t.extensions={...t.extensions,MOZ_hubs_components:lr(n),ANDROID_xr_scenecore:ur(n)}}function lr(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 n=yn(t),r=[];if(!n)return r;for(let[i,o]of Object.entries(_o(n)))/^[A-Za-z][A-Za-z0-9]{0,63}$/.test(i)&&(typeof o=="boolean"?r.push(`bool ${i} = ${o}`):typeof o=="number"?Number.isFinite(o)&&r.push(`double ${i} = ${o}`):typeof o=="string"?r.push(`string ${i} = "${e(o)}"`):o.length===3&&o.every(s=>Number.isFinite(s))&&r.push(`double3 ${i} = (${o.join(", ")})`));return r}function ui(){try{Object.defineProperty(Ie(),"xrTraitSerializer",{value:Object.freeze({gltfNode:Ro,usdLines:Co}),writable:!1,configurable:!1,enumerable:!0})}catch{}}var ar=new Set(["grab","scale","billboard","follow","anchor","anchorPersist","physics","orbit","handles","particles","holdToAsk","worldUnderstanding","splatUrl","splatQuality","spatialSlot","audio","dimensions","snapTo","snapSocket","gaze","explode","navigable","text","bloom","outline","ik","sync","pointerEvents","character","agent","integrity","zone","spawner","objective","audioCues","collidable","traits","schemaVersion"]),pn={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:"audio",hint:`Use 'audio: { src: "..." }' or 'audioCues' instead of 'sound'.`},sfx:{target:"audioCues",hint:`Use 'audioCues: { onTap: "confirm" }' instead of 'sfx'.`},measure:{target:"dimensions",hint:"Use 'dimensions: true' instead of 'measure'."},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'.`},caption:{target:"text",hint:`Use 'text: { text: "...", size: 0.12 }' instead of 'caption'.`},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'."},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 Io(t,e){let n=t.length,r=e.length,i=Array.from({length:r+1},(o,s)=>s);for(let o=1;o<=n;o++){let s=i[0];i[0]=o;for(let l=1;l<=r;l++){let a=i[l];i[l]=t[o-1]===e[l-1]?s:1+Math.min(s,i[l],i[l-1]),s=a}}return i[r]}function oi(t){let e=t.toLowerCase(),n=null,r=4;for(let i of ar){if(i==="traits")continue;let o=Io(e,i.toLowerCase());o<r&&(r=o,n=i)}return n}function li(t,e="unnamed"){let n=[];if(t==null)return n;let r=(h,A,$,V="warning")=>n.push({code:h,severity:V,node:e,message:A,hint:$}),i=de(t);if(!i)return r("TL201",`userData.xr on node '${e}' must be a plain object.`,"Assign an object such as mesh.userData.xr = { grab: true }."),n;for(let h of Object.keys(i)){if(ar.has(h))continue;let A=pn[h]??pn[h.toLowerCase()];if(A)r("TL201",`Unrecognized key '${h}' in userData.xr on node '${e}'; did you mean '${A.target}'?`,A.hint);else{let $=oi(h);r("TL201",$?`Unknown key '${h}' on node '${e}'; did you mean '${$}'?`:`Unknown key '${h}' in userData.xr on node '${e}'.`,$?`Replace '${h}' with '${$}'.`:"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(i.traits)){for(let h of i.traits)if(typeof h=="string"&&!ar.has(h)){let A=pn[h]??pn[h.toLowerCase()],$=A?.target??oi(h);r("TL201",$?`Unknown trait '${h}' in userData.xr.traits on node '${e}'; did you mean '${$}'?`:`Unknown trait '${h}' in userData.xr.traits on node '${e}'.`,A?.hint??($?`Use '${$}' instead of '${h}'.`:"Use canonical trait keys on userData.xr directly."))}}let o=(h,A,$,V)=>{if(typeof A=="number"){if(!Number.isFinite(A)){r("TL202",`Numeric trait parameter '${h}' on node '${e}' is non-finite (${A}); clamped to default.`,`Provide a finite number in [${$}, ${V}] for '${h}'.`);return}if(A<$||A>V){let K=Math.max($,Math.min(V,A));r("TL202",`Numeric trait parameter '${h}' (${A}) on node '${e}' is out of range [${$}, ${V}]; clamped to ${K}.`,`Keep '${h}' within [${$}, ${V}].`)}}},s=de(i.scale);if(s){o("scale.min",s.min,.001,1e3);let h=ie(s.min,.001,1e3,.05);o("scale.max",s.max,h,1e3)}let l=de(i.follow);l&&l.lazy!==!1&&(o("follow.distance",l.distance,.1,10),o("follow.deadzoneDeg",l.deadzoneDeg,0,90),o("follow.stiffness",l.stiffness,.5,40),o("follow.height",l.height,-2,2));let a=de(i.orbit);a&&(o("orbit.radius",a.radius,.01,50),o("orbit.speed",a.speed,-20,20),o("orbit.height",a.height,-10,10),o("orbit.phase",a.phase,-1e6,1e6));let c=de(i.handles);if(c){o("handles.minScale",c.minScale,.001,1e3);let h=ie(c.minScale,.001,1e3,.1);o("handles.maxScale",c.maxScale,h,1e3)}let u=de(i.particles);if(u){if(o("particles.count",u.count,1,si),o("particles.speed",u.speed,.05,10),typeof u.area=="number")o("particles.area",u.area,.05,50);else if(Array.isArray(u.area))for(let h=0;h<Math.min(3,u.area.length);h++)o(`particles.area[${h}]`,u.area[h],.05,50)}let m=de(i.holdToAsk);m&&o("holdToAsk.holdMs",m.holdMs,100,5e3);let f=de(i.audio);f&&o("audio.refDistance",f.refDistance,.01,1e3);let d=de(i.snapTo);if(d){if(o("snapTo.angleDeg",d.angleDeg,0,180),o("snapTo.radius",d.radius,.01,2),typeof d.grid=="number"&&d.grid>0)o("snapTo.grid",d.grid,.001,100);else if(Array.isArray(d.grid))for(let h=0;h<Math.min(3,d.grid.length);h++)o(`snapTo.grid[${h}]`,d.grid[h],.001,100)}let g=de(i.snapSocket);g&&o("snapSocket.radius",g.radius,.01,2);let y=de(i.gaze);y&&y.enabled!==!1&&o("gaze.dwellMs",y.dwellMs,250,1e4);let M=de(i.explode);M&&M.enabled!==!1&&(o("explode.distance",M.distance,0,10),o("explode.layer",M.layer,1,10));let L=de(i.text);if(L&&(o("text.size",L.size,.005,10),o("text.depth",L.depth??L.height,.001,5)),typeof i.bloom=="number"&&i.bloom>0)o("bloom",i.bloom,0,5);else{let h=de(i.bloom);h&&h.enabled!==!1&&(o("bloom.strength",h.strength??h.intensity,0,5),o("bloom.threshold",h.threshold,0,4),o("bloom.radius",h.radius,0,2))}let G=de(i.outline);if(G&&G.enabled!==!1){let h=G.thickness??G.width;typeof h=="number"&&!(h>0&&h<.25)&&o("outline.thickness",h,.5,20)}let p=de(i.ik);p&&p.enabled!==!1&&(o("ik.iterations",p.iterations,1,32),o("ik.tolerance",p.tolerance,1e-5,.1),o("ik.weight",p.weight,0,1));let E=de(i.character);if(E&&E.enabled!==!1){o("character.speed",E.speed,.1,20),o("character.runMultiplier",E.runMultiplier,1,4),o("character.jumpVelocity",E.jumpVelocity,0,30),o("character.gravity",E.gravity,0,50),o("character.radius",E.radius,.05,5);let h=ie(E.radius,.05,5,.35);o("character.height",E.height,h*2,10),o("character.cameraDistance",E.cameraDistance,.5,50),o("character.cameraHeight",E.cameraHeight,-10,50)}let _=de(i.agent);if(_&&_.enabled!==!1&&(o("agent.speed",_.speed,.1,20),o("agent.turnSpeed",_.turnSpeed,.1,50),o("agent.sightRadius",_.sightRadius,0,100),o("agent.stopDistance",_.stopDistance,.01,10),o("agent.separationRadius",_.separationRadius,0,10)),typeof i.integrity=="number")o("integrity.max",i.integrity,1,1e6);else{let h=de(i.integrity);if(h&&h.enabled!==!1){o("integrity.max",h.max,1,1e6);let A=ie(h.max,1,1e6,100);o("integrity.current",h.current,0,A),o("integrity.cooldownMs",h.cooldownMs,0,1e4),o("integrity.scoreValue",h.scoreValue,-1e6,1e6),o("integrity.contactAmount",h.contactAmount,0,1e6)}}let P=de(i.zone);if(P&&P.enabled!==!1){if(o("zone.radius",P.radius,.01,1e3),typeof P.size=="number")o("zone.size",P.size,.01,1e3);else if(Array.isArray(P.size))for(let h=0;h<Math.min(3,P.size.length);h++)o(`zone.size[${h}]`,P.size[h],.01,1e3)}let z=de(i.spawner);z&&z.enabled!==!1&&(o("spawner.intervalSec",z.intervalSec,.05,3600),o("spawner.maxActive",z.maxActive,1,32),o("spawner.totalCount",z.totalCount,0,1e4),o("spawner.spawnRadius",z.spawnRadius,0,100));let R=de(i.objective);R&&R.enabled!==!1&&(o("objective.amount",R.amount??R.points,-1e6,1e6),o("objective.radius",R.radius,.05,50),o("objective.order",R.order,0,1e3),o("objective.spinSpeed",R.spinSpeed,-50,50),o("objective.bobAmplitude",R.bobAmplitude,0,5),o("objective.respawnSec",R.respawnSec,0,3600));let C=de(i.audioCues);C&&(o("audioCues.pitchJitter",C.pitchJitter,0,.5),o("audioCues.volume",C.volume,0,1));let I=(h,A)=>{A!=null&&(cr(A)||r("TL203",`Unsafe or disallowed media URL in '${h}' (${JSON.stringify(A)}) 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"))},b=(h,A)=>{A!=null&&(Tt(A)||r("TL203",`Unsafe or invalid identifier in '${h}' (${JSON.stringify(A)}) 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"))};i.splatUrl!==void 0&&i.splatUrl!==null&&I("splatUrl",i.splatUrl),typeof i.audio=="string"?I("audio",i.audio):f&&(f.src!==void 0?I("audio.src",f.src):Object.keys(f).some(h=>h.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 T=(h,A)=>{if(A==null||A==="")return;let $=typeof A=="string"?A.trim():"";(!$||!/^[A-Za-z0-9_.:-]{1,64}$/.test($)||bn.has($))&&r("TL203",`Unsafe or invalid identifier in '${h}' (${JSON.stringify(A)}) 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")},N=de(i.integrity);if(N&&N.group!==void 0&&T("integrity.group",N.group),P&&P.watchGroups!==void 0){let h=Array.isArray(P.watchGroups)?P.watchGroups:[P.watchGroups];for(let A=0;A<h.length;A++)T(`zone.watchGroups[${A}]`,h[A])}R&&R.tag!==void 0&&T("objective.tag",R.tag);let v=de(i.anchor);v&&v.id!==void 0&&b("anchor.id",v.id);let D=de(i.anchorPersist);if(D&&D.id!==void 0&&b("anchorPersist.id",D.id),p&&p.enabled!==!1){b("ik.root",p.root),b("ik.effector",p.effector),p.mid!==void 0&&b("ik.mid",p.mid),p.target!==void 0&&!Array.isArray(p.target)&&b("ik.target",p.target);let h=p.pole??p.poleTarget;h!==void 0&&!Array.isArray(h)&&b("ik.pole",h)}return n}function fr(t){if(typeof t!="string")return;let e=t.trim();return/^[A-Za-z0-9_.:-]{1,64}$/.test(e)&&!bn.has(e)?e:void 0}function gn(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}var ko=["third-person","first-person","top-down","fixed"],Do=["idle","walk","run","jump"];function Lo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{cameraMode:t}:{});if(e.enabled===!1)return null;let n=ie(e.radius,.05,5,.35),r=de(e.clips)??{},i={};for(let o of Do){let s=qe(r[o],128);s&&(i[o]=s)}return{speed:ie(e.speed,.1,20,4),runMultiplier:ie(e.runMultiplier,1,4,1.6),jumpVelocity:ie(e.jumpVelocity,0,30,5.5),gravity:ie(e.gravity,0,50,15),radius:n,height:ie(e.height,n*2,10,Math.max(1.4,n*2)),cameraMode:gn(e.cameraMode,ko,"third-person"),cameraDistance:ie(e.cameraDistance,.5,50,3.5),cameraHeight:ie(e.cameraHeight,-10,50,1.8),clips:i}}var Po=["patrol","chase","flee","wander","follow"],No=32,hr="user";function Uo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{mode:t}:{});if(e.enabled===!1)return null;let n=gn(e.mode,Po,"wander"),r=e.target,i=r==="camera"||r===hr?hr:qe(r,256)??"";!i&&(n==="chase"||n==="flee"||n==="follow")&&(i=hr);let o=l=>ie(l,-1e4,1e4,0),s=Array.isArray(e.waypoints)?e.waypoints.filter(et).slice(0,No).map(l=>[o(l[0]),o(l[1]),o(l[2])]):[];return{mode:n,target:i,speed:ie(e.speed,.1,20,2),turnSpeed:ie(e.turnSpeed,.1,50,6),sightRadius:ie(e.sightRadius,0,100,6),stopDistance:ie(e.stopDistance,.01,10,.6),separationRadius:ie(e.separationRadius,0,10,.8),waypoints:s,loopWaypoints:e.loopWaypoints!==!1}}function Oo(t){if(!t)return null;let e=de(t)??(typeof t=="number"?{max:t}:{});if(e.enabled===!1)return null;let n=ie(e.max,1,1e6,100);return{max:n,current:ie(e.current,0,n,n),group:fr(e.group)??"neutral",showBar:e.showBar===!0,cooldownMs:Math.round(ie(e.cooldownMs,0,1e4,250)),hideOnDepleted:e.hideOnDepleted!==!1,scoreValue:ie(e.scoreValue,-1e6,1e6,0),contactAmount:ie(e.contactAmount,0,1e6,0)}}var Fo=16;function zo(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{shape:t}:{});if(e.enabled===!1)return null;let n=gn(e.shape,["box","sphere"],"box"),r=e.size,i=m=>ie(m,.01,1e3,1),o=et(r)?[i(r[0]),i(r[1]),i(r[2])]:typeof r=="number"?[i(r),i(r),i(r)]:[1,1,1],s=ie(e.radius??(typeof r=="number"?r:void 0),.01,1e3,.5),l=e.watchGroups,a=[...new Set((Array.isArray(l)?l:l===void 0?[]:[l]).map(fr).filter(m=>m!==void 0))].slice(0,Fo),c={shape:n,size:o,radius:s,watchGroups:a},u=Ut(e.color,"");return u?{...c,color:u}:c}var Vo=32;function Bo(t){let e=de(t)??(typeof t=="string"?{template:t}:null),n=qe(e?.template,256)?.trim();return!e||!n||e.enabled===!1?null:{template:n,intervalSec:ie(e.intervalSec,.05,3600,3),maxActive:Math.round(ie(e.maxActive,1,Vo,8)),totalCount:Math.round(ie(e.totalCount,0,1e4,0)),spawnRadius:ie(e.spawnRadius,0,100,0)}}var Go=["pickup","checkpoint","time-bonus","restore","key"];function Ho(t){if(!t)return null;let e=de(t)??(typeof t=="string"?{type:t}:{});if(e.enabled===!1)return null;let n=gn(e.type,Go,"pickup"),r=n==="pickup";return{type:n,amount:ie(e.amount??e.points,-1e6,1e6,10),tag:fr(e.tag)??"",radius:ie(e.radius,.05,50,.65),required:e.required===!0,order:Math.round(ie(e.order,0,1e3,0)),spinSpeed:ie(e.spinSpeed,-50,50,r?2.5:0),bobAmplitude:ie(e.bobAmplitude,0,5,r?.08:0),respawnSec:ie(e.respawnSec,0,3600,0)}}var $o=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Xo=["onTap","onObjective","onHit","onDepleted","onZoneEnter","onZoneExit","onSpawn","onJump","onLand"];function jo(t){let e=de(t);if(!e)return null;let n={};for(let r of Xo){let i=e[r];typeof i=="string"&&$o.includes(i)&&(n[r]=i)}return Object.keys(n).length===0?null:{cues:n,pitchJitter:ie(e.pitchJitter,0,.5,.08),volume:ie(e.volume,0,1,1),spatial:e.spatial!==!1}}var Wo={normalize(t,e){let n=Lo(t.character);n&&(e.character=n);let r=Uo(t.agent);r&&(e.agent=r);let i=Oo(t.integrity);i&&(e.integrity=i);let o=zo(t.zone);o&&(e.zone=o);let s=Bo(t.spawner);s&&(e.spawner=s);let l=Ho(t.objective);l&&(e.objective=l);let a=jo(t.audioCues);a&&(e.audioCues=a),t.collidable===!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(n=>[...n])}),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.collidable&&(e.collidable={enabled:!0})},usd(t,e,n){if(t.character){n.character=!0,e("character",{...t.character,clips:void 0});for(let[r,i]of Object.entries(t.character.clips))n["characterClip"+r[0].toUpperCase()+r.slice(1)]=i}t.agent&&(e("agent",{...t.agent,waypoints:void 0}),n.agentWaypointCount=t.agent.waypoints.length,t.agent.waypoints.forEach((r,i)=>{n[`agentWaypoint${i}`]=[r[0],r[1],r[2]]})),t.integrity&&(n.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.collidable&&(n.collidable=!0)}};function hi(){ai(Wo)}var vn=class t{constructor(e=0,n=0){this.x=Number(e),this.y=Number(n)}set(e,n){return this.x=Number(e),this.y=Number(n),this}clone(){return new t(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}sub(e){return this.x-=e.x,this.y-=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}},Le=class t{constructor(e=0,n=0,r=0){this.x=Number(e),this.y=Number(n),this.z=Number(r)}set(e,n,r){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this}clone(){return new t(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addVectors(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subVectors(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let e=this.length();return e>1e-5&&(this.x/=e,this.y/=e,this.z/=e),this}cross(e){let n=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.x=n,this.y=r,this.z=i,this}crossVectors(e,n){let r=e.x,i=e.y,o=e.z,s=n.x,l=n.y,a=n.z;return this.x=i*a-o*l,this.y=o*s-r*a,this.z=r*l-i*s,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}distanceTo(e){return Math.hypot(this.x-e.x,this.y-e.y,this.z-e.z)}lerp(e,n){return this.lerpVectors(this,e,n)}lerpVectors(e,n,r){return this.x=e.x+(n.x-e.x)*r,this.y=e.y+(n.y-e.y)*r,this.z=e.z+(n.z-e.z)*r,this}applyMatrix4(e){let n=this.x,r=this.y,i=this.z,o=e.elements,s=1/(o[3]*n+o[7]*r+o[11]*i+o[15]);return this.x=(o[0]*n+o[4]*r+o[8]*i+o[12])*s,this.y=(o[1]*n+o[5]*r+o[9]*i+o[13])*s,this.z=(o[2]*n+o[6]*r+o[10]*i+o[14])*s,this}},Tn=class{constructor(e=0,n=0,r=0,i=1){this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i)}set(e,n,r,i){return this.x=Number(e),this.y=Number(n),this.z=Number(r),this.w=Number(i),this}},Wt=class t{constructor(e=0,n=0,r=0,i="XYZ"){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}set(e,n,r,i=this.order){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this.order=i,this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this.order=e.order,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this.order)}_onChange(e){return this._onChangeCallback=e,this}},Yt=class t{constructor(e=0,n=0,r=0,i=1){this._onChangeCallback=null;this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i)}get x(){return this._x}set x(e){this._x=Number(e),this._onChangeCallback?.()}get y(){return this._y}set y(e){this._y=Number(e),this._onChangeCallback?.()}get z(){return this._z}set z(e){this._z=Number(e),this._onChangeCallback?.()}get w(){return this._w}set w(e){this._w=Number(e),this._onChangeCallback?.()}set(e,n,r,i){return this._x=Number(e),this._y=Number(n),this._z=Number(r),this._w=Number(i),this._onChangeCallback?.(),this}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback?.(),this}clone(){return new t(this._x,this._y,this._z,this._w)}setFromEuler(e,n=!0){let r=e.x,i=e.y,o=e.z,s=Math.cos(r/2),l=Math.cos(i/2),a=Math.cos(o/2),c=Math.sin(r/2),u=Math.sin(i/2),m=Math.sin(o/2);return this._x=c*l*a+s*u*m,this._y=s*u*a-c*l*m,this._z=s*l*m+c*u*a,this._w=s*l*a-c*u*m,n&&this._onChangeCallback?.(),this}setFromAxisAngle(e,n){let r=n/2,i=Math.sin(r);return this.set(e.x*i,e.y*i,e.z*i,Math.cos(r))}normalize(){let e=Math.hypot(this._x,this._y,this._z,this._w);return e===0?this.set(0,0,0,1):this.set(this._x/e,this._y/e,this._z/e,this._w/e)}setFromUnitVectors(e,n){let r=e.dot(n)+1;return r<1e-6?(Math.abs(e.x)>Math.abs(e.z)?this.set(-e.y,e.x,0,0):this.set(0,-e.z,e.y,0)).normalize():this.set(e.y*n.z-e.z*n.y,e.z*n.x-e.x*n.z,e.x*n.y-e.y*n.x,r).normalize()}multiply(e){return this.multiplyQuaternions(this,e)}multiplyQuaternions(e,n){let r=e.x,i=e.y,o=e.z,s=e.w,l=n.x,a=n.y,c=n.z,u=n.w;return this._x=r*u+s*l+i*c-o*a,this._y=i*u+s*a+o*l-r*c,this._z=o*u+s*c+r*a-i*l,this._w=s*u-r*l-i*a-o*c,this._onChangeCallback?.(),this}_onChange(e){return this._onChangeCallback=e,this}},it=class t{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,this}copy(e){return this.elements.set(e.elements),this}clone(){let e=new t;return e.copy(this),e}compose(e,n,r){return vt(this.elements,[n.x,n.y,n.z,n.w],[e.x,e.y,e.z],[r.x,r.y,r.z]),this}multiply(e){return this.multiplyMatrices(this,e)}multiplyMatrices(e,n){return De(this.elements,e.elements,n.elements),this}lookAt(e,n,r){return kt(this.elements,[e.x,e.y,e.z],[n.x,n.y,n.z],[r.x,r.y,r.z]),this}makeRotationFromQuaternion(e){let n=new Le(0,0,0),r=new Le(1,1,1);return this.compose(n,e,r)}makeTranslation(e,n,r){return this.identity(),this.elements[12]=Number(e),this.elements[13]=Number(n),this.elements[14]=Number(r),this}makeScale(e,n,r){return this.identity(),this.elements[0]=Number(e),this.elements[5]=Number(n),this.elements[10]=Number(r),this}},Mn=class{constructor(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])}identity(){let e=this.elements;return e.fill(0),e[0]=1,e[4]=1,e[8]=1,this}getNormalMatrix(e){return $e(this.elements,e.elements),this}},Ze=class t{constructor(e,n,r){this.r=1;this.g=1;this.b=1;e!==void 0&&(n!==void 0&&r!==void 0?this.setRGB(e,n,r):this.set(e))}set(e){if(typeof e=="number")this.setHex(e);else if(typeof e=="string")if(e.startsWith("#")){let n=parseInt(e.slice(1),16);this.setHex(n)}else e==="red"?this.setRGB(1,0,0):e==="green"?this.setRGB(0,1,0):e==="blue"?this.setRGB(0,0,1):e==="white"?this.setRGB(1,1,1):e==="black"&&this.setRGB(0,0,0);else e&&typeof e=="object"&&"r"in e&&(this.r=Number(e.r),this.g=Number(e.g),this.b=Number(e.b));return this}setHex(e){let n=Math.floor(e);return this.r=(n>>16&255)/255,this.g=(n>>8&255)/255,this.b=(n&255)/255,this}setRGB(e,n,r){return this.r=Number(e),this.g=Number(n),this.b=Number(r),this}getHex(){return Math.round(Math.max(0,Math.min(1,this.r))*255)<<16|Math.round(Math.max(0,Math.min(1,this.g))*255)<<8|Math.round(Math.max(0,Math.min(1,this.b))*255)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}clone(){return new t(this.r,this.g,this.b)}},gi={degToRad:t=>t*Math.PI/180,radToDeg:t=>t*180/Math.PI,clamp:(t,e,n)=>Math.max(e,Math.min(n,t)),lerp:(t,e,n)=>t+(e-t)*n,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(t,e)=>t+Math.random()*(e-t)},Be=class{constructor(e,n){this.needsUpdate=!1;if(typeof n!="number"||!Number.isInteger(n)||n<1||n>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(n)}`);Array.isArray(e)?this.array=new Float32Array(e):this.array=e,this.itemSize=n;let r=this.array?this.array.length:0;if(!Number.isFinite(r)||r<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(r)}`);this.count=Math.floor(r/n)}getX(e){return this.array[e*this.itemSize]}getY(e){return this.array[e*this.itemSize+1]}getZ(e){return this.array[e*this.itemSize+2]}setX(e,n){return this.array[e*this.itemSize]=n,this.needsUpdate=!0,this}setY(e,n){return this.array[e*this.itemSize+1]=n,this.needsUpdate=!0,this}setZ(e,n){return this.array[e*this.itemSize+2]=n,this.needsUpdate=!0,this}setXYZ(e,n,r,i){let o=e*this.itemSize;return this.array[o]=n,this.array[o+1]=r,this.array[o+2]=i,this.needsUpdate=!0,this}},wn=class extends Be{constructor(e,n){super(e instanceof Float32Array?e:new Float32Array(e),n)}},Sn=class extends Be{constructor(e,n){super(e instanceof Uint16Array?e:new Uint16Array(e),n)}},An=class extends Be{constructor(e,n){super(e instanceof Uint32Array?e:new Uint32Array(e),n)}},Ye=class{constructor(){this.name="";this.attributes={};this.index=null;this.boundingBox=null}setAttribute(e,n){return this.attributes[e]=n,this}getAttribute(e){return this.attributes[e]}setIndex(e){if(e instanceof Be)this.index=e;else if(Array.isArray(e)){let n=0;for(let r of e)r>n&&(n=r);this.index=new Be(new(n>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 n=e.count,r=new Float32Array(n*3),i=new Le,o=new Le,s=new Le,l=new Le,a=new Le;if(this.index){let c=this.index.array;for(let u=0;u<c.length;u+=3){let m=c[u],f=c[u+1],d=c[u+2];i.set(e.getX(m),e.getY(m),e.getZ(m)),o.set(e.getX(f),e.getY(f),e.getZ(f)),s.set(e.getX(d),e.getY(d),e.getZ(d)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let g of[m,f,d])r[g*3]+=l.x,r[g*3+1]+=l.y,r[g*3+2]+=l.z}}else for(let c=0;c<n;c+=3){i.set(e.getX(c),e.getY(c),e.getZ(c)),o.set(e.getX(c+1),e.getY(c+1),e.getZ(c+1)),s.set(e.getX(c+2),e.getY(c+2),e.getZ(c+2)),l.subVectors(s,o),a.subVectors(i,o),l.cross(a).normalize();for(let u=0;u<3;u++)r[(c+u)*3]=l.x,r[(c+u)*3+1]=l.y,r[(c+u)*3+2]=l.z}for(let c=0;c<n;c++){let u=r[c*3],m=r[c*3+1],f=r[c*3+2],d=Math.hypot(u,m,f)||1;r[c*3]=u/d,r[c*3+1]=m/d,r[c*3+2]=f/d}return this.setAttribute("normal",new Be(r,3)),this}setFromBuffers(e,n,r,i){this.setAttribute("position",new Be(e,3)),this.setAttribute("normal",new Be(n,3)),this.setAttribute("uv",new Be(r,2)),this.setIndex(i)}computeBoundingBox(){let e=this.attributes.position,n=new Le(1/0,1/0,1/0),r=new Le(-1/0,-1/0,-1/0);if(e&&e.count>0)for(let i=0;i<e.count;i++){let o=e.getX(i),s=e.getY(i),l=e.getZ(i);o<n.x&&(n.x=o),s<n.y&&(n.y=s),l<n.z&&(n.z=l),o>r.x&&(r.x=o),s>r.y&&(r.y=s),l>r.z&&(r.z=l)}else n.set(0,0,0),r.set(0,0,0);return this.boundingBox={min:n,max:r},this.boundingBox}center(){let e=this.computeBoundingBox(),n=(e.min.x+e.max.x)*.5,r=(e.min.y+e.max.y)*.5,i=(e.min.z+e.max.z)*.5,o=this.attributes.position;if(o&&o.count>0){for(let s=0;s<o.count;s++)o.setXYZ(s,o.getX(s)-n,o.getY(s)-r,o.getZ(s)-i);this.computeBoundingBox()}return this}dispose(){}},Kt=class extends Ye{constructor(e=1,n=1,r=1){super();{let m=globalThis.__three_live_native_box__;if(typeof m=="function"){let f=m(e,n,r);this.setFromBuffers(f.positions,f.normals,f.uvs,f.indices);return}}let i=e/2,o=n/2,s=r/2,l=[-i,-o,s,i,-o,s,i,o,s,-i,o,s,i,-o,-s,-i,-o,-s,-i,o,-s,i,o,-s,-i,o,s,i,o,s,i,o,-s,-i,o,-s,-i,-o,-s,i,-o,-s,i,-o,s,-i,-o,s,i,-o,s,i,-o,-s,i,o,-s,i,o,s,-i,-o,-s,-i,-o,s,-i,o,s,-i,o,-s],a=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],c=[],u=[];for(let m=0;m<6;m++){let f=m*4;c.push(0,0,1,0,1,1,0,1),u.push(f,f+1,f+2,f,f+2,f+3)}this.setFromBuffers(l,a,c,u)}},En=class extends Ye{constructor(e=1,n=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));{let c=globalThis.__three_live_native_plane__;if(typeof c=="function"){let u=c(e,n,r,i);this.setFromBuffers(u.positions,u.normals,u.uvs,u.indices);return}}let o=[],s=[],l=[],a=[];for(let c=0;c<=i;c++){let u=c/i;for(let m=0;m<=r;m++){let f=m/r;if(o.push((f-.5)*e,(.5-u)*n,0),s.push(0,0,1),l.push(f,1-u),c>0&&m>0){let d=(r+1)*c+m-1,g=d-(r+1);a.push(g,d,g+1,d,d+1,g+1)}}}this.setFromBuffers(o,s,l,a)}},qt=class extends Ye{constructor(e=1,n=16,r=12){super(),n=Math.max(3,Math.floor(n)),r=Math.max(2,Math.floor(r));{let a=globalThis.__three_live_native_sphere__;if(typeof a=="function"){let c=a(e,n,r);this.setFromBuffers(c.positions,c.normals,c.uvs,c.indices);return}}let i=[],o=[],s=[],l=[];for(let a=0;a<=r;a++){let c=a/r;for(let u=0;u<=n;u++){let m=u/n,f=m*Math.PI*2,d=c*Math.PI,g=-Math.cos(f)*Math.sin(d),y=Math.cos(d),M=Math.sin(f)*Math.sin(d);if(i.push(e*g,e*y,e*M),o.push(g,y,M),s.push(m,1-c),a>0&&u>0){let L=(n+1)*a+u,G=L-(n+1),p=G-1,E=L-1;a!==1&&l.push(G,p,L),a!==r&&l.push(p,E,L)}}}this.setFromBuffers(i,o,s,l)}},pt=class extends Ye{constructor(e=1,n=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));{let u=globalThis.__three_live_native_cylinder__;if(typeof u=="function"){let m=u(e,n,r,i);this.setFromBuffers(m.positions,m.normals,m.uvs,m.indices);return}}let o=[],s=[],l=[],a=[],c=r/2;for(let u=0;u<=1;u++){let m=u,f=u===0?e:n,d=u===0?c:-c;for(let g=0;g<=i;g++){let y=g/i,M=y*Math.PI*2,L=Math.sin(M),G=Math.cos(M);o.push(f*L,d,f*G),s.push(L,0,G),l.push(y,1-m)}}for(let u=0;u<i;u++){let m=u,f=u+i+1,d=u+i+2,g=u+1;a.push(m,f,g,f,d,g)}if(e>0){let u=o.length/3;o.push(0,c,0),s.push(0,1,0),l.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let d=f/i*Math.PI*2,g=Math.sin(d),y=Math.cos(d);o.push(e*g,c,e*y),s.push(0,1,0),l.push(y*.5+.5,g*.5+.5)}for(let f=0;f<i;f++)a.push(u,m+f,m+f+1)}if(n>0){let u=o.length/3;o.push(0,-c,0),s.push(0,-1,0),l.push(.5,.5);let m=o.length/3;for(let f=0;f<=i;f++){let d=f/i*Math.PI*2,g=Math.sin(d),y=Math.cos(d);o.push(n*g,-c,n*y),s.push(0,-1,0),l.push(y*.5+.5,1-(g*.5+.5))}for(let f=0;f<i;f++)a.push(u,m+f+1,m+f)}this.setFromBuffers(o,s,l,a)}},_n=class extends pt{constructor(e=1,n=1,r=16){super(0,e,n,r)}},Rn=class extends Ye{constructor(e=1,n=.4,r=12,i=48,o=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));{let u=globalThis.__three_live_native_torus__;if(typeof u=="function"){let m=u(e,n,r,i,o);this.setFromBuffers(m.positions,m.normals,m.uvs,m.indices);return}}let s=[],l=[],a=[],c=[];for(let u=0;u<=r;u++){let m=u/r*Math.PI*2,f=Math.cos(m),d=Math.sin(m);for(let g=0;g<=i;g++){let y=g/i*o,M=Math.cos(y),L=Math.sin(y);if(s.push((e+n*f)*M,(e+n*f)*L,n*d),l.push(f*M,f*L,d),a.push(g/i,u/r),u>0&&g>0){let G=(i+1)*u+g-1,p=G-(i+1);c.push(G,p,G+1,p,p+1,G+1)}}}this.setFromBuffers(s,l,a,c)}},Cn=class extends Ye{constructor(e=1,n=.4,r=64,i=8,o=2,s=3){super(),r=Math.floor(r),i=Math.floor(i);{let p=globalThis.__three_live_native_torus_knot__;if(typeof p=="function"){let E=p(e,n,r,i,o,s);this.setFromBuffers(E.positions,E.normals,E.uvs,E.indices);return}}let l=[],a=[],c=[],u=[],m=new Le,f=new Le,d=new Le,g=new Le,y=new Le;function M(p,E){let _=Math.cos(E),P=Math.sin(E),z=s/o*E,R=e*(2+Math.cos(z))*.5;p.set(R*_,R*P,e*Math.sin(z)*.5)}let L=[];for(let p=0;p<=i;++p){let E=p/i*Math.PI*2;L.push(-n*Math.cos(E),n*Math.sin(E),p/i)}for(let p=0;p<=r;++p){let E=p/r,_=E*o*Math.PI*2;M(m,_),M(f,_+.01),d.subVectors(f,m).normalize(),g.addVectors(m,f).normalize(),y.crossVectors(d,g).normalize(),g.crossVectors(y,d).normalize();for(let P=0;P<=i;++P){let z=P*3,R=L[z],C=L[z+1],I=L[z+2],b=R*g.x+C*y.x,T=R*g.y+C*y.y,N=R*g.z+C*y.z;l.push(m.x+b,m.y+T,m.z+N);let v=Math.hypot(b,T,N)||1;a.push(b/v,T/v,N/v),c.push(E,I)}}let G=i+1;for(let p=1;p<=r;p++){let E=G*(p-1),_=E+G;for(let P=1;P<=i;P++){let z=E+(P-1),R=_+(P-1),C=_+P,I=E+P;u.push(z,R,I,R,C,I)}}this.setFromBuffers(l,a,c,u)}},Zt=class{constructor(e=""){this.isTexture=!0;this.wrapS=10497;this.wrapT=10497;this.image=null;this.width=0;this.height=0;this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},In=class{load(e,n){let r=new Zt(e);return n?.(r),r}};function Ve(t,e){return t!==void 0?Number(t):e}function mr(t,e){return t!==void 0?!!t:e}var Ke=class{constructor(e={}){this.name=e.name||"",this.color=new Ze(e.color!==void 0?e.color:16777215),this.emissive=new Ze(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=Ve(e.emissiveIntensity,1),this.roughness=Ve(e.roughness,.5),this.metalness=Ve(e.metalness,.1),this.opacity=Ve(e.opacity,1),this.transparent=mr(e.transparent,!1),this.wireframe=mr(e.wireframe,!1),this.side=Ve(e.side,2),this.doubleSided=mr(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=Ve(e.clearcoat,0),this.clearcoatRoughness=Ve(e.clearcoatRoughness,0),this.sheen=Ve(e.sheen,0),this.sheenColor=new Ze(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=Ve(e.sheenRoughness,0),this.transmission=Ve(e.transmission,0),this.thickness=Ve(e.thickness,0),this.attenuationColor=new Ze(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=Ve(e.attenuationDistance,1/0),this.ior=Ve(e.ior,1.5),this.dispersion=Ve(e.dispersion,0),this.iridescence=Ve(e.iridescence,0),this.iridescenceIOR=Ve(e.iridescenceIOR,1.3)}dispose(){}},bt=class extends Ke{},kn=class extends Ke{},Dn=class extends Ke{},Ln=class extends Ke{},Pn=class extends Ke{},Xe=class t{constructor(){this.name="";this.matrixAutoUpdate=!0;this.visible=!0;this.castShadow=!1;this.receiveShadow=!1;this.parent=null;this.children=[];this.userData={};this.position=new Le,this.rotation=new Wt,this.quaternion=new Yt,this.scale=new Le(1,1,1),this.matrix=new it,this.matrixWorld=new it,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let e=this.quaternion,n=Math.atan2(2*(e.w*e.x+e.y*e.z),1-2*(e.x*e.x+e.y*e.y)),r=Math.asin(Math.max(-1,Math.min(1,2*(e.w*e.y-e.z*e.x)))),i=Math.atan2(2*(e.w*e.z+e.x*e.y),1-2*(e.y*e.y+e.z*e.z));this.rotation.set(n,r,i)})}add(...e){for(let n of e)n&&n instanceof t&&(n.parent&&n.parent.remove(n),n.parent=this,this.children.push(n));return this}remove(...e){for(let n of e){let r=this.children.indexOf(n);r!==-1&&(n.parent=null,this.children.splice(r,1))}return this}traverse(e){e(this);for(let n of this.children)n.traverse(e)}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(e=!1){dr(this),(this.matrixAutoUpdate||e)&&this.updateMatrix(),this.parent?this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix):this.matrixWorld.copy(this.matrix);for(let n of this.children)n.updateMatrixWorld(e)}lookAt(e,n,r){let i=typeof e=="object"?e:new Le(e,n,r);this.updateMatrixWorld(!0);let o=new it;o.lookAt(this.position,i,new Le(0,1,0));let s=o.elements,l=s[0],a=s[4],c=s[8],u=s[1],m=s[5],f=s[9],d=s[2],g=s[6],y=s[10],M=l+m+y;if(M>0){let L=.5/Math.sqrt(M+1);this.quaternion.set((g-f)*L,(c-d)*L,(u-a)*L,.25/L)}}},Nn=class extends Xe{},Mt=class extends Xe{constructor(n,r){super();this.isMesh=!0;let i=Array.isArray(r)?r[0]:r;this.geometry=n instanceof Ye?n:n?(je("unsupported geometry","BoxGeometry"),new Kt(.5,.5,.5)):new Ye,this.material=i instanceof Ke?i:i?(je("unsupported material","MeshStandardMaterial"),new bt({color:13421772})):new bt}};function dr(t){let e=Ie().materializeDeclarativeGeometry;typeof e=="function"&&e(t)}var Qt=1e4,Ft=class extends Mt{constructor(n,r,i=1){super(n,r);this.instanceColor=null;this.isInstancedMesh=!0;let o=Number(i);if(!Number.isFinite(o)||o<0||o>Qt)throw new RangeError(`SecurityError: InstancedMesh count (${String(i)}) exceeds MAX_INSTANCES_PER_MESH (${Qt})`);this.count=Math.floor(o);let s=new Float32Array(this.count*16);for(let l=0;l<this.count;l++){let a=l*16;s[a]=1,s[a+5]=1,s[a+10]=1,s[a+15]=1}this.instanceMatrix=new Be(s,16)}setMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++){let a=Number(r.elements[l]);o[s+l]=Number.isFinite(a)?a:l%5===0?1:0}}getMatrixAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r||!r.elements)return;let o=this.instanceMatrix.array,s=i*16;if(!(s+16>o.length))for(let l=0;l<16;l++)r.elements[l]=o[s+l]}setColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let l=new Float32Array(this.count*3);l.fill(1),this.instanceColor=new Be(l,3)}let o=this.instanceColor.array,s=i*3;o[s]=Number.isFinite(r.r)?r.r:1,o[s+1]=Number.isFinite(r.g)?r.g:1,o[s+2]=Number.isFinite(r.b)?r.b:1}getColorAt(n,r){let i=Math.floor(Number(n));if(!Number.isFinite(i)||i<0||i>=this.count||!r)return;if(!this.instanceColor||this.instanceColor.array.length<(i+1)*3){r.setRGB(1,1,1);return}let o=this.instanceColor.array,s=i*3;r.setRGB(o[s],o[s+1],o[s+2])}dispose(){}},yt=class extends Xe{constructor(e=16777215,n=1){super(),this.color=new Ze(e),this.intensity=Number(n),this.type="directional"}},Jt=class extends yt{constructor(e,n){super(e,n),this.type="ambient"}},Un=class extends yt{constructor(n,r){super(n,r);this.target=new Xe;this.type="directional"}},en=class extends yt{constructor(n,r,i=0,o=2){super(n,r);this.distance=0;this.decay=2;this.type="point",this.distance=i,this.decay=o}},tn=class extends Xe{},zt=class extends tn{constructor(n=45,r=1,i=.1,o=1e3){super();this.target=new Le(0,0,0);this.fov=Number(n),this.aspect=Number(r),this.near=Number(i),this.far=Number(o)}},wt=class extends Xe{constructor(){super(...arguments);this.background=null;this.environmentIntensity=1}toCanvas3D(){return tt.validate(this),Pt(this)}toGLB(){return tt.validate(this),Ht(this)}toUSDZ(){return tt.validate(this),Nt(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let n=new Map,r=0;return this.traverse(i=>{if(i instanceof Mt){let o=new Float32Array(i.matrixWorld.elements);n.set(r,o),i.name&&n.set(i.name,o),r++}}),n}},pr=Pt,br=Ht,xi=Nt;var tt=class{static validate(e){let n=0,r=0,i=0,o=new Set,s=(a,c,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${a} (${c}). Found: ${u}`)},l=(a,c)=>{if(!Number.isFinite(c))throw new Error(`SecurityError: Scene reports a non-finite ${a} count (${String(c)}), which cannot be bounds-checked.`);return c};e.traverse(a=>{if(dr(a),a instanceof Mt||a.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),a instanceof Ft){let u=l("instance",a.count);(u<0||u>Qt)&&s("INSTANCES",Qt,u)}let c=a.geometry;if(c){let u=0;if(c.attributes.position&&(u=l("vertex",c.attributes.position.count),n+=u,n>1e5&&s("VERTICES",1e5,n)),c.index){let m=l("index",c.index.count);r+=m,r>3e5&&s("INDICES",3e5,r);let f=c.index.array;if(f&&u>0){let d=Math.min(m,f.length);for(let g=0;g<d;g++){let y=f[g];if(!Number.isFinite(y)||y<0||y>=u)throw new Error(`SecurityError: Index buffer value (${String(y)}) out of vertex bounds [0, ${u}).`)}}}}if(a.material){let u=a.material;u.map&&o.add(u.map),u.normalMap&&o.add(u.normalMap),u.roughnessMap&&o.add(u.roughnessMap)}}}),o.size>16&&s("TEXTURES",16,o.size);for(let a of o){let c=a,u=c.image,m=Number(u?.width??c.width??0)||0,f=Number(u?.height??c.height??0)||0;(!Number.isFinite(m)||!Number.isFinite(f)||m>2048||f>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(m,f))}}},On=class{constructor(e={}){this.shadowMap={enabled:!1,type:0};this.capabilities={isWebGL2:!0,maxTextures:16};this.boundViewer=null;this.isSandboxed=!1;this.containerId="";this.hasInitialModelRendered=!1;this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let n=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||n,this.containerId=e.containerId||""}setSize(e,n){return this}setPixelRatio(e){return this}setClearColor(e,n=1){let r=new Ze(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,n),this}clear(){return this}dispose(){}render(e,n){if(this.isSandboxed){tt.validate(e);let i=(o,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(o,s):self.postMessage(o))};if(this.hasInitialModelRendered){let o=e.getMeshTransforms(),s={};for(let[l,a]of o.entries())s[l]=Array.from(a);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let o=pr(e),s=br(e),l=(o.lights||[]).map(a=>({type:a.type,color:a.color,intensity:a.intensity,position:a.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:n?{fov:n.fov||60,position:[n.position.x,n.position.y,n.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function fi(){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 Fn=class{constructor(e=!0){this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=!1;this.autoStart=e,e&&this.start()}start(){this.startTime=fi(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let n=fi();e=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=e}return e}};function Yo(){}var Ot=new Proxy(Yo,{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:Ot},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>Ot,construct:()=>Ot}),mi=(()=>{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 Vt(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function gt(t,e){if(!t||typeof t!="string")return!1;let n=t.trim();if(!n)return!1;try{let r=new URL(n,Vt());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 di,Xt;function vi(t){if(!gt(t))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${t}".`);let n=globalThis.trustedTypes;if(!n||typeof n.createPolicy!="function")return t;if(Xt===void 0||di!==n){di=n;try{Xt=n.createPolicy("three-live#worker",{createScriptURL:r=>{if(!gt(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Xt=null}}return Xt?Xt.createScriptURL(t):t}function Ko(t){Ie().sandboxEngineSrc=t}function yr(){let t=Ie().sandboxEngineSrc;if(t)return t;if(mi)return mi;try{if(typeof document>"u")return null;let e=Vt(),n=Array.from(document.querySelectorAll("script[src]"));for(let r of n){let i=r.src;if(!i)continue;let o=new URL(i,e).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(o)&>(i,{requireSameOrigin:!0}))return i}}catch{}return null}function qo(){let t=yr();if(!t)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox engine from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}function Zo(t){Ie().sandboxIframeSrc=t}function Ti(){let t=Ie().sandboxIframeSrc;if(t)return t;let e=yr();if(!e||!gt(e))return null;let n=new URL(e,Vt());return n.protocol==="blob:"?null:new URL("three-live-sandbox.html",n).href}function Qo(){let t=Ti();if(!t)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");if(!gt(t))throw new Error(`SecurityError: Refusing to load sandbox iframe from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}function Jo(t){Ie().allowClientScripts=t}function Mi(){return!!Ie().allowClientScripts}function es(t){if(!gt(t))throw new Error(`SecurityError: Refusing to load procedural scene script from disallowed URL "${t}". Only http:, https:, and blob: URLs are permitted.`);return new URL(t,Vt()).href}var ts=["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 ns(t,e){let n=self,r=t.nonce,i=t.engineSrc,o=t.allowedScriptUrl,s=t.allowClientScripts,l=t.revoked,a=n.postMessage.bind(n);function c(P){a({type:"ERROR",nonce:r,message:String(P)})}let u=typeof n.importScripts=="function"?n.importScripts.bind(n):null,m=o,f=null;try{let P=i;if(typeof n.trustedTypes<"u"&&n.trustedTypes&&typeof n.trustedTypes.createPolicy=="function")try{let z={createScriptURL:function(C){if(C!==i&&(!o||C!==o))throw new TypeError("Disallowed worker importScripts URL");return C}};s&&(z.createScript=function(C){return String(C)});let R=n.trustedTypes.createPolicy("three-live#worker-boot",z);P=R.createScriptURL(i),o&&(m=R.createScriptURL(o)),s&&typeof R.createScript=="function"&&(f=R.createScript.bind(R))}catch{}u(P)}catch(P){c('Sandbox failed to load the Three-Live engine from "'+i+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(P&&P.message||P));return}let d=n.THREE;if(!d||typeof d.Scene!="function"){c('Sandbox loaded "'+i+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(e)){let P=n.__THREE_LIVE_REGISTRY__;for(let z=0;z<e.length;z++)if(typeof e[z]=="function")try{e[z](d,P)}catch{}}for(let P=0;P<l.length;P++){let z=l[P],R=n;for(;R&&R!==Object.prototype;){if(R!==n)try{delete R[z]}catch{}try{Object.defineProperty(R,z,{value:void 0,writable:!1,configurable:!1,enumerable:!1})}catch{}try{R=Object.getPrototypeOf(R)}catch{break}}}let g=Object.freeze({now:function(){return Date.now()}}),y=n;for(;y&&y!==Object.prototype;){if(y!==n)try{delete y.performance}catch{}try{Object.defineProperty(y,"performance",{value:g,writable:!1,configurable:!1,enumerable:!1})}catch{}try{y=Object.getPrototypeOf(y)}catch{break}}let M=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],L=!1;function G(P,z){if(P.type==="3D_MODEL_READY"){if(L)return;L=!0}P.nonce=r,z&&z.length?a(P,z):a(P)}let p=function(P,z){if(!P||M.indexOf(P.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+M.join(", ")+").");G(P,z)},E=n;for(;E&&E!==Object.prototype;){if(E===n||Object.prototype.hasOwnProperty.call(E,"postMessage"))try{Object.defineProperty(E,"postMessage",{value:p,writable:!1,configurable:!1})}catch{}try{E=Object.getPrototypeOf(E)}catch{break}}let _=!1;n.onmessage=function(P){let z=P&&P.data;if(!(!z||z.nonce!==r)&&!(z.type!=="EXECUTE"&&z.type!=="EXECUTE_URL")&&!_){_=!0;try{let R=new d.Scene,C=new d.PerspectiveCamera(60,1,.1,1e3),I=new d.WebGLRenderer({isSandboxed:!0});if(z.type==="EXECUTE_URL"){if(!o||z.scriptUrl!==o||typeof u!="function"){c("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let b=m||o,T=u;if(u=null,m=null,n.THREE=d,n.scene=R,n.camera=C,n.renderer=I,T(b),typeof n.__THREE_LIVE_SCENE__=="function"){let N=n.__THREE_LIVE_SCENE__(d,R,C,I);N&&typeof N.toGLB=="function"&&(R=N)}else n.scene&&typeof n.scene.toGLB=="function"&&(R=n.scene)}else{if(!s){c("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let b=f?(0,eval)(f(`(function (THREE, scene, camera, renderer) {
|
|
321
323
|
return (function () {
|
|
322
324
|
`+z.script+`
|
|
323
325
|
})();
|
|
324
326
|
})`)):new Function("THREE","scene","camera","renderer",`return (function () {
|
|
325
327
|
`+z.script+`
|
|
326
|
-
})();`);h=null;let M=g(d,I,E,R);M&&typeof M.toGLB=="function"&&(I=M)}if(!D){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(I);let g=I.toGLB(),M=g instanceof ArrayBuffer?g:g.buffer.slice(g.byteOffset,g.byteOffset+g.byteLength);V({type:"3D_MODEL_READY",glbBuffer:M},[M])}a({type:"DONE",nonce:r})}catch(I){c(I&&I.message||I)}}},a({type:"READY",nonce:r})}function gr(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:ts},s=(ke().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${ns.toString()})(${JSON.stringify(o)},[${s}]);`}function Mi(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 dt=0;function Si(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function rs(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var is=1024,os=256;function pi(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function xr(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,is)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!pi(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let s=Object.create(null),l=i;for(let a of o){if(a.length>os||a==="__proto__"||a==="constructor"||a==="prototype")return null;let c=l[a];if(!pi(c))return null;s[a]=c}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function ss(t){let e=rs(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ai(t,e,n,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function as(t,e,n,r){let i=Si(),o=gr(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.display="none",s.src=n,dt++;let l=!1,a=!1,c={modelDispatched:!1},u,f=()=>{if(l||a)return;let x=s.contentWindow;!x||typeof x.postMessage!="function"||(a=!0,x.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},h=()=>{},d=x=>{if(l||!s.contentWindow||x.source!==s.contentWindow)return;let T=x.data;if(T&&typeof T=="object"&&T.type==="IFRAME_READY"){f();return}let D=xr(T,i);D&&Ai(D,r,h,c)};h=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),dt=Math.max(0,dt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof s.remove=="function"?s.remove():s.parentNode&&s.parentNode.removeChild(s))},u=setTimeout(()=>{l||(h(),Mi(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),s.onload=()=>{f()},s.onerror=()=>{h(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let y=document.body||document.documentElement;if(!y||typeof y.appendChild!="function"){h();let x=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(x),x}return y.appendChild(s),{terminate:h}}function bi(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(dt>=32)return r(`SecurityError: ${dt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=qo()}catch(h){let d=h instanceof Error?h.message:String(h);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let h;try{h=Qo()}catch(d){let y=d instanceof Error?d.message:String(d);return r(y,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(as(t,i,h,n))}catch(d){return Promise.reject(d)}}let o=Si(),s=gr(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let h=new Blob([s],{type:"application/javascript"}),d=URL.createObjectURL(h);try{let y=vi(d);l=new Worker(y)}finally{URL.revokeObjectURL(d)}}catch(h){let d=h instanceof Error?h.message:String(h);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}dt++;let a=!1,c={modelDispatched:!1},u,f=()=>{a||(a=!0,u!==void 0&&clearTimeout(u),dt=Math.max(0,dt-1),l.terminate())};return u=setTimeout(()=>{a||(f(),Mi(n))},3e3),l.onmessage=h=>{let d=xr(h.data,o);d&&Ai(d,n,f,c)},l.onerror=h=>{f(),n.onError?.(new Error(`Worker execution error: ${h.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:f})}function yi(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 Ri={execute(t,e,n,r){let i=(l,a)=>{let c=new Error(l);return n.onError?.(c),a&&n.onToast?.(a),Promise.reject(c)},o=yi(e,i);if(o)return o;try{ss(t)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Ti()?bi({kind:"script",script:t},e,n,i):i(Pr,Nr)},executeUrl(t,e,n){let r=(s,l)=>{let a=new Error(s);return n.onError?.(a),l&&n.onToast?.(l),Promise.reject(a)},i=yi(e,r);if(i)return i;let o;try{o=es(t)}catch(s){let l=s instanceof Error?s.message:String(s);return r(l,"Security Error: disallowed scene script URL.")}return bi({kind:"url",scriptUrl:o},e,n,r)}},zn=new Set;function We(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;zn.has(n)||(zn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function vr(){return Array.from(zn)}function wr(){zn.clear()}var nn=class extends bt{constructor(e={}){We("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},Ei=nn,At=class extends qt{constructor(e=1,n=0,r="PolyhedronGeometry"){We(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Vn=class extends At{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Bn=class extends At{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},Gn=class extends At{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},Hn=class extends At{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},$n=class extends pt{constructor(e=1,n=1,r=4,i=8){We("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Xn=class extends pt{constructor(e=.5,n=1,r=16){We("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},jn=class extends pt{constructor(e=1,n=16){We("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Wn=class extends en{constructor(n,r,i=0,o=Math.PI/3,s=0,l=2){We("SpotLight","PointLight");super(n,r,i,l);this.target=new je;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=s}},rn=class extends Jt{constructor(e,n,r){We("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new Ze(n??4473924)}},_i=rn,Ci={Vector2:vn,Vector3:Pe,Vector4:wn,Euler:Wt,Quaternion:Yt,Matrix4:it,Matrix3:Tn,Color:Ze,MathUtils:gi,BufferAttribute:ge,Float32BufferAttribute:Mn,Uint16BufferAttribute:Sn,Uint32BufferAttribute:An,BufferGeometry:Ke,BoxGeometry:Kt,PlaneGeometry:Rn,SphereGeometry:qt,CylinderGeometry:pt,ConeGeometry:En,TorusGeometry:_n,TorusKnotGeometry:Cn,IcosahedronGeometry:Vn,OctahedronGeometry:Bn,DodecahedronGeometry:Gn,TetrahedronGeometry:Hn,CapsuleGeometry:$n,RingGeometry:Xn,CircleGeometry:jn,Texture:Zt,TextureLoader:In,Material:qe,MeshStandardMaterial:bt,MeshBasicMaterial:kn,MeshLambertMaterial:Dn,MeshPhongMaterial:Ln,MeshPhysicalMaterial:Pn,ShaderMaterial:nn,RawShaderMaterial:Ei,Object3D:je,Group:Nn,Mesh:Mt,InstancedMesh:Ft,Light:yt,AmbientLight:Jt,DirectionalLight:Un,PointLight:en,SpotLight:Wn,HemisphereLight:rn,RectAreaLight:_i,Camera:tn,PerspectiveCamera:zt,Scene:St,WebGLRenderer:On,Clock:Fn,SceneQuotaValidator:tt,exportSceneToCanvas3D:pr,exportSceneToGLB:br,exportSceneToUSDZ:xi,generateUSDZ:sr,glbToUSDZ:mn,sceneToCanvas3D:Nt,sceneToGLB:Ht,sceneToUSDZ:Ut,authorScriptRunner:Ri,getAuthorWarnings:vr,clearAuthorWarnings:wr};Object.freeze(tt);Object.freeze(tt.prototype);Object.freeze(St.prototype);Object.freeze(Ci);var ot=new Proxy(Ci,{get:(t,e)=>{if(e in t)return t[e];let n=ke().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&We(`THREE.${e}`,"no-op proxy"),Ot)},has:(t,e)=>{if(e in t)return!0;let n=ke().authorNamespace;return!!(n&&typeof e=="string"&&e in n)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),xn=ke();xn.threeNamespace=ot;if(xn.workerExtensionInstallers)for(let t of xn.workerExtensionInstallers)t(ot,xn);var jt={name:"three_author",THREE:ot},cs=jt,Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Ee.THREE>"u"&&(Ee.THREE=ot);typeof Ee.requestAnimationFrame!="function"&&(Ee.requestAnimationFrame=t=>(typeof t=="function"&&typeof Ee.__three_live_raf_cb__!="function"&&(Ee.__three_live_raf_cb__=t),Ee.__three_live_in_step__||We("requestAnimationFrame","single-frame static evaluation"),0));typeof Ee.cancelAnimationFrame!="function"&&(Ee.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=ot,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=jt,t.ThreeLivePlugins.three_author=jt,t.ThreeLivePlugins["three-author"]=jt}{ui(),hi(),Fr(ot,ke()),Zn(ot,ke());let t=new St,e=new zt(45,1,.1,1e3);e.position.set(0,2,5),Ee.scene=t,Ee.camera=e,typeof Ee.window>"u"&&(Ee.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Ee.document>"u"&&(Ee.document={createElement:()=>({getContext:()=>Ot,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Ee,"__three_live_reset_scene__",{value:function(){wr(),delete Ee.__three_live_sim_time_ms__,delete Ee.__three_live_raf_cb__,delete Ee.__three_live_in_step__,t=new St,e=new zt(45,1,.1,1e3),e.position.set(0,2,5),Ee.scene=t,Ee.camera=e},writable:!1,configurable:!1}),Object.defineProperty(Ee,"__three_live_step_js__",{value:function(c,u){Ee.__three_live_sim_time_ms__=c*1e3,Ee.__three_live_in_step__=!0;try{typeof Ee.animate=="function"?Ee.animate(c,u):typeof Ee.__three_live_raf_cb__=="function"&&Ee.__three_live_raf_cb__(c*1e3)}finally{Ee.__three_live_in_step__=!1}},writable:!1,configurable:!1});let i=function(c){if(c==null)return null;let u=2e4,f=new Set,h=(d,y)=>{if(--u<0||y>32)return;if(d===null||typeof d=="string"||typeof d=="boolean")return d;if(typeof d=="number")return Number.isFinite(d)?d:void 0;if(typeof d!="object"||f.has(d))return;f.add(d);let x;if(Array.isArray(d)){x=[];for(let T of d)x.push(h(T,y+1)??null)}else{x={};for(let T of Object.keys(d)){if(T==="__proto__"||T==="prototype"||T==="constructor")continue;let D=h(d[T],y+1);D!==void 0&&(x[T]=D)}}return f.delete(d),x};try{return h(c,0)??null}catch{return null}},o=15*1024,s=1e3*4,l=function(c){let u=yn(c);if(!u)return{};let f=JSON.stringify({...c,...u});return f.length>o&&(We(`userData.xr larger than ${o} characters`,"canonical XR traits only"),f=JSON.stringify(u)),{xr_normalized_json:f,xr_scenecore_json:JSON.stringify(ur(u)),xr_hubs_json:JSON.stringify(lr(u))}};Object.defineProperty(Ee,"__three_live_extract_scene_raw__",{value:function(){let c=[],u=[],f=[],h=[];function d(m){if(!m)return null;let L=h.indexOf(m);if(L===-1){h.push(m);let W="";m.map&&(typeof m.map=="string"?W=m.map:m.map.source?W=m.map.source:m.map.image&&(W=m.map.image)),u.push({name:m.name||`Material_${u.length}`,base_color:[m.color.r,m.color.g,m.color.b,m.opacity!==void 0?m.opacity:1],metallic:m.metalness!==void 0?m.metalness:.1,roughness:m.roughness!==void 0?m.roughness:.5,double_sided:m.side===2||m.doubleSided,base_color_texture:W||null,clearcoat:m.clearcoat||0,clearcoat_roughness:m.clearcoatRoughness||0,transmission:m.transmission||0,ior:m.ior!==void 0?m.ior:1.5,thickness:m.thickness||0}),L=u.length-1}return L}let y=(m,L)=>typeof m=="number"&&Number.isFinite(m)?m:L,x=[],T=[],D=[],V=!1,b=Ee.scene||t,_=new it().compose({x:y(b.position?.x,0),y:y(b.position?.y,0),z:y(b.position?.z,0)},{x:y(b.quaternion?.x,0),y:y(b.quaternion?.y,0),z:y(b.quaternion?.z,0),w:y(b.quaternion?.w,1)},{x:y(b.scale?.x,1),y:y(b.scale?.y,1),z:y(b.scale?.z,1)}),S=new Set([b]);{let m=new Set([b]),L=Array.isArray(b.children)?[...b.children]:[],W=0;for(;L.length>0&&W<=s;){let G=L.pop();if(!(!(G instanceof je)||m.has(G))&&(m.add(G),W++,Array.isArray(G.children)))for(let K of G.children)L.push(K)}if(W>s)return{meshes:[],nodes:new Array(W),materials:[],lights:[]}}let U=[],z=(m,L)=>{let W=Array.isArray(m.children)?m.children:[];for(let G=W.length-1;G>=0;G--)U.push([W[G],L])};z(b,-1);let I=m=>{let L=[];for(let G=m;G>=0&&L.length<=x.length;G=x[G].parent)L.push(G);let W=_.clone();for(let G=L.length-1;G>=0;G--){let K=x[L[G]];W.multiply(new it().compose({x:K.translation[0],y:K.translation[1],z:K.translation[2]},{x:K.rotation[0],y:K.rotation[1],z:K.rotation[2],w:K.rotation[3]},{x:K.scale[0],y:K.scale[1],z:K.scale[2]}))}return W};for(;U.length>0;){let[m,L]=U.pop();if(!(m instanceof je)||S.has(m))continue;S.add(m);let W=[y(m.position?.x,0),y(m.position?.y,0),y(m.position?.z,0)],G=[y(m.quaternion?.x,0),y(m.quaternion?.y,0),y(m.quaternion?.z,0),y(m.quaternion?.w,1)],K=[y(m.scale?.x,1),y(m.scale?.y,1),y(m.scale?.z,1)];dr(m);let k=-1,ee=m.geometry,Q=ee?.attributes?.position;if(Q&&Q.array&&Q.count>0){k=c.length;let he=null,ve=m.userData?.variants;if(ve&&typeof ve=="object"){let Me=new Map;for(let pe of Object.keys(ve)){if(!pe||pe==="__proto__"||pe==="constructor"||pe==="prototype")continue;let xe=ve[pe],C=xe instanceof qe?xe:xe&&typeof xe=="object"?new bt(xe):null;if(!C)continue;let w=T.indexOf(pe);if(w===-1&&T.length<256&&(w=T.length,T.push(pe)),w===-1)continue;let A=d(C);if(A!==null){let N=Me.get(A);N||(N=[],Me.set(A,N)),N.push(w)}}if(Me.size>0){let pe=[];for(let[xe,C]of Me.entries())pe.push({material:xe,variants:C});he=JSON.stringify({mappings:pe})}}c.push({name:m.name||`Mesh_${c.length}`,raw_positions:Q.array,raw_normals:ee.attributes.normal?ee.attributes.normal.array:null,raw_uvs:ee.attributes.uv?ee.attributes.uv.array:null,raw_indices:ee.index?ee.index.array:null,vertex_count:Q.count,material_index:d(m.material instanceof qe?m.material:null),variant_mappings_json:he})}let q=i(m.userData?.xr),ae=!!m.userData?.xr&&q!==null,O=i(m.userData?.interactivity),te=x.length,ue=m instanceof Ft&&m.count>0&&m.instanceMatrix?.array,le=[];if(O&&typeof O=="object")for(let he of["onSelect","onHoverIn","onHoverOut","onStart","onReceive"])O[he]&&le.push(he);if(x.push({name:typeof m.name=="string"?m.name.slice(0,1024):"",parent:L,translation:W,rotation:G,scale:K,mesh:k,xr_traits_json:ae?JSON.stringify(q):null,interactivity_events_json:le.length>0?JSON.stringify(le):null,interactivity_raw_json:O?JSON.stringify(O):null,...ae?l(q):{},...ue?{instance_matrices:m.instanceMatrix.array.subarray(0,m.count*16),instance_colors:m.instanceColor?.array?m.instanceColor.array.subarray(0,m.count*3):null}:{}}),D.push(O),O&&(V=!0),x.length>s)break;if(m instanceof yt){let he=I(te).elements;f.push({light_type:m.type,color:[m.color.r,m.color.g,m.color.b],intensity:m.intensity,position:[y(he[12],0),y(he[13],0),y(he[14],0)]})}z(m,te)}let E=[];for(let m of vr())m.includes("ShaderMaterial")||m.includes("RawShaderMaterial")||m.includes("unsupported material")?E.push({code:"TL101",severity:"warning",message:m,hint:"Use THREE.MeshStandardMaterial({ color, metalness, roughness }) instead of custom GLSL shaders."}):m.includes("requestAnimationFrame")?E.push({code:"TL104",severity:"warning",message:m,hint:"Static exports evaluate a single frame; use userData.xr.orbit, userData.interactivity, or define function animate(t) for time-stepped rendering."}):m.includes("THREE.")?E.push({code:"TL103",severity:"warning",message:m,hint:"Load external models via <three-live src='...'> or <xr-anchor src='...'>; camera controls and post-processing are managed by the host viewer."}):m.includes("larger than")?E.push({code:"TL105",severity:"warning",message:m,hint:"Keep per-node userData.xr metadata under 15 KB."}):E.push({code:"TL102",severity:"warning",message:m,hint:"Use core primitives (BoxGeometry, SphereGeometry, CylinderGeometry, ConeGeometry, TorusGeometry, TorusKnotGeometry, PlaneGeometry) and DirectionalLight / PointLight / AmbientLight."});let R=new Set;for(let m of x)typeof m.name=="string"&&m.name.trim().length>0&&R.add(m.name);for(let m=0;m<x.length;m++){let L=x[m],W=typeof L.name=="string"&&L.name.trim().length>0?L.name:"",G=W||L.mesh>=0&&c[L.mesh]?.name||`Node_${m}`,K=D[m],k=null;if(L.xr_traits_json)try{k=JSON.parse(L.xr_traits_json)}catch{k=null}if((k||K)&&!W&&E.push({code:"TL205",severity:"warning",node:G,message:`Interactive node '${G}' is missing an explicit mesh.name.`,hint:"Assign a unique mesh.name = '...' so raycasting, meshclick, and WebMCP tools can target it."}),k!==null){for(let Q of li(k,G))E.push(Q);let ee=(Q,q)=>{typeof q=="string"&&q.trim().length>0&&!R.has(q)&&E.push({code:"TL204",severity:"warning",node:G,message:`userData.xr.${Q} on node '${G}' references target node '${q}', which does not exist in scene.`,hint:`Ensure a node with mesh.name = '${q}' is added to scene via scene.add().`})};if(k.orbit&&typeof k.orbit=="object"&&ee("orbit.target",k.orbit.target),typeof k.spawner=="string"?ee("spawner.template",k.spawner):k.spawner&&typeof k.spawner=="object"&&ee("spawner.template",k.spawner.template),k.agent&&typeof k.agent=="object"){let Q=k.agent.target;Q!=="user"&&Q!=="camera"&&ee("agent.target",Q)}if(k.ik&&typeof k.ik=="object"&&k.ik.enabled!==!1){ee("ik.root",k.ik.root),ee("ik.mid",k.ik.mid),ee("ik.effector",k.ik.effector),Array.isArray(k.ik.target)||ee("ik.target",k.ik.target);let Q=k.ik.pole??k.ik.poleTarget;Array.isArray(Q)||ee("ik.pole",Q)}}if(K&&typeof K=="object"){let ee=new Set(["onSelect","onHoverIn","onHoverOut","onStart","onReceive"]),Q=new Set(["interpolate","toggleTransform","setProperty","toggleVisibility","cycleMaterialColor","playAnimation","stopAnimation","sendEvent"]),q=(O,te)=>{let ue=Array.isArray(O)?O:[O];for(let le of ue){if(!le||typeof le!="object")continue;let he=le.action;typeof he=="string"&&!Q.has(he)&&E.push({code:"TL201",severity:"warning",node:G,message:`Unrecognized action '${he}' in userData.interactivity.${te} on node '${G}'.`,hint:"Supported interactivity actions: interpolate, toggleTransform, setProperty, toggleVisibility, cycleMaterialColor, playAnimation, stopAnimation, sendEvent."});let ve=le.target;typeof ve=="string"&&ve.length>0&&!R.has(ve)&&E.push({code:"TL204",severity:"warning",node:G,message:`userData.interactivity.${te} on node '${G}' references target node '${ve}', which does not exist in scene.`,hint:`Ensure a node with mesh.name = '${ve}' is added to scene via scene.add().`});let Me=le.targetNode;typeof Me=="number"&&(Me<0||Me>=x.length)&&E.push({code:"TL204",severity:"warning",node:G,message:`userData.interactivity.${te} on node '${G}' references out-of-range targetNode ${Me} (scene has ${x.length} nodes).`,hint:"Prefer referencing nodes by name via target: '<nodeName>'."})}},ae=K;for(let O of Object.keys(ae))if(!ee.has(O)){let te=O.toLowerCase(),ue=te==="onclick"||te==="ontap"||te==="onpointerdown"?"onSelect":te==="onhover"||te==="onmouseenter"?"onHoverIn":te==="onmouseleave"?"onHoverOut":null;E.push({code:"TL201",severity:"warning",node:G,message:ue?`Unrecognized trigger '${O}' in userData.interactivity on node '${G}'; did you mean '${ue}'?`:`Unrecognized trigger '${O}' in userData.interactivity on node '${G}'.`,hint:"Supported interactivity triggers: onSelect, onHoverIn, onHoverOut, onStart, onReceive."})}for(let O of["onSelect","onHoverIn","onHoverOut","onStart"])ae[O]&&q(ae[O],O);if(ae.onReceive&&typeof ae.onReceive=="object")for(let[O,te]of Object.entries(ae.onReceive))q(te,`onReceive.${O}`)}}let g=(m,L)=>m.every((W,G)=>W===L[G]),M=i({interactivity:b.userData?.interactivity,gltfExtensions:{KHR_interactivity:b.userData?.gltfExtensions?.KHR_interactivity}}),P=!!(M?.interactivity??M?.gltfExtensions?.KHR_interactivity),v=null;(V||P)&&(v=on(x.map((m,L)=>({name:m.name,...m.mesh>=0?{mesh:m.mesh}:{},...g(m.translation,[0,0,0])?{}:{translation:m.translation},...g(m.rotation,[0,0,0,1])?{}:{rotation:m.rotation},...g(m.scale,[1,1,1])?{}:{scale:m.scale},extras:D[L]?{interactivity:D[L]}:void 0})),c.map(m=>({primitives:[{material:m.material_index??0}]})),M??void 0));let p=Ee.camera||e;return{meshes:c,nodes:x,materials:u,lights:f,interactivity_json:v?JSON.stringify(v):null,variants_json:T.length>0?JSON.stringify({variants:T.map(m=>({name:m}))}):null,diagnostics_json:E.length>0?JSON.stringify(E):null,camera:{fov:p.fov||45,position:p.position?[p.position.x,p.position.y,p.position.z]:[0,2,5],target:p.target?[p.target.x,p.target.y,p.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var us=ot;return Oi(ls);})();
|
|
328
|
+
})();`);f=null;let T=b(d,R,C,I);T&&typeof T.toGLB=="function"&&(R=T)}if(!L){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(R);let b=R.toGLB(),T=b instanceof ArrayBuffer?b:b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength);G({type:"3D_MODEL_READY",glbBuffer:T},[T])}a({type:"DONE",nonce:r})}catch(R){c(R&&R.message||R)}}},a({type:"READY",nonce:r})}function gr(t,e,n){let r=n?.allowedScriptUrl??null,i=n?.allowClientScripts??r===null,o={nonce:e,engineSrc:t,allowedScriptUrl:r,allowClientScripts:i,revoked:ts},s=(Ie().workerExtensionInstallers??[]).map(l=>`(${l.toString()})`).join(",");return`'use strict';(${ns.toString()})(${JSON.stringify(o)},[${s}]);`}function wi(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 dt=0;function Si(){try{let t=new Uint32Array(4);return globalThis.crypto?.getRandomValues(t),Array.from(t,n=>n.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function rs(t){try{return new TextEncoder().encode(t).length}catch{return t.length}}var is=1024,os=256;function pi(t){if(!Array.isArray(t)&&!(t instanceof Float32Array)||t.length!==16)return!1;for(let e=0;e<16;e++){let n=t[e];if(typeof n!="number"||!Number.isFinite(n))return!1}return!0}function xr(t,e){if(!t||typeof t!="object")return null;let n=t;if(n.nonce!==e)return null;switch(n.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof n.message=="string"?n.message:String(n.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,is)};case"3D_UPDATE_TRANSFORMS":{let i=n.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let o of i)if(!pi(o))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let o=Object.keys(i);if(o.length>1e3)return null;let s=Object.create(null),l=i;for(let a of o){if(a.length>os||a==="__proto__"||a==="constructor"||a==="prototype")return null;let c=l[a];if(!pi(c))return null;s[a]=c}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=n.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function ss(t){let e=rs(t);if(e>1048576)throw new Error(`SecurityError: Script length (${e} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Ai(t,e,n,r){switch(t.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":e.onUpdateTransforms?.(t.transforms);return;case"3D_MODEL_READY":if(r.modelDispatched)return;r.modelDispatched=!0,e.onModelReady(t.payload);return;case"DONE":n();return;case"ERROR":n(),e.onError?.(new Error(`Worker script error: ${t.message}`));return;default:return t}}function as(t,e,n,r){let i=Si(),o=gr(e,i,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts"),s.setAttribute("aria-hidden","true"),s.tabIndex=-1,s.style.display="none",s.src=n,dt++;let l=!1,a=!1,c={modelDispatched:!1},u,m=()=>{if(l||a)return;let y=s.contentWindow;!y||typeof y.postMessage!="function"||(a=!0,y.postMessage(t.kind==="url"?{type:"SANDBOX_RUN",nonce:i,workerSource:o,scriptUrl:t.scriptUrl}:{type:"SANDBOX_RUN",nonce:i,workerSource:o,script:t.script},"*"))},f=()=>{},d=y=>{if(l||!s.contentWindow||y.source!==s.contentWindow)return;let M=y.data;if(M&&typeof M=="object"&&M.type==="IFRAME_READY"){m();return}let L=xr(M,i);L&&Ai(L,r,f,c)};f=()=>{l||(l=!0,u!==void 0&&clearTimeout(u),dt=Math.max(0,dt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof s.remove=="function"?s.remove():s.parentNode&&s.parentNode.removeChild(s))},u=setTimeout(()=>{l||(f(),wi(r))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),s.onload=()=>{m()},s.onerror=()=>{f(),r.onError?.(new Error(`Sandbox iframe failed to load "${n}". Verify that three-live-sandbox.html is served at that URL.`))};let g=document.body||document.documentElement;if(!g||typeof g.appendChild!="function"){f();let y=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw r.onError?.(y),y}return g.appendChild(s),{terminate:f}}function bi(t,e,n,r){if(e==="worker"&&typeof Worker>"u")return r("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(e==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return r("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(dt>=32)return r(`SecurityError: ${dt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let i;try{i=qo()}catch(f){let d=f instanceof Error?f.message:String(f);return r(d,"Security Error: sandbox engine URL is not configured.")}if(e==="iframe"){let f;try{f=Qo()}catch(d){let g=d instanceof Error?d.message:String(d);return r(g,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(as(t,i,f,n))}catch(d){return Promise.reject(d)}}let o=Si(),s=gr(i,o,t.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:t.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l;try{let f=new Blob([s],{type:"application/javascript"}),d=URL.createObjectURL(f);try{let g=vi(d);l=new Worker(g)}finally{URL.revokeObjectURL(d)}}catch(f){let d=f instanceof Error?f.message:String(f);return r(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}dt++;let a=!1,c={modelDispatched:!1},u,m=()=>{a||(a=!0,u!==void 0&&clearTimeout(u),dt=Math.max(0,dt-1),l.terminate())};return u=setTimeout(()=>{a||(m(),wi(n))},3e3),l.onmessage=f=>{let d=xr(f.data,o);d&&Ai(d,n,m,c)},l.onerror=f=>{m(),n.onError?.(new Error(`Worker execution error: ${f.message}`))},t.kind==="url"?l.postMessage({type:"EXECUTE_URL",scriptUrl:t.scriptUrl,nonce:o}):l.postMessage({type:"EXECUTE",script:t.script,nonce:o}),Promise.resolve({terminate:m})}function yi(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 Ei={execute(t,e,n,r){let i=(l,a)=>{let c=new Error(l);return n.onError?.(c),a&&n.onToast?.(a),Promise.reject(c)},o=yi(e,i);if(o)return o;try{ss(t)}catch(l){let a=l instanceof Error?l.message:String(l);return i(a,"Security Error: script exceeds the size limit.")}return r?.allowClientScripts??Mi()?bi({kind:"script",script:t},e,n,i):i(Pr,Nr)},executeUrl(t,e,n){let r=(s,l)=>{let a=new Error(s);return n.onError?.(a),l&&n.onToast?.(l),Promise.reject(a)},i=yi(e,r);if(i)return i;let o;try{o=es(t)}catch(s){let l=s instanceof Error?s.message:String(s);return r(l,"Security Error: disallowed scene script URL.")}return bi({kind:"url",scriptUrl:o},e,n,r)}},zn=new Set;function je(t,e){let n=`[three-live] ${t} is unsupported; degraded to ${e}.`;zn.has(n)||(zn.add(n),typeof console<"u"&&typeof console.warn=="function"&&console.warn(n))}function vr(){return Array.from(zn)}function Tr(){zn.clear()}var nn=class extends bt{constructor(e={}){je("ShaderMaterial","MeshStandardMaterial");let n=e.uniforms||{},r=n.color?.value??n.uColor?.value??n.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:n.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=n}},_i=nn,St=class extends qt{constructor(e=1,n=0,r="PolyhedronGeometry"){je(r,"SphereGeometry");let i=Math.max(4,Math.min(32,4<<Math.min(n,3)));super(e,i,i)}},Vn=class extends St{constructor(e=1,n=0){super(e,n,"IcosahedronGeometry")}},Bn=class extends St{constructor(e=1,n=0){super(e,n,"OctahedronGeometry")}},Gn=class extends St{constructor(e=1,n=0){super(e,n,"DodecahedronGeometry")}},Hn=class extends St{constructor(e=1,n=0){super(e,n,"TetrahedronGeometry")}},$n=class extends pt{constructor(e=1,n=1,r=4,i=8){je("CapsuleGeometry","CylinderGeometry"),super(e,e,n+e*2,i)}},Xn=class extends pt{constructor(e=.5,n=1,r=16){je("RingGeometry","CylinderGeometry"),super(n,n,.01,Math.max(8,r))}},jn=class extends pt{constructor(e=1,n=16){je("CircleGeometry","CylinderGeometry"),super(e,e,.01,Math.max(8,n))}},Wn=class extends en{constructor(n,r,i=0,o=Math.PI/3,s=0,l=2){je("SpotLight","PointLight");super(n,r,i,l);this.target=new Xe;this.angle=Math.PI/3;this.penumbra=0;this.angle=o,this.penumbra=s}},rn=class extends Jt{constructor(e,n,r){je("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new Ze(n??4473924)}},Ri=rn,Ci={Vector2:vn,Vector3:Le,Vector4:Tn,Euler:Wt,Quaternion:Yt,Matrix4:it,Matrix3:Mn,Color:Ze,MathUtils:gi,BufferAttribute:Be,Float32BufferAttribute:wn,Uint16BufferAttribute:Sn,Uint32BufferAttribute:An,BufferGeometry:Ye,BoxGeometry:Kt,PlaneGeometry:En,SphereGeometry:qt,CylinderGeometry:pt,ConeGeometry:_n,TorusGeometry:Rn,TorusKnotGeometry:Cn,IcosahedronGeometry:Vn,OctahedronGeometry:Bn,DodecahedronGeometry:Gn,TetrahedronGeometry:Hn,CapsuleGeometry:$n,RingGeometry:Xn,CircleGeometry:jn,Texture:Zt,TextureLoader:In,Material:Ke,MeshStandardMaterial:bt,MeshBasicMaterial:kn,MeshLambertMaterial:Dn,MeshPhongMaterial:Ln,MeshPhysicalMaterial:Pn,ShaderMaterial:nn,RawShaderMaterial:_i,Object3D:Xe,Group:Nn,Mesh:Mt,InstancedMesh:Ft,Light:yt,AmbientLight:Jt,DirectionalLight:Un,PointLight:en,SpotLight:Wn,HemisphereLight:rn,RectAreaLight:Ri,Camera:tn,PerspectiveCamera:zt,Scene:wt,WebGLRenderer:On,Clock:Fn,SceneQuotaValidator:tt,exportSceneToCanvas3D:pr,exportSceneToGLB:br,exportSceneToUSDZ:xi,generateUSDZ:or,glbToUSDZ:dn,sceneToCanvas3D:Pt,sceneToGLB:Ht,sceneToUSDZ:Nt,authorScriptRunner:Ei,getAuthorWarnings:vr,clearAuthorWarnings:Tr};Object.freeze(tt);Object.freeze(tt.prototype);Object.freeze(wt.prototype);Object.freeze(Ci);var ot=new Proxy(Ci,{get:(t,e)=>{if(e in t)return t[e];let n=Ie().authorNamespace;return n&&typeof e=="string"&&e in n?n[e]:(typeof e=="string"&&e!=="then"&&e!=="toJSON"&&!e.startsWith("__")&&je(`THREE.${e}`,"no-op proxy"),Ot)},has:(t,e)=>{if(e in t)return!0;let n=Ie().authorNamespace;return!!(n&&typeof e=="string"&&e in n)},set:(t,e)=>{throw new TypeError(`Cannot assign to read only property '${String(e)}' of #<THREE>`)},defineProperty:(t,e)=>{throw new TypeError(`Cannot define property '${String(e)}', object is not extensible`)},deleteProperty:(t,e)=>{throw new TypeError(`Cannot delete property '${String(e)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),xn=Ie();xn.threeNamespace=ot;if(xn.workerExtensionInstallers)for(let t of xn.workerExtensionInstallers)t(ot,xn);var jt={name:"three_author",THREE:ot},cs=jt,Ee=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;typeof Ee.THREE>"u"&&(Ee.THREE=ot);typeof Ee.requestAnimationFrame!="function"&&(Ee.requestAnimationFrame=t=>(typeof t=="function"&&typeof Ee.__three_live_raf_cb__!="function"&&(Ee.__three_live_raf_cb__=t),Ee.__three_live_in_step__||je("requestAnimationFrame","single-frame static evaluation"),0));typeof Ee.cancelAnimationFrame!="function"&&(Ee.cancelAnimationFrame=()=>{});if(typeof window<"u"){let t=window;t.ThreeLive=t.ThreeLive||{},t.ThreeLive.THREE=ot,t.ThreeLivePlugins=t.ThreeLivePlugins||{},t.ThreeLivePlugins.threeAuthor=jt,t.ThreeLivePlugins.three_author=jt,t.ThreeLivePlugins["three-author"]=jt}{ui(),hi(),Fr(ot,Ie()),Zn(ot,Ie());let t=new wt,e=new zt(45,1,.1,1e3);e.position.set(0,2,5),Ee.scene=t,Ee.camera=e,typeof Ee.window>"u"&&(Ee.window={innerWidth:1024,innerHeight:768,devicePixelRatio:1,addEventListener:()=>{},removeEventListener:()=>{}}),typeof Ee.document>"u"&&(Ee.document={createElement:()=>({getContext:()=>Ot,style:{},addEventListener:()=>{}}),body:{appendChild:()=>{},style:{}},addEventListener:()=>{}}),Object.defineProperty(Ee,"__three_live_reset_scene__",{value:function(){Tr(),delete Ee.__three_live_sim_time_ms__,delete Ee.__three_live_raf_cb__,delete Ee.__three_live_in_step__,t=new wt,e=new zt(45,1,.1,1e3),e.position.set(0,2,5),Ee.scene=t,Ee.camera=e},writable:!1,configurable:!1}),Object.defineProperty(Ee,"__three_live_step_js__",{value:function(c,u){Ee.__three_live_sim_time_ms__=c*1e3,Ee.__three_live_in_step__=!0;try{typeof Ee.animate=="function"?Ee.animate(c,u):typeof Ee.__three_live_raf_cb__=="function"&&Ee.__three_live_raf_cb__(c*1e3)}finally{Ee.__three_live_in_step__=!1}},writable:!1,configurable:!1});let i=function(c){if(c==null)return null;let u=2e4,m=new Set,f=(d,g)=>{if(--u<0||g>32)return;if(d===null||typeof d=="string"||typeof d=="boolean")return d;if(typeof d=="number")return Number.isFinite(d)?d:void 0;if(typeof d!="object"||m.has(d))return;m.add(d);let y;if(Array.isArray(d)){y=[];for(let M of d)y.push(f(M,g+1)??null)}else{y={};for(let M of Object.keys(d)){if(M==="__proto__"||M==="prototype"||M==="constructor")continue;let L=f(d[M],g+1);L!==void 0&&(y[M]=L)}}return m.delete(d),y};try{return f(c,0)??null}catch{return null}},o=15*1024,s=1e3*4,l=function(c){let u=yn(c);if(!u)return{};let m=JSON.stringify({...c,...u});return m.length>o&&(je(`userData.xr larger than ${o} characters`,"canonical XR traits only"),m=JSON.stringify(u)),{xr_normalized_json:m,xr_scenecore_json:JSON.stringify(ur(u)),xr_hubs_json:JSON.stringify(lr(u))}};Object.defineProperty(Ee,"__three_live_extract_scene_raw__",{value:function(){let c=[],u=[],m=[],f=[];function d(h){if(!h)return null;let A=f.indexOf(h);if(A===-1){f.push(h);let $="";h.map&&(typeof h.map=="string"?$=h.map:h.map.source?$=h.map.source:h.map.image&&($=h.map.image)),u.push({name:h.name||`Material_${u.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:.1,roughness:h.roughness!==void 0?h.roughness:.5,double_sided:h.side===2||h.doubleSided,base_color_texture:$||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}),A=u.length-1}return A}let g=(h,A)=>typeof h=="number"&&Number.isFinite(h)?h:A,y=[],M=[],L=[],G=!1,p=Ee.scene||t,E=new it().compose({x:g(p.position?.x,0),y:g(p.position?.y,0),z:g(p.position?.z,0)},{x:g(p.quaternion?.x,0),y:g(p.quaternion?.y,0),z:g(p.quaternion?.z,0),w:g(p.quaternion?.w,1)},{x:g(p.scale?.x,1),y:g(p.scale?.y,1),z:g(p.scale?.z,1)}),_=new Set([p]);{let h=new Set([p]),A=Array.isArray(p.children)?[...p.children]:[],$=0;for(;A.length>0&&$<=s;){let V=A.pop();if(!(!(V instanceof Xe)||h.has(V))&&(h.add(V),$++,Array.isArray(V.children)))for(let K of V.children)A.push(K)}if($>s)return{meshes:[],nodes:new Array($),materials:[],lights:[]}}let P=[],z=(h,A)=>{let $=Array.isArray(h.children)?h.children:[];for(let V=$.length-1;V>=0;V--)P.push([$[V],A])};z(p,-1);let R=h=>{let A=[];for(let V=h;V>=0&&A.length<=y.length;V=y[V].parent)A.push(V);let $=E.clone();for(let V=A.length-1;V>=0;V--){let K=y[A[V]];$.multiply(new it().compose({x:K.translation[0],y:K.translation[1],z:K.translation[2]},{x:K.rotation[0],y:K.rotation[1],z:K.rotation[2],w:K.rotation[3]},{x:K.scale[0],y:K.scale[1],z:K.scale[2]}))}return $};for(;P.length>0;){let[h,A]=P.pop();if(!(h instanceof Xe)||_.has(h))continue;_.add(h);let $=[g(h.position?.x,0),g(h.position?.y,0),g(h.position?.z,0)],V=[g(h.quaternion?.x,0),g(h.quaternion?.y,0),g(h.quaternion?.z,0),g(h.quaternion?.w,1)],K=[g(h.scale?.x,1),g(h.scale?.y,1),g(h.scale?.z,1)];dr(h);let k=-1,ee=h.geometry,Q=ee?.attributes?.position;if(Q&&Q.array&&Q.count>0){k=c.length;let he=null,xe=h.userData?.variants;if(xe&&typeof xe=="object"){let Me=new Map;for(let pe of Object.keys(xe)){if(!pe||pe==="__proto__"||pe==="constructor"||pe==="prototype")continue;let ge=xe[pe],S=ge instanceof Ke?ge:ge&&typeof ge=="object"?new bt(ge):null;if(!S)continue;let x=M.indexOf(pe);if(x===-1&&M.length<256&&(x=M.length,M.push(pe)),x===-1)continue;let w=d(S);if(w!==null){let U=Me.get(w);U||(U=[],Me.set(w,U)),U.push(x)}}if(Me.size>0){let pe=[];for(let[ge,S]of Me.entries())pe.push({material:ge,variants:S});he=JSON.stringify({mappings:pe})}}c.push({name:h.name||`Mesh_${c.length}`,raw_positions:Q.array,raw_normals:ee.attributes.normal?ee.attributes.normal.array:null,raw_uvs:ee.attributes.uv?ee.attributes.uv.array:null,raw_indices:ee.index?ee.index.array:null,vertex_count:Q.count,material_index:d(h.material instanceof Ke?h.material:null),variant_mappings_json:he})}let q=i(h.userData?.xr),ae=!!h.userData?.xr&&q!==null,F=i(h.userData?.interactivity),te=y.length,ue=h instanceof Ft&&h.count>0&&h.instanceMatrix?.array,le=[];if(F&&typeof F=="object")for(let he of["onSelect","onHoverIn","onHoverOut","onStart","onReceive"])F[he]&&le.push(he);if(y.push({name:typeof h.name=="string"?h.name.slice(0,1024):"",parent:A,translation:$,rotation:V,scale:K,mesh:k,xr_traits_json:ae?JSON.stringify(q):null,interactivity_events_json:le.length>0?JSON.stringify(le):null,interactivity_raw_json:F?JSON.stringify(F):null,...ae?l(q):{},...ue?{instance_matrices:h.instanceMatrix.array.subarray(0,h.count*16),instance_colors:h.instanceColor?.array?h.instanceColor.array.subarray(0,h.count*3):null}:{}}),L.push(F),F&&(G=!0),y.length>s)break;if(h instanceof yt){let he=R(te).elements;m.push({light_type:h.type,color:[h.color.r,h.color.g,h.color.b],intensity:h.intensity,position:[g(he[12],0),g(he[13],0),g(he[14],0)]})}z(h,te)}let C=[];for(let h of vr()){let[A,$]=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.']:h.includes("THREE.")?["TL103","Load external models via <three-live src='...'> or <xr-anchor src='...'>; camera controls and post-processing are managed by the host viewer."]:h.includes("larger than")?["TL105","Keep per-node userData.xr metadata under 15 KB."]:["TL102","Use core primitives (BoxGeometry, SphereGeometry, CylinderGeometry, ConeGeometry, TorusGeometry, TorusKnotGeometry, PlaneGeometry) and DirectionalLight / PointLight / AmbientLight."];C.push({code:A,severity:"warning",message:h,hint:$})}let I=new Set;for(let h of y)typeof h.name=="string"&&h.name.trim().length>0&&I.add(h.name);for(let h=0;h<y.length;h++){let A=y[h],$=typeof A.name=="string"&&A.name.trim().length>0?A.name:"",V=$||A.mesh>=0&&c[A.mesh]?.name||`Node_${h}`,K=L[h],k=null;if(A.xr_traits_json)try{k=JSON.parse(A.xr_traits_json)}catch{k=null}if((k||K)&&!$&&C.push({code:"TL205",severity:"warning",node:V,message:`Interactive node '${V}' is missing an explicit mesh.name.`,hint:"Assign a unique mesh.name = '...' so raycasting, meshclick, and WebMCP tools can target it."}),k!==null){for(let Q of li(k,V))C.push(Q);let ee=(Q,q)=>{typeof q=="string"&&q.trim().length>0&&!I.has(q)&&C.push({code:"TL204",severity:"warning",node:V,message:`userData.xr.${Q} on node '${V}' references target node '${q}', which does not exist in scene.`,hint:`Ensure a node with mesh.name = '${q}' is added to scene via scene.add().`})};if(k.orbit&&typeof k.orbit=="object"&&ee("orbit.target",k.orbit.target),typeof k.spawner=="string"?ee("spawner.template",k.spawner):k.spawner&&typeof k.spawner=="object"&&ee("spawner.template",k.spawner.template),k.agent&&typeof k.agent=="object"){let Q=k.agent.target;Q!=="user"&&Q!=="camera"&&ee("agent.target",Q)}if(k.ik&&typeof k.ik=="object"&&k.ik.enabled!==!1){ee("ik.root",k.ik.root),ee("ik.mid",k.ik.mid),ee("ik.effector",k.ik.effector),Array.isArray(k.ik.target)||ee("ik.target",k.ik.target);let Q=k.ik.pole??k.ik.poleTarget;Array.isArray(Q)||ee("ik.pole",Q)}}if(K&&typeof K=="object"){let ee=new Set(["onSelect","onHoverIn","onHoverOut","onStart","onReceive"]),Q=new Set(["interpolate","toggleTransform","setProperty","toggleVisibility","cycleMaterialColor","playAnimation","stopAnimation","sendEvent"]),q=(F,te)=>{let ue=Array.isArray(F)?F:[F];for(let le of ue){if(!le||typeof le!="object")continue;let he=le.action;typeof he=="string"&&!Q.has(he)&&C.push({code:"TL201",severity:"warning",node:V,message:`Unrecognized action '${he}' in userData.interactivity.${te} on node '${V}'.`,hint:"Supported interactivity actions: interpolate, toggleTransform, setProperty, toggleVisibility, cycleMaterialColor, playAnimation, stopAnimation, sendEvent."});let xe=le.target;typeof xe=="string"&&xe.length>0&&!I.has(xe)&&C.push({code:"TL204",severity:"warning",node:V,message:`userData.interactivity.${te} on node '${V}' references target node '${xe}', which does not exist in scene.`,hint:`Ensure a node with mesh.name = '${xe}' is added to scene via scene.add().`});let Me=le.targetNode;typeof Me=="number"&&(Me<0||Me>=y.length)&&C.push({code:"TL204",severity:"warning",node:V,message:`userData.interactivity.${te} on node '${V}' references out-of-range targetNode ${Me} (scene has ${y.length} nodes).`,hint:"Prefer referencing nodes by name via target: '<nodeName>'."})}},ae=K;for(let F of Object.keys(ae))if(!ee.has(F)){let te=F.toLowerCase(),ue=te==="onclick"||te==="ontap"||te==="onpointerdown"?"onSelect":te==="onhover"||te==="onmouseenter"?"onHoverIn":te==="onmouseleave"?"onHoverOut":null;C.push({code:"TL201",severity:"warning",node:V,message:ue?`Unrecognized trigger '${F}' in userData.interactivity on node '${V}'; did you mean '${ue}'?`:`Unrecognized trigger '${F}' in userData.interactivity on node '${V}'.`,hint:"Supported interactivity triggers: onSelect, onHoverIn, onHoverOut, onStart, onReceive."})}for(let F of["onSelect","onHoverIn","onHoverOut","onStart"])ae[F]&&q(ae[F],F);if(ae.onReceive&&typeof ae.onReceive=="object")for(let[F,te]of Object.entries(ae.onReceive))q(te,`onReceive.${F}`)}}let b=(h,A)=>h.every(($,V)=>$===A[V]),T=i({interactivity:p.userData?.interactivity,gltfExtensions:{KHR_interactivity:p.userData?.gltfExtensions?.KHR_interactivity}}),N=!!(T?.interactivity??T?.gltfExtensions?.KHR_interactivity),v=null;(G||N)&&(v=on(y.map((h,A)=>({name:h.name,...h.mesh>=0?{mesh:h.mesh}:{},...b(h.translation,[0,0,0])?{}:{translation:h.translation},...b(h.rotation,[0,0,0,1])?{}:{rotation:h.rotation},...b(h.scale,[1,1,1])?{}:{scale:h.scale},extras:L[A]?{interactivity:L[A]}:void 0})),c.map(h=>({primitives:[{material:h.material_index??0}]})),T??void 0));let D=Ee.camera||e;return{meshes:c,nodes:y,materials:u,lights:m,interactivity_json:v?JSON.stringify(v):null,variants_json:M.length>0?JSON.stringify({variants:M.map(h=>({name:h}))}):null,diagnostics_json:C.length>0?JSON.stringify(C):null,camera:{fov:D.fov||45,position:D.position?[D.position.x,D.position.y,D.position.z]:[0,2,5],target:D.target?[D.target.x,D.target.y,D.target.z]:[0,0,0]}}},writable:!1,configurable:!1})}var us=ot;return Oi(ls);})();
|