three-live 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,8 +13,8 @@
13
13
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
- */var gi=Object.defineProperty,Ba=Object.getOwnPropertyDescriptor,za=Object.getOwnPropertyNames,Ga=Object.prototype.hasOwnProperty,Ha=(e,t)=>{for(var r in t)gi(e,r,{get:t[r],enumerable:!0})},Xa=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of za(t))!Ga.call(e,n)&&n!==r&&gi(e,n,{get:()=>t[n],enumerable:!(i=Ba(t,n))||i.enumerable});return e},$a=e=>Xa(gi({},"__esModule",{value:!0}),e),Co={};Ha(Co,{AmbientLight:()=>kn,BoxGeometry:()=>In,BufferAttribute:()=>He,BufferGeometry:()=>Fe,Camera:()=>Un,CapsuleGeometry:()=>Wr,CatmullRomCurve3:()=>_r,CircleGeometry:()=>jr,Clock:()=>Br,Color:()=>it,ConeGeometry:()=>Tr,CubicBezierCurve3:()=>Rr,Curve3:()=>Mt,CylinderGeometry:()=>Cn,DataTexture:()=>Ir,DirectionalLight:()=>Ur,DodecahedronGeometry:()=>$r,EdgesGeometry:()=>Yr,Euler:()=>_n,Float32BufferAttribute:()=>yr,Group:()=>Or,HemisphereLight:()=>Gn,IKSolver:()=>Qo,IcosahedronGeometry:()=>Xr,InstancedMesh:()=>Nn,InteractivityVM:()=>Kn,LOD:()=>ns,LatheGeometry:()=>Dn,Light:()=>Gt,Line:()=>Ut,LineBasicMaterial:()=>un,LineCurve3:()=>Sr,LineDashedMaterial:()=>Kr,LineLoop:()=>Zr,LineSegments:()=>Qr,LodController:()=>yn,MAX_BSP_DEPTH:()=>Wo,MAX_CSG_TRIANGLES:()=>$o,MAX_INSTANCES_PER_MESH:()=>Pn,MAX_SHAPE_POINTS:()=>Ko,MAX_TEXT_GEOMETRY_CHARS:()=>jo,Material:()=>Je,MathUtils:()=>Os,Matrix3:()=>br,Matrix4:()=>Ot,Mesh:()=>mt,MeshBasicMaterial:()=>Dr,MeshLambertMaterial:()=>Pr,MeshPhongMaterial:()=>Nr,MeshPhysicalMaterial:()=>kr,MeshStandardMaterial:()=>zt,Object3D:()=>ot,OctahedronGeometry:()=>Hr,PerspectiveCamera:()=>Fr,PlaneGeometry:()=>vr,PointLight:()=>On,Points:()=>Jr,PointsMaterial:()=>zn,PolyhedronFallbackGeometry:()=>Fc,PolyhedronGeometry:()=>Tt,QuadraticBezierCurve3:()=>Er,Quaternion:()=>Ln,RawShaderMaterial:()=>Ks,RectAreaLight:()=>Zs,RingGeometry:()=>Bn,Scene:()=>Fn,SceneQuotaValidator:()=>lt,ShaderMaterial:()=>Vn,SphereGeometry:()=>Mr,SpotLight:()=>ei,THREE:()=>Xt,TetrahedronGeometry:()=>Gr,Texture:()=>an,TextureLoader:()=>Cr,ThreeLiveElement:()=>ft,ThreeView:()=>je,TorusGeometry:()=>Ar,TorusKnotGeometry:()=>wr,TubeGeometry:()=>Lr,Uint16BufferAttribute:()=>gr,Uint32BufferAttribute:()=>xr,Vector2:()=>nt,Vector3:()=>ge,Vector4:()=>pr,WebGLRenderer:()=>Vr,WireframeGeometry:()=>qr,activateAR:()=>oi,applyMeshoptFilter:()=>Ao,authorScriptRunner:()=>ln,buildSandboxWorkerSource:()=>Wi,cadPlugin:()=>xi,clearAuthorWarnings:()=>js,computeOutlineClipOffset:()=>Na,contactShadowPlugin:()=>Wn,createUSDZBlob:()=>sn,crossFadeTo:()=>eo,decimateGeometry:()=>ts,decodeMeshoptBuffer:()=>wo,decodeMeshoptGLB:()=>hi,encodeMeshoptBuffer:()=>La,environmentMapPlugin:()=>ho,evaluateKawaseBloom:()=>Pa,evaluateToneMapping:()=>ms,exportSceneToCanvas3D:()=>Gi,exportSceneToGLB:()=>Hi,exportSceneToUSDZ:()=>Vs,extractMaterialVariants:()=>_o,extractPrimitiveVariantMappings:()=>ka,generateUSDZ:()=>wn,getARCapabilities:()=>ii,getAllowClientScripts:()=>Gs,getAuthorWarnings:()=>Ws,getBestARMode:()=>oa,getEnvironmentSH:()=>ca,getInteractivityVM:()=>mi,getLodController:()=>rs,getSandboxEngineSrc:()=>Xi,getSandboxIframeSrc:()=>zs,glbToUSDZ:()=>An,hotspotPlugin:()=>yo,ikPlugin:()=>Li,installCadExtension:()=>tr,installLodExtension:()=>bn,interactivityPlugin:()=>Mo,isAllowedSandboxEngineUrl:()=>cn,isQuickLookSupported:()=>co,isSceneViewerSupported:()=>uo,isWebXRSupported:()=>lo,keyframeAnimationPlugin:()=>to,lodPlugin:()=>Ii,materialsPlugin:()=>To,meshoptDecoder:()=>pi,meshoptPlugin:()=>So,morphPlugin:()=>no,noopProxy:()=>En,parseAnimations:()=>Ji,parseHexRgb:()=>Eo,parseLod:()=>sr,parseSafeGltfPointer:()=>jn,postprocessingPlugin:()=>Ro,quatFromUnitVectors:()=>ir,registerMaterialShader:()=>ba,sampleChannel:()=>fn,sceneToCanvas3D:()=>on,sceneToGLB:()=>vn,sceneToUSDZ:()=>Tn,selectLodLevelIndex:()=>or,selectMaterialVariant:()=>Oa,sendInteractivityEvent:()=>vo,setAllowClientScripts:()=>Lc,setEnvironmentSH:()=>si,setMorphTargetWeight:()=>ta,setSandboxEngineSrc:()=>Sc,setSandboxIframeSrc:()=>Rc,skinningPlugin:()=>io,solveFABRIK:()=>Ri,solveTwoBoneIK:()=>Ei,threeAuthorPlugin:()=>Rn,threeMicroPlugin:()=>zc,toGLBData:()=>gt,toTrustedWorkerScriptURL:()=>Bs,validateSandboxWorkerMessage:()=>ji,variantsPlugin:()=>Lo,warnUnsupported:()=>Ht,webxrPlugin:()=>Io}),module.exports=$a(Co);function Xo(e,t,r){let i=[],n=new Map,s=[],l=[],o=[],a=new Map,u=d=>{let y=n.get(d);return y===void 0&&(y=i.length,i.push({op:d}),n.set(d,y)),y},h=d=>{let y=a.get(d);return y===void 0&&(y=o.length,o.push({id:d}),a.set(d,y)),y},c=(d,y={})=>s.push({declaration:u(d),...y})-1,f=(d,y,M)=>l.push({id:d,type:y,value:M})-1,p=d=>({node:d,socket:"value"}),m=r?.interactivity??r?.gltfExtensions?.KHR_interactivity;if(m&&typeof m=="object"){let d=Array.isArray(m.graphs)?m.graphs[m.graph??0]:m;if(d&&Array.isArray(d.nodes)){let y=Array.isArray(d.declarations)?d.declarations:[];for(let M of y)M?.op&&u(M.op);Array.isArray(d.variables)&&l.push(...d.variables);for(let M of d.events||[])M?.id&&h(M.id);for(let M of d.nodes){if(!M||typeof M!="object")continue;let T=M.op||(typeof M.declaration=="number"?y[M.declaration]?.op:"");s.push(T?{...M,declaration:u(T)}:{...M})}}}let g=(d,y,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,y)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,y)}/${M}`:M==="visible"?`/nodes/${d}/extensions/KHR_node_visibility/visible`:`/nodes/${d}/${M}`,x=new Map;e.forEach((d,y)=>{typeof d?.name=="string"&&!x.has(d.name)&&x.set(d.name,y)});let b=(d,y)=>typeof d.target=="string"&&x.has(d.target)?x.get(d.target):typeof d.targetNode=="number"?d.targetNode:y,v=d=>{let y=e[d];return(typeof y?.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0};for(let d=0;d<e.length;d++){let y=e[d],M=y?.extras?.interactivity;if(!M||typeof M!="object")continue;let T=(typeof y.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0,V=P=>{let R=Array.isArray(P)?P:[P],C=[];for(let N=0;N<R.length;N++){let w=R[N];if(!w||typeof w!="object")continue;let ie=w.action||"interpolate",ae=typeof w.duration=="number"?w.duration:.35;if(ie==="toggleTransform"){let k=w.property==="rotation"||w.property==="scale"?w.property:"translation",J=k==="rotation"?y.rotation||[0,0,0,1]:k==="scale"?y.scale||[1,1,1]:y.translation||[0,0,0],z=`/nodes/${d}/${k}`,Y=f(`__toggle_${d}_${N}`,"bool",!1),le=c("variable/get",{configuration:{variable:Y}}),ce=c("math/not",{values:{a:p(le)}}),$=c("variable/set",{configuration:{variable:Y},values:{value:p(ce)}}),U=c("pointer/interpolate",{configuration:{pointer:z},values:{value:{value:Array.isArray(w.to)?w.to:J},duration:{value:ae}}}),_=c("pointer/interpolate",{configuration:{pointer:z},values:{value:{value:Array.isArray(w.from)?w.from:J},duration:{value:ae}}});s[$].flows={out:{node:c("flow/branch",{values:{condition:p(le)},flows:{true:{node:U},false:{node:_}}})}},C.push($)}else if(ie==="interpolate"){let k=w.to??w.value;if(k===void 0)continue;let J={value:{value:k},duration:{value:ae}};w.from!==void 0&&(J.from={value:w.from}),C.push(c("pointer/interpolate",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,d),v(b(w,d)),w.property)},values:J}))}else if(ie==="setProperty"){if(w.value===void 0)continue;C.push(c("pointer/set",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,d),v(b(w,d)),w.property)},values:{value:{value:w.value}}}))}else if(ie==="toggleVisibility"){let k=b(w,d),J=f(`__vis_${k}_${N}`,"bool",!0),z=c("variable/get",{configuration:{variable:J}}),Y=c("math/not",{values:{a:p(z)}}),le=c("variable/set",{configuration:{variable:J},values:{value:p(Y)}});s[le].flows={out:{node:c("pointer/set",{configuration:{pointer:`/nodes/${k}/extensions/KHR_node_visibility/visible`},values:{value:p(z)}})}},C.push(le)}else if(ie==="cycleMaterialColor"&&Array.isArray(w.colors)&&w.colors.length>0){let k=typeof w.duration=="number"?w.duration:.25,J=`/materials/${Math.max(0,T)}/pbrMetallicRoughness/baseColorFactor`,z=f(`__color_idx_${d}_${N}`,"int",0),Y=c("variable/get",{configuration:{variable:z}}),le=c("math/add",{values:{a:p(Y),b:{value:1}}}),ce=c("math/rem",{values:{a:p(le),b:{value:w.colors.length}}}),$=c("variable/set",{configuration:{variable:z},values:{value:p(ce)}}),U={};for(let _=0;_<w.colors.length;_++){let H=w.colors[_],D=Array.isArray(H)&&H.length>=3?[H[0],H[1],H[2],H[3]??1]:[1,1,1,1];U[String(_)]={node:k>0?c("pointer/interpolate",{configuration:{pointer:J},values:{value:{value:D},duration:{value:k}}}):c("pointer/set",{configuration:{pointer:J},values:{value:{value:D}}})}}s[$].flows={out:{node:c("flow/switch",{values:{selection:p(Y)},flows:U})}},C.push($)}else if(ie==="playAnimation")C.push(c("animation/start",{configuration:{animation:w.animation??w.clip??0}}));else if(ie==="stopAnimation")C.push(c("animation/stop"));else if(ie==="sendEvent"){let k={};for(let[J,z]of Object.entries(w.values||{}))k[J]={value:z};C.push(c("event/send",{configuration:{event:h(String(w.event??w.id??"custom"))},values:k}))}}if(!C.length)return null;if(C.length===1)return C[0];let B={};return C.forEach((N,w)=>{B[String(w)]={node:N}}),c("flow/sequence",{flows:B})},X=(P,R,C)=>{let B=V(R);B!==null&&c(P,{...C?{configuration:C}:{},flows:{out:{node:B}}})};if(M.onSelect&&X("pointer/onSelect",M.onSelect,{nodeIndex:d}),M.onHoverIn&&X("pointer/onHoverIn",M.onHoverIn,{nodeIndex:d}),M.onHoverOut&&X("pointer/onHoverOut",M.onHoverOut,{nodeIndex:d}),M.onStart&&X("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[P,R]of Object.entries(M.onReceive))X("event/receive",R,{event:h(P)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:l,events:o}],graph:0}:null}var Zn='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).',Qn="Security Error: client-side scripts require allow-client-scripts opt-in.",Jn="__THREE_LIVE_REGISTRY__";function Me(){let e=typeof globalThis<"u"?globalThis:{};if(!e[Jn]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,Jn,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[Jn]=t}}return e[Jn]}var Oe=Me().plugins;function Jt(e){let t=Me();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function Ue(e){let t=Me().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function er(){return Me().plugins}var $o=8192,Wo=2048,jo=128,Ko=4096;function tr(e,t){if(!e||!e.BufferGeometry)return null;let r=e.Vector2,i=e.Vector3,n=e.Quaternion,s=e.Matrix4,l=e.Matrix3,o=e.Color,a=e.BufferAttribute,u=e.BufferGeometry,h=e.Material,c=e.MeshStandardMaterial,f=e.Mesh,p=8192,m=2048,g=128,x=4096,b=(A,S)=>{let L=A==null?NaN:Number(A);return Number.isFinite(L)?L:S};class v{constructor(S){this.currentPoint=new r(0,0),this.segments=[],Array.isArray(S)&&S.length>0&&this.fromPoints(S)}fromPoints(S){if(!S.length)return this;this.moveTo(S[0].x,S[0].y);for(let L=1;L<S.length;L++)this.lineTo(S[L].x,S[L].y);return this}moveTo(S,L){let O=Number(S)||0,I=Number(L)||0;return this.currentPoint.set(O,I),this.segments.push({type:"move",pts:[O,I]}),this}lineTo(S,L){let O=Number(S)||0,I=Number(L)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(O,I),this.segments.push({type:"line",pts:[O,I]}),this}quadraticCurveTo(S,L,O,I){let W=this.currentPoint.x,Q=this.currentPoint.y,K=Number(S)||0,Z=Number(L)||0,q=Number(O)||0,re=Number(I)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[W,Q]}),this.currentPoint.set(q,re),this.segments.push({type:"quad",pts:[W,Q,K,Z,q,re]}),this}bezierCurveTo(S,L,O,I,W,Q){let K=this.currentPoint.x,Z=this.currentPoint.y,q=Number(S)||0,re=Number(L)||0,ne=Number(O)||0,te=Number(I)||0,ue=Number(W)||0,me=Number(Q)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[K,Z]}),this.currentPoint.set(ue,me),this.segments.push({type:"cubic",pts:[K,Z,q,re,ne,te,ue,me]}),this}absarc(S,L,O,I,W,Q=!1){return this.absellipse(S,L,O,O,I,W,Q,0)}arc(S,L,O,I,W,Q=!1){return this.absarc(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(L)||0),O,I,W,Q)}absellipse(S,L,O,I,W,Q,K=!1,Z=0){let q=Number(S)||0,re=Number(L)||0,ne=Math.max(0,Number(O)||0),te=Math.max(0,Number(I)||0),ue=Number(W)||0,me=Number(Q)||0,pe=K?1:0,fe=Number(Z)||0;this.segments.push({type:"arc",pts:[q,re,ne,te,ue,me,pe,fe]});let de=Math.cos(fe),ye=Math.sin(fe),we=ne*Math.cos(me),be=te*Math.sin(me);return this.currentPoint.set(q+we*de-be*ye,re+we*ye+be*de),this}ellipse(S,L,O,I,W,Q,K=!1,Z=0){return this.absellipse(this.currentPoint.x+(Number(S)||0),this.currentPoint.y+(Number(L)||0),O,I,W,Q,K,Z)}closePath(){if(this.segments.length>0){let S=this.segments[0],L=0,O=0;if(S.type==="arc"){let I=S.pts[0],W=S.pts[1],Q=S.pts[2],K=S.pts[3],Z=S.pts[4],q=S.pts[7],re=Math.cos(q),ne=Math.sin(q),te=Q*Math.cos(Z),ue=K*Math.sin(Z);L=I+te*re-ue*ne,O=W+te*ne+ue*re}else L=S.pts[0],O=S.pts[1];Math.hypot(this.currentPoint.x-L,this.currentPoint.y-O)>1e-6&&this.lineTo(L,O)}return this}getPoints(S=12){let L=Math.max(1,Math.min(128,Math.floor(Number(S)||12))),O=[],I=(W,Q)=>{if(O.length>0){let K=O[O.length-1];if(Math.hypot(K.x-W,K.y-Q)<1e-6)return}O.push(new r(W,Q))};for(let W of this.segments){let Q=W.pts;if(W.type==="move"||W.type==="line")I(Q[0],Q[1]);else if(W.type==="quad"){let K=Q[0],Z=Q[1],q=Q[2],re=Q[3],ne=Q[4],te=Q[5];I(K,Z);for(let ue=1;ue<=L;ue++){let me=ue/L,pe=1-me;I(pe*pe*K+2*pe*me*q+me*me*ne,pe*pe*Z+2*pe*me*re+me*me*te)}}else if(W.type==="cubic"){let K=Q[0],Z=Q[1],q=Q[2],re=Q[3],ne=Q[4],te=Q[5],ue=Q[6],me=Q[7];I(K,Z);for(let pe=1;pe<=L;pe++){let fe=pe/L,de=1-fe,ye=de*de,we=fe*fe;I(ye*de*K+3*ye*fe*q+3*de*we*ne+we*fe*ue,ye*de*Z+3*ye*fe*re+3*de*we*te+we*fe*me)}}else if(W.type==="arc"){let K=Q[0],Z=Q[1],q=Q[2],re=Q[3],ne=Q[4],te=Q[5],ue=Q[6]!==0,me=Q[7],pe=Math.PI*2,fe=te-ne,de=Math.abs(fe)<1e-9;for(;fe<0;)fe+=pe;for(;fe>pe;)fe-=pe;fe<1e-9&&(fe=de?0:pe),ue&&!de&&(fe=fe===pe?-pe:fe-pe);let ye=Math.cos(me),we=Math.sin(me),be=Math.max(2,L);for(let _e=0;_e<=be;_e++){let Te=_e/be,Ce=ne+Te*fe,Le=q*Math.cos(Ce),De=re*Math.sin(Ce);I(K+Le*ye-De*we,Z+Le*we+De*ye)}}}if(O.length>2){let W=O[0],Q=O[O.length-1];Math.hypot(W.x-Q.x,W.y-Q.y)<1e-6&&O.pop()}return O}getSpacedPoints(S=12){return this.getPoints(S)}clone(){let S=new this.constructor;return S.currentPoint.copy(this.currentPoint),S.segments=this.segments.map(L=>({type:L.type,pts:[...L.pts]})),Array.isArray(this.holes)&&(S.holes=this.holes.map(L=>L.clone())),S}}class d extends v{constructor(S){super(S),this.holes=[]}extractPoints(S=12){return{shape:this.getPoints(S),holes:this.holes.map(L=>L.getPoints(S))}}}function y(A){let S=0,L=A.length;for(let O=0,I=L-1;O<L;I=O++)S+=A[I].x*A[O].y-A[O].x*A[I].y;return S*.5}function M(A,S,L,O,I,W,Q,K){let Z=Q-L,q=K-O,re=I-L,ne=W-O,te=A-L,ue=S-O,me=Z*Z+q*q,pe=Z*re+q*ne,fe=Z*te+q*ue,de=re*re+ne*ne,ye=re*te+ne*ue,we=me*de-pe*pe;if(Math.abs(we)<1e-12)return!1;let be=1/we,_e=(de*fe-pe*ye)*be,Te=(me*ye-pe*fe)*be;return _e>=-1e-7&&Te>=-1e-7&&_e+Te<=1+1e-7}function T(A,S){let L=A.slice();y(L)<0&&L.reverse();let O=L.map(Z=>new r(Z.x,Z.y)),I=L.map((Z,q)=>q),W=[];for(let Z of S){if(!Z||Z.length<3)continue;let q=Z.slice();y(q)>0&&q.reverse();let re=[],ne=-1/0,te=0;for(let ue=0;ue<q.length;ue++){let me=q[ue],pe=O.length;O.push(new r(me.x,me.y)),re.push(pe),me.x>ne&&(ne=me.x,te=ue)}W.push({pts:q,indices:re,maxX:ne,maxIdx:te})}W.sort((Z,q)=>q.maxX-Z.maxX);let Q=(Z,q,re)=>(q.x-Z.x)*(re.y-Z.y)-(q.y-Z.y)*(re.x-Z.x),K=(Z,q,re)=>{for(let ne=0;ne<re.length;ne++){let te=re[ne],ue=re[(ne+1)%re.length];if(Q(Z,q,te)*Q(Z,q,ue)<0&&Q(te,ue,Z)*Q(te,ue,q)<0)return!0}return!1};for(let Z of W){let q=Z.pts[Z.maxIdx],re=q.x,ne=I.length,te=I.map(de=>O[de]),ue=de=>Math.hypot(te[de].x-re,te[de].y-q.y),me=te.map((de,ye)=>ye).sort((de,ye)=>+(te[de].x<re)-+(te[ye].x<re)||ue(de)-ue(ye)),pe=me[0];for(let de of me){let ye=te[de],we=te[(de+ne-1)%ne],be=te[(de+1)%ne],_e=Q(ye,be,q)>=0,Te=Q(we,ye,q)>=0;if((Q(we,ye,be)>=0?_e&&Te:_e||Te)&&!K(q,ye,te)&&!W.some(Ce=>K(q,ye,Ce.pts))){pe=de;break}}let fe=[];for(let de=0;de<=pe;de++)fe.push(I[de]);for(let de=0;de<=Z.indices.length;de++){let ye=Z.indices[(Z.maxIdx+de)%Z.indices.length];fe.push(ye)}for(let de=pe;de<I.length;de++)fe.push(I[de]);I=fe}return{merged:I.map(Z=>O[Z]),mergedIndices:I,allVertices:O}}function V(A,S){let L=[],O=A.slice();if(O.length<3)return L;let I=O.length*O.length+64,W=0;for(;O.length>2&&I-- >0;){let Q=O.length,K=O[(W+Q-1)%Q],Z=O[W%Q],q=O[(W+1)%Q],re=S[K],ne=S[Z],te=S[q];if((ne.x-re.x)*(te.y-re.y)-(ne.y-re.y)*(te.x-re.x)>1e-9){let ue=!0;for(let me=0;me<Q;me++){let pe=O[me];if(pe===K||pe===Z||pe===q)continue;let fe=S[pe];if(M(fe.x,fe.y,re.x,re.y,ne.x,ne.y,te.x,te.y)&&Math.hypot(fe.x-re.x,fe.y-re.y)>=1e-6&&Math.hypot(fe.x-ne.x,fe.y-ne.y)>=1e-6&&Math.hypot(fe.x-te.x,fe.y-te.y)>=1e-6){ue=!1;break}}if(ue){L.push([K,Z,q]),O.splice(W%Q,1),W=Math.max(0,W%Q-1);continue}}W++,W>=Q*2&&(L.push([K,Z,q]),O.splice((W-1)%Q,1),W=0)}return L}function X(A,S){let L=A instanceof d?A.extractPoints(S):{shape:A.getPoints(S),holes:[]},O=L.shape.length;for(let I of L.holes)O+=I.length;if(O>x)throw new RangeError(`SecurityError: shape point count (${O}) exceeds MAX_SHAPE_POINTS (${x})`);return L}class P extends u{constructor(S=new d,L=12){super();let O=Array.isArray(S)?S:[S],I=[],W=[],Q=[],K=[];for(let Z of O){if(!(Z instanceof v))continue;let q=X(Z,L);if(q.shape.length<3)continue;let{mergedIndices:re,allVertices:ne}=T(q.shape,q.holes),te=V(re,ne),ue=I.length/3,me=1/0,pe=1/0,fe=-1/0,de=-1/0;for(let be of ne)be.x<me&&(me=be.x),be.y<pe&&(pe=be.y),be.x>fe&&(fe=be.x),be.y>de&&(de=be.y);let ye=Math.max(1e-6,fe-me),we=Math.max(1e-6,de-pe);for(let be of ne)I.push(be.x,be.y,0),W.push(0,0,1),Q.push((be.x-me)/ye,(be.y-pe)/we);for(let[be,_e,Te]of te)K.push(ue+be,ue+_e,ue+Te)}R(this,I,W,Q,K)}}function R(A,S,L,O,I){return A.setAttribute("position",new a(S,3)),A.setAttribute("normal",new a(L,3)),A.setAttribute("uv",new a(O,2)),A.setIndex(I),A}function C(A){let S=A.length,L=[];for(let O=0;O<S;O++){let I=A[(O+S-1)%S],W=A[O],Q=A[(O+1)%S],K=W.x-I.x,Z=W.y-I.y,q=Math.hypot(K,Z)||1;K/=q,Z/=q;let re=Q.x-W.x,ne=Q.y-W.y,te=Math.hypot(re,ne)||1;re/=te,ne/=te;let ue=Z,me=-K,pe=ne,fe=-re,de=ue+pe,ye=me+fe,we=Math.hypot(de,ye);if(we>1e-6){de/=we,ye/=we;let be=Math.max(.35,de*ue+ye*me);L.push(new r(de/be,ye/be))}else L.push(new r(ue,me))}return L}class B extends u{constructor(S=new d,L={}){super();let O=Array.isArray(S)?S:[S],I=Math.max(1,Math.min(64,Math.floor(b(L.curveSegments,12)))),W=b(L.depth??L.amount,1),Q=Math.max(1,Math.min(32,Math.floor(b(L.steps,1)))),K=!!(L.bevelEnabled??!1),Z=K?Math.max(0,b(L.bevelThickness,.06)):0,q=K?Math.max(0,b(L.bevelSize,Z*.8)):0,re=K?b(L.bevelOffset,0):0,ne=K?Math.max(1,Math.min(8,Math.floor(b(L.bevelSegments,2)))):0,te=[],ue=[],me=[],pe=[];for(let fe of O){if(!(fe instanceof v))continue;let de=X(fe,I);if(de.shape.length<3)continue;let ye=de.shape.slice();y(ye)<0&&ye.reverse();let we=[];for(let xe of de.holes){if(xe.length<3)continue;let Re=xe.slice();y(Re)>0&&Re.reverse(),we.push(Re)}let{mergedIndices:be,allVertices:_e}=T(ye,we),Te=V(be,_e),Ce=[ye,...we],Le=[];for(let xe of Ce){let Re=C(xe);for(let Ie of Re)Le.push(Ie)}let De=1/0,We=1/0,$e=-1/0,at=-1/0;for(let xe of _e)xe.x<De&&(De=xe.x),xe.y<We&&(We=xe.y),xe.x>$e&&($e=xe.x),xe.y>at&&(at=xe.y);let Ke=Math.max(1e-6,$e-De),ct=Math.max(1e-6,at-We),qt=-Z,Kt=W+Z,St=te.length/3;for(let xe=0;xe<_e.length;xe++){let Re=_e[xe],Ie=Le[xe]??new r(0,0),Ve=Re.x+Ie.x*re,Be=Re.y+Ie.y*re;te.push(Ve,Be,qt),ue.push(0,0,-1),me.push((Ve-De)/Ke,(Be-We)/ct)}for(let[xe,Re,Ie]of Te)pe.push(St+xe,St+Ie,St+Re);let Rt=te.length/3;for(let xe=0;xe<_e.length;xe++){let Re=_e[xe],Ie=Le[xe]??new r(0,0),Ve=Re.x+Ie.x*re,Be=Re.y+Ie.y*re;te.push(Ve,Be,Kt),ue.push(0,0,1),me.push((Ve-De)/Ke,(Be-We)/ct)}for(let[xe,Re,Ie]of Te)pe.push(Rt+xe,Rt+Re,Rt+Ie);let Ye=[];if(K&&ne>0)for(let xe=0;xe<ne;xe++){let Re=xe/ne*Math.PI/2;Ye.push({z:-Z*Math.cos(Re),expand:re+q*Math.sin(Re)})}for(let xe=0;xe<=Q;xe++){let Re=xe/Q;Ye.push({z:Re*W,expand:re+q})}if(K&&ne>0)for(let xe=1;xe<=ne;xe++){let Re=xe/ne*Math.PI/2;Ye.push({z:W+Z*Math.sin(Re),expand:re+q*Math.cos(Re)})}let pt=0;for(let xe of Ce){let Re=xe.length;for(let Ie=0;Ie<Ye.length-1;Ie++){let Ve=Ye[Ie],Be=Ye[Ie+1];for(let et=0;et<Re;et++){let bt=(et+1)%Re,Ct=xe[et],Et=xe[bt],_t=Le[pt+et],Lt=Le[pt+bt],It=Ct.x+_t.x*Ve.expand,Ft=Ct.y+_t.y*Ve.expand,jt=Et.x+Lt.x*Ve.expand,wt=Et.y+Lt.y*Ve.expand,sl=Et.x+Lt.x*Be.expand,ol=Et.y+Lt.y*Be.expand,Yi=Ct.x+_t.x*Be.expand,so=Ct.y+_t.y*Be.expand,Po=jt-It,No=wt-Ft,Do=0,ko=Yi-It,Fo=so-Ft,Vo=Be.z-Ve.z,Yt=No*Vo-Do*Fo,Zt=Do*ko-Po*Vo,Qt=Po*Fo-No*ko,qi=Math.hypot(Yt,Zt,Qt)||1;Yt/=qi,Zt/=qi,Qt/=qi;let yi=te.length/3;te.push(It,Ft,Ve.z,jt,wt,Ve.z,sl,ol,Be.z,Yi,so,Be.z),ue.push(Yt,Zt,Qt,Yt,Zt,Qt,Yt,Zt,Qt,Yt,Zt,Qt);let Oo=et/Re,Uo=(et+1)/Re,Bo=Ie/(Ye.length-1),zo=(Ie+1)/(Ye.length-1);me.push(Oo,Bo,Uo,Bo,Uo,zo,Oo,zo),pe.push(yi,yi+1,yi+2,yi,yi+2,yi+3)}}pt+=Re}}R(this,te,ue,me,pe)}}function N(A){return{x:A.x,y:A.y,z:A.z,nx:A.nx,ny:A.ny,nz:A.nz,u:A.u,v:A.v}}function w(A){return{x:A.x,y:A.y,z:A.z,nx:-A.nx,ny:-A.ny,nz:-A.nz,u:A.u,v:A.v}}function ie(A,S,L){let O=A.nx+(S.nx-A.nx)*L,I=A.ny+(S.ny-A.ny)*L,W=A.nz+(S.nz-A.nz)*L,Q=Math.hypot(O,I,W)||1;return{x:A.x+(S.x-A.x)*L,y:A.y+(S.y-A.y)*L,z:A.z+(S.z-A.z)*L,nx:O/Q,ny:I/Q,nz:W/Q,u:A.u+(S.u-A.u)*L,v:A.v+(S.v-A.v)*L}}function ae(A){if(A.length<3)return null;let S=A[0],L=A[1],O=A[2],I=L.x-S.x,W=L.y-S.y,Q=L.z-S.z,K=O.x-S.x,Z=O.y-S.y,q=O.z-S.z,re=W*q-Q*Z,ne=Q*K-I*q,te=I*Z-W*K,ue=Math.hypot(re,ne,te);if(ue<1e-9)return null;re/=ue,ne/=ue,te/=ue;let me=re*S.x+ne*S.y+te*S.z;return{vertices:A,nx:re,ny:ne,nz:te,w:me}}function k(A){A.vertices.reverse();for(let S=0;S<A.vertices.length;S++)A.vertices[S]=w(A.vertices[S]);A.nx=-A.nx,A.ny=-A.ny,A.nz=-A.nz,A.w=-A.w}let J=1e-5,z=0,Y=1,le=2,ce=3;function $(A,S,L,O,I,W,Q,K,Z){let q=0,re=[];for(let ne=0;ne<I.vertices.length;ne++){let te=I.vertices[ne],ue=A*te.x+S*te.y+L*te.z-O,me=ue<-J?le:ue>J?Y:z;q|=me,re.push(me)}switch(q){case z:{A*I.nx+S*I.ny+L*I.nz>0?W.push(I):Q.push(I);break}case Y:K.push(I);break;case le:Z.push(I);break;case ce:{let ne=[],te=[],ue=I.vertices.length;for(let ye=0;ye<ue;ye++){let we=(ye+1)%ue,be=re[ye],_e=re[we],Te=I.vertices[ye],Ce=I.vertices[we];if(be!==le&&ne.push(Te),be!==Y&&te.push(be!==le?N(Te):Te),(be|_e)===ce){let Le=Ce.x-Te.x,De=Ce.y-Te.y,We=Ce.z-Te.z,$e=A*Le+S*De+L*We,at=Math.abs($e)>1e-12?(O-(A*Te.x+S*Te.y+L*Te.z))/$e:.5,Ke=ie(Te,Ce,Math.max(0,Math.min(1,at)));ne.push(Ke),te.push(N(Ke))}}let{nx:me,ny:pe,nz:fe,w:de}=I;ne.length>=3&&K.push({vertices:ne,nx:me,ny:pe,nz:fe,w:de}),te.length>=3&&Z.push({vertices:te,nx:me,ny:pe,nz:fe,w:de});break}default:break}}class U{constructor(S,L=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,S&&S.length>0&&this.build(S,L)}invert(){for(let L=0;L<this.polygons.length;L++)k(this.polygons[L]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let S=this.front;this.front=this.back,this.back=S}clipPolygons(S,L=0){if(!this.hasPlane||S.length===0)return S.slice();if(L>=m)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${m})`);let O=[],I=[];for(let W=0;W<S.length;W++)$(this.nx,this.ny,this.nz,this.w,S[W],O,I,O,I);return this.front&&O.length>0&&(O=this.front.clipPolygons(O,L+1)),this.back?I=I.length>0?this.back.clipPolygons(I,L+1):[]:I=[],O.concat(I)}clipTo(S,L=0){this.polygons.length>0&&(this.polygons=S.clipPolygons(this.polygons,0)),L<m&&(this.front&&this.front.clipTo(S,L+1),this.back&&this.back.clipTo(S,L+1))}allPolygons(S=[]){for(let L=0;L<this.polygons.length;L++)S.push(this.polygons[L]);return this.front&&this.front.allPolygons(S),this.back&&this.back.allPolygons(S),S}build(S,L=0){if(!S.length)return;if(!this.hasPlane){let W=S[S.length>>1];this.nx=W.nx,this.ny=W.ny,this.nz=W.nz,this.w=W.w,this.hasPlane=!0}if(L>=m)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${m})`);let O=[],I=[];for(let W=0;W<S.length;W++)$(this.nx,this.ny,this.nz,this.w,S[W],this.polygons,this.polygons,O,I);O.length>0&&(this.front||(this.front=new U),this.front.build(O,L+1)),I.length>0&&(this.back||(this.back=new U),this.back.build(I,L+1))}}function _(A,S){if(!S&&A._csgPolygons)return A._csgPolygons;let L=A.attributes.position;if(!L||L.count===0)return[];let O=A.attributes.normal,I=A.attributes.uv,W=A.index?A.index.array:null,Q=Math.floor(W?W.length/3:L.count/3);if(Q>p)throw new RangeError(`SecurityError: CSG input triangle count (${Q}) exceeds MAX_CSG_TRIANGLES (${p})`);let K=S?S.elements:null,Z=K?K[0]*(K[5]*K[10]-K[9]*K[6])-K[4]*(K[1]*K[10]-K[9]*K[2])+K[8]*(K[1]*K[6]-K[5]*K[2])<0:!1,q=K?new l().getNormalMatrix(S).elements:null,re=te=>{let ue=L.getX(te),me=L.getY(te),pe=L.getZ(te),fe=O?O.getX(te):NaN,de=O?O.getY(te):NaN,ye=O?O.getZ(te):NaN;if(K&&q){let _e=K[0]*ue+K[4]*me+K[8]*pe+K[12],Te=K[1]*ue+K[5]*me+K[9]*pe+K[13],Ce=K[2]*ue+K[6]*me+K[10]*pe+K[14];ue=_e,me=Te,pe=Ce;let Le=q[0]*fe+q[3]*de+q[6]*ye,De=q[1]*fe+q[4]*de+q[7]*ye,We=q[2]*fe+q[5]*de+q[8]*ye,$e=Math.hypot(Le,De,We)||1;fe=Le/$e,de=De/$e,ye=We/$e}let we=I?I.getX(te):0,be=I?I.getY(te):0;return{x:ue,y:me,z:pe,nx:fe,ny:de,nz:ye,u:we,v:be}},ne=[];for(let te=0;te<Q;te++){let ue=W?W[te*3]:te*3,me=W?W[te*3+1]:te*3+1,pe=W?W[te*3+2]:te*3+2,fe=ae(Z?[re(ue),re(pe),re(me)]:[re(ue),re(me),re(pe)]);fe&&ne.push(fe)}return ne}function H(A){let S=[],L=[],O=[],I=[];for(let Q of A){let K=Q.vertices;if(K.length<3)continue;let Z=S.length/3;for(let q of K)S.push(q.x,q.y,q.z),Number.isFinite(q.nx)&&q.nx*q.nx+q.ny*q.ny+q.nz*q.nz>.5?L.push(q.nx,q.ny,q.nz):L.push(Q.nx,Q.ny,Q.nz),O.push(q.u,q.v);for(let q=1;q<K.length-1;q++)I.push(Z,Z+q,Z+q+1)}let W=R(new u,S,L,O,I);return W._csgPolygons=A,W}function D(A,S,L){if(A.length+S.length>p)throw new RangeError(`SecurityError: Combined CSG triangle count (${A.length+S.length}) exceeds MAX_CSG_TRIANGLES (${p})`);if(A.length===0)return L==="union"?S:[];if(S.length===0)return L==="intersect"?[]:A;let O=1/0,I=1/0,W=1/0,Q=-1/0,K=-1/0,Z=-1/0;for(let ue=0;ue<S.length;ue++){let me=S[ue].vertices;for(let pe=0;pe<me.length;pe++){let fe=me[pe];fe.x<O&&(O=fe.x),fe.y<I&&(I=fe.y),fe.z<W&&(W=fe.z),fe.x>Q&&(Q=fe.x),fe.y>K&&(K=fe.y),fe.z>Z&&(Z=fe.z)}}O-=1e-4,I-=1e-4,W-=1e-4,Q+=1e-4,K+=1e-4,Z+=1e-4;let q=[],re=[];for(let ue=0;ue<A.length;ue++){let me=A[ue],pe=me.vertices,fe=1/0,de=1/0,ye=1/0,we=-1/0,be=-1/0,_e=-1/0;for(let Te=0;Te<pe.length;Te++){let Ce=pe[Te];Ce.x<fe&&(fe=Ce.x),Ce.y<de&&(de=Ce.y),Ce.z<ye&&(ye=Ce.z),Ce.x>we&&(we=Ce.x),Ce.y>be&&(be=Ce.y),Ce.z>_e&&(_e=Ce.z)}we<O||fe>Q||be<I||de>K||_e<W||ye>Z?re.push(me):q.push(me)}if(q.length===0)return L==="union"?A.concat(S):L==="subtract"?A:[];let ne=new U(q),te=new U(S);return L==="union"?(ne.clipTo(te),te.clipTo(ne),te.invert(),te.clipTo(ne),te.invert(),ne.build(te.allPolygons()),re.concat(ne.allPolygons())):L==="subtract"?(ne.invert(),ne.clipTo(te),te.clipTo(ne),te.invert(),te.clipTo(ne),te.invert(),ne.build(te.allPolygons()),ne.invert(),re.concat(ne.allPolygons())):(ne.invert(),te.clipTo(ne),te.invert(),ne.clipTo(te),te.clipTo(ne),ne.build(te.allPolygons()),ne.invert(),ne.allPolygons())}function F(A,S,L,O=null,I=null){let W=_(A,O),Q=_(S,I);return H(D(W,Q,L))}function E(A,S,L){let O=A instanceof f||!!A?.isMesh,I=S instanceof f||!!S?.isMesh,W=O?A.geometry:A,Q=I?S.geometry:S,K=null;if(I)if(S.updateMatrix(),O){A.updateMatrix();let ne=new s().makeScale(1/(A.scale.x||1),1/(A.scale.y||1),1/(A.scale.z||1)),te=Math.hypot(A.quaternion.x,A.quaternion.y,A.quaternion.z,A.quaternion.w)||1,ue=new s().compose(new i(0,0,0),new n(-A.quaternion.x/te,-A.quaternion.y/te,-A.quaternion.z/te,A.quaternion.w/te),new i(1,1,1)),me=new s().makeTranslation(-A.position.x,-A.position.y,-A.position.z);K=ne.multiply(ue).multiply(me).multiply(S.matrix)}else K=S.matrix;let Z=F(W,Q,L,null,K),q=O?A.material:new c,re=new f(Z,q);return O&&(re.position.copy(A.position),re.quaternion.copy(A.quaternion),re.scale.copy(A.scale),re.name=A.name),re}let G={toGeometry:F,subtract(A,S){return E(A,S,"subtract")},union(A,S){return E(A,S,"union")},intersect(A,S){return E(A,S,"intersect")}},ee={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 se extends u{constructor(S="",L={}){super();let O=String(S??"").slice(0,g),I=Math.max(.005,Math.min(100,b(L.size,.2))),W=!!(L.bevelEnabled??!1),Q=W?Math.max(0,Math.min(2,b(L.bevelThickness,I*.04))):0,K=W?Math.max(0,Math.min(2,b(L.bevelSize,I*.03))):0,Z=Math.max(.001,Math.min(20,b(L.depth??L.height,I*.2)))+Q*2,q=I*.085+K,re=I*.68,ne=I*.82,te=[],ue=[],me=[],pe=[],fe=(we,be,_e,Te,Ce,Le,De)=>{let We=_e-we,$e=Te-be,at=Math.hypot(We,$e),Ke=1,ct=0;at>1e-6&&(Ke=We/at,ct=$e/at);let qt=-ct*Ce,Kt=Ke*Ce,St=Ke*Ce*.6,Rt=ct*Ce*.6,Ye=we-St+qt,pt=be-Rt+Kt,xe=we-St-qt,Re=be-Rt-Kt,Ie=_e+St-qt,Ve=Te+Rt-Kt,Be=_e+St+qt,et=Te+Rt+Kt,bt=(Ct,Et,_t,Lt,It,Ft,jt)=>{let wt=te.length/3;te.push(Ct[0],Ct[1],Ct[2],Et[0],Et[1],Et[2],_t[0],_t[1],_t[2],Lt[0],Lt[1],Lt[2]),ue.push(It,Ft,jt,It,Ft,jt,It,Ft,jt,It,Ft,jt),me.push(0,0,1,0,1,1,0,1),pe.push(wt,wt+1,wt+2,wt,wt+2,wt+3)};bt([Ye,pt,De],[xe,Re,De],[Ie,Ve,De],[Be,et,De],0,0,1),bt([xe,Re,Le],[Ye,pt,Le],[Be,et,Le],[Ie,Ve,Le],0,0,-1),bt([Ye,pt,Le],[xe,Re,Le],[xe,Re,De],[Ye,pt,De],-Ke,-ct,0),bt([Ie,Ve,Le],[Be,et,Le],[Be,et,De],[Ie,Ve,De],Ke,ct,0),bt([xe,Re,Le],[Ie,Ve,Le],[Ie,Ve,De],[xe,Re,De],ct,-Ke,0),bt([Be,et,Le],[Ye,pt,Le],[Ye,pt,De],[Be,et,De],-ct,Ke,0)},de=0,ye=0;for(let we=0;we<O.length;we++){let be=O[we];if(be===`
17
- `){de=0,ye-=I*1.35;continue}if(be===" "||be===" "){de+=ne*(be===" "?.75:3);continue}if(be==="\r")continue;let _e=be.toUpperCase(),Te=be!==_e&&be>="a"&&be<="z",Ce=ee[_e]??ee["?"],Le=Te?I*.76:I,De=Te?re*.88:re;for(let We of Ce)for(let $e=0;$e<We.length-1;$e++){let at=We[$e],Ke=We[$e+1];fe(de+at[0]*De,ye+at[1]*Le,de+Ke[0]*De,ye+Ke[1]*Le,q,-Z*.5,Z*.5)}de+=Te?ne*.88:ne}R(this,te,ue,me,pe),L.center!==!1?this.center():this.computeBoundingBox()}}function oe(A){if(!A)return;let S=A,L=A.userData?.xr?.text??A.userData?.xr?.label??A.userData?.xr?.title??A.userData?.xr?.caption??A.userData?.xr?.spatialLabel;if(L!=null&&L!==!1){let I=S.geometry?.attributes?.position;if((!I||I.count===0)&&A.userData._textApplied!==!0){let W="",Q=.08,K=.015,Z;if(typeof L=="string"||typeof L=="number")W=String(L);else if(typeof L=="object"){let q=L;W=String(q.text??q.value??""),q.size!==void 0&&(Q=Number(q.size)||.08),(q.depth!==void 0||q.height!==void 0)&&(K=Number(q.depth??q.height)||Q*.2),(typeof q.color=="string"||typeof q.color=="number")&&(Z=q.color)}W.trim().length>0&&(S.geometry=new se(W,{size:Q,depth:K}),A.userData._textApplied=!0,S.material instanceof h?Z!==void 0&&A.userData._autoTextColorApplied!==!0&&(S.material.color=new o(Z),A.userData._autoTextColorApplied=!0):S.material=new c({color:Z??16317180}))}}let O=A.userData?.csg;if(O&&typeof O=="object"&&A.userData._csgApplied!==!0&&S.geometry instanceof u&&S.geometry.attributes.position?.count>0){A.userData._csgApplied=!0;let I=Array.isArray(O)?O:[O],W=S.geometry;for(let Q of I){if(!Q||typeof Q!="object")continue;let K=Q,Z=String(K.op??K.operation??"subtract"),q=Z==="union"||Z==="intersect"?Z:"subtract",re=K.target??K.mesh??K.geometry;if(re instanceof f||re instanceof u)try{let ne=q==="union"?G.union(S,re):q==="intersect"?G.intersect(S,re):G.subtract(S,re);S.geometry!==W&&S.geometry.dispose?.(),S.geometry=ne.geometry}catch(ne){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ne)}}}}let j={Path:v,Shape:d,ShapeGeometry:P,ExtrudeGeometry:B,TextGeometry:se,CSG:G,MAX_CSG_TRIANGLES:p,MAX_BSP_DEPTH:m,MAX_TEXT_GEOMETRY_CHARS:g,MAX_SHAPE_POINTS:x,materializeDeclarativeGeometry:oe};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,j),t._cadMaterialize=oe,t.materializeDeclarativeGeometry=A=>{t._cadMaterialize?.(A),t._lodMaterialize?.(A)}),j}var xi={name:"cad",onRegister(){Jt(tr);let e=Me(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);t&&tr(t,e)}};function Se(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function nr(e,t,r,i,n){let s=1/Math.tan(t/2);e.fill(0),e[0]=s/r,e[5]=s,e[11]=-1;let l=1/(i-n);return e[10]=(n+i)*l,e[14]=2*n*i*l,e}function en(e,t,r,i){let[n,s,l]=t,[o,a,u]=i,[h,c,f]=r,p=n-h,m=s-c,g=l-f,x=Math.hypot(p,m,g);x<=1e-5?(p=0,m=0,g=1):(p/=x,m/=x,g/=x);let b=a*g-u*m,v=u*p-o*g,d=o*m-a*p;x=Math.hypot(b,v,d),x<=1e-5?(b=0,v=0,d=0):(b/=x,v/=x,d/=x);let y=m*d-g*v,M=g*b-p*d,T=p*v-m*b;return x=Math.hypot(y,M,T),x<=1e-5?(y=0,M=0,T=0):(y/=x,M/=x,T/=x),e[0]=b,e[1]=y,e[2]=p,e[3]=0,e[4]=v,e[5]=M,e[6]=m,e[7]=0,e[8]=d,e[9]=T,e[10]=g,e[11]=0,e[12]=-(b*n+v*s+d*l),e[13]=-(y*n+M*s+T*l),e[14]=-(p*n+m*s+g*l),e[15]=1,e}function Pe(e,t,r){let i=t[0],n=t[1],s=t[2],l=t[3],o=t[4],a=t[5],u=t[6],h=t[7],c=t[8],f=t[9],p=t[10],m=t[11],g=t[12],x=t[13],b=t[14],v=t[15],d=r[0],y=r[1],M=r[2],T=r[3];return e[0]=d*i+y*o+M*c+T*g,e[1]=d*n+y*a+M*f+T*x,e[2]=d*s+y*u+M*p+T*b,e[3]=d*l+y*h+M*m+T*v,d=r[4],y=r[5],M=r[6],T=r[7],e[4]=d*i+y*o+M*c+T*g,e[5]=d*n+y*a+M*f+T*x,e[6]=d*s+y*u+M*p+T*b,e[7]=d*l+y*h+M*m+T*v,d=r[8],y=r[9],M=r[10],T=r[11],e[8]=d*i+y*o+M*c+T*g,e[9]=d*n+y*a+M*f+T*x,e[10]=d*s+y*u+M*p+T*b,e[11]=d*l+y*h+M*m+T*v,d=r[12],y=r[13],M=r[14],T=r[15],e[12]=d*i+y*o+M*c+T*g,e[13]=d*n+y*a+M*f+T*x,e[14]=d*s+y*u+M*p+T*b,e[15]=d*l+y*h+M*m+T*v,e}function yt(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=n+n,u=s+s,h=l+l,c=n*a,f=n*u,p=n*h,m=s*u,g=s*h,x=l*h,b=o*a,v=o*u,d=o*h,y=i[0],M=i[1],T=i[2];return e[0]=(1-(m+x))*y,e[1]=(f+d)*y,e[2]=(p-v)*y,e[3]=0,e[4]=(f-d)*M,e[5]=(1-(c+x))*M,e[6]=(g+b)*M,e[7]=0,e[8]=(p+v)*T,e[9]=(g-b)*T,e[10]=(1-(c+m))*T,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function ze(e,t,r=0){let i=t[0],n=t[1],s=t[2],l=t[4],o=t[5],a=t[6],u=t[8],h=t[9],c=t[10],f=c*o-a*h,p=-c*l+a*u,m=h*l-o*u,g=i*f+n*p+s*m;return!g||r>0&&(!Number.isFinite(g)||Math.abs(g)<=r)||(g=1/g,e[0]=f*g,e[1]=p*g,e[2]=m*g,e[3]=(-c*n+s*h)*g,e[4]=(c*i-s*u)*g,e[5]=(-h*i+n*u)*g,e[6]=(a*n-s*o)*g,e[7]=(-a*i+s*l)*g,e[8]=(o*i-n*l)*g),e}function tn(e,t){let r=t[0],i=t[1],n=t[2],s=t[3],l=t[4],o=t[5],a=t[6],u=t[7],h=t[8],c=t[9],f=t[10],p=t[11],m=t[12],g=t[13],x=t[14],b=t[15],v=r*o-i*l,d=r*a-n*l,y=r*u-s*l,M=i*a-n*o,T=i*u-s*o,V=n*u-s*a,X=h*g-c*m,P=h*x-f*m,R=h*b-p*m,C=c*x-f*g,B=c*b-p*g,N=f*b-p*x,w=v*N-d*B+y*C+M*R-T*P+V*X;return w?(w=1/w,e[0]=(o*N-a*B+u*C)*w,e[1]=(n*B-i*N-s*C)*w,e[2]=(g*V-x*T+b*M)*w,e[3]=(f*T-c*V-p*M)*w,e[4]=(a*R-l*N-u*P)*w,e[5]=(r*N-n*R+s*P)*w,e[6]=(x*y-m*V-b*d)*w,e[7]=(h*V-f*y+p*d)*w,e[8]=(l*B-o*R+u*X)*w,e[9]=(i*R-r*B-s*X)*w,e[10]=(m*T-g*y+b*v)*w,e[11]=(c*y-h*T-p*v)*w,e[12]=(o*P-l*C-a*X)*w,e[13]=(r*C-i*P+n*X)*w,e[14]=(g*d-m*M-x*v)*w,e[15]=(h*M-c*d+f*v)*w,e):null}function vi(e,t,r,i,n){let s=n[0]*t+n[4]*r+n[8]*i+n[12],l=n[1]*t+n[5]*r+n[9]*i+n[13],o=n[2]*t+n[6]*r+n[10]*i+n[14],a=n[3]*t+n[7]*r+n[11]*i+n[15],u=a!==0?1/a:1;e[0]=s*u,e[1]=l*u,e[2]=o*u}function qo(e,t,r,i,n,s,l,o,a,u,h,c,f,p,m,g,x=0){let b=u-l,v=h-o,d=c-a,y=f-l,M=p-o,T=m-a,V=n*T-s*M,X=s*y-i*T,P=i*M-n*y,R=b*V+v*X+d*P;if(R>-1e-7&&R<1e-7)return!1;let C=1/R,B=e-l,N=t-o,w=r-a,ie=C*(B*V+N*X+w*P);if(ie<-x||ie>1+x)return!1;let ae=N*d-w*v,k=w*b-B*d,J=B*v-N*b,z=C*(i*ae+n*k+s*J);if(z<-x||ie+z>1+x)return!1;let Y=C*(y*ae+M*k+T*J);if(Y>1e-4&&Y<g.distance){g.distance=Y,g.point=[e+i*Y,t+n*Y,r+s*Y];let le=v*T-d*M,ce=d*y-b*T,$=b*M-v*y,U=Math.hypot(le,ce,$)||1;return g.normal=[le/U,ce/U,$/U],!0}return!1}function Vt(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let h=0;h<r;h++)i.push(Se());if(r===0)return i;let n=new Set;for(let h of e.nodes)if(Array.isArray(h.children))for(let c of h.children)n.add(c);let s=new Set,l=128,o=(h,c,f=0)=>{if(f>l||h<0||h>=r||s.has(h))return;s.add(h);let p=e.nodes[h];if(!p)return;let m=Se();if(t&&t[h])m.set(t[h]);else if(p.matrix&&p.matrix.length===16)m.set(p.matrix);else{let x=p.translation||[0,0,0],b=p.rotation||[0,0,0,1],v=p.scale||[1,1,1];yt(m,b,x,v)}let g=i[h];if(c?Pe(g,c,m):g.set(m),Array.isArray(p.children))for(let x of p.children)typeof x=="number"&&o(x,g,f+1)},a=[],u=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let h=0;h<r;h++)n.has(h)||a.push(h);for(let h of a)o(h,null);for(let h=0;h<r;h++)!n.has(h)&&!a.includes(h)&&o(h,null);return i}function Ai(e,t){function r(a,u,h,c){let f=typeof a=="number"?a:Number(a);return Number.isFinite(f)?Math.max(u,Math.min(h,f)):c}function i(a,u){let h=a[0]*u[0]+a[1]*u[1]+a[2]*u[2]+1;if(h<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let x=Math.hypot(a[1],a[0])||1;return[-a[1]/x,a[0]/x,0,0]}let g=Math.hypot(a[2],a[1])||1;return[0,-a[2]/g,a[1]/g,0]}let c=a[1]*u[2]-a[2]*u[1],f=a[2]*u[0]-a[0]*u[2],p=a[0]*u[1]-a[1]*u[0],m=Math.hypot(c,f,p,h)||1;return[c/m,f/m,p/m,h/m]}function n(a,u,h,c,f){let p=u[0]-a[0],m=u[1]-a[1],g=u[2]-a[2],x=Math.hypot(p,m,g),b=h[0]-u[0],v=h[1]-u[1],d=h[2]-u[2],y=Math.hypot(b,v,d);if(x<1e-6||y<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[u[0],u[1],u[2]],effectorPos:[h[0],h[1],h[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let M=[p/x,m/x,g/x],T=[b/y,v/y,d/y],V=c[0]-a[0],X=c[1]-a[1],P=c[2]-a[2],R=Math.hypot(V,X,P),C=R>1e-6?[V/R,X/R,P/R]:M,B=Math.abs(x-y)+1e-5,N=Math.max(B,x+y-1e-5),w=Math.max(B,Math.min(N,R>1e-6?R:B)),ie=r((x*x+w*w-y*y)/(2*x*w),-1,1,1),ae=Math.sqrt(Math.max(0,1-ie*ie)),k=f?f[0]-a[0]:p,J=f?f[1]-a[1]:m,z=f?f[2]-a[2]:g,Y=k*C[0]+J*C[1]+z*C[2],le=k-C[0]*Y,ce=J-C[1]*Y,$=z-C[2]*Y,U=Math.hypot(le,ce,$);if(U<=1e-6){let A=Math.abs(C[1])<.99?0:1,S=Math.abs(C[1])<.99?1:0,L=0;le=C[1]*L-C[2]*S,ce=C[2]*A-C[0]*L,$=C[0]*S-C[1]*A,U=Math.hypot(le,ce,$)||1}let _=[le/U,ce/U,$/U],H=[a[0]+C[0]*(x*ie)+_[0]*(x*ae),a[1]+C[1]*(x*ie)+_[1]*(x*ae),a[2]+C[2]*(x*ie)+_[2]*(x*ae)],D=[a[0]+C[0]*w,a[1]+C[1]*w,a[2]+C[2]*w],F=D[0]-H[0],E=D[1]-H[1],G=D[2]-H[2],ee=Math.hypot(F,E,G),se=ee>1e-6?[F/ee,E/ee,G/ee]:C,oe=[H[0]+se[0]*y,H[1]+se[1]*y,H[2]+se[2]*y],j=[(H[0]-a[0])/x,(H[1]-a[1])/x,(H[2]-a[2])/x];return{rootPos:[a[0],a[1],a[2]],midPos:H,effectorPos:oe,rootRotation:i(M,j),midRotation:i(T,se)}}function s(a,u,h=8,c=.001){let f=a.length;if(f<2)return{positions:a.map(R=>[R[0],R[1],R[2]]),rotations:[],iterations:0};let p=a.map(R=>[R[0],R[1],R[2]]),m=[],g=[],x=0;for(let R=0;R<f-1;R++){let C=p[R+1][0]-p[R][0],B=p[R+1][1]-p[R][1],N=p[R+1][2]-p[R][2],w=Math.hypot(C,B,N);m.push(w),x+=w,g.push(w>1e-6?[C/w,B/w,N/w]:[0,1,0])}let b=[p[0][0],p[0][1],p[0][2]],v=Math.round(r(h,1,32,8)),d=r(c,1e-5,.1,.001),y=u[0]-b[0],M=u[1]-b[1],T=u[2]-b[2],V=Math.hypot(y,M,T),X=0;if(V>=x&&x>1e-6){let R=V>1e-6?[y/V,M/V,T/V]:g[0];p[0]=[b[0],b[1],b[2]];for(let C=0;C<f-1;C++){let B=m[C];p[C+1]=[p[C][0]+R[0]*B,p[C][1]+R[1]*B,p[C][2]+R[2]*B]}X=1}else for(let R=1;R<=v;R++){let C=p[f-1];if(Math.hypot(C[0]-u[0],C[1]-u[1],C[2]-u[2])<=d)break;X=R;let B=(N,w,ie,ae,k)=>{let J=w[0]-N[0],z=w[1]-N[1],Y=w[2]-N[2],le=Math.hypot(J,z,Y);if(le>1e-6){let ce=ie/le;return[N[0]+J*ce,N[1]+z*ce,N[2]+Y*ce]}return[N[0]+ae[0]*ie*k,N[1]+ae[1]*ie*k,N[2]+ae[2]*ie*k]};p[f-1]=[u[0],u[1],u[2]];for(let N=f-2;N>=0;N--)p[N]=B(p[N+1],p[N],m[N],g[N],-1);p[0]=[b[0],b[1],b[2]];for(let N=0;N<f-1;N++)p[N+1]=B(p[N],p[N+1],m[N],g[N],1)}let P=[];for(let R=0;R<f-1;R++){let C=p[R+1][0]-p[R][0],B=p[R+1][1]-p[R][1],N=p[R+1][2]-p[R][2],w=Math.hypot(C,B,N),ie=w>1e-6?[C/w,B/w,N/w]:g[R];P.push(i(g[R],ie))}return{positions:p,rotations:P,iterations:X}}function l(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let u=a;if(u.enabled===!1)return null;let h=d=>{if(typeof d!="string")return;let y=d.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(y)?y:void 0},c=d=>Array.isArray(d)&&d.length===3&&d.every(y=>typeof y=="number"&&Number.isFinite(y))?[r(d[0],-1e3,1e3,0),r(d[1],-1e3,1e3,0),r(d[2],-1e3,1e3,0)]:void 0,f=h(u.root),p=h(u.effector);if(!f||!p)return null;let m=h(u.mid),g=c(u.target)??h(u.target);if(!g)return null;let x=u.pole??u.poleTarget,b=c(x)??h(x),v=u.solver==="fabrik"?"fabrik":u.solver==="two-bone"||m?"two-bone":"fabrik";return{root:f,...m?{mid:m}:{},effector:p,target:g,...b?{pole:b}:{},solver:v,iterations:Math.round(r(u.iterations,1,32,8)),tolerance:r(u.tolerance,1e-5,.1,.001),weight:r(u.weight,0,1,1)}}let o=Object.freeze({solveTwoBone:n,solveFABRIK:s,parseIKTrait:l});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=o),{clampNum:r,parseIKTrait:l,quatFromUnitVectors:i,solveTwoBoneIK:n,solveFABRIK:s,IKSolver:o}}var nn=Ai(),Zo=nn.clampNum,Wa=nn.parseIKTrait,ir=nn.quatFromUnitVectors,Ei=nn.solveTwoBoneIK,Ri=nn.solveFABRIK,Qo=nn.IKSolver;function wi(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function ja(e,t){let r=e?.transform??e?.modelMatrix;!r||r.length<16||(r[12]=t[0],r[13]=t[1],r[14]=t[2])}function Ka(e,t,r,i,n){let s=Zo(n,0,1,1),l=t[0]+(r[0]-t[0])*s,o=t[1]+(r[1]-t[1])*s,a=t[2]+(r[2]-t[2])*s,u=l-e[0],h=o-e[1],c=a-e[2],f=Math.hypot(u,h,c);if(f>1e-6&&i>1e-6){let b=i/f;return[e[0]+u*b,e[1]+h*b,e[2]+c*b]}let p=r[0]-e[0],m=r[1]-e[1],g=r[2]-e[2],x=Math.hypot(p,m,g);if(x>1e-6&&i>1e-6){let b=i/x;return[e[0]+p*b,e[1]+m*b,e[2]+g*b]}return[l,o,a]}function qa(e,t){let r=e?.modelRootMatrix;if(!r||r.length!==16)return t;let i=new Float32Array(16);return tn(i,r instanceof Float32Array?r:Float32Array.from(r))?[i[0]*t[0]+i[4]*t[1]+i[8]*t[2]+i[12],i[1]*t[0]+i[5]*t[1]+i[9]*t[2]+i[13],i[2]*t[0]+i[6]*t[1]+i[10]*t[2]+i[14]]:t}function Mi(e,t){e.__ikWarned||(e.__ikWarned=new Set);let r=e.__ikWarned;r.has(t)||(r.add(t),console.warn(`[three-live] ik: joint '${t}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function Si(e,t,r){if(Array.isArray(e))return[e[0],e[1],e[2]];let i=t.get(e);if(i)return wi(i);let n;if(e==="head"?n=r?.headPose?.position??r?.headPose??r?.cameraPosition:e==="hand-left"?n=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:e==="hand-right"&&(n=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(n)||ArrayBuffer.isView(n))&&n.length>=3){let s=n;return qa(r,[s[0],s[1],s[2]])}return null}function Ti(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function Ya(e){return[-e[0],-e[1],-e[2],e[3]]}function _i(e){let t=Math.hypot(e[0],e[1],e[2],e[3]);return t>1e-12?[e[0]/t,e[1]/t,e[2]/t,e[3]/t]:[0,0,0,1]}function Za(e,t){if(t>=1)return e;if(t<=0)return[0,0,0,1];let[r,i,n,s]=e;s<0&&(r=-r,i=-i,n=-n,s=-s);let l=Math.acos(Math.min(1,s)),o=Math.sin(l);if(o<1e-9)return[0,0,0,1];let a=Math.sin(l*t)/o;return _i([r*a,i*a,n*a,Math.cos(l*t)])}function Qa(e){let t=Math.hypot(e[0],e[1],e[2])||1,r=Math.hypot(e[4],e[5],e[6])||1,i=Math.hypot(e[8],e[9],e[10])||1,n=e[0]/t,s=e[1]/t,l=e[2]/t,o=e[4]/r,a=e[5]/r,u=e[6]/r,h=e[8]/i,c=e[9]/i,f=e[10]/i,p=n+a+f,m;if(p>0){let g=Math.sqrt(p+1)*2;m=[(u-c)/g,(h-l)/g,(s-o)/g,.25*g]}else if(n>a&&n>f){let g=Math.sqrt(1+n-a-f)*2;m=[.25*g,(o+s)/g,(h+l)/g,(u-c)/g]}else if(a>f){let g=Math.sqrt(1+a-n-f)*2;m=[(o+s)/g,.25*g,(c+u)/g,(h-l)/g]}else{let g=Math.sqrt(1+f-n-a)*2;m=[(h+l)/g,(c+u)/g,.25*g,(s-o)/g]}return _i(m)}function Ja(e,t,r){let[i,n,s,l]=r,o=1-2*(n*n+s*s),a=2*(i*n-s*l),u=2*(i*s+n*l),h=2*(i*n+s*l),c=1-2*(i*i+s*s),f=2*(n*s-i*l),p=2*(i*s-n*l),m=2*(n*s+i*l),g=1-2*(i*i+n*n);for(let x=0;x<3;x++){let b=t[x*4],v=t[x*4+1],d=t[x*4+2];e[x*4]=o*b+a*v+u*d,e[x*4+1]=h*b+c*v+f*d,e[x*4+2]=p*b+m*v+g*d}}function rr(e,t){let r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],s=Math.hypot(r,i,n);return s>1e-9?[r/s,i/s,n/s]:null}function Jo(e){e?.normalMatrix&&e?.transform&&ze(e.normalMatrix,e.transform)}var Yo=new WeakMap;function ec(e){let t=Yo.get(e);return t||(t=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((r,i)=>{for(let n of Array.isArray(r?.children)?r.children:[])typeof n=="number"&&n>=0&&n<t.length&&(t[n]=i)}),Yo.set(e,t)),t}function tc(e,t,r){let i=e?.gltf,n=i?.nodes;if(!Array.isArray(n)||n.length===0)return!1;let s=new Map;n.forEach((P,R)=>{typeof P?.name=="string"&&P.name&&!s.has(P.name)&&s.set(P.name,R)});let l=(t.mid?[t.root,t.mid,t.effector]:[t.root,t.effector]).map(P=>s.get(P));if(l.some(P=>P===void 0))return!1;let o=l,a=ec(i);for(let P=1;P<o.length;P++){let R=a[o[P]],C=0;for(;R>=0&&R!==o[P-1]&&C++<256;)R=a[R];if(R!==o[P-1])return!1}let u=o[0],h=e.initialNodeTransforms,c=new Map,f=[],p=[u];for(;p.length&&f.length<4096;){let P=p.pop();if(c.has(P))continue;let R=h?.[P],C=n[P];c.set(P,{t:R?[R.t[0],R.t[1],R.t[2]]:C?.translation?[...C.translation]:[0,0,0],r:R?[R.r[0],R.r[1],R.r[2],R.r[3]]:C?.rotation?[...C.rotation]:[0,0,0,1],s:R?[R.s[0],R.s[1],R.s[2]]:C?.scale?[...C.scale]:[1,1,1]}),f.push(P);for(let B of Array.isArray(C?.children)?C.children:[])typeof B=="number"&&p.push(B)}let m=a[u],g=m>=0&&e.worldMatrices?.[m]?.length===16?Float32Array.from(e.worldMatrices[m]):Se(),x=new Map,b=()=>{let P=(R,C)=>{let B=c.get(R);if(!B)return;let N=Se();yt(N,B.r,B.t,B.s);let w=Se();Pe(w,C,N),x.set(R,w);for(let ie of Array.isArray(n[R]?.children)?n[R].children:[])typeof ie=="number"&&P(ie,w)};P(u,g)},v=P=>{let R=x.get(P);return[R[12],R[13],R[14]]};b();let d=o.map(v),y=P=>{if(typeof P=="string"&&!r.has(P)){let R=s.get(P),C=R!==void 0?x.get(R)??e.worldMatrices?.[R]:void 0;if(C&&C.length===16)return[C[12],C[13],C[14]]}return Si(P,r,e)},M=y(t.target);if(!M)return!0;let T=t.pole?y(t.pole)??void 0:void 0,V=es(d,t,M,T),X=Zo(t.weight,0,1,1);for(let P=0;P<o.length-1;P++){let R=rr(v(o[P]),v(o[P+1])),C=rr(V[P],V[P+1]);if(!R||!C)continue;let B=Za(ir(R,C),X),N=o[P],w=a[N],ie=w===m||w<0?g:x.get(w)??g,ae=Qa(ie),k=c.get(N);k.r=_i(Ti(Ya(ae),Ti(B,Ti(ae,k.r)))),b()}if(Array.isArray(e.worldMatrices))for(let[P,R]of x)e.worldMatrices[P]?.set&&e.worldMatrices[P].set(R);for(let P of e.meshes??[]){let R=x.get(P?.nodeIndex);R&&P.transform?.set&&(P.transform.set(R),Jo(P))}return!0}function es(e,t,r,i){if(t.solver==="two-bone"&&e.length===3){let n=Ei(e[0],e[1],e[2],r,i);return[e[0],n.midPos,n.effectorPos]}return Ri(e,r,t.iterations,t.tolerance).positions}function nc(e,t,r){let i=e.__ikRestOffsets,n=e.__ikRestMats;if(!(!i||!n))for(let s=0;s<t.length-1;s++){let l=t[s]?.transform??t[s]?.modelMatrix,o=n[s],a=rr([0,0,0],i[s]),u=rr(r[s],r[s+1]);!l||l.length<16||!o||o.length<16||!a||!u||(Ja(l,o,ir(a,u)),Jo(t[s]))}}var Li={name:"ik",onRegister(){let e=Me();Jt(Ai),Ai(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let r=null;for(let i of t){let n=i?.userData?.xr?.ik??i?.extras?.xr?.ik??i?.extensions?.ANDROID_xr_scenecore?.ik;if(!n)continue;let s=Wa(n);if(!s||s.weight<=0)continue;if(!r){r=new Map;for(let d of t)d&&typeof d.name=="string"&&d.name&&r.set(d.name,d)}if(tc(e,s,r))continue;let l=r.get(s.root),o=r.get(s.effector),a=s.mid?r.get(s.mid):void 0;if(l||Mi(i,s.root),o||Mi(i,s.effector),s.mid&&!a&&Mi(i,s.mid),!l||!o)continue;let u=Si(s.target,r,e);if(!u)continue;let h=s.pole?Si(s.pole,r,e)??void 0:void 0,c=a?[l,a,o]:[l,o],f=c.map(d=>d.name||"").join(">");if(!i.__ikRestOffsets||i.__ikRestKey!==f){let d=c.map(wi),y=[];for(let M=0;M<d.length-1;M++)y.push([d[M+1][0]-d[M][0],d[M+1][1]-d[M][1],d[M+1][2]-d[M][2]]);i.__ikRestOffsets=y,i.__ikRestKey=f,i.__ikRestMats=c.map(M=>Array.from(M.transform??M.modelMatrix??[]))}let p=i.__ikRestOffsets,m=[wi(l)],g=[];for(let d=0;d<p.length;d++){let y=m[d],M=p[d];m.push([y[0]+M[0],y[1]+M[1],y[2]+M[2]]),g.push(Math.hypot(M[0],M[1],M[2]))}let x=es(m,s,u,h),b=m[0],v=[m[0]];for(let d=1;d<c.length;d++){let y=p[d-1],M=[b[0]+y[0],b[1]+y[1],b[2]+y[2]],T=[b[0]+(x[d][0]-x[d-1][0]),b[1]+(x[d][1]-x[d-1][1]),b[2]+(x[d][2]-x[d-1][2])],V=Ka(b,M,T,g[d-1],s.weight);ja(c[d],V),b=V,v.push(V)}nc(i,c,v)}}};function bn(e,t){let r=(h,c,f,p)=>{let m=typeof h=="number"?h:Number(h);return Number.isFinite(m)?Math.max(c,Math.min(f,m)):p};function i(h,c,f=0,p=.05,m){if(!h||!h.length)return-1;let g=h[0]>0?[0,...h]:h,x=Number.isFinite(c)?Math.max(0,c):0,b=Number.isFinite(p)?Math.max(0,Math.min(.5,p)):.05;if(typeof m=="number"&&Number.isFinite(m)&&m>0){let y=f===-1?m*(1-b):m*(1+b);if(x>y)return-1}let v=0;for(let y=g.length-1;y>=1;y--)if(x>=g[y]){v=y;break}if(f<0||f>=g.length||f===v)return v;if(v>f){let y=f;for(let M=f+1;M<=v&&x>=g[M]*(1+b);M++)y=M;return y}let d=f;for(let y=f;y>v&&x<g[y]*(1-b);y--)d=y-1;return d}function n(h){if(!h)return null;let c=h===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(h)?{distances:h}:typeof h=="object"?h:null;if(!c||c.enabled===!1)return null;let f=r(c.hysteresis,0,.5,.05),p=[],m;if(Array.isArray(c.levels)&&c.levels.length>0){let v=c.levels.slice(0,8);for(let y=0;y<v.length;y++){let M=v[y];if(!M||typeof M!="object"||Array.isArray(M))continue;let T=M,V=r(T.distance,0,1e4,y===0?0:y*4),X=typeof T.hysteresis=="number"?r(T.hysteresis,0,.5,f):void 0,P=typeof T.ratio=="number"?r(T.ratio,.05,1,.5):void 0,R=typeof T.childIndex=="number"&&Number.isFinite(T.childIndex)?Math.max(0,Math.round(T.childIndex)):void 0,C=typeof T.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(T.node.trim())?T.node.trim().slice(0,64):void 0;p.push({distance:V,...X!==void 0?{hysteresis:X}:{},...P!==void 0?{ratio:P}:{},...R!==void 0?{childIndex:R}:{},...C?{node:C}:{}})}p.sort((y,M)=>y.distance-M.distance),p.length>0&&p[0].distance>0&&p.unshift({distance:0,childIndex:0});let d=0;p=p.slice(0,8).map((y,M)=>{let T=M===0?0:Math.max(d,y.distance);return d=T,{...y,distance:T,childIndex:y.childIndex??M}})}if(Array.isArray(c.ratios)&&c.ratios.length>0){let v=[];for(let d of c.ratios.slice(0,7))typeof d=="number"&&v.push(r(d,.05,1,.5));v.length>0&&(m=v)}if(p.length===0){let v=Array.isArray(c.distances)?c.distances:[],d=[];for(let M of v.slice(0,8))typeof M=="number"&&d.push(r(M,0,1e4,4));if(d.length===0&&m&&m.length>0)for(let M=0;M<m.length;M++)d.push((M+1)*4);if(d.length===0&&c.cullDistance===void 0)return null;d.length===0||d[0]>0?d.unshift(0):m&&m.length===d.length&&m[0]===1&&(m=m.slice(1));let y=0;for(let M=0;M<Math.min(8,d.length);M++){let T=M===0?0:Math.max(y,d[M]);y=T;let V=M>0&&m?m[M-1]:void 0;p.push({distance:T,childIndex:M,...V!==void 0?{ratio:V}:{}})}}else if(!m){let v=[];for(let d=1;d<p.length;d++)typeof p[d].ratio=="number"&&v.push(p[d].ratio);v.length>0&&(m=v)}let g=p.map(v=>v.distance),x=g[g.length-1]??0,b=c.cullDistance!==void 0&&c.cullDistance!==null&&c.cullDistance!==!1?r(c.cullDistance,Math.max(1,x),1e4,100):void 0;return{levels:p,distances:g,...m?{ratios:m}:{},hysteresis:f,...b!==void 0?{cullDistance:b}:{}}}function s(h,c){let f=h?.attributes?.position;if(!f||!f.array||f.count<3)return h;let p=r(c,.05,1,.5),m=f.array,g=f.count,x=h.attributes?.normal?.array,b=h.attributes?.uv?.array,v=h.index?.array,d=Math.floor((v?v.length:g)/3);if(d<1)return h;let y=Math.max(1,Math.min(d,Math.round(d*p))),M=1/0,T=1/0,V=1/0,X=-1/0,P=-1/0,R=-1/0;for(let U=0;U<g;U++){let _=m[U*3],H=m[U*3+1],D=m[U*3+2];_<M&&(M=_),H<T&&(T=H),D<V&&(V=D),_>X&&(X=_),H>P&&(P=H),D>R&&(R=D)}let C=Math.max(1e-5,X-M),B=Math.max(1e-5,P-T),N=Math.max(1e-5,R-V),w=Math.max(C,B,N),ie=U=>{let _=Math.max(1,Math.round(C/w*U)),H=Math.max(1,Math.round(B/w*U)),D=Math.max(1,Math.round(N/w*U)),F=new Map,E=new Int32Array(g),G=[],ee=[],se=[],oe=[];for(let I=0;I<g;I++){let W=m[I*3],Q=m[I*3+1],K=m[I*3+2],Z=Math.min(_-1,Math.max(0,Math.floor((W-M)/C*_))),q=Math.min(H-1,Math.max(0,Math.floor((Q-T)/B*H))),re=Math.min(D-1,Math.max(0,Math.floor((K-V)/N*D))),ne=Z+q*_+re*_*H,te=F.get(ne);te===void 0?(te=oe.length,F.set(ne,te),G.push(W,Q,K),x&&ee.push(x[I*3],x[I*3+1],x[I*3+2]),b&&se.push(b[I*2],b[I*2+1]),oe.push(1)):(G[te*3]+=W,G[te*3+1]+=Q,G[te*3+2]+=K,x&&(ee[te*3]+=x[I*3],ee[te*3+1]+=x[I*3+1],ee[te*3+2]+=x[I*3+2]),oe[te]++),E[I]=te}let j=[],A=new Set;for(let I=0;I<d;I++){let W=v?v[I*3]:I*3,Q=v?v[I*3+1]:I*3+1,K=v?v[I*3+2]:I*3+2,Z=E[W],q=E[Q],re=E[K];if(Z===q||q===re||re===Z)continue;let ne=Math.min(Z,q,re),te=Math.max(Z,q,re),ue=Z+q+re-ne-te,me=`${ne}_${ue}_${te}`;A.has(me)||(A.add(me),j.push(Z,q,re))}let S=oe.length,L=new Float32Array(S*3),O=x?new Float32Array(S*3):null;for(let I=0;I<S;I++){let W=1/oe[I];if(L[I*3]=G[I*3]*W,L[I*3+1]=G[I*3+1]*W,L[I*3+2]=G[I*3+2]*W,O){let Q=ee[I*3],K=ee[I*3+1],Z=ee[I*3+2],q=Math.hypot(Q,K,Z)||1;O[I*3]=Q/q,O[I*3+1]=K/q,O[I*3+2]=Z/q}}return{pos:L,norm:O,uv:b?new Float32Array(se):null,tris:j,triCount:j.length/3,vertCount:S}},ae=Math.max(2,Math.round(Math.sqrt(y/4))),k=ie(ae);if(k.triCount>y*1.25&&ae>2){let U=Math.max(2,Math.round(ae*Math.sqrt(y/k.triCount)));if(U!==ae){let _=ie(U);_.triCount>=Math.min(4,y)&&(k=_)}}else if(k.triCount<Math.min(4,y)){let U=ie(Math.max(ae*2,8));U.triCount>k.triCount&&(k=U)}let J=k.tris;if(p<1&&k.triCount>y){let U=[],_=k.triCount/y;for(let H=0;H<y;H++){let D=Math.min(k.triCount-1,Math.floor(H*_));U.push(k.tris[D*3],k.tris[D*3+1],k.tris[D*3+2])}J=U}if(J.length<3){J=[];for(let U=0;U<y*3;U++)J.push(v?v[U]:U);k={pos:m.slice(),norm:x?x.slice():null,uv:b?b.slice():null,tris:J,triCount:y,vertCount:g}}let z=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),Y=z?.BufferGeometry??h.constructor,le=z?.BufferAttribute??f.constructor,ce=new Y;ce.setAttribute("position",new le(k.pos,3)),k.norm&&ce.setAttribute("normal",new le(k.norm,3)),k.uv&&ce.setAttribute("uv",new le(k.uv,2));let $=k.vertCount>65535?new Uint32Array(J):new Uint16Array(J);return typeof ce.setIndex=="function"?ce.setIndex(new le($,1)):ce.index=new le($,1),ce}let l=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...h){for(let c of h)c&&(c.parent=this,this.children.push(c));return this}};class o extends l{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(c,f=0,p=.05){if(!c)return this;let m=Math.max(0,Number.isFinite(Number(f))?Number(f):0),g=r(p,0,.5,.05),x=this.levels.length;for(let d=0;d<this.levels.length;d++)if(m<this.levels[d].distance){x=d;break}this.levels.splice(x,0,{object:c,distance:m,hysteresis:g}),this.add(c);let b=this.levels.map(d=>d.object),v=this.children.filter(d=>!b.includes(d));this.children=[...b,...v];for(let d=0;d<this.levels.length;d++)this.levels[d].object.visible=d===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(c){if(!this.levels.length)return null;let f=i(this.levels.map(p=>p.distance),c,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return f>=0&&f<this.levels.length?this.levels[f].object:null}update(c){if(this.levels.length===0||!c)return;let f=c.position??{x:0,y:0,z:0},p=this.position??{x:0,y:0,z:0},m=Math.hypot((Number(f.x)||0)-(Number(p.x)||0),(Number(f.y)||0)-(Number(p.y)||0),(Number(f.z)||0)-(Number(p.z)||0)),g=i(this.levels.map(x=>x.distance),m,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=g;for(let x=0;x<this.levels.length;x++)this.levels[x].object.visible=x===g}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let c=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((f,p)=>({distance:f.distance,hysteresis:f.hysteresis,childIndex:p,...f.object?.name?{node:f.object.name}:{}})),distances:this.levels.map(f=>f.distance),hysteresis:this.levels[0]?.hysteresis??.05,...c!==void 0?{cullDistance:c}:{}}}}function a(h){if(!h||h._lodMaterialized||!h.userData?.xr?.lod||h.isLOD||Array.isArray(h.children)&&h.children.length>0)return;let c=h.geometry?.attributes?.position;if(!c||!c.array||c.count<3)return;let f=n(h.userData.xr.lod);if(!f||f.levels.length<2)return;h._lodMaterialized=!0;let p=h.geometry;h._lodOriginalGeometry=p;let m=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),g=m?.Mesh??h.constructor,x=m?.BufferGeometry??p.constructor,b=typeof h.name=="string"&&h.name.trim()?h.name.trim():"Mesh",v=new g(p,h.material);v.name=`${b}_LOD0`,v.visible=!0,v.castShadow=!!h.castShadow,v.receiveShadow=!!h.receiveShadow,h.add(v);for(let d=1;d<f.levels.length;d++){let y=f.levels[d].ratio??f.ratios?.[d-1]??Math.max(.05,Math.pow(.5,d)),M=s(p,y),T=new g(M,h.material);T.name=`${b}_LOD${d}`,T.visible=!1,T.castShadow=!!h.castShadow,T.receiveShadow=!!h.receiveShadow,h.add(T)}h.geometry=new x,h.userData.xr.lod={...f,levels:f.levels.map((d,y)=>({...d,childIndex:y,node:`${b}_LOD${y}`}))}}let u={LOD:o,decimateGeometry:s,selectLodLevelIndex:i,parseLod:n,materializeLodGeometry:a};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:o,decimateGeometry:s}),t._lodMaterialize=a,t.materializeDeclarativeGeometry=h=>{t._cadMaterialize?.(h),t._lodMaterialize?.(h)}),u}var gn=bn(),ts=gn.decimateGeometry,or=gn.selectLodLevelIndex,sr=gn.parseLod,Vu=gn.materializeLodGeometry,ns=gn.LOD,pn=new WeakMap;function rs(e){return e&&typeof e=="object"?pn.get(e):void 0}var yn=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let n=t.get(i.nodeIndex);n||(n=[],t.set(i.nodeIndex,n)),n.push(i)}let r=i=>{let n=[],s=new Set,l=[i];for(;l.length>0;){let o=l.pop();if(s.has(o)||o<0||o>=e.length)continue;s.add(o);let a=t.get(o);a&&n.push(...a);let u=e[o]?.children;if(Array.isArray(u))for(let h=u.length-1;h>=0;h--)typeof u[h]=="number"&&l.push(u[h])}return n};for(let i=0;i<e.length;i++){let n=e[i];if(!n||typeof n!="object")continue;let s=n.extras?.xr?.lod??n.extensions?.ANDROID_xr_scenecore?.lod??n.extensions?.MOZ_hubs_components?.lod,l=Array.isArray(n.extensions?.MSFT_lod?.ids)?n.extensions.MSFT_lod.ids.filter(p=>typeof p=="number"&&Number.isInteger(p)&&p>=0&&p<e.length):[],o=sr(s);if(!o&&l.length>0&&(o=sr({distances:l.map((p,m)=>m*4)})),!o)continue;let a=l.length>0?l:Array.isArray(n.children)?n.children.filter(p=>typeof p=="number"&&Number.isInteger(p)&&p>=0&&p<e.length):[],u=[],h=[];if(a.length>0){let p=Math.min(a.length,o.levels.length);for(let m=0;m<p;m++){let g=a[m];u.push(g),h.push(r(g))}}else{let p=t.get(i)??[];if(p.length===0)continue;u.push(i),h.push(p)}let c=o.distances.slice(0,h.length);c.length===0&&c.push(0);let f={nodeIndex:i,name:typeof n.name=="string"?n.name:`LOD_${i}`,distances:c,hysteresis:o.hysteresis,...o.cullDistance!==void 0?{cullDistance:o.cullDistance}:{},childNodeIndices:u,levelMeshes:h,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(f,0),this.groups.push(f)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let n=or(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=n,this.applyGroupVisibility(r,n);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let n=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,s=n&&n[12]||0,l=n&&n[13]||0,o=n&&n[14]||0,a=r?r[0]*s+r[4]*l+r[8]*o+r[12]:s,u=r?r[1]*s+r[5]*l+r[9]*o+r[13]:l,h=r?r[2]*s+r[6]*l+r[10]*o+r[14]:o,c=Math.hypot((e[0]||0)-a,(e[1]||0)-u,(e[2]||0)-h);if(i.lastDistance=c,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let f=or(i.distances,c,i.activeLevelIndex,i.hysteresis,i.cullDistance);f!==i.activeLevelIndex&&(i.activeLevelIndex=f,this.applyGroupVisibility(i,f))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let n=i===t;for(let o of e.levelMeshes[i])o.visible=n;let s=e.childNodeIndices[i],l=Array.isArray(r)?r[s]:null;l&&typeof l=="object"&&(l.visible=n,l.extensions=l.extensions||{},l.extensions.KHR_node_visibility={visible:n})}}},Ii={name:"lod",onRegister(){Jt(bn);let e=Me(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);bn(t,e)},onLoadModel(e,t){!e||typeof e!="object"||pn.set(e,new yn(e,t))},onUpdate(e){let t=pn.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},n=r?.radius??3,s=r?.phi??0,l=r?.theta??0,o=Math.cos(s),a=(i.x||0)+n*o*Math.sin(l),u=(i.y||0)+n*Math.sin(s),h=(i.z||0)+n*o*Math.cos(l);t.update([a,u,h])},onBeforeDrawScene(e,t,r,i){let n=pn.get(e);n&&n.update(i)},onDestroy(e,t){t&&typeof t=="object"&&pn.delete(t)}},rc={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function ut(e,t,r,i){if(!r||r.bufferView===void 0)return null;let n=e.bufferViews?.[r.bufferView];if(!n)return null;let s=Number(r.count??0);if(!Number.isInteger(s)||s<=0)return null;let l=r.componentType??5126,o=rc[l];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let a=o*i,u=n.byteStride&&n.byteStride>0?n.byteStride:a,h=(n.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(h)||h<0||u<a||h+(s-1)*u+a>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(l===5126&&u===a&&h%4===0)return new Float32Array(t,h,s*i);let c=new DataView(t),f=r.normalized===!0,p=new Float32Array(s*i);for(let m=0;m<s;m++){let g=h+m*u;for(let x=0;x<i;x++){let b=g+x*o,v;switch(l){case 5126:v=c.getFloat32(b,!0);break;case 5120:v=c.getInt8(b),f&&(v=Math.max(v/127,-1));break;case 5121:v=c.getUint8(b),f&&(v/=255);break;case 5122:v=c.getInt16(b,!0),f&&(v=Math.max(v/32767,-1));break;case 5123:v=c.getUint16(b,!0),f&&(v/=65535);break;default:v=c.getUint32(b,!0),f&&(v/=4294967295)}p[m*i+x]=v}}return p}function is(e,t){let r=Number(t.offset?.[0]??0)||0,i=Number(t.offset?.[1]??0)||0,n=Number(t.scale?.[0]??1),s=Number(t.scale?.[1]??1),l=Number(t.rotation??0)||0,o=Math.cos(l),a=Math.sin(l),u=(Number.isFinite(n)?n:1)*o,h=(Number.isFinite(n)?n:1)*a,c=-(Number.isFinite(s)?s:1)*a,f=(Number.isFinite(s)?s:1)*o;for(let p=0;p+1<e.length;p+=2){let m=e[p],g=e[p+1];e[p]=u*m+h*g+r,e[p+1]=c*m+f*g+i}}function Dt(e,t,r,i=!0){let n=[],s=null;try{for(let[l,o]of[[35633,t],[35632,r]]){let a=e.createShader(l);if(!a){if(i)throw new Error("Shader allocation failed");return null}if(n.push(a),e.shaderSource(a,o),e.compileShader(a),e.getShaderParameter&&!e.getShaderParameter(a,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(a)}`);return null}}if(s=e.createProgram(),!s){if(i)throw new Error("Program allocation failed");return null}for(let l of n)e.attachShader(s,l);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let l=i?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,i)throw new Error(`Program link error: ${l}`);return null}return s}finally{for(let l of n)s&&e.detachShader?.(s,l),e.deleteShader?.(l)}}var as=["neutral","reinhard","none","aces","agx"];function Bt(e){let t=String(e??"").trim().toLowerCase();return as.includes(t)?t:"neutral"}function ic(e){return as.indexOf(Bt(e))}function oc(e){return new TextDecoder().decode(e)}var cs=Me().decoders;function sc(e,t){cs.set(e.toLowerCase(),t)}function rn(e){return cs.get(e.toLowerCase())}function us(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,r=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let i=r.getUint32(0,!0);if(i!==1179937895){let f=r.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${i.toString(16)}`)}let n=r.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=r.getUint32(8,!0),l=12,o=null,a=null;for(;l+8<=s&&l+8<=t.byteLength;){let f=r.getUint32(l,!0),p=r.getUint32(l+4,!0),m=l+8;if(m+f>t.byteLength)throw new Error(`Truncated GLB chunk: required ${m+f} bytes, buffer has ${t.byteLength}`);if(p===1313821514){let g=new Uint8Array(t,m,f),x=oc(g);o=JSON.parse(x,(b,v)=>b==="__proto__"||b==="constructor"||b==="prototype"?void 0:v)}else p===5130562&&(a=t.slice(m,m+f));l=m+f}if(!o)throw new Error("Missing JSON chunk in GLB");let u=o.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!rn("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(u.includes(f)&&!rn("meshopt"))throw new Error(`Model requires ${f}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!rn("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let h=a||new ArrayBuffer(0),c={gltf:o,bin:h,animations:[]};for(let f of Oe)f.onParseGLB?.(c);return c}function ac(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function gt(e){if(ac(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return us(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var ls=`#version 300 es
16
+ */var Mi=Object.defineProperty,Pa=Object.getOwnPropertyDescriptor,Na=Object.getOwnPropertyNames,ka=Object.prototype.hasOwnProperty,Oa=(e,t)=>{for(var r in t)Mi(e,r,{get:t[r],enumerable:!0})},Ua=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Na(t))!ka.call(e,n)&&n!==r&&Mi(e,n,{get:()=>t[n],enumerable:!(i=Pa(t,n))||i.enumerable});return e},Fa=e=>Ua(Mi({},"__esModule",{value:!0}),e),Co={};Oa(Co,{AmbientLight:()=>On,BoxGeometry:()=>Cn,BufferAttribute:()=>$e,BufferGeometry:()=>Be,Camera:()=>Fn,CapsuleGeometry:()=>qr,CatmullRomCurve3:()=>Cr,CircleGeometry:()=>Yr,Clock:()=>Hr,Color:()=>ut,ConeGeometry:()=>Sr,CubicBezierCurve3:()=>Ir,Curve3:()=>St,CylinderGeometry:()=>Dn,DataTexture:()=>Pr,DirectionalLight:()=>Br,DodecahedronGeometry:()=>Kr,EdgesGeometry:()=>Jr,Euler:()=>In,Float32BufferAttribute:()=>vr,Group:()=>Vr,HemisphereLight:()=>Hn,IKSolver:()=>$o,IcosahedronGeometry:()=>jr,InstancedMesh:()=>kn,InteractivityVM:()=>qn,LOD:()=>qo,LatheGeometry:()=>Pn,Light:()=>zt,Line:()=>Nt,LineBasicMaterial:()=>un,LineCurve3:()=>_r,LineDashedMaterial:()=>Zr,LineLoop:()=>ei,LineSegments:()=>ti,LodController:()=>xn,MAX_BSP_DEPTH:()=>Vo,MAX_CSG_TRIANGLES:()=>Fo,MAX_INSTANCES_PER_MESH:()=>Nn,MAX_SHAPE_POINTS:()=>zo,MAX_TEXT_GEOMETRY_CHARS:()=>Bo,Material:()=>et,MathUtils:()=>_s,Matrix3:()=>xr,Matrix4:()=>Pt,Mesh:()=>gt,MeshBasicMaterial:()=>kr,MeshLambertMaterial:()=>Or,MeshPhongMaterial:()=>Ur,MeshPhysicalMaterial:()=>Fr,MeshStandardMaterial:()=>Bt,Object3D:()=>lt,OctahedronGeometry:()=>Wr,PerspectiveCamera:()=>zr,PlaneGeometry:()=>Ar,PointLight:()=>Un,Points:()=>ni,PointsMaterial:()=>Gn,PolyhedronFallbackGeometry:()=>Dc,PolyhedronGeometry:()=>Et,QuadraticBezierCurve3:()=>Lr,Quaternion:()=>sn,RawShaderMaterial:()=>Bs,RectAreaLight:()=>Hs,RingGeometry:()=>zn,Scene:()=>Vn,SceneQuotaValidator:()=>yt,ShaderMaterial:()=>Bn,SphereGeometry:()=>wr,SpotLight:()=>ri,THREE:()=>Ht,TetrahedronGeometry:()=>$r,Texture:()=>an,TextureLoader:()=>Nr,ThreeLiveElement:()=>mt,ThreeView:()=>Ke,TorusGeometry:()=>Er,TorusKnotGeometry:()=>Rr,TubeGeometry:()=>Dr,Uint16BufferAttribute:()=>Mr,Uint32BufferAttribute:()=>Tr,Vector2:()=>rt,Vector3:()=>ge,Vector4:()=>gr,WebGLRenderer:()=>Gr,WireframeGeometry:()=>Qr,activateAR:()=>ci,applyMeshoptFilter:()=>Ao,authorScriptRunner:()=>ln,buildSandboxWorkerSource:()=>Wi,cadPlugin:()=>Ti,clearAuthorWarnings:()=>Vs,computeOutlineClipOffset:()=>Ra,contactShadowPlugin:()=>jn,createUSDZBlob:()=>on,crossFadeTo:()=>eo,decimateGeometry:()=>Ko,decodeMeshoptBuffer:()=>wo,decodeMeshoptGLB:()=>yi,defineModelViewer:()=>$s,encodeMeshoptBuffer:()=>Ta,environmentMapPlugin:()=>ho,evaluateKawaseBloom:()=>Ea,evaluateToneMapping:()=>is,exportSceneToCanvas3D:()=>Gi,exportSceneToGLB:()=>Hi,exportSceneToUSDZ:()=>Cs,extractMaterialVariants:()=>_o,extractPrimitiveVariantMappings:()=>_a,generateUSDZ:()=>En,getARCapabilities:()=>ai,getAllowClientScripts:()=>Ns,getAuthorWarnings:()=>Fs,getBestARMode:()=>Qs,getEnvironmentSH:()=>ta,getInteractivityVM:()=>hi,getLodController:()=>Yo,getSandboxEngineSrc:()=>Xi,getSandboxIframeSrc:()=>Ps,glbToUSDZ:()=>Sn,hotspotPlugin:()=>yo,ikPlugin:()=>Di,installCadExtension:()=>nr,installLodExtension:()=>gn,interactivityPlugin:()=>Mo,isAllowedSandboxEngineUrl:()=>cn,isQuickLookSupported:()=>co,isSceneViewerSupported:()=>uo,isWebXRSupported:()=>lo,keyframeAnimationPlugin:()=>to,lodPlugin:()=>Pi,materialsPlugin:()=>To,meshoptDecoder:()=>gi,meshoptPlugin:()=>So,morphPlugin:()=>no,noopProxy:()=>_n,parseAnimations:()=>Ji,parseHexRgb:()=>Eo,parseLod:()=>ar,parseSafeGltfPointer:()=>Kn,postprocessingPlugin:()=>Ro,quatFromUnitVectors:()=>or,registerMaterialShader:()=>ua,sampleChannel:()=>fn,sceneToCanvas3D:()=>rn,sceneToGLB:()=>Tn,sceneToUSDZ:()=>wn,selectLodLevelIndex:()=>sr,selectMaterialVariant:()=>La,sendInteractivityEvent:()=>vo,setAllowClientScripts:()=>Ac,setEnvironmentSH:()=>ui,setMorphTargetWeight:()=>Ks,setSandboxEngineSrc:()=>xc,setSandboxIframeSrc:()=>Mc,skinningPlugin:()=>io,solveFABRIK:()=>Ii,solveTwoBoneIK:()=>Li,threeAuthorPlugin:()=>Ln,threeMicroPlugin:()=>kc,toGLBData:()=>Lt,toTrustedWorkerScriptURL:()=>Ds,validateSandboxWorkerMessage:()=>ji,variantsPlugin:()=>Lo,warnUnsupported:()=>Gt,webxrPlugin:()=>Io}),module.exports=Fa(Co);function Uo(e,t,r){let i=[],n=new Map,s=[],l=[],o=[],a=new Map,u=p=>{let y=n.get(p);return y===void 0&&(y=i.length,i.push({op:p}),n.set(p,y)),y},h=p=>{let y=a.get(p);return y===void 0&&(y=o.length,o.push({id:p}),a.set(p,y)),y},m=(p,y={})=>s.push({declaration:u(p),...y})-1,c=(p,y,M)=>l.push({id:p,type:y,value:M})-1,d=p=>({node:p,socket:"value"}),f=r?.interactivity??r?.gltfExtensions?.KHR_interactivity;if(f&&typeof f=="object"){let p=Array.isArray(f.graphs)?f.graphs[f.graph??0]:f;if(p&&Array.isArray(p.nodes)){let y=Array.isArray(p.declarations)?p.declarations:[];for(let M of y)M?.op&&u(M.op);Array.isArray(p.variables)&&l.push(...p.variables);for(let M of p.events||[])M?.id&&h(M.id);for(let M of p.nodes){if(!M||typeof M!="object")continue;let P=M.op||(typeof M.declaration=="number"?y[M.declaration]?.op:"");s.push(P?{...M,declaration:u(P)}:{...M})}}}let g=(p,y,M="translation")=>M==="baseColorFactor"||M==="metallicFactor"||M==="roughnessFactor"?`/materials/${Math.max(0,y)}/pbrMetallicRoughness/${M}`:M==="emissiveFactor"||M==="alphaCutoff"?`/materials/${Math.max(0,y)}/${M}`:M==="visible"?`/nodes/${p}/extensions/KHR_node_visibility/visible`:`/nodes/${p}/${M}`,x=new Map;e.forEach((p,y)=>{typeof p?.name=="string"&&!x.has(p.name)&&x.set(p.name,y)});let b=(p,y)=>typeof p.target=="string"&&x.has(p.target)?x.get(p.target):typeof p.targetNode=="number"?p.targetNode:y,v=p=>{let y=e[p];return(typeof y?.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0};for(let p=0;p<e.length;p++){let y=e[p],M=y?.extras?.interactivity;if(!M||typeof M!="object")continue;let P=(typeof y.mesh=="number"?t[y.mesh]?.primitives?.[0]?.material:0)??0,F=T=>{let E=Array.isArray(T)?T:[T],S=[];for(let k=0;k<E.length;k++){let w=E[k];if(!w||typeof w!="object")continue;let ie=w.action||"interpolate",oe=typeof w.duration=="number"?w.duration:.35;if(ie==="toggleTransform"){let I=w.property==="rotation"||w.property==="scale"?w.property:"translation",H=I==="rotation"?y.rotation||[0,0,0,1]:I==="scale"?y.scale||[1,1,1]:y.translation||[0,0,0],N=`/nodes/${p}/${I}`,z=c(`__toggle_${p}_${k}`,"bool",!1),ue=m("variable/get",{configuration:{variable:z}}),ce=m("math/not",{values:{a:d(ue)}}),B=m("variable/set",{configuration:{variable:z},values:{value:d(ce)}}),$=m("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(w.to)?w.to:H},duration:{value:oe}}}),_=m("pointer/interpolate",{configuration:{pointer:N},values:{value:{value:Array.isArray(w.from)?w.from:H},duration:{value:oe}}});s[B].flows={out:{node:m("flow/branch",{values:{condition:d(ue)},flows:{true:{node:$},false:{node:_}}})}},S.push(B)}else if(ie==="interpolate"){let I=w.to??w.value;if(I===void 0)continue;let H={value:{value:I},duration:{value:oe}};w.from!==void 0&&(H.from={value:w.from}),S.push(m("pointer/interpolate",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,p),v(b(w,p)),w.property)},values:H}))}else if(ie==="setProperty"){if(w.value===void 0)continue;S.push(m("pointer/set",{configuration:{pointer:typeof w.pointer=="string"?w.pointer:g(b(w,p),v(b(w,p)),w.property)},values:{value:{value:w.value}}}))}else if(ie==="toggleVisibility"){let I=b(w,p),H=c(`__vis_${I}_${k}`,"bool",!0),N=m("variable/get",{configuration:{variable:H}}),z=m("math/not",{values:{a:d(N)}}),ue=m("variable/set",{configuration:{variable:H},values:{value:d(z)}});s[ue].flows={out:{node:m("pointer/set",{configuration:{pointer:`/nodes/${I}/extensions/KHR_node_visibility/visible`},values:{value:d(N)}})}},S.push(ue)}else if(ie==="cycleMaterialColor"&&Array.isArray(w.colors)&&w.colors.length>0){let I=typeof w.duration=="number"?w.duration:.25,H=`/materials/${Math.max(0,P)}/pbrMetallicRoughness/baseColorFactor`,N=c(`__color_idx_${p}_${k}`,"int",0),z=m("variable/get",{configuration:{variable:N}}),ue=m("math/add",{values:{a:d(z),b:{value:1}}}),ce=m("math/rem",{values:{a:d(ue),b:{value:w.colors.length}}}),B=m("variable/set",{configuration:{variable:N},values:{value:d(ce)}}),$={};for(let _=0;_<w.colors.length;_++){let G=w.colors[_],j=Array.isArray(G)&&G.length>=3?[G[0],G[1],G[2],G[3]??1]:[1,1,1,1];$[String(_)]={node:I>0?m("pointer/interpolate",{configuration:{pointer:H},values:{value:{value:j},duration:{value:I}}}):m("pointer/set",{configuration:{pointer:H},values:{value:{value:j}}})}}s[B].flows={out:{node:m("flow/switch",{values:{selection:d(z)},flows:$})}},S.push(B)}else if(ie==="playAnimation")S.push(m("animation/start",{configuration:{animation:w.animation??w.clip??0}}));else if(ie==="stopAnimation")S.push(m("animation/stop"));else if(ie==="sendEvent"){let I={};for(let[H,N]of Object.entries(w.values||{}))I[H]={value:N};S.push(m("event/send",{configuration:{event:h(String(w.event??w.id??"custom"))},values:I}))}}if(!S.length)return null;if(S.length===1)return S[0];let O={};return S.forEach((k,w)=>{O[String(w)]={node:k}}),m("flow/sequence",{flows:O})},W=(T,E,S)=>{let O=F(E);O!==null&&m(T,{...S?{configuration:S}:{},flows:{out:{node:O}}})};if(M.onSelect&&W("pointer/onSelect",M.onSelect,{nodeIndex:p}),M.onHoverIn&&W("pointer/onHoverIn",M.onHoverIn,{nodeIndex:p}),M.onHoverOut&&W("pointer/onHoverOut",M.onHoverOut,{nodeIndex:p}),M.onStart&&W("event/onStart",M.onStart),M.onReceive&&typeof M.onReceive=="object")for(let[T,E]of Object.entries(M.onReceive))W("event/receive",E,{event:h(T)})}return s.length?{graphs:[{declarations:i,nodes:s,variables:l,events:o}],graph:0}:null}var Qn='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).',Jn="Security Error: client-side scripts require allow-client-scripts opt-in.",er="__THREE_LIVE_REGISTRY__";function Ae(){let e=typeof globalThis<"u"?globalThis:{};if(!e[er]){let t={plugins:[],decoders:new Map};try{Object.defineProperty(e,er,{value:t,writable:!1,configurable:!1,enumerable:!1})}catch{e[er]=t}}return e[er]}var Oe=Ae().plugins;function Qt(e){let t=Ae();t.workerExtensionInstallers||(t.workerExtensionInstallers=[]),t.workerExtensionInstallers.includes(e)||t.workerExtensionInstallers.push(e)}function Ve(e){let t=Ae().plugins;t.some(r=>r.name===e.name)||t.push(e),e.onRegister?.()}function tr(){return Ae().plugins}var Fo=8192,Vo=2048,Bo=128,zo=4096;function nr(e,t){if(!e||!e.BufferGeometry)return null;let r=e.Vector2,i=e.Vector3,n=e.Quaternion,s=e.Matrix4,l=e.Matrix3,o=e.Color,a=e.BufferAttribute,u=e.BufferGeometry,h=e.Material,m=e.MeshStandardMaterial,c=e.Mesh,d=8192,f=2048,g=128,x=4096,b=(R,A)=>{let L=R==null?NaN:Number(R);return Number.isFinite(L)?L:A};class v{constructor(A){this.currentPoint=new r(0,0),this.segments=[],Array.isArray(A)&&A.length>0&&this.fromPoints(A)}fromPoints(A){if(!A.length)return this;this.moveTo(A[0].x,A[0].y);for(let L=1;L<A.length;L++)this.lineTo(A[L].x,A[L].y);return this}moveTo(A,L){let C=Number(A)||0,U=Number(L)||0;return this.currentPoint.set(C,U),this.segments.push({type:"move",pts:[C,U]}),this}lineTo(A,L){let C=Number(A)||0,U=Number(L)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[this.currentPoint.x,this.currentPoint.y]}),this.currentPoint.set(C,U),this.segments.push({type:"line",pts:[C,U]}),this}quadraticCurveTo(A,L,C,U){let Q=this.currentPoint.x,X=this.currentPoint.y,Z=Number(A)||0,J=Number(L)||0,K=Number(C)||0,ae=Number(U)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[Q,X]}),this.currentPoint.set(K,ae),this.segments.push({type:"quad",pts:[Q,X,Z,J,K,ae]}),this}bezierCurveTo(A,L,C,U,Q,X){let Z=this.currentPoint.x,J=this.currentPoint.y,K=Number(A)||0,ae=Number(L)||0,ne=Number(C)||0,re=Number(U)||0,me=Number(Q)||0,fe=Number(X)||0;return this.segments.length===0&&this.segments.push({type:"move",pts:[Z,J]}),this.currentPoint.set(me,fe),this.segments.push({type:"cubic",pts:[Z,J,K,ae,ne,re,me,fe]}),this}absarc(A,L,C,U,Q,X=!1){return this.absellipse(A,L,C,C,U,Q,X,0)}arc(A,L,C,U,Q,X=!1){return this.absarc(this.currentPoint.x+(Number(A)||0),this.currentPoint.y+(Number(L)||0),C,U,Q,X)}absellipse(A,L,C,U,Q,X,Z=!1,J=0){let K=Number(A)||0,ae=Number(L)||0,ne=Math.max(0,Number(C)||0),re=Math.max(0,Number(U)||0),me=Number(Q)||0,fe=Number(X)||0,ye=Z?1:0,de=Number(J)||0;this.segments.push({type:"arc",pts:[K,ae,ne,re,me,fe,ye,de]});let pe=Math.cos(de),be=Math.sin(de),ve=ne*Math.cos(fe),xe=re*Math.sin(fe);return this.currentPoint.set(K+ve*pe-xe*be,ae+ve*be+xe*pe),this}ellipse(A,L,C,U,Q,X,Z=!1,J=0){return this.absellipse(this.currentPoint.x+(Number(A)||0),this.currentPoint.y+(Number(L)||0),C,U,Q,X,Z,J)}closePath(){if(this.segments.length>0){let A=this.segments[0],L=0,C=0;if(A.type==="arc"){let U=A.pts[0],Q=A.pts[1],X=A.pts[2],Z=A.pts[3],J=A.pts[4],K=A.pts[7],ae=Math.cos(K),ne=Math.sin(K),re=X*Math.cos(J),me=Z*Math.sin(J);L=U+re*ae-me*ne,C=Q+re*ne+me*ae}else L=A.pts[0],C=A.pts[1];Math.hypot(this.currentPoint.x-L,this.currentPoint.y-C)>1e-6&&this.lineTo(L,C)}return this}getPoints(A=12){let L=Math.max(1,Math.min(128,Math.floor(Number(A)||12))),C=[],U=(Q,X)=>{if(C.length>0){let Z=C[C.length-1];if(Math.hypot(Z.x-Q,Z.y-X)<1e-6)return}C.push(new r(Q,X))};for(let Q of this.segments){let X=Q.pts;if(Q.type==="move"||Q.type==="line")U(X[0],X[1]);else if(Q.type==="quad"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5];U(Z,J);for(let me=1;me<=L;me++){let fe=me/L,ye=1-fe;U(ye*ye*Z+2*ye*fe*K+fe*fe*ne,ye*ye*J+2*ye*fe*ae+fe*fe*re)}}else if(Q.type==="cubic"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5],me=X[6],fe=X[7];U(Z,J);for(let ye=1;ye<=L;ye++){let de=ye/L,pe=1-de,be=pe*pe,ve=de*de;U(be*pe*Z+3*be*de*K+3*pe*ve*ne+ve*de*me,be*pe*J+3*be*de*ae+3*pe*ve*re+ve*de*fe)}}else if(Q.type==="arc"){let Z=X[0],J=X[1],K=X[2],ae=X[3],ne=X[4],re=X[5],me=X[6]!==0,fe=X[7],ye=Math.PI*2,de=re-ne,pe=Math.abs(de)<1e-9;for(;de<0;)de+=ye;for(;de>ye;)de-=ye;de<1e-9&&(de=pe?0:ye),me&&!pe&&(de=de===ye?-ye:de-ye);let be=Math.cos(fe),ve=Math.sin(fe),xe=Math.max(2,L);for(let Ee=0;Ee<=xe;Ee++){let Te=Ee/xe,Pe=ne+Te*de,Ce=K*Math.cos(Pe),ke=ae*Math.sin(Pe);U(Z+Ce*be-ke*ve,J+Ce*ve+ke*be)}}}if(C.length>2){let Q=C[0],X=C[C.length-1];Math.hypot(Q.x-X.x,Q.y-X.y)<1e-6&&C.pop()}return C}getSpacedPoints(A=12){return this.getPoints(A)}clone(){let A=new this.constructor;return A.currentPoint.copy(this.currentPoint),A.segments=this.segments.map(L=>({type:L.type,pts:[...L.pts]})),Array.isArray(this.holes)&&(A.holes=this.holes.map(L=>L.clone())),A}}class p extends v{constructor(A){super(A),this.holes=[]}extractPoints(A=12){return{shape:this.getPoints(A),holes:this.holes.map(L=>L.getPoints(A))}}}function y(R){let A=0,L=R.length;for(let C=0,U=L-1;C<L;U=C++)A+=R[U].x*R[C].y-R[C].x*R[U].y;return A*.5}function M(R,A,L,C,U,Q,X,Z){let J=X-L,K=Z-C,ae=U-L,ne=Q-C,re=R-L,me=A-C,fe=J*J+K*K,ye=J*ae+K*ne,de=J*re+K*me,pe=ae*ae+ne*ne,be=ae*re+ne*me,ve=fe*pe-ye*ye;if(Math.abs(ve)<1e-12)return!1;let xe=1/ve,Ee=(pe*de-ye*be)*xe,Te=(fe*be-ye*de)*xe;return Ee>=-1e-7&&Te>=-1e-7&&Ee+Te<=1+1e-7}function P(R,A){let L=R.slice();y(L)<0&&L.reverse();let C=L.map(J=>new r(J.x,J.y)),U=L.map((J,K)=>K),Q=[];for(let J of A){if(!J||J.length<3)continue;let K=J.slice();y(K)>0&&K.reverse();let ae=[],ne=-1/0,re=0;for(let me=0;me<K.length;me++){let fe=K[me],ye=C.length;C.push(new r(fe.x,fe.y)),ae.push(ye),fe.x>ne&&(ne=fe.x,re=me)}Q.push({pts:K,indices:ae,maxX:ne,maxIdx:re})}Q.sort((J,K)=>K.maxX-J.maxX);let X=(J,K,ae)=>(K.x-J.x)*(ae.y-J.y)-(K.y-J.y)*(ae.x-J.x),Z=(J,K,ae)=>{for(let ne=0;ne<ae.length;ne++){let re=ae[ne],me=ae[(ne+1)%ae.length];if(X(J,K,re)*X(J,K,me)<0&&X(re,me,J)*X(re,me,K)<0)return!0}return!1};for(let J of Q){let K=J.pts[J.maxIdx],ae=K.x,ne=U.length,re=U.map(pe=>C[pe]),me=pe=>Math.hypot(re[pe].x-ae,re[pe].y-K.y),fe=re.map((pe,be)=>be).sort((pe,be)=>+(re[pe].x<ae)-+(re[be].x<ae)||me(pe)-me(be)),ye=fe[0];for(let pe of fe){let be=re[pe],ve=re[(pe+ne-1)%ne],xe=re[(pe+1)%ne],Ee=X(be,xe,K)>=0,Te=X(ve,be,K)>=0;if((X(ve,be,xe)>=0?Ee&&Te:Ee||Te)&&!Z(K,be,re)&&!Q.some(Pe=>Z(K,be,Pe.pts))){ye=pe;break}}let de=[];for(let pe=0;pe<=ye;pe++)de.push(U[pe]);for(let pe=0;pe<=J.indices.length;pe++){let be=J.indices[(J.maxIdx+pe)%J.indices.length];de.push(be)}for(let pe=ye;pe<U.length;pe++)de.push(U[pe]);U=de}return{merged:U.map(J=>C[J]),mergedIndices:U,allVertices:C}}function F(R,A){let L=[],C=R.slice();if(C.length<3)return L;let U=C.length*C.length+64,Q=0;for(;C.length>2&&U-- >0;){let X=C.length,Z=C[(Q+X-1)%X],J=C[Q%X],K=C[(Q+1)%X],ae=A[Z],ne=A[J],re=A[K];if((ne.x-ae.x)*(re.y-ae.y)-(ne.y-ae.y)*(re.x-ae.x)>1e-9){let me=!0,fe=Math.min(ae.x,ne.x,re.x)-1e-7,ye=Math.max(ae.x,ne.x,re.x)+1e-7,de=Math.min(ae.y,ne.y,re.y)-1e-7,pe=Math.max(ae.y,ne.y,re.y)+1e-7;for(let be=0;be<X;be++){let ve=C[be];if(ve===Z||ve===J||ve===K)continue;let xe=A[ve];if(xe.x>=fe&&xe.x<=ye&&xe.y>=de&&xe.y<=pe&&M(xe.x,xe.y,ae.x,ae.y,ne.x,ne.y,re.x,re.y)&&(xe.x-ae.x)*(xe.x-ae.x)+(xe.y-ae.y)*(xe.y-ae.y)>=1e-12&&(xe.x-ne.x)*(xe.x-ne.x)+(xe.y-ne.y)*(xe.y-ne.y)>=1e-12&&(xe.x-re.x)*(xe.x-re.x)+(xe.y-re.y)*(xe.y-re.y)>=1e-12){me=!1;break}}if(me){L.push([Z,J,K]),C.splice(Q%X,1),Q=Math.max(0,Q%X-1);continue}}Q++,Q>=X*2&&(L.push([Z,J,K]),C.splice((Q-1)%X,1),Q=0)}return L}function W(R,A){let L=R instanceof p?R.extractPoints(A):{shape:R.getPoints(A),holes:[]},C=L.shape.length;for(let U of L.holes)C+=U.length;if(C>x)throw new RangeError(`SecurityError: shape point count (${C}) exceeds MAX_SHAPE_POINTS (${x})`);return L}function T(R){let A=1/0,L=1/0,C=-1/0,U=-1/0;for(let Q of R)Q.x<A&&(A=Q.x),Q.y<L&&(L=Q.y),Q.x>C&&(C=Q.x),Q.y>U&&(U=Q.y);return[A,L,Math.max(1e-6,C-A),Math.max(1e-6,U-L)]}class E extends u{constructor(A=new p,L=12){super();let C=Array.isArray(A)?A:[A],U=[],Q=[],X=[],Z=[];for(let J of C){if(!(J instanceof v))continue;let K=W(J,L);if(K.shape.length<3)continue;let{mergedIndices:ae,allVertices:ne}=P(K.shape,K.holes),re=F(ae,ne),me=U.length/3,[fe,ye,de,pe]=T(ne);for(let be of ne)U.push(be.x,be.y,0),Q.push(0,0,1),X.push((be.x-fe)/de,(be.y-ye)/pe);for(let[be,ve,xe]of re)Z.push(me+be,me+ve,me+xe)}S(this,U,Q,X,Z)}}function S(R,A,L,C,U){return R.setAttribute("position",new a(A,3)),R.setAttribute("normal",new a(L,3)),R.setAttribute("uv",new a(C,2)),R.setIndex(U),R}function O(R){let A=R.length,L=[];for(let C=0;C<A;C++){let U=R[(C+A-1)%A],Q=R[C],X=R[(C+1)%A],Z=Q.x-U.x,J=Q.y-U.y,K=Math.hypot(Z,J)||1;Z/=K,J/=K;let ae=X.x-Q.x,ne=X.y-Q.y,re=Math.hypot(ae,ne)||1;ae/=re,ne/=re;let me=J,fe=-Z,ye=ne,de=-ae,pe=me+ye,be=fe+de,ve=Math.hypot(pe,be);if(ve>1e-6){pe/=ve,be/=ve;let xe=Math.max(.35,pe*me+be*fe);L.push(new r(pe/xe,be/xe))}else L.push(new r(me,fe))}return L}class k extends u{constructor(A=new p,L={}){super();let C=Array.isArray(A)?A:[A],U=Math.max(1,Math.min(64,Math.floor(b(L.curveSegments,12)))),Q=b(L.depth??L.amount,1),X=Math.max(1,Math.min(32,Math.floor(b(L.steps,1)))),Z=!!(L.bevelEnabled??!1),J=Z?Math.max(0,b(L.bevelThickness,.06)):0,K=Z?Math.max(0,b(L.bevelSize,J*.8)):0,ae=Z?b(L.bevelOffset,0):0,ne=Z?Math.max(1,Math.min(8,Math.floor(b(L.bevelSegments,2)))):0,re=[],me=[],fe=[],ye=[];for(let de of C){if(!(de instanceof v))continue;let pe=W(de,U);if(pe.shape.length<3)continue;let be=pe.shape.slice();y(be)<0&&be.reverse();let ve=[];for(let _e of pe.holes){if(_e.length<3)continue;let Le=_e.slice();y(Le)>0&&Le.reverse(),ve.push(Le)}let{mergedIndices:xe,allVertices:Ee}=P(be,ve),Te=F(xe,Ee),Pe=[be,...ve],Ce=[];for(let _e of Pe){let Le=O(_e);for(let qe of Le)Ce.push(qe)}let[ke,tt,Ze,pt]=T(Ee);for(let[_e,Le]of[[-J,-1],[Q+J,1]]){let qe=re.length/3;for(let We=0;We<Ee.length;We++){let Ue=Ee[We],He=Ce[We]??new r(0,0),st=Ue.x+He.x*ae,Je=Ue.y+He.y*ae;re.push(st,Je,_e),me.push(0,0,Le),fe.push((st-ke)/Ze,(Je-tt)/pt)}for(let[We,Ue,He]of Te)ye.push(qe+We,qe+(Le<0?He:Ue),qe+(Le<0?Ue:He))}let Fe=[];if(Z&&ne>0)for(let _e=0;_e<ne;_e++){let Le=_e/ne*Math.PI/2;Fe.push({z:-J*Math.cos(Le),expand:ae+K*Math.sin(Le)})}for(let _e=0;_e<=X;_e++){let Le=_e/X;Fe.push({z:Le*Q,expand:ae+K})}if(Z&&ne>0)for(let _e=1;_e<=ne;_e++){let Le=_e/ne*Math.PI/2;Fe.push({z:Q+J*Math.sin(Le),expand:ae+K*Math.cos(Le)})}let at=0;for(let _e of Pe){let Le=_e.length;for(let qe=0;qe<Fe.length-1;qe++){let We=Fe[qe],Ue=Fe[qe+1];for(let He=0;He<Le;He++){let st=(He+1)%Le,Je=_e[He],ot=_e[st],ht=Ce[at+He],ct=Ce[at+st],dt=Je.x+ht.x*We.expand,Mt=Je.y+ht.y*We.expand,jt=ot.x+ct.x*We.expand,qt=ot.y+ct.y*We.expand,qi=ot.x+ct.x*Ue.expand,Yi=ot.y+ct.y*Ue.expand,Ut=Je.x+ht.x*Ue.expand,Ot=Je.y+ht.y*Ue.expand,Wt=jt-dt,kt=qt-Mt,sl=Ut-dt,al=Ot-Mt,bn=Ue.z-We.z,Kt=kt*bn,Yt=-Wt*bn,Zt=Wt*al-kt*sl,pn=Math.hypot(Kt,Yt,Zt)||1;Kt/=pn,Yt/=pn,Zt/=pn;let vi=re.length/3;re.push(dt,Mt,We.z,jt,qt,We.z,qi,Yi,Ue.z,Ut,Ot,Ue.z),me.push(Kt,Yt,Zt,Kt,Yt,Zt,Kt,Yt,Zt,Kt,Yt,Zt);let Ca=He/Le,Da=(He+1)/Le,so=qe/(Fe.length-1),Po=(qe+1)/(Fe.length-1);fe.push(Ca,so,Da,so,Da,Po,Ca,Po),ye.push(vi,vi+1,vi+2,vi,vi+2,vi+3)}}at+=Le}}S(this,re,me,fe,ye)}}function w(R){return{x:R.x,y:R.y,z:R.z,nx:R.nx,ny:R.ny,nz:R.nz,u:R.u,v:R.v}}function ie(R){return{x:R.x,y:R.y,z:R.z,nx:-R.nx,ny:-R.ny,nz:-R.nz,u:R.u,v:R.v}}function oe(R,A,L){let C=R.nx+(A.nx-R.nx)*L,U=R.ny+(A.ny-R.ny)*L,Q=R.nz+(A.nz-R.nz)*L,X=Math.hypot(C,U,Q)||1;return{x:R.x+(A.x-R.x)*L,y:R.y+(A.y-R.y)*L,z:R.z+(A.z-R.z)*L,nx:C/X,ny:U/X,nz:Q/X,u:R.u+(A.u-R.u)*L,v:R.v+(A.v-R.v)*L}}function I(R){if(R.length<3)return null;let A=R[0],L=R[1],C=R[2],U=L.x-A.x,Q=L.y-A.y,X=L.z-A.z,Z=C.x-A.x,J=C.y-A.y,K=C.z-A.z,ae=Q*K-X*J,ne=X*Z-U*K,re=U*J-Q*Z,me=Math.hypot(ae,ne,re);if(me<1e-9)return null;ae/=me,ne/=me,re/=me;let fe=ae*A.x+ne*A.y+re*A.z;return{vertices:R,nx:ae,ny:ne,nz:re,w:fe}}function H(R){R.vertices.reverse();for(let A=0;A<R.vertices.length;A++)R.vertices[A]=ie(R.vertices[A]);R.nx=-R.nx,R.ny=-R.ny,R.nz=-R.nz,R.w=-R.w}let N=1e-5,z=0,ue=1,ce=2,B=3;function $(R,A,L,C,U,Q,X,Z,J){let K=0,ae=[];for(let ne=0;ne<U.vertices.length;ne++){let re=U.vertices[ne],me=R*re.x+A*re.y+L*re.z-C,fe=me<-N?ce:me>N?ue:z;K|=fe,ae.push(fe)}switch(K){case z:{R*U.nx+A*U.ny+L*U.nz>0?Q.push(U):X.push(U);break}case ue:Z.push(U);break;case ce:J.push(U);break;case B:{let ne=[],re=[],me=U.vertices.length;for(let be=0;be<me;be++){let ve=(be+1)%me,xe=ae[be],Ee=ae[ve],Te=U.vertices[be],Pe=U.vertices[ve];if(xe!==ce&&ne.push(Te),xe!==ue&&re.push(xe!==ce?w(Te):Te),(xe|Ee)===B){let Ce=Pe.x-Te.x,ke=Pe.y-Te.y,tt=Pe.z-Te.z,Ze=R*Ce+A*ke+L*tt,pt=Math.abs(Ze)>1e-12?(C-(R*Te.x+A*Te.y+L*Te.z))/Ze:.5,Fe=oe(Te,Pe,Math.max(0,Math.min(1,pt)));ne.push(Fe),re.push(w(Fe))}}let{nx:fe,ny:ye,nz:de,w:pe}=U;ne.length>=3&&Z.push({vertices:ne,nx:fe,ny:ye,nz:de,w:pe}),re.length>=3&&J.push({vertices:re,nx:fe,ny:ye,nz:de,w:pe});break}default:break}}class _{constructor(A,L=0){this.nx=0,this.ny=0,this.nz=0,this.w=0,this.hasPlane=!1,this.polygons=[],this.front=null,this.back=null,A&&A.length>0&&this.build(A,L)}invert(){for(let L=0;L<this.polygons.length;L++)H(this.polygons[L]);this.nx=-this.nx,this.ny=-this.ny,this.nz=-this.nz,this.w=-this.w,this.front&&this.front.invert(),this.back&&this.back.invert();let A=this.front;this.front=this.back,this.back=A}clipPolygons(A,L=0){if(!this.hasPlane||A.length===0)return A.slice();if(L>=f)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${f})`);let C=[],U=[];for(let Q=0;Q<A.length;Q++)$(this.nx,this.ny,this.nz,this.w,A[Q],C,U,C,U);return this.front&&C.length>0&&(C=this.front.clipPolygons(C,L+1)),this.back?U=U.length>0?this.back.clipPolygons(U,L+1):[]:U=[],C.concat(U)}clipTo(A,L=0){this.polygons.length>0&&(this.polygons=A.clipPolygons(this.polygons,0)),L<f&&(this.front&&this.front.clipTo(A,L+1),this.back&&this.back.clipTo(A,L+1))}allPolygons(A=[]){for(let L=0;L<this.polygons.length;L++)A.push(this.polygons[L]);return this.front&&this.front.allPolygons(A),this.back&&this.back.allPolygons(A),A}build(A,L=0){if(!A.length)return;if(!this.hasPlane){let Q=A[A.length>>1];this.nx=Q.nx,this.ny=Q.ny,this.nz=Q.nz,this.w=Q.w,this.hasPlane=!0}if(L>=f)throw new RangeError(`SecurityError: CSG BSP depth exceeds MAX_BSP_DEPTH (${f})`);let C=[],U=[];for(let Q=0;Q<A.length;Q++)$(this.nx,this.ny,this.nz,this.w,A[Q],this.polygons,this.polygons,C,U);C.length>0&&(this.front||(this.front=new _),this.front.build(C,L+1)),U.length>0&&(this.back||(this.back=new _),this.back.build(U,L+1))}}function G(R,A){if(!A&&R._csgPolygons)return R._csgPolygons;let L=R.attributes.position;if(!L||L.count===0)return[];let C=R.attributes.normal,U=R.attributes.uv,Q=R.index?R.index.array:null,X=Math.floor(Q?Q.length/3:L.count/3);if(X>d)throw new RangeError(`SecurityError: CSG input triangle count (${X}) exceeds MAX_CSG_TRIANGLES (${d})`);let Z=A?A.elements:null,J=Z?Z[0]*(Z[5]*Z[10]-Z[9]*Z[6])-Z[4]*(Z[1]*Z[10]-Z[9]*Z[2])+Z[8]*(Z[1]*Z[6]-Z[5]*Z[2])<0:!1,K=Z?new l().getNormalMatrix(A).elements:null,ae=re=>{let me=L.getX(re),fe=L.getY(re),ye=L.getZ(re),de=C?C.getX(re):NaN,pe=C?C.getY(re):NaN,be=C?C.getZ(re):NaN;if(Z&&K){let Ee=Z[0]*me+Z[4]*fe+Z[8]*ye+Z[12],Te=Z[1]*me+Z[5]*fe+Z[9]*ye+Z[13],Pe=Z[2]*me+Z[6]*fe+Z[10]*ye+Z[14];me=Ee,fe=Te,ye=Pe;let Ce=K[0]*de+K[3]*pe+K[6]*be,ke=K[1]*de+K[4]*pe+K[7]*be,tt=K[2]*de+K[5]*pe+K[8]*be,Ze=Math.hypot(Ce,ke,tt)||1;de=Ce/Ze,pe=ke/Ze,be=tt/Ze}let ve=U?U.getX(re):0,xe=U?U.getY(re):0;return{x:me,y:fe,z:ye,nx:de,ny:pe,nz:be,u:ve,v:xe}},ne=[];for(let re=0;re<X;re++){let me=Q?Q[re*3]:re*3,fe=Q?Q[re*3+1]:re*3+1,ye=Q?Q[re*3+2]:re*3+2,de=I(J?[ae(me),ae(ye),ae(fe)]:[ae(me),ae(fe),ae(ye)]);de&&ne.push(de)}return ne}function j(R){let A=[],L=[],C=[],U=[];for(let X of R){let Z=X.vertices;if(Z.length<3)continue;let J=A.length/3;for(let K of Z)A.push(K.x,K.y,K.z),Number.isFinite(K.nx)&&K.nx*K.nx+K.ny*K.ny+K.nz*K.nz>.5?L.push(K.nx,K.ny,K.nz):L.push(X.nx,X.ny,X.nz),C.push(K.u,K.v);for(let K=1;K<Z.length-1;K++)U.push(J,J+K,J+K+1)}let Q=S(new u,A,L,C,U);return Q._csgPolygons=R,Q}function q(R,A,L){if(R.length+A.length>d)throw new RangeError(`SecurityError: Combined CSG triangle count (${R.length+A.length}) exceeds MAX_CSG_TRIANGLES (${d})`);if(R.length===0)return L==="union"?A:[];if(A.length===0)return L==="intersect"?[]:R;let C=1/0,U=1/0,Q=1/0,X=-1/0,Z=-1/0,J=-1/0;for(let me=0;me<A.length;me++){let fe=A[me].vertices;for(let ye=0;ye<fe.length;ye++){let de=fe[ye];de.x<C&&(C=de.x),de.y<U&&(U=de.y),de.z<Q&&(Q=de.z),de.x>X&&(X=de.x),de.y>Z&&(Z=de.y),de.z>J&&(J=de.z)}}C-=1e-4,U-=1e-4,Q-=1e-4,X+=1e-4,Z+=1e-4,J+=1e-4;let K=[],ae=[];for(let me=0;me<R.length;me++){let fe=R[me],ye=fe.vertices,de=1/0,pe=1/0,be=1/0,ve=-1/0,xe=-1/0,Ee=-1/0;for(let Te=0;Te<ye.length;Te++){let Pe=ye[Te];Pe.x<de&&(de=Pe.x),Pe.y<pe&&(pe=Pe.y),Pe.z<be&&(be=Pe.z),Pe.x>ve&&(ve=Pe.x),Pe.y>xe&&(xe=Pe.y),Pe.z>Ee&&(Ee=Pe.z)}ve<C||de>X||xe<U||pe>Z||Ee<Q||be>J?ae.push(fe):K.push(fe)}if(K.length===0)return L==="union"?R.concat(A):L==="subtract"?R:[];let ne=new _(K),re=new _(A);return L==="union"?(ne.clipTo(re),re.clipTo(ne),re.invert(),re.clipTo(ne),re.invert(),ne.build(re.allPolygons()),ae.concat(ne.allPolygons())):L==="subtract"?(ne.invert(),ne.clipTo(re),re.clipTo(ne),re.invert(),re.clipTo(ne),re.invert(),ne.build(re.allPolygons()),ne.invert(),ae.concat(ne.allPolygons())):(ne.invert(),re.clipTo(ne),re.invert(),ne.clipTo(re),re.clipTo(ne),ne.build(re.allPolygons()),ne.invert(),ne.allPolygons())}function D(R,A,L,C=null,U=null){let Q=G(R,C),X=G(A,U);return j(q(Q,X,L))}function Y(R,A,L){let C=R instanceof c||!!R?.isMesh,U=A instanceof c||!!A?.isMesh,Q=C?R.geometry:R,X=U?A.geometry:A,Z=null;if(U)if(A.updateMatrix(),C){R.updateMatrix();let ne=new s().makeScale(1/(R.scale.x||1),1/(R.scale.y||1),1/(R.scale.z||1)),re=Math.hypot(R.quaternion.x,R.quaternion.y,R.quaternion.z,R.quaternion.w)||1,me=new s().compose(new i(0,0,0),new n(-R.quaternion.x/re,-R.quaternion.y/re,-R.quaternion.z/re,R.quaternion.w/re),new i(1,1,1)),fe=new s().makeTranslation(-R.position.x,-R.position.y,-R.position.z);Z=ne.multiply(me).multiply(fe).multiply(A.matrix)}else Z=A.matrix;let J=D(Q,X,L,null,Z),K=C?R.material:new m,ae=new c(J,K);return C&&(ae.position.copy(R.position),ae.quaternion.copy(R.quaternion),ae.scale.copy(R.scale),ae.name=R.name),ae}let te={toGeometry:D,subtract(R,A){return Y(R,A,"subtract")},union(R,A){return Y(R,A,"union")},intersect(R,A){return Y(R,A,"intersect")}},se={0:[[[.15,0],[.85,0],[.85,1],[.15,1],[.15,0]]],1:[[[.3,.8],[.5,1],[.5,0]],[[.2,0],[.8,0]]],2:[[[.15,.8],[.3,1],[.7,1],[.85,.8],[.85,.55],[.15,0],[.85,0]]],3:[[[.15,.85],[.3,1],[.75,1],[.85,.75],[.5,.5],[.85,.25],[.75,0],[.3,0],[.15,.15]]],4:[[[.7,0],[.7,1],[.15,.35],[.9,.35]]],5:[[[.85,1],[.2,1],[.15,.55],[.75,.55],[.85,.3],[.75,0],[.2,0]]],6:[[[.8,.9],[.5,1],[.15,.7],[.15,.15],[.5,0],[.85,.2],[.85,.45],[.5,.55],[.15,.45]]],7:[[[.15,1],[.85,1],[.35,0]]],8:[[[.2,.5],[.15,.75],[.3,1],[.7,1],[.85,.75],[.8,.5],[.2,.5],[.15,.2],[.3,0],[.7,0],[.85,.2],[.8,.5]]],9:[[[.85,.55],[.5,.45],[.15,.55],[.15,.85],[.5,1],[.85,.85],[.85,.2],[.5,0],[.2,.1]]],A:[[[.1,0],[.5,1],[.9,0]],[[.25,.35],[.75,.35]]],B:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.7,.5],[.85,.25],[.7,0],[.15,0]]],C:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.65,0],[.85,.2]]],D:[[[.15,0],[.15,1],[.65,1],[.85,.75],[.85,.25],[.65,0],[.15,0]]],E:[[[.85,1],[.15,1],[.15,0],[.85,0]],[[.15,.5],[.7,.5]]],F:[[[.85,1],[.15,1],[.15,0]],[[.15,.5],[.7,.5]]],G:[[[.85,.8],[.65,1],[.3,1],[.15,.75],[.15,.25],[.3,0],[.85,0],[.85,.45],[.55,.45]]],H:[[[.15,0],[.15,1]],[[.85,0],[.85,1]],[[.15,.5],[.85,.5]]],I:[[[.25,1],[.75,1]],[[.5,1],[.5,0]],[[.25,0],[.75,0]]],J:[[[.8,1],[.8,.25],[.6,0],[.3,0],[.15,.25]]],K:[[[.15,0],[.15,1]],[[.85,1],[.15,.45],[.85,0]]],L:[[[.15,1],[.15,0],[.85,0]]],M:[[[.1,0],[.1,1],[.5,.35],[.9,1],[.9,0]]],N:[[[.15,0],[.15,1],[.85,0],[.85,1]]],O:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]]],P:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]]],Q:[[[.3,0],[.7,0],[.85,.25],[.85,.75],[.7,1],[.3,1],[.15,.75],[.15,.25],[.3,0]],[[.55,.3],[.9,-.05]]],R:[[[.15,0],[.15,1],[.7,1],[.85,.75],[.7,.5],[.15,.5]],[[.55,.5],[.85,0]]],S:[[[.85,.85],[.65,1],[.3,1],[.15,.75],[.85,.25],[.7,0],[.3,0],[.15,.15]]],T:[[[.1,1],[.9,1]],[[.5,1],[.5,0]]],U:[[[.15,1],[.15,.25],[.35,0],[.65,0],[.85,.25],[.85,1]]],V:[[[.1,1],[.5,0],[.9,1]]],W:[[[.05,1],[.25,0],[.5,.65],[.75,0],[.95,1]]],X:[[[.15,1],[.85,0]],[[.85,1],[.15,0]]],Y:[[[.15,1],[.5,.5],[.85,1]],[[.5,.5],[.5,0]]],Z:[[[.15,1],[.85,1],[.15,0],[.85,0]]],".":[[[.45,0],[.55,0],[.55,.12],[.45,.12],[.45,0]]],",":[[[.5,.15],[.4,-.1]]],":":[[[.45,.1],[.55,.1]],[[.45,.7],[.55,.7]]],"-":[[[.2,.5],[.8,.5]]],"+":[[[.2,.5],[.8,.5]],[[.5,.2],[.5,.8]]],"=":[[[.2,.35],[.8,.35]],[[.2,.65],[.8,.65]]],"/":[[[.2,0],[.8,1]]],"!":[[[.5,1],[.5,.28]],[[.5,.1],[.5,0]]],"?":[[[.2,.8],[.35,1],[.7,1],[.85,.75],[.5,.45],[.5,.28]],[[.5,.1],[.5,0]]],"(":[[[.65,1],[.35,.65],[.35,.35],[.65,0]]],")":[[[.35,1],[.65,.65],[.65,.35],[.35,0]]],"%":[[[.2,0],[.8,1]],[[.2,.8],[.35,.8],[.35,.95],[.2,.95],[.2,.8]],[[.65,.05],[.8,.05],[.8,.2],[.65,.2],[.65,.05]]],"#":[[[.32,0],[.32,1]],[[.68,0],[.68,1]],[[.12,.35],[.88,.35]],[[.12,.65],[.88,.65]]],$:[[[.8,.8],[.6,.92],[.3,.92],[.18,.72],[.82,.28],[.7,.08],[.4,.08],[.2,.2]],[[.5,1],[.5,0]]],_:[[[.1,0],[.9,0]]],"[":[[[.65,1],[.3,1],[.3,0],[.65,0]]],"]":[[[.35,1],[.7,1],[.7,0],[.35,0]]],"<":[[[.75,.85],[.25,.5],[.75,.15]]],">":[[[.25,.85],[.75,.5],[.25,.15]]],"*":[[[.5,.2],[.5,.8]],[[.2,.35],[.8,.65]],[[.2,.65],[.8,.35]]],"\\":[[[.2,1],[.8,0]]]};class le extends u{constructor(A="",L={}){super();let C=String(A??"").slice(0,g),U=Math.max(.005,Math.min(100,b(L.size,.2))),Q=!!(L.bevelEnabled??!1),X=Q?Math.max(0,Math.min(2,b(L.bevelThickness,U*.04))):0,Z=Q?Math.max(0,Math.min(2,b(L.bevelSize,U*.03))):0,J=Math.max(.001,Math.min(20,b(L.depth??L.height,U*.2)))+X*2,K=U*.085+Z,ae=U*.68,ne=U*.82,re=[],me=[],fe=[],ye=[],de=(ve,xe,Ee,Te,Pe,Ce,ke)=>{let tt=Ee-ve,Ze=Te-xe,pt=Math.hypot(tt,Ze),Fe=1,at=0;pt>1e-6&&(Fe=tt/pt,at=Ze/pt);let _e=-at*Pe,Le=Fe*Pe,qe=Fe*Pe*.6,We=at*Pe*.6,Ue=ve-qe+_e,He=xe-We+Le,st=ve-qe-_e,Je=xe-We-Le,ot=Ee+qe-_e,ht=Te+We-Le,ct=Ee+qe+_e,dt=Te+We+Le,Mt=(jt,qt,qi,Yi,Ut,Ot,Wt)=>{let kt=re.length/3;re.push(jt[0],jt[1],jt[2],qt[0],qt[1],qt[2],qi[0],qi[1],qi[2],Yi[0],Yi[1],Yi[2]),me.push(Ut,Ot,Wt,Ut,Ot,Wt,Ut,Ot,Wt,Ut,Ot,Wt),fe.push(0,0,1,0,1,1,0,1),ye.push(kt,kt+1,kt+2,kt,kt+2,kt+3)};Mt([Ue,He,ke],[st,Je,ke],[ot,ht,ke],[ct,dt,ke],0,0,1),Mt([st,Je,Ce],[Ue,He,Ce],[ct,dt,Ce],[ot,ht,Ce],0,0,-1),Mt([Ue,He,Ce],[st,Je,Ce],[st,Je,ke],[Ue,He,ke],-Fe,-at,0),Mt([ot,ht,Ce],[ct,dt,Ce],[ct,dt,ke],[ot,ht,ke],Fe,at,0),Mt([st,Je,Ce],[ot,ht,Ce],[ot,ht,ke],[st,Je,ke],at,-Fe,0),Mt([ct,dt,Ce],[Ue,He,Ce],[Ue,He,ke],[ct,dt,ke],-at,Fe,0)},pe=0,be=0;for(let ve=0;ve<C.length;ve++){let xe=C[ve];if(xe===`
17
+ `){pe=0,be-=U*1.35;continue}if(xe===" "||xe===" "){pe+=ne*(xe===" "?.75:3);continue}if(xe==="\r")continue;let Ee=xe.toUpperCase(),Te=xe!==Ee&&xe>="a"&&xe<="z",Pe=se[Ee]??se["?"],Ce=Te?U*.76:U,ke=Te?ae*.88:ae;for(let tt of Pe)for(let Ze=0;Ze<tt.length-1;Ze++){let pt=tt[Ze],Fe=tt[Ze+1];de(pe+pt[0]*ke,be+pt[1]*Ce,pe+Fe[0]*ke,be+Fe[1]*Ce,K,-J*.5,J*.5)}pe+=Te?ne*.88:ne}S(this,re,me,fe,ye),L.center!==!1?this.center():this.computeBoundingBox()}}function V(R){if(!R)return;let A=R,L=R.userData?.xr?.text??R.userData?.xr?.label??R.userData?.xr?.title??R.userData?.xr?.caption??R.userData?.xr?.spatialLabel;if(L!=null&&L!==!1){let U=A.geometry?.attributes?.position;if((!U||U.count===0)&&R.userData._textApplied!==!0){let Q="",X=.08,Z=.015,J;if(typeof L=="string"||typeof L=="number")Q=String(L);else if(typeof L=="object"){let K=L;Q=String(K.text??K.value??""),K.size!==void 0&&(X=Number(K.size)||.08),(K.depth!==void 0||K.height!==void 0)&&(Z=Number(K.depth??K.height)||X*.2),(typeof K.color=="string"||typeof K.color=="number")&&(J=K.color)}Q.trim().length>0&&(A.geometry=new le(Q,{size:X,depth:Z}),R.userData._textApplied=!0,A.material instanceof h?J!==void 0&&R.userData._autoTextColorApplied!==!0&&(A.material.color=new o(J),R.userData._autoTextColorApplied=!0):A.material=new m({color:J??16317180}))}}let C=R.userData?.csg;if(C&&typeof C=="object"&&R.userData._csgApplied!==!0&&A.geometry instanceof u&&A.geometry.attributes.position?.count>0){R.userData._csgApplied=!0;let U=Array.isArray(C)?C:[C],Q=A.geometry;for(let X of U){if(!X||typeof X!="object")continue;let Z=X,J=String(Z.op??Z.operation??"subtract"),K=J==="union"||J==="intersect"?J:"subtract",ae=Z.target??Z.mesh??Z.geometry;if(ae instanceof c||ae instanceof u)try{let ne=K==="union"?te.union(A,ae):K==="intersect"?te.intersect(A,ae):te.subtract(A,ae);A.geometry!==Q&&A.geometry.dispose?.(),A.geometry=ne.geometry}catch(ne){typeof console<"u"&&console.warn("[three-live] userData.csg skipped:",ne)}}}}let ee={Path:v,Shape:p,ShapeGeometry:E,ExtrudeGeometry:k,TextGeometry:le,CSG:te,MAX_CSG_TRIANGLES:d,MAX_BSP_DEPTH:f,MAX_TEXT_GEOMETRY_CHARS:g,MAX_SHAPE_POINTS:x,materializeDeclarativeGeometry:V};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,ee),t._cadMaterialize=V,t.materializeDeclarativeGeometry=R=>{t._cadMaterialize?.(R),t._lodMaterialize?.(R)}),ee}var Ti={name:"cad",onRegister(){Qt(nr);let e=Ae(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);t&&nr(t,e)}};function Se(){let e=new Float32Array(16);return e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function rr(e,t,r,i,n){let s=1/Math.tan(t/2);e.fill(0),e[0]=s/r,e[5]=s,e[11]=-1;let l=1/(i-n);return e[10]=(n+i)*l,e[14]=2*n*i*l,e}function Jt(e,t,r,i){let[n,s,l]=t,[o,a,u]=i,[h,m,c]=r,d=n-h,f=s-m,g=l-c,x=Math.hypot(d,f,g);x<=1e-5?(d=0,f=0,g=1):(d/=x,f/=x,g/=x);let b=a*g-u*f,v=u*d-o*g,p=o*f-a*d;x=Math.hypot(b,v,p),x<=1e-5?(b=0,v=0,p=0):(b/=x,v/=x,p/=x);let y=f*p-g*v,M=g*b-d*p,P=d*v-f*b;return x=Math.hypot(y,M,P),x<=1e-5?(y=0,M=0,P=0):(y/=x,M/=x,P/=x),e[0]=b,e[1]=y,e[2]=d,e[3]=0,e[4]=v,e[5]=M,e[6]=f,e[7]=0,e[8]=p,e[9]=P,e[10]=g,e[11]=0,e[12]=-(b*n+v*s+p*l),e[13]=-(y*n+M*s+P*l),e[14]=-(d*n+f*s+g*l),e[15]=1,e}function Ie(e,t,r){let i=t[0],n=t[1],s=t[2],l=t[3],o=t[4],a=t[5],u=t[6],h=t[7],m=t[8],c=t[9],d=t[10],f=t[11],g=t[12],x=t[13],b=t[14],v=t[15],p=r[0],y=r[1],M=r[2],P=r[3];return e[0]=p*i+y*o+M*m+P*g,e[1]=p*n+y*a+M*c+P*x,e[2]=p*s+y*u+M*d+P*b,e[3]=p*l+y*h+M*f+P*v,p=r[4],y=r[5],M=r[6],P=r[7],e[4]=p*i+y*o+M*m+P*g,e[5]=p*n+y*a+M*c+P*x,e[6]=p*s+y*u+M*d+P*b,e[7]=p*l+y*h+M*f+P*v,p=r[8],y=r[9],M=r[10],P=r[11],e[8]=p*i+y*o+M*m+P*g,e[9]=p*n+y*a+M*c+P*x,e[10]=p*s+y*u+M*d+P*b,e[11]=p*l+y*h+M*f+P*v,p=r[12],y=r[13],M=r[14],P=r[15],e[12]=p*i+y*o+M*m+P*g,e[13]=p*n+y*a+M*c+P*x,e[14]=p*s+y*u+M*d+P*b,e[15]=p*l+y*h+M*f+P*v,e}function Tt(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=n+n,u=s+s,h=l+l,m=n*a,c=n*u,d=n*h,f=s*u,g=s*h,x=l*h,b=o*a,v=o*u,p=o*h,y=i[0],M=i[1],P=i[2];return e[0]=(1-(f+x))*y,e[1]=(c+p)*y,e[2]=(d-v)*y,e[3]=0,e[4]=(c-p)*M,e[5]=(1-(m+x))*M,e[6]=(g+b)*M,e[7]=0,e[8]=(d+v)*P,e[9]=(g-b)*P,e[10]=(1-(m+f))*P,e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e}function Xe(e,t,r=0){let i=t[0],n=t[1],s=t[2],l=t[4],o=t[5],a=t[6],u=t[8],h=t[9],m=t[10],c=m*o-a*h,d=-m*l+a*u,f=h*l-o*u,g=i*c+n*d+s*f;return!g||r>0&&(!Number.isFinite(g)||Math.abs(g)<=r)||(g=1/g,e[0]=c*g,e[1]=d*g,e[2]=f*g,e[3]=(-m*n+s*h)*g,e[4]=(m*i-s*u)*g,e[5]=(-h*i+n*u)*g,e[6]=(a*n-s*o)*g,e[7]=(-a*i+s*l)*g,e[8]=(o*i-n*l)*g),e}function en(e,t){let r=t[0],i=t[1],n=t[2],s=t[3],l=t[4],o=t[5],a=t[6],u=t[7],h=t[8],m=t[9],c=t[10],d=t[11],f=t[12],g=t[13],x=t[14],b=t[15],v=r*o-i*l,p=r*a-n*l,y=r*u-s*l,M=i*a-n*o,P=i*u-s*o,F=n*u-s*a,W=h*g-m*f,T=h*x-c*f,E=h*b-d*f,S=m*x-c*g,O=m*b-d*g,k=c*b-d*x,w=v*k-p*O+y*S+M*E-P*T+F*W;return w?(w=1/w,e[0]=(o*k-a*O+u*S)*w,e[1]=(n*O-i*k-s*S)*w,e[2]=(g*F-x*P+b*M)*w,e[3]=(c*P-m*F-d*M)*w,e[4]=(a*E-l*k-u*T)*w,e[5]=(r*k-n*E+s*T)*w,e[6]=(x*y-f*F-b*p)*w,e[7]=(h*F-c*y+d*p)*w,e[8]=(l*O-o*E+u*W)*w,e[9]=(i*E-r*O-s*W)*w,e[10]=(f*P-g*y+b*v)*w,e[11]=(m*y-h*P-d*v)*w,e[12]=(o*T-l*S-a*W)*w,e[13]=(r*S-i*T+n*W)*w,e[14]=(g*p-f*M-x*v)*w,e[15]=(h*M-m*p+c*v)*w,e):null}function Ai(e,t,r,i,n){let s=n[0]*t+n[4]*r+n[8]*i+n[12],l=n[1]*t+n[5]*r+n[9]*i+n[13],o=n[2]*t+n[6]*r+n[10]*i+n[14],a=n[3]*t+n[7]*r+n[11]*i+n[15],u=a!==0?1/a:1;e[0]=s*u,e[1]=l*u,e[2]=o*u}function Go(e,t,r,i,n,s,l,o,a,u,h,m,c,d,f,g,x=0){let b=u-l,v=h-o,p=m-a,y=c-l,M=d-o,P=f-a,F=n*P-s*M,W=s*y-i*P,T=i*M-n*y,E=b*F+v*W+p*T;if(E>-1e-7&&E<1e-7)return!1;let S=1/E,O=e-l,k=t-o,w=r-a,ie=S*(O*F+k*W+w*T);if(ie<-x||ie>1+x)return!1;let oe=k*p-w*v,I=w*b-O*p,H=O*v-k*b,N=S*(i*oe+n*I+s*H);if(N<-x||ie+N>1+x)return!1;let z=S*(y*oe+M*I+P*H);if(z>1e-4&&z<g.distance){g.distance=z,g.point=[e+i*z,t+n*z,r+s*z];let ue=v*P-p*M,ce=p*y-b*P,B=b*M-v*y,$=Math.hypot(ue,ce,B)||1;return g.normal=[ue/$,ce/$,B/$],!0}return!1}function Ft(e,t){let r=Array.isArray(e?.nodes)?e.nodes.length:0,i=[];for(let h=0;h<r;h++)i.push(Se());if(r===0)return i;let n=new Set;for(let h of e.nodes)if(Array.isArray(h.children))for(let m of h.children)n.add(m);let s=new Set,l=128,o=(h,m,c=0)=>{if(c>l||h<0||h>=r||s.has(h))return;s.add(h);let d=e.nodes[h];if(!d)return;let f=Se();if(t&&t[h])f.set(t[h]);else if(d.matrix&&d.matrix.length===16)f.set(d.matrix);else{let x=d.translation||[0,0,0],b=d.rotation||[0,0,0,1],v=d.scale||[1,1,1];Tt(f,b,x,v)}let g=i[h];if(m?Ie(g,m,f):g.set(f),Array.isArray(d.children))for(let x of d.children)typeof x=="number"&&o(x,g,c+1)},a=[],u=e.scenes&&e.scenes[e.scene!==void 0?e.scene:0];if(u&&Array.isArray(u.nodes))a.push(...u.nodes);else for(let h=0;h<r;h++)n.has(h)||a.push(h);for(let h of a)o(h,null);for(let h=0;h<r;h++)!n.has(h)&&!a.includes(h)&&o(h,null);return i}function Ei(e,t){function r(a,u,h,m){let c=typeof a=="number"?a:Number(a);return Number.isFinite(c)?Math.max(u,Math.min(h,c)):m}function i(a,u){let h=a[0]*u[0]+a[1]*u[1]+a[2]*u[2]+1;if(h<1e-6){if(Math.abs(a[0])>Math.abs(a[2])){let x=Math.hypot(a[1],a[0])||1;return[-a[1]/x,a[0]/x,0,0]}let g=Math.hypot(a[2],a[1])||1;return[0,-a[2]/g,a[1]/g,0]}let m=a[1]*u[2]-a[2]*u[1],c=a[2]*u[0]-a[0]*u[2],d=a[0]*u[1]-a[1]*u[0],f=Math.hypot(m,c,d,h)||1;return[m/f,c/f,d/f,h/f]}function n(a,u,h,m,c){let d=u[0]-a[0],f=u[1]-a[1],g=u[2]-a[2],x=Math.hypot(d,f,g),b=h[0]-u[0],v=h[1]-u[1],p=h[2]-u[2],y=Math.hypot(b,v,p);if(x<1e-6||y<1e-6)return{rootPos:[a[0],a[1],a[2]],midPos:[u[0],u[1],u[2]],effectorPos:[h[0],h[1],h[2]],rootRotation:[0,0,0,1],midRotation:[0,0,0,1]};let M=[d/x,f/x,g/x],P=[b/y,v/y,p/y],F=m[0]-a[0],W=m[1]-a[1],T=m[2]-a[2],E=Math.hypot(F,W,T),S=E>1e-6?[F/E,W/E,T/E]:M,O=Math.abs(x-y)+1e-5,k=Math.max(O,x+y-1e-5),w=Math.max(O,Math.min(k,E>1e-6?E:O)),ie=r((x*x+w*w-y*y)/(2*x*w),-1,1,1),oe=Math.sqrt(Math.max(0,1-ie*ie)),I=c?c[0]-a[0]:d,H=c?c[1]-a[1]:f,N=c?c[2]-a[2]:g,z=I*S[0]+H*S[1]+N*S[2],ue=I-S[0]*z,ce=H-S[1]*z,B=N-S[2]*z,$=Math.hypot(ue,ce,B);if($<=1e-6){let ee=Math.abs(S[1])<.99?0:1,R=Math.abs(S[1])<.99?1:0,A=0;ue=S[1]*A-S[2]*R,ce=S[2]*ee-S[0]*A,B=S[0]*R-S[1]*ee,$=Math.hypot(ue,ce,B)||1}let _=[ue/$,ce/$,B/$],G=[a[0]+S[0]*(x*ie)+_[0]*(x*oe),a[1]+S[1]*(x*ie)+_[1]*(x*oe),a[2]+S[2]*(x*ie)+_[2]*(x*oe)],j=[a[0]+S[0]*w,a[1]+S[1]*w,a[2]+S[2]*w],q=j[0]-G[0],D=j[1]-G[1],Y=j[2]-G[2],te=Math.hypot(q,D,Y),se=te>1e-6?[q/te,D/te,Y/te]:S,le=[G[0]+se[0]*y,G[1]+se[1]*y,G[2]+se[2]*y],V=[(G[0]-a[0])/x,(G[1]-a[1])/x,(G[2]-a[2])/x];return{rootPos:[a[0],a[1],a[2]],midPos:G,effectorPos:le,rootRotation:i(M,V),midRotation:i(P,se)}}function s(a,u,h=8,m=.001){let c=a.length;if(c<2)return{positions:a.map(E=>[E[0],E[1],E[2]]),rotations:[],iterations:0};let d=a.map(E=>[E[0],E[1],E[2]]),f=[],g=[],x=0;for(let E=0;E<c-1;E++){let S=d[E+1][0]-d[E][0],O=d[E+1][1]-d[E][1],k=d[E+1][2]-d[E][2],w=Math.hypot(S,O,k);f.push(w),x+=w,g.push(w>1e-6?[S/w,O/w,k/w]:[0,1,0])}let b=[d[0][0],d[0][1],d[0][2]],v=Math.round(r(h,1,32,8)),p=r(m,1e-5,.1,.001),y=u[0]-b[0],M=u[1]-b[1],P=u[2]-b[2],F=Math.hypot(y,M,P),W=0;if(F>=x&&x>1e-6){let E=F>1e-6?[y/F,M/F,P/F]:g[0];d[0]=[b[0],b[1],b[2]];for(let S=0;S<c-1;S++){let O=f[S];d[S+1]=[d[S][0]+E[0]*O,d[S][1]+E[1]*O,d[S][2]+E[2]*O]}W=1}else for(let E=1;E<=v;E++){let S=d[c-1];if(Math.hypot(S[0]-u[0],S[1]-u[1],S[2]-u[2])<=p)break;W=E;let O=(k,w,ie,oe,I)=>{let H=w[0]-k[0],N=w[1]-k[1],z=w[2]-k[2],ue=Math.hypot(H,N,z);if(ue>1e-6){let ce=ie/ue;return[k[0]+H*ce,k[1]+N*ce,k[2]+z*ce]}return[k[0]+oe[0]*ie*I,k[1]+oe[1]*ie*I,k[2]+oe[2]*ie*I]};d[c-1]=[u[0],u[1],u[2]];for(let k=c-2;k>=0;k--)d[k]=O(d[k+1],d[k],f[k],g[k],-1);d[0]=[b[0],b[1],b[2]];for(let k=0;k<c-1;k++)d[k+1]=O(d[k],d[k+1],f[k],g[k],1)}let T=[];for(let E=0;E<c-1;E++){let S=d[E+1][0]-d[E][0],O=d[E+1][1]-d[E][1],k=d[E+1][2]-d[E][2],w=Math.hypot(S,O,k),ie=w>1e-6?[S/w,O/w,k/w]:g[E];T.push(i(g[E],ie))}return{positions:d,rotations:T,iterations:W}}function l(a){if(!a||typeof a!="object"||Array.isArray(a))return null;let u=a;if(u.enabled===!1)return null;let h=p=>{if(typeof p!="string")return;let y=p.trim().slice(0,64);return/^[A-Za-z0-9_.:-]+$/.test(y)?y:void 0},m=p=>Array.isArray(p)&&p.length===3&&p.every(y=>typeof y=="number"&&Number.isFinite(y))?[r(p[0],-1e3,1e3,0),r(p[1],-1e3,1e3,0),r(p[2],-1e3,1e3,0)]:void 0,c=h(u.root),d=h(u.effector);if(!c||!d)return null;let f=h(u.mid),g=m(u.target)??h(u.target);if(!g)return null;let x=u.pole??u.poleTarget,b=m(x)??h(x),v=u.solver==="fabrik"?"fabrik":u.solver==="two-bone"||f?"two-bone":"fabrik";return{root:c,...f?{mid:f}:{},effector:d,target:g,...b?{pole:b}:{},solver:v,iterations:Math.round(r(u.iterations,1,32,8)),tolerance:r(u.tolerance,1e-5,.1,.001),weight:r(u.weight,0,1,1)}}let o=Object.freeze({solveTwoBone:n,solveFABRIK:s,parseIKTrait:l});return t&&typeof t=="object"&&(t.authorNamespace=t.authorNamespace||{},t.authorNamespace.IKSolver=o),{clampNum:r,parseIKTrait:l,quatFromUnitVectors:i,solveTwoBoneIK:n,solveFABRIK:s,IKSolver:o}}var tn=Ei(),Xo=tn.clampNum,Va=tn.parseIKTrait,or=tn.quatFromUnitVectors,Li=tn.solveTwoBoneIK,Ii=tn.solveFABRIK,$o=tn.IKSolver;function Ri(e){let t=e?.transform??e?.modelMatrix;return t&&t.length>=16?[t[12]||0,t[13]||0,t[14]||0]:[0,0,0]}function Ba(e,t){let r=e?.transform??e?.modelMatrix;!r||r.length<16||(r[12]=t[0],r[13]=t[1],r[14]=t[2])}function za(e,t,r,i,n){let s=Xo(n,0,1,1),l=t[0]+(r[0]-t[0])*s,o=t[1]+(r[1]-t[1])*s,a=t[2]+(r[2]-t[2])*s,u=l-e[0],h=o-e[1],m=a-e[2],c=Math.hypot(u,h,m);if(c>1e-6&&i>1e-6){let b=i/c;return[e[0]+u*b,e[1]+h*b,e[2]+m*b]}let d=r[0]-e[0],f=r[1]-e[1],g=r[2]-e[2],x=Math.hypot(d,f,g);if(x>1e-6&&i>1e-6){let b=i/x;return[e[0]+d*b,e[1]+f*b,e[2]+g*b]}return[l,o,a]}function Ga(e,t){let r=e?.modelRootMatrix;if(!r||r.length!==16)return t;let i=new Float32Array(16);return en(i,r instanceof Float32Array?r:Float32Array.from(r))?[i[0]*t[0]+i[4]*t[1]+i[8]*t[2]+i[12],i[1]*t[0]+i[5]*t[1]+i[9]*t[2]+i[13],i[2]*t[0]+i[6]*t[1]+i[10]*t[2]+i[14]]:t}function wi(e,t){e.__ikWarned||(e.__ikWarned=new Set);let r=e.__ikWarned;r.has(t)||(r.add(t),console.warn(`[three-live] ik: joint '${t}' on '${e?.name??""}' not found among scene nodes or meshes.`))}function _i(e,t,r){if(Array.isArray(e))return[e[0],e[1],e[2]];let i=t.get(e);if(i)return Ri(i);let n;if(e==="head"?n=r?.headPose?.position??r?.headPose??r?.cameraPosition:e==="hand-left"?n=r?.handPoses?.left?.position??r?.handPoses?.left??r?.hands?.left?.position??r?.hands?.left:e==="hand-right"&&(n=r?.handPoses?.right?.position??r?.handPoses?.right??r?.hands?.right?.position??r?.hands?.right),(Array.isArray(n)||ArrayBuffer.isView(n))&&n.length>=3){let s=n;return Ga(r,[s[0],s[1],s[2]])}return null}function Si(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function Ha(e){return[-e[0],-e[1],-e[2],e[3]]}function Ci(e){let t=Math.hypot(e[0],e[1],e[2],e[3]);return t>1e-12?[e[0]/t,e[1]/t,e[2]/t,e[3]/t]:[0,0,0,1]}function Xa(e,t){if(t>=1)return e;if(t<=0)return[0,0,0,1];let[r,i,n,s]=e;s<0&&(r=-r,i=-i,n=-n,s=-s);let l=Math.acos(Math.min(1,s)),o=Math.sin(l);if(o<1e-9)return[0,0,0,1];let a=Math.sin(l*t)/o;return Ci([r*a,i*a,n*a,Math.cos(l*t)])}function $a(e){let t=Math.hypot(e[0],e[1],e[2])||1,r=Math.hypot(e[4],e[5],e[6])||1,i=Math.hypot(e[8],e[9],e[10])||1,n=e[0]/t,s=e[1]/t,l=e[2]/t,o=e[4]/r,a=e[5]/r,u=e[6]/r,h=e[8]/i,m=e[9]/i,c=e[10]/i,d=n+a+c,f;if(d>0){let g=Math.sqrt(d+1)*2;f=[(u-m)/g,(h-l)/g,(s-o)/g,.25*g]}else if(n>a&&n>c){let g=Math.sqrt(1+n-a-c)*2;f=[.25*g,(o+s)/g,(h+l)/g,(u-m)/g]}else if(a>c){let g=Math.sqrt(1+a-n-c)*2;f=[(o+s)/g,.25*g,(m+u)/g,(h-l)/g]}else{let g=Math.sqrt(1+c-n-a)*2;f=[(h+l)/g,(m+u)/g,.25*g,(s-o)/g]}return Ci(f)}function Wa(e,t,r){let[i,n,s,l]=r,o=1-2*(n*n+s*s),a=2*(i*n-s*l),u=2*(i*s+n*l),h=2*(i*n+s*l),m=1-2*(i*i+s*s),c=2*(n*s-i*l),d=2*(i*s-n*l),f=2*(n*s+i*l),g=1-2*(i*i+n*n);for(let x=0;x<3;x++){let b=t[x*4],v=t[x*4+1],p=t[x*4+2];e[x*4]=o*b+a*v+u*p,e[x*4+1]=h*b+m*v+c*p,e[x*4+2]=d*b+f*v+g*p}}function ir(e,t){let r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],s=Math.hypot(r,i,n);return s>1e-9?[r/s,i/s,n/s]:null}function Wo(e){e?.normalMatrix&&e?.transform&&Xe(e.normalMatrix,e.transform)}var Ho=new WeakMap;function ja(e){let t=Ho.get(e);return t||(t=new Int32Array(e.nodes.length).fill(-1),e.nodes.forEach((r,i)=>{for(let n of Array.isArray(r?.children)?r.children:[])typeof n=="number"&&n>=0&&n<t.length&&(t[n]=i)}),Ho.set(e,t)),t}function Ka(e,t,r){let i=e?.gltf,n=i?.nodes;if(!Array.isArray(n)||n.length===0)return!1;let s=new Map;n.forEach((T,E)=>{typeof T?.name=="string"&&T.name&&!s.has(T.name)&&s.set(T.name,E)});let l=(t.mid?[t.root,t.mid,t.effector]:[t.root,t.effector]).map(T=>s.get(T));if(l.some(T=>T===void 0))return!1;let o=l,a=ja(i);for(let T=1;T<o.length;T++){let E=a[o[T]],S=0;for(;E>=0&&E!==o[T-1]&&S++<256;)E=a[E];if(E!==o[T-1])return!1}let u=o[0],h=e.initialNodeTransforms,m=new Map,c=[],d=[u];for(;d.length&&c.length<4096;){let T=d.pop();if(m.has(T))continue;let E=h?.[T],S=n[T];m.set(T,{t:E?[E.t[0],E.t[1],E.t[2]]:S?.translation?[...S.translation]:[0,0,0],r:E?[E.r[0],E.r[1],E.r[2],E.r[3]]:S?.rotation?[...S.rotation]:[0,0,0,1],s:E?[E.s[0],E.s[1],E.s[2]]:S?.scale?[...S.scale]:[1,1,1]}),c.push(T);for(let O of Array.isArray(S?.children)?S.children:[])typeof O=="number"&&d.push(O)}let f=a[u],g=f>=0&&e.worldMatrices?.[f]?.length===16?Float32Array.from(e.worldMatrices[f]):Se(),x=new Map,b=()=>{let T=(E,S)=>{let O=m.get(E);if(!O)return;let k=Se();Tt(k,O.r,O.t,O.s);let w=Se();Ie(w,S,k),x.set(E,w);for(let ie of Array.isArray(n[E]?.children)?n[E].children:[])typeof ie=="number"&&T(ie,w)};T(u,g)},v=T=>{let E=x.get(T);return[E[12],E[13],E[14]]};b();let p=o.map(v),y=T=>{if(typeof T=="string"&&!r.has(T)){let E=s.get(T),S=E!==void 0?x.get(E)??e.worldMatrices?.[E]:void 0;if(S&&S.length===16)return[S[12],S[13],S[14]]}return _i(T,r,e)},M=y(t.target);if(!M)return!0;let P=t.pole?y(t.pole)??void 0:void 0,F=jo(p,t,M,P),W=Xo(t.weight,0,1,1);for(let T=0;T<o.length-1;T++){let E=ir(v(o[T]),v(o[T+1])),S=ir(F[T],F[T+1]);if(!E||!S)continue;let O=Xa(or(E,S),W),k=o[T],w=a[k],ie=w===f||w<0?g:x.get(w)??g,oe=$a(ie),I=m.get(k);I.r=Ci(Si(Ha(oe),Si(O,Si(oe,I.r)))),b()}if(Array.isArray(e.worldMatrices))for(let[T,E]of x)e.worldMatrices[T]?.set&&e.worldMatrices[T].set(E);for(let T of e.meshes??[]){let E=x.get(T?.nodeIndex);E&&T.transform?.set&&(T.transform.set(E),Wo(T))}return!0}function jo(e,t,r,i){if(t.solver==="two-bone"&&e.length===3){let n=Li(e[0],e[1],e[2],r,i);return[e[0],n.midPos,n.effectorPos]}return Ii(e,r,t.iterations,t.tolerance).positions}function qa(e,t,r){let i=e.__ikRestOffsets,n=e.__ikRestMats;if(!(!i||!n))for(let s=0;s<t.length-1;s++){let l=t[s]?.transform??t[s]?.modelMatrix,o=n[s],a=ir([0,0,0],i[s]),u=ir(r[s],r[s+1]);!l||l.length<16||!o||o.length<16||!a||!u||(Wa(l,o,or(a,u)),Wo(t[s]))}}var Di={name:"ik",onRegister(){let e=Ae();Qt(Ei),Ei(e.threeNamespace,e)},onUpdate(e){let t=e?.meshes;if(!Array.isArray(t)||t.length===0)return;let r=null;for(let i of t){let n=i?.userData?.xr?.ik??i?.extras?.xr?.ik??i?.extensions?.ANDROID_xr_scenecore?.ik;if(!n)continue;let s=Va(n);if(!s||s.weight<=0)continue;if(!r){r=new Map;for(let p of t)p&&typeof p.name=="string"&&p.name&&r.set(p.name,p)}if(Ka(e,s,r))continue;let l=r.get(s.root),o=r.get(s.effector),a=s.mid?r.get(s.mid):void 0;if(l||wi(i,s.root),o||wi(i,s.effector),s.mid&&!a&&wi(i,s.mid),!l||!o)continue;let u=_i(s.target,r,e);if(!u)continue;let h=s.pole?_i(s.pole,r,e)??void 0:void 0,m=a?[l,a,o]:[l,o],c=m.map(p=>p.name||"").join(">");if(!i.__ikRestOffsets||i.__ikRestKey!==c){let p=m.map(Ri),y=[];for(let M=0;M<p.length-1;M++)y.push([p[M+1][0]-p[M][0],p[M+1][1]-p[M][1],p[M+1][2]-p[M][2]]);i.__ikRestOffsets=y,i.__ikRestKey=c,i.__ikRestMats=m.map(M=>Array.from(M.transform??M.modelMatrix??[]))}let d=i.__ikRestOffsets,f=[Ri(l)],g=[];for(let p=0;p<d.length;p++){let y=f[p],M=d[p];f.push([y[0]+M[0],y[1]+M[1],y[2]+M[2]]),g.push(Math.hypot(M[0],M[1],M[2]))}let x=jo(f,s,u,h),b=f[0],v=[f[0]];for(let p=1;p<m.length;p++){let y=d[p-1],M=[b[0]+y[0],b[1]+y[1],b[2]+y[2]],P=[b[0]+(x[p][0]-x[p-1][0]),b[1]+(x[p][1]-x[p-1][1]),b[2]+(x[p][2]-x[p-1][2])],F=za(b,M,P,g[p-1],s.weight);Ba(m[p],F),b=F,v.push(F)}qa(i,m,v)}}};function gn(e,t){let r=(h,m,c,d)=>{let f=typeof h=="number"?h:Number(h);return Number.isFinite(f)?Math.max(m,Math.min(c,f)):d};function i(h,m,c=0,d=.05,f){if(!h||!h.length)return-1;let g=h[0]>0?[0,...h]:h,x=Number.isFinite(m)?Math.max(0,m):0,b=Number.isFinite(d)?Math.max(0,Math.min(.5,d)):.05;if(typeof f=="number"&&Number.isFinite(f)&&f>0){let y=c===-1?f*(1-b):f*(1+b);if(x>y)return-1}let v=0;for(let y=g.length-1;y>=1;y--)if(x>=g[y]){v=y;break}if(c<0||c>=g.length||c===v)return v;if(v>c){let y=c;for(let M=c+1;M<=v&&x>=g[M]*(1+b);M++)y=M;return y}let p=c;for(let y=c;y>v&&x<g[y]*(1-b);y--)p=y-1;return p}function n(h){if(!h)return null;let m=h===!0?{distances:[4,10],ratios:[.5,.25]}:Array.isArray(h)?{distances:h}:typeof h=="object"?h:null;if(!m||m.enabled===!1)return null;let c=r(m.hysteresis,0,.5,.05),d=[],f;if(Array.isArray(m.levels)&&m.levels.length>0){let v=m.levels.slice(0,8);for(let y=0;y<v.length;y++){let M=v[y];if(!M||typeof M!="object"||Array.isArray(M))continue;let P=M,F=r(P.distance,0,1e4,y===0?0:y*4),W=typeof P.hysteresis=="number"?r(P.hysteresis,0,.5,c):void 0,T=typeof P.ratio=="number"?r(P.ratio,.05,1,.5):void 0,E=typeof P.childIndex=="number"&&Number.isFinite(P.childIndex)?Math.max(0,Math.round(P.childIndex)):void 0,S=typeof P.node=="string"&&/^[A-Za-z0-9_.:-]+$/.test(P.node.trim())?P.node.trim().slice(0,64):void 0;d.push({distance:F,...W!==void 0?{hysteresis:W}:{},...T!==void 0?{ratio:T}:{},...E!==void 0?{childIndex:E}:{},...S?{node:S}:{}})}d.sort((y,M)=>y.distance-M.distance),d.length>0&&d[0].distance>0&&d.unshift({distance:0,childIndex:0});let p=0;d=d.slice(0,8).map((y,M)=>{let P=M===0?0:Math.max(p,y.distance);return p=P,{...y,distance:P,childIndex:y.childIndex??M}})}if(Array.isArray(m.ratios)&&m.ratios.length>0){let v=[];for(let p of m.ratios.slice(0,7))typeof p=="number"&&v.push(r(p,.05,1,.5));v.length>0&&(f=v)}if(d.length===0){let v=Array.isArray(m.distances)?m.distances:[],p=[];for(let M of v.slice(0,8))typeof M=="number"&&p.push(r(M,0,1e4,4));if(p.length===0&&f&&f.length>0)for(let M=0;M<f.length;M++)p.push((M+1)*4);if(p.length===0&&m.cullDistance===void 0)return null;p.length===0||p[0]>0?p.unshift(0):f&&f.length===p.length&&f[0]===1&&(f=f.slice(1));let y=0;for(let M=0;M<Math.min(8,p.length);M++){let P=M===0?0:Math.max(y,p[M]);y=P;let F=M>0&&f?f[M-1]:void 0;d.push({distance:P,childIndex:M,...F!==void 0?{ratio:F}:{}})}}else if(!f){let v=[];for(let p=1;p<d.length;p++)typeof d[p].ratio=="number"&&v.push(d[p].ratio);v.length>0&&(f=v)}let g=d.map(v=>v.distance),x=g[g.length-1]??0,b=m.cullDistance!==void 0&&m.cullDistance!==null&&m.cullDistance!==!1?r(m.cullDistance,Math.max(1,x),1e4,100):void 0;return{levels:d,distances:g,...f?{ratios:f}:{},hysteresis:c,...b!==void 0?{cullDistance:b}:{}}}function s(h,m){let c=h?.attributes?.position;if(!c||!c.array||c.count<3)return h;let d=r(m,.05,1,.5),f=c.array,g=c.count,x=h.attributes?.normal?.array,b=h.attributes?.uv?.array,v=h.index?.array,p=Math.floor((v?v.length:g)/3);if(p<1)return h;let y=Math.max(1,Math.min(p,Math.round(p*d))),M=1/0,P=1/0,F=1/0,W=-1/0,T=-1/0,E=-1/0;for(let $=0;$<g;$++){let _=f[$*3],G=f[$*3+1],j=f[$*3+2];_<M&&(M=_),G<P&&(P=G),j<F&&(F=j),_>W&&(W=_),G>T&&(T=G),j>E&&(E=j)}let S=Math.max(1e-5,W-M),O=Math.max(1e-5,T-P),k=Math.max(1e-5,E-F),w=Math.max(S,O,k),ie=$=>{let _=Math.max(1,Math.round(S/w*$)),G=Math.max(1,Math.round(O/w*$)),j=Math.max(1,Math.round(k/w*$)),q=new Map,D=new Int32Array(g),Y=[],te=[],se=[],le=[];for(let C=0;C<g;C++){let U=f[C*3],Q=f[C*3+1],X=f[C*3+2],Z=Math.min(_-1,Math.max(0,Math.floor((U-M)/S*_))),J=Math.min(G-1,Math.max(0,Math.floor((Q-P)/O*G))),K=Math.min(j-1,Math.max(0,Math.floor((X-F)/k*j))),ae=Z+J*_+K*_*G,ne=q.get(ae);ne===void 0?(ne=le.length,q.set(ae,ne),Y.push(U,Q,X),x&&te.push(x[C*3],x[C*3+1],x[C*3+2]),b&&se.push(b[C*2],b[C*2+1]),le.push(1)):(Y[ne*3]+=U,Y[ne*3+1]+=Q,Y[ne*3+2]+=X,x&&(te[ne*3]+=x[C*3],te[ne*3+1]+=x[C*3+1],te[ne*3+2]+=x[C*3+2]),le[ne]++),D[C]=ne}let V=[],ee=new Set;for(let C=0;C<p;C++){let U=v?v[C*3]:C*3,Q=v?v[C*3+1]:C*3+1,X=v?v[C*3+2]:C*3+2,Z=D[U],J=D[Q],K=D[X];if(Z===J||J===K||K===Z)continue;let ae=Math.min(Z,J,K),ne=Math.max(Z,J,K),re=Z+J+K-ae-ne,me=`${ae}_${re}_${ne}`;ee.has(me)||(ee.add(me),V.push(Z,J,K))}let R=le.length,A=new Float32Array(R*3),L=x?new Float32Array(R*3):null;for(let C=0;C<R;C++){let U=1/le[C];if(A[C*3]=Y[C*3]*U,A[C*3+1]=Y[C*3+1]*U,A[C*3+2]=Y[C*3+2]*U,L){let Q=te[C*3],X=te[C*3+1],Z=te[C*3+2],J=Math.hypot(Q,X,Z)||1;L[C*3]=Q/J,L[C*3+1]=X/J,L[C*3+2]=Z/J}}return{pos:A,norm:L,uv:b?new Float32Array(se):null,tris:V,triCount:V.length/3,vertCount:R}},oe=Math.max(2,Math.round(Math.sqrt(y/4))),I=ie(oe);if(I.triCount>y*1.25&&oe>2){let $=Math.max(2,Math.round(oe*Math.sqrt(y/I.triCount)));if($!==oe){let _=ie($);_.triCount>=Math.min(4,y)&&(I=_)}}else if(I.triCount<Math.min(4,y)){let $=ie(Math.max(oe*2,8));$.triCount>I.triCount&&(I=$)}let H=I.tris;if(d<1&&I.triCount>y){let $=[],_=I.triCount/y;for(let G=0;G<y;G++){let j=Math.min(I.triCount-1,Math.floor(G*_));$.push(I.tris[j*3],I.tris[j*3+1],I.tris[j*3+2])}H=$}if(H.length<3){H=[];for(let $=0;$<y*3;$++)H.push(v?v[$]:$);I={pos:f.slice(),norm:x?x.slice():null,uv:b?b.slice():null,tris:H,triCount:y,vertCount:g}}let N=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),z=N?.BufferGeometry??h.constructor,ue=N?.BufferAttribute??c.constructor,ce=new z;ce.setAttribute("position",new ue(I.pos,3)),I.norm&&ce.setAttribute("normal",new ue(I.norm,3)),I.uv&&ce.setAttribute("uv",new ue(I.uv,2));let B=I.vertCount>65535?new Uint32Array(H):new Uint16Array(H);return typeof ce.setIndex=="function"?ce.setIndex(new ue(B,1)):ce.index=new ue(B,1),ce}let l=e?.Object3D??t?.threeNamespace?.Object3D??class{constructor(){this.name="",this.position={x:0,y:0,z:0},this.rotation={x:0,y:0,z:0},this.quaternion={x:0,y:0,z:0,w:1},this.scale={x:1,y:1,z:1},this.visible=!0,this.parent=null,this.children=[],this.userData={}}add(...h){for(let m of h)m&&(m.parent=this,this.children.push(m));return this}};class o extends l{constructor(){super(),this.isLOD=!0,this.type="LOD",this.autoUpdate=!0,this.levels=[],this._currentLevel=0}addLevel(m,c=0,d=.05){if(!m)return this;let f=Math.max(0,Number.isFinite(Number(c))?Number(c):0),g=r(d,0,.5,.05),x=this.levels.length;for(let p=0;p<this.levels.length;p++)if(f<this.levels[p].distance){x=p;break}this.levels.splice(x,0,{object:m,distance:f,hysteresis:g}),this.add(m);let b=this.levels.map(p=>p.object),v=this.children.filter(p=>!b.includes(p));this.children=[...b,...v];for(let p=0;p<this.levels.length;p++)this.levels[p].object.visible=p===this._currentLevel;return this.syncUserDataTrait(),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(m){if(!this.levels.length)return null;let c=i(this.levels.map(d=>d.distance),m,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);return c>=0&&c<this.levels.length?this.levels[c].object:null}update(m){if(this.levels.length===0||!m)return;let c=m.position??{x:0,y:0,z:0},d=this.position??{x:0,y:0,z:0},f=Math.hypot((Number(c.x)||0)-(Number(d.x)||0),(Number(c.y)||0)-(Number(d.y)||0),(Number(c.z)||0)-(Number(d.z)||0)),g=i(this.levels.map(x=>x.distance),f,this._currentLevel,this.levels[0]?.hysteresis??.05,this.userData?.xr?.lod?.cullDistance);this._currentLevel=g;for(let x=0;x<this.levels.length;x++)this.levels[x].object.visible=x===g}syncUserDataTrait(){this.userData=this.userData||{},this.userData.xr=this.userData.xr||{};let m=this.userData.xr.lod?.cullDistance;this.userData.xr.lod={levels:this.levels.map((c,d)=>({distance:c.distance,hysteresis:c.hysteresis,childIndex:d,...c.object?.name?{node:c.object.name}:{}})),distances:this.levels.map(c=>c.distance),hysteresis:this.levels[0]?.hysteresis??.05,...m!==void 0?{cullDistance:m}:{}}}}function a(h){if(!h||h._lodMaterialized||!h.userData?.xr?.lod||h.isLOD||Array.isArray(h.children)&&h.children.length>0)return;let m=h.geometry?.attributes?.position;if(!m||!m.array||m.count<3)return;let c=n(h.userData.xr.lod);if(!c||c.levels.length<2)return;h._lodMaterialized=!0;let d=h.geometry;h._lodOriginalGeometry=d;let f=e??t?.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0),g=f?.Mesh??h.constructor,x=f?.BufferGeometry??d.constructor,b=typeof h.name=="string"&&h.name.trim()?h.name.trim():"Mesh",v=new g(d,h.material);v.name=`${b}_LOD0`,v.visible=!0,v.castShadow=!!h.castShadow,v.receiveShadow=!!h.receiveShadow,h.add(v);for(let p=1;p<c.levels.length;p++){let y=c.levels[p].ratio??c.ratios?.[p-1]??Math.max(.05,Math.pow(.5,p)),M=s(d,y),P=new g(M,h.material);P.name=`${b}_LOD${p}`,P.visible=!1,P.castShadow=!!h.castShadow,P.receiveShadow=!!h.receiveShadow,h.add(P)}h.geometry=new x,h.userData.xr.lod={...c,levels:c.levels.map((p,y)=>({...p,childIndex:y,node:`${b}_LOD${y}`}))}}let u={LOD:o,decimateGeometry:s,selectLodLevelIndex:i,parseLod:n,materializeLodGeometry:a};return t&&typeof t=="object"&&(t.authorNamespace||(t.authorNamespace={}),Object.assign(t.authorNamespace,{LOD:o,decimateGeometry:s}),t._lodMaterialize=a,t.materializeDeclarativeGeometry=h=>{t._cadMaterialize?.(h),t._lodMaterialize?.(h)}),u}var vn=gn(),Ko=vn.decimateGeometry,sr=vn.selectLodLevelIndex,ar=vn.parseLod,Pu=vn.materializeLodGeometry,qo=vn.LOD,yn=new WeakMap;function Yo(e){return e&&typeof e=="object"?yn.get(e):void 0}var xn=class{constructor(e,t){this.groups=[],this.viewer=e,this.gltf=t,this.rebuild()}rebuild(){this.groups.length=0;let e=this.gltf?.nodes;if(!Array.isArray(e)||e.length===0)return;let t=new Map;for(let i of this.viewer?.meshes??[])if(typeof i?.nodeIndex=="number"&&i.nodeIndex>=0){let n=t.get(i.nodeIndex);n||(n=[],t.set(i.nodeIndex,n)),n.push(i)}let r=i=>{let n=[],s=new Set,l=[i];for(;l.length>0;){let o=l.pop();if(s.has(o)||o<0||o>=e.length)continue;s.add(o);let a=t.get(o);a&&n.push(...a);let u=e[o]?.children;if(Array.isArray(u))for(let h=u.length-1;h>=0;h--)typeof u[h]=="number"&&l.push(u[h])}return n};for(let i=0;i<e.length;i++){let n=e[i];if(!n||typeof n!="object")continue;let s=n.extras?.xr?.lod??n.extensions?.ANDROID_xr_scenecore?.lod??n.extensions?.MOZ_hubs_components?.lod,l=Array.isArray(n.extensions?.MSFT_lod?.ids)?n.extensions.MSFT_lod.ids.filter(d=>typeof d=="number"&&Number.isInteger(d)&&d>=0&&d<e.length):[],o=ar(s);if(!o&&l.length>0&&(o=ar({distances:l.map((d,f)=>f*4)})),!o)continue;let a=l.length>0?l:Array.isArray(n.children)?n.children.filter(d=>typeof d=="number"&&Number.isInteger(d)&&d>=0&&d<e.length):[],u=[],h=[];if(a.length>0){let d=Math.min(a.length,o.levels.length);for(let f=0;f<d;f++){let g=a[f];u.push(g),h.push(r(g))}}else{let d=t.get(i)??[];if(d.length===0)continue;u.push(i),h.push(d)}let m=o.distances.slice(0,h.length);m.length===0&&m.push(0);let c={nodeIndex:i,name:typeof n.name=="string"?n.name:`LOD_${i}`,distances:m,hysteresis:o.hysteresis,...o.cullDistance!==void 0?{cullDistance:o.cullDistance}:{},childNodeIndices:u,levelMeshes:h,activeLevelIndex:0,lastDistance:0};this.applyGroupVisibility(c,0),this.groups.push(c)}}getGroups(){return this.groups}getActiveLevel(e){let t=this.findGroup(e);return t?t.activeLevelIndex:null}forceLodLevel(e,t){let r=this.findGroup(e);if(!r)return;if(t==null){r.forcedLevelIndex=null;let n=sr(r.distances,r.lastDistance,r.activeLevelIndex,r.hysteresis,r.cullDistance);r.activeLevelIndex=n,this.applyGroupVisibility(r,n);return}let i=t<0?-1:Math.min(Math.max(0,Math.trunc(t)),r.levelMeshes.length-1);r.forcedLevelIndex=i,r.activeLevelIndex=i,this.applyGroupVisibility(r,i)}findGroup(e){return typeof e=="number"?this.groups.find(t=>t.nodeIndex===e)??this.groups[e]:this.groups.find(t=>t.name===e)}update(e){if(this.groups.length===0)return;let t=this.viewer?.worldMatrices,r=this.viewer?.modelRootMatrix;for(let i of this.groups){let n=Array.isArray(t)&&i.nodeIndex<t.length?t[i.nodeIndex]:null,s=n&&n[12]||0,l=n&&n[13]||0,o=n&&n[14]||0,a=r?r[0]*s+r[4]*l+r[8]*o+r[12]:s,u=r?r[1]*s+r[5]*l+r[9]*o+r[13]:l,h=r?r[2]*s+r[6]*l+r[10]*o+r[14]:o,m=Math.hypot((e[0]||0)-a,(e[1]||0)-u,(e[2]||0)-h);if(i.lastDistance=m,i.forcedLevelIndex!==void 0&&i.forcedLevelIndex!==null){i.activeLevelIndex!==i.forcedLevelIndex&&(i.activeLevelIndex=i.forcedLevelIndex,this.applyGroupVisibility(i,i.forcedLevelIndex));continue}let c=sr(i.distances,m,i.activeLevelIndex,i.hysteresis,i.cullDistance);c!==i.activeLevelIndex&&(i.activeLevelIndex=c,this.applyGroupVisibility(i,c))}}applyGroupVisibility(e,t){let r=this.gltf?.nodes;for(let i=0;i<e.levelMeshes.length;i++){let n=i===t;for(let o of e.levelMeshes[i])o.visible=n;let s=e.childNodeIndices[i],l=Array.isArray(r)?r[s]:null;l&&typeof l=="object"&&(l.visible=n,l.extensions=l.extensions||{},l.extensions.KHR_node_visibility={visible:n})}}},Pi={name:"lod",onRegister(){Qt(gn);let e=Ae(),t=e.threeNamespace??(typeof globalThis<"u"?globalThis.THREE:void 0);gn(t,e)},onLoadModel(e,t){!e||typeof e!="object"||yn.set(e,new xn(e,t))},onUpdate(e){let t=yn.get(e);if(!t||typeof e?.getCameraOrbit!="function")return;let r=e.getCameraOrbit(),i=typeof e.getCameraTarget=="function"?e.getCameraTarget():{x:0,y:0,z:0},n=r?.radius??3,s=r?.phi??0,l=r?.theta??0,o=Math.cos(s),a=(i.x||0)+n*o*Math.sin(l),u=(i.y||0)+n*Math.sin(s),h=(i.z||0)+n*o*Math.cos(l);t.update([a,u,h])},onBeforeDrawScene(e,t,r,i){let n=yn.get(e);n&&n.update(i)},onDestroy(e,t){t&&typeof t=="object"&&yn.delete(t)}},Ya={5120:1,5121:1,5122:2,5123:2,5125:4,5126:4};function bt(e,t,r,i){if(!r||r.bufferView===void 0)return null;let n=e.bufferViews?.[r.bufferView];if(!n)return null;let s=Number(r.count??0);if(!Number.isInteger(s)||s<=0)return null;let l=r.componentType??5126,o=Ya[l];if(!o)throw new RangeError(`glTF accessor has unsupported componentType ${l}`);let a=o*i,u=n.byteStride&&n.byteStride>0?n.byteStride:a,h=(n.byteOffset||0)+(r.byteOffset||0);if(!Number.isInteger(h)||h<0||u<a||h+(s-1)*u+a>t.byteLength)throw new RangeError(`glTF accessor reads past the end of the binary buffer (${t.byteLength} bytes)`);if(l===5126&&u===a&&h%4===0)return new Float32Array(t,h,s*i);let m=new DataView(t),c=r.normalized===!0,d=new Float32Array(s*i);for(let f=0;f<s;f++){let g=h+f*u;for(let x=0;x<i;x++){let b=g+x*o,v;switch(l){case 5126:v=m.getFloat32(b,!0);break;case 5120:v=m.getInt8(b),c&&(v=Math.max(v/127,-1));break;case 5121:v=m.getUint8(b),c&&(v/=255);break;case 5122:v=m.getInt16(b,!0),c&&(v=Math.max(v/32767,-1));break;case 5123:v=m.getUint16(b,!0),c&&(v/=65535);break;default:v=m.getUint32(b,!0),c&&(v/=4294967295)}d[f*i+x]=v}}return d}function Zo(e,t){let r=Number(t.offset?.[0]??0)||0,i=Number(t.offset?.[1]??0)||0,n=Number(t.scale?.[0]??1),s=Number(t.scale?.[1]??1),l=Number(t.rotation??0)||0,o=Math.cos(l),a=Math.sin(l),u=(Number.isFinite(n)?n:1)*o,h=(Number.isFinite(n)?n:1)*a,m=-(Number.isFinite(s)?s:1)*a,c=(Number.isFinite(s)?s:1)*o;for(let d=0;d+1<e.length;d+=2){let f=e[d],g=e[d+1];e[d]=u*f+h*g+r,e[d+1]=m*f+c*g+i}}function _t(e,t,r,i=!0){let n=[],s=null;try{for(let[l,o]of[[35633,t],[35632,r]]){let a=e.createShader(l);if(!a){if(i)throw new Error("Shader allocation failed");return null}if(n.push(a),e.shaderSource(a,o),e.compileShader(a),e.getShaderParameter&&!e.getShaderParameter(a,35713)){if(i)throw new Error(`Shader compile error: ${e.getShaderInfoLog(a)}`);return null}}if(s=e.createProgram(),!s){if(i)throw new Error("Program allocation failed");return null}for(let l of n)e.attachShader(s,l);if(e.linkProgram(s),e.getProgramParameter&&!e.getProgramParameter(s,35714)){let l=i?e.getProgramInfoLog(s):null;if(e.deleteProgram?.(s),s=null,i)throw new Error(`Program link error: ${l}`);return null}return s}finally{for(let l of n)s&&e.detachShader?.(s,l),e.deleteShader?.(l)}}var es=["neutral","reinhard","none","aces","agx"];function Vt(e){let t=String(e??"").trim().toLowerCase();return es.includes(t)?t:"neutral"}function Za(e){return es.indexOf(Vt(e))}function Qa(e){return new TextDecoder().decode(e)}var ts=Ae().decoders;function Ja(e,t){ts.set(e.toLowerCase(),t)}function nn(e){return ts.get(e.toLowerCase())}function ns(e){let t=ArrayBuffer.isView(e)?e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength):e,r=new DataView(t);if(t.byteLength<12)throw new Error(`Invalid GLB buffer size: ${t.byteLength} bytes`);let i=r.getUint32(0,!0);if(i!==1179937895){let c=r.getUint8(0);throw c===123||c===32||c===10||c===13?new Error("[three-live] Multi-file JSON .gltf is not supported for performance reasons. Please pack your asset into a single binary .glb file."):new Error(`Invalid GLB magic: 0x${i.toString(16)}`)}let n=r.getUint32(4,!0);if(n!==2)throw new Error(`Unsupported GLB version: ${n}`);let s=r.getUint32(8,!0),l=12,o=null,a=null;for(;l+8<=s&&l+8<=t.byteLength;){let c=r.getUint32(l,!0),d=r.getUint32(l+4,!0),f=l+8;if(f+c>t.byteLength)throw new Error(`Truncated GLB chunk: required ${f+c} bytes, buffer has ${t.byteLength}`);if(d===1313821514){let g=new Uint8Array(t,f,c),x=Qa(g);o=JSON.parse(x,(b,v)=>b==="__proto__"||b==="constructor"||b==="prototype"?void 0:v)}else d===5130562&&(a=t.slice(f,f+c));l=f+c}if(!o)throw new Error("Missing JSON chunk in GLB");let u=o.extensionsRequired||[];if(u.includes("KHR_draco_mesh_compression")&&!nn("draco"))throw new Error("Model requires KHR_draco_mesh_compression. Register a decoder via ThreeLiveElement.registerDecoder('draco', decoder).");for(let c of["EXT_meshopt_compression","KHR_meshopt_compression"])if(u.includes(c)&&!nn("meshopt"))throw new Error(`Model requires ${c}. Register a decoder via ThreeLiveElement.registerDecoder('meshopt', decoder).`);if(u.includes("KHR_texture_basisu")&&!nn("ktx2"))throw new Error("Model requires KHR_texture_basisu. Register a decoder via ThreeLiveElement.registerDecoder('ktx2', decoder).");let h=a||new ArrayBuffer(0),m={gltf:o,bin:h,animations:[]};for(let c of Oe)c.onParseGLB?.(m);return m}function ec(e){return typeof e=="object"&&e!==null&&"gltf"in e&&typeof e.gltf=="object"&&e.gltf!==null&&"bin"in e&&(e.bin instanceof ArrayBuffer||ArrayBuffer.isView(e.bin))}function Lt(e){if(ec(e))return e;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return ns(e);throw new TypeError("Invalid 3D model input: expected GLBData ({ gltf, bin }) or binary GLB (ArrayBuffer / ArrayBufferView).")}var rs=`#version 300 es
18
18
  layout(location=0) in vec3 aPos;
19
19
  layout(location=3) in vec3 aOff;
20
20
  layout(location=1) in vec3 aNormal;
@@ -49,7 +49,7 @@ vec2 scaleUV=uUvTransform.zw;
49
49
  if(scaleUV.x==0.0&&scaleUV.y==0.0)scaleUV=vec2(1.0);
50
50
  vUV=aUV*scaleUV+uUvTransform.xy;
51
51
  gl_Position=uMVP*vec4(aPosition,1.0);
52
- }`,cc=`#version 300 es
52
+ }`,tc=`#version 300 es
53
53
  precision highp float;
54
54
  in vec3 vNormal,vWorldPos;
55
55
  in vec2 vUV;
@@ -240,15 +240,15 @@ color=applyToneMapping(color,uToneMapping);
240
240
  float outAlpha=base.a;
241
241
  /*XRD_O*/
242
242
  fragColor=vec4(color,outAlpha);
243
- }`;function ms(e,t,r=1){t=Bt(t);let i=Number.isFinite(r)?Math.max(0,r):1,[n,s,l]=[0,1,2].map(g=>Math.max(0,(Number(e[g])||0)*i)),o=g=>Math.max(0,Math.min(1,g)),a=g=>[g(n),g(s),g(l)];if(t==="none")return a(o);if(t==="reinhard")return a(g=>g/(g+1));if(t==="aces")return a(g=>{let x=g*.6;return o(x*(2.51*x+.03)/(x*(2.43*x+.59)+.14))});if(t==="agx"){let[g,x,b]=[.84247906*n+.0784336*s+.07922375*l,.04232824*n+.87846864*s+.07916613*l,.04237565*n+.0784336*s+.87914297*l].map(v=>{let d=o((Math.log2(Math.max(v,1e-6))+12.47393)/16.5),y=d*d,M=y*y;return 15.5*M*y-40.14*M*d+31.96*M-6.868*y*d+.4298*y+.1191*d-.00232});return[1.196879*g-.09802088*x-.09902974*b,-.05289685*g+1.15190313*x-.09896118*b,-.05297164*g-.09804345*x+1.15107367*b].map(v=>o(Math.pow(Math.max(v,0),2.2)))}let u=Math.min(n,s,l),h=u<.08?u-6.25*u*u:.04;[n,s,l]=a(g=>g-h);let c=Math.max(n,s,l);if(c<.76)return a(o);let f=1-.0576/(c-.52),p=f/c,m=1-1/(.15*(c-f)+1);return a(g=>o(g*p+(f-g*p)*m))}var uc=`#version 300 es
243
+ }`;function is(e,t,r=1){t=Vt(t);let i=Number.isFinite(r)?Math.max(0,r):1,[n,s,l]=[0,1,2].map(g=>Math.max(0,(Number(e[g])||0)*i)),o=g=>Math.max(0,Math.min(1,g)),a=g=>[g(n),g(s),g(l)];if(t==="none")return a(o);if(t==="reinhard")return a(g=>g/(g+1));if(t==="aces")return a(g=>{let x=g*.6;return o(x*(2.51*x+.03)/(x*(2.43*x+.59)+.14))});if(t==="agx"){let[g,x,b]=[.84247906*n+.0784336*s+.07922375*l,.04232824*n+.87846864*s+.07916613*l,.04237565*n+.0784336*s+.87914297*l].map(v=>{let p=o((Math.log2(Math.max(v,1e-6))+12.47393)/16.5),y=p*p,M=y*y;return 15.5*M*y-40.14*M*p+31.96*M-6.868*y*p+.4298*y+.1191*p-.00232});return[1.196879*g-.09802088*x-.09902974*b,-.05289685*g+1.15190313*x-.09896118*b,-.05297164*g-.09804345*x+1.15107367*b].map(v=>o(Math.pow(Math.max(v,0),2.2)))}let u=Math.min(n,s,l),h=u<.08?u-6.25*u*u:.04;[n,s,l]=a(g=>g-h);let m=Math.max(n,s,l);if(m<.76)return a(o);let c=1-.0576/(m-.52),d=c/m,f=1-1/(.15*(m-c)+1);return a(g=>o(g*d+(c-g*d)*f))}var nc=`#version 300 es
244
244
  layout(location=0) in vec3 aPosition;
245
245
  uniform mat4 uMVP;
246
- void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,lc=`#version 300 es
246
+ void main(){gl_Position=uMVP*vec4(aPosition,1.0);}`,rc=`#version 300 es
247
247
  precision highp float;
248
248
  uniform vec4 uColorId;
249
249
  out vec4 fragColor;
250
- void main(){fragColor=uColorId;}`;function Pi(e,t,r){let i={};for(let n of r)i[n]=e.getUniformLocation(t,n);return i}var os=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function fs(){let e=Me().xrDepthShader;return{fs:cc.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...os,...e.uniformNames]:os}}function mc(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let r=t.toLowerCase();return r.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:r.startsWith("https://")||r.startsWith("blob:")?t:r.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Ci(e,t,r,i,n,s,l,o){if(i===void 0||!t.accessors?.[i])return null;let a=ut(t,r,t.accessors[i],s);if(!a)return null;o&&(a=a.slice(),is(a,o));let u=e.createBuffer();return l.push(u),e.bindBuffer(34962,u),e.bufferData(34962,a,35044),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,s,5126,!1,0,0),a}function Di(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ds(e,t,r){let i=fs(),n=ls,s=i.fs,l=!1;for(let a of Oe)if(a.onResolveShader){let u=a.onResolveShader(t,r,n,s);u&&(n=u.vs,s=u.fs,l=!0)}let o=l?Dt(e,n,s):null;return{program:o,uniforms:o?Pi(e,o,i.uniforms):null}}function fc(e,t,r){let i=t.instanceMatrices;if(!i||i.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let n=i.length>>4,s=t.instanceColors,l=new Float32Array(n*20);for(let a=0;a<n;a++)l.set(i.subarray(a*16,a*16+16),a*20),l[a*20+16]=s?s[a*3]:1,l[a*20+17]=s?s[a*3+1]:1,l[a*20+18]=s?s[a*3+2]:1,l[a*20+19]=1;let o=e.createBuffer();r.push(o),e.bindBuffer(34962,o),e.bufferData(34962,l,35044);for(let a=0;a<5;a++)e.enableVertexAttribArray(8+a),e.vertexAttribPointer(8+a,4,5126,!1,80,a*16),e.vertexAttribDivisor(8+a,1);return!0}function dc(e,t){let r=e.materials?.[t?.material];if(!r)return null;let i=[r.pbrMetallicRoughness?.baseColorTexture,r.pbrMetallicRoughness?.metallicRoughnessTexture,r.normalTexture,r.occlusionTexture,r.emissiveTexture];for(let n of i){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var hs=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),ps=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function ar(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function bs(e,t){let r=e?.pbrMetallicRoughness,i=r?.baseColorFactor,n=e?.extensions?.KHR_materials_clearcoat,s=l=>l!==void 0&&t[l.index]?t[l.index]:null;return{baseColor:i?[i[0],i[1],i[2],i[3]??1]:[.8,.8,.8,1],metallic:r?.metallicFactor??.1,roughness:r?.roughnessFactor??.5,clearcoat:n?n.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,n?.clearcoatRoughnessFactor??.04),texture:s(r?.baseColorTexture),metallicRoughnessTexture:s(r?.metallicRoughnessTexture),normalTexture:s(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:s(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function ys(e,t,r){let i=new Set,n=s=>{s&&!i.has(s)&&(i.add(s),e.deleteTexture(s))};for(let s of t)for(let l of s.primitives){if(l.vao&&e.deleteVertexArray(l.vao),l.buffers)for(let a of l.buffers)e.deleteBuffer(a);n(l.texture),n(l.metallicRoughnessTexture),n(l.normalTexture),n(l.occlusionTexture);let o=new Set;l.customProgram&&o.add(l.customProgram);for(let a of l.programCache?.values()??[])a.program&&o.add(a.program);for(let a of o)e.deleteProgram(a)}if(r)for(let s of r)n(s)}function ss(e,t,r=ps,i){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return hc(e,t,r,i,n)}catch(s){let l=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;ys(e,l,n.gpuTextures),n.vao&&e.deleteVertexArray(n.vao);for(let o of n.buffers)e.deleteBuffer(o);throw s}}function hc(e,t,r,i,n){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=t,l=rn("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(s,t);let o=t.bin,a=[];n.meshes=a;let u=[],h=s.extensions?.KHR_materials_variants;h&&Array.isArray(h.variants)&&h.variants.forEach((N,w)=>{u.push(typeof N?.name=="string"&&N.name?N.name:`Variant_${w}`)});let c=Vt(s),f=[];if(Array.isArray(s.nodes))for(let N=0;N<s.nodes.length;N++){let w=s.nodes[N];w.mesh!==void 0&&s.meshes&&s.meshes[w.mesh]&&f.push({node:w,nodeIdx:N,meshIdx:w.mesh})}let p=f.length>0?f:(s.meshes||[]).map((N,w)=>({node:N,nodeIdx:-1,meshIdx:w})),m=[],g=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(g)for(let N of g)m.push({...N,type:N.type||N.light_type||"point",innerConeAngle:N.innerConeAngle??N.inner_cone_angle,outerConeAngle:N.outerConeAngle??N.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let N=s.extensions.KHR_lights_punctual.lights;for(let w of N){let ie=w.type==="directional"?"directional":w.type==="point"?"point":w.type==="spot"?"spot":"ambient";m.push({type:ie,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(m.length===0&&(m.push({type:"ambient",color:[1,1,1],intensity:.35}),m.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),p.length>r.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${r.maxMeshes}). Found: ${p.length}`);let x=[];if(n.gpuTextures=x,s.textures&&s.images){if(s.textures.length>r.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${r.maxTextures}). Found: ${s.textures.length}`);for(let N=0;N<s.textures.length;N++){let w=s.textures[N],ie=s.images[w.source];if(ie){let ae=e.createTexture();e.bindTexture(3553,ae),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let k=J=>{e.bindTexture(3553,ae),e.texImage2D(3553,0,6408,6408,5121,J),e.generateMipmap(3553),i?.()};if(ie.bufferView!==void 0){let J=s.bufferViews[ie.bufferView],z=J.byteOffset||0,Y=new Blob([o.slice(z,z+J.byteLength)],{type:ie.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(Y).then(k).catch(()=>{})}else if(ie.uri){let J=mc(ie.uri);if(J){let z=new Image;z.crossOrigin="anonymous",z.referrerPolicy="no-referrer",z.onload=()=>k(z),z.src=J}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",ie.uri)}x.push(ae)}else x.push(null)}}let b=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],d=0,y=0;for(let N=0;N<p.length;N++){let w=p[N],ie=s.meshes[w.meshIdx],ae=w.nodeIdx>=0?c[w.nodeIdx]:Se(),k=new Float32Array(9);ze(k,ae);let J={name:w.node.name||ie.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:ae,normalMatrix:k,primitives:[],extras:w.node.extras||ie.extras,...w.node?.visible===!1||w.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};n.mesh=J;let z=w.node?.extensions?.EXT_mesh_gpu_instancing;if(z&&z.attributes&&typeof z.attributes=="object"){let Y=z.attributes,le=Y.TRANSLATION!==void 0?s.accessors?.[Y.TRANSLATION]:null,ce=Y.ROTATION!==void 0?s.accessors?.[Y.ROTATION]:null,$=Y.SCALE!==void 0?s.accessors?.[Y.SCALE]:null,U=Y._COLOR_0!==void 0?s.accessors?.[Y._COLOR_0]:null,_=Number(le?.count??ce?.count??$?.count??0);if(!Number.isFinite(_)||_<0||_>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${_}`);if(_>0){let H=(j,A)=>{if(!j||j.bufferView===void 0||!s.bufferViews?.[j.bufferView])return null;let S=j.componentType??5126,L=I=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${I})`),null);if(S!==5120&&S!==5121&&S!==5122&&S!==5123&&S!==5126)return L(`componentType ${S}`);if(!(Number(j.count)>=_))return L(`count ${j.count} < ${_}`);let O=null;try{O=ut(s,o,{...j,count:_},A)}catch{return L("out of bounds")}return!O||!O.every(Number.isFinite)?L("non-finite value"):O},D=H(le,3),F=H(ce,4),E=H($,3),G=U?.type==="VEC4"?4:3,ee=H(U,G),se=new Float32Array(_*16),oe=Se();for(let j=0;j<_;j++){let A=D?[D[j*3],D[j*3+1],D[j*3+2]]:[0,0,0],S=F?[F[j*4],F[j*4+1],F[j*4+2],F[j*4+3]]:[0,0,0,1],L=E?[E[j*3],E[j*3+1],E[j*3+2]]:[1,1,1];yt(oe,S,A,L),se.set(oe,j*16)}if(J.instanceMatrices=se,ee){let j=new Float32Array(_*3);for(let A=0;A<_;A++)j[A*3]=ee[A*G],j[A*3+1]=ee[A*G+1],j[A*3+2]=ee[A*G+2];J.instanceColors=j}}}for(let Y of ie.primitives||[]){if(Y.extensions?.KHR_draco_mesh_compression){let O=rn("draco");O&&O.decodePrimitive(s,Y,o)}let le=[],ce=e.createVertexArray();n.vao=ce,n.buffers=le,e.bindVertexArray(ce);let $=fc(e,J,le),U=s.accessors[Y.attributes.POSITION],_=Number(U?.count??0);if(!Number.isFinite(_)||_<0||d+_>r.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${r.maxVertices}).`);if(d+=_,U?.min&&U?.max){let O=I=>{for(let W=0;W<3;W++){let Q=I[12+W],K=I[12+W];for(let Z=0;Z<3;Z++){let q=I[Z*4+W]*U.min[Z],re=I[Z*4+W]*U.max[Z];Q+=q<re?q:re,K+=q>re?q:re}Q<b[W]&&(b[W]=Q),K>v[W]&&(v[W]=K)}};if(J.instanceMatrices&&J.instanceMatrices.length>=16){let I=J.instanceMatrices.length>>4,W=Se();for(let Q=0;Q<I;Q++){let K=J.instanceMatrices.subarray(Q*16,Q*16+16);Pe(W,ae,K),O(W)}}else O(ae)}let H=Ci(e,s,o,Y.attributes.POSITION,0,3,le);Ci(e,s,o,Y.attributes.NORMAL,1,3,le),Ci(e,s,o,Y.attributes.TEXCOORD_0,2,2,le,dc(s,Y));let D=0,F=5123,E=null;if(Y.indices!==void 0){let O=s.accessors[Y.indices],I=(s.bufferViews[O.bufferView].byteOffset||0)+(O.byteOffset||0);if(D=Number(O.count??0),!Number.isFinite(D)||D<0||y+D>r.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${r.maxIndices}).`);y+=D,F=O.componentType===5125?5125:5123;let W=e.createBuffer();le.push(W),e.bindBuffer(34963,W),O.componentType===5125?E=new Uint32Array(o,I,O.count):O.componentType===5121?E=Uint16Array.from(new Uint8Array(o,I,O.count)):E=I%2===0?new Uint16Array(o,I,O.count):new Uint16Array(o.slice(I,I+O.count*2)),e.bufferData(34963,E,35044)}else D=U.count;let G={};for(let O of Oe)if(O.onBuildPrimitiveVAO){let I=O.onBuildPrimitiveVAO(e,ce,Y,s,o);I&&(G[O.name]=I)}e.bindVertexArray(null);let ee=s.materials&&Y.material!==void 0?s.materials[Y.material]:null,{program:se,uniforms:oe}=ds(e,Y,ee),j=bs(ee,x),A=!!(ee?.extensions?.KHR_materials_transmission||G.materials?.isTransmissive),S=Y.extensions?.KHR_materials_variants?.mappings,L=Array.isArray(S)?S.filter(O=>O&&typeof O.material=="number"&&Array.isArray(O.variants)).map(O=>({material:O.material|0,variants:O.variants.map(I=>Number(I)|0)})):void 0;J.primitives.push({vao:ce,instanced:$,indexCount:D,indexType:F,...j,positions:H,indices:E,buffers:le,materialIndex:Y.material,defaultMaterialIndex:Y.material,variantMappings:L,primitiveDef:Y,programCache:new Map([[Y.material??-1,{program:se,uniforms:oe}]]),pluginData:G,customProgram:se,customUniforms:oe,isTransmissive:A})}a.push(J)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let M=[(b[0]+v[0])/2,(b[1]+v[1])/2,(b[2]+v[2])/2],T=v[0]-b[0],V=v[1]-b[1],X=v[2]-b[2],P=Math.max(Math.hypot(T,V,X)/2,.5),R=[b[0],b[1],b[2]],C=[v[0],v[1],v[2]],B=t.animations;if(!B){for(let N of Oe)if(N.onParseGLB?.(t),t.animations){B=t.animations;break}}return B||(B=[]),{meshes:a,bounds:{center:M,radius:P,min:R,max:C},lights:m,animations:B,worldMatrices:c,gpuTextures:x,availableVariants:u}}function xn(e){let t=e.customTarget||e.bounds.center,r=e.currDistance*Math.cos(e.currPhi);return[t[0]+r*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+r*Math.cos(e.currTheta)]}var je=class{constructor(e,t,r){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=Se(),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=Se(),this.viewMatrix=Se(),this.activeViewMatrix=null,this.modelMatrix=Se(),this.mvpMatrix=Se(),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:Se(),rawValueToMeters:.001,format:0},this.container=e;let i,n;if(t&&typeof t.getContext=="function"?(i=t,n=r):(n=t,i=n?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=n||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=Di(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=Bt(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){sc(e,t)}static getDecoder(e){return rn(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=fs();this.renderProg=Dt(e,ls,t.fs),this.pickProg=Dt(e,uc,lc),this.uRender=Pi(e,this.renderProg,t.uniforms),this.uPick=Pi(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of Oe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),n=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=n,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,n,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,n)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:n,animations:s,worldMatrices:l,gpuTextures:o,availableVariants:a}=ss(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=o||[],this.availableVariants=a||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let c of e.gltf.nodes)this.initialNodeTransforms.push({t:c.translation?[c.translation[0],c.translation[1],c.translation[2]]:[0,0,0],r:c.rotation?[c.rotation[0],c.rotation[1],c.rotation[2],c.rotation[3]]:[0,0,0,1],s:c.scale?[c.scale[0],c.scale[1],c.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let c of Oe)c.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=Di(u));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(us(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of Oe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(gt(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=gt(e),{meshes:i}=ss(this.gl,r,ps,()=>this.render());if(t)for(let n of i)n.transform[12]+=t[0],n.transform[13]+=t[1],n.transform[14]+=t[2],ze(n.normalMatrix,n.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),ze(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],n=[],s=[],l=[],o=[],a=[];for(let u of this.lights){let h=u.color||[1,1,1],c=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[h[0]*c,h[1]*c,h[2]*c];else if(u.type==="directional"&&i.length<6){let f=u.direction||[.5,1,.8];i.push(f[0],f[1],f[2]),n.push(h[0]*c,h[1]*c,h[2]*c)}else if((u.type==="point"||u.type==="spot")&&s.length<6){let f=u.position||[0,0,0];if(s.push(f[0],f[1],f[2]),l.push(h[0]*c,h[1]*c,h[2]*c),u.type==="spot"){let p=u.direction||[0,-1,0],m=Math.max(.01,Math.min(Math.PI/2,u.outerConeAngle??Math.PI/3)),g=Math.max(0,Math.min(m-1e-4,u.innerConeAngle??0));o.push(p[0],p[1],p[2]),a.push(Math.cos(g),Math.cos(m))}else o.push(0,-1,0),a.push(-2,-3)}}i.length===0&&(i.push(.5,1,.8),n.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,n)),t.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(t.uniform3fv(e.uPointLightPos,s),t.uniform3fv(e.uPointLightColor,l),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,a)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=Di(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Bt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Oe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Oe)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),n=i[0],s=n?[...n.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=n?n.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:s,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:u=>{let h=[u[0],u[1],u[2],u[3]??1];a.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let c of i)c.baseColor=h;this.render()},setMetallicFactor:u=>{a.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let h of i)h.metallic=u;this.render()},setRoughnessFactor:u=>{a.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let h of i)h.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let n of this.meshes)for(let s of n.primitives){let l=s.defaultMaterialIndex;if(!t&&Array.isArray(s.variantMappings)){for(let a of s.variantMappings)if(Array.isArray(a.variants)&&a.variants.includes(r)){l=a.material;break}}let o=l!==void 0?i[l]:void 0;s.materialIndex=o?l:void 0,Object.assign(s,bs(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,n=e.programCache.get(i);n||(n=ds(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,n)),e.customProgram=n.program,e.customUniforms=n.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of Oe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let n=this.clampDistance(r);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else if(i!==void 0&&i>0){let n=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else{this.customDistance=!1;let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=Se();Pe(r,this.projMatrix,this.viewMatrix);let[i,n,s]=e,l=t?t[0]:0,o=t?t[1]:0,a=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],n=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(l=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],a=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let h=r[0]*i+r[4]*n+r[8]*s+r[12],c=r[1]*i+r[5]*n+r[9]*s+r[13],f=r[2]*i+r[6]*n+r[10]*s+r[14],p=r[3]*i+r[7]*n+r[11]*s+r[15];if(p<=1e-4)return{x:0,y:0,z:1,visible:!1};let m=h/p,g=c/p,x=f/p,b=this.canvas.getBoundingClientRect(),v=b.width||this.canvas.clientWidth||this.canvas.width||300,d=b.height||this.canvas.clientHeight||this.canvas.height||150,y=(m*.5+.5)*v,M=(-g*.5+.5)*d,T=m>=-1.1&&m<=1.1&&g>=-1.1&&g<=1.1&&x>=-1&&x<=1;if(T&&t){let[V,X,P]=xn(this),R=[i-V,n-X,s-P];l*R[0]+o*R[1]+a*R[2]>.05&&(T=!1)}return{x:y,y:M,z:x,visible:T}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=r=>{r.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=r=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist=0,this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.isPanning=r.button===2||r.shiftKey||this.activePointers.size===2,e.setPointerCapture(r.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=r=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let i=this.activePointers.get(r.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=r.clientX-i.x,s=r.clientY-i.y;if(this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||r.button===2||r.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-n*l[0]+s*o[0])*u,a[1]+=(-n*l[1]+s*o[1])*u,a[2]+=(-n*l[2]+s*o[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=r=>{this.lastInteractionTime=t(),this.activePointers.delete(r.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(r.pointerId)}catch{}if(this.totalDragDist<5&&r.button===0){let i=e.getBoundingClientRect(),n=Math.floor((r.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((r.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(n,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=r=>{if(!this.interactive)return;r.preventDefault(),this.lastInteractionTime=t();let i=Math.exp(r.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=r=>{let i=r.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=r=>{if(this.interactive){switch(r.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),r.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(r,i,n)=>{this[n]&&(r.removeEventListener(i,this[n]),this[n]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),n=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(n/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(s/i.height)):Math.floor(t);return this.performMeshPick(l,o,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,n);let l=Se();Pe(l,this.projMatrix,this.viewMatrix);let o=[],a=Math.max(0,Math.min(n-1,e)),u=Math.max(0,Math.min(s-1,s-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,n,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16640),i.useProgram(this.pickProg);for(let M=0;M<this.meshes.length;M++){let T=this.meshes[M];if(T.visible===!1||T.isPluginMesh)continue;let V=M+1,X=(V&255)/255,P=(V>>8&255)/255,R=(V>>16&255)/255;i.uniform4f(this.uPick.uColorId,X,P,R,1),Pe(this.modelMatrix,this.modelRootMatrix,T.transform);let C=T.instanceMatrices;if(C&&C.length>=16){let B=C.length>>4,N=Se();for(let w of T.primitives){i.bindVertexArray(w.vao);for(let ie=0;ie<B;ie++)Pe(N,this.modelMatrix,C.subarray(ie*16,ie*16+16)),Pe(this.mvpMatrix,l,N),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),ar(i,w)}}else{Pe(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let B of T.primitives)i.bindVertexArray(B.vao),ar(i,B)}}let d=new Uint8Array(4);i.readPixels(a,u,1,1,6408,5121,d),i.bindFramebuffer(36160,null);let y=d[0]+(d[1]<<8)+(d[2]<<16);y>0&&y<=this.meshes.length&&(o=[this.meshes[y-1]])}o.length===0&&(o=this.meshes.filter(d=>d.visible!==!1));let h=null,c=1/0,f=[0,0,0],p=[0,1,0],[m,g,x]=xn(this),b=Se();for(let d of o){Pe(b,this.modelRootMatrix,d.transform);let y=d.instanceMatrices,M=y&&y.length>=16?y.length>>4:1;for(let T=0;T<M;T++){y&&y.length>=16?Pe(this.modelMatrix,b,y.subarray(T*16,T*16+16)):this.modelMatrix.set(b),Pe(this.mvpMatrix,l,this.modelMatrix);let V=Se();if(!tn(V,this.mvpMatrix))continue;let X=(a+.5)/n*2-1,P=(u+.5)/s*2-1,R=[0,0,0],C=[0,0,0];vi(R,X,P,-1,V),vi(C,X,P,1,V);let B=C[0]-R[0],N=C[1]-R[1],w=C[2]-R[2],ie=Math.hypot(B,N,w)||1,ae=B/ie,k=N/ie,J=w/ie,z={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((Y=>{for(let le of d.primitives){if(!le.positions)continue;let ce=le.positions,$=le.indices,U=Math.floor($?$.length/3:ce.length/9);for(let _=0;_<U;_++){let H=$?$[_*3]:_*3,D=$?$[_*3+1]:_*3+1,F=$?$[_*3+2]:_*3+2;qo(R[0],R[1],R[2],ae,k,J,ce[H*3],ce[H*3+1],ce[H*3+2],ce[D*3],ce[D*3+1],ce[D*3+2],ce[F*3],ce[F*3+1],ce[F*3+2],z,Y)}}})(1e-4),isFinite(z.distance)){let Y=z.point[0],le=z.point[1],ce=z.point[2],$=this.modelMatrix,U=$[0]*Y+$[4]*le+$[8]*ce+$[12],_=$[1]*Y+$[5]*le+$[9]*ce+$[13],H=$[2]*Y+$[6]*le+$[10]*ce+$[14],D=U-m,F=_-g,E=H-x,G=Math.hypot(D,F,E);if(G<c){ze(this.normalMatrix,this.modelMatrix);let ee=this.normalMatrix,se=z.normal[0],oe=z.normal[1],j=z.normal[2],A=ee[0]*se+ee[3]*oe+ee[6]*j,S=ee[1]*se+ee[4]*oe+ee[7]*j,L=ee[2]*se+ee[5]*oe+ee[8]*j,O=Math.hypot(A,S,L)||1;A/=O,S/=O,L/=O,A*D+S*F+L*E>0&&(A=-A,S=-S,L=-L),h=d,c=Math.round(G*1e3)/1e3,f=[Math.round(U*1e3)/1e3,Math.round(_*1e3)/1e3,Math.round(H*1e3)/1e3],p=[Math.round(A*1e3)/1e3,Math.round(S*1e3)/1e3,Math.round(L*1e3)/1e3]}}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:c,hitPoint:f,normal:p,screenX:e,screenY:t};if(r){for(let d of Oe)d.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,n=i?e-r:e,s=i?Math.max(1,t-r):r,l=(n+.5)/s*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);nr(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;en(this.viewMatrix,xn(this),r,[0,1,0]),Pe(this.mvpMatrix,this.projMatrix,this.viewMatrix),ze(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of 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 t of Oe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],n=this.modelRootMatrix;n[0]=e,n[1]=0,n[2]=-t,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=t,n[9]=0,n[10]=e,n[11]=0,n[12]=r-(e*r+t*i),n[13]=0,n[14]=i-(-t*r+e*i),n[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Oe)s.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of 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),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=n;let s={theta:r,phi:i,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,t,r,i,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,u=a?[a.x,a.y,a.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:n})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),d=Math.max(1,this.canvas.height||1),y=Math.max(1,Math.floor(v*.5)),M=Math.max(1,v-y),T=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),V=this.customTarget||this.bounds.center,[X,P,R]=xn(this),C=Math.cos(this.currTheta),B=-Math.sin(this.currTheta),N=.032,w=Se(),ie=Se(),ae=[X-C*N,P,R-B*N],k=[V[0]-C*N*.25,V[1],V[2]-B*N*.25];nr(w,this.fov,y/d,.1,T),en(ie,ae,k,[0,1,0]);let J=Se(),z=Se(),Y=[X+C*N,P,R+B*N],le=[V[0]+C*N*.25,V[1],V[2]+B*N*.25];nr(J,this.fov,M/d,.1,T),en(z,Y,le,[0,1,0]),this.render({viewMatrix:ie,projMatrix:w,eyePos:ae,viewport:[0,0,y,d],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:z,projMatrix:J,eyePos:Y,viewport:[y,0,M,d],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,d);return}let t=this.gl,r=0,i=0,n=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],n=e.viewport[2],s=e.viewport[3],t.viewport(r,i,n,s)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let l=Se(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,Pe(l,e?.projMatrix??this.projMatrix,o);let a=Me().xrDepthShader,u=ic(this.toneMapping),[h,c,f]=e?e.eyePos:xn(this);for(let v of Oe)v.onBeforeDrawScene?.(this,t,l,[h,c,f],u);let p=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&p===0)return;let m=e?.eye||"none",g=!1,x=p>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=v=>{for(let d=0;d<x.length;d++){let y=x[d];if(y.visible===!1)continue;let M=this.selectedMeshName!==""&&y.name===this.selectedMeshName;d<p||y.worldSpace===!0||y.name==="__xr_reticle__"?this.modelMatrix.set(y.transform):Pe(this.modelMatrix,this.modelRootMatrix,y.transform),Pe(this.mvpMatrix,l,this.modelMatrix),ze(y.normalMatrix,this.modelMatrix);let T=y.extras?.xr?.stereo||y.userData?.xr?.stereo,V=0,X=0,P=1,R=1;T==="sbs"?(P=.5,V=m==="right"?.5:0):T==="ou"&&(R=.5,X=m==="right"?.5:0);for(let C of y.primitives){let B=!!C.isTransmissive;if(!v&&B){g=!0;continue}if(v&&!B)continue;let N=C.customProgram||this.renderProg,w=C.customUniforms||this.uRender;t.useProgram(N),t.vertexAttrib3f(3,0,0,0),w.uInstanced&&t.uniform1i(w.uInstanced,0),t.uniform1i(w.uToneMapping,u),t.uniform1f(w.uEnvIntensity,this.envIntensity),w.uExposure&&t.uniform1f(w.uExposure,this.exposure),t.uniform3f(w.uCameraPos,h,c,f),t.uniform1f(w.uEmissive,M?1:0),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(w.uNormalMatrix,!1,y.normalMatrix),w.uUvTransform&&t.uniform4f(w.uUvTransform,V,X,P,R),w.uViewportSize&&t.uniform2f(w.uViewportSize,Math.max(1,n),Math.max(1,s)),a?.bind(t,w,this.xrDepthState,o,[r,i,Math.max(1,n),Math.max(1,s)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(w.uEnvironmentMap,4),t.uniform1i(w.uHasEnvironmentMap,1)):t.uniform1i(w.uHasEnvironmentMap,0),this.bindLights(w),w.uSectionEnabled&&t.uniform1i(w.uSectionEnabled,0);for(let ae of Oe)ae.onBeforeDrawPrimitive?.(t,N,C,y,this.worldMatrices||[],this.gltf);t.uniform4fv(w.uBaseColor,C.baseColor),t.uniform1f(w.uMetallic,C.metallic),t.uniform1f(w.uRoughness,C.roughness),w.uClearcoat&&t.uniform2f(w.uClearcoat,C.clearcoat??0,C.clearcoatRoughness??.04),C.texture?(t.activeTexture(33984),t.bindTexture(3553,C.texture),t.uniform1i(w.uBaseColorTexture,0),t.uniform1i(w.uHasTexture,1)):t.uniform1i(w.uHasTexture,0),C.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,C.metallicRoughnessTexture),t.uniform1i(w.uMetallicRoughnessTexture,1),t.uniform1i(w.uHasMetallicRoughnessTexture,1)):t.uniform1i(w.uHasMetallicRoughnessTexture,0),C.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,C.normalTexture),t.uniform1i(w.uNormalTexture,2),t.uniform1i(w.uHasNormalTexture,1),t.uniform1f(w.uNormalScale,C.normalScale)):t.uniform1i(w.uHasNormalTexture,0),C.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,C.occlusionTexture),t.uniform1i(w.uOcclusionTexture,3),t.uniform1i(w.uHasOcclusionTexture,1),t.uniform1f(w.uOcclusionStrength,C.occlusionStrength)):t.uniform1i(w.uHasOcclusionTexture,0),t.bindVertexArray(C.vao);let ie=y.instanceMatrices;if(C.instanceCount!==void 0)t.drawElementsInstanced(4,C.indexCount,C.indexType,0,C.instanceCount);else if(ie&&ie.length>=16&&C.instanced&&w.uInstanced&&w.uViewProj){let ae=ie.length>>4;t.uniform1i(w.uInstanced,1),t.uniformMatrix4fv(w.uViewProj,!1,l),C.indices?t.drawElementsInstanced(4,C.indexCount,C.indexType,0,ae):t.drawArraysInstanced(4,0,C.indexCount,ae),t.uniform1i(w.uInstanced,0)}else if(ie&&ie.length>=16){let ae=ie.length>>4,k=y.instanceColors,J=Se(),z=new Float32Array(9),Y=[C.baseColor[0],C.baseColor[1],C.baseColor[2],C.baseColor[3]];for(let le=0;le<ae;le++)Pe(J,this.modelMatrix,ie.subarray(le*16,le*16+16)),Pe(this.mvpMatrix,l,J),ze(z,J),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,J),t.uniformMatrix3fv(w.uNormalMatrix,!1,z),k&&(Y[0]=C.baseColor[0]*k[le*3],Y[1]=C.baseColor[1]*k[le*3+1],Y[2]=C.baseColor[2]*k[le*3+2],Y[3]=C.baseColor[3],t.uniform4fv(w.uBaseColor,Y)),ar(t,C)}else ar(t,C)}}};if(b(!1),g){for(let v of Oe)v.onBeforeTransmissivePass?.(t,this);b(!0)}for(let v of Oe)v.onAfterRender?.(t,this,l,e?.eye??"none",[r,i,n,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ys(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Oe)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};je.registerPlugin=Ue,je.getRegisteredPlugins=er;function pc(e){return e+3&-4}var ve=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function vs(e,t){let r=t,i=1;for(;e.has(r);)r=`${t}_${i++}`;return e.add(r),r}function Ms(e,t=0){let[r,i,n,,s,l,o,,a,u,h,,c,f,p]=Array.from({length:15},(z,Y)=>ve(e[t+Y],Y%5===0?1:0)),m=Math.hypot(r,i,n),g=Math.hypot(s,l,o),x=Math.hypot(a,u,h);r*(l*h-u*o)-s*(i*h-u*n)+a*(i*o-l*n)<0&&(m=-m);let b=Math.abs(m)>1e-8?1/m:0,v=Math.abs(g)>1e-8?1/g:0,d=Math.abs(x)>1e-8?1/x:0,y=r*b,M=i*b,T=n*b,V=s*v,X=l*v,P=o*v,R=a*d,C=u*d,B=h*d,N=y+X+B,w=0,ie=0,ae=0,k=1;if(N>0){let z=.5/Math.sqrt(N+1);k=.25/z,w=(P-C)*z,ie=(R-T)*z,ae=(M-V)*z}else if(y>X&&y>B){let z=2*Math.sqrt(Math.max(0,1+y-X-B));z>1e-8&&(k=(P-C)/z,w=.25*z,ie=(V+M)/z,ae=(R+T)/z)}else if(X>B){let z=2*Math.sqrt(Math.max(0,1+X-y-B));z>1e-8&&(k=(R-T)/z,w=(V+M)/z,ie=.25*z,ae=(P+C)/z)}else{let z=2*Math.sqrt(Math.max(0,1+B-y-X));z>1e-8&&(k=(M-V)/z,w=(R+T)/z,ie=(P+C)/z,ae=.25*z)}let J=Math.hypot(w,ie,ae,k);return J>1e-8&&Number.isFinite(J)?(w/=J,ie/=J,ae/=J,k/=J):(w=0,ie=0,ae=0,k=1),{t:[c,f,p],r:[w,ie,ae,k],s:[m,g,x]}}function bc(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var Pt=(e,t,r,i)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(r,e)):i;function Ts(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let r=typeof t=="string"?{preset:t}:t,i=typeof r.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(r.src)?r.src:void 0,n=typeof r.preset=="string"?r.preset:void 0;return!i&&!n?null:{ae:r,src:i,preset:n,volume:Pt(r.volume,0,2,.6),loop:typeof r.loop=="boolean"?r.loop:!0,isGlobal:r.type==="global"||r.positional===!1}}function on(e,t){return As(e,t)[0]}function As(e,t){e.updateMatrixWorld(!0);let r=[],i=0,n=[],s=[],l=[],o=[],a=new Set,u=[],h=[],c=new Map,f=[],p=[],m=[],g=new Map,x=[],b=[];function v(k){let J=c.get(k);if(J!==void 0)return J;J=h.length,c.set(k,J);let z=k,Y=z.color?.r??.8,le=z.color?.g??.8,ce=z.color?.b??.8,$=z.opacity??1,U={baseColorFactor:[Y,le,ce,$],metallicFactor:z.metalness??0,roughnessFactor:z.roughness??.5},_={};if(z.map){let F="";typeof z.map=="string"?F=z.map:typeof z.map.source=="string"?F=z.map.source:typeof z.map.image=="string"&&(F=z.map.image);let E=F.trim(),G=E&&!/[\x00-\x1f\x7f\\]|\.\./.test(E)&&(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(E)||!E.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(E))?E:null;if(G){let se=g.get(G);if(se===void 0){let oe=f.length;f.push({uri:G}),p.length===0&&p.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),se=m.length,m.push({sampler:0,source:oe}),g.set(G,se)}U.baseColorTexture={index:se}}let ee=z.map.avgColor;Array.isArray(ee)&&ee.length>=3&&(_.avgColor=[ee[0],ee[1],ee[2]])}let H={name:z.name||"",pbrMetallicRoughness:U,doubleSided:z.side===2||!!z.doubleSided,...Object.keys(_).length>0?{extras:_}:{}};if(z.emissive&&(z.emissive.r>0||z.emissive.g>0||z.emissive.b>0)){let F=z.emissiveIntensity??1;H.emissiveFactor=[z.emissive.r*F,z.emissive.g*F,z.emissive.b*F]}let D={};return z.clearcoat&&z.clearcoat>0&&(D.KHR_materials_clearcoat={clearcoatFactor:z.clearcoat,clearcoatRoughnessFactor:z.clearcoatRoughness||0}),z.sheen&&z.sheen>0&&(D.KHR_materials_sheen={sheenColorFactor:z.sheenColor?[z.sheenColor.r,z.sheenColor.g,z.sheenColor.b]:[1,1,1],sheenRoughnessFactor:z.sheenRoughness||0}),z.transmission&&z.transmission>0&&(D.KHR_materials_transmission={transmissionFactor:z.transmission}),z.thickness&&z.thickness>0&&(D.KHR_materials_volume={thicknessFactor:z.thickness,attenuationDistance:z.attenuationDistance??1/0,attenuationColor:z.attenuationColor?[z.attenuationColor.r,z.attenuationColor.g,z.attenuationColor.b]:[1,1,1]}),z.ior!==void 0&&z.ior!==1.5&&(D.KHR_materials_ior={ior:z.ior}),z.dispersion&&z.dispersion>0&&(D.KHR_materials_dispersion={dispersion:z.dispersion}),z.iridescence&&z.iridescence>0&&(D.KHR_materials_iridescence={iridescenceFactor:z.iridescence,iridescenceIor:z.iridescenceIOR??1.3}),Object.keys(D).length>0&&(H.extensions=D),h.push(H),J}function d(k,J){let z=new Uint8Array(k.buffer,k.byteOffset,k.byteLength),Y=pc(z.byteLength),le=new Uint8Array(Y);le.set(z),r.push(le);let ce=n.length;return n.push({buffer:0,byteOffset:i,byteLength:z.byteLength,target:J}),i+=Y,ce}function y(k,J,z,Y,le,ce,$){let U=d(k,z),_=s.length,H={bufferView:U,byteOffset:0,componentType:Y,count:le,type:J};return ce&&(H.min=ce),$&&(H.max=$),s.push(H),_}e.traverse(k=>{if(k.isLight||k.color&&k.intensity!==void 0){let J=k.matrixWorld?.elements,z=ve(J?J[12]:k.position?.x,0),Y=ve(J?J[13]:k.position?.y,0),le=ve(J?J[14]:k.position?.z,0),ce=k.target,$=ce?.parent?ce?.matrixWorld?.elements:void 0,U=ve($?$[12]:ce?.position?.x,0),_=ve($?$[13]:ce?.position?.y,0),H=ve($?$[14]:ce?.position?.z,0),D=U-z,F=_-Y,E=H-le,G=Math.hypot(D,F,E),ee=Math.max(.01,Math.min(Math.PI/2,ve(k.angle,Math.PI/3))),se=Math.max(0,Math.min(1,ve(k.penumbra,0)));b.push({type:k.type,color:[k.color.r,k.color.g,k.color.b],intensity:k.intensity,position:[z,Y,le],...k.type==="spot"?{direction:G>1e-6?[D/G,F/G,E/G]:[0,-1,0],outerConeAngle:ee,innerConeAngle:Math.max(0,ee*(1-se)),range:Math.max(0,ve(k.distance,0))}:k.type==="point"?{range:Math.max(0,ve(k.distance,0))}:{}})}});let M=[],T=new Set([e]),V=[];if(Array.isArray(e.children))for(let k=e.children.length-1;k>=0;k--)V.push({obj:e.children[k],parentKids:M});for(;V.length>0;){let{obj:k,parentKids:J}=V.pop();if(!k||typeof k!="object"||T.has(k))continue;T.add(k),k._bakeAuthorGeometry?.(),Me().materializeDeclarativeGeometry?.(k);let z=!!(k.userData&&(k.userData.xr&&typeof k.userData.xr=="object"&&Object.keys(k.userData.xr).length>0||k.userData.interactivity&&typeof k.userData.interactivity=="object"&&Object.keys(k.userData.interactivity).length>0)),Y={name:k.name||(z?`Node_${o.length}`:"")},le=ve(k.position?.x,0),ce=ve(k.position?.y,0),$=ve(k.position?.z,0),U=ve(k.quaternion?.x,0),_=ve(k.quaternion?.y,0),H=ve(k.quaternion?.z,0),D=ve(k.quaternion?.w,1),F=ve(k.scale?.x,1),E=ve(k.scale?.y,1),G=ve(k.scale?.z,1);if((le||ce||$)&&(Y.translation=[le,ce,$]),(U||_||H||D!==1)&&(Y.rotation=[U,_,H,D]),(F!==1||E!==1||G!==1)&&(Y.scale=[F,E,G]),k.visible===!1&&(Y.extensions={...Y.extensions||{},KHR_node_visibility:{visible:!1}},a.add("KHR_node_visibility")),k.userData&&Object.keys(k.userData).length>0&&(Y.extras=JSON.parse(JSON.stringify(k.userData,(oe,j)=>{if(!(oe==="__proto__"||oe==="prototype"||oe==="constructor"))return typeof j=="function"?void 0:j})),k.userData.xr)){let oe=bc(k.userData.xr);Y.extensions={...Y.extensions||{},MOZ_hubs_components:oe,ANDROID_xr_scenecore:oe},Me().xrTraitSerializer?.gltfNode(Y,k.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(k.geometry){let oe=k.geometry,j=oe.attributes.position;if(j&&j.count>0){let A=[1/0,1/0,1/0],S=[-1/0,-1/0,-1/0];for(let K=0;K<j.count;K++){let Z=j.getX(K),q=j.getY(K),re=j.getZ(K);Z<A[0]&&(A[0]=Z),Z>S[0]&&(S[0]=Z),q<A[1]&&(A[1]=q),q>S[1]&&(S[1]=q),re<A[2]&&(A[2]=re),re>S[2]&&(S[2]=re)}let L={attributes:{POSITION:y(j.array,"VEC3",34962,5126,j.count,A,S)}};if(oe.attributes.normal&&(L.attributes.NORMAL=y(oe.attributes.normal.array,"VEC3",34962,5126,oe.attributes.normal.count)),oe.attributes.uv&&(L.attributes.TEXCOORD_0=y(oe.attributes.uv.array,"VEC2",34962,5126,oe.attributes.uv.count)),oe.index){let K=oe.index.array instanceof Uint32Array;L.indices=y(oe.index.array,"SCALAR",34963,K?5125:5123,oe.index.count)}let O=Array.isArray(k.material)?k.material[0]:k.material;O&&(L.material=v(O));let I=k.userData?.variants;if(I&&typeof I=="object"){let K=new Map;for(let Z of Object.keys(I)){if(!Z||Z==="__proto__"||Z==="constructor"||Z==="prototype")continue;let q=I[Z];if(!q||typeof q!="object")continue;let re=x.indexOf(Z);if(re===-1&&x.length<256&&(re=x.length,x.push(Z)),re===-1)continue;let ne=v(q),te=K.get(ne);te||(te=[],K.set(ne,te)),te.push(re)}if(K.size>0){let Z=[];for(let[q,re]of K.entries())Z.push({material:q,variants:re});L.extensions={...L.extensions||{},KHR_materials_variants:{mappings:Z}},a.add("KHR_materials_variants")}}let W=k;if(W.isInstancedMesh&&typeof W.count=="number"&&W.count>0&&W.instanceMatrix?.array){let K=Math.min(1e4,Math.floor(W.count)),Z=W.instanceMatrix.array,q=new Float32Array(K*3),re=new Float32Array(K*4),ne=new Float32Array(K*3);for(let ue=0;ue<K;ue++){let{t:me,r:pe,s:fe}=Ms(Z,ue*16);q[ue*3]=me[0],q[ue*3+1]=me[1],q[ue*3+2]=me[2],re[ue*4]=pe[0],re[ue*4+1]=pe[1],re[ue*4+2]=pe[2],re[ue*4+3]=pe[3],ne[ue*3]=fe[0],ne[ue*3+1]=fe[1],ne[ue*3+2]=fe[2]}let te={TRANSLATION:y(q,"VEC3",0,5126,K),ROTATION:y(re,"VEC4",0,5126,K),SCALE:y(ne,"VEC3",0,5126,K)};if(W.instanceColor?.array&&W.instanceColor.array.length>=K*3){let ue=new Float32Array(W.instanceColor.array.subarray(0,K*3));te._COLOR_0=y(ue,"VEC3",0,5126,K)}Y.extensions={...Y.extensions||{},EXT_mesh_gpu_instancing:{attributes:te}},a.add("EXT_mesh_gpu_instancing")}let Q=l.length;l.push({primitives:[L],name:k.name,...Y.extras?{extras:Y.extras}:{}}),Y.mesh=Q}}let ee=o.length;o.push(Y),u.push(k),J.push(ee);let se=k.children;if(Array.isArray(se)&&se.length>0){let oe=[];Y.children=oe;for(let j=se.length-1;j>=0;j--)V.push({obj:se[j],parentKids:oe})}}for(let k=0;k<o.length;k++){let J=o[k];J.children&&J.children.length===0?delete J.children:J.children&&J.children.length>0&&(J.extras?.xr?.lod||J.extensions?.ANDROID_xr_scenecore?.lod||u[k]?.isLOD)&&(J.extensions={...J.extensions||{},MSFT_lod:{ids:[...J.children]}},a.add("MSFT_lod"))}let X=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),P=[];if(typeof X=="function"&&u.length>0){let k=t?.duration??4,J=t?.fps??15,z=Math.max(2,Math.round(k*J)+1),Y=new Float32Array(z),le=u.map(E=>[ve(E.position?.x,0),ve(E.position?.y,0),ve(E.position?.z,0),ve(E.quaternion?.x,0),ve(E.quaternion?.y,0),ve(E.quaternion?.z,0),ve(E.quaternion?.w,1),ve(E.scale?.x,1),ve(E.scale?.y,1),ve(E.scale?.z,1)]),ce=u.map(()=>new Float32Array(z*3)),$=u.map(()=>new Float32Array(z*4)),U=u.map(()=>new Float32Array(z*3));for(let E=0;E<z;E++){let G=E/(z-1)*k;Y[E]=G;try{X(G)}catch{}for(let ee=0;ee<u.length;ee++){let se=u[ee];ce[ee][E*3]=ve(se.position?.x,0),ce[ee][E*3+1]=ve(se.position?.y,0),ce[ee][E*3+2]=ve(se.position?.z,0);let oe=ve(se.quaternion?.x,0),j=ve(se.quaternion?.y,0),A=ve(se.quaternion?.z,0),S=ve(se.quaternion?.w,1),L=Math.hypot(oe,j,A,S)||1;if(oe/=L,j/=L,A/=L,S/=L,E>0){let O=(E-1)*4,I=$[ee];I[O]*oe+I[O+1]*j+I[O+2]*A+I[O+3]*S<0&&(oe=-oe,j=-j,A=-A,S=-S)}$[ee][E*4]=oe,$[ee][E*4+1]=j,$[ee][E*4+2]=A,$[ee][E*4+3]=S,U[ee][E*3]=ve(se.scale?.x,1),U[ee][E*3+1]=ve(se.scale?.y,1),U[ee][E*3+2]=ve(se.scale?.z,1)}}for(let E=0;E<u.length;E++){let G=u[E],ee=le[E];G.position?.set(ee[0],ee[1],ee[2]),G.quaternion?.set(ee[3],ee[4],ee[5],ee[6]),G.scale?.set(ee[7],ee[8],ee[9])}e.updateMatrixWorld(!0);let _=null,H=()=>(_===null&&(_=y(Y,"SCALAR",0,5126,z,[0],[k])),_),D=[],F=[];for(let E=0;E<u.length;E++){let G=le[E],ee=(oe,j,A)=>oe.some((S,L)=>Math.abs(S-G[A+L%j])>1e-4),se=(oe,j,A,S)=>{oe&&F.push({sampler:D.push({input:H(),interpolation:"LINEAR",output:y(j,A,0,5126,z)})-1,target:{node:E,path:S}})};se(ee(ce[E],3,0),ce[E],"VEC3","translation"),se(ee($[E],4,3),$[E],"VEC4","rotation"),se(ee(U[E],3,7),U[E],"VEC3","scale")}F.length>0&&P.push({name:"ProceduralLoop",samplers:D,channels:F})}let R=Xo(o,l,e.userData),C=[],B=[],N=[];for(let k=0;k<o.length;k++){let J=o[k],z=Ts(J.extras?.xr);if(!z)continue;let{ae:Y,src:le,preset:ce,volume:$,loop:U,isGlobal:_}=z,H=J.name||`Node_${k}`,D=B.length;B.push({name:`${H}_source`,gain:$,loop:U,autoPlay:typeof Y.autoplay=="boolean"?Y.autoplay:!0,...le!==void 0?{audio:C.push({uri:le})-1}:{},...ce?{extras:{preset:ce,pitch:Pt(Y.pitch,.25,4,1)}}:{}});let F=N.length,E=Pt(Y.refDistance,.05,100,1),G=Pt(Y.coneInnerAngle,0,360,360),ee=Pt(Y.coneOuterAngle,G,360,360);N.push({name:`${H}_emitter`,type:_?"global":"positional",gain:$,sources:[D],..._?{}:{positional:{distanceModel:Y.distanceModel==="linear"||Y.distanceModel==="exponential"?Y.distanceModel:"inverse",refDistance:E,maxDistance:Pt(Y.maxDistance,E,500,Math.max(E,25)),rolloffFactor:Pt(Y.rolloffFactor,0,10,1),coneInnerAngle:+(G*Math.PI/180).toFixed(6),coneOuterAngle:+(ee*Math.PI/180).toFixed(6),coneOuterGain:Pt(Y.coneOuterGain,0,1,0)}}}),J.extensions={...J.extensions||{},KHR_audio_emitter:{emitter:F}},a.add("KHR_audio_emitter")}let w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:M}],scene:0,nodes:o,meshes:l,materials:h,...f.length>0?{images:f}:{},...p.length>0?{samplers:p}:{},...m.length>0?{textures:m}:{},accessors:s,bufferViews:n,buffers:[{byteLength:i}],...P.length>0?{animations:P}:{},...R||a.size>0?{extensionsUsed:[...R?["KHR_interactivity"]:[],...a]}:{},...R||x.length>0||N.length>0?{extensions:{...R?{KHR_interactivity:R}:{},...x.length>0?{KHR_materials_variants:{variants:x.map(k=>({name:k}))}}:{},...N.length>0?{KHR_audio_emitter:{...C.length>0?{audio:C}:{},sources:B,emitters:N}}:{}}}:{}},ie=new Uint8Array(i),ae=0;for(let k of r)ie.set(k,ae),ae+=k.byteLength;return[{gltf:w,bin:ie.buffer,lights:b,environmentIntensity:e.environmentIntensity},u]}function Oi(e){return new TextEncoder().encode(e)}function vn(e,t){let{gltf:r,bin:i}=on(e,t),n=JSON.stringify(r),s=Oi(n),l=(4-s.byteLength%4)%4,o=s.byteLength+l,a=20+o+8+i.byteLength,u=new Uint8Array(a),h=new DataView(u.buffer);h.setUint32(0,1179937895,!0),h.setUint32(4,2,!0),h.setUint32(8,a,!0),h.setUint32(12,o,!0),h.setUint32(16,1313821514,!0),u.set(s,20);for(let f=0;f<l;f++)u[20+s.byteLength+f]=32;let c=20+o;return h.setUint32(c,i.byteLength,!0),h.setUint32(c+4,5130562,!0),u.set(new Uint8Array(i),c+8),u}function yc(e,t){let[r,i]=As(e,t);return Ui(r,i)}function Ui(e,t){let r=[],i=e.gltf,n=Me().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(i,e);let s=e.bin,l=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=i.accessors||[],a=i.bufferViews||[],u=i.materials||[],h=i.meshes||[],c=i.nodes||[],f=new Set,p=u.map((x,b)=>vs(f,ur(x?.name,`Material_${b}`)));function m(x){let b=o[x];if(!b)throw new Error(`Accessor ${x} not found`);let v=a[b.bufferView||0],d=(v.byteOffset||0)+(b.byteOffset||0),y=v.byteLength||0;return{acc:b,buffer:l.slice(d,d+y)}}function g(x,b,v,d){let y=[],M=h[x];if(!M)return y;let T=M.primitives||[];for(let V=0;V<T.length;V++){let X=T[V],P=X.attributes?.POSITION;if(P===void 0)continue;let{acc:R,buffer:C}=m(P),B=new Float32Array(C,0,R.count*3),N,w=X.attributes?.NORMAL;if(w!==void 0){let{acc:D,buffer:F}=m(w),E=new Float32Array(F,0,D.count*3);N=new Float32Array(E.length);for(let G=0;G<D.count;G++){let ee=E[G*3],se=E[G*3+1],oe=E[G*3+2],j=Math.hypot(ee,se,oe)||1;N[G*3]=ee/j,N[G*3+1]=se/j,N[G*3+2]=oe/j}}let ie,ae=X.attributes?.TEXCOORD_0;if(ae!==void 0){let{acc:D,buffer:F}=m(ae);ie=new Float32Array(F,0,D.count*2)}let k;if(X.indices!==void 0){let{acc:D,buffer:F}=m(X.indices);k=D.componentType===5125?new Uint32Array(F,0,D.count):new Uint16Array(F,0,D.count);let E=R.count;for(let G of k)if(G>=E)throw new Error(`SecurityError: Index buffer value (${G}) out of vertex bounds [0, ${E}).`)}else{let D=R.count;k=D>65535?new Uint32Array(D):new Uint16Array(D);for(let F=0;F<D;F++)k[F]=F}let J="DefaultMaterial",z=[.8,.8,.8],Y=.5,le=0,ce=0,$=0,U=1.5,_=1,H=[0,0,0];if(X.material!==void 0&&u[X.material]){let D=u[X.material];J=p[X.material]||`Material_${X.material}`;let F=D.pbrMetallicRoughness||{},E=(oe,j)=>Array.isArray(oe)&&oe.length>=3?[oe[0],oe[1],oe[2]]:j;z=E(F.baseColorFactor,[1,1,1]);let G=D.extras?.avgColor;Array.isArray(G)&&G.length>=3&&(z=[z[0]*G[0],z[1]*G[1],z[2]*G[2]]);let ee=Array.isArray(F.baseColorFactor)&&typeof F.baseColorFactor[3]=="number"?F.baseColorFactor[3]:1;typeof F.roughnessFactor=="number"&&(Y=F.roughnessFactor),typeof F.metallicFactor=="number"&&(le=F.metallicFactor),H=E(D.emissiveFactor,[0,0,0]);let se=D.extensions||{};se.KHR_materials_clearcoat&&(ce=se.KHR_materials_clearcoat.clearcoatFactor??0,$=se.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof se.KHR_materials_ior?.ior=="number"&&(U=se.KHR_materials_ior.ior),_=ee*(1-(se.KHR_materials_transmission?.transmissionFactor??0))}y.push({name:T.length>1?`${b}_p${V}`:b,positions:B,indices:k,normals:N,uvs:ie,materialName:J,color:z,roughness:Y,metallic:le,clearcoat:ce,clearcoatRoughness:$,ior:U,opacity:_,emissiveColor:H,xrTraits:v||M.extras?.xr,...d?{invisible:!0}:{}})}return y}if(c.length>0){let x=new Float32Array(0),b=new Uint16Array(0),v=(B,N)=>{if(B===void 0)return null;let{acc:w,buffer:ie}=m(B);return new Float32Array(ie,0,w.count*N)},d=(B,N)=>Array.isArray(B)&&B.length>=3?[ve(B[0],N),ve(B[1],N),ve(B[2],N)]:[N,N,N],y=(B,N,w)=>B&&B.length>=(N+1)*3?[B[N*3],B[N*3+1],B[N*3+2]]:w,M=(B,N,w)=>B&&B.length>=(N+1)*4?[B[N*4],B[N*4+1],B[N*4+2],B[N*4+3]]:w,T=new Map,V=i.animations?.[0];if(V&&Array.isArray(V.channels)&&Array.isArray(V.samplers))for(let B of V.channels){let N=V.samplers[B?.sampler],w=B?.target?.node,ie=B?.target?.path;if(!N||typeof w!="number"||N.input===void 0)continue;let ae=T.get(w);ae||(ae={input:N.input},T.set(w,ae)),ie==="translation"?ae.t=N.output:ie==="rotation"?ae.r=N.output:ie==="scale"&&(ae.s=N.output)}let X=i.scenes?.[i.scene??0]?.nodes??[];if(!Array.isArray(X)||X.length===0){let B=new Set;for(let N of c)if(Array.isArray(N?.children))for(let w of N.children)B.add(w);X=[];for(let N=0;N<c.length;N++)B.has(N)||X.push(N);X.length===0&&(X=[0])}let P=new Set,R=[],C=(B,N)=>{if(Array.isArray(B))for(let w=B.length-1;w>=0;w--)R.push({idx:B[w],out:N})};for(C(X,r);R.length>0;){let{idx:B,out:N}=R.pop();if(typeof B!="number"||B<0||B>=c.length||P.has(B))continue;P.add(B);let w=c[B];if(!w)continue;let ie=[0,0,0],ae=[0,0,0,1],k=[1,1,1];if(Array.isArray(w.matrix)&&w.matrix.length===16){let _=Ms(w.matrix);ie=_.t,ae=_.r,k=_.s}else ie=d(w.translation,0),Array.isArray(w.rotation)&&w.rotation.length>=4&&(ae=[ve(w.rotation[0],0),ve(w.rotation[1],0),ve(w.rotation[2],0),ve(w.rotation[3],1)]),k=d(w.scale,1);let J,z=T.get(B);if(z){let _=v(z.input,1);if(_&&_.length>0){let H=v(z.t,3),D=v(z.r,4),F=v(z.s,3),E=Array.from(_),G=[],ee=[],se=[];for(let oe=0;oe<_.length;oe++)G.push(y(H,oe,ie)),ee.push(M(D,oe,ae)),se.push(y(F,oe,k));J={times:E,translations:G,rotations:ee,scales:se}}}let Y=Array.isArray(w.children)?w.children:[],le=typeof w.mesh=="number"&&w.mesh>=0&&w.mesh<h.length,ce=t?.[B]?.userData?.xr??w.extras?.xr;if(!le&&Y.length===0&&(w.camera!==void 0||w.extensions?.KHR_lights_punctual||!w.name&&!w.extras&&!ce&&!J))continue;let $=(_,H,D)=>({name:_,positions:x,indices:b,isXform:!0,xrTraits:ce,timeSamples:J,translation:ie,rotation:ae,scale:k,children:H,...D?{invisible:!0}:{}}),U=w.visible===!1||w.extensions?.KHR_node_visibility?.visible===!1||t?.[B]?.visible===!1;if(le){let _=w.name||h[w.mesh]?.name||`Mesh_${B}`,H=g(w.mesh,_,ce,U),D=w.extensions?.EXT_mesh_gpu_instancing?.attributes;if(D&&typeof D=="object"&&H.length>0){let F=v(D.TRANSLATION,3),E=v(D.ROTATION,4),G=v(D.SCALE,3),ee=v(D._COLOR_0,3),se=Math.min(1e3,F?F.length/3:E?E.length/4:G?G.length/3:0);if(se>0){let oe=[];for(let j=0;j<se;j++){let A=y(F,j,[0,0,0]),S=M(E,j,[0,0,0,1]),L=y(G,j,[1,1,1]);for(let O of H){let I=O.color||[.8,.8,.8],W=ee&&ee.length>=(j+1)*3;oe.push({...O,name:`${O.name}_${j}`,materialName:W?`${O.materialName}_inst_${j}`:O.materialName,color:W?[I[0]*ee[j*3],I[1]*ee[j*3+1],I[2]*ee[j*3+2]]:O.color,translation:A,rotation:S,scale:L})}}C(Y,oe),N.push($(_,oe,U));continue}}if(H.length===1)H[0].translation=ie,H[0].rotation=ae,H[0].scale=k,H[0].timeSamples=J,Y.length>0&&(H[0].children=[],C(Y,H[0].children)),N.push(H[0]);else{let F=[...H];C(Y,F),N.push($(_,F,U))}}else{let _=[];C(Y,_),N.push($(w.name||`Group_${B}`,_,U))}}}else for(let x=0;x<h.length;x++){let b=h[x].name||`Mesh_${x}`;r.push(...g(x,b,h[x].extras?.xr))}return r}function ur(e,t){if(!e||typeof e!="string")return t;let r=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(r)&&(r="_"+r),r||t}function Ni(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function Ge(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var xt=(e,t,r)=>`(${Ge(e)}, ${Ge(t)}, ${Ge(r)})`,gs=(e,t,r,i)=>`(${Ge(e)}, ${Ge(t)}, ${Ge(r)}, ${Ge(i)})`;function xs(e){let t=e.length/3,r=new Array(t);for(let i=0;i<t;i++)r[i]=xt(e[i*3],e[i*3+1],e[i*3+2]);return r.join(", ")}function gc(e,t){let r=new Array(t);for(let i=0;i<t;i++)r[i]=`(${Ge(e[i*2])}, ${Ge(1-e[i*2+1])})`;return r.join(", ")}function xc(e){return Array.from(e).join(", ")}function ki(e){let t=new Map,r=0,i=null,n=[...e];for(;n.length>0;){let m=n.pop();if(!m.isXform&&m.positions&&m.positions.length>0){let g=ur(m.materialName,"DefaultMaterial");t.has(g)||t.set(g,{color:m.color||[.8,.8,.8],roughness:m.roughness??.5,metallic:m.metallic??0,clearcoat:m.clearcoat??0,clearcoatRoughness:m.clearcoatRoughness??0,ior:m.ior??1.5,opacity:m.opacity??1,emissiveColor:m.emissiveColor||[0,0,0]})}if(m.timeSamples&&m.timeSamples.times.length>0){let g=m.timeSamples.times[m.timeSamples.times.length-1];g>r&&(r=g)}if(m.xrTraits?.anchor&&!i&&(i=m.xrTraits.anchor==="vertical"||m.xrTraits.anchor==="wall"?"vertical":"horizontal"),m.children)for(let g=m.children.length-1;g>=0;g--)n.push(m.children[g])}let s="";r>0&&(s=`startTimeCode = 0
251
- endTimeCode = ${Ge(r)}
250
+ void main(){fragColor=uColorId;}`;function Oi(e,t,r){let i={};for(let n of r)i[n]=e.getUniformLocation(t,n);return i}var Qo=["uMVP","uModel","uInstanced","uViewProj","uNormalMatrix","uUvTransform","uBaseColor","uMetallic","uRoughness","uClearcoat","uEmissive","uCameraPos","uBaseColorTexture","uHasTexture","uMetallicRoughnessTexture","uHasMetallicRoughnessTexture","uNormalTexture","uHasNormalTexture","uNormalScale","uOcclusionTexture","uHasOcclusionTexture","uOcclusionStrength","uToneMapping","uEnvironmentMap","uHasEnvironmentMap","uAmbientColor","uNumDirLights","uDirLightDir","uDirLightColor","uNumPointLights","uPointLightPos","uPointLightColor","uPointLightSpotDir","uPointLightSpotCone","uEnvIntensity","uExposure","uViewportSize","uSectionPlane","uSectionEnabled"];function os(){let e=Ae().xrDepthShader;return{fs:tc.replace("/*XRD_U*/",e?.uniformsGLSL||"").replace("/*XRD_O*/",e?.occlusionGLSL||""),uniforms:e?[...Qo,...e.uniformNames]:Qo}}function ic(e){if(typeof e!="string")return null;let t=e.trim();if(!t||/[\x00-\x1f\x7f]/.test(t))return null;let r=t.toLowerCase();return r.startsWith("data:")?/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(t)?t:null:r.startsWith("https://")||r.startsWith("blob:")?t:r.startsWith("//")||/^[a-z][a-z0-9+.-]*:/i.test(t)||/(^|[\\/])\.\.([\\/]|$)/.test(t)?null:t}function Ni(e,t,r,i,n,s,l,o){if(i===void 0||!t.accessors?.[i])return null;let a=bt(t,r,t.accessors[i],s);if(!a)return null;o&&(a=a.slice(),Zo(a,o));let u=e.createBuffer();return l.push(u),e.bindBuffer(34962,u),e.bufferData(34962,a,35044),e.enableVertexAttribArray(n),e.vertexAttribPointer(n,s,5126,!1,0,0),a}function ki(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,t):1}function ss(e,t,r){let i=os(),n=rs,s=i.fs,l=!1;for(let a of Oe)if(a.onResolveShader){let u=a.onResolveShader(t,r,n,s);u&&(n=u.vs,s=u.fs,l=!0)}let o=l?_t(e,n,s):null;return{program:o,uniforms:o?Oi(e,o,i.uniforms):null}}function oc(e,t,r){let i=t.instanceMatrices;if(!i||i.length<16||typeof e.vertexAttribDivisor!="function"||typeof e.drawElementsInstanced!="function")return!1;let n=i.length>>4,s=t.instanceColors,l=new Float32Array(n*20);for(let a=0;a<n;a++)l.set(i.subarray(a*16,a*16+16),a*20),l[a*20+16]=s?s[a*3]:1,l[a*20+17]=s?s[a*3+1]:1,l[a*20+18]=s?s[a*3+2]:1,l[a*20+19]=1;let o=e.createBuffer();r.push(o),e.bindBuffer(34962,o),e.bufferData(34962,l,35044);for(let a=0;a<5;a++)e.enableVertexAttribArray(8+a),e.vertexAttribPointer(8+a,4,5126,!1,80,a*16),e.vertexAttribDivisor(8+a,1);return!0}function sc(e,t){let r=e.materials?.[t?.material];if(!r)return null;let i=[r.pbrMetallicRoughness?.baseColorTexture,r.pbrMetallicRoughness?.metallicRoughnessTexture,r.normalTexture,r.occlusionTexture,r.emissiveTexture];for(let n of i){let s=n?.extensions?.KHR_texture_transform;if(s&&typeof s=="object")return s}return null}var as=Object.freeze({maxMeshes:1e3,maxTextures:64,maxVertices:1e6,maxIndices:3e6}),cs=Object.freeze({maxMeshes:1/0,maxTextures:1/0,maxVertices:1/0,maxIndices:1/0});function cr(e,t){t.indices?e.drawElements(4,t.indexCount,t.indexType,0):e.drawArrays(4,0,t.indexCount)}function us(e,t){let r=e?.pbrMetallicRoughness,i=r?.baseColorFactor,n=e?.extensions?.KHR_materials_clearcoat,s=l=>l!==void 0&&t[l.index]?t[l.index]:null;return{baseColor:i?[i[0],i[1],i[2],i[3]??1]:[.8,.8,.8,1],metallic:r?.metallicFactor??.1,roughness:r?.roughnessFactor??.5,clearcoat:n?n.clearcoatFactor??1:0,clearcoatRoughness:Math.max(.04,n?.clearcoatRoughnessFactor??.04),texture:s(r?.baseColorTexture),metallicRoughnessTexture:s(r?.metallicRoughnessTexture),normalTexture:s(e?.normalTexture),normalScale:e?.normalTexture?.scale??1,occlusionTexture:s(e?.occlusionTexture),occlusionStrength:e?.occlusionTexture?.strength??1,isTransmissive:(e?.extensions?.KHR_materials_transmission?.transmissionFactor??0)>0}}function ls(e,t,r){let i=new Set,n=s=>{s&&!i.has(s)&&(i.add(s),e.deleteTexture(s))};for(let s of t)for(let l of s.primitives){if(l.vao&&e.deleteVertexArray(l.vao),l.buffers)for(let a of l.buffers)e.deleteBuffer(a);n(l.texture),n(l.metallicRoughnessTexture),n(l.normalTexture),n(l.occlusionTexture);let o=new Set;l.customProgram&&o.add(l.customProgram);for(let a of l.programCache?.values()??[])a.program&&o.add(a.program);for(let a of o)e.deleteProgram(a)}if(r)for(let s of r)n(s)}function Jo(e,t,r=cs,i){let n={meshes:[],mesh:null,gpuTextures:[],vao:null,buffers:[]};try{return ac(e,t,r,i,n)}catch(s){let l=n.mesh&&!n.meshes.includes(n.mesh)?[...n.meshes,n.mesh]:n.meshes;ls(e,l,n.gpuTextures),n.vao&&e.deleteVertexArray(n.vao);for(let o of n.buffers)e.deleteBuffer(o);throw s}}function ac(e,t,r,i,n){if(!t||!t.gltf)throw new Error("Invalid GLBData passed to buildGpuScene: missing gltf object.");let{gltf:s}=t,l=nn("meshopt");l?.decodeBufferViews&&l.decodeBufferViews(s,t);let o=t.bin,a=[];n.meshes=a;let u=[],h=s.extensions?.KHR_materials_variants;h&&Array.isArray(h.variants)&&h.variants.forEach((k,w)=>{u.push(typeof k?.name=="string"&&k.name?k.name:`Variant_${w}`)});let m=Ft(s),c=[];if(Array.isArray(s.nodes))for(let k=0;k<s.nodes.length;k++){let w=s.nodes[k];w.mesh!==void 0&&s.meshes&&s.meshes[w.mesh]&&c.push({node:w,nodeIdx:k,meshIdx:w.mesh})}let d=c.length>0?c:(s.meshes||[]).map((k,w)=>({node:k,nodeIdx:-1,meshIdx:w})),f=[],g=Array.isArray(t.lights)&&t.lights.length>0?t.lights:Array.isArray(s.asset?.extras?.lights)&&s.asset.extras.lights.length>0?s.asset.extras.lights:null;if(g)for(let k of g)f.push({...k,type:k.type||k.light_type||"point",innerConeAngle:k.innerConeAngle??k.inner_cone_angle,outerConeAngle:k.outerConeAngle??k.outer_cone_angle});else if(s.extensions?.KHR_lights_punctual?.lights){let k=s.extensions.KHR_lights_punctual.lights;for(let w of k){let ie=w.type==="directional"?"directional":w.type==="point"?"point":w.type==="spot"?"spot":"ambient";f.push({type:ie,color:w.color||[1,1,1],intensity:w.intensity!==void 0?w.intensity:1})}}if(f.length===0&&(f.push({type:"ambient",color:[1,1,1],intensity:.35}),f.push({type:"directional",color:[1,1,1],intensity:.85,direction:[.5,1,.8]})),d.length>r.maxMeshes)throw new Error(`SecurityError: GLB scene exceeds host mesh limit (${r.maxMeshes}). Found: ${d.length}`);let x=[];if(n.gpuTextures=x,s.textures&&s.images){if(s.textures.length>r.maxTextures)throw new Error(`SecurityError: GLB scene exceeds host texture limit (${r.maxTextures}). Found: ${s.textures.length}`);for(let k=0;k<s.textures.length;k++){let w=s.textures[k],ie=s.images[w.source];if(ie){let oe=e.createTexture();e.bindTexture(3553,oe),e.texImage2D(3553,0,6408,1,1,0,6408,5121,new Uint8Array([255,255,255,255])),e.texParameteri(3553,10242,10497),e.texParameteri(3553,10243,10497),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729);let I=H=>{e.bindTexture(3553,oe),e.texImage2D(3553,0,6408,6408,5121,H),e.generateMipmap(3553),i?.()};if(ie.bufferView!==void 0){let H=s.bufferViews[ie.bufferView],N=H.byteOffset||0,z=new Blob([o.slice(N,N+H.byteLength)],{type:ie.mimeType||"image/png"});typeof createImageBitmap=="function"&&createImageBitmap(z).then(I).catch(()=>{})}else if(ie.uri){let H=ic(ie.uri);if(H){let N=new Image;N.crossOrigin="anonymous",N.referrerPolicy="no-referrer",N.onload=()=>I(N),N.src=H}else console.warn("[Three-Live Security] Blocked unsafe glTF image URI:",ie.uri)}x.push(oe)}else x.push(null)}}let b=[1/0,1/0,1/0],v=[-1/0,-1/0,-1/0],p=0,y=0;for(let k=0;k<d.length;k++){let w=d[k],ie=s.meshes[w.meshIdx],oe=w.nodeIdx>=0?m[w.nodeIdx]:Se(),I=new Float32Array(9);Xe(I,oe);let H={name:w.node.name||ie.name||`Mesh_${w.meshIdx}`,nodeIndex:w.nodeIdx,transform:oe,normalMatrix:I,primitives:[],extras:w.node.extras||ie.extras,...w.node?.visible===!1||w.node?.extensions?.KHR_node_visibility?.visible===!1?{visible:!1}:{}};n.mesh=H;let N=w.node?.extensions?.EXT_mesh_gpu_instancing;if(N&&N.attributes&&typeof N.attributes=="object"){let z=N.attributes,ue=z.TRANSLATION!==void 0?s.accessors?.[z.TRANSLATION]:null,ce=z.ROTATION!==void 0?s.accessors?.[z.ROTATION]:null,B=z.SCALE!==void 0?s.accessors?.[z.SCALE]:null,$=z._COLOR_0!==void 0?s.accessors?.[z._COLOR_0]:null,_=Number(ue?.count??ce?.count??B?.count??0);if(!Number.isFinite(_)||_<0||_>1e4)throw new Error(`SecurityError: EXT_mesh_gpu_instancing exceeds maximum instance limit (10000). Found: ${_}`);if(_>0){let G=(V,ee)=>{if(!V||V.bufferView===void 0||!s.bufferViews?.[V.bufferView])return null;let R=V.componentType??5126,A=C=>(console.warn(`[three-live] EXT_mesh_gpu_instancing: skipping accessor (${C})`),null);if(R!==5120&&R!==5121&&R!==5122&&R!==5123&&R!==5126)return A(`componentType ${R}`);if(!(Number(V.count)>=_))return A(`count ${V.count} < ${_}`);let L=null;try{L=bt(s,o,{...V,count:_},ee)}catch{return A("out of bounds")}return!L||!L.every(Number.isFinite)?A("non-finite value"):L},j=G(ue,3),q=G(ce,4),D=G(B,3),Y=$?.type==="VEC4"?4:3,te=G($,Y),se=new Float32Array(_*16),le=Se();for(let V=0;V<_;V++){let ee=j?[j[V*3],j[V*3+1],j[V*3+2]]:[0,0,0],R=q?[q[V*4],q[V*4+1],q[V*4+2],q[V*4+3]]:[0,0,0,1],A=D?[D[V*3],D[V*3+1],D[V*3+2]]:[1,1,1];Tt(le,R,ee,A),se.set(le,V*16)}if(H.instanceMatrices=se,te){let V=new Float32Array(_*3);for(let ee=0;ee<_;ee++)V[ee*3]=te[ee*Y],V[ee*3+1]=te[ee*Y+1],V[ee*3+2]=te[ee*Y+2];H.instanceColors=V}}}for(let z of ie.primitives||[]){if(z.extensions?.KHR_draco_mesh_compression){let L=nn("draco");L&&L.decodePrimitive(s,z,o)}let ue=[],ce=e.createVertexArray();n.vao=ce,n.buffers=ue,e.bindVertexArray(ce);let B=oc(e,H,ue),$=s.accessors[z.attributes.POSITION],_=Number($?.count??0);if(!Number.isFinite(_)||_<0||p+_>r.maxVertices)throw new Error(`SecurityError: GLB scene exceeds host vertex limit (${r.maxVertices}).`);if(p+=_,$?.min&&$?.max){let L=C=>{for(let U=0;U<3;U++){let Q=C[12+U],X=C[12+U];for(let Z=0;Z<3;Z++){let J=C[Z*4+U]*$.min[Z],K=C[Z*4+U]*$.max[Z];Q+=J<K?J:K,X+=J>K?J:K}Q<b[U]&&(b[U]=Q),X>v[U]&&(v[U]=X)}};if(H.instanceMatrices&&H.instanceMatrices.length>=16){let C=H.instanceMatrices.length>>4,U=Se();for(let Q=0;Q<C;Q++){let X=H.instanceMatrices.subarray(Q*16,Q*16+16);Ie(U,oe,X),L(U)}}else L(oe)}let G=Ni(e,s,o,z.attributes.POSITION,0,3,ue);Ni(e,s,o,z.attributes.NORMAL,1,3,ue),Ni(e,s,o,z.attributes.TEXCOORD_0,2,2,ue,sc(s,z));let j=0,q=5123,D=null;if(z.indices!==void 0){let L=s.accessors[z.indices],C=(s.bufferViews[L.bufferView].byteOffset||0)+(L.byteOffset||0);if(j=Number(L.count??0),!Number.isFinite(j)||j<0||y+j>r.maxIndices)throw new Error(`SecurityError: GLB scene exceeds host index limit (${r.maxIndices}).`);y+=j,q=L.componentType===5125?5125:5123;let U=e.createBuffer();ue.push(U),e.bindBuffer(34963,U),L.componentType===5125?D=new Uint32Array(o,C,L.count):L.componentType===5121?D=Uint16Array.from(new Uint8Array(o,C,L.count)):D=C%2===0?new Uint16Array(o,C,L.count):new Uint16Array(o.slice(C,C+L.count*2)),e.bufferData(34963,D,35044)}else j=$.count;let Y={};for(let L of Oe)if(L.onBuildPrimitiveVAO){let C=L.onBuildPrimitiveVAO(e,ce,z,s,o);C&&(Y[L.name]=C)}e.bindVertexArray(null);let te=s.materials&&z.material!==void 0?s.materials[z.material]:null,{program:se,uniforms:le}=ss(e,z,te),V=us(te,x),ee=!!(te?.extensions?.KHR_materials_transmission||Y.materials?.isTransmissive),R=z.extensions?.KHR_materials_variants?.mappings,A=Array.isArray(R)?R.filter(L=>L&&typeof L.material=="number"&&Array.isArray(L.variants)).map(L=>({material:L.material|0,variants:L.variants.map(C=>Number(C)|0)})):void 0;H.primitives.push({vao:ce,instanced:B,indexCount:j,indexType:q,...V,positions:G,indices:D,buffers:ue,materialIndex:z.material,defaultMaterialIndex:z.material,variantMappings:A,primitiveDef:z,programCache:new Map([[z.material??-1,{program:se,uniforms:le}]]),pluginData:Y,customProgram:se,customUniforms:le,isTransmissive:ee})}a.push(H)}isFinite(b[0])||(b=[-1,-1,-1]),isFinite(v[0])||(v=[1,1,1]);let M=[(b[0]+v[0])/2,(b[1]+v[1])/2,(b[2]+v[2])/2],P=v[0]-b[0],F=v[1]-b[1],W=v[2]-b[2],T=Math.max(Math.hypot(P,F,W)/2,.5),E=[b[0],b[1],b[2]],S=[v[0],v[1],v[2]],O=t.animations;if(!O){for(let k of Oe)if(k.onParseGLB?.(t),t.animations){O=t.animations;break}}return O||(O=[]),{meshes:a,bounds:{center:M,radius:T,min:E,max:S},lights:f,animations:O,worldMatrices:m,gpuTextures:x,availableVariants:u}}function Mn(e){let t=e.customTarget||e.bounds.center,r=e.currDistance*Math.cos(e.currPhi);return[t[0]+r*Math.sin(e.currTheta),t[1]+e.currDistance*Math.sin(e.currPhi),t[2]+r*Math.cos(e.currTheta)]}var Ke=class{constructor(e,t,r){this.supportsInstanceOffsets=!0,this.meshes=[],this.backdropMeshes=[],this.bounds={center:[0,0,0],radius:1,min:[-1,-1,-1],max:[1,1,1]},this.lights=[],this.modelRootMatrix=Se(),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=Se(),this.viewMatrix=Se(),this.activeViewMatrix=null,this.modelMatrix=Se(),this.mvpMatrix=Se(),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:Se(),rawValueToMeters:.001,format:0},this.container=e;let i,n;if(t&&typeof t.getContext=="function"?(i=t,n=r):(n=t,i=n?.canvas),!i){let o=e.querySelector("canvas");o||(o=document.createElement("canvas"),o.style.width="100%",o.style.height="100%",o.style.display="block",o.style.touchAction="none",e.prepend(o)),i=o}this.canvas=i,this.opts=n||{},this.opts.clearColor&&(this.clearColor=this.opts.clearColor);let s=typeof window<"u"&&typeof window.matchMedia=="function"&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;this.opts.autoRotate!==void 0?this.autoRotate=this.opts.autoRotate&&!s:s&&(this.autoRotate=!1),this.opts.autoRotateSpeed!==void 0&&(this.autoRotateSpeed=this.opts.autoRotateSpeed),this.opts.autoRotateDelay!==void 0&&(this.autoRotateDelay=Math.max(0,Number(this.opts.autoRotateDelay)||0)),this.opts.exposure!==void 0&&(this.exposure=ki(this.opts.exposure)),this.opts.camera&&this.setInitialCamera(this.opts.camera.theta,this.opts.camera.phi,this.opts.camera.distance,this.opts.camera.zoom),this.opts.shadowIntensity!==void 0&&(this.shadowIntensity=Math.max(0,Math.min(1,Number(this.opts.shadowIntensity)||0))),this.opts.shadowSoftness!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(this.opts.shadowSoftness)||0))),this.opts.toneMapping!==void 0&&(this.toneMapping=Vt(this.opts.toneMapping)),this.opts.autoplay!==void 0&&(this.autoplay=this.opts.autoplay),this.opts.animationName!==void 0&&(this.animationName=this.opts.animationName),this.opts.variantName!==void 0&&(this.activeVariantName=this.opts.variantName||null),this.opts.fieldOfView!==void 0&&(this.fov=this.opts.fieldOfView*Math.PI/180),this.opts.distanceMode!==void 0&&(this.distanceMode=this.opts.distanceMode),this.opts.cameraTarget!==void 0&&(this.setTarget(this.opts.cameraTarget[0],this.opts.cameraTarget[1],this.opts.cameraTarget[2]),this.initialCustomTarget=[...this.opts.cameraTarget]),(this.opts.minCameraOrbit||this.opts.maxCameraOrbit)&&this.setOrbitLimits({minTheta:this.opts.minCameraOrbit?.theta,maxTheta:this.opts.maxCameraOrbit?.theta,minPhi:this.opts.minCameraOrbit?.phi,maxPhi:this.opts.maxCameraOrbit?.phi,minDistance:this.opts.minCameraOrbit?.distance,maxDistance:this.opts.maxCameraOrbit?.distance});let l=i.getContext("webgl2",{antialias:!0,alpha:!0,xrCompatible:!0});if(!l)throw new Error("WebGL2 not supported");this.gl=l,this.initGlState(),this.setupEvents(),this.setupContextLossHandling(),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}static registerDecoder(e,t){Ja(e,t)}static getDecoder(e){return nn(e)}setupContextLossHandling(){let e=this.canvas;typeof e?.addEventListener=="function"&&(this.boundContextLost=t=>{t.preventDefault?.(),this.contextLost=!0,this.stop()},this.boundContextRestored=()=>this.restoreContext(),e.addEventListener("webglcontextlost",this.boundContextLost),e.addEventListener("webglcontextrestored",this.boundContextRestored))}initGlState(){let e=this.gl,t=os();this.renderProg=_t(e,rs,t.fs),this.pickProg=_t(e,nc,rc),this.uRender=Oi(e,this.renderProg,t.uniforms),this.uPick=Oi(e,this.pickProg,["uMVP","uColorId"]),this.setupPickingFbo()}restoreContext(){let e=this.gl;this.contextLost=!1,this.initGlState();for(let t of Oe)t.onContextRestored?.(e,this);this.meshes=[],this.gpuTextures=[],this.environmentTexture=null,this.lastGlbData&&this.loadGLBData(this.lastGlbData,this.lastLimits),this.opts.environmentImage&&this.setEnvironmentImage(this.opts.environmentImage).catch(()=>{}),typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}setupPickingFbo(){let e=this.gl;if(typeof e.createFramebuffer!="function")return;this.pickFbo=e.createFramebuffer(),this.pickTexture=e.createTexture(),this.pickDepth=e.createRenderbuffer();let t=Math.max(1,this.canvas.width),r=Math.max(1,this.canvas.height);this.pickFboWidth=t,this.pickFboHeight=r,e.bindTexture(3553,this.pickTexture),e.texImage2D(3553,0,6408,t,r,0,6408,5121,null),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728),e.bindRenderbuffer(36161,this.pickDepth),e.renderbufferStorage(36161,33189,t,r),e.bindFramebuffer(36160,this.pickFbo),e.framebufferTexture2D(36160,36064,3553,this.pickTexture,0),e.framebufferRenderbuffer(36160,36096,36161,this.pickDepth),e.bindFramebuffer(36160,null)}resizePickingFbo(e,t){if(!this.pickFbo)return;let r=this.gl,i=Math.max(1,e),n=Math.max(1,t);this.pickFboWidth=i,this.pickFboHeight=n,r.bindTexture(3553,this.pickTexture),r.texImage2D(3553,0,6408,i,n,0,6408,5121,null),r.bindRenderbuffer(36161,this.pickDepth),r.renderbufferStorage(36161,33189,i,n)}loadGLBData(e,t){let{meshes:r,bounds:i,lights:n,animations:s,worldMatrices:l,gpuTextures:o,availableVariants:a}=Jo(this.gl,e,t,()=>this.render());if(this.lastGlbData=e,this.lastLimits=t,this.disposeMeshGpuResources(),this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.meshes=r,this.bounds=i,this.turntableRotation=0,this.updateTurntableMatrix(),this.lights=n,this.animations=s||[],this.worldMatrices=l||[],this.gpuTextures=o||[],this.availableVariants=a||[],this.gltf=e.gltf,this.activeVariantName&&!this.applyVariantMaterial(this.activeVariantName)&&(this.activeVariantName=null),this.initialNodeTransforms=[],Array.isArray(e.gltf?.nodes))for(let m of e.gltf.nodes)this.initialNodeTransforms.push({t:m.translation?[m.translation[0],m.translation[1],m.translation[2]]:[0,0,0],r:m.rotation?[m.rotation[0],m.rotation[1],m.rotation[2],m.rotation[3]]:[0,0,0,1],s:m.scale?[m.scale[0],m.scale[1],m.scale[2]]:[1,1,1]});this.autoplay&&this.animations.length>0&&this.playAnimation(this.animationName||void 0);for(let m of Oe)m.onLoadModel?.(this,this.gltf);this.customDistance||(this.initialDistance=this.distanceMode==="absolute"?3:i.radius*2.5,this.targetDistance=this.initialDistance,this.currDistance=this.initialDistance);let u=e.exposure??e.gltf?.extras?.exposure??e.gltf?.asset?.extras?.exposure;u!==void 0&&(this.exposure=ki(u));let h=e.environmentIntensity??e.gltf?.extras?.environmentIntensity??e.gltf?.asset?.extras?.environmentIntensity;h!==void 0&&(this.envIntensity=Math.max(0,Number(h)||0)),this.container&&typeof this.container.hasAttribute=="function"&&this.container.hasAttribute("poster")&&this.container.removeAttribute("poster"),this.resize(),this.update(0),this.render(),this.animFrameId===null&&typeof requestAnimationFrame<"u"&&this.opts.autoStart!==!1&&this.start()}loadGLB(e){this.loadGLBData(ns(e))}clearScene(){this.disposeMeshGpuResources(),this.lights=[],this.animations=[],this.currentClip=null,this.isPlayingAnimation=!1,this.animationTime=0,this.lastGlbData=null;for(let e of Oe)e.onClearScene?.(this);this.worldMatrices=[],this.gltf=null,this.initialNodeTransforms=[],this.turntableRotation=0,this.updateTurntableMatrix(),this.gl&&this.render()}loadModel(e){this.loadGLBData(Lt(e))}setBackdropGLB(e,t){if(this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[],!e){this.update(0),this.render();return}let r=Lt(e),{meshes:i}=Jo(this.gl,r,cs,()=>this.render());if(t)for(let n of i)n.transform[12]+=t[0],n.transform[13]+=t[1],n.transform[14]+=t[2],Xe(n.normalMatrix,n.transform);this.backdropMeshes=i,this.update(0),this.render()}setClearColor(e,t,r,i=1){this.clearColor=[e,t,r,i]}updateMeshTransforms(e){for(let t=0;t<this.meshes.length;t++){let r=this.meshes[t],i;e instanceof Map?i=e.get(r.name)??e.get(t):Array.isArray(e)?i=e[t]:e&&typeof e=="object"&&(Object.prototype.hasOwnProperty.call(e,r.name)?i=e[r.name]:Object.prototype.hasOwnProperty.call(e,t)&&(i=e[t])),i&&i.length===16&&(r.transform.set(i),Xe(r.normalMatrix,r.transform))}}bindLights(e=this.uRender){let t=this.gl,r=[.28,.28,.28],i=[],n=[],s=[],l=[],o=[],a=[];for(let u of this.lights){let h=u.color||[1,1,1],m=u.intensity!==void 0?u.intensity:1;if(u.type==="ambient")r=[h[0]*m,h[1]*m,h[2]*m];else if(u.type==="directional"&&i.length<6){let c=u.direction||[.5,1,.8];i.push(c[0],c[1],c[2]),n.push(h[0]*m,h[1]*m,h[2]*m)}else if((u.type==="point"||u.type==="spot")&&s.length<6){let c=u.position||[0,0,0];if(s.push(c[0],c[1],c[2]),l.push(h[0]*m,h[1]*m,h[2]*m),u.type==="spot"){let d=u.direction||[0,-1,0],f=Math.max(.01,Math.min(Math.PI/2,u.outerConeAngle??Math.PI/3)),g=Math.max(0,Math.min(f-1e-4,u.innerConeAngle??0));o.push(d[0],d[1],d[2]),a.push(Math.cos(g),Math.cos(f))}else o.push(0,-1,0),a.push(-2,-3)}}i.length===0&&(i.push(.5,1,.8),n.push(1,1,1)),t.uniform3fv(e.uAmbientColor,r),t.uniform1i(e.uNumDirLights,i.length/3),i.length>0&&(t.uniform3fv(e.uDirLightDir,i),t.uniform3fv(e.uDirLightColor,n)),t.uniform1i(e.uNumPointLights,s.length/3),s.length>0&&(t.uniform3fv(e.uPointLightPos,s),t.uniform3fv(e.uPointLightColor,l),e.uPointLightSpotDir&&t.uniform3fv(e.uPointLightSpotDir,o),e.uPointLightSpotCone&&t.uniform2fv(e.uPointLightSpotCone,a)),t.uniform1f(e.uEnvIntensity,this.envIntensity)}setExposure(e){this.exposure=ki(e)}getExposure(){return this.exposure}setShadow(e,t){this.shadowIntensity=Math.max(0,Math.min(1,Number(e)||0)),t!==void 0&&(this.shadowSoftness=Math.max(0,Math.min(1,Number(t)||0)))}getShadowIntensity(){return this.shadowIntensity}getShadowSoftness(){return this.shadowSoftness}setToneMapping(e){this.toneMapping=Vt(e)}getToneMapping(){return this.toneMapping}async setEnvironmentImage(e){for(let t of Oe)if(t.setEnvironmentImage){await t.setEnvironmentImage(this,e);return}}async setSkyboxImage(e){for(let t of Oe)if(t.setSkyboxImage){await t.setSkyboxImage(this,e);return}}setInteractive(e){this.interactive=e}isInteractive(){return this.interactive}getCameraOrbit(){let e=this.currTheta,t=this.currPhi,r=this.currDistance;return{theta:e,phi:t,radius:r,toString(){return`${e.toFixed(4)}rad ${t.toFixed(4)}rad ${r.toFixed(4)}m`}}}getCameraTarget(){let e=this.customTarget||this.bounds.center;return{x:e[0],y:e[1],z:e[2],toString(){return`${e[0].toFixed(4)}m ${e[1].toFixed(4)}m ${e[2].toFixed(4)}m`}}}jumpCameraToGoal(){this.currTheta=this.targetTheta,this.currPhi=this.targetPhi,this.currDistance=this.targetDistance,this.update(0),this.render()}getModelMaterials(){let e=this.gltf?.materials?.length?this.gltf.materials:[{name:"DefaultMaterial",pbrMetallicRoughness:{}}];return e.map((t,r)=>{let i=this.meshes.flatMap(u=>u.primitives.filter(h=>h.materialIndex===r||e.length===1&&h.materialIndex===void 0)),n=i[0],s=n?[...n.baseColor]:t.pbrMetallicRoughness?.baseColorFactor||[.8,.8,.8,1],l=n?n.metallic:t.pbrMetallicRoughness?.metallicFactor??.1,o=n?n.roughness:t.pbrMetallicRoughness?.roughnessFactor??.5,a={baseColorFactor:s,metallicFactor:l,roughnessFactor:o,setBaseColorFactor:u=>{let h=[u[0],u[1],u[2],u[3]??1];a.baseColorFactor=h,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.baseColorFactor=h);for(let m of i)m.baseColor=h;this.render()},setMetallicFactor:u=>{a.metallicFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.metallicFactor=u);for(let h of i)h.metallic=u;this.render()},setRoughnessFactor:u=>{a.roughnessFactor=u,t.pbrMetallicRoughness&&(t.pbrMetallicRoughness.roughnessFactor=u);for(let h of i)h.roughness=u;this.render()}};return{name:t.name||`Material_${r}`,pbrMetallicRoughness:a}})}playAnimation(e){if(this.animations.length!==0){if(e){let t=this.animations.find(r=>r.name===e);t&&(this.currentClip=t)}else this.currentClip||(this.currentClip=this.animations[0]);this.isPlayingAnimation=!0}}pauseAnimation(){this.isPlayingAnimation=!1}getAvailableAnimations(){return this.animations.map(e=>e.name)}getAvailableVariants(){return[...this.availableVariants]}getVariantName(){return this.activeVariantName}selectVariant(e){let t=this.applyVariantMaterial(e);return t&&this.gl&&this.render(),t}applyVariantMaterial(e){let t=e===null||e==="",r=-1;if(t)this.activeVariantName=null;else{if(r=this.availableVariants.indexOf(e),r<0)return!1;this.activeVariantName=e}let i=this.gltf?.materials;if(!Array.isArray(i))return t;for(let n of this.meshes)for(let s of n.primitives){let l=s.defaultMaterialIndex;if(!t&&Array.isArray(s.variantMappings)){for(let a of s.variantMappings)if(Array.isArray(a.variants)&&a.variants.includes(r)){l=a.material;break}}let o=l!==void 0?i[l]:void 0;s.materialIndex=o?l:void 0,Object.assign(s,us(o,this.gpuTextures)),this.applyPrimitiveProgram(s,s.materialIndex,o??null)}return!0}applyPrimitiveProgram(e,t,r){if(!this.gl||!e.primitiveDef)return;e.programCache??(e.programCache=new Map);let i=t??-1,n=e.programCache.get(i);n||(n=ss(this.gl,{...e.primitiveDef,material:t},r),e.programCache.set(i,n)),e.customProgram=n.program,e.customUniforms=n.uniforms,e.pluginData&&(e.pluginData.materials=e.isTransmissive?{isTransmissive:!0}:void 0)}setAutoplay(e){this.autoplay=e,e?this.playAnimation(this.animationName||void 0):this.pauseAnimation()}setAnimationName(e){this.animationName=e,(this.isPlayingAnimation||this.autoplay)&&this.playAnimation(e)}evaluateAnimation(e){for(let t of Oe)if(t.evaluateAnimation){t.evaluateAnimation(this,e);return}}setTarget(e,t,r){this.customTarget=[e,t,r],this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}getTarget(){return this.customTarget?[...this.customTarget]:null}setFieldOfView(e){let t=Math.max(10,Math.min(90,e));this.fov=t*Math.PI/180}getFieldOfView(){return this.fov*180/Math.PI}setDistanceMode(e){if(this.distanceMode=e,!this.customDistance){let t=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=t,this.targetDistance=t,this.currDistance=t,this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}}getDistanceMode(){return this.distanceMode}setOrbitLimits(e){e.minTheta!==void 0&&(this.minTheta=e.minTheta*Math.PI/180),e.maxTheta!==void 0&&(this.maxTheta=e.maxTheta*Math.PI/180),e.minPhi!==void 0&&(this.minPhi=Math.max(-Math.PI*.48,e.minPhi*Math.PI/180)),e.maxPhi!==void 0&&(this.maxPhi=Math.min(Math.PI*.48,e.maxPhi*Math.PI/180)),e.minDistance!==void 0&&(this.minDistanceLimit=e.minDistance),e.maxDistance!==void 0&&(this.maxDistanceLimit=e.maxDistance),this.targetTheta=this.clampTheta(this.targetTheta),this.targetPhi=this.clampPhi(this.targetPhi),this.targetDistance=this.clampDistance(this.targetDistance)}getOrbitLimits(){return{minTheta:isFinite(this.minTheta)?this.minTheta*180/Math.PI:void 0,maxTheta:isFinite(this.maxTheta)?this.maxTheta*180/Math.PI:void 0,minPhi:this.minPhi*180/Math.PI,maxPhi:this.maxPhi*180/Math.PI,minDistance:this.minDistanceLimit!==null?this.minDistanceLimit:void 0,maxDistance:this.maxDistanceLimit!==null?this.maxDistanceLimit:void 0}}clampTheta(e){return Math.max(this.minTheta,Math.min(this.maxTheta,e))}clampPhi(e){return Math.max(this.minPhi,Math.min(this.maxPhi,e))}clampDistance(e){let t=this.minDistanceLimit!==null?this.minDistanceLimit:this.bounds?this.bounds.radius*.5:.1,r=this.maxDistanceLimit!==null?this.maxDistanceLimit:this.bounds?this.bounds.radius*8:100;return Math.max(t,Math.min(r,e))}setCamera(e,t,r,i){e!==void 0&&(this.targetTheta=this.clampTheta(e*Math.PI/180)),t!==void 0&&(this.targetPhi=this.clampPhi(t*Math.PI/180)),r!==void 0&&r>0&&(this.targetDistance=this.clampDistance(r)),i!==void 0&&i>0&&(this.targetDistance=this.clampDistance(this.bounds.radius*2.5/i))}setInitialCamera(e,t,r,i){if(e!==void 0&&(this.initialTheta=this.clampTheta(e*Math.PI/180),this.targetTheta=this.initialTheta,this.currTheta=this.initialTheta),t!==void 0&&(this.initialPhi=this.clampPhi(t*Math.PI/180),this.targetPhi=this.initialPhi,this.currPhi=this.initialPhi),r!==void 0&&r>0){let n=this.clampDistance(r);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else if(i!==void 0&&i>0){let n=this.clampDistance(this.bounds.radius*2.5/i);this.initialDistance=n,this.customDistance=!0,this.targetDistance=n,this.currDistance=n}else{this.customDistance=!1;let n=this.clampDistance(this.distanceMode==="absolute"?3:this.bounds.radius*2.5);this.initialDistance=n,this.targetDistance=n,this.currDistance=n}this.gl&&(this.meshes.length>0||this.backdropMeshes.length>0)&&(this.update(0),this.render())}resetCamera(){this.targetTheta=this.clampTheta(this.initialTheta),this.targetPhi=this.clampPhi(this.initialPhi),this.initialDistance!==null?this.targetDistance=this.clampDistance(this.initialDistance):this.targetDistance=this.clampDistance(this.bounds.radius*2.5),this.initialCustomTarget?this.customTarget=[...this.initialCustomTarget]:this.customTarget=null,this.turntableRotation=0,this.updateTurntableMatrix()}projectPointToScreen(e,t){let r=Se();Ie(r,this.projMatrix,this.viewMatrix);let[i,n,s]=e,l=t?t[0]:0,o=t?t[1]:0,a=t?t[2]:0,u=this.modelRootMatrix;u&&(i=u[0]*e[0]+u[4]*e[1]+u[8]*e[2]+u[12],n=u[1]*e[0]+u[5]*e[1]+u[9]*e[2]+u[13],s=u[2]*e[0]+u[6]*e[1]+u[10]*e[2]+u[14],t&&(l=u[0]*t[0]+u[4]*t[1]+u[8]*t[2],o=u[1]*t[0]+u[5]*t[1]+u[9]*t[2],a=u[2]*t[0]+u[6]*t[1]+u[10]*t[2]));let h=r[0]*i+r[4]*n+r[8]*s+r[12],m=r[1]*i+r[5]*n+r[9]*s+r[13],c=r[2]*i+r[6]*n+r[10]*s+r[14],d=r[3]*i+r[7]*n+r[11]*s+r[15];if(d<=1e-4)return{x:0,y:0,z:1,visible:!1};let f=h/d,g=m/d,x=c/d,b=this.canvas.getBoundingClientRect(),v=b.width||this.canvas.clientWidth||this.canvas.width||300,p=b.height||this.canvas.clientHeight||this.canvas.height||150,y=(f*.5+.5)*v,M=(-g*.5+.5)*p,P=f>=-1.1&&f<=1.1&&g>=-1.1&&g<=1.1&&x>=-1&&x<=1;if(P&&t){let[F,W,T]=Mn(this),E=[i-F,n-W,s-T];l*E[0]+o*E[1]+a*E[2]>.05&&(P=!1)}return{x:y,y:M,z:x,visible:P}}setSelectedMesh(e){this.selectedMeshName=e||""}getSelectedMesh(){return this.selectedMeshName}setupEvents(){let e=this.canvas,t=()=>typeof performance<"u"?performance.now():Date.now();this.boundContextMenu=r=>{r.preventDefault()},e.addEventListener("contextmenu",this.boundContextMenu),this.boundPointerDown=r=>{this.interactive&&(this.isPointerDown=!0,this.lastInteractionTime=t(),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist=0,this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.isPanning=r.button===2||r.shiftKey||this.activePointers.size===2,e.setPointerCapture(r.pointerId))},e.addEventListener("pointerdown",this.boundPointerDown),this.boundPointerMove=r=>{if(!this.isPointerDown||!this.interactive)return;this.lastInteractionTime=t();let i=this.activePointers.get(r.pointerId)||{x:this.lastPointerX,y:this.lastPointerY},n=r.clientX-i.x,s=r.clientY-i.y;if(this.activePointers.set(r.pointerId,{x:r.clientX,y:r.clientY}),this.lastPointerX=r.clientX,this.lastPointerY=r.clientY,this.totalDragDist+=Math.hypot(n,s),this.isPanning||r.button===2||r.shiftKey||this.activePointers.size===2){let l=[this.viewMatrix[0],this.viewMatrix[4],this.viewMatrix[8]],o=[this.viewMatrix[1],this.viewMatrix[5],this.viewMatrix[9]],a=this.customTarget?[...this.customTarget]:[...this.bounds.center],u=this.currDistance/Math.max(e.clientHeight||300,1)*1.5;a[0]+=(-n*l[0]+s*o[0])*u,a[1]+=(-n*l[1]+s*o[1])*u,a[2]+=(-n*l[2]+s*o[2])*u,this.customTarget=a}else this.targetTheta=this.clampTheta(this.targetTheta-n*.008),this.targetPhi=this.clampPhi(this.targetPhi+s*.008)},e.addEventListener("pointermove",this.boundPointerMove),this.boundPointerUp=r=>{this.lastInteractionTime=t(),this.activePointers.delete(r.pointerId),this.activePointers.size===0?(this.isPointerDown=!1,this.isPanning=!1):this.activePointers.size===1&&(this.isPanning=!1);try{e.releasePointerCapture(r.pointerId)}catch{}if(this.totalDragDist<5&&r.button===0){let i=e.getBoundingClientRect(),n=Math.floor((r.clientX-i.left)*(e.width/Math.max(i.width,1))),s=Math.floor((r.clientY-i.top)*(e.height/Math.max(i.height,1)));this.performMeshPick(n,s,!0)}},e.addEventListener("pointerup",this.boundPointerUp),this.boundWheel=r=>{if(!this.interactive)return;r.preventDefault(),this.lastInteractionTime=t();let i=Math.exp(r.deltaY*.001);this.targetDistance=this.clampDistance(this.targetDistance*i)},e.addEventListener("wheel",this.boundWheel,{passive:!1}),this.boundSetCamera=r=>{let i=r.detail||{};i.reset?this.resetCamera():this.setCamera(i.theta,i.phi,i.distance,i.zoom)},this.container.addEventListener("setCamera",this.boundSetCamera),this.boundResetCamera=()=>{this.resetCamera()},this.container.addEventListener("resetCamera",this.boundResetCamera),e.tabIndex!==void 0&&e.tabIndex<0&&(e.tabIndex=0),e.getAttribute?.("role")||e.setAttribute?.("role","region"),e.getAttribute?.("aria-label")||e.setAttribute?.("aria-label","Interactive 3D model viewport"),this.boundKeyDown=r=>{if(this.interactive){switch(r.key){case"ArrowLeft":this.targetTheta=this.clampTheta(this.targetTheta-.1);break;case"ArrowRight":this.targetTheta=this.clampTheta(this.targetTheta+.1);break;case"ArrowUp":this.targetPhi=this.clampPhi(this.targetPhi+.08);break;case"ArrowDown":this.targetPhi=this.clampPhi(this.targetPhi-.08);break;case"+":case"=":this.targetDistance=this.clampDistance(this.targetDistance*.9);break;case"-":case"_":this.targetDistance=this.clampDistance(this.targetDistance*1.1);break;case"Home":this.resetCamera();break;default:return}this.lastInteractionTime=t(),r.preventDefault()}},e.addEventListener("keydown",this.boundKeyDown)}teardownEvents(){let e=(r,i,n)=>{this[n]&&(r.removeEventListener(i,this[n]),this[n]=null)},t=this.canvas;e(t,"webglcontextlost","boundContextLost"),e(t,"webglcontextrestored","boundContextRestored"),e(t,"contextmenu","boundContextMenu"),e(t,"pointerdown","boundPointerDown"),e(t,"pointermove","boundPointerMove"),e(t,"pointerup","boundPointerUp"),e(t,"wheel","boundWheel"),e(t,"keydown","boundKeyDown"),e(this.container,"setCamera","boundSetCamera"),e(this.container,"resetCamera","boundResetCamera")}raycastFromScreenPoint(e,t){let r=this.canvas,i=r.getBoundingClientRect(),n=r.width||300,s=r.height||300,l=i.width>0?Math.floor((e-i.left)*(n/i.width)):Math.floor(e),o=i.height>0?Math.floor((t-i.top)*(s/i.height)):Math.floor(t);return this.performMeshPick(l,o,!1)}performMeshPick(e,t,r=!0){if(this.meshes.length===0)return null;let i=this.gl,n=Math.max(1,this.canvas.width||300),s=Math.max(1,this.canvas.height||300);e=this.mapStereoPickX(e,n);let l=Se();Ie(l,this.projMatrix,this.viewMatrix);let o=[],a=Math.max(0,Math.min(n-1,e)),u=Math.max(0,Math.min(s-1,s-1-t));if(this.pickFbo&&i&&!this.xrSessionActive){(this.pickFboWidth!==n||this.pickFboHeight!==s)&&this.resizePickingFbo(n,s),i.bindFramebuffer(36160,this.pickFbo),i.viewport(0,0,n,s),i.enable(2929),i.clearColor(0,0,0,0),i.clear(16640),i.useProgram(this.pickProg);for(let M=0;M<this.meshes.length;M++){let P=this.meshes[M];if(P.visible===!1||P.isPluginMesh)continue;let F=M+1,W=(F&255)/255,T=(F>>8&255)/255,E=(F>>16&255)/255;i.uniform4f(this.uPick.uColorId,W,T,E,1),Ie(this.modelMatrix,this.modelRootMatrix,P.transform);let S=P.instanceMatrices;if(S&&S.length>=16){let O=S.length>>4,k=Se();for(let w of P.primitives){i.bindVertexArray(w.vao);for(let ie=0;ie<O;ie++)Ie(k,this.modelMatrix,S.subarray(ie*16,ie*16+16)),Ie(this.mvpMatrix,l,k),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix),cr(i,w)}}else{Ie(this.mvpMatrix,l,this.modelMatrix),i.uniformMatrix4fv(this.uPick.uMVP,!1,this.mvpMatrix);for(let O of P.primitives)i.bindVertexArray(O.vao),cr(i,O)}}let p=new Uint8Array(4);i.readPixels(a,u,1,1,6408,5121,p),i.bindFramebuffer(36160,null);let y=p[0]+(p[1]<<8)+(p[2]<<16);y>0&&y<=this.meshes.length&&(o=[this.meshes[y-1]])}o.length===0&&(o=this.meshes.filter(p=>p.visible!==!1));let h=null,m=1/0,c=[0,0,0],d=[0,1,0],[f,g,x]=Mn(this),b=Se();for(let p of o){Ie(b,this.modelRootMatrix,p.transform);let y=p.instanceMatrices,M=y&&y.length>=16?y.length>>4:1;for(let P=0;P<M;P++){y&&y.length>=16?Ie(this.modelMatrix,b,y.subarray(P*16,P*16+16)):this.modelMatrix.set(b),Ie(this.mvpMatrix,l,this.modelMatrix);let F=Se();if(!en(F,this.mvpMatrix))continue;let W=(a+.5)/n*2-1,T=(u+.5)/s*2-1,E=[0,0,0],S=[0,0,0];Ai(E,W,T,-1,F),Ai(S,W,T,1,F);let O=S[0]-E[0],k=S[1]-E[1],w=S[2]-E[2],ie=Math.hypot(O,k,w)||1,oe=O/ie,I=k/ie,H=w/ie,N={distance:1/0,point:[0,0,0],normal:[0,1,0]};if((z=>{for(let ue of p.primitives){if(!ue.positions)continue;let ce=ue.positions,B=ue.indices,$=Math.floor(B?B.length/3:ce.length/9);for(let _=0;_<$;_++){let G=B?B[_*3]:_*3,j=B?B[_*3+1]:_*3+1,q=B?B[_*3+2]:_*3+2;Go(E[0],E[1],E[2],oe,I,H,ce[G*3],ce[G*3+1],ce[G*3+2],ce[j*3],ce[j*3+1],ce[j*3+2],ce[q*3],ce[q*3+1],ce[q*3+2],N,z)}}})(1e-4),isFinite(N.distance)){let z=N.point[0],ue=N.point[1],ce=N.point[2],B=this.modelMatrix,$=B[0]*z+B[4]*ue+B[8]*ce+B[12],_=B[1]*z+B[5]*ue+B[9]*ce+B[13],G=B[2]*z+B[6]*ue+B[10]*ce+B[14],j=$-f,q=_-g,D=G-x,Y=Math.hypot(j,q,D);if(Y<m){Xe(this.normalMatrix,this.modelMatrix);let te=this.normalMatrix,se=N.normal[0],le=N.normal[1],V=N.normal[2],ee=te[0]*se+te[3]*le+te[6]*V,R=te[1]*se+te[4]*le+te[7]*V,A=te[2]*se+te[5]*le+te[8]*V,L=Math.hypot(ee,R,A)||1;ee/=L,R/=L,A/=L,ee*j+R*q+A*D>0&&(ee=-ee,R=-R,A=-A),h=p,m=Math.round(Y*1e3)/1e3,c=[Math.round($*1e3)/1e3,Math.round(_*1e3)/1e3,Math.round(G*1e3)/1e3],d=[Math.round(ee*1e3)/1e3,Math.round(R*1e3)/1e3,Math.round(A*1e3)/1e3]}}}}if(!h)return null;let v={meshIndex:this.meshes.indexOf(h),meshName:h.name,nodeIndex:h.nodeIndex,distance:m,hitPoint:c,normal:d,screenX:e,screenY:t};if(r){for(let p of Oe)p.onMeshSelect?.(this,v);this.opts.onMeshClick&&this.opts.onMeshClick(v),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("meshClick",{bubbles:!0,detail:v}))}return v}mapStereoPickX(e,t){if(!this.stereoSBS||this.xrSessionActive||t<2)return e;let r=Math.max(1,Math.floor(t*.5)),i=e>=r,n=i?e-r:e,s=i?Math.max(1,t-r):r,l=(n+.5)/s*2-1;return Math.floor((l*.5+1)*.5*t)}setStereoSBS(e){this.stereoSBS=!!e,this.xrSessionActive||(this.syncCameraMatrices(),this.render())}syncCameraMatrices(){let e=Math.max(1,this.canvas.width||1)/Math.max(1,this.canvas.height||1),t=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10);rr(this.projMatrix,this.fov,e,.1,t);let r=this.customTarget||this.bounds.center;Jt(this.viewMatrix,Mn(this),r,[0,1,0]),Ie(this.mvpMatrix,this.projMatrix,this.viewMatrix),Xe(this.normalMatrix,this.modelMatrix)}resize(){let e=Math.min((typeof window<"u"?window.devicePixelRatio:1)||1,2),t=this.canvas.getBoundingClientRect(),r=Math.max(1,Math.floor(t.width*e)),i=Math.max(1,Math.floor(t.height*e));this.canvas.width!==r||this.canvas.height!==i?(this.canvas.width=r,this.canvas.height=i,this.resizePickingFbo(r,i),this.xrSessionActive||this.syncCameraMatrices()):!this.xrSessionActive&&this.projMatrix[0]===0&&this.syncCameraMatrices()}getGLContext(){return this.gl}setXRSessionActive(e){let t=this.xrSessionActive;if(this.xrSessionActive=e,t&&!e){this.xrDepthState.enabled=!1;for(let r of 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 t of Oe)t.onUpdate?.(this,e)}start(){if(this.animFrameId!==null)return;this.lastTime=typeof performance<"u"?performance.now():Date.now();let e=t=>{if(this.animFrameId===null)return;let r=Math.min(Math.max((t-this.lastTime)/1e3,0),.1);if(this.lastTime=t,this.isVisible&&!this.xrSessionActive)try{this.resize(),this.update(r),this.render()}catch(i){this.reportRenderError(i)}this.animFrameId!==null&&(this.animFrameId=requestAnimationFrame(e))};this.animFrameId=requestAnimationFrame(e)}stop(){this.animFrameId!==null&&(cancelAnimationFrame(this.animFrameId),this.animFrameId=null)}setAutoRotate(e){this.autoRotate=e}getAutoRotate(){return this.autoRotate}setAutoRotateSpeed(e){this.autoRotateSpeed=e}getAutoRotateSpeed(){return this.autoRotateSpeed}setAutoRotateDelay(e){this.autoRotateDelay=Math.max(0,Number(e)||0)}getAutoRotateDelay(){return this.autoRotateDelay}resetTurntableRotation(e=0){this.turntableRotation=Number(e)||0,this.updateTurntableMatrix(),this.render()}updateTurntableMatrix(){let e=Math.cos(this.turntableRotation),t=Math.sin(this.turntableRotation),r=this.bounds.center[0],i=this.bounds.center[2],n=this.modelRootMatrix;n[0]=e,n[1]=0,n[2]=-t,n[3]=0,n[4]=0,n[5]=1,n[6]=0,n[7]=0,n[8]=t,n[9]=0,n[10]=e,n[11]=0,n[12]=r-(e*r+t*i),n[13]=0,n[14]=i-(-t*r+e*i),n[15]=1}setVisible(e){this.isVisible=e}update(e){for(let s of Oe)s.onUpdate?.(this,e);let t=typeof performance<"u"?performance.now():Date.now();if(!this.isPointerDown&&this.autoRotate&&t-this.lastInteractionTime>=this.autoRotateDelay){this.turntableRotation+=this.autoRotateSpeed*e,this.updateTurntableMatrix();for(let s of 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),n=Math.round(this.bounds.radius*2.5/this.currDistance*100)/100;if(Math.abs(r-this.lastReportedTheta)>=1||Math.abs(i-this.lastReportedPhi)>=1||Math.abs(n-this.lastReportedZoom)>=.02){this.lastReportedTheta=r,this.lastReportedPhi=i,this.lastReportedZoom=n;let s={theta:r,phi:i,zoom:n,distance:Math.round(this.currDistance*100)/100};this.opts.onCameraChange&&this.opts.onCameraChange(s),typeof CustomEvent<"u"&&typeof this.container.dispatchEvent=="function"&&this.container.dispatchEvent(new CustomEvent("cameraChange",{bubbles:!0,detail:s}))}}renderXRView(e,t,r,i,n=!0,s=0){this.onBeforeRenderXRView&&this.onBeforeRenderXRView(e);let l=e?.transform?.inverse?.matrix||this.viewMatrix,o=e?.projectionMatrix||this.projMatrix,a=e?.transform?.position,u=a?[a.x,a.y,a.z]:[0,1.6,0];t?this.modelRootMatrix.set(t):r&&t&&this.modelRootMatrix.set(t),this.render({viewMatrix:l,projMatrix:o,eyePos:u,viewport:i,eye:e?.eye||"none",clear:s>0?!1:e?.eye!=="right",isAR:n})}render(e){if(this.contextLost)return;if(!e&&this.stereoSBS){let v=Math.max(2,this.canvas.width||2),p=Math.max(1,this.canvas.height||1),y=Math.max(1,Math.floor(v*.5)),M=Math.max(1,v-y),P=this.backdropMeshes.length>0?Math.max(this.bounds.radius*20,120):Math.max(this.bounds.radius*20,10),F=this.customTarget||this.bounds.center,[W,T,E]=Mn(this),S=Math.cos(this.currTheta),O=-Math.sin(this.currTheta),k=.032,w=Se(),ie=Se(),oe=[W-S*k,T,E-O*k],I=[F[0]-S*k*.25,F[1],F[2]-O*k*.25];rr(w,this.fov,y/p,.1,P),Jt(ie,oe,I,[0,1,0]);let H=Se(),N=Se(),z=[W+S*k,T,E+O*k],ue=[F[0]+S*k*.25,F[1],F[2]+O*k*.25];rr(H,this.fov,M/p,.1,P),Jt(N,z,ue,[0,1,0]),this.render({viewMatrix:ie,projMatrix:w,eyePos:oe,viewport:[0,0,y,p],eye:"left",clear:!0,isAR:!1}),this.render({viewMatrix:N,projMatrix:H,eyePos:z,viewport:[y,0,M,p],eye:"right",clear:!1,isAR:!1}),this.gl.viewport(0,0,v,p);return}let t=this.gl,r=0,i=0,n=this.canvas.width,s=this.canvas.height;e?.viewport?(r=e.viewport[0],i=e.viewport[1],n=e.viewport[2],s=e.viewport[3],t.viewport(r,i,n,s)):t.viewport(0,0,this.canvas.width,this.canvas.height),t.enable(2929),(!e||e.clear!==!1)&&(e?.isAR?t.clearColor(0,0,0,0):t.clearColor(this.clearColor[0],this.clearColor[1],this.clearColor[2],this.clearColor[3]),t.clear(16640));let l=Se(),o=e?.viewMatrix??this.viewMatrix;this.activeViewMatrix=o,Ie(l,e?.projMatrix??this.projMatrix,o);let a=Ae().xrDepthShader,u=Za(this.toneMapping),[h,m,c]=e?e.eyePos:Mn(this);for(let v of Oe)v.onBeforeDrawScene?.(this,t,l,[h,m,c],u);let d=e?.isAR?0:this.backdropMeshes.length;if(this.meshes.length===0&&d===0)return;let f=e?.eye||"none",g=!1,x=d>0?[...this.backdropMeshes,...this.meshes]:this.meshes,b=v=>{for(let p=0;p<x.length;p++){let y=x[p];if(y.visible===!1)continue;let M=this.selectedMeshName!==""&&y.name===this.selectedMeshName;p<d||y.worldSpace===!0||y.name==="__xr_reticle__"?this.modelMatrix.set(y.transform):Ie(this.modelMatrix,this.modelRootMatrix,y.transform),Ie(this.mvpMatrix,l,this.modelMatrix),Xe(y.normalMatrix,this.modelMatrix);let P=y.extras?.xr?.stereo||y.userData?.xr?.stereo,F=0,W=0,T=1,E=1;P==="sbs"?(T=.5,F=f==="right"?.5:0):P==="ou"&&(E=.5,W=f==="right"?.5:0);for(let S of y.primitives){let O=!!S.isTransmissive;if(!v&&O){g=!0;continue}if(v&&!O)continue;let k=S.customProgram||this.renderProg,w=S.customUniforms||this.uRender;t.useProgram(k),t.vertexAttrib3f(3,0,0,0),w.uInstanced&&t.uniform1i(w.uInstanced,0),t.uniform1i(w.uToneMapping,u),t.uniform1f(w.uEnvIntensity,this.envIntensity),w.uExposure&&t.uniform1f(w.uExposure,this.exposure),t.uniform3f(w.uCameraPos,h,m,c),t.uniform1f(w.uEmissive,M?1:0),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,this.modelMatrix),t.uniformMatrix3fv(w.uNormalMatrix,!1,y.normalMatrix),w.uUvTransform&&t.uniform4f(w.uUvTransform,F,W,T,E),w.uViewportSize&&t.uniform2f(w.uViewportSize,Math.max(1,n),Math.max(1,s)),a?.bind(t,w,this.xrDepthState,o,[r,i,Math.max(1,n),Math.max(1,s)]),this.environmentTexture?(t.activeTexture(33988),t.bindTexture(3553,this.environmentTexture),t.uniform1i(w.uEnvironmentMap,4),t.uniform1i(w.uHasEnvironmentMap,1)):t.uniform1i(w.uHasEnvironmentMap,0),this.bindLights(w),w.uSectionEnabled&&t.uniform1i(w.uSectionEnabled,0);for(let oe of Oe)oe.onBeforeDrawPrimitive?.(t,k,S,y,this.worldMatrices||[],this.gltf);t.uniform4fv(w.uBaseColor,S.baseColor),t.uniform1f(w.uMetallic,S.metallic),t.uniform1f(w.uRoughness,S.roughness),w.uClearcoat&&t.uniform2f(w.uClearcoat,S.clearcoat??0,S.clearcoatRoughness??.04),S.texture?(t.activeTexture(33984),t.bindTexture(3553,S.texture),t.uniform1i(w.uBaseColorTexture,0),t.uniform1i(w.uHasTexture,1)):t.uniform1i(w.uHasTexture,0),S.metallicRoughnessTexture?(t.activeTexture(33985),t.bindTexture(3553,S.metallicRoughnessTexture),t.uniform1i(w.uMetallicRoughnessTexture,1),t.uniform1i(w.uHasMetallicRoughnessTexture,1)):t.uniform1i(w.uHasMetallicRoughnessTexture,0),S.normalTexture?(t.activeTexture(33986),t.bindTexture(3553,S.normalTexture),t.uniform1i(w.uNormalTexture,2),t.uniform1i(w.uHasNormalTexture,1),t.uniform1f(w.uNormalScale,S.normalScale)):t.uniform1i(w.uHasNormalTexture,0),S.occlusionTexture?(t.activeTexture(33987),t.bindTexture(3553,S.occlusionTexture),t.uniform1i(w.uOcclusionTexture,3),t.uniform1i(w.uHasOcclusionTexture,1),t.uniform1f(w.uOcclusionStrength,S.occlusionStrength)):t.uniform1i(w.uHasOcclusionTexture,0),t.bindVertexArray(S.vao);let ie=y.instanceMatrices;if(S.instanceCount!==void 0)t.drawElementsInstanced(4,S.indexCount,S.indexType,0,S.instanceCount);else if(ie&&ie.length>=16&&S.instanced&&w.uInstanced&&w.uViewProj){let oe=ie.length>>4;t.uniform1i(w.uInstanced,1),t.uniformMatrix4fv(w.uViewProj,!1,l),S.indices?t.drawElementsInstanced(4,S.indexCount,S.indexType,0,oe):t.drawArraysInstanced(4,0,S.indexCount,oe),t.uniform1i(w.uInstanced,0)}else if(ie&&ie.length>=16){let oe=ie.length>>4,I=y.instanceColors,H=Se(),N=new Float32Array(9),z=[S.baseColor[0],S.baseColor[1],S.baseColor[2],S.baseColor[3]];for(let ue=0;ue<oe;ue++)Ie(H,this.modelMatrix,ie.subarray(ue*16,ue*16+16)),Ie(this.mvpMatrix,l,H),Xe(N,H),t.uniformMatrix4fv(w.uMVP,!1,this.mvpMatrix),t.uniformMatrix4fv(w.uModel,!1,H),t.uniformMatrix3fv(w.uNormalMatrix,!1,N),I&&(z[0]=S.baseColor[0]*I[ue*3],z[1]=S.baseColor[1]*I[ue*3+1],z[2]=S.baseColor[2]*I[ue*3+2],z[3]=S.baseColor[3],t.uniform4fv(w.uBaseColor,z)),cr(t,S)}else cr(t,S)}}};if(b(!1),g){for(let v of Oe)v.onBeforeTransmissivePass?.(t,this);b(!0)}for(let v of Oe)v.onAfterRender?.(t,this,l,e?.eye??"none",[r,i,n,s],e?.projMatrix??this.projMatrix)}disposeMeshListGpuResources(e,t){ls(this.gl,e,t)}disposeMeshGpuResources(){this.disposeMeshListGpuResources(this.meshes,this.gpuTextures),this.meshes=[],this.gpuTextures=[],this.availableVariants=[]}disposeGpuResources(){let e=this.gl;this.disposeMeshGpuResources(),this.disposeMeshListGpuResources(this.backdropMeshes),this.backdropMeshes=[];for(let t of Oe)t.onDestroy?.(e,this);this.environmentTexture&&(e.deleteTexture(this.environmentTexture),this.environmentTexture=null),this.renderProg&&e.deleteProgram(this.renderProg),this.pickProg&&e.deleteProgram(this.pickProg),this.pickFbo&&e.deleteFramebuffer(this.pickFbo),this.pickTexture&&e.deleteTexture(this.pickTexture),this.pickDepth&&e.deleteRenderbuffer(this.pickDepth),this.pickFbo=null,this.pickTexture=null,this.pickDepth=null}dispose(){this.stop(),this.teardownEvents(),this.disposeGpuResources()}destroy(){this.dispose()}};Ke.registerPlugin=Ve,Ke.getRegisteredPlugins=tr;function cc(e){return e+3&-4}var Me=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t;function fs(e,t){let r=t,i=1;for(;e.has(r);)r=`${t}_${i++}`;return e.add(r),r}function ds(e,t=0){let[r,i,n,,s,l,o,,a,u,h,,m,c,d]=Array.from({length:15},(N,z)=>Me(e[t+z],z%5===0?1:0)),f=Math.hypot(r,i,n),g=Math.hypot(s,l,o),x=Math.hypot(a,u,h);r*(l*h-u*o)-s*(i*h-u*n)+a*(i*o-l*n)<0&&(f=-f);let b=Math.abs(f)>1e-8?1/f:0,v=Math.abs(g)>1e-8?1/g:0,p=Math.abs(x)>1e-8?1/x:0,y=r*b,M=i*b,P=n*b,F=s*v,W=l*v,T=o*v,E=a*p,S=u*p,O=h*p,k=y+W+O,w=0,ie=0,oe=0,I=1;if(k>0){let N=.5/Math.sqrt(k+1);I=.25/N,w=(T-S)*N,ie=(E-P)*N,oe=(M-F)*N}else if(y>W&&y>O){let N=2*Math.sqrt(Math.max(0,1+y-W-O));N>1e-8&&(I=(T-S)/N,w=.25*N,ie=(F+M)/N,oe=(E+P)/N)}else if(W>O){let N=2*Math.sqrt(Math.max(0,1+W-y-O));N>1e-8&&(I=(E-P)/N,w=(F+M)/N,ie=.25*N,oe=(T+S)/N)}else{let N=2*Math.sqrt(Math.max(0,1+O-y-W));N>1e-8&&(I=(M-F)/N,w=(E+P)/N,ie=(T+S)/N,oe=.25*N)}let H=Math.hypot(w,ie,oe,I);return H>1e-8&&Number.isFinite(H)?(w/=H,ie/=H,oe/=H,I/=H):(w=0,ie=0,oe=0,I=1),{t:[m,c,d],r:[w,ie,oe,I],s:[f,g,x]}}function uc(e){let t={};return e.grab&&(t.interactable={mode:typeof e.grab=="string"?e.grab:"2-hand"},t.movable={scaleInZ:!!e.scale,minScale:typeof e.scale=="object"?e.scale.min??.1:.1,maxScale:typeof e.scale=="object"?e.scale.max??10:10}),e.billboard&&(t.billboard={mode:typeof e.billboard=="string"?e.billboard:"capsule"}),e.follow&&(t.follow={target:typeof e.follow=="object"?e.follow.mode??"head":e.follow}),e.anchor&&(t.anchor={plane:e.anchor}),e.physics&&e.physics!=="none"&&(t.rigidbody={type:e.physics}),t}var It=(e,t,r,i)=>typeof e=="number"&&Number.isFinite(e)?Math.max(t,Math.min(r,e)):i;function hs(e){let t=e?.audioEmitter??e?.spatialAudio??(typeof e?.audio=="object"&&e.audio&&("preset"in e.audio||"distanceModel"in e.audio||"coneInnerAngle"in e.audio||"maxDistance"in e.audio||"volume"in e.audio)?e.audio:typeof e?.audio=="string"&&/^(hum|reactor|wind|beacon|geiger|chimeLoop|machinery|water)$/.test(e.audio)?{preset:e.audio}:void 0);if(!t||typeof t=="object"&&t.enabled===!1)return null;let r=typeof t=="string"?{preset:t}:t,i=typeof r.src=="string"&&!/[\x00-\x20\\%]|^\s*(javascript|data|file|http):/i.test(r.src)?r.src:void 0,n=typeof r.preset=="string"?r.preset:void 0;return!i&&!n?null:{ae:r,src:i,preset:n,volume:It(r.volume,0,2,.6),loop:typeof r.loop=="boolean"?r.loop:!0,isGlobal:r.type==="global"||r.positional===!1}}function rn(e,t){return ps(e,t)[0]}function ps(e,t){e.updateMatrixWorld(!0);let r=[],i=0,n=[],s=[],l=[],o=[],a=new Set,u=[],h=[],m=new Map,c=[],d=[],f=[],g=new Map,x=[],b=[];function v(I){let H=m.get(I);if(H!==void 0)return H;H=h.length,m.set(I,H);let N=I,z=N.color?.r??1,ue=N.color?.g??1,ce=N.color?.b??1,B=N.opacity??1,$={baseColorFactor:[z,ue,ce,B],metallicFactor:N.metalness??0,roughnessFactor:N.roughness??.5},_={},G=ee=>{if(!ee)return;let R=(typeof ee=="string"?ee:typeof ee.source=="string"?ee.source:typeof ee.image=="string"?ee.image:"").trim();if(!R||/[\x00-\x1f\x7f\\]|\.\./.test(R)||!(/^data:image\/(png|jpeg|jpg|webp|ktx2|avif)(;|,)/i.test(R)||!R.startsWith("//")&&!/^[a-z][a-z0-9+.-]*:/i.test(R)))return;let A=g.get(R);if(A===void 0){let L=c.length;c.push({uri:R}),d.length===0&&d.push({magFilter:9729,minFilter:9987,wrapS:10497,wrapT:10497}),A=f.length,f.push({sampler:0,source:L}),g.set(R,A)}return{index:A}},j=G(N.map);j&&($.baseColorTexture=j);let q=G(N.roughnessMap||N.metalnessMap);q&&($.metallicRoughnessTexture=q);let D=N.map?.avgColor;Array.isArray(D)&&D.length>=3&&(_.avgColor=[D[0],D[1],D[2]]);let Y=G(N.normalMap),te=G(N.emissiveMap),se=G(N.aoMap),le={name:N.name||"",pbrMetallicRoughness:$,doubleSided:N.side===2||!!N.doubleSided,...Y?{normalTexture:Y}:{},...te?{emissiveTexture:te}:{},...se?{occlusionTexture:se}:{},...Object.keys(_).length>0?{extras:_}:{}};if(N.emissive&&(N.emissive.r>0||N.emissive.g>0||N.emissive.b>0)){let ee=N.emissiveIntensity??1;le.emissiveFactor=[N.emissive.r*ee,N.emissive.g*ee,N.emissive.b*ee]}let V={};return N.clearcoat&&N.clearcoat>0&&(V.KHR_materials_clearcoat={clearcoatFactor:N.clearcoat,clearcoatRoughnessFactor:N.clearcoatRoughness||0}),N.sheen&&N.sheen>0&&(V.KHR_materials_sheen={sheenColorFactor:N.sheenColor?[N.sheenColor.r,N.sheenColor.g,N.sheenColor.b]:[1,1,1],sheenRoughnessFactor:N.sheenRoughness||0}),N.transmission&&N.transmission>0&&(V.KHR_materials_transmission={transmissionFactor:N.transmission}),N.thickness&&N.thickness>0&&(V.KHR_materials_volume={thicknessFactor:N.thickness,attenuationDistance:N.attenuationDistance??1/0,attenuationColor:N.attenuationColor?[N.attenuationColor.r,N.attenuationColor.g,N.attenuationColor.b]:[1,1,1]}),N.ior!==void 0&&N.ior!==1.5&&(V.KHR_materials_ior={ior:N.ior}),N.dispersion&&N.dispersion>0&&(V.KHR_materials_dispersion={dispersion:N.dispersion}),N.iridescence&&N.iridescence>0&&(V.KHR_materials_iridescence={iridescenceFactor:N.iridescence,iridescenceIor:N.iridescenceIOR??1.3}),Object.keys(V).length>0&&(le.extensions=V),h.push(le),H}function p(I,H){let N=new Uint8Array(I.buffer,I.byteOffset,I.byteLength),z=cc(N.byteLength),ue=new Uint8Array(z);ue.set(N),r.push(ue);let ce=n.length;return n.push({buffer:0,byteOffset:i,byteLength:N.byteLength,target:H}),i+=z,ce}function y(I,H,N,z,ue,ce,B){let $=p(I,N),_=s.length,G={bufferView:$,byteOffset:0,componentType:z,count:ue,type:H};return ce&&(G.min=ce),B&&(G.max=B),s.push(G),_}e.traverse(I=>{if(I.isLight||I.color&&I.intensity!==void 0){let H=I.matrixWorld?.elements,N=Me(H?H[12]:I.position?.x,0),z=Me(H?H[13]:I.position?.y,0),ue=Me(H?H[14]:I.position?.z,0),ce=I.target,B=ce?.parent?ce?.matrixWorld?.elements:void 0,$=Me(B?B[12]:ce?.position?.x,0),_=Me(B?B[13]:ce?.position?.y,0),G=Me(B?B[14]:ce?.position?.z,0),j=$-N,q=_-z,D=G-ue,Y=Math.hypot(j,q,D),te=Math.max(.01,Math.min(Math.PI/2,Me(I.angle,Math.PI/3))),se=Math.max(0,Math.min(1,Me(I.penumbra,0)));b.push({type:I.type,color:[I.color.r,I.color.g,I.color.b],intensity:I.intensity,position:[N,z,ue],...I.type==="spot"?{direction:Y>1e-6?[j/Y,q/Y,D/Y]:[0,-1,0],outerConeAngle:te,innerConeAngle:Math.max(0,te*(1-se)),range:Math.max(0,Me(I.distance,0))}:I.type==="point"?{range:Math.max(0,Me(I.distance,0))}:{}})}});let M=[],P=new Set([e]),F=[];if(Array.isArray(e.children))for(let I=e.children.length-1;I>=0;I--)F.push({obj:e.children[I],parentKids:M});for(;F.length>0;){let{obj:I,parentKids:H}=F.pop();if(!I||typeof I!="object"||P.has(I))continue;P.add(I),I._bakeAuthorGeometry?.(),Ae().materializeDeclarativeGeometry?.(I);let N=!!(I.userData&&(I.userData.xr&&typeof I.userData.xr=="object"&&Object.keys(I.userData.xr).length>0||I.userData.interactivity&&typeof I.userData.interactivity=="object"&&Object.keys(I.userData.interactivity).length>0)),z={name:I.name||(N?`Node_${o.length}`:"")},ue=Me(I.position?.x,0),ce=Me(I.position?.y,0),B=Me(I.position?.z,0),$=Me(I.quaternion?.x,0),_=Me(I.quaternion?.y,0),G=Me(I.quaternion?.z,0),j=Me(I.quaternion?.w,1),q=Me(I.scale?.x,1),D=Me(I.scale?.y,1),Y=Me(I.scale?.z,1);if((ue||ce||B)&&(z.translation=[ue,ce,B]),($||_||G||j!==1)&&(z.rotation=[$,_,G,j]),(q!==1||D!==1||Y!==1)&&(z.scale=[q,D,Y]),I.visible===!1&&(z.extensions={...z.extensions||{},KHR_node_visibility:{visible:!1}},a.add("KHR_node_visibility")),I.userData&&Object.keys(I.userData).length>0&&(z.extras=JSON.parse(JSON.stringify(I.userData,(le,V)=>{if(!(le==="__proto__"||le==="prototype"||le==="constructor"))return typeof V=="function"?void 0:V})),I.userData.xr)){let le=uc(I.userData.xr);z.extensions={...z.extensions||{},MOZ_hubs_components:le,ANDROID_xr_scenecore:le},Ae().xrTraitSerializer?.gltfNode(z,I.userData.xr),a.add("MOZ_hubs_components").add("ANDROID_xr_scenecore")}if(I.geometry){let le=I.geometry,V=le.attributes.position;if(V&&V.count>0){let ee=[1/0,1/0,1/0],R=[-1/0,-1/0,-1/0];for(let X=0;X<V.count;X++){let Z=V.getX(X),J=V.getY(X),K=V.getZ(X);Z<ee[0]&&(ee[0]=Z),Z>R[0]&&(R[0]=Z),J<ee[1]&&(ee[1]=J),J>R[1]&&(R[1]=J),K<ee[2]&&(ee[2]=K),K>R[2]&&(R[2]=K)}let A={attributes:{POSITION:y(V.array,"VEC3",34962,5126,V.count,ee,R)}};if(le.attributes.normal&&(A.attributes.NORMAL=y(le.attributes.normal.array,"VEC3",34962,5126,le.attributes.normal.count)),le.attributes.uv&&(A.attributes.TEXCOORD_0=y(le.attributes.uv.array,"VEC2",34962,5126,le.attributes.uv.count)),le.index){let X=le.index.array instanceof Uint32Array;A.indices=y(le.index.array,"SCALAR",34963,X?5125:5123,le.index.count)}let L=Array.isArray(I.material)?I.material[0]:I.material;L&&(A.material=v(L));let C=I.userData?.variants;if(C&&typeof C=="object"){let X=new Map;for(let Z of Object.keys(C)){if(!Z||Z==="__proto__"||Z==="constructor"||Z==="prototype")continue;let J=C[Z];if(!J||typeof J!="object")continue;let K=x.indexOf(Z);if(K===-1&&x.length<256&&(K=x.length,x.push(Z)),K===-1)continue;let ae=v(J),ne=X.get(ae);ne||(ne=[],X.set(ae,ne)),ne.push(K)}if(X.size>0){let Z=[];for(let[J,K]of X.entries())Z.push({material:J,variants:K});A.extensions={...A.extensions||{},KHR_materials_variants:{mappings:Z}},a.add("KHR_materials_variants")}}let U=I;if(U.isInstancedMesh&&typeof U.count=="number"&&U.count>0&&U.instanceMatrix?.array){let X=Math.min(1e4,Math.floor(U.count)),Z=U.instanceMatrix.array,J=new Float32Array(X*3),K=new Float32Array(X*4),ae=new Float32Array(X*3);for(let re=0;re<X;re++){let{t:me,r:fe,s:ye}=ds(Z,re*16);J[re*3]=me[0],J[re*3+1]=me[1],J[re*3+2]=me[2],K[re*4]=fe[0],K[re*4+1]=fe[1],K[re*4+2]=fe[2],K[re*4+3]=fe[3],ae[re*3]=ye[0],ae[re*3+1]=ye[1],ae[re*3+2]=ye[2]}let ne={TRANSLATION:y(J,"VEC3",0,5126,X),ROTATION:y(K,"VEC4",0,5126,X),SCALE:y(ae,"VEC3",0,5126,X)};if(U.instanceColor?.array&&U.instanceColor.array.length>=X*3){let re=new Float32Array(U.instanceColor.array.subarray(0,X*3));ne._COLOR_0=y(re,"VEC3",0,5126,X)}z.extensions={...z.extensions||{},EXT_mesh_gpu_instancing:{attributes:ne}},a.add("EXT_mesh_gpu_instancing")}let Q=l.length;l.push({primitives:[A],name:I.name,...z.extras?{extras:z.extras}:{}}),z.mesh=Q}}let te=o.length;o.push(z),u.push(I),H.push(te);let se=I.children;if(Array.isArray(se)&&se.length>0){let le=[];z.children=le;for(let V=se.length-1;V>=0;V--)F.push({obj:se[V],parentKids:le})}}for(let I=0;I<o.length;I++){let H=o[I];H.children&&H.children.length===0?delete H.children:H.children&&H.children.length>0&&(H.extras?.xr?.lod||H.extensions?.ANDROID_xr_scenecore?.lod||u[I]?.isLOD)&&(H.extensions={...H.extensions||{},MSFT_lod:{ids:[...H.children]}},a.add("MSFT_lod"))}let W=t?.animateCallback||t?.animateFn||(typeof e.userData?.animate=="function"?e.userData.animate:typeof e.__animateFn=="function"?e.__animateFn:typeof globalThis.animate=="function"?globalThis.animate:void 0),T=[];if(typeof W=="function"&&u.length>0){let I=t?.duration??4,H=t?.fps??15,N=Math.max(2,Math.round(I*H)+1),z=new Float32Array(N),ue=u.map(D=>[Me(D.position?.x,0),Me(D.position?.y,0),Me(D.position?.z,0),Me(D.quaternion?.x,0),Me(D.quaternion?.y,0),Me(D.quaternion?.z,0),Me(D.quaternion?.w,1),Me(D.scale?.x,1),Me(D.scale?.y,1),Me(D.scale?.z,1)]),ce=u.map(()=>new Float32Array(N*3)),B=u.map(()=>new Float32Array(N*4)),$=u.map(()=>new Float32Array(N*3));for(let D=0;D<N;D++){let Y=D/(N-1)*I;z[D]=Y;try{W(Y)}catch{}for(let te=0;te<u.length;te++){let se=u[te];ce[te][D*3]=Me(se.position?.x,0),ce[te][D*3+1]=Me(se.position?.y,0),ce[te][D*3+2]=Me(se.position?.z,0);let le=Me(se.quaternion?.x,0),V=Me(se.quaternion?.y,0),ee=Me(se.quaternion?.z,0),R=Me(se.quaternion?.w,1),A=Math.hypot(le,V,ee,R)||1;if(le/=A,V/=A,ee/=A,R/=A,D>0){let L=(D-1)*4,C=B[te];C[L]*le+C[L+1]*V+C[L+2]*ee+C[L+3]*R<0&&(le=-le,V=-V,ee=-ee,R=-R)}B[te][D*4]=le,B[te][D*4+1]=V,B[te][D*4+2]=ee,B[te][D*4+3]=R,$[te][D*3]=Me(se.scale?.x,1),$[te][D*3+1]=Me(se.scale?.y,1),$[te][D*3+2]=Me(se.scale?.z,1)}}for(let D=0;D<u.length;D++){let Y=u[D],te=ue[D];Y.position?.set(te[0],te[1],te[2]),Y.quaternion?.set(te[3],te[4],te[5],te[6]),Y.scale?.set(te[7],te[8],te[9])}e.updateMatrixWorld(!0);let _=null,G=()=>(_===null&&(_=y(z,"SCALAR",0,5126,N,[0],[I])),_),j=[],q=[];for(let D=0;D<u.length;D++){let Y=ue[D],te=(le,V,ee)=>le.some((R,A)=>Math.abs(R-Y[ee+A%V])>1e-4),se=(le,V,ee,R)=>{le&&q.push({sampler:j.push({input:G(),interpolation:"LINEAR",output:y(V,ee,0,5126,N)})-1,target:{node:D,path:R}})};se(te(ce[D],3,0),ce[D],"VEC3","translation"),se(te(B[D],4,3),B[D],"VEC4","rotation"),se(te($[D],3,7),$[D],"VEC3","scale")}q.length>0&&T.push({name:"ProceduralLoop",samplers:j,channels:q})}let E=Uo(o,l,e.userData),S=[],O=[],k=[];for(let I=0;I<o.length;I++){let H=o[I],N=hs(H.extras?.xr);if(!N)continue;let{ae:z,src:ue,preset:ce,volume:B,loop:$,isGlobal:_}=N,G=H.name||`Node_${I}`,j=O.length;O.push({name:`${G}_source`,gain:B,loop:$,autoPlay:typeof z.autoplay=="boolean"?z.autoplay:!0,...ue!==void 0?{audio:S.push({uri:ue})-1}:{},...ce?{extras:{preset:ce,pitch:It(z.pitch,.25,4,1)}}:{}});let q=k.length,D=It(z.refDistance,.05,100,1),Y=It(z.coneInnerAngle,0,360,360),te=It(z.coneOuterAngle,Y,360,360);k.push({name:`${G}_emitter`,type:_?"global":"positional",gain:B,sources:[j],..._?{}:{positional:{distanceModel:z.distanceModel==="linear"||z.distanceModel==="exponential"?z.distanceModel:"inverse",refDistance:D,maxDistance:It(z.maxDistance,D,500,Math.max(D,25)),rolloffFactor:It(z.rolloffFactor,0,10,1),coneInnerAngle:+(Y*Math.PI/180).toFixed(6),coneOuterAngle:+(te*Math.PI/180).toFixed(6),coneOuterGain:It(z.coneOuterGain,0,1,0)}}}),H.extensions={...H.extensions||{},KHR_audio_emitter:{emitter:q}},a.add("KHR_audio_emitter")}let w={asset:{version:"2.0",generator:"ThreeLiveConvert",extras:{environmentIntensity:e.environmentIntensity}},scenes:[{nodes:M}],scene:0,nodes:o,meshes:l,materials:h,...c.length>0?{images:c}:{},...d.length>0?{samplers:d}:{},...f.length>0?{textures:f}:{},accessors:s,bufferViews:n,buffers:[{byteLength:i}],...T.length>0?{animations:T}:{},...E||a.size>0?{extensionsUsed:[...E?["KHR_interactivity"]:[],...a]}:{},...E||x.length>0||k.length>0?{extensions:{...E?{KHR_interactivity:E}:{},...x.length>0?{KHR_materials_variants:{variants:x.map(I=>({name:I}))}}:{},...k.length>0?{KHR_audio_emitter:{...S.length>0?{audio:S}:{},sources:O,emitters:k}}:{}}}:{}},ie=new Uint8Array(i),oe=0;for(let I of r)ie.set(I,oe),oe+=I.byteLength;return[{gltf:w,bin:ie.buffer,lights:b,environmentIntensity:e.environmentIntensity},u]}function Ui(e){return new TextEncoder().encode(e)}function Tn(e,t){let{gltf:r,bin:i}=rn(e,t),n=JSON.stringify(r),s=Ui(n),l=(4-s.byteLength%4)%4,o=s.byteLength+l,a=20+o+8+i.byteLength,u=new Uint8Array(a),h=new DataView(u.buffer);h.setUint32(0,1179937895,!0),h.setUint32(4,2,!0),h.setUint32(8,a,!0),h.setUint32(12,o,!0),h.setUint32(16,1313821514,!0),u.set(s,20);for(let c=0;c<l;c++)u[20+s.byteLength+c]=32;let m=20+o;return h.setUint32(m,i.byteLength,!0),h.setUint32(m+4,5130562,!0),u.set(new Uint8Array(i),m+8),u}function lc(e,t){let[r,i]=ps(e,t);return bs(r,i)}function bs(e,t){let r=[],i=e.gltf,n=Ae().decoders.get("meshopt");n&&typeof n.decodeBufferViews=="function"&&n.decodeBufferViews(i,e);let s=e.bin,l=s instanceof ArrayBuffer?s:s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength),o=i.accessors||[],a=i.bufferViews||[],u=i.materials||[],h=i.meshes||[],m=i.nodes||[],c=i.textures||[],d=i.images||[],f=i.samplers||[],g=new Set,x=u.map((P,F)=>fs(g,fr(P?.name,`Material_${F}`))),b=new Map;function v(P){let F=/^data:image\/(png|jpe?g)(?:;[^,]*)?;base64,([A-Za-z0-9+/=\s]+)$/i.exec(P);if(!F)return null;let W=F[2].replace(/\s+/g,""),T=W.endsWith("==")?2:W.endsWith("=")?1:0,E=new Uint8Array((W.length*3>>2)-T),S=k=>{let w=W.charCodeAt(k);return w>96?w-71:w>64?w-65:w>47?w+4:w===43?62:w===47?63:0},O=0;for(let k=0;k<W.length;k+=4){let w=S(k)<<18|S(k+1)<<12|S(k+2)<<6|S(k+3);E[O++]=w>>16&255,O<E.length&&(E[O++]=w>>8&255),O<E.length&&(E[O++]=w&255)}return E}function p(P,F,W){let T=P?.index;if(typeof T!="number")return;let E=c[T],S=E?.source;if(typeof S!="number"||!d[S])return;let O=b.get(S);if(O===void 0){O=null;let ie=d[S],oe=null;if(typeof ie.bufferView=="number"){let I=a[ie.bufferView],H=I?.byteOffset||0,N=I?.byteLength||0;I&&N>0&&H>=0&&H+N<=l.byteLength&&(oe=new Uint8Array(l,H,N))}else typeof ie.uri=="string"&&(oe=v(ie.uri));if(oe&&oe.byteLength>0){let I=oe[0]===255&&oe[1]===216&&oe[2]===255||!(oe[0]===137&&oe[1]===80)&&/jpe?g/i.test(ie.mimeType||ie.uri||"");O={file:`texture_${S}.${I?"jpg":"png"}`,data:oe}}b.set(S,O)}if(!O)return;let k=typeof E.sampler=="number"?f[E.sampler]:void 0,w=ie=>ie===33071?"clamp":ie===33648?"mirror":"repeat";return{file:O.file,data:O.data,wrapS:w(k?.wrapS),wrapT:w(k?.wrapT),...F?{scale:F}:{},...W?{bias:W}:{}}}function y(P){let F=o[P];if(!F)throw new Error(`Accessor ${P} not found`);let W=a[F.bufferView||0],T=(W.byteOffset||0)+(F.byteOffset||0),E=W.byteLength||0;return{acc:F,buffer:l.slice(T,T+E)}}function M(P,F,W,T){let E=[],S=h[P];if(!S)return E;let O=S.primitives||[];for(let k=0;k<O.length;k++){let w=O[k],ie=w.attributes?.POSITION;if(ie===void 0)continue;let{acc:oe,buffer:I}=y(ie),H=new Float32Array(I,0,oe.count*3),N,z=w.attributes?.NORMAL;if(z!==void 0){let{acc:V,buffer:ee}=y(z),R=new Float32Array(ee,0,V.count*3);N=new Float32Array(R.length);for(let A=0;A<V.count;A++){let L=R[A*3],C=R[A*3+1],U=R[A*3+2],Q=Math.hypot(L,C,U)||1;N[A*3]=L/Q,N[A*3+1]=C/Q,N[A*3+2]=U/Q}}let ue,ce=w.attributes?.TEXCOORD_0;if(ce!==void 0){let{acc:V,buffer:ee}=y(ce);ue=new Float32Array(ee,0,V.count*2)}let B;if(w.indices!==void 0){let{acc:V,buffer:ee}=y(w.indices);B=V.componentType===5125?new Uint32Array(ee,0,V.count):new Uint16Array(ee,0,V.count);let R=oe.count;for(let A of B)if(A>=R)throw new Error(`SecurityError: Index buffer value (${A}) out of vertex bounds [0, ${R}).`)}else{let V=oe.count;B=V>65535?new Uint32Array(V):new Uint16Array(V);for(let ee=0;ee<V;ee++)B[ee]=ee}let $="DefaultMaterial",_=[1,1,1],G=.5,j=0,q=0,D=0,Y=1.5,te=1,se=[0,0,0],le;if(w.material!==void 0&&u[w.material]){let V=u[w.material];$=x[w.material]||`Material_${w.material}`;let ee=V.pbrMetallicRoughness||{},R=(me,fe)=>Array.isArray(me)&&me.length>=3?[me[0],me[1],me[2]]:fe;_=R(ee.baseColorFactor,[1,1,1]);let A=Array.isArray(ee.baseColorFactor)&&typeof ee.baseColorFactor[3]=="number"?ee.baseColorFactor[3]:1,L=_[0]!==1||_[1]!==1||_[2]!==1||A!==1,C=p(ee.baseColorTexture,L?[_[0],_[1],_[2],A]:void 0),U=V.extras?.avgColor;!C&&Array.isArray(U)&&U.length>=3&&(_=[_[0]*U[0],_[1]*U[1],_[2]*U[2]]),typeof ee.roughnessFactor=="number"&&(G=ee.roughnessFactor),typeof ee.metallicFactor=="number"&&(j=ee.metallicFactor);let Q=typeof ee.roughnessFactor=="number"?ee.roughnessFactor:1,X=typeof ee.metallicFactor=="number"?ee.metallicFactor:1,Z=p(ee.metallicRoughnessTexture,Q!==1||X!==1?[1,Q,X,1]:void 0);se=R(V.emissiveFactor,[0,0,0]);let J=(se[0]>0||se[1]>0||se[2]>0)&&(se[0]!==1||se[1]!==1||se[2]!==1)?[se[0],se[1],se[2],1]:void 0,K=p(V.emissiveTexture,J),ae=p(V.normalTexture,[2,2,2,1],[-1,-1,-1,0]),ne=p(V.occlusionTexture);(C||Z||ae||K||ne)&&(le=[C,Z,ae,K,ne]);let re=V.extensions||{};re.KHR_materials_clearcoat&&(q=re.KHR_materials_clearcoat.clearcoatFactor??0,D=re.KHR_materials_clearcoat.clearcoatRoughnessFactor??0),typeof re.KHR_materials_ior?.ior=="number"&&(Y=re.KHR_materials_ior.ior),te=A*(1-(re.KHR_materials_transmission?.transmissionFactor??0))}E.push({name:O.length>1?`${F}_p${k}`:F,positions:H,indices:B,normals:N,uvs:ue,materialName:$,color:_,roughness:G,metallic:j,clearcoat:q,clearcoatRoughness:D,ior:Y,opacity:te,emissiveColor:se,...le?{textures:le}:{},xrTraits:W||S.extras?.xr,...T?{invisible:!0}:{}})}return E}if(m.length>0){let P=new Float32Array(0),F=new Uint16Array(0),W=(H,N)=>{if(H===void 0)return null;let{acc:z,buffer:ue}=y(H);return new Float32Array(ue,0,z.count*N)},T=(H,N)=>Array.isArray(H)&&H.length>=3?[Me(H[0],N),Me(H[1],N),Me(H[2],N)]:[N,N,N],E=(H,N,z)=>H&&H.length>=(N+1)*3?[H[N*3],H[N*3+1],H[N*3+2]]:z,S=(H,N,z)=>H&&H.length>=(N+1)*4?[H[N*4],H[N*4+1],H[N*4+2],H[N*4+3]]:z,O=new Map,k=i.animations?.[0];if(k&&Array.isArray(k.channels)&&Array.isArray(k.samplers))for(let H of k.channels){let N=k.samplers[H?.sampler],z=H?.target?.node,ue=H?.target?.path;if(!N||typeof z!="number"||N.input===void 0)continue;let ce=O.get(z);ce||(ce={input:N.input},O.set(z,ce)),ue==="translation"?ce.t=N.output:ue==="rotation"?ce.r=N.output:ue==="scale"&&(ce.s=N.output)}let w=i.scenes?.[i.scene??0]?.nodes??[];if(!Array.isArray(w)||w.length===0){let H=new Set;for(let N of m)if(Array.isArray(N?.children))for(let z of N.children)H.add(z);w=[];for(let N=0;N<m.length;N++)H.has(N)||w.push(N);w.length===0&&(w=[0])}let ie=new Set,oe=[],I=(H,N)=>{if(Array.isArray(H))for(let z=H.length-1;z>=0;z--)oe.push({idx:H[z],out:N})};for(I(w,r);oe.length>0;){let{idx:H,out:N}=oe.pop();if(typeof H!="number"||H<0||H>=m.length||ie.has(H))continue;ie.add(H);let z=m[H];if(!z)continue;let ue=[0,0,0],ce=[0,0,0,1],B=[1,1,1];if(Array.isArray(z.matrix)&&z.matrix.length===16){let te=ds(z.matrix);ue=te.t,ce=te.r,B=te.s}else ue=T(z.translation,0),Array.isArray(z.rotation)&&z.rotation.length>=4&&(ce=[Me(z.rotation[0],0),Me(z.rotation[1],0),Me(z.rotation[2],0),Me(z.rotation[3],1)]),B=T(z.scale,1);let $,_=O.get(H);if(_){let te=W(_.input,1);if(te&&te.length>0){let se=W(_.t,3),le=W(_.r,4),V=W(_.s,3),ee=Array.from(te),R=[],A=[],L=[];for(let C=0;C<te.length;C++)R.push(E(se,C,ue)),A.push(S(le,C,ce)),L.push(E(V,C,B));$={times:ee,translations:R,rotations:A,scales:L}}}let G=Array.isArray(z.children)?z.children:[],j=typeof z.mesh=="number"&&z.mesh>=0&&z.mesh<h.length,q=t?.[H]?.userData?.xr??z.extras?.xr;if(!j&&G.length===0&&(z.camera!==void 0||z.extensions?.KHR_lights_punctual||!z.name&&!z.extras&&!q&&!$))continue;let D=(te,se,le)=>({name:te,positions:P,indices:F,isXform:!0,xrTraits:q,timeSamples:$,translation:ue,rotation:ce,scale:B,children:se,...le?{invisible:!0}:{}}),Y=z.visible===!1||z.extensions?.KHR_node_visibility?.visible===!1||t?.[H]?.visible===!1;if(j){let te=z.name||h[z.mesh]?.name||`Mesh_${H}`,se=M(z.mesh,te,q,Y),le=z.extensions?.EXT_mesh_gpu_instancing?.attributes;if(le&&typeof le=="object"&&se.length>0){let V=W(le.TRANSLATION,3),ee=W(le.ROTATION,4),R=W(le.SCALE,3),A=W(le._COLOR_0,3),L=Math.min(1e3,V?V.length/3:ee?ee.length/4:R?R.length/3:0);if(L>0){let C=[];for(let U=0;U<L;U++){let Q=E(V,U,[0,0,0]),X=S(ee,U,[0,0,0,1]),Z=E(R,U,[1,1,1]);for(let J of se){let K=J.color||[.8,.8,.8],ae=A&&A.length>=(U+1)*3;C.push({...J,name:`${J.name}_${U}`,materialName:ae?`${J.materialName}_inst_${U}`:J.materialName,color:ae?[K[0]*A[U*3],K[1]*A[U*3+1],K[2]*A[U*3+2]]:J.color,translation:Q,rotation:X,scale:Z})}}I(G,C),N.push(D(te,C,Y));continue}}if(se.length===1)se[0].translation=ue,se[0].rotation=ce,se[0].scale=B,se[0].timeSamples=$,G.length>0&&(se[0].children=[],I(G,se[0].children)),N.push(se[0]);else{let V=[...se];I(G,V),N.push(D(te,V,Y))}}else{let te=[];I(G,te),N.push(D(z.name||`Group_${H}`,te,Y))}}}else for(let P=0;P<h.length;P++){let F=h[P].name||`Mesh_${P}`;r.push(...M(P,F,h[P].extras?.xr))}return r}function fr(e,t){if(!e||typeof e!="string")return t;let r=e.replace(/[^A-Za-z0-9_]/g,"_");return/^[0-9]/.test(r)&&(r="_"+r),r||t}function ur(e){return String(e??"").replace(/[\x00-\x1f\x7f]/g,"").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function je(e){if(!Number.isFinite(e)||Math.abs(e)<1e-7)return"0";let t=Number(e.toFixed(5)).toString();return t.indexOf(".")===-1?`${t}.0`:t}var At=(e,t,r)=>`(${je(e)}, ${je(t)}, ${je(r)})`,lr=(e,t,r,i)=>`(${je(e)}, ${je(t)}, ${je(r)}, ${je(i)})`;function ms(e){let t=e.length/3,r=new Array(t);for(let i=0;i<t;i++)r[i]=At(e[i*3],e[i*3+1],e[i*3+2]);return r.join(", ")}function mc(e,t){let r=new Array(t);for(let i=0;i<t;i++)r[i]=`(${je(e[i*2])}, ${je(1-e[i*2+1])})`;return r.join(", ")}function fc(e){return Array.from(e).join(", ")}function dc(e){let t=new Map,r=0,i=null,n=[...e];for(;n.length>0;){let f=n.pop();if(!f.isXform&&f.positions&&f.positions.length>0){let g=fr(f.materialName,"DefaultMaterial");t.has(g)||t.set(g,{color:f.color||[1,1,1],roughness:f.roughness??.5,metallic:f.metallic??0,clearcoat:f.clearcoat??0,clearcoatRoughness:f.clearcoatRoughness??0,ior:f.ior??1.5,opacity:f.opacity??1,emissiveColor:f.emissiveColor||[0,0,0],textures:f.textures})}if(f.timeSamples&&f.timeSamples.times.length>0){let g=f.timeSamples.times[f.timeSamples.times.length-1];g>r&&(r=g)}if(f.xrTraits?.anchor&&!i&&(i=f.xrTraits.anchor==="vertical"||f.xrTraits.anchor==="wall"?"vertical":"horizontal"),f.children)for(let g=f.children.length-1;g>=0;g--)n.push(f.children[g])}let s="";r>0&&(s=`startTimeCode = 0
251
+ endTimeCode = ${je(r)}
252
252
  timeCodesPerSecond = 1.0
253
253
  `);let l="";i&&(l=`uniform token preliminary:anchoring:type = "plane"
254
254
  uniform token preliminary:planeAnchoring:alignment = "${i}"
@@ -265,81 +265,108 @@ kind = "component"
265
265
  {
266
266
  ${l}def Scope "Materials"
267
267
  {
268
- `;for(let[m,g]of t.entries()){let[x,b,v]=g.color,[d,y,M]=g.emissiveColor,T="";g.clearcoat>0&&(T+=`float inputs:clearcoat = ${Ge(g.clearcoat)}
269
- `,T+=`float inputs:clearcoatRoughness = ${Ge(g.clearcoatRoughness)}
270
- `),g.ior!==1.5&&(T+=`float inputs:ior = ${Ge(g.ior)}
271
- `),g.opacity<1&&(T+=`float inputs:opacity = ${Ge(g.opacity)}
272
- `),(d>0||y>0||M>0)&&(T+=`color3f inputs:emissiveColor = ${xt(d,y,M)}
273
- `),o+=`def Material "${m}"
268
+ `;for(let[f,g]of t.entries()){let[x,b,v]=g.color,[p,y,M]=g.emissiveColor,P=`/Root/Materials/${f}`,[F,W,T,E,S]=g.textures||[],O=(I,H)=>`.connect = <${P}/${I}.outputs:${H}>`,k=F?`color3f inputs:diffuseColor${O("DiffuseTexture","rgb")}`:`color3f inputs:diffuseColor = ${At(x,b,v)}`,w=W?`float inputs:metallic${O("MetallicRoughnessTexture","b")}
269
+ float inputs:roughness${O("MetallicRoughnessTexture","g")}`:`float inputs:metallic = ${je(g.metallic)}
270
+ float inputs:roughness = ${je(g.roughness)}`,ie="";g.clearcoat>0&&(ie+=`float inputs:clearcoat = ${je(g.clearcoat)}
271
+ `,ie+=`float inputs:clearcoatRoughness = ${je(g.clearcoatRoughness)}
272
+ `),g.ior!==1.5&&(ie+=`float inputs:ior = ${je(g.ior)}
273
+ `),g.opacity<1&&(ie+=`float inputs:opacity = ${je(g.opacity)}
274
+ `),E?ie+=`color3f inputs:emissiveColor${O("EmissiveTexture","rgb")}
275
+ `:(p>0||y>0||M>0)&&(ie+=`color3f inputs:emissiveColor = ${At(p,y,M)}
276
+ `),T&&(ie+=`normal3f inputs:normal${O("NormalTexture","rgb")}
277
+ `),S&&(ie+=`float inputs:occlusion${O("OcclusionTexture","r")}
278
+ `);let oe="";if(F||W||T||E||S){oe+=`def Shader "PrimvarReader"
279
+ {
280
+ uniform token info:id = "UsdPrimvarReader_float2"
281
+ string inputs:varname = "st"
282
+ float2 outputs:result
283
+ }
284
+ `;let I=(H,N,z,ue)=>{if(!N)return;let ce=N.scale?`float4 inputs:scale = ${lr(N.scale[0],N.scale[1],N.scale[2],N.scale[3])}
285
+ `:"",B=N.bias?`float4 inputs:bias = ${lr(N.bias[0],N.bias[1],N.bias[2],N.bias[3])}
286
+ `:"";oe+=`def Shader "${H}"
287
+ {
288
+ uniform token info:id = "UsdUVTexture"
289
+ asset inputs:file = @${ur(N.file)}@
290
+ float2 inputs:st${O("PrimvarReader","result")}
291
+ token inputs:sourceColorSpace = "${z}"
292
+ token inputs:wrapS = "${N.wrapS||"repeat"}"
293
+ token inputs:wrapT = "${N.wrapT||"repeat"}"
294
+ ${ce}${B}${ue}}
295
+ `};I("DiffuseTexture",F,"sRGB",`float3 outputs:rgb
296
+ `),I("MetallicRoughnessTexture",W,"raw",`float outputs:g
297
+ float outputs:b
298
+ `),I("NormalTexture",T,"raw",`float3 outputs:rgb
299
+ `),I("EmissiveTexture",E,"sRGB",`float3 outputs:rgb
300
+ `),I("OcclusionTexture",S,"raw",`float outputs:r
301
+ `)}o+=`def Material "${f}"
274
302
  {
275
303
  def Shader "PBRShader"
276
304
  {
277
305
  uniform token info:id = "UsdPreviewSurface"
278
- color3f inputs:diffuseColor = ${xt(x,b,v)}
279
- float inputs:metallic = ${Ge(g.metallic)}
280
- float inputs:roughness = ${Ge(g.roughness)}
281
- ${T}token outputs:surface
282
- }
283
- token outputs:surface.connect = </Root/Materials/${m}/PBRShader.outputs:surface>
306
+ ${k}
307
+ ${w}
308
+ ${ie}token outputs:surface
284
309
  }
310
+ token outputs:surface${O("PBRShader","surface")}
311
+ ${oe}}
285
312
  `}o+=`}
286
313
  def Scope "Meshes"
287
314
  {
288
- `;let a=(m,g,x)=>{let b=[];g&&b.push('"MaterialBindingAPI"');let v=!!(m?.rigidBody&&m.rigidBody!=="none"&&(typeof m.rigidBody!="object"||m.rigidBody.enabled!==!1)),d=!!(m?.physics&&m.physics!=="none"||v);d&&b.push(...v?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let y=[];if(b.length>0&&y.push(`prepend apiSchemas = [${b.join(", ")}]`),m){let P=Me().xrTraitSerializer?.usdLines(m,Ni)??[];if(!P.length)for(let R of["grab","billboard","follow","anchor","physics"]){let C=R==="follow"&&typeof m.follow=="object"?m.follow.mode??"head":m[R];C!==void 0&&P.push(`string ${R} = "${Ni(C)}"`)}P.length>0&&y.push(`customData = {
315
+ `;let a=(f,g,x)=>{let b=[];g&&b.push('"MaterialBindingAPI"');let v=!!(f?.rigidBody&&f.rigidBody!=="none"&&(typeof f.rigidBody!="object"||f.rigidBody.enabled!==!1)),p=!!(f?.physics&&f.physics!=="none"||v);p&&b.push(...v?['"PhysicsBodyAPI"','"PhysicsRigidBodyAPI"','"PhysicsCollisionAPI"','"PhysicsMassAPI"']:['"PhysicsBodyAPI"','"PhysicsCollisionAPI"']);let y=[];if(b.length>0&&y.push(`prepend apiSchemas = [${b.join(", ")}]`),f){let T=Ae().xrTraitSerializer?.usdLines(f,ur)??[];if(!T.length)for(let E of["grab","billboard","follow","anchor","physics"]){let S=E==="follow"&&typeof f.follow=="object"?f.follow.mode??"head":f[E];S!==void 0&&T.push(`string ${E} = "${ur(S)}"`)}T.length>0&&y.push(`customData = {
289
316
  dictionary xr = {
290
- ${P.join(`
317
+ ${T.join(`
291
318
  `)}
292
319
  }
293
320
  }`)}let M=y.length>0?` (
294
321
  ${y.join(`
295
322
  `)}
296
- )`:"",T=x?`uniform token visibility = "invisible"
297
- `:"";if(d){let P=m?.rigidBody??m?.physics,R=P?.body??P?.mode??P;T+=`bool physics:rigidBodyEnabled = true
298
- bool physics:kinematicEnabled = ${R==="static"||R==="kinematic"}
323
+ )`:"",P=x?`uniform token visibility = "invisible"
324
+ `:"";if(p){let T=f?.rigidBody??f?.physics,E=T?.body??T?.mode??T;P+=`bool physics:rigidBodyEnabled = true
325
+ bool physics:kinematicEnabled = ${E==="static"||E==="kinematic"}
299
326
  bool physics:collisionEnabled = true
300
- `,P?.mass>0&&Number.isFinite(P.mass)&&(T+=`float physics:mass = ${Ge(P.mass)}
301
- `)}let V=Ts(m),X=V?`def SpatialAudio "AudioEmitter"
327
+ `,T?.mass>0&&Number.isFinite(T.mass)&&(P+=`float physics:mass = ${je(T.mass)}
328
+ `)}let F=hs(f),W=F?`def SpatialAudio "AudioEmitter"
302
329
  {
303
- ${V.src?`asset inputs:file = @${Ni(V.src)}@
304
- `:""}uniform token inputs:auralMode = "${V.isGlobal?"nonSpatial":"spatial"}"
305
- uniform token inputs:playbackMode = "${V.loop?"loopFromStart":"onceFromStart"}"
306
- double gain = ${Ge(V.volume)}
330
+ ${F.src?`asset inputs:file = @${ur(F.src)}@
331
+ `:""}uniform token inputs:auralMode = "${F.isGlobal?"nonSpatial":"spatial"}"
332
+ uniform token inputs:playbackMode = "${F.loop?"loopFromStart":"onceFromStart"}"
333
+ double gain = ${je(F.volume)}
307
334
  }
308
- `:"";return{header:M,body:T,tail:X}},u=m=>{if(m.timeSamples&&m.timeSamples.times.length>0){let y=m.timeSamples,M=(P,R,C)=>y.times.map((B,N)=>`${Ge(B)}: ${C(P?.[N]||R)}`).join(", "),T=M(y.translations,[0,0,0],P=>xt(P[0],P[1],P[2])),V=M(y.rotations,[0,0,0,1],P=>{let R=Math.hypot(P[0],P[1],P[2],P[3])||1;return gs(P[3]/R,P[0]/R,P[1]/R,P[2]/R)}),X=M(y.scales,[1,1,1],P=>xt(P[0],P[1],P[2]));return`double3 xformOp:translate.timeSamples = { ${T} }
309
- quatf xformOp:orient.timeSamples = { ${V} }
310
- double3 xformOp:scale.timeSamples = { ${X} }
335
+ `:"";return{header:M,body:P,tail:W}},u=f=>{if(f.timeSamples&&f.timeSamples.times.length>0){let y=f.timeSamples,M=(T,E,S)=>y.times.map((O,k)=>`${je(O)}: ${S(T?.[k]||E)}`).join(", "),P=M(y.translations,[0,0,0],T=>At(T[0],T[1],T[2])),F=M(y.rotations,[0,0,0,1],T=>{let E=Math.hypot(T[0],T[1],T[2],T[3])||1;return lr(T[3]/E,T[0]/E,T[1]/E,T[2]/E)}),W=M(y.scales,[1,1,1],T=>At(T[0],T[1],T[2]));return`double3 xformOp:translate.timeSamples = { ${P} }
336
+ quatf xformOp:orient.timeSamples = { ${F} }
337
+ double3 xformOp:scale.timeSamples = { ${W} }
311
338
  uniform token[] xformOpOrder = ["xformOp:translate", "xformOp:orient", "xformOp:scale"]
312
- `}let g=[],x="",b=m.translation;b&&(Math.abs(b[0])>1e-7||Math.abs(b[1])>1e-7||Math.abs(b[2])>1e-7)&&(x+=`double3 xformOp:translate = ${xt(b[0],b[1],b[2])}
313
- `,g.push('"xformOp:translate"'));let v=m.rotation;if(v){let y=Math.hypot(v[0],v[1],v[2],v[3])||1,M=v[0]/y,T=v[1]/y,V=v[2]/y,X=v[3]/y;(1-Math.abs(X)>1e-7||Math.hypot(M,T,V)>1e-7)&&(x+=`quatf xformOp:orient = ${gs(X,M,T,V)}
314
- `,g.push('"xformOp:orient"'))}let d=m.scale;return d&&(Math.abs(d[0]-1)>1e-7||Math.abs(d[1]-1)>1e-7||Math.abs(d[2]-1)>1e-7)&&(x+=`float3 xformOp:scale = ${xt(d[0],d[1],d[2])}
339
+ `}let g=[],x="",b=f.translation;b&&(Math.abs(b[0])>1e-7||Math.abs(b[1])>1e-7||Math.abs(b[2])>1e-7)&&(x+=`double3 xformOp:translate = ${At(b[0],b[1],b[2])}
340
+ `,g.push('"xformOp:translate"'));let v=f.rotation;if(v){let y=Math.hypot(v[0],v[1],v[2],v[3])||1,M=v[0]/y,P=v[1]/y,F=v[2]/y,W=v[3]/y;(1-Math.abs(W)>1e-7||Math.hypot(M,P,F)>1e-7)&&(x+=`quatf xformOp:orient = ${lr(W,M,P,F)}
341
+ `,g.push('"xformOp:orient"'))}let p=f.scale;return p&&(Math.abs(p[0]-1)>1e-7||Math.abs(p[1]-1)>1e-7||Math.abs(p[2]-1)>1e-7)&&(x+=`float3 xformOp:scale = ${At(p[0],p[1],p[2])}
315
342
  `,g.push('"xformOp:scale"')),g.length>0&&(x+=`uniform token[] xformOpOrder = [${g.join(", ")}]
316
- `),x},h=m=>{let g=m.positions.length/3,x=1/0,b=1/0,v=1/0,d=-1/0,y=-1/0,M=-1/0;for(let R=0;R<g;R++){let C=m.positions[R*3],B=m.positions[R*3+1],N=m.positions[R*3+2];C<x&&(x=C),C>d&&(d=C),B<b&&(b=B),B>y&&(y=B),N<v&&(v=N),N>M&&(M=N)}isFinite(x)||(x=b=v=-1,d=y=M=1);let T=Math.floor(m.indices.length/3),V=ur(m.materialName,"DefaultMaterial"),X=T>0?T===1?"3":"3, ".repeat(T-1)+"3":"",P=`float3[] extent = [${xt(x,b,v)}, ${xt(d,y,M)}]
317
- int[] faceVertexCounts = [${X}]
318
- int[] faceVertexIndices = [${xc(m.indices)}]
319
- point3f[] points = [${xs(m.positions)}]
320
- `;return m.normals&&m.normals.length===m.positions.length&&(P+=`normal3f[] normals = [${xs(m.normals)}] (
343
+ `),x},h=f=>{let g=f.positions.length/3,x=1/0,b=1/0,v=1/0,p=-1/0,y=-1/0,M=-1/0;for(let E=0;E<g;E++){let S=f.positions[E*3],O=f.positions[E*3+1],k=f.positions[E*3+2];S<x&&(x=S),S>p&&(p=S),O<b&&(b=O),O>y&&(y=O),k<v&&(v=k),k>M&&(M=k)}isFinite(x)||(x=b=v=-1,p=y=M=1);let P=Math.floor(f.indices.length/3),F=fr(f.materialName,"DefaultMaterial"),W=P>0?P===1?"3":"3, ".repeat(P-1)+"3":"",T=`float3[] extent = [${At(x,b,v)}, ${At(p,y,M)}]
344
+ int[] faceVertexCounts = [${W}]
345
+ int[] faceVertexIndices = [${fc(f.indices)}]
346
+ point3f[] points = [${ms(f.positions)}]
347
+ `;return f.normals&&f.normals.length===f.positions.length&&(T+=`normal3f[] normals = [${ms(f.normals)}] (
321
348
  interpolation = "vertex"
322
349
  )
323
- `),m.uvs&&m.uvs.length===g*2&&(P+=`texCoord2f[] primvars:st = [${gc(m.uvs,g)}] (
350
+ `),f.uvs&&f.uvs.length===g*2&&(T+=`texCoord2f[] primvars:st = [${mc(f.uvs,g)}] (
324
351
  interpolation = "vertex"
325
352
  )
326
- `),P+=`rel material:binding = </Root/Materials/${V}>
327
- `,P},c=new Set,f=[];for(let m=e.length-1;m>=0;m--)f.push({node:e[m],siblings:c});let p=0;for(;f.length>0;){let m=f.pop();if(m.close){o+=`}
328
- `;continue}let{node:g,siblings:x}=m,b=!!(g.isXform||g.positions.length===0),v=vs(x,ur(g.name,b?`Group_${p}`:`Mesh_${p}`));p++;let d=g.children||[];if(b){let y=a(g.xrTraits,!1,g.invisible);o+=`def Xform "${v}"${y.header}
353
+ `),T+=`rel material:binding = </Root/Materials/${F}>
354
+ `,T},m=new Set,c=[];for(let f=e.length-1;f>=0;f--)c.push({node:e[f],siblings:m});let d=0;for(;c.length>0;){let f=c.pop();if(f.close){o+=`}
355
+ `;continue}let{node:g,siblings:x}=f,b=!!(g.isXform||g.positions.length===0),v=fs(x,fr(g.name,b?`Group_${d}`:`Mesh_${d}`));d++;let p=g.children||[];if(b){let y=a(g.xrTraits,!1,g.invisible);o+=`def Xform "${v}"${y.header}
329
356
  {
330
- ${y.body}${u(g)}${y.tail}`,f.push({close:!0});let M=new Set;for(let T=d.length-1;T>=0;T--)f.push({node:d[T],siblings:M})}else if(d.length>0){let y=a(g.xrTraits,!1,g.invisible),M=`${v}_mesh`;o+=`def Xform "${v}"${y.header}
357
+ ${y.body}${u(g)}${y.tail}`,c.push({close:!0});let M=new Set;for(let P=p.length-1;P>=0;P--)c.push({node:p[P],siblings:M})}else if(p.length>0){let y=a(g.xrTraits,!1,g.invisible),M=`${v}_mesh`;o+=`def Xform "${v}"${y.header}
331
358
  {
332
359
  ${y.body}${u(g)}${y.tail}`,o+=`def Mesh "${M}" (
333
360
  prepend apiSchemas = ["MaterialBindingAPI"]
334
361
  )
335
362
  {
336
363
  ${h(g)}}
337
- `,f.push({close:!0});let T=new Set([M]);for(let V=d.length-1;V>=0;V--)f.push({node:d[V],siblings:T})}else{let y=a(g.xrTraits,!0,g.invisible);o+=`def Mesh "${v}"${y.header}
364
+ `,c.push({close:!0});let P=new Set([M]);for(let F=p.length-1;F>=0;F--)c.push({node:p[F],siblings:P})}else{let y=a(g.xrTraits,!0,g.invisible);o+=`def Mesh "${v}"${y.header}
338
365
  {
339
366
  ${y.body}${u(g)}${h(g)}${y.tail}}
340
367
  `}}return o+=`}
341
368
  }
342
- `,o}function ws(e,t){if(e&&typeof e.traverse=="function"){let n=yc(e,t);return ki(n)}let r=gt(e),i=Ui(r);return ki(i)}var cr=null;function Mn(e){if(!cr){cr=new Uint32Array(256);for(let r=0;r<256;r++){let i=r;for(let n=0;n<8;n++)i=i&1?3988292384^i>>>1:i>>>1;cr[r]=i}}let t=4294967295;for(let r=0;r<e.length;r++)t=cr[(t^e[r])&255]^t>>>8;return(t^4294967295)>>>0}function Ss(e){let t=[],r=0,i=[];for(let h of e){let c=Oi(h.filename),f=Mn(h.data),p=h.data.length,m=30+c.length,g=(r+m)%64,x=g!==0?64-g:0,b=new Uint8Array(m+x),v=new DataView(b.buffer);v.setUint32(0,67324752,!0),v.setUint16(4,20,!0),v.setUint32(14,f,!0),v.setUint32(18,p,!0),v.setUint32(22,p,!0),v.setUint16(26,c.length,!0),v.setUint16(28,x,!0),b.set(c,30),t.push({offset:r,size:p,crc:f,filenameBytes:c,entry:h}),i.push(b,h.data),r+=b.length+h.data.length}let n=r;for(let h of t){let c=new Uint8Array(46+h.filenameBytes.length),f=new DataView(c.buffer);f.setUint32(0,33639248,!0),f.setUint16(4,20,!0),f.setUint16(6,20,!0),f.setUint32(16,h.crc,!0),f.setUint32(20,h.size,!0),f.setUint32(24,h.size,!0),f.setUint16(28,h.filenameBytes.length,!0),f.setUint32(42,h.offset,!0),c.set(h.filenameBytes,46),i.push(c),r+=c.length}let s=r-n,l=new Uint8Array(22),o=new DataView(l.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),i.push(l),r+=22;let a=new Uint8Array(r),u=0;for(let h of i)a.set(h,u),u+=h.length;return a}var Es=e=>Ss([{filename:"model.usda",data:Oi(e)}]);function Tn(e){return Es(ws(e))}function An(e){return Es(ki(Ui(gt(e))))}function wn(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():An(e)}function sn(e){let t=wn(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function Nt(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function vc(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Fi(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Mc(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function Rs(e){let t=Fi(e);if(!t)return null;let r=t.target;return{target:vc(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:Nt(t.radius,.01,50,.5),speed:Nt(t.speed,-20,20,.5),height:Nt(t.height,-10,10,0),phase:Nt(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var Tc=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],Ac=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Qu=new Set(Tc),Ju=new Set(Ac);function Vi(e,t){let r=Mc(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function Bi(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:Fi(e);if(!t||t.enabled===!1)return null;let r=Nt(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:Nt(t.threshold,0,4,.8),radius:Nt(t.radius,0,2,.5)}:null}function lr(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:Fi(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:Vi(t.color,"#38bdf8"),thickness:Nt(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}var nt=class Ho{constructor(t=0,r=0){this.x=Number(t),this.y=Number(r)}set(t,r){return this.x=Number(t),this.y=Number(r),this}clone(){return new Ho(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},ge=class Go{constructor(t=0,r=0,i=0){this.x=Number(t),this.y=Number(r),this.z=Number(i)}set(t,r,i){return this.x=Number(t),this.y=Number(r),this.z=Number(i),this}clone(){return new Go(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addVectors(t,r){return this.x=t.x+r.x,this.y=t.y+r.y,this.z=t.z+r.z,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subVectors(t,r){return this.x=t.x-r.x,this.y=t.y-r.y,this.z=t.z-r.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,r){return this.x+=t.x*r,this.y+=t.y*r,this.z+=t.z*r,this}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5&&(this.x/=t,this.y/=t,this.z/=t),this}cross(t){let r=this.y*t.z-this.z*t.y,i=this.z*t.x-this.x*t.z,n=this.x*t.y-this.y*t.x;return this.x=r,this.y=i,this.z=n,this}crossVectors(t,r){let i=t.x,n=t.y,s=t.z,l=r.x,o=r.y,a=r.z;return this.x=n*a-s*o,this.y=s*l-i*a,this.z=i*o-n*l,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,r){return this.lerpVectors(this,t,r)}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this}applyMatrix4(t){let r=this.x,i=this.y,n=this.z,s=t.elements,l=1/(s[3]*r+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*r+s[4]*i+s[8]*n+s[12])*l,this.y=(s[1]*r+s[5]*i+s[9]*n+s[13])*l,this.z=(s[2]*r+s[6]*i+s[10]*n+s[14])*l,this}},pr=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},_n=class Fa{constructor(t=0,r=0,i=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,r,i,n=this.order){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n,this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this.order=t.order,this._onChangeCallback?.(),this}clone(){return new Fa(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},Ln=class Va{constructor(t=0,r=0,i=0,n=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,r,i,n){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n),this._onChangeCallback?.(),this}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback?.(),this}clone(){return new Va(this._x,this._y,this._z,this._w)}setFromEuler(t,r=!0){let i=t.x,n=t.y,s=t.z,l=Math.cos(i/2),o=Math.cos(n/2),a=Math.cos(s/2),u=Math.sin(i/2),h=Math.sin(n/2),c=Math.sin(s/2);return this._x=u*o*a+l*h*c,this._y=l*h*a-u*o*c,this._z=l*o*c+u*h*a,this._w=l*o*a-u*h*c,r&&this._onChangeCallback?.(),this}setFromAxisAngle(t,r){let i=r/2,n=Math.sin(i);return this.set(t.x*n,t.y*n,t.z*n,Math.cos(i))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,r){let i=t.dot(r)+1;return i<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*r.z-t.z*r.y,t.z*r.x-t.x*r.z,t.x*r.y-t.y*r.x,i).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,r){let i=t.x,n=t.y,s=t.z,l=t.w,o=r.x,a=r.y,u=r.z,h=r.w;return this._x=i*h+l*o+n*u-s*a,this._y=n*h+l*a+s*o-i*u,this._z=s*h+l*u+i*a-n*o,this._w=l*h-i*o-n*a-s*u,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Ot=class el{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new el;return t.copy(this),t}compose(t,r,i){return yt(this.elements,[r.x,r.y,r.z,r.w],[t.x,t.y,t.z],[i.x,i.y,i.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,r){return Pe(this.elements,t.elements,r.elements),this}lookAt(t,r,i){return en(this.elements,[t.x,t.y,t.z],[r.x,r.y,r.z],[i.x,i.y,i.z]),this}makeRotationFromQuaternion(t){let r=new ge(0,0,0),i=new ge(1,1,1);return this.compose(r,t,i)}makeTranslation(t,r,i){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(r),this.elements[14]=Number(i),this}makeScale(t,r,i){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(r),this.elements[10]=Number(i),this}},br=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 ze(this.elements,e.elements),this}},Qe=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,mr=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,_s={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},it=class tl{constructor(t,r,i){this.r=1,this.g=1,this.b=1,t!==void 0&&(r!==void 0&&i!==void 0?this.setRGB(t,r,i):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let r=t.trim().toLowerCase();if(r[0]==="#"){let i=r.slice(1);i.length===3||i.length===4?i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i.length===8&&(i=i.slice(0,6));let n=parseInt(i,16);i.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(r in _s)this.setHex(_s[r]);else if(r.startsWith("hsl")){let i=/^hsla?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);i&&i.length>=3&&this.setHSL((parseFloat(i[0])||0)/360,(parseFloat(i[1])||0)/100,(parseFloat(i[2])||0)/100)}else{let i=/^rgba?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);if(i&&i.length>=3){let n=s=>Qe(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(i[0]),n(i[1]),n(i[2]))}}return this}setHSL(t,r,i){if(t=((Number(t)||0)%1+1)%1,r=Math.max(0,Math.min(1,Number(r)||0)),i=Math.max(0,Math.min(1,Number(i)||0)),r===0){let o=Qe(i);return this.setRGB(o,o,o)}let n=i<=.5?i*(1+r):i+r-i*r,s=2*i-n,l=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(Qe(l(t+1/3)),Qe(l(t)),Qe(l(t-1/3)))}lerp(t,r){let i=Number(r)||0;return this.r+=(t.r-this.r)*i,this.g+=(t.g-this.g)*i,this.b+=(t.b-this.b)*i,this}lerpColors(t,r,i){let n=Number(i)||0;return this.r=t.r+(r.r-t.r)*n,this.g=t.g+(r.g-t.g)*n,this.b=t.b+(r.b-t.b)*n,this}multiplyScalar(t){let r=Number(t)||0;return this.r*=r,this.g*=r,this.b*=r,this}setScalar(t){let r=Number(t)||0;return this.setRGB(r,r,r)}setHex(t){let r=Math.floor(t);return this.r=Qe((r>>16&255)/255),this.g=Qe((r>>8&255)/255),this.b=Qe((r&255)/255),this}setRGB(t,r,i){return this.r=Number(t),this.g=Number(r),this.b=Number(i),this}convertSRGBToLinear(){return this.r=Qe(this.r),this.g=Qe(this.g),this.b=Qe(this.b),this}convertLinearToSRGB(){return this.r=mr(this.r),this.g=mr(this.g),this.b=mr(this.b),this}getHex(){let t=r=>Math.round(mr(Math.max(0,Math.min(1,r)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new tl(this.r,this.g,this.b)}},Os={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,r)=>Math.max(t,Math.min(r,e)),lerp:(e,t,r)=>e+(t-e)*r,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},He=class rl{constructor(t,r){if(this.needsUpdate=!1,typeof r!="number"||!Number.isInteger(r)||r<1||r>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(r)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=r;let i=this.array?this.array.length:0;if(!Number.isFinite(i)||i<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(i)}`);this.count=Math.floor(i/r)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,r){return this.array[t*this.itemSize]=r,this.needsUpdate=!0,this}setY(t,r){return this.array[t*this.itemSize+1]=r,this.needsUpdate=!0,this}setZ(t,r){return this.array[t*this.itemSize+2]=r,this.needsUpdate=!0,this}setXYZ(t,r,i,n){let s=t*this.itemSize;return this.array[s]=r,this.array[s+1]=i,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new rl(new t(this.array),this.itemSize)}},yr=class extends He{constructor(e,t){super(e instanceof Float32Array?e:new Float32Array(e),t)}},gr=class extends He{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},xr=class extends He{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},Fe=class il{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,r){return this.attributes[t]=r,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof He)this.index=t;else if(Array.isArray(t)){let r=0;for(let i of t)i>r&&(r=i);this.index=new He(new(r>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new He(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let r=t.count,i=new Float32Array(r*3),n=new ge,s=new ge,l=new ge,o=new ge,a=new ge,u=this.index?.array,h=u?u.length:r;for(let c=0;c<h;c+=3){let f=u?u[c]:c,p=u?u[c+1]:c+1,m=u?u[c+2]:c+2;n.set(t.getX(f),t.getY(f),t.getZ(f)),s.set(t.getX(p),t.getY(p),t.getZ(p)),l.set(t.getX(m),t.getY(m),t.getZ(m)),o.subVectors(l,s),a.subVectors(n,s),o.cross(a).normalize();for(let g of[f,p,m])i[g*3]+=o.x,i[g*3+1]+=o.y,i[g*3+2]+=o.z}for(let c=0;c<r;c++){let f=i[c*3],p=i[c*3+1],m=i[c*3+2],g=Math.hypot(f,p,m)||1;i[c*3]=f/g,i[c*3+1]=p/g,i[c*3+2]=m/g}return this.setAttribute("normal",new He(i,3)),this}setFromBuffers(t,r,i,n){this.setAttribute("position",new He(t,3)),this.setAttribute("normal",new He(r,3)),this.setAttribute("uv",new He(i,2)),this.setIndex(n)}setFromPoints(t){let r=[];if(Array.isArray(t))for(let i of t)r.push(Number(i?.x)||0,Number(i?.y)||0,Number(i?.z)||0);return this.setAttribute("position",new He(r,3))}computeBoundingBox(){let t=this.attributes.position,r=new ge(1/0,1/0,1/0),i=new ge(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let n=0;n<t.count;n++){let s=t.getX(n),l=t.getY(n),o=t.getZ(n);s<r.x&&(r.x=s),l<r.y&&(r.y=l),o<r.z&&(r.z=o),s>i.x&&(i.x=s),l>i.y&&(i.y=l),o>i.z&&(i.z=o)}else r.set(0,0,0),i.set(0,0,0);return this.boundingBox={min:r,max:i},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,r){let i=this.attributes.position;if(i){let n=i.array;for(let s=0;s<n.length;s+=3)t(n,s);i.needsUpdate=!0,r&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,r=0,i=0){return this._xform((n,s)=>{n[s]+=t,n[s+1]+=r,n[s+2]+=i})}scale(t=1,r=1,i=1){return this._xform((n,s)=>{n[s]*=t,n[s+1]*=r,n[s+2]*=i},!0)}_rot(t,r,i){let n=Math.cos(i),s=Math.sin(i);for(let l of[this.attributes.position,this.attributes.normal]){if(!l)continue;let o=l.array;for(let a=0;a<o.length;a+=3){let u=o[a+t],h=o[a+r];o[a+t]=u*n-h*s,o[a+r]=u*s+h*n}l.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let r=this.attributes.position;if(r&&t?.elements){let i=new ge;for(let n=0;n<r.count;n++)i.set(r.getX(n),r.getY(n),r.getZ(n)).applyMatrix4(t),r.setXYZ(n,i.x,i.y,i.z);this.computeVertexNormals()}return this}clone(){let t=new il;t.name=this.name;for(let r of Object.keys(this.attributes))t.attributes[r]=this.attributes[r].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},In=class extends Fe{constructor(e=1,t=1,r=1){super();let i=e/2,n=t/2,s=r/2,l=[-i,-n,s,i,-n,s,i,n,s,-i,n,s,i,-n,-s,-i,-n,-s,-i,n,-s,i,n,-s,-i,n,s,i,n,s,i,n,-s,-i,n,-s,-i,-n,-s,i,-n,-s,i,-n,s,-i,-n,s,i,-n,s,i,-n,-s,i,n,-s,i,n,s,-i,-n,-s,-i,-n,s,-i,n,s,-i,n,-s],o=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],a=[],u=[];for(let h=0;h<6;h++){let c=h*4;a.push(0,0,1,0,1,1,0,1),u.push(c,c+1,c+2,c,c+2,c+3)}this.setFromBuffers(l,o,a,u)}},vr=class extends Fe{constructor(e=1,t=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let n=[],s=[],l=[],o=[];for(let a=0;a<=i;a++){let u=a/i;for(let h=0;h<=r;h++){let c=h/r;if(n.push((c-.5)*e,(.5-u)*t,0),s.push(0,0,1),l.push(c,1-u),a>0&&h>0){let f=(r+1)*a+h-1,p=f-(r+1);o.push(p,f,p+1,f,f+1,p+1)}}}this.setFromBuffers(n,s,l,o)}},Mr=class extends Fe{constructor(e=1,t=16,r=12){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let i=[],n=[],s=[],l=[];for(let o=0;o<=r;o++){let a=o/r;for(let u=0;u<=t;u++){let h=u/t,c=h*Math.PI*2,f=a*Math.PI,p=-Math.cos(c)*Math.sin(f),m=Math.cos(f),g=Math.sin(c)*Math.sin(f);if(i.push(e*p,e*m,e*g),n.push(p,m,g),s.push(h,1-a),o>0&&u>0){let x=(t+1)*o+u,b=x-(t+1),v=b-1,d=x-1;o!==1&&l.push(b,v,x),o!==r&&l.push(v,d,x)}}}this.setFromBuffers(i,n,s,l)}},Cn=class extends Fe{constructor(e=1,t=1,r=1,i=16){super(),i=Math.max(3,Math.floor(i));let n=[],s=[],l=[],o=[],a=r/2;for(let h=0;h<=1;h++){let c=h,f=h===0?e:t,p=h===0?a:-a;for(let m=0;m<=i;m++){let g=m/i,x=g*Math.PI*2,b=Math.sin(x),v=Math.cos(x);n.push(f*b,p,f*v),s.push(b,0,v),l.push(g,1-c)}}for(let h=0;h<i;h++){let c=h,f=h+i+1,p=h+i+2,m=h+1;o.push(c,f,m,f,p,m)}let u=(h,c)=>{if(h<=0)return;let f=c*a,p=n.length/3;n.push(0,f,0),s.push(0,c,0),l.push(.5,.5);let m=n.length/3;for(let g=0;g<=i;g++){let x=g/i*Math.PI*2,b=Math.sin(x),v=Math.cos(x);n.push(h*b,f,h*v),s.push(0,c,0),l.push(v*.5+.5,.5+c*b*.5)}for(let g=0;g<i;g++)o.push(p,m+g+(c>0?0:1),m+g+(c>0?1:0))};u(e,1),u(t,-1),this.setFromBuffers(n,s,l,o)}},Tr=class extends Cn{constructor(e=1,t=1,r=16){super(0,e,t,r)}},Ar=class extends Fe{constructor(e=1,t=.4,r=12,i=48,n=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],l=[],o=[],a=[];for(let u=0;u<=r;u++){let h=u/r*Math.PI*2,c=Math.cos(h),f=Math.sin(h);for(let p=0;p<=i;p++){let m=p/i*n,g=Math.cos(m),x=Math.sin(m);if(s.push((e+t*c)*g,(e+t*c)*x,t*f),l.push(c*g,c*x,f),o.push(p/i,u/r),u>0&&p>0){let b=(i+1)*u+p-1,v=b-(i+1);a.push(b,v,b+1,v,v+1,b+1)}}}this.setFromBuffers(s,l,o,a)}};function Us(e,t,r,i,n){let s=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),l=Math.max(3,Math.min(64,Math.floor(Number(r)||8))),o=Number(i)||.1,a=[],u=[],h=[],c=[],f=new ge,p=new ge,m=new ge,g=new ge,x=new ge;for(let v=0;v<=s;v++){let d=v/s;n(Math.max(0,d-.001),f),n(Math.min(1,d+.001),p),m.subVectors(p,f).normalize(),v===0&&g.set(Math.abs(m.y)>.9?1:0,Math.abs(m.y)>.9?0:1,0),x.crossVectors(m,g).normalize(),g.crossVectors(x,m).normalize(),n(d,f);for(let y=0;y<=l;y++){let M=y/l*Math.PI*2,T=-o*Math.cos(M),V=o*Math.sin(M),X=T*g.x+V*x.x,P=T*g.y+V*x.y,R=T*g.z+V*x.z;a.push(f.x+X,f.y+P,f.z+R);let C=Math.hypot(X,P,R)||1;u.push(X/C,P/C,R/C),h.push(d,y/l)}}let b=l+1;for(let v=1;v<=s;v++){let d=b*(v-1),y=d+b;for(let M=1;M<=l;M++){let T=d+M-1,V=y+M-1;c.push(T,V,d+M,V,y+M,d+M)}}e.setFromBuffers(a,u,h,c)}var wr=class extends Fe{constructor(e=1,t=.4,r=64,i=8,n=2,s=3){super(),r=Math.floor(r),i=Math.floor(i),Us(this,r,i,t,(l,o)=>{let a=l*n*Math.PI*2,u=s/n*a,h=e*(2+Math.cos(u))*.5;o.set(h*Math.cos(a),h*Math.sin(a),e*Math.sin(u)*.5)})}},Mt=class{getPoint(e,t=new ge){return t}getPointAt(e,t=new ge){return this.getPoint(e,t)}getTangent(e,t=new ge){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),r=[];for(let i=0;i<=t;i++)r.push(this.getPoint(i/t));return r}getSpacedPoints(e=5){return this.getPoints(e)}},Sr=class extends Mt{constructor(e=new ge,t=new ge){super(),this.v1=e,this.v2=t}getPoint(e,t=new ge){return t.lerpVectors(this.v1,this.v2,e)}},Er=class extends Mt{constructor(e=new ge,t=new ge,r=new ge){super(),this.v0=e,this.v1=t,this.v2=r}getPoint(e,t=new ge){return t.lerpVectors(this.v0,this.v1,e).lerp(new ge().lerpVectors(this.v1,this.v2,e),e)}},Rr=class extends Mt{constructor(e=new ge,t=new ge,r=new ge,i=new ge){super(),this.v0=e,this.v1=t,this.v2=r,this.v3=i}getPoint(e,t=new ge){let r=new ge().lerpVectors(this.v0,this.v1,e),i=new ge().lerpVectors(this.v1,this.v2,e),n=new ge().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(r.lerp(i,e),i.lerp(n,e),e)}},_r=class extends Mt{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new ge){let r=this.points,i=r.length;if(!i)return t.set(0,0,0);if(i===1)return t.copy(r[0]);let n=(this.closed?i:i-1)*Math.max(0,Math.min(1,Number(e)||0)),s=Math.floor(n),l=n-s;!this.closed&&s>=i-1&&(s=i-2,l=1);let o=g=>r[this.closed?(g%i+i)%i:Math.max(0,Math.min(i-1,g))],a=o(s-1),u=o(s),h=o(s+1),c=o(s+2),f=l*l,p=f*l,m=(g,x,b,v)=>.5*(2*x+(b-g)*l+(2*g-5*x+4*b-v)*f+(3*x-g-3*b+v)*p);return t.set(m(a.x,u.x,h.x,c.x),m(a.y,u.y,h.y,c.y),m(a.z,u.z,h.z,c.z))}},Dn=class extends Fe{constructor(e=[new nt(0,-.5),new nt(.5,0),new nt(0,.5)],t=12,r=0,i=Math.PI*2){super();let n=Array.isArray(e)&&e.length>=2?e:[new nt(.2,0),new nt(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),l=[],o=[],a=[],u=[],h=n.length;for(let c=0;c<=s;c++){let f=c/s,p=r+f*i,m=Math.sin(p),g=Math.cos(p);for(let x=0;x<h;x++){let b=n[x],v=Number(b?.x)||0,d=Number(b?.y)||0;l.push(v*m,d,v*g);let y=n[Math.max(0,x-1)],M=n[Math.min(h-1,x+1)],T=(Number(M?.x)||0)-(Number(y?.x)||0),V=(Number(M?.y)||0)-(Number(y?.y)||0),X=Math.hypot(V,T)||1;o.push(V/X*m,-T/X,V/X*g),a.push(f,x/(h-1))}}for(let c=0;c<s;c++){let f=c*h;for(let p=0;p<h-1;p++){let m=f+p,g=f+h+p;u.push(m,g,m+1,g,g+1,m+1)}}this.setFromBuffers(l,o,a,u)}},Lr=class extends Fe{constructor(e,t=64,r=1,i=8,n=!1){super(),Us(this,t,i,r,(s,l)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let a=o.call(e,s,l);a&&a!==l&&l.copy(a)}else l.set(0,s,0)})}},fr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",an=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new nt(1,1),this.offset=new nt(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Ir=class extends an{constructor(e=null,t=1,r=1,i=1023,n=1009,s,l=1001,o=1001,a=1003,u=1003,h=1,c=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1;let f=Number(t),p=Number(r),m=e&&typeof e.length=="number"?e:null;this.width=f,this.height=p,this.image={data:m,width:f,height:p},this.format=Number(i)||1023,this.type=Number(n)||1009,this.wrapS=Number(l)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(a)||1003,this.minFilter=Number(u)||1003,this.colorSpace=c||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,r=Number(e?.width??this.width),i=Number(e?.height??this.height);if(!t||!t.length||!(r>0&&i>0)||r>2048||i>2048){this.source="";return}let n=Math.max(1,r|0),s=Math.max(1,i|0),l=n*s,o=this.format,a=o===1021||o===1024||o===1028||t.length===l?1:o===1025||o===1030||t.length===l*2?2:o===1022||t.length===l*3?3:4,u=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,h=Math.min(n,96),c=Math.min(s,96),f=c*(1+h*4),p=new Uint8Array(68+f),m=new DataView(p.buffer);m.setUint32(0,2303741511),m.setUint32(4,218765834),m.setUint32(8,13),m.setUint32(12,1229472850),m.setUint32(16,h),m.setUint32(20,c),p[24]=8,p[25]=6,m.setUint32(29,Mn(p.subarray(12,29))),m.setUint32(33,f+11),m.setUint32(37,1229209940),p[41]=120,p[42]=1,p[43]=1,m.setUint16(44,f,!0),m.setUint16(46,~f&65535,!0);let g=48,x=1,b=0,v=0,d=0,y=0,M=0,T=R=>{if(!Number.isFinite(R))return 0;let C=u&&R<=1?R*255:R;return C>0?C<255?C+.5|0:255:0};for(let R=0;R<c;R++){let C=R*s/c|0,B=this.flipY?s-1-C:C;p[g++]=0,b+=x;for(let N=0;N<h;N++){let w=(B*n+(N*n/h|0))*a,ie=o===1021?255:T(t[w]??0),ae=a>=3||o===1030?T(t[w+1]??0):ie,k=a>=3?T(t[w+2]??0):o===1030?0:ie,J=a===4?T(t[w+3]??255):o===1021?T(t[w]??255):o===1025?T(t[w+1]??255):255;p[g++]=ie,x+=ie,b+=x,p[g++]=ae,x+=ae,b+=x,p[g++]=k,x+=k,b+=x,p[g++]=J,x+=J,b+=x,v+=ie,d+=ae,y+=k,M+=J}x%=65521,b%=65521}m.setUint32(g,(b<<16|x)>>>0),m.setUint32(g+4,Mn(p.subarray(37,g+4))),m.setUint32(g+12,1229278788),m.setUint32(g+16,2923585666);let V=h*c*255,X=this.colorSpace==="srgb-linear";this.avgColor=[X?v/V:Qe(v/V),X?d/V:Qe(d/V),X?y/V:Qe(y/V),M/V];let P=["data:image/png;base64,"];for(let R=0;R<p.length;R+=3){let C=p[R]<<16|(p[R+1]??0)<<8|(p[R+2]??0);P.push(fr[C>>18&63]+fr[C>>12&63]+(R+1<p.length?fr[C>>6&63]:"=")+(R+2<p.length?fr[C&63]:"="))}this.source=P.join("")}},Cr=class{load(e,t){let r=new an(e);return t?.(r),r}};function qe(e,t){return e!==void 0?Number(e):t}function zi(e,t){return e!==void 0?!!e:t}var Je=class{constructor(e={}){this.name=e.name||"",this.color=new it(e.color!==void 0?e.color:16777215),this.emissive=new it(e.emissive!==void 0?e.emissive:0),this.emissiveIntensity=qe(e.emissiveIntensity,1),this.roughness=qe(e.roughness,.5),this.metalness=qe(e.metalness,0),this.opacity=qe(e.opacity,1),this.transparent=zi(e.transparent,!1),this.wireframe=zi(e.wireframe,!1),this.side=qe(e.side,2),this.doubleSided=zi(e.doubleSided,!0),this.map=e.map||null,this.clearcoat=qe(e.clearcoat,0),this.clearcoatRoughness=qe(e.clearcoatRoughness,0),this.sheen=qe(e.sheen,0),this.sheenColor=new it(e.sheenColor!==void 0?e.sheenColor:0),this.sheenRoughness=qe(e.sheenRoughness,0),this.transmission=qe(e.transmission,0),this.thickness=qe(e.thickness,0),this.attenuationColor=new it(e.attenuationColor!==void 0?e.attenuationColor:16777215),this.attenuationDistance=qe(e.attenuationDistance,1/0),this.ior=qe(e.ior,1.5),this.dispersion=qe(e.dispersion,0),this.iridescence=qe(e.iridescence,0),this.iridescenceIOR=qe(e.iridescenceIOR,1.3)}dispose(){}},zt=class extends Je{},Dr=class extends Je{},Pr=class extends Je{},Nr=class extends Je{},kr=class extends Je{},ot=class nl{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 ge,this.rotation=new _n,this.quaternion=new Ln,this.scale=new ge(1,1,1),this.matrix=new Ot,this.matrixWorld=new Ot,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,r=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),i=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),n=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(r,i,n)})}add(...t){for(let r of t)r&&r instanceof nl&&(r.parent&&r.parent.remove(r),r.parent=this,this.children.push(r));return this}remove(...t){for(let r of t){let i=this.children.indexOf(r);i!==-1&&(r.parent=null,this.children.splice(i,1))}return this}traverse(t){let r=new Set,i=[this];for(;i.length>0;){let n=i.pop();if(!n||typeof n!="object"||r.has(n))continue;r.add(n),t(n);let s=n.children;if(Array.isArray(s))for(let l=s.length-1;l>=0;l--)i.push(s[l])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(r=>{Fs(r),(r.matrixAutoUpdate||t)&&r.updateMatrix?.(),r.parent&&r.parent.matrixWorld?r.matrixWorld?.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrix&&r.matrixWorld?.copy(r.matrix)})}lookAt(t,r,i){let n=typeof t=="object"?t:new ge(t,r,i);this.target instanceof ge?this.target.copy(n):this.target?.position instanceof ge&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new Ot;s.lookAt(this.position,n,new ge(0,1,0));let l=s.elements,o=l[0],a=l[4],u=l[8],h=l[1],c=l[5],f=l[9],p=l[2],m=l[6],g=l[10],x=o+c+g;if(x>0){let b=.5/Math.sqrt(x+1);this.quaternion.set((m-f)*b,(u-p)*b,(h-a)*b,.25/b)}}translateOnAxis(t,r){let i=t.clone().applyMatrix4(new Ot().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(r);return this.position.add(i),this}translateX(t){return this.translateOnAxis(new ge(1,0,0),t)}translateY(t){return this.translateOnAxis(new ge(0,1,0),t)}translateZ(t){return this.translateOnAxis(new ge(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}clone(t=!0){let r=this instanceof Ut?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof mt?new mt(this.geometry,this.material):new this.constructor;r.name=this.name,r.position.copy(this.position),r.quaternion.copy(this.quaternion),r.scale.copy(this.scale),r.visible=this.visible,r.castShadow=this.castShadow,r.receiveShadow=this.receiveShadow;try{r.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{r.userData={...this.userData||{}}}if(t)for(let i of this.children)r.add(i.clone(!0));return r}},Or=class extends ot{},mt=class extends ot{constructor(e,t){super(),this.isMesh=!0;let r=Array.isArray(t)?t[0]:t;this.geometry=e instanceof Fe?e:e?(Ht("unsupported geometry","BoxGeometry"),new In(.5,.5,.5)):new Fe,this.material=r instanceof Je?r:r?(Ht("unsupported material","MeshStandardMaterial"),new zt({color:13421772})):new zt}};function Fs(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=Me().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var Pn=1e4,Nn=class extends mt{constructor(e,t,r=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let i=Number(r);if(!Number.isFinite(i)||i<0||i>Pn)throw new RangeError(`SecurityError: InstancedMesh count (${String(r)}) exceeds MAX_INSTANCES_PER_MESH (${Pn})`);this.count=Math.floor(i);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let l=s*16;n[l]=1,n[l+5]=1,n[l+10]=1,n[l+15]=1}this.instanceMatrix=new He(n,16)}setMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++){let l=Number(t.elements[s]);i[n+s]=Number.isFinite(l)?l:s%5===0?1:0}}getMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++)t.elements[s]=i[n+s]}setColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new He(s,3)}let i=this.instanceColor.array,n=r*3;i[n]=Number.isFinite(t.r)?t.r:1,i[n+1]=Number.isFinite(t.g)?t.g:1,i[n+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(r+1)*3){t.setRGB(1,1,1);return}let i=this.instanceColor.array,n=r*3;t.setRGB(i[n],i[n+1],i[n+2])}dispose(){}},Gt=class extends ot{constructor(e=16777215,t=1){super(),this.color=new it(e),this.intensity=Number(t),this.type="directional"}},kn=class extends Gt{constructor(e,t){super(e,t),this.type="ambient"}},Ur=class extends Gt{constructor(e,t){super(e,t),this.target=new ot,this.type="directional"}},On=class extends Gt{constructor(e,t,r=0,i=2){super(e,t),this.type="point",this.distance=r,this.decay=i}},Un=class extends ot{},Fr=class extends Un{constructor(e=45,t=1,r=.1,i=1e3){super(),this.target=new ge(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(r),this.far=Number(i)}},Fn=class extends ot{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return lt.validate(this),on(this)}toGLB(){return lt.validate(this),vn(this)}toUSDZ(){return lt.validate(this),Tn(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(r=>{if(r instanceof mt){let i=new Float32Array(r.matrixWorld.elements);e.set(t,i),r.name&&e.set(r.name,i),t++}}),e}},Gi=on,Hi=vn,Vs=Tn,lt=class{static validate(e){let t=0,r=0,i=0,n=new Set,s=(o,a,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${a}). Found: ${u}`)},l=(o,a)=>{if(!Number.isFinite(a))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(a)}), which cannot be bounds-checked.`);return a};e.traverse(o=>{if(Fs(o),o instanceof mt||o.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),o instanceof Nn){let u=l("instance",o.count);(u<0||u>Pn)&&s("INSTANCES",Pn,u)}let a=o.geometry;if(a){let u=0;if(a.attributes.position&&(u=l("vertex",a.attributes.position.count),t+=u,t>1e5&&s("VERTICES",1e5,t)),a.index){let h=l("index",a.index.count);r+=h,r>3e5&&s("INDICES",3e5,r);let c=a.index.array;if(c&&u>0){let f=Math.min(h,c.length);for(let p=0;p<f;p++){let m=c[p];if(!Number.isFinite(m)||m<0||m>=u)throw new Error(`SecurityError: Index buffer value (${String(m)}) out of vertex bounds [0, ${u}).`)}}}}if(o.material){let u=o.material;u.map&&n.add(u.map),u.normalMap&&n.add(u.normalMap),u.roughnessMap&&n.add(u.roughnessMap)}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let a=o,u=a.image,h=Number(u?.width??a.width??0)||0,c=Number(u?.height??a.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(c)||h>2048||c>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(h,c))}}},Vr=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new it(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){lt.validate(e);let i=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=e.getMeshTransforms(),s={};for(let[l,o]of n.entries())s[l]=Array.from(o);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=Gi(e),s=Hi(e),l=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Ls(){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 Br=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=Ls(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=Ls();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function wc(){}var En=new Proxy(wc,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:En},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>En,construct:()=>En}),Is=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function ti(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function cn(e,t){if(!e||typeof e!="string")return!1;let r=e.trim();if(!r)return!1;try{let i=new URL(r,ti());return!(i.protocol!=="https:"&&i.protocol!=="http:"&&i.protocol!=="blob:"||t?.requireSameOrigin&&i.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&i.origin!==location.origin)}catch{return!1}}var Cs,Sn;function Bs(e){if(!cn(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(Sn===void 0||Cs!==t){Cs=t;try{Sn=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!cn(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Sn=null}}return Sn?Sn.createScriptURL(e):e}function Sc(e){Me().sandboxEngineSrc=e}function Xi(){let e=Me().sandboxEngineSrc;if(e)return e;if(Is)return Is;try{if(typeof document>"u")return null;let t=ti(),r=Array.from(document.querySelectorAll("script[src]"));for(let i of r){let n=i.src;if(!n)continue;let s=new URL(n,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&cn(n,{requireSameOrigin:!0}))return n}}catch{}return null}function $i(e,t){if(!cn(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,ti()).href}function Ec(){let e=Xi();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return $i(e,"sandbox engine")}function Rc(e){Me().sandboxIframeSrc=e}function zs(){let e=Me().sandboxIframeSrc;if(e)return e;let t=Xi();if(!t||!cn(t))return null;let r=new URL(t,ti());return r.protocol==="blob:"?null:new URL("three-live-sandbox.html",r).href}function _c(){let e=zs();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return $i(e,"sandbox iframe")}function Lc(e){Me().allowClientScripts=e}function Gs(){return!!Me().allowClientScripts}function Ic(e){return $i(e,"procedural scene script")}var Cc=["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 Dc(e,t){let r=self,i=e.nonce,n=e.engineSrc,s=e.allowedScriptUrl,l=e.allowClientScripts,o=e.revoked,a=r.postMessage.bind(r);function u(d){a({type:"ERROR",nonce:i,message:String(d)})}let h=typeof r.importScripts=="function"?r.importScripts.bind(r):null,c=s,f=null;try{let d=n;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let y={createScriptURL:function(T){if(T!==n&&(!s||T!==s))throw new TypeError("Disallowed worker importScripts URL");return T}};l&&(y.createScript=function(T){return String(T)});let M=r.trustedTypes.createPolicy("three-live#worker-boot",y);d=M.createScriptURL(n),s&&(c=M.createScriptURL(s)),l&&typeof M.createScript=="function"&&(f=M.createScript.bind(M))}catch{}h(d)}catch(d){u('Sandbox failed to load the Three-Live engine from "'+n+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(d&&d.message||d));return}let p=r.THREE;if(!p||typeof p.Scene!="function"){u('Sandbox loaded "'+n+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let d=r.__THREE_LIVE_REGISTRY__;for(let y=0;y<t.length;y++)if(typeof t[y]=="function")try{t[y](p,d)}catch{}}function m(d,y,M){let T=r;for(;T&&T!==Object.prototype;){if(!M&&T!==r)try{delete T[d]}catch{}if(!M||T===r||Object.prototype.hasOwnProperty.call(T,d))try{Object.defineProperty(T,d,M?{value:y,writable:!1,configurable:!1}:{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{T=Object.getPrototypeOf(T)}catch{break}}}for(let d=0;d<o.length;d++)m(o[d],void 0);m("performance",Object.freeze({now:function(){return Date.now()}}));let g=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function b(d,y){if(d.type==="3D_MODEL_READY"){if(x)return;x=!0}d.nonce=i,y&&y.length?a(d,y):a(d)}m("postMessage",function(d,y){if(!d||g.indexOf(d.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+g.join(", ")+").");b(d,y)},!0);let v=!1;r.onmessage=function(d){let y=d&&d.data;if(!(!y||y.nonce!==i)&&!(y.type!=="EXECUTE"&&y.type!=="EXECUTE_URL")&&!v){v=!0;try{let M=new p.Scene,T=new p.PerspectiveCamera(60,1,.1,1e3),V=new p.WebGLRenderer({isSandboxed:!0});if(y.type==="EXECUTE_URL"){if(!s||y.scriptUrl!==s||typeof h!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let X=c||s,P=h;if(h=null,c=null,r.THREE=p,r.scene=M,r.camera=T,r.renderer=V,P(X),typeof r.__THREE_LIVE_SCENE__=="function"){let R=r.__THREE_LIVE_SCENE__(p,M,T,V);R&&typeof R.toGLB=="function"&&(M=R)}else r.scene&&typeof r.scene.toGLB=="function"&&(M=r.scene)}else{if(!l){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let X=f?(0,eval)(f(`(function (THREE, scene, camera, renderer) {
369
+ `,o}var mr=null;function An(e){if(!mr){mr=new Uint32Array(256);for(let r=0;r<256;r++){let i=r;for(let n=0;n<8;n++)i=i&1?3988292384^i>>>1:i>>>1;mr[r]=i}}let t=4294967295;for(let r=0;r<e.length;r++)t=mr[(t^e[r])&255]^t>>>8;return(t^4294967295)>>>0}function ys(e){let t=[],r=0,i=[];for(let h of e){let m=Ui(h.filename),c=An(h.data),d=h.data.length,f=30+m.length,g=(r+f)%64,x=g!==0?64-g:0;x>0&&x<4&&(x+=64);let b=new Uint8Array(f+x),v=new DataView(b.buffer);v.setUint32(0,67324752,!0),v.setUint16(4,20,!0),v.setUint32(14,c,!0),v.setUint32(18,d,!0),v.setUint32(22,d,!0),v.setUint16(26,m.length,!0),v.setUint16(28,x,!0),b.set(m,30),x>=4&&(v.setUint16(f,6534,!0),v.setUint16(f+2,x-4,!0)),t.push({offset:r,size:d,crc:c,filenameBytes:m,entry:h}),i.push(b,h.data),r+=b.length+h.data.length}let n=r;for(let h of t){let m=new Uint8Array(46+h.filenameBytes.length),c=new DataView(m.buffer);c.setUint32(0,33639248,!0),c.setUint16(4,20,!0),c.setUint16(6,20,!0),c.setUint32(16,h.crc,!0),c.setUint32(20,h.size,!0),c.setUint32(24,h.size,!0),c.setUint16(28,h.filenameBytes.length,!0),c.setUint32(42,h.offset,!0),m.set(h.filenameBytes,46),i.push(m),r+=m.length}let s=r-n,l=new Uint8Array(22),o=new DataView(l.buffer);o.setUint32(0,101010256,!0),o.setUint16(8,t.length,!0),o.setUint16(10,t.length,!0),o.setUint32(12,s,!0),o.setUint32(16,n,!0),i.push(l),r+=22;let a=new Uint8Array(r),u=0;for(let h of i)a.set(h,u),u+=h.length;return a}function gs(e){let t=[{filename:"model.usda",data:Ui(dc(e))}],r=new Set(["model.usda"]),i=[...e];for(;i.length>0;){let n=i.pop();for(let s of n.textures||[])s?.file&&s.data?.byteLength&&!r.has(s.file)&&(r.add(s.file),t.push({filename:s.file,data:s.data}));if(n.children)for(let s=n.children.length-1;s>=0;s--)i.push(n.children[s])}return ys(t)}function wn(e){return gs(lc(e))}function Sn(e){return gs(bs(Lt(e)))}function En(e){return e&&typeof e.toUSDZ=="function"?e.toUSDZ():Sn(e)}function on(e){let t=En(e);return new Blob([t],{type:"model/vnd.usdz+zip"})}function Ct(e,t,r,i){let n=typeof e=="number"&&Number.isFinite(e)?e:i;return Math.max(t,Math.min(r,n))}function hc(e){return Array.isArray(e)&&e.length>=3&&Number.isFinite(e[0])&&Number.isFinite(e[1])&&Number.isFinite(e[2])}function Fi(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function pc(e,t=256){return typeof e=="string"&&e.length>0?e.slice(0,t):void 0}function xs(e){let t=Fi(e);if(!t)return null;let r=t.target;return{target:hc(r)?[r[0],r[1],r[2]]:typeof r=="string"&&r.length>0&&r.length<=256?r:[0,0,0],radius:Ct(t.radius,.01,50,.5),speed:Ct(t.speed,-20,20,.5),height:Ct(t.height,-10,10,0),phase:Ct(t.phase,-1e6,1e6,0),faceCenter:t.faceCenter===!0}}var bc=["hum","reactor","wind","beacon","geiger","chimeLoop","machinery","water"],yc=["confirm","error","alarm","warning","pickup","jump","beam","impact","burst","powerup","step","pass","fail"],Wu=new Set(bc),ju=new Set(yc);function Vi(e,t){let r=pc(e,16)?.trim();if(!r)return t;let i=/^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(r);return i?`#${i[1].toLowerCase()}`:t}function Bi(e){if(!e||typeof e=="number"&&!(e>0&&Number.isFinite(e)))return null;let t=e===!0?{}:typeof e=="number"?{strength:e}:Fi(e);if(!t||t.enabled===!1)return null;let r=Ct(t.strength??t.intensity,0,5,.35);return r>0?{enabled:!0,strength:r,threshold:Ct(t.threshold,0,4,.8),radius:Ct(t.radius,0,2,.5)}:null}function dr(e){if(!e)return null;let t=e===!0?{}:typeof e=="string"?{color:e}:Fi(e);if(!t||t.enabled===!1)return null;let r=t.thickness??t.width;return{enabled:!0,color:Vi(t.color,"#38bdf8"),thickness:Ct(typeof r=="number"&&r>0&&r<.25?Math.max(1.5,r*140):r,.5,20,3),pulse:t.pulse===!0}}var rt=class No{constructor(t=0,r=0){this.x=Number(t),this.y=Number(r)}set(t,r){return this.x=Number(t),this.y=Number(r),this}clone(){return new No(this.x,this.y)}copy(t){return this.set(t.x,t.y)}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t)}},ge=class Do{constructor(t=0,r=0,i=0){this.x=Number(t),this.y=Number(r),this.z=Number(i)}set(t,r,i){return this.x=Number(t),this.y=Number(r),this.z=Number(i),this}clone(){return new Do(this.x,this.y,this.z)}copy(t){return this.set(t.x,t.y,t.z)}add(t){return this.addVectors(this,t)}addVectors(t,r){return this.set(t.x+r.x,t.y+r.y,t.z+r.z)}sub(t){return this.subVectors(this,t)}subVectors(t,r){return this.set(t.x-r.x,t.y-r.y,t.z-r.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}divideScalar(t){return this.multiplyScalar(t?1/t:0)}setScalar(t){return this.set(t,t,t)}addScaledVector(t,r){return this.set(this.x+t.x*r,this.y+t.y*r,this.z+t.z*r)}length(){return Math.hypot(this.x,this.y,this.z)}normalize(){let t=this.length();return t>1e-5?this.multiplyScalar(1/t):this}cross(t){return this.crossVectors(this,t)}crossVectors(t,r){let i=t.x,n=t.y,s=t.z,l=r.x,o=r.y,a=r.z;return this.set(n*a-s*o,s*l-i*a,i*o-n*l)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}distanceTo(t){return Math.hypot(this.x-t.x,this.y-t.y,this.z-t.z)}lerp(t,r){return this.lerpVectors(this,t,r)}lerpVectors(t,r,i){return this.x=t.x+(r.x-t.x)*i,this.y=t.y+(r.y-t.y)*i,this.z=t.z+(r.z-t.z)*i,this}applyMatrix4(t){let r=this.x,i=this.y,n=this.z,s=t.elements,l=1/(s[3]*r+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*r+s[4]*i+s[8]*n+s[12])*l,this.y=(s[1]*r+s[5]*i+s[9]*n+s[13])*l,this.z=(s[2]*r+s[6]*i+s[10]*n+s[14])*l,this}},gr=class{constructor(e=0,t=0,r=0,i=1){this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i)}set(e,t,r,i){return this.x=Number(e),this.y=Number(t),this.z=Number(r),this.w=Number(i),this}},In=class ko{constructor(t=0,r=0,i=0,n="XYZ"){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}set(t,r,i,n=this.order){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this.order=n,this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.order)}clone(){return new ko(this._x,this._y,this._z,this.order)}_onChange(t){return this._onChangeCallback=t,this}},sn=class Oo{constructor(t=0,r=0,i=0,n=1){this._onChangeCallback=null,this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n)}get x(){return this._x}set x(t){this._x=Number(t),this._onChangeCallback?.()}get y(){return this._y}set y(t){this._y=Number(t),this._onChangeCallback?.()}get z(){return this._z}set z(t){this._z=Number(t),this._onChangeCallback?.()}get w(){return this._w}set w(t){this._w=Number(t),this._onChangeCallback?.()}set(t,r,i,n){return this._x=Number(t),this._y=Number(r),this._z=Number(i),this._w=Number(n),this._onChangeCallback?.(),this}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){return new Oo(this._x,this._y,this._z,this._w)}identity(){return this.set(0,0,0,1)}setFromEuler(t,r=!0){let i=t.x,n=t.y,s=t.z,l=Math.cos(i/2),o=Math.cos(n/2),a=Math.cos(s/2),u=Math.sin(i/2),h=Math.sin(n/2),m=Math.sin(s/2);return this._x=u*o*a+l*h*m,this._y=l*h*a-u*o*m,this._z=l*o*m+u*h*a,this._w=l*o*a-u*h*m,r&&this._onChangeCallback?.(),this}setFromAxisAngle(t,r){let i=r/2,n=Math.sin(i);return this.set(t.x*n,t.y*n,t.z*n,Math.cos(i))}normalize(){let t=Math.hypot(this._x,this._y,this._z,this._w);return t===0?this.set(0,0,0,1):this.set(this._x/t,this._y/t,this._z/t,this._w/t)}setFromUnitVectors(t,r){let i=t.dot(r)+1;return i<1e-6?(Math.abs(t.x)>Math.abs(t.z)?this.set(-t.y,t.x,0,0):this.set(0,-t.z,t.y,0)).normalize():this.set(t.y*r.z-t.z*r.y,t.z*r.x-t.x*r.z,t.x*r.y-t.y*r.x,i).normalize()}multiply(t){return this.multiplyQuaternions(this,t)}multiplyQuaternions(t,r){let i=t.x,n=t.y,s=t.z,l=t.w,o=r.x,a=r.y,u=r.z,h=r.w;return this._x=i*h+l*o+n*u-s*a,this._y=n*h+l*a+s*o-i*u,this._z=s*h+l*u+i*a-n*o,this._w=l*h-i*o-n*a-s*u,this._onChangeCallback?.(),this}_onChange(t){return this._onChangeCallback=t,this}},Pt=class el{constructor(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}identity(){let t=this.elements;return t.fill(0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,this}copy(t){return this.elements.set(t.elements),this}clone(){let t=new el;return t.copy(this),t}compose(t,r,i){return Tt(this.elements,[r.x,r.y,r.z,r.w],[t.x,t.y,t.z],[i.x,i.y,i.z]),this}multiply(t){return this.multiplyMatrices(this,t)}multiplyMatrices(t,r){return Ie(this.elements,t.elements,r.elements),this}lookAt(t,r,i){return Jt(this.elements,[t.x,t.y,t.z],[r.x,r.y,r.z],[i.x,i.y,i.z]),this}makeRotationFromQuaternion(t){let r=new ge(0,0,0),i=new ge(1,1,1);return this.compose(r,t,i)}makeTranslation(t,r,i){return this.identity(),this.elements[12]=Number(t),this.elements[13]=Number(r),this.elements[14]=Number(i),this}makeScale(t,r,i){return this.identity(),this.elements[0]=Number(t),this.elements[5]=Number(r),this.elements[10]=Number(i),this}},xr=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 Xe(this.elements,e.elements),this}},Qe=e=>e<=.04045?e/12.92:((e+.055)/1.055)**2.4,hr=e=>e<=.0031308?e*12.92:1.055*e**(1/2.4)-.055,vs={black:0,white:16777215,red:16711680,green:32768,lime:65280,blue:255,yellow:16776960,cyan:65535,aqua:65535,magenta:16711935,fuchsia:16711935,gray:8421504,grey:8421504,silver:12632256,orange:16753920,purple:8388736,pink:16761035,gold:16766720},ut=class tl{constructor(t,r,i){this.r=1,this.g=1,this.b=1,t!==void 0&&(r!==void 0&&i!==void 0?this.setRGB(t,r,i):this.set(t))}set(t){return typeof t=="number"?this.setHex(t):typeof t=="string"?this.setStyle(t):(t&&typeof t=="object"&&"r"in t&&(this.r=Number(t.r),this.g=Number(t.g),this.b=Number(t.b)),this)}setStyle(t){let r=t.trim().toLowerCase();if(r[0]==="#"){let i=r.slice(1);i.length===3||i.length===4?i=i[0]+i[0]+i[1]+i[1]+i[2]+i[2]:i.length===8&&(i=i.slice(0,6));let n=parseInt(i,16);i.length===6&&!Number.isNaN(n)&&this.setHex(n)}else if(r in vs)this.setHex(vs[r]);else if(r.startsWith("hsl")){let i=/^hsla?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);i&&i.length>=3&&this.setHSL((parseFloat(i[0])||0)/360,(parseFloat(i[1])||0)/100,(parseFloat(i[2])||0)/100)}else{let i=/^rgba?\(([^)]+)\)$/.exec(r)?.[1].trim().split(/[\s,/]+/);if(i&&i.length>=3){let n=s=>Qe(Math.max(0,Math.min(1,(parseFloat(s)||0)/(s.endsWith("%")?100:255))));this.setRGB(n(i[0]),n(i[1]),n(i[2]))}}return this}setHSL(t,r,i){if(t=((Number(t)||0)%1+1)%1,r=Math.max(0,Math.min(1,Number(r)||0)),i=Math.max(0,Math.min(1,Number(i)||0)),r===0){let o=Qe(i);return this.setRGB(o,o,o)}let n=i<=.5?i*(1+r):i+r-i*r,s=2*i-n,l=o=>(o<0&&(o+=1),o>1&&(o-=1),o<1/6?s+(n-s)*6*o:o<1/2?n:o<2/3?s+(n-s)*6*(2/3-o):s);return this.setRGB(Qe(l(t+1/3)),Qe(l(t)),Qe(l(t-1/3)))}lerp(t,r){return this.lerpColors(this,t,r)}lerpColors(t,r,i){let n=Number(i)||0;return this.setRGB(t.r+(r.r-t.r)*n,t.g+(r.g-t.g)*n,t.b+(r.b-t.b)*n)}multiplyScalar(t){let r=Number(t)||0;return this.setRGB(this.r*r,this.g*r,this.b*r)}setScalar(t){let r=Number(t)||0;return this.setRGB(r,r,r)}setHex(t){let r=Math.floor(t);return this.setRGB(Qe((r>>16&255)/255),Qe((r>>8&255)/255),Qe((r&255)/255))}setRGB(t,r,i){return this.r=Number(t),this.g=Number(r),this.b=Number(i),this}convertSRGBToLinear(){return this.setRGB(Qe(this.r),Qe(this.g),Qe(this.b))}convertLinearToSRGB(){return this.setRGB(hr(this.r),hr(this.g),hr(this.b))}getHex(){let t=r=>Math.round(hr(Math.max(0,Math.min(1,r)))*255);return t(this.r)<<16|t(this.g)<<8|t(this.b)}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}copy(t){return this.setRGB(t.r,t.g,t.b)}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}clone(){return new tl(this.r,this.g,this.b)}},_s={degToRad:e=>e*Math.PI/180,radToDeg:e=>e*180/Math.PI,clamp:(e,t,r)=>Math.max(t,Math.min(r,e)),lerp:(e,t,r)=>e+(t-e)*r,generateUUID:()=>Math.random().toString(36).substring(2,15),randFloat:(e,t)=>e+Math.random()*(t-e)},$e=class rl{constructor(t,r){if(this.needsUpdate=!1,typeof r!="number"||!Number.isInteger(r)||r<1||r>16)throw new Error(`SecurityError: BufferAttribute itemSize must be an integer in [1, 16]. Received: ${String(r)}`);Array.isArray(t)?this.array=new Float32Array(t):this.array=t,this.itemSize=r;let i=this.array?this.array.length:0;if(!Number.isFinite(i)||i<0)throw new Error(`SecurityError: BufferAttribute array has a non-finite length: ${String(i)}`);this.count=Math.floor(i/r)}getX(t){return this.array[t*this.itemSize]}getY(t){return this.array[t*this.itemSize+1]}getZ(t){return this.array[t*this.itemSize+2]}setX(t,r){return this.array[t*this.itemSize]=r,this.needsUpdate=!0,this}setY(t,r){return this.array[t*this.itemSize+1]=r,this.needsUpdate=!0,this}setZ(t,r){return this.array[t*this.itemSize+2]=r,this.needsUpdate=!0,this}setXYZ(t,r,i,n){let s=t*this.itemSize;return this.array[s]=r,this.array[s+1]=i,this.array[s+2]=n,this.needsUpdate=!0,this}setUsage(t){return this}clone(){let t=this.array?.constructor||Float32Array;return new rl(new t(this.array),this.itemSize)}},vr=class extends $e{constructor(e,t){super(e instanceof Float32Array||Array.isArray(e)?e:new Float32Array(e),t)}},Mr=class extends $e{constructor(e,t){super(e instanceof Uint16Array?e:new Uint16Array(e),t)}},Tr=class extends $e{constructor(e,t){super(e instanceof Uint32Array?e:new Uint32Array(e),t)}},Be=class il{constructor(){this.name="",this.attributes={},this.index=null,this.boundingBox=null}setAttribute(t,r){return this.attributes[t]=r,this}getAttribute(t){return this.attributes[t]}setIndex(t){if(t instanceof $e)this.index=t;else if(Array.isArray(t)){let r=0;for(let i of t)i>r&&(r=i);this.index=new $e(new(r>65535?Uint32Array:Uint16Array)(t),1)}else t&&t.buffer&&(this.index=new $e(t,1));return this}computeVertexNormals(){let t=this.attributes.position;if(!t)return this;let r=!1;if(typeof r=="function"){let a=r(t.array,this.index?.array);return this.setAttribute("normal",new $e(a,3)),this}let i=t.count,n=t.array,s=new Float32Array(i*3),l=this.index?.array,o=l?l.length:i;for(let a=0;a<o;a+=3){let u=(l?l[a]:a)*3,h=(l?l[a+1]:a+1)*3,m=(l?l[a+2]:a+2)*3,c=n[h],d=n[h+1],f=n[h+2],g=n[m]-c,x=n[m+1]-d,b=n[m+2]-f,v=n[u]-c,p=n[u+1]-d,y=n[u+2]-f,M=x*y-b*p,P=b*v-g*y,F=g*p-x*v;s[u]+=M,s[u+1]+=P,s[u+2]+=F,s[h]+=M,s[h+1]+=P,s[h+2]+=F,s[m]+=M,s[m+1]+=P,s[m+2]+=F}for(let a=0;a<i*3;a+=3){let u=s[a],h=s[a+1],m=s[a+2],c=Math.hypot(u,h,m)||1;s[a]=u/c,s[a+1]=h/c,s[a+2]=m/c}return this.setAttribute("normal",new $e(s,3)),this}setFromBuffers(t,r,i,n){this.setAttribute("position",new $e(t,3)),this.setAttribute("normal",new $e(r,3)),this.setAttribute("uv",new $e(i,2)),this.setIndex(n)}setFromPoints(t){let r=[];if(Array.isArray(t))for(let i of t)r.push(Number(i?.x)||0,Number(i?.y)||0,Number(i?.z)||0);return this.setAttribute("position",new $e(r,3))}computeBoundingBox(){let t=this.attributes.position,r=new ge(1/0,1/0,1/0),i=new ge(-1/0,-1/0,-1/0);if(t&&t.count>0)for(let n=0;n<t.count;n++){let s=t.getX(n),l=t.getY(n),o=t.getZ(n);s<r.x&&(r.x=s),l<r.y&&(r.y=l),o<r.z&&(r.z=o),s>i.x&&(i.x=s),l>i.y&&(i.y=l),o>i.z&&(i.z=o)}else r.set(0,0,0),i.set(0,0,0);return this.boundingBox={min:r,max:i},this.boundingBox}center(){let t=this.computeBoundingBox();return this.translate(-(t.min.x+t.max.x)*.5,-(t.min.y+t.max.y)*.5,-(t.min.z+t.max.z)*.5)}_xform(t,r){let i=this.attributes.position;if(i){let n=i.array;for(let s=0;s<n.length;s+=3)t(n,s);i.needsUpdate=!0,r&&this.computeVertexNormals(),this.computeBoundingBox()}return this}translate(t=0,r=0,i=0){return this._xform((n,s)=>{n[s]+=t,n[s+1]+=r,n[s+2]+=i})}scale(t=1,r=1,i=1){return this._xform((n,s)=>{n[s]*=t,n[s+1]*=r,n[s+2]*=i},!0)}_rot(t,r,i){let n=Math.cos(i),s=Math.sin(i);for(let l of[this.attributes.position,this.attributes.normal]){if(!l)continue;let o=l.array;for(let a=0;a<o.length;a+=3){let u=o[a+t],h=o[a+r];o[a+t]=u*n-h*s,o[a+r]=u*s+h*n}l.needsUpdate=!0}return this}rotateX(t){return this._rot(1,2,t)}rotateY(t){return this._rot(2,0,t)}rotateZ(t){return this._rot(0,1,t)}applyMatrix4(t){let r=this.attributes.position;if(r&&t?.elements){let i=new ge;for(let n=0;n<r.count;n++)i.set(r.getX(n),r.getY(n),r.getZ(n)).applyMatrix4(t),r.setXYZ(n,i.x,i.y,i.z);this.computeVertexNormals()}return this}clone(){let t=new il;t.name=this.name;for(let r of Object.keys(this.attributes))t.attributes[r]=this.attributes[r].clone();return this.index&&(t.index=this.index.clone()),t}dispose(){}},Cn=class extends Be{constructor(e=1,t=1,r=1){super();let i=e/2,n=t/2,s=r/2,l=[-i,-n,s,i,-n,s,i,n,s,-i,n,s,i,-n,-s,-i,-n,-s,-i,n,-s,i,n,-s,-i,n,s,i,n,s,i,n,-s,-i,n,-s,-i,-n,-s,i,-n,-s,i,-n,s,-i,-n,s,i,-n,s,i,-n,-s,i,n,-s,i,n,s,-i,-n,-s,-i,-n,s,-i,n,s,-i,n,-s],o=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0],a=[],u=[];for(let h=0;h<6;h++){let m=h*4;a.push(0,0,1,0,1,1,0,1),u.push(m,m+1,m+2,m,m+2,m+3)}this.setFromBuffers(l,o,a,u)}},Ar=class extends Be{constructor(e=1,t=1,r=1,i=1){super(),r=Math.max(1,Math.floor(r)),i=Math.max(1,Math.floor(i));let n=[],s=[],l=[],o=[];for(let a=0;a<=i;a++){let u=a/i;for(let h=0;h<=r;h++){let m=h/r;if(n.push((m-.5)*e,(.5-u)*t,0),s.push(0,0,1),l.push(m,1-u),a>0&&h>0){let c=(r+1)*a+h-1,d=c-(r+1);o.push(d,c,d+1,c,c+1,d+1)}}}this.setFromBuffers(n,s,l,o)}},wr=class extends Be{constructor(e=1,t=16,r=12,i=0,n=Math.PI*2,s=0,l=Math.PI){super(),t=Math.max(3,Math.floor(t)),r=Math.max(2,Math.floor(r));let o=[],a=[],u=[],h=[],m=Math.min(s+l,Math.PI);for(let c=0;c<=r;c++){let d=c/r,f=s+d*l;for(let g=0;g<=t;g++){let x=g/t,b=i+x*n,v=-Math.cos(b)*Math.sin(f),p=Math.cos(f),y=Math.sin(b)*Math.sin(f);if(o.push(e*v,e*p,e*y),a.push(v,p,y),u.push(x,1-d),c>0&&g>0){let M=(t+1)*c+g,P=M-(t+1),F=P-1,W=M-1;(c!==1||s>0)&&h.push(P,F,M),(c!==r||m<Math.PI)&&h.push(F,W,M)}}}this.setFromBuffers(o,a,u,h)}},Dn=class extends Be{constructor(e=1,t=1,r=1,i=16,n=1,s=!1,l=0,o=Math.PI*2){super(),i=Math.max(3,Math.floor(i)),n=Math.max(1,Math.floor(Number(n)||1));let a=[],u=[],h=[],m=[],c=r/2,d=(t-e)/(r||1),f=i+1;for(let x=0;x<=n;x++){let b=x/n,v=b*(t-e)+e,p=c-b*r;for(let y=0;y<=i;y++){let M=y/i,P=l+M*o,F=Math.sin(P),W=Math.cos(P),T=Math.hypot(F,d,W)||1;if(a.push(v*F,p,v*W),u.push(F/T,d/T,W/T),h.push(M,1-b),x<n&&y<i){let E=x*f+y,S=E+f;m.push(E,S,E+1,S,S+1,E+1)}}}let g=(x,b)=>{if(s||x<=0)return;let v=b*c,p=a.length/3;a.push(0,v,0),u.push(0,b,0),h.push(.5,.5);let y=p+1;for(let M=0;M<=i;M++){let P=l+M/i*o,F=Math.sin(P),W=Math.cos(P);a.push(x*F,v,x*W),u.push(0,b,0),h.push(W*.5+.5,.5+b*F*.5),M<i&&m.push(p,y+M+(b>0?0:1),y+M+(b>0?1:0))}};g(e,1),g(t,-1),this.setFromBuffers(a,u,h,m)}},Sr=class extends Dn{constructor(e=1,t=1,r=16,i=1,n=!1,s=0,l=Math.PI*2){super(0,e,t,r,i,n,s,l)}},Er=class extends Be{constructor(e=1,t=.4,r=12,i=48,n=Math.PI*2){super(),r=Math.max(3,Math.floor(r)),i=Math.max(3,Math.floor(i));let s=[],l=[],o=[],a=[];for(let u=0;u<=r;u++){let h=u/r*Math.PI*2,m=Math.cos(h),c=Math.sin(h);for(let d=0;d<=i;d++){let f=d/i*n,g=Math.cos(f),x=Math.sin(f);if(s.push((e+t*m)*g,(e+t*m)*x,t*c),l.push(m*g,m*x,c),o.push(d/i,u/r),u>0&&d>0){let b=(i+1)*u+d-1,v=b-(i+1);a.push(b,v,b+1,v,v+1,b+1)}}}this.setFromBuffers(s,l,o,a)}};function Ls(e,t,r,i,n){let s=Math.max(2,Math.min(256,Math.floor(Number(t)||64))),l=Math.max(3,Math.min(64,Math.floor(Number(r)||8))),o=Number(i)||.1,a=[],u=[],h=[],m=[],c=[],d=new ge,f=new ge,g=new ge;for(let b=0;b<=s;b++){let v=new ge;n(b/s,v),c.push(v)}let x=l+1;for(let b=0;b<=s;b++){let v=b/s,p=c[b];d.subVectors(c[Math.min(s,b+1)],c[Math.max(0,b-1)]).normalize(),b===0&&f.set(Math.abs(d.y)>.9?1:0,Math.abs(d.y)>.9?0:1,0),g.crossVectors(d,f).normalize(),f.crossVectors(g,d).normalize();for(let y=0;y<=l;y++){let M=y/l*Math.PI*2,P=-Math.cos(M),F=Math.sin(M),W=P*f.x+F*g.x,T=P*f.y+F*g.y,E=P*f.z+F*g.z;if(a.push(p.x+o*W,p.y+o*T,p.z+o*E),u.push(W,T,E),h.push(v,y/l),b>0&&y>0){let S=x*(b-1)+y-1,O=S+x;m.push(S,O,S+1,O,O+1,S+1)}}}e.setFromBuffers(a,u,h,m)}var Rr=class extends Be{constructor(e=1,t=.4,r=64,i=8,n=2,s=3){super(),r=Math.floor(r),i=Math.floor(i),Ls(this,r,i,t,(l,o)=>{let a=l*n*Math.PI*2,u=s/n*a,h=e*(2+Math.cos(u))*.5;o.set(h*Math.cos(a),h*Math.sin(a),e*Math.sin(u)*.5)})}},St=class{getPoint(e,t=new ge){return t}getPointAt(e,t=new ge){return this.getPoint(e,t)}getTangent(e,t=new ge){return t.subVectors(this.getPoint(Math.min(1,e+.001)),this.getPoint(Math.max(0,e-.001))).normalize()}getPoints(e=5){let t=Math.max(1,Math.min(512,Math.floor(Number(e)||5))),r=[];for(let i=0;i<=t;i++)r.push(this.getPoint(i/t));return r}getSpacedPoints(e=5){return this.getPoints(e)}},_r=class extends St{constructor(e=new ge,t=new ge){super(),this.v1=e,this.v2=t}getPoint(e,t=new ge){return t.lerpVectors(this.v1,this.v2,e)}},Lr=class extends St{constructor(e=new ge,t=new ge,r=new ge){super(),this.v0=e,this.v1=t,this.v2=r}getPoint(e,t=new ge){return t.lerpVectors(this.v0,this.v1,e).lerp(new ge().lerpVectors(this.v1,this.v2,e),e)}},Ir=class extends St{constructor(e=new ge,t=new ge,r=new ge,i=new ge){super(),this.v0=e,this.v1=t,this.v2=r,this.v3=i}getPoint(e,t=new ge){let r=new ge().lerpVectors(this.v0,this.v1,e),i=new ge().lerpVectors(this.v1,this.v2,e),n=new ge().lerpVectors(this.v2,this.v3,e);return t.lerpVectors(r.lerp(i,e),i.lerp(n,e),e)}},Cr=class extends St{constructor(e=[],t=!1){super(),this.points=Array.isArray(e)?e:[],this.closed=!!t}getPoint(e,t=new ge){let r=this.points,i=r.length;if(!i)return t.set(0,0,0);if(i===1)return t.copy(r[0]);let n=(this.closed?i:i-1)*Math.max(0,Math.min(1,Number(e)||0)),s=Math.floor(n),l=n-s;!this.closed&&s>=i-1&&(s=i-2,l=1);let o=g=>r[this.closed?(g%i+i)%i:Math.max(0,Math.min(i-1,g))],a=o(s-1),u=o(s),h=o(s+1),m=o(s+2),c=l*l,d=c*l,f=(g,x,b,v)=>.5*(2*x+(b-g)*l+(2*g-5*x+4*b-v)*c+(3*x-g-3*b+v)*d);return t.set(f(a.x,u.x,h.x,m.x),f(a.y,u.y,h.y,m.y),f(a.z,u.z,h.z,m.z))}},Pn=class extends Be{constructor(e=[new rt(0,-.5),new rt(.5,0),new rt(0,.5)],t=12,r=0,i=Math.PI*2){super();let n=Array.isArray(e)&&e.length>=2?e:[new rt(.2,0),new rt(.2,.5)],s=Math.max(3,Math.min(128,Math.floor(Number(t)||12))),l=[],o=[],a=[],u=[],h=n.length;for(let m=0;m<=s;m++){let c=m/s,d=r+c*i,f=Math.sin(d),g=Math.cos(d),x=m*h;for(let b=0;b<h;b++){let v=n[b],p=Number(v?.x)||0,y=Number(v?.y)||0;l.push(p*f,y,p*g);let M=n[Math.max(0,b-1)],P=n[Math.min(h-1,b+1)],F=(Number(P?.x)||0)-(Number(M?.x)||0),W=(Number(P?.y)||0)-(Number(M?.y)||0),T=Math.hypot(W,F)||1;if(o.push(W/T*f,-F/T,W/T*g),a.push(c,b/(h-1)),m<s&&b<h-1){let E=x+b,S=E+h;u.push(E,S,E+1,S,S+1,E+1)}}}this.setFromBuffers(l,o,a,u)}},Dr=class extends Be{constructor(e,t=64,r=1,i=8,n=!1){super(),Ls(this,t,i,r,(s,l)=>{let o=e?.getPointAt??e?.getPoint;if(typeof o=="function"){let a=o.call(e,s,l);a&&a!==l&&l.copy(a)}else l.set(0,s,0)})}},pr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",an=class{constructor(e=""){this.isTexture=!0,this.wrapS=10497,this.wrapT=10497,this.repeat=new rt(1,1),this.offset=new rt(0,0),this.image=null,this.width=0,this.height=0,this.source=e,e&&typeof e=="object"&&(this.image=e)}dispose(){}},Pr=class extends an{constructor(e=null,t=1,r=1,i=1023,n=1009,s,l=1001,o=1001,a=1003,u=1003,h=1,m=""){super(""),this.isDataTexture=!0,this.avgColor=[1,1,1,1],this.flipY=!1,this.generateMipmaps=!1,this.unpackAlignment=1,this._sig=0;let c=Number(t),d=Number(r),f=e&&typeof e.length=="number"?e:null;this.width=c,this.height=d,this.image={data:f,width:c,height:d},this.format=Number(i)||1023,this.type=Number(n)||1009,this.wrapS=Number(l)||1001,this.wrapT=Number(o)||1001,this.magFilter=Number(a)||1003,this.minFilter=Number(u)||1003,this.colorSpace=m||"",this._bake()}get needsUpdate(){return!1}set needsUpdate(e){e&&this._bake()}_bake(){let e=this.image,t=e?.data,r=Number(e?.width??this.width),i=Number(e?.height??this.height);if(!t||!t.length||!(r>0&&i>0)||r>2048||i>2048){this.source="";return}let n=Math.max(1,r|0),s=Math.max(1,i|0),l=n*s,o=this.format,a=o===1021||o===1024||o===1028||t.length===l?1:o===1025||o===1030||t.length===l*2?2:o===1022||t.length===l*3?3:4,u=this.type===1015||this.type===1016||t instanceof Float32Array||t instanceof Float64Array,h=Math.min(n,48),m=Math.min(s,48),c=(this.flipY?257:1)^this.colorSpace.length^t.length,d=Math.max(1,t.length>>6|0);for(let O=0;O<t.length;O+=d)c=Math.imul(c^(t[O]*256|0),16777619)|0;if(c===this._sig&&this.source)return;this._sig=c;let f=m*(1+h*4),g=new Uint8Array(68+f),x=new DataView(g.buffer);x.setUint32(0,2303741511),x.setUint32(4,218765834),x.setUint32(8,13),x.setUint32(12,1229472850),x.setUint32(16,h),x.setUint32(20,m),g[24]=8,g[25]=6,x.setUint32(29,An(g.subarray(12,29))),x.setUint32(33,f+11),x.setUint32(37,1229209940),g[41]=120,g[42]=1,g[43]=1,x.setUint16(44,f,!0),x.setUint16(46,~f&65535,!0);let b=48,v=1,p=0,y=0,M=0,P=0,F=0,W=O=>{if(!Number.isFinite(O))return 0;let k=u&&O<=1?O*255:O;return k>0?k<255?k+.5|0:255:0};for(let O=0;O<m;O++){let k=O*s/m|0,w=this.flipY?s-1-k:k;g[b++]=0,p+=v;for(let ie=0;ie<h;ie++){let oe=(w*n+(ie*n/h|0))*a,I=o===1021?255:W(t[oe]??0),H=a>=3||o===1030?W(t[oe+1]??0):I,N=a>=3?W(t[oe+2]??0):o===1030?0:I,z=a===4?W(t[oe+3]??255):o===1021?W(t[oe]??255):o===1025?W(t[oe+1]??255):255;g[b++]=I,v+=I,p+=v,g[b++]=H,v+=H,p+=v,g[b++]=N,v+=N,p+=v,g[b++]=z,v+=z,p+=v,y+=I,M+=H,P+=N,F+=z}v%=65521,p%=65521}x.setUint32(b,(p<<16|v)>>>0),x.setUint32(b+4,An(g.subarray(37,b+4))),x.setUint32(b+12,1229278788),x.setUint32(b+16,2923585666);let T=h*m*255,E=this.colorSpace==="srgb-linear";this.avgColor=[E?y/T:Qe(y/T),E?M/T:Qe(M/T),E?P/T:Qe(P/T),F/T];let S=["data:image/png;base64,"];for(let O=0;O<g.length;O+=3){let k=g[O]<<16|(g[O+1]??0)<<8|(g[O+2]??0);S.push(pr[k>>18&63]+pr[k>>12&63]+(O+1<g.length?pr[k>>6&63]:"=")+(O+2<g.length?pr[k&63]:"="))}this.source=S.join("")}},Nr=class{load(e,t){let r=new an(e);return t?.(r),r}};function Ye(e,t){return e!==void 0?Number(e):t}function zi(e,t){return e!==void 0?!!e:t}var et=class{constructor(e={}){this.name=e.name||"",this.color=new ut(e.color??16777215),this.emissive=new ut(e.emissive??0),this.emissiveIntensity=Ye(e.emissiveIntensity,1),this.roughness=Ye(e.roughness,.5),this.metalness=Ye(e.metalness,0),this.opacity=Ye(e.opacity,1),this.transparent=zi(e.transparent,!1),this.wireframe=zi(e.wireframe,!1),this.side=Ye(e.side,2),this.doubleSided=zi(e.doubleSided,!0),this.map=e.map||null;for(let t of["normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])e[t]&&(this[t]=e[t]);this.clearcoat=Ye(e.clearcoat,0),this.clearcoatRoughness=Ye(e.clearcoatRoughness,0),this.sheen=Ye(e.sheen,0),this.sheenColor=new ut(e.sheenColor??0),this.sheenRoughness=Ye(e.sheenRoughness,0),this.transmission=Ye(e.transmission,0),this.thickness=Ye(e.thickness,0),this.attenuationColor=new ut(e.attenuationColor??16777215),this.attenuationDistance=Ye(e.attenuationDistance,1/0),this.ior=Ye(e.ior,1.5),this.dispersion=Ye(e.dispersion,0),this.iridescence=Ye(e.iridescence,0),this.iridescenceIOR=Ye(e.iridescenceIOR,1.3)}dispose(){}},Bt=class extends et{},kr=class extends et{},Or=class extends et{},Ur=class extends et{},Fr=class extends et{},lt=class nl{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 ge,this.rotation=new In,this.quaternion=new sn,this.scale=new ge(1,1,1),this.matrix=new Pt,this.matrixWorld=new Pt,this.rotation._onChange(()=>{this.quaternion.setFromEuler(this.rotation,!1)}),this.quaternion._onChange(()=>{let t=this.quaternion,r=Math.atan2(2*(t.w*t.x+t.y*t.z),1-2*(t.x*t.x+t.y*t.y)),i=Math.asin(Math.max(-1,Math.min(1,2*(t.w*t.y-t.z*t.x)))),n=Math.atan2(2*(t.w*t.z+t.x*t.y),1-2*(t.y*t.y+t.z*t.z));this.rotation.set(r,i,n)})}add(...t){for(let r of t)r&&r instanceof nl&&(r.parent&&r.parent.remove(r),r.parent=this,this.children.push(r));return this}remove(...t){for(let r of t){let i=this.children.indexOf(r);i!==-1&&(r.parent=null,this.children.splice(i,1))}return this}traverse(t){let r=new Set,i=[this];for(;i.length>0;){let n=i.pop();if(!n||typeof n!="object"||r.has(n))continue;r.add(n),t(n);let s=n.children;if(Array.isArray(s))for(let l=s.length-1;l>=0;l--)i.push(s[l])}}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale)}updateMatrixWorld(t=!1){this.traverse(r=>{Is(r),(r.matrixAutoUpdate||t)&&r.updateMatrix?.(),r.parent&&r.parent.matrixWorld?r.matrixWorld?.multiplyMatrices(r.parent.matrixWorld,r.matrix):r.matrix&&r.matrixWorld?.copy(r.matrix)})}lookAt(t,r,i){let n=typeof t=="object"?t:new ge(t,r,i);this.target instanceof ge?this.target.copy(n):this.target?.position instanceof ge&&this.target.position.copy(n),this.updateMatrixWorld(!0);let s=new Pt;s.lookAt(this.position,n,new ge(0,1,0));let l=s.elements,o=l[0],a=l[4],u=l[8],h=l[1],m=l[5],c=l[9],d=l[2],f=l[6],g=l[10],x=o+m+g;if(x>0){let b=.5/Math.sqrt(x+1);this.quaternion.set((f-c)*b,(u-d)*b,(h-a)*b,.25/b)}}translateOnAxis(t,r){let i=t.clone().applyMatrix4(new Pt().makeRotationFromQuaternion(this.quaternion)).multiplyScalar(r);return this.position.add(i),this}translateX(t){return this.translateOnAxis(new ge(1,0,0),t)}translateY(t){return this.translateOnAxis(new ge(0,1,0),t)}translateZ(t){return this.translateOnAxis(new ge(0,0,1),t)}rotateX(t){return this.rotation.x+=t,this}rotateY(t){return this.rotation.y+=t,this}rotateZ(t){return this.rotation.z+=t,this}_chain(){let t=[];for(let r=this;r&&t.length<64;r=r.parent)t.push(r);return t}_syncWorld(){let t=this._chain();for(let r=t.length-1;r>=0;r--){let i=t[r];i.updateMatrix?.(),i.parent?.matrixWorld?i.matrixWorld.multiplyMatrices(i.parent.matrixWorld,i.matrix):i.matrixWorld?.copy(i.matrix)}return this.matrixWorld.elements}getWorldPosition(t=new ge){let r=this._syncWorld();return t.set(r[12],r[13],r[14])}getWorldScale(t=new ge){let r=this._syncWorld();return t.set(Math.hypot(r[0],r[1],r[2]),Math.hypot(r[4],r[5],r[6]),Math.hypot(r[8],r[9],r[10]))}getWorldDirection(t=new ge){let r=this._syncWorld();return t.set(r[8],r[9],r[10]).normalize()}getWorldQuaternion(t=new sn){let r=this._chain();t.set(0,0,0,1);for(let i=r.length-1;i>=0;i--)t.multiply(r[i].quaternion);return t}clone(t=!0){let r=this instanceof Nt?new this.constructor(this._sourceGeo||this.geometry,this.material):this instanceof gt?new gt(this.geometry,this.material):new this.constructor;r.name=this.name,r.position.copy(this.position),r.quaternion.copy(this.quaternion),r.scale.copy(this.scale),r.visible=this.visible,r.castShadow=this.castShadow,r.receiveShadow=this.receiveShadow;try{r.userData=JSON.parse(JSON.stringify(this.userData||{}))}catch{r.userData={...this.userData||{}}}if(t)for(let i of this.children)r.add(i.clone(!0));return r}},Vr=class extends lt{},gt=class extends lt{constructor(e,t){super(),this.isMesh=!0;let r=Array.isArray(t)?t[0]:t;this.geometry=e instanceof Be?e:e?(Gt("unsupported geometry","BoxGeometry"),new Cn(.5,.5,.5)):new Be,this.material=r instanceof et?r:r?(Gt("unsupported material","MeshStandardMaterial"),new Bt({color:13421772})):new Bt}};function Is(e){typeof e?._bakeAuthorGeometry=="function"&&e._bakeAuthorGeometry();let t=Ae().materializeDeclarativeGeometry;typeof t=="function"&&t(e)}var Nn=1e4,kn=class extends gt{constructor(e,t,r=1){super(e,t),this.instanceColor=null,this.isInstancedMesh=!0;let i=Number(r);if(!Number.isFinite(i)||i<0||i>Nn)throw new RangeError(`SecurityError: InstancedMesh count (${String(r)}) exceeds MAX_INSTANCES_PER_MESH (${Nn})`);this.count=Math.floor(i);let n=new Float32Array(this.count*16);for(let s=0;s<this.count;s++){let l=s*16;n[l]=1,n[l+5]=1,n[l+10]=1,n[l+15]=1}this.instanceMatrix=new $e(n,16)}setMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++){let l=Number(t.elements[s]);i[n+s]=Number.isFinite(l)?l:s%5===0?1:0}}getMatrixAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t||!t.elements)return;let i=this.instanceMatrix.array,n=r*16;if(!(n+16>i.length))for(let s=0;s<16;s++)t.elements[s]=i[n+s]}setColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<this.count*3){let s=new Float32Array(this.count*3);s.fill(1),this.instanceColor=new $e(s,3)}let i=this.instanceColor.array,n=r*3;i[n]=Number.isFinite(t.r)?t.r:1,i[n+1]=Number.isFinite(t.g)?t.g:1,i[n+2]=Number.isFinite(t.b)?t.b:1}getColorAt(e,t){let r=Math.floor(Number(e));if(!Number.isFinite(r)||r<0||r>=this.count||!t)return;if(!this.instanceColor||this.instanceColor.array.length<(r+1)*3){t.setRGB(1,1,1);return}let i=this.instanceColor.array,n=r*3;t.setRGB(i[n],i[n+1],i[n+2])}dispose(){}},zt=class extends lt{constructor(e=16777215,t=1){super(),this.color=new ut(e),this.intensity=Number(t),this.type="directional"}},On=class extends zt{constructor(e,t){super(e,t),this.type="ambient"}},Br=class extends zt{constructor(e,t){super(e,t),this.target=new lt,this.type="directional"}},Un=class extends zt{constructor(e,t,r=0,i=2){super(e,t),this.type="point",this.distance=r,this.decay=i}},Fn=class extends lt{},zr=class extends Fn{constructor(e=45,t=1,r=.1,i=1e3){super(),this.target=new ge(0,0,0),this.fov=Number(e),this.aspect=Number(t),this.near=Number(r),this.far=Number(i)}},Vn=class extends lt{constructor(){super(...arguments),this.background=null,this.environmentIntensity=1}toCanvas3D(){return yt.validate(this),rn(this)}toGLB(){return yt.validate(this),Tn(this)}toUSDZ(){return yt.validate(this),wn(this)}getMeshTransforms(){this.updateMatrixWorld(!0);let e=new Map,t=0;return this.traverse(r=>{if(r instanceof gt){let i=new Float32Array(r.matrixWorld.elements);e.set(t,i),r.name&&e.set(r.name,i),t++}}),e}},Gi=rn,Hi=Tn,Cs=wn,yt=class{static validate(e){let t=0,r=0,i=0,n=new Set,s=(o,a,u)=>{throw new Error(`SecurityError: Scene exceeds SECURITY_3D_MAX_${o} (${a}). Found: ${u}`)},l=(o,a)=>{if(!Number.isFinite(a))throw new Error(`SecurityError: Scene reports a non-finite ${o} count (${String(a)}), which cannot be bounds-checked.`);return a};e.traverse(o=>{if(Is(o),o instanceof gt||o.geometry?.attributes?.position?.count){if(i++,i>1e3&&s("MESHES",1e3,i),o instanceof kn){let u=l("instance",o.count);(u<0||u>Nn)&&s("INSTANCES",Nn,u)}let a=o.geometry;if(a){let u=0;if(a.attributes.position&&(u=l("vertex",a.attributes.position.count),t+=u,t>1e5&&s("VERTICES",1e5,t)),a.index){let h=l("index",a.index.count);r+=h,r>3e5&&s("INDICES",3e5,r);let m=a.index.array;if(m&&u>0){let c=Math.min(h,m.length);for(let d=0;d<c;d++){let f=m[d];if(!Number.isFinite(f)||f<0||f>=u)throw new Error(`SecurityError: Index buffer value (${String(f)}) out of vertex bounds [0, ${u}).`)}}}}if(o.material){let u=o.material;for(let h of["map","normalMap","roughnessMap","metalnessMap","emissiveMap","aoMap"])u[h]&&n.add(u[h])}}}),n.size>16&&s("TEXTURES",16,n.size);for(let o of n){let a=o,u=a.image,h=Number(u?.width??a.width??0)||0,m=Number(u?.height??a.height??0)||0;(!Number.isFinite(h)||!Number.isFinite(m)||h>2048||m>2048)&&s("TEXTURE_DIMENSION",2048,Math.max(h,m))}}},Gr=class{constructor(e={}){this.shadowMap={enabled:!1,type:0},this.capabilities={isWebGL2:!0,maxTextures:16},this.boundViewer=null,this.hasInitialModelRendered=!1,this.domElement=e.canvas||(typeof document<"u"?document.createElement("canvas"):{}),e.viewer&&(this.boundViewer=e.viewer),e.container?.threeLiveViewer&&(this.boundViewer=e.container.threeLiveViewer),e.canvas?.parentElement?.threeLiveViewer&&(this.boundViewer=e.canvas.parentElement.threeLiveViewer);let t=typeof WorkerGlobalScope<"u"&&typeof self<"u"&&self instanceof WorkerGlobalScope;this.isSandboxed=e.isSandboxed||t,this.containerId=e.containerId||""}setSize(e,t){return this}setPixelRatio(e){return this}setClearColor(e,t=1){let r=new ut(e);return this.boundViewer&&typeof this.boundViewer.setClearColor=="function"&&this.boundViewer.setClearColor(r.r,r.g,r.b,t),this}clear(){return this}dispose(){}render(e,t){if(this.isSandboxed){yt.validate(e);let i=(n,s)=>{typeof self<"u"&&typeof self.postMessage=="function"&&(s&&s.length?self.postMessage(n,s):self.postMessage(n))};if(this.hasInitialModelRendered){let n=e.getMeshTransforms(),s={};for(let[l,o]of n.entries())s[l]=Array.from(o);i({type:"3D_UPDATE_TRANSFORMS",containerId:this.containerId,transforms:s})}else{this.hasInitialModelRendered=!0;let n=Gi(e),s=Hi(e),l=(n.lights||[]).map(o=>({type:o.type,color:o.color,intensity:o.intensity,position:o.position}));i({type:"3D_MODEL_READY",containerId:this.containerId,glbBuffer:s.buffer,dynamicLights:l,camera:t?{fov:t.fov||60,position:[t.position.x,t.position.y,t.position.z]}:void 0},[s.buffer])}return}let r=this.boundViewer;!r&&this.domElement?.parentElement&&this.domElement.parentElement.threeLiveViewer&&(r=this.domElement.parentElement.threeLiveViewer,this.boundViewer=r),!r&&typeof window<"u"&&(r=window.__three_live_active_viewer__,this.boundViewer=r),r&&typeof r.loadModel=="function"&&(r._hasThreeLiveModelLoaded?typeof r.updateMeshTransforms=="function"&&r.updateMeshTransforms(e.getMeshTransforms()):(r.loadModel(e.toCanvas3D()),r._hasThreeLiveModelLoaded=!0))}};function Ms(){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 Hr=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=Ms(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let e=0;if(this.autoStart&&!this.running&&this.start(),this.running){let t=Ms();e=(t-this.oldTime)/1e3,this.oldTime=t,this.elapsedTime+=e}return e}};function gc(){}var _n=new Proxy(gc,{get:(e,t)=>{if(t==="isProxy")return!0;if(!(t==="constructor"||t==="__proto__"||t==="prototype"))return t==="domElement"?typeof document<"u"?document.createElement("canvas"):{}:t==="shadowMap"?{enabled:!1,type:0}:t==="capabilities"?{isWebGL2:!0,maxTextures:16}:t===Symbol.toPrimitive?()=>0:_n},getPrototypeOf:()=>null,setPrototypeOf:()=>!1,apply:()=>_n,construct:()=>_n}),Ts=(()=>{try{if(typeof document>"u")return null;let e=document.currentScript;return e?.src?e.src:e?.textContent&&typeof Blob<"u"&&typeof URL<"u"&&typeof URL.createObjectURL=="function"?URL.createObjectURL(new Blob([e.textContent],{type:"text/javascript"})):null}catch{return null}})();function ii(){return typeof document<"u"&&document.baseURI?document.baseURI:typeof location<"u"&&location.href?location.href:"https://localhost/"}function cn(e,t){if(!e||typeof e!="string")return!1;let r=e.trim();if(!r)return!1;try{let i=new URL(r,ii());return!(i.protocol!=="https:"&&i.protocol!=="http:"&&i.protocol!=="blob:"||t?.requireSameOrigin&&i.protocol!=="blob:"&&typeof location<"u"&&location.origin&&location.origin!=="null"&&i.origin!==location.origin)}catch{return!1}}var As,Rn;function Ds(e){if(!cn(e))throw new Error(`SecurityError: Refusing to create TrustedScriptURL for disallowed URL "${e}".`);let t=globalThis.trustedTypes;if(!t||typeof t.createPolicy!="function")return e;if(Rn===void 0||As!==t){As=t;try{Rn=t.createPolicy("three-live#worker",{createScriptURL:r=>{if(!cn(r))throw new TypeError(`SecurityError: Disallowed Three-Live worker script URL "${r}".`);return r}})}catch{Rn=null}}return Rn?Rn.createScriptURL(e):e}function xc(e){Ae().sandboxEngineSrc=e}function Xi(){let e=Ae().sandboxEngineSrc;if(e)return e;if(Ts)return Ts;try{if(typeof document>"u")return null;let t=ii(),r=Array.from(document.querySelectorAll("script[src]"));for(let i of r){let n=i.src;if(!n)continue;let s=new URL(n,t).pathname;if(/(?:^|\/)(?:three|xr)-live[^/]*\.js$/.test(s)&&cn(n,{requireSameOrigin:!0}))return n}}catch{}return null}function $i(e,t){if(!cn(e))throw new Error(`SecurityError: Refusing to load ${t} from disallowed URL "${e}". Only http:, https:, and blob: URLs are permitted.`);return new URL(e,ii()).href}function vc(){let e=Xi();if(!e)throw new Error("Three-Live could not locate its own bundle URL, which the worker sandbox needs in order to load the THREE runtime. Set it explicitly, e.g. ThreeLiveElement.sandboxEngineSrc = new URL('three-live.min.js', import.meta.url).href. Refusing to execute the script, because unsandboxed host-realm execution is prohibited.");return $i(e,"sandbox engine")}function Mc(e){Ae().sandboxIframeSrc=e}function Ps(){let e=Ae().sandboxIframeSrc;if(e)return e;let t=Xi();if(!t||!cn(t))return null;let r=new URL(t,ii());return r.protocol==="blob:"?null:new URL("three-live-sandbox.html",r).href}function Tc(){let e=Ps();if(!e)throw new Error("Three-Live could not locate three-live-sandbox.html for iframe sandbox execution. Set ThreeLiveElement.sandboxIframeSrc (or ThreeLiveElement.sandboxEngineSrc) explicitly.");return $i(e,"sandbox iframe")}function Ac(e){Ae().allowClientScripts=e}function Ns(){return!!Ae().allowClientScripts}function wc(e){return $i(e,"procedural scene script")}var Sc=["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 Ec(e,t){let r=self,i=e.nonce,n=e.engineSrc,s=e.allowedScriptUrl,l=e.allowClientScripts,o=e.revoked,a=r.postMessage.bind(r);function u(p){a({type:"ERROR",nonce:i,message:String(p)})}let h=typeof r.importScripts=="function"?r.importScripts.bind(r):null,m=s,c=null;try{let p=n;if(typeof r.trustedTypes<"u"&&r.trustedTypes&&typeof r.trustedTypes.createPolicy=="function")try{let y={createScriptURL:function(P){if(P!==n&&(!s||P!==s))throw new TypeError("Disallowed worker importScripts URL");return P}};l&&(y.createScript=function(P){return String(P)});let M=r.trustedTypes.createPolicy("three-live#worker-boot",y);p=M.createScriptURL(n),s&&(m=M.createScriptURL(s)),l&&typeof M.createScript=="function"&&(c=M.createScript.bind(M))}catch{}h(p)}catch(p){u('Sandbox failed to load the Three-Live engine from "'+n+'". It must be a same-origin (or CORS-enabled) IIFE bundle such as three-live.min.js. Underlying error: '+(p&&p.message||p));return}let d=r.THREE;if(!d||typeof d.Scene!="function"){u('Sandbox loaded "'+n+'" but it did not install a THREE namespace. Point sandboxEngineSrc at an IIFE build (three-live.min.js), not an ES module build.');return}if(Array.isArray(t)){let p=r.__THREE_LIVE_REGISTRY__;for(let y=0;y<t.length;y++)if(typeof t[y]=="function")try{t[y](d,p)}catch{}}function f(p,y,M){let P=r;for(;P&&P!==Object.prototype;){if(!M&&P!==r)try{delete P[p]}catch{}if(!M||P===r||Object.prototype.hasOwnProperty.call(P,p))try{Object.defineProperty(P,p,M?{value:y,writable:!1,configurable:!1}:{value:y,writable:!1,configurable:!1,enumerable:!1})}catch{}try{P=Object.getPrototypeOf(P)}catch{break}}}for(let p=0;p<o.length;p++)f(o[p],void 0);f("performance",Object.freeze({now:function(){return Date.now()}}));let g=["3D_MODEL_READY","3D_UPDATE_TRANSFORMS"],x=!1;function b(p,y){if(p.type==="3D_MODEL_READY"){if(x)return;x=!0}p.nonce=i,y&&y.length?a(p,y):a(p)}f("postMessage",function(p,y){if(!p||g.indexOf(p.type)===-1)throw new Error("Sandboxed scripts may only post Three-Live scene messages ("+g.join(", ")+").");b(p,y)},!0);let v=!1;r.onmessage=function(p){let y=p&&p.data;if(!(!y||y.nonce!==i)&&!(y.type!=="EXECUTE"&&y.type!=="EXECUTE_URL")&&!v){v=!0;try{let M=new d.Scene,P=new d.PerspectiveCamera(60,1,.1,1e3),F=new d.WebGLRenderer({isSandboxed:!0});if(y.type==="EXECUTE_URL"){if(!s||y.scriptUrl!==s||typeof h!="function"){u("SecurityError: Refusing to execute unapproved script URL inside sandbox worker.");return}let W=m||s,T=h;if(h=null,m=null,r.THREE=d,r.scene=M,r.camera=P,r.renderer=F,T(W),typeof r.__THREE_LIVE_SCENE__=="function"){let E=r.__THREE_LIVE_SCENE__(d,M,P,F);E&&typeof E.toGLB=="function"&&(M=E)}else r.scene&&typeof r.scene.toGLB=="function"&&(M=r.scene)}else{if(!l){u("SecurityError: Client-modified script compilation (Use Case 1) is disabled in this sandbox worker.");return}let W=c?(0,eval)(c(`(function (THREE, scene, camera, renderer) {
343
370
  return (function () {
344
371
  `+y.script+`
345
372
  ;
@@ -349,18 +376,18 @@ return typeof scene === "object" && scene ? scene : undefined;
349
376
  `+y.script+`
350
377
  ;
351
378
  return typeof scene === "object" && scene ? scene : undefined;
352
- })();`);f=null;let P=X(p,M,T,V);P&&typeof P.toGLB=="function"&&(M=P)}if(!x){p.SceneQuotaValidator&&p.SceneQuotaValidator.validate(M);let X=M.toGLB(),P=X instanceof ArrayBuffer?X:X.buffer.slice(X.byteOffset,X.byteOffset+X.byteLength);b({type:"3D_MODEL_READY",glbBuffer:P},[P])}a({type:"DONE",nonce:i})}catch(M){u(M&&M.message||M)}}},a({type:"READY",nonce:i})}function Wi(e,t,r){let i=r?.allowedScriptUrl??null,n=r?.allowClientScripts??i===null,s={nonce:t,engineSrc:e,allowedScriptUrl:i,allowClientScripts:n,revoked:Cc},l=(Me().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${Dc.toString()})(${JSON.stringify(s)},[${l}]);`}function Hs(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var kt=0;function Xs(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Pc(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var Nc=1024,kc=256;function Ds(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let r=e[t];if(typeof r!="number"||!Number.isFinite(r))return!1}return!0}function ji(e,t){if(!e||typeof e!="object")return null;let r=e;if(r.nonce!==t)return null;switch(r.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof r.message=="string"?r.message:String(r.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,Nc)};case"3D_UPDATE_TRANSFORMS":{let i=r.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let n of i)if(!Ds(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let n=Object.keys(i);if(n.length>1e3)return null;let s=Object.create(null),l=i;for(let o of n){if(o.length>kc||o==="__proto__"||o==="constructor"||o==="prototype")return null;let a=l[o];if(!Ds(a))return null;s[o]=a}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=r.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Oc(e){let t=Pc(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function $s(e,t,r,i){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(i.modelDispatched)return;i.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":r();return;case"ERROR":r(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Uc(e,t,r,i){let n=Xs(),s=Wi(t,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l=document.createElement("iframe");l.setAttribute("sandbox","allow-scripts"),l.setAttribute("aria-hidden","true"),l.tabIndex=-1,l.style.display="none",l.src=r,kt++;let o=!1,a=!1,u={modelDispatched:!1},h,c=()=>{if(o||a)return;let g=l.contentWindow;!g||typeof g.postMessage!="function"||(a=!0,g.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:e.script},"*"))},f=()=>{},p=g=>{if(o||!l.contentWindow||g.source!==l.contentWindow)return;let x=g.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){c();return}let b=ji(x,n);b&&$s(b,i,f,u)};f=()=>{o||(o=!0,h!==void 0&&clearTimeout(h),kt=Math.max(0,kt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",p),typeof l.remove=="function"?l.remove():l.parentNode&&l.parentNode.removeChild(l))},h=setTimeout(()=>{o||(f(),Hs(i))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",p),l.onload=()=>{c()},l.onerror=()=>{f(),i.onError?.(new Error(`Sandbox iframe failed to load "${r}". Verify that three-live-sandbox.html is served at that URL.`))};let m=document.body||document.documentElement;if(!m||typeof m.appendChild!="function"){f();let g=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw i.onError?.(g),g}return m.appendChild(l),{terminate:f}}function Ps(e,t,r,i){if(t==="worker"&&typeof Worker>"u")return i("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return i("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(kt>=32)return i(`SecurityError: ${kt} sandbox workers are already running, which meets SECURITY_3D_MAX_CONCURRENT_TASKS (32). Refusing to start another.`,"Security Error: too many concurrent sandboxed scripts.");let n;try{n=Ec()}catch(f){let p=f instanceof Error?f.message:String(f);return i(p,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let f;try{f=_c()}catch(p){let m=p instanceof Error?p.message:String(p);return i(m,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Uc(e,n,f,r))}catch(p){return Promise.reject(p)}}let s=Xs(),l=Wi(n,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let f=new Blob([l],{type:"application/javascript"}),p=URL.createObjectURL(f);try{let m=Bs(p);o=new Worker(m)}finally{URL.revokeObjectURL(p)}}catch(f){let p=f instanceof Error?f.message:String(f);return i(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${p}`,"Security Error: Failed to start Worker sandbox.")}kt++;let a=!1,u={modelDispatched:!1},h,c=()=>{a||(a=!0,h!==void 0&&clearTimeout(h),kt=Math.max(0,kt-1),o.terminate())};return h=setTimeout(()=>{a||(c(),Hs(r))},3e3),o.onmessage=f=>{let p=ji(f.data,s);p&&$s(p,r,c,u)},o.onerror=f=>{c(),r.onError?.(new Error(`Worker execution error: ${f.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:s}):o.postMessage({type:"EXECUTE",script:e.script,nonce:s}),Promise.resolve({terminate:c})}function Ns(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var ks=e=>(t,r)=>{let i=new Error(t);return e.onError?.(i),r&&e.onToast?.(r),Promise.reject(i)},ln={execute(e,t,r,i){let n=ks(r),s=Ns(t,n);if(s)return s;try{Oc(e)}catch(l){let o=l instanceof Error?l.message:String(l);return n(o,"Security Error: script exceeds the size limit.")}return i?.allowClientScripts??Gs()?Ps({kind:"script",script:e},t,r,n):n(Zn,Qn)},executeUrl(e,t,r){let i=ks(r),n=Ns(t,i);if(n)return n;let s;try{s=Ic(e)}catch(l){let o=l instanceof Error?l.message:String(l);return i(o,"Security Error: disallowed scene script URL.")}return Ps({kind:"url",scriptUrl:s},t,r,i)}},zr=new Set;function Ht(e,t){let r=`[three-live] ${e} is unsupported; degraded to ${t}.`;zr.has(r)||(zr.add(r),typeof console<"u"&&typeof console.warn=="function"&&console.warn(r))}function Ws(){return Array.from(zr)}function js(){zr.clear()}var Vn=class extends zt{constructor(e={}){Ht("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Ks=Vn,Tt=class extends Fe{constructor(e=[],t=[],r=1,i=0){super();let n=Number(r)||1,s=Math.max(0,Math.min(7,Math.floor(Number(i)||0))),l=s+1,o=[],a=[],u=[],h=[],c=new ge,f=new ge,p=new ge,m=(b,v)=>v.set(e[b*3]||0,e[b*3+1]||0,e[b*3+2]||0),g=(b,v)=>{let d=b.clone().normalize();o.push(d.x*n,d.y*n,d.z*n),a.push(v.x,v.y,v.z),u.push(Math.atan2(d.z,-d.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,d.y)))/Math.PI)},x=(b,v,d)=>{let y=o.length/3,M=s===0?new ge().subVectors(d,v).cross(new ge().subVectors(b,v)).normalize():null;g(b,M||b.clone().normalize()),g(v,M||v.clone().normalize()),g(d,M||d.clone().normalize()),h.push(y,y+1,y+2)};for(let b=0;b<t.length;b+=3){m(t[b],c),m(t[b+1],f),m(t[b+2],p);let v=[];for(let d=0;d<=l;d++){v[d]=[];let y=c.clone().lerp(p,d/l),M=f.clone().lerp(p,d/l),T=l-d;for(let V=0;V<=T;V++)v[d][V]=T===0?y.clone():y.clone().lerp(M,V/T)}for(let d=0;d<l;d++)for(let y=0;y<2*(l-d)-1;y++){let M=y>>1;(y&1)===0?x(v[d][M+1],v[d+1][M],v[d][M]):x(v[d][M+1],v[d+1][M+1],v[d+1][M])}}this.setFromBuffers(o,a,u,h)}},Fc=Tt,Gr=class extends Tt{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},dr=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],qs=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],Hr=class extends Tt{constructor(e=1,t=0){super(dr,qs,e,t)}},ke=(1+Math.sqrt(5))/2,Xr=class extends Tt{constructor(e=1,t=0){super([-1,ke,0,1,ke,0,-1,-ke,0,1,-ke,0,0,-1,ke,0,1,ke,0,-1,-ke,0,1,-ke,ke,0,-1,ke,0,1,-ke,0,-1,-ke,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},tt=1/ke,$r=class extends Tt{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-tt,-ke,0,-tt,ke,0,tt,-ke,0,tt,ke,-tt,-ke,0,-tt,ke,0,tt,-ke,0,tt,ke,0,-ke,0,-tt,ke,0,-tt,-ke,0,tt,ke,0,tt],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},Wr=class extends Dn{constructor(e=1,t=1,r=4,i=8){let n=Math.max(1e-4,Number(e)||1),s=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,l=Math.max(2,Math.min(64,Math.floor(Number(r)||4))),o=[];for(let a=-1;a<=1;a+=2)for(let u=0;u<=l;u++){if(a>0&&u===0&&s===0)continue;let h=(a<0?u/l-1:u/l)*(Math.PI/2);o.push(new nt(Math.max(0,Math.cos(h)*n),a*s+Math.sin(h)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(i)||8))))}},Bn=class extends Fe{constructor(e=.5,t=1,r=32,i=1,n=0,s=Math.PI*2){super();let l=Math.max(1e-4,Number(t)||1),o=Number(e),a=Number.isFinite(o)?Math.max(0,o):l*.5,u=Math.max(l,a),h=Math.min(u*.999,Math.min(l,a)),c=Math.max(3,Math.min(256,Math.floor(Number(r)||32))),f=Math.max(1,Math.min(64,Math.floor(Number(i)||1))),p=Number.isFinite(Number(n))?Number(n):0,m=Number.isFinite(Number(s))?Number(s):Math.PI*2,g=[],x=[],b=[],v=[];for(let d=0;d<=f;d++){let y=h+d/f*(u-h);for(let M=0;M<=c;M++){let T=p+M/c*m,V=Math.cos(T),X=Math.sin(T);if(g.push(y*V,y*X,0),x.push(0,0,1),b.push(y/u*V*.5+.5,y/u*X*.5+.5),d<f&&M<c){let P=d*(c+1)+M,R=P+c+1;y>1e-6&&v.push(P,R,P+1),v.push(R,R+1,P+1)}}}this.setFromBuffers(g,x,b,v)}},jr=class extends Bn{constructor(e=1,t=32,r=0,i=Math.PI*2){super(0,e,t,1,r,i)}},zn=class extends Je{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},un=class extends Je{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},Kr=class extends un{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Ys(e,t){let r=e?.attributes?.position;if(!r?.array||r.count<3)return new Float32Array(0);let i=r.array,n=e?.index?.array,s=Math.min(8192,Math.floor((n?n.length:r.count)/3)),l=f=>`${Math.round((i[f*3]||0)*1e4)},${Math.round((i[f*3+1]||0)*1e4)},${Math.round((i[f*3+2]||0)*1e4)}`,o=t===void 0,a=o?1:Math.cos(t*Math.PI/180),u={},h=[],c=(f,p)=>h.push(i[f*3]||0,i[f*3+1]||0,i[f*3+2]||0,i[p*3]||0,i[p*3+1]||0,i[p*3+2]||0);for(let f=0;f<s;f++){let p=n?n[f*3]:f*3,m=n?n[f*3+1]:f*3+1,g=n?n[f*3+2]:f*3+2,x=i[p*3]||0,b=i[p*3+1]||0,v=i[p*3+2]||0,d=(i[m*3]||0)-x,y=(i[m*3+1]||0)-b,M=(i[m*3+2]||0)-v,T=(i[g*3]||0)-x,V=(i[g*3+1]||0)-b,X=(i[g*3+2]||0)-v,P=y*X-M*V,R=M*T-d*X,C=d*V-y*T,B=Math.hypot(P,R,C);if(!o&&B<1e-8)continue;B>0&&(P/=B,R/=B,C/=B);let N=[p,m,g];for(let w=0;w<3;w++){let ie=N[w],ae=N[(w+1)%3],k=l(ie),J=l(ae);if(k===J)continue;let z=k<J?`${k}|${J}`:`${J}|${k}`,Y=u[z];Y?Y.m||(Y.m=1,Y.nx*P+Y.ny*R+Y.nz*C<=a&&c(ie,ae)):(u[z]={va:ie,vb:ae,nx:P,ny:R,nz:C,m:o?1:0},o&&c(ie,ae))}}if(!o){let f=Object.keys(u);for(let p=0;p<f.length;p++){let m=u[f[p]];m&&!m.m&&c(m.va,m.vb)}}return new Float32Array(h)}var qr=class extends Fe{constructor(e){super(),this.setAttribute("position",new He(Ys(e),3)),this.__isSegmentPairs=!0}},Yr=class extends Fe{constructor(e,t=1){super();let r=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new He(Ys(e,r),3)),this.__isSegmentPairs=!0}};function Vc(e,t,r=1){let i=new Fe;i.__baked=!0;let n=e?.attributes?.position;if(!n?.array||n.count<2)return i;let s=n.array,l=e.index?.array,o=e.__isSegmentPairs?"segments":t,a=l?l.length:n.count,u=Math.min(4096,Math.max(0,o==="segments"?Math.floor(a/2):o==="loop"&&a>=3?a:a-1));if(u===0)return i;e.computeBoundingBox();let h=e.boundingBox,c=h&&h.max.distanceTo(h.min)||1,f=Math.max(.0015,Math.min(.025,c*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(r)||1))),p=[],m=[],g=[],x=[];for(let b=0;b<u;b++){let v=o==="segments"?b*2:b,d=o==="segments"?b*2+1:(b+1)%a,y=l?l[v]:v,M=l?l[d]:d,T=s[y*3]||0,V=s[y*3+1]||0,X=s[y*3+2]||0,P=(s[M*3]||0)-T,R=(s[M*3+1]||0)-V,C=(s[M*3+2]||0)-X,B=Math.hypot(P,R,C);if(B<1e-6)continue;let N=P/B,w=R/B,ie=C/B,ae=(Math.abs(w)<.9?Math.hypot(ie,N):Math.hypot(ie,w))||1,k=Math.abs(w)<.9?ie/ae:0,J=Math.abs(w)<.9?0:-ie/ae,z=Math.abs(w)<.9?-N/ae:w/ae,Y=w*z-ie*J,le=ie*k-N*z,ce=N*J-w*k,$=p.length/3,U=[[k,J,z],[Y,le,ce],[-k,-J,-z],[-Y,-le,-ce]];for(let _=0;_<2;_++){let H=T+_*P,D=V+_*R,F=X+_*C;for(let E=0;E<4;E++){let G=U[E];p.push(H+G[0]*f,D+G[1]*f,F+G[2]*f),m.push(G[0],G[1],G[2]),g.push(E/4,_)}}for(let _=0;_<4;_++){let H=(_+1)%4;x.push($+_,$+H,$+4+H,$+_,$+4+H,$+4+_)}}return p.length>0&&i.setFromBuffers(p,m,g,x),i}function Bc(e,t=.05){let r=new Fe;r.__baked=!0;let i=e?.attributes?.position;if(!i?.array||i.count<1)return r;let n=i.array,s=i.count,l=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),a=[],u=[],h=[],c=[];for(let f=0;f<l;f++){let p=s<=5e3?f:Math.floor(f*s/l),m=n[p*3]||0,g=n[p*3+1]||0,x=n[p*3+2]||0,b=f*6;for(let v=0;v<6;v++){let d=dr[v*3],y=dr[v*3+1],M=dr[v*3+2];a.push(m+d*o,g+y*o,x+M*o),u.push(d,y,M),h.push(.5,.5)}for(let v=0;v<24;v++)c.push(b+qs[v])}return r.setFromBuffers(a,u,h,c),r}var Ut=class extends mt{constructor(e,t,r="strip"){let i=t&&typeof t=="object"?t:{},n=t instanceof Je?t:r==="points"?new zn(i):new un(i),s=e instanceof Fe?e:new Fe;super(s,n),this.isLine=!0,this._lineMode=r,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let r=t.array,i=Math.min(t.count,64),n=0,s=0,l=0;for(let o=0;o<i;o++)n+=r[o*3]||0,s+=r[o*3+1]||0,l+=r[o*3+2]||0;this.material.color.setRGB(n/i,s/i,l/i)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Bc(this._sourceGeo,this.material?.size??.05):Vc(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},Zr=class extends Ut{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},Qr=class extends Ut{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},Jr=class extends Ut{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},ei=class extends On{constructor(e,t,r=0,i=Math.PI/3,n=0,s=2){super(e,t,r,s),this.target=new ot,this.type="spot";let l=Number(i);this.angle=Number.isFinite(l)?Math.max(.01,Math.min(Math.PI/2,l)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},Gn=class extends kn{constructor(e,t,r){Ht("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new it(t??4473924)}},Zs=Gn,Qs={Vector2:nt,Vector3:ge,Vector4:pr,Euler:_n,Quaternion:Ln,Matrix4:Ot,Matrix3:br,Color:it,MathUtils:Os,BufferAttribute:He,Float32BufferAttribute:yr,Uint16BufferAttribute:gr,Uint32BufferAttribute:xr,BufferGeometry:Fe,BoxGeometry:In,PlaneGeometry:vr,SphereGeometry:Mr,CylinderGeometry:Cn,ConeGeometry:Tr,TorusGeometry:Ar,TorusKnotGeometry:wr,Curve:Mt,Curve3:Mt,LineCurve3:Sr,QuadraticBezierCurve3:Er,CubicBezierCurve3:Rr,CatmullRomCurve3:_r,LatheGeometry:Dn,TubeGeometry:Lr,PolyhedronGeometry:Tt,IcosahedronGeometry:Xr,OctahedronGeometry:Hr,DodecahedronGeometry:$r,TetrahedronGeometry:Gr,CapsuleGeometry:Wr,RingGeometry:Bn,CircleGeometry:jr,WireframeGeometry:qr,EdgesGeometry:Yr,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:an,DataTexture:Ir,TextureLoader:Cr,Material:Je,MeshStandardMaterial:zt,MeshBasicMaterial:Dr,MeshLambertMaterial:Pr,MeshPhongMaterial:Nr,MeshPhysicalMaterial:kr,PointsMaterial:zn,LineBasicMaterial:un,LineDashedMaterial:Kr,ShaderMaterial:Vn,RawShaderMaterial:Ks,Object3D:ot,Group:Or,Mesh:mt,InstancedMesh:Nn,Line:Ut,LineLoop:Zr,LineSegments:Qr,Points:Jr,Light:Gt,AmbientLight:kn,DirectionalLight:Ur,PointLight:On,SpotLight:ei,HemisphereLight:Gn,RectAreaLight:Zs,Camera:Un,PerspectiveCamera:Fr,Scene:Fn,WebGLRenderer:Vr,Clock:Br,SceneQuotaValidator:lt,exportSceneToCanvas3D:Gi,exportSceneToGLB:Hi,exportSceneToUSDZ:Vs,generateUSDZ:wn,glbToUSDZ:An,sceneToCanvas3D:on,sceneToGLB:vn,sceneToUSDZ:Tn,authorScriptRunner:ln,getAuthorWarnings:Ws,clearAuthorWarnings:js};Object.freeze(lt),Object.freeze(lt.prototype),Object.freeze(Fn.prototype),Object.freeze(Qs);var Xt=new Proxy(Qs,{get:(e,t)=>{if(t in e)return e[t];let r=Me().authorNamespace;return r&&typeof t=="string"&&t in r?r[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Ht(`THREE.${t}`,"no-op proxy"),En)},has:(e,t)=>{if(t in e)return!0;let r=Me().authorNamespace;return!!(r&&typeof t=="string"&&t in r)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),hr=Me();if(hr.threeNamespace=Xt,hr.workerExtensionInstallers)for(let e of hr.workerExtensionInstallers)e(Xt,hr);var Rn={name:"three_author",THREE:Xt},zc=Rn,vt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof vt.THREE>"u"&&(vt.THREE=Xt),typeof vt.requestAnimationFrame!="function"&&(vt.requestAnimationFrame=e=>(typeof e=="function"&&typeof vt.__three_live_raf_cb__!="function"&&(vt.__three_live_raf_cb__=e),vt.__three_live_in_step__||Ht("requestAnimationFrame","single-frame static evaluation"),0)),typeof vt.cancelAnimationFrame!="function"&&(vt.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=Xt,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=Rn,e.ThreeLivePlugins.three_author=Rn,e.ThreeLivePlugins["three-author"]=Rn}function mn(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var Ki=(e,t,r)=>({x:e,y:t,z:r,toString:()=>`${e}m ${t}m ${r}m`}),Gc=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(e,t){super(e,t),this.detail=t?.detail??null}});var Xe=class Ze extends Gc{constructor(){super(...arguments),this.viewer=null,this.canvas=null,this.posterEl=null,this.arButton=null,this.currentModel=null,this.activeXRSession=null,this.toastTimer=null,this.currentModelLimits=void 0,this.isModelLoaded=!1,this.scriptHandle=null,this.loadController=null,this.resizeObserver=null,this.mutationObserver=null}static get arProvider(){return Me().arProvider}static set arProvider(t){Me().arProvider=t}static get scriptRunner(){return Me().scriptRunner}static set scriptRunner(t){Me().scriptRunner=t}static get sandboxEngineSrc(){return Me().sandboxEngineSrc??null}static set sandboxEngineSrc(t){Me().sandboxEngineSrc=t}static get sandboxIframeSrc(){return Me().sandboxIframeSrc??null}static set sandboxIframeSrc(t){Me().sandboxIframeSrc=t}static get allowClientScripts(){return!!Me().allowClientScripts}static set allowClientScripts(t){Me().allowClientScripts=t}static registerScriptRunner(t){Ze.scriptRunner=t}static registerDecoder(t,r){je.registerDecoder(t,r)}static getDecoder(t){return je.getDecoder(t)}static registerAR(t){typeof t=="function"?Ze.arProvider={activateAR:t}:Ze.arProvider=t,typeof document<"u"&&document.querySelectorAll("three-live").forEach(r=>{r instanceof Ze&&r.updateARButtonVisibility()})}static isARSupported(){return!!Ze.arProvider}getLoadedModel(){return this.currentModel}beginLoad(){let t=this.loadController,r=this.scriptHandle,i=new AbortController;return this.loadController=i,this.scriptHandle=null,t?.abort(),r?.terminate(),i}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let t=this.getAttribute("src"),r=this.getAttribute("script-src");if(t)this.loadModel(t).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of je.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let t of je.getRegisteredPlugins())t.onElementDisconnected?.(this);this.beginLoad().abort(),this.mutationObserver?.disconnect(),this.mutationObserver=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.activeXRSession?.stop?.().catch?.(()=>{}),this.activeXRSession=null,this.toastTimer&&clearTimeout(this.toastTimer),this.toastTimer=null,this.viewer?.destroy(),this.viewer=null,this.isModelLoaded=!1}attributeChangedCallback(t,r,i){if(r!==i){switch(t){case"src":i&&this.loadModel(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let n=parseFloat(i);isNaN(n)||this.viewer.setExposure(n)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer?.setToneMapping(Bt(i));break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let n=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(n),this.canvas&&(this.canvas.style.touchAction=n?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"variant-name":this.viewer&&this.selectVariant(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let n of je.getRegisteredPlugins())n.onAttributeChanged?.(this,t,r,i)}}getAttr(t){return this.getAttribute(t)}setAttr(t,r){r!==null?this.setAttribute(t,String(r)):this.removeAttribute(t)}getBoolAttr(t){return this.hasAttribute(t)&&this.getAttr(t)!=="false"}setBoolAttr(t,r){this.setAttr(t,r?"":null)}getFloatAttr(t,r){let i=this.getAttr(t);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(t){this.setAttr("src",t)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(t){this.setBoolAttr("camera-controls",t)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(t){this.setAttr("camera-orbit",t)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(t){this.setAttr("camera-target",t)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(t){this.setAttr("min-camera-orbit",t)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(t){this.setAttr("max-camera-orbit",t)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(t){this.setAttr("field-of-view",t)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(t){this.setAttr("ios-src",t)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(t){this.setAttr("script-src",t)}get sandbox(){return this.getAttr("sandbox")||(Me().sandboxIframeSrc?"iframe":"worker")}set sandbox(t){this.setAttr("sandbox",t)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||Ze.allowClientScripts}set allowClientScripts(t){this.setBoolAttr("allow-client-scripts",t)}get poster(){return this.getAttr("poster")}set poster(t){this.setAttr("poster",t)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(t){this.setAttr("selected-mesh",t)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(t){this.setAttr("exposure",t)}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(t){this.setBoolAttr("auto-rotate",t)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(t){this.setAttr("auto-rotate-delay",t)}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(t){this.setAttr("rotation-per-second",t)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(t){this.setBoolAttr("ar",t)}get arScale(){return this.getAttr("ar-scale")||"auto"}set arScale(t){this.setAttr("ar-scale",t)}get arPlacement(){return this.getAttr("ar-placement")||"floor"}set arPlacement(t){this.setAttr("ar-placement",t)}get canActivateAR(){return Ze.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(t){this.setAttr("shadow-intensity",t)}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(t){this.setAttr("shadow-softness",t)}get toneMapping(){return Bt(this.getAttr("tone-mapping"))}set toneMapping(t){this.setAttr("tone-mapping",t)}get bloom(){return this.getFloatAttr("bloom",0)}set bloom(t){this.setAttr("bloom",t)}get bloomThreshold(){return mn(this.getAttr("bloom-threshold"),.62)}set bloomThreshold(t){this.setAttr("bloom-threshold",t)}get bloomRadius(){return mn(this.getAttr("bloom-radius"),.75)}set bloomRadius(t){this.setAttr("bloom-radius",t)}get outlineSelected(){return this.getBoolAttr("outline-selected")}set outlineSelected(t){this.setBoolAttr("outline-selected",t)}get outlineColor(){return this.getAttr("outline-color")||"#38bdf8"}set outlineColor(t){this.setAttr("outline-color",t)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(t){this.setAttr("environment-image",t)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(t){this.setAttr("skybox-image",t)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(t){this.setBoolAttr("autoplay",t)}get animationName(){return this.getAttr("animation-name")}set animationName(t){this.setAttr("animation-name",t)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get variantName(){return this.viewer?this.viewer.getVariantName():this.getAttr("variant-name")}set variantName(t){this.setAttr("variant-name",t)}get availableVariants(){return this.viewer?this.viewer.getAvailableVariants():[]}fireEvent(t,r){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:r}))}setSlotVisible(t,r){let i=typeof this.querySelector=="function"?this.querySelector(`[slot="${t}"]`):null;i&&(i.hidden=!r,i.style&&(i.style.display=r?"":"none"))}emitError(t,r="script"){this.setSlotVisible("error",!0),this.fireEvent("error",{error:t}),this.fireEvent("three-error",{error:t,message:t?.message||String(t),stage:r})}selectVariant(t){if(!this.viewer)return!1;let r=this.viewer.selectVariant(t);return r&&this.fireEvent("variant-applied",{variantName:this.viewer.getVariantName()}),r}get model(){let t=this.viewer?this.viewer.getModelMaterials():[];return{materials:t,getMaterialByName(r){return t.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(t=0){this.viewer?.resetTurntableRotation(t)}setCamera(t,r,i,n){this.viewer&&this.viewer.setCamera(t,r,i,n)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():Ki(0,0,0)}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(t,r){return this.viewer?.render?.(),this.canvas?this.canvas.toDataURL(t,r):""}toBlob(t){return this.viewer?.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(n=>{n?r(n):i(new Error("Failed to capture canvas blob."))},t?.mimeType,t?.qualityArgument)})}positionAndNormalFromPoint(t,r){let i=this.viewer?.raycastFromScreenPoint(t,r);if(!i)return null;let[n,s,l]=i.hitPoint||i.point,[o,a,u]=i.normal;return{position:Ki(n,s,l),normal:Ki(o,a,u)}}loadModel(t){return this.loadModelWithLimits(t)}async loadModelWithLimits(t,r,i=this.beginLoad()){if(i.signal.throwIfAborted(),!this.viewer){this.currentModel=t,this.currentModelLimits=r;return}try{let n;if(typeof t=="string"){let a=await fetch(t,{signal:i.signal});if(!a.ok)throw new Error(`Failed to load "${t}": HTTP ${a.status}`);n=await a.arrayBuffer()}else n=t;i.signal.throwIfAborted();let s=gt(n);this.viewer.loadGLBData(s,r),this.currentModel=s,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.setSlotVisible("error",!1),this.updateHotspots();let l=this.getAttr("selected-mesh");l&&this.viewer.setSelectedMesh(l);let o=this.getAttr("variant-name");o&&this.selectVariant(o),this.fireEvent("load",{model:s}),this.fireEvent("three-load",{model:s,source:typeof t=="string"?"src":"model"})}catch(n){throw i.signal.aborted||this.emitError(n,"load"),n}}showToast(t,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=t,this.toastTimer&&clearTimeout(this.toastTimer);let n=()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")};typeof requestAnimationFrame<"u"?requestAnimationFrame(n):n(),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){this.activeXRSession?.isSessionActive?.()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null);let t=(n,s=n.message)=>{throw this.fireEvent("ar-status",{status:"failed",error:n}),this.showToast(s,6e3),n};this.currentModel||t(new Error("No 3D model is loaded in <three-live>.")),Ze.arProvider||t(new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR()."));let r=this.getAttr("ios-src"),i=(this.getAttr("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.fireEvent("ar-status",{status:"session-started"});let n=await Ze.arProvider.activateAR({model:r||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:i.length>0?i:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"not-presenting"})},onError:s=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"failed",error:s}),this.showToast(`AR error: ${s.message}`,6e3)}}});if(n.success){n.session&&(this.activeXRSession=n.session);let s=n.mode==="quick-look"?"Opening Apple AR Quick Look...":n.mode==="scene-viewer"?"Opening Google Scene Viewer...":n.mode==="webxr"?"WebXR AR session started.":"";s&&this.showToast(s)}else{let s=typeof navigator<"u"&&navigator.userAgent||"",l=/Macintosh/i.test(s)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1),o=/Android|iPhone|iPad|iPod/i.test(s),a=n.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.";if(l&&!o&&typeof document<"u"&&this.currentModel&&Ze.arProvider.createUSDZBlob)try{let u=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:Ze.arProvider.createUSDZBlob(this.currentModel),h=URL.createObjectURL(u),c=document.createElement("a");c.href=h,c.download="three_live_model.usdz",document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(h),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(a,6e3)}else this.showToast(a,6e3);n.error&&this.fireEvent("ar-status",{status:"failed",error:n.error})}return n}catch(n){return this.activeXRSession=null,t(n,`AR error: ${n.message||String(n)}`)}}setupDOM(){let t=this.querySelector("canvas");t||(t=document.createElement("canvas"),t.style.cssText=`width:100%;height:100%;display:block;touch-action:${this.cameraControls?"none":"auto"};outline:none`,this.appendChild(t)),this.canvas=t,typeof t.addEventListener=="function"&&!t.__tlCtxBound&&(t.__tlCtxBound=!0,t.addEventListener("webglcontextlost",i=>this.fireEvent("three-context-lost",{originalEvent:i})),t.addEventListener("webglcontextrestored",i=>this.fireEvent("three-context-restored",{originalEvent:i}))),this.setSlotVisible("error",!1),this.isModelLoaded||this.setSlotVisible("poster",!0);let r=this.getAttr("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let t=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),n=this.parseOrbitLimit(this.getAttr("max-camera-orbit")),s=this.parseCameraTarget(this.getAttr("camera-target")),l=this.parseFieldOfView(this.getAttr("field-of-view"));this.viewer=new je(this,this.canvas,{autoRotate:t,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttr("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,variantName:this.getAttr("variant-name")||void 0,fieldOfView:l,cameraTarget:s,minCameraOrbit:i,maxCameraOrbit:n,onMeshClick:a=>{this.fireEvent("meshclick",a)},onCameraChange:a=>{this.updateHotspots();for(let u of je.getRegisteredPlugins())u.onCameraChange?.(this.viewer,this);this.fireEvent("camera-change",a)}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let o=this.getAttr("camera-orbit");o&&this.applyCameraOrbit(o),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(t){if(!(typeof document>"u")){if(!t){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.alt="3D Scene Preview",this.posterEl.style.cssText="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:opacity .35s ease-out;pointer-events:none;z-index:1",this.appendChild(this.posterEl)),this.posterEl.src=t,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.setSlotVisible("poster",!1),this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let t=document.createElement("button");t.type="button",t.className="three-live-ar-button";for(let[n,s]of[["aria-label","View in Augmented Reality"],["part","default-ar-button"]])t.setAttribute(n,s);let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let n=document.createElementNS(r,"svg");for(let[l,o]of[["width","20"],["height","20"],["viewBox","0 0 24 24"],["fill","none"],["stroke","currentColor"],["stroke-width","2"],["stroke-linecap","round"],["stroke-linejoin","round"]])n.setAttribute(l,o);n.style.marginRight="6px";let s=document.createElementNS(r,"path");s.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16zM3.27 6.96 12 12.01l8.73-5.05M12 22.08V12"),n.appendChild(s),t.appendChild(n)}let i=document.createElement("span");i.textContent="View in AR",t.appendChild(i),t.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",t.addEventListener("mouseenter",()=>{t.style.backgroundColor="rgba(30, 41, 59, 0.95)",t.style.transform="scale(1.04)"}),t.addEventListener("mouseleave",()=>{t.style.backgroundColor="rgba(15, 23, 42, 0.85)",t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),this.activateAR()}),this.arButton=t,this.appendChild(t)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let t=this.hasAttribute("ar")&&!!Ze.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=t?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.arButton.style.display=t?"flex":"none")}applyCameraOrbit(t){if(!(!t||!this.viewer))try{let r=JSON.parse(t);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=this.parseOrbitLimit(t);(r.theta!==void 0||r.phi!==void 0)&&this.viewer.setInitialCamera(r.theta,r.phi,r.distance)}}parseOrbitLimit(t){if(!t)return{};let[r,i,n]=t.trim().split(/\s+/),s=n&&n!=="auto"?parseFloat(n):NaN;return{theta:r&&r!=="auto"?this.parseFieldOfView(r):void 0,phi:i&&i!=="auto"?this.parseFieldOfView(i):void 0,distance:isNaN(s)?void 0:s}}applyOrbitLimits(){if(!this.viewer)return;let t=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttr("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:t.theta,maxTheta:r.theta,minPhi:t.phi,maxPhi:r.phi,minDistance:t.distance,maxDistance:r.distance})}parseCameraTarget(t){if(!t)return;let r=t.trim().split(/\s+/).map(parseFloat);return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(t){if(!t)return;let r=parseFloat(t);return isNaN(r)?void 0:t.endsWith("rad")?r*180/Math.PI:r}parseRotationPerSecond(t){if(!t)return Math.PI/6;let r=t.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(t){let r=this.parseCameraTarget(t);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(t){let r=this.parseFieldOfView(t);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(t){let r=this.querySelector(`[slot="${t.name}"]`);r&&(t.position!==void 0&&r.setAttribute("data-position",t.position),t.normal!==void 0&&r.setAttribute("data-normal",t.normal)),this.updateHotspots()}updateHotspots(){for(let t of je.getRegisteredPlugins())if(t.updateHotspotsForElement){t.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(t){let r=Ze.scriptRunner;if(!r){let s=new Error('Script execution requires "three-live/full" or registerScriptRunner().');return this.showToast(s.message),this.emitError(s,"script"),Promise.reject(s)}let i=this.beginLoad(),n=()=>!i.signal.aborted;return new Promise((s,l)=>{let o=()=>l(i.signal.reason);if(i.signal.addEventListener("abort",o,{once:!0}),!n()){o();return}let a={onModelReady:u=>{this.loadModelWithLimits(u,hs,i).then(()=>s(u),l)},onUpdateTransforms:u=>{n()&&this.viewer?.updateMeshTransforms(u)},onError:u=>{n()&&(this.showToast(u.message),this.emitError(u,"script"),l(u))},onToast:u=>{n()&&this.showToast(u)}};t(r,a).then(u=>{n()?this.scriptHandle=u||null:u?.terminate()},u=>{n()&&a.onError?.(u)})})}loadScriptFromSrc(t){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let n=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(n),Promise.reject(n)}return r.executeUrl(t,this.sandbox,i)})}executeScript(t){if(!Ze.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Zn);return this.showToast(Qn),this.emitError(r,"security"),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(t,this.sandbox,i,{allowClientScripts:!0}))}};Xe.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","bloom","bloom-threshold","bloom-radius","outline","outline-selected","outline-color","environment-image","skybox-image","autoplay","animation-name","variant-name","auto-rotate","auto-rotate-delay","rotation-per-second"],Xe.registerPlugin=je.registerPlugin,Xe.getRegisteredPlugins=je.getRegisteredPlugins;var ft=Xe;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",ft);function Js(e,t,r){return t%4===0?new Float32Array(e,t,r):new Float32Array(e.slice(t,t+r*4))}function ni(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=r[0],u=r[1],h=r[2],c=r[3],f=n*a+s*u+l*h+o*c;if(f<0&&(a=-a,u=-u,h=-h,c=-c,f=-f),Math.abs(f)>=1)return e[0]=n,e[1]=s,e[2]=l,e[3]=o,e;let p=Math.acos(f),m=Math.sqrt(1-f*f);if(Math.abs(m)<.001)return e[0]=.5*(n+a),e[1]=.5*(s+u),e[2]=.5*(l+h),e[3]=.5*(o+c),e;let g=Math.sin((1-i)*p)/m,x=Math.sin(i*p)/m;return e[0]=n*g+a*x,e[1]=s*g+u*x,e[2]=l*g+h*x,e[3]=o*g+c*x,e}function ea(e,t,r,i){return e[0]=t[0]+i*(r[0]-t[0]),e[1]=t[1]+i*(r[1]-t[1]),e[2]=t[2]+i*(r[2]-t[2]),e}function Ji(e,t){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let n=e.animations[i],s=n.name||`Animation_${i}`,l=[],o=0;if(Array.isArray(n.channels)&&Array.isArray(n.samplers))for(let a of n.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let u=n.samplers[a.sampler];if(!u)continue;let h=e.accessors?.[u.input],c=e.accessors?.[u.output];if(!h||!c)continue;let f=e.bufferViews?.[h.bufferView],p=e.bufferViews?.[c.bufferView];if(!f||!p)continue;let m=(f.byteOffset||0)+(h.byteOffset||0),g=(p.byteOffset||0)+(c.byteOffset||0),x=ut(e,t,h,1)??Js(t,m,h.count);x.length>0&&x[x.length-1]>o&&(o=x[x.length-1]);let b=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(c.count/Math.max(1,h.count))):3,v=a.target.path==="weights"?1:b,d=ut(e,t,c,v)??Js(t,g,c.count*v),y=u.interpolation==="STEP"?"STEP":"LINEAR";l.push({nodeIndex:a.target.node,path:a.target.path,times:x,values:d,interpolation:y})}l.length>0&&r.push({name:s,duration:o,channels:l})}return r}function fn(e,t,r){let{times:i,values:n,path:s,interpolation:l}=e,o=i.length;if(o===0)return;let a=s==="rotation"?4:s==="weights"?Math.max(1,Math.round(n.length/o)):3;if(t<=i[0]){for(let v=0;v<a;v++)r[v]=n[v];return}if(t>=i[o-1]){let v=(o-1)*a;for(let d=0;d<a;d++)r[d]=n[v+d];return}let u=0,h=o-1;for(;u<=h;){let v=u+h>>1;i[v]<=t?u=v+1:h=v-1}let c=Math.max(0,h),f=Math.min(o-1,c+1);if(l==="STEP"||c===f){let v=c*a;for(let d=0;d<a;d++)r[d]=n[v+d];return}let p=i[c],m=i[f],g=(t-p)/Math.max(1e-5,m-p),x=c*a,b=f*a;if(s==="rotation"){let v=[n[x],n[x+1],n[x+2],n[x+3]],d=[n[b],n[b+1],n[b+2],n[b+3]];ni(r,v,d,g)}else for(let v=0;v<a;v++)r[v]=n[x+v]+g*(n[b+v]-n[x+v])}var Hn=new WeakMap;function eo(e,t,r=.3){if(!e?.animations)return;let i=e.animations.find(o=>o.name===t);if(!i)return;let n=Hn.get(e);n||(n=[],e.currentClip&&n.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Hn.set(e,n));let s=r>0?1/r:1e3;for(let o of n)o.clip.name!==t&&(o.fadeSpeed=-s);let l=n.find(o=>o.clip.name===t);l?l.fadeSpeed=s:n.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:s}),e.currentClip=i,e.isPlayingAnimation=!0}function Zi(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=Hn.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,n=[];for(let c=0;c<i;c++){let f=e.initialNodeTransforms[c];f?n.push({t:[f.t[0],f.t[1],f.t[2]],r:[f.r[0],f.r[1],f.r[2],f.r[3]],s:[f.s[0],f.s[1],f.s[2]]}):n.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let s=[0,0,0],l=[0,0,0,1],o=[1,1,1],a=new Float32Array(64);for(let c of r){let f=Math.max(0,Math.min(1,c.weight));if(!(f<=1e-4))for(let p of c.clip.channels){if(p.nodeIndex<0||p.nodeIndex>=i)continue;let m=n[p.nodeIndex];if(p.path==="translation")fn(p,c.time,s),ea(m.t,m.t,s,f);else if(p.path==="rotation")fn(p,c.time,l),ni(m.r,m.r,l,f);else if(p.path==="scale")fn(p,c.time,o),ea(m.s,m.s,o,f);else if(p.path==="weights"&&(fn(p,c.time,a),e.meshes)){for(let g of e.meshes)if(g.nodeIndex===p.nodeIndex){for(let x of g.primitives)if(x.pluginData?.morph?.weights){let b=x.pluginData.morph.weights,v=x.pluginData.morph.numTargets||b.length;for(let d=0;d<v;d++)b[d]=b[d]*(1-f)+a[d]*f}}}}}let u=[];for(let c=0;c<i;c++){let f=Se(),{t:p,r:m,s:g}=n[c];yt(f,m,p,g),u.push(f)}let h=Vt(e.gltf,u);e.worldMatrices=h;for(let c of e.meshes)c.nodeIndex>=0&&c.nodeIndex<h.length&&(c.transform.set(h[c.nodeIndex]),ze(c.normalMatrix,c.transform))}var Qi=e=>{Hn.delete(e)},to={name:"keyframes",evaluateAnimation:Zi,crossFadeTo:eo,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Ji(e.gltf,e.bin))},onLoadModel:Qi,onClearScene:Qi,onDestroy:(e,t)=>Qi(t),onUpdate(e,t){if(!e.isPlayingAnimation)return;let r=Hn.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let n=r[i];if(n.time+=t,n.clip.duration>0&&(n.time%=n.clip.duration),n.fadeSpeed!==0)if(n.weight+=n.fadeSpeed*t,n.weight<=0){r.splice(i,1);continue}else n.weight>=1&&(n.weight=1,n.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),Zi(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),Zi(e,e.animationTime))}},Xn=64;function ta(e,t,r){if(!(!e?.meshes||t<0||t>=Xn))for(let i of e.meshes)for(let n of i.primitives){let s=n.pluginData?.morph;s?.weights&&(s.weights[t]=r)}}var no={name:"morph",onResolveShader(e,t,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let n=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
379
+ })();`);c=null;let T=W(d,M,P,F);T&&typeof T.toGLB=="function"&&(M=T)}if(!x){d.SceneQuotaValidator&&d.SceneQuotaValidator.validate(M);let W=M.toGLB(),T=W instanceof ArrayBuffer?W:W.buffer.slice(W.byteOffset,W.byteOffset+W.byteLength);b({type:"3D_MODEL_READY",glbBuffer:T},[T])}a({type:"DONE",nonce:i})}catch(M){u(M&&M.message||M)}}},a({type:"READY",nonce:i})}function Wi(e,t,r){let i=r?.allowedScriptUrl??null,n=r?.allowClientScripts??i===null,s={nonce:t,engineSrc:e,allowedScriptUrl:i,allowClientScripts:n,revoked:Sc},l=(Ae().workerExtensionInstallers??[]).map(o=>`(${o.toString()})`).join(",");return`'use strict';(${Ec.toString()})(${JSON.stringify(s)},[${l}]);`}function ks(e){e.onError?.(new Error("SecurityError: Sandboxed script exceeded SECURITY_3D_SANDBOX_TIMEOUT_MS (3000 ms) and was terminated.")),e.onToast?.("Security Error: script timed out and was stopped.")}var Dt=0;function Os(){try{let e=new Uint32Array(4);return globalThis.crypto?.getRandomValues(e),Array.from(e,t=>t.toString(16).padStart(8,"0")).join("")}catch{return`${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`}}function Rc(e){try{return new TextEncoder().encode(e).length}catch{return e.length}}var _c=1024,Lc=256;function ws(e){if(!Array.isArray(e)&&!(e instanceof Float32Array)||e.length!==16)return!1;for(let t=0;t<16;t++){let r=e[t];if(typeof r!="number"||!Number.isFinite(r))return!1}return!0}function ji(e,t){if(!e||typeof e!="object")return null;let r=e;if(r.nonce!==t)return null;switch(r.type){case"READY":return{type:"READY"};case"DONE":return{type:"DONE"};case"ERROR":return{type:"ERROR",message:(typeof r.message=="string"?r.message:String(r.message??"Unknown worker error")).replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,"").slice(0,_c)};case"3D_UPDATE_TRANSFORMS":{let i=r.transforms;if(Array.isArray(i)){if(i.length>1e3)return null;for(let n of i)if(!ws(n))return null;return{type:"3D_UPDATE_TRANSFORMS",transforms:i}}if(i&&typeof i=="object"){let n=Object.keys(i);if(n.length>1e3)return null;let s=Object.create(null),l=i;for(let o of n){if(o.length>Lc||o==="__proto__"||o==="constructor"||o==="prototype")return null;let a=l[o];if(!ws(a))return null;s[o]=a}return{type:"3D_UPDATE_TRANSFORMS",transforms:s}}return null}case"3D_MODEL_READY":{let i=r.glbBuffer;return!(i instanceof ArrayBuffer)||i.byteLength>16777216?null:{type:"3D_MODEL_READY",payload:i}}default:return null}}function Ic(e){let t=Rc(e);if(t>1048576)throw new Error(`SecurityError: Script length (${t} bytes) exceeds SECURITY_3D_MAX_SCRIPT_BYTES (1048576).`)}function Us(e,t,r,i){switch(e.type){case"READY":return;case"3D_UPDATE_TRANSFORMS":t.onUpdateTransforms?.(e.transforms);return;case"3D_MODEL_READY":if(i.modelDispatched)return;i.modelDispatched=!0,t.onModelReady(e.payload);return;case"DONE":r();return;case"ERROR":r(),t.onError?.(new Error(`Worker script error: ${e.message}`));return;default:return e}}function Cc(e,t,r,i){let n=Os(),s=Wi(t,n,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),l=document.createElement("iframe");l.setAttribute("sandbox","allow-scripts"),l.setAttribute("aria-hidden","true"),l.tabIndex=-1,l.style.display="none",l.src=r,Dt++;let o=!1,a=!1,u={modelDispatched:!1},h,m=()=>{if(o||a)return;let g=l.contentWindow;!g||typeof g.postMessage!="function"||(a=!0,g.postMessage(e.kind==="url"?{type:"SANDBOX_RUN",nonce:n,workerSource:s,scriptUrl:e.scriptUrl}:{type:"SANDBOX_RUN",nonce:n,workerSource:s,script:e.script},"*"))},c=()=>{},d=g=>{if(o||!l.contentWindow||g.source!==l.contentWindow)return;let x=g.data;if(x&&typeof x=="object"&&x.type==="IFRAME_READY"){m();return}let b=ji(x,n);b&&Us(b,i,c,u)};c=()=>{o||(o=!0,h!==void 0&&clearTimeout(h),Dt=Math.max(0,Dt-1),typeof globalThis.removeEventListener=="function"&&globalThis.removeEventListener("message",d),typeof l.remove=="function"?l.remove():l.parentNode&&l.parentNode.removeChild(l))},h=setTimeout(()=>{o||(c(),ks(i))},3e3),typeof globalThis.addEventListener=="function"&&globalThis.addEventListener("message",d),l.onload=()=>{m()},l.onerror=()=>{c(),i.onError?.(new Error(`Sandbox iframe failed to load "${r}". Verify that three-live-sandbox.html is served at that URL.`))};let f=document.body||document.documentElement;if(!f||typeof f.appendChild!="function"){c();let g=new Error("SecurityError: Cannot mount sandbox iframe because document.body is unavailable.");throw i.onError?.(g),g}return f.appendChild(l),{terminate:c}}function Ss(e,t,r,i){if(t==="worker"&&typeof Worker>"u")return i("Sandboxed procedural execution requires Web Workers, but Workers are unavailable in this environment. For host security, Three-Live prohibits unsandboxed in-process evaluation.","Security Error: Web Workers unavailable. Script execution aborted.");if(t==="iframe"&&(typeof document>"u"||typeof document.createElement!="function"))return i("Sandboxed iframe execution requires a DOM environment with document.createElement. Refusing to evaluate in the host realm.","Security Error: DOM unavailable for iframe sandbox.");if(Dt>=32)return i(`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 n;try{n=vc()}catch(c){let d=c instanceof Error?c.message:String(c);return i(d,"Security Error: sandbox engine URL is not configured.")}if(t==="iframe"){let c;try{c=Tc()}catch(d){let f=d instanceof Error?d.message:String(d);return i(f,"Security Error: sandbox iframe URL is not configured.")}try{return Promise.resolve(Cc(e,n,c,r))}catch(d){return Promise.reject(d)}}let s=Os(),l=Wi(n,s,e.kind==="url"?{allowClientScripts:!1,allowedScriptUrl:e.scriptUrl}:{allowClientScripts:!0,allowedScriptUrl:null}),o;try{let c=new Blob([l],{type:"application/javascript"}),d=URL.createObjectURL(c);try{let f=Ds(d);o=new Worker(f)}finally{URL.revokeObjectURL(d)}}catch(c){let d=c instanceof Error?c.message:String(c);return i(`Failed to initialize Web Worker for sandboxed execution (CSP may block blob workers): ${d}`,"Security Error: Failed to start Worker sandbox.")}Dt++;let a=!1,u={modelDispatched:!1},h,m=()=>{a||(a=!0,h!==void 0&&clearTimeout(h),Dt=Math.max(0,Dt-1),o.terminate())};return h=setTimeout(()=>{a||(m(),ks(r))},3e3),o.onmessage=c=>{let d=ji(c.data,s);d&&Us(d,r,m,u)},o.onerror=c=>{m(),r.onError?.(new Error(`Worker execution error: ${c.message}`))},e.kind==="url"?o.postMessage({type:"EXECUTE_URL",scriptUrl:e.scriptUrl,nonce:s}):o.postMessage({type:"EXECUTE",script:e.script,nonce:s}),Promise.resolve({terminate:m})}function Es(e,t){return e==="none"||e==="unsafe-host-realm"?t(`SecurityError: sandbox="${e}" is prohibited. Sandboxing is mandatory for live compilation and cannot be bypassed. Use sandbox="worker" (default) or sandbox="iframe".`,`Security Error: sandbox="${e}" is not permitted.`):e!=="worker"&&e!=="iframe"?t(`SecurityError: Unsupported sandbox mode "${e}". Live compilation requires sandbox="worker" or sandbox="iframe".`,"Security Error: unsupported sandbox mode."):null}var Rs=e=>(t,r)=>{let i=new Error(t);return e.onError?.(i),r&&e.onToast?.(r),Promise.reject(i)},ln={execute(e,t,r,i){let n=Rs(r),s=Es(t,n);if(s)return s;try{Ic(e)}catch(l){let o=l instanceof Error?l.message:String(l);return n(o,"Security Error: script exceeds the size limit.")}return i?.allowClientScripts??Ns()?Ss({kind:"script",script:e},t,r,n):n(Qn,Jn)},executeUrl(e,t,r){let i=Rs(r),n=Es(t,i);if(n)return n;let s;try{s=wc(e)}catch(l){let o=l instanceof Error?l.message:String(l);return i(o,"Security Error: disallowed scene script URL.")}return Ss({kind:"url",scriptUrl:s},t,r,i)}},Xr=new Set;function Gt(e,t){let r=`[three-live] ${e} is unsupported; degraded to ${t}.`;Xr.has(r)||(Xr.add(r),typeof console<"u"&&typeof console.warn=="function"&&console.warn(r))}function Fs(){return Array.from(Xr)}function Vs(){Xr.clear()}var Bn=class extends Bt{constructor(e={}){Gt("ShaderMaterial","MeshStandardMaterial");let t=e.uniforms||{},r=t.color?.value??t.uColor?.value??t.diffuse?.value??e.color;super({color:r!==void 0?r:8421504,opacity:t.opacity?.value??e.opacity??1,transparent:!!e.transparent,wireframe:!!e.wireframe,side:e.side}),this.uniforms=t}},Bs=Bn,Et=class extends Be{constructor(e=[],t=[],r=1,i=0){super();let n=Number(r)||1,s=Math.max(0,Math.min(7,Math.floor(Number(i)||0))),l=s+1,o=[],a=[],u=[],h=[],m=new ge,c=new ge,d=new ge,f=(b,v)=>v.set(e[b*3]||0,e[b*3+1]||0,e[b*3+2]||0),g=(b,v)=>{let p=b.clone().normalize();o.push(p.x*n,p.y*n,p.z*n),a.push(v.x,v.y,v.z),u.push(Math.atan2(p.z,-p.x)/(2*Math.PI)+.5,1-Math.acos(Math.max(-1,Math.min(1,p.y)))/Math.PI)},x=(b,v,p)=>{let y=o.length/3,M=s===0?new ge().subVectors(p,v).cross(new ge().subVectors(b,v)).normalize():null;g(b,M||b.clone().normalize()),g(v,M||v.clone().normalize()),g(p,M||p.clone().normalize()),h.push(y,y+1,y+2)};for(let b=0;b<t.length;b+=3){f(t[b],m),f(t[b+1],c),f(t[b+2],d);let v=[];for(let p=0;p<=l;p++){v[p]=[];let y=m.clone().lerp(d,p/l),M=c.clone().lerp(d,p/l),P=l-p;for(let F=0;F<=P;F++)v[p][F]=P===0?y.clone():y.clone().lerp(M,F/P)}for(let p=0;p<l;p++)for(let y=0;y<2*(l-p)-1;y++){let M=y>>1;(y&1)===0?x(v[p][M+1],v[p+1][M],v[p][M]):x(v[p][M+1],v[p+1][M+1],v[p+1][M])}}this.setFromBuffers(o,a,u,h)}},Dc=Et,$r=class extends Et{constructor(e=1,t=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],e,t)}},br=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],zs=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],Wr=class extends Et{constructor(e=1,t=0){super(br,zs,e,t)}},Ne=(1+Math.sqrt(5))/2,jr=class extends Et{constructor(e=1,t=0){super([-1,Ne,0,1,Ne,0,-1,-Ne,0,1,-Ne,0,0,-1,Ne,0,1,Ne,0,-1,-Ne,0,1,-Ne,Ne,0,-1,Ne,0,1,-Ne,0,-1,-Ne,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],e,t)}},nt=1/Ne,Kr=class extends Et{constructor(e=1,t=0){super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-nt,-Ne,0,-nt,Ne,0,nt,-Ne,0,nt,Ne,-nt,-Ne,0,-nt,Ne,0,nt,-Ne,0,nt,Ne,0,-Ne,0,-nt,Ne,0,-nt,-Ne,0,nt,Ne,0,nt],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],e,t)}},qr=class extends Pn{constructor(e=1,t=1,r=4,i=8){let n=Math.max(1e-4,Number(e)||1),s=Math.max(0,Number.isFinite(Number(t))?Number(t):1)*.5,l=Math.max(2,Math.min(64,Math.floor(Number(r)||4))),o=[];for(let a=-1;a<=1;a+=2)for(let u=0;u<=l;u++){if(a>0&&u===0&&s===0)continue;let h=(a<0?u/l-1:u/l)*(Math.PI/2);o.push(new rt(Math.max(0,Math.cos(h)*n),a*s+Math.sin(h)*n))}super(o,Math.max(4,Math.min(128,Math.floor(Number(i)||8))))}},zn=class extends Be{constructor(e=.5,t=1,r=32,i=1,n=0,s=Math.PI*2){super();let l=Math.max(1e-4,Number(t)||1),o=Number(e),a=Number.isFinite(o)?Math.max(0,o):l*.5,u=Math.max(l,a),h=Math.min(u*.999,Math.min(l,a)),m=Math.max(3,Math.min(256,Math.floor(Number(r)||32))),c=Math.max(1,Math.min(64,Math.floor(Number(i)||1))),d=Number.isFinite(Number(n))?Number(n):0,f=Number.isFinite(Number(s))?Number(s):Math.PI*2,g=[],x=[],b=[],v=[];for(let p=0;p<=c;p++){let y=h+p/c*(u-h);for(let M=0;M<=m;M++){let P=d+M/m*f,F=Math.cos(P),W=Math.sin(P);if(g.push(y*F,y*W,0),x.push(0,0,1),b.push(y/u*F*.5+.5,y/u*W*.5+.5),p<c&&M<m){let T=p*(m+1)+M,E=T+m+1;y>1e-6&&v.push(T,E,T+1),v.push(E,E+1,T+1)}}}this.setFromBuffers(g,x,b,v)}},Yr=class extends zn{constructor(e=1,t=32,r=0,i=Math.PI*2){super(0,e,t,1,r,i)}},Gn=class extends et{constructor(e={}){super({roughness:.35,metalness:.1,side:2,...e});let t=Number(e.size);this.size=Number.isFinite(t)?Math.max(.002,Math.min(2,t)):.05,this.sizeAttenuation=e.sizeAttenuation!==!1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.35)}},un=class extends et{constructor(e={}){super({roughness:.4,metalness:.1,side:2,...e});let t=Number(e.linewidth);this.linewidth=Number.isFinite(t)?Math.max(.5,Math.min(20,t)):1,e.emissive===void 0&&(this.emissive=this.color.clone(),this.emissiveIntensity=.3)}},Zr=class extends un{constructor(e={}){super(e),this.dashSize=Number(e.dashSize)||3,this.gapSize=Number(e.gapSize)||1,this.scale=Number(e.scale)||1}};function Gs(e,t){let r=e?.attributes?.position;if(!r?.array||r.count<3)return new Float32Array(0);let i=r.array,n=e?.index?.array,s=Math.min(8192,Math.floor((n?n.length:r.count)/3)),l=c=>`${Math.round((i[c*3]||0)*1e4)},${Math.round((i[c*3+1]||0)*1e4)},${Math.round((i[c*3+2]||0)*1e4)}`,o=t===void 0,a=o?1:Math.cos(t*Math.PI/180),u={},h=[],m=(c,d)=>h.push(i[c*3]||0,i[c*3+1]||0,i[c*3+2]||0,i[d*3]||0,i[d*3+1]||0,i[d*3+2]||0);for(let c=0;c<s;c++){let d=n?n[c*3]:c*3,f=n?n[c*3+1]:c*3+1,g=n?n[c*3+2]:c*3+2,x=i[d*3]||0,b=i[d*3+1]||0,v=i[d*3+2]||0,p=(i[f*3]||0)-x,y=(i[f*3+1]||0)-b,M=(i[f*3+2]||0)-v,P=(i[g*3]||0)-x,F=(i[g*3+1]||0)-b,W=(i[g*3+2]||0)-v,T=y*W-M*F,E=M*P-p*W,S=p*F-y*P,O=Math.hypot(T,E,S);if(!o&&O<1e-8)continue;O>0&&(T/=O,E/=O,S/=O);let k=[d,f,g];for(let w=0;w<3;w++){let ie=k[w],oe=k[(w+1)%3],I=l(ie),H=l(oe);if(I===H)continue;let N=I<H?`${I}|${H}`:`${H}|${I}`,z=u[N];z?z.m||(z.m=1,z.nx*T+z.ny*E+z.nz*S<=a&&m(ie,oe)):(u[N]={va:ie,vb:oe,nx:T,ny:E,nz:S,m:o?1:0},o&&m(ie,oe))}}if(!o){let c=Object.keys(u);for(let d=0;d<c.length;d++){let f=u[c[d]];f&&!f.m&&m(f.va,f.vb)}}return new Float32Array(h)}var Qr=class extends Be{constructor(e){super(),this.setAttribute("position",new $e(Gs(e),3)),this.__isSegmentPairs=!0}},Jr=class extends Be{constructor(e,t=1){super();let r=Number.isFinite(Number(t))?Number(t):1;this.setAttribute("position",new $e(Gs(e,r),3)),this.__isSegmentPairs=!0}};function Pc(e,t,r=1){let i=new Be;i.__baked=!0;let n=e?.attributes?.position;if(!n?.array||n.count<2)return i;let s=n.array,l=e.index?.array,o=e.__isSegmentPairs?"segments":t,a=l?l.length:n.count,u=Math.min(4096,Math.max(0,o==="segments"?Math.floor(a/2):o==="loop"&&a>=3?a:a-1));if(u===0)return i;e.computeBoundingBox();let h=e.boundingBox,m=h&&h.max.distanceTo(h.min)||1,c=Math.max(.0015,Math.min(.025,m*.003))*(.5+.5*Math.max(.5,Math.min(6,Number(r)||1))),d=[],f=[],g=[],x=[];for(let b=0;b<u;b++){let v=o==="segments"?b*2:b,p=o==="segments"?b*2+1:(b+1)%a,y=l?l[v]:v,M=l?l[p]:p,P=s[y*3]||0,F=s[y*3+1]||0,W=s[y*3+2]||0,T=(s[M*3]||0)-P,E=(s[M*3+1]||0)-F,S=(s[M*3+2]||0)-W,O=Math.hypot(T,E,S);if(O<1e-6)continue;let k=T/O,w=E/O,ie=S/O,oe=(Math.abs(w)<.9?Math.hypot(ie,k):Math.hypot(ie,w))||1,I=Math.abs(w)<.9?ie/oe:0,H=Math.abs(w)<.9?0:-ie/oe,N=Math.abs(w)<.9?-k/oe:w/oe,z=w*N-ie*H,ue=ie*I-k*N,ce=k*H-w*I,B=d.length/3,$=[[I,H,N],[z,ue,ce],[-I,-H,-N],[-z,-ue,-ce]];for(let _=0;_<2;_++){let G=P+_*T,j=F+_*E,q=W+_*S;for(let D=0;D<4;D++){let Y=$[D];d.push(G+Y[0]*c,j+Y[1]*c,q+Y[2]*c),f.push(Y[0],Y[1],Y[2]),g.push(D/4,_)}}for(let _=0;_<4;_++){let G=(_+1)%4;x.push(B+_,B+G,B+4+G,B+_,B+4+G,B+4+_)}}return d.length>0&&i.setFromBuffers(d,f,g,x),i}function Nc(e,t=.05){let r=new Be;r.__baked=!0;let i=e?.attributes?.position;if(!i?.array||i.count<1)return r;let n=i.array,s=i.count,l=Math.min(s,5e3),o=Math.max(.003,Math.min(.25,(Number(t)||.05)*.6)),a=[],u=[],h=[],m=[];for(let c=0;c<l;c++){let d=s<=5e3?c:Math.floor(c*s/l),f=n[d*3]||0,g=n[d*3+1]||0,x=n[d*3+2]||0,b=c*6;for(let v=0;v<6;v++){let p=br[v*3],y=br[v*3+1],M=br[v*3+2];a.push(f+p*o,g+y*o,x+M*o),u.push(p,y,M),h.push(.5,.5)}for(let v=0;v<24;v++)m.push(b+zs[v])}return r.setFromBuffers(a,u,h,m),r}var Nt=class extends gt{constructor(e,t,r="strip"){let i=t&&typeof t=="object"?t:{},n=t instanceof et?t:r==="points"?new Gn(i):new un(i),s=e instanceof Be?e:new Be;super(s,n),this.isLine=!0,this._lineMode=r,this._sourceGeo=s}computeLineDistances(){return this}_bakeAuthorGeometry(){this.geometry&&!this.geometry.__baked&&(this._sourceGeo=this.geometry);let e=this._lineMode==="points";if(e){let t=this._sourceGeo?.attributes?.color;if(t?.array&&t.count>0&&this.material?.color.r===1&&this.material.color.g===1&&this.material.color.b===1){let r=t.array,i=Math.min(t.count,64),n=0,s=0,l=0;for(let o=0;o<i;o++)n+=r[o*3]||0,s+=r[o*3+1]||0,l+=r[o*3+2]||0;this.material.color.setRGB(n/i,s/i,l/i)}}!this.geometry?.__baked&&this._sourceGeo?.attributes?.position?.count>=(e?1:2)&&(this.geometry=e?Nc(this._sourceGeo,this.material?.size??.05):Pc(this._sourceGeo,this._lineMode,this.material?.linewidth??1))}},ei=class extends Nt{constructor(e,t){super(e,t,"loop"),this.isLineLoop=!0}},ti=class extends Nt{constructor(e,t){super(e,t,"segments"),this.isLineSegments=!0}},ni=class extends Nt{constructor(e,t){super(e,t,"points"),this.isPoints=!0}},ri=class extends Un{constructor(e,t,r=0,i=Math.PI/3,n=0,s=2){super(e,t,r,s),this.target=new lt,this.type="spot";let l=Number(i);this.angle=Number.isFinite(l)?Math.max(.01,Math.min(Math.PI/2,l)):Math.PI/3;let o=Number(n);this.penumbra=Number.isFinite(o)?Math.max(0,Math.min(1,o)):0}},Hn=class extends On{constructor(e,t,r){Gt("HemisphereLight","AmbientLight"),super(e,r),this.groundColor=new ut(t??4473924)}},Hs=Hn,Xs={Vector2:rt,Vector3:ge,Vector4:gr,Euler:In,Quaternion:sn,Matrix4:Pt,Matrix3:xr,Color:ut,MathUtils:_s,BufferAttribute:$e,Float32BufferAttribute:vr,Uint16BufferAttribute:Mr,Uint32BufferAttribute:Tr,BufferGeometry:Be,BoxGeometry:Cn,PlaneGeometry:Ar,SphereGeometry:wr,CylinderGeometry:Dn,ConeGeometry:Sr,TorusGeometry:Er,TorusKnotGeometry:Rr,Curve:St,Curve3:St,LineCurve3:_r,QuadraticBezierCurve3:Lr,CubicBezierCurve3:Ir,CatmullRomCurve3:Cr,LatheGeometry:Pn,TubeGeometry:Dr,PolyhedronGeometry:Et,IcosahedronGeometry:jr,OctahedronGeometry:Wr,DodecahedronGeometry:Kr,TetrahedronGeometry:$r,CapsuleGeometry:qr,RingGeometry:zn,CircleGeometry:Yr,WireframeGeometry:Qr,EdgesGeometry:Jr,FrontSide:0,BackSide:1,DoubleSide:2,NoBlending:0,NormalBlending:1,AdditiveBlending:2,MultiplyBlending:4,RepeatWrapping:1e3,ClampToEdgeWrapping:1001,MirroredRepeatWrapping:1002,NearestFilter:1003,NearestMipmapNearestFilter:1004,NearestMipmapLinearFilter:1005,LinearFilter:1006,LinearMipmapNearestFilter:1007,LinearMipmapLinearFilter:1008,UnsignedByteType:1009,ByteType:1010,ShortType:1011,UnsignedShortType:1012,IntType:1013,UnsignedIntType:1014,FloatType:1015,HalfFloatType:1016,AlphaFormat:1021,RGBFormat:1022,RGBAFormat:1023,LuminanceFormat:1024,LuminanceAlphaFormat:1025,RedFormat:1028,RGFormat:1030,NoColorSpace:"",SRGBColorSpace:"srgb",LinearSRGBColorSpace:"srgb-linear",StaticDrawUsage:35044,DynamicDrawUsage:35048,ACESFilmicToneMapping:4,PCFSoftShadowMap:2,Texture:an,DataTexture:Pr,TextureLoader:Nr,Material:et,MeshStandardMaterial:Bt,MeshBasicMaterial:kr,MeshLambertMaterial:Or,MeshPhongMaterial:Ur,MeshPhysicalMaterial:Fr,PointsMaterial:Gn,LineBasicMaterial:un,LineDashedMaterial:Zr,ShaderMaterial:Bn,RawShaderMaterial:Bs,Object3D:lt,Group:Vr,Mesh:gt,InstancedMesh:kn,Line:Nt,LineLoop:ei,LineSegments:ti,Points:ni,Light:zt,AmbientLight:On,DirectionalLight:Br,PointLight:Un,SpotLight:ri,HemisphereLight:Hn,RectAreaLight:Hs,Camera:Fn,PerspectiveCamera:zr,Scene:Vn,WebGLRenderer:Gr,Clock:Hr,SceneQuotaValidator:yt,exportSceneToCanvas3D:Gi,exportSceneToGLB:Hi,exportSceneToUSDZ:Cs,generateUSDZ:En,glbToUSDZ:Sn,sceneToCanvas3D:rn,sceneToGLB:Tn,sceneToUSDZ:wn,authorScriptRunner:ln,getAuthorWarnings:Fs,clearAuthorWarnings:Vs};Object.freeze(yt),Object.freeze(yt.prototype),Object.freeze(Vn.prototype),Object.freeze(Xs);var Ht=new Proxy(Xs,{get:(e,t)=>{if(t in e)return e[t];let r=Ae().authorNamespace;return r&&typeof t=="string"&&t in r?r[t]:(typeof t=="string"&&t!=="then"&&t!=="toJSON"&&!t.startsWith("__")&&Gt(`THREE.${t}`,"no-op proxy"),_n)},has:(e,t)=>{if(t in e)return!0;let r=Ae().authorNamespace;return!!(r&&typeof t=="string"&&t in r)},set:(e,t)=>{throw new TypeError(`Cannot assign to read only property '${String(t)}' of #<THREE>`)},defineProperty:(e,t)=>{throw new TypeError(`Cannot define property '${String(t)}', object is not extensible`)},deleteProperty:(e,t)=>{throw new TypeError(`Cannot delete property '${String(t)}' of #<THREE>`)},setPrototypeOf:()=>{throw new TypeError("#<THREE> is not extensible")}}),yr=Ae();if(yr.threeNamespace=Ht,yr.workerExtensionInstallers)for(let e of yr.workerExtensionInstallers)e(Ht,yr);var Ln={name:"three_author",THREE:Ht},kc=Ln,wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:void 0;if(typeof wt.THREE>"u"&&(wt.THREE=Ht),typeof wt.requestAnimationFrame!="function"&&(wt.requestAnimationFrame=e=>(typeof e=="function"&&typeof wt.__three_live_raf_cb__!="function"&&(wt.__three_live_raf_cb__=e),wt.__three_live_in_step__||Gt("requestAnimationFrame","single-frame static evaluation"),0)),typeof wt.cancelAnimationFrame!="function"&&(wt.cancelAnimationFrame=()=>{}),typeof window<"u"){let e=window;e.ThreeLive=e.ThreeLive||{},e.ThreeLive.THREE=Ht,e.ThreeLivePlugins=e.ThreeLivePlugins||{},e.ThreeLivePlugins.threeAuthor=Ln,e.ThreeLivePlugins.three_author=Ln,e.ThreeLivePlugins["three-author"]=Ln}function mn(e,t){let r=e?.trim(),i=r?Number(r):NaN;return Number.isFinite(i)?i:t}var Ki=(e,t,r)=>({x:e,y:t,z:r,toString:()=>`${e}m ${t}m ${r}m`}),Oc=typeof HTMLElement<"u"?HTMLElement:class{};typeof CustomEvent>"u"&&typeof Event<"u"&&(globalThis.CustomEvent=class extends Event{constructor(e,t){super(e,t),this.detail=t?.detail??null}});var ze=class Ge extends Oc{constructor(){super(...arguments),this.viewer=null,this.canvas=null,this.posterEl=null,this.arButton=null,this.currentModel=null,this.activeXRSession=null,this.toastTimer=null,this.currentModelLimits=void 0,this.isModelLoaded=!1,this.scriptHandle=null,this.loadController=null,this.resizeObserver=null,this.mutationObserver=null}static get arProvider(){return Ae().arProvider}static set arProvider(t){Ae().arProvider=t}static get scriptRunner(){return Ae().scriptRunner}static set scriptRunner(t){Ae().scriptRunner=t}static get sandboxEngineSrc(){return Ae().sandboxEngineSrc??null}static set sandboxEngineSrc(t){Ae().sandboxEngineSrc=t}static get sandboxIframeSrc(){return Ae().sandboxIframeSrc??null}static set sandboxIframeSrc(t){Ae().sandboxIframeSrc=t}static get allowClientScripts(){return!!Ae().allowClientScripts}static set allowClientScripts(t){Ae().allowClientScripts=t}static registerScriptRunner(t){Ge.scriptRunner=t}static defineModelViewer(t="model-viewer"){if(typeof customElements>"u")return!1;let r=customElements.get(t);if(r!=null)return r===Ge||r.prototype instanceof Ge;class i extends Ge{}return customElements.define(t,i),!0}static registerDecoder(t,r){Ke.registerDecoder(t,r)}static getDecoder(t){return Ke.getDecoder(t)}static registerAR(t){typeof t=="function"?Ge.arProvider={activateAR:t}:Ge.arProvider=t,typeof document<"u"&&document.querySelectorAll("three-live").forEach(r=>{r instanceof Ge&&r.updateARButtonVisibility()})}static isARSupported(){return!!Ge.arProvider}getLoadedModel(){return this.currentModel}beginLoad(){let t=this.loadController,r=this.scriptHandle,i=new AbortController;return this.loadController=i,this.scriptHandle=null,t?.abort(),r?.terminate(),i}connectedCallback(){if(typeof document>"u")return;(!this.style.display||this.style.display==="inline")&&(this.style.display="block"),getComputedStyle(this).position==="static"&&(this.style.position="relative"),this.style.overflow="hidden",this.setupDOM(),this.initViewer(),this.setupResizeObserver();let t=this.getAttribute("src"),r=this.getAttribute("script-src");if(t)this.loadModel(t).catch(()=>{});else if(r)this.loadScriptFromSrc(r).catch(()=>{});else{let i=this.querySelector('script[type="text/three"], script[type="text/three-live"]');i&&i.textContent&&this.executeScript(i.textContent).catch(()=>{})}for(let i of Ke.getRegisteredPlugins())i.onElementConnected?.(this)}disconnectedCallback(){for(let t of Ke.getRegisteredPlugins())t.onElementDisconnected?.(this);this.beginLoad().abort(),this.mutationObserver?.disconnect(),this.mutationObserver=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,this.activeXRSession?.stop?.().catch?.(()=>{}),this.activeXRSession=null,this.toastTimer&&clearTimeout(this.toastTimer),this.toastTimer=null,this.viewer?.destroy(),this.viewer=null,this.isModelLoaded=!1}attributeChangedCallback(t,r,i){if(r!==i){switch(t){case"src":i&&this.loadModel(i).catch(()=>{});break;case"camera-target":this.applyCameraTarget(i);break;case"min-camera-orbit":case"max-camera-orbit":this.applyOrbitLimits();break;case"field-of-view":this.applyFieldOfView(i);break;case"script-src":i&&this.loadScriptFromSrc(i).catch(()=>{});break;case"sandbox":case"allow-client-scripts":case"ios-src":break;case"poster":this.updatePoster(i);break;case"camera-orbit":this.applyCameraOrbit(i);break;case"selected-mesh":this.viewer&&i!==null&&this.viewer.setSelectedMesh(i);break;case"exposure":if(this.viewer&&i!==null){let n=parseFloat(i);isNaN(n)||this.viewer.setExposure(n)}break;case"shadow-intensity":case"shadow-softness":this.viewer&&this.viewer.setShadow(this.shadowIntensity,this.shadowSoftness);break;case"tone-mapping":this.viewer?.setToneMapping(Vt(i));break;case"environment-image":this.viewer&&this.viewer.setEnvironmentImage(i).catch(()=>{});break;case"skybox-image":this.viewer&&this.viewer.setSkyboxImage?.(i)?.catch?.(()=>{});break;case"camera-controls":{let n=this.cameraControls;this.viewer&&this.viewer.setInteractive?.(n),this.canvas&&(this.canvas.style.touchAction=n?"none":"auto");break}case"autoplay":this.viewer&&this.viewer.setAutoplay(i!==null&&i!=="false");break;case"animation-name":this.viewer&&i!==null&&this.viewer.setAnimationName(i);break;case"variant-name":this.viewer&&this.selectVariant(i);break;case"auto-rotate":this.viewer&&this.viewer.setAutoRotate(i!==null&&i!=="false");break;case"auto-rotate-delay":this.viewer&&this.viewer.setAutoRotateDelay(this.autoRotateDelay);break;case"rotation-per-second":this.viewer&&this.viewer.setAutoRotateSpeed(this.parseRotationPerSecond(i));break;case"ar":this.updateARButtonVisibility();break}for(let n of Ke.getRegisteredPlugins())n.onAttributeChanged?.(this,t,r,i)}}getAttr(t){return this.getAttribute(t)}setAttr(t,r){r!==null?this.setAttribute(t,String(r)):this.removeAttribute(t)}getBoolAttr(t){return this.hasAttribute(t)&&this.getAttr(t)!=="false"}setBoolAttr(t,r){this.setAttr(t,r?"":null)}getFloatAttr(t,r){let i=this.getAttr(t);return i!==null?parseFloat(i):r}get src(){return this.getAttr("src")}set src(t){this.setAttr("src",t)}get cameraControls(){return this.getBoolAttr("camera-controls")}set cameraControls(t){this.setBoolAttr("camera-controls",t)}get cameraOrbit(){return this.getAttr("camera-orbit")}set cameraOrbit(t){this.setAttr("camera-orbit",t)}get cameraTarget(){return this.getAttr("camera-target")}set cameraTarget(t){this.setAttr("camera-target",t)}get minCameraOrbit(){return this.getAttr("min-camera-orbit")}set minCameraOrbit(t){this.setAttr("min-camera-orbit",t)}get maxCameraOrbit(){return this.getAttr("max-camera-orbit")}set maxCameraOrbit(t){this.setAttr("max-camera-orbit",t)}get fieldOfView(){return this.getAttr("field-of-view")}set fieldOfView(t){this.setAttr("field-of-view",t)}get iosSrc(){return this.getAttr("ios-src")}set iosSrc(t){this.setAttr("ios-src",t)}get scriptSrc(){return this.getAttr("script-src")}set scriptSrc(t){this.setAttr("script-src",t)}get sandbox(){return this.getAttr("sandbox")||(Ae().sandboxIframeSrc?"iframe":"worker")}set sandbox(t){this.setAttr("sandbox",t)}get allowClientScripts(){return this.getBoolAttr("allow-client-scripts")||Ge.allowClientScripts}set allowClientScripts(t){this.setBoolAttr("allow-client-scripts",t)}get poster(){return this.getAttr("poster")}set poster(t){this.setAttr("poster",t)}get selectedMesh(){return this.getAttr("selected-mesh")}set selectedMesh(t){this.setAttr("selected-mesh",t)}get exposure(){return this.getFloatAttr("exposure",1)}set exposure(t){this.setAttr("exposure",t)}get autoRotate(){return this.getBoolAttr("auto-rotate")}set autoRotate(t){this.setBoolAttr("auto-rotate",t)}get autoRotateDelay(){return this.getFloatAttr("auto-rotate-delay",3e3)}set autoRotateDelay(t){this.setAttr("auto-rotate-delay",t)}get rotationPerSecond(){return this.getAttr("rotation-per-second")||"30deg"}set rotationPerSecond(t){this.setAttr("rotation-per-second",t)}get turntableRotation(){return this.viewer?this.viewer.turntableRotation:0}get ar(){return this.hasAttribute("ar")}set ar(t){this.setBoolAttr("ar",t)}get arScale(){return this.getAttr("ar-scale")||"auto"}set arScale(t){this.setAttr("ar-scale",t)}get arPlacement(){return this.getAttr("ar-placement")||"floor"}set arPlacement(t){this.setAttr("ar-placement",t)}get canActivateAR(){return Ge.isARSupported()}get shadowIntensity(){return this.getFloatAttr("shadow-intensity",0)}set shadowIntensity(t){this.setAttr("shadow-intensity",t)}get shadowSoftness(){return this.getFloatAttr("shadow-softness",.5)}set shadowSoftness(t){this.setAttr("shadow-softness",t)}get toneMapping(){return Vt(this.getAttr("tone-mapping"))}set toneMapping(t){this.setAttr("tone-mapping",t)}get bloom(){return this.getFloatAttr("bloom",0)}set bloom(t){this.setAttr("bloom",t)}get bloomThreshold(){return mn(this.getAttr("bloom-threshold"),.62)}set bloomThreshold(t){this.setAttr("bloom-threshold",t)}get bloomRadius(){return mn(this.getAttr("bloom-radius"),.75)}set bloomRadius(t){this.setAttr("bloom-radius",t)}get outlineSelected(){return this.getBoolAttr("outline-selected")}set outlineSelected(t){this.setBoolAttr("outline-selected",t)}get outlineColor(){return this.getAttr("outline-color")||"#38bdf8"}set outlineColor(t){this.setAttr("outline-color",t)}get environmentImage(){return this.getAttr("environment-image")}set environmentImage(t){this.setAttr("environment-image",t)}get skyboxImage(){return this.getAttr("skybox-image")}set skyboxImage(t){this.setAttr("skybox-image",t)}get autoplay(){return this.getBoolAttr("autoplay")}set autoplay(t){this.setBoolAttr("autoplay",t)}get animationName(){return this.getAttr("animation-name")}set animationName(t){this.setAttr("animation-name",t)}get availableAnimations(){return this.viewer?this.viewer.getAvailableAnimations():[]}get variantName(){return this.viewer?this.viewer.getVariantName():this.getAttr("variant-name")}set variantName(t){this.setAttr("variant-name",t)}get availableVariants(){return this.viewer?this.viewer.getAvailableVariants():[]}fireEvent(t,r){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:r}))}setSlotVisible(t,r){let i=typeof this.querySelector=="function"?this.querySelector(`[slot="${t}"]`):null;i&&(i.hidden=!r,i.style&&(i.style.display=r?"":"none"))}emitError(t,r="script"){this.setSlotVisible("error",!0),this.fireEvent("error",{error:t}),this.fireEvent("three-error",{error:t,message:t?.message||String(t),stage:r})}selectVariant(t){if(!this.viewer)return!1;let r=this.viewer.selectVariant(t);return r&&this.fireEvent("variant-applied",{variantName:this.viewer.getVariantName()}),r}get model(){let t=this.viewer?this.viewer.getModelMaterials():[];return{materials:t,getMaterialByName(r){return t.find(i=>i.name===r)??null}}}play(){this.viewer&&this.viewer.playAnimation(this.animationName||void 0)}pause(){this.viewer&&this.viewer.pauseAnimation()}resetCamera(){this.viewer?.resetCamera()}resetTurntableRotation(t=0){this.viewer?.resetTurntableRotation(t)}setCamera(t,r,i,n){this.viewer&&this.viewer.setCamera(t,r,i,n)}getCameraOrbit(){return this.viewer?this.viewer.getCameraOrbit():{theta:0,phi:0,radius:3,toString(){return"0rad 0rad 3m"}}}getCameraTarget(){return this.viewer?this.viewer.getCameraTarget():Ki(0,0,0)}getFieldOfView(){return this.viewer?this.viewer.getFieldOfView():45}jumpCameraToGoal(){this.viewer?.jumpCameraToGoal()}toDataURL(t,r){return this.viewer?.render?.(),this.canvas?this.canvas.toDataURL(t,r):""}toBlob(t){return this.viewer?.render?.(),new Promise((r,i)=>{if(!this.canvas||typeof this.canvas.toBlob!="function"){i(new Error("Canvas toBlob is not supported in this environment."));return}this.canvas.toBlob(n=>{n?r(n):i(new Error("Failed to capture canvas blob."))},t?.mimeType,t?.qualityArgument)})}positionAndNormalFromPoint(t,r){let i=this.viewer?.raycastFromScreenPoint(t,r);if(!i)return null;let[n,s,l]=i.hitPoint||i.point,[o,a,u]=i.normal;return{position:Ki(n,s,l),normal:Ki(o,a,u)}}loadModel(t){return this.loadModelWithLimits(t)}async loadModelWithLimits(t,r,i=this.beginLoad()){if(i.signal.throwIfAborted(),!this.viewer){this.currentModel=t,this.currentModelLimits=r;return}try{let n;if(typeof t=="string"){let a=await fetch(t,{signal:i.signal});if(!a.ok)throw new Error(`Failed to load "${t}": HTTP ${a.status}`);n=await a.arrayBuffer()}else n=t;i.signal.throwIfAborted();let s=Lt(n);this.viewer.loadGLBData(s,r),this.currentModel=s,this.currentModelLimits=r,this.isModelLoaded=!0,this.hidePoster(),this.setSlotVisible("error",!1),this.updateHotspots();let l=this.getAttr("selected-mesh");l&&this.viewer.setSelectedMesh(l);let o=this.getAttr("variant-name");o&&this.selectVariant(o),this.fireEvent("load",{model:s}),this.fireEvent("three-load",{model:s,source:typeof t=="string"?"src":"model"})}catch(n){throw i.signal.aborted||this.emitError(n,"load"),n}}showToast(t,r=4500){if(typeof document>"u")return;let i=this.querySelector(".three-live-toast");i||(i=document.createElement("div"),i.className="three-live-toast",i.style.cssText="position:absolute;bottom:70px;left:50%;transform:translateX(-50%) translateY(10px);z-index:10;padding:10px 16px;background-color:rgba(15,23,42,0.94);color:#f8fafc;border:1px solid rgba(56,189,248,0.45);border-radius:14px;font:500 13px/1.35 system-ui,-apple-system,sans-serif;box-shadow:0 10px 25px rgba(0,0,0,0.45);backdrop-filter:blur(12px);pointer-events:none;opacity:0;transition:opacity .25s ease,transform .25s ease;max-width:88%;text-align:center;white-space:normal;word-break:break-word",this.appendChild(i)),i.textContent=t,this.toastTimer&&clearTimeout(this.toastTimer);let n=()=>{i&&(i.style.opacity="1",i.style.transform="translateX(-50%) translateY(0)")};typeof requestAnimationFrame<"u"?requestAnimationFrame(n):n(),this.toastTimer=setTimeout(()=>{i&&(i.style.opacity="0",i.style.transform="translateX(-50%) translateY(10px)"),this.toastTimer=null},r)}async activateAR(){this.activeXRSession?.isSessionActive?.()&&(await this.activeXRSession.stop().catch(()=>{}),this.activeXRSession=null);let t=(n,s=n.message)=>{throw this.fireEvent("ar-status",{status:"failed",error:n}),this.showToast(s,6e3),n};this.currentModel||t(new Error("No 3D model is loaded in <three-live>.")),Ge.arProvider||t(new Error("AR module not bundled. Use the default 'three-live' bundle or call ThreeLiveElement.registerAR()."));let r=this.getAttr("ios-src"),i=(this.getAttr("ar-modes")||"").split(/\s+/).filter(Boolean);try{this.fireEvent("ar-status",{status:"session-started"});let n=await Ge.arProvider.activateAR({model:r||this.currentModel,glbUrl:typeof this.currentModel=="string"?this.currentModel:void 0,view:this.viewer||void 0,element:this,preferredModes:i.length>0?i:void 0,arScale:this.arScale,arPlacement:this.arPlacement,webXROptions:{onExit:()=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"not-presenting"})},onError:s=>{this.activeXRSession=null,this.fireEvent("ar-status",{status:"failed",error:s}),this.showToast(`AR error: ${s.message}`,6e3)}}});if(n.success){n.session&&(this.activeXRSession=n.session);let s=n.mode==="quick-look"?"Opening Apple AR Quick Look...":n.mode==="scene-viewer"?"Opening Google Scene Viewer...":n.mode==="webxr"?"WebXR AR session started.":"";s&&this.showToast(s)}else{let s=n.error?.message||"AR requires an iOS (Quick Look) or Android (WebXR / Scene Viewer) device.";if(this.isDesktopMac()&&typeof document<"u"&&this.currentModel&&Ge.arProvider.createUSDZBlob)try{let l=this.currentModel instanceof Blob&&this.currentModel.type==="model/vnd.usdz+zip"?this.currentModel:Ge.arProvider.createUSDZBlob(this.currentModel),o=URL.createObjectURL(l),a=document.createElement("a");a.href=o,a.download="three_live_model.usdz",document.body.appendChild(a),a.click(),document.body.removeChild(a),setTimeout(()=>URL.revokeObjectURL(o),3e3),this.showToast("Downloaded USDZ preview for macOS Quick Look.",5e3)}catch{this.showToast(s,6e3)}else this.showToast(s,6e3);n.error&&this.fireEvent("ar-status",{status:"failed",error:n.error})}return n}catch(n){return this.activeXRSession=null,t(n,`AR error: ${n.message||String(n)}`)}}setupDOM(){let t=this.querySelector("canvas");t||(t=document.createElement("canvas"),t.style.cssText=`width:100%;height:100%;display:block;touch-action:${this.cameraControls?"none":"auto"};outline:none`,this.appendChild(t)),this.canvas=t,typeof t.addEventListener=="function"&&!t.__tlCtxBound&&(t.__tlCtxBound=!0,t.addEventListener("webglcontextlost",i=>this.fireEvent("three-context-lost",{originalEvent:i})),t.addEventListener("webglcontextrestored",i=>this.fireEvent("three-context-restored",{originalEvent:i}))),this.setSlotVisible("error",!1),this.isModelLoaded||this.setSlotVisible("poster",!0);let r=this.getAttr("poster");r&&this.updatePoster(r),this.createARButton(),typeof MutationObserver<"u"&&!this.mutationObserver&&(this.mutationObserver=new MutationObserver(()=>{this.updateARButtonVisibility()}),this.mutationObserver.observe(this,{childList:!0}))}initViewer(){if(!this.canvas)return;let t=this.autoRotate,r=this.exposure,i=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),n=this.parseOrbitLimit(this.getAttr("max-camera-orbit")),s=this.parseCameraTarget(this.getAttr("camera-target")),l=this.parseFieldOfView(this.getAttr("field-of-view"));this.viewer=new Ke(this,this.canvas,{autoRotate:t,autoRotateDelay:this.autoRotateDelay,autoRotateSpeed:this.parseRotationPerSecond(this.getAttr("rotation-per-second")),exposure:r,shadowIntensity:this.shadowIntensity,shadowSoftness:this.shadowSoftness,toneMapping:this.toneMapping,environmentImage:this.environmentImage,autoplay:this.autoplay,animationName:this.animationName||void 0,variantName:this.getAttr("variant-name")||void 0,fieldOfView:l,cameraTarget:s,minCameraOrbit:i,maxCameraOrbit:n,onMeshClick:a=>{this.fireEvent("meshclick",a)},onCameraChange:a=>{this.updateHotspots();for(let u of Ke.getRegisteredPlugins())u.onCameraChange?.(this.viewer,this);this.fireEvent("camera-change",a)}}),this.viewer.setInteractive(this.cameraControls),this.skyboxImage&&this.viewer.setSkyboxImage(this.skyboxImage).catch(()=>{});let o=this.getAttr("camera-orbit");o&&this.applyCameraOrbit(o),this.currentModel&&this.loadModelWithLimits(this.currentModel,this.currentModelLimits)}setupResizeObserver(){typeof ResizeObserver>"u"||(this.resizeObserver=new ResizeObserver(()=>{this.viewer&&(this.viewer.resize(),this.viewer.render(),this.updateHotspots())}),this.resizeObserver.observe(this))}updatePoster(t){if(!(typeof document>"u")){if(!t){this.posterEl&&(this.posterEl.remove(),this.posterEl=null);return}this.posterEl||(this.posterEl=document.createElement("img"),this.posterEl.alt="3D Scene Preview",this.posterEl.style.cssText="position:absolute;inset:0;width:100%;height:100%;object-fit:cover;transition:opacity .35s ease-out;pointer-events:none;z-index:1",this.appendChild(this.posterEl)),this.posterEl.src=t,this.isModelLoaded||(this.posterEl.style.opacity="1")}}hidePoster(){this.setSlotVisible("poster",!1),this.posterEl&&(this.posterEl.style.opacity="0",setTimeout(()=>{this.isModelLoaded&&this.posterEl&&(this.posterEl.remove(),this.posterEl=null)},400))}isDesktopMac(){let t=typeof navigator<"u"&&navigator.userAgent||"";return/Macintosh/i.test(t)&&!(typeof navigator<"u"&&navigator.maxTouchPoints>1)&&!/Android|iPhone|iPad|iPod/i.test(t)}syncARButtonLabel(t){let r=this.isDesktopMac(),i=r?"Quick Look (.usdz)":"View in AR",n=r?"Download .usdz preview for macOS Quick Look (live camera AR requires iOS or Android)":"View in Augmented Reality";typeof t.setAttribute=="function"&&(t.setAttribute("aria-label",n),t.setAttribute("title",n));let s=t._labelSpan||(typeof t.querySelector=="function"?t.querySelector("span"):null);s&&(s.textContent=i)}createARButton(){if(!(typeof document>"u")){if(!this.arButton){let t=document.createElement("button");t.type="button",t.className="three-live-ar-button",t.setAttribute("part","default-ar-button");let r="http://www.w3.org/2000/svg";if(typeof document.createElementNS=="function"){let n=document.createElementNS(r,"svg");for(let[l,o]of[["width","20"],["height","20"],["viewBox","0 0 24 24"],["fill","none"],["stroke","currentColor"],["stroke-width","2"],["stroke-linecap","round"],["stroke-linejoin","round"]])n.setAttribute(l,o);n.style.marginRight="6px";let s=document.createElementNS(r,"path");s.setAttribute("d","M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16zM3.27 6.96 12 12.01l8.73-5.05M12 22.08V12"),n.appendChild(s),t.appendChild(n)}let i=document.createElement("span");t._labelSpan=i,t.appendChild(i),this.syncARButtonLabel(t),t.style.cssText="position:absolute;right:16px;bottom:16px;z-index:2;align-items:center;justify-content:center;padding:8px 16px;background-color:rgba(15,23,42,0.85);color:#fff;border:1px solid rgba(255,255,255,0.15);border-radius:9999px;font:600 13px system-ui,-apple-system,sans-serif;cursor:pointer;backdrop-filter:blur(8px);box-shadow:0 4px 12px rgba(0,0,0,0.25);transition:transform .15s ease,background-color .15s ease;display:none",t.addEventListener("mouseenter",()=>{t.style.backgroundColor="rgba(30, 41, 59, 0.95)",t.style.transform="scale(1.04)"}),t.addEventListener("mouseleave",()=>{t.style.backgroundColor="rgba(15, 23, 42, 0.85)",t.style.transform="scale(1)"}),t.addEventListener("click",n=>{n.stopPropagation(),this.activateAR()}),this.arButton=t,this.appendChild(t)}this.updateARButtonVisibility()}}updateARButtonVisibility(){let t=this.hasAttribute("ar")&&!!Ge.arProvider,r=typeof this.querySelector=="function"?this.querySelector('[slot="ar-button"]'):null;r?(this.arButton&&(this.arButton.style.display="none"),r.__tlARBound||(r.__tlARBound=!0,r.addEventListener("click",i=>{i.stopPropagation(),this.activateAR()})),r.dataset.tlOrigDisplay===void 0&&(r.dataset.tlOrigDisplay=r.style.display==="none"?"":r.style.display),r.style.display=t?r.dataset.tlOrigDisplay||"":"none"):this.arButton&&(this.syncARButtonLabel(this.arButton),this.arButton.style.display=t?"flex":"none")}applyCameraOrbit(t){if(!(!t||!this.viewer))try{let r=JSON.parse(t);this.viewer.setInitialCamera(r.theta,r.phi,r.distance,r.zoom)}catch{let r=this.parseOrbitLimit(t);(r.theta!==void 0||r.phi!==void 0)&&this.viewer.setInitialCamera(r.theta,r.phi,r.distance)}}parseOrbitLimit(t){if(!t)return{};let[r,i,n]=t.trim().split(/\s+/),s=n&&n!=="auto"?parseFloat(n):NaN;return{theta:r&&r!=="auto"?this.parseFieldOfView(r):void 0,phi:i&&i!=="auto"?this.parseFieldOfView(i):void 0,distance:isNaN(s)?void 0:s}}applyOrbitLimits(){if(!this.viewer)return;let t=this.parseOrbitLimit(this.getAttr("min-camera-orbit")),r=this.parseOrbitLimit(this.getAttr("max-camera-orbit"));this.viewer.setOrbitLimits({minTheta:t.theta,maxTheta:r.theta,minPhi:t.phi,maxPhi:r.phi,minDistance:t.distance,maxDistance:r.distance})}parseCameraTarget(t){if(!t)return;let r=t.trim().split(/\s+/).map(parseFloat);return r.length>=3&&!r.some(isNaN)?[r[0],r[1],r[2]]:void 0}parseFieldOfView(t){if(!t)return;let r=parseFloat(t);return isNaN(r)?void 0:t.endsWith("rad")?r*180/Math.PI:r}parseRotationPerSecond(t){if(!t)return Math.PI/6;let r=t.trim(),i=parseFloat(r);return isNaN(i)?Math.PI/6:r.endsWith("rad")?i:r.endsWith("%")?i/100*Math.PI*2:i*Math.PI/180}applyCameraTarget(t){let r=this.parseCameraTarget(t);this.viewer&&r&&this.viewer.setTarget(r[0],r[1],r[2])}applyFieldOfView(t){let r=this.parseFieldOfView(t);this.viewer&&r!==void 0&&this.viewer.setFieldOfView(r)}updateHotspot(t){let r=this.querySelector(`[slot="${t.name}"]`);r&&(t.position!==void 0&&r.setAttribute("data-position",t.position),t.normal!==void 0&&r.setAttribute("data-normal",t.normal)),this.updateHotspots()}updateHotspots(){for(let t of Ke.getRegisteredPlugins())if(t.updateHotspotsForElement){t.updateHotspotsForElement(this,this.viewer);return}}runWithScriptRunner(t){let r=Ge.scriptRunner;if(!r){let s=new Error('Script execution requires "three-live/full" or registerScriptRunner().');return this.showToast(s.message),this.emitError(s,"script"),Promise.reject(s)}let i=this.beginLoad(),n=()=>!i.signal.aborted;return new Promise((s,l)=>{let o=()=>l(i.signal.reason);if(i.signal.addEventListener("abort",o,{once:!0}),!n()){o();return}let a={onModelReady:u=>{this.loadModelWithLimits(u,as,i).then(()=>s(u),l)},onUpdateTransforms:u=>{n()&&this.viewer?.updateMeshTransforms(u)},onError:u=>{n()&&(this.showToast(u.message),this.emitError(u,"script"),l(u))},onToast:u=>{n()&&this.showToast(u)}};t(r,a).then(u=>{n()?this.scriptHandle=u||null:u?.terminate()},u=>{n()&&a.onError?.(u)})})}loadScriptFromSrc(t){return this.runWithScriptRunner((r,i)=>{if(typeof r.executeUrl!="function"){let n=new Error("Registered ScriptRunner does not support executeUrl() for server-generated scripts.");return i.onError?.(n),Promise.reject(n)}return r.executeUrl(t,this.sandbox,i)})}executeScript(t){if(!Ge.scriptRunner)return this.runWithScriptRunner(()=>Promise.resolve());if(!this.allowClientScripts){let r=new Error(Qn);return this.showToast(Jn),this.emitError(r,"security"),Promise.reject(r)}return this.runWithScriptRunner((r,i)=>r.execute(t,this.sandbox,i,{allowClientScripts:!0}))}};ze.observedAttributes=["src","ios-src","script-src","sandbox","allow-client-scripts","poster","camera-controls","camera-orbit","camera-target","min-camera-orbit","max-camera-orbit","field-of-view","selected-mesh","ar","ar-modes","ar-scale","ar-placement","exposure","shadow-intensity","shadow-softness","tone-mapping","bloom","bloom-threshold","bloom-radius","outline","outline-selected","outline-color","environment-image","skybox-image","autoplay","animation-name","variant-name","auto-rotate","auto-rotate-delay","rotation-per-second"],ze.registerPlugin=Ke.registerPlugin,ze.getRegisteredPlugins=Ke.getRegisteredPlugins;var mt=ze;typeof customElements<"u"&&!customElements.get("three-live")&&customElements.define("three-live",mt);function $s(e="model-viewer"){return mt.defineModelViewer(e)}function Ws(e,t,r){return t%4===0?new Float32Array(e,t,r):new Float32Array(e.slice(t,t+r*4))}function oi(e,t,r,i){let n=t[0],s=t[1],l=t[2],o=t[3],a=r[0],u=r[1],h=r[2],m=r[3],c=n*a+s*u+l*h+o*m;if(c<0&&(a=-a,u=-u,h=-h,m=-m,c=-c),Math.abs(c)>=1)return e[0]=n,e[1]=s,e[2]=l,e[3]=o,e;let d=Math.acos(c),f=Math.sqrt(1-c*c);if(Math.abs(f)<.001)return e[0]=.5*(n+a),e[1]=.5*(s+u),e[2]=.5*(l+h),e[3]=.5*(o+m),e;let g=Math.sin((1-i)*d)/f,x=Math.sin(i*d)/f;return e[0]=n*g+a*x,e[1]=s*g+u*x,e[2]=l*g+h*x,e[3]=o*g+m*x,e}function js(e,t,r,i){return e[0]=t[0]+i*(r[0]-t[0]),e[1]=t[1]+i*(r[1]-t[1]),e[2]=t[2]+i*(r[2]-t[2]),e}function Ji(e,t){if(!Array.isArray(e?.animations))return[];let r=[];for(let i=0;i<e.animations.length;i++){let n=e.animations[i],s=n.name||`Animation_${i}`,l=[],o=0;if(Array.isArray(n.channels)&&Array.isArray(n.samplers))for(let a of n.channels){if(!a.target||a.target.node===void 0||!a.target.path)continue;let u=n.samplers[a.sampler];if(!u)continue;let h=e.accessors?.[u.input],m=e.accessors?.[u.output];if(!h||!m)continue;let c=e.bufferViews?.[h.bufferView],d=e.bufferViews?.[m.bufferView];if(!c||!d)continue;let f=(c.byteOffset||0)+(h.byteOffset||0),g=(d.byteOffset||0)+(m.byteOffset||0),x=bt(e,t,h,1)??Ws(t,f,h.count);x.length>0&&x[x.length-1]>o&&(o=x[x.length-1]);let b=a.target.path==="rotation"?4:a.target.path==="weights"?Math.max(1,Math.round(m.count/Math.max(1,h.count))):3,v=a.target.path==="weights"?1:b,p=bt(e,t,m,v)??Ws(t,g,m.count*v),y=u.interpolation==="STEP"?"STEP":"LINEAR";l.push({nodeIndex:a.target.node,path:a.target.path,times:x,values:p,interpolation:y})}l.length>0&&r.push({name:s,duration:o,channels:l})}return r}function fn(e,t,r){let{times:i,values:n,path:s,interpolation:l}=e,o=i.length;if(o===0)return;let a=s==="rotation"?4:s==="weights"?Math.max(1,Math.round(n.length/o)):3;if(t<=i[0]){for(let v=0;v<a;v++)r[v]=n[v];return}if(t>=i[o-1]){let v=(o-1)*a;for(let p=0;p<a;p++)r[p]=n[v+p];return}let u=0,h=o-1;for(;u<=h;){let v=u+h>>1;i[v]<=t?u=v+1:h=v-1}let m=Math.max(0,h),c=Math.min(o-1,m+1);if(l==="STEP"||m===c){let v=m*a;for(let p=0;p<a;p++)r[p]=n[v+p];return}let d=i[m],f=i[c],g=(t-d)/Math.max(1e-5,f-d),x=m*a,b=c*a;if(s==="rotation"){let v=[n[x],n[x+1],n[x+2],n[x+3]],p=[n[b],n[b+1],n[b+2],n[b+3]];oi(r,v,p,g)}else for(let v=0;v<a;v++)r[v]=n[x+v]+g*(n[b+v]-n[x+v])}var Xn=new WeakMap;function eo(e,t,r=.3){if(!e?.animations)return;let i=e.animations.find(o=>o.name===t);if(!i)return;let n=Xn.get(e);n||(n=[],e.currentClip&&n.push({clip:e.currentClip,time:e.animationTime||0,weight:1,fadeSpeed:0}),Xn.set(e,n));let s=r>0?1/r:1e3;for(let o of n)o.clip.name!==t&&(o.fadeSpeed=-s);let l=n.find(o=>o.clip.name===t);l?l.fadeSpeed=s:n.push({clip:i,time:0,weight:r>0?0:1,fadeSpeed:s}),e.currentClip=i,e.isPlayingAnimation=!0}function Zi(e,t){if(!e.gltf||!Array.isArray(e.gltf.nodes))return;let r=Xn.get(e);if(!r||r.length===0){if(!e.currentClip)return;r=[{clip:e.currentClip,time:t,weight:1,fadeSpeed:0}]}let i=e.gltf.nodes.length,n=[];for(let m=0;m<i;m++){let c=e.initialNodeTransforms[m];c?n.push({t:[c.t[0],c.t[1],c.t[2]],r:[c.r[0],c.r[1],c.r[2],c.r[3]],s:[c.s[0],c.s[1],c.s[2]]}):n.push({t:[0,0,0],r:[0,0,0,1],s:[1,1,1]})}let s=[0,0,0],l=[0,0,0,1],o=[1,1,1],a=new Float32Array(64);for(let m of r){let c=Math.max(0,Math.min(1,m.weight));if(!(c<=1e-4))for(let d of m.clip.channels){if(d.nodeIndex<0||d.nodeIndex>=i)continue;let f=n[d.nodeIndex];if(d.path==="translation")fn(d,m.time,s),js(f.t,f.t,s,c);else if(d.path==="rotation")fn(d,m.time,l),oi(f.r,f.r,l,c);else if(d.path==="scale")fn(d,m.time,o),js(f.s,f.s,o,c);else if(d.path==="weights"&&(fn(d,m.time,a),e.meshes)){for(let g of e.meshes)if(g.nodeIndex===d.nodeIndex){for(let x of g.primitives)if(x.pluginData?.morph?.weights){let b=x.pluginData.morph.weights,v=x.pluginData.morph.numTargets||b.length;for(let p=0;p<v;p++)b[p]=b[p]*(1-c)+a[p]*c}}}}}let u=[];for(let m=0;m<i;m++){let c=Se(),{t:d,r:f,s:g}=n[m];Tt(c,f,d,g),u.push(c)}let h=Ft(e.gltf,u);e.worldMatrices=h;for(let m of e.meshes)m.nodeIndex>=0&&m.nodeIndex<h.length&&(m.transform.set(h[m.nodeIndex]),Xe(m.normalMatrix,m.transform))}var Qi=e=>{Xn.delete(e)},to={name:"keyframes",evaluateAnimation:Zi,crossFadeTo:eo,onParseGLB(e){!e.animations&&e.gltf?.animations&&(e.animations=Ji(e.gltf,e.bin))},onLoadModel:Qi,onClearScene:Qi,onDestroy:(e,t)=>Qi(t),onUpdate(e,t){if(!e.isPlayingAnimation)return;let r=Xn.get(e);if(r&&r.length>0){for(let i=r.length-1;i>=0;i--){let n=r[i];if(n.time+=t,n.clip.duration>0&&(n.time%=n.clip.duration),n.fadeSpeed!==0)if(n.weight+=n.fadeSpeed*t,n.weight<=0){r.splice(i,1);continue}else n.weight>=1&&(n.weight=1,n.fadeSpeed=0)}r.length>0&&(e.animationTime=r[r.length-1].time),Zi(e,e.animationTime)}else e.currentClip&&(e.animationTime+=t,e.currentClip.duration>0&&(e.animationTime%=e.currentClip.duration),Zi(e,e.animationTime))}},$n=64;function Ks(e,t,r){if(!(!e?.meshes||t<0||t>=$n))for(let i of e.meshes)for(let n of i.primitives){let s=n.pluginData?.morph;s?.weights&&(s.weights[t]=r)}}var no={name:"morph",onResolveShader(e,t,r,i){if(!Array.isArray(e?.targets)||e.targets.length===0)return null;let n=r.replace("uniform mat4 uMVP,uModel;",`uniform mat4 uMVP,uModel;
353
380
  uniform sampler2D uMorphDeltasTex;
354
- uniform float uMorphWeights[${Xn}];
381
+ uniform float uMorphWeights[${$n}];
355
382
  uniform int uNumMorphTargets;`);return n=n.replace("vec4 world=uModel*vec4(aPosition,1.0);",`vec3 morphedPos = aPosition;
356
- for (int m = 0; m < ${Xn}; m++) {
383
+ for (int m = 0; m < ${$n}; m++) {
357
384
  if (m >= uNumMorphTargets) break;
358
385
  float w = uMorphWeights[m];
359
386
  if (abs(w) > 0.0001) {
360
387
  morphedPos += texelFetch(uMorphDeltasTex, ivec2(gl_VertexID, m), 0).xyz * w;
361
388
  }
362
389
  }
363
- vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.targets;if(!Array.isArray(s)||s.length===0)return null;let l=r.attributes?.POSITION,o=i?.accessors?.[l];if(!o)return null;let a=o.count,u=Math.min(s.length,Xn),h=new Float32Array(a*u*4);for(let p=0;p<u;p++){let m=s[p].POSITION;if(m===void 0)continue;let g=i.accessors?.[m],x=i.bufferViews?.[g?.bufferView];if(!g||!x)continue;let b=ut(i,n,g,3);if(!b||b.length<a*3)continue;let v=p*a*4;for(let d=0;d<a;d++)h[v+d*4]=b[d*3],h[v+d*4+1]=b[d*3+1],h[v+d*4+2]=b[d*3+2],h[v+d*4+3]=0}let c=e.createTexture();e.bindTexture(3553,c),e.texImage2D(3553,0,34836,a,u,0,6408,5126,h),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let f=new Float32Array(Xn);return{hasMorph:!0,morphTex:c,numTargets:u,vertexCount:a,weights:f}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.pluginData?.morph;if(!l?.hasMorph||!l.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,l.morphTex);let o=e.getUniformLocation(t,"uMorphDeltasTex");o&&e.uniform1i(o,5);let a=e.getUniformLocation(t,"uNumMorphTargets");a&&e.uniform1i(a,l.numTargets);let u=e.getUniformLocation(t,"uMorphWeights[0]");u&&e.uniform1fv(u,l.weights)}},ro=64,io={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
390
+ vec4 world=uModel*vec4(morphedPos,1.0);`).replace("gl_Position=uMVP*vec4(aPosition,1.0);","gl_Position=uMVP*vec4(morphedPos,1.0);"),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.targets;if(!Array.isArray(s)||s.length===0)return null;let l=r.attributes?.POSITION,o=i?.accessors?.[l];if(!o)return null;let a=o.count,u=Math.min(s.length,$n),h=new Float32Array(a*u*4);for(let d=0;d<u;d++){let f=s[d].POSITION;if(f===void 0)continue;let g=i.accessors?.[f],x=i.bufferViews?.[g?.bufferView];if(!g||!x)continue;let b=bt(i,n,g,3);if(!b||b.length<a*3)continue;let v=d*a*4;for(let p=0;p<a;p++)h[v+p*4]=b[p*3],h[v+p*4+1]=b[p*3+1],h[v+p*4+2]=b[p*3+2],h[v+p*4+3]=0}let m=e.createTexture();e.bindTexture(3553,m),e.texImage2D(3553,0,34836,a,u,0,6408,5126,h),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9728),e.texParameteri(3553,10240,9728);let c=new Float32Array($n);return{hasMorph:!0,morphTex:m,numTargets:u,vertexCount:a,weights:c}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.pluginData?.morph;if(!l?.hasMorph||!l.morphTex)return;e.activeTexture(33989),e.bindTexture(3553,l.morphTex);let o=e.getUniformLocation(t,"uMorphDeltasTex");o&&e.uniform1i(o,5);let a=e.getUniformLocation(t,"uNumMorphTargets");a&&e.uniform1i(a,l.numTargets);let u=e.getUniformLocation(t,"uMorphWeights[0]");u&&e.uniform1fv(u,l.weights)}},ro=64,io={name:"skinning",onResolveShader(e,t,r,i){if(e?.attributes?.JOINTS_0===void 0||e?.attributes?.WEIGHTS_0===void 0)return null;let n=r.replace("layout(location=2) in vec2 aUV;",`layout(location=2) in vec2 aUV;
364
391
  layout(location=4) in uvec4 aJoints;
365
392
  layout(location=5) in vec4 aWeights;
366
393
  uniform mat4 uJointMatrix[${ro}];`),s=n.includes("morphedPos")?"morphedPos":"aPosition";return n=n.replace(`vec4 world=uModel*vec4(${s},1.0);`,`mat4 skinMatrix =
@@ -368,11 +395,11 @@ uniform mat4 uJointMatrix[${ro}];`),s=n.includes("morphedPos")?"morphedPos":"aPo
368
395
  aWeights.y * uJointMatrix[int(aJoints.y)] +
369
396
  aWeights.z * uJointMatrix[int(aJoints.z)] +
370
397
  aWeights.w * uJointMatrix[int(aJoints.w)];
371
- vec4 world=uModel*(skinMatrix*vec4(${s},1.0));`).replace(`gl_Position=uMVP*vec4(${s},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${s},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.attributes;if(!s||s.JOINTS_0===void 0||s.WEIGHTS_0===void 0)return null;let l=i.accessors[s.JOINTS_0],o=i.accessors[s.WEIGHTS_0];if(!l||!o)return null;let a=i.bufferViews[l.bufferView],u=i.bufferViews[o.bufferView];if(!a||!u)return null;let h=(a.byteOffset||0)+(l.byteOffset||0),c=(u.byteOffset||0)+(o.byteOffset||0),f=e.createBuffer();e.bindBuffer(34962,f);let p=l.componentType===5121?5121:5123,m=p===5121?new Uint8Array(n,h,l.count*4):new Uint16Array(n,h,l.count*4);e.bufferData(34962,m,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,p,0,0);let g=e.createBuffer();e.bindBuffer(34962,g);let x=ut(i,n,o,4)??new Float32Array(n,c,o.count*4);return e.bufferData(34962,x,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[f,g]}},onBeforeDrawPrimitive(e,t,r,i,n,s){if(!r.pluginData?.skinning?.hasSkin)return;let l=s?.nodes?.[i.nodeIndex]?.skin;if(l===void 0||!s.skins||!s.skins[l])return;let o=s.skins[l].joints||[],a=new Float32Array(ro*16);for(let h=0;h<o.length&&h<ro;h++){let c=o[h],f=n[c]||Se();a.subarray(h*16,(h+1)*16).set(f)}let u=e.getUniformLocation(t,"uJointMatrix[0]");u&&e.uniformMatrix4fv(u,!1,a)}};Ue(no),Ue(to),Ue(io),Ue(Li),Ue(xi);var Hc=`#version 300 es
372
- layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,Xc=`#version 300 es
373
- precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,$n=new WeakMap,na=new Float32Array(20);function oo(e,t){let[r,i,n,s,l,o]=t;return[e[0]*r+e[4]*i+e[8]*n+e[12],e[1]*r+e[5]*i+e[9]*n+e[13],e[2]*r+e[6]*i+e[10]*n+e[14],Math.abs(e[0])*s+Math.abs(e[4])*l+Math.abs(e[8])*o,Math.abs(e[1])*s+Math.abs(e[5])*l+Math.abs(e[9])*o,Math.abs(e[2])*s+Math.abs(e[6])*l+Math.abs(e[10])*o]}function $c(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,n=-1e9,s=-1e9,l=-1e9;for(let o of e.primitives||[]){let a=o.positions;if(a)for(let u=0;u<a.length;u+=3)a[u]<t&&(t=a[u]),a[u+1]<r&&(r=a[u+1]),a[u+2]<i&&(i=a[u+2]),a[u]>n&&(n=a[u]),a[u+1]>s&&(s=a[u+1]),a[u+2]>l&&(l=a[u+2])}return e._lb=t<=n?[(t+n)*.5,(r+s)*.5,(i+l)*.5,(n-t)*.5,(s-r)*.5,(l-i)*.5]:null}function Wc(e){let t=$n.get(e);if(t)return t;let r=(o,a)=>{let u=e.createShader(o);return e.shaderSource(u,a),e.compileShader(u),u},i=e.createProgram();e.attachShader(i,r(35633,Hc)),e.attachShader(i,r(35632,Xc)),e.linkProgram(i);let n=e.createVertexArray(),s=e.createBuffer(),l=e.createBuffer();return e.bindVertexArray(n),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,l),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:n,vbo:s,ibo:l,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},$n.set(e,t),t}var Wn={name:"contact-shadow",onContextRestored(e){$n.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let n=Wc(e),s=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,l=[],o=[];for(let m of t.meshes||[]){if(!m||m.visible===!1||m.isPluginMesh||m.name==="__xr_reticle__"||m.name?.startsWith("__xr_slot_"))continue;let g=$c(m);if(!g)continue;m.transform&&(g=oo(m.transform,g)),t.modelRootMatrix&&(g=oo(t.modelRootMatrix,g));let[x,b,v,d,y,M]=g,T=[x,v,d,M,b-y,b+y];/floor|table|pedestal|ground|base|plane/i.test(m.name||"")||y<.14&&Math.min(d,M)>.45?o.push(T):l.push(T)}let a=[],u=t.bounds.center||[0,0,0],h=Math.max(.05,Number(t.bounds.radius)||.5),c=t.bounds.min,f=c?[u[0],u[1],u[2],h,Math.max(.01,u[1]-c[1]),h]:[u[0],u[1],u[2],h,h,h];t.modelRootMatrix&&(f=oo(t.modelRootMatrix,f));let p=t.xrSessionActive&&o.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:f[1]-f[4]+.002;for(let[m,g,x,b,v]of l){let d=-1/0;for(let[M,T,V,X,,P]of o)v>=P-.08&&Math.abs(m-M)<=V&&Math.abs(g-T)<=X&&P+.002>d&&(d=P+.002);s&&(d=Math.max(d,m>=.04&&m<=.36&&g>=-.34&&g<=-.04&&v>=.01?.036:Math.hypot(m,g)<=.66&&v>=-.06?.003:-.477)),isFinite(d)||(d=p);let y=a.find(M=>Math.hypot(m-M[0],g-M[1])<.06&&Math.abs(d-M[5])<.05);y?(y[2]=Math.max(y[2],x*.78),y[3]=Math.max(y[3],b*.78),y[4]=Math.min(y[4],v)):a.push([m,g,x,b,v,d])}if(a.length===0){let m=Math.max(.1,f[3]*1.5)/1.45;a.push([f[0],f[2],m,m,p,p])}e.useProgram(n.prog),e.uniformMatrix4fv(n.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(n.vao),e.bindBuffer(34962,n.vbo);for(let[m,g,x,b,v,d]of a){let y=Math.max(0,v-d),M=i/(1+y*2);if(M<.02)continue;let T=1+Math.min(.75,y*.85),V=Math.max(.045,x*1.45*T),X=Math.max(.045,b*1.45*T);na.set([m-V,d,g-X,0,0,m+V,d,g-X,1,0,m+V,d,g+X,1,1,m-V,d,g+X,0,1]),e.bufferSubData(34962,0,na),e.uniform1f(n.uIntensity,M),e.uniform1f(n.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,y*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=$n.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),$n.delete(e))}};function co(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let t=document.createElement("a");return t.relList!==void 0&&t.relList.supports!==void 0&&t.relList.supports("ar")}function uo(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function lo(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function oa(){return(await ii()).bestMode}async function ii(){let[e,t,r]=await Promise.all([lo(),Promise.resolve(co()),Promise.resolve(uo())]),i=[];t&&i.push("quick-look"),e&&i.push("webxr"),r&&i.push("scene-viewer");let n=null;return t?n="quick-look":e?n="webxr":r&&(n="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:r,availableModes:i,bestMode:n}}function ra(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let r,i=!1;if(typeof e=="string"){if(r=jc(e),!r)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else r=URL.createObjectURL(e),i=!0;let n=[];if(t.allowScale===!1&&n.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let o=ri(t.canonicalWebPageUrl,!1);o&&n.push(`canonicalWebPageURL=${encodeURIComponent(o)}`)}t.checkoutTitle&&n.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&n.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&n.push(`price=${encodeURIComponent(t.price)}`),n.length>0&&(r+=`#${n.join("&")}`);let s=document.createElement("a");s.setAttribute("rel","ar"),s.setAttribute("href",r);let l=document.createElement("img");l.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),l.style.display="none",s.appendChild(l),document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s),i&&URL.revokeObjectURL(r.split("#")[0])},3e3)}function ri(e,t=!1){if(typeof e!="string")return"";let r=e.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!r)return"";if(/^[\\/]{2}/.test(r))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${r.slice(0,32)}`);let i=r.toLowerCase();if(i.startsWith("https://")||i.startsWith("http://")||t&&i.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(r))return r;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${r.slice(0,32)}`)}function jc(e){try{return ri(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function Kc(e,t={}){let r=ri(e,!0),i=t.mode||"ar_preferred",n=new URLSearchParams({file:r,mode:i,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&n.set("title",t.title),t.link&&n.set("link",ri(t.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${n.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function qc(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let r=Kc(e,t);window.location.href=r}var $t=null;function Yc(e,t){let r=new Float32Array(144),i=new Float32Array(144),n=new Float32Array(96),s=new Uint16Array(144);for(let h=0;h<24;h++){let c=h/24*Math.PI*2,f=Math.cos(c),p=Math.sin(c),m=h*2,g=m+1,x=(h+1)%24*2;r[m*3]=f*.11,r[m*3+1]=.002,r[m*3+2]=p*.11,r[g*3]=f*.145,r[g*3+1]=.002,r[g*3+2]=p*.145,i[m*3+1]=i[g*3+1]=1,s.set([m,x,g,g,x,x+1],h*6)}let l=e.createVertexArray();e.bindVertexArray(l);let o=(h,c,f)=>{let p=e.createBuffer();return e.bindBuffer(34962,p),e.bufferData(34962,h,35044),e.enableVertexAttribArray(c),e.vertexAttribPointer(c,f,5126,!1,0,0),p},a=[o(r,0,3),o(i,1,3),o(n,2,2)],u=e.createBuffer();return a.push(u),e.bindBuffer(34963,u),e.bufferData(34963,s,35044),e.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:l,indexCount:s.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:s,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:a}]}}function ia(e,t,r,i,n){let s=Math.cos(i),l=Math.sin(i),o=Math.max(.01,n);e.fill(0),e[0]=o*s,e[2]=-o*l,e[5]=o,e[8]=o*l,e[10]=o*s,e[12]=t[0]-o*(s*r[0]+l*r[2]),e[13]=t[1]-o*r[1],e[14]=t[2]-o*(-l*r[0]+s*r[2]),e[15]=1}var ao=class{constructor(e={}){this.s=null,this.placed=!1,this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.cleanFn=null,this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,t){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");$t&&$t!==this&&$t.isSessionActive()&&await $t.stop().catch(()=>{});let r=navigator.xr,i=this.opts,n=t||e?.container,s=String(n?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,o=Number(l?.radius)||1,a=Array.isArray(l?.center)?l.center:[0,0,0],u=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],h=typeof navigator<"u"&&navigator.userAgent||"",c=/Android|iPhone|iPad|iPod/i.test(h)&&!/Quest|Oculus|Pico|Vision/i.test(h),f=s?i.arScale==="fixed"?1:c?.55:1:i.arScale==="fixed"?1:o>.45?.3/o:o<.05?.12/Math.max(o,.001):1,p=s?[0,-.25,0]:[a[0]||0,i.arPlacement==="wall"?a[1]:u[1]??0,a[2]||0],m="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(m="immersive-vr")}catch{m="immersive-vr"}let g=n?.querySelector?.('[slot="ar-overlay"]')||null,x=!1,b=null,v=()=>{x&&g?.parentNode&&g.parentNode.removeChild(g),g=null,b=null,x=!1};if(m==="immersive-ar"){if(g)g.addEventListener?.("beforexrselect",_=>_.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let _=document.createElement("div");_.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let H=document.createElement("button");H.type="button",H.textContent="\u2715 Exit AR",H.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",H.addEventListener("beforexrselect",D=>D.preventDefault()),H.addEventListener("click",D=>{D.stopPropagation(),this.stop().catch(()=>{})}),b=document.createElement("div"),b.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",b.textContent="Move phone to detect a surface \u2022 Tap to place",_.appendChild(H),_.appendChild(b),document.body.appendChild(_),g=_,x=!0}}let d=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),y={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(d)};g&&(d.add("dom-overlay"),y.optionalFeatures=Array.from(d),y.domOverlay={root:g});for(let _ of Oe)_.onConfigureXRSessionInit?.(n,y);Array.isArray(y.optionalFeatures)&&y.optionalFeatures.includes("dom-overlay")&&!y.domOverlay?.root&&(y.optionalFeatures=y.optionalFeatures.filter(_=>_!=="dom-overlay"));let M=_=>{let H=String(_?.name||"");return H==="NotAllowedError"||H==="SecurityError"};try{this.s=await r.requestSession(m,y)}catch(_){if(v(),M(_))throw i.onError?.(_),_;try{this.s=await r.requestSession(m,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(H){if(M(H))throw i.onError?.(H),H;try{this.s=await r.requestSession(m)}catch(D){throw i.onError?.(D),D}}}let T=this.s;$t=this,this.placed=!1;let V=null,X=null,P=null,R=null,C=null,B=[0,-.25,-1.2],N=[0,-.25,-1.2],w=new Float32Array(16),ie=new Float32Array(16),ae=!1,k=1,J=0,z=!1,Y=null,le=null,ce=0,$=null,U=()=>{$t===this&&($t=null),$?.(),$=null;try{X?.cancel?.()}catch{}if(X=null,P){let _=e?.meshes;if(Array.isArray(_)){let D=_.indexOf(P);D!==-1&&_.splice(D,1)}let H=e.getGLContext?.()||e?.gl;if(H)for(let D of P.primitives||[]){H.deleteVertexArray?.(D.vao);for(let F of D.buffers||[])H.deleteBuffer?.(F)}P=null}e?.setXRSessionActive?.(!1),v(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=U,T.addEventListener("end",()=>{U(),i.onExit?.()}),T.addEventListener("select",()=>{if(!this.placed){let _=C||B;N=[_[0],_[1],_[2]],ia(this.placedMat,N,p,J,f*k),this.placed=!0,P&&(P.visible=!1),b&&(b.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let _=e.getGLContext?.()||e?.gl;_&&typeof _.makeXRCompatible=="function"&&await _.makeXRCompatible();let H=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;_&&typeof H=="function"&&typeof T.updateRenderState=="function"&&T.updateRenderState({baseLayer:new H(T,_,{alpha:!0})});try{V=await T.requestReferenceSpace("local")}catch{try{V=await T.requestReferenceSpace("local-floor")}catch{V=await T.requestReferenceSpace("viewer")}}let D=await T.requestReferenceSpace("viewer").catch(()=>V);if(typeof T.requestHitTestSource=="function"&&D&&(X=await T.requestHitTestSource({space:D}).catch(()=>null)),m==="immersive-ar"&&_&&typeof _.createVertexArray=="function"&&Array.isArray(e.meshes)&&(P=Yc(_,i.reticleColor),e.meshes.push(P)),typeof window<"u"&&typeof window.addEventListener=="function"){let E=j=>Math.hypot(j.touches[1].clientX-j.touches[0].clientX,j.touches[1].clientY-j.touches[0].clientY),G=j=>Math.atan2(j.touches[1].clientY-j.touches[0].clientY,j.touches[1].clientX-j.touches[0].clientX),ee=j=>{this.s&&(j.touches.length===1&&this.placed?z=!0:j.touches.length>=2&&(z=!1,Y=E(j),le=G(j)))},se=j=>{if(!this.s||j.touches.length<2)return;let A=E(j),S=G(j);if(Y&&Y>4&&i.arScale!=="fixed"&&(k=Math.max(.15,Math.min(6,k*(A/Y)))),le!==null){let L=S-le;L>Math.PI&&(L-=Math.PI*2),L<-Math.PI&&(L+=Math.PI*2),J-=L}Y=A,le=S},oe=j=>{(!j.touches||j.touches.length===0)&&(z=!1),(!j.touches||j.touches.length<2)&&(Y=null,le=null)};window.addEventListener("touchstart",ee,{passive:!0}),window.addEventListener("touchmove",se,{passive:!0}),window.addEventListener("touchend",oe,{passive:!0}),window.addEventListener("touchcancel",oe,{passive:!0}),$=()=>{window.removeEventListener("touchstart",ee),window.removeEventListener("touchmove",se),window.removeEventListener("touchend",oe),window.removeEventListener("touchcancel",oe)}}e.setXRSessionActive?.(!0);let F=(E,G)=>{if(this.s!==T)return;T.requestAnimationFrame(F);let ee=ce>0?Math.min(Math.max((E-ce)/1e3,0),.1):1/60;ce=E,e?.stepXRUpdate?.(ee);let se=G.getViewerPose(V);if(!se)return;let oe=se.views?.[0];if(!ae&&oe?.transform){let I=oe.transform.position,W=oe.transform.matrix,Q=I?.x??(W?W[12]:0),K=I?.y??(W?W[13]:0),Z=I?.z??(W?W[14]:0),q=W?-W[8]:0,re=W?-W[10]:-1,ne=Math.hypot(q,re);ne>1e-4?(q/=ne,re/=ne):(q=0,re=-1),B=[Q+q*1.2,K-.25,Z+re*1.2],J=Math.atan2(-q,-re),ae=!0}if(X&&typeof G.getHitTestResults=="function"&&(!this.placed||z)){let I=G.getHitTestResults(X)||[],W=!1;for(let Q of I){let K=Q.getPose(V);if(K?.transform?.matrix){let Z=K.transform.matrix,q=Z[5];if(i.arPlacement==="wall"&&Math.abs(q)>.35||i.arPlacement==="floor"&&Math.abs(q)<.65)continue;R||(R=new Float32Array(16)),R.set(Z),C=[Z[12],Z[13],Z[14]],this.placed&&z&&(N=[Z[12],Z[13],Z[14]]),P&&(P.visible=!this.placed||z,P.transform.set(Z)),!this.placed&&b&&(b.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(R),W=!0;break}}!W&&P&&(P.visible=!1)}ia(w,this.placed?N:C||B,p,J,f*k),this.placed&&this.placedMat.set(w);let j=e.xrRigMatrix;j instanceof Float32Array&&j.length===16?Pe(ie,j,w):ie.set(w),e.modelRootMatrix&&e.modelRootMatrix.set(ie);for(let I of Oe)I.onXRFrame?.(e,T,G,V);let A=e.getGLContext?.()||e?.gl,S=T.renderState?.baseLayer;A&&S&&S.framebuffer!==void 0&&A.bindFramebuffer(36160,S.framebuffer);let L=m==="immersive-ar",O=se.views||[];for(let I=0;I<O.length;I++){let W=O[I];if(typeof e.renderXRView=="function"){let Q;if(S&&typeof S.getViewport=="function"){let K=S.getViewport(W);K&&K.width>0&&K.height>0&&(Q=[K.x,K.y,K.width,K.height])}else S?.framebufferWidth>0&&S?.framebufferHeight>0&&(Q=[0,0,S.framebufferWidth,S.framebufferHeight]);e.renderXRView(W,ie,this.placed,Q,L,I)}}A&&S&&S.framebuffer&&A.bindFramebuffer(36160,null)};T.requestAnimationFrame(F)}catch(_){throw typeof T.end=="function"&&await T.end().catch(()=>{}),U(),i.onError?.(_),_}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function oi(e){let t=await ii(),r=e.preferredModes||["quick-look","webxr","scene-viewer"],i=null;for(let o of r)if(t.availableModes.includes(o)){i=o;break}if(i||(i=t.bestMode),!i)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let n={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},s={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},l={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(i==="quick-look"){let o;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")o=e.model;else{if(typeof e.model=="string")return ra(e.model,n),{mode:"quick-look",success:!0};o=sn(e.model)}return ra(o,n),{mode:"quick-look",success:!0}}if(i==="scene-viewer"){let o=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!o)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return qc(o,s),{mode:"scene-viewer",success:!0}}if(i==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let o=new ao(l);return await o.start(e.view,e.element),{mode:"webxr",success:!0,session:o}}}catch(o){return{mode:i,success:!1,error:o}}return{mode:i,success:!1,error:new Error(`Unhandled AR mode: ${i}`)}}ft.registerAR({activateAR:oi,createUSDZBlob:sn}),ft.registerScriptRunner(ln),Ue(Wn);var fo=new WeakMap;function si(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);fo.set(e,r)}function ca(e){return fo.get(e)}async function Zc(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let n=await(await fetch(t)).blob();r=await createImageBitmap(n)}else if(typeof Image<"u")r=await new Promise((n,s)=>{let l=new Image;l.crossOrigin="anonymous",l.onload=()=>n(l),l.onerror=s,l.src=t});else return null;else r=t;let i=e.createTexture();return e.bindTexture(3553,i),e.texImage2D(3553,0,6408,6408,5121,r),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),i}var mo=new WeakMap,sa=new Float32Array(16);async function aa(e,t,r){let i=r?await Zc(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var ho={name:"environment-map",onContextRestored(e){mo.delete(e)},setEnvironmentImage(e,t){return aa(e,"environmentTexture",t)},setSkyboxImage(e,t){return aa(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,n){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=mo.get(t);if(!s){let c=(m,g)=>{let x=t.createShader(m);return t.shaderSource(x,g),t.compileShader(x),x},f=t.createProgram();t.attachShader(f,c(35633,`#version 300 es
374
- out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(f,c(35632,`#version 300 es
375
- precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(f);let p=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:f,vao:p},mo.set(t,s)}let l=tn(sa,r)||sa;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let o=t.getUniformLocation(s.program,"uSkyboxMap");o&&t.uniform1i(o,0);let a=t.getUniformLocation(s.program,"uInvVP");a&&t.uniformMatrix4fv(a,!1,l);let u=t.getUniformLocation(s.program,"uCameraPos");u&&t.uniform3f(u,i[0],i[1],i[2]);let h=t.getUniformLocation(s.program,"uExposure");h&&t.uniform1f(h,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let n=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
398
+ vec4 world=uModel*(skinMatrix*vec4(${s},1.0));`).replace(`gl_Position=uMVP*vec4(${s},1.0);`,`gl_Position=uMVP*(skinMatrix*vec4(${s},1.0));`),{vs:n,fs:i}},onBuildPrimitiveVAO(e,t,r,i,n){let s=r?.attributes;if(!s||s.JOINTS_0===void 0||s.WEIGHTS_0===void 0)return null;let l=i.accessors[s.JOINTS_0],o=i.accessors[s.WEIGHTS_0];if(!l||!o)return null;let a=i.bufferViews[l.bufferView],u=i.bufferViews[o.bufferView];if(!a||!u)return null;let h=(a.byteOffset||0)+(l.byteOffset||0),m=(u.byteOffset||0)+(o.byteOffset||0),c=e.createBuffer();e.bindBuffer(34962,c);let d=l.componentType===5121?5121:5123,f=d===5121?new Uint8Array(n,h,l.count*4):new Uint16Array(n,h,l.count*4);e.bufferData(34962,f,35044),e.enableVertexAttribArray(4),e.vertexAttribIPointer(4,4,d,0,0);let g=e.createBuffer();e.bindBuffer(34962,g);let x=bt(i,n,o,4)??new Float32Array(n,m,o.count*4);return e.bufferData(34962,x,35044),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,4,5126,!1,0,0),{hasSkin:!0,buffers:[c,g]}},onBeforeDrawPrimitive(e,t,r,i,n,s){if(!r.pluginData?.skinning?.hasSkin)return;let l=s?.nodes?.[i.nodeIndex]?.skin;if(l===void 0||!s.skins||!s.skins[l])return;let o=s.skins[l].joints||[],a=new Float32Array(ro*16);for(let h=0;h<o.length&&h<ro;h++){let m=o[h],c=n[m]||Se();a.subarray(h*16,(h+1)*16).set(c)}let u=e.getUniformLocation(t,"uJointMatrix[0]");u&&e.uniformMatrix4fv(u,!1,a)}};Ve(no),Ve(to),Ve(io),Ve(Di),Ve(Ti);var Uc=`#version 300 es
399
+ layout(location=0) in vec3 aPosition;layout(location=1) in vec2 aUV;uniform mat4 uMVP;out vec2 vUV;void main(){vUV=aUV;gl_Position=uMVP*vec4(aPosition,1.);}`,Fc=`#version 300 es
400
+ precision highp float;in vec2 vUV;uniform float uShadowIntensity,uShadowSoftness;out vec4 fragColor;void main(){vec2 p=(vUV-.5)*2.;float d=clamp(length(p),0.,1.);fragColor=vec4(0.,0.,0.,pow(1.-d*d,mix(1.2,2.8,uShadowSoftness))*smoothstep(1.,.85-uShadowSoftness*.6,d)*uShadowIntensity);}`,Wn=new WeakMap,qs=new Float32Array(20);function oo(e,t){let[r,i,n,s,l,o]=t;return[e[0]*r+e[4]*i+e[8]*n+e[12],e[1]*r+e[5]*i+e[9]*n+e[13],e[2]*r+e[6]*i+e[10]*n+e[14],Math.abs(e[0])*s+Math.abs(e[4])*l+Math.abs(e[8])*o,Math.abs(e[1])*s+Math.abs(e[5])*l+Math.abs(e[9])*o,Math.abs(e[2])*s+Math.abs(e[6])*l+Math.abs(e[10])*o]}function Vc(e){if(e._lb!==void 0)return e._lb;let t=1e9,r=1e9,i=1e9,n=-1e9,s=-1e9,l=-1e9;for(let o of e.primitives||[]){let a=o.positions;if(a)for(let u=0;u<a.length;u+=3)a[u]<t&&(t=a[u]),a[u+1]<r&&(r=a[u+1]),a[u+2]<i&&(i=a[u+2]),a[u]>n&&(n=a[u]),a[u+1]>s&&(s=a[u+1]),a[u+2]>l&&(l=a[u+2])}return e._lb=t<=n?[(t+n)*.5,(r+s)*.5,(i+l)*.5,(n-t)*.5,(s-r)*.5,(l-i)*.5]:null}function Bc(e){let t=Wn.get(e);if(t)return t;let r=(o,a)=>{let u=e.createShader(o);return e.shaderSource(u,a),e.compileShader(u),u},i=e.createProgram();e.attachShader(i,r(35633,Uc)),e.attachShader(i,r(35632,Fc)),e.linkProgram(i);let n=e.createVertexArray(),s=e.createBuffer(),l=e.createBuffer();return e.bindVertexArray(n),e.bindBuffer(34962,s),e.bufferData(34962,80,35048),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,5126,!1,20,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,5126,!1,20,12),e.bindBuffer(34963,l),e.bufferData(34963,new Uint16Array([0,1,2,0,2,3]),35044),e.bindVertexArray(null),t={prog:i,vao:n,vbo:s,ibo:l,uMVP:e.getUniformLocation(i,"uMVP"),uIntensity:e.getUniformLocation(i,"uShadowIntensity"),uSoftness:e.getUniformLocation(i,"uShadowSoftness")},Wn.set(e,t),t}var jn={name:"contact-shadow",onContextRestored(e){Wn.delete(e)},onAfterRender(e,t,r){let i=t.shadowIntensity;if(i<=0||!t.bounds)return;let n=Bc(e),s=!t.xrSessionActive&&(t.backdropMeshes?.length??0)>0,l=[],o=[];for(let f of t.meshes||[]){if(!f||f.visible===!1||f.isPluginMesh||f.name==="__xr_reticle__"||f.name?.startsWith("__xr_slot_"))continue;let g=Vc(f);if(!g)continue;f.transform&&(g=oo(f.transform,g)),t.modelRootMatrix&&(g=oo(t.modelRootMatrix,g));let[x,b,v,p,y,M]=g,P=[x,v,p,M,b-y,b+y];/floor|table|pedestal|ground|base|plane/i.test(f.name||"")||y<.14&&Math.min(p,M)>.45?o.push(P):l.push(P)}let a=[],u=t.bounds.center||[0,0,0],h=Math.max(.05,Number(t.bounds.radius)||.5),m=t.bounds.min,c=m?[u[0],u[1],u[2],h,Math.max(.01,u[1]-m[1]),h]:[u[0],u[1],u[2],h,h,h];t.modelRootMatrix&&(c=oo(t.modelRootMatrix,c));let d=t.xrSessionActive&&o.length===0&&String(t.container?.tagName||"").toLowerCase()==="xr-live"?(t.modelRootMatrix?t.modelRootMatrix[5]*-.25+t.modelRootMatrix[13]:-.25)+.002:c[1]-c[4]+.002;for(let[f,g,x,b,v]of l){let p=-1/0;for(let[M,P,F,W,,T]of o)v>=T-.08&&Math.abs(f-M)<=F&&Math.abs(g-P)<=W&&T+.002>p&&(p=T+.002);s&&(p=Math.max(p,f>=.04&&f<=.36&&g>=-.34&&g<=-.04&&v>=.01?.036:Math.hypot(f,g)<=.66&&v>=-.06?.003:-.477)),isFinite(p)||(p=d);let y=a.find(M=>Math.hypot(f-M[0],g-M[1])<.06&&Math.abs(p-M[5])<.05);y?(y[2]=Math.max(y[2],x*.78),y[3]=Math.max(y[3],b*.78),y[4]=Math.min(y[4],v)):a.push([f,g,x,b,v,p])}if(a.length===0){let f=Math.max(.1,c[3]*1.5)/1.45;a.push([c[0],c[2],f,f,d,d])}e.useProgram(n.prog),e.uniformMatrix4fv(n.uMVP,!1,r),e.enable(3042),(e.blendFuncSeparate||e.blendFunc).call(e,770,771,1,771),e.depthMask(!1),e.bindVertexArray(n.vao),e.bindBuffer(34962,n.vbo);for(let[f,g,x,b,v,p]of a){let y=Math.max(0,v-p),M=i/(1+y*2);if(M<.02)continue;let P=1+Math.min(.75,y*.85),F=Math.max(.045,x*1.45*P),W=Math.max(.045,b*1.45*P);qs.set([f-F,p,g-W,0,0,f+F,p,g-W,1,0,f+F,p,g+W,1,1,f-F,p,g+W,0,1]),e.bufferSubData(34962,0,qs),e.uniform1f(n.uIntensity,M),e.uniform1f(n.uSoftness,Math.min(1,t.shadowSoftness+Math.min(.45,y*.6))),e.drawElements(4,6,5123,0)}e.bindVertexArray(null),e.depthMask(!0),e.disable(3042)},onDestroy(e){let t=Wn.get(e);t&&(e.deleteVertexArray(t.vao),e.deleteBuffer(t.vbo),e.deleteBuffer(t.ibo),e.deleteProgram(t.prog),Wn.delete(e))}};function co(){if(typeof window>"u"||typeof navigator>"u")return!1;let e=navigator.userAgent||"";if(!(/iPad|iPhone|iPod/.test(e)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1))return!1;let t=document.createElement("a");return t.relList!==void 0&&t.relList.supports!==void 0&&t.relList.supports("ar")}function uo(){if(typeof navigator>"u")return!1;let e=navigator.userAgent||"";return/android/i.test(e)}async function lo(){if(typeof navigator>"u")return!1;let e=navigator;if(!e.xr||typeof e.xr.isSessionSupported!="function")return!1;try{return await e.xr.isSessionSupported("immersive-ar")?!0:await e.xr.isSessionSupported("immersive-vr")}catch{return!1}}async function Qs(){return(await ai()).bestMode}async function ai(){let[e,t,r]=await Promise.all([lo(),Promise.resolve(co()),Promise.resolve(uo())]),i=[];t&&i.push("quick-look"),e&&i.push("webxr"),r&&i.push("scene-viewer");let n=null;return t?n="quick-look":e?n="webxr":r&&(n="scene-viewer"),{webxr:e,quickLook:t,sceneViewer:r,availableModes:i,bestMode:n}}function Ys(e,t={}){if(typeof document>"u")throw new Error("launchQuickLook requires a browser DOM environment");let r,i=!1;if(typeof e=="string"){if(r=zc(e),!r)throw new Error("[XR-Live Security] Quick Look URL is empty.")}else r=URL.createObjectURL(e),i=!0;let n=[];if(t.allowScale===!1&&n.push("allowsContentScaling=0"),t.canonicalWebPageUrl){let o=si(t.canonicalWebPageUrl,!1);o&&n.push(`canonicalWebPageURL=${encodeURIComponent(o)}`)}t.checkoutTitle&&n.push(`checkoutTitle=${encodeURIComponent(t.checkoutTitle)}`),t.checkoutSubtitle&&n.push(`checkoutSubtitle=${encodeURIComponent(t.checkoutSubtitle)}`),t.price&&n.push(`price=${encodeURIComponent(t.price)}`),n.length>0&&(r+=`#${n.join("&")}`);let s=document.createElement("a");s.setAttribute("rel","ar"),s.setAttribute("href",r);let l=document.createElement("img");l.setAttribute("src","data:image/svg+xml;utf8,<svg/>"),l.style.display="none",s.appendChild(l),document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s),i&&URL.revokeObjectURL(r.split("#")[0])},3e3)}function si(e,t=!1){if(typeof e!="string")return"";let r=e.replace(/[\x00-\x1f\x7f]+/g,"").trim();if(!r)return"";if(/^[\\/]{2}/.test(r))throw new Error(`[XR-Live Security] Rejected protocol-relative URL in Scene Viewer intent: ${r.slice(0,32)}`);let i=r.toLowerCase();if(i.startsWith("https://")||i.startsWith("http://")||t&&i.startsWith("blob:")||!/^[a-z][a-z0-9+.-]*:/i.test(r))return r;throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Scene Viewer intent: ${r.slice(0,32)}`)}function zc(e){try{return si(e,!0)}catch{throw new Error(`[XR-Live Security] Rejected unsafe URL scheme in Quick Look launch: ${(e||"").trim().slice(0,32)}`)}}function Gc(e,t={}){let r=si(e,!0),i=t.mode||"ar_preferred",n=new URLSearchParams({file:r,mode:i,resizable:t.resizable!==!1?"true":"false",enable_vertical_placement:t.enableVerticalPlacement?"true":"false"});return t.title&&n.set("title",t.title),t.link&&n.set("link",si(t.link,!1)),`intent://arvr.google.com/scene-viewer/1.0?${n.toString()}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;end;`}function Hc(e,t={}){if(typeof window>"u")throw new Error("launchSceneViewer requires a browser environment");let r=Gc(e,t);window.location.href=r}var Xt=null;function Xc(e,t){let r=new Float32Array(144),i=new Float32Array(144),n=new Float32Array(96),s=new Uint16Array(144);for(let h=0;h<24;h++){let m=h/24*Math.PI*2,c=Math.cos(m),d=Math.sin(m),f=h*2,g=f+1,x=(h+1)%24*2;r[f*3]=c*.11,r[f*3+1]=.002,r[f*3+2]=d*.11,r[g*3]=c*.145,r[g*3+1]=.002,r[g*3+2]=d*.145,i[f*3+1]=i[g*3+1]=1,s.set([f,x,g,g,x,x+1],h*6)}let l=e.createVertexArray();e.bindVertexArray(l);let o=(h,m,c)=>{let d=e.createBuffer();return e.bindBuffer(34962,d),e.bufferData(34962,h,35044),e.enableVertexAttribArray(m),e.vertexAttribPointer(m,c,5126,!1,0,0),d},a=[o(r,0,3),o(i,1,3),o(n,2,2)],u=e.createBuffer();return a.push(u),e.bindBuffer(34963,u),e.bufferData(34963,s,35044),e.bindVertexArray(null),{name:"__xr_reticle__",nodeIndex:-1,worldSpace:!0,visible:!1,transform:new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),normalMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),primitives:[{vao:l,indexCount:s.length,indexType:5123,baseColor:t&&t.length>=3?[t[0],t[1],t[2],t[3]??.95]:[.22,.74,.97,.95],metallic:0,roughness:.2,positions:r,indices:s,texture:null,metallicRoughnessTexture:null,normalTexture:null,occlusionTexture:null,normalScale:1,occlusionStrength:1,buffers:a}]}}function Zs(e,t,r,i,n){let s=Math.cos(i),l=Math.sin(i),o=Math.max(.01,n);e.fill(0),e[0]=o*s,e[2]=-o*l,e[5]=o,e[8]=o*l,e[10]=o*s,e[12]=t[0]-o*(s*r[0]+l*r[2]),e[13]=t[1]-o*r[1],e[14]=t[2]-o*(-l*r[0]+s*r[2]),e[15]=1}var ao=class{constructor(e={}){this.s=null,this.placed=!1,this.placedMat=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),this.cleanFn=null,this.opts=e}isSessionActive(){return this.s!==null}hasPlacedModel(){return this.placed}getPlacedMatrix(){return this.placedMat}async start(e,t){if(typeof navigator>"u"||!navigator.xr)throw new Error("WebXR is not supported on this browser.");Xt&&Xt!==this&&Xt.isSessionActive()&&await Xt.stop().catch(()=>{});let r=navigator.xr,i=this.opts,n=t||e?.container,s=String(n?.tagName||"").toLowerCase()==="xr-live",l=e?.bounds,o=Number(l?.radius)||1,a=Array.isArray(l?.center)?l.center:[0,0,0],u=Array.isArray(l?.min)?l.min:[-.5,-.5,-.5],h=typeof navigator<"u"&&navigator.userAgent||"",m=/Android|iPhone|iPad|iPod/i.test(h)&&!/Quest|Oculus|Pico|Vision/i.test(h),c=s?i.arScale==="fixed"?1:m?.55:1:i.arScale==="fixed"?1:o>.45?.3/o:o<.05?.12/Math.max(o,.001):1,d=s?[0,-.25,0]:[a[0]||0,i.arPlacement==="wall"?a[1]:u[1]??0,a[2]||0],f="immersive-ar";try{await r.isSessionSupported("immersive-ar")||(f="immersive-vr")}catch{f="immersive-vr"}let g=n?.querySelector?.('[slot="ar-overlay"]')||null,x=!1,b=null,v=()=>{x&&g?.parentNode&&g.parentNode.removeChild(g),g=null,b=null,x=!1};if(f==="immersive-ar"){if(g)g.addEventListener?.("beforexrselect",_=>_.preventDefault());else if(typeof document<"u"&&document.body&&typeof document.createElement=="function"){let _=document.createElement("div");_.style.cssText="position:fixed;inset:0;pointer-events:none;background:transparent!important;z-index:2147483647;font-family:system-ui,sans-serif;user-select:none";let G=document.createElement("button");G.type="button",G.textContent="\u2715 Exit AR",G.style.cssText="position:absolute;top:max(16px,env(safe-area-inset-top,16px));right:16px;pointer-events:auto;padding:8px 14px;border-radius:99px;border:1px solid rgba(255,255,255,.3);background:rgba(15,23,42,.8);color:#f8fafc;font:600 13px system-ui,sans-serif",G.addEventListener("beforexrselect",j=>j.preventDefault()),G.addEventListener("click",j=>{j.stopPropagation(),this.stop().catch(()=>{})}),b=document.createElement("div"),b.style.cssText="position:absolute;bottom:max(28px,env(safe-area-inset-bottom,28px));left:50%;transform:translateX(-50%);padding:8px 15px;border-radius:99px;border:1px solid rgba(56,189,248,.4);background:rgba(15,23,42,.82);color:#f8fafc;font:500 12.5px system-ui,sans-serif;text-align:center;max-width:88vw",b.textContent="Move phone to detect a surface \u2022 Tap to place",_.appendChild(G),_.appendChild(b),document.body.appendChild(_),g=_,x=!0}}let p=new Set(i.optionalFeatures||["local","local-floor","hit-test","light-estimation"]),y={requiredFeatures:i.requiredFeatures?[...i.requiredFeatures]:[],optionalFeatures:Array.from(p)};g&&(p.add("dom-overlay"),y.optionalFeatures=Array.from(p),y.domOverlay={root:g});for(let _ of Oe)_.onConfigureXRSessionInit?.(n,y);Array.isArray(y.optionalFeatures)&&y.optionalFeatures.includes("dom-overlay")&&!y.domOverlay?.root&&(y.optionalFeatures=y.optionalFeatures.filter(_=>_!=="dom-overlay"));let M=_=>{let G=String(_?.name||"");return G==="NotAllowedError"||G==="SecurityError"};try{this.s=await r.requestSession(f,y)}catch(_){if(v(),M(_))throw i.onError?.(_),_;try{this.s=await r.requestSession(f,{requiredFeatures:[],optionalFeatures:["local","hit-test"]})}catch(G){if(M(G))throw i.onError?.(G),G;try{this.s=await r.requestSession(f)}catch(j){throw i.onError?.(j),j}}}let P=this.s;Xt=this,this.placed=!1;let F=null,W=null,T=null,E=null,S=null,O=[0,-.25,-1.2],k=[0,-.25,-1.2],w=new Float32Array(16),ie=new Float32Array(16),oe=!1,I=1,H=0,N=!1,z=null,ue=null,ce=0,B=null,$=()=>{Xt===this&&(Xt=null),B?.(),B=null;try{W?.cancel?.()}catch{}if(W=null,T){let _=e?.meshes;if(Array.isArray(_)){let j=_.indexOf(T);j!==-1&&_.splice(j,1)}let G=e.getGLContext?.()||e?.gl;if(G)for(let j of T.primitives||[]){G.deleteVertexArray?.(j.vao);for(let q of j.buffers||[])G.deleteBuffer?.(q)}T=null}e?.setXRSessionActive?.(!1),v(),this.s=null,this.placed=!1,this.cleanFn=null};this.cleanFn=$,P.addEventListener("end",()=>{$(),i.onExit?.()}),P.addEventListener("select",()=>{if(!this.placed){let _=S||O;k=[_[0],_[1],_[2]],Zs(this.placedMat,k,d,H,c*I),this.placed=!0,T&&(T.visible=!1),b&&(b.textContent="Placed \u2022 Drag to move \u2022 Pinch to scale"),i.onPlaced?.(this.placedMat)}});try{let _=e.getGLContext?.()||e?.gl;_&&typeof _.makeXRCompatible=="function"&&await _.makeXRCompatible();let G=typeof XRWebGLLayer<"u"?XRWebGLLayer:globalThis?.XRWebGLLayer;_&&typeof G=="function"&&typeof P.updateRenderState=="function"&&P.updateRenderState({baseLayer:new G(P,_,{alpha:!0})});try{F=await P.requestReferenceSpace("local")}catch{try{F=await P.requestReferenceSpace("local-floor")}catch{F=await P.requestReferenceSpace("viewer")}}let j=await P.requestReferenceSpace("viewer").catch(()=>F);if(typeof P.requestHitTestSource=="function"&&j&&(W=await P.requestHitTestSource({space:j}).catch(()=>null)),f==="immersive-ar"&&_&&typeof _.createVertexArray=="function"&&Array.isArray(e.meshes)&&(T=Xc(_,i.reticleColor),e.meshes.push(T)),typeof window<"u"&&typeof window.addEventListener=="function"){let D=V=>Math.hypot(V.touches[1].clientX-V.touches[0].clientX,V.touches[1].clientY-V.touches[0].clientY),Y=V=>Math.atan2(V.touches[1].clientY-V.touches[0].clientY,V.touches[1].clientX-V.touches[0].clientX),te=V=>{this.s&&(V.touches.length===1&&this.placed?N=!0:V.touches.length>=2&&(N=!1,z=D(V),ue=Y(V)))},se=V=>{if(!this.s||V.touches.length<2)return;let ee=D(V),R=Y(V);if(z&&z>4&&i.arScale!=="fixed"&&(I=Math.max(.15,Math.min(6,I*(ee/z)))),ue!==null){let A=R-ue;A>Math.PI&&(A-=Math.PI*2),A<-Math.PI&&(A+=Math.PI*2),H-=A}z=ee,ue=R},le=V=>{(!V.touches||V.touches.length===0)&&(N=!1),(!V.touches||V.touches.length<2)&&(z=null,ue=null)};window.addEventListener("touchstart",te,{passive:!0}),window.addEventListener("touchmove",se,{passive:!0}),window.addEventListener("touchend",le,{passive:!0}),window.addEventListener("touchcancel",le,{passive:!0}),B=()=>{window.removeEventListener("touchstart",te),window.removeEventListener("touchmove",se),window.removeEventListener("touchend",le),window.removeEventListener("touchcancel",le)}}e.setXRSessionActive?.(!0);let q=(D,Y)=>{if(this.s!==P)return;P.requestAnimationFrame(q);let te=ce>0?Math.min(Math.max((D-ce)/1e3,0),.1):1/60;ce=D,e?.stepXRUpdate?.(te);let se=Y.getViewerPose(F);if(!se)return;let le=se.views?.[0];if(!oe&&le?.transform){let C=le.transform.position,U=le.transform.matrix,Q=C?.x??(U?U[12]:0),X=C?.y??(U?U[13]:0),Z=C?.z??(U?U[14]:0),J=U?-U[8]:0,K=U?-U[10]:-1,ae=Math.hypot(J,K);ae>1e-4?(J/=ae,K/=ae):(J=0,K=-1),O=[Q+J*1.2,X-.25,Z+K*1.2],H=Math.atan2(-J,-K),oe=!0}if(W&&typeof Y.getHitTestResults=="function"&&(!this.placed||N)){let C=Y.getHitTestResults(W)||[],U=!1;for(let Q of C){let X=Q.getPose(F);if(X?.transform?.matrix){let Z=X.transform.matrix,J=Z[5];if(i.arPlacement==="wall"&&Math.abs(J)>.35||i.arPlacement==="floor"&&Math.abs(J)<.65)continue;E||(E=new Float32Array(16)),E.set(Z),S=[Z[12],Z[13],Z[14]],this.placed&&N&&(k=[Z[12],Z[13],Z[14]]),T&&(T.visible=!this.placed||N,T.transform.set(Z)),!this.placed&&b&&(b.textContent="Surface found \u2022 Tap to place \u2022 Pinch to scale"),i.onHit?.(E),U=!0;break}}!U&&T&&(T.visible=!1)}Zs(w,this.placed?k:S||O,d,H,c*I),this.placed&&this.placedMat.set(w);let V=e.xrRigMatrix;V instanceof Float32Array&&V.length===16?Ie(ie,V,w):ie.set(w),e.modelRootMatrix&&e.modelRootMatrix.set(ie);for(let C of Oe)C.onXRFrame?.(e,P,Y,F);let ee=e.getGLContext?.()||e?.gl,R=P.renderState?.baseLayer;ee&&R&&R.framebuffer!==void 0&&ee.bindFramebuffer(36160,R.framebuffer);let A=f==="immersive-ar",L=se.views||[];for(let C=0;C<L.length;C++){let U=L[C];if(typeof e.renderXRView=="function"){let Q;if(R&&typeof R.getViewport=="function"){let X=R.getViewport(U);X&&X.width>0&&X.height>0&&(Q=[X.x,X.y,X.width,X.height])}else R?.framebufferWidth>0&&R?.framebufferHeight>0&&(Q=[0,0,R.framebufferWidth,R.framebufferHeight]);e.renderXRView(U,ie,this.placed,Q,A,C)}}ee&&R&&R.framebuffer&&ee.bindFramebuffer(36160,null)};P.requestAnimationFrame(q)}catch(_){throw typeof P.end=="function"&&await P.end().catch(()=>{}),$(),i.onError?.(_),_}}async stop(){let e=this.s;if(e)try{await e.end()}catch{}finally{this.cleanFn?.()}else this.cleanFn?.()}};async function ci(e){let t=await ai(),r=e.preferredModes||["quick-look","webxr","scene-viewer"],i=null;for(let o of r)if(t.availableModes.includes(o)){i=o;break}if(i||(i=t.bestMode),!i)return{mode:"quick-look",success:!1,error:new Error("No augmented reality viewing mode is supported on this device.")};let n={...e.quickLookOptions,allowScale:e.arScale==="fixed"?!1:e.quickLookOptions?.allowScale},s={...e.sceneViewerOptions,resizable:e.arScale==="fixed"?!1:e.sceneViewerOptions?.resizable,enableVerticalPlacement:e.arPlacement==="wall"?!0:e.sceneViewerOptions?.enableVerticalPlacement},l={...e.webXROptions,arScale:e.arScale||e.webXROptions?.arScale,arPlacement:e.arPlacement||e.webXROptions?.arPlacement};try{if(i==="quick-look"){let o;if(e.model instanceof Blob&&e.model.type==="model/vnd.usdz+zip")o=e.model;else{if(typeof e.model=="string")return Ys(e.model,n),{mode:"quick-look",success:!0};o=on(e.model)}return Ys(o,n),{mode:"quick-look",success:!0}}if(i==="scene-viewer"){let o=e.glbUrl||(typeof e.model=="string"?e.model:null);if(!o)throw new Error("Scene Viewer requires a hosted GLB URL (glbUrl option).");return Hc(o,s),{mode:"scene-viewer",success:!0}}if(i==="webxr"){if(!e.view)throw new Error("WebXR AR mode requires an active ThreeView instance.");let o=new ao(l);return await o.start(e.view,e.element),{mode:"webxr",success:!0,session:o}}}catch(o){return{mode:i,success:!1,error:o}}return{mode:i,success:!1,error:new Error(`Unhandled AR mode: ${i}`)}}mt.registerAR({activateAR:ci,createUSDZBlob:on}),mt.registerScriptRunner(ln),Ve(jn);var fo=new WeakMap;function ui(e,t){let r=t instanceof Float32Array?t:new Float32Array(t);fo.set(e,r)}function ta(e){return fo.get(e)}async function $c(e,t){if(!t)return null;let r;if(typeof t=="string")if(typeof fetch<"u"&&typeof createImageBitmap=="function"){let n=await(await fetch(t)).blob();r=await createImageBitmap(n)}else if(typeof Image<"u")r=await new Promise((n,s)=>{let l=new Image;l.crossOrigin="anonymous",l.onload=()=>n(l),l.onerror=s,l.src=t});else return null;else r=t;let i=e.createTexture();return e.bindTexture(3553,i),e.texImage2D(3553,0,6408,6408,5121,r),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553),i}var mo=new WeakMap,Js=new Float32Array(16);async function ea(e,t,r){let i=r?await $c(e.gl,r):null;e[t]&&e.gl.deleteTexture(e[t]),e[t]=i}var ho={name:"environment-map",onContextRestored(e){mo.delete(e)},setEnvironmentImage(e,t){return ea(e,"environmentTexture",t)},setSkyboxImage(e,t){return ea(e,"skyboxTexture",t)},onBeforeDrawScene(e,t,r,i,n){if(!e.skyboxTexture||typeof t.createProgram!="function")return;let s=mo.get(t);if(!s){let m=(f,g)=>{let x=t.createShader(f);return t.shaderSource(x,g),t.compileShader(x),x},c=t.createProgram();t.attachShader(c,m(35633,`#version 300 es
401
+ out vec2 vNDC;void main(){vec2 p=vec2((gl_VertexID<<1)&2,gl_VertexID&2);vNDC=p*2.-1.;gl_Position=vec4(vNDC,.999999,1.);}`)),t.attachShader(c,m(35632,`#version 300 es
402
+ precision highp float;in vec2 vNDC;uniform mat4 uInvVP;uniform vec3 uCameraPos;uniform sampler2D uSkyboxMap;uniform float uExposure;out vec4 fragColor;vec2 eqUV(vec3 d){return vec2(atan(d.x,d.z)/6.2831853+.5,asin(clamp(d.y,-1.,1.))/3.1415926+.5);}void main(){vec4 fp=uInvVP*vec4(vNDC,1.,1.);vec3 dir=normalize(fp.xyz/fp.w-uCameraPos);fragColor=vec4(pow(texture(uSkyboxMap,eqUV(dir)).rgb*uExposure,vec3(1./2.2)),1.);}`)),t.linkProgram(c);let d=typeof t.createVertexArray=="function"?t.createVertexArray():null;s={program:c,vao:d},mo.set(t,s)}let l=en(Js,r)||Js;t.depthMask(!1),t.useProgram(s.program),s.vao&&t.bindVertexArray(s.vao),t.activeTexture(33984),t.bindTexture(3553,e.skyboxTexture);let o=t.getUniformLocation(s.program,"uSkyboxMap");o&&t.uniform1i(o,0);let a=t.getUniformLocation(s.program,"uInvVP");a&&t.uniformMatrix4fv(a,!1,l);let u=t.getUniformLocation(s.program,"uCameraPos");u&&t.uniform3f(u,i[0],i[1],i[2]);let h=t.getUniformLocation(s.program,"uExposure");h&&t.uniform1f(h,e.exposure??1),t.drawArrays(4,0,3),t.depthMask(!0)},onResolveShader(e,t,r,i){if(i.includes("evalSHIrradiance"))return null;let n=i.replace("out vec4 fragColor;",`uniform vec3 uSH[9];
376
403
  uniform int uHasSH;
377
404
  out vec4 fragColor;`).replace("void main(){",`vec3 integrateBRDFApprox(vec3 f0,float r,float NoV){vec4 c0=vec4(-1.,-.0275,-.572,.022),c1=vec4(1.,.0425,1.04,-.04),rv=r*c0+c1;float a=min(rv.x*rv.x,exp2(-9.28*NoV))*rv.x+rv.y;vec2 ab=vec2(-1.04,1.04)*a+rv.zw;return f0*ab.x+vec3(ab.y);}
378
405
  vec3 evalSHIrradiance(vec3 n){return max(vec3(0.),uSH[0]+uSH[1]*n.y+uSH[2]*n.z+uSH[3]*n.x+uSH[4]*(n.x*n.y)+uSH[5]*(n.y*n.z)+uSH[6]*(3.*n.z*n.z-1.)+uSH[7]*(n.x*n.z)+uSH[8]*(n.x*n.x-n.y*n.y));}
@@ -385,15 +412,15 @@ envDiffuse=uHasSH==1?evalSHIrradiance(N):textureLod(uEnvironmentMap,equirectangu
385
412
  }else if(uHasSH==1){
386
413
  specularIBL=getStudioRadiance(R,roughness)*integrateBRDFApprox(F,roughness,NoV);
387
414
  envDiffuse=evalSHIrradiance(N);
388
- }`),{vs:r,fs:n}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=fo.get(e),o=e.getUniformLocation(t,"uHasSH");if(l&&l.length>=27){o&&e.uniform1i(o,1);let a=e.getUniformLocation(t,"uSH");a&&e.uniform3fv(a,l)}else o&&e.uniform1i(o,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},po=new WeakMap;function bo(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let n=0;n<i.length;n++){let s=i[n],l=s.getAttribute("data-position");if(!l)continue;let o=l.trim().split(/\s+/).map(c=>parseFloat(c.replace(/m$/,"")));if(o.length<3||o.some(isNaN))continue;let a=s.getAttribute("data-normal"),u;if(a){let c=a.trim().split(/\s+/).map(f=>parseFloat(f));c.length>=3&&!c.some(isNaN)&&(u=[c[0],c[1],c[2]])}let h=r.projectPointToScreen([o[0],o[1],o[2]],u);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${h.x}px, ${h.y}px, 0)`,s.style.zIndex="3",h.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var yo={name:"hotspots",updateHotspotsForElement:bo,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{bo(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),po.set(e,t)},onCameraChange(e,t){t&&bo(t,e)},onElementDisconnected(e){let t=po.get(e);t&&(t.disconnect(),po.delete(e))}},ua=1024,go=256,ai=2048,Qc=128,Jc=64,eu=16,tu=1e4,nu=8,At=new Set(["__proto__","constructor","prototype"]),la={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},ma={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},ci={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},ui=(e,t)=>e!==null&&typeof e=="object"&&!At.has(t)&&Object.prototype.hasOwnProperty.call(e,t),rt=e=>Array.isArray(e)?[...e]:e,pa=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&ui(e,"value")?e.value:e,Ne=(e,t)=>ui(e.configuration,t)?pa(e.configuration[t]):void 0,he=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},Wt=e=>Math.max(0,Math.min(1,e)),st=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function jn(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||At.has(i)||At.has(r))return null;t.push(i)}return{segments:t}}var dn=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},fa=e=>{let t=he(e[0]),r=he(e[1]),i=he(e[2]),n=he(e[3],1),s=Math.hypot(t,r,i,n);return s>1e-8?[t/s,r/s,i/s,n/s]:[0,0,0,1]},da=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let n=[0,0,0,1];return ni(n,fa(e),fa(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},xo=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(he(i),he(t[n]))):Array.isArray(e)?e.map(i=>r(he(i),he(t))):Array.isArray(t)?t.map(i=>r(he(e),he(i))):r(he(e),he(t)),ru=(e,t)=>Array.isArray(e)?e.map(r=>t(he(r))):t(he(e)),ha=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,Kn=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>ua)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${ua})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>go)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${go})`);let s=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],o=new Map,a=new Map,u=new Map,h=new Map,c=new Map,f=new Map,p=[],m=[],g=new Map,x=1,b=0,v=0,d=0,y=0,M=!1,T=!1,V=!1;n.forEach(($,U)=>{if(!$||typeof $!="object")return;let _=rt(pa($.value));o.set(U,_);let H=$.id??$.name;typeof H=="string"&&H&&!At.has(H)&&o.set(H,_)}),(t?.nodes||[]).forEach(($,U)=>{for(let _ of $?.children||[])typeof _=="number"&&g.set(_,U)});let X=$=>$.op||typeof $.declaration=="number"&&s[$.declaration]?.op||"",P=($,U,_)=>{if(At.has(U))return;let H=a.get($);H||a.set($,H=Object.create(null)),H[U]=_},R=($,U)=>{if(typeof $!="number"&&typeof $!="string"||typeof $=="string"&&At.has($)||!o.has($)&&o.size>=go*2)return;let _=rt(U);if(o.set($,_),typeof $=="number"){let H=n[$]?.id??n[$]?.name;typeof H=="string"&&!At.has(H)&&o.set(H,_)}},C=$=>typeof $=="number"?l[$]?.id??String($):typeof $=="string"?/^\d+$/.test($)&&l[Number($)]?.id?l[Number($)].id:$:"",B=($,U)=>{for(let _=$,H=0;_!==void 0&&_>=0&&H<128;_=g.get(_),H++)if(_===U)return!0;return!1},N=$=>{for(let U=p.length-1;U>=0;U--)p[U].key===$&&p.splice(U,1)},w=$=>{N($.key),p.length>=Qc&&p.shift(),p.push($)},ie=$=>{let U=jn($)?.segments;if(U){if(U[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[dn(U[1],t.nodes.length)];if(!_)return;let H=U[2];if(H in ci){let D=ci[H],F=_[H]||D;return D.map((E,G)=>he(F[G],E))}if(H==="weights"){let D=Array.isArray(_.weights)?_.weights:[0],F=U.length===4?dn(U[3],64):-2;return F===-2?D.map(E=>he(E)):F>=0?he(D[F]):void 0}if(H==="visible"||H==="extensions"&&U[3]==="KHR_node_visibility"&&U[4]==="visible")return _.extensions?.KHR_node_visibility?.visible??_.visible??!0}else if(U[0]==="materials"&&Array.isArray(t?.materials)){let _=t.materials[dn(U[1],t.materials.length)];if(!_)return;let H=_.pbrMetallicRoughness||{};if(U[2]==="pbrMetallicRoughness"){if(U[3]==="baseColorFactor"){let D=H.baseColorFactor||[1,1,1,1];return[he(D[0],1),he(D[1],1),he(D[2],1),he(D[3],1)]}if(U[3]==="metallicFactor"||U[3]==="roughnessFactor")return he(H[U[3]],1)}if(U[2]==="emissiveFactor"){let D=_.emissiveFactor||[0,0,0];return[he(D[0]),he(D[1]),he(D[2])]}if(U[2]==="alphaCutoff")return he(_.alphaCutoff,.5)}}},ae=($,U)=>{let _=jn($)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let H=dn(_[1],t.nodes.length),D=t.nodes[H];if(!D)return!1;let F=_[2];if(F in ci&&Array.isArray(U)){let E=ci[F];if(U.length<E.length)return!1;let G=E.map((se,oe)=>he(U[oe],se));if(F==="rotation"){let se=Math.hypot(...G);G=se>1e-8?G.map(oe=>oe/se):[0,0,0,1]}D[F]=G,delete D.matrix;let ee=e?.initialNodeTransforms?.[H];return ee&&(ee[F[0]]=[...G]),M=!0,!0}if(F==="weights"){Array.isArray(D.weights)||(D.weights=[]);let E=(G,ee)=>{for(let se of e?.meshes||[])if(se.nodeIndex===H)for(let oe of se.primitives||[])oe.pluginData?.morph?.weights&&(oe.pluginData.morph.weights[G]=ee)};if(_.length===4){let G=dn(_[3],64);if(G<0)return!1;E(G,D.weights[G]=he(U))}else if(Array.isArray(U))D.weights=U.slice(0,64).map(G=>he(G)),D.weights.forEach((G,ee)=>E(ee,G));else return!1;return V=!0,!0}if(F==="visible"||F==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let E=st(U);return D.visible=E,(!D.extensions||typeof D.extensions!="object")&&(D.extensions={}),D.extensions.KHR_node_visibility={visible:E},T=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let H=dn(_[1],t.materials.length),D=t.materials[H];if(!D)return!1;let F=D.pbrMetallicRoughness||(D.pbrMetallicRoughness={}),E=G=>{for(let ee of e?.meshes||[])for(let se of ee.primitives||[])(se.materialIndex??0)===H&&G(se)};if(_[2]==="pbrMetallicRoughness"){if(_[3]==="baseColorFactor"&&Array.isArray(U)&&U.length>=3){let G=[Wt(he(U[0],1)),Wt(he(U[1],1)),Wt(he(U[2],1)),U[3]!==void 0?Wt(he(U[3],1)):F.baseColorFactor?.[3]??1];return F.baseColorFactor=G,E(ee=>ee.baseColor=[...G]),V=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let G=_[3]==="metallicFactor",ee=Wt(he(U,G?0:.5));return F[_[3]]=ee,E(se=>se[G?"metallic":"roughness"]=ee),V=!0}}if(_[2]==="emissiveFactor"&&Array.isArray(U)&&U.length>=3)return D.emissiveFactor=[0,1,2].map(G=>Math.max(0,he(U[G]))),V=!0;if(_[2]==="alphaCutoff")return D.alphaCutoff=Wt(he(U,.5)),V=!0}return!1},k=($,U,_=new Set)=>{let H=Ne(U,"pointer");if(typeof H!="string"||!H.startsWith("/"))return null;let D=H.replace(/\{([a-zA-Z0-9_]+)\}/g,(F,E)=>{let G=Math.trunc(Number(J($,E,void 0,_)??Ne(U,E)));return Number.isSafeInteger(G)&&G>=0?String(G):"-1"});return jn(D)?D:null},J=($,U,_,H)=>{let D=i[$]?.values;if(!ui(D,U))return _;let F=D[U];if(F==null)return _;if(typeof F!="object"||Array.isArray(F))return rt(F);let E=F;return typeof E.node=="number"?z(E.node,E.socket||"value",H):ui(E,"value")?rt(E.value):_},z=($,U,_)=>{if($<0||$>=i.length||_.has($)||_.size>128||++d>tu)return;let H=i[$],D=X(H);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(D))return rt(a.get($)?.[U]);_.add($);try{let F=(E,G=0)=>J($,E,G,_);if(D==="variable/get"){let E=Ne(H,"variable")??Ne(H,"id");return typeof E=="number"||typeof E=="string"?rt(o.get(E)):void 0}if(D==="pointer/get"){let E=k($,H,_);return E?ie(E):void 0}if(D.startsWith("math/")){let E=D.slice(5);if(E in la)return ru(F("a"),la[E]);if(E in ma){let G=/^(mul|div|rem|mod|pow)$/.test(E)?1:0;return xo(F("a",E==="mul"?1:0),F("b",G),ma[E])}if(E==="pi")return Math.PI;if(E==="e")return Math.E;if(E==="random")return Math.random();if(E==="clamp")return xo(xo(F("a"),F("b",F("min",0)),Math.max),F("c",F("max",1)),Math.min);if(E==="mix"||E==="quatSlerp")return da(F("a",0),F("b",1),he(F("c",F("t",.5)),.5),E==="quatSlerp");if(E==="dot"){let G=F("a"),ee=F("b");return Array.isArray(G)&&Array.isArray(ee)?G.reduce((se,oe,j)=>se+(oe||0)*(ee[j]||0),0):he(G)*he(ee)}if(E==="cross"){let G=F("a",[0,0,0]),ee=F("b",[0,0,0]);return Array.isArray(G)&&Array.isArray(ee)?[(G[1]||0)*(ee[2]||0)-(G[2]||0)*(ee[1]||0),(G[2]||0)*(ee[0]||0)-(G[0]||0)*(ee[2]||0),(G[0]||0)*(ee[1]||0)-(G[1]||0)*(ee[0]||0)]:[0,0,0]}if(E==="length"){let G=F("a");return Array.isArray(G)?Math.hypot(...G):Math.abs(he(G))}if(E==="distance"){let G=F("a"),ee=F("b");return Array.isArray(G)&&Array.isArray(ee)?Math.hypot(...G.map((se,oe)=>(se||0)-(ee[oe]||0))):Math.abs(he(G)-he(ee))}if(E==="normalize"){let G=F("a");if(!Array.isArray(G))return he(G)>=0?1:-1;let ee=Math.hypot(...G);return ee>1e-8?G.map(se=>se/ee):G.map(()=>0)}if(E.startsWith("combine"))return["a","b","c","d"].slice(0,Number(E[7])||2).map(G=>he(F(G)));if(E.startsWith("extract")){let G=F("a");return Array.isArray(G)?G[U==="0"||U==="x"?0:U==="1"||U==="y"?1:U==="2"||U==="z"?2:3]??0:0}if(E==="eq")return ha(F("a"),F("b"));if(E==="ne")return!ha(F("a"),F("b"));if(E==="lt")return he(F("a"))<he(F("b"));if(E==="le")return he(F("a"))<=he(F("b"));if(E==="gt")return he(F("a"))>he(F("b"));if(E==="ge")return he(F("a"))>=he(F("b"));if(E==="isNaN")return Number.isNaN(Number(F("a")));if(E==="isInf"){let G=Number(F("a"));return!Number.isFinite(G)&&!Number.isNaN(G)}return E==="and"?st(F("a",!1))&&st(F("b",!1)):E==="or"?st(F("a",!1))||st(F("b",!1)):E==="xor"?st(F("a",!1))!==st(F("b",!1)):E==="not"?!st(F("a",!1)):E==="select"?rt(st(F("condition",!1))?F("a"):F("b")):void 0}return D==="type/boolToInt"||D==="type/boolToFloat"?st(F("a",!1))?1:0:D==="type/intToBool"||D==="type/floatToBool"?he(F("a",0))!==0:D==="type/intToFloat"?he(F("a",0)):D==="type/floatToInt"?Math.trunc(he(F("a",0))):void 0}finally{_.delete($)}},Y=()=>{if(M){M=!1,V=!0;let $=Vt(t);if(e){e.worldMatrices=$;for(let U of e.meshes||[])U.nodeIndex>=0&&U.nodeIndex<$.length&&(U.transform.set($[U.nodeIndex]),ze(U.normalMatrix,U.transform))}}if(T){T=!1,V=!0;let $=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray($))for(let U of e.meshes){let _=!0;for(let H=U.nodeIndex,D=0;H!==void 0&&H>=0&&D<128;H=g.get(H),D++){let F=$[H];if(F?.visible===!1||F?.extensions?.KHR_node_visibility?.visible===!1){_=!1;break}}U.visible=_}}V&&(V=!1,e?.render?.())},le=($,U={steps:0})=>{if(!$||typeof $.node!="number")return;U.steps===0&&(d=0);let _=[$],H=D=>{_.length+U.steps<ai&&_.push(D)};for(;_.length>0&&U.steps<ai;){U.steps++;let D=_.shift();if(!D||D.node<0||D.node>=i.length)continue;let F=D.node,E=i[F];if(!E)continue;let G=D.socket||"in",ee=X(E),se=(j,A=void 0)=>J(F,j,A,new Set),oe=(j="out")=>{let A=E.flows?.[j];A&&H(A)};switch(ee){case"flow/branch":oe(st(se("condition",!1))?"true":"false");break;case"flow/sequence":for(let j of Object.keys(E.flows||{}).sort((A,S)=>Number(A)-Number(S)||A.localeCompare(S)))oe(j);break;case"flow/switch":{let j=E.flows?.[String(se("selection",se("value",0)))]??E.flows?.default;j&&H(j);break}case"flow/for":{let j=Math.trunc(he(se("startIndex",0))),A=Math.trunc(he(se("endIndex",0))),S=Math.max(1,Math.trunc(he(se("step",1),1))),L=E.flows?.body;if(L&&A>j&&y<nu){let I=Math.min(Math.ceil((A-j)/S),ai);y++;try{for(let W=0;W<I&&U.steps<ai;W++)P(F,"index",j+W*S),le(L,U)}finally{y--}}let O=E.flows?.completed??E.flows?.out;O&&H(O);break}case"flow/doN":{let j=G==="reset"?0:(u.get(F)||0)+1;if(u.set(F,j),P(F,"currentCount",j),P(F,"count",j),G!=="reset"){let A=Math.trunc(he(se("n",Ne(E,"stopIterations")??Ne(E,"n")??1),1));j<=A&&oe()}break}case"flow/multiGate":{if(G==="reset"){f.set(F,0);break}let j=Object.keys(E.flows||{}).sort();if(!j.length)break;let A=Ne(E,"isRandom")?Math.floor(Math.random()*j.length):f.get(F)||0;A<j.length&&(oe(j[A]),f.set(F,Ne(E,"isLoop")!==!1?(A+1)%j.length:A+1));break}case"flow/waitAll":{if(G==="reset"){h.delete(F);break}let j=h.get(F);j||h.set(F,j=new Set),j.add(G),j.size>=Math.max(1,Math.trunc(Number(Ne(E,"inputFlows")??2)||2))&&(j.clear(),oe("out"),oe("completed"));break}case"flow/throttle":{if(G==="reset"){c.delete(F);break}let j=Math.max(0,he(se("duration",0))),A=c.get(F);A===void 0||b-A>=j?(c.set(F,b),P(F,"lastRemainingTime",0),oe()):P(F,"lastRemainingTime",Math.max(0,j-(b-A)));break}case"flow/delay":case"flow/setDelay":{if(G==="cancel"){for(let L=m.length-1;L>=0;L--)m[L].nodeIdx===F&&m.splice(L,1);P(F,"lastDelayIndex",-1);break}let j=Math.max(0,he(se("duration",Ne(E,"duration")??0))),A=E.flows?.done??E.flows?.out;if(j<=0){P(F,"lastDelayIndex",-1),A&&H(A);break}m.length>=Jc&&m.shift();let S=x++;P(F,"lastDelayIndex",S),m.push({id:S,nodeIdx:F,rem:j,done:A}),ee==="flow/setDelay"&&E.flows?.out&&E.flows?.done&&oe("out");break}case"flow/cancelDelay":{let j=Math.trunc(he(se("delayIndex",-1),-1));if(j<0)m.length=0;else for(let A=m.length-1;A>=0;A--)m[A].id===j&&m.splice(A,1);oe();break}case"variable/set":R(Ne(E,"variable")??Ne(E,"id"),se("value")),oe();break;case"variable/interpolate":{let j=Ne(E,"variable")??Ne(E,"id"),A=se("value",se("target")),S=Math.max(0,he(se("duration",Ne(E,"duration")??.3),.3));j!==void 0&&A!==void 0&&w({key:`var:${String(j)}`,varKey:j,from:rt(se("from")??o.get(j)??0),to:rt(A),dur:S,elapsed:0,quat:!1,linear:Ne(E,"easing")==="linear",done:E.flows?.done}),oe();break}case"pointer/set":{let j=k(F,E),A=se("value");j&&A!==void 0&&(N(`ptr:${j}`),ae(j,A)),oe();break}case"pointer/interpolate":{let j=k(F,E),A=se("value",se("target")),S=Math.max(0,he(se("duration",Ne(E,"duration")??.3),.3));if(j&&A!==void 0){let L=se("from")??ie(j);L!==void 0&&(S<=0?(ae(j,A),oe("done")):w({key:`ptr:${j}`,ptr:j,from:rt(L),to:rt(A),dur:S,elapsed:0,quat:j.endsWith("/rotation"),linear:Ne(E,"easing")==="linear",done:E.flows?.done}))}oe();break}case"animation/start":{let j=se("animation")??Ne(E,"animation")??Ne(E,"clipName"),A=typeof j=="number"?e?.animations?.[j]?.name??t?.animations?.[j]?.name:typeof j=="string"?j:void 0;e?.playAnimation?.(A),V=!0,oe();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),ee==="animation/resetAt"&&e?.evaluateAnimation?.(he(se("time",0))),V=!0,oe();break;case"event/send":case"customEvent/send":{let j=C(Ne(E,"event")??Ne(E,"id")),A={};for(let S of Object.keys(E.values||{}))At.has(S)||(A[S]=se(S));j&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:j,values:A}})),ce(j,A,U)),oe();break}default:oe();break}}};this.readScenePointer=ie,this.writeScenePointer=ae,this.fireOnStart=()=>{i.forEach($=>{X($)==="event/onStart"&&le($.flows?.out)}),Y()},this.fireOnSelect=$=>{if(!$)return;let U=typeof $.meshIndex=="number"?$.meshIndex:-1,_=typeof $.nodeIndex=="number"?$.nodeIndex:e?.meshes?.[U]?.nodeIndex??-1;i.forEach((H,D)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(X(H)))return;let F=Ne(H,"nodeIndex")??Ne(H,"node")??J(D,"nodeIndex",void 0,new Set),E=Ne(H,"meshName");if(typeof E=="string"&&E?$.meshName===E:F==null||Number(F)<0||Number.isNaN(Number(F))||B(_,Math.trunc(Number(F)))){if(P(D,"nodeIndex",_),P(D,"meshIndex",U),Array.isArray($.hitPoint)){let G=[he($.hitPoint[0]),he($.hitPoint[1]),he($.hitPoint[2])];P(D,"hitPoint",G),P(D,"point",G),P(D,"intersectionPoint",G)}if(Array.isArray($.normal)){let G=[he($.normal[0]),he($.normal[1],1),he($.normal[2])];P(D,"normal",G),P(D,"hitNormal",G)}typeof $.distance=="number"&&P(D,"distance",$.distance),le(H.flows?.out)}}),Y()},this.receiveCustomEvent=($,U={})=>ce($,U,{steps:0});function ce($,U,_){if(!(v>=eu)){v++;try{let H=C($);i.forEach((D,F)=>{if(!/^(customE|e)vent\/receive$/.test(X(D)))return;let E=Ne(D,"event")??Ne(D,"id");if(!(C(E)!==H&&String(E)!==String($))){for(let[G,ee]of Object.entries(U))At.has(G)||P(F,G,rt(ee));le(D.flows?.out,_)}}),Y()}finally{v--}}}this.tick=$=>{if(!Number.isFinite($)||$<0)return;let U=Math.min($,.25);b+=U,i.forEach((H,D)=>{X(H)==="event/onTick"&&(P(D,"timeDelta",U),P(D,"dt",U),P(D,"timeElapsed",b),le(H.flows?.out))});let _=[];for(let H=p.length-1;H>=0;H--){let D=p[H];D.elapsed+=U;let F=D.dur>1e-6?Wt(D.elapsed/D.dur):1,E=D.linear?F:F*F*(3-2*F),G=da(D.from,D.to,E,D.quat);D.ptr?ae(D.ptr,G):D.varKey!==void 0&&R(D.varKey,G),F>=1&&(p.splice(H,1),D.done&&_.push(D.done))}for(let H=m.length-1;H>=0;H--){let D=m[H];D.rem-=U,D.rem<=0&&(m.splice(H,1),D.done&&_.push(D.done))}for(let H of _)le(H);Y()},this.dispose=()=>{p.length=0,m.length=0,o.clear(),a.clear(),u.clear(),h.clear(),c.clear(),f.clear()}}},dt=new WeakMap,li=new WeakMap;function iu(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||er().some(o=>o.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let n=Math.min(t,.1),s=(li.get(e)||0)+n,l=!1;for(let o=0;o<i.length;o++){let a=i[o],u=Rs(a?.extras?.xr?.orbit);if(!u)continue;let h=0,c=0,f=0;if(Array.isArray(u.target))h=u.target[0],c=u.target[1],f=u.target[2];else if(typeof u.target=="string"&&u.target!=="head"){let b=i.find(v=>v?.name===u.target);Array.isArray(b?.translation)&&(h=he(b.translation[0]),c=he(b.translation[1]),f=he(b.translation[2]))}let p=u.phase+u.speed*s,m=h+Math.cos(p)*u.radius,g=c+u.height,x=f+Math.sin(p)*u.radius;if(a.translation=[m,g,x],u.faceCenter){let b=Math.atan2(h-m,f-x);a.rotation=[0,Math.sin(b*.5),0,Math.cos(b*.5)]}l=!0}if(l){li.set(e,s);let o=Vt(r);e.worldMatrices=o;for(let a of e.meshes||[])a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),ze(a.normalMatrix,a.transform))}}function mi(e){if(!(!e||typeof e!="object"))return dt.get(e)||dt.get(e.viewer)||dt.get(e._view)}function vo(e,t,r){let i=mi(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var Mo={name:"khr-interactivity",sendInteractivityEvent:vo,getInteractivityVM:mi,onLoadModel(e,t){if(!e||typeof e!="object")return;dt.get(e)?.dispose(),dt.delete(e),li.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let n=new Kn(e,t,i);dt.set(e,n),n.fireOnStart()},onMeshSelect(e,t){dt.get(e)?.fireOnSelect(t)},onUpdate(e,t){dt.get(e)?.tick(t),iu(e,t)},onDestroy(e,t){dt.get(t)?.dispose(),dt.delete(t),li.delete(t)}},qn=new Map,fi=new WeakMap;function ba(e,t){qn.set(e,t)}var To={name:"materials",onContextRestored(e){fi.delete(e)},onBuildPrimitiveVAO(e,t,r,i,n){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=fi.get(e);r||(r=e.createTexture(),fi.set(e,r));let i=Math.max(1,t.canvas.width),n=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,n,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&qn.has(t.name)){let m=qn.get(t.name);return{vs:m.vs||r,fs:m.fs||i}}let n=t.extensions||{},s=n.KHR_materials_clearcoat,l=n.KHR_materials_sheen,o=!!n.KHR_materials_transmission,a=!!n.KHR_materials_ior,u=n.KHR_materials_iridescence;if(!s&&!l&&!n.KHR_materials_unlit&&!o&&!n.KHR_materials_volume&&!a&&!n.KHR_materials_dispersion&&!u)return null;if(n.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let h=i;if(o){let m=h.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
415
+ }`),{vs:r,fs:n}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=fo.get(e),o=e.getUniformLocation(t,"uHasSH");if(l&&l.length>=27){o&&e.uniform1i(o,1);let a=e.getUniformLocation(t,"uSH");a&&e.uniform3fv(a,l)}else o&&e.uniform1i(o,0)},onAttributeChanged(e,t,r,i){t==="environment-image"&&e.viewer?this.setEnvironmentImage?.(e.viewer,i):t==="skybox-image"&&e.viewer&&this.setSkyboxImage?.(e.viewer,i)}},po=new WeakMap;function bo(e,t){let r=t||e.viewer;if(!r||typeof r.projectPointToScreen!="function")return;let i=e.mockHotspots||e.querySelectorAll('[slot^="hotspot-"], [data-position]');for(let n=0;n<i.length;n++){let s=i[n],l=s.getAttribute("data-position");if(!l)continue;let o=l.trim().split(/\s+/).map(m=>parseFloat(m.replace(/m$/,"")));if(o.length<3||o.some(isNaN))continue;let a=s.getAttribute("data-normal"),u;if(a){let m=a.trim().split(/\s+/).map(c=>parseFloat(c));m.length>=3&&!m.some(isNaN)&&(u=[m[0],m[1],m[2]])}let h=r.projectPointToScreen([o[0],o[1],o[2]],u);s.style.position="absolute",s.style.left="0",s.style.top="0",s.style.transform=`translate(-50%, -50%) translate3d(${h.x}px, ${h.y}px, 0)`,s.style.zIndex="3",h.visible?(s.style.opacity="1",s.style.pointerEvents="auto",s.removeAttribute("data-occluded")):(s.style.opacity="0",s.style.pointerEvents="none",s.setAttribute("data-occluded",""))}}var yo={name:"hotspots",updateHotspotsForElement:bo,onElementConnected(e){if(typeof MutationObserver>"u"||!e)return;let t=new MutationObserver(()=>{bo(e)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["data-position","data-normal"]}),po.set(e,t)},onCameraChange(e,t){t&&bo(t,e)},onElementDisconnected(e){let t=po.get(e);t&&(t.disconnect(),po.delete(e))}},na=1024,go=256,li=2048,Wc=128,jc=64,Kc=16,qc=1e4,Yc=8,Rt=new Set(["__proto__","constructor","prototype"]),ra={neg:e=>-e,abs:Math.abs,sign:Math.sign,floor:Math.floor,ceil:Math.ceil,round:Math.round,trunc:Math.trunc,fract:e=>e-Math.floor(e),sqrt:e=>Math.sqrt(Math.max(0,e)),cbrt:Math.cbrt,exp:Math.exp,log:e=>e>0?Math.log(e):0,sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:e=>Math.asin(Math.max(-1,Math.min(1,e))),acos:e=>Math.acos(Math.max(-1,Math.min(1,e))),atan:Math.atan,rad:e=>e*Math.PI/180,deg:e=>e*180/Math.PI,saturate:e=>Math.max(0,Math.min(1,e))},ia={add:(e,t)=>e+t,sub:(e,t)=>e-t,mul:(e,t)=>e*t,div:(e,t)=>Math.abs(t)<1e-12?0:e/t,rem:(e,t)=>Math.abs(t)<1e-12?0:e%t,mod:(e,t)=>Math.abs(t)<1e-12?0:e%t,min:Math.min,max:Math.max,pow:Math.pow,atan2:Math.atan2},mi={translation:[0,0,0],rotation:[0,0,0,1],scale:[1,1,1]},fi=(e,t)=>e!==null&&typeof e=="object"&&!Rt.has(t)&&Object.prototype.hasOwnProperty.call(e,t),it=e=>Array.isArray(e)?[...e]:e,ca=e=>e!==null&&typeof e=="object"&&!Array.isArray(e)&&fi(e,"value")?e.value:e,De=(e,t)=>fi(e.configuration,t)?ca(e.configuration[t]):void 0,he=(e,t=0)=>{let r=Number(e);return Number.isFinite(r)?r:t},$t=e=>Math.max(0,Math.min(1,e)),ft=e=>typeof e=="boolean"?e:typeof e=="number"?e!==0&&!Number.isNaN(e):typeof e=="string"?e.length>0&&e!=="false":!!e;function Kn(e){if(typeof e!="string"||!e.startsWith("/"))return null;let t=[];for(let r of e.slice(1).split("/")){let i=r.replace(/~1/g,"/").replace(/~0/g,"~");if(!i||Rt.has(i)||Rt.has(r))return null;t.push(i)}return{segments:t}}var dn=(e,t)=>{if(e===void 0||!/^\d+$/.test(e))return-1;let r=Number(e);return Number.isSafeInteger(r)&&r>=0&&r<t?r:-1},oa=e=>{let t=he(e[0]),r=he(e[1]),i=he(e[2]),n=he(e[3],1),s=Math.hypot(t,r,i,n);return s>1e-8?[t/s,r/s,i/s,n/s]:[0,0,0,1]},sa=(e,t,r,i)=>{if(typeof e=="number"&&typeof t=="number")return e+(t-e)*r;if(Array.isArray(e)&&Array.isArray(t)){if(i&&e.length===4&&t.length===4){let n=[0,0,0,1];return oi(n,oa(e),oa(t),r),n}return e.slice(0,t.length).map((n,s)=>n+(t[s]-n)*r)}return r>=.5?t:e},xo=(e,t,r)=>Array.isArray(e)&&Array.isArray(t)?e.slice(0,t.length).map((i,n)=>r(he(i),he(t[n]))):Array.isArray(e)?e.map(i=>r(he(i),he(t))):Array.isArray(t)?t.map(i=>r(he(e),he(i))):r(he(e),he(t)),Zc=(e,t)=>Array.isArray(e)?e.map(r=>t(he(r))):t(he(e)),aa=(e,t)=>Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((r,i)=>Math.abs(r-t[i])<=1e-6):e===t,qn=class{constructor(e,t,r){let i=Array.isArray(r.nodes)?r.nodes:[];if(i.length>na)throw new Error(`SecurityError: Exceeds MAX_GRAPH_NODES (${na})`);let n=Array.isArray(r.variables)?r.variables:[];if(n.length>go)throw new Error(`SecurityError: Exceeds MAX_VARIABLES (${go})`);let s=Array.isArray(r.declarations)?r.declarations:[],l=Array.isArray(r.events)?r.events:[],o=new Map,a=new Map,u=new Map,h=new Map,m=new Map,c=new Map,d=[],f=[],g=new Map,x=1,b=0,v=0,p=0,y=0,M=!1,P=!1,F=!1;n.forEach((B,$)=>{if(!B||typeof B!="object")return;let _=it(ca(B.value));o.set($,_);let G=B.id??B.name;typeof G=="string"&&G&&!Rt.has(G)&&o.set(G,_)}),(t?.nodes||[]).forEach((B,$)=>{for(let _ of B?.children||[])typeof _=="number"&&g.set(_,$)});let W=B=>B.op||typeof B.declaration=="number"&&s[B.declaration]?.op||"",T=(B,$,_)=>{if(Rt.has($))return;let G=a.get(B);G||a.set(B,G=Object.create(null)),G[$]=_},E=(B,$)=>{if(typeof B!="number"&&typeof B!="string"||typeof B=="string"&&Rt.has(B)||!o.has(B)&&o.size>=go*2)return;let _=it($);if(o.set(B,_),typeof B=="number"){let G=n[B]?.id??n[B]?.name;typeof G=="string"&&!Rt.has(G)&&o.set(G,_)}},S=B=>typeof B=="number"?l[B]?.id??String(B):typeof B=="string"?/^\d+$/.test(B)&&l[Number(B)]?.id?l[Number(B)].id:B:"",O=(B,$)=>{for(let _=B,G=0;_!==void 0&&_>=0&&G<128;_=g.get(_),G++)if(_===$)return!0;return!1},k=B=>{for(let $=d.length-1;$>=0;$--)d[$].key===B&&d.splice($,1)},w=B=>{k(B.key),d.length>=Wc&&d.shift(),d.push(B)},ie=B=>{let $=Kn(B)?.segments;if($){if($[0]==="nodes"&&Array.isArray(t?.nodes)){let _=t.nodes[dn($[1],t.nodes.length)];if(!_)return;let G=$[2];if(G in mi){let j=mi[G],q=_[G]||j;return j.map((D,Y)=>he(q[Y],D))}if(G==="weights"){let j=Array.isArray(_.weights)?_.weights:[0],q=$.length===4?dn($[3],64):-2;return q===-2?j.map(D=>he(D)):q>=0?he(j[q]):void 0}if(G==="visible"||G==="extensions"&&$[3]==="KHR_node_visibility"&&$[4]==="visible")return _.extensions?.KHR_node_visibility?.visible??_.visible??!0}else if($[0]==="materials"&&Array.isArray(t?.materials)){let _=t.materials[dn($[1],t.materials.length)];if(!_)return;let G=_.pbrMetallicRoughness||{};if($[2]==="pbrMetallicRoughness"){if($[3]==="baseColorFactor"){let j=G.baseColorFactor||[1,1,1,1];return[he(j[0],1),he(j[1],1),he(j[2],1),he(j[3],1)]}if($[3]==="metallicFactor"||$[3]==="roughnessFactor")return he(G[$[3]],1)}if($[2]==="emissiveFactor"){let j=_.emissiveFactor||[0,0,0];return[he(j[0]),he(j[1]),he(j[2])]}if($[2]==="alphaCutoff")return he(_.alphaCutoff,.5)}}},oe=(B,$)=>{let _=Kn(B)?.segments;if(!_)return!1;if(_[0]==="nodes"&&Array.isArray(t?.nodes)){let G=dn(_[1],t.nodes.length),j=t.nodes[G];if(!j)return!1;let q=_[2];if(q in mi&&Array.isArray($)){let D=mi[q];if($.length<D.length)return!1;let Y=D.map((se,le)=>he($[le],se));if(q==="rotation"){let se=Math.hypot(...Y);Y=se>1e-8?Y.map(le=>le/se):[0,0,0,1]}j[q]=Y,delete j.matrix;let te=e?.initialNodeTransforms?.[G];return te&&(te[q[0]]=[...Y]),M=!0,!0}if(q==="weights"){Array.isArray(j.weights)||(j.weights=[]);let D=(Y,te)=>{for(let se of e?.meshes||[])if(se.nodeIndex===G)for(let le of se.primitives||[])le.pluginData?.morph?.weights&&(le.pluginData.morph.weights[Y]=te)};if(_.length===4){let Y=dn(_[3],64);if(Y<0)return!1;D(Y,j.weights[Y]=he($))}else if(Array.isArray($))j.weights=$.slice(0,64).map(Y=>he(Y)),j.weights.forEach((Y,te)=>D(te,Y));else return!1;return F=!0,!0}if(q==="visible"||q==="extensions"&&_[3]==="KHR_node_visibility"&&_[4]==="visible"){let D=ft($);return j.visible=D,(!j.extensions||typeof j.extensions!="object")&&(j.extensions={}),j.extensions.KHR_node_visibility={visible:D},P=!0,!0}}else if(_[0]==="materials"&&Array.isArray(t?.materials)){let G=dn(_[1],t.materials.length),j=t.materials[G];if(!j)return!1;let q=j.pbrMetallicRoughness||(j.pbrMetallicRoughness={}),D=Y=>{for(let te of e?.meshes||[])for(let se of te.primitives||[])(se.materialIndex??0)===G&&Y(se)};if(_[2]==="pbrMetallicRoughness"){if(_[3]==="baseColorFactor"&&Array.isArray($)&&$.length>=3){let Y=[$t(he($[0],1)),$t(he($[1],1)),$t(he($[2],1)),$[3]!==void 0?$t(he($[3],1)):q.baseColorFactor?.[3]??1];return q.baseColorFactor=Y,D(te=>te.baseColor=[...Y]),F=!0}if(_[3]==="metallicFactor"||_[3]==="roughnessFactor"){let Y=_[3]==="metallicFactor",te=$t(he($,Y?0:.5));return q[_[3]]=te,D(se=>se[Y?"metallic":"roughness"]=te),F=!0}}if(_[2]==="emissiveFactor"&&Array.isArray($)&&$.length>=3)return j.emissiveFactor=[0,1,2].map(Y=>Math.max(0,he($[Y]))),F=!0;if(_[2]==="alphaCutoff")return j.alphaCutoff=$t(he($,.5)),F=!0}return!1},I=(B,$,_=new Set)=>{let G=De($,"pointer");if(typeof G!="string"||!G.startsWith("/"))return null;let j=G.replace(/\{([a-zA-Z0-9_]+)\}/g,(q,D)=>{let Y=Math.trunc(Number(H(B,D,void 0,_)??De($,D)));return Number.isSafeInteger(Y)&&Y>=0?String(Y):"-1"});return Kn(j)?j:null},H=(B,$,_,G)=>{let j=i[B]?.values;if(!fi(j,$))return _;let q=j[$];if(q==null)return _;if(typeof q!="object"||Array.isArray(q))return it(q);let D=q;return typeof D.node=="number"?N(D.node,D.socket||"value",G):fi(D,"value")?it(D.value):_},N=(B,$,_)=>{if(B<0||B>=i.length||_.has(B)||_.size>128||++p>qc)return;let G=i[B],j=W(G);if(/^(event\/|pointer\/on|scene\/on|flow\/)/.test(j))return it(a.get(B)?.[$]);_.add(B);try{let q=(D,Y=0)=>H(B,D,Y,_);if(j==="variable/get"){let D=De(G,"variable")??De(G,"id");return typeof D=="number"||typeof D=="string"?it(o.get(D)):void 0}if(j==="pointer/get"){let D=I(B,G,_);return D?ie(D):void 0}if(j.startsWith("math/")){let D=j.slice(5);if(D in ra)return Zc(q("a"),ra[D]);if(D in ia){let Y=/^(mul|div|rem|mod|pow)$/.test(D)?1:0;return xo(q("a",D==="mul"?1:0),q("b",Y),ia[D])}if(D==="pi")return Math.PI;if(D==="e")return Math.E;if(D==="random")return Math.random();if(D==="clamp")return xo(xo(q("a"),q("b",q("min",0)),Math.max),q("c",q("max",1)),Math.min);if(D==="mix"||D==="quatSlerp")return sa(q("a",0),q("b",1),he(q("c",q("t",.5)),.5),D==="quatSlerp");if(D==="dot"){let Y=q("a"),te=q("b");return Array.isArray(Y)&&Array.isArray(te)?Y.reduce((se,le,V)=>se+(le||0)*(te[V]||0),0):he(Y)*he(te)}if(D==="cross"){let Y=q("a",[0,0,0]),te=q("b",[0,0,0]);return Array.isArray(Y)&&Array.isArray(te)?[(Y[1]||0)*(te[2]||0)-(Y[2]||0)*(te[1]||0),(Y[2]||0)*(te[0]||0)-(Y[0]||0)*(te[2]||0),(Y[0]||0)*(te[1]||0)-(Y[1]||0)*(te[0]||0)]:[0,0,0]}if(D==="length"){let Y=q("a");return Array.isArray(Y)?Math.hypot(...Y):Math.abs(he(Y))}if(D==="distance"){let Y=q("a"),te=q("b");return Array.isArray(Y)&&Array.isArray(te)?Math.hypot(...Y.map((se,le)=>(se||0)-(te[le]||0))):Math.abs(he(Y)-he(te))}if(D==="normalize"){let Y=q("a");if(!Array.isArray(Y))return he(Y)>=0?1:-1;let te=Math.hypot(...Y);return te>1e-8?Y.map(se=>se/te):Y.map(()=>0)}if(D.startsWith("combine"))return["a","b","c","d"].slice(0,Number(D[7])||2).map(Y=>he(q(Y)));if(D.startsWith("extract")){let Y=q("a");return Array.isArray(Y)?Y[$==="0"||$==="x"?0:$==="1"||$==="y"?1:$==="2"||$==="z"?2:3]??0:0}if(D==="eq")return aa(q("a"),q("b"));if(D==="ne")return!aa(q("a"),q("b"));if(D==="lt")return he(q("a"))<he(q("b"));if(D==="le")return he(q("a"))<=he(q("b"));if(D==="gt")return he(q("a"))>he(q("b"));if(D==="ge")return he(q("a"))>=he(q("b"));if(D==="isNaN")return Number.isNaN(Number(q("a")));if(D==="isInf"){let Y=Number(q("a"));return!Number.isFinite(Y)&&!Number.isNaN(Y)}return D==="and"?ft(q("a",!1))&&ft(q("b",!1)):D==="or"?ft(q("a",!1))||ft(q("b",!1)):D==="xor"?ft(q("a",!1))!==ft(q("b",!1)):D==="not"?!ft(q("a",!1)):D==="select"?it(ft(q("condition",!1))?q("a"):q("b")):void 0}return j==="type/boolToInt"||j==="type/boolToFloat"?ft(q("a",!1))?1:0:j==="type/intToBool"||j==="type/floatToBool"?he(q("a",0))!==0:j==="type/intToFloat"?he(q("a",0)):j==="type/floatToInt"?Math.trunc(he(q("a",0))):void 0}finally{_.delete(B)}},z=()=>{if(M){M=!1,F=!0;let B=Ft(t);if(e){e.worldMatrices=B;for(let $ of e.meshes||[])$.nodeIndex>=0&&$.nodeIndex<B.length&&($.transform.set(B[$.nodeIndex]),Xe($.normalMatrix,$.transform))}}if(P){P=!1,F=!0;let B=t?.nodes;if(Array.isArray(e?.meshes)&&Array.isArray(B))for(let $ of e.meshes){let _=!0;for(let G=$.nodeIndex,j=0;G!==void 0&&G>=0&&j<128;G=g.get(G),j++){let q=B[G];if(q?.visible===!1||q?.extensions?.KHR_node_visibility?.visible===!1){_=!1;break}}$.visible=_}}F&&(F=!1,e?.render?.())},ue=(B,$={steps:0})=>{if(!B||typeof B.node!="number")return;$.steps===0&&(p=0);let _=[B],G=j=>{_.length+$.steps<li&&_.push(j)};for(;_.length>0&&$.steps<li;){$.steps++;let j=_.shift();if(!j||j.node<0||j.node>=i.length)continue;let q=j.node,D=i[q];if(!D)continue;let Y=j.socket||"in",te=W(D),se=(V,ee=void 0)=>H(q,V,ee,new Set),le=(V="out")=>{let ee=D.flows?.[V];ee&&G(ee)};switch(te){case"flow/branch":le(ft(se("condition",!1))?"true":"false");break;case"flow/sequence":for(let V of Object.keys(D.flows||{}).sort((ee,R)=>Number(ee)-Number(R)||ee.localeCompare(R)))le(V);break;case"flow/switch":{let V=D.flows?.[String(se("selection",se("value",0)))]??D.flows?.default;V&&G(V);break}case"flow/for":{let V=Math.trunc(he(se("startIndex",0))),ee=Math.trunc(he(se("endIndex",0))),R=Math.max(1,Math.trunc(he(se("step",1),1))),A=D.flows?.body;if(A&&ee>V&&y<Yc){let C=Math.min(Math.ceil((ee-V)/R),li);y++;try{for(let U=0;U<C&&$.steps<li;U++)T(q,"index",V+U*R),ue(A,$)}finally{y--}}let L=D.flows?.completed??D.flows?.out;L&&G(L);break}case"flow/doN":{let V=Y==="reset"?0:(u.get(q)||0)+1;if(u.set(q,V),T(q,"currentCount",V),T(q,"count",V),Y!=="reset"){let ee=Math.trunc(he(se("n",De(D,"stopIterations")??De(D,"n")??1),1));V<=ee&&le()}break}case"flow/multiGate":{if(Y==="reset"){c.set(q,0);break}let V=Object.keys(D.flows||{}).sort();if(!V.length)break;let ee=De(D,"isRandom")?Math.floor(Math.random()*V.length):c.get(q)||0;ee<V.length&&(le(V[ee]),c.set(q,De(D,"isLoop")!==!1?(ee+1)%V.length:ee+1));break}case"flow/waitAll":{if(Y==="reset"){h.delete(q);break}let V=h.get(q);V||h.set(q,V=new Set),V.add(Y),V.size>=Math.max(1,Math.trunc(Number(De(D,"inputFlows")??2)||2))&&(V.clear(),le("out"),le("completed"));break}case"flow/throttle":{if(Y==="reset"){m.delete(q);break}let V=Math.max(0,he(se("duration",0))),ee=m.get(q);ee===void 0||b-ee>=V?(m.set(q,b),T(q,"lastRemainingTime",0),le()):T(q,"lastRemainingTime",Math.max(0,V-(b-ee)));break}case"flow/delay":case"flow/setDelay":{if(Y==="cancel"){for(let A=f.length-1;A>=0;A--)f[A].nodeIdx===q&&f.splice(A,1);T(q,"lastDelayIndex",-1);break}let V=Math.max(0,he(se("duration",De(D,"duration")??0))),ee=D.flows?.done??D.flows?.out;if(V<=0){T(q,"lastDelayIndex",-1),ee&&G(ee);break}f.length>=jc&&f.shift();let R=x++;T(q,"lastDelayIndex",R),f.push({id:R,nodeIdx:q,rem:V,done:ee}),te==="flow/setDelay"&&D.flows?.out&&D.flows?.done&&le("out");break}case"flow/cancelDelay":{let V=Math.trunc(he(se("delayIndex",-1),-1));if(V<0)f.length=0;else for(let ee=f.length-1;ee>=0;ee--)f[ee].id===V&&f.splice(ee,1);le();break}case"variable/set":E(De(D,"variable")??De(D,"id"),se("value")),le();break;case"variable/interpolate":{let V=De(D,"variable")??De(D,"id"),ee=se("value",se("target")),R=Math.max(0,he(se("duration",De(D,"duration")??.3),.3));V!==void 0&&ee!==void 0&&w({key:`var:${String(V)}`,varKey:V,from:it(se("from")??o.get(V)??0),to:it(ee),dur:R,elapsed:0,quat:!1,linear:De(D,"easing")==="linear",done:D.flows?.done}),le();break}case"pointer/set":{let V=I(q,D),ee=se("value");V&&ee!==void 0&&(k(`ptr:${V}`),oe(V,ee)),le();break}case"pointer/interpolate":{let V=I(q,D),ee=se("value",se("target")),R=Math.max(0,he(se("duration",De(D,"duration")??.3),.3));if(V&&ee!==void 0){let A=se("from")??ie(V);A!==void 0&&(R<=0?(oe(V,ee),le("done")):w({key:`ptr:${V}`,ptr:V,from:it(A),to:it(ee),dur:R,elapsed:0,quat:V.endsWith("/rotation"),linear:De(D,"easing")==="linear",done:D.flows?.done}))}le();break}case"animation/start":{let V=se("animation")??De(D,"animation")??De(D,"clipName"),ee=typeof V=="number"?e?.animations?.[V]?.name??t?.animations?.[V]?.name:typeof V=="string"?V:void 0;e?.playAnimation?.(ee),F=!0,le();break}case"animation/stop":case"animation/resetAt":e?.pauseAnimation?.(),te==="animation/resetAt"&&e?.evaluateAnimation?.(he(se("time",0))),F=!0,le();break;case"event/send":case"customEvent/send":{let V=S(De(D,"event")??De(D,"id")),ee={};for(let R of Object.keys(D.values||{}))Rt.has(R)||(ee[R]=se(R));V&&(typeof CustomEvent<"u"&&typeof e?.container?.dispatchEvent=="function"&&e.container.dispatchEvent(new CustomEvent("interactivityEvent",{bubbles:!0,composed:!0,detail:{id:V,values:ee}})),ce(V,ee,$)),le();break}default:le();break}}};this.readScenePointer=ie,this.writeScenePointer=oe,this.fireOnStart=()=>{i.forEach(B=>{W(B)==="event/onStart"&&ue(B.flows?.out)}),z()},this.fireOnSelect=B=>{if(!B)return;let $=typeof B.meshIndex=="number"?B.meshIndex:-1,_=typeof B.nodeIndex=="number"?B.nodeIndex:e?.meshes?.[$]?.nodeIndex??-1;i.forEach((G,j)=>{if(!/^(pointer|event|scene)\/onSelect$/.test(W(G)))return;let q=De(G,"nodeIndex")??De(G,"node")??H(j,"nodeIndex",void 0,new Set),D=De(G,"meshName");if(typeof D=="string"&&D?B.meshName===D:q==null||Number(q)<0||Number.isNaN(Number(q))||O(_,Math.trunc(Number(q)))){if(T(j,"nodeIndex",_),T(j,"meshIndex",$),Array.isArray(B.hitPoint)){let Y=[he(B.hitPoint[0]),he(B.hitPoint[1]),he(B.hitPoint[2])];T(j,"hitPoint",Y),T(j,"point",Y),T(j,"intersectionPoint",Y)}if(Array.isArray(B.normal)){let Y=[he(B.normal[0]),he(B.normal[1],1),he(B.normal[2])];T(j,"normal",Y),T(j,"hitNormal",Y)}typeof B.distance=="number"&&T(j,"distance",B.distance),ue(G.flows?.out)}}),z()},this.receiveCustomEvent=(B,$={})=>ce(B,$,{steps:0});function ce(B,$,_){if(!(v>=Kc)){v++;try{let G=S(B);i.forEach((j,q)=>{if(!/^(customE|e)vent\/receive$/.test(W(j)))return;let D=De(j,"event")??De(j,"id");if(!(S(D)!==G&&String(D)!==String(B))){for(let[Y,te]of Object.entries($))Rt.has(Y)||T(q,Y,it(te));ue(j.flows?.out,_)}}),z()}finally{v--}}}this.tick=B=>{if(!Number.isFinite(B)||B<0)return;let $=Math.min(B,.25);b+=$,i.forEach((G,j)=>{W(G)==="event/onTick"&&(T(j,"timeDelta",$),T(j,"dt",$),T(j,"timeElapsed",b),ue(G.flows?.out))});let _=[];for(let G=d.length-1;G>=0;G--){let j=d[G];j.elapsed+=$;let q=j.dur>1e-6?$t(j.elapsed/j.dur):1,D=j.linear?q:q*q*(3-2*q),Y=sa(j.from,j.to,D,j.quat);j.ptr?oe(j.ptr,Y):j.varKey!==void 0&&E(j.varKey,Y),q>=1&&(d.splice(G,1),j.done&&_.push(j.done))}for(let G=f.length-1;G>=0;G--){let j=f[G];j.rem-=$,j.rem<=0&&(f.splice(G,1),j.done&&_.push(j.done))}for(let G of _)ue(G);z()},this.dispose=()=>{d.length=0,f.length=0,o.clear(),a.clear(),u.clear(),h.clear(),m.clear(),c.clear()}}},xt=new WeakMap,di=new WeakMap;function Qc(e,t){if(!e||typeof e!="object"||!Number.isFinite(t)||t<=0||tr().some(o=>o.name==="xr-live-head-follow")||(typeof e.getAutoRotate=="function"?e.getAutoRotate():e.autoRotate)===!1)return;let r=e.gltf,i=r?.nodes;if(!Array.isArray(i)||i.length===0)return;let n=Math.min(t,.1),s=(di.get(e)||0)+n,l=!1;for(let o=0;o<i.length;o++){let a=i[o],u=xs(a?.extras?.xr?.orbit);if(!u)continue;let h=0,m=0,c=0;if(Array.isArray(u.target))h=u.target[0],m=u.target[1],c=u.target[2];else if(typeof u.target=="string"&&u.target!=="head"){let b=i.find(v=>v?.name===u.target);Array.isArray(b?.translation)&&(h=he(b.translation[0]),m=he(b.translation[1]),c=he(b.translation[2]))}let d=u.phase+u.speed*s,f=h+Math.cos(d)*u.radius,g=m+u.height,x=c+Math.sin(d)*u.radius;if(a.translation=[f,g,x],u.faceCenter){let b=Math.atan2(h-f,c-x);a.rotation=[0,Math.sin(b*.5),0,Math.cos(b*.5)]}l=!0}if(l){di.set(e,s);let o=Ft(r);e.worldMatrices=o;for(let a of e.meshes||[])a.nodeIndex>=0&&a.nodeIndex<o.length&&(a.transform.set(o[a.nodeIndex]),Xe(a.normalMatrix,a.transform))}}function hi(e){if(!(!e||typeof e!="object"))return xt.get(e)||xt.get(e.viewer)||xt.get(e._view)}function vo(e,t,r){let i=hi(e);return i?(i.receiveCustomEvent(t,r),!0):!1}var Mo={name:"khr-interactivity",sendInteractivityEvent:vo,getInteractivityVM:hi,onLoadModel(e,t){if(!e||typeof e!="object")return;xt.get(e)?.dispose(),xt.delete(e),di.delete(e);let r=t?.extensions?.KHR_interactivity,i=Array.isArray(r?.graphs)?r.graphs[r.graph??0]:r;if(!i||!Array.isArray(i.nodes))return;let n=new qn(e,t,i);xt.set(e,n),n.fireOnStart()},onMeshSelect(e,t){xt.get(e)?.fireOnSelect(t)},onUpdate(e,t){xt.get(e)?.tick(t),Qc(e,t)},onDestroy(e,t){xt.get(t)?.dispose(),xt.delete(t),di.delete(t)}},Yn=new Map,pi=new WeakMap;function ua(e,t){Yn.set(e,t)}var To={name:"materials",onContextRestored(e){pi.delete(e)},onBuildPrimitiveVAO(e,t,r,i,n){return(((i?.materials&&r.material!==void 0?i.materials[r.material]:null)?.extensions||{}).KHR_materials_transmission?.transmissionFactor??0)>0?{isTransmissive:!0}:null},onBeforeTransmissivePass(e,t){let r=pi.get(e);r||(r=e.createTexture(),pi.set(e,r));let i=Math.max(1,t.canvas.width),n=Math.max(1,t.canvas.height);e.activeTexture(33990),e.bindTexture(3553,r),e.copyTexImage2D(3553,0,6408,0,0,i,n,0),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),e.texParameteri(3553,10241,9987),e.texParameteri(3553,10240,9729),e.generateMipmap(3553)},onResolveShader(e,t,r,i){if(!t)return null;if(t.name&&Yn.has(t.name)){let f=Yn.get(t.name);return{vs:f.vs||r,fs:f.fs||i}}let n=t.extensions||{},s=n.KHR_materials_clearcoat,l=n.KHR_materials_sheen,o=!!n.KHR_materials_transmission,a=!!n.KHR_materials_ior,u=n.KHR_materials_iridescence;if(!s&&!l&&!n.KHR_materials_unlit&&!o&&!n.KHR_materials_volume&&!a&&!n.KHR_materials_dispersion&&!u)return null;if(n.KHR_materials_unlit)return{vs:r,fs:i.replace("fragColor=vec4(color,outAlpha);","fragColor=vec4(base.rgb,outAlpha);").replace("fragColor=vec4(color,base.a);","fragColor=vec4(base.rgb,base.a);")};let h=i;if(o){let f=h.includes("uniform vec2 uViewportSize;")?"":`uniform vec2 uViewportSize;
389
416
  `;h=h.replace("out vec4 fragColor;",`uniform sampler2D uTransmissionTex;
390
- ${m}out vec4 fragColor;`)}let c=(m,g,x=0,b=1e6,v=3)=>{let d=Number(m);return(Number.isFinite(d)?Math.min(b,Math.max(x,d)):g).toFixed(v)},f=Number(n.KHR_materials_ior?.ior??1.5),p=Number.isFinite(f)?Math.min(10,Math.max(1,f)):1.5;if(a){let m=Math.pow((p-1)/(p+1),2);h=h.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${c(m,.04,0,1,4)}),base.rgb,metallic);`)}if(u){let m=c(u.iridescenceFactor,1,0,1),g=c(u.iridescenceIor,1.3,1,10);h=h.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${g}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${m}*pow(1.-NoV,2.));`)}if(o){let m=c(n.KHR_materials_transmission?.transmissionFactor,1,0,1),g=n.KHR_materials_volume||{},x=c(g.thicknessFactor,.5,0,1e4),b=c(g.attenuationDistance,1,.001,1e6),v=Array.isArray(g.attenuationColor)?g.attenuationColor:[1,1,1],d=c(n.KHR_materials_dispersion?.dispersion,0,0,10);h=h.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
391
- vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${c(p,1.5,1,10)},dV=${d},tV=${x},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
417
+ ${f}out vec4 fragColor;`)}let m=(f,g,x=0,b=1e6,v=3)=>{let p=Number(f);return(Number.isFinite(p)?Math.min(b,Math.max(x,p)):g).toFixed(v)},c=Number(n.KHR_materials_ior?.ior??1.5),d=Number.isFinite(c)?Math.min(10,Math.max(1,c)):1.5;if(a){let f=Math.pow((d-1)/(d+1),2);h=h.replace("vec3 F0=mix(vec3(0.04),base.rgb,metallic);",`vec3 F0=mix(vec3(${m(f,.04,0,1,4)}),base.rgb,metallic);`)}if(u){let f=m(u.iridescenceFactor,1,0,1),g=m(u.iridescenceIor,1.3,1,10);h=h.replace("vec3 F=F_SchlickRoughness(F0,roughness,NoV);",`vec3 F=F_SchlickRoughness(F0,roughness,NoV);vec3 iridColor=.5+.5*cos(800.*${g}*NoV*vec3(.015,.018,.022));F=mix(F,iridColor,${f}*pow(1.-NoV,2.));`)}if(o){let f=m(n.KHR_materials_transmission?.transmissionFactor,1,0,1),g=n.KHR_materials_volume||{},x=m(g.thicknessFactor,.5,0,1e4),b=m(g.attenuationDistance,1,.001,1e6),v=Array.isArray(g.attenuationColor)?g.attenuationColor:[1,1,1],p=m(n.KHR_materials_dispersion?.dispersion,0,0,10);h=h.replace("vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;",`vec3 diffuseIBL=kD*base.rgb*(uAmbientColor+envDiffuse*0.5)*occ;
418
+ vec2 sUV=gl_FragCoord.xy/max(uViewportSize,vec2(1.));float iorB=${m(d,1.5,1,10)},dV=${p},tV=${x},lod=clamp(roughness*5.,0.,5.),sc=.06*(1.+tV);
392
419
  vec3 refractedR=refract(-V,N,1./(iorB-.02*dV)),rG=refract(-V,N,1./iorB),refractedB=refract(-V,N,1./(iorB+.02*dV));
393
420
  vec3 tr=vec3(textureLod(uTransmissionTex,clamp(sUV+refractedR.xy*sc,.001,.999),lod).r,textureLod(uTransmissionTex,clamp(sUV+rG.xy*sc,.001,.999),lod).g,textureLod(uTransmissionTex,clamp(sUV+refractedB.xy*sc,.001,.999),lod).b);
394
- vec3 aCol=vec3(${c(v[0],1,0,1)},${c(v[1],1,0,1)},${c(v[2],1,0,1)});
421
+ vec3 aCol=vec3(${m(v[0],1,0,1)},${m(v[1],1,0,1)},${m(v[2],1,0,1)});
395
422
  vec3 volumeAtten=exp(-tV*(vec3(1.)-aCol)/max(${b},.001));
396
- diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${m});`)}if(s&&!i.includes("uClearcoat")){let m=c(s.clearcoatFactor,1,0,1),g=c(s.clearcoatRoughnessFactor,0,0,1);h=h.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${g},NoV)*${m};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${g})*ccF;fragColor=vec4(color,base.a);`)}if(l){let m=Array.isArray(l.sheenColorFactor)?l.sheenColorFactor:[1,1,1],g=`color+=vec3(${c(m[0],1,0,1)},${c(m[1],1,0,1)},${c(m[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;h.includes("color=applyToneMapping(color,uToneMapping);")?h=h.replace("color=applyToneMapping(color,uToneMapping);",`${g}color=applyToneMapping(color,uToneMapping);`):h=h.replace("fragColor=vec4(color,base.a);",`${g}fragColor=vec4(color,base.a);`)}return{vs:r,fs:h}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.materialIndex;if(l!==void 0&&s?.materials){let o=s.materials[l];o?.name&&qn.has(o.name)&&qn.get(o.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let o=fi.get(e);if(o){e.activeTexture(33990),e.bindTexture(3553,o);let a=e.getUniformLocation(t,"uTransmissionTex");a&&e.uniform1i(a,6);let u=e.getUniformLocation(t,"uViewportSize");u&&e.uniform2f(u,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},ya=64*1024*1024,ga=128*1024*1024,ou=16777216;function su(e){return(e>>>1^-(e&1))&255}function au(e){return(e>>>1^-(e&1))&65535}function cu(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function xa(e){return(e<<1^e>>31)>>>0}function Ta(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw Ee(`unknown filter "${String(e)}"`)}var Ae=Math.fround;function hn(e){return Math.trunc(Ae(e+(e>=0?.5:-.5)))}function Ao(e,t,r,i="NONE"){if(Ta(i),!i||i==="NONE"||t<=0)return;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw Ee(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let c=r===8,f=c?32767:127,p=x=>c?n.getInt16(x,!0):n.getInt8(x),m=(x,b)=>c?n.setInt16(x,b,!0):n.setInt8(x,b<<24>>24),g=c?2:1;for(let x=0;x<t;x++){let b=x*r,v=p(b),d=p(b+g),y=Ae(p(b+2*g)-Math.abs(v)-Math.abs(d)),M=y>=0?0:y;v=Ae(v+(v>=0?M:-M)),d=Ae(d+(d>=0?M:-M));let T=Ae(Math.sqrt(Ae(Ae(Ae(v*v)+Ae(d*d))+Ae(y*y))));if(T===0){m(b,0),m(b+g,0),m(b+2*g,f);continue}let V=Ae(f/T);m(b,hn(Ae(v*V))),m(b+g,hn(Ae(d*V))),m(b+2*g,hn(Ae(y*V)))}return}if(i==="QUATERNION"){if(r!==8)throw Ee(`QUATERNION filter requires byteStride 8 (got ${r})`);let c=Ae(32767/Ae(Math.SQRT2));for(let f=0;f<t;f++){let p=f*8,m=n.getInt16(p+6,!0),g=m|3,x=n.getInt16(p,!0),b=n.getInt16(p+2,!0),v=n.getInt16(p+4,!0),d=Ae(g*g),y=Ae(Ae(Ae(Ae(d*2)-Ae(x*x))-Ae(b*b))-Ae(v*v)),M=Ae(Math.sqrt(y>=0?y:0)),T=Ae(c/g),V=m&3,X=[0,0,0,0];X[V+1&3]=hn(Ae(x*T)),X[V+2&3]=hn(Ae(b*T)),X[V+3&3]=hn(Ae(v*T)),X[V]=Math.trunc(Ae(Ae(M*T)+.5));for(let P=0;P<4;P++)n.setInt16(p+P*2,X[P]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw Ee(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let c=t*r>>>2;for(let f=0;f<c;f++){let p=f*4,m=n.getUint32(p,!0),g=m<<8>>8,x=m>>24;n.setUint32(p,x+127<<23>>>0,!0);let b=n.getFloat32(p,!0);n.setFloat32(p,Ae(b*g),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let s=r===8,l=s?65535:255,o=c=>s?n.getUint16(c,!0):n.getUint8(c),a=c=>s?n.getInt16(c,!0):n.getInt8(c),u=(c,f)=>s?n.setUint16(c,f&65535,!0):n.setUint8(c,f&255),h=s?2:1;for(let c=0;c<t;c++){let f=c*r,p=o(f+3*h);p|=p>>1,p|=p>>2,p|=p>>4,p|=p>>8;let m=o(f),g=a(f+h),x=a(f+2*h),b=m+g-x,v=m+x,d=m-g-x,y=o(f+3*h);y=y<<1&p|y&1;let M=p===0?0:Ae(l/p);u(f,Math.trunc(Ae(Ae(b*M)+.5))),u(f+h,Math.trunc(Ae(Ae(v*M)+.5))),u(f+2*h,Math.trunc(Ae(Ae(d*M)+.5))),u(f+3*h,Math.trunc(Ae(Ae(y*M)+.5)))}}var Aa=160,ht=16,uu=24,wa=32,lu=24,mu=[0,2,4,8],fu=[0,1,2,4,8];function Sa(e){let t=Math.floor(8192/e)&~(ht-1);return t<256?t:256}function Ee(e){return new Error(`EXT_meshopt_compression: ${e}`)}function du(e,t,r,i,n){if(n===0)return r.fill(0,i,i+ht),t;if(n===8)return r.set(e.subarray(t,t+ht),i),t+ht;let s=(1<<n)-1,l=8/n,o=t+ht*n/8;for(let a=0;a<ht;a++){let u=e[t+Math.floor(a/l)],h=a%l,c=n===1?u>>h&1:u>>8-n-h*n&s;r[i+a]=c===s?e[o++]:c}return o}function va(e,t,r,i,n,s,l,o){let a=s/ht,u=a+3>>2;if(r-t<u)throw Ee("truncated ATTRIBUTES stream");let h=t;t+=u;for(let c=0;c<a;c++){if(r-t<uu)throw Ee("truncated ATTRIBUTES stream");let f=e[h+(c>>2)]>>(c&3)*2&3;t=du(e,t,i,n+c*ht,l[o+f])}return t}function hu(e,t,r,i){if(r%4!==0||r>256)throw Ee(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw Ee("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==Aa)throw Ee(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let l=s&15;if(l>1)throw Ee(`unsupported ATTRIBUTES codec version ${l}`);let o=r+(l===0?0:r/4),a=l===0?wa:lu,u=o<a?a:o;if(n-1<u)throw Ee("truncated ATTRIBUTES stream");let h=n-o,c=e.slice(h,h+r),f=h+r,p=Sa(r),m=new Uint8Array(256*4),g=1;for(let x=0;x<t;){let b=Math.min(p,t-x),v=b+ht-1&~(ht-1),d=l===0?0:r/4;if(n-g<d)throw Ee("truncated ATTRIBUTES stream");let y=g;g+=d;for(let M=0;M<r;M+=4){let T=l===0?0:e[y+M/4];for(let P=0;P<4;P++){let R=T>>P*2&3;if(R===3){if(n-g<b)throw Ee("truncated ATTRIBUTES stream");m.set(e.subarray(g,g+b),P*b),g+=b}else R===2?m.fill(0,P*b,P*b+b):g=l===0?va(e,g,n,m,P*b,v,mu,0):va(e,g,n,m,P*b,v,fu,R)}let V=l===0?0:e[f+M/4],X=V&3;if(X===0)for(let P=0;P<4;P++){let R=c[M+P];for(let C=0;C<b;C++)R=su(m[P*b+C])+R&255,i[(x+C)*r+M+P]=R}else if(X===1)for(let P=0;P<4;P+=2){let R=c[M+P]|c[M+P+1]<<8,C=P*b;for(let B=0;B<b;B++){let N=m[C+B]|m[C+b+B]<<8;R=au(N)+R&65535;let w=(x+B)*r+M+P;i[w]=R&255,i[w+1]=R>>8}}else if(X===2){let P=32-(V>>4)&31,R=(c[M]|c[M+1]<<8|c[M+2]<<16|c[M+3]<<24)>>>0;for(let C=0;C<b;C++){let B=(m[C]|m[b+C]<<8|m[2*b+C]<<16|m[3*b+C]<<24)>>>0;B=((B<<P|B>>>(32-P&31))^R)>>>0,R=B;let N=(x+C)*r+M;i[N]=B&255,i[N+1]=B>>>8&255,i[N+2]=B>>>16&255,i[N+3]=B>>>24}}else throw Ee(`invalid ATTRIBUTES channel ${V}`)}c.set(i.subarray((x+b-1)*r,(x+b)*r)),x+=b}if(n-g!==u)throw Ee("ATTRIBUTES trailing data")}var Ea=224,Ra=208;function _a(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,n=7;for(let s=0;s<4;s++){let l=e[t.pos++]??0;if(i=(i|(l&127)<<n)>>>0,n+=7,l<128)break}return i>>>0}function di(e,t,r){let i=_a(e,t),n=i>>>1^-(i&1);return r+n>>>0}function pu(e,t,r){if(t%3!==0)throw Ee(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw Ee("truncated TRIANGLES stream");let n=e[0];if((n&240)!==Ea)throw Ee(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw Ee(`unsupported TRIANGLES codec version ${s}`);let l=new Uint32Array(16).fill(4294967295),o=new Uint32Array(16).fill(4294967295),a=new Uint32Array(16).fill(4294967295),u=0,h=0,c=(T,V)=>{l[u]=T,o[u]=V,u=u+1&15},f=(T,V=1)=>{a[h]=T,h=h+V&15},p=0,m=0,g=s>=1?13:15,x=1+i,b=e.byteLength-16,v=b,d={pos:x},y=0,M=(T,V,X)=>{r(y++,T),r(y++,V),r(y++,X)};for(let T=1;T<x;T++){let V=e[T];if(V<240){let X=V>>4,P=u-1-X&15,R=l[P],C=o[P],B=0,N=V&15;if(N<g){let w=a[h-1-N&15];B=N===0?p:w;let ie=N===0?1:0;p=p+ie>>>0,f(B,ie)}else{if(d.pos>b)throw Ee("truncated TRIANGLES stream");B=N!==15?m+(N*2-27)>>>0:di(e,d,m),m=B,f(B)}c(B,C),c(R,B),M(R,C,B)}else if(V<254){let X=e[v+(V&15)],P=X>>4,R=X&15,C=p;p=p+1>>>0;let B=a[h-P&15],N=P===0?p:B,w=P===0?1:0;p=p+w>>>0;let ie=a[h-R&15],ae=R===0?p:ie,k=R===0?1:0;p=p+k>>>0,M(C,N,ae),f(C),f(N,w),f(ae,k),c(N,C),c(ae,N),c(C,ae)}else{if(d.pos>b)throw Ee("truncated TRIANGLES stream");let X=e[d.pos++],P=V===254?0:15,R=X>>4,C=X&15;X===0&&(p=0);let B=0;P===0&&(B=p,p=p+1>>>0);let N;R===0?(N=p,p=p+1>>>0):N=a[h-R&15];let w;C===0?(w=p,p=p+1>>>0):w=a[h-C&15],P===15&&(m=B=di(e,d,m)),R===15&&(m=N=di(e,d,m)),C===15&&(m=w=di(e,d,m)),M(B,N,w),f(B),f(N,R===0||R===15?1:0),f(w,C===0||C===15?1:0),c(N,B),c(w,N),c(B,w)}}if(d.pos!==b)throw Ee("TRIANGLES trailing data")}function bu(e,t,r){if(e.byteLength<1+t+4)throw Ee("truncated INDICES stream");let i=e[0];if((i&240)!==Ra)throw Ee(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw Ee(`unsupported INDICES codec version ${n}`);let s=e.byteLength-4,l=[0,0],o={pos:1};for(let a=0;a<t;a++){if(o.pos>=s)throw Ee("truncated INDICES stream");let u=_a(e,o),h=u&1;u>>>=1;let c=u>>>1^-(u&1),f=l[h]+c>>>0;l[h]=f,r(a,f)}if(o.pos!==s)throw Ee("INDICES trailing data")}function wo(e,t,r,i,n="NONE"){if(Ta(n),!Number.isInteger(t)||t<0||t>ou||!Number.isInteger(r)||r<=0||r>256)throw Ee(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>ya)throw Ee(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${ya})`);if(t===0)return new Uint8Array(0);let l=new Uint8Array(s);if(i==="ATTRIBUTES")return hu(e,t,r,l),Ao(l,t,r,n),l;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw Ee(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw Ee(`filter ${n} is only valid for ATTRIBUTES`);let o=new DataView(l.buffer),a=r===2?(u,h)=>o.setUint16(u*2,h&65535,!0):(u,h)=>o.setUint32(u*4,h>>>0,!0);return i==="TRIANGLES"?pu(e,t,a):bu(e,t,a),l}throw Ee(`unknown mode "${String(i)}"`)}function Ma(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function La(e,t,r,i){let n=t*r;if(e.byteLength<n)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${n})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let o=[Aa],a=Sa(r),u=new Uint8Array(r);t>0&&u.set(e.subarray(0,r));let h=u.slice(),c=new Uint8Array(256);for(let f=0;f<t;){let p=Math.min(a,t-f),m=p+15&-16;for(let g=0;g<r;g++){c.fill(0);let x=u[g];for(let d=0;d<p;d++){let y=e[(f+d)*r+g];c[d]=cu(y-x&255),x=y}u[g]=x;let b=m/16,v=o.length;for(let d=0;d<b+3>>2;d++)o.push(0);for(let d=0;d<b;d++){let y=c.subarray(d*16,d*16+16);if(!y.every(M=>M===0)){o[v+(d>>2)]|=3<<(d&3)*2;for(let M of y)o.push(M)}}}f+=p}for(let f=r;f<wa;f++)o.push(0);for(let f=0;f<r;f++)o.push(h[f]);return new Uint8Array(o)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let s=new DataView(e.buffer,e.byteOffset,e.byteLength),l=o=>r===2?s.getUint16(o*2,!0):s.getUint32(o*4,!0);if(i==="INDICES"){let o=[Ra|1],a=0;for(let u=0;u<t;u++){let h=l(u),c=h-a|0;a=h,Ma(o,xa(c)<<1>>>0)}return o.push(0,0,0,0),new Uint8Array(o)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let o=t/3,a=[Ea|1];for(let h=0;h<o;h++)a.push(255);let u=0;for(let h=0;h<o;h++){a.push(255);for(let c=0;c<3;c++){let f=l(h*3+c);Ma(a,xa(f-u|0)),u=f}}for(let h=0;h<16;h++)a.push(0);return new Uint8Array(a)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function hi(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let n=new Uint8Array(r.bin),s=[],l=0;for(let c=0;c<i.bufferViews.length;c++){let f=i.bufferViews[c],p=f?.extensions?.KHR_meshopt_compression,m=p??f?.extensions?.EXT_meshopt_compression;if(!m||typeof m!="object")continue;let g=p?"KHR_meshopt_compression":"EXT_meshopt_compression",x=Number(m.count),b=Number(m.byteStride),v=Number(m.byteOffset??0),d=Number(m.byteLength??0),y=m.mode||"ATTRIBUTES",M=m.filter||"NONE";if(M==="COLOR"&&!p)throw Ee(`bufferView ${c} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(m.buffer??0)!==0)throw new Error(`${g}: bufferView ${c} references buffer ${String(m.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(v)||v<0||!Number.isInteger(d)||d<0||v+d>n.byteLength)throw new Error(`${g}: bufferView ${c} compressed range [${v}, ${v+d}] out of bounds (${n.byteLength})`);let T=x*b;if(l+=T,l>ga)throw Ee(`total decompressed size (${l}) exceeds MAX_MESHOPT_TOTAL_BYTES (${ga})`);let V=n.subarray(v,v+d),X=wo(V,x,b,y,M);s.push({index:c,bytes:X,ext:m})}if(s.length===0)return;let o=n.byteLength+3&-4,a=0;for(let c of s)a+=c.bytes.byteLength+3&-4;let u=new Uint8Array(o+a);u.set(n,0);let h=o;for(let c of s){u.set(c.bytes,h);let f=i.bufferViews[c.index];f.buffer=0,f.byteOffset=h,f.byteLength=c.bytes.byteLength,f._decoded=c.bytes,c.ext.mode==="ATTRIBUTES"&&f.byteStride===void 0&&(f.byteStride=Number(c.ext.byteStride)),f.extensions&&(delete f.extensions.EXT_meshopt_compression,delete f.extensions.KHR_meshopt_compression),h+=c.bytes.byteLength+3&-4}r.bin=u.buffer}var pi={decodeBufferViews(e,t){hi(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};Me().decoders.set("meshopt",pi);var So={name:"meshopt",onParseGLB(e){Me().decoders.set("meshopt",pi),hi(e)}},yu=`#version 300 es
423
+ diffuseIBL=mix(diffuseIBL,tr*volumeAtten*base.rgb,${f});`)}if(s&&!i.includes("uClearcoat")){let f=m(s.clearcoatFactor,1,0,1),g=m(s.clearcoatRoughnessFactor,0,0,1);h=h.replace("fragColor=vec4(color,base.a);",`vec3 ccF=F_SchlickRoughness(vec3(.04),${g},NoV)*${f};color=color*(vec3(1.)-ccF)+getStudioRadiance(R,${g})*ccF;fragColor=vec4(color,base.a);`)}if(l){let f=Array.isArray(l.sheenColorFactor)?l.sheenColorFactor:[1,1,1],g=`color+=vec3(${m(f[0],1,0,1)},${m(f[1],1,0,1)},${m(f[2],1,0,1)})*pow(1.-NoV,4.)*.5;`;h.includes("color=applyToneMapping(color,uToneMapping);")?h=h.replace("color=applyToneMapping(color,uToneMapping);",`${g}color=applyToneMapping(color,uToneMapping);`):h=h.replace("fragColor=vec4(color,base.a);",`${g}fragColor=vec4(color,base.a);`)}return{vs:r,fs:h}},onBeforeDrawPrimitive(e,t,r,i,n,s){let l=r.materialIndex;if(l!==void 0&&s?.materials){let o=s.materials[l];o?.name&&Yn.has(o.name)&&Yn.get(o.name).onBindUniforms?.(e,t,r)}if(r.isTransmissive){let o=pi.get(e);if(o){e.activeTexture(33990),e.bindTexture(3553,o);let a=e.getUniformLocation(t,"uTransmissionTex");a&&e.uniform1i(a,6);let u=e.getUniformLocation(t,"uViewportSize");u&&e.uniform2f(u,e.drawingBufferWidth||1,e.drawingBufferHeight||1)}}}},la=64*1024*1024,ma=128*1024*1024,Jc=16777216;function eu(e){return(e>>>1^-(e&1))&255}function tu(e){return(e>>>1^-(e&1))&65535}function nu(e){let t=e<<24>>24;return(t<<1^t>>7)&255}function fa(e){return(e<<1^e>>31)>>>0}function pa(e){if(e!==void 0&&e!=="NONE"&&e!=="OCTAHEDRAL"&&e!=="QUATERNION"&&e!=="EXPONENTIAL"&&e!=="COLOR")throw Re(`unknown filter "${String(e)}"`)}var we=Math.fround;function hn(e){return Math.trunc(we(e+(e>=0?.5:-.5)))}function Ao(e,t,r,i="NONE"){if(pa(i),!i||i==="NONE"||t<=0)return;let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(i==="OCTAHEDRAL"){if(r!==4&&r!==8)throw Re(`OCTAHEDRAL filter requires byteStride 4 or 8 (got ${r})`);let m=r===8,c=m?32767:127,d=x=>m?n.getInt16(x,!0):n.getInt8(x),f=(x,b)=>m?n.setInt16(x,b,!0):n.setInt8(x,b<<24>>24),g=m?2:1;for(let x=0;x<t;x++){let b=x*r,v=d(b),p=d(b+g),y=we(d(b+2*g)-Math.abs(v)-Math.abs(p)),M=y>=0?0:y;v=we(v+(v>=0?M:-M)),p=we(p+(p>=0?M:-M));let P=we(Math.sqrt(we(we(we(v*v)+we(p*p))+we(y*y))));if(P===0){f(b,0),f(b+g,0),f(b+2*g,c);continue}let F=we(c/P);f(b,hn(we(v*F))),f(b+g,hn(we(p*F))),f(b+2*g,hn(we(y*F)))}return}if(i==="QUATERNION"){if(r!==8)throw Re(`QUATERNION filter requires byteStride 8 (got ${r})`);let m=we(32767/we(Math.SQRT2));for(let c=0;c<t;c++){let d=c*8,f=n.getInt16(d+6,!0),g=f|3,x=n.getInt16(d,!0),b=n.getInt16(d+2,!0),v=n.getInt16(d+4,!0),p=we(g*g),y=we(we(we(we(p*2)-we(x*x))-we(b*b))-we(v*v)),M=we(Math.sqrt(y>=0?y:0)),P=we(m/g),F=f&3,W=[0,0,0,0];W[F+1&3]=hn(we(x*P)),W[F+2&3]=hn(we(b*P)),W[F+3&3]=hn(we(v*P)),W[F]=Math.trunc(we(we(M*P)+.5));for(let T=0;T<4;T++)n.setInt16(d+T*2,W[T]<<16>>16,!0)}return}if(i==="EXPONENTIAL"){if(r<4||r%4!==0)throw Re(`EXPONENTIAL filter requires byteStride multiple of 4 (got ${r})`);let m=t*r>>>2;for(let c=0;c<m;c++){let d=c*4,f=n.getUint32(d,!0),g=f<<8>>8,x=f>>24;n.setUint32(d,x+127<<23>>>0,!0);let b=n.getFloat32(d,!0);n.setFloat32(d,we(b*g),!0)}return}if(r!==4&&r!==8)throw new Error(`KHR_meshopt_compression: COLOR filter requires byteStride 4 or 8 (got ${r})`);let s=r===8,l=s?65535:255,o=m=>s?n.getUint16(m,!0):n.getUint8(m),a=m=>s?n.getInt16(m,!0):n.getInt8(m),u=(m,c)=>s?n.setUint16(m,c&65535,!0):n.setUint8(m,c&255),h=s?2:1;for(let m=0;m<t;m++){let c=m*r,d=o(c+3*h);d|=d>>1,d|=d>>2,d|=d>>4,d|=d>>8;let f=o(c),g=a(c+h),x=a(c+2*h),b=f+g-x,v=f+x,p=f-g-x,y=o(c+3*h);y=y<<1&d|y&1;let M=d===0?0:we(l/d);u(c,Math.trunc(we(we(b*M)+.5))),u(c+h,Math.trunc(we(we(v*M)+.5))),u(c+2*h,Math.trunc(we(we(p*M)+.5))),u(c+3*h,Math.trunc(we(we(y*M)+.5)))}}var ba=160,vt=16,ru=24,ya=32,iu=24,ou=[0,2,4,8],su=[0,1,2,4,8];function ga(e){let t=Math.floor(8192/e)&~(vt-1);return t<256?t:256}function Re(e){return new Error(`EXT_meshopt_compression: ${e}`)}function au(e,t,r,i,n){if(n===0)return r.fill(0,i,i+vt),t;if(n===8)return r.set(e.subarray(t,t+vt),i),t+vt;let s=(1<<n)-1,l=8/n,o=t+vt*n/8;for(let a=0;a<vt;a++){let u=e[t+Math.floor(a/l)],h=a%l,m=n===1?u>>h&1:u>>8-n-h*n&s;r[i+a]=m===s?e[o++]:m}return o}function da(e,t,r,i,n,s,l,o){let a=s/vt,u=a+3>>2;if(r-t<u)throw Re("truncated ATTRIBUTES stream");let h=t;t+=u;for(let m=0;m<a;m++){if(r-t<ru)throw Re("truncated ATTRIBUTES stream");let c=e[h+(m>>2)]>>(m&3)*2&3;t=au(e,t,i,n+m*vt,l[o+c])}return t}function cu(e,t,r,i){if(r%4!==0||r>256)throw Re(`ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let n=e.byteLength;if(n<1)throw Re("truncated ATTRIBUTES stream");let s=e[0];if((s&240)!==ba)throw Re(`unsupported ATTRIBUTES header 0x${s.toString(16)}`);let l=s&15;if(l>1)throw Re(`unsupported ATTRIBUTES codec version ${l}`);let o=r+(l===0?0:r/4),a=l===0?ya:iu,u=o<a?a:o;if(n-1<u)throw Re("truncated ATTRIBUTES stream");let h=n-o,m=e.slice(h,h+r),c=h+r,d=ga(r),f=new Uint8Array(256*4),g=1;for(let x=0;x<t;){let b=Math.min(d,t-x),v=b+vt-1&~(vt-1),p=l===0?0:r/4;if(n-g<p)throw Re("truncated ATTRIBUTES stream");let y=g;g+=p;for(let M=0;M<r;M+=4){let P=l===0?0:e[y+M/4];for(let T=0;T<4;T++){let E=P>>T*2&3;if(E===3){if(n-g<b)throw Re("truncated ATTRIBUTES stream");f.set(e.subarray(g,g+b),T*b),g+=b}else E===2?f.fill(0,T*b,T*b+b):g=l===0?da(e,g,n,f,T*b,v,ou,0):da(e,g,n,f,T*b,v,su,E)}let F=l===0?0:e[c+M/4],W=F&3;if(W===0)for(let T=0;T<4;T++){let E=m[M+T];for(let S=0;S<b;S++)E=eu(f[T*b+S])+E&255,i[(x+S)*r+M+T]=E}else if(W===1)for(let T=0;T<4;T+=2){let E=m[M+T]|m[M+T+1]<<8,S=T*b;for(let O=0;O<b;O++){let k=f[S+O]|f[S+b+O]<<8;E=tu(k)+E&65535;let w=(x+O)*r+M+T;i[w]=E&255,i[w+1]=E>>8}}else if(W===2){let T=32-(F>>4)&31,E=(m[M]|m[M+1]<<8|m[M+2]<<16|m[M+3]<<24)>>>0;for(let S=0;S<b;S++){let O=(f[S]|f[b+S]<<8|f[2*b+S]<<16|f[3*b+S]<<24)>>>0;O=((O<<T|O>>>(32-T&31))^E)>>>0,E=O;let k=(x+S)*r+M;i[k]=O&255,i[k+1]=O>>>8&255,i[k+2]=O>>>16&255,i[k+3]=O>>>24}}else throw Re(`invalid ATTRIBUTES channel ${F}`)}m.set(i.subarray((x+b-1)*r,(x+b)*r)),x+=b}if(n-g!==u)throw Re("ATTRIBUTES trailing data")}var xa=224,va=208;function Ma(e,t){let r=e[t.pos++]??0;if(r<128)return r;let i=r&127,n=7;for(let s=0;s<4;s++){let l=e[t.pos++]??0;if(i=(i|(l&127)<<n)>>>0,n+=7,l<128)break}return i>>>0}function bi(e,t,r){let i=Ma(e,t),n=i>>>1^-(i&1);return r+n>>>0}function uu(e,t,r){if(t%3!==0)throw Re(`TRIANGLES count must be divisible by 3 (got ${t})`);let i=t/3;if(e.byteLength<1+i+16)throw Re("truncated TRIANGLES stream");let n=e[0];if((n&240)!==xa)throw Re(`unsupported TRIANGLES header 0x${n.toString(16)}`);let s=n&15;if(s>1)throw Re(`unsupported TRIANGLES codec version ${s}`);let l=new Uint32Array(16).fill(4294967295),o=new Uint32Array(16).fill(4294967295),a=new Uint32Array(16).fill(4294967295),u=0,h=0,m=(P,F)=>{l[u]=P,o[u]=F,u=u+1&15},c=(P,F=1)=>{a[h]=P,h=h+F&15},d=0,f=0,g=s>=1?13:15,x=1+i,b=e.byteLength-16,v=b,p={pos:x},y=0,M=(P,F,W)=>{r(y++,P),r(y++,F),r(y++,W)};for(let P=1;P<x;P++){let F=e[P];if(F<240){let W=F>>4,T=u-1-W&15,E=l[T],S=o[T],O=0,k=F&15;if(k<g){let w=a[h-1-k&15];O=k===0?d:w;let ie=k===0?1:0;d=d+ie>>>0,c(O,ie)}else{if(p.pos>b)throw Re("truncated TRIANGLES stream");O=k!==15?f+(k*2-27)>>>0:bi(e,p,f),f=O,c(O)}m(O,S),m(E,O),M(E,S,O)}else if(F<254){let W=e[v+(F&15)],T=W>>4,E=W&15,S=d;d=d+1>>>0;let O=a[h-T&15],k=T===0?d:O,w=T===0?1:0;d=d+w>>>0;let ie=a[h-E&15],oe=E===0?d:ie,I=E===0?1:0;d=d+I>>>0,M(S,k,oe),c(S),c(k,w),c(oe,I),m(k,S),m(oe,k),m(S,oe)}else{if(p.pos>b)throw Re("truncated TRIANGLES stream");let W=e[p.pos++],T=F===254?0:15,E=W>>4,S=W&15;W===0&&(d=0);let O=0;T===0&&(O=d,d=d+1>>>0);let k;E===0?(k=d,d=d+1>>>0):k=a[h-E&15];let w;S===0?(w=d,d=d+1>>>0):w=a[h-S&15],T===15&&(f=O=bi(e,p,f)),E===15&&(f=k=bi(e,p,f)),S===15&&(f=w=bi(e,p,f)),M(O,k,w),c(O),c(k,E===0||E===15?1:0),c(w,S===0||S===15?1:0),m(k,O),m(w,k),m(O,w)}}if(p.pos!==b)throw Re("TRIANGLES trailing data")}function lu(e,t,r){if(e.byteLength<1+t+4)throw Re("truncated INDICES stream");let i=e[0];if((i&240)!==va)throw Re(`unsupported INDICES header 0x${i.toString(16)}`);let n=i&15;if(n>1)throw Re(`unsupported INDICES codec version ${n}`);let s=e.byteLength-4,l=[0,0],o={pos:1};for(let a=0;a<t;a++){if(o.pos>=s)throw Re("truncated INDICES stream");let u=Ma(e,o),h=u&1;u>>>=1;let m=u>>>1^-(u&1),c=l[h]+m>>>0;l[h]=c,r(a,c)}if(o.pos!==s)throw Re("INDICES trailing data")}function wo(e,t,r,i,n="NONE"){if(pa(n),!Number.isInteger(t)||t<0||t>Jc||!Number.isInteger(r)||r<=0||r>256)throw Re(`invalid count (${t}) or byteStride (${r})`);let s=t*r;if(s>la)throw Re(`decompressed size (${s}) exceeds MAX_MESHOPT_BUFFER_BYTES (${la})`);if(t===0)return new Uint8Array(0);let l=new Uint8Array(s);if(i==="ATTRIBUTES")return cu(e,t,r,l),Ao(l,t,r,n),l;if(i==="TRIANGLES"||i==="INDICES"){if(r!==2&&r!==4)throw Re(`${i} byteStride must be 2 or 4 (got ${r})`);if(n&&n!=="NONE")throw Re(`filter ${n} is only valid for ATTRIBUTES`);let o=new DataView(l.buffer),a=r===2?(u,h)=>o.setUint16(u*2,h&65535,!0):(u,h)=>o.setUint32(u*4,h>>>0,!0);return i==="TRIANGLES"?uu(e,t,a):lu(e,t,a),l}throw Re(`unknown mode "${String(i)}"`)}function ha(e,t){t>>>=0;do e.push(t&127|(t>127?128:0)),t>>>=7;while(t)}function Ta(e,t,r,i){let n=t*r;if(e.byteLength<n)throw new Error(`encodeMeshoptBuffer: raw buffer (${e.byteLength}) smaller than count * byteStride (${n})`);if(i==="ATTRIBUTES"){if(r%4!==0||r>256)throw new Error(`encodeMeshoptBuffer: ATTRIBUTES byteStride must be a multiple of 4 and <= 256 (got ${r})`);let o=[ba],a=ga(r),u=new Uint8Array(r);t>0&&u.set(e.subarray(0,r));let h=u.slice(),m=new Uint8Array(256);for(let c=0;c<t;){let d=Math.min(a,t-c),f=d+15&-16;for(let g=0;g<r;g++){m.fill(0);let x=u[g];for(let p=0;p<d;p++){let y=e[(c+p)*r+g];m[p]=nu(y-x&255),x=y}u[g]=x;let b=f/16,v=o.length;for(let p=0;p<b+3>>2;p++)o.push(0);for(let p=0;p<b;p++){let y=m.subarray(p*16,p*16+16);if(!y.every(M=>M===0)){o[v+(p>>2)]|=3<<(p&3)*2;for(let M of y)o.push(M)}}}c+=d}for(let c=r;c<ya;c++)o.push(0);for(let c=0;c<r;c++)o.push(h[c]);return new Uint8Array(o)}if(r!==2&&r!==4)throw new Error(`encodeMeshoptBuffer: ${i} byteStride must be 2 or 4 (got ${r})`);let s=new DataView(e.buffer,e.byteOffset,e.byteLength),l=o=>r===2?s.getUint16(o*2,!0):s.getUint32(o*4,!0);if(i==="INDICES"){let o=[va|1],a=0;for(let u=0;u<t;u++){let h=l(u),m=h-a|0;a=h,ha(o,fa(m)<<1>>>0)}return o.push(0,0,0,0),new Uint8Array(o)}if(i==="TRIANGLES"){if(t%3!==0)throw new Error(`encodeMeshoptBuffer: TRIANGLES count must be divisible by 3 (got ${t})`);let o=t/3,a=[xa|1];for(let h=0;h<o;h++)a.push(255);let u=0;for(let h=0;h<o;h++){a.push(255);for(let m=0;m<3;m++){let c=l(h*3+m);ha(a,fa(c-u|0)),u=c}}for(let h=0;h<16;h++)a.push(0);return new Uint8Array(a)}throw new Error(`encodeMeshoptBuffer: unknown mode "${String(i)}"`)}function yi(e,t){let r=t&&typeof t=="object"?t:e,i=t&&typeof t=="object"?e:r?.gltf;if(!i||!Array.isArray(i.bufferViews))return;let n=new Uint8Array(r.bin),s=[],l=0;for(let m=0;m<i.bufferViews.length;m++){let c=i.bufferViews[m],d=c?.extensions?.KHR_meshopt_compression,f=d??c?.extensions?.EXT_meshopt_compression;if(!f||typeof f!="object")continue;let g=d?"KHR_meshopt_compression":"EXT_meshopt_compression",x=Number(f.count),b=Number(f.byteStride),v=Number(f.byteOffset??0),p=Number(f.byteLength??0),y=f.mode||"ATTRIBUTES",M=f.filter||"NONE";if(M==="COLOR"&&!d)throw Re(`bufferView ${m} uses the COLOR filter, which requires KHR_meshopt_compression`);if(Number(f.buffer??0)!==0)throw new Error(`${g}: bufferView ${m} references buffer ${String(f.buffer)}; only the GLB BIN chunk (buffer 0) is supported`);if(!Number.isInteger(v)||v<0||!Number.isInteger(p)||p<0||v+p>n.byteLength)throw new Error(`${g}: bufferView ${m} compressed range [${v}, ${v+p}] out of bounds (${n.byteLength})`);let P=x*b;if(l+=P,l>ma)throw Re(`total decompressed size (${l}) exceeds MAX_MESHOPT_TOTAL_BYTES (${ma})`);let F=n.subarray(v,v+p),W=wo(F,x,b,y,M);s.push({index:m,bytes:W,ext:f})}if(s.length===0)return;let o=n.byteLength+3&-4,a=0;for(let m of s)a+=m.bytes.byteLength+3&-4;let u=new Uint8Array(o+a);u.set(n,0);let h=o;for(let m of s){u.set(m.bytes,h);let c=i.bufferViews[m.index];c.buffer=0,c.byteOffset=h,c.byteLength=m.bytes.byteLength,c._decoded=m.bytes,m.ext.mode==="ATTRIBUTES"&&c.byteStride===void 0&&(c.byteStride=Number(m.ext.byteStride)),c.extensions&&(delete c.extensions.EXT_meshopt_compression,delete c.extensions.KHR_meshopt_compression),h+=m.bytes.byteLength+3&-4}r.bin=u.buffer}var gi={decodeBufferViews(e,t){yi(t)},decodePrimitive(e,t,r){let i=t?.extensions;i?.EXT_meshopt_compression&&delete i.EXT_meshopt_compression,i?.KHR_meshopt_compression&&delete i.KHR_meshopt_compression}};Ae().decoders.set("meshopt",gi);var So={name:"meshopt",onParseGLB(e){Ae().decoders.set("meshopt",gi),yi(e)}},mu=`#version 300 es
397
424
  layout(location=0) in vec3 aPosition;
398
425
  layout(location=1) in vec3 aNormal;
399
426
  uniform mat4 uMVP,uVP;
@@ -414,19 +441,19 @@ vec2 pxOffset=dir*(uOutlineThickness*2.0/max(uViewportSize,vec2(1.0)))*clipPos.w
414
441
  clipPos.xy+=pxOffset;
415
442
  clipPos.z+=1e-4*clipPos.w;
416
443
  gl_Position=clipPos;
417
- }`,gu=`#version 300 es
444
+ }`,fu=`#version 300 es
418
445
  precision highp float;
419
446
  uniform vec4 uOutlineColor;
420
447
  out vec4 fragColor;
421
448
  void main(){
422
449
  fragColor=uOutlineColor;
423
- }`,Ia=`#version 300 es
450
+ }`,Aa=`#version 300 es
424
451
  out vec2 vUV;
425
452
  void main(){
426
453
  vec2 pos=vec2((gl_VertexID<<1)&2,gl_VertexID&2);
427
454
  vUV=pos;
428
455
  gl_Position=vec4(pos*2.0-1.0,0.0,1.0);
429
- }`,xu=`#version 300 es
456
+ }`,du=`#version 300 es
430
457
  precision highp float;
431
458
  in vec2 vUV;
432
459
  uniform sampler2D uSourceTex;
@@ -449,7 +476,7 @@ c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,-h.y)).rgb)*0.125;
449
476
  c+=prefilter(texture(uSourceTex,vUV+vec2(-h.x,h.y)).rgb)*0.125;
450
477
  c+=prefilter(texture(uSourceTex,vUV+vec2(h.x,h.y)).rgb)*0.125;
451
478
  fragColor=vec4(c,1.0);
452
- }`,vu=`#version 300 es
479
+ }`,hu=`#version 300 es
453
480
  precision highp float;
454
481
  in vec2 vUV;
455
482
  uniform sampler2D uBloomTex;
@@ -471,4 +498,4 @@ sum+=texture(uBloomTex,vUV+vec2(-d.x,-d.y)).rgb*2.0;
471
498
  vec3 bloom=(sum/12.0)*uStrength;
472
499
  float a=clamp(min(bloom.r,min(bloom.g,bloom.b)),0.0,1.0);
473
500
  fragColor=vec4(bloom,a);
474
- }`,bi=3,Yn=new WeakMap;function Eo(e,t=[.22,.74,.97]){let r=Vi(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let n=+("0x"+i[0]+i[0])/255,s=+("0x"+i[1]+i[1])/255,l=+("0x"+i[2]+i[2])/255;return[n,s,l]}if(i.length===6){let n=+("0x"+i.slice(0,2))/255,s=+("0x"+i.slice(2,4))/255,l=+("0x"+i.slice(4,6))/255;return[n,s,l]}return[t[0],t[1],t[2]]}function Pa(e,t,r=.8,i=.5){let n=Number.isFinite(t)?Math.max(0,t):0;if(n<=0)return[0,0,0];let s=Math.max(0,Number(e[0])||0),l=Math.max(0,Number(e[1])||0),o=Math.max(0,Number(e[2])||0),a=Math.max(s,l,o);if(a<=1e-6)return[0,0,0];let u=Number.isFinite(r)?Math.max(0,r):.8,h=Math.max(u*Math.max(0,i),1e-4),c=Math.max(0,Math.min(2*h,a-u+h)),f=c*c/(4*h+1e-4),p=Math.min(1,Math.max(0,Math.max(f,a-u)/Math.max(a,1e-4)))*n;return[s*p,l*p,o*p]}function Na(e,t,r,i){let n=Number(e[0])||0,s=Number(e[1])||0,l=Math.hypot(n,s);if(l<=1e-5||t<=0||r<=0)return[0,0];let o=Math.max(1,Number(i[0])||1),a=Math.max(1,Number(i[1])||1),u=Math.max(0,r)*2*t;return[n/l*(u/o),s/l*(u/a)]}var Ca=new WeakSet;function Da(e){let t=Yn.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Yn.delete(e)}if(Ca.has(e)||e.isContextLost?.())return null;let r=Dt(e,yu,gu,!1),i=Dt(e,Ia,xu,!1),n=Dt(e,Ia,vu,!1);if(!r||!i||!n){for(let l of[r,i,n])l&&e.deleteProgram(l);return Ca.add(e),null}let s=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:n,uUpBloomTex:e.getUniformLocation(n,"uBloomTex"),uUpTexelSize:e.getUniformLocation(n,"uTexelSize"),uUpRadius:e.getUniformLocation(n,"uRadius"),uUpStrength:e.getUniformLocation(n,"uStrength"),fsVao:s,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Yn.set(e,t),t}function Mu(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let n=Math.max(2,r|0),s=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===bi&&t.texWidth===n&&t.texHeight===s)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,n,s,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let l=n,o=s;for(let a=0;a<bi;a++)l=Math.max(1,l>>1),o=Math.max(1,o>>1),t.mipWidth[a]=l,t.mipHeight[a]=o,t.bloomTex[a]||(t.bloomTex[a]=e.createTexture()),e.bindTexture(3553,t.bloomTex[a]),e.texImage2D(3553,0,6408,l,o,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[a]||(t.bloomFbo[a]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[a]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[a],0);return e.bindFramebuffer(36160,null),t.texWidth=n,t.texHeight=s,!0}function Tu(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let n=i.trim().toLowerCase();if(n==="false"||n==="0"||n==="none")return null;let s=n===""||n==="true"?.35:Number(n);if(!Number.isFinite(s)||s<=0)return null;let l=Bi({strength:s,threshold:mn(t.getAttribute("bloom-threshold"),.62),radius:mn(t.getAttribute("bloom-radius"),.75)});if(l)return l}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let n=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,s=Bi(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function Au(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let n=t,s=3.5,l=!1;if(r&&i!=="true"){let o=r.split(/\s+/);for(let a of o)if(a.startsWith("#"))n=a;else if(a.toLowerCase()==="pulse")l=!0;else{let u=Number(a);Number.isFinite(u)&&u>0&&(s=u)}}return lr({color:n,thickness:s,pulse:l})}var wu=new Set(["floor","pedestal","ground","table","grid","pad"]);function Su(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>wu.has(t))}function Eu(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let h=i.trim().toLowerCase();if(h==="false"||h==="0"||h==="none")return null}let n=t?.extras?.xr?.outline??t?.userData?.xr?.outline,s=lr(n);if(s)return s;let l=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",o=Au(i,l),a=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",u=e.getSelectedMesh?.()||"";if(u)return t.name!==u?null:o||(a?lr({color:l,thickness:3,pulse:!1}):null);if(o){let h=t.name||"";return Su(h)?null:o}return null}var Ro={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),n=Math.max(1,t.canvas?.height||150),s=[];for(let f of t.meshes){if(f.visible===!1)continue;let p=Eu(t,f);p&&s.push({mesh:f,trait:p})}let l=s.length>0?Da(e):null;if(l){let f=l,p=Se(),m=Se(),g=new Float32Array(9),x=(typeof performance<"u"?performance.now():Date.now())*.001,b=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,v=Math.max(1,b?.[2]||i),d=Math.max(1,b?.[3]||n);e.useProgram(f.outlineProg),f.uOutlineViewportSize&&e.uniform2f(f.uOutlineViewportSize,v,d),f.uOutlineVP&&e.uniformMatrix4fv(f.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:y,trait:M}of s){let[T,V,X]=Eo(M.color),P=M.pulse?.8+.25*Math.sin(x*4):1;f.uOutlineColor&&e.uniform4f(f.uOutlineColor,T,V,X,1),f.uOutlineThickness&&e.uniform1f(f.uOutlineThickness,M.thickness*P),y.worldSpace===!0?p.set(y.transform):Pe(p,t.modelRootMatrix,y.transform);let R=y.instanceMatrices;for(let C of y.primitives)if(!(C.pluginData?.skinning?.hasSkin||C.pluginData?.morph?.hasMorph))if(e.bindVertexArray(C.vao),R&&R.length>=16){let B=R.length>>4,N=Se();for(let w=0;w<B;w++)Pe(N,p,R.subarray(w*16,w*16+16)),Pe(m,r,N),ze(g,N),e.uniformMatrix4fv(f.uOutlineMVP,!1,m),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,g),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}else Pe(m,r,p),ze(g,p),e.uniformMatrix4fv(f.uOutlineMVP,!1,m),e.uniformMatrix3fv(f.uOutlineNormalMatrix,!1,g),C.indices?e.drawElements(4,C.indexCount,C.indexType,0):e.drawArrays(4,0,C.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let o=Tu(t);if(!o||o.strength<=0)return;let a=Da(e);if(!a||!Mu(e,a,i,n)||!a.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,a.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,n),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(a.downProg),e.uniform1i(a.uDownSourceTex,0),e.bindVertexArray(a.fsVao);let u=a.sceneTex,h=i,c=n;for(let f=0;f<bi;f++){let p=a.mipWidth[f],m=a.mipHeight[f];e.bindFramebuffer(36160,a.bloomFbo[f]),e.viewport(0,0,p,m),e.bindTexture(3553,u),e.uniform2f(a.uDownTexelSize,1/h,1/c),e.uniform1f(a.uDownThreshold,f===0?o.threshold:0),e.drawArrays(4,0,3),u=a.bloomTex[f],h=p,c=m}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(a.upProg),e.uniform1i(a.uUpBloomTex,0),e.uniform1f(a.uUpRadius,o.radius);for(let f=bi-1;f>=1;f--){let p=f-1;e.bindFramebuffer(36160,a.bloomFbo[p]),e.viewport(0,0,a.mipWidth[p],a.mipHeight[p]),e.bindTexture(3553,a.bloomTex[f]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[f],1/a.mipHeight[f]),e.uniform1f(a.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,n),e.bindTexture(3553,a.bloomTex[0]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[0],1/a.mipHeight[0]),e.uniform1f(a.uUpStrength,o.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Yn.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Yn.delete(e)}}};function _o(e){let t=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(t))return[];let r=[];for(let i=0;i<t.length&&r.length<256;i++){let n=t[i]?.name;r.push(typeof n=="string"&&n.length>0?n:`Variant_${i}`)}return r}function ka(e){let t=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let n=i,s=Number(n.material);if(!Number.isInteger(s)||s<0)continue;let l=[];if(Array.isArray(n.variants))for(let o of n.variants){let a=Number(o);Number.isInteger(a)&&a>=0&&l.push(a)}l.length>0&&r.push({material:s,variants:l})}return r}function Oa(e,t,r,i=0){let n=e;if(n&&typeof n.selectVariant=="function"&&!Array.isArray(t))return n.selectVariant(typeof t=="string"?t:null);let s=e,l=Array.isArray(t)?t:[],o=r??null;if(!o)return i;let a=_o(s).indexOf(o);if(a<0)return i;for(let u of l)if(u.variants.includes(a))return u.material;return i}var Lo={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},Ua=new WeakMap,Io={name:"webxr-suite",onConfigureXRSessionInit(e,t){let r=new Set(t.optionalFeatures||[]);r.add("hit-test"),r.add("light-estimation");let i=e?.querySelector?.('[slot="ar-overlay"]')||null;i&&(r.add("dom-overlay"),t.domOverlay={root:i},i.addEventListener?.("beforexrselect",n=>{n.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let n=Ua.get(t);if(n||(n={lightProbe:null},Ua.set(t,n),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(s=>{n&&s&&(n.lightProbe=s)}).catch(()=>{})),n.lightProbe&&typeof r.getLightEstimate=="function"){let s=r.getLightEstimate(n.lightProbe);if(s){let l=s.primaryLightDirection,o=s.primaryLightIntensity;if(l&&o&&Array.isArray(e.lights)){let a=e.lights.find(h=>h.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(a)),a.direction=[l.x,l.y,l.z];let u=Math.max(o.x,o.y,o.z,.001);a.color=[o.x/u,o.y/u,o.z/u],a.intensity=u}s.sphericalHarmonicsCoefficients&&e.gl&&si(e.gl,s.sphericalHarmonicsCoefficients)}}}};Ue(Wn),Ue(yo),Ue(ho),Ue(To),Ue(Io),Ue(Mo),Ue(So),Ue(Lo),Ue(Ro),Ue(Ii),ft.registerScriptRunner(ln),typeof window<"u"&&(window.ThreeLiveBundle=Co);
501
+ }`,xi=3,Zn=new WeakMap;function Eo(e,t=[.22,.74,.97]){let r=Vi(e,"");if(!r.startsWith("#"))return[t[0],t[1],t[2]];let i=r.slice(1);if(i.length===3){let n=+("0x"+i[0]+i[0])/255,s=+("0x"+i[1]+i[1])/255,l=+("0x"+i[2]+i[2])/255;return[n,s,l]}if(i.length===6){let n=+("0x"+i.slice(0,2))/255,s=+("0x"+i.slice(2,4))/255,l=+("0x"+i.slice(4,6))/255;return[n,s,l]}return[t[0],t[1],t[2]]}function Ea(e,t,r=.8,i=.5){let n=Number.isFinite(t)?Math.max(0,t):0;if(n<=0)return[0,0,0];let s=Math.max(0,Number(e[0])||0),l=Math.max(0,Number(e[1])||0),o=Math.max(0,Number(e[2])||0),a=Math.max(s,l,o);if(a<=1e-6)return[0,0,0];let u=Number.isFinite(r)?Math.max(0,r):.8,h=Math.max(u*Math.max(0,i),1e-4),m=Math.max(0,Math.min(2*h,a-u+h)),c=m*m/(4*h+1e-4),d=Math.min(1,Math.max(0,Math.max(c,a-u)/Math.max(a,1e-4)))*n;return[s*d,l*d,o*d]}function Ra(e,t,r,i){let n=Number(e[0])||0,s=Number(e[1])||0,l=Math.hypot(n,s);if(l<=1e-5||t<=0||r<=0)return[0,0];let o=Math.max(1,Number(i[0])||1),a=Math.max(1,Number(i[1])||1),u=Math.max(0,r)*2*t;return[n/l*(u/o),s/l*(u/a)]}var wa=new WeakSet;function Sa(e){let t=Zn.get(e);if(t){if(typeof e.isProgram!="function"||e.isProgram(t.outlineProg))return t;Zn.delete(e)}if(wa.has(e)||e.isContextLost?.())return null;let r=_t(e,mu,fu,!1),i=_t(e,Aa,du,!1),n=_t(e,Aa,hu,!1);if(!r||!i||!n){for(let l of[r,i,n])l&&e.deleteProgram(l);return wa.add(e),null}let s=typeof e.createVertexArray=="function"?e.createVertexArray():null;return t={outlineProg:r,uOutlineMVP:e.getUniformLocation(r,"uMVP"),uOutlineVP:e.getUniformLocation(r,"uVP"),uOutlineNormalMatrix:e.getUniformLocation(r,"uNormalMatrix"),uOutlineViewportSize:e.getUniformLocation(r,"uViewportSize"),uOutlineThickness:e.getUniformLocation(r,"uOutlineThickness"),uOutlineColor:e.getUniformLocation(r,"uOutlineColor"),downProg:i,uDownSourceTex:e.getUniformLocation(i,"uSourceTex"),uDownTexelSize:e.getUniformLocation(i,"uTexelSize"),uDownThreshold:e.getUniformLocation(i,"uThreshold"),upProg:n,uUpBloomTex:e.getUniformLocation(n,"uBloomTex"),uUpTexelSize:e.getUniformLocation(n,"uTexelSize"),uUpRadius:e.getUniformLocation(n,"uRadius"),uUpStrength:e.getUniformLocation(n,"uStrength"),fsVao:s,sceneTex:null,bloomTex:[],bloomFbo:[],mipWidth:[],mipHeight:[],texWidth:0,texHeight:0},Zn.set(e,t),t}function pu(e,t,r,i){if(typeof e.createFramebuffer!="function"||typeof e.copyTexSubImage2D!="function")return!1;let n=Math.max(2,r|0),s=Math.max(2,i|0);if(t.sceneTex&&t.bloomFbo.length===xi&&t.texWidth===n&&t.texHeight===s)return!0;t.sceneTex||(t.sceneTex=e.createTexture()),e.bindTexture(3553,t.sceneTex),e.texImage2D(3553,0,6408,n,s,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071);let l=n,o=s;for(let a=0;a<xi;a++)l=Math.max(1,l>>1),o=Math.max(1,o>>1),t.mipWidth[a]=l,t.mipHeight[a]=o,t.bloomTex[a]||(t.bloomTex[a]=e.createTexture()),e.bindTexture(3553,t.bloomTex[a]),e.texImage2D(3553,0,6408,l,o,0,6408,5121,null),e.texParameteri(3553,10241,9729),e.texParameteri(3553,10240,9729),e.texParameteri(3553,10242,33071),e.texParameteri(3553,10243,33071),t.bloomFbo[a]||(t.bloomFbo[a]=e.createFramebuffer()),e.bindFramebuffer(36160,t.bloomFbo[a]),e.framebufferTexture2D(36160,36064,3553,t.bloomTex[a],0);return e.bindFramebuffer(36160,null),t.texWidth=n,t.texHeight=s,!0}function bu(e){let t=e.container;if(t&&typeof t.getAttribute=="function"){let i=t.getAttribute("bloom");if(i!==null){let n=i.trim().toLowerCase();if(n==="false"||n==="0"||n==="none")return null;let s=n===""||n==="true"?.35:Number(n);if(!Number.isFinite(s)||s<=0)return null;let l=Bi({strength:s,threshold:mn(t.getAttribute("bloom-threshold"),.62),radius:mn(t.getAttribute("bloom-radius"),.75)});if(l)return l}}let r=null;for(let i of e.meshes||[]){if(i.visible===!1)continue;let n=i?.extras?.xr?.bloom??i?.userData?.xr?.bloom,s=Bi(n);s&&(!r||s.strength>r.strength)&&(r=s)}return r}function yu(e,t){if(e==null)return null;let r=e.trim(),i=r.toLowerCase();if(i==="false"||i==="0"||i==="none")return null;let n=t,s=3.5,l=!1;if(r&&i!=="true"){let o=r.split(/\s+/);for(let a of o)if(a.startsWith("#"))n=a;else if(a.toLowerCase()==="pulse")l=!0;else{let u=Number(a);Number.isFinite(u)&&u>0&&(s=u)}}return dr({color:n,thickness:s,pulse:l})}var gu=new Set(["floor","pedestal","ground","table","grid","pad"]);function xu(e){return e.replace(/([a-z\d])([A-Z])/g,"$1 $2").toLowerCase().split(/[^a-z]+/).some(t=>gu.has(t))}function vu(e,t){let r=e.container,i=typeof r?.getAttribute=="function"?r.getAttribute("outline"):null;if(i!=null){let h=i.trim().toLowerCase();if(h==="false"||h==="0"||h==="none")return null}let n=t?.extras?.xr?.outline??t?.userData?.xr?.outline,s=dr(n);if(s)return s;let l=typeof r?.getAttribute=="function"&&r.getAttribute("outline-color")||"#38bdf8",o=yu(i,l),a=r!=null&&typeof r.hasAttribute=="function"&&r.hasAttribute("outline-selected")&&r.getAttribute("outline-selected")!=="false",u=e.getSelectedMesh?.()||"";if(u)return t.name!==u?null:o||(a?dr({color:l,thickness:3,pulse:!1}):null);if(o){let h=t.name||"";return xu(h)?null:o}return null}var Ro={name:"postprocessing",onAttributeChanged(e,t){(t==="bloom"||t==="bloom-threshold"||t==="bloom-radius"||t==="outline"||t==="outline-selected"||t==="outline-color"||t==="selected-mesh")&&e.viewer?.render?.()},onAfterRender(e,t,r){if(!t.meshes||t.meshes.length===0)return;let i=Math.max(1,t.canvas?.width||300),n=Math.max(1,t.canvas?.height||150),s=[];for(let c of t.meshes){if(c.visible===!1)continue;let d=vu(t,c);d&&s.push({mesh:c,trait:d})}let l=s.length>0?Sa(e):null;if(l){let c=l,d=Se(),f=Se(),g=new Float32Array(9),x=(typeof performance<"u"?performance.now():Date.now())*.001,b=typeof e.getParameter=="function"?e.getParameter(e.VIEWPORT):null,v=Math.max(1,b?.[2]||i),p=Math.max(1,b?.[3]||n);e.useProgram(c.outlineProg),c.uOutlineViewportSize&&e.uniform2f(c.uOutlineViewportSize,v,p),c.uOutlineVP&&e.uniformMatrix4fv(c.uOutlineVP,!1,r),e.enable(e.CULL_FACE),e.cullFace(e.FRONT),e.enable(2929),e.depthFunc(e.LEQUAL),e.depthMask(!1);for(let{mesh:y,trait:M}of s){let[P,F,W]=Eo(M.color),T=M.pulse?.8+.25*Math.sin(x*4):1;c.uOutlineColor&&e.uniform4f(c.uOutlineColor,P,F,W,1),c.uOutlineThickness&&e.uniform1f(c.uOutlineThickness,M.thickness*T),y.worldSpace===!0?d.set(y.transform):Ie(d,t.modelRootMatrix,y.transform);let E=y.instanceMatrices;for(let S of y.primitives)if(!(S.pluginData?.skinning?.hasSkin||S.pluginData?.morph?.hasMorph))if(e.bindVertexArray(S.vao),E&&E.length>=16){let O=E.length>>4,k=Se();for(let w=0;w<O;w++)Ie(k,d,E.subarray(w*16,w*16+16)),Ie(f,r,k),Xe(g,k),e.uniformMatrix4fv(c.uOutlineMVP,!1,f),e.uniformMatrix3fv(c.uOutlineNormalMatrix,!1,g),S.indices?e.drawElements(4,S.indexCount,S.indexType,0):e.drawArrays(4,0,S.indexCount)}else Ie(f,r,d),Xe(g,d),e.uniformMatrix4fv(c.uOutlineMVP,!1,f),e.uniformMatrix3fv(c.uOutlineNormalMatrix,!1,g),S.indices?e.drawElements(4,S.indexCount,S.indexType,0):e.drawArrays(4,0,S.indexCount)}e.bindVertexArray(null),e.cullFace(e.BACK),e.disable(e.CULL_FACE),e.depthFunc(e.LESS),e.depthMask(!0)}if(t.xrSessionActive||t.stereoSBS)return;let o=bu(t);if(!o||o.strength<=0)return;let a=Sa(e);if(!a||!pu(e,a,i,n)||!a.fsVao)return;e.activeTexture(33984),e.bindTexture(3553,a.sceneTex),e.copyTexSubImage2D(3553,0,0,0,0,0,i,n),e.disable(2929),e.depthMask(!1),e.disable(3042),e.useProgram(a.downProg),e.uniform1i(a.uDownSourceTex,0),e.bindVertexArray(a.fsVao);let u=a.sceneTex,h=i,m=n;for(let c=0;c<xi;c++){let d=a.mipWidth[c],f=a.mipHeight[c];e.bindFramebuffer(36160,a.bloomFbo[c]),e.viewport(0,0,d,f),e.bindTexture(3553,u),e.uniform2f(a.uDownTexelSize,1/h,1/m),e.uniform1f(a.uDownThreshold,c===0?o.threshold:0),e.drawArrays(4,0,3),u=a.bloomTex[c],h=d,m=f}e.enable(3042),typeof e.blendFuncSeparate=="function"?e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,771):e.blendFunc(e.ONE,e.ONE),e.useProgram(a.upProg),e.uniform1i(a.uUpBloomTex,0),e.uniform1f(a.uUpRadius,o.radius);for(let c=xi-1;c>=1;c--){let d=c-1;e.bindFramebuffer(36160,a.bloomFbo[d]),e.viewport(0,0,a.mipWidth[d],a.mipHeight[d]),e.bindTexture(3553,a.bloomTex[c]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[c],1/a.mipHeight[c]),e.uniform1f(a.uUpStrength,.85),e.drawArrays(4,0,3)}e.bindFramebuffer(36160,null),e.viewport(0,0,i,n),e.bindTexture(3553,a.bloomTex[0]),e.uniform2f(a.uUpTexelSize,1/a.mipWidth[0],1/a.mipHeight[0]),e.uniform1f(a.uUpStrength,o.strength),e.drawArrays(4,0,3),e.bindVertexArray(null),e.blendFunc(770,771),e.disable(3042),e.depthMask(!0),e.enable(2929)},onDestroy(e){let t=Zn.get(e);if(t){e.deleteProgram(t.outlineProg),e.deleteProgram(t.downProg),e.deleteProgram(t.upProg),t.fsVao&&e.deleteVertexArray(t.fsVao),t.sceneTex&&e.deleteTexture(t.sceneTex);for(let r of t.bloomTex)r&&e.deleteTexture(r);for(let r of t.bloomFbo)r&&e.deleteFramebuffer(r);Zn.delete(e)}}};function _o(e){let t=e?.extensions?.KHR_materials_variants?.variants;if(!Array.isArray(t))return[];let r=[];for(let i=0;i<t.length&&r.length<256;i++){let n=t[i]?.name;r.push(typeof n=="string"&&n.length>0?n:`Variant_${i}`)}return r}function _a(e){let t=e?.extensions?.KHR_materials_variants?.mappings;if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let n=i,s=Number(n.material);if(!Number.isInteger(s)||s<0)continue;let l=[];if(Array.isArray(n.variants))for(let o of n.variants){let a=Number(o);Number.isInteger(a)&&a>=0&&l.push(a)}l.length>0&&r.push({material:s,variants:l})}return r}function La(e,t,r,i=0){let n=e;if(n&&typeof n.selectVariant=="function"&&!Array.isArray(t))return n.selectVariant(typeof t=="string"?t:null);let s=e,l=Array.isArray(t)?t:[],o=r??null;if(!o)return i;let a=_o(s).indexOf(o);if(a<0)return i;for(let u of l)if(u.variants.includes(a))return u.material;return i}var Lo={name:"variants",onLoadModel(e,t){let r=e.getVariantName?.();r&&e.selectVariant(r)}},Ia=new WeakMap,Io={name:"webxr-suite",onConfigureXRSessionInit(e,t){let r=new Set(t.optionalFeatures||[]);r.add("hit-test"),r.add("light-estimation");let i=e?.querySelector?.('[slot="ar-overlay"]')||null;i&&(r.add("dom-overlay"),t.domOverlay={root:i},i.addEventListener?.("beforexrselect",n=>{n.preventDefault()})),t.optionalFeatures=Array.from(r)},onXRFrame(e,t,r,i){if(!e||!t||!r||!i)return;let n=Ia.get(t);if(n||(n={lightProbe:null},Ia.set(t,n),typeof t.requestLightProbe=="function"&&t.requestLightProbe().then(s=>{n&&s&&(n.lightProbe=s)}).catch(()=>{})),n.lightProbe&&typeof r.getLightEstimate=="function"){let s=r.getLightEstimate(n.lightProbe);if(s){let l=s.primaryLightDirection,o=s.primaryLightIntensity;if(l&&o&&Array.isArray(e.lights)){let a=e.lights.find(h=>h.type==="directional");a||(a={type:"directional",direction:[.5,1,.8],color:[1,1,1],intensity:1},e.lights.push(a)),a.direction=[l.x,l.y,l.z];let u=Math.max(o.x,o.y,o.z,.001);a.color=[o.x/u,o.y/u,o.z/u],a.intensity=u}s.sphericalHarmonicsCoefficients&&e.gl&&ui(e.gl,s.sphericalHarmonicsCoefficients)}}}};Ve(jn),Ve(yo),Ve(ho),Ve(To),Ve(Io),Ve(Mo),Ve(So),Ve(Lo),Ve(Ro),Ve(Pi),mt.registerScriptRunner(ln),typeof window<"u"&&(window.ThreeLiveBundle=Co);