vestige/apps/dashboard/build/_app/immutable/chunks/DSmtfx7F.js
Sam Valladares 488252d19d release: v2.3.0 — Cognitive Observatory + Zero-Knowledge Sync
Version bumps across all 9 manifests (incl. the mcpb manifest stale at
2.2.0 since v2.2.1) + Cargo.lock + rebuilt embedded dashboard. Full
changelog for the 42 audit fixes (#139/#140/#141), the consolidation
opt-out (#142, thanks @Vrakoss), the WebGPU Cognitive Observatory, and
the zero-knowledge cloud-sync client.

Gates: cargo test 1580/0, clippy clean, svelte-check 937/0/0, build green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 21:58:03 +08:00

1479 lines
468 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var dl=Object.defineProperty;var fl=(l,t,e)=>t in l?dl(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var T=(l,t,e)=>fl(l,typeof t!="symbol"?t+"":t,e);import"./Bzak7iHL.js";import{o as mh,a as pl}from"./JVtQszIZ.js";import{p as Ms,e as rt,r as st,h as ct,t as oe,a as xt,b as Ss,j as At,c as gh,f as qr,g as D,u as Xr,s as Pt,d as yh,i as mt,n as ml,x as gl,bh as yl}from"./CW7md74C.js";import{d as xh,s as Xt,a as wn,e as xl}from"./D90q9c2i.js";import{i as zt}from"./9-jplUL5.js";import{e as bh,s as us,a as Yr}from"./Cc0l8Nd4.js";import{b as vh}from"./ChcFQRZo.js";import{p as lt}from"./BjbQ7qSx.js";import{a as bl}from"./C-rZhKee.js";import{b as wh}from"./CaEJGM7b.js";import{s as kr}from"./BNUnVJrY.js";import{N as ka}from"./CcUbQ_Wl.js";/**
* @license
* Copyright 2010-2024 Three.js Authors
* SPDX-License-Identifier: MIT
*/const _h="172",Rm={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},Lm={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Om=0,Nm=1,Dm=2,Um=3,Vm=0,Gm=1,Wm=2,Hm=3,Er=0,Mh=1,qm=2,vl=0,Ea=1,wl=2,Xm=3,Ym=4,Jm=5,Ra=100,Zm=101,Km=102,jm=103,Qm=104,$m=200,t0=201,e0=202,i0=203,La=204,Oa=205,s0=206,n0=207,r0=208,a0=209,o0=210,h0=211,l0=212,c0=213,u0=214,d0=0,f0=1,p0=2,Na=3,m0=4,g0=5,y0=6,x0=7,Jr=0,b0=1,v0=2,w0=0,_0=1,M0=2,S0=3,A0=4,T0=5,I0=6,C0=7,Da="attached",_l="detached",Zr=300,Kr=301,Ml=302,Sl=303,Al=304,Tl=306,Rr=1e3,ue=1001,Lr=1002,he=1003,Il=1004,z0=1004,Cl=1005,B0=1005,ee=1006,zl=1007,F0=1007,Ln=1008,P0=1008,Sh=1009,Bl=1010,Fl=1011,Pl=1012,kl=1013,jr=1014,Li=1015,El=1016,Rl=1017,Ll=1018,Ol=1020,Nl=35902,Dl=1021,Ul=1022,ys=1023,Vl=1024,Gl=1025,qn=1026,Ua=1027,Ah=1028,Th=1029,Wl=1030,Hl=1031,k0=1032,ql=1033,Xl=33776,Yl=33777,Jl=33778,Zl=33779,Kl=35840,jl=35841,Ql=35842,$l=35843,tc=36196,ec=37492,ic=37496,sc=37808,nc=37809,rc=37810,ac=37811,oc=37812,hc=37813,lc=37814,cc=37815,uc=37816,dc=37817,fc=37818,pc=37819,mc=37820,gc=37821,yc=36492,xc=36494,bc=36495,vc=36283,wc=36284,_c=36285,Mc=36286,Sc=2200,Ac=2201,Tc=2202,Mn=2300,Or=2301,Xn=2302,zi=2400,Bi=2401,Sn=2402,Qr=2500,Ih=2501,E0=0,R0=1,L0=2,Ic=3200,O0=3201,N0=3202,D0=3203,Ni=0,U0=1,Ch="",$t="srgb",Va="srgb-linear",Ga="linear",Yn="srgb",V0=0,li=7680,G0=7681,W0=7682,H0=7683,q0=34055,X0=34056,Y0=5386,J0=512,Z0=513,K0=514,j0=515,Q0=516,$0=517,tg=518,Wa=519,eg=512,ig=513,sg=514,ng=515,rg=516,ag=517,og=518,hg=519,An=35044,lg=35048,cg=35040,ug=35045,dg=35049,fg=35041,pg=35046,mg=35050,gg=35042,yg="100",xg="300 es",Te=2e3,Tn=2001;class We{addEventListener(t,e){this._listeners===void 0&&(this._listeners={});const i=this._listeners;i[t]===void 0&&(i[t]=[]),i[t].indexOf(e)===-1&&i[t].push(e)}hasEventListener(t,e){if(this._listeners===void 0)return!1;const i=this._listeners;return i[t]!==void 0&&i[t].indexOf(e)!==-1}removeEventListener(t,e){if(this._listeners===void 0)return;const s=this._listeners[t];if(s!==void 0){const n=s.indexOf(e);n!==-1&&s.splice(n,1)}}dispatchEvent(t){if(this._listeners===void 0)return;const i=this._listeners[t.type];if(i!==void 0){t.target=this;const s=i.slice(0);for(let n=0,r=s.length;n<r;n++)s[n].call(this,t);t.target=null}}}const Tt=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Ha=1234567;const ii=Math.PI/180,xs=180/Math.PI;function Jt(){const l=Math.random()*4294967295|0,t=Math.random()*4294967295|0,e=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Tt[l&255]+Tt[l>>8&255]+Tt[l>>16&255]+Tt[l>>24&255]+"-"+Tt[t&255]+Tt[t>>8&255]+"-"+Tt[t>>16&15|64]+Tt[t>>24&255]+"-"+Tt[e&63|128]+Tt[e>>8&255]+"-"+Tt[e>>16&255]+Tt[e>>24&255]+Tt[i&255]+Tt[i>>8&255]+Tt[i>>16&255]+Tt[i>>24&255]).toLowerCase()}function H(l,t,e){return Math.max(t,Math.min(e,l))}function $r(l,t){return(l%t+t)%t}function Cc(l,t,e,i,s){return i+(l-t)*(s-i)/(e-t)}function zc(l,t,e){return l!==t?(e-l)/(t-l):0}function ds(l,t,e){return(1-e)*l+e*t}function Bc(l,t,e,i){return ds(l,t,1-Math.exp(-e*i))}function Fc(l,t=1){return t-Math.abs($r(l,t*2)-t)}function Pc(l,t,e){return l<=t?0:l>=e?1:(l=(l-t)/(e-t),l*l*(3-2*l))}function kc(l,t,e){return l<=t?0:l>=e?1:(l=(l-t)/(e-t),l*l*l*(l*(l*6-15)+10))}function Ec(l,t){return l+Math.floor(Math.random()*(t-l+1))}function Rc(l,t){return l+Math.random()*(t-l)}function Lc(l){return l*(.5-Math.random())}function Oc(l){l!==void 0&&(Ha=l);let t=Ha+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function Nc(l){return l*ii}function Dc(l){return l*xs}function Uc(l){return(l&l-1)===0&&l!==0}function Vc(l){return Math.pow(2,Math.ceil(Math.log(l)/Math.LN2))}function Gc(l){return Math.pow(2,Math.floor(Math.log(l)/Math.LN2))}function Wc(l,t,e,i,s){const n=Math.cos,r=Math.sin,a=n(e/2),o=r(e/2),h=n((t+i)/2),c=r((t+i)/2),u=n((t-i)/2),d=r((t-i)/2),f=n((i-t)/2),p=r((i-t)/2);switch(s){case"XYX":l.set(a*c,o*u,o*d,a*h);break;case"YZY":l.set(o*d,a*c,o*u,a*h);break;case"ZXZ":l.set(o*u,o*d,a*c,a*h);break;case"XZX":l.set(a*c,o*p,o*f,a*h);break;case"YXY":l.set(o*f,a*c,o*p,a*h);break;case"ZYZ":l.set(o*p,o*f,a*c,a*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function kt(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return l/4294967295;case Uint16Array:return l/65535;case Uint8Array:return l/255;case Int32Array:return Math.max(l/2147483647,-1);case Int16Array:return Math.max(l/32767,-1);case Int8Array:return Math.max(l/127,-1);default:throw new Error("Invalid component type.")}}function X(l,t){switch(t.constructor){case Float32Array:return l;case Uint32Array:return Math.round(l*4294967295);case Uint16Array:return Math.round(l*65535);case Uint8Array:return Math.round(l*255);case Int32Array:return Math.round(l*2147483647);case Int16Array:return Math.round(l*32767);case Int8Array:return Math.round(l*127);default:throw new Error("Invalid component type.")}}const bg={DEG2RAD:ii,RAD2DEG:xs,generateUUID:Jt,clamp:H,euclideanModulo:$r,mapLinear:Cc,inverseLerp:zc,lerp:ds,damp:Bc,pingpong:Fc,smoothstep:Pc,smootherstep:kc,randInt:Ec,randFloat:Rc,randFloatSpread:Lc,seededRandom:Oc,degToRad:Nc,radToDeg:Dc,isPowerOfTwo:Uc,ceilPowerOfTwo:Vc,floorPowerOfTwo:Gc,setQuaternionFromProperEuler:Wc,normalize:X,denormalize:kt};class B{constructor(t=0,e=0){B.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(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}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=H(this.x,t.x,e.x),this.y=H(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=H(this.x,t,e),this.y=H(this.y,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(H(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(H(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class pe{constructor(t,e,i,s,n,r,a,o,h){pe.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,h)}set(t,e,i,s,n,r,a,o,h){const c=this.elements;return c[0]=t,c[1]=s,c[2]=a,c[3]=e,c[4]=n,c[5]=o,c[6]=i,c[7]=r,c[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],h=i[1],c=i[4],u=i[7],d=i[2],f=i[5],p=i[8],m=s[0],g=s[3],x=s[6],y=s[1],b=s[4],v=s[7],_=s[2],M=s[5],A=s[8];return n[0]=r*m+a*y+o*_,n[3]=r*g+a*b+o*M,n[6]=r*x+a*v+o*A,n[1]=h*m+c*y+u*_,n[4]=h*g+c*b+u*M,n[7]=h*x+c*v+u*A,n[2]=d*m+f*y+p*_,n[5]=d*g+f*b+p*M,n[8]=d*x+f*v+p*A,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],c=t[8];return e*r*c-e*a*h-i*n*c+i*a*o+s*n*h-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],c=t[8],u=c*r-a*h,d=a*o-c*n,f=h*n-r*o,p=e*u+i*d+s*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=u*m,t[1]=(s*h-c*i)*m,t[2]=(a*i-s*r)*m,t[3]=d*m,t[4]=(c*e-s*o)*m,t[5]=(s*n-a*e)*m,t[6]=f*m,t[7]=(i*o-h*e)*m,t[8]=(r*e-i*n)*m,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),h=Math.sin(n);return this.set(i*o,i*h,-i*(o*r+h*a)+r+t,-s*h,s*o,-s*(-h*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Jn.makeScale(t,e)),this}rotate(t){return this.premultiply(Jn.makeRotation(-t)),this}translate(t,e){return this.premultiply(Jn.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<9;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return new this.constructor().fromArray(this.elements)}}const Jn=new pe;function Hc(l){for(let t=l.length-1;t>=0;--t)if(l[t]>=65535)return!0;return!1}const qc={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function Fi(l,t){return new qc[l](t)}function In(l){return document.createElementNS("http://www.w3.org/1999/xhtml",l)}function vg(){const l=In("canvas");return l.style.display="block",l}const qa={};function wg(l){l in qa||(qa[l]=!0,console.warn(l))}function _g(l,t,e){return new Promise(function(i,s){function n(){switch(l.clientWaitSync(t,l.SYNC_FLUSH_COMMANDS_BIT,0)){case l.WAIT_FAILED:s();break;case l.TIMEOUT_EXPIRED:setTimeout(n,e);break;default:i()}}setTimeout(n,e)})}function Mg(l){const t=l.elements;t[2]=.5*t[2]+.5*t[3],t[6]=.5*t[6]+.5*t[7],t[10]=.5*t[10]+.5*t[11],t[14]=.5*t[14]+.5*t[15]}function Sg(l){const t=l.elements;t[11]===-1?(t[10]=-t[10]-1,t[14]=-t[14]):(t[10]=-t[10],t[14]=-t[14]+1)}const Xa=new pe().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ya=new pe().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Xc(){const l={enabled:!0,workingColorSpace:Va,spaces:{},convert:function(s,n,r){return this.enabled===!1||n===r||!n||!r||(this.spaces[n].transfer===Yn&&(s.r=Ie(s.r),s.g=Ie(s.g),s.b=Ie(s.b)),this.spaces[n].primaries!==this.spaces[r].primaries&&(s.applyMatrix3(this.spaces[n].toXYZ),s.applyMatrix3(this.spaces[r].fromXYZ)),this.spaces[r].transfer===Yn&&(s.r=Ei(s.r),s.g=Ei(s.g),s.b=Ei(s.b))),s},fromWorkingColorSpace:function(s,n){return this.convert(s,this.workingColorSpace,n)},toWorkingColorSpace:function(s,n){return this.convert(s,n,this.workingColorSpace)},getPrimaries:function(s){return this.spaces[s].primaries},getTransfer:function(s){return s===Ch?Ga:this.spaces[s].transfer},getLuminanceCoefficients:function(s,n=this.workingColorSpace){return s.fromArray(this.spaces[n].luminanceCoefficients)},define:function(s){Object.assign(this.spaces,s)},_getMatrix:function(s,n,r){return s.copy(this.spaces[n].toXYZ).multiply(this.spaces[r].fromXYZ)},_getDrawingBufferColorSpace:function(s){return this.spaces[s].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(s=this.workingColorSpace){return this.spaces[s].workingColorSpaceConfig.unpackColorSpace}},t=[.64,.33,.3,.6,.15,.06],e=[.2126,.7152,.0722],i=[.3127,.329];return l.define({[Va]:{primaries:t,whitePoint:i,transfer:Ga,toXYZ:Xa,fromXYZ:Ya,luminanceCoefficients:e,workingColorSpaceConfig:{unpackColorSpace:$t},outputColorSpaceConfig:{drawingBufferColorSpace:$t}},[$t]:{primaries:t,whitePoint:i,transfer:Yn,toXYZ:Xa,fromXYZ:Ya,luminanceCoefficients:e,outputColorSpaceConfig:{drawingBufferColorSpace:$t}}}),l}const qt=Xc();function Ie(l){return l<.04045?l*.0773993808:Math.pow(l*.9478672986+.0521327014,2.4)}function Ei(l){return l<.0031308?l*12.92:1.055*Math.pow(l,.41666)-.055}let ci;class Yc{static getDataURL(t){if(/^data:/i.test(t.src)||typeof HTMLCanvasElement>"u")return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{ci===void 0&&(ci=In("canvas")),ci.width=t.width,ci.height=t.height;const i=ci.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=ci}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",t),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(t){if(typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&t instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap){const e=In("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let r=0;r<n.length;r++)n[r]=Ie(n[r]/255)*255;return i.putImageData(s,0,0),e}else if(t.data){const e=t.data.slice(0);for(let i=0;i<e.length;i++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[i]=Math.floor(Ie(e[i]/255)*255):e[i]=Ie(e[i]);return{data:e,width:t.width,height:t.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let Jc=0;class Pi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Jc++}),this.uuid=Jt(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){t===!0&&this.version++}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.images[this.uuid]!==void 0)return t.images[this.uuid];const i={uuid:this.uuid,url:""},s=this.data;if(s!==null){let n;if(Array.isArray(s)){n=[];for(let r=0,a=s.length;r<a;r++)s[r].isDataTexture?n.push(Zn(s[r].image)):n.push(Zn(s[r]))}else n=Zn(s);i.url=n}return e||(t.images[this.uuid]=i),i}}function Zn(l){return typeof HTMLImageElement<"u"&&l instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&l instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&l instanceof ImageBitmap?Yc.getDataURL(l):l.data?{data:Array.from(l.data),width:l.width,height:l.height,type:l.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let Zc=0;class gt extends We{constructor(t=gt.DEFAULT_IMAGE,e=gt.DEFAULT_MAPPING,i=ue,s=ue,n=ee,r=Ln,a=ys,o=Sh,h=gt.DEFAULT_ANISOTROPY,c=Ch){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:Zc++}),this.uuid=Jt(),this.name="",this.source=new Pi(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=h,this.format=a,this.internalFormat=null,this.type=o,this.offset=new B(0,0),this.repeat=new B(1,1),this.center=new B(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new pe,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=c,this.userData={},this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=t===void 0||typeof t=="string";if(!e&&t.textures[this.uuid]!==void 0)return t.textures[this.uuid];const i={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==Zr)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Rr:t.x=t.x-Math.floor(t.x);break;case ue:t.x=t.x<0?0:1;break;case Lr:Math.abs(Math.floor(t.x)%2)===1?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x);break}if(t.y<0||t.y>1)switch(this.wrapT){case Rr:t.y=t.y-Math.floor(t.y);break;case ue:t.y=t.y<0?0:1;break;case Lr:Math.abs(Math.floor(t.y)%2)===1?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y);break}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){t===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){t===!0&&this.pmremVersion++}}gt.DEFAULT_IMAGE=null;gt.DEFAULT_MAPPING=Zr;gt.DEFAULT_ANISOTROPY=1;class St{constructor(t=0,e=0,i=0,s=1){St.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w!==void 0?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const o=t.elements,h=o[0],c=o[4],u=o[8],d=o[1],f=o[5],p=o[9],m=o[2],g=o[6],x=o[10];if(Math.abs(c-d)<.01&&Math.abs(u-m)<.01&&Math.abs(p-g)<.01){if(Math.abs(c+d)<.1&&Math.abs(u+m)<.1&&Math.abs(p+g)<.1&&Math.abs(h+f+x-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;const b=(h+1)/2,v=(f+1)/2,_=(x+1)/2,M=(c+d)/4,A=(u+m)/4,S=(p+g)/4;return b>v&&b>_?b<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(b),s=M/i,n=A/i):v>_?v<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(v),i=M/s,n=S/s):_<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(_),i=A/n,s=S/n),this.set(i,s,n,e),this}let y=Math.sqrt((g-p)*(g-p)+(u-m)*(u-m)+(d-c)*(d-c));return Math.abs(y)<.001&&(y=1),this.x=(g-p)/y,this.y=(u-m)/y,this.z=(d-c)/y,this.w=Math.acos((h+f+x-1)/2),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this.w=e[15],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=H(this.x,t.x,e.x),this.y=H(this.y,t.y,e.y),this.z=H(this.z,t.z,e.z),this.w=H(this.w,t.w,e.w),this}clampScalar(t,e){return this.x=H(this.x,t,e),this.y=H(this.y,t,e),this.z=H(this.z,t,e),this.w=H(this.w,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(H(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class ta extends We{constructor(t=1,e=1,i={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new St(0,0,t,e),this.scissorTest=!1,this.viewport=new St(0,0,t,e);const s={width:t,height:e,depth:1};i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:ee,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},i);const n=new gt(s,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.colorSpace);n.flipY=!1,n.generateMipmaps=i.generateMipmaps,n.internalFormat=i.internalFormat,this.textures=[];const r=i.count;for(let a=0;a<r;a++)this.textures[a]=n.clone(),this.textures[a].isRenderTargetTexture=!0,this.textures[a].renderTarget=this;this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}set depthTexture(t){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),t!==null&&(t.renderTarget=this),this._depthTexture=t}get depthTexture(){return this._depthTexture}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let s=0,n=this.textures.length;s<n;s++)this.textures[s].image.width=t,this.textures[s].image.height=e,this.textures[s].image.depth=i;this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return new this.constructor().copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let i=0,s=t.textures.length;i<s;i++)this.textures[i]=t.textures[i].clone(),this.textures[i].isRenderTargetTexture=!0,this.textures[i].renderTarget=this;const e=Object.assign({},t.texture.image);return this.texture.source=new Pi(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,t.depthTexture!==null&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class ea extends ta{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class zh extends gt{constructor(t=null,e=1,i=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=he,this.minFilter=he,this.wrapR=ue,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Ag extends ea{constructor(t=1,e=1,i=1,s={}){super(t,e,s),this.isWebGLArrayRenderTarget=!0,this.depth=i,this.texture=new zh(null,t,e,i),this.texture.isRenderTargetTexture=!0}}class Bh extends gt{constructor(t=null,e=1,i=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=he,this.minFilter=he,this.wrapR=ue,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Tg extends ea{constructor(t=1,e=1,i=1,s={}){super(t,e,s),this.isWebGL3DRenderTarget=!0,this.depth=i,this.texture=new Bh(null,t,e,i),this.texture.isRenderTargetTexture=!0}}class Zt{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],h=i[s+1],c=i[s+2],u=i[s+3];const d=n[r+0],f=n[r+1],p=n[r+2],m=n[r+3];if(a===0){t[e+0]=o,t[e+1]=h,t[e+2]=c,t[e+3]=u;return}if(a===1){t[e+0]=d,t[e+1]=f,t[e+2]=p,t[e+3]=m;return}if(u!==m||o!==d||h!==f||c!==p){let g=1-a;const x=o*d+h*f+c*p+u*m,y=x>=0?1:-1,b=1-x*x;if(b>Number.EPSILON){const _=Math.sqrt(b),M=Math.atan2(_,x*y);g=Math.sin(g*M)/_,a=Math.sin(a*M)/_}const v=a*y;if(o=o*g+d*v,h=h*g+f*v,c=c*g+p*v,u=u*g+m*v,g===1-a){const _=1/Math.sqrt(o*o+h*h+c*c+u*u);o*=_,h*=_,c*=_,u*=_}}t[e]=o,t[e+1]=h,t[e+2]=c,t[e+3]=u}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],h=i[s+2],c=i[s+3],u=n[r],d=n[r+1],f=n[r+2],p=n[r+3];return t[e]=a*p+c*u+o*f-h*d,t[e+1]=o*p+c*d+h*u-a*f,t[e+2]=h*p+c*f+a*d-o*u,t[e+3]=c*p-a*u-o*d-h*f,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,h=a(i/2),c=a(s/2),u=a(n/2),d=o(i/2),f=o(s/2),p=o(n/2);switch(r){case"XYZ":this._x=d*c*u+h*f*p,this._y=h*f*u-d*c*p,this._z=h*c*p+d*f*u,this._w=h*c*u-d*f*p;break;case"YXZ":this._x=d*c*u+h*f*p,this._y=h*f*u-d*c*p,this._z=h*c*p-d*f*u,this._w=h*c*u+d*f*p;break;case"ZXY":this._x=d*c*u-h*f*p,this._y=h*f*u+d*c*p,this._z=h*c*p+d*f*u,this._w=h*c*u-d*f*p;break;case"ZYX":this._x=d*c*u-h*f*p,this._y=h*f*u+d*c*p,this._z=h*c*p-d*f*u,this._w=h*c*u+d*f*p;break;case"YZX":this._x=d*c*u+h*f*p,this._y=h*f*u+d*c*p,this._z=h*c*p-d*f*u,this._w=h*c*u-d*f*p;break;case"XZY":this._x=d*c*u-h*f*p,this._y=h*f*u-d*c*p,this._z=h*c*p+d*f*u,this._w=h*c*u+d*f*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+r)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],h=e[2],c=e[6],u=e[10],d=i+a+u;if(d>0){const f=.5/Math.sqrt(d+1);this._w=.25/f,this._x=(c-o)*f,this._y=(n-h)*f,this._z=(r-s)*f}else if(i>a&&i>u){const f=2*Math.sqrt(1+i-a-u);this._w=(c-o)/f,this._x=.25*f,this._y=(s+r)/f,this._z=(n+h)/f}else if(a>u){const f=2*Math.sqrt(1+a-i-u);this._w=(n-h)/f,this._x=(s+r)/f,this._y=.25*f,this._z=(o+c)/f}else{const f=2*Math.sqrt(1+u-i-a);this._w=(r-s)/f,this._x=(n+h)/f,this._y=(o+c)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(H(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(i===0)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,h=e._z,c=e._w;return this._x=i*c+r*a+s*h-n*o,this._y=s*c+r*o+n*a-i*h,this._z=n*c+r*h+i*o-s*a,this._w=r*c-i*a-s*o-n*h,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const i=this._x,s=this._y,n=this._z,r=this._w;let a=r*t._w+i*t._x+s*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=s,this._z=n,this;const o=1-a*a;if(o<=Number.EPSILON){const f=1-e;return this._w=f*r+e*this._w,this._x=f*i+e*this._x,this._y=f*s+e*this._y,this._z=f*n+e*this._z,this.normalize(),this}const h=Math.sqrt(o),c=Math.atan2(h,a),u=Math.sin((1-e)*c)/h,d=Math.sin(e*c)/h;return this._w=r*u+this._w*d,this._x=i*u+this._x*d,this._y=s*u+this._y*d,this._z=n*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),i=Math.random(),s=Math.sqrt(1-i),n=Math.sqrt(i);return this.set(s*Math.sin(t),s*Math.cos(t),n*Math.sin(e),n*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class w{constructor(t=0,e=0,i=0){w.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return i===void 0&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(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}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Ja.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ja.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,h=2*(r*s-a*i),c=2*(a*e-n*s),u=2*(n*i-r*e);return this.x=e+o*h+r*u-a*c,this.y=i+o*c+a*h-n*u,this.z=s+o*u+n*c-r*h,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=H(this.x,t.x,e.x),this.y=H(this.y,t.y,e.y),this.z=H(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=H(this.x,t,e),this.y=H(this.y,t,e),this.z=H(this.z,t,e),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(H(i,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Kn.copy(this).projectOnVector(t),this.sub(Kn)}reflect(t){return this.sub(Kn.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(H(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=Math.random()*2-1,i=Math.sqrt(1-e*e);return this.x=i*Math.cos(t),this.y=e,this.z=i*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Kn=new w,Ja=new Zt;class Ut{constructor(t=new w(1/0,1/0,1/0),e=new w(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(ne.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(ne.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=ne.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){t.updateWorldMatrix(!1,!1);const i=t.geometry;if(i!==void 0){const n=i.getAttribute("position");if(e===!0&&n!==void 0&&t.isInstancedMesh!==!0)for(let r=0,a=n.count;r<a;r++)t.isMesh===!0?t.getVertexPosition(r,ne):ne.fromBufferAttribute(n,r),ne.applyMatrix4(t.matrixWorld),this.expandByPoint(ne);else t.boundingBox!==void 0?(t.boundingBox===null&&t.computeBoundingBox(),Bs.copy(t.boundingBox)):(i.boundingBox===null&&i.computeBoundingBox(),Bs.copy(i.boundingBox)),Bs.applyMatrix4(t.matrixWorld),this.union(Bs)}const s=t.children;for(let n=0,r=s.length;n<r;n++)this.expandByObject(s[n],e);return this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,ne),ne.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Hi),Fs.subVectors(this.max,Hi),ui.subVectors(t.a,Hi),di.subVectors(t.b,Hi),fi.subVectors(t.c,Hi),Ee.subVectors(di,ui),Re.subVectors(fi,di),He.subVectors(ui,fi);let e=[0,-Ee.z,Ee.y,0,-Re.z,Re.y,0,-He.z,He.y,Ee.z,0,-Ee.x,Re.z,0,-Re.x,He.z,0,-He.x,-Ee.y,Ee.x,0,-Re.y,Re.x,0,-He.y,He.x,0];return!jn(e,ui,di,fi,Fs)||(e=[1,0,0,0,1,0,0,0,1],!jn(e,ui,di,fi,Fs))?!1:(Ps.crossVectors(Ee,Re),e=[Ps.x,Ps.y,Ps.z],jn(e,ui,di,fi,Fs))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,ne).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=this.getSize(ne).length()*.5),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()?this:(be[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),be[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),be[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),be[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),be[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),be[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),be[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),be[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(be),this)}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const be=[new w,new w,new w,new w,new w,new w,new w,new w],ne=new w,Bs=new Ut,ui=new w,di=new w,fi=new w,Ee=new w,Re=new w,He=new w,Hi=new w,Fs=new w,Ps=new w,qe=new w;function jn(l,t,e,i,s){for(let n=0,r=l.length-3;n<=r;n+=3){qe.fromArray(l,n);const a=s.x*Math.abs(qe.x)+s.y*Math.abs(qe.y)+s.z*Math.abs(qe.z),o=t.dot(qe),h=e.dot(qe),c=i.dot(qe);if(Math.max(-Math.max(o,h,c),Math.min(o,h,c))>a)return!1}return!0}const Kc=new Ut,qi=new w,Qn=new w;class Et{constructor(t=new w,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;e!==void 0?i.copy(e):Kc.setFromPoints(t).getCenter(i);let s=0;for(let n=0,r=t.length;n<r;n++)s=Math.max(s,i.distanceToSquared(t[n]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;qi.subVectors(t,this.center);const e=qi.lengthSq();if(e>this.radius*this.radius){const i=Math.sqrt(e),s=(i-this.radius)*.5;this.center.addScaledVector(qi,s/i),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(this.center.equals(t.center)===!0?this.radius=Math.max(this.radius,t.radius):(Qn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(qi.copy(t.center).add(Qn)),this.expandByPoint(qi.copy(t.center).sub(Qn))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return new this.constructor().copy(this)}}const ve=new w,$n=new w,ks=new w,Le=new w,tr=new w,Es=new w,er=new w;class As{constructor(t=new w,e=new w(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,ve)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=ve.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(ve.copy(this.origin).addScaledVector(this.direction,e),ve.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){$n.copy(t).add(e).multiplyScalar(.5),ks.copy(e).sub(t).normalize(),Le.copy(this.origin).sub($n);const n=t.distanceTo(e)*.5,r=-this.direction.dot(ks),a=Le.dot(this.direction),o=-Le.dot(ks),h=Le.lengthSq(),c=Math.abs(1-r*r);let u,d,f,p;if(c>0)if(u=r*o-a,d=r*a-o,p=n*c,u>=0)if(d>=-p)if(d<=p){const m=1/c;u*=m,d*=m,f=u*(u+r*d+2*a)+d*(r*u+d+2*o)+h}else d=n,u=Math.max(0,-(r*d+a)),f=-u*u+d*(d+2*o)+h;else d=-n,u=Math.max(0,-(r*d+a)),f=-u*u+d*(d+2*o)+h;else d<=-p?(u=Math.max(0,-(-r*n+a)),d=u>0?-n:Math.min(Math.max(-n,-o),n),f=-u*u+d*(d+2*o)+h):d<=p?(u=0,d=Math.min(Math.max(-n,-o),n),f=d*(d+2*o)+h):(u=Math.max(0,-(r*n+a)),d=u>0?n:Math.min(Math.max(-n,-o),n),f=-u*u+d*(d+2*o)+h);else d=r>0?-n:n,u=Math.max(0,-(r*d+a)),f=-u*u+d*(d+2*o)+h;return i&&i.copy(this.origin).addScaledVector(this.direction,u),s&&s.copy($n).addScaledVector(ks,d),f}intersectSphere(t,e){ve.subVectors(t.center,this.origin);const i=ve.dot(this.direction),s=ve.dot(ve)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(e===0)return t.distanceToPoint(this.origin)===0?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return i===null?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return e===0||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,s,n,r,a,o;const h=1/this.direction.x,c=1/this.direction.y,u=1/this.direction.z,d=this.origin;return h>=0?(i=(t.min.x-d.x)*h,s=(t.max.x-d.x)*h):(i=(t.max.x-d.x)*h,s=(t.min.x-d.x)*h),c>=0?(n=(t.min.y-d.y)*c,r=(t.max.y-d.y)*c):(n=(t.max.y-d.y)*c,r=(t.min.y-d.y)*c),i>r||n>s||((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),u>=0?(a=(t.min.z-d.z)*u,o=(t.max.z-d.z)*u):(a=(t.max.z-d.z)*u,o=(t.min.z-d.z)*u),i>o||a>s)||((a>i||i!==i)&&(i=a),(o<s||s!==s)&&(s=o),s<0)?null:this.at(i>=0?i:s,e)}intersectsBox(t){return this.intersectBox(t,ve)!==null}intersectTriangle(t,e,i,s,n){tr.subVectors(e,t),Es.subVectors(i,t),er.crossVectors(tr,Es);let r=this.direction.dot(er),a;if(r>0){if(s)return null;a=1}else if(r<0)a=-1,r=-r;else return null;Le.subVectors(this.origin,t);const o=a*this.direction.dot(Es.crossVectors(Le,Es));if(o<0)return null;const h=a*this.direction.dot(tr.cross(Le));if(h<0||o+h>r)return null;const c=-a*Le.dot(er);return c<0?null:this.at(c/r,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Y{constructor(t,e,i,s,n,r,a,o,h,c,u,d,f,p,m,g){Y.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,e,i,s,n,r,a,o,h,c,u,d,f,p,m,g)}set(t,e,i,s,n,r,a,o,h,c,u,d,f,p,m,g){const x=this.elements;return x[0]=t,x[4]=e,x[8]=i,x[12]=s,x[1]=n,x[5]=r,x[9]=a,x[13]=o,x[2]=h,x[6]=c,x[10]=u,x[14]=d,x[3]=f,x[7]=p,x[11]=m,x[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Y().fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,s=1/pi.setFromMatrixColumn(t,0).length(),n=1/pi.setFromMatrixColumn(t,1).length(),r=1/pi.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),h=Math.sin(s),c=Math.cos(n),u=Math.sin(n);if(t.order==="XYZ"){const d=r*c,f=r*u,p=a*c,m=a*u;e[0]=o*c,e[4]=-o*u,e[8]=h,e[1]=f+p*h,e[5]=d-m*h,e[9]=-a*o,e[2]=m-d*h,e[6]=p+f*h,e[10]=r*o}else if(t.order==="YXZ"){const d=o*c,f=o*u,p=h*c,m=h*u;e[0]=d+m*a,e[4]=p*a-f,e[8]=r*h,e[1]=r*u,e[5]=r*c,e[9]=-a,e[2]=f*a-p,e[6]=m+d*a,e[10]=r*o}else if(t.order==="ZXY"){const d=o*c,f=o*u,p=h*c,m=h*u;e[0]=d-m*a,e[4]=-r*u,e[8]=p+f*a,e[1]=f+p*a,e[5]=r*c,e[9]=m-d*a,e[2]=-r*h,e[6]=a,e[10]=r*o}else if(t.order==="ZYX"){const d=r*c,f=r*u,p=a*c,m=a*u;e[0]=o*c,e[4]=p*h-f,e[8]=d*h+m,e[1]=o*u,e[5]=m*h+d,e[9]=f*h-p,e[2]=-h,e[6]=a*o,e[10]=r*o}else if(t.order==="YZX"){const d=r*o,f=r*h,p=a*o,m=a*h;e[0]=o*c,e[4]=m-d*u,e[8]=p*u+f,e[1]=u,e[5]=r*c,e[9]=-a*c,e[2]=-h*c,e[6]=f*u+p,e[10]=d-m*u}else if(t.order==="XZY"){const d=r*o,f=r*h,p=a*o,m=a*h;e[0]=o*c,e[4]=-u,e[8]=h*c,e[1]=d*u+m,e[5]=r*c,e[9]=f*u-p,e[2]=p*u-f,e[6]=a*c,e[10]=m*u+d}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(jc,t,Qc)}lookAt(t,e,i){const s=this.elements;return Wt.subVectors(t,e),Wt.lengthSq()===0&&(Wt.z=1),Wt.normalize(),Oe.crossVectors(i,Wt),Oe.lengthSq()===0&&(Math.abs(i.z)===1?Wt.x+=1e-4:Wt.z+=1e-4,Wt.normalize(),Oe.crossVectors(i,Wt)),Oe.normalize(),Rs.crossVectors(Wt,Oe),s[0]=Oe.x,s[4]=Rs.x,s[8]=Wt.x,s[1]=Oe.y,s[5]=Rs.y,s[9]=Wt.y,s[2]=Oe.z,s[6]=Rs.z,s[10]=Wt.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],h=i[12],c=i[1],u=i[5],d=i[9],f=i[13],p=i[2],m=i[6],g=i[10],x=i[14],y=i[3],b=i[7],v=i[11],_=i[15],M=s[0],A=s[4],S=s[8],C=s[12],z=s[1],k=s[5],U=s[9],W=s[13],R=s[2],I=s[6],N=s[10],wt=s[14],Bt=s[3],nt=s[7],ht=s[11],et=s[15];return n[0]=r*M+a*z+o*R+h*Bt,n[4]=r*A+a*k+o*I+h*nt,n[8]=r*S+a*U+o*N+h*ht,n[12]=r*C+a*W+o*wt+h*et,n[1]=c*M+u*z+d*R+f*Bt,n[5]=c*A+u*k+d*I+f*nt,n[9]=c*S+u*U+d*N+f*ht,n[13]=c*C+u*W+d*wt+f*et,n[2]=p*M+m*z+g*R+x*Bt,n[6]=p*A+m*k+g*I+x*nt,n[10]=p*S+m*U+g*N+x*ht,n[14]=p*C+m*W+g*wt+x*et,n[3]=y*M+b*z+v*R+_*Bt,n[7]=y*A+b*k+v*I+_*nt,n[11]=y*S+b*U+v*N+_*ht,n[15]=y*C+b*W+v*wt+_*et,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],h=t[13],c=t[2],u=t[6],d=t[10],f=t[14],p=t[3],m=t[7],g=t[11],x=t[15];return p*(+n*o*u-s*h*u-n*a*d+i*h*d+s*a*f-i*o*f)+m*(+e*o*f-e*h*d+n*r*d-s*r*f+s*h*c-n*o*c)+g*(+e*h*u-e*a*f-n*r*u+i*r*f+n*a*c-i*h*c)+x*(-s*a*c-e*o*u+e*a*d+s*r*u-i*r*d+i*o*c)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],h=t[7],c=t[8],u=t[9],d=t[10],f=t[11],p=t[12],m=t[13],g=t[14],x=t[15],y=u*g*h-m*d*h+m*o*f-a*g*f-u*o*x+a*d*x,b=p*d*h-c*g*h-p*o*f+r*g*f+c*o*x-r*d*x,v=c*m*h-p*u*h+p*a*f-r*m*f-c*a*x+r*u*x,_=p*u*o-c*m*o-p*a*d+r*m*d+c*a*g-r*u*g,M=e*y+i*b+s*v+n*_;if(M===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const A=1/M;return t[0]=y*A,t[1]=(m*d*n-u*g*n-m*s*f+i*g*f+u*s*x-i*d*x)*A,t[2]=(a*g*n-m*o*n+m*s*h-i*g*h-a*s*x+i*o*x)*A,t[3]=(u*o*n-a*d*n-u*s*h+i*d*h+a*s*f-i*o*f)*A,t[4]=b*A,t[5]=(c*g*n-p*d*n+p*s*f-e*g*f-c*s*x+e*d*x)*A,t[6]=(p*o*n-r*g*n-p*s*h+e*g*h+r*s*x-e*o*x)*A,t[7]=(r*d*n-c*o*n+c*s*h-e*d*h-r*s*f+e*o*f)*A,t[8]=v*A,t[9]=(p*u*n-c*m*n-p*i*f+e*m*f+c*i*x-e*u*x)*A,t[10]=(r*m*n-p*a*n+p*i*h-e*m*h-r*i*x+e*a*x)*A,t[11]=(c*a*n-r*u*n-c*i*h+e*u*h+r*i*f-e*a*f)*A,t[12]=_*A,t[13]=(c*m*s-p*u*s+p*i*d-e*m*d-c*i*g+e*u*g)*A,t[14]=(p*a*s-r*m*s-p*i*o+e*m*o+r*i*g-e*a*g)*A,t[15]=(r*u*s-c*a*s+c*i*o-e*u*o-r*i*d+e*a*d)*A,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,h=n*r,c=n*a;return this.set(h*r+i,h*a-s*o,h*o+s*a,0,h*a+s*o,c*a+i,c*o-s*r,0,h*o-s*a,c*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,h=n+n,c=r+r,u=a+a,d=n*h,f=n*c,p=n*u,m=r*c,g=r*u,x=a*u,y=o*h,b=o*c,v=o*u,_=i.x,M=i.y,A=i.z;return s[0]=(1-(m+x))*_,s[1]=(f+v)*_,s[2]=(p-b)*_,s[3]=0,s[4]=(f-v)*M,s[5]=(1-(d+x))*M,s[6]=(g+y)*M,s[7]=0,s[8]=(p+b)*A,s[9]=(g-y)*A,s[10]=(1-(d+m))*A,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;let n=pi.set(s[0],s[1],s[2]).length();const r=pi.set(s[4],s[5],s[6]).length(),a=pi.set(s[8],s[9],s[10]).length();this.determinant()<0&&(n=-n),t.x=s[12],t.y=s[13],t.z=s[14],re.copy(this);const h=1/n,c=1/r,u=1/a;return re.elements[0]*=h,re.elements[1]*=h,re.elements[2]*=h,re.elements[4]*=c,re.elements[5]*=c,re.elements[6]*=c,re.elements[8]*=u,re.elements[9]*=u,re.elements[10]*=u,e.setFromRotationMatrix(re),i.x=n,i.y=r,i.z=a,this}makePerspective(t,e,i,s,n,r,a=Te){const o=this.elements,h=2*n/(e-t),c=2*n/(i-s),u=(e+t)/(e-t),d=(i+s)/(i-s);let f,p;if(a===Te)f=-(r+n)/(r-n),p=-2*r*n/(r-n);else if(a===Tn)f=-r/(r-n),p=-r*n/(r-n);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);return o[0]=h,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=c,o[9]=d,o[13]=0,o[2]=0,o[6]=0,o[10]=f,o[14]=p,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=Te){const o=this.elements,h=1/(e-t),c=1/(i-s),u=1/(r-n),d=(e+t)*h,f=(i+s)*c;let p,m;if(a===Te)p=(r+n)*u,m=-2*u;else if(a===Tn)p=n*u,m=-1*u;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);return o[0]=2*h,o[4]=0,o[8]=0,o[12]=-d,o[1]=0,o[5]=2*c,o[9]=0,o[13]=-f,o[2]=0,o[6]=0,o[10]=m,o[14]=-p,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let s=0;s<16;s++)if(e[s]!==i[s])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const pi=new w,re=new Y,jc=new w(0,0,0),Qc=new w(1,1,1),Oe=new w,Rs=new w,Wt=new w,Za=new Y,Ka=new Zt;class fe{constructor(t=0,e=0,i=0,s=fe.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],h=s[5],c=s[9],u=s[2],d=s[6],f=s[10];switch(e){case"XYZ":this._y=Math.asin(H(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,f),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(d,h),this._z=0);break;case"YXZ":this._x=Math.asin(-H(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,f),this._z=Math.atan2(o,h)):(this._y=Math.atan2(-u,n),this._z=0);break;case"ZXY":this._x=Math.asin(H(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-r,h)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-H(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,h));break;case"YZX":this._z=Math.asin(H(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,h),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(a,f));break;case"XZY":this._z=Math.asin(-H(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,h),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-c,f),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,i===!0&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return Za.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Za,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Ka.setFromEuler(this),this.setFromQuaternion(Ka,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],t[3]!==void 0&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}fe.DEFAULT_ORDER="XYZ";class Fh{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return(this.mask&t.mask)!==0}isEnabled(t){return(this.mask&(1<<t|0))!==0}}let $c=0;const ja=new w,mi=new Zt,we=new Y,Ls=new w,Xi=new w,tu=new w,eu=new Zt,Qa=new w(1,0,0),$a=new w(0,1,0),to=new w(0,0,1),eo={type:"added"},iu={type:"removed"},gi={type:"childadded",child:null},ir={type:"childremoved",child:null};class tt extends We{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:$c++}),this.uuid=Jt(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=tt.DEFAULT_UP.clone();const t=new w,e=new fe,i=new Zt,s=new w(1,1,1);function n(){i.setFromEuler(e,!1)}function r(){e.setFromQuaternion(i,void 0,!1)}e._onChange(n),i._onChange(r),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new Y},normalMatrix:{value:new pe}}),this.matrix=new Y,this.matrixWorld=new Y,this.matrixAutoUpdate=tt.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=tt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Fh,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return mi.setFromAxisAngle(t,e),this.quaternion.multiply(mi),this}rotateOnWorldAxis(t,e){return mi.setFromAxisAngle(t,e),this.quaternion.premultiply(mi),this}rotateX(t){return this.rotateOnAxis(Qa,t)}rotateY(t){return this.rotateOnAxis($a,t)}rotateZ(t){return this.rotateOnAxis(to,t)}translateOnAxis(t,e){return ja.copy(t).applyQuaternion(this.quaternion),this.position.add(ja.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Qa,t)}translateY(t){return this.translateOnAxis($a,t)}translateZ(t){return this.translateOnAxis(to,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(we.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Ls.copy(t):Ls.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),Xi.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?we.lookAt(Xi,Ls,this.up):we.lookAt(Ls,Xi,this.up),this.quaternion.setFromRotationMatrix(we),s&&(we.extractRotation(s.matrixWorld),mi.setFromRotationMatrix(we),this.quaternion.premultiply(mi.invert()))}add(t){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?(console.error("THREE.Object3D.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(eo),gi.child=t,this.dispatchEvent(gi),gi.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let i=0;i<arguments.length;i++)this.remove(arguments[i]);return this}const e=this.children.indexOf(t);return e!==-1&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(iu),ir.child=t,this.dispatchEvent(ir),ir.child=null),this}removeFromParent(){const t=this.parent;return t!==null&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),we.copy(this.matrixWorld).invert(),t.parent!==null&&(t.parent.updateWorldMatrix(!0,!1),we.multiply(t.parent.matrixWorld)),t.applyMatrix4(we),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(eo),gi.child=t,this.dispatchEvent(gi),gi.child=null,this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const r=this.children[i].getObjectByProperty(t,e);if(r!==void 0)return r}}getObjectsByProperty(t,e,i=[]){this[t]===e&&i.push(this);const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].getObjectsByProperty(t,e,i);return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xi,t,tu),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Xi,eu,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(this.visible===!1)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;e!==null&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e){const i=this.parent;if(t===!0&&i!==null&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),e===!0){const s=this.children;for(let n=0,r=s.length;n<r;n++)s[n].updateWorldMatrix(!1,!0)}}toJSON(t){const e=t===void 0||typeof t=="string",i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const s={};s.uuid=this.uuid,s.type=this.type,this.name!==""&&(s.name=this.name),this.castShadow===!0&&(s.castShadow=!0),this.receiveShadow===!0&&(s.receiveShadow=!0),this.visible===!1&&(s.visible=!1),this.frustumCulled===!1&&(s.frustumCulled=!1),this.renderOrder!==0&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(s.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(s.type="BatchedMesh",s.perObjectFrustumCulled=this.perObjectFrustumCulled,s.sortObjects=this.sortObjects,s.drawRanges=this._drawRanges,s.reservedRanges=this._reservedRanges,s.visibility=this._visibility,s.active=this._active,s.bounds=this._bounds.map(a=>({boxInitialized:a.boxInitialized,boxMin:a.box.min.toArray(),boxMax:a.box.max.toArray(),sphereInitialized:a.sphereInitialized,sphereRadius:a.sphere.radius,sphereCenter:a.sphere.center.toArray()})),s.maxInstanceCount=this._maxInstanceCount,s.maxVertexCount=this._maxVertexCount,s.maxIndexCount=this._maxIndexCount,s.geometryInitialized=this._geometryInitialized,s.geometryCount=this._geometryCount,s.matricesTexture=this._matricesTexture.toJSON(t),this._colorsTexture!==null&&(s.colorsTexture=this._colorsTexture.toJSON(t)),this.boundingSphere!==null&&(s.boundingSphere={center:s.boundingSphere.center.toArray(),radius:s.boundingSphere.radius}),this.boundingBox!==null&&(s.boundingBox={min:s.boundingBox.min.toArray(),max:s.boundingBox.max.toArray()}));function n(a,o){return a[o.uuid]===void 0&&(a[o.uuid]=o.toJSON(t)),o.uuid}if(this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const a=this.geometry.parameters;if(a!==void 0&&a.shapes!==void 0){const o=a.shapes;if(Array.isArray(o))for(let h=0,c=o.length;h<c;h++){const u=o[h];n(t.shapes,u)}else n(t.shapes,o)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){const a=[];for(let o=0,h=this.material.length;o<h;o++)a.push(n(t.materials,this.material[o]));s.material=a}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let a=0;a<this.children.length;a++)s.children.push(this.children[a].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let a=0;a<this.animations.length;a++){const o=this.animations[a];s.animations.push(n(t.animations,o))}}if(e){const a=r(t.geometries),o=r(t.materials),h=r(t.textures),c=r(t.images),u=r(t.shapes),d=r(t.skeletons),f=r(t.animations),p=r(t.nodes);a.length>0&&(i.geometries=a),o.length>0&&(i.materials=o),h.length>0&&(i.textures=h),c.length>0&&(i.images=c),u.length>0&&(i.shapes=u),d.length>0&&(i.skeletons=d),f.length>0&&(i.animations=f),p.length>0&&(i.nodes=p)}return i.object=s,i;function r(a){const o=[];for(const h in a){const c=a[h];delete c.metadata,o.push(c)}return o}}clone(t){return new this.constructor().copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),e===!0)for(let i=0;i<t.children.length;i++){const s=t.children[i];this.add(s.clone())}return this}}tt.DEFAULT_UP=new w(0,1,0);tt.DEFAULT_MATRIX_AUTO_UPDATE=!0;tt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ae=new w,_e=new w,sr=new w,Me=new w,yi=new w,xi=new w,io=new w,nr=new w,rr=new w,ar=new w,or=new St,hr=new St,lr=new St;class Yt{constructor(t=new w,e=new w,i=new w){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),ae.subVectors(t,e),s.cross(ae);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){ae.subVectors(s,e),_e.subVectors(i,e),sr.subVectors(t,e);const r=ae.dot(ae),a=ae.dot(_e),o=ae.dot(sr),h=_e.dot(_e),c=_e.dot(sr),u=r*h-a*a;if(u===0)return n.set(0,0,0),null;const d=1/u,f=(h*o-a*c)*d,p=(r*c-a*o)*d;return n.set(1-f-p,p,f)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,Me)===null?!1:Me.x>=0&&Me.y>=0&&Me.x+Me.y<=1}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,Me)===null?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(n,Me.x),o.addScaledVector(r,Me.y),o.addScaledVector(a,Me.z),o)}static getInterpolatedAttribute(t,e,i,s,n,r){return or.setScalar(0),hr.setScalar(0),lr.setScalar(0),or.fromBufferAttribute(t,e),hr.fromBufferAttribute(t,i),lr.fromBufferAttribute(t,s),r.setScalar(0),r.addScaledVector(or,n.x),r.addScaledVector(hr,n.y),r.addScaledVector(lr,n.z),r}static isFrontFacing(t,e,i,s){return ae.subVectors(i,e),_e.subVectors(t,e),ae.cross(_e).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return new this.constructor().copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return ae.subVectors(this.c,this.b),_e.subVectors(this.a,this.b),ae.cross(_e).length()*.5}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Yt.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Yt.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,i,s,n){return Yt.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return Yt.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Yt.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;yi.subVectors(s,i),xi.subVectors(n,i),nr.subVectors(t,i);const o=yi.dot(nr),h=xi.dot(nr);if(o<=0&&h<=0)return e.copy(i);rr.subVectors(t,s);const c=yi.dot(rr),u=xi.dot(rr);if(c>=0&&u<=c)return e.copy(s);const d=o*u-c*h;if(d<=0&&o>=0&&c<=0)return r=o/(o-c),e.copy(i).addScaledVector(yi,r);ar.subVectors(t,n);const f=yi.dot(ar),p=xi.dot(ar);if(p>=0&&f<=p)return e.copy(n);const m=f*h-o*p;if(m<=0&&h>=0&&p<=0)return a=h/(h-p),e.copy(i).addScaledVector(xi,a);const g=c*p-f*u;if(g<=0&&u-c>=0&&f-p>=0)return io.subVectors(n,s),a=(u-c)/(u-c+(f-p)),e.copy(s).addScaledVector(io,a);const x=1/(g+m+d);return r=m*x,a=d*x,e.copy(i).addScaledVector(yi,r).addScaledVector(xi,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Ph={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},Ne={h:0,s:0,l:0},Os={h:0,s:0,l:0};function cr(l,t,e){return e<0&&(e+=1),e>1&&(e-=1),e<1/6?l+(t-l)*6*e:e<1/2?t:e<2/3?l+(t-l)*6*(2/3-e):l}class V{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(e===void 0&&i===void 0){const s=t;s&&s.isColor?this.copy(s):typeof s=="number"?this.setHex(s):typeof s=="string"&&this.setStyle(s)}else this.setRGB(t,e,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=$t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(t&255)/255,qt.toWorkingColorSpace(this,e),this}setRGB(t,e,i,s=qt.workingColorSpace){return this.r=t,this.g=e,this.b=i,qt.toWorkingColorSpace(this,s),this}setHSL(t,e,i,s=qt.workingColorSpace){if(t=$r(t,1),e=H(e,0,1),i=H(i,0,1),e===0)this.r=this.g=this.b=i;else{const n=i<=.5?i*(1+e):i+e-i*e,r=2*i-n;this.r=cr(r,n,t+1/3),this.g=cr(r,n,t),this.b=cr(r,n,t-1/3)}return qt.toWorkingColorSpace(this,s),this}setStyle(t,e=$t){function i(n){n!==void 0&&parseFloat(n)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let n;const r=s[1],a=s[2];switch(r){case"rgb":case"rgba":if(n=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(n[4]),this.setRGB(Math.min(255,parseInt(n[1],10))/255,Math.min(255,parseInt(n[2],10))/255,Math.min(255,parseInt(n[3],10))/255,e);if(n=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(n[4]),this.setRGB(Math.min(100,parseInt(n[1],10))/100,Math.min(100,parseInt(n[2],10))/100,Math.min(100,parseInt(n[3],10))/100,e);break;case"hsl":case"hsla":if(n=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return i(n[4]),this.setHSL(parseFloat(n[1])/360,parseFloat(n[2])/100,parseFloat(n[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const n=s[1],r=n.length;if(r===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(r===6)return this.setHex(parseInt(n,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=$t){const i=Ph[t.toLowerCase()];return i!==void 0?this.setHex(i,e):console.warn("THREE.Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Ie(t.r),this.g=Ie(t.g),this.b=Ie(t.b),this}copyLinearToSRGB(t){return this.r=Ei(t.r),this.g=Ei(t.g),this.b=Ei(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=$t){return qt.fromWorkingColorSpace(It.copy(this),t),Math.round(H(It.r*255,0,255))*65536+Math.round(H(It.g*255,0,255))*256+Math.round(H(It.b*255,0,255))}getHexString(t=$t){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=qt.workingColorSpace){qt.fromWorkingColorSpace(It.copy(this),e);const i=It.r,s=It.g,n=It.b,r=Math.max(i,s,n),a=Math.min(i,s,n);let o,h;const c=(a+r)/2;if(a===r)o=0,h=0;else{const u=r-a;switch(h=c<=.5?u/(r+a):u/(2-r-a),r){case i:o=(s-n)/u+(s<n?6:0);break;case s:o=(n-i)/u+2;break;case n:o=(i-s)/u+4;break}o/=6}return t.h=o,t.s=h,t.l=c,t}getRGB(t,e=qt.workingColorSpace){return qt.fromWorkingColorSpace(It.copy(this),e),t.r=It.r,t.g=It.g,t.b=It.b,t}getStyle(t=$t){qt.fromWorkingColorSpace(It.copy(this),t);const e=It.r,i=It.g,s=It.b;return t!==$t?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(e*255)},${Math.round(i*255)},${Math.round(s*255)})`}offsetHSL(t,e,i){return this.getHSL(Ne),this.setHSL(Ne.h+t,Ne.s+e,Ne.l+i)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(Ne),t.getHSL(Os);const i=ds(Ne.h,Os.h,e),s=ds(Ne.s,Os.s,e),n=ds(Ne.l,Os.l,e);return this.setHSL(i,s,n),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,s=this.b,n=t.elements;return this.r=n[0]*e+n[3]*i+n[6]*s,this.g=n[1]*e+n[4]*i+n[7]*s,this.b=n[2]*e+n[5]*i+n[8]*s,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const It=new V;V.NAMES=Ph;let su=0;class Rt extends We{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:su++}),this.uuid=Jt(),this.name="",this.type="Material",this.blending=Ea,this.side=Er,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=La,this.blendDst=Oa,this.blendEquation=Ra,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new V(0,0,0),this.blendAlpha=0,this.depthFunc=Na,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=Wa,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=li,this.stencilZFail=li,this.stencilZPass=li,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(t!==void 0)for(const e in t){const i=t[e];if(i===void 0){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const s=this[e];if(s===void 0){console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`);continue}s&&s.isColor?s.set(i):s&&s.isVector3&&i&&i.isVector3?s.copy(i):this[e]=i}}toJSON(t){const e=t===void 0||typeof t=="string";e&&(t={textures:{},images:{}});const i={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};i.uuid=this.uuid,i.type=this.type,this.name!==""&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),this.roughness!==void 0&&(i.roughness=this.roughness),this.metalness!==void 0&&(i.metalness=this.metalness),this.sheen!==void 0&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity!==void 0&&this.emissiveIntensity!==1&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(i.shininess=this.shininess),this.clearcoat!==void 0&&(i.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.dispersion!==void 0&&(i.dispersion=this.dispersion),this.iridescence!==void 0&&(i.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(i.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),this.anisotropy!==void 0&&(i.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,this.combine!==void 0&&(i.combine=this.combine)),this.envMapRotation!==void 0&&(i.envMapRotation=this.envMapRotation.toArray()),this.envMapIntensity!==void 0&&(i.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(i.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),this.transmission!==void 0&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),this.thickness!==void 0&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(i.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(i.size=this.size),this.shadowSide!==null&&(i.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==Ea&&(i.blending=this.blending),this.side!==Er&&(i.side=this.side),this.vertexColors===!0&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.transparent===!0&&(i.transparent=!0),this.blendSrc!==La&&(i.blendSrc=this.blendSrc),this.blendDst!==Oa&&(i.blendDst=this.blendDst),this.blendEquation!==Ra&&(i.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(i.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(i.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(i.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(i.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(i.blendAlpha=this.blendAlpha),this.depthFunc!==Na&&(i.depthFunc=this.depthFunc),this.depthTest===!1&&(i.depthTest=this.depthTest),this.depthWrite===!1&&(i.depthWrite=this.depthWrite),this.colorWrite===!1&&(i.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(i.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==Wa&&(i.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(i.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(i.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==li&&(i.stencilFail=this.stencilFail),this.stencilZFail!==li&&(i.stencilZFail=this.stencilZFail),this.stencilZPass!==li&&(i.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(i.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(i.rotation=this.rotation),this.polygonOffset===!0&&(i.polygonOffset=!0),this.polygonOffsetFactor!==0&&(i.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(i.linewidth=this.linewidth),this.dashSize!==void 0&&(i.dashSize=this.dashSize),this.gapSize!==void 0&&(i.gapSize=this.gapSize),this.scale!==void 0&&(i.scale=this.scale),this.dithering===!0&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),this.alphaHash===!0&&(i.alphaHash=!0),this.alphaToCoverage===!0&&(i.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=!0),this.forceSinglePass===!0&&(i.forceSinglePass=!0),this.wireframe===!0&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(i.flatShading=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),this.fog===!1&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData);function s(n){const r=[];for(const a in n){const o=n[a];delete o.metadata,r.push(o)}return r}if(e){const n=s(t.textures),r=s(t.images);n.length>0&&(i.textures=n),r.length>0&&(i.images=r)}return i}clone(){return new this.constructor().copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(e!==null){const s=e.length;i=new Array(s);for(let n=0;n!==s;++n)i[n]=e[n].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){t===!0&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}}class Di extends Rt{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new V(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fe,this.combine=Jr,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Ae=nu();function nu(){const l=new ArrayBuffer(4),t=new Float32Array(l),e=new Uint32Array(l),i=new Uint32Array(512),s=new Uint32Array(512);for(let o=0;o<256;++o){const h=o-127;h<-27?(i[o]=0,i[o|256]=32768,s[o]=24,s[o|256]=24):h<-14?(i[o]=1024>>-h-14,i[o|256]=1024>>-h-14|32768,s[o]=-h-1,s[o|256]=-h-1):h<=15?(i[o]=h+15<<10,i[o|256]=h+15<<10|32768,s[o]=13,s[o|256]=13):h<128?(i[o]=31744,i[o|256]=64512,s[o]=24,s[o|256]=24):(i[o]=31744,i[o|256]=64512,s[o]=13,s[o|256]=13)}const n=new Uint32Array(2048),r=new Uint32Array(64),a=new Uint32Array(64);for(let o=1;o<1024;++o){let h=o<<13,c=0;for(;(h&8388608)===0;)h<<=1,c-=8388608;h&=-8388609,c+=947912704,n[o]=h|c}for(let o=1024;o<2048;++o)n[o]=939524096+(o-1024<<13);for(let o=1;o<31;++o)r[o]=o<<23;r[31]=1199570944,r[32]=2147483648;for(let o=33;o<63;++o)r[o]=2147483648+(o-32<<23);r[63]=3347054592;for(let o=1;o<64;++o)o!==32&&(a[o]=1024);return{floatView:t,uint32View:e,baseTable:i,shiftTable:s,mantissaTable:n,exponentTable:r,offsetTable:a}}function Dt(l){Math.abs(l)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),l=H(l,-65504,65504),Ae.floatView[0]=l;const t=Ae.uint32View[0],e=t>>23&511;return Ae.baseTable[e]+((t&8388607)>>Ae.shiftTable[e])}function ls(l){const t=l>>10;return Ae.uint32View[0]=Ae.mantissaTable[Ae.offsetTable[t]+(l&1023)]+Ae.exponentTable[t],Ae.floatView[0]}const Ig={toHalfFloat:Dt,fromHalfFloat:ls},yt=new w,Ns=new B;class dt{constructor(t,e,i=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=t!==void 0?t.length/e:0,this.normalized=i,this.usage=An,this.updateRanges=[],this.gpuType=Li,this.version=0}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(this.itemSize===2)for(let e=0,i=this.count;e<i;e++)Ns.fromBufferAttribute(this,e),Ns.applyMatrix3(t),this.setXY(e,Ns.x,Ns.y);else if(this.itemSize===3)for(let e=0,i=this.count;e<i;e++)yt.fromBufferAttribute(this,e),yt.applyMatrix3(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)yt.fromBufferAttribute(this,e),yt.applyMatrix4(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)yt.fromBufferAttribute(this,e),yt.applyNormalMatrix(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)yt.fromBufferAttribute(this,e),yt.transformDirection(t),this.setXYZ(e,yt.x,yt.y,yt.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=kt(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=X(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=kt(e,this.array)),e}setX(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=kt(e,this.array)),e}setY(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+1]=e,this}getZ(t){let e=this.array[t*this.itemSize+2];return this.normalized&&(e=kt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+2]=e,this}getW(t){let e=this.array[t*this.itemSize+3];return this.normalized&&(e=kt(e,this.array)),e}setW(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array),n=X(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==""&&(t.name=this.name),this.usage!==An&&(t.usage=this.usage),t}}class Cg extends dt{constructor(t,e,i){super(new Int8Array(t),e,i)}}class zg extends dt{constructor(t,e,i){super(new Uint8Array(t),e,i)}}class Bg extends dt{constructor(t,e,i){super(new Uint8ClampedArray(t),e,i)}}class Fg extends dt{constructor(t,e,i){super(new Int16Array(t),e,i)}}class ru extends dt{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Pg extends dt{constructor(t,e,i){super(new Int32Array(t),e,i)}}class au extends dt{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class kg extends dt{constructor(t,e,i){super(new Uint16Array(t),e,i),this.isFloat16BufferAttribute=!0}getX(t){let e=ls(this.array[t*this.itemSize]);return this.normalized&&(e=kt(e,this.array)),e}setX(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize]=Dt(e),this}getY(t){let e=ls(this.array[t*this.itemSize+1]);return this.normalized&&(e=kt(e,this.array)),e}setY(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+1]=Dt(e),this}getZ(t){let e=ls(this.array[t*this.itemSize+2]);return this.normalized&&(e=kt(e,this.array)),e}setZ(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+2]=Dt(e),this}getW(t){let e=ls(this.array[t*this.itemSize+3]);return this.normalized&&(e=kt(e,this.array)),e}setW(t,e){return this.normalized&&(e=X(e,this.array)),this.array[t*this.itemSize+3]=Dt(e),this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array)),this.array[t+0]=Dt(e),this.array[t+1]=Dt(i),this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array)),this.array[t+0]=Dt(e),this.array[t+1]=Dt(i),this.array[t+2]=Dt(s),this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array),n=X(n,this.array)),this.array[t+0]=Dt(e),this.array[t+1]=Dt(i),this.array[t+2]=Dt(s),this.array[t+3]=Dt(n),this}}class O extends dt{constructor(t,e,i){super(new Float32Array(t),e,i)}}let ou=0;const Qt=new Y,ur=new tt,bi=new w,Ht=new Ut,Yi=new Ut,Mt=new w;class Z extends We{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:ou++}),this.uuid=Jt(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Hc(t)?au:ru)(t,1):this.index=t,this}setIndirect(t){return this.indirect=t,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return this.attributes[t]!==void 0}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;e!==void 0&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(i!==void 0){const n=new pe().getNormalMatrix(t);i.applyNormalMatrix(n),i.needsUpdate=!0}const s=this.attributes.tangent;return s!==void 0&&(s.transformDirection(t),s.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(t){return Qt.makeRotationFromQuaternion(t),this.applyMatrix4(Qt),this}rotateX(t){return Qt.makeRotationX(t),this.applyMatrix4(Qt),this}rotateY(t){return Qt.makeRotationY(t),this.applyMatrix4(Qt),this}rotateZ(t){return Qt.makeRotationZ(t),this.applyMatrix4(Qt),this}translate(t,e,i){return Qt.makeTranslation(t,e,i),this.applyMatrix4(Qt),this}scale(t,e,i){return Qt.makeScale(t,e,i),this.applyMatrix4(Qt),this}lookAt(t){return ur.lookAt(t),ur.updateMatrix(),this.applyMatrix4(ur.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(bi).negate(),this.translate(bi.x,bi.y,bi.z),this}setFromPoints(t){const e=this.getAttribute("position");if(e===void 0){const i=[];for(let s=0,n=t.length;s<n;s++){const r=t[s];i.push(r.x,r.y,r.z||0)}this.setAttribute("position",new O(i,3))}else{const i=Math.min(t.length,e.count);for(let s=0;s<i;s++){const n=t[s];e.setXYZ(s,n.x,n.y,n.z||0)}t.length>e.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ut);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),this.boundingBox.set(new w(-1/0,-1/0,-1/0),new w(1/0,1/0,1/0));return}if(t!==void 0){if(this.boundingBox.setFromBufferAttribute(t),e)for(let i=0,s=e.length;i<s;i++){const n=e[i];Ht.setFromBufferAttribute(n),this.morphTargetsRelative?(Mt.addVectors(this.boundingBox.min,Ht.min),this.boundingBox.expandByPoint(Mt),Mt.addVectors(this.boundingBox.max,Ht.max),this.boundingBox.expandByPoint(Mt)):(this.boundingBox.expandByPoint(Ht.min),this.boundingBox.expandByPoint(Ht.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Et);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute){console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),this.boundingSphere.set(new w,1/0);return}if(t){const i=this.boundingSphere.center;if(Ht.setFromBufferAttribute(t),e)for(let n=0,r=e.length;n<r;n++){const a=e[n];Yi.setFromBufferAttribute(a),this.morphTargetsRelative?(Mt.addVectors(Ht.min,Yi.min),Ht.expandByPoint(Mt),Mt.addVectors(Ht.max,Yi.max),Ht.expandByPoint(Mt)):(Ht.expandByPoint(Yi.min),Ht.expandByPoint(Yi.max))}Ht.getCenter(i);let s=0;for(let n=0,r=t.count;n<r;n++)Mt.fromBufferAttribute(t,n),s=Math.max(s,i.distanceToSquared(Mt));if(e)for(let n=0,r=e.length;n<r;n++){const a=e[n],o=this.morphTargetsRelative;for(let h=0,c=a.count;h<c;h++)Mt.fromBufferAttribute(a,h),o&&(bi.fromBufferAttribute(t,h),Mt.add(bi)),s=Math.max(s,i.distanceToSquared(Mt))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeTangents(){const t=this.index,e=this.attributes;if(t===null||e.position===void 0||e.normal===void 0||e.uv===void 0){console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");return}const i=e.position,s=e.normal,n=e.uv;this.hasAttribute("tangent")===!1&&this.setAttribute("tangent",new dt(new Float32Array(4*i.count),4));const r=this.getAttribute("tangent"),a=[],o=[];for(let S=0;S<i.count;S++)a[S]=new w,o[S]=new w;const h=new w,c=new w,u=new w,d=new B,f=new B,p=new B,m=new w,g=new w;function x(S,C,z){h.fromBufferAttribute(i,S),c.fromBufferAttribute(i,C),u.fromBufferAttribute(i,z),d.fromBufferAttribute(n,S),f.fromBufferAttribute(n,C),p.fromBufferAttribute(n,z),c.sub(h),u.sub(h),f.sub(d),p.sub(d);const k=1/(f.x*p.y-p.x*f.y);isFinite(k)&&(m.copy(c).multiplyScalar(p.y).addScaledVector(u,-f.y).multiplyScalar(k),g.copy(u).multiplyScalar(f.x).addScaledVector(c,-p.x).multiplyScalar(k),a[S].add(m),a[C].add(m),a[z].add(m),o[S].add(g),o[C].add(g),o[z].add(g))}let y=this.groups;y.length===0&&(y=[{start:0,count:t.count}]);for(let S=0,C=y.length;S<C;++S){const z=y[S],k=z.start,U=z.count;for(let W=k,R=k+U;W<R;W+=3)x(t.getX(W+0),t.getX(W+1),t.getX(W+2))}const b=new w,v=new w,_=new w,M=new w;function A(S){_.fromBufferAttribute(s,S),M.copy(_);const C=a[S];b.copy(C),b.sub(_.multiplyScalar(_.dot(C))).normalize(),v.crossVectors(M,C);const k=v.dot(o[S])<0?-1:1;r.setXYZW(S,b.x,b.y,b.z,k)}for(let S=0,C=y.length;S<C;++S){const z=y[S],k=z.start,U=z.count;for(let W=k,R=k+U;W<R;W+=3)A(t.getX(W+0)),A(t.getX(W+1)),A(t.getX(W+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(e!==void 0){let i=this.getAttribute("normal");if(i===void 0)i=new dt(new Float32Array(e.count*3),3),this.setAttribute("normal",i);else for(let d=0,f=i.count;d<f;d++)i.setXYZ(d,0,0,0);const s=new w,n=new w,r=new w,a=new w,o=new w,h=new w,c=new w,u=new w;if(t)for(let d=0,f=t.count;d<f;d+=3){const p=t.getX(d+0),m=t.getX(d+1),g=t.getX(d+2);s.fromBufferAttribute(e,p),n.fromBufferAttribute(e,m),r.fromBufferAttribute(e,g),c.subVectors(r,n),u.subVectors(s,n),c.cross(u),a.fromBufferAttribute(i,p),o.fromBufferAttribute(i,m),h.fromBufferAttribute(i,g),a.add(c),o.add(c),h.add(c),i.setXYZ(p,a.x,a.y,a.z),i.setXYZ(m,o.x,o.y,o.z),i.setXYZ(g,h.x,h.y,h.z)}else for(let d=0,f=e.count;d<f;d+=3)s.fromBufferAttribute(e,d+0),n.fromBufferAttribute(e,d+1),r.fromBufferAttribute(e,d+2),c.subVectors(r,n),u.subVectors(s,n),c.cross(u),i.setXYZ(d+0,c.x,c.y,c.z),i.setXYZ(d+1,c.x,c.y,c.z),i.setXYZ(d+2,c.x,c.y,c.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)Mt.fromBufferAttribute(t,e),Mt.normalize(),t.setXYZ(e,Mt.x,Mt.y,Mt.z)}toNonIndexed(){function t(a,o){const h=a.array,c=a.itemSize,u=a.normalized,d=new h.constructor(o.length*c);let f=0,p=0;for(let m=0,g=o.length;m<g;m++){a.isInterleavedBufferAttribute?f=o[m]*a.data.stride+a.offset:f=o[m]*c;for(let x=0;x<c;x++)d[p++]=h[f++]}return new dt(d,c,u)}if(this.index===null)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Z,i=this.index.array,s=this.attributes;for(const a in s){const o=s[a],h=t(o,i);e.setAttribute(a,h)}const n=this.morphAttributes;for(const a in n){const o=[],h=n[a];for(let c=0,u=h.length;c<u;c++){const d=h[c],f=t(d,i);o.push(f)}e.morphAttributes[a]=o}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let a=0,o=r.length;a<o;a++){const h=r[a];e.addGroup(h.start,h.count,h.materialIndex)}return e}toJSON(){const t={metadata:{version:4.6,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,this.name!==""&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),this.parameters!==void 0){const o=this.parameters;for(const h in o)o[h]!==void 0&&(t[h]=o[h]);return t}t.data={attributes:{}};const e=this.index;e!==null&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const o in i){const h=i[o];t.data.attributes[o]=h.toJSON(t.data)}const s={};let n=!1;for(const o in this.morphAttributes){const h=this.morphAttributes[o],c=[];for(let u=0,d=h.length;u<d;u++){const f=h[u];c.push(f.toJSON(t.data))}c.length>0&&(s[o]=c,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return a!==null&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return new this.constructor().copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;i!==null&&this.setIndex(i.clone(e));const s=t.attributes;for(const h in s){const c=s[h];this.setAttribute(h,c.clone(e))}const n=t.morphAttributes;for(const h in n){const c=[],u=n[h];for(let d=0,f=u.length;d<f;d++)c.push(u[d].clone(e));this.morphAttributes[h]=c}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let h=0,c=r.length;h<c;h++){const u=r[h];this.addGroup(u.start,u.count,u.materialIndex)}const a=t.boundingBox;a!==null&&(this.boundingBox=a.clone());const o=t.boundingSphere;return o!==null&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const so=new Y,Xe=new As,Ds=new Et,no=new w,Us=new w,Vs=new w,Gs=new w,dr=new w,Ws=new w,ro=new w,Hs=new w;class Vt extends tt{constructor(t=new Z,e=new Di){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),t.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),t.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const s=e[i[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let n=0,r=s.length;n<r;n++){const a=s[n].name||String(n);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=n}}}}getVertexPosition(t,e){const i=this.geometry,s=i.attributes.position,n=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(s,t);const a=this.morphTargetInfluences;if(n&&a){Ws.set(0,0,0);for(let o=0,h=n.length;o<h;o++){const c=a[o],u=n[o];c!==0&&(dr.fromBufferAttribute(u,t),r?Ws.addScaledVector(dr,c):Ws.addScaledVector(dr.sub(e),c))}e.add(Ws)}return e}raycast(t,e){const i=this.geometry,s=this.material,n=this.matrixWorld;s!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),Ds.copy(i.boundingSphere),Ds.applyMatrix4(n),Xe.copy(t.ray).recast(t.near),!(Ds.containsPoint(Xe.origin)===!1&&(Xe.intersectSphere(Ds,no)===null||Xe.origin.distanceToSquared(no)>(t.far-t.near)**2))&&(so.copy(n).invert(),Xe.copy(t.ray).applyMatrix4(so),!(i.boundingBox!==null&&Xe.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(t,e,Xe)))}_computeIntersections(t,e,i){let s;const n=this.geometry,r=this.material,a=n.index,o=n.attributes.position,h=n.attributes.uv,c=n.attributes.uv1,u=n.attributes.normal,d=n.groups,f=n.drawRange;if(a!==null)if(Array.isArray(r))for(let p=0,m=d.length;p<m;p++){const g=d[p],x=r[g.materialIndex],y=Math.max(g.start,f.start),b=Math.min(a.count,Math.min(g.start+g.count,f.start+f.count));for(let v=y,_=b;v<_;v+=3){const M=a.getX(v),A=a.getX(v+1),S=a.getX(v+2);s=qs(this,x,t,i,h,c,u,M,A,S),s&&(s.faceIndex=Math.floor(v/3),s.face.materialIndex=g.materialIndex,e.push(s))}}else{const p=Math.max(0,f.start),m=Math.min(a.count,f.start+f.count);for(let g=p,x=m;g<x;g+=3){const y=a.getX(g),b=a.getX(g+1),v=a.getX(g+2);s=qs(this,r,t,i,h,c,u,y,b,v),s&&(s.faceIndex=Math.floor(g/3),e.push(s))}}else if(o!==void 0)if(Array.isArray(r))for(let p=0,m=d.length;p<m;p++){const g=d[p],x=r[g.materialIndex],y=Math.max(g.start,f.start),b=Math.min(o.count,Math.min(g.start+g.count,f.start+f.count));for(let v=y,_=b;v<_;v+=3){const M=v,A=v+1,S=v+2;s=qs(this,x,t,i,h,c,u,M,A,S),s&&(s.faceIndex=Math.floor(v/3),s.face.materialIndex=g.materialIndex,e.push(s))}}else{const p=Math.max(0,f.start),m=Math.min(o.count,f.start+f.count);for(let g=p,x=m;g<x;g+=3){const y=g,b=g+1,v=g+2;s=qs(this,r,t,i,h,c,u,y,b,v),s&&(s.faceIndex=Math.floor(g/3),e.push(s))}}}}function hu(l,t,e,i,s,n,r,a){let o;if(t.side===Mh?o=i.intersectTriangle(r,n,s,!0,a):o=i.intersectTriangle(s,n,r,t.side===Er,a),o===null)return null;Hs.copy(a),Hs.applyMatrix4(l.matrixWorld);const h=e.ray.origin.distanceTo(Hs);return h<e.near||h>e.far?null:{distance:h,point:Hs.clone(),object:l}}function qs(l,t,e,i,s,n,r,a,o,h){l.getVertexPosition(a,Us),l.getVertexPosition(o,Vs),l.getVertexPosition(h,Gs);const c=hu(l,t,e,i,Us,Vs,Gs,ro);if(c){const u=new w;Yt.getBarycoord(ro,Us,Vs,Gs,u),s&&(c.uv=Yt.getInterpolatedAttribute(s,a,o,h,u,new B)),n&&(c.uv1=Yt.getInterpolatedAttribute(n,a,o,h,u,new B)),r&&(c.normal=Yt.getInterpolatedAttribute(r,a,o,h,u,new w),c.normal.dot(i.direction)>0&&c.normal.multiplyScalar(-1));const d={a,b:o,c:h,normal:new w,materialIndex:0};Yt.getNormal(Us,Vs,Gs,d.normal),c.face=d,c.barycoord=u}return c}class On extends Z{constructor(t=1,e=1,i=1,s=1,n=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:s,heightSegments:n,depthSegments:r};const a=this;s=Math.floor(s),n=Math.floor(n),r=Math.floor(r);const o=[],h=[],c=[],u=[];let d=0,f=0;p("z","y","x",-1,-1,i,e,t,r,n,0),p("z","y","x",1,-1,i,e,-t,r,n,1),p("x","z","y",1,1,t,i,e,s,r,2),p("x","z","y",1,-1,t,i,-e,s,r,3),p("x","y","z",1,-1,t,e,i,s,n,4),p("x","y","z",-1,-1,t,e,-i,s,n,5),this.setIndex(o),this.setAttribute("position",new O(h,3)),this.setAttribute("normal",new O(c,3)),this.setAttribute("uv",new O(u,2));function p(m,g,x,y,b,v,_,M,A,S,C){const z=v/A,k=_/S,U=v/2,W=_/2,R=M/2,I=A+1,N=S+1;let wt=0,Bt=0;const nt=new w;for(let ht=0;ht<N;ht++){const et=ht*k-W;for(let Lt=0;Lt<I;Lt++){const ye=Lt*z-U;nt[m]=ye*y,nt[g]=et*b,nt[x]=R,h.push(nt.x,nt.y,nt.z),nt[m]=0,nt[g]=0,nt[x]=M>0?1:-1,c.push(nt.x,nt.y,nt.z),u.push(Lt/A),u.push(1-ht/S),wt+=1}}for(let ht=0;ht<S;ht++)for(let et=0;et<A;et++){const Lt=d+et+I*ht,ye=d+et+I*(ht+1),Gi=d+(et+1)+I*(ht+1),hi=d+(et+1)+I*ht;o.push(Lt,ye,hi),o.push(ye,Gi,hi),Bt+=6}a.addGroup(f,Bt,C),f+=Bt,d+=wt}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new On(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function Nn(l){const t={};for(const e in l){t[e]={};for(const i in l[e]){const s=l[e][i];s&&(s.isColor||s.isMatrix3||s.isMatrix4||s.isVector2||s.isVector3||s.isVector4||s.isTexture||s.isQuaternion)?s.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),t[e][i]=null):t[e][i]=s.clone():Array.isArray(s)?t[e][i]=s.slice():t[e][i]=s}}return t}function lu(l){const t={};for(let e=0;e<l.length;e++){const i=Nn(l[e]);for(const s in i)t[s]=i[s]}return t}function cu(l){const t=[];for(let e=0;e<l.length;e++)t.push(l[e].clone());return t}function Eg(l){const t=l.getRenderTarget();return t===null?l.outputColorSpace:t.isXRRenderTarget===!0?t.texture.colorSpace:qt.workingColorSpace}const Rg={clone:Nn,merge:lu};var uu=`void main() {
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}`,du=`void main() {
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
}`;class ia extends Rt{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=uu,this.fragmentShader=du,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,t!==void 0&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=Nn(t.uniforms),this.uniformsGroups=cu(t.uniformsGroups),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.fog=t.fog,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const s in this.uniforms){const r=this.uniforms[s].value;r&&r.isTexture?e.uniforms[s]={type:"t",value:r.toJSON(t).uuid}:r&&r.isColor?e.uniforms[s]={type:"c",value:r.getHex()}:r&&r.isVector2?e.uniforms[s]={type:"v2",value:r.toArray()}:r&&r.isVector3?e.uniforms[s]={type:"v3",value:r.toArray()}:r&&r.isVector4?e.uniforms[s]={type:"v4",value:r.toArray()}:r&&r.isMatrix3?e.uniforms[s]={type:"m3",value:r.toArray()}:r&&r.isMatrix4?e.uniforms[s]={type:"m4",value:r.toArray()}:e.uniforms[s]={value:r}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const i={};for(const s in this.extensions)this.extensions[s]===!0&&(i[s]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}}class sa extends tt{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Y,this.projectionMatrix=new Y,this.projectionMatrixInverse=new Y,this.coordinateSystem=Te}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const De=new w,ao=new B,oo=new B;class te extends sa{constructor(t=50,e=1,i=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=t.view===null?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=xs*2*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(ii*.5*this.fov);return .5*this.getFilmHeight()/t}getEffectiveFOV(){return xs*2*Math.atan(Math.tan(ii*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,i){De.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(De.x,De.y).multiplyScalar(-t/De.z),De.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(De.x,De.y).multiplyScalar(-t/De.z)}getViewSize(t,e){return this.getViewBounds(t,ao,oo),e.subVectors(oo,ao)}setViewOffset(t,e,i,s,n,r){this.aspect=t/e,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(ii*.5*this.fov)/this.zoom,i=2*e,s=this.aspect*i,n=-.5*s;const r=this.view;if(this.view!==null&&this.view.enabled){const o=r.fullWidth,h=r.fullHeight;n+=r.offsetX*s/o,e-=r.offsetY*i/h,s*=r.width/o,i*=r.height/h}const a=this.filmOffset;a!==0&&(n+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(n,n+s,e,e-i,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,this.view!==null&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const vi=-90,wi=1;class fu extends tt{constructor(t,e,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new te(vi,wi,t,e);s.layers=this.layers,this.add(s);const n=new te(vi,wi,t,e);n.layers=this.layers,this.add(n);const r=new te(vi,wi,t,e);r.layers=this.layers,this.add(r);const a=new te(vi,wi,t,e);a.layers=this.layers,this.add(a);const o=new te(vi,wi,t,e);o.layers=this.layers,this.add(o);const h=new te(vi,wi,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[i,s,n,r,a,o]=e;for(const h of e)this.remove(h);if(t===Te)i.up.set(0,1,0),i.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),n.up.set(0,0,-1),n.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else if(t===Tn)i.up.set(0,-1,0),i.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),n.up.set(0,0,1),n.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);for(const h of e)this.add(h),h.updateMatrixWorld()}update(t,e){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[n,r,a,o,h,c]=this.children,u=t.getRenderTarget(),d=t.getActiveCubeFace(),f=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,t.setRenderTarget(i,0,s),t.render(e,n),t.setRenderTarget(i,1,s),t.render(e,r),t.setRenderTarget(i,2,s),t.render(e,a),t.setRenderTarget(i,3,s),t.render(e,o),t.setRenderTarget(i,4,s),t.render(e,h),i.texture.generateMipmaps=m,t.setRenderTarget(i,5,s),t.render(e,c),t.setRenderTarget(u,d,f),t.xr.enabled=p,i.texture.needsPMREMUpdate=!0}}class na extends gt{constructor(t,e,i,s,n,r,a,o,h,c){t=t!==void 0?t:[],e=e!==void 0?e:Kr,super(t,e,i,s,n,r,a,o,h,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class Lg extends ea{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const i={width:t,height:t,depth:1},s=[i,i,i,i,i,i];this.texture=new na(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=e.generateMipmaps!==void 0?e.generateMipmaps:!1,this.texture.minFilter=e.minFilter!==void 0?e.minFilter:ee}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:`
varying vec3 vWorldDirection;
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
}
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include <begin_vertex>
#include <project_vertex>
}
`,fragmentShader:`
uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include <common>
void main() {
vec3 direction = normalize( vWorldDirection );
vec2 sampleUV = equirectUv( direction );
gl_FragColor = texture2D( tEquirect, sampleUV );
}
`},s=new On(5,5,5),n=new ia({name:"CubemapFromEquirect",uniforms:Nn(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:Mh,blending:vl});n.uniforms.tEquirect.value=e;const r=new Vt(s,n),a=e.minFilter;return e.minFilter===Ln&&(e.minFilter=ee),new fu(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e,i,s){const n=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,i,s);t.setRenderTarget(n)}}class ra{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new V(t),this.density=e}clone(){return new ra(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class aa{constructor(t,e=1,i=1e3){this.isFog=!0,this.name="",this.color=new V(t),this.near=e,this.far=i}clone(){return new aa(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class pu extends tt{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new fe,this.environmentIntensity=1,this.environmentRotation=new fe,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),t.background!==null&&(this.background=t.background.clone()),t.environment!==null&&(this.environment=t.environment.clone()),t.fog!==null&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),t.overrideMaterial!==null&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return this.fog!==null&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class oa{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=t!==void 0?t.length/e:0,this.usage=An,this.updateRanges=[],this.version=0,this.uuid=Jt()}onUploadCallback(){}set needsUpdate(t){t===!0&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let s=0,n=this.stride;s<n;s++)this.array[t+s]=e.array[i+s];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Jt()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return t.arrayBuffers===void 0&&(t.arrayBuffers={}),this.array.buffer._uuid===void 0&&(this.array.buffer._uuid=Jt()),t.arrayBuffers[this.array.buffer._uuid]===void 0&&(t.arrayBuffers[this.array.buffer._uuid]=Array.from(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}const Ft=new w;class Oi{constructor(t,e,i,s=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=s}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)Ft.fromBufferAttribute(this,e),Ft.applyMatrix4(t),this.setXYZ(e,Ft.x,Ft.y,Ft.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)Ft.fromBufferAttribute(this,e),Ft.applyNormalMatrix(t),this.setXYZ(e,Ft.x,Ft.y,Ft.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)Ft.fromBufferAttribute(this,e),Ft.transformDirection(t),this.setXYZ(e,Ft.x,Ft.y,Ft.z);return this}getComponent(t,e){let i=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(i=kt(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=X(i,this.array)),this.data.array[t*this.data.stride+this.offset+e]=i,this}setX(t,e){return this.normalized&&(e=X(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=X(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=X(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=X(e,this.array)),this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){let e=this.data.array[t*this.data.stride+this.offset];return this.normalized&&(e=kt(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=kt(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=kt(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=kt(e,this.array)),e}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=X(e,this.array),i=X(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=X(e,this.array),i=X(i,this.array),s=X(s,this.array),n=X(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=s,this.data.array[t+3]=n,this}clone(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const s=i*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)e.push(this.data.array[s+n])}return new dt(new this.array.constructor(e),this.itemSize,this.normalized)}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Oi(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(t===void 0){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const e=[];for(let i=0;i<this.count;i++){const s=i*this.data.stride+this.offset;for(let n=0;n<this.itemSize;n++)e.push(this.data.array[s+n])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:e,normalized:this.normalized}}else return t.interleavedBuffers===void 0&&(t.interleavedBuffers={}),t.interleavedBuffers[this.data.uuid]===void 0&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}class fs extends Rt{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new V(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}let _i;const Ji=new w,Mi=new w,Si=new w,Ai=new B,Zi=new B,kh=new Y,Xs=new w,Ki=new w,Ys=new w,ho=new B,fr=new B,lo=new B;class cs extends tt{constructor(t=new fs){if(super(),this.isSprite=!0,this.type="Sprite",_i===void 0){_i=new Z;const e=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),i=new oa(e,5);_i.setIndex([0,1,2,0,2,3]),_i.setAttribute("position",new Oi(i,3,0,!1)),_i.setAttribute("uv",new Oi(i,2,3,!1))}this.geometry=_i,this.material=t,this.center=new B(.5,.5)}raycast(t,e){t.camera===null&&console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),Mi.setFromMatrixScale(this.matrixWorld),kh.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),Si.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&this.material.sizeAttenuation===!1&&Mi.multiplyScalar(-Si.z);const i=this.material.rotation;let s,n;i!==0&&(n=Math.cos(i),s=Math.sin(i));const r=this.center;Js(Xs.set(-.5,-.5,0),Si,r,Mi,s,n),Js(Ki.set(.5,-.5,0),Si,r,Mi,s,n),Js(Ys.set(.5,.5,0),Si,r,Mi,s,n),ho.set(0,0),fr.set(1,0),lo.set(1,1);let a=t.ray.intersectTriangle(Xs,Ki,Ys,!1,Ji);if(a===null&&(Js(Ki.set(-.5,.5,0),Si,r,Mi,s,n),fr.set(0,1),a=t.ray.intersectTriangle(Xs,Ys,Ki,!1,Ji),a===null))return;const o=t.ray.origin.distanceTo(Ji);o<t.near||o>t.far||e.push({distance:o,point:Ji.clone(),uv:Yt.getInterpolation(Ji,Xs,Ki,Ys,ho,fr,lo,new B),face:null,object:this})}copy(t,e){return super.copy(t,e),t.center!==void 0&&this.center.copy(t.center),this.material=t.material,this}}function Js(l,t,e,i,s,n){Ai.subVectors(l,e).addScalar(.5).multiply(i),s!==void 0?(Zi.x=n*Ai.x-s*Ai.y,Zi.y=s*Ai.x+n*Ai.y):Zi.copy(Ai),l.copy(t),l.x+=Zi.x,l.y+=Zi.y,l.applyMatrix4(kh)}const Zs=new w,co=new w;class mu extends tt{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(t){super.copy(t,!1);const e=t.levels;for(let i=0,s=e.length;i<s;i++){const n=e[i];this.addLevel(n.object.clone(),n.distance,n.hysteresis)}return this.autoUpdate=t.autoUpdate,this}addLevel(t,e=0,i=0){e=Math.abs(e);const s=this.levels;let n;for(n=0;n<s.length&&!(e<s[n].distance);n++);return s.splice(n,0,{distance:e,hysteresis:i,object:t}),this.add(t),this}removeLevel(t){const e=this.levels;for(let i=0;i<e.length;i++)if(e[i].distance===t){const s=e.splice(i,1);return this.remove(s[0].object),!0}return!1}getCurrentLevel(){return this._currentLevel}getObjectForDistance(t){const e=this.levels;if(e.length>0){let i,s;for(i=1,s=e.length;i<s;i++){let n=e[i].distance;if(e[i].object.visible&&(n-=n*e[i].hysteresis),t<n)break}return e[i-1].object}return null}raycast(t,e){if(this.levels.length>0){Zs.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(Zs);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Zs.setFromMatrixPosition(t.matrixWorld),co.setFromMatrixPosition(this.matrixWorld);const i=Zs.distanceTo(co)/t.zoom;e[0].object.visible=!0;let s,n;for(s=1,n=e.length;s<n;s++){let r=e[s].distance;if(e[s].object.visible&&(r-=r*e[s].hysteresis),i>=r)e[s-1].object.visible=!1,e[s].object.visible=!0;else break}for(this._currentLevel=s-1;s<n;s++)e[s].object.visible=!1}}toJSON(t){const e=super.toJSON(t);this.autoUpdate===!1&&(e.object.autoUpdate=!1),e.object.levels=[];const i=this.levels;for(let s=0,n=i.length;s<n;s++){const r=i[s];e.object.levels.push({object:r.object.uuid,distance:r.distance,hysteresis:r.hysteresis})}return e}}const uo=new w,fo=new St,po=new St,gu=new w,mo=new Y,Ks=new w,pr=new Et,go=new Y,mr=new As;class yu extends Vt{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=Da,this.bindMatrix=new Y,this.bindMatrixInverse=new Y,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;this.boundingBox===null&&(this.boundingBox=new Ut),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Ks),this.boundingBox.expandByPoint(Ks)}computeBoundingSphere(){const t=this.geometry;this.boundingSphere===null&&(this.boundingSphere=new Et),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let i=0;i<e.count;i++)this.getVertexPosition(i,Ks),this.boundingSphere.expandByPoint(Ks)}copy(t,e){return super.copy(t,e),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const i=this.material,s=this.matrixWorld;i!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),pr.copy(this.boundingSphere),pr.applyMatrix4(s),t.ray.intersectsSphere(pr)!==!1&&(go.copy(s).invert(),mr.copy(t.ray).applyMatrix4(go),!(this.boundingBox!==null&&mr.intersectsBox(this.boundingBox)===!1)&&this._computeIntersections(t,e,mr)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,e===void 0&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new St,e=this.geometry.attributes.skinWeight;for(let i=0,s=e.count;i<s;i++){t.fromBufferAttribute(e,i);const n=1/t.manhattanLength();n!==1/0?t.multiplyScalar(n):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===Da?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===_l?this.bindMatrixInverse.copy(this.bindMatrix).invert():console.warn("THREE.SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const i=this.skeleton,s=this.geometry;fo.fromBufferAttribute(s.attributes.skinIndex,t),po.fromBufferAttribute(s.attributes.skinWeight,t),uo.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let n=0;n<4;n++){const r=po.getComponent(n);if(r!==0){const a=fo.getComponent(n);mo.multiplyMatrices(i.bones[a].matrixWorld,i.boneInverses[a]),e.addScaledVector(gu.copy(uo).applyMatrix4(mo),r)}}return e.applyMatrix4(this.bindMatrixInverse)}}class Eh extends tt{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Ce extends gt{constructor(t=null,e=1,i=1,s,n,r,a,o,h=he,c=he,u,d){super(null,r,a,o,h,c,s,n,u,d),this.isDataTexture=!0,this.image={data:t,width:e,height:i},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const yo=new Y,xu=new Y;class ha{constructor(t=[],e=[]){this.uuid=Jt(),this.bones=t.slice(0),this.boneInverses=e,this.boneMatrices=null,this.boneTexture=null,this.init()}init(){const t=this.bones,e=this.boneInverses;if(this.boneMatrices=new Float32Array(t.length*16),e.length===0)this.calculateInverses();else if(t.length!==e.length){console.warn("THREE.Skeleton: Number of inverse bone matrices does not match amount of bones."),this.boneInverses=[];for(let i=0,s=this.bones.length;i<s;i++)this.boneInverses.push(new Y)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const i=new Y;this.bones[t]&&i.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(i)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&i.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const i=this.bones[t];i&&(i.parent&&i.parent.isBone?(i.matrix.copy(i.parent.matrixWorld).invert(),i.matrix.multiply(i.matrixWorld)):i.matrix.copy(i.matrixWorld),i.matrix.decompose(i.position,i.quaternion,i.scale))}}update(){const t=this.bones,e=this.boneInverses,i=this.boneMatrices,s=this.boneTexture;for(let n=0,r=t.length;n<r;n++){const a=t[n]?t[n].matrixWorld:xu;yo.multiplyMatrices(a,e[n]),yo.toArray(i,n*16)}s!==null&&(s.needsUpdate=!0)}clone(){return new ha(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(this.bones.length*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const i=new Ce(e,t,t,ys,Li);return i.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=i,this}getBoneByName(t){for(let e=0,i=this.bones.length;e<i;e++){const s=this.bones[e];if(s.name===t)return s}}dispose(){this.boneTexture!==null&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let i=0,s=t.bones.length;i<s;i++){const n=t.bones[i];let r=e[n];r===void 0&&(console.warn("THREE.Skeleton: No bone found with UUID:",n),r=new Eh),this.bones.push(r),this.boneInverses.push(new Y().fromArray(t.boneInverses[i]))}return this.init(),this}toJSON(){const t={metadata:{version:4.6,type:"Skeleton",generator:"Skeleton.toJSON"},bones:[],boneInverses:[]};t.uuid=this.uuid;const e=this.bones,i=this.boneInverses;for(let s=0,n=e.length;s<n;s++){const r=e[s];t.bones.push(r.uuid);const a=i[s];t.boneInverses.push(a.toArray())}return t}}class bs extends dt{constructor(t,e,i,s=1){super(t,e,i),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=s}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}const Ti=new Y,xo=new Y,js=[],bo=new Ut,bu=new Y,ji=new Vt,Qi=new Et;class vu extends Vt{constructor(t,e,i){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new bs(new Float32Array(i*16),16),this.instanceColor=null,this.morphTexture=null,this.count=i,this.boundingBox=null,this.boundingSphere=null;for(let s=0;s<i;s++)this.setMatrixAt(s,bu)}computeBoundingBox(){const t=this.geometry,e=this.count;this.boundingBox===null&&(this.boundingBox=new Ut),t.boundingBox===null&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,Ti),bo.copy(t.boundingBox).applyMatrix4(Ti),this.boundingBox.union(bo)}computeBoundingSphere(){const t=this.geometry,e=this.count;this.boundingSphere===null&&(this.boundingSphere=new Et),t.boundingSphere===null&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let i=0;i<e;i++)this.getMatrixAt(i,Ti),Qi.copy(t.boundingSphere).applyMatrix4(Ti),this.boundingSphere.union(Qi)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),t.morphTexture!==null&&(this.morphTexture=t.morphTexture.clone()),t.instanceColor!==null&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,t.boundingBox!==null&&(this.boundingBox=t.boundingBox.clone()),t.boundingSphere!==null&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){e.fromArray(this.instanceColor.array,t*3)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,t*16)}getMorphAt(t,e){const i=e.morphTargetInfluences,s=this.morphTexture.source.data.data,n=i.length+1,r=t*n+1;for(let a=0;a<i.length;a++)i[a]=s[r+a]}raycast(t,e){const i=this.matrixWorld,s=this.count;if(ji.geometry=this.geometry,ji.material=this.material,ji.material!==void 0&&(this.boundingSphere===null&&this.computeBoundingSphere(),Qi.copy(this.boundingSphere),Qi.applyMatrix4(i),t.ray.intersectsSphere(Qi)!==!1))for(let n=0;n<s;n++){this.getMatrixAt(n,Ti),xo.multiplyMatrices(i,Ti),ji.matrixWorld=xo,ji.raycast(t,js);for(let r=0,a=js.length;r<a;r++){const o=js[r];o.instanceId=n,o.object=this,e.push(o)}js.length=0}}setColorAt(t,e){this.instanceColor===null&&(this.instanceColor=new bs(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),e.toArray(this.instanceColor.array,t*3)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,t*16)}setMorphAt(t,e){const i=e.morphTargetInfluences,s=i.length+1;this.morphTexture===null&&(this.morphTexture=new Ce(new Float32Array(s*this.count),s,this.count,Ah,Li));const n=this.morphTexture.source.data.data;let r=0;for(let h=0;h<i.length;h++)r+=i[h];const a=this.geometry.morphTargetsRelative?1:1-r,o=s*t;n[o]=a,n.set(i,o+1)}updateMorphTargets(){}dispose(){return this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null),this}}const gr=new w,wu=new w,_u=new pe;class Ii{constructor(t=new w(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=gr.subVectors(i,e).cross(wu.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const i=t.delta(gr),s=this.normal.dot(i);if(s===0)return this.distanceToPoint(t.start)===0?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/s;return n<0||n>1?null:e.copy(t.start).addScaledVector(i,n)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||_u.getNormalMatrix(t),s=this.coplanarPoint(gr).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return new this.constructor().copy(this)}}const Ye=new Et,Qs=new w;class Rh{constructor(t=new Ii,e=new Ii,i=new Ii,s=new Ii,n=new Ii,r=new Ii){this.planes=[t,e,i,s,n,r]}set(t,e,i,s,n,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(i),a[3].copy(s),a[4].copy(n),a[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=Te){const i=this.planes,s=t.elements,n=s[0],r=s[1],a=s[2],o=s[3],h=s[4],c=s[5],u=s[6],d=s[7],f=s[8],p=s[9],m=s[10],g=s[11],x=s[12],y=s[13],b=s[14],v=s[15];if(i[0].setComponents(o-n,d-h,g-f,v-x).normalize(),i[1].setComponents(o+n,d+h,g+f,v+x).normalize(),i[2].setComponents(o+r,d+c,g+p,v+y).normalize(),i[3].setComponents(o-r,d-c,g-p,v-y).normalize(),i[4].setComponents(o-a,d-u,g-m,v-b).normalize(),e===Te)i[5].setComponents(o+a,d+u,g+m,v+b).normalize();else if(e===Tn)i[5].setComponents(a,u,m,b).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);return this}intersectsObject(t){if(t.boundingSphere!==void 0)t.boundingSphere===null&&t.computeBoundingSphere(),Ye.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;e.boundingSphere===null&&e.computeBoundingSphere(),Ye.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(Ye)}intersectsSprite(t){return Ye.center.set(0,0,0),Ye.radius=.7071067811865476,Ye.applyMatrix4(t.matrixWorld),this.intersectsSphere(Ye)}intersectsSphere(t){const e=this.planes,i=t.center,s=-t.radius;for(let n=0;n<6;n++)if(e[n].distanceToPoint(i)<s)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const s=e[i];if(Qs.x=s.normal.x>0?t.max.x:t.min.x,Qs.y=s.normal.y>0?t.max.y:t.min.y,Qs.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint(Qs)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function yr(l,t){return l-t}function Mu(l,t){return l.z-t.z}function Su(l,t){return t.z-l.z}class Au{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,i,s){const n=this.pool,r=this.list;this.index>=n.length&&n.push({start:-1,count:-1,z:-1,index:-1});const a=n[this.index];r.push(a),this.index++,a.start=t,a.count=e,a.z=i,a.index=s}reset(){this.list.length=0,this.index=0}}const Nt=new Y,Tu=new V(1,1,1),xr=new Rh,$s=new Ut,Je=new Et,$i=new w,vo=new w,Iu=new w,br=new Au,Ct=new Vt,tn=[];function Cu(l,t,e=0){const i=t.itemSize;if(l.isInterleavedBufferAttribute||l.array.constructor!==t.array.constructor){const s=l.count;for(let n=0;n<s;n++)for(let r=0;r<i;r++)t.setComponent(n+e,r,l.getComponent(n,r))}else t.array.set(l.array,e*i);t.needsUpdate=!0}function Ze(l,t){if(l.constructor!==t.constructor){const e=Math.min(l.length,t.length);for(let i=0;i<e;i++)t[i]=l[i]}else{const e=Math.min(l.length,t.length);t.set(new l.constructor(l.buffer,0,e))}}class zu extends Vt{get maxInstanceCount(){return this._maxInstanceCount}get instanceCount(){return this._instanceInfo.length-this._availableInstanceIds.length}get unusedVertexCount(){return this._maxVertexCount-this._nextVertexStart}get unusedIndexCount(){return this._maxIndexCount-this._nextIndexStart}constructor(t,e,i=e*2,s){super(new Z,s),this.isBatchedMesh=!0,this.perObjectFrustumCulled=!0,this.sortObjects=!0,this.boundingBox=null,this.boundingSphere=null,this.customSort=null,this._instanceInfo=[],this._geometryInfo=[],this._availableInstanceIds=[],this._availableGeometryIds=[],this._nextIndexStart=0,this._nextVertexStart=0,this._geometryCount=0,this._visibilityChanged=!0,this._geometryInitialized=!1,this._maxInstanceCount=t,this._maxVertexCount=e,this._maxIndexCount=i,this._multiDrawCounts=new Int32Array(t),this._multiDrawStarts=new Int32Array(t),this._multiDrawCount=0,this._multiDrawInstances=null,this._matricesTexture=null,this._indirectTexture=null,this._colorsTexture=null,this._initMatricesTexture(),this._initIndirectTexture()}_initMatricesTexture(){let t=Math.sqrt(this._maxInstanceCount*4);t=Math.ceil(t/4)*4,t=Math.max(t,4);const e=new Float32Array(t*t*4),i=new Ce(e,t,t,ys,Li);this._matricesTexture=i}_initIndirectTexture(){let t=Math.sqrt(this._maxInstanceCount);t=Math.ceil(t);const e=new Uint32Array(t*t),i=new Ce(e,t,t,Th,jr);this._indirectTexture=i}_initColorsTexture(){let t=Math.sqrt(this._maxInstanceCount);t=Math.ceil(t);const e=new Float32Array(t*t*4).fill(1),i=new Ce(e,t,t,ys,Li);i.colorSpace=qt.workingColorSpace,this._colorsTexture=i}_initializeGeometry(t){const e=this.geometry,i=this._maxVertexCount,s=this._maxIndexCount;if(this._geometryInitialized===!1){for(const n in t.attributes){const r=t.getAttribute(n),{array:a,itemSize:o,normalized:h}=r,c=new a.constructor(i*o),u=new dt(c,o,h);e.setAttribute(n,u)}if(t.getIndex()!==null){const n=i>65535?new Uint32Array(s):new Uint16Array(s);e.setIndex(new dt(n,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(!!t.getIndex()!=!!e.getIndex())throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');for(const i in e.attributes){if(!t.hasAttribute(i))throw new Error(`THREE.BatchedMesh: Added geometry missing "${i}". All geometries must have consistent attributes.`);const s=t.getAttribute(i),n=e.getAttribute(i);if(s.itemSize!==n.itemSize||s.normalized!==n.normalized)throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}validateInstanceId(t){const e=this._instanceInfo;if(t<0||t>=e.length||e[t].active===!1)throw new Error(`THREE.BatchedMesh: Invalid instanceId ${t}. Instance is either out of range or has been deleted.`)}validateGeometryId(t){const e=this._geometryInfo;if(t<0||t>=e.length||e[t].active===!1)throw new Error(`THREE.BatchedMesh: Invalid geometryId ${t}. Geometry is either out of range or has been deleted.`)}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ut);const t=this.boundingBox,e=this._instanceInfo;t.makeEmpty();for(let i=0,s=e.length;i<s;i++){if(e[i].active===!1)continue;const n=e[i].geometryIndex;this.getMatrixAt(i,Nt),this.getBoundingBoxAt(n,$s).applyMatrix4(Nt),t.union($s)}}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Et);const t=this.boundingSphere,e=this._instanceInfo;t.makeEmpty();for(let i=0,s=e.length;i<s;i++){if(e[i].active===!1)continue;const n=e[i].geometryIndex;this.getMatrixAt(i,Nt),this.getBoundingSphereAt(n,Je).applyMatrix4(Nt),t.union(Je)}}addInstance(t){if(this._instanceInfo.length>=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw new Error("THREE.BatchedMesh: Maximum item count reached.");const i={visible:!0,active:!0,geometryIndex:t};let s=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(yr),s=this._availableInstanceIds.shift(),this._instanceInfo[s]=i):(s=this._instanceInfo.length,this._instanceInfo.push(i));const n=this._matricesTexture;Nt.identity().toArray(n.image.data,s*16),n.needsUpdate=!0;const r=this._colorsTexture;return r&&(Tu.toArray(r.image.data,s*4),r.needsUpdate=!0),this._visibilityChanged=!0,s}addGeometry(t,e=-1,i=-1){this._initializeGeometry(t),this._validateGeometry(t);const s={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},n=this._geometryInfo;s.vertexStart=this._nextVertexStart,s.reservedVertexCount=e===-1?t.getAttribute("position").count:e;const r=t.getIndex();if(r!==null&&(s.indexStart=this._nextIndexStart,s.reservedIndexCount=i===-1?r.count:i),s.indexStart!==-1&&s.indexStart+s.reservedIndexCount>this._maxIndexCount||s.vertexStart+s.reservedVertexCount>this._maxVertexCount)throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");let o;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(yr),o=this._availableGeometryIds.shift(),n[o]=s):(o=this._geometryCount,this._geometryCount++,n.push(s)),this.setGeometryAt(o,t),this._nextIndexStart=s.indexStart+s.reservedIndexCount,this._nextVertexStart=s.vertexStart+s.reservedVertexCount,o}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const i=this.geometry,s=i.getIndex()!==null,n=i.getIndex(),r=e.getIndex(),a=this._geometryInfo[t];if(s&&r.count>a.reservedIndexCount||e.attributes.position.count>a.reservedVertexCount)throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");const o=a.vertexStart,h=a.reservedVertexCount;a.vertexCount=e.getAttribute("position").count;for(const c in i.attributes){const u=e.getAttribute(c),d=i.getAttribute(c);Cu(u,d,o);const f=u.itemSize;for(let p=u.count,m=h;p<m;p++){const g=o+p;for(let x=0;x<f;x++)d.setComponent(g,x,0)}d.needsUpdate=!0,d.addUpdateRange(o*f,h*f)}if(s){const c=a.indexStart,u=a.reservedIndexCount;a.indexCount=e.getIndex().count;for(let d=0;d<r.count;d++)n.setX(c+d,o+r.getX(d));for(let d=r.count,f=u;d<f;d++)n.setX(c+d,o);n.needsUpdate=!0,n.addUpdateRange(c,a.reservedIndexCount)}return a.start=s?a.indexStart:a.vertexStart,a.count=s?a.indexCount:a.vertexCount,a.boundingBox=null,e.boundingBox!==null&&(a.boundingBox=e.boundingBox.clone()),a.boundingSphere=null,e.boundingSphere!==null&&(a.boundingSphere=e.boundingSphere.clone()),this._visibilityChanged=!0,t}deleteGeometry(t){const e=this._geometryInfo;if(t>=e.length||e[t].active===!1)return this;const i=this._instanceInfo;for(let s=0,n=i.length;s<n;s++)i[s].geometryIndex===t&&this.deleteInstance(s);return e[t].active=!1,this._availableGeometryIds.push(t),this._visibilityChanged=!0,this}deleteInstance(t){return this.validateInstanceId(t),this._instanceInfo[t].active=!1,this._availableInstanceIds.push(t),this._visibilityChanged=!0,this}optimize(){let t=0,e=0;const i=this._geometryInfo,s=i.map((r,a)=>a).sort((r,a)=>i[r].vertexStart-i[a].vertexStart),n=this.geometry;for(let r=0,a=i.length;r<a;r++){const o=s[r],h=i[o];if(h.active!==!1){if(n.index!==null){if(h.indexStart!==e){const{indexStart:c,vertexStart:u,reservedIndexCount:d}=h,f=n.index,p=f.array,m=t-u;for(let g=c;g<c+d;g++)p[g]=p[g]+m;f.array.copyWithin(e,c,c+d),f.addUpdateRange(e,d),h.indexStart=e}e+=h.reservedIndexCount}if(h.vertexStart!==t){const{vertexStart:c,reservedVertexCount:u}=h,d=n.attributes;for(const f in d){const p=d[f],{array:m,itemSize:g}=p;m.copyWithin(t*g,c*g,(c+u)*g),p.addUpdateRange(t*g,u*g)}h.vertexStart=t}t+=h.reservedVertexCount,h.start=n.index?h.indexStart:h.vertexStart,this._nextIndexStart=n.index?h.indexStart+h.reservedIndexCount:0,this._nextVertexStart=h.vertexStart+h.reservedVertexCount}}return this}getBoundingBoxAt(t,e){if(t>=this._geometryCount)return null;const i=this.geometry,s=this._geometryInfo[t];if(s.boundingBox===null){const n=new Ut,r=i.index,a=i.attributes.position;for(let o=s.start,h=s.start+s.count;o<h;o++){let c=o;r&&(c=r.getX(c)),n.expandByPoint($i.fromBufferAttribute(a,c))}s.boundingBox=n}return e.copy(s.boundingBox),e}getBoundingSphereAt(t,e){if(t>=this._geometryCount)return null;const i=this.geometry,s=this._geometryInfo[t];if(s.boundingSphere===null){const n=new Et;this.getBoundingBoxAt(t,$s),$s.getCenter(n.center);const r=i.index,a=i.attributes.position;let o=0;for(let h=s.start,c=s.start+s.count;h<c;h++){let u=h;r&&(u=r.getX(u)),$i.fromBufferAttribute(a,u),o=Math.max(o,n.center.distanceToSquared($i))}n.radius=Math.sqrt(o),s.boundingSphere=n}return e.copy(s.boundingSphere),e}setMatrixAt(t,e){this.validateInstanceId(t);const i=this._matricesTexture,s=this._matricesTexture.image.data;return e.toArray(s,t*16),i.needsUpdate=!0,this}getMatrixAt(t,e){return this.validateInstanceId(t),e.fromArray(this._matricesTexture.image.data,t*16)}setColorAt(t,e){return this.validateInstanceId(t),this._colorsTexture===null&&this._initColorsTexture(),e.toArray(this._colorsTexture.image.data,t*4),this._colorsTexture.needsUpdate=!0,this}getColorAt(t,e){return this.validateInstanceId(t),e.fromArray(this._colorsTexture.image.data,t*4)}setVisibleAt(t,e){return this.validateInstanceId(t),this._instanceInfo[t].visible===e?this:(this._instanceInfo[t].visible=e,this._visibilityChanged=!0,this)}getVisibleAt(t){return this.validateInstanceId(t),this._instanceInfo[t].visible}setGeometryIdAt(t,e){return this.validateInstanceId(t),this.validateGeometryId(e),this._instanceInfo[t].geometryIndex=e,this}getGeometryIdAt(t){return this.validateInstanceId(t),this._instanceInfo[t].geometryIndex}getGeometryRangeAt(t,e={}){this.validateGeometryId(t);const i=this._geometryInfo[t];return e.vertexStart=i.vertexStart,e.vertexCount=i.vertexCount,e.reservedVertexCount=i.reservedVertexCount,e.indexStart=i.indexStart,e.indexCount=i.indexCount,e.reservedIndexCount=i.reservedIndexCount,e.start=i.start,e.count=i.count,e}setInstanceCount(t){const e=this._availableInstanceIds,i=this._instanceInfo;for(e.sort(yr);e[e.length-1]===i.length;)i.pop(),e.pop();if(t<i.length)throw new Error(`BatchedMesh: Instance ids outside the range ${t} are being used. Cannot shrink instance count.`);const s=new Int32Array(t),n=new Int32Array(t);Ze(this._multiDrawCounts,s),Ze(this._multiDrawStarts,n),this._multiDrawCounts=s,this._multiDrawStarts=n,this._maxInstanceCount=t;const r=this._indirectTexture,a=this._matricesTexture,o=this._colorsTexture;r.dispose(),this._initIndirectTexture(),Ze(r.image.data,this._indirectTexture.image.data),a.dispose(),this._initMatricesTexture(),Ze(a.image.data,this._matricesTexture.image.data),o&&(o.dispose(),this._initColorsTexture(),Ze(o.image.data,this._colorsTexture.image.data))}setGeometrySize(t,e){const i=[...this._geometryInfo].filter(a=>a.active);if(Math.max(...i.map(a=>a.vertexStart+a.reservedVertexCount))>t)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${e}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...i.map(o=>o.indexStart+o.reservedIndexCount))>e)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${e}. Cannot shrink further.`);const n=this.geometry;n.dispose(),this._maxVertexCount=t,this._maxIndexCount=e,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new Z,this._initializeGeometry(n));const r=this.geometry;n.index&&Ze(n.index.array,r.index.array);for(const a in n.attributes)Ze(n.attributes[a].array,r.attributes[a].array)}raycast(t,e){const i=this._instanceInfo,s=this._geometryInfo,n=this.matrixWorld,r=this.geometry;Ct.material=this.material,Ct.geometry.index=r.index,Ct.geometry.attributes=r.attributes,Ct.geometry.boundingBox===null&&(Ct.geometry.boundingBox=new Ut),Ct.geometry.boundingSphere===null&&(Ct.geometry.boundingSphere=new Et);for(let a=0,o=i.length;a<o;a++){if(!i[a].visible||!i[a].active)continue;const h=i[a].geometryIndex,c=s[h];Ct.geometry.setDrawRange(c.start,c.count),this.getMatrixAt(a,Ct.matrixWorld).premultiply(n),this.getBoundingBoxAt(h,Ct.geometry.boundingBox),this.getBoundingSphereAt(h,Ct.geometry.boundingSphere),Ct.raycast(t,tn);for(let u=0,d=tn.length;u<d;u++){const f=tn[u];f.object=this,f.batchId=a,e.push(f)}tn.length=0}Ct.material=null,Ct.geometry.index=null,Ct.geometry.attributes={},Ct.geometry.setDrawRange(0,1/0)}copy(t){return super.copy(t),this.geometry=t.geometry.clone(),this.perObjectFrustumCulled=t.perObjectFrustumCulled,this.sortObjects=t.sortObjects,this.boundingBox=t.boundingBox!==null?t.boundingBox.clone():null,this.boundingSphere=t.boundingSphere!==null?t.boundingSphere.clone():null,this._geometryInfo=t._geometryInfo.map(e=>({...e,boundingBox:e.boundingBox!==null?e.boundingBox.clone():null,boundingSphere:e.boundingSphere!==null?e.boundingSphere.clone():null})),this._instanceInfo=t._instanceInfo.map(e=>({...e})),this._maxInstanceCount=t._maxInstanceCount,this._maxVertexCount=t._maxVertexCount,this._maxIndexCount=t._maxIndexCount,this._geometryInitialized=t._geometryInitialized,this._geometryCount=t._geometryCount,this._multiDrawCounts=t._multiDrawCounts.slice(),this._multiDrawStarts=t._multiDrawStarts.slice(),this._matricesTexture=t._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=t._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,i,s,n){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const r=s.getIndex(),a=r===null?1:r.array.BYTES_PER_ELEMENT,o=this._instanceInfo,h=this._multiDrawStarts,c=this._multiDrawCounts,u=this._geometryInfo,d=this.perObjectFrustumCulled,f=this._indirectTexture,p=f.image.data;d&&(Nt.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse).multiply(this.matrixWorld),xr.setFromProjectionMatrix(Nt,t.coordinateSystem));let m=0;if(this.sortObjects){Nt.copy(this.matrixWorld).invert(),$i.setFromMatrixPosition(i.matrixWorld).applyMatrix4(Nt),vo.set(0,0,-1).transformDirection(i.matrixWorld).transformDirection(Nt);for(let y=0,b=o.length;y<b;y++)if(o[y].visible&&o[y].active){const v=o[y].geometryIndex;this.getMatrixAt(y,Nt),this.getBoundingSphereAt(v,Je).applyMatrix4(Nt);let _=!1;if(d&&(_=!xr.intersectsSphere(Je)),!_){const M=u[v],A=Iu.subVectors(Je.center,$i).dot(vo);br.push(M.start,M.count,A,y)}}const g=br.list,x=this.customSort;x===null?g.sort(n.transparent?Su:Mu):x.call(this,g,i);for(let y=0,b=g.length;y<b;y++){const v=g[y];h[m]=v.start*a,c[m]=v.count,p[m]=v.index,m++}br.reset()}else for(let g=0,x=o.length;g<x;g++)if(o[g].visible&&o[g].active){const y=o[g].geometryIndex;let b=!1;if(d&&(this.getMatrixAt(g,Nt),this.getBoundingSphereAt(y,Je).applyMatrix4(Nt),b=!xr.intersectsSphere(Je)),!b){const v=u[y];h[m]=v.start*a,c[m]=v.count,p[m]=g,m++}}f.needsUpdate=!0,this._multiDrawCount=m,this._visibilityChanged=!1}onBeforeShadow(t,e,i,s,n,r){this.onBeforeRender(t,null,s,n,r)}}class Gt extends Rt{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new V(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const Cn=new w,zn=new w,wo=new Y,ts=new As,en=new Et,vr=new w,_o=new w;class ni extends tt{constructor(t=new Z,e=new Gt){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[0];for(let s=1,n=e.count;s<n;s++)Cn.fromBufferAttribute(e,s-1),zn.fromBufferAttribute(e,s),i[s]=i[s-1],i[s]+=Cn.distanceTo(zn);t.setAttribute("lineDistance",new O(i,1))}else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const i=this.geometry,s=this.matrixWorld,n=t.params.Line.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),en.copy(i.boundingSphere),en.applyMatrix4(s),en.radius+=n,t.ray.intersectsSphere(en)===!1)return;wo.copy(s).invert(),ts.copy(t.ray).applyMatrix4(wo);const a=n/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,h=this.isLineSegments?2:1,c=i.index,d=i.attributes.position;if(c!==null){const f=Math.max(0,r.start),p=Math.min(c.count,r.start+r.count);for(let m=f,g=p-1;m<g;m+=h){const x=c.getX(m),y=c.getX(m+1),b=sn(this,t,ts,o,x,y);b&&e.push(b)}if(this.isLineLoop){const m=c.getX(p-1),g=c.getX(f),x=sn(this,t,ts,o,m,g);x&&e.push(x)}}else{const f=Math.max(0,r.start),p=Math.min(d.count,r.start+r.count);for(let m=f,g=p-1;m<g;m+=h){const x=sn(this,t,ts,o,m,m+1);x&&e.push(x)}if(this.isLineLoop){const m=sn(this,t,ts,o,p-1,f);m&&e.push(m)}}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const s=e[i[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let n=0,r=s.length;n<r;n++){const a=s[n].name||String(n);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=n}}}}}function sn(l,t,e,i,s,n){const r=l.geometry.attributes.position;if(Cn.fromBufferAttribute(r,s),zn.fromBufferAttribute(r,n),e.distanceSqToSegment(Cn,zn,vr,_o)>i)return;vr.applyMatrix4(l.matrixWorld);const o=t.ray.origin.distanceTo(vr);if(!(o<t.near||o>t.far))return{distance:o,point:_o.clone().applyMatrix4(l.matrixWorld),index:s,face:null,faceIndex:null,barycoord:null,object:l}}const Mo=new w,So=new w;class Fe extends ni{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.index===null){const e=t.attributes.position,i=[];for(let s=0,n=e.count;s<n;s+=2)Mo.fromBufferAttribute(e,s),So.fromBufferAttribute(e,s+1),i[s]=s===0?0:i[s-1],i[s+1]=i[s]+Mo.distanceTo(So);t.setAttribute("lineDistance",new O(i,1))}else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class Bu extends ni{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class Lh extends Rt{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new V(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this.fog=t.fog,this}}const Ao=new Y,Nr=new As,nn=new Et,rn=new w;class Fu extends tt{constructor(t=new Z,e=new Lh){super(),this.isPoints=!0,this.type="Points",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,s=this.matrixWorld,n=t.params.Points.threshold,r=i.drawRange;if(i.boundingSphere===null&&i.computeBoundingSphere(),nn.copy(i.boundingSphere),nn.applyMatrix4(s),nn.radius+=n,t.ray.intersectsSphere(nn)===!1)return;Ao.copy(s).invert(),Nr.copy(t.ray).applyMatrix4(Ao);const a=n/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,h=i.index,u=i.attributes.position;if(h!==null){const d=Math.max(0,r.start),f=Math.min(h.count,r.start+r.count);for(let p=d,m=f;p<m;p++){const g=h.getX(p);rn.fromBufferAttribute(u,g),To(rn,g,o,s,t,e,this)}}else{const d=Math.max(0,r.start),f=Math.min(u.count,r.start+r.count);for(let p=d,m=f;p<m;p++)rn.fromBufferAttribute(u,p),To(rn,p,o,s,t,e,this)}}updateMorphTargets(){const e=this.geometry.morphAttributes,i=Object.keys(e);if(i.length>0){const s=e[i[0]];if(s!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let n=0,r=s.length;n<r;n++){const a=s[n].name||String(n);this.morphTargetInfluences.push(0),this.morphTargetDictionary[a]=n}}}}}function To(l,t,e,i,s,n,r){const a=Nr.distanceSqToPoint(l);if(a<e){const o=new w;Nr.closestPointToPoint(l,o),o.applyMatrix4(i);const h=s.ray.origin.distanceTo(o);if(h<s.near||h>s.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:o,index:t,face:null,faceIndex:null,barycoord:null,object:r})}}class Oh extends tt{constructor(){super(),this.isGroup=!0,this.type="Group"}}class Og extends gt{constructor(t,e,i,s,n,r,a,o,h){super(t,e,i,s,n,r,a,o,h),this.isVideoTexture=!0,this.minFilter=r!==void 0?r:ee,this.magFilter=n!==void 0?n:ee,this.generateMipmaps=!1;const c=this;function u(){c.needsUpdate=!0,t.requestVideoFrameCallback(u)}"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback(u)}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;"requestVideoFrameCallback"in t===!1&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Ng extends gt{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=he,this.minFilter=he,this.generateMipmaps=!1,this.needsUpdate=!0}}class la extends gt{constructor(t,e,i,s,n,r,a,o,h,c,u,d){super(null,r,a,o,h,c,s,n,u,d),this.isCompressedTexture=!0,this.image={width:e,height:i},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Dg extends la{constructor(t,e,i,s,n,r){super(t,e,i,n,r),this.isCompressedArrayTexture=!0,this.image.depth=s,this.wrapR=ue,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Ug extends la{constructor(t,e,i){super(void 0,t[0].width,t[0].height,e,i,Kr),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Nh extends gt{constructor(t,e,i,s,n,r,a,o,h){super(t,e,i,s,n,r,a,o,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Vg extends gt{constructor(t,e,i,s,n,r,a,o,h,c=qn){if(c!==qn&&c!==Ua)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");i===void 0&&c===qn&&(i=jr),i===void 0&&c===Ua&&(i=Ol),super(null,s,n,r,a,o,c,i,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=a!==void 0?a:he,this.minFilter=o!==void 0?o:he,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(t){return super.copy(t),this.compareFunction=t.compareFunction,this}toJSON(t){const e=super.toJSON(t);return this.compareFunction!==null&&(e.compareFunction=this.compareFunction),e}}class me{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const i=this.getUtoTmapping(t);return this.getPoint(i,e)}getPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return e}getSpacedPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPointAt(i/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let i,s=this.getPoint(0),n=0;e.push(0);for(let r=1;r<=t;r++)i=this.getPoint(r/t),n+=i.distanceTo(s),e.push(n),s=i;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const i=this.getLengths();let s=0;const n=i.length;let r;e?r=e:r=t*i[n-1];let a=0,o=n-1,h;for(;a<=o;)if(s=Math.floor(a+(o-a)/2),h=i[s]-r,h<0)a=s+1;else if(h>0)o=s-1;else{o=s;break}if(s=o,i[s]===r)return s/(n-1);const c=i[s],d=i[s+1]-c,f=(r-c)/d;return(s+f)/(n-1)}getTangent(t,e){let s=t-1e-4,n=t+1e-4;s<0&&(s=0),n>1&&(n=1);const r=this.getPoint(s),a=this.getPoint(n),o=e||(r.isVector2?new B:new w);return o.copy(a).sub(r).normalize(),o}getTangentAt(t,e){const i=this.getUtoTmapping(t);return this.getTangent(i,e)}computeFrenetFrames(t,e){const i=new w,s=[],n=[],r=[],a=new w,o=new Y;for(let f=0;f<=t;f++){const p=f/t;s[f]=this.getTangentAt(p,new w)}n[0]=new w,r[0]=new w;let h=Number.MAX_VALUE;const c=Math.abs(s[0].x),u=Math.abs(s[0].y),d=Math.abs(s[0].z);c<=h&&(h=c,i.set(1,0,0)),u<=h&&(h=u,i.set(0,1,0)),d<=h&&i.set(0,0,1),a.crossVectors(s[0],i).normalize(),n[0].crossVectors(s[0],a),r[0].crossVectors(s[0],n[0]);for(let f=1;f<=t;f++){if(n[f]=n[f-1].clone(),r[f]=r[f-1].clone(),a.crossVectors(s[f-1],s[f]),a.length()>Number.EPSILON){a.normalize();const p=Math.acos(H(s[f-1].dot(s[f]),-1,1));n[f].applyMatrix4(o.makeRotationAxis(a,p))}r[f].crossVectors(s[f],n[f])}if(e===!0){let f=Math.acos(H(n[0].dot(n[t]),-1,1));f/=t,s[0].dot(a.crossVectors(n[0],n[t]))>0&&(f=-f);for(let p=1;p<=t;p++)n[p].applyMatrix4(o.makeRotationAxis(s[p],f*p)),r[p].crossVectors(s[p],n[p])}return{tangents:s,normals:n,binormals:r}}clone(){return new this.constructor().copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class ca extends me{constructor(t=0,e=0,i=1,s=1,n=0,r=Math.PI*2,a=!1,o=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=i,this.yRadius=s,this.aStartAngle=n,this.aEndAngle=r,this.aClockwise=a,this.aRotation=o}getPoint(t,e=new B){const i=e,s=Math.PI*2;let n=this.aEndAngle-this.aStartAngle;const r=Math.abs(n)<Number.EPSILON;for(;n<0;)n+=s;for(;n>s;)n-=s;n<Number.EPSILON&&(r?n=0:n=s),this.aClockwise===!0&&!r&&(n===s?n=-s:n=n-s);const a=this.aStartAngle+t*n;let o=this.aX+this.xRadius*Math.cos(a),h=this.aY+this.yRadius*Math.sin(a);if(this.aRotation!==0){const c=Math.cos(this.aRotation),u=Math.sin(this.aRotation),d=o-this.aX,f=h-this.aY;o=d*c-f*u+this.aX,h=d*u+f*c+this.aY}return i.set(o,h)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}class Pu extends ca{constructor(t,e,i,s,n,r){super(t,e,i,i,s,n,r),this.isArcCurve=!0,this.type="ArcCurve"}}function ua(){let l=0,t=0,e=0,i=0;function s(n,r,a,o){l=n,t=a,e=-3*n+3*r-2*a-o,i=2*n-2*r+a+o}return{initCatmullRom:function(n,r,a,o,h){s(r,a,h*(a-n),h*(o-r))},initNonuniformCatmullRom:function(n,r,a,o,h,c,u){let d=(r-n)/h-(a-n)/(h+c)+(a-r)/c,f=(a-r)/c-(o-r)/(c+u)+(o-a)/u;d*=c,f*=c,s(r,a,d,f)},calc:function(n){const r=n*n,a=r*n;return l+t*n+e*r+i*a}}}const an=new w,wr=new ua,_r=new ua,Mr=new ua;class ku extends me{constructor(t=[],e=!1,i="centripetal",s=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=i,this.tension=s}getPoint(t,e=new w){const i=e,s=this.points,n=s.length,r=(n-(this.closed?0:1))*t;let a=Math.floor(r),o=r-a;this.closed?a+=a>0?0:(Math.floor(Math.abs(a)/n)+1)*n:o===0&&a===n-1&&(a=n-2,o=1);let h,c;this.closed||a>0?h=s[(a-1)%n]:(an.subVectors(s[0],s[1]).add(s[0]),h=an);const u=s[a%n],d=s[(a+1)%n];if(this.closed||a+2<n?c=s[(a+2)%n]:(an.subVectors(s[n-1],s[n-2]).add(s[n-1]),c=an),this.curveType==="centripetal"||this.curveType==="chordal"){const f=this.curveType==="chordal"?.5:.25;let p=Math.pow(h.distanceToSquared(u),f),m=Math.pow(u.distanceToSquared(d),f),g=Math.pow(d.distanceToSquared(c),f);m<1e-4&&(m=1),p<1e-4&&(p=m),g<1e-4&&(g=m),wr.initNonuniformCatmullRom(h.x,u.x,d.x,c.x,p,m,g),_r.initNonuniformCatmullRom(h.y,u.y,d.y,c.y,p,m,g),Mr.initNonuniformCatmullRom(h.z,u.z,d.z,c.z,p,m,g)}else this.curveType==="catmullrom"&&(wr.initCatmullRom(h.x,u.x,d.x,c.x,this.tension),_r.initCatmullRom(h.y,u.y,d.y,c.y,this.tension),Mr.initCatmullRom(h.z,u.z,d.z,c.z,this.tension));return i.set(wr.calc(o),_r.calc(o),Mr.calc(o)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const s=t.points[e];this.points.push(s.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const s=this.points[e];t.points.push(s.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const s=t.points[e];this.points.push(new w().fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function Io(l,t,e,i,s){const n=(i-t)*.5,r=(s-e)*.5,a=l*l,o=l*a;return(2*e-2*i+n+r)*o+(-3*e+3*i-2*n-r)*a+n*l+e}function Eu(l,t){const e=1-l;return e*e*t}function Ru(l,t){return 2*(1-l)*l*t}function Lu(l,t){return l*l*t}function ps(l,t,e,i){return Eu(l,t)+Ru(l,e)+Lu(l,i)}function Ou(l,t){const e=1-l;return e*e*e*t}function Nu(l,t){const e=1-l;return 3*e*e*l*t}function Du(l,t){return 3*(1-l)*l*l*t}function Uu(l,t){return l*l*l*t}function ms(l,t,e,i,s){return Ou(l,t)+Nu(l,e)+Du(l,i)+Uu(l,s)}class Dh extends me{constructor(t=new B,e=new B,i=new B,s=new B){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=i,this.v3=s}getPoint(t,e=new B){const i=e,s=this.v0,n=this.v1,r=this.v2,a=this.v3;return i.set(ms(t,s.x,n.x,r.x,a.x),ms(t,s.y,n.y,r.y,a.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class Vu extends me{constructor(t=new w,e=new w,i=new w,s=new w){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=i,this.v3=s}getPoint(t,e=new w){const i=e,s=this.v0,n=this.v1,r=this.v2,a=this.v3;return i.set(ms(t,s.x,n.x,r.x,a.x),ms(t,s.y,n.y,r.y,a.y),ms(t,s.z,n.z,r.z,a.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}class Uh extends me{constructor(t=new B,e=new B){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new B){const i=e;return t===1?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new B){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Gu extends me{constructor(t=new w,e=new w){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new w){const i=e;return t===1?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new w){return e.subVectors(this.v2,this.v1).normalize()}getTangentAt(t,e){return this.getTangent(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Vh extends me{constructor(t=new B,e=new B,i=new B){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new B){const i=e,s=this.v0,n=this.v1,r=this.v2;return i.set(ps(t,s.x,n.x,r.x),ps(t,s.y,n.y,r.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Gh extends me{constructor(t=new w,e=new w,i=new w){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new w){const i=e,s=this.v0,n=this.v1,r=this.v2;return i.set(ps(t,s.x,n.x,r.x),ps(t,s.y,n.y,r.y),ps(t,s.z,n.z,r.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}class Wh extends me{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new B){const i=e,s=this.points,n=(s.length-1)*t,r=Math.floor(n),a=n-r,o=s[r===0?r:r-1],h=s[r],c=s[r>s.length-2?s.length-1:r+1],u=s[r>s.length-3?s.length-1:r+2];return i.set(Io(a,o.x,h.x,c.x,u.x),Io(a,o.y,h.y,c.y,u.y)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const s=t.points[e];this.points.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const s=this.points[e];t.points.push(s.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const s=t.points[e];this.points.push(new B().fromArray(s))}return this}}var Bn=Object.freeze({__proto__:null,ArcCurve:Pu,CatmullRomCurve3:ku,CubicBezierCurve:Dh,CubicBezierCurve3:Vu,EllipseCurve:ca,LineCurve:Uh,LineCurve3:Gu,QuadraticBezierCurve:Vh,QuadraticBezierCurve3:Gh,SplineCurve:Wh});class Wu extends me{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);if(!t.equals(e)){const i=t.isVector2===!0?"LineCurve":"LineCurve3";this.curves.push(new Bn[i](e,t))}return this}getPoint(t,e){const i=t*this.getLength(),s=this.getCurveLengths();let n=0;for(;n<s.length;){if(s[n]>=i){const r=s[n]-i,a=this.curves[n],o=a.getLength(),h=o===0?0:1-r/o;return a.getPointAt(h,e)}n++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let i=0,s=this.curves.length;i<s;i++)e+=this.curves[i].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let i;for(let s=0,n=this.curves;s<n.length;s++){const r=n[s],a=r.isEllipseCurve?t*2:r.isLineCurve||r.isLineCurve3?1:r.isSplineCurve?t*r.points.length:t,o=r.getPoints(a);for(let h=0;h<o.length;h++){const c=o[h];i&&i.equals(c)||(e.push(c),i=c)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const s=t.curves[e];this.curves.push(s.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,i=this.curves.length;e<i;e++){const s=this.curves[e];t.curves.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const s=t.curves[e];this.curves.push(new Bn[s.type]().fromJSON(s))}return this}}class Fn extends Wu{constructor(t){super(),this.type="Path",this.currentPoint=new B,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,i=t.length;e<i;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const i=new Uh(this.currentPoint.clone(),new B(t,e));return this.curves.push(i),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,i,s){const n=new Vh(this.currentPoint.clone(),new B(t,e),new B(i,s));return this.curves.push(n),this.currentPoint.set(i,s),this}bezierCurveTo(t,e,i,s,n,r){const a=new Dh(this.currentPoint.clone(),new B(t,e),new B(i,s),new B(n,r));return this.curves.push(a),this.currentPoint.set(n,r),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),i=new Wh(e);return this.curves.push(i),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,i,s,n,r){const a=this.currentPoint.x,o=this.currentPoint.y;return this.absarc(t+a,e+o,i,s,n,r),this}absarc(t,e,i,s,n,r){return this.absellipse(t,e,i,i,s,n,r),this}ellipse(t,e,i,s,n,r,a,o){const h=this.currentPoint.x,c=this.currentPoint.y;return this.absellipse(t+h,e+c,i,s,n,r,a,o),this}absellipse(t,e,i,s,n,r,a,o){const h=new ca(t,e,i,s,n,r,a,o);if(this.curves.length>0){const u=h.getPoint(0);u.equals(this.currentPoint)||this.lineTo(u.x,u.y)}this.curves.push(h);const c=h.getPoint(1);return this.currentPoint.copy(c),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class Dn extends Z{constructor(t=[new B(0,-.5),new B(.5,0),new B(0,.5)],e=12,i=0,s=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:i,phiLength:s},e=Math.floor(e),s=H(s,0,Math.PI*2);const n=[],r=[],a=[],o=[],h=[],c=1/e,u=new w,d=new B,f=new w,p=new w,m=new w;let g=0,x=0;for(let y=0;y<=t.length-1;y++)switch(y){case 0:g=t[y+1].x-t[y].x,x=t[y+1].y-t[y].y,f.x=x*1,f.y=-g,f.z=x*0,m.copy(f),f.normalize(),o.push(f.x,f.y,f.z);break;case t.length-1:o.push(m.x,m.y,m.z);break;default:g=t[y+1].x-t[y].x,x=t[y+1].y-t[y].y,f.x=x*1,f.y=-g,f.z=x*0,p.copy(f),f.x+=m.x,f.y+=m.y,f.z+=m.z,f.normalize(),o.push(f.x,f.y,f.z),m.copy(p)}for(let y=0;y<=e;y++){const b=i+y*c*s,v=Math.sin(b),_=Math.cos(b);for(let M=0;M<=t.length-1;M++){u.x=t[M].x*v,u.y=t[M].y,u.z=t[M].x*_,r.push(u.x,u.y,u.z),d.x=y/e,d.y=M/(t.length-1),a.push(d.x,d.y);const A=o[3*M+0]*v,S=o[3*M+1],C=o[3*M+0]*_;h.push(A,S,C)}}for(let y=0;y<e;y++)for(let b=0;b<t.length-1;b++){const v=b+y*t.length,_=v,M=v+t.length,A=v+t.length+1,S=v+1;n.push(_,M,S),n.push(A,S,M)}this.setIndex(n),this.setAttribute("position",new O(r,3)),this.setAttribute("uv",new O(a,2)),this.setAttribute("normal",new O(h,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Dn(t.points,t.segments,t.phiStart,t.phiLength)}}class da extends Dn{constructor(t=1,e=1,i=4,s=8){const n=new Fn;n.absarc(0,-e/2,t,Math.PI*1.5,0),n.absarc(0,e/2,t,0,Math.PI*.5),super(n.getPoints(i),s),this.type="CapsuleGeometry",this.parameters={radius:t,length:e,capSegments:i,radialSegments:s}}static fromJSON(t){return new da(t.radius,t.length,t.capSegments,t.radialSegments)}}class fa extends Z{constructor(t=1,e=32,i=0,s=Math.PI*2){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:i,thetaLength:s},e=Math.max(3,e);const n=[],r=[],a=[],o=[],h=new w,c=new B;r.push(0,0,0),a.push(0,0,1),o.push(.5,.5);for(let u=0,d=3;u<=e;u++,d+=3){const f=i+u/e*s;h.x=t*Math.cos(f),h.y=t*Math.sin(f),r.push(h.x,h.y,h.z),a.push(0,0,1),c.x=(r[d]/t+1)/2,c.y=(r[d+1]/t+1)/2,o.push(c.x,c.y)}for(let u=1;u<=e;u++)n.push(u,u+1,0);this.setIndex(n),this.setAttribute("position",new O(r,3)),this.setAttribute("normal",new O(a,3)),this.setAttribute("uv",new O(o,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new fa(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Ts extends Z{constructor(t=1,e=1,i=1,s=32,n=1,r=!1,a=0,o=Math.PI*2){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:i,radialSegments:s,heightSegments:n,openEnded:r,thetaStart:a,thetaLength:o};const h=this;s=Math.floor(s),n=Math.floor(n);const c=[],u=[],d=[],f=[];let p=0;const m=[],g=i/2;let x=0;y(),r===!1&&(t>0&&b(!0),e>0&&b(!1)),this.setIndex(c),this.setAttribute("position",new O(u,3)),this.setAttribute("normal",new O(d,3)),this.setAttribute("uv",new O(f,2));function y(){const v=new w,_=new w;let M=0;const A=(e-t)/i;for(let S=0;S<=n;S++){const C=[],z=S/n,k=z*(e-t)+t;for(let U=0;U<=s;U++){const W=U/s,R=W*o+a,I=Math.sin(R),N=Math.cos(R);_.x=k*I,_.y=-z*i+g,_.z=k*N,u.push(_.x,_.y,_.z),v.set(I,A,N).normalize(),d.push(v.x,v.y,v.z),f.push(W,1-z),C.push(p++)}m.push(C)}for(let S=0;S<s;S++)for(let C=0;C<n;C++){const z=m[C][S],k=m[C+1][S],U=m[C+1][S+1],W=m[C][S+1];(t>0||C!==0)&&(c.push(z,k,W),M+=3),(e>0||C!==n-1)&&(c.push(k,U,W),M+=3)}h.addGroup(x,M,0),x+=M}function b(v){const _=p,M=new B,A=new w;let S=0;const C=v===!0?t:e,z=v===!0?1:-1;for(let U=1;U<=s;U++)u.push(0,g*z,0),d.push(0,z,0),f.push(.5,.5),p++;const k=p;for(let U=0;U<=s;U++){const R=U/s*o+a,I=Math.cos(R),N=Math.sin(R);A.x=C*N,A.y=g*z,A.z=C*I,u.push(A.x,A.y,A.z),d.push(0,z,0),M.x=I*.5+.5,M.y=N*.5*z+.5,f.push(M.x,M.y),p++}for(let U=0;U<s;U++){const W=_+U,R=k+U;v===!0?c.push(R,R+1,W):c.push(R+1,R,W),S+=3}h.addGroup(x,S,v===!0?1:2),x+=S}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ts(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class pa extends Ts{constructor(t=1,e=1,i=32,s=1,n=!1,r=0,a=Math.PI*2){super(0,t,e,i,s,n,r,a),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:i,heightSegments:s,openEnded:n,thetaStart:r,thetaLength:a}}static fromJSON(t){return new pa(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class ai extends Z{constructor(t=[],e=[],i=1,s=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:i,detail:s};const n=[],r=[];a(s),h(i),c(),this.setAttribute("position",new O(n,3)),this.setAttribute("normal",new O(n.slice(),3)),this.setAttribute("uv",new O(r,2)),s===0?this.computeVertexNormals():this.normalizeNormals();function a(y){const b=new w,v=new w,_=new w;for(let M=0;M<e.length;M+=3)f(e[M+0],b),f(e[M+1],v),f(e[M+2],_),o(b,v,_,y)}function o(y,b,v,_){const M=_+1,A=[];for(let S=0;S<=M;S++){A[S]=[];const C=y.clone().lerp(v,S/M),z=b.clone().lerp(v,S/M),k=M-S;for(let U=0;U<=k;U++)U===0&&S===M?A[S][U]=C:A[S][U]=C.clone().lerp(z,U/k)}for(let S=0;S<M;S++)for(let C=0;C<2*(M-S)-1;C++){const z=Math.floor(C/2);C%2===0?(d(A[S][z+1]),d(A[S+1][z]),d(A[S][z])):(d(A[S][z+1]),d(A[S+1][z+1]),d(A[S+1][z]))}}function h(y){const b=new w;for(let v=0;v<n.length;v+=3)b.x=n[v+0],b.y=n[v+1],b.z=n[v+2],b.normalize().multiplyScalar(y),n[v+0]=b.x,n[v+1]=b.y,n[v+2]=b.z}function c(){const y=new w;for(let b=0;b<n.length;b+=3){y.x=n[b+0],y.y=n[b+1],y.z=n[b+2];const v=g(y)/2/Math.PI+.5,_=x(y)/Math.PI+.5;r.push(v,1-_)}p(),u()}function u(){for(let y=0;y<r.length;y+=6){const b=r[y+0],v=r[y+2],_=r[y+4],M=Math.max(b,v,_),A=Math.min(b,v,_);M>.9&&A<.1&&(b<.2&&(r[y+0]+=1),v<.2&&(r[y+2]+=1),_<.2&&(r[y+4]+=1))}}function d(y){n.push(y.x,y.y,y.z)}function f(y,b){const v=y*3;b.x=t[v+0],b.y=t[v+1],b.z=t[v+2]}function p(){const y=new w,b=new w,v=new w,_=new w,M=new B,A=new B,S=new B;for(let C=0,z=0;C<n.length;C+=9,z+=6){y.set(n[C+0],n[C+1],n[C+2]),b.set(n[C+3],n[C+4],n[C+5]),v.set(n[C+6],n[C+7],n[C+8]),M.set(r[z+0],r[z+1]),A.set(r[z+2],r[z+3]),S.set(r[z+4],r[z+5]),_.copy(y).add(b).add(v).divideScalar(3);const k=g(_);m(M,z+0,y,k),m(A,z+2,b,k),m(S,z+4,v,k)}}function m(y,b,v,_){_<0&&y.x===1&&(r[b]=y.x-1),v.x===0&&v.z===0&&(r[b]=_/2/Math.PI+.5)}function g(y){return Math.atan2(y.z,-y.x)}function x(y){return Math.atan2(-y.y,Math.sqrt(y.x*y.x+y.z*y.z))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ai(t.vertices,t.indices,t.radius,t.details)}}class ma extends ai{constructor(t=1,e=0){const i=(1+Math.sqrt(5))/2,s=1/i,n=[-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,-s,-i,0,-s,i,0,s,-i,0,s,i,-s,-i,0,-s,i,0,s,-i,0,s,i,0,-i,0,-s,i,0,-s,-i,0,s,i,0,s],r=[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];super(n,r,t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new ma(t.radius,t.detail)}}const on=new w,hn=new w,Sr=new w,ln=new Yt;class Hu extends Z{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},t!==null){const s=Math.pow(10,4),n=Math.cos(ii*e),r=t.getIndex(),a=t.getAttribute("position"),o=r?r.count:a.count,h=[0,0,0],c=["a","b","c"],u=new Array(3),d={},f=[];for(let p=0;p<o;p+=3){r?(h[0]=r.getX(p),h[1]=r.getX(p+1),h[2]=r.getX(p+2)):(h[0]=p,h[1]=p+1,h[2]=p+2);const{a:m,b:g,c:x}=ln;if(m.fromBufferAttribute(a,h[0]),g.fromBufferAttribute(a,h[1]),x.fromBufferAttribute(a,h[2]),ln.getNormal(Sr),u[0]=`${Math.round(m.x*s)},${Math.round(m.y*s)},${Math.round(m.z*s)}`,u[1]=`${Math.round(g.x*s)},${Math.round(g.y*s)},${Math.round(g.z*s)}`,u[2]=`${Math.round(x.x*s)},${Math.round(x.y*s)},${Math.round(x.z*s)}`,!(u[0]===u[1]||u[1]===u[2]||u[2]===u[0]))for(let y=0;y<3;y++){const b=(y+1)%3,v=u[y],_=u[b],M=ln[c[y]],A=ln[c[b]],S=`${v}_${_}`,C=`${_}_${v}`;C in d&&d[C]?(Sr.dot(d[C].normal)<=n&&(f.push(M.x,M.y,M.z),f.push(A.x,A.y,A.z)),d[C]=null):S in d||(d[S]={index0:h[y],index1:h[b],normal:Sr.clone()})}}for(const p in d)if(d[p]){const{index0:m,index1:g}=d[p];on.fromBufferAttribute(a,m),hn.fromBufferAttribute(a,g),f.push(on.x,on.y,on.z),f.push(hn.x,hn.y,hn.z)}this.setAttribute("position",new O(f,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}class Ri extends Fn{constructor(t){super(t),this.uuid=Jt(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let i=0,s=this.holes.length;i<s;i++)e[i]=this.holes[i].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const s=t.holes[e];this.holes.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,i=this.holes.length;e<i;e++){const s=this.holes[e];t.holes.push(s.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const s=t.holes[e];this.holes.push(new Fn().fromJSON(s))}return this}}const qu={triangulate:function(l,t,e=2){const i=t&&t.length,s=i?t[0]*e:l.length;let n=Hh(l,0,s,e,!0);const r=[];if(!n||n.next===n.prev)return r;let a,o,h,c,u,d,f;if(i&&(n=Ku(l,t,n,e)),l.length>80*e){a=h=l[0],o=c=l[1];for(let p=e;p<s;p+=e)u=l[p],d=l[p+1],u<a&&(a=u),d<o&&(o=d),u>h&&(h=u),d>c&&(c=d);f=Math.max(h-a,c-o),f=f!==0?32767/f:0}return vs(n,r,e,a,o,f,0),r}};function Hh(l,t,e,i,s){let n,r;if(s===od(l,t,e,i)>0)for(n=t;n<e;n+=i)r=Co(n,l[n],l[n+1],r);else for(n=e-i;n>=t;n-=i)r=Co(n,l[n],l[n+1],r);return r&&Un(r,r.next)&&(_s(r),r=r.next),r}function ri(l,t){if(!l)return l;t||(t=l);let e=l,i;do if(i=!1,!e.steiner&&(Un(e,e.next)||ut(e.prev,e,e.next)===0)){if(_s(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function vs(l,t,e,i,s,n,r){if(!l)return;!r&&n&&ed(l,i,s,n);let a=l,o,h;for(;l.prev!==l.next;){if(o=l.prev,h=l.next,n?Yu(l,i,s,n):Xu(l)){t.push(o.i/e|0),t.push(l.i/e|0),t.push(h.i/e|0),_s(l),l=h.next,a=h.next;continue}if(l=h,l===a){r?r===1?(l=Ju(ri(l),t,e),vs(l,t,e,i,s,n,2)):r===2&&Zu(l,t,e,i,s,n):vs(ri(l),t,e,i,s,n,1);break}}}function Xu(l){const t=l.prev,e=l,i=l.next;if(ut(t,e,i)>=0)return!1;const s=t.x,n=e.x,r=i.x,a=t.y,o=e.y,h=i.y,c=s<n?s<r?s:r:n<r?n:r,u=a<o?a<h?a:h:o<h?o:h,d=s>n?s>r?s:r:n>r?n:r,f=a>o?a>h?a:h:o>h?o:h;let p=i.next;for(;p!==t;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&ki(s,a,n,o,r,h,p.x,p.y)&&ut(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function Yu(l,t,e,i){const s=l.prev,n=l,r=l.next;if(ut(s,n,r)>=0)return!1;const a=s.x,o=n.x,h=r.x,c=s.y,u=n.y,d=r.y,f=a<o?a<h?a:h:o<h?o:h,p=c<u?c<d?c:d:u<d?u:d,m=a>o?a>h?a:h:o>h?o:h,g=c>u?c>d?c:d:u>d?u:d,x=Dr(f,p,t,e,i),y=Dr(m,g,t,e,i);let b=l.prevZ,v=l.nextZ;for(;b&&b.z>=x&&v&&v.z<=y;){if(b.x>=f&&b.x<=m&&b.y>=p&&b.y<=g&&b!==s&&b!==r&&ki(a,c,o,u,h,d,b.x,b.y)&&ut(b.prev,b,b.next)>=0||(b=b.prevZ,v.x>=f&&v.x<=m&&v.y>=p&&v.y<=g&&v!==s&&v!==r&&ki(a,c,o,u,h,d,v.x,v.y)&&ut(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;b&&b.z>=x;){if(b.x>=f&&b.x<=m&&b.y>=p&&b.y<=g&&b!==s&&b!==r&&ki(a,c,o,u,h,d,b.x,b.y)&&ut(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=y;){if(v.x>=f&&v.x<=m&&v.y>=p&&v.y<=g&&v!==s&&v!==r&&ki(a,c,o,u,h,d,v.x,v.y)&&ut(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Ju(l,t,e){let i=l;do{const s=i.prev,n=i.next.next;!Un(s,n)&&qh(s,i,i.next,n)&&ws(s,n)&&ws(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),_s(i),_s(i.next),i=l=n),i=i.next}while(i!==l);return ri(i)}function Zu(l,t,e,i,s,n){let r=l;do{let a=r.next.next;for(;a!==r.prev;){if(r.i!==a.i&&nd(r,a)){let o=Xh(r,a);r=ri(r,r.next),o=ri(o,o.next),vs(r,t,e,i,s,n,0),vs(o,t,e,i,s,n,0);return}a=a.next}r=r.next}while(r!==l)}function Ku(l,t,e,i){const s=[];let n,r,a,o,h;for(n=0,r=t.length;n<r;n++)a=t[n]*i,o=n<r-1?t[n+1]*i:l.length,h=Hh(l,a,o,i,!1),h===h.next&&(h.steiner=!0),s.push(sd(h));for(s.sort(ju),n=0;n<s.length;n++)e=Qu(s[n],e);return e}function ju(l,t){return l.x-t.x}function Qu(l,t){const e=$u(l,t);if(!e)return t;const i=Xh(e,l);return ri(i,i.next),ri(e,e.next)}function $u(l,t){let e=t,i=-1/0,s;const n=l.x,r=l.y;do{if(r<=e.y&&r>=e.next.y&&e.next.y!==e.y){const d=e.x+(r-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(d<=n&&d>i&&(i=d,s=e.x<e.next.x?e:e.next,d===n))return s}e=e.next}while(e!==t);if(!s)return null;const a=s,o=s.x,h=s.y;let c=1/0,u;e=s;do n>=e.x&&e.x>=o&&n!==e.x&&ki(r<h?n:i,r,o,h,r<h?i:n,r,e.x,e.y)&&(u=Math.abs(r-e.y)/(n-e.x),ws(e,l)&&(u<c||u===c&&(e.x>s.x||e.x===s.x&&td(s,e)))&&(s=e,c=u)),e=e.next;while(e!==a);return s}function td(l,t){return ut(l.prev,l,t.prev)<0&&ut(t.next,l,l.next)<0}function ed(l,t,e,i){let s=l;do s.z===0&&(s.z=Dr(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==l);s.prevZ.nextZ=null,s.prevZ=null,id(s)}function id(l){let t,e,i,s,n,r,a,o,h=1;do{for(e=l,l=null,n=null,r=0;e;){for(r++,i=e,a=0,t=0;t<h&&(a++,i=i.nextZ,!!i);t++);for(o=h;a>0||o>0&&i;)a!==0&&(o===0||!i||e.z<=i.z)?(s=e,e=e.nextZ,a--):(s=i,i=i.nextZ,o--),n?n.nextZ=s:l=s,s.prevZ=n,n=s;e=i}n.nextZ=null,h*=2}while(r>1);return l}function Dr(l,t,e,i,s){return l=(l-e)*s|0,t=(t-i)*s|0,l=(l|l<<8)&16711935,l=(l|l<<4)&252645135,l=(l|l<<2)&858993459,l=(l|l<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,l|t<<1}function sd(l){let t=l,e=l;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==l);return e}function ki(l,t,e,i,s,n,r,a){return(s-r)*(t-a)>=(l-r)*(n-a)&&(l-r)*(i-a)>=(e-r)*(t-a)&&(e-r)*(n-a)>=(s-r)*(i-a)}function nd(l,t){return l.next.i!==t.i&&l.prev.i!==t.i&&!rd(l,t)&&(ws(l,t)&&ws(t,l)&&ad(l,t)&&(ut(l.prev,l,t.prev)||ut(l,t.prev,t))||Un(l,t)&&ut(l.prev,l,l.next)>0&&ut(t.prev,t,t.next)>0)}function ut(l,t,e){return(t.y-l.y)*(e.x-t.x)-(t.x-l.x)*(e.y-t.y)}function Un(l,t){return l.x===t.x&&l.y===t.y}function qh(l,t,e,i){const s=un(ut(l,t,e)),n=un(ut(l,t,i)),r=un(ut(e,i,l)),a=un(ut(e,i,t));return!!(s!==n&&r!==a||s===0&&cn(l,e,t)||n===0&&cn(l,i,t)||r===0&&cn(e,l,i)||a===0&&cn(e,t,i))}function cn(l,t,e){return t.x<=Math.max(l.x,e.x)&&t.x>=Math.min(l.x,e.x)&&t.y<=Math.max(l.y,e.y)&&t.y>=Math.min(l.y,e.y)}function un(l){return l>0?1:l<0?-1:0}function rd(l,t){let e=l;do{if(e.i!==l.i&&e.next.i!==l.i&&e.i!==t.i&&e.next.i!==t.i&&qh(e,e.next,l,t))return!0;e=e.next}while(e!==l);return!1}function ws(l,t){return ut(l.prev,l,l.next)<0?ut(l,t,l.next)>=0&&ut(l,l.prev,t)>=0:ut(l,t,l.prev)<0||ut(l,l.next,t)<0}function ad(l,t){let e=l,i=!1;const s=(l.x+t.x)/2,n=(l.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==l);return i}function Xh(l,t){const e=new Ur(l.i,l.x,l.y),i=new Ur(t.i,t.x,t.y),s=l.next,n=t.prev;return l.next=t,t.prev=l,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function Co(l,t,e,i){const s=new Ur(l,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function _s(l){l.next.prev=l.prev,l.prev.next=l.next,l.prevZ&&(l.prevZ.nextZ=l.nextZ),l.nextZ&&(l.nextZ.prevZ=l.prevZ)}function Ur(l,t,e){this.i=l,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function od(l,t,e,i){let s=0;for(let n=t,r=e-i;n<e;n+=i)s+=(l[r]-l[n])*(l[n+1]+l[r+1]),r=n;return s}class ze{static area(t){const e=t.length;let i=0;for(let s=e-1,n=0;n<e;s=n++)i+=t[s].x*t[n].y-t[n].x*t[s].y;return i*.5}static isClockWise(t){return ze.area(t)<0}static triangulateShape(t,e){const i=[],s=[],n=[];zo(t),Bo(i,t);let r=t.length;e.forEach(zo);for(let o=0;o<e.length;o++)s.push(r),r+=e[o].length,Bo(i,e[o]);const a=qu.triangulate(i,s);for(let o=0;o<a.length;o+=3)n.push(a.slice(o,o+3));return n}}function zo(l){const t=l.length;t>2&&l[t-1].equals(l[0])&&l.pop()}function Bo(l,t){for(let e=0;e<t.length;e++)l.push(t[e].x),l.push(t[e].y)}class ga extends Z{constructor(t=new Ri([new B(.5,.5),new B(-.5,.5),new B(-.5,-.5),new B(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const i=this,s=[],n=[];for(let a=0,o=t.length;a<o;a++){const h=t[a];r(h)}this.setAttribute("position",new O(s,3)),this.setAttribute("uv",new O(n,2)),this.computeVertexNormals();function r(a){const o=[],h=e.curveSegments!==void 0?e.curveSegments:12,c=e.steps!==void 0?e.steps:1,u=e.depth!==void 0?e.depth:1;let d=e.bevelEnabled!==void 0?e.bevelEnabled:!0,f=e.bevelThickness!==void 0?e.bevelThickness:.2,p=e.bevelSize!==void 0?e.bevelSize:f-.1,m=e.bevelOffset!==void 0?e.bevelOffset:0,g=e.bevelSegments!==void 0?e.bevelSegments:3;const x=e.extrudePath,y=e.UVGenerator!==void 0?e.UVGenerator:hd;let b,v=!1,_,M,A,S;x&&(b=x.getSpacedPoints(c),v=!0,d=!1,_=x.computeFrenetFrames(c,!1),M=new w,A=new w,S=new w),d||(g=0,f=0,p=0,m=0);const C=a.extractPoints(h);let z=C.shape;const k=C.holes;if(!ze.isClockWise(z)){z=z.reverse();for(let F=0,P=k.length;F<P;F++){const E=k[F];ze.isClockWise(E)&&(k[F]=E.reverse())}}const W=ze.triangulateShape(z,k),R=z;for(let F=0,P=k.length;F<P;F++){const E=k[F];z=z.concat(E)}function I(F,P,E){return P||console.error("THREE.ExtrudeGeometry: vec does not exist"),F.clone().addScaledVector(P,E)}const N=z.length,wt=W.length;function Bt(F,P,E){let G,L,j;const Q=F.x-P.x,ot=F.y-P.y,_t=E.x-F.x,bt=E.y-F.y,ke=Q*Q+ot*ot,Wi=Q*bt-ot*_t;if(Math.abs(Wi)>Number.EPSILON){const ie=Math.sqrt(ke),Cs=Math.sqrt(_t*_t+bt*bt),J=P.x-ot/ie,at=P.y+Q/ie,le=E.x-bt/Cs,se=E.y+_t/Cs,xe=((le-J)*bt-(se-at)*_t)/(Q*bt-ot*_t);G=J+Q*xe-F.x,L=at+ot*xe-F.y;const zs=G*G+L*L;if(zs<=2)return new B(G,L);j=Math.sqrt(zs/2)}else{let ie=!1;Q>Number.EPSILON?_t>Number.EPSILON&&(ie=!0):Q<-Number.EPSILON?_t<-Number.EPSILON&&(ie=!0):Math.sign(ot)===Math.sign(bt)&&(ie=!0),ie?(G=-ot,L=Q,j=Math.sqrt(ke)):(G=Q,L=ot,j=Math.sqrt(ke/2))}return new B(G/j,L/j)}const nt=[];for(let F=0,P=R.length,E=P-1,G=F+1;F<P;F++,E++,G++)E===P&&(E=0),G===P&&(G=0),nt[F]=Bt(R[F],R[E],R[G]);const ht=[];let et,Lt=nt.concat();for(let F=0,P=k.length;F<P;F++){const E=k[F];et=[];for(let G=0,L=E.length,j=L-1,Q=G+1;G<L;G++,j++,Q++)j===L&&(j=0),Q===L&&(Q=0),et[G]=Bt(E[G],E[j],E[Q]);ht.push(et),Lt=Lt.concat(et)}for(let F=0;F<g;F++){const P=F/g,E=f*Math.cos(P*Math.PI/2),G=p*Math.sin(P*Math.PI/2)+m;for(let L=0,j=R.length;L<j;L++){const Q=I(R[L],nt[L],G);it(Q.x,Q.y,-E)}for(let L=0,j=k.length;L<j;L++){const Q=k[L];et=ht[L];for(let ot=0,_t=Q.length;ot<_t;ot++){const bt=I(Q[ot],et[ot],G);it(bt.x,bt.y,-E)}}}const ye=p+m;for(let F=0;F<N;F++){const P=d?I(z[F],Lt[F],ye):z[F];v?(A.copy(_.normals[0]).multiplyScalar(P.x),M.copy(_.binormals[0]).multiplyScalar(P.y),S.copy(b[0]).add(A).add(M),it(S.x,S.y,S.z)):it(P.x,P.y,0)}for(let F=1;F<=c;F++)for(let P=0;P<N;P++){const E=d?I(z[P],Lt[P],ye):z[P];v?(A.copy(_.normals[F]).multiplyScalar(E.x),M.copy(_.binormals[F]).multiplyScalar(E.y),S.copy(b[F]).add(A).add(M),it(S.x,S.y,S.z)):it(E.x,E.y,u/c*F)}for(let F=g-1;F>=0;F--){const P=F/g,E=f*Math.cos(P*Math.PI/2),G=p*Math.sin(P*Math.PI/2)+m;for(let L=0,j=R.length;L<j;L++){const Q=I(R[L],nt[L],G);it(Q.x,Q.y,u+E)}for(let L=0,j=k.length;L<j;L++){const Q=k[L];et=ht[L];for(let ot=0,_t=Q.length;ot<_t;ot++){const bt=I(Q[ot],et[ot],G);v?it(bt.x,bt.y+b[c-1].y,b[c-1].x+E):it(bt.x,bt.y,u+E)}}}Gi(),hi();function Gi(){const F=s.length/3;if(d){let P=0,E=N*P;for(let G=0;G<wt;G++){const L=W[G];jt(L[2]+E,L[1]+E,L[0]+E)}P=c+g*2,E=N*P;for(let G=0;G<wt;G++){const L=W[G];jt(L[0]+E,L[1]+E,L[2]+E)}}else{for(let P=0;P<wt;P++){const E=W[P];jt(E[2],E[1],E[0])}for(let P=0;P<wt;P++){const E=W[P];jt(E[0]+N*c,E[1]+N*c,E[2]+N*c)}}i.addGroup(F,s.length/3-F,0)}function hi(){const F=s.length/3;let P=0;K(R,P),P+=R.length;for(let E=0,G=k.length;E<G;E++){const L=k[E];K(L,P),P+=L.length}i.addGroup(F,s.length/3-F,1)}function K(F,P){let E=F.length;for(;--E>=0;){const G=E;let L=E-1;L<0&&(L=F.length-1);for(let j=0,Q=c+g*2;j<Q;j++){const ot=N*j,_t=N*(j+1),bt=P+G+ot,ke=P+L+ot,Wi=P+L+_t,ie=P+G+_t;Pe(bt,ke,Wi,ie)}}}function it(F,P,E){o.push(F),o.push(P),o.push(E)}function jt(F,P,E){q(F),q(P),q(E);const G=s.length/3,L=y.generateTopUV(i,s,G-3,G-2,G-1);Ot(L[0]),Ot(L[1]),Ot(L[2])}function Pe(F,P,E,G){q(F),q(P),q(G),q(P),q(E),q(G);const L=s.length/3,j=y.generateSideWallUV(i,s,L-6,L-3,L-2,L-1);Ot(j[0]),Ot(j[1]),Ot(j[3]),Ot(j[1]),Ot(j[2]),Ot(j[3])}function q(F){s.push(o[F*3+0]),s.push(o[F*3+1]),s.push(o[F*3+2])}function Ot(F){n.push(F.x),n.push(F.y)}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes,i=this.parameters.options;return ld(e,i,t)}static fromJSON(t,e){const i=[];for(let n=0,r=t.shapes.length;n<r;n++){const a=e[t.shapes[n]];i.push(a)}const s=t.options.extrudePath;return s!==void 0&&(t.options.extrudePath=new Bn[s.type]().fromJSON(s)),new ga(i,t.options)}}const hd={generateTopUV:function(l,t,e,i,s){const n=t[e*3],r=t[e*3+1],a=t[i*3],o=t[i*3+1],h=t[s*3],c=t[s*3+1];return[new B(n,r),new B(a,o),new B(h,c)]},generateSideWallUV:function(l,t,e,i,s,n){const r=t[e*3],a=t[e*3+1],o=t[e*3+2],h=t[i*3],c=t[i*3+1],u=t[i*3+2],d=t[s*3],f=t[s*3+1],p=t[s*3+2],m=t[n*3],g=t[n*3+1],x=t[n*3+2];return Math.abs(a-c)<Math.abs(r-h)?[new B(r,1-o),new B(h,1-u),new B(d,1-p),new B(m,1-x)]:[new B(a,1-o),new B(c,1-u),new B(f,1-p),new B(g,1-x)]}};function ld(l,t,e){if(e.shapes=[],Array.isArray(l))for(let i=0,s=l.length;i<s;i++){const n=l[i];e.shapes.push(n.uuid)}else e.shapes.push(l.uuid);return e.options=Object.assign({},t),t.extrudePath!==void 0&&(e.options.extrudePath=t.extrudePath.toJSON()),e}class ya extends ai{constructor(t=1,e=0){const i=(1+Math.sqrt(5))/2,s=[-1,i,0,1,i,0,-1,-i,0,1,-i,0,0,-1,i,0,1,i,0,-1,-i,0,1,-i,i,0,-1,i,0,1,-i,0,-1,-i,0,1],n=[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];super(s,n,t,e),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new ya(t.radius,t.detail)}}class Vn extends ai{constructor(t=1,e=0){const i=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],s=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2];super(i,s,t,e),this.type="OctahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Vn(t.radius,t.detail)}}class xa extends Z{constructor(t=1,e=1,i=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:s};const n=t/2,r=e/2,a=Math.floor(i),o=Math.floor(s),h=a+1,c=o+1,u=t/a,d=e/o,f=[],p=[],m=[],g=[];for(let x=0;x<c;x++){const y=x*d-r;for(let b=0;b<h;b++){const v=b*u-n;p.push(v,-y,0),m.push(0,0,1),g.push(b/a),g.push(1-x/o)}}for(let x=0;x<o;x++)for(let y=0;y<a;y++){const b=y+h*x,v=y+h*(x+1),_=y+1+h*(x+1),M=y+1+h*x;f.push(b,v,M),f.push(v,_,M)}this.setIndex(f),this.setAttribute("position",new O(p,3)),this.setAttribute("normal",new O(m,3)),this.setAttribute("uv",new O(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new xa(t.width,t.height,t.widthSegments,t.heightSegments)}}class ba extends Z{constructor(t=.5,e=1,i=32,s=1,n=0,r=Math.PI*2){super(),this.type="RingGeometry",this.parameters={innerRadius:t,outerRadius:e,thetaSegments:i,phiSegments:s,thetaStart:n,thetaLength:r},i=Math.max(3,i),s=Math.max(1,s);const a=[],o=[],h=[],c=[];let u=t;const d=(e-t)/s,f=new w,p=new B;for(let m=0;m<=s;m++){for(let g=0;g<=i;g++){const x=n+g/i*r;f.x=u*Math.cos(x),f.y=u*Math.sin(x),o.push(f.x,f.y,f.z),h.push(0,0,1),p.x=(f.x/e+1)/2,p.y=(f.y/e+1)/2,c.push(p.x,p.y)}u+=d}for(let m=0;m<s;m++){const g=m*(i+1);for(let x=0;x<i;x++){const y=x+g,b=y,v=y+i+1,_=y+i+2,M=y+1;a.push(b,v,M),a.push(v,_,M)}}this.setIndex(a),this.setAttribute("position",new O(o,3)),this.setAttribute("normal",new O(h,3)),this.setAttribute("uv",new O(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new ba(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class va extends Z{constructor(t=new Ri([new B(0,.5),new B(-.5,-.5),new B(.5,-.5)]),e=12){super(),this.type="ShapeGeometry",this.parameters={shapes:t,curveSegments:e};const i=[],s=[],n=[],r=[];let a=0,o=0;if(Array.isArray(t)===!1)h(t);else for(let c=0;c<t.length;c++)h(t[c]),this.addGroup(a,o,c),a+=o,o=0;this.setIndex(i),this.setAttribute("position",new O(s,3)),this.setAttribute("normal",new O(n,3)),this.setAttribute("uv",new O(r,2));function h(c){const u=s.length/3,d=c.extractPoints(e);let f=d.shape;const p=d.holes;ze.isClockWise(f)===!1&&(f=f.reverse());for(let g=0,x=p.length;g<x;g++){const y=p[g];ze.isClockWise(y)===!0&&(p[g]=y.reverse())}const m=ze.triangulateShape(f,p);for(let g=0,x=p.length;g<x;g++){const y=p[g];f=f.concat(y)}for(let g=0,x=f.length;g<x;g++){const y=f[g];s.push(y.x,y.y,0),n.push(0,0,1),r.push(y.x,y.y)}for(let g=0,x=m.length;g<x;g++){const y=m[g],b=y[0]+u,v=y[1]+u,_=y[2]+u;i.push(b,v,_),o+=3}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes;return cd(e,t)}static fromJSON(t,e){const i=[];for(let s=0,n=t.shapes.length;s<n;s++){const r=e[t.shapes[s]];i.push(r)}return new va(i,t.curveSegments)}}function cd(l,t){if(t.shapes=[],Array.isArray(l))for(let e=0,i=l.length;e<i;e++){const s=l[e];t.shapes.push(s.uuid)}else t.shapes.push(l.uuid);return t}class Is extends Z{constructor(t=1,e=32,i=16,s=0,n=Math.PI*2,r=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:i,phiStart:s,phiLength:n,thetaStart:r,thetaLength:a},e=Math.max(3,Math.floor(e)),i=Math.max(2,Math.floor(i));const o=Math.min(r+a,Math.PI);let h=0;const c=[],u=new w,d=new w,f=[],p=[],m=[],g=[];for(let x=0;x<=i;x++){const y=[],b=x/i;let v=0;x===0&&r===0?v=.5/e:x===i&&o===Math.PI&&(v=-.5/e);for(let _=0;_<=e;_++){const M=_/e;u.x=-t*Math.cos(s+M*n)*Math.sin(r+b*a),u.y=t*Math.cos(r+b*a),u.z=t*Math.sin(s+M*n)*Math.sin(r+b*a),p.push(u.x,u.y,u.z),d.copy(u).normalize(),m.push(d.x,d.y,d.z),g.push(M+v,1-b),y.push(h++)}c.push(y)}for(let x=0;x<i;x++)for(let y=0;y<e;y++){const b=c[x][y+1],v=c[x][y],_=c[x+1][y],M=c[x+1][y+1];(x!==0||r>0)&&f.push(b,v,M),(x!==i-1||o<Math.PI)&&f.push(v,_,M)}this.setIndex(f),this.setAttribute("position",new O(p,3)),this.setAttribute("normal",new O(m,3)),this.setAttribute("uv",new O(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Is(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class wa extends ai{constructor(t=1,e=0){const i=[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],s=[2,1,0,0,3,2,1,3,0,2,3,1];super(i,s,t,e),this.type="TetrahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new wa(t.radius,t.detail)}}class _a extends Z{constructor(t=1,e=.4,i=12,s=48,n=Math.PI*2){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:i,tubularSegments:s,arc:n},i=Math.floor(i),s=Math.floor(s);const r=[],a=[],o=[],h=[],c=new w,u=new w,d=new w;for(let f=0;f<=i;f++)for(let p=0;p<=s;p++){const m=p/s*n,g=f/i*Math.PI*2;u.x=(t+e*Math.cos(g))*Math.cos(m),u.y=(t+e*Math.cos(g))*Math.sin(m),u.z=e*Math.sin(g),a.push(u.x,u.y,u.z),c.x=t*Math.cos(m),c.y=t*Math.sin(m),d.subVectors(u,c).normalize(),o.push(d.x,d.y,d.z),h.push(p/s),h.push(f/i)}for(let f=1;f<=i;f++)for(let p=1;p<=s;p++){const m=(s+1)*f+p-1,g=(s+1)*(f-1)+p-1,x=(s+1)*(f-1)+p,y=(s+1)*f+p;r.push(m,g,y),r.push(g,x,y)}this.setIndex(r),this.setAttribute("position",new O(a,3)),this.setAttribute("normal",new O(o,3)),this.setAttribute("uv",new O(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new _a(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class Ma extends Z{constructor(t=1,e=.4,i=64,s=8,n=2,r=3){super(),this.type="TorusKnotGeometry",this.parameters={radius:t,tube:e,tubularSegments:i,radialSegments:s,p:n,q:r},i=Math.floor(i),s=Math.floor(s);const a=[],o=[],h=[],c=[],u=new w,d=new w,f=new w,p=new w,m=new w,g=new w,x=new w;for(let b=0;b<=i;++b){const v=b/i*n*Math.PI*2;y(v,n,r,t,f),y(v+.01,n,r,t,p),g.subVectors(p,f),x.addVectors(p,f),m.crossVectors(g,x),x.crossVectors(m,g),m.normalize(),x.normalize();for(let _=0;_<=s;++_){const M=_/s*Math.PI*2,A=-e*Math.cos(M),S=e*Math.sin(M);u.x=f.x+(A*x.x+S*m.x),u.y=f.y+(A*x.y+S*m.y),u.z=f.z+(A*x.z+S*m.z),o.push(u.x,u.y,u.z),d.subVectors(u,f).normalize(),h.push(d.x,d.y,d.z),c.push(b/i),c.push(_/s)}}for(let b=1;b<=i;b++)for(let v=1;v<=s;v++){const _=(s+1)*(b-1)+(v-1),M=(s+1)*b+(v-1),A=(s+1)*b+v,S=(s+1)*(b-1)+v;a.push(_,M,S),a.push(M,A,S)}this.setIndex(a),this.setAttribute("position",new O(o,3)),this.setAttribute("normal",new O(h,3)),this.setAttribute("uv",new O(c,2));function y(b,v,_,M,A){const S=Math.cos(b),C=Math.sin(b),z=_/v*b,k=Math.cos(z);A.x=M*(2+k)*.5*S,A.y=M*(2+k)*C*.5,A.z=M*Math.sin(z)*.5}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Ma(t.radius,t.tube,t.tubularSegments,t.radialSegments,t.p,t.q)}}class Sa extends Z{constructor(t=new Gh(new w(-1,-1,0),new w(-1,1,0),new w(1,1,0)),e=64,i=1,s=8,n=!1){super(),this.type="TubeGeometry",this.parameters={path:t,tubularSegments:e,radius:i,radialSegments:s,closed:n};const r=t.computeFrenetFrames(e,n);this.tangents=r.tangents,this.normals=r.normals,this.binormals=r.binormals;const a=new w,o=new w,h=new B;let c=new w;const u=[],d=[],f=[],p=[];m(),this.setIndex(p),this.setAttribute("position",new O(u,3)),this.setAttribute("normal",new O(d,3)),this.setAttribute("uv",new O(f,2));function m(){for(let b=0;b<e;b++)g(b);g(n===!1?e:0),y(),x()}function g(b){c=t.getPointAt(b/e,c);const v=r.normals[b],_=r.binormals[b];for(let M=0;M<=s;M++){const A=M/s*Math.PI*2,S=Math.sin(A),C=-Math.cos(A);o.x=C*v.x+S*_.x,o.y=C*v.y+S*_.y,o.z=C*v.z+S*_.z,o.normalize(),d.push(o.x,o.y,o.z),a.x=c.x+i*o.x,a.y=c.y+i*o.y,a.z=c.z+i*o.z,u.push(a.x,a.y,a.z)}}function x(){for(let b=1;b<=e;b++)for(let v=1;v<=s;v++){const _=(s+1)*(b-1)+(v-1),M=(s+1)*b+(v-1),A=(s+1)*b+v,S=(s+1)*(b-1)+v;p.push(_,M,S),p.push(M,A,S)}}function y(){for(let b=0;b<=e;b++)for(let v=0;v<=s;v++)h.x=b/e,h.y=v/s,f.push(h.x,h.y)}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return t.path=this.parameters.path.toJSON(),t}static fromJSON(t){return new Sa(new Bn[t.path.type]().fromJSON(t.path),t.tubularSegments,t.radius,t.radialSegments,t.closed)}}class ud extends Z{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},t!==null){const e=[],i=new Set,s=new w,n=new w;if(t.index!==null){const r=t.attributes.position,a=t.index;let o=t.groups;o.length===0&&(o=[{start:0,count:a.count,materialIndex:0}]);for(let h=0,c=o.length;h<c;++h){const u=o[h],d=u.start,f=u.count;for(let p=d,m=d+f;p<m;p+=3)for(let g=0;g<3;g++){const x=a.getX(p+g),y=a.getX(p+(g+1)%3);s.fromBufferAttribute(r,x),n.fromBufferAttribute(r,y),Fo(s,n,i)===!0&&(e.push(s.x,s.y,s.z),e.push(n.x,n.y,n.z))}}}else{const r=t.attributes.position;for(let a=0,o=r.count/3;a<o;a++)for(let h=0;h<3;h++){const c=3*a+h,u=3*a+(h+1)%3;s.fromBufferAttribute(r,c),n.fromBufferAttribute(r,u),Fo(s,n,i)===!0&&(e.push(s.x,s.y,s.z),e.push(n.x,n.y,n.z))}}this.setAttribute("position",new O(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function Fo(l,t,e){const i=`${l.x},${l.y},${l.z}-${t.x},${t.y},${t.z}`,s=`${t.x},${t.y},${t.z}-${l.x},${l.y},${l.z}`;return e.has(i)===!0||e.has(s)===!0?!1:(e.add(i),e.add(s),!0)}var Po=Object.freeze({__proto__:null,BoxGeometry:On,CapsuleGeometry:da,CircleGeometry:fa,ConeGeometry:pa,CylinderGeometry:Ts,DodecahedronGeometry:ma,EdgesGeometry:Hu,ExtrudeGeometry:ga,IcosahedronGeometry:ya,LatheGeometry:Dn,OctahedronGeometry:Vn,PlaneGeometry:xa,PolyhedronGeometry:ai,RingGeometry:ba,ShapeGeometry:va,SphereGeometry:Is,TetrahedronGeometry:wa,TorusGeometry:_a,TorusKnotGeometry:Ma,TubeGeometry:Sa,WireframeGeometry:ud});class dd extends Rt{constructor(t){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new V(0),this.transparent=!0,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.fog=t.fog,this}}class fd extends ia{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Aa extends Rt{constructor(t){super(),this.isMeshStandardMaterial=!0,this.type="MeshStandardMaterial",this.defines={STANDARD:""},this.color=new V(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new V(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fe,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.envMapIntensity=t.envMapIntensity,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class pd extends Aa{constructor(t){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new B(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return H(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(e){this.ior=(1+.4*e)/(1-.4*e)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new V(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=1/0,this.attenuationColor=new V(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new V(1,1,1),this.specularColorMap=null,this._anisotropy=0,this._clearcoat=0,this._dispersion=0,this._iridescence=0,this._sheen=0,this._transmission=0,this.setValues(t)}get anisotropy(){return this._anisotropy}set anisotropy(t){this._anisotropy>0!=t>0&&this.version++,this._anisotropy=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get iridescence(){return this._iridescence}set iridescence(t){this._iridescence>0!=t>0&&this.version++,this._iridescence=t}get dispersion(){return this._dispersion}set dispersion(t){this._dispersion>0!=t>0&&this.version++,this._dispersion=t}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=t.anisotropy,this.anisotropyRotation=t.anisotropyRotation,this.anisotropyMap=t.anisotropyMap,this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.dispersion=t.dispersion,this.ior=t.ior,this.iridescence=t.iridescence,this.iridescenceMap=t.iridescenceMap,this.iridescenceIOR=t.iridescenceIOR,this.iridescenceThicknessRange=[...t.iridescenceThicknessRange],this.iridescenceThicknessMap=t.iridescenceThicknessMap,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}class md extends Rt{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new V(16777215),this.specular=new V(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new V(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fe,this.combine=Jr,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class gd extends Rt{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new V(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new V(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}class yd extends Rt{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}class xd extends Rt{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new V(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new V(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fe,this.combine=Jr,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this.fog=t.fog,this}}class bd extends Rt{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=Ic,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class vd extends Rt{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}class wd extends Rt{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new V(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ni,this.normalScale=new B(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this.fog=t.fog,this}}class _d extends Gt{constructor(t){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}function ei(l,t,e){return!l||!e&&l.constructor===t?l:typeof t.BYTES_PER_ELEMENT=="number"?new t(l):Array.prototype.slice.call(l)}function Yh(l){return ArrayBuffer.isView(l)&&!(l instanceof DataView)}function Jh(l){function t(s,n){return l[s]-l[n]}const e=l.length,i=new Array(e);for(let s=0;s!==e;++s)i[s]=s;return i.sort(t),i}function Vr(l,t,e){const i=l.length,s=new l.constructor(i);for(let n=0,r=0;r!==i;++n){const a=e[n]*t;for(let o=0;o!==t;++o)s[r++]=l[a+o]}return s}function Ta(l,t,e,i){let s=1,n=l[0];for(;n!==void 0&&n[i]===void 0;)n=l[s++];if(n===void 0)return;let r=n[i];if(r!==void 0)if(Array.isArray(r))do r=n[i],r!==void 0&&(t.push(n.time),e.push.apply(e,r)),n=l[s++];while(n!==void 0);else if(r.toArray!==void 0)do r=n[i],r!==void 0&&(t.push(n.time),r.toArray(e,e.length)),n=l[s++];while(n!==void 0);else do r=n[i],r!==void 0&&(t.push(n.time),e.push(r)),n=l[s++];while(n!==void 0)}function Md(l,t,e,i,s=30){const n=l.clone();n.name=t;const r=[];for(let o=0;o<n.tracks.length;++o){const h=n.tracks[o],c=h.getValueSize(),u=[],d=[];for(let f=0;f<h.times.length;++f){const p=h.times[f]*s;if(!(p<e||p>=i)){u.push(h.times[f]);for(let m=0;m<c;++m)d.push(h.values[f*c+m])}}u.length!==0&&(h.times=ei(u,h.times.constructor),h.values=ei(d,h.values.constructor),r.push(h))}n.tracks=r;let a=1/0;for(let o=0;o<n.tracks.length;++o)a>n.tracks[o].times[0]&&(a=n.tracks[o].times[0]);for(let o=0;o<n.tracks.length;++o)n.tracks[o].shift(-1*a);return n.resetDuration(),n}function Sd(l,t=0,e=l,i=30){i<=0&&(i=30);const s=e.tracks.length,n=t/i;for(let r=0;r<s;++r){const a=e.tracks[r],o=a.ValueTypeName;if(o==="bool"||o==="string")continue;const h=l.tracks.find(function(x){return x.name===a.name&&x.ValueTypeName===o});if(h===void 0)continue;let c=0;const u=a.getValueSize();a.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(c=u/3);let d=0;const f=h.getValueSize();h.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(d=f/3);const p=a.times.length-1;let m;if(n<=a.times[0]){const x=c,y=u-c;m=a.values.slice(x,y)}else if(n>=a.times[p]){const x=p*u+c,y=x+u-c;m=a.values.slice(x,y)}else{const x=a.createInterpolant(),y=c,b=u-c;x.evaluate(n),m=x.resultBuffer.slice(y,b)}o==="quaternion"&&new Zt().fromArray(m).normalize().conjugate().toArray(m);const g=h.times.length;for(let x=0;x<g;++x){const y=x*f+d;if(o==="quaternion")Zt.multiplyQuaternionsFlat(h.values,y,m,0,h.values,y);else{const b=f-d*2;for(let v=0;v<b;++v)h.values[y+v]-=m[v]}}}return l.blendMode=Ih,l}const Gg={convertArray:ei,isTypedArray:Yh,getKeyframeOrder:Jh,sortedArray:Vr,flattenJSON:Ta,subclip:Md,makeClipAdditive:Sd};class Gn{constructor(t,e,i,s){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=s!==void 0?s:new e.constructor(i),this.sampleValues=e,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let i=this._cachedIndex,s=e[i],n=e[i-1];t:{e:{let r;i:{s:if(!(t<s)){for(let a=i+2;;){if(s===void 0){if(t<n)break s;return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}if(i===a)break;if(n=s,s=e[++i],t<s)break e}r=e.length;break i}if(!(t>=n)){const a=e[1];t<a&&(i=2,n=a);for(let o=i-2;;){if(n===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(i===o)break;if(s=n,n=e[--i-1],t>=n)break e}r=i,i=0;break i}break t}for(;i<r;){const a=i+r>>>1;t<e[a]?r=a:i=a+1}if(s=e[i],n=e[i-1],n===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(s===void 0)return i=e.length,this._cachedIndex=i,this.copySampleValue_(i-1)}this._cachedIndex=i,this.intervalChanged_(i,n,s)}return this.interpolate_(i,n,t,s)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,i=this.sampleValues,s=this.valueSize,n=t*s;for(let r=0;r!==s;++r)e[r]=i[n+r];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}class Ad extends Gn{constructor(t,e,i,s){super(t,e,i,s),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:zi,endingEnd:zi}}intervalChanged_(t,e,i){const s=this.parameterPositions;let n=t-2,r=t+1,a=s[n],o=s[r];if(a===void 0)switch(this.getSettings_().endingStart){case Bi:n=t,a=2*e-i;break;case Sn:n=s.length-2,a=e+s[n]-s[n+1];break;default:n=t,a=i}if(o===void 0)switch(this.getSettings_().endingEnd){case Bi:r=t,o=2*i-e;break;case Sn:r=1,o=i+s[1]-s[0];break;default:r=t-1,o=e}const h=(i-e)*.5,c=this.valueSize;this._weightPrev=h/(e-a),this._weightNext=h/(o-i),this._offsetPrev=n*c,this._offsetNext=r*c}interpolate_(t,e,i,s){const n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,h=o-a,c=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(i-e)/(s-e),m=p*p,g=m*p,x=-d*g+2*d*m-d*p,y=(1+d)*g+(-1.5-2*d)*m+(-.5+d)*p+1,b=(-1-f)*g+(1.5+f)*m+.5*p,v=f*g-f*m;for(let _=0;_!==a;++_)n[_]=x*r[c+_]+y*r[h+_]+b*r[o+_]+v*r[u+_];return n}}class Zh extends Gn{constructor(t,e,i,s){super(t,e,i,s)}interpolate_(t,e,i,s){const n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,h=o-a,c=(i-e)/(s-e),u=1-c;for(let d=0;d!==a;++d)n[d]=r[h+d]*u+r[o+d]*c;return n}}class Td extends Gn{constructor(t,e,i,s){super(t,e,i,s)}interpolate_(t){return this.copySampleValue_(t-1)}}class ge{constructor(t,e,i,s){if(t===void 0)throw new Error("THREE.KeyframeTrack: track name is undefined");if(e===void 0||e.length===0)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=ei(e,this.TimeBufferType),this.values=ei(i,this.ValueBufferType),this.setInterpolation(s||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let i;if(e.toJSON!==this.toJSON)i=e.toJSON(t);else{i={name:t.name,times:ei(t.times,Array),values:ei(t.values,Array)};const s=t.getInterpolation();s!==t.DefaultInterpolation&&(i.interpolation=s)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new Td(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new Zh(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Ad(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case Mn:e=this.InterpolantFactoryMethodDiscrete;break;case Or:e=this.InterpolantFactoryMethodLinear;break;case Xn:e=this.InterpolantFactoryMethodSmooth;break}if(e===void 0){const i="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===void 0)if(t!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw new Error(i);return console.warn("THREE.KeyframeTrack:",i),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Mn;case this.InterpolantFactoryMethodLinear:return Or;case this.InterpolantFactoryMethodSmooth:return Xn}}getValueSize(){return this.values.length/this.times.length}shift(t){if(t!==0){const e=this.times;for(let i=0,s=e.length;i!==s;++i)e[i]+=t}return this}scale(t){if(t!==1){const e=this.times;for(let i=0,s=e.length;i!==s;++i)e[i]*=t}return this}trim(t,e){const i=this.times,s=i.length;let n=0,r=s-1;for(;n!==s&&i[n]<t;)++n;for(;r!==-1&&i[r]>e;)--r;if(++r,n!==0||r!==s){n>=r&&(r=Math.max(r,1),n=r-1);const a=this.getValueSize();this.times=i.slice(n,r),this.values=this.values.slice(n*a,r*a)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);const i=this.times,s=this.values,n=i.length;n===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let r=null;for(let a=0;a!==n;a++){const o=i[a];if(typeof o=="number"&&isNaN(o)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,a,o),t=!1;break}if(r!==null&&r>o){console.error("THREE.KeyframeTrack: Out of order keys.",this,a,o,r),t=!1;break}r=o}if(s!==void 0&&Yh(s))for(let a=0,o=s.length;a!==o;++a){const h=s[a];if(isNaN(h)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,a,h),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),i=this.getValueSize(),s=this.getInterpolation()===Xn,n=t.length-1;let r=1;for(let a=1;a<n;++a){let o=!1;const h=t[a],c=t[a+1];if(h!==c&&(a!==1||h!==t[0]))if(s)o=!0;else{const u=a*i,d=u-i,f=u+i;for(let p=0;p!==i;++p){const m=e[u+p];if(m!==e[d+p]||m!==e[f+p]){o=!0;break}}}if(o){if(a!==r){t[r]=t[a];const u=a*i,d=r*i;for(let f=0;f!==i;++f)e[d+f]=e[u+f]}++r}}if(n>0){t[r]=t[n];for(let a=n*i,o=r*i,h=0;h!==i;++h)e[o+h]=e[a+h];++r}return r!==t.length?(this.times=t.slice(0,r),this.values=e.slice(0,r*i)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),i=this.constructor,s=new i(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}ge.prototype.TimeBufferType=Float32Array;ge.prototype.ValueBufferType=Float32Array;ge.prototype.DefaultInterpolation=Or;class Ui extends ge{constructor(t,e,i){super(t,e,i)}}Ui.prototype.ValueTypeName="bool";Ui.prototype.ValueBufferType=Array;Ui.prototype.DefaultInterpolation=Mn;Ui.prototype.InterpolantFactoryMethodLinear=void 0;Ui.prototype.InterpolantFactoryMethodSmooth=void 0;class Kh extends ge{}Kh.prototype.ValueTypeName="color";class Pn extends ge{}Pn.prototype.ValueTypeName="number";class Id extends Gn{constructor(t,e,i,s){super(t,e,i,s)}interpolate_(t,e,i,s){const n=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=(i-e)/(s-e);let h=t*a;for(let c=h+a;h!==c;h+=4)Zt.slerpFlat(n,0,r,h-a,r,h,o);return n}}class Wn extends ge{InterpolantFactoryMethodLinear(t){return new Id(this.times,this.values,this.getValueSize(),t)}}Wn.prototype.ValueTypeName="quaternion";Wn.prototype.InterpolantFactoryMethodSmooth=void 0;class Vi extends ge{constructor(t,e,i){super(t,e,i)}}Vi.prototype.ValueTypeName="string";Vi.prototype.ValueBufferType=Array;Vi.prototype.DefaultInterpolation=Mn;Vi.prototype.InterpolantFactoryMethodLinear=void 0;Vi.prototype.InterpolantFactoryMethodSmooth=void 0;class kn extends ge{}kn.prototype.ValueTypeName="vector";class En{constructor(t="",e=-1,i=[],s=Qr){this.name=t,this.tracks=i,this.duration=e,this.blendMode=s,this.uuid=Jt(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],i=t.tracks,s=1/(t.fps||1);for(let r=0,a=i.length;r!==a;++r)e.push(zd(i[r]).scale(s));const n=new this(t.name,t.duration,e,t.blendMode);return n.uuid=t.uuid,n}static toJSON(t){const e=[],i=t.tracks,s={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let n=0,r=i.length;n!==r;++n)e.push(ge.toJSON(i[n]));return s}static CreateFromMorphTargetSequence(t,e,i,s){const n=e.length,r=[];for(let a=0;a<n;a++){let o=[],h=[];o.push((a+n-1)%n,a,(a+1)%n),h.push(0,1,0);const c=Jh(o);o=Vr(o,1,c),h=Vr(h,1,c),!s&&o[0]===0&&(o.push(n),h.push(h[0])),r.push(new Pn(".morphTargetInfluences["+e[a].name+"]",o,h).scale(1/i))}return new this(t,-1,r)}static findByName(t,e){let i=t;if(!Array.isArray(t)){const s=t;i=s.geometry&&s.geometry.animations||s.animations}for(let s=0;s<i.length;s++)if(i[s].name===e)return i[s];return null}static CreateClipsFromMorphTargetSequences(t,e,i){const s={},n=/^([\w-]*?)([\d]+)$/;for(let a=0,o=t.length;a<o;a++){const h=t[a],c=h.name.match(n);if(c&&c.length>1){const u=c[1];let d=s[u];d||(s[u]=d=[]),d.push(h)}}const r=[];for(const a in s)r.push(this.CreateFromMorphTargetSequence(a,s[a],e,i));return r}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const i=function(u,d,f,p,m){if(f.length!==0){const g=[],x=[];Ta(f,g,x,p),g.length!==0&&m.push(new u(d,g,x))}},s=[],n=t.name||"default",r=t.fps||30,a=t.blendMode;let o=t.length||-1;const h=t.hierarchy||[];for(let u=0;u<h.length;u++){const d=h[u].keys;if(!(!d||d.length===0))if(d[0].morphTargets){const f={};let p;for(p=0;p<d.length;p++)if(d[p].morphTargets)for(let m=0;m<d[p].morphTargets.length;m++)f[d[p].morphTargets[m]]=-1;for(const m in f){const g=[],x=[];for(let y=0;y!==d[p].morphTargets.length;++y){const b=d[p];g.push(b.time),x.push(b.morphTarget===m?1:0)}s.push(new Pn(".morphTargetInfluence["+m+"]",g,x))}o=f.length*r}else{const f=".bones["+e[u].name+"]";i(kn,f+".position",d,"pos",s),i(Wn,f+".quaternion",d,"rot",s),i(kn,f+".scale",d,"scl",s)}}return s.length===0?null:new this(n,o,s,a)}resetDuration(){const t=this.tracks;let e=0;for(let i=0,s=t.length;i!==s;++i){const n=this.tracks[i];e=Math.max(e,n.times[n.times.length-1])}return this.duration=e,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let e=0;e<this.tracks.length;e++)t.push(this.tracks[e].clone());return new this.constructor(this.name,this.duration,t,this.blendMode)}toJSON(){return this.constructor.toJSON(this)}}function Cd(l){switch(l.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Pn;case"vector":case"vector2":case"vector3":case"vector4":return kn;case"color":return Kh;case"quaternion":return Wn;case"bool":case"boolean":return Ui;case"string":return Vi}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+l)}function zd(l){if(l.type===void 0)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const t=Cd(l.type);if(l.times===void 0){const e=[],i=[];Ta(l.keys,e,i,"value"),l.times=e,l.values=i}return t.parse!==void 0?t.parse(l):new t(l.name,l.times,l.values,l.interpolation)}const Ve={enabled:!1,files:{},add:function(l,t){this.enabled!==!1&&(this.files[l]=t)},get:function(l){if(this.enabled!==!1)return this.files[l]},remove:function(l){delete this.files[l]},clear:function(){this.files={}}};class jh{constructor(t,e,i){const s=this;let n=!1,r=0,a=0,o;const h=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=i,this.itemStart=function(c){a++,n===!1&&s.onStart!==void 0&&s.onStart(c,r,a),n=!0},this.itemEnd=function(c){r++,s.onProgress!==void 0&&s.onProgress(c,r,a),r===a&&(n=!1,s.onLoad!==void 0&&s.onLoad())},this.itemError=function(c){s.onError!==void 0&&s.onError(c)},this.resolveURL=function(c){return o?o(c):c},this.setURLModifier=function(c){return o=c,this},this.addHandler=function(c,u){return h.push(c,u),this},this.removeHandler=function(c){const u=h.indexOf(c);return u!==-1&&h.splice(u,2),this},this.getHandler=function(c){for(let u=0,d=h.length;u<d;u+=2){const f=h[u],p=h[u+1];if(f.global&&(f.lastIndex=0),f.test(c))return p}return null}}}const Bd=new jh;class Kt{constructor(t){this.manager=t!==void 0?t:Bd,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const i=this;return new Promise(function(s,n){i.load(t,s,e,n)})}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}}Kt.DEFAULT_MATERIAL_NAME="__DEFAULT";const Se={};class Fd extends Error{constructor(t,e){super(t),this.response=e}}class Ge extends Kt{constructor(t){super(t)}load(t,e,i,s){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const n=Ve.get(t);if(n!==void 0)return this.manager.itemStart(t),setTimeout(()=>{e&&e(n),this.manager.itemEnd(t)},0),n;if(Se[t]!==void 0){Se[t].push({onLoad:e,onProgress:i,onError:s});return}Se[t]=[],Se[t].push({onLoad:e,onProgress:i,onError:s});const r=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),a=this.mimeType,o=this.responseType;fetch(r).then(h=>{if(h.status===200||h.status===0){if(h.status===0&&console.warn("THREE.FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||h.body===void 0||h.body.getReader===void 0)return h;const c=Se[t],u=h.body.getReader(),d=h.headers.get("X-File-Size")||h.headers.get("Content-Length"),f=d?parseInt(d):0,p=f!==0;let m=0;const g=new ReadableStream({start(x){y();function y(){u.read().then(({done:b,value:v})=>{if(b)x.close();else{m+=v.byteLength;const _=new ProgressEvent("progress",{lengthComputable:p,loaded:m,total:f});for(let M=0,A=c.length;M<A;M++){const S=c[M];S.onProgress&&S.onProgress(_)}x.enqueue(v),y()}},b=>{x.error(b)})}}});return new Response(g)}else throw new Fd(`fetch for "${h.url}" responded with ${h.status}: ${h.statusText}`,h)}).then(h=>{switch(o){case"arraybuffer":return h.arrayBuffer();case"blob":return h.blob();case"document":return h.text().then(c=>new DOMParser().parseFromString(c,a));case"json":return h.json();default:if(a===void 0)return h.text();{const u=/charset="?([^;"\s]*)"?/i.exec(a),d=u&&u[1]?u[1].toLowerCase():void 0,f=new TextDecoder(d);return h.arrayBuffer().then(p=>f.decode(p))}}}).then(h=>{Ve.add(t,h);const c=Se[t];delete Se[t];for(let u=0,d=c.length;u<d;u++){const f=c[u];f.onLoad&&f.onLoad(h)}}).catch(h=>{const c=Se[t];if(c===void 0)throw this.manager.itemError(t),h;delete Se[t];for(let u=0,d=c.length;u<d;u++){const f=c[u];f.onError&&f.onError(h)}this.manager.itemError(t)}).finally(()=>{this.manager.itemEnd(t)}),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class Wg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=new Ge(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(a){try{e(n.parse(JSON.parse(a)))}catch(o){s?s(o):console.error(o),n.manager.itemError(t)}},i,s)}parse(t){const e=[];for(let i=0;i<t.length;i++){const s=En.parse(t[i]);e.push(s)}return e}}class Hg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=[],a=new la,o=new Ge(this.manager);o.setPath(this.path),o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setWithCredentials(n.withCredentials);let h=0;function c(u){o.load(t[u],function(d){const f=n.parse(d,!0);r[u]={width:f.width,height:f.height,format:f.format,mipmaps:f.mipmaps},h+=1,h===6&&(f.mipmapCount===1&&(a.minFilter=ee),a.image=r,a.format=f.format,a.needsUpdate=!0,e&&e(a))},i,s)}if(Array.isArray(t))for(let u=0,d=t.length;u<d;++u)c(u);else o.load(t,function(u){const d=n.parse(u,!0);if(d.isCubemap){const f=d.mipmaps.length/d.mipmapCount;for(let p=0;p<f;p++){r[p]={mipmaps:[]};for(let m=0;m<d.mipmapCount;m++)r[p].mipmaps.push(d.mipmaps[p*d.mipmapCount+m]),r[p].format=d.format,r[p].width=d.width,r[p].height=d.height}a.image=r}else a.image.width=d.width,a.image.height=d.height,a.mipmaps=d.mipmaps;d.mipmapCount===1&&(a.minFilter=ee),a.format=d.format,a.needsUpdate=!0,e&&e(a)},i,s);return a}}class Rn extends Kt{constructor(t){super(t)}load(t,e,i,s){this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const n=this,r=Ve.get(t);if(r!==void 0)return n.manager.itemStart(t),setTimeout(function(){e&&e(r),n.manager.itemEnd(t)},0),r;const a=In("img");function o(){c(),Ve.add(t,this),e&&e(this),n.manager.itemEnd(t)}function h(u){c(),s&&s(u),n.manager.itemError(t),n.manager.itemEnd(t)}function c(){a.removeEventListener("load",o,!1),a.removeEventListener("error",h,!1)}return a.addEventListener("load",o,!1),a.addEventListener("error",h,!1),t.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),n.manager.itemStart(t),a.src=t,a}}class qg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=new na;n.colorSpace=$t;const r=new Rn(this.manager);r.setCrossOrigin(this.crossOrigin),r.setPath(this.path);let a=0;function o(h){r.load(t[h],function(c){n.images[h]=c,a++,a===6&&(n.needsUpdate=!0,e&&e(n))},void 0,s)}for(let h=0;h<t.length;++h)o(h);return n}}class Xg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=new Ce,a=new Ge(this.manager);return a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setPath(this.path),a.setWithCredentials(n.withCredentials),a.load(t,function(o){let h;try{h=n.parse(o)}catch(c){if(s!==void 0)s(c);else{console.error(c);return}}h.image!==void 0?r.image=h.image:h.data!==void 0&&(r.image.width=h.width,r.image.height=h.height,r.image.data=h.data),r.wrapS=h.wrapS!==void 0?h.wrapS:ue,r.wrapT=h.wrapT!==void 0?h.wrapT:ue,r.magFilter=h.magFilter!==void 0?h.magFilter:ee,r.minFilter=h.minFilter!==void 0?h.minFilter:ee,r.anisotropy=h.anisotropy!==void 0?h.anisotropy:1,h.colorSpace!==void 0&&(r.colorSpace=h.colorSpace),h.flipY!==void 0&&(r.flipY=h.flipY),h.format!==void 0&&(r.format=h.format),h.type!==void 0&&(r.type=h.type),h.mipmaps!==void 0&&(r.mipmaps=h.mipmaps,r.minFilter=Ln),h.mipmapCount===1&&(r.minFilter=ee),h.generateMipmaps!==void 0&&(r.generateMipmaps=h.generateMipmaps),r.needsUpdate=!0,e&&e(r,h)},i,s),r}}class Yg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=new gt,r=new Rn(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(t,function(a){n.image=a,n.needsUpdate=!0,e!==void 0&&e(n)},i,s),n}}class oi extends tt{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new V(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,this.groundColor!==void 0&&(e.object.groundColor=this.groundColor.getHex()),this.distance!==void 0&&(e.object.distance=this.distance),this.angle!==void 0&&(e.object.angle=this.angle),this.decay!==void 0&&(e.object.decay=this.decay),this.penumbra!==void 0&&(e.object.penumbra=this.penumbra),this.shadow!==void 0&&(e.object.shadow=this.shadow.toJSON()),this.target!==void 0&&(e.object.target=this.target.uuid),e}}class Pd extends oi{constructor(t,e,i){super(t,i),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.groundColor=new V(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const Ar=new Y,ko=new w,Eo=new w;class Ia{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new B(512,512),this.map=null,this.mapPass=null,this.matrix=new Y,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Rh,this._frameExtents=new B(1,1),this._viewportCount=1,this._viewports=[new St(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;ko.setFromMatrixPosition(t.matrixWorld),e.position.copy(ko),Eo.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Eo),e.updateMatrixWorld(),Ar.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Ar),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(Ar)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return new this.constructor().copy(this)}toJSON(){const t={};return this.intensity!==1&&(t.intensity=this.intensity),this.bias!==0&&(t.bias=this.bias),this.normalBias!==0&&(t.normalBias=this.normalBias),this.radius!==1&&(t.radius=this.radius),(this.mapSize.x!==512||this.mapSize.y!==512)&&(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class kd extends Ia{constructor(){super(new te(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,i=xs*2*t.angle*this.focus,s=this.mapSize.width/this.mapSize.height,n=t.distance||e.far;(i!==e.fov||s!==e.aspect||n!==e.far)&&(e.fov=i,e.aspect=s,e.far=n,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class Ed extends oi{constructor(t,e,i=0,s=Math.PI/3,n=0,r=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.target=new tt,this.distance=i,this.angle=s,this.penumbra=n,this.decay=r,this.map=null,this.shadow=new kd}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}const Ro=new Y,es=new w,Tr=new w;class Rd extends Ia{constructor(){super(new te(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new B(4,2),this._viewportCount=6,this._viewports=[new St(2,1,1,1),new St(0,1,1,1),new St(3,1,1,1),new St(1,1,1,1),new St(3,0,1,1),new St(1,0,1,1)],this._cubeDirections=[new w(1,0,0),new w(-1,0,0),new w(0,0,1),new w(0,0,-1),new w(0,1,0),new w(0,-1,0)],this._cubeUps=[new w(0,1,0),new w(0,1,0),new w(0,1,0),new w(0,1,0),new w(0,0,1),new w(0,0,-1)]}updateMatrices(t,e=0){const i=this.camera,s=this.matrix,n=t.distance||i.far;n!==i.far&&(i.far=n,i.updateProjectionMatrix()),es.setFromMatrixPosition(t.matrixWorld),i.position.copy(es),Tr.copy(i.position),Tr.add(this._cubeDirections[e]),i.up.copy(this._cubeUps[e]),i.lookAt(Tr),i.updateMatrixWorld(),s.makeTranslation(-es.x,-es.y,-es.z),Ro.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Ro)}}class Ld extends oi{constructor(t,e,i=0,s=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=i,this.decay=s,this.shadow=new Rd}get power(){return this.intensity*4*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}}class Qh extends sa{constructor(t=-1,e=1,i=1,s=-1,n=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=s,this.near=n,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=t.view===null?null:Object.assign({},t.view),this}setViewOffset(t,e,i,s,n,r){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let n=i-t,r=i+t,a=s+e,o=s-e;if(this.view!==null&&this.view.enabled){const h=(this.right-this.left)/this.view.fullWidth/this.zoom,c=(this.top-this.bottom)/this.view.fullHeight/this.zoom;n+=h*this.view.offsetX,r=n+h*this.view.width,a-=c*this.view.offsetY,o=a-c*this.view.height}this.projectionMatrix.makeOrthographic(n,r,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,this.view!==null&&(e.object.view=Object.assign({},this.view)),e}}class Od extends Ia{constructor(){super(new Qh(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class Nd extends oi{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(tt.DEFAULT_UP),this.updateMatrix(),this.target=new tt,this.shadow=new Od}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Dd extends oi{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class Ud extends oi{constructor(t,e,i=10,s=10){super(t,e),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=i,this.height=s}get power(){return this.intensity*this.width*this.height*Math.PI}set power(t){this.intensity=t/(this.width*this.height*Math.PI)}copy(t){return super.copy(t),this.width=t.width,this.height=t.height,this}toJSON(t){const e=super.toJSON(t);return e.object.width=this.width,e.object.height=this.height,e}}class Vd{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new w)}set(t){for(let e=0;e<9;e++)this.coefficients[e].copy(t[e]);return this}zero(){for(let t=0;t<9;t++)this.coefficients[t].set(0,0,0);return this}getAt(t,e){const i=t.x,s=t.y,n=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.282095),e.addScaledVector(r[1],.488603*s),e.addScaledVector(r[2],.488603*n),e.addScaledVector(r[3],.488603*i),e.addScaledVector(r[4],1.092548*(i*s)),e.addScaledVector(r[5],1.092548*(s*n)),e.addScaledVector(r[6],.315392*(3*n*n-1)),e.addScaledVector(r[7],1.092548*(i*n)),e.addScaledVector(r[8],.546274*(i*i-s*s)),e}getIrradianceAt(t,e){const i=t.x,s=t.y,n=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.886227),e.addScaledVector(r[1],2*.511664*s),e.addScaledVector(r[2],2*.511664*n),e.addScaledVector(r[3],2*.511664*i),e.addScaledVector(r[4],2*.429043*i*s),e.addScaledVector(r[5],2*.429043*s*n),e.addScaledVector(r[6],.743125*n*n-.247708),e.addScaledVector(r[7],2*.429043*i*n),e.addScaledVector(r[8],.429043*(i*i-s*s)),e}add(t){for(let e=0;e<9;e++)this.coefficients[e].add(t.coefficients[e]);return this}addScaledSH(t,e){for(let i=0;i<9;i++)this.coefficients[i].addScaledVector(t.coefficients[i],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let i=0;i<9;i++)this.coefficients[i].lerp(t.coefficients[i],e);return this}equals(t){for(let e=0;e<9;e++)if(!this.coefficients[e].equals(t.coefficients[e]))return!1;return!0}copy(t){return this.set(t.coefficients)}clone(){return new this.constructor().copy(this)}fromArray(t,e=0){const i=this.coefficients;for(let s=0;s<9;s++)i[s].fromArray(t,e+s*3);return this}toArray(t=[],e=0){const i=this.coefficients;for(let s=0;s<9;s++)i[s].toArray(t,e+s*3);return t}static getBasisAt(t,e){const i=t.x,s=t.y,n=t.z;e[0]=.282095,e[1]=.488603*s,e[2]=.488603*n,e[3]=.488603*i,e[4]=1.092548*i*s,e[5]=1.092548*s*n,e[6]=.315392*(3*n*n-1),e[7]=1.092548*i*n,e[8]=.546274*(i*i-s*s)}}class Gd extends oi{constructor(t=new Vd,e=1){super(void 0,e),this.isLightProbe=!0,this.sh=t}copy(t){return super.copy(t),this.sh.copy(t.sh),this}fromJSON(t){return this.intensity=t.intensity,this.sh.fromArray(t.sh),this}toJSON(t){const e=super.toJSON(t);return e.object.sh=this.sh.toArray(),e}}class Ca extends Kt{constructor(t){super(t),this.textures={}}load(t,e,i,s){const n=this,r=new Ge(n.manager);r.setPath(n.path),r.setRequestHeader(n.requestHeader),r.setWithCredentials(n.withCredentials),r.load(t,function(a){try{e(n.parse(JSON.parse(a)))}catch(o){s?s(o):console.error(o),n.manager.itemError(t)}},i,s)}parse(t){const e=this.textures;function i(n){return e[n]===void 0&&console.warn("THREE.MaterialLoader: Undefined texture",n),e[n]}const s=this.createMaterialFromType(t.type);if(t.uuid!==void 0&&(s.uuid=t.uuid),t.name!==void 0&&(s.name=t.name),t.color!==void 0&&s.color!==void 0&&s.color.setHex(t.color),t.roughness!==void 0&&(s.roughness=t.roughness),t.metalness!==void 0&&(s.metalness=t.metalness),t.sheen!==void 0&&(s.sheen=t.sheen),t.sheenColor!==void 0&&(s.sheenColor=new V().setHex(t.sheenColor)),t.sheenRoughness!==void 0&&(s.sheenRoughness=t.sheenRoughness),t.emissive!==void 0&&s.emissive!==void 0&&s.emissive.setHex(t.emissive),t.specular!==void 0&&s.specular!==void 0&&s.specular.setHex(t.specular),t.specularIntensity!==void 0&&(s.specularIntensity=t.specularIntensity),t.specularColor!==void 0&&s.specularColor!==void 0&&s.specularColor.setHex(t.specularColor),t.shininess!==void 0&&(s.shininess=t.shininess),t.clearcoat!==void 0&&(s.clearcoat=t.clearcoat),t.clearcoatRoughness!==void 0&&(s.clearcoatRoughness=t.clearcoatRoughness),t.dispersion!==void 0&&(s.dispersion=t.dispersion),t.iridescence!==void 0&&(s.iridescence=t.iridescence),t.iridescenceIOR!==void 0&&(s.iridescenceIOR=t.iridescenceIOR),t.iridescenceThicknessRange!==void 0&&(s.iridescenceThicknessRange=t.iridescenceThicknessRange),t.transmission!==void 0&&(s.transmission=t.transmission),t.thickness!==void 0&&(s.thickness=t.thickness),t.attenuationDistance!==void 0&&(s.attenuationDistance=t.attenuationDistance),t.attenuationColor!==void 0&&s.attenuationColor!==void 0&&s.attenuationColor.setHex(t.attenuationColor),t.anisotropy!==void 0&&(s.anisotropy=t.anisotropy),t.anisotropyRotation!==void 0&&(s.anisotropyRotation=t.anisotropyRotation),t.fog!==void 0&&(s.fog=t.fog),t.flatShading!==void 0&&(s.flatShading=t.flatShading),t.blending!==void 0&&(s.blending=t.blending),t.combine!==void 0&&(s.combine=t.combine),t.side!==void 0&&(s.side=t.side),t.shadowSide!==void 0&&(s.shadowSide=t.shadowSide),t.opacity!==void 0&&(s.opacity=t.opacity),t.transparent!==void 0&&(s.transparent=t.transparent),t.alphaTest!==void 0&&(s.alphaTest=t.alphaTest),t.alphaHash!==void 0&&(s.alphaHash=t.alphaHash),t.depthFunc!==void 0&&(s.depthFunc=t.depthFunc),t.depthTest!==void 0&&(s.depthTest=t.depthTest),t.depthWrite!==void 0&&(s.depthWrite=t.depthWrite),t.colorWrite!==void 0&&(s.colorWrite=t.colorWrite),t.blendSrc!==void 0&&(s.blendSrc=t.blendSrc),t.blendDst!==void 0&&(s.blendDst=t.blendDst),t.blendEquation!==void 0&&(s.blendEquation=t.blendEquation),t.blendSrcAlpha!==void 0&&(s.blendSrcAlpha=t.blendSrcAlpha),t.blendDstAlpha!==void 0&&(s.blendDstAlpha=t.blendDstAlpha),t.blendEquationAlpha!==void 0&&(s.blendEquationAlpha=t.blendEquationAlpha),t.blendColor!==void 0&&s.blendColor!==void 0&&s.blendColor.setHex(t.blendColor),t.blendAlpha!==void 0&&(s.blendAlpha=t.blendAlpha),t.stencilWriteMask!==void 0&&(s.stencilWriteMask=t.stencilWriteMask),t.stencilFunc!==void 0&&(s.stencilFunc=t.stencilFunc),t.stencilRef!==void 0&&(s.stencilRef=t.stencilRef),t.stencilFuncMask!==void 0&&(s.stencilFuncMask=t.stencilFuncMask),t.stencilFail!==void 0&&(s.stencilFail=t.stencilFail),t.stencilZFail!==void 0&&(s.stencilZFail=t.stencilZFail),t.stencilZPass!==void 0&&(s.stencilZPass=t.stencilZPass),t.stencilWrite!==void 0&&(s.stencilWrite=t.stencilWrite),t.wireframe!==void 0&&(s.wireframe=t.wireframe),t.wireframeLinewidth!==void 0&&(s.wireframeLinewidth=t.wireframeLinewidth),t.wireframeLinecap!==void 0&&(s.wireframeLinecap=t.wireframeLinecap),t.wireframeLinejoin!==void 0&&(s.wireframeLinejoin=t.wireframeLinejoin),t.rotation!==void 0&&(s.rotation=t.rotation),t.linewidth!==void 0&&(s.linewidth=t.linewidth),t.dashSize!==void 0&&(s.dashSize=t.dashSize),t.gapSize!==void 0&&(s.gapSize=t.gapSize),t.scale!==void 0&&(s.scale=t.scale),t.polygonOffset!==void 0&&(s.polygonOffset=t.polygonOffset),t.polygonOffsetFactor!==void 0&&(s.polygonOffsetFactor=t.polygonOffsetFactor),t.polygonOffsetUnits!==void 0&&(s.polygonOffsetUnits=t.polygonOffsetUnits),t.dithering!==void 0&&(s.dithering=t.dithering),t.alphaToCoverage!==void 0&&(s.alphaToCoverage=t.alphaToCoverage),t.premultipliedAlpha!==void 0&&(s.premultipliedAlpha=t.premultipliedAlpha),t.forceSinglePass!==void 0&&(s.forceSinglePass=t.forceSinglePass),t.visible!==void 0&&(s.visible=t.visible),t.toneMapped!==void 0&&(s.toneMapped=t.toneMapped),t.userData!==void 0&&(s.userData=t.userData),t.vertexColors!==void 0&&(typeof t.vertexColors=="number"?s.vertexColors=t.vertexColors>0:s.vertexColors=t.vertexColors),t.uniforms!==void 0)for(const n in t.uniforms){const r=t.uniforms[n];switch(s.uniforms[n]={},r.type){case"t":s.uniforms[n].value=i(r.value);break;case"c":s.uniforms[n].value=new V().setHex(r.value);break;case"v2":s.uniforms[n].value=new B().fromArray(r.value);break;case"v3":s.uniforms[n].value=new w().fromArray(r.value);break;case"v4":s.uniforms[n].value=new St().fromArray(r.value);break;case"m3":s.uniforms[n].value=new pe().fromArray(r.value);break;case"m4":s.uniforms[n].value=new Y().fromArray(r.value);break;default:s.uniforms[n].value=r.value}}if(t.defines!==void 0&&(s.defines=t.defines),t.vertexShader!==void 0&&(s.vertexShader=t.vertexShader),t.fragmentShader!==void 0&&(s.fragmentShader=t.fragmentShader),t.glslVersion!==void 0&&(s.glslVersion=t.glslVersion),t.extensions!==void 0)for(const n in t.extensions)s.extensions[n]=t.extensions[n];if(t.lights!==void 0&&(s.lights=t.lights),t.clipping!==void 0&&(s.clipping=t.clipping),t.size!==void 0&&(s.size=t.size),t.sizeAttenuation!==void 0&&(s.sizeAttenuation=t.sizeAttenuation),t.map!==void 0&&(s.map=i(t.map)),t.matcap!==void 0&&(s.matcap=i(t.matcap)),t.alphaMap!==void 0&&(s.alphaMap=i(t.alphaMap)),t.bumpMap!==void 0&&(s.bumpMap=i(t.bumpMap)),t.bumpScale!==void 0&&(s.bumpScale=t.bumpScale),t.normalMap!==void 0&&(s.normalMap=i(t.normalMap)),t.normalMapType!==void 0&&(s.normalMapType=t.normalMapType),t.normalScale!==void 0){let n=t.normalScale;Array.isArray(n)===!1&&(n=[n,n]),s.normalScale=new B().fromArray(n)}return t.displacementMap!==void 0&&(s.displacementMap=i(t.displacementMap)),t.displacementScale!==void 0&&(s.displacementScale=t.displacementScale),t.displacementBias!==void 0&&(s.displacementBias=t.displacementBias),t.roughnessMap!==void 0&&(s.roughnessMap=i(t.roughnessMap)),t.metalnessMap!==void 0&&(s.metalnessMap=i(t.metalnessMap)),t.emissiveMap!==void 0&&(s.emissiveMap=i(t.emissiveMap)),t.emissiveIntensity!==void 0&&(s.emissiveIntensity=t.emissiveIntensity),t.specularMap!==void 0&&(s.specularMap=i(t.specularMap)),t.specularIntensityMap!==void 0&&(s.specularIntensityMap=i(t.specularIntensityMap)),t.specularColorMap!==void 0&&(s.specularColorMap=i(t.specularColorMap)),t.envMap!==void 0&&(s.envMap=i(t.envMap)),t.envMapRotation!==void 0&&s.envMapRotation.fromArray(t.envMapRotation),t.envMapIntensity!==void 0&&(s.envMapIntensity=t.envMapIntensity),t.reflectivity!==void 0&&(s.reflectivity=t.reflectivity),t.refractionRatio!==void 0&&(s.refractionRatio=t.refractionRatio),t.lightMap!==void 0&&(s.lightMap=i(t.lightMap)),t.lightMapIntensity!==void 0&&(s.lightMapIntensity=t.lightMapIntensity),t.aoMap!==void 0&&(s.aoMap=i(t.aoMap)),t.aoMapIntensity!==void 0&&(s.aoMapIntensity=t.aoMapIntensity),t.gradientMap!==void 0&&(s.gradientMap=i(t.gradientMap)),t.clearcoatMap!==void 0&&(s.clearcoatMap=i(t.clearcoatMap)),t.clearcoatRoughnessMap!==void 0&&(s.clearcoatRoughnessMap=i(t.clearcoatRoughnessMap)),t.clearcoatNormalMap!==void 0&&(s.clearcoatNormalMap=i(t.clearcoatNormalMap)),t.clearcoatNormalScale!==void 0&&(s.clearcoatNormalScale=new B().fromArray(t.clearcoatNormalScale)),t.iridescenceMap!==void 0&&(s.iridescenceMap=i(t.iridescenceMap)),t.iridescenceThicknessMap!==void 0&&(s.iridescenceThicknessMap=i(t.iridescenceThicknessMap)),t.transmissionMap!==void 0&&(s.transmissionMap=i(t.transmissionMap)),t.thicknessMap!==void 0&&(s.thicknessMap=i(t.thicknessMap)),t.anisotropyMap!==void 0&&(s.anisotropyMap=i(t.anisotropyMap)),t.sheenColorMap!==void 0&&(s.sheenColorMap=i(t.sheenColorMap)),t.sheenRoughnessMap!==void 0&&(s.sheenRoughnessMap=i(t.sheenRoughnessMap)),s}setTextures(t){return this.textures=t,this}createMaterialFromType(t){return Ca.createMaterialFromType(t)}static createMaterialFromType(t){const e={ShadowMaterial:dd,SpriteMaterial:fs,RawShaderMaterial:fd,ShaderMaterial:ia,PointsMaterial:Lh,MeshPhysicalMaterial:pd,MeshStandardMaterial:Aa,MeshPhongMaterial:md,MeshToonMaterial:gd,MeshNormalMaterial:yd,MeshLambertMaterial:xd,MeshDepthMaterial:bd,MeshDistanceMaterial:vd,MeshBasicMaterial:Di,MeshMatcapMaterial:wd,LineDashedMaterial:_d,LineBasicMaterial:Gt,Material:Rt};return new e[t]}}class Lo{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),typeof TextDecoder<"u")return new TextDecoder().decode(t);let e="";for(let i=0,s=t.length;i<s;i++)e+=String.fromCharCode(t[i]);try{return decodeURIComponent(escape(e))}catch{return e}}static extractUrlBase(t){const e=t.lastIndexOf("/");return e===-1?"./":t.slice(0,e+1)}static resolveURL(t,e){return typeof t!="string"||t===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class Wd extends Z{constructor(){super(),this.isInstancedBufferGeometry=!0,this.type="InstancedBufferGeometry",this.instanceCount=1/0}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}toJSON(){const t=super.toJSON();return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}class Hd extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=new Ge(n.manager);r.setPath(n.path),r.setRequestHeader(n.requestHeader),r.setWithCredentials(n.withCredentials),r.load(t,function(a){try{e(n.parse(JSON.parse(a)))}catch(o){s?s(o):console.error(o),n.manager.itemError(t)}},i,s)}parse(t){const e={},i={};function s(f,p){if(e[p]!==void 0)return e[p];const g=f.interleavedBuffers[p],x=n(f,g.buffer),y=Fi(g.type,x),b=new oa(y,g.stride);return b.uuid=g.uuid,e[p]=b,b}function n(f,p){if(i[p]!==void 0)return i[p];const g=f.arrayBuffers[p],x=new Uint32Array(g).buffer;return i[p]=x,x}const r=t.isInstancedBufferGeometry?new Wd:new Z,a=t.data.index;if(a!==void 0){const f=Fi(a.type,a.array);r.setIndex(new dt(f,1))}const o=t.data.attributes;for(const f in o){const p=o[f];let m;if(p.isInterleavedBufferAttribute){const g=s(t.data,p.data);m=new Oi(g,p.itemSize,p.offset,p.normalized)}else{const g=Fi(p.type,p.array),x=p.isInstancedBufferAttribute?bs:dt;m=new x(g,p.itemSize,p.normalized)}p.name!==void 0&&(m.name=p.name),p.usage!==void 0&&m.setUsage(p.usage),r.setAttribute(f,m)}const h=t.data.morphAttributes;if(h)for(const f in h){const p=h[f],m=[];for(let g=0,x=p.length;g<x;g++){const y=p[g];let b;if(y.isInterleavedBufferAttribute){const v=s(t.data,y.data);b=new Oi(v,y.itemSize,y.offset,y.normalized)}else{const v=Fi(y.type,y.array);b=new dt(v,y.itemSize,y.normalized)}y.name!==void 0&&(b.name=y.name),m.push(b)}r.morphAttributes[f]=m}t.data.morphTargetsRelative&&(r.morphTargetsRelative=!0);const u=t.data.groups||t.data.drawcalls||t.data.offsets;if(u!==void 0)for(let f=0,p=u.length;f!==p;++f){const m=u[f];r.addGroup(m.start,m.count,m.materialIndex)}const d=t.data.boundingSphere;if(d!==void 0){const f=new w;d.center!==void 0&&f.fromArray(d.center),r.boundingSphere=new Et(f,d.radius)}return t.name&&(r.name=t.name),t.userData&&(r.userData=t.userData),r}}class Jg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=this.path===""?Lo.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||r;const a=new Ge(this.manager);a.setPath(this.path),a.setRequestHeader(this.requestHeader),a.setWithCredentials(this.withCredentials),a.load(t,function(o){let h=null;try{h=JSON.parse(o)}catch(u){s!==void 0&&s(u),console.error("THREE:ObjectLoader: Can't parse "+t+".",u.message);return}const c=h.metadata;if(c===void 0||c.type===void 0||c.type.toLowerCase()==="geometry"){s!==void 0&&s(new Error("THREE.ObjectLoader: Can't load "+t)),console.error("THREE.ObjectLoader: Can't load "+t);return}n.parse(h,e)},i,s)}async loadAsync(t,e){const i=this,s=this.path===""?Lo.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||s;const n=new Ge(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials);const r=await n.loadAsync(t,e),a=JSON.parse(r),o=a.metadata;if(o===void 0||o.type===void 0||o.type.toLowerCase()==="geometry")throw new Error("THREE.ObjectLoader: Can't load "+t);return await i.parseAsync(a)}parse(t,e){const i=this.parseAnimations(t.animations),s=this.parseShapes(t.shapes),n=this.parseGeometries(t.geometries,s),r=this.parseImages(t.images,function(){e!==void 0&&e(h)}),a=this.parseTextures(t.textures,r),o=this.parseMaterials(t.materials,a),h=this.parseObject(t.object,n,o,a,i),c=this.parseSkeletons(t.skeletons,h);if(this.bindSkeletons(h,c),this.bindLightTargets(h),e!==void 0){let u=!1;for(const d in r)if(r[d].data instanceof HTMLImageElement){u=!0;break}u===!1&&e(h)}return h}async parseAsync(t){const e=this.parseAnimations(t.animations),i=this.parseShapes(t.shapes),s=this.parseGeometries(t.geometries,i),n=await this.parseImagesAsync(t.images),r=this.parseTextures(t.textures,n),a=this.parseMaterials(t.materials,r),o=this.parseObject(t.object,s,a,r,e),h=this.parseSkeletons(t.skeletons,o);return this.bindSkeletons(o,h),this.bindLightTargets(o),o}parseShapes(t){const e={};if(t!==void 0)for(let i=0,s=t.length;i<s;i++){const n=new Ri().fromJSON(t[i]);e[n.uuid]=n}return e}parseSkeletons(t,e){const i={},s={};if(e.traverse(function(n){n.isBone&&(s[n.uuid]=n)}),t!==void 0)for(let n=0,r=t.length;n<r;n++){const a=new ha().fromJSON(t[n],s);i[a.uuid]=a}return i}parseGeometries(t,e){const i={};if(t!==void 0){const s=new Hd;for(let n=0,r=t.length;n<r;n++){let a;const o=t[n];switch(o.type){case"BufferGeometry":case"InstancedBufferGeometry":a=s.parse(o);break;default:o.type in Po?a=Po[o.type].fromJSON(o,e):console.warn(`THREE.ObjectLoader: Unsupported geometry type "${o.type}"`)}a.uuid=o.uuid,o.name!==void 0&&(a.name=o.name),o.userData!==void 0&&(a.userData=o.userData),i[o.uuid]=a}}return i}parseMaterials(t,e){const i={},s={};if(t!==void 0){const n=new Ca;n.setTextures(e);for(let r=0,a=t.length;r<a;r++){const o=t[r];i[o.uuid]===void 0&&(i[o.uuid]=n.parse(o)),s[o.uuid]=i[o.uuid]}}return s}parseAnimations(t){const e={};if(t!==void 0)for(let i=0;i<t.length;i++){const s=t[i],n=En.parse(s);e[n.uuid]=n}return e}parseImages(t,e){const i=this,s={};let n;function r(o){return i.manager.itemStart(o),n.load(o,function(){i.manager.itemEnd(o)},void 0,function(){i.manager.itemError(o),i.manager.itemEnd(o)})}function a(o){if(typeof o=="string"){const h=o,c=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(h)?h:i.resourcePath+h;return r(c)}else return o.data?{data:Fi(o.type,o.data),width:o.width,height:o.height}:null}if(t!==void 0&&t.length>0){const o=new jh(e);n=new Rn(o),n.setCrossOrigin(this.crossOrigin);for(let h=0,c=t.length;h<c;h++){const u=t[h],d=u.url;if(Array.isArray(d)){const f=[];for(let p=0,m=d.length;p<m;p++){const g=d[p],x=a(g);x!==null&&(x instanceof HTMLImageElement?f.push(x):f.push(new Ce(x.data,x.width,x.height)))}s[u.uuid]=new Pi(f)}else{const f=a(u.url);s[u.uuid]=new Pi(f)}}}return s}async parseImagesAsync(t){const e=this,i={};let s;async function n(r){if(typeof r=="string"){const a=r,o=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(a)?a:e.resourcePath+a;return await s.loadAsync(o)}else return r.data?{data:Fi(r.type,r.data),width:r.width,height:r.height}:null}if(t!==void 0&&t.length>0){s=new Rn(this.manager),s.setCrossOrigin(this.crossOrigin);for(let r=0,a=t.length;r<a;r++){const o=t[r],h=o.url;if(Array.isArray(h)){const c=[];for(let u=0,d=h.length;u<d;u++){const f=h[u],p=await n(f);p!==null&&(p instanceof HTMLImageElement?c.push(p):c.push(new Ce(p.data,p.width,p.height)))}i[o.uuid]=new Pi(c)}else{const c=await n(o.url);i[o.uuid]=new Pi(c)}}}return i}parseTextures(t,e){function i(n,r){return typeof n=="number"?n:(console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.",n),r[n])}const s={};if(t!==void 0)for(let n=0,r=t.length;n<r;n++){const a=t[n];a.image===void 0&&console.warn('THREE.ObjectLoader: No "image" specified for',a.uuid),e[a.image]===void 0&&console.warn("THREE.ObjectLoader: Undefined image",a.image);const o=e[a.image],h=o.data;let c;Array.isArray(h)?(c=new na,h.length===6&&(c.needsUpdate=!0)):(h&&h.data?c=new Ce:c=new gt,h&&(c.needsUpdate=!0)),c.source=o,c.uuid=a.uuid,a.name!==void 0&&(c.name=a.name),a.mapping!==void 0&&(c.mapping=i(a.mapping,qd)),a.channel!==void 0&&(c.channel=a.channel),a.offset!==void 0&&c.offset.fromArray(a.offset),a.repeat!==void 0&&c.repeat.fromArray(a.repeat),a.center!==void 0&&c.center.fromArray(a.center),a.rotation!==void 0&&(c.rotation=a.rotation),a.wrap!==void 0&&(c.wrapS=i(a.wrap[0],Oo),c.wrapT=i(a.wrap[1],Oo)),a.format!==void 0&&(c.format=a.format),a.internalFormat!==void 0&&(c.internalFormat=a.internalFormat),a.type!==void 0&&(c.type=a.type),a.colorSpace!==void 0&&(c.colorSpace=a.colorSpace),a.minFilter!==void 0&&(c.minFilter=i(a.minFilter,No)),a.magFilter!==void 0&&(c.magFilter=i(a.magFilter,No)),a.anisotropy!==void 0&&(c.anisotropy=a.anisotropy),a.flipY!==void 0&&(c.flipY=a.flipY),a.generateMipmaps!==void 0&&(c.generateMipmaps=a.generateMipmaps),a.premultiplyAlpha!==void 0&&(c.premultiplyAlpha=a.premultiplyAlpha),a.unpackAlignment!==void 0&&(c.unpackAlignment=a.unpackAlignment),a.compareFunction!==void 0&&(c.compareFunction=a.compareFunction),a.userData!==void 0&&(c.userData=a.userData),s[a.uuid]=c}return s}parseObject(t,e,i,s,n){let r;function a(d){return e[d]===void 0&&console.warn("THREE.ObjectLoader: Undefined geometry",d),e[d]}function o(d){if(d!==void 0){if(Array.isArray(d)){const f=[];for(let p=0,m=d.length;p<m;p++){const g=d[p];i[g]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",g),f.push(i[g])}return f}return i[d]===void 0&&console.warn("THREE.ObjectLoader: Undefined material",d),i[d]}}function h(d){return s[d]===void 0&&console.warn("THREE.ObjectLoader: Undefined texture",d),s[d]}let c,u;switch(t.type){case"Scene":r=new pu,t.background!==void 0&&(Number.isInteger(t.background)?r.background=new V(t.background):r.background=h(t.background)),t.environment!==void 0&&(r.environment=h(t.environment)),t.fog!==void 0&&(t.fog.type==="Fog"?r.fog=new aa(t.fog.color,t.fog.near,t.fog.far):t.fog.type==="FogExp2"&&(r.fog=new ra(t.fog.color,t.fog.density)),t.fog.name!==""&&(r.fog.name=t.fog.name)),t.backgroundBlurriness!==void 0&&(r.backgroundBlurriness=t.backgroundBlurriness),t.backgroundIntensity!==void 0&&(r.backgroundIntensity=t.backgroundIntensity),t.backgroundRotation!==void 0&&r.backgroundRotation.fromArray(t.backgroundRotation),t.environmentIntensity!==void 0&&(r.environmentIntensity=t.environmentIntensity),t.environmentRotation!==void 0&&r.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":r=new te(t.fov,t.aspect,t.near,t.far),t.focus!==void 0&&(r.focus=t.focus),t.zoom!==void 0&&(r.zoom=t.zoom),t.filmGauge!==void 0&&(r.filmGauge=t.filmGauge),t.filmOffset!==void 0&&(r.filmOffset=t.filmOffset),t.view!==void 0&&(r.view=Object.assign({},t.view));break;case"OrthographicCamera":r=new Qh(t.left,t.right,t.top,t.bottom,t.near,t.far),t.zoom!==void 0&&(r.zoom=t.zoom),t.view!==void 0&&(r.view=Object.assign({},t.view));break;case"AmbientLight":r=new Dd(t.color,t.intensity);break;case"DirectionalLight":r=new Nd(t.color,t.intensity),r.target=t.target||"";break;case"PointLight":r=new Ld(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":r=new Ud(t.color,t.intensity,t.width,t.height);break;case"SpotLight":r=new Ed(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),r.target=t.target||"";break;case"HemisphereLight":r=new Pd(t.color,t.groundColor,t.intensity);break;case"LightProbe":r=new Gd().fromJSON(t);break;case"SkinnedMesh":c=a(t.geometry),u=o(t.material),r=new yu(c,u),t.bindMode!==void 0&&(r.bindMode=t.bindMode),t.bindMatrix!==void 0&&r.bindMatrix.fromArray(t.bindMatrix),t.skeleton!==void 0&&(r.skeleton=t.skeleton);break;case"Mesh":c=a(t.geometry),u=o(t.material),r=new Vt(c,u);break;case"InstancedMesh":c=a(t.geometry),u=o(t.material);const d=t.count,f=t.instanceMatrix,p=t.instanceColor;r=new vu(c,u,d),r.instanceMatrix=new bs(new Float32Array(f.array),16),p!==void 0&&(r.instanceColor=new bs(new Float32Array(p.array),p.itemSize));break;case"BatchedMesh":c=a(t.geometry),u=o(t.material),r=new zu(t.maxInstanceCount,t.maxVertexCount,t.maxIndexCount,u),r.geometry=c,r.perObjectFrustumCulled=t.perObjectFrustumCulled,r.sortObjects=t.sortObjects,r._drawRanges=t.drawRanges,r._reservedRanges=t.reservedRanges,r._visibility=t.visibility,r._active=t.active,r._bounds=t.bounds.map(m=>{const g=new Ut;g.min.fromArray(m.boxMin),g.max.fromArray(m.boxMax);const x=new Et;return x.radius=m.sphereRadius,x.center.fromArray(m.sphereCenter),{boxInitialized:m.boxInitialized,box:g,sphereInitialized:m.sphereInitialized,sphere:x}}),r._maxInstanceCount=t.maxInstanceCount,r._maxVertexCount=t.maxVertexCount,r._maxIndexCount=t.maxIndexCount,r._geometryInitialized=t.geometryInitialized,r._geometryCount=t.geometryCount,r._matricesTexture=h(t.matricesTexture.uuid),t.colorsTexture!==void 0&&(r._colorsTexture=h(t.colorsTexture.uuid));break;case"LOD":r=new mu;break;case"Line":r=new ni(a(t.geometry),o(t.material));break;case"LineLoop":r=new Bu(a(t.geometry),o(t.material));break;case"LineSegments":r=new Fe(a(t.geometry),o(t.material));break;case"PointCloud":case"Points":r=new Fu(a(t.geometry),o(t.material));break;case"Sprite":r=new cs(o(t.material));break;case"Group":r=new Oh;break;case"Bone":r=new Eh;break;default:r=new tt}if(r.uuid=t.uuid,t.name!==void 0&&(r.name=t.name),t.matrix!==void 0?(r.matrix.fromArray(t.matrix),t.matrixAutoUpdate!==void 0&&(r.matrixAutoUpdate=t.matrixAutoUpdate),r.matrixAutoUpdate&&r.matrix.decompose(r.position,r.quaternion,r.scale)):(t.position!==void 0&&r.position.fromArray(t.position),t.rotation!==void 0&&r.rotation.fromArray(t.rotation),t.quaternion!==void 0&&r.quaternion.fromArray(t.quaternion),t.scale!==void 0&&r.scale.fromArray(t.scale)),t.up!==void 0&&r.up.fromArray(t.up),t.castShadow!==void 0&&(r.castShadow=t.castShadow),t.receiveShadow!==void 0&&(r.receiveShadow=t.receiveShadow),t.shadow&&(t.shadow.intensity!==void 0&&(r.shadow.intensity=t.shadow.intensity),t.shadow.bias!==void 0&&(r.shadow.bias=t.shadow.bias),t.shadow.normalBias!==void 0&&(r.shadow.normalBias=t.shadow.normalBias),t.shadow.radius!==void 0&&(r.shadow.radius=t.shadow.radius),t.shadow.mapSize!==void 0&&r.shadow.mapSize.fromArray(t.shadow.mapSize),t.shadow.camera!==void 0&&(r.shadow.camera=this.parseObject(t.shadow.camera))),t.visible!==void 0&&(r.visible=t.visible),t.frustumCulled!==void 0&&(r.frustumCulled=t.frustumCulled),t.renderOrder!==void 0&&(r.renderOrder=t.renderOrder),t.userData!==void 0&&(r.userData=t.userData),t.layers!==void 0&&(r.layers.mask=t.layers),t.children!==void 0){const d=t.children;for(let f=0;f<d.length;f++)r.add(this.parseObject(d[f],e,i,s,n))}if(t.animations!==void 0){const d=t.animations;for(let f=0;f<d.length;f++){const p=d[f];r.animations.push(n[p])}}if(t.type==="LOD"){t.autoUpdate!==void 0&&(r.autoUpdate=t.autoUpdate);const d=t.levels;for(let f=0;f<d.length;f++){const p=d[f],m=r.getObjectByProperty("uuid",p.object);m!==void 0&&r.addLevel(m,p.distance,p.hysteresis)}}return r}bindSkeletons(t,e){Object.keys(e).length!==0&&t.traverse(function(i){if(i.isSkinnedMesh===!0&&i.skeleton!==void 0){const s=e[i.skeleton];s===void 0?console.warn("THREE.ObjectLoader: No skeleton found with UUID:",i.skeleton):i.bind(s,i.bindMatrix)}})}bindLightTargets(t){t.traverse(function(e){if(e.isDirectionalLight||e.isSpotLight){const i=e.target,s=t.getObjectByProperty("uuid",i);s!==void 0?e.target=s:e.target=new tt}})}}const qd={UVMapping:Zr,CubeReflectionMapping:Kr,CubeRefractionMapping:Ml,EquirectangularReflectionMapping:Sl,EquirectangularRefractionMapping:Al,CubeUVReflectionMapping:Tl},Oo={RepeatWrapping:Rr,ClampToEdgeWrapping:ue,MirroredRepeatWrapping:Lr},No={NearestFilter:he,NearestMipmapNearestFilter:Il,NearestMipmapLinearFilter:Cl,LinearFilter:ee,LinearMipmapNearestFilter:zl,LinearMipmapLinearFilter:Ln};class Zg extends Kt{constructor(t){super(t),this.isImageBitmapLoader=!0,typeof createImageBitmap>"u"&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,i,s){t===void 0&&(t=""),this.path!==void 0&&(t=this.path+t),t=this.manager.resolveURL(t);const n=this,r=Ve.get(t);if(r!==void 0){if(n.manager.itemStart(t),r.then){r.then(h=>{e&&e(h),n.manager.itemEnd(t)}).catch(h=>{s&&s(h)});return}return setTimeout(function(){e&&e(r),n.manager.itemEnd(t)},0),r}const a={};a.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",a.headers=this.requestHeader;const o=fetch(t,a).then(function(h){return h.blob()}).then(function(h){return createImageBitmap(h,Object.assign(n.options,{colorSpaceConversion:"none"}))}).then(function(h){return Ve.add(t,h),e&&e(h),n.manager.itemEnd(t),h}).catch(function(h){s&&s(h),Ve.remove(t),n.manager.itemError(t),n.manager.itemEnd(t)});Ve.add(t,o),n.manager.itemStart(t)}}let dn;class $h{static getContext(){return dn===void 0&&(dn=new(window.AudioContext||window.webkitAudioContext)),dn}static setContext(t){dn=t}}class Kg extends Kt{constructor(t){super(t)}load(t,e,i,s){const n=this,r=new Ge(this.manager);r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,function(o){try{const h=o.slice(0);$h.getContext().decodeAudioData(h,function(u){e(u)}).catch(a)}catch(h){a(h)}},i,s);function a(o){s?s(o):console.error(o),n.manager.itemError(t)}}}const Do=new Y,Uo=new Y,Ke=new Y;class jg{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new te,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new te,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(t){const e=this._cache;if(e.focus!==t.focus||e.fov!==t.fov||e.aspect!==t.aspect*this.aspect||e.near!==t.near||e.far!==t.far||e.zoom!==t.zoom||e.eyeSep!==this.eyeSep){e.focus=t.focus,e.fov=t.fov,e.aspect=t.aspect*this.aspect,e.near=t.near,e.far=t.far,e.zoom=t.zoom,e.eyeSep=this.eyeSep,Ke.copy(t.projectionMatrix);const s=e.eyeSep/2,n=s*e.near/e.focus,r=e.near*Math.tan(ii*e.fov*.5)/e.zoom;let a,o;Uo.elements[12]=-s,Do.elements[12]=s,a=-r*e.aspect+n,o=r*e.aspect+n,Ke.elements[0]=2*e.near/(o-a),Ke.elements[8]=(o+a)/(o-a),this.cameraL.projectionMatrix.copy(Ke),a=-r*e.aspect-n,o=r*e.aspect-n,Ke.elements[0]=2*e.near/(o-a),Ke.elements[8]=(o+a)/(o-a),this.cameraR.projectionMatrix.copy(Ke)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Uo),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply(Do)}}class Qg extends te{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Xd{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Vo(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let t=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const e=Vo();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Vo(){return performance.now()}const je=new w,Go=new Zt,Yd=new w,Qe=new w;class $g extends tt{constructor(){super(),this.type="AudioListener",this.context=$h.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Xd}getInput(){return this.gain}removeFilter(){return this.filter!==null&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(t){return this.filter!==null?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=t,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}updateMatrixWorld(t){super.updateMatrixWorld(t);const e=this.context.listener,i=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(je,Go,Yd),Qe.set(0,0,-1).applyQuaternion(Go),e.positionX){const s=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(je.x,s),e.positionY.linearRampToValueAtTime(je.y,s),e.positionZ.linearRampToValueAtTime(je.z,s),e.forwardX.linearRampToValueAtTime(Qe.x,s),e.forwardY.linearRampToValueAtTime(Qe.y,s),e.forwardZ.linearRampToValueAtTime(Qe.z,s),e.upX.linearRampToValueAtTime(i.x,s),e.upY.linearRampToValueAtTime(i.y,s),e.upZ.linearRampToValueAtTime(i.z,s)}else e.setPosition(je.x,je.y,je.z),e.setOrientation(Qe.x,Qe.y,Qe.z,i.x,i.y,i.z)}}class Jd extends tt{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(this.isPlaying===!0){console.warn("THREE.Audio: Audio is already playing.");return}if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.isPlaying===!0&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,this.loop===!0&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(t=0){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this._progress=0,this.source!==null&&(this.source.stop(this.context.currentTime+t),this.source.onended=null),this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].connect(this.filters[t]);this.filters[this.filters.length-1].connect(this.getOutput())}else this.source.connect(this.getOutput());return this._connected=!0,this}disconnect(){if(this._connected!==!1){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].disconnect(this.filters[t]);this.filters[this.filters.length-1].disconnect(this.getOutput())}else this.source.disconnect(this.getOutput());return this._connected=!1,this}}getFilters(){return this.filters}setFilters(t){return t||(t=[]),this._connected===!0?(this.disconnect(),this.filters=t.slice(),this.connect()):this.filters=t.slice(),this}setDetune(t){return this.detune=t,this.isPlaying===!0&&this.source.detune!==void 0&&this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,.01),this}getDetune(){return this.detune}getFilter(){return this.getFilters()[0]}setFilter(t){return this.setFilters(t?[t]:[])}setPlaybackRate(t){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.playbackRate=t,this.isPlaying===!0&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1,this._progress=0}getLoop(){return this.hasPlaybackControl===!1?(console.warn("THREE.Audio: this Audio has no playback control."),!1):this.loop}setLoop(t){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.loop=t,this.isPlaying===!0&&(this.source.loop=this.loop),this}setLoopStart(t){return this.loopStart=t,this}setLoopEnd(t){return this.loopEnd=t,this}getVolume(){return this.gain.gain.value}setVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}copy(t,e){return super.copy(t,e),t.sourceType!=="buffer"?(console.warn("THREE.Audio: Audio source type cannot be copied."),this):(this.autoplay=t.autoplay,this.buffer=t.buffer,this.detune=t.detune,this.loop=t.loop,this.loopStart=t.loopStart,this.loopEnd=t.loopEnd,this.offset=t.offset,this.duration=t.duration,this.playbackRate=t.playbackRate,this.hasPlaybackControl=t.hasPlaybackControl,this.sourceType=t.sourceType,this.filters=t.filters.slice(),this)}clone(t){return new this.constructor(this.listener).copy(this,t)}}const $e=new w,Wo=new Zt,Zd=new w,ti=new w;class ty extends Jd{constructor(t){super(t),this.panner=this.context.createPanner(),this.panner.panningModel="HRTF",this.panner.connect(this.gain)}connect(){super.connect(),this.panner.connect(this.gain)}disconnect(){super.disconnect(),this.panner.disconnect(this.gain)}getOutput(){return this.panner}getRefDistance(){return this.panner.refDistance}setRefDistance(t){return this.panner.refDistance=t,this}getRolloffFactor(){return this.panner.rolloffFactor}setRolloffFactor(t){return this.panner.rolloffFactor=t,this}getDistanceModel(){return this.panner.distanceModel}setDistanceModel(t){return this.panner.distanceModel=t,this}getMaxDistance(){return this.panner.maxDistance}setMaxDistance(t){return this.panner.maxDistance=t,this}setDirectionalCone(t,e,i){return this.panner.coneInnerAngle=t,this.panner.coneOuterAngle=e,this.panner.coneOuterGain=i,this}updateMatrixWorld(t){if(super.updateMatrixWorld(t),this.hasPlaybackControl===!0&&this.isPlaying===!1)return;this.matrixWorld.decompose($e,Wo,Zd),ti.set(0,0,1).applyQuaternion(Wo);const e=this.panner;if(e.positionX){const i=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime($e.x,i),e.positionY.linearRampToValueAtTime($e.y,i),e.positionZ.linearRampToValueAtTime($e.z,i),e.orientationX.linearRampToValueAtTime(ti.x,i),e.orientationY.linearRampToValueAtTime(ti.y,i),e.orientationZ.linearRampToValueAtTime(ti.z,i)}else e.setPosition($e.x,$e.y,$e.z),e.setOrientation(ti.x,ti.y,ti.z)}}class ey{constructor(t,e=2048){this.analyser=t.context.createAnalyser(),this.analyser.fftSize=e,this.data=new Uint8Array(this.analyser.frequencyBinCount),t.getOutput().connect(this.analyser)}getFrequencyData(){return this.analyser.getByteFrequencyData(this.data),this.data}getAverageFrequency(){let t=0;const e=this.getFrequencyData();for(let i=0;i<e.length;i++)t+=e[i];return t/e.length}}class Kd{constructor(t,e,i){this.binding=t,this.valueSize=i;let s,n,r;switch(e){case"quaternion":s=this._slerp,n=this._slerpAdditive,r=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(i*6),this._workIndex=5;break;case"string":case"bool":s=this._select,n=this._select,r=this._setAdditiveIdentityOther,this.buffer=new Array(i*5);break;default:s=this._lerp,n=this._lerpAdditive,r=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(i*5)}this._mixBufferRegion=s,this._mixBufferRegionAdditive=n,this._setIdentity=r,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const i=this.buffer,s=this.valueSize,n=t*s+s;let r=this.cumulativeWeight;if(r===0){for(let a=0;a!==s;++a)i[n+a]=i[a];r=e}else{r+=e;const a=e/r;this._mixBufferRegion(i,n,0,a,s)}this.cumulativeWeight=r}accumulateAdditive(t){const e=this.buffer,i=this.valueSize,s=i*this._addIndex;this.cumulativeWeightAdditive===0&&this._setIdentity(),this._mixBufferRegionAdditive(e,s,0,t,i),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,i=this.buffer,s=t*e+e,n=this.cumulativeWeight,r=this.cumulativeWeightAdditive,a=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,n<1){const o=e*this._origIndex;this._mixBufferRegion(i,s,o,1-n,e)}r>0&&this._mixBufferRegionAdditive(i,s,this._addIndex*e,1,e);for(let o=e,h=e+e;o!==h;++o)if(i[o]!==i[o+e]){a.setValue(i,s);break}}saveOriginalState(){const t=this.binding,e=this.buffer,i=this.valueSize,s=i*this._origIndex;t.getValue(e,s);for(let n=i,r=s;n!==r;++n)e[n]=e[s+n%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=this.valueSize*3;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let i=t;i<e;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[e+i]=this.buffer[t+i]}_select(t,e,i,s,n){if(s>=.5)for(let r=0;r!==n;++r)t[e+r]=t[i+r]}_slerp(t,e,i,s){Zt.slerpFlat(t,e,t,e,t,i,s)}_slerpAdditive(t,e,i,s,n){const r=this._workIndex*n;Zt.multiplyQuaternionsFlat(t,r,t,e,t,i),Zt.slerpFlat(t,e,t,e,t,r,s)}_lerp(t,e,i,s,n){const r=1-s;for(let a=0;a!==n;++a){const o=e+a;t[o]=t[o]*r+t[i+a]*s}}_lerpAdditive(t,e,i,s,n){for(let r=0;r!==n;++r){const a=e+r;t[a]=t[a]+t[i+r]*s}}}const za="\\[\\]\\.:\\/",jd=new RegExp("["+za+"]","g"),Ba="[^"+za+"]",Qd="[^"+za.replace("\\.","")+"]",$d=/((?:WC+[\/:])*)/.source.replace("WC",Ba),tf=/(WCOD+)?/.source.replace("WCOD",Qd),ef=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Ba),sf=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Ba),nf=new RegExp("^"+$d+tf+ef+sf+"$"),rf=["material","materials","bones","map"];class af{constructor(t,e,i){const s=i||$.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,s)}getValue(t,e){this.bind();const i=this._targetGroup.nCachedObjects_,s=this._bindings[i];s!==void 0&&s.getValue(t,e)}setValue(t,e){const i=this._bindings;for(let s=this._targetGroup.nCachedObjects_,n=i.length;s!==n;++s)i[s].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].unbind()}}class ${constructor(t,e,i){this.path=e,this.parsedPath=i||$.parseTrackName(e),this.node=$.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,i){return t&&t.isAnimationObjectGroup?new $.Composite(t,e,i):new $(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(jd,"")}static parseTrackName(t){const e=nf.exec(t);if(e===null)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const i={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},s=i.nodeName&&i.nodeName.lastIndexOf(".");if(s!==void 0&&s!==-1){const n=i.nodeName.substring(s+1);rf.indexOf(n)!==-1&&(i.nodeName=i.nodeName.substring(0,s),i.objectName=n)}if(i.propertyName===null||i.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return i}static findNode(t,e){if(e===void 0||e===""||e==="."||e===-1||e===t.name||e===t.uuid)return t;if(t.skeleton){const i=t.skeleton.getBoneByName(e);if(i!==void 0)return i}if(t.children){const i=function(n){for(let r=0;r<n.length;r++){const a=n[r];if(a.name===e||a.uuid===e)return a;const o=i(a.children);if(o)return o}return null},s=i(t.children);if(s)return s}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const i=this.resolvedProperty;for(let s=0,n=i.length;s!==n;++s)t[e++]=i[s]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const i=this.resolvedProperty;for(let s=0,n=i.length;s!==n;++s)i[s]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const i=this.resolvedProperty;for(let s=0,n=i.length;s!==n;++s)i[s]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const i=this.resolvedProperty;for(let s=0,n=i.length;s!==n;++s)i[s]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,i=e.objectName,s=e.propertyName;let n=e.propertyIndex;if(t||(t=$.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){console.warn("THREE.PropertyBinding: No target node found for track: "+this.path+".");return}if(i){let h=e.objectIndex;switch(i){case"materials":if(!t.material){console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.materials){console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);return}t=t.material.materials;break;case"bones":if(!t.skeleton){console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);return}t=t.skeleton.bones;for(let c=0;c<t.length;c++)if(t[c].name===h){h=c;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material){console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);return}if(!t.material.map){console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);return}t=t.material.map;break;default:if(t[i]===void 0){console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.",this);return}t=t[i]}if(h!==void 0){if(t[h]===void 0){console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);return}t=t[h]}}const r=t[s];if(r===void 0){const h=e.nodeName;console.error("THREE.PropertyBinding: Trying to update property for track: "+h+"."+s+" but it wasn't found.",t);return}let a=this.Versioning.None;this.targetObject=t,t.isMaterial===!0?a=this.Versioning.NeedsUpdate:t.isObject3D===!0&&(a=this.Versioning.MatrixWorldNeedsUpdate);let o=this.BindingType.Direct;if(n!==void 0){if(s==="morphTargetInfluences"){if(!t.geometry){console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);return}if(!t.geometry.morphAttributes){console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);return}t.morphTargetDictionary[n]!==void 0&&(n=t.morphTargetDictionary[n])}o=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=n}else r.fromArray!==void 0&&r.toArray!==void 0?(o=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(o=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=s;this.getValue=this.GetterByBindingType[o],this.setValue=this.SetterByBindingTypeAndVersioning[o][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}$.Composite=af;$.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3};$.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2};$.prototype.GetterByBindingType=[$.prototype._getValue_direct,$.prototype._getValue_array,$.prototype._getValue_arrayElement,$.prototype._getValue_toArray];$.prototype.SetterByBindingTypeAndVersioning=[[$.prototype._setValue_direct,$.prototype._setValue_direct_setNeedsUpdate,$.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[$.prototype._setValue_array,$.prototype._setValue_array_setNeedsUpdate,$.prototype._setValue_array_setMatrixWorldNeedsUpdate],[$.prototype._setValue_arrayElement,$.prototype._setValue_arrayElement_setNeedsUpdate,$.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[$.prototype._setValue_fromArray,$.prototype._setValue_fromArray_setNeedsUpdate,$.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class iy{constructor(){this.isAnimationObjectGroup=!0,this.uuid=Jt(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const t={};this._indicesByUUID=t;for(let i=0,s=arguments.length;i!==s;++i)t[arguments[i].uuid]=i;this._paths=[],this._parsedPaths=[],this._bindings=[],this._bindingsIndicesByPath={};const e=this;this.stats={objects:{get total(){return e._objects.length},get inUse(){return this.total-e.nCachedObjects_}},get bindingsPerObject(){return e._bindings.length}}}add(){const t=this._objects,e=this._indicesByUUID,i=this._paths,s=this._parsedPaths,n=this._bindings,r=n.length;let a,o=t.length,h=this.nCachedObjects_;for(let c=0,u=arguments.length;c!==u;++c){const d=arguments[c],f=d.uuid;let p=e[f];if(p===void 0){p=o++,e[f]=p,t.push(d);for(let m=0,g=r;m!==g;++m)n[m].push(new $(d,i[m],s[m]))}else if(p<h){a=t[p];const m=--h,g=t[m];e[g.uuid]=p,t[p]=g,e[f]=m,t[m]=d;for(let x=0,y=r;x!==y;++x){const b=n[x],v=b[m];let _=b[p];b[p]=v,_===void 0&&(_=new $(d,i[x],s[x])),b[m]=_}}else t[p]!==a&&console.error("THREE.AnimationObjectGroup: Different objects with the same UUID detected. Clean the caches or recreate your infrastructure when reloading scenes.")}this.nCachedObjects_=h}remove(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,s=i.length;let n=this.nCachedObjects_;for(let r=0,a=arguments.length;r!==a;++r){const o=arguments[r],h=o.uuid,c=e[h];if(c!==void 0&&c>=n){const u=n++,d=t[u];e[d.uuid]=c,t[c]=d,e[h]=u,t[u]=o;for(let f=0,p=s;f!==p;++f){const m=i[f],g=m[u],x=m[c];m[c]=g,m[u]=x}}}this.nCachedObjects_=n}uncache(){const t=this._objects,e=this._indicesByUUID,i=this._bindings,s=i.length;let n=this.nCachedObjects_,r=t.length;for(let a=0,o=arguments.length;a!==o;++a){const h=arguments[a],c=h.uuid,u=e[c];if(u!==void 0)if(delete e[c],u<n){const d=--n,f=t[d],p=--r,m=t[p];e[f.uuid]=u,t[u]=f,e[m.uuid]=d,t[d]=m,t.pop();for(let g=0,x=s;g!==x;++g){const y=i[g],b=y[d],v=y[p];y[u]=b,y[d]=v,y.pop()}}else{const d=--r,f=t[d];d>0&&(e[f.uuid]=u),t[u]=f,t.pop();for(let p=0,m=s;p!==m;++p){const g=i[p];g[u]=g[d],g.pop()}}}this.nCachedObjects_=n}subscribe_(t,e){const i=this._bindingsIndicesByPath;let s=i[t];const n=this._bindings;if(s!==void 0)return n[s];const r=this._paths,a=this._parsedPaths,o=this._objects,h=o.length,c=this.nCachedObjects_,u=new Array(h);s=n.length,i[t]=s,r.push(t),a.push(e),n.push(u);for(let d=c,f=o.length;d!==f;++d){const p=o[d];u[d]=new $(p,t,e)}return u}unsubscribe_(t){const e=this._bindingsIndicesByPath,i=e[t];if(i!==void 0){const s=this._paths,n=this._parsedPaths,r=this._bindings,a=r.length-1,o=r[a],h=t[a];e[h]=i,r[i]=o,r.pop(),n[i]=n[a],n.pop(),s[i]=s[a],s.pop()}}}class of{constructor(t,e,i=null,s=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=i,this.blendMode=s;const n=e.tracks,r=n.length,a=new Array(r),o={endingStart:zi,endingEnd:zi};for(let h=0;h!==r;++h){const c=n[h].createInterpolant(null);a[h]=c,c.settings=o}this._interpolantSettings=o,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=Ac,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,i){if(t.fadeOut(e),this.fadeIn(e),i){const s=this._clip.duration,n=t._clip.duration,r=n/s,a=s/n;t.warp(1,r,e),this.warp(a,1,e)}return this}crossFadeTo(t,e,i){return t.crossFadeFrom(this,e,i)}stopFading(){const t=this._weightInterpolant;return t!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,i){const s=this._mixer,n=s.time,r=this.timeScale;let a=this._timeScaleInterpolant;a===null&&(a=s._lendControlInterpolant(),this._timeScaleInterpolant=a);const o=a.parameterPositions,h=a.sampleValues;return o[0]=n,o[1]=n+i,h[0]=t/r,h[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return t!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,i,s){if(!this.enabled){this._updateWeight(t);return}const n=this._startTime;if(n!==null){const o=(t-n)*i;o<0||i===0?e=0:(this._startTime=null,e=i*o)}e*=this._updateTimeScale(t);const r=this._updateTime(e),a=this._updateWeight(t);if(a>0){const o=this._interpolants,h=this._propertyBindings;switch(this.blendMode){case Ih:for(let c=0,u=o.length;c!==u;++c)o[c].evaluate(r),h[c].accumulateAdditive(a);break;case Qr:default:for(let c=0,u=o.length;c!==u;++c)o[c].evaluate(r),h[c].accumulate(s,a)}}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const i=this._weightInterpolant;if(i!==null){const s=i.evaluate(t)[0];e*=s,t>i.parameterPositions[1]&&(this.stopFading(),s===0&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const s=i.evaluate(t)[0];e*=s,t>i.parameterPositions[1]&&(this.stopWarping(),e===0?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,i=this.loop;let s=this.time+t,n=this._loopCount;const r=i===Tc;if(t===0)return n===-1?s:r&&(n&1)===1?e-s:s;if(i===Sc){n===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(s>=e)s=e;else if(s<0)s=0;else{this.time=s;break t}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=s,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(n===-1&&(t>=0?(n=0,this._setEndings(!0,this.repetitions===0,r)):this._setEndings(this.repetitions===0,!0,r)),s>=e||s<0){const a=Math.floor(s/e);s-=e*a,n+=Math.abs(a);const o=this.repetitions-n;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,s=t>0?e:0,this.time=s,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(o===1){const h=t<0;this._setEndings(h,!h,r)}else this._setEndings(!1,!1,r);this._loopCount=n,this.time=s,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:a})}}else this.time=s;if(r&&(n&1)===1)return e-s}return s}_setEndings(t,e,i){const s=this._interpolantSettings;i?(s.endingStart=Bi,s.endingEnd=Bi):(t?s.endingStart=this.zeroSlopeAtStart?Bi:zi:s.endingStart=Sn,e?s.endingEnd=this.zeroSlopeAtEnd?Bi:zi:s.endingEnd=Sn)}_scheduleFading(t,e,i){const s=this._mixer,n=s.time;let r=this._weightInterpolant;r===null&&(r=s._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,o=r.sampleValues;return a[0]=n,o[0]=e,a[1]=n+t,o[1]=i,this}}const hf=new Float32Array(1);class sy extends We{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const i=t._localRoot||this._root,s=t._clip.tracks,n=s.length,r=t._propertyBindings,a=t._interpolants,o=i.uuid,h=this._bindingsByRootAndName;let c=h[o];c===void 0&&(c={},h[o]=c);for(let u=0;u!==n;++u){const d=s[u],f=d.name;let p=c[f];if(p!==void 0)++p.referenceCount,r[u]=p;else{if(p=r[u],p!==void 0){p._cacheIndex===null&&(++p.referenceCount,this._addInactiveBinding(p,o,f));continue}const m=e&&e._propertyBindings[u].binding.parsedPath;p=new Kd($.create(i,f,m),d.ValueTypeName,d.getValueSize()),++p.referenceCount,this._addInactiveBinding(p,o,f),r[u]=p}a[u].resultBuffer=p.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(t._cacheIndex===null){const i=(t._localRoot||this._root).uuid,s=t._clip.uuid,n=this._actionsByClip[s];this._bindAction(t,n&&n.knownActions[0]),this._addInactiveAction(t,s,i)}const e=t._propertyBindings;for(let i=0,s=e.length;i!==s;++i){const n=e[i];n.useCount++===0&&(this._lendBinding(n),n.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let i=0,s=e.length;i!==s;++i){const n=e[i];--n.useCount===0&&(n.restoreOriginalState(),this._takeBackBinding(n))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return e!==null&&e<this._nActiveActions}_addInactiveAction(t,e,i){const s=this._actions,n=this._actionsByClip;let r=n[e];if(r===void 0)r={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,n[e]=r;else{const a=r.knownActions;t._byClipCacheIndex=a.length,a.push(t)}t._cacheIndex=s.length,s.push(t),r.actionByRoot[i]=t}_removeInactiveAction(t){const e=this._actions,i=e[e.length-1],s=t._cacheIndex;i._cacheIndex=s,e[s]=i,e.pop(),t._cacheIndex=null;const n=t._clip.uuid,r=this._actionsByClip,a=r[n],o=a.knownActions,h=o[o.length-1],c=t._byClipCacheIndex;h._byClipCacheIndex=c,o[c]=h,o.pop(),t._byClipCacheIndex=null;const u=a.actionByRoot,d=(t._localRoot||this._root).uuid;delete u[d],o.length===0&&delete r[n],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let i=0,s=e.length;i!==s;++i){const n=e[i];--n.referenceCount===0&&this._removeInactiveBinding(n)}}_lendAction(t){const e=this._actions,i=t._cacheIndex,s=this._nActiveActions++,n=e[s];t._cacheIndex=s,e[s]=t,n._cacheIndex=i,e[i]=n}_takeBackAction(t){const e=this._actions,i=t._cacheIndex,s=--this._nActiveActions,n=e[s];t._cacheIndex=s,e[s]=t,n._cacheIndex=i,e[i]=n}_addInactiveBinding(t,e,i){const s=this._bindingsByRootAndName,n=this._bindings;let r=s[e];r===void 0&&(r={},s[e]=r),r[i]=t,t._cacheIndex=n.length,n.push(t)}_removeInactiveBinding(t){const e=this._bindings,i=t.binding,s=i.rootNode.uuid,n=i.path,r=this._bindingsByRootAndName,a=r[s],o=e[e.length-1],h=t._cacheIndex;o._cacheIndex=h,e[h]=o,e.pop(),delete a[n],Object.keys(a).length===0&&delete r[s]}_lendBinding(t){const e=this._bindings,i=t._cacheIndex,s=this._nActiveBindings++,n=e[s];t._cacheIndex=s,e[s]=t,n._cacheIndex=i,e[i]=n}_takeBackBinding(t){const e=this._bindings,i=t._cacheIndex,s=--this._nActiveBindings,n=e[s];t._cacheIndex=s,e[s]=t,n._cacheIndex=i,e[i]=n}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let i=t[e];return i===void 0&&(i=new Zh(new Float32Array(2),new Float32Array(2),1,hf),i.__cacheIndex=e,t[e]=i),i}_takeBackControlInterpolant(t){const e=this._controlInterpolants,i=t.__cacheIndex,s=--this._nActiveControlInterpolants,n=e[s];t.__cacheIndex=s,e[s]=t,n.__cacheIndex=i,e[i]=n}clipAction(t,e,i){const s=e||this._root,n=s.uuid;let r=typeof t=="string"?En.findByName(s,t):t;const a=r!==null?r.uuid:t,o=this._actionsByClip[a];let h=null;if(i===void 0&&(r!==null?i=r.blendMode:i=Qr),o!==void 0){const u=o.actionByRoot[n];if(u!==void 0&&u.blendMode===i)return u;h=o.knownActions[0],r===null&&(r=h._clip)}if(r===null)return null;const c=new of(this,r,e,i);return this._bindAction(c,h),this._addInactiveAction(c,a,n),c}existingAction(t,e){const i=e||this._root,s=i.uuid,n=typeof t=="string"?En.findByName(i,t):t,r=n?n.uuid:t,a=this._actionsByClip[r];return a!==void 0&&a.actionByRoot[s]||null}stopAllAction(){const t=this._actions,e=this._nActiveActions;for(let i=e-1;i>=0;--i)t[i].stop();return this}update(t){t*=this.timeScale;const e=this._actions,i=this._nActiveActions,s=this.time+=t,n=Math.sign(t),r=this._accuIndex^=1;for(let h=0;h!==i;++h)e[h]._update(s,t,n,r);const a=this._bindings,o=this._nActiveBindings;for(let h=0;h!==o;++h)a[h].apply(r);return this}setTime(t){this.time=0;for(let e=0;e<this._actions.length;e++)this._actions[e].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,i=t.uuid,s=this._actionsByClip,n=s[i];if(n!==void 0){const r=n.knownActions;for(let a=0,o=r.length;a!==o;++a){const h=r[a];this._deactivateAction(h);const c=h._cacheIndex,u=e[e.length-1];h._cacheIndex=null,h._byClipCacheIndex=null,u._cacheIndex=c,e[c]=u,e.pop(),this._removeInactiveBindingsForAction(h)}delete s[i]}}uncacheRoot(t){const e=t.uuid,i=this._actionsByClip;for(const r in i){const a=i[r].actionByRoot,o=a[e];o!==void 0&&(this._deactivateAction(o),this._removeInactiveAction(o))}const s=this._bindingsByRootAndName,n=s[e];if(n!==void 0)for(const r in n){const a=n[r];a.restoreOriginalState(),this._removeInactiveBinding(a)}}uncacheAction(t,e){const i=this.existingAction(t,e);i!==null&&(this._deactivateAction(i),this._removeInactiveAction(i))}}class ny extends ta{constructor(t=1,e=1,i=1,s={}){super(t,e,s),this.isRenderTarget3D=!0,this.depth=i,this.texture=new Bh(null,t,e,i),this.texture.isRenderTargetTexture=!0}}class ry extends ta{constructor(t=1,e=1,i=1,s={}){super(t,e,s),this.isRenderTargetArray=!0,this.depth=i,this.texture=new zh(null,t,e,i),this.texture.isRenderTargetTexture=!0}}class tl{constructor(t){this.value=t}clone(){return new tl(this.value.clone===void 0?this.value:this.value.clone())}}let lf=0;class ay extends We{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:lf++}),this.name="",this.usage=An,this.uniforms=[]}add(t){return this.uniforms.push(t),this}remove(t){const e=this.uniforms.indexOf(t);return e!==-1&&this.uniforms.splice(e,1),this}setName(t){return this.name=t,this}setUsage(t){return this.usage=t,this}dispose(){return this.dispatchEvent({type:"dispose"}),this}copy(t){this.name=t.name,this.usage=t.usage;const e=t.uniforms;this.uniforms.length=0;for(let i=0,s=e.length;i<s;i++){const n=Array.isArray(e[i])?e[i]:[e[i]];for(let r=0;r<n.length;r++)this.uniforms.push(n[r].clone())}return this}clone(){return new this.constructor().copy(this)}}class oy extends oa{constructor(t,e,i=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}class hy{constructor(t,e,i,s,n){this.isGLBufferAttribute=!0,this.name="",this.buffer=t,this.type=e,this.itemSize=i,this.elementSize=s,this.count=n,this.version=0}set needsUpdate(t){t===!0&&this.version++}setBuffer(t){return this.buffer=t,this}setType(t,e){return this.type=t,this.elementSize=e,this}setItemSize(t){return this.itemSize=t,this}setCount(t){return this.count=t,this}}const Ho=new Y;class ly{constructor(t,e,i=0,s=1/0){this.ray=new As(t,e),this.near=i,this.far=s,this.camera=null,this.layers=new Fh,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e.isOrthographicCamera?(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e):console.error("THREE.Raycaster: Unsupported camera type: "+e.type)}setFromXRController(t){return Ho.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Ho),this}intersectObject(t,e=!0,i=[]){return Gr(t,this,i,e),i.sort(qo),i}intersectObjects(t,e=!0,i=[]){for(let s=0,n=t.length;s<n;s++)Gr(t[s],this,i,e);return i.sort(qo),i}}function qo(l,t){return l.distance-t.distance}function Gr(l,t,e,i){let s=!0;if(l.layers.test(t.layers)&&l.raycast(t,e)===!1&&(s=!1),s===!0&&i===!0){const n=l.children;for(let r=0,a=n.length;r<a;r++)Gr(n[r],t,e,!0)}}class cy{constructor(t=1,e=0,i=0){return this.radius=t,this.phi=e,this.theta=i,this}set(t,e,i){return this.radius=t,this.phi=e,this.theta=i,this}copy(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}makeSafe(){return this.phi=H(this.phi,1e-6,Math.PI-1e-6),this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,i){return this.radius=Math.sqrt(t*t+e*e+i*i),this.radius===0?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,i),this.phi=Math.acos(H(e/this.radius,-1,1))),this}clone(){return new this.constructor().copy(this)}}class uy{constructor(t=1,e=0,i=0){return this.radius=t,this.theta=e,this.y=i,this}set(t,e,i){return this.radius=t,this.theta=e,this.y=i,this}copy(t){return this.radius=t.radius,this.theta=t.theta,this.y=t.y,this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,i){return this.radius=Math.sqrt(t*t+i*i),this.theta=Math.atan2(t,i),this.y=e,this}clone(){return new this.constructor().copy(this)}}class el{constructor(t,e,i,s){el.prototype.isMatrix2=!0,this.elements=[1,0,0,1],t!==void 0&&this.set(t,e,i,s)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let i=0;i<4;i++)this.elements[i]=t[i+e];return this}set(t,e,i,s){const n=this.elements;return n[0]=t,n[2]=e,n[1]=i,n[3]=s,this}}const Xo=new B;class dy{constructor(t=new B(1/0,1/0),e=new B(-1/0,-1/0)){this.isBox2=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Xo.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}clone(){return new this.constructor().copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=1/0,this.max.x=this.max.y=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y}getCenter(t){return this.isEmpty()?t.set(0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}containsPoint(t){return t.x>=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Xo).distanceTo(t)}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}const Yo=new w,fn=new w;class fy{constructor(t=new w,e=new w){this.start=t,this.end=e}set(t,e){return this.start.copy(t),this.end.copy(e),this}copy(t){return this.start.copy(t.start),this.end.copy(t.end),this}getCenter(t){return t.addVectors(this.start,this.end).multiplyScalar(.5)}delta(t){return t.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(t,e){return this.delta(e).multiplyScalar(t).add(this.start)}closestPointToPointParameter(t,e){Yo.subVectors(t,this.start),fn.subVectors(this.end,this.start);const i=fn.dot(fn);let n=fn.dot(Yo)/i;return e&&(n=H(n,0,1)),n}closestPointToPoint(t,e,i){const s=this.closestPointToPointParameter(t,e);return this.delta(i).multiplyScalar(s).add(this.start)}applyMatrix4(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this}equals(t){return t.start.equals(this.start)&&t.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}const Jo=new w;class py extends tt{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const i=new Z,s=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let r=0,a=1,o=32;r<o;r++,a++){const h=r/o*Math.PI*2,c=a/o*Math.PI*2;s.push(Math.cos(h),Math.sin(h),1,Math.cos(c),Math.sin(c),1)}i.setAttribute("position",new O(s,3));const n=new Gt({fog:!1,toneMapped:!1});this.cone=new Fe(i,n),this.add(this.cone),this.update()}dispose(){this.cone.geometry.dispose(),this.cone.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),this.parent?(this.parent.updateWorldMatrix(!0),this.matrix.copy(this.parent.matrixWorld).invert().multiply(this.light.matrixWorld)):this.matrix.copy(this.light.matrixWorld),this.matrixWorld.copy(this.light.matrixWorld);const t=this.light.distance?this.light.distance:1e3,e=t*Math.tan(this.light.angle);this.cone.scale.set(e,e,t),Jo.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(Jo),this.color!==void 0?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}}const Ue=new w,pn=new Y,Ir=new Y;class my extends Fe{constructor(t){const e=il(t),i=new Z,s=[],n=[],r=new V(0,0,1),a=new V(0,1,0);for(let h=0;h<e.length;h++){const c=e[h];c.parent&&c.parent.isBone&&(s.push(0,0,0),s.push(0,0,0),n.push(r.r,r.g,r.b),n.push(a.r,a.g,a.b))}i.setAttribute("position",new O(s,3)),i.setAttribute("color",new O(n,3));const o=new Gt({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0});super(i,o),this.isSkeletonHelper=!0,this.type="SkeletonHelper",this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1}updateMatrixWorld(t){const e=this.bones,i=this.geometry,s=i.getAttribute("position");Ir.copy(this.root.matrixWorld).invert();for(let n=0,r=0;n<e.length;n++){const a=e[n];a.parent&&a.parent.isBone&&(pn.multiplyMatrices(Ir,a.matrixWorld),Ue.setFromMatrixPosition(pn),s.setXYZ(r,Ue.x,Ue.y,Ue.z),pn.multiplyMatrices(Ir,a.parent.matrixWorld),Ue.setFromMatrixPosition(pn),s.setXYZ(r+1,Ue.x,Ue.y,Ue.z),r+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose()}}function il(l){const t=[];l.isBone===!0&&t.push(l);for(let e=0;e<l.children.length;e++)t.push.apply(t,il(l.children[e]));return t}class gy extends Vt{constructor(t,e,i){const s=new Is(e,4,2),n=new Di({wireframe:!0,fog:!1,toneMapped:!1});super(s,n),this.light=t,this.color=i,this.type="PointLightHelper",this.matrix=this.light.matrixWorld,this.matrixAutoUpdate=!1,this.update()}dispose(){this.geometry.dispose(),this.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.color!==void 0?this.material.color.set(this.color):this.material.color.copy(this.light.color)}}const cf=new w,Zo=new V,Ko=new V;class yy extends tt{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="HemisphereLightHelper";const s=new Vn(e);s.rotateY(Math.PI*.5),this.material=new Di({wireframe:!0,fog:!1,toneMapped:!1}),this.color===void 0&&(this.material.vertexColors=!0);const n=s.getAttribute("position"),r=new Float32Array(n.count*3);s.setAttribute("color",new dt(r,3)),this.add(new Vt(s,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const t=this.children[0];if(this.color!==void 0)this.material.color.set(this.color);else{const e=t.geometry.getAttribute("color");Zo.copy(this.light.color),Ko.copy(this.light.groundColor);for(let i=0,s=e.count;i<s;i++){const n=i<s/2?Zo:Ko;e.setXYZ(i,n.r,n.g,n.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(cf.setFromMatrixPosition(this.light.matrixWorld).negate())}}class xy extends Fe{constructor(t=10,e=10,i=4473924,s=8947848){i=new V(i),s=new V(s);const n=e/2,r=t/e,a=t/2,o=[],h=[];for(let d=0,f=0,p=-a;d<=e;d++,p+=r){o.push(-a,0,p,a,0,p),o.push(p,0,-a,p,0,a);const m=d===n?i:s;m.toArray(h,f),f+=3,m.toArray(h,f),f+=3,m.toArray(h,f),f+=3,m.toArray(h,f),f+=3}const c=new Z;c.setAttribute("position",new O(o,3)),c.setAttribute("color",new O(h,3));const u=new Gt({vertexColors:!0,toneMapped:!1});super(c,u),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}class by extends Fe{constructor(t=10,e=16,i=8,s=64,n=4473924,r=8947848){n=new V(n),r=new V(r);const a=[],o=[];if(e>1)for(let u=0;u<e;u++){const d=u/e*(Math.PI*2),f=Math.sin(d)*t,p=Math.cos(d)*t;a.push(0,0,0),a.push(f,0,p);const m=u&1?n:r;o.push(m.r,m.g,m.b),o.push(m.r,m.g,m.b)}for(let u=0;u<i;u++){const d=u&1?n:r,f=t-t/i*u;for(let p=0;p<s;p++){let m=p/s*(Math.PI*2),g=Math.sin(m)*f,x=Math.cos(m)*f;a.push(g,0,x),o.push(d.r,d.g,d.b),m=(p+1)/s*(Math.PI*2),g=Math.sin(m)*f,x=Math.cos(m)*f,a.push(g,0,x),o.push(d.r,d.g,d.b)}}const h=new Z;h.setAttribute("position",new O(a,3)),h.setAttribute("color",new O(o,3));const c=new Gt({vertexColors:!0,toneMapped:!1});super(h,c),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}const jo=new w,mn=new w,Qo=new w;class vy extends tt{constructor(t,e,i){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=i,this.type="DirectionalLightHelper",e===void 0&&(e=1);let s=new Z;s.setAttribute("position",new O([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const n=new Gt({fog:!1,toneMapped:!1});this.lightPlane=new ni(s,n),this.add(this.lightPlane),s=new Z,s.setAttribute("position",new O([0,0,0,0,0,1],3)),this.targetLine=new ni(s,n),this.add(this.targetLine),this.update()}dispose(){this.lightPlane.geometry.dispose(),this.lightPlane.material.dispose(),this.targetLine.geometry.dispose(),this.targetLine.material.dispose()}update(){this.light.updateWorldMatrix(!0,!1),this.light.target.updateWorldMatrix(!0,!1),jo.setFromMatrixPosition(this.light.matrixWorld),mn.setFromMatrixPosition(this.light.target.matrixWorld),Qo.subVectors(mn,jo),this.lightPlane.lookAt(mn),this.color!==void 0?(this.lightPlane.material.color.set(this.color),this.targetLine.material.color.set(this.color)):(this.lightPlane.material.color.copy(this.light.color),this.targetLine.material.color.copy(this.light.color)),this.targetLine.lookAt(mn),this.targetLine.scale.z=Qo.length()}}const gn=new w,ft=new sa;class wy extends Fe{constructor(t){const e=new Z,i=new Gt({color:16777215,vertexColors:!0,toneMapped:!1}),s=[],n=[],r={};a("n1","n2"),a("n2","n4"),a("n4","n3"),a("n3","n1"),a("f1","f2"),a("f2","f4"),a("f4","f3"),a("f3","f1"),a("n1","f1"),a("n2","f2"),a("n3","f3"),a("n4","f4"),a("p","n1"),a("p","n2"),a("p","n3"),a("p","n4"),a("u1","u2"),a("u2","u3"),a("u3","u1"),a("c","t"),a("p","c"),a("cn1","cn2"),a("cn3","cn4"),a("cf1","cf2"),a("cf3","cf4");function a(p,m){o(p),o(m)}function o(p){s.push(0,0,0),n.push(0,0,0),r[p]===void 0&&(r[p]=[]),r[p].push(s.length/3-1)}e.setAttribute("position",new O(s,3)),e.setAttribute("color",new O(n,3)),super(e,i),this.type="CameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=r,this.update();const h=new V(16755200),c=new V(16711680),u=new V(43775),d=new V(16777215),f=new V(3355443);this.setColors(h,c,u,d,f)}setColors(t,e,i,s,n){const a=this.geometry.getAttribute("color");a.setXYZ(0,t.r,t.g,t.b),a.setXYZ(1,t.r,t.g,t.b),a.setXYZ(2,t.r,t.g,t.b),a.setXYZ(3,t.r,t.g,t.b),a.setXYZ(4,t.r,t.g,t.b),a.setXYZ(5,t.r,t.g,t.b),a.setXYZ(6,t.r,t.g,t.b),a.setXYZ(7,t.r,t.g,t.b),a.setXYZ(8,t.r,t.g,t.b),a.setXYZ(9,t.r,t.g,t.b),a.setXYZ(10,t.r,t.g,t.b),a.setXYZ(11,t.r,t.g,t.b),a.setXYZ(12,t.r,t.g,t.b),a.setXYZ(13,t.r,t.g,t.b),a.setXYZ(14,t.r,t.g,t.b),a.setXYZ(15,t.r,t.g,t.b),a.setXYZ(16,t.r,t.g,t.b),a.setXYZ(17,t.r,t.g,t.b),a.setXYZ(18,t.r,t.g,t.b),a.setXYZ(19,t.r,t.g,t.b),a.setXYZ(20,t.r,t.g,t.b),a.setXYZ(21,t.r,t.g,t.b),a.setXYZ(22,t.r,t.g,t.b),a.setXYZ(23,t.r,t.g,t.b),a.setXYZ(24,e.r,e.g,e.b),a.setXYZ(25,e.r,e.g,e.b),a.setXYZ(26,e.r,e.g,e.b),a.setXYZ(27,e.r,e.g,e.b),a.setXYZ(28,e.r,e.g,e.b),a.setXYZ(29,e.r,e.g,e.b),a.setXYZ(30,e.r,e.g,e.b),a.setXYZ(31,e.r,e.g,e.b),a.setXYZ(32,i.r,i.g,i.b),a.setXYZ(33,i.r,i.g,i.b),a.setXYZ(34,i.r,i.g,i.b),a.setXYZ(35,i.r,i.g,i.b),a.setXYZ(36,i.r,i.g,i.b),a.setXYZ(37,i.r,i.g,i.b),a.setXYZ(38,s.r,s.g,s.b),a.setXYZ(39,s.r,s.g,s.b),a.setXYZ(40,n.r,n.g,n.b),a.setXYZ(41,n.r,n.g,n.b),a.setXYZ(42,n.r,n.g,n.b),a.setXYZ(43,n.r,n.g,n.b),a.setXYZ(44,n.r,n.g,n.b),a.setXYZ(45,n.r,n.g,n.b),a.setXYZ(46,n.r,n.g,n.b),a.setXYZ(47,n.r,n.g,n.b),a.setXYZ(48,n.r,n.g,n.b),a.setXYZ(49,n.r,n.g,n.b),a.needsUpdate=!0}update(){const t=this.geometry,e=this.pointMap,i=1,s=1;ft.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse);const n=this.camera.coordinateSystem===Te?-1:0;pt("c",e,t,ft,0,0,n),pt("t",e,t,ft,0,0,1),pt("n1",e,t,ft,-i,-s,n),pt("n2",e,t,ft,i,-s,n),pt("n3",e,t,ft,-i,s,n),pt("n4",e,t,ft,i,s,n),pt("f1",e,t,ft,-i,-s,1),pt("f2",e,t,ft,i,-s,1),pt("f3",e,t,ft,-i,s,1),pt("f4",e,t,ft,i,s,1),pt("u1",e,t,ft,i*.7,s*1.1,n),pt("u2",e,t,ft,-i*.7,s*1.1,n),pt("u3",e,t,ft,0,s*2,n),pt("cf1",e,t,ft,-i,0,1),pt("cf2",e,t,ft,i,0,1),pt("cf3",e,t,ft,0,-s,1),pt("cf4",e,t,ft,0,s,1),pt("cn1",e,t,ft,-i,0,n),pt("cn2",e,t,ft,i,0,n),pt("cn3",e,t,ft,0,-s,n),pt("cn4",e,t,ft,0,s,n),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}function pt(l,t,e,i,s,n,r){gn.set(s,n,r).unproject(i);const a=t[l];if(a!==void 0){const o=e.getAttribute("position");for(let h=0,c=a.length;h<c;h++)o.setXYZ(a[h],gn.x,gn.y,gn.z)}}const yn=new Ut;class _y extends Fe{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),s=new Float32Array(24),n=new Z;n.setIndex(new dt(i,1)),n.setAttribute("position",new dt(s,3)),super(n,new Gt({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(t){if(t!==void 0&&console.warn("THREE.BoxHelper: .update() has no longer arguments."),this.object!==void 0&&yn.setFromObject(this.object),yn.isEmpty())return;const e=yn.min,i=yn.max,s=this.geometry.attributes.position,n=s.array;n[0]=i.x,n[1]=i.y,n[2]=i.z,n[3]=e.x,n[4]=i.y,n[5]=i.z,n[6]=e.x,n[7]=e.y,n[8]=i.z,n[9]=i.x,n[10]=e.y,n[11]=i.z,n[12]=i.x,n[13]=i.y,n[14]=e.z,n[15]=e.x,n[16]=i.y,n[17]=e.z,n[18]=e.x,n[19]=e.y,n[20]=e.z,n[21]=i.x,n[22]=e.y,n[23]=e.z,s.needsUpdate=!0,this.geometry.computeBoundingSphere()}setFromObject(t){return this.object=t,this.update(),this}copy(t,e){return super.copy(t,e),this.object=t.object,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class My extends Fe{constructor(t,e=16776960){const i=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]),s=[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],n=new Z;n.setIndex(new dt(i,1)),n.setAttribute("position",new O(s,3)),super(n,new Gt({color:e,toneMapped:!1})),this.box=t,this.type="Box3Helper",this.geometry.computeBoundingSphere()}updateMatrixWorld(t){const e=this.box;e.isEmpty()||(e.getCenter(this.position),e.getSize(this.scale),this.scale.multiplyScalar(.5),super.updateMatrixWorld(t))}dispose(){this.geometry.dispose(),this.material.dispose()}}class Sy extends ni{constructor(t,e=1,i=16776960){const s=i,n=[1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],r=new Z;r.setAttribute("position",new O(n,3)),r.computeBoundingSphere(),super(r,new Gt({color:s,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const a=[1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],o=new Z;o.setAttribute("position",new O(a,3)),o.computeBoundingSphere(),this.add(new Vt(o,new Di({color:s,opacity:.2,transparent:!0,depthWrite:!1,toneMapped:!1})))}updateMatrixWorld(t){this.position.set(0,0,0),this.scale.set(.5*this.size,.5*this.size,1),this.lookAt(this.plane.normal),this.translateZ(-this.plane.constant),super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose(),this.children[0].geometry.dispose(),this.children[0].material.dispose()}}const $o=new w;let xn,Cr;class Ay extends tt{constructor(t=new w(0,0,1),e=new w(0,0,0),i=1,s=16776960,n=i*.2,r=n*.2){super(),this.type="ArrowHelper",xn===void 0&&(xn=new Z,xn.setAttribute("position",new O([0,0,0,0,1,0],3)),Cr=new Ts(0,.5,1,5,1),Cr.translate(0,-.5,0)),this.position.copy(e),this.line=new ni(xn,new Gt({color:s,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new Vt(Cr,new Di({color:s,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(t),this.setLength(i,n,r)}setDirection(t){if(t.y>.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{$o.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle($o,e)}}setLength(t,e=t*.2,i=e*.2){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(i,e,i),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class Ty extends Fe{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],i=[1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],s=new Z;s.setAttribute("position",new O(e,3)),s.setAttribute("color",new O(i,3));const n=new Gt({vertexColors:!0,toneMapped:!1});super(s,n),this.type="AxesHelper"}setColors(t,e,i){const s=new V,n=this.geometry.attributes.color.array;return s.set(t),s.toArray(n,0),s.toArray(n,3),s.set(e),s.toArray(n,6),s.toArray(n,9),s.set(i),s.toArray(n,12),s.toArray(n,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class Iy{constructor(){this.type="ShapePath",this.color=new V,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new Fn,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,i,s){return this.currentPath.quadraticCurveTo(t,e,i,s),this}bezierCurveTo(t,e,i,s,n,r){return this.currentPath.bezierCurveTo(t,e,i,s,n,r),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(x){const y=[];for(let b=0,v=x.length;b<v;b++){const _=x[b],M=new Ri;M.curves=_.curves,y.push(M)}return y}function i(x,y){const b=y.length;let v=!1;for(let _=b-1,M=0;M<b;_=M++){let A=y[_],S=y[M],C=S.x-A.x,z=S.y-A.y;if(Math.abs(z)>Number.EPSILON){if(z<0&&(A=y[M],C=-C,S=y[_],z=-z),x.y<A.y||x.y>S.y)continue;if(x.y===A.y){if(x.x===A.x)return!0}else{const k=z*(x.x-A.x)-C*(x.y-A.y);if(k===0)return!0;if(k<0)continue;v=!v}}else{if(x.y!==A.y)continue;if(S.x<=x.x&&x.x<=A.x||A.x<=x.x&&x.x<=S.x)return!0}}return v}const s=ze.isClockWise,n=this.subPaths;if(n.length===0)return[];let r,a,o;const h=[];if(n.length===1)return a=n[0],o=new Ri,o.curves=a.curves,h.push(o),h;let c=!s(n[0].getPoints());c=t?!c:c;const u=[],d=[];let f=[],p=0,m;d[p]=void 0,f[p]=[];for(let x=0,y=n.length;x<y;x++)a=n[x],m=a.getPoints(),r=s(m),r=t?!r:r,r?(!c&&d[p]&&p++,d[p]={s:new Ri,p:m},d[p].s.curves=a.curves,c&&p++,f[p]=[]):f[p].push({h:a,p:m[0]});if(!d[0])return e(n);if(d.length>1){let x=!1,y=0;for(let b=0,v=d.length;b<v;b++)u[b]=[];for(let b=0,v=d.length;b<v;b++){const _=f[b];for(let M=0;M<_.length;M++){const A=_[M];let S=!0;for(let C=0;C<d.length;C++)i(A.p,d[C].p)&&(b!==C&&y++,S?(S=!1,u[C].push(A)):x=!0);S&&u[b].push(A)}}y>0&&x===!1&&(f=u)}let g;for(let x=0,y=d.length;x<y;x++){o=d[x].s,h.push(o),g=f[x];for(let b=0,v=g.length;b<v;b++)o.holes.push(g[b].h)}return h}}class Cy extends We{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}function uf(l,t){const e=l.image&&l.image.width?l.image.width/l.image.height:1;return e>t?(l.repeat.x=1,l.repeat.y=e/t,l.offset.x=0,l.offset.y=(1-l.repeat.y)/2):(l.repeat.x=t/e,l.repeat.y=1,l.offset.x=(1-l.repeat.x)/2,l.offset.y=0),l}function df(l,t){const e=l.image&&l.image.width?l.image.width/l.image.height:1;return e>t?(l.repeat.x=t/e,l.repeat.y=1,l.offset.x=(1-l.repeat.x)/2,l.offset.y=0):(l.repeat.x=1,l.repeat.y=e/t,l.offset.x=0,l.offset.y=(1-l.repeat.y)/2),l}function ff(l){return l.repeat.x=1,l.repeat.y=1,l.offset.x=0,l.offset.y=0,l}function pf(l,t,e,i){const s=mf(i);switch(e){case Dl:return l*t;case Vl:return l*t;case Gl:return l*t*2;case Ah:return l*t/s.components*s.byteLength;case Th:return l*t/s.components*s.byteLength;case Wl:return l*t*2/s.components*s.byteLength;case Hl:return l*t*2/s.components*s.byteLength;case Ul:return l*t*3/s.components*s.byteLength;case ys:return l*t*4/s.components*s.byteLength;case ql:return l*t*4/s.components*s.byteLength;case Xl:case Yl:return Math.floor((l+3)/4)*Math.floor((t+3)/4)*8;case Jl:case Zl:return Math.floor((l+3)/4)*Math.floor((t+3)/4)*16;case jl:case $l:return Math.max(l,16)*Math.max(t,8)/4;case Kl:case Ql:return Math.max(l,8)*Math.max(t,8)/2;case tc:case ec:return Math.floor((l+3)/4)*Math.floor((t+3)/4)*8;case ic:return Math.floor((l+3)/4)*Math.floor((t+3)/4)*16;case sc:return Math.floor((l+3)/4)*Math.floor((t+3)/4)*16;case nc:return Math.floor((l+4)/5)*Math.floor((t+3)/4)*16;case rc:return Math.floor((l+4)/5)*Math.floor((t+4)/5)*16;case ac:return Math.floor((l+5)/6)*Math.floor((t+4)/5)*16;case oc:return Math.floor((l+5)/6)*Math.floor((t+5)/6)*16;case hc:return Math.floor((l+7)/8)*Math.floor((t+4)/5)*16;case lc:return Math.floor((l+7)/8)*Math.floor((t+5)/6)*16;case cc:return Math.floor((l+7)/8)*Math.floor((t+7)/8)*16;case uc:return Math.floor((l+9)/10)*Math.floor((t+4)/5)*16;case dc:return Math.floor((l+9)/10)*Math.floor((t+5)/6)*16;case fc:return Math.floor((l+9)/10)*Math.floor((t+7)/8)*16;case pc:return Math.floor((l+9)/10)*Math.floor((t+9)/10)*16;case mc:return Math.floor((l+11)/12)*Math.floor((t+9)/10)*16;case gc:return Math.floor((l+11)/12)*Math.floor((t+11)/12)*16;case yc:case xc:case bc:return Math.ceil(l/4)*Math.ceil(t/4)*16;case vc:case wc:return Math.ceil(l/4)*Math.ceil(t/4)*8;case _c:case Mc:return Math.ceil(l/4)*Math.ceil(t/4)*16}throw new Error(`Unable to determine texture byte length for ${e} format.`)}function mf(l){switch(l){case Sh:case Bl:return{byteLength:1,components:1};case Pl:case Fl:case El:return{byteLength:2,components:1};case Rl:case Ll:return{byteLength:2,components:4};case jr:case kl:case Li:return{byteLength:4,components:1};case Nl:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${l}.`)}const zy={contain:uf,cover:df,fill:ff,getByteLength:pf};typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:_h}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=_h);function sl(l){return l>=.7?"active":l>=.4?"dormant":l>=.1?"silent":"unavailable"}const nl={active:"#10b981",dormant:"#f59e0b",silent:"#8b5cf6",unavailable:"#6b7280"},By={active:"Easily retrievable (retention ≥ 70%)",dormant:"Retrievable with effort (4070%)",silent:"Difficult, needs cues (1040%)",unavailable:"Needs reinforcement (< 10%)"},zr={aha:"#FFD700",confusion:"#EF4444",failure:"#9CA3AF"},Fy={aha:"Aha moments and breakthroughs",confusion:"Confusions and weak spots",failure:"Failures and guardrails"};function th(l,t){return t==="state"?nl[sl(l.retention)]:t==="ahagraph"?rl(l)??ka[l.type]??"#8B95A5":ka[l.type]||"#8B95A5"}function rl(l){const t=new Set((l.tags??[]).map(e=>e.toLowerCase()));return t.has("aha")?zr.aha:t.has("confusion")||t.has("weak-spot")?zr.confusion:t.has("failure")||t.has("guardrail")?zr.failure:null}let is=null;function gf(){if(is)return is;const l=128,t=document.createElement("canvas");t.width=l,t.height=l;const e=t.getContext("2d");if(!e)return is=new gt,is;const i=e.createRadialGradient(l/2,l/2,0,l/2,l/2,l/2);i.addColorStop(0,"rgba(255, 255, 255, 1.0)"),i.addColorStop(.25,"rgba(255, 255, 255, 0.7)"),i.addColorStop(.55,"rgba(255, 255, 255, 0.2)"),i.addColorStop(1,"rgba(255, 255, 255, 0.0)"),e.fillStyle=i,e.fillRect(0,0,l,l);const s=new Nh(t);return s.needsUpdate=!0,is=s,s}function eh(l){if(l===0||l===1)return l;const t=.3;return Math.pow(2,-10*l)*Math.sin((l-t/4)*(2*Math.PI)/t)+1}function yf(l){return l*l*((1.70158+1)*l-1.70158)}class Py{constructor(){T(this,"group");T(this,"meshMap",new Map);T(this,"glowMap",new Map);T(this,"positions",new Map);T(this,"labelSprites",new Map);T(this,"hoveredNode",null);T(this,"selectedNode",null);T(this,"colorMode","type");T(this,"materializingNodes",[]);T(this,"dissolvingNodes",[]);T(this,"growingNodes",[]);this.group=new Oh}setColorMode(t){if(this.colorMode!==t){this.colorMode=t;for(const[e,i]of this.meshMap){const s=i.userData.retention??0,n=i.userData.type??"fact",r=Array.isArray(i.userData.tags)?i.userData.tags:[],o=th({type:n,retention:s,tags:r},t),h=new V(o),c=i.material;c.color.copy(h),c.emissive.copy(h);const u=this.glowMap.get(e);u&&u.material.color.copy(h)}}}createNodes(t){const e=(1+Math.sqrt(5))/2,i=t.length;for(let s=0;s<i;s++){const n=t[s],r=1-2*s/(i-1||1),a=Math.sqrt(1-r*r),o=2*Math.PI*s/e,h=30+i*.5,c=new w(a*Math.cos(o)*h,r*h,a*Math.sin(o)*h);n.isCenter&&c.set(0,0,0),this.positions.set(n.id,c),this.createNodeMeshes(n,c,1)}return this.positions}createNodeMeshes(t,e,i){const s=.5+t.retention*2,n=th(t,this.colorMode),r=(t.suppression_count??0)>0,a=new Is(s,16,16),o=new Aa({color:new V(n),emissive:new V(n),emissiveIntensity:r?0:.3+t.retention*.5,roughness:.3,metalness:.1,transparent:!0,opacity:r?.2:.3+t.retention*.7}),h=new Vt(a,o);h.position.copy(e),h.scale.setScalar(i),h.userData={nodeId:t.id,type:t.type,retention:t.retention,tags:t.tags},this.meshMap.set(t.id,h),this.group.add(h);const c=new fs({map:gf(),color:new V(n),transparent:!0,opacity:i>0?r?.1:.3+t.retention*.35:0,blending:wl,depthWrite:!1}),u=new cs(c);u.scale.set(s*6*i,s*6*i,1),u.position.copy(e),u.userData={isGlow:!0,nodeId:t.id},this.glowMap.set(t.id,u),this.group.add(u);const d=t.label||t.type,f=this.createTextSprite(d,"#94a3b8");return f.position.copy(e),f.position.y+=s*2+1.5,f.userData={isLabel:!0,nodeId:t.id,offset:s*2+1.5},this.group.add(f),this.labelSprites.set(t.id,f),{mesh:h,glow:u,label:f,size:s}}addNode(t,e,i={}){const s=(e==null?void 0:e.clone())??new w((Math.random()-.5)*40,(Math.random()-.5)*40,(Math.random()-.5)*40);this.positions.set(t.id,s);const{mesh:n,glow:r,label:a}=this.createNodeMeshes(t,s,0);return n.scale.setScalar(.001),r.scale.set(.001,.001,1),r.material.opacity=0,a.material.opacity=0,i.isBirthRitual?(n.visible=!1,r.visible=!1,a.visible=!1,n.userData.birthRitualPending={totalFrames:30,targetScale:.5+t.retention*2}):this.materializingNodes.push({id:t.id,frame:0,totalFrames:30,mesh:n,glow:r,label:a,targetScale:.5+t.retention*2}),s}igniteNode(t){const e=this.meshMap.get(t),i=this.glowMap.get(t),s=this.labelSprites.get(t);if(!e||!i||!s)return;const n=e.userData.birthRitualPending;n&&(e.visible=!0,i.visible=!0,s.visible=!0,delete e.userData.birthRitualPending,this.materializingNodes.push({id:t,frame:0,totalFrames:n.totalFrames,mesh:e,glow:i,label:s,targetScale:n.targetScale}))}removeNode(t){const e=this.meshMap.get(t),i=this.glowMap.get(t),s=this.labelSprites.get(t);!e||!i||!s||(this.materializingNodes=this.materializingNodes.filter(n=>n.id!==t),this.dissolvingNodes.push({id:t,frame:0,totalFrames:60,mesh:e,glow:i,label:s,originalScale:e.scale.x}))}growNode(t,e){const i=this.meshMap.get(t);if(!i)return;const s=i.scale.x,n=.5+e*2;i.userData.retention=e,this.growingNodes.push({id:t,frame:0,totalFrames:30,startScale:s,targetScale:n})}createTextSprite(t,e){const i=document.createElement("canvas"),s=i.getContext("2d");if(!s){const x=new gt;return new cs(new fs({map:x,transparent:!0,opacity:0}))}i.width=512,i.height=64;const n=t.length>40?t.slice(0,37)+"...":t;s.clearRect(0,0,i.width,i.height),s.font='600 22px -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif';const a=s.measureText(n).width,h=Math.min(a+14*2,i.width-4),c=40,u=(i.width-h)/2,d=(i.height-c)/2,f=c/2;s.fillStyle="rgba(10, 16, 28, 0.82)",s.beginPath(),s.moveTo(u+f,d),s.lineTo(u+h-f,d),s.quadraticCurveTo(u+h,d,u+h,d+f),s.lineTo(u+h,d+c-f),s.quadraticCurveTo(u+h,d+c,u+h-f,d+c),s.lineTo(u+f,d+c),s.quadraticCurveTo(u,d+c,u,d+c-f),s.lineTo(u,d+f),s.quadraticCurveTo(u,d,u+f,d),s.closePath(),s.fill(),s.strokeStyle="rgba(148, 163, 184, 0.18)",s.lineWidth=1,s.stroke(),s.textAlign="center",s.textBaseline="middle",s.fillStyle=e,s.fillText(n,i.width/2,i.height/2+1);const p=new Nh(i);p.needsUpdate=!0;const m=new fs({map:p,transparent:!0,opacity:0,depthTest:!1,sizeAttenuation:!0}),g=new cs(m);return g.scale.set(9,1.2,1),g}updatePositions(){this.group.children.forEach(t=>{if(t.userData.nodeId){const e=this.positions.get(t.userData.nodeId);if(!e)return;t.userData.isGlow?t.position.copy(e):t.userData.isLabel?(t.position.copy(e),t.position.y+=t.userData.offset):t instanceof Vt&&t.position.copy(e)}})}animate(t,e,i,s=1){var r,a;for(let o=this.materializingNodes.length-1;o>=0;o--){const h=this.materializingNodes[o];h.frame++;const c=Math.min(h.frame/h.totalFrames,1),u=eh(c);if(h.mesh.scale.setScalar(Math.max(.001,u)),h.frame>=5){const d=Math.min((h.frame-5)/5,1),f=h.glow.material;f.opacity=d*.4;const p=h.targetScale*6*u;h.glow.scale.set(p,p,1)}if(h.frame>=40){const d=Math.min((h.frame-40)/20,1);h.label.material.opacity=d*.9}h.frame>=60&&this.materializingNodes.splice(o,1)}for(let o=this.dissolvingNodes.length-1;o>=0;o--){const h=this.dissolvingNodes[o];h.frame++;const c=Math.min(h.frame/h.totalFrames,1),u=1-yf(c),d=Math.max(.001,h.originalScale*u);h.mesh.scale.setScalar(d);const f=d*6;h.glow.scale.set(f,f,1);const p=h.mesh.material;p.opacity*=.97,h.glow.material.opacity*=.95,h.label.material.opacity*=.93,h.frame>=h.totalFrames&&(this.group.remove(h.mesh),this.group.remove(h.glow),this.group.remove(h.label),h.mesh.geometry.dispose(),h.mesh.material.dispose(),(r=h.glow.material.map)==null||r.dispose(),h.glow.material.dispose(),(a=h.label.material.map)==null||a.dispose(),h.label.material.dispose(),this.meshMap.delete(h.id),this.glowMap.delete(h.id),this.labelSprites.delete(h.id),this.positions.delete(h.id),this.dissolvingNodes.splice(o,1))}for(let o=this.growingNodes.length-1;o>=0;o--){const h=this.growingNodes[o];h.frame++;const c=Math.min(h.frame/h.totalFrames,1),u=h.startScale+(h.targetScale-h.startScale)*eh(c),d=this.meshMap.get(h.id);d&&d.scale.setScalar(u);const f=this.glowMap.get(h.id);if(f){const p=u*6;f.scale.set(p,p,1)}h.frame>=h.totalFrames&&this.growingNodes.splice(o,1)}const n=new Set([...this.materializingNodes.map(o=>o.id),...this.dissolvingNodes.map(o=>o.id),...this.growingNodes.map(o=>o.id)]);this.meshMap.forEach((o,h)=>{if(n.has(h))return;const c=e.find(y=>y.id===h);if(!c)return;const u=1+Math.sin(t*1.5+e.indexOf(c)*.5)*.15*c.retention;o.scale.setScalar(u);const d=this.positions.get(h),f=d?i.position.distanceTo(d):0,p=1+Math.min(1.4,Math.max(0,(f-60)/100)),m=o.material;if(h===this.hoveredNode)m.emissiveIntensity=1*s;else if(h===this.selectedNode)m.emissiveIntensity=.8*s;else{const b=.3+c.retention*.5+Math.sin(t*(.8+c.retention*.7))*.1*c.retention;m.emissiveIntensity=b*s*p}const g=.3+c.retention*.7;m.opacity=Math.min(1,g*s*p);const x=this.glowMap.get(h);if(x){const y=x.material,b=.3+c.retention*.35;y.opacity=Math.min(.95,b*s*p)}}),this.labelSprites.forEach((o,h)=>{if(n.has(h))return;const c=this.positions.get(h);if(!c)return;const u=i.position.distanceTo(c),d=o.material,f=h===this.hoveredNode||h===this.selectedNode?1:u<40?.9:u<80?.9*(1-(u-40)/40):0;d.opacity+=(f-d.opacity)*.1})}getMeshes(){return Array.from(this.meshMap.values())}dispose(){this.group.traverse(t=>{var e,i,s,n,r;t instanceof Vt?((e=t.geometry)==null||e.dispose(),(i=t.material)==null||i.dispose()):t instanceof cs&&((n=(s=t.material)==null?void 0:s.map)==null||n.dispose(),(r=t.material)==null||r.dispose())}),this.materializingNodes=[],this.dissolvingNodes=[],this.growingNodes=[]}}function xf(l){var e,i;const t={};for(const s of l)(t[e=s.source]??(t[e]=[])).push({edge:s,otherId:s.target}),(t[i=s.target]??(t[i]=[])).push({edge:s,otherId:s.source});for(const s of Object.keys(t))t[s].sort((n,r)=>(r.edge.weight??0)-(n.edge.weight??0));return t}function Br(l){const t=(l.type??"").toLowerCase();return t.includes("contradict")||t.includes("conflict")||t.includes("supersede")}function bn(l){const t=Date.parse(l.updatedAt||l.createdAt||"");return Number.isFinite(t)?t:0}function bf(l,t,e,i=7){var g;const s=new Map(l.map(x=>[x.id,x])),n={beats:[],centerId:e,pivoted:!1,flowEdges:[]};if(l.length===0)return n;const r=xf(t),a=s.has(e);let o=a?e:"";o||(o=((g=l.find(x=>x.isCenter))==null?void 0:g.id)??""),o||(o=l.map(x=>{var y;return{id:x.id,deg:((y=r[x.id])==null?void 0:y.length)??0}}).sort((x,y)=>y.deg-x.deg)[0].id);const h=s.get(o);if(!h)return n;const c=!a,u=new Set([o]),d=[{nodeId:o,node:h,viaEdge:null,kind:"origin",intensity:1}],f=[];let p=o,m=!1;for(;d.length<i;){const x=r[p]??[];let y;if(m||(y=x.find(v=>!u.has(v.otherId)&&Br(v.edge)),y&&(m=!0)),y||(y=x.find(v=>!u.has(v.otherId))),!y){const v=l.filter(M=>!u.has(M.id)).sort((M,A)=>bn(A)-bn(M));if(v.length===0)break;const _=v[0];u.add(_.id),d.push({nodeId:_.id,node:_,viaEdge:null,kind:"bridge",intensity:.6}),p=_.id;continue}const b=s.get(y.otherId);if(!b){u.add(y.otherId);continue}u.add(b.id),f.push(y.edge),d.push({nodeId:b.id,node:b,viaEdge:y.edge,kind:Br(y.edge)?"contradiction":"connection",intensity:Br(y.edge)?1:Math.min(1,.55+(y.edge.weight??0)*.45)}),p=b.id}if(d.length<i){const x=d[d.length-1].nodeId,y=l.filter(b=>b.id!==x).sort((b,v)=>bn(v)-bn(b))[0];y&&!d.some(b=>b.nodeId===y.id)&&d.push({nodeId:y.id,node:y,viaEdge:null,kind:"recent",intensity:.8})}return{beats:d,centerId:o,pivoted:c,flowEdges:f}}var vf=At('<span class="hidden lg:inline text-[#ffffff]/[0.5] whitespace-nowrap"> </span>'),wf=At('<span class="text-[#a6dcff] tracking-widest whitespace-nowrap">CAPTURE</span>'),_f=At('<span class="text-[#5dcaa5] whitespace-nowrap w-[6ch] text-right"> </span>'),Mf=At('<div class="absolute top-0 left-0 right-0 z-20 pointer-events-none" style="padding-top: env(safe-area-inset-top);"><div class="flex items-center justify-between gap-3 px-4 py-2 bg-gradient-to-b from-[#05060a]/85 to-transparent font-mono text-xs [font-variant-numeric:tabular-nums]"><div class="flex items-center gap-3 min-w-0 flex-1 overflow-hidden"><span class="text-[#5dcaa5] tracking-widest uppercase truncate"> </span> <span class="hidden md:inline text-[#ffffff]/[0.5] whitespace-nowrap"> </span></div> <div class="hidden sm:flex items-center gap-4"><span class="text-[#ffffff]/[0.55] whitespace-nowrap"> </span> <!></div> <div class="flex items-center gap-3"><span class="text-[#ffffff]/[0.55] whitespace-nowrap"> </span> <!> <button class="text-[#ffffff]/[0.5] hover:text-[#5dcaa5] transition-colors cursor-pointer pointer-events-auto whitespace-nowrap" title="Copy shareable demo URL">[url]</button></div></div></div>');function Sf(l,t){Ms(t,!0);let e=lt(t,"demoMode",3,"recall-path"),i=lt(t,"seed",3,"vestige-observatory-v1"),s=lt(t,"nodeCount",3,0),n=lt(t,"edgeCount",3,0),r=lt(t,"centerId",3,""),a=lt(t,"frameCount",3,0),o=lt(t,"fpsEstimate",3,0),h=lt(t,"freezeFrame",3,null);lt(t,"loading",3,!1),lt(t,"error",3,"");function c(){const R=new URLSearchParams({demo:e(),seed:i()});h()!==null&&R.set("frame",String(h()));const I=`${window.location.origin}${wh}/observatory?${R.toString()}`;navigator.clipboard.writeText(I).catch(()=>{})}var u=Mf(),d=rt(u),f=rt(d),p=rt(f),m=rt(p,!0);st(p);var g=ct(p,2),x=rt(g);st(g),st(f);var y=ct(f,2),b=rt(y),v=rt(b);st(b);var _=ct(b,2);{var M=R=>{var I=vf(),N=rt(I);st(I),oe(wt=>Xt(N,`center=${wt??""}`),[()=>r().slice(0,8)]),xt(R,I)};zt(_,R=>{r()&&R(M)})}st(y);var A=ct(y,2),S=rt(A),C=rt(S);st(S);var z=ct(S,2);{var k=R=>{var I=wf();xt(R,I)},U=R=>{var I=_f(),N=rt(I);st(I),oe(()=>Xt(N,`${o()??""}fps`)),xt(R,I)};zt(z,R=>{h()!==null?R(k):o()>0&&R(U,1)})}var W=ct(z,2);st(A),st(d),st(u),oe((R,I)=>{Xt(m,e()),Xt(x,`seed=${R??""}${i().length>12?"…":""}`),Xt(v,`${s()??""} nodes · ${n()??""} edges`),Xt(C,`frame: ${I??""}`)},[()=>i().slice(0,12),()=>String(a()).padStart(3,"")]),wn("click",W,c),xt(l,u),Ss()}xh(["click"]);var Af=At('<div class="active-label svelte-8n8iia"> </div>'),Tf=At("<div></div>"),If=At('<div class="spine svelte-8n8iia"><!> <div class="track svelte-8n8iia"><!> <div class="playhead svelte-8n8iia"></div></div></div>');function Cf(l,t){Ms(t,!0);let e=lt(t,"steps",19,()=>[]),i=lt(t,"frame",3,0),s=lt(t,"loopFrames",3,720);const n=u=>u/s()*100;function r(u,d){const f=d-u;return f<-14||f>90?0:f<0?1+f/14:1-f/90}let a=Xr(()=>{let u="",d=.15;for(const f of e()){const p=r(f.beatFrame,i());p>d&&(d=p,u=f.label)}return u});var o=gh(),h=qr(o);{var c=u=>{var d=If(),f=rt(d);{var p=y=>{var b=Af(),v=rt(b,!0);st(b),oe(()=>Xt(v,D(a))),xt(y,b)};zt(f,y=>{D(a)&&y(p)})}var m=ct(f,2),g=rt(m);bh(g,17,e,y=>y.beatFrame,(y,b)=>{var v=Tf();let _;oe((M,A,S)=>{_=us(v,1,"tick svelte-8n8iia",null,_,M),kr(v,`left: ${A??""}%; opacity: ${S??""}`),Yr(v,"title",D(b).label)},[()=>({hot:r(D(b).beatFrame,i())>0,backward:D(b).kind===1}),()=>n(D(b).beatFrame),()=>.45+.55*r(D(b).beatFrame,i())]),xt(y,v)});var x=ct(g,2);st(m),st(d),oe(y=>kr(x,`left: ${y??""}%`),[()=>n(i())]),xt(u,d)};zt(h,u=>{e().length>0&&u(c)})}xt(l,o),Ss()}var zf=At('<div><div class="k svelte-ssd7yu"> </div> <div class="v svelte-ssd7yu"> </div> <div class="s svelte-ssd7yu"> </div></div>');function ih(l,t){Ms(t,!0);let e=lt(t,"frame",3,0),i=lt(t,"fadeWindow",19,()=>[600,620,705,719]),s=lt(t,"tone",3,"triumph");const n=(c,u,d)=>{const f=Math.min(1,Math.max(0,(d-c)/(u-c)));return f*f*(3-2*f)};let r=Xr(()=>n(i()[0],i()[1],e())*(1-n(i()[2],i()[3],e())));var a=gh(),o=qr(a);{var h=c=>{var u=zf();let d;var f=rt(u),p=rt(f,!0);st(f);var m=ct(f,2),g=rt(m,!0);st(m);var x=ct(m,2),y=rt(x,!0);st(x),st(u),oe(()=>{d=us(u,1,"verdict svelte-ssd7yu",null,d,{quarantine:s()==="quarantine"}),kr(u,`opacity: ${D(r)??""}`),Xt(p,t.verdict.headline),Xt(g,t.verdict.causeLabel),Xt(y,t.verdict.receipt)}),xt(c,u)};zt(o,c=>{D(r)>.001&&c(h)})}xt(l,a),Ss()}function sh(l){let t=1779033703^l.length;for(let e=0;e<l.length;e++)t=Math.imul(t^l.charCodeAt(e),2654435761),t=t<<13|t>>>19;return function(){let e=t+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}}function nh(l){return function(){let t=l+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}class Hn{constructor(t){T(this,"fps");T(this,"loopFrames");T(this,"seedStr");T(this,"_frame");T(this,"_totalFrames");T(this,"_rng");this.fps=t.fps??60,this.loopFrames=t.loopFrames??720,this.seedStr=t.seed,this._frame=0,this._totalFrames=0;const e=sh(this.seedStr)();this._rng=nh(Math.floor(e*2**32))}tick(){return this._frame=(this._frame+1)%this.loopFrames,this._totalFrames++,this.state}get state(){return{frame:this._frame,phase:this._frame/this.loopFrames,rng:this._rng,totalFrames:this._totalFrames}}reset(){this._frame=0,this._totalFrames=0;const t=sh(this.seedStr)();this._rng=nh(Math.floor(t*2**32))}get loopDuration(){return this.loopFrames/this.fps}get framesPerLoop(){return this.loopFrames}}function al(l,t,e,i){const s=Math.PI*(3-Math.sqrt(5)),n=1-l/(t-1||1)*2,r=Math.sqrt(1-n*n),a=s*l,o=Math.cos(a)*r,h=Math.sin(a)*r,c=(i()-.5)*.1*e,u=(i()-.5)*.1*e,d=(i()-.5)*.1*e;return[o*e+c,n*e+u,h*e+d]}const Fa=["recall-path","engram-birth","salience-rescue","forgetting-horizon","firewall"];function ky(l){return Fa.includes(l)}const vt=16,ce={posRadius:0,velRetention:4,colorFlags:8},ss={isCenter:1,suppressed:2,isAha:4,isFailure:8,isConfusion:16},Fr=2,ns=4,Be={recall:0,backwardCause:1,probe:2},Bf=12;function Ff(l){const t=Fa.indexOf(l);return t<0?0:t}function Pf(l,t){return{id:l.id,index:t,label:l.label,type:l.type,retention:typeof l.retention=="number"?l.retention:0,tags:Array.isArray(l.tags)?l.tags:[],isCenter:!!l.isCenter,suppressed:(l.suppression_count??0)>0}}function kf(l,t){const e=Math.max(1,l>>1),i=Math.max(1,t>>1),s=Math.min(6,Math.max(1,1+Math.floor(Math.log2(Math.min(e,i)/8)))),n=Array.from({length:s},(r,a)=>[Math.max(1,e>>a),Math.max(1,i>>a)]);return{baseW:e,baseH:i,mipCount:s,sizes:n}}const _n=.18,Ef=0,Rf=2/255,Lf=.85,Of=.62,Nf=`
// Tuning constants — interpolated from post.wgsl.ts (TS single source of truth).
const BLOOM_STRENGTH: f32 = ${_n};
const BLOOM_CHROMATIC_TEXELS: f32 = ${Ef};
const GRAIN_AMP: f32 = ${Rf};
const VIGNETTE_LIFT: f32 = ${Lf};
const VIGNETTE_TAN: f32 = ${Of};
// Params layout — VERBATIM from render-nodes.wgsl.ts (types.PARAMS_FLOATS).
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
// Globally unique bindings — each entry point statically uses a subset; the
// explicit bind group layouts in post-chain.ts carry exactly what each
// pipeline needs (blur: 1+2, composite: 0+2+3+4).
@group(0) @binding(0) var<uniform> params: Params; // composite only
@group(0) @binding(1) var src: texture_2d<f32>; // blur chain input
@group(0) @binding(2) var samp: sampler; // shared
@group(0) @binding(3) var scene_tex: texture_2d<f32>; // composite only
@group(0) @binding(4) var bloom_tex: texture_2d<f32>; // composite only (FULL-mip view)
struct FSOut {
@builtin(position) pos: vec4f,
@location(0) uv: vec2f,
};
// Fullscreen triangle from bit math — no vertex buffer, no arrays.
// vi 0/1/2 → clip (-1,-1) (3,-1) (-1,3); uv y flipped so uv(0,0) = top-left.
@vertex
fn vs_fullscreen(@builtin(vertex_index) vi: u32) -> FSOut {
let xy = vec2f(f32((vi << 1u) & 2u), f32(vi & 2u)) * 2.0 - 1.0;
var out: FSOut;
out.pos = vec4f(xy, 0.0, 1.0);
out.uv = vec2f(xy.x, -xy.y) * 0.5 + 0.5;
return out;
}
fn luma(c: vec3f) -> f32 {
return dot(c, vec3f(0.2126, 0.7152, 0.0722));
}
// ---------------------------------------------------------------------------
// Bloom downsample — 13-tap Jimenez (SIGGRAPH 2014 "Next Generation Post
// Processing in Call of Duty: Advanced Warfare"), taps fully unrolled.
//
// a b c outer ring at ±2 texels
// j k inner ring at ±1 texels
// d e f e = center
// l m
// g h i
//
// Grouped as 5 overlapping 4-tap boxes: center box (the four inner taps)
// weight 0.5, four corner boxes weight 0.125 each. A flat field reproduces
// itself EXACTLY (0.5 + 4·0.125 = 1) — that exactness is what the void
// preimage in tone-reference.ts depends on.
// ---------------------------------------------------------------------------
@fragment
fn fs_downsample_karis(in: FSOut) -> @location(0) vec4f {
let ts = 1.0 / vec2f(textureDimensions(src));
let a = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, -2.0) * ts, 0.0).rgb;
let b = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, -2.0) * ts, 0.0).rgb;
let c = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, -2.0) * ts, 0.0).rgb;
let d = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, 0.0) * ts, 0.0).rgb;
let e = textureSampleLevel(src, samp, in.uv, 0.0).rgb;
let f = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, 0.0) * ts, 0.0).rgb;
let g = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, 2.0) * ts, 0.0).rgb;
let h = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, 2.0) * ts, 0.0).rgb;
let i = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, 2.0) * ts, 0.0).rgb;
let j = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, -1.0) * ts, 0.0).rgb;
let k = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, -1.0) * ts, 0.0).rgb;
let l = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, 1.0) * ts, 0.0).rgb;
let m = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, 1.0) * ts, 0.0).rgb;
let box_c = (j + k + l + m) * 0.25;
let box_tl = (a + b + d + e) * 0.25;
let box_tr = (b + c + e + f) * 0.25;
let box_bl = (d + e + g + h) * 0.25;
let box_br = (e + f + h + i) * 0.25;
// Karis average (fireflies killer) — used ONLY on the full→mip0 hop.
// Each box is additionally weighted 1/(1 + luma) and the sum RENORMALIZED:
// on a flat field every Karis factor is equal, so the result is exact.
let w_c = 0.5 / (1.0 + luma(box_c));
let w_tl = 0.125 / (1.0 + luma(box_tl));
let w_tr = 0.125 / (1.0 + luma(box_tr));
let w_bl = 0.125 / (1.0 + luma(box_bl));
let w_br = 0.125 / (1.0 + luma(box_br));
let sum = w_c * box_c + w_tl * box_tl + w_tr * box_tr + w_bl * box_bl + w_br * box_br;
return vec4f(sum / (w_c + w_tl + w_tr + w_bl + w_br), 1.0);
}
@fragment
fn fs_downsample(in: FSOut) -> @location(0) vec4f {
let ts = 1.0 / vec2f(textureDimensions(src));
let a = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, -2.0) * ts, 0.0).rgb;
let b = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, -2.0) * ts, 0.0).rgb;
let c = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, -2.0) * ts, 0.0).rgb;
let d = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, 0.0) * ts, 0.0).rgb;
let e = textureSampleLevel(src, samp, in.uv, 0.0).rgb;
let f = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, 0.0) * ts, 0.0).rgb;
let g = textureSampleLevel(src, samp, in.uv + vec2f(-2.0, 2.0) * ts, 0.0).rgb;
let h = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, 2.0) * ts, 0.0).rgb;
let i = textureSampleLevel(src, samp, in.uv + vec2f( 2.0, 2.0) * ts, 0.0).rgb;
let j = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, -1.0) * ts, 0.0).rgb;
let k = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, -1.0) * ts, 0.0).rgb;
let l = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, 1.0) * ts, 0.0).rgb;
let m = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, 1.0) * ts, 0.0).rgb;
let box_c = (j + k + l + m) * 0.25;
let box_tl = (a + b + d + e) * 0.25;
let box_tr = (b + c + e + f) * 0.25;
let box_bl = (d + e + g + h) * 0.25;
let box_br = (e + f + h + i) * 0.25;
return vec4f(box_c * 0.5 + (box_tl + box_tr + box_bl + box_br) * 0.125, 1.0);
}
// ---------------------------------------------------------------------------
// Bloom upsample — 9-tap 3×3 tent, 1/16·[1 2 1; 2 4 2; 1 2 1], radius = one
// SOURCE-mip texel. Rendered with additive one/one blending onto the stored
// downsample of the destination mip (accumulate-up-the-chain). The resulting
// DC gain of exactly mipCount is normalized in fs_composite.
// ---------------------------------------------------------------------------
@fragment
fn fs_upsample_tent(in: FSOut) -> @location(0) vec4f {
let ts = 1.0 / vec2f(textureDimensions(src));
let a = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, -1.0) * ts, 0.0).rgb;
let b = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, -1.0) * ts, 0.0).rgb;
let c = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, -1.0) * ts, 0.0).rgb;
let d = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, 0.0) * ts, 0.0).rgb;
let e = textureSampleLevel(src, samp, in.uv, 0.0).rgb;
let f = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, 0.0) * ts, 0.0).rgb;
let g = textureSampleLevel(src, samp, in.uv + vec2f(-1.0, 1.0) * ts, 0.0).rgb;
let h = textureSampleLevel(src, samp, in.uv + vec2f( 0.0, 1.0) * ts, 0.0).rgb;
let i = textureSampleLevel(src, samp, in.uv + vec2f( 1.0, 1.0) * ts, 0.0).rgb;
let sum = (a + c + g + i) + (b + d + f + h) * 2.0 + e * 4.0;
return vec4f(sum * (1.0 / 16.0), 1.0);
}
// ---------------------------------------------------------------------------
// Composite — bloom-add → PBR Neutral → grain → vignette (order is mandated).
// ---------------------------------------------------------------------------
// Khronos PBR Neutral — EXACT port of the Khronos reference implementation.
// Hue-preserving; the FSRS palette keeps its channel ordering. Pinned to the
// CPU mirror in post/tone-reference.ts (pbrNeutralReference) — keep in
// lockstep, the void-preimage tests run against the mirror.
fn pbr_neutral(color_in: vec3f) -> vec3f {
let start_compression = 0.8 - 0.04;
let desaturation = 0.15;
var color = color_in;
let x = min(color.r, min(color.g, color.b));
// WGSL select(false_value, true_value, condition) — argument order trap.
let offset = select(0.04, x - 6.25 * x * x, x < 0.08);
color = color - vec3f(offset);
let peak = max(color.r, max(color.g, color.b));
if (peak < start_compression) {
return color;
}
let d = 1.0 - start_compression;
let new_peak = 1.0 - d * d / (peak + d - start_compression);
color = color * (new_peak / peak);
let g = 1.0 / (desaturation * (peak - new_peak) + 1.0);
// mix weight = 1 - g per the Khronos spec.
return mix(color, vec3f(new_peak), 1.0 - g);
}
// PCG hash — integers only, 24-bit-exact output in [0, 1). Deterministic.
fn pcg(v: u32) -> u32 {
var s = v * 747796405u + 2891336453u;
let t = ((s >> ((s >> 28u) + 4u)) ^ s) * 277803737u;
return (t >> 22u) ^ t;
}
fn hashf(p: vec2u, f: u32) -> f32 {
return f32(pcg(p.x ^ pcg(p.y ^ pcg(f))) >> 8u) / 16777216.0;
}
@fragment
fn fs_composite(in: FSOut) -> @location(0) vec4f {
let pix = vec2u(in.pos.xy);
// Exact 1:1 fetch (alpha discarded — see module header).
let scene = textureLoad(scene_tex, pix, 0).rgb;
// Bloom, normalized by the mip count: the additive up-chain has DC gain
// exactly mipCount, so /mips makes flat-field gain exactly 1 — the void
// preimage holds and brightness is viewport-stable. Chromatic dispersion
// rides the bloom term ONLY (BLOOM_CHROMATIC_TEXELS = 0.0 kills it).
let mips = f32(textureNumLevels(bloom_tex));
let dims = vec2f(textureDimensions(bloom_tex));
let dvec = in.uv - vec2f(0.5);
let off = dvec * (BLOOM_CHROMATIC_TEXELS * dot(dvec, dvec) * 4.0) / dims;
let bloom = vec3f(
textureSampleLevel(bloom_tex, samp, in.uv - off, 0.0).r,
textureSampleLevel(bloom_tex, samp, in.uv, 0.0).g,
textureSampleLevel(bloom_tex, samp, in.uv + off, 0.0).b
) / mips;
var c = pbr_neutral(scene + BLOOM_STRENGTH * bloom);
// Seeded TPDF film grain (post-tonemap dither): keyed to the WRAPPED loop
// frame → 720-periodic and capture-pinned. Full strength in the shadows
// (kills #05060a banding), fades out of highlights.
let f = u32(params.frame + 0.5);
let n = hashf(pix, f) + hashf(pix ^ vec2u(0x9E3779B9u, 0x85EBCA6Bu), f) - 1.0;
let w = 1.0 - smoothstep(0.0, 0.8, luma(c));
c += GRAIN_AMP * n * w;
// cos⁴ vignette: cos⁴θ = (1 + r²·tan²)⁻², aspect-normalized so rn = 1.0
// exactly at the corners regardless of viewport shape. Lifted floor keeps
// it an observatory, not a tunnel.
let ar = vec2f(params.viewport_w / max(params.viewport_h, 1.0), 1.0);
let rn = length((in.uv * 2.0 - 1.0) * ar) / length(ar);
let k = rn * rn * VIGNETTE_TAN * VIGNETTE_TAN;
c *= mix(VIGNETTE_LIFT, 1.0, 1.0 / ((1.0 + k) * (1.0 + k)));
// NO gamma encode — display-referred pass-through, matching the pre-post
// look where shader outputs went straight to the swapchain.
return vec4f(c, 1.0);
}
`,Ci="rgba16float",Df={color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}};class Uf{constructor(t,e,i){T(this,"device");T(this,"paramsBuffer");T(this,"samp");T(this,"blurLayout");T(this,"compositeLayout");T(this,"pipeDownFirst");T(this,"pipeDown");T(this,"pipeUp");T(this,"pipeComposite");T(this,"width",0);T(this,"height",0);T(this,"plan",null);T(this,"sceneTex",null);T(this,"_sceneView",null);T(this,"bloomTex",null);T(this,"mipViews",[]);T(this,"bloomFullView",null);T(this,"downBind",[]);T(this,"upBind",[]);T(this,"compositeBind",null);this.device=t,this.paramsBuffer=e,this.samp=t.createSampler({label:"observatory-post-sampler",minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"});const s=t.createShaderModule({label:"observatory-post",code:Nf});this.blurLayout=t.createBindGroupLayout({label:"observatory-post-blur-layout",entries:[{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}}]}),this.compositeLayout=t.createBindGroupLayout({label:"observatory-post-composite-layout",entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,buffer:{type:"uniform"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:3,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d"}},{binding:4,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d"}}]});const n=t.createPipelineLayout({label:"observatory-post-blur-pipe-layout",bindGroupLayouts:[this.blurLayout]}),r=t.createPipelineLayout({label:"observatory-post-composite-pipe-layout",bindGroupLayouts:[this.compositeLayout]}),a=(o,h,c,u,d)=>t.createRenderPipeline({label:o,layout:h,vertex:{module:s,entryPoint:"vs_fullscreen"},fragment:{module:s,entryPoint:c,targets:[{format:u,blend:d}]},primitive:{topology:"triangle-list"}});this.pipeDownFirst=a("observatory-post-down-karis",n,"fs_downsample_karis",Ci),this.pipeDown=a("observatory-post-down",n,"fs_downsample",Ci),this.pipeUp=a("observatory-post-up",n,"fs_upsample_tent",Ci,Df),this.pipeComposite=a("observatory-post-composite",r,"fs_composite",i)}get sceneView(){if(!this._sceneView)throw new Error("PostChain.ensure() must run before sceneView is used");return this._sceneView}ensure(t,e){var o,h;const i=Math.max(1,Math.floor(t)),s=Math.max(1,Math.floor(e));if(i===this.width&&s===this.height&&this.sceneTex!==null)return;this.width=i,this.height=s,(o=this.sceneTex)==null||o.destroy(),(h=this.bloomTex)==null||h.destroy(),this.sceneTex=this.device.createTexture({label:"observatory-scene-hdr",size:[i,s],format:Ci,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),this._sceneView=this.sceneTex.createView({label:"observatory-scene-hdr-view"});const n=kf(i,s);this.plan=n,this.bloomTex=this.device.createTexture({label:"observatory-bloom-mips",size:[n.baseW,n.baseH],format:Ci,mipLevelCount:n.mipCount,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING});const r=this.bloomTex;this.mipViews=Array.from({length:n.mipCount},(c,u)=>r.createView({label:`observatory-bloom-mip-${u}`,baseMipLevel:u,mipLevelCount:1})),this.bloomFullView=r.createView({label:"observatory-bloom-full"});const a=this._sceneView;this.downBind=this.mipViews.map((c,u)=>this.device.createBindGroup({label:`observatory-bloom-down-bind-${u}`,layout:this.blurLayout,entries:[{binding:1,resource:u===0?a:this.mipViews[u-1]},{binding:2,resource:this.samp}]})),this.upBind=[];for(let c=0;c+1<n.mipCount;c++)this.upBind.push(this.device.createBindGroup({label:`observatory-bloom-up-bind-${c}`,layout:this.blurLayout,entries:[{binding:1,resource:this.mipViews[c+1]},{binding:2,resource:this.samp}]}));this.compositeBind=this.device.createBindGroup({label:"observatory-post-composite-bind",layout:this.compositeLayout,entries:[{binding:0,resource:{buffer:this.paramsBuffer}},{binding:2,resource:this.samp},{binding:3,resource:a},{binding:4,resource:this.bloomFullView}]})}encode(t,e){const i=this.plan;if(!i||!this.compositeBind)return;const s=i.mipCount;for(let r=0;r<s;r++){const a=t.beginRenderPass({label:`observatory-bloom-down-${r}`,colorAttachments:[{view:this.mipViews[r],loadOp:"clear",storeOp:"store"}]});a.setPipeline(r===0?this.pipeDownFirst:this.pipeDown),a.setBindGroup(0,this.downBind[r]),a.draw(3),a.end()}for(let r=s-2;r>=0;r--){const a=t.beginRenderPass({label:`observatory-bloom-up-${r}`,colorAttachments:[{view:this.mipViews[r],loadOp:"load",storeOp:"store"}]});a.setPipeline(this.pipeUp),a.setBindGroup(0,this.upBind[r]),a.draw(3),a.end()}const n=t.beginRenderPass({label:"observatory-post-composite",colorAttachments:[{view:e,loadOp:"clear",storeOp:"store"}]});n.setPipeline(this.pipeComposite),n.setBindGroup(0,this.compositeBind),n.draw(3),n.end()}dispose(){var t,e;(t=this.sceneTex)==null||t.destroy(),(e=this.bloomTex)==null||e.destroy(),this.sceneTex=null,this.bloomTex=null,this._sceneView=null,this.bloomFullView=null,this.mipViews=[],this.downBind=[],this.upBind=[],this.compositeBind=null,this.plan=null,this.width=0,this.height=0}}const ol=Math.sqrt(5/255/6.25),rh=ol-5/255,Vf={r:ol/(1+_n),g:(6/255+rh)/(1+_n),b:(10/255+rh)/(1+_n),a:1},gs=class gs{constructor(t){T(this,"canvas");T(this,"device",null);T(this,"context",null);T(this,"format","bgra8unorm");T(this,"clock");T(this,"demo");T(this,"freezeFrame");T(this,"rafId",0);T(this,"running",!1);T(this,"disposed",!1);T(this,"maxDpr");T(this,"onFrame");T(this,"params",new Float32Array(Bf));T(this,"paramsBuffer",null);T(this,"passes",[]);T(this,"post",null);T(this,"_status",{state:"booting"});T(this,"statusListeners",new Set);T(this,"lastRafTs",0);T(this,"fpsEstimate",0);T(this,"accumulatorMs",0);T(this,"frame",t=>{var u,d,f;if(!this.running||!this.device||!this.context||!this.paramsBuffer||!this.post)return;let e=0;for(this.lastRafTs>0&&(e=t-this.lastRafTs,e>0&&(this.fpsEstimate=Math.round(1e3/e))),this.lastRafTs=t,this.accumulatorMs+=Math.min(e,250);this.accumulatorMs>=gs.FIXED_DT_MS;)this.clock.tick(),this.accumulatorMs-=gs.FIXED_DT_MS;const i=this.clock.state,s=this.freezeFrame??i.frame,n=s/this.clock.framesPerLoop,r=this.params;r[0]=s,r[1]=n,r[5]=.5+.5*Math.sin(2*Math.PI*4*n),r[6]=this.canvas.width,r[7]=this.canvas.height,r[9]=Ff(this.demo),r[10]=s/60,r[11]=this.freezeFrame!==null?1:0,this.device.queue.writeBuffer(this.paramsBuffer,0,r);let a;try{a=this.context.getCurrentTexture()}catch{this.rafId=requestAnimationFrame(this.frame);return}this.post.ensure(a.width,a.height);const o=a.createView(),h=this.device.createCommandEncoder({label:"observatory-frame"});for(const p of this.passes)(u=p.compute)==null||u.call(p,h,s);const c=h.beginRenderPass({label:"observatory-main",colorAttachments:[{view:this.post.sceneView,clearValue:Vf,loadOp:"clear",storeOp:"store"}]});for(const p of this.passes)(d=p.render)==null||d.call(p,c,s);c.end(),this.post.encode(h,o),this.device.queue.submit([h.finish()]),(f=this.onFrame)==null||f.call(this,s,this.fpsEstimate),this.rafId=requestAnimationFrame(this.frame)});this.canvas=t.canvas,this.demo=t.demo,this.maxDpr=t.maxDpr??2,this.onFrame=t.onFrame,this.clock=new Hn({seed:t.seed}),this.freezeFrame=typeof t.freezeFrame=="number"&&Number.isFinite(t.freezeFrame)?(Math.floor(t.freezeFrame)%this.clock.framesPerLoop+this.clock.framesPerLoop)%this.clock.framesPerLoop:null,this.params[8]=1}get status(){return this._status}get gpuDevice(){return this.device}get presentationFormat(){return this.format}get sceneFormat(){return Ci}get demoClock(){return this.clock}onStatus(t){return this.statusListeners.add(t),t(this._status),()=>this.statusListeners.delete(t)}setStatus(t){this._status=t;for(const e of this.statusListeners)e(t)}addPass(t){this.passes.push(t)}async start(){var s;if(this.disposed)return!1;const t=navigator.gpu;if(!t)return this.setStatus({state:"unsupported",reason:"WebGPU is not available in this browser."}),!1;let e=null;try{e=await t.requestAdapter()}catch(n){return this.setStatus({state:"error",reason:n instanceof Error?n.message:"requestAdapter failed"}),!1}if(!e)return this.setStatus({state:"unsupported",reason:"No suitable GPU adapter found."}),!1;try{this.device=await e.requestDevice()}catch(n){return this.setStatus({state:"error",reason:n instanceof Error?n.message:"requestDevice failed"}),!1}if(this.disposed)return(s=this.device)==null||s.destroy(),this.device=null,!1;this.device.lost.then(n=>{this.disposed||n.reason==="destroyed"||(this.setStatus({state:"error",reason:`GPU device lost: ${n.message}`}),this.stopLoop())}),this.device.onuncapturederror=n=>{console.error("[observatory] WebGPU error:",n.error.message)};const i=this.canvas.getContext("webgpu");return i?(this.context=i,this.format=t.getPreferredCanvasFormat(),this.configureContext(),this.paramsBuffer=this.device.createBuffer({label:"observatory-params",size:this.params.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.post=new Uf(this.device,this.paramsBuffer,this.format),this.setStatus({state:"running"}),this.running=!0,this.rafId=requestAnimationFrame(this.frame),!0):(this.setStatus({state:"error",reason:"Could not get webgpu canvas context."}),!1)}resize(){var s;if(!this.device||!this.context)return;const t=Math.min(window.devicePixelRatio||1,this.maxDpr),e=Math.max(1,Math.floor(this.canvas.clientWidth*t)),i=Math.max(1,Math.floor(this.canvas.clientHeight*t));(this.canvas.width!==e||this.canvas.height!==i)&&(this.canvas.width=e,this.canvas.height=i,this.configureContext(),(s=this.post)==null||s.ensure(e,i))}configureContext(){!this.device||!this.context||this.context.configure({device:this.device,format:this.format,alphaMode:"opaque"})}stopLoop(){this.running=!1,this.rafId!==0&&(cancelAnimationFrame(this.rafId),this.rafId=0)}dispose(){var t,e,i;this.disposed||(this.disposed=!0,this.stopLoop(),(t=this.paramsBuffer)==null||t.destroy(),this.paramsBuffer=null,(e=this.post)==null||e.dispose(),this.post=null,(i=this.device)==null||i.destroy(),this.device=null,this.context=null,this.passes=[],this.setStatus({state:"disposed"}),this.statusListeners.clear())}};T(gs,"FIXED_DT_MS",1e3/60);let Wr=gs;var Gf=At(`<div class="fallback svelte-16248mg" role="alert"><div class="fallback-title svelte-16248mg">MEMORY FIELD OFFLINE</div> <div class="fallback-reason svelte-16248mg"> </div> <div class="fallback-hint svelte-16248mg">WebGPU is required for the Observatory. Chrome 113+, Edge 113+, or Safari 18+ —
the classic <a class="svelte-16248mg">Graph view</a> works everywhere.</div></div>`),Wf=At('<canvas class="observatory-canvas svelte-16248mg" aria-label="Vestige memory field"></canvas> <!>',1);function Hf(l,t){Ms(t,!0);let e=lt(t,"freezeFrame",3,null),i,s=null,n=Pt(yh({state:"booting"})),r=null,a=null;mh(()=>{s=new Wr({canvas:i,demo:t.demo,seed:t.seed,freezeFrame:e(),maxDpr:2,onFrame:(d,f)=>{var p;return(p=t.onframe)==null?void 0:p.call(t,d,f)}}),r=s.onStatus(d=>{var f;mt(n,d,!0),(f=t.onstatus)==null||f.call(t,d)}),a=new ResizeObserver(()=>s==null?void 0:s.resize()),a.observe(i),s.start().then(d=>{var f;d&&s&&(s.resize(),(f=t.onready)==null||f.call(t,s))})}),pl(()=>{r==null||r(),a==null||a.disconnect(),s==null||s.dispose(),s=null});var o=Wf(),h=qr(o);vh(h,d=>i=d,()=>i);var c=ct(h,2);{var u=d=>{var f=Gf(),p=ct(rt(f),2),m=rt(p,!0);st(p);var g=ct(p,2),x=ct(rt(g));ml(),st(g),st(f),oe(()=>{Xt(m,D(n).reason),Yr(x,"href",`${wh??""}/graph`)}),xt(d,f)};zt(c,d=>{(D(n).state==="unsupported"||D(n).state==="error")&&d(u)})}xt(l,o),Ss()}function qf(l,t,e,i){const s=1/Math.tan(l/2),n=1/(e-i),r=new Float32Array(16);return r[0]=s/t,r[5]=s,r[10]=i*n,r[11]=-1,r[14]=i*e*n,r}function Xf(l,t,e){const[i,s,n]=l;let r=i-t[0],a=s-t[1],o=n-t[2],h=Math.hypot(r,a,o)||1;r/=h,a/=h,o/=h;let c=e[1]*o-e[2]*a,u=e[2]*r-e[0]*o,d=e[0]*a-e[1]*r;h=Math.hypot(c,u,d)||1,c/=h,u/=h,d/=h;const f=a*d-o*u,p=o*c-r*d,m=r*u-a*c,g=new Float32Array(16);return g[0]=c,g[1]=f,g[2]=r,g[4]=u,g[5]=p,g[6]=a,g[8]=d,g[9]=m,g[10]=o,g[12]=-(c*i+u*s+d*n),g[13]=-(f*i+p*s+m*n),g[14]=-(r*i+a*s+o*n),g[15]=1,g}function Yf(l,t){const e=new Float32Array(16);for(let i=0;i<4;i++)for(let s=0;s<4;s++)e[i*4+s]=l[s]*t[i*4]+l[4+s]*t[i*4+1]+l[8+s]*t[i*4+2]+l[12+s]*t[i*4+3];return e}function ah(l,t,e,i=.35){const s=l*Math.PI*2,n=[Math.sin(s)*e,e*i,Math.cos(s)*e],r=qf(50*Math.PI/180,t,.1,4e3),a=Xf(n,[0,0,0],[0,1,0]);let o=-n[0],h=-n[1],c=-n[2],u=Math.hypot(o,h,c)||1;o/=u,h/=u,c/=u;let d=h*0-c*1,f=c*0-o*0,p=o*1-h*0;u=Math.hypot(d,f,p)||1,d/=u,f/=u,p/=u;const m=f*c-p*h,g=p*o-d*c,x=d*h-f*o;return{viewProj:Yf(r,a),right:[d,f,p],up:[m,g,x],eye:n}}function oh(l){const t=/^#?([0-9a-fA-F]{6})$/.exec(l.trim());if(!t)return[107/255,114/255,128/255];const e=parseInt(t[1],16);return[(e>>16&255)/255,(e>>8&255)/255,(e&255)/255]}function Jf(l){const t=rl({tags:l.tags});return oh(t||nl[sl(l.retention)])}function Zf(l){const e=[...l.nodes].sort((r,a)=>r.isCenter!==a.isCenter?r.isCenter?-1:1:r.id<a.id?-1:r.id>a.id?1:0).map((r,a)=>Pf(r,a)),i=new Map;for(const r of e)i.set(r.id,r.index);const s=[];for(const r of l.edges){const a=i.get(r.source),o=i.get(r.target);a===void 0||o===void 0||a===o||s.push({sourceIndex:a,targetIndex:o,weight:r.weight,type:r.type})}const n=e.findIndex(r=>r.isCenter);return{nodes:e,edges:s,indexById:i,centerIndex:n<0?0:n}}function hl(l,t,e=120){const i=l.nodes.length,s=new Float32Array(i*vt);for(let n=0;n<i;n++){const r=l.nodes[n],a=n*vt,[o,h,c]=r.isCenter&&l.centerIndex===n?[0,0,0]:al(n,i,e,t),u=r.isCenter?4.2:1.4+r.retention*1.8;s[a+ce.posRadius+0]=o,s[a+ce.posRadius+1]=h,s[a+ce.posRadius+2]=c,s[a+ce.posRadius+3]=u,s[a+ce.velRetention+3]=r.retention;const[d,f,p]=Jf(r);let m=0;r.isCenter&&(m|=ss.isCenter),r.suppressed&&(m|=ss.suppressed);const g=new Set(r.tags.map(x=>x.toLowerCase()));g.has("aha")&&(m|=ss.isAha),(g.has("failure")||g.has("guardrail"))&&(m|=ss.isFailure),(g.has("confusion")||g.has("weak-spot"))&&(m|=ss.isConfusion),s[a+ce.colorFlags+0]=d,s[a+ce.colorFlags+1]=f,s[a+ce.colorFlags+2]=p,s[a+ce.colorFlags+3]=m}return{data:s,nodeCount:i}}function Kf(l){const t=new Uint32Array(Math.max(1,l.edges.length)*Fr);return l.edges.forEach((e,i)=>{t[i*Fr]=e.sourceIndex,t[i*Fr+1]=e.targetIndex}),t}const jf=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Camera {
view_proj: mat4x4<f32>,
right: vec4<f32>,
up: vec4<f32>,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<uniform> camera: Camera;
@group(0) @binding(2) var<storage, read> nodes: array<Node>;
// Iridescent thin-film band — ported EXACTLY from causal-brain-demo.html
// spectral(w) (visual DNA §7.1): indigo → cyan-teal → mint → magenta rim,
// wrapping. Activation glow rides this band; base color stays FSRS state.
fn spectral(w_in: f32) -> vec3<f32> {
let w = fract(w_in);
// var, not let: WGSL only allows dynamic indexing through a reference.
var stops = array<vec3<f32>, 4>(
vec3<f32>(0.20, 0.28, 0.95), // indigo
vec3<f32>(0.20, 0.85, 0.90), // cyan-teal
vec3<f32>(0.45, 1.00, 0.72), // mint
vec3<f32>(0.85, 0.45, 1.00) // magenta rim
);
let f = w * 4.0;
let i = u32(floor(f)) % 4u;
let frac = f - floor(f);
let a = stops[i];
let b = stops[(i + 1u) % 4u];
return mix(a, b, frac);
}
struct VSOut {
@builtin(position) clip: vec4<f32>,
@location(0) uv: vec2<f32>,
// Per-instance constants: flat interpolation guarantees the flag bit
// field survives the raster stage bit-exact (no barycentric rounding).
@location(1) @interpolate(flat) color: vec3<f32>,
// x retention, y flags (bit field as f32), z recall intensity, w radius
@location(2) @interpolate(flat) misc: vec4<f32>,
// Per-demo choreography lanes (demo.y, demo.z, demo.w), gated by demo_id:
// rescue (2) searchlight/wave/shock, forgetting-horizon (3) fade-and-fall,
// firewall (4) flare-membrane/shock. Each demo's choreography pass is the
// ONLY writer of its lanes, and every gated term below is an exact no-op
// when its lane is 0.0 — other demos stay pixel-identical.
@location(3) @interpolate(flat) demo_yzw: vec3<f32>,
};
// Quad corners for two triangles (vertex_index 0..5).
const CORNERS = array<vec2<f32>, 6>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, 1.0)
);
@vertex
fn vs_main(
@builtin(vertex_index) vi: u32,
@builtin(instance_index) ii: u32
) -> VSOut {
var out: VSOut;
if (ii >= u32(params.node_count)) {
// degenerate — clipped away
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
return out;
}
let node = nodes[ii];
let corner = CORNERS[vi];
// Breath: halo geometry swells ~6% on the global pulse (§7.2), and the
// center memory breathes a touch deeper — a heartbeat, not a strobe.
let flags = u32(node.color_flags.w);
let is_center = (flags & 1u) != 0u;
var breath = 1.0 + 0.06 * params.pulse;
if (is_center) {
breath = 1.0 + 0.12 * params.pulse;
}
// Sprite spans ~3.2× the core radius so the halo has room to feather out.
// Recall activation swells the sprite — the wavefront physically blooms.
// Per-demo choreography lanes swell it too, gated by demo_id so each
// demo's grammar can never leak into another (lanes are 0.0 elsewhere,
// and the gate makes the no-op structural, not just numerical).
let recall = node.demo.x;
let dy = node.demo.y;
let dz = node.demo.z;
let dw = node.demo.w;
var lane_swell = 0.0;
if (params.demo_id == 2.0) {
// salience-rescue: searchlight pop, wave shiver, shock bloom.
lane_swell = 0.5 * dy + 0.25 * dz + 0.9 * dw;
} else if (params.demo_id == 4.0) {
// firewall: intrusion flare pop (band (0..1]), membrane presence
// (band [2.6..2.9] via the range gate), crimson shock bloom.
lane_swell = 0.35 * min(dy, 1.0) + 0.3 * smoothstep(1.5, 2.2, dy) + 0.55 * dw;
}
// forgetting-horizon (demo 3): VISUAL displacement toward the horizon —
// down and away from the field axis, ~40.5 units at dz = 1 — plus a
// shrink. pos_radius is NEVER written (the force sim owns positions);
// drift is pure of demo.z, so ?frame=N capture stays exact. CPU mirror:
// forgetting-plan.ts horizonDrift().
var horizon_scale = 1.0;
var drift = vec3<f32>(0.0);
if (params.demo_id == 3.0) {
let dzc = clamp(dz, 0.0, 1.0);
horizon_scale = 1.0 - 0.35 * dzc;
if (dz > 0.0) {
let p = node.pos_radius.xyz;
let r_xz = max(length(p.xz), 0.001);
let away = vec3<f32>(p.x / r_xz, 0.0, p.z / r_xz);
drift = dzc * (vec3<f32>(0.0, -34.0, 0.0) + away * 22.0);
}
}
let half_size = node.pos_radius.w * 3.2 * breath * (1.0 + 0.9 * recall)
* (1.0 + lane_swell) * horizon_scale;
let world = node.pos_radius.xyz + drift
+ camera.right.xyz * corner.x * half_size
+ camera.up.xyz * corner.y * half_size;
out.clip = camera.view_proj * vec4<f32>(world, 1.0);
out.uv = corner;
out.color = node.color_flags.rgb;
out.misc = vec4<f32>(node.vel_retention.w, node.color_flags.w, node.demo.x, node.pos_radius.w);
out.demo_yzw = vec3<f32>(dy, dz, dw);
return out;
}
@fragment
fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
let d = length(in.uv);
if (d > 1.0) {
discard;
}
let retention = in.misc.x;
let flags = u32(in.misc.y);
let suppressed = (flags & 2u) != 0u;
let is_center = (flags & 1u) != 0u;
// Soft sprite: hot core + feathered halo. The halo rides the breath pulse.
let core = smoothstep(0.22, 0.0, d);
let halo = pow(max(1.0 - d, 0.0), 2.4);
var intensity = core * 1.35 + halo * (0.42 + 0.18 * params.pulse);
// Meaning layer: low-retention memories glow dimmer (drifting toward the
// horizon), the center anchor reads brightest.
intensity = intensity * (0.45 + 0.55 * retention);
if (is_center) {
intensity = intensity * 1.6;
}
if (suppressed) {
intensity = intensity * 0.28;
}
var color = in.color * intensity;
// Forgetting-horizon (demo 3): multiplicative dim toward near-black as
// demo.z rises. Floor 0.06 — never fully gone, always retrievable. Sits
// BEFORE the recall block so a rescued memory's ignition burns through
// the fade. demo_yzw.y carries demo.z (vec3 = y/z/w lanes).
if (params.demo_id == 3.0) {
color = color * mix(1.0, 0.06, clamp(in.demo_yzw.y, 0.0, 1.0));
}
// Recall activation (§7.1): the thin-film band takes over as the wave
// lands. Hue drifts exactly ONE full spectral cycle per 720-frame loop
// (loop_phase wraps 0→1 and spectral() fract-wraps) — oil-slick shimmer
// with a mathematically invisible loop seam.
let recall = in.misc.z;
if (recall > 0.001) {
let band = spectral(0.1 + params.loop_phase + d * 0.35);
let activation = band * recall * (core * 1.7 + halo * 0.9);
// white-hot pinpoint at full ignition
let flash = vec3<f32>(1.0, 1.0, 1.0) * core * recall * 0.55;
color = color + activation + flash;
}
// Per-demo choreography lanes — gated by demo_id AND on nonzero values so
// every other demo is pixel-unchanged (each demo's pass is the only
// writer of its lanes, and lanes are exactly 0.0 everywhere else).
if (params.demo_id == 2.0) {
if (in.demo_yzw.x > 0.001) {
// Searchlight: cold clinical white — unmistakably NOT the spectral grammar.
color = color + vec3<f32>(0.82, 0.90, 1.00) * in.demo_yzw.x * (core * 1.8 + halo * 0.7);
}
if (in.demo_yzw.y > 0.001) {
// Interrogation shimmer: icy spectral strobe as the wave scrubs the past.
color = color + spectral(0.55 + params.loop_phase) * in.demo_yzw.y * (core * 0.9 + halo * 0.5)
+ vec3<f32>(1.0) * core * in.demo_yzw.y * 0.2;
}
if (in.demo_yzw.z > 0.001) {
// Detonation: crimson blaze + warm-white pinpoint.
color = color + vec3<f32>(1.00, 0.16, 0.10) * in.demo_yzw.z * (core * 1.9 + halo * 1.1)
+ vec3<f32>(1.0, 0.85, 0.8) * core * in.demo_yzw.z * 0.4;
}
} else if (params.demo_id == 4.0) {
// firewall: demo.y carries TWO value bands — intrusion flare (0..1]
// and membrane [2.6..2.9] — separated by range, one lane. demo.w is
// the crimson shock rim / sever blink. (demo_yzw = y/z/w lanes.)
let fy = in.demo_yzw.x;
let fw = in.demo_yzw.z;
// Intrusion flare: sickly green-white — a hue deliberately OUTSIDE
// both the FSRS palette and the thin-film band. Continuous across the
// band boundary (fades out as fy climbs toward the membrane band).
let flare = min(fy, 1.0) * (1.0 - smoothstep(1.0, 1.8, fy));
if (flare > 0.001) {
color = color + vec3<f32>(0.62, 1.00, 0.55) * flare * (core * 1.7 + halo * 0.9)
+ vec3<f32>(0.90, 1.00, 0.85) * core * flare * 0.5;
}
// Membrane: quarantine ring at d ≈ 0.75 with fresnel-ish falloff —
// green body, crimson edge. exp(-q·q) squares by multiplication and
// the pow base is clamped ≥ 0 (no pow(neg) anywhere).
let mw = smoothstep(1.5, 2.2, fy);
if (mw > 0.001) {
let q = (d - 0.75) * 9.0;
let ring = exp(-q * q);
let fresnel = pow(clamp(d / 0.75, 0.0, 1.0), 3.0);
let ring_col = mix(vec3<f32>(0.55, 1.00, 0.60), vec3<f32>(1.00, 0.20, 0.16),
smoothstep(0.72, 0.92, d));
color = color + ring_col * ring * fresnel * mw * 1.4;
}
// Shockwave: crimson RIM as the front passes (a rim, not a blaze).
if (fw > 0.001) {
let rim = smoothstep(0.45, 0.8, d) * (1.0 - smoothstep(0.85, 1.0, d));
color = color + vec3<f32>(1.00, 0.14, 0.10) * rim * fw * 1.5
+ vec3<f32>(1.00, 0.60, 0.50) * core * fw * 0.15;
}
}
// Additive target (src=one, dst=one): alpha is ignored, light accumulates.
return vec4<f32>(color * params.brightness, 1.0);
}
`,Qf=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read_write> nodes: array<Node>;
// x source index, y target index, z beat frame, w kind (0 recall, 1 backward)
@group(0) @binding(2) var<storage, read> path: array<vec4<u32>>;
// x source index, y target node index (Increment 7: force simulation edges)
@group(0) @binding(3) var<storage, read> edges: array<vec2<u32>>;
// --- Force-simulation helpers (Increment 7) ---
fn safe_normalize(v: vec3<f32>) -> vec3<f32> {
let l = length(v);
if (l < 0.0001) { return vec3<f32>(0.0); }
return v / l;
}
fn clamp_len(v: vec3<f32>, hi: f32) -> vec3<f32> {
let l = length(v);
if (l > hi && l > 0.0001) { return v * (hi / l); }
return v;
}
@compute @workgroup_size(64)
fn recall_sim(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i >= u32(params.node_count)) {
return;
}
let frame = params.frame;
var intensity = 0.0;
let steps = u32(params.path_count);
for (var s = 0u; s < steps; s = s + 1u) {
let step = path[s];
let bf = f32(step.z);
if (step.y == i) {
// Arrival: sharp attack as the wavefront lands, slow afterglow.
let attack = smoothstep(bf - 14.0, bf + 4.0, frame);
let decay = 1.0 - smoothstep(bf + 40.0, bf + 200.0, frame);
intensity = max(intensity, attack * decay);
}
if (step.x == i && step.x != step.y) {
// Departure: the source shimmers as the wave leaves it.
let rise = smoothstep(bf - 55.0, bf - 30.0, frame);
let fall = 1.0 - smoothstep(bf + 10.0, bf + 70.0, frame);
intensity = max(intensity, rise * fall * 0.45);
}
}
var node = nodes[i];
let flags = u32(node.color_flags.w);
let is_center = (flags & 1u) != 0u;
// Write recall intensity (existing behavior preserved).
node.demo.x = intensity;
// --- Increment 7: force simulation ---
// Capture mode (params._pad == 1.0): skip physics integration entirely.
// The storage-buffer state stays frozen at initial upload values,
// making same URL + frame → identical pixels (spec §4 Inc 9).
if (params._pad == 0.0) {
// 7B: center anchor — center node never moves.
// (WGSL forbids swizzle stores — reconstruct the vec4, preserving .w.)
if (is_center) {
node.pos_radius = vec4<f32>(0.0, 0.0, 0.0, node.pos_radius.w);
node.vel_retention = vec4<f32>(0.0, 0.0, 0.0, node.vel_retention.w);
nodes[i] = node;
return;
}
let pos = node.pos_radius.xyz;
var force = vec3<f32>(0.0);
// 7C: edge springs — scan existing edgeBuffer, no atomics.
for (var e = 0u; e < u32(params.edge_count); e = e + 1u) {
let edge = edges[e];
var other_idx = 0xffffffffu;
if (edge.x == i) { other_idx = edge.y; }
if (edge.y == i) { other_idx = edge.x; }
if (other_idx != 0xffffffffu && other_idx < u32(params.node_count)) {
let other = nodes[other_idx].pos_radius.xyz;
let delta = other - pos;
let dist = max(length(delta), 0.001);
let dir = delta / dist;
let stretch = dist - 34.0;
force = force + dir * stretch * 0.00055;
}
}
// 7D: soft repulsion (only ≤ 500 nodes for performance).
if (u32(params.node_count) <= 500u) {
for (var j = 0u; j < u32(params.node_count); j = j + 1u) {
if (j == i) { continue; }
let other = nodes[j].pos_radius.xyz;
let delta = pos - other;
let d2 = max(dot(delta, delta), 9.0);
force = force + safe_normalize(delta) * (7.5 / d2);
}
}
// Gentle centering: keeps the field in frame without crushing it.
force = force + (-pos) * 0.0008;
// 7B: velocity damping + cap, then position integration.
var vel = node.vel_retention.xyz;
vel = (vel + force) * 0.88;
vel = clamp_len(vel, 0.42);
node.vel_retention = vec4<f32>(vel, node.vel_retention.w);
node.pos_radius = vec4<f32>(pos + vel, node.pos_radius.w);
}
// When capture_mode (params._pad == 1.0), node is NOT written back —
// the storage buffer retains its initial upload values, guaranteeing
// deterministic pixels for the same frame index.
nodes[i] = node;
}
`,ll=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Camera {
view_proj: mat4x4<f32>,
right: vec4<f32>,
up: vec4<f32>,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<uniform> camera: Camera;
@group(0) @binding(2) var<storage, read> nodes: array<Node>;
// x source index, y target index, z beat frame, w kind (0 recall, 1 backward)
@group(0) @binding(3) var<storage, read> path: array<vec4<u32>>;
// Same thin-film band as the node shader (§7.1).
fn spectral(w_in: f32) -> vec3<f32> {
let w = fract(w_in);
// var, not let: WGSL only allows dynamic indexing through a reference.
var stops = array<vec3<f32>, 4>(
vec3<f32>(0.20, 0.28, 0.95),
vec3<f32>(0.20, 0.85, 0.90),
vec3<f32>(0.45, 1.00, 0.72),
vec3<f32>(0.85, 0.45, 1.00)
);
let f = w * 4.0;
let i = u32(floor(f)) % 4u;
let frac = f - floor(f);
let a = stops[i];
let b = stops[(i + 1u) % 4u];
return mix(a, b, frac);
}
struct VSOut {
@builtin(position) clip: vec4<f32>,
// x: t along segment (0 source → 1 target), y: side (-1..1)
@location(0) uv: vec2<f32>,
// x: beat frame, y: kind, z: segment visible (0 skips degenerate steps)
// Per-instance constant — flat keeps it bit-exact through the raster.
@location(1) @interpolate(flat) beat: vec3<f32>,
};
// (t, side) corners for two triangles of the ribbon.
const RIBBON = array<vec2<f32>, 6>(
vec2<f32>(0.0, -1.0),
vec2<f32>(1.0, -1.0),
vec2<f32>(1.0, 1.0),
vec2<f32>(0.0, -1.0),
vec2<f32>(1.0, 1.0),
vec2<f32>(0.0, 1.0)
);
@vertex
fn vs_main(
@builtin(vertex_index) vi: u32,
@builtin(instance_index) ii: u32
) -> VSOut {
var out: VSOut;
if (ii >= u32(params.path_count)) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
out.beat = vec3<f32>(0.0);
return out;
}
let step = path[ii];
let src = nodes[step.x];
let dst = nodes[step.y];
let corner = RIBBON[vi];
// Degenerate (origin beat: source == target) — emit nothing visible.
if (step.x == step.y) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
out.beat = vec3<f32>(0.0);
return out;
}
let a = camera.view_proj * vec4<f32>(src.pos_radius.xyz, 1.0);
let b = camera.view_proj * vec4<f32>(dst.pos_radius.xyz, 1.0);
// NDC-space perpendicular for constant screen width.
let ndc_a = a.xy / max(a.w, 0.0001);
let ndc_b = b.xy / max(b.w, 0.0001);
var dir = ndc_b - ndc_a;
let dlen = max(length(dir), 0.0001);
dir = dir / dlen;
let perp = vec2<f32>(-dir.y, dir.x);
// Ribbon half-width in NDC (aspect-corrected), ~2.5 px on a 900px-tall view.
let px = 2.5 / max(params.viewport_h, 1.0) * 2.0;
let width = vec2<f32>(px * (params.viewport_h / max(params.viewport_w, 1.0)), px);
let base = mix(a, b, corner.x);
let offset = perp * width * corner.y * base.w;
out.clip = vec4<f32>(base.xy + offset, base.zw);
out.uv = vec2<f32>(corner.x, corner.y);
out.beat = vec3<f32>(f32(step.z), f32(step.w), 1.0);
return out;
}
@fragment
fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
if (in.beat.z < 0.5) {
discard;
}
let frame = params.frame;
let bf = in.beat.x;
let t = in.uv.x;
// Wave departs 45 frames before the beat and lands exactly on it.
let progress = clamp((frame - (bf - 45.0)) / 45.0, 0.0, 1.0);
// Nothing before departure; trail lingers ~90 frames after arrival.
let live = smoothstep(bf - 46.0, bf - 44.0, frame)
* (1.0 - smoothstep(bf + 40.0, bf + 90.0, frame));
if (live <= 0.001) {
discard;
}
// The light packet: gaussian around the wavefront position.
let dwave = (t - progress) * 14.0;
let packet = exp(-dwave * dwave);
// Fading trail behind the packet — provenance stays visible a beat.
var trail = 0.0;
if (t < progress) {
trail = (1.0 - (progress - t)) * 0.22;
}
// Feather across the ribbon width.
let across = 1.0 - abs(in.uv.y);
let profile = across * across;
// Backward/contradiction hops burn hotter into the magenta rim (§7.4).
// Hue drifts one full spectral cycle per loop (seamless at the wrap).
// Kind 2 (salience-rescue probe): a gray failing beam — vector search
// visibly probing lookalikes and coming back empty. Kinds 0/1 unchanged.
var band = spectral(0.15 + t * 0.35 + params.loop_phase);
var packet_white = 0.35;
if (in.beat.y > 1.5) {
band = vec3<f32>(0.62, 0.66, 0.72);
packet_white = 0.18;
} else if (in.beat.y > 0.5) {
band = mix(band, vec3<f32>(1.0, 0.25, 0.45), 0.55);
}
let energy = (packet * 1.6 + trail) * profile * live;
let color = band * energy + vec3<f32>(1.0) * packet * profile * live * packet_white;
return vec4<f32>(color * params.brightness, 1.0);
}
`;function $f(l){return 60+l*60}function tp(l,t,e=8){const i=[...l.nodes].sort((o,h)=>o.id<h.id?-1:o.id>h.id?1:0),s=[...l.edges].sort((o,h)=>{const c=`${o.source}\0${o.target}\0${o.type}`,u=`${h.source}\0${h.target}\0${h.type}`;return c<u?-1:c>u?1:0}),n=bf(i,s,l.center_id,e),r=[];for(let o=0;o<n.beats.length;o++){const h=n.beats[o],c=t.indexById.get(h.nodeId);if(c===void 0)continue;const u=o>0?n.beats[o-1].nodeId:h.nodeId,d=t.indexById.get(u)??c;r.push({sourceIndex:d,targetIndex:c,beatFrame:$f(o),kind:h.kind==="contradiction"?Be.backwardCause:Be.recall,beatKind:h.kind,nodeId:h.nodeId,label:h.node.label})}const a=new Uint32Array(Math.max(1,r.length)*ns);return r.forEach((o,h)=>{a[h*ns]=o.sourceIndex,a[h*ns+1]=o.targetIndex,a[h*ns+2]=o.beatFrame,a[h*ns+3]=o.kind}),{data:a,steps:r,path:n}}const ep=24,hh=300;class ip{constructor(t){T(this,"engine");T(this,"pipeline",null);T(this,"bindGroup",null);T(this,"cameraBuffer",null);T(this,"nodeBuffer",null);T(this,"edgeBuffer",null);T(this,"cameraData",new Float32Array(ep));T(this,"nodeCount",0);T(this,"simPipeline",null);T(this,"simBindGroup",null);T(this,"pathBuffer",null);T(this,"pathPipeline",null);T(this,"pathBindGroup",null);T(this,"pathStepCount",0);T(this,"graph",null);T(this,"pathSteps",[]);this.engine=t,t.addPass(this)}upload(t,e,i){var d,f,p;const s=this.engine.gpuDevice;if(!s)return;const n=(i==null?void 0:i.recallPath)??!0,r=Zf(t);this.graph=r;const a=new Hn({seed:e}),{data:o,nodeCount:h}=hl(r,a.state.rng);this.nodeCount=h,(d=this.nodeBuffer)==null||d.destroy(),this.nodeBuffer=s.createBuffer({label:"observatory-node-state",size:Math.max(o.byteLength,64),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.COPY_SRC|GPUBufferUsage.VERTEX}),s.queue.writeBuffer(this.nodeBuffer,0,o.buffer);const c=Kf(r);(f=this.edgeBuffer)==null||f.destroy(),this.edgeBuffer=s.createBuffer({label:"observatory-edge-index",size:c.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),s.queue.writeBuffer(this.edgeBuffer,0,c.buffer);const u=n?tp(t,r):{steps:[],data:new Uint32Array(4)};this.pathSteps=u.steps,(p=this.pathBuffer)==null||p.destroy(),this.pathBuffer=s.createBuffer({label:"observatory-path-steps",size:u.data.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),s.queue.writeBuffer(this.pathBuffer,0,u.data.buffer),this.pathStepCount=this.pathSteps.length,this.engine.params[2]=h,this.engine.params[3]=r.edges.length,this.engine.params[4]=this.pathSteps.length,this.cameraBuffer||(this.cameraBuffer=s.createBuffer({label:"observatory-camera",size:this.cameraData.byteLength,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST})),this.createPipeline(s)}setPathSteps(t,e){var s;const i=this.engine.gpuDevice;i&&(this.pathSteps=e,this.pathStepCount=e.length,(s=this.pathBuffer)==null||s.destroy(),this.pathBuffer=i.createBuffer({label:"observatory-path-steps",size:Math.max(t.byteLength,16),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),i.queue.writeBuffer(this.pathBuffer,0,t.buffer),this.engine.params[4]=e.length,this.createPipeline(i))}createPipeline(t){if(!this.engine.paramsBuffer||!this.cameraBuffer||!this.nodeBuffer)return;if(this.pathBuffer){const i=t.createShaderModule({label:"observatory-simulate",code:Qf});this.simPipeline=t.createComputePipeline({label:"observatory-recall-sim",layout:"auto",compute:{module:i,entryPoint:"recall_sim"}});const s=[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.nodeBuffer}},{binding:2,resource:{buffer:this.pathBuffer}}];this.edgeBuffer&&s.push({binding:3,resource:{buffer:this.edgeBuffer}}),this.simBindGroup=t.createBindGroup({label:"observatory-recall-sim-bind",layout:this.simPipeline.getBindGroupLayout(0),entries:s})}const e=t.createShaderModule({label:"observatory-render-nodes",code:jf});if(this.pipeline=t.createRenderPipeline({label:"observatory-nodes",layout:"auto",vertex:{module:e,entryPoint:"vs_main"},fragment:{module:e,entryPoint:"fs_main",targets:[{format:this.engine.sceneFormat,blend:{color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),this.bindGroup=t.createBindGroup({label:"observatory-nodes-bind",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.cameraBuffer}},{binding:2,resource:{buffer:this.nodeBuffer}}]}),this.pathBuffer){const i=t.createShaderModule({label:"observatory-render-path",code:ll});this.pathPipeline=t.createRenderPipeline({label:"observatory-path",layout:"auto",vertex:{module:i,entryPoint:"vs_main"},fragment:{module:i,entryPoint:"fs_main",targets:[{format:this.engine.sceneFormat,blend:{color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),this.pathBindGroup=t.createBindGroup({label:"observatory-path-bind",layout:this.pathPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.cameraBuffer}},{binding:2,resource:{buffer:this.nodeBuffer}},{binding:3,resource:{buffer:this.pathBuffer}}]})}}compute(t){const e=this.engine.gpuDevice;if(!e||!this.cameraBuffer)return;const i=this.engine.params[6]||1,s=this.engine.params[7]||1,n=this.engine.params[1],r=ah(n,i/s,hh);if(this.cameraData.set(r.viewProj,0),this.cameraData[16]=r.right[0],this.cameraData[17]=r.right[1],this.cameraData[18]=r.right[2],this.cameraData[19]=0,this.cameraData[20]=r.up[0],this.cameraData[21]=r.up[1],this.cameraData[22]=r.up[2],this.cameraData[23]=0,e.queue.writeBuffer(this.cameraBuffer,0,this.cameraData),this.simPipeline&&this.simBindGroup&&this.nodeCount>0){const a=t.beginComputePass({label:"observatory-recall-sim"});a.setPipeline(this.simPipeline),a.setBindGroup(0,this.simBindGroup),a.dispatchWorkgroups(Math.ceil(this.nodeCount/64)),a.end()}}render(t){!this.pipeline||!this.bindGroup||this.nodeCount===0||(t.setPipeline(this.pipeline),t.setBindGroup(0,this.bindGroup),t.draw(6,this.nodeCount),this.pathPipeline&&this.pathBindGroup&&this.pathStepCount>0&&(t.setPipeline(this.pathPipeline),t.setBindGroup(0,this.pathBindGroup),t.draw(6,this.pathStepCount)))}get nodeStateBuffer(){return this.nodeBuffer}get cameraUniformBuffer(){return this.cameraBuffer}get nodeCountValue(){return this.nodeCount}get pathStepMeta(){return this.pathSteps}async pickAt(t,e){const i=this.engine.gpuDevice;if(!i||!this.nodeBuffer||!this.graph||this.nodeCount===0)return null;const s=this.nodeCount*vt*4,n=i.createBuffer({label:"observatory-pick-staging",size:s,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),r=i.createCommandEncoder({label:"observatory-pick-copy"});r.copyBufferToBuffer(this.nodeBuffer,0,n,0,s),i.queue.submit([r.finish()]);let a;try{await n.mapAsync(GPUMapMode.READ),a=new Float32Array(n.getMappedRange().slice(0))}catch{return n.destroy(),null}n.unmap(),n.destroy();const o=this.engine.params[6]||1,h=this.engine.params[7]||1,c=this.engine.params[1],u=ah(c,o/h,hh).viewProj,d=1/Math.tan(50*Math.PI/360);let f=-1,p=1/0;for(let m=0;m<this.nodeCount;m++){const g=m*vt+ce.posRadius,x=a[g],y=a[g+1],b=a[g+2],v=a[g+3],_=u[3]*x+u[7]*y+u[11]*b+u[15];if(_<=0)continue;const M=(u[0]*x+u[4]*y+u[8]*b+u[12])/_,A=(u[1]*x+u[5]*y+u[9]*b+u[13])/_,S=Math.max(v*d/_,.012),C=Math.hypot(M-t,A-e)/S;C<1.6&&C<p&&(p=C,f=m)}return f<0?null:{index:f,id:this.graph.nodes[f].id}}dispose(){var t,e,i,s;(t=this.nodeBuffer)==null||t.destroy(),(e=this.edgeBuffer)==null||e.destroy(),(i=this.cameraBuffer)==null||i.destroy(),(s=this.pathBuffer)==null||s.destroy(),this.nodeBuffer=null,this.edgeBuffer=null,this.cameraBuffer=null,this.pathBuffer=null,this.pipeline=null,this.bindGroup=null,this.simPipeline=null,this.simBindGroup=null,this.pathPipeline=null,this.pathBindGroup=null}}const vn=16,rs=4,lh=110,sp=180,np=.7,rp=.2,ap=360,op=18;function hp(l){if(l.edges.length>0){const t=l.centerIndex,e=l.edges.filter(i=>i.sourceIndex===t||i.targetIndex===t);if(e.length>0){let i=-1,s=-1;for(const n of e){const r=n.sourceIndex===t?n.targetIndex:n.sourceIndex,a=l.nodes[r];a&&a.retention>s&&(s=a.retention,i=r)}if(i>=0)return i}}for(let t=0;t<l.nodes.length;t++)if(t!==l.centerIndex)return t;return l.centerIndex}function lp(l,t,e=8192){const i=hp(l),n=l.nodes[i].id,r=ch(l,i),o=new Hn({seed:t+":birth:"+n}).state.rng,h=new Float32Array(e*vn),c=Math.floor(e*np),u=Math.floor(e*rp),d=e-c-u;for(let x=0;x<c;x++){const y=x*vn,[b,v,_]=al(x,c,lh+o()*(sp-lh),o);h[y+0]=r[0]+b,h[y+1]=r[1]+v,h[y+2]=r[2]+_,h[y+3]=o(),h[y+4]=r[0],h[y+5]=r[1],h[y+6]=r[2],h[y+7]=1+o()*1.8,h[y+8]=.55,h[y+9]=.32,h[y+10]=1,h[y+11]=o(),h[y+12]=0,h[y+13]=0,h[y+14]=0,h[y+15]=0}const f=l.edges.filter(x=>x.sourceIndex===i||x.targetIndex===i);for(let x=0;x<u;x++){const y=(c+x)*vn;if(f.length===0)continue;const b=x%f.length,v=f[b],_=v.sourceIndex===i?v.targetIndex:v.sourceIndex,M=ch(l,_),A=M[0]-r[0],S=M[1]-r[1],C=M[2]-r[2],z=Math.sqrt(A*A+S*S+C*C)||1,k=x/Math.max(1,u)*2+.5,U=o()*30,W=-S*U/z,R=A*U/z,I=0;h[y+0]=r[0]+A/z*k*80+W,h[y+1]=r[1]+S/z*k*80+R,h[y+2]=r[2]+C/z*k*80+I,h[y+3]=o(),h[y+4]=r[0],h[y+5]=r[1],h[y+6]=r[2],h[y+7]=1+o()*1.8,h[y+8]=.55,h[y+9]=.32,h[y+10]=1,h[y+11]=o(),h[y+12]=0,h[y+13]=0,h[y+14]=0,h[y+15]=0}const p=300;for(let x=0;x<d;x++){const y=(c+u+x)*vn,b=o()*Math.PI*2,v=o()*120;h[y+0]=r[0]+Math.cos(b)*v,h[y+1]=r[1]+Math.sin(b)*v,h[y+2]=r[2]+p*.6+o()*40,h[y+3]=o(),h[y+4]=r[0],h[y+5]=r[1],h[y+6]=r[2],h[y+7]=1+o()*1.8,h[y+8]=.55,h[y+9]=.32,h[y+10]=1,h[y+11]=o(),h[y+12]=0,h[y+13]=0,h[y+14]=0,h[y+15]=0}const m=cp(l,i),g=up();return{targetIndex:i,targetNodeId:n,particles:h,edgeSteps:m,timeline:g}}function ch(l,t){const e=l.nodes[t],i=l.nodes.length;if(e.isCenter&&l.centerIndex===t)return[0,0,0];const s=Math.PI*(3-Math.sqrt(5)),n=1-t/(i-1||1)*2,r=Math.sqrt(1-n*n),a=s*t,o=120,h=(t*7+3)%100/100*.1*o-.05*o,c=(t*13+7)%100/100*.1*o-.05*o,u=(t*17+11)%100/100*.1*o-.05*o;return[Math.cos(a)*r*o+h,n*o+c,Math.sin(a)*r*o+u]}function cp(l,t){const e=l.edges.filter(n=>n.sourceIndex===t||n.targetIndex===t),i=e.length;if(i===0)return new Uint32Array(0);const s=new Uint32Array(i*rs);for(let n=0;n<i;n++){const r=e[n],a=r.sourceIndex===t?r.targetIndex:r.sourceIndex,o=ap+n*op;s[n*rs+0]=t,s[n*rs+1]=a,s[n*rs+2]=o,s[n*rs+3]=0}return s}function up(){return[{label:"latent trace condensing",startFrame:60,endFrame:239},{label:"engram coalescence",startFrame:240,endFrame:329},{label:"memory ignition",startFrame:330,endFrame:359},{label:"associations engrave",startFrame:360,endFrame:509},{label:"stabilization",startFrame:510,endFrame:659}]}const dp=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
// 16 floats / 64 bytes per particle (matches birth-plan.ts layout).
struct BirthParticle {
start_life: vec4<f32>,
target_size: vec4<f32>,
color_phase: vec4<f32>,
state: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read_write> particles: array<BirthParticle>;
@compute @workgroup_size(64)
fn birth_compute(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i >= arrayLength(&particles)) {
return;
}
// Capture mode (params._pad == 1.0): skip physics integration.
// The storage-buffer state stays frozen at initial upload values.
if (params._pad == 1.0) {
return;
}
var particle = particles[i];
let frame = params.frame;
let phase = params.loop_phase;
// --- Convergence choreography (integer cycles per 720-frame loop) ---
// Phase offset (stagger) from start_life.w: 0..1 → delays convergence.
let stagger = particle.start_life.w;
// Effective frame: staggered loop frame (wraps at 720).
let effFrame = fract(phase + stagger * 0.15) * 720.0;
// --- Phase 1: latent trace condensing (frames 0239) ---
// Slow drift toward target.
var t: f32;
if (effFrame < 240.0) {
// Smooth ease-in: 0 → 1 over 240 frames.
t = effFrame / 240.0;
t = t * t * (3.0 - 2.0 * t); // smoothstep
}
// --- Phase 2: engram coalescence (frames 240329) ---
// Accelerated convergence to target.
else if (effFrame < 330.0) {
let localFrame = effFrame - 240.0;
// 0 → 1 over 90 frames, with slight overshoot then settle.
t = localFrame / 90.0;
t = t * t * (3.0 - 2.0 * t);
// Add a small overshoot (1.05) then settle back to 1.0.
t = 1.0 - 0.05 * (1.0 - t);
}
// --- Phase 3: memory ignition (frames 330359) ---
// Hold at target (flash handled in render).
else if (effFrame < 360.0) {
t = 1.0;
}
// --- Phase 4: associations engrave (frames 360509) ---
// Hold at target.
else if (effFrame < 510.0) {
t = 1.0;
}
// --- Phase 5: stabilization (frames 510719) ---
// Hold at target, then fade alpha for reset.
else {
let localFrame = effFrame - 510.0;
// Fade alpha to 0 for seamless reset at frame 0.
t = 1.0;
particle.state.w = 1.0 - smoothstep(0.0, 150.0, localFrame);
}
// Interpolate from start to target.
let startPos = particle.start_life.xyz;
let targetPos = particle.target_size.xyz;
// (WGSL forbids swizzle stores - reconstruct, preserving alpha in .w)
particle.state = vec4<f32>(mix(startPos, targetPos, t), particle.state.w);
// Alpha: particles fade in during convergence, fade out during reset.
let fadeIn = smoothstep(0.0, 60.0, effFrame);
particle.state.w = max(particle.state.w, fadeIn * 0.8);
particles[i] = particle;
}
`,fp=16,pp=6,mp=330,gp=359,yp=360;class xp{constructor(t){T(this,"engine");T(this,"nodeRenderer");T(this,"active");T(this,"computePipeline",null);T(this,"computeBindGroup",null);T(this,"particleBuffer",null);T(this,"particleCount",0);T(this,"renderPipeline",null);T(this,"renderBindGroup",null);T(this,"haloPipeline",null);T(this,"haloBindGroup",null);T(this,"haloIndexBuffer",null);T(this,"engravePipeline",null);T(this,"engraveBindGroup",null);T(this,"engraveBuffer",null);T(this,"engraveStepCount",0);T(this,"timeline",[]);T(this,"birthPlan",null);this.engine=t.engine,this.nodeRenderer=t.nodeRenderer,this.active=!1,this.engine.addPass(this)}get engraveSteps(){var t;return((t=this.birthPlan)==null?void 0:t.edgeSteps)??new Uint32Array(0)}upload(t){var n,r;const e=this.engine.gpuDevice;if(!e||!this.nodeRenderer.nodeStateBuffer)return;const i=this.nodeRenderer.graph;if(!i)return;this.birthPlan=lp(i,t),this.timeline=this.birthPlan.timeline;const s=this.birthPlan.particles.length/fp;this.particleCount=s,(n=this.particleBuffer)==null||n.destroy(),this.particleBuffer=e.createBuffer({label:"observatory-birth-particles",size:this.birthPlan.particles.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.particleBuffer,0,this.birthPlan.particles.buffer),(r=this.engraveBuffer)==null||r.destroy(),this.engraveStepCount=this.birthPlan.edgeSteps.length/4,this.engraveStepCount>0&&(this.engraveBuffer=e.createBuffer({label:"observatory-birth-engrave",size:this.birthPlan.edgeSteps.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),e.queue.writeBuffer(this.engraveBuffer,0,this.birthPlan.edgeSteps.buffer)),this.createComputePipeline(e),this.createRenderPipeline(e),this.createHaloPipeline(e),this.createEngravePipeline(e)}createComputePipeline(t){const e=t.createShaderModule({label:"observatory-birth-compute",code:dp});this.computePipeline=t.createComputePipeline({label:"observatory-birth-compute-pipeline",layout:"auto",compute:{module:e,entryPoint:"birth_compute"}});const i=[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.particleBuffer}}];this.computeBindGroup=t.createBindGroup({label:"observatory-birth-compute-bind",layout:this.computePipeline.getBindGroupLayout(0),entries:i})}createRenderPipeline(t){const i=t.createShaderModule({label:"observatory-birth-render",code:`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Camera {
view_proj: mat4x4<f32>,
right: vec4<f32>,
up: vec4<f32>,
};
struct BirthParticle {
start_life: vec4<f32>,
target_size: vec4<f32>,
color_phase: vec4<f32>,
state: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<uniform> camera: Camera;
@group(0) @binding(2) var<storage, read> particles: array<BirthParticle>;
struct VSOut {
@builtin(position) clip: vec4<f32>,
@location(0) uv: vec2<f32>,
@location(1) @interpolate(flat) color: vec3<f32>,
@location(2) @interpolate(flat) misc: vec4<f32>,
};
const CORNERS = array<vec2<f32>, 6>(
vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, -1.0),
vec2<f32>( 1.0, 1.0),
vec2<f32>(-1.0, 1.0)
);
@vertex
fn vs_main(
@builtin(vertex_index) vi: u32,
@builtin(instance_index) ii: u32
) -> VSOut {
var out: VSOut;
if (ii >= arrayLength(&particles)) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
return out;
}
let particle = particles[ii];
let corner = CORNERS[vi];
// Current position from state.xyz.
let pos = particle.state.xyz;
// Base size from target_size.w.
let baseSize = particle.target_size.w;
// Flash boost during ignition (frames 330359).
let frame = params.frame;
var flashBoost = 1.0;
if (frame >= 330.0 && frame <= 359.0) {
let flashT = (frame - 330.0) / 29.0; // 0..1 over flash frames
// Sharp flash: peaks at frame 345, fades by 359.
flashBoost = 1.0 + 3.0 * (1.0 - smoothstep(330.0, 345.0, frame))
+ 2.0 * smoothstep(345.0, 359.0, frame);
}
// Size: base + flash boost + pulse breathing.
let breath = 1.0 + 0.06 * params.pulse;
let halfSize = baseSize * 4.0 * breath * flashBoost;
let world = pos
+ camera.right.xyz * corner.x * halfSize
+ camera.up.xyz * corner.y * halfSize;
out.clip = camera.view_proj * vec4<f32>(world, 1.0);
out.uv = corner;
// Color: violet dust (0.55, 0.32, 1.00) with spectral rim.
let phase = particle.color_phase.w;
let spectralW = fract(params.loop_phase + phase);
var spectralColor: vec3<f32>;
var stops = array<vec3<f32>, 4>(
vec3<f32>(0.55, 0.32, 1.00), // violet base
vec3<f32>(0.40, 0.60, 1.00), // blue-violet
vec3<f32>(0.70, 0.45, 1.00), // magenta-violet
vec3<f32>(0.55, 0.32, 1.00) // wrap
);
let f = spectralW * 4.0;
let i = u32(floor(f)) % 4u;
let frac = f - floor(f);
spectralColor = mix(stops[i], stops[(i + 1u) % 4u], frac);
// Alpha from state.w (convergence progress + fade).
let alpha = particle.state.w;
out.color = spectralColor;
out.misc = vec4<f32>(baseSize, 0.0, 0.0, alpha);
return out;
}
@fragment
fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
let d = length(in.uv);
if (d > 1.0) {
discard;
}
let alpha = in.misc.w;
let core = smoothstep(0.25, 0.0, d);
let halo = pow(max(1.0 - d, 0.0), 2.0);
// Additive glow: core + halo.
let intensity = core * 1.5 + halo * 0.6;
// Flash boost during ignition.
let frame = params.frame;
var flash = 0.0;
if (frame >= 330.0 && frame <= 359.0) {
flash = smoothstep(330.0, 345.0, frame) * 2.0;
}
let color = in.color * (intensity + flash);
return vec4<f32>(color * params.brightness, 1.0);
}
`});this.renderPipeline=t.createRenderPipeline({label:"observatory-birth-render",layout:"auto",vertex:{module:i,entryPoint:"vs_main"},fragment:{module:i,entryPoint:"fs_main",targets:[{format:this.engine.sceneFormat,blend:{color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"}});const s=this.nodeRenderer.cameraUniformBuffer;this.renderBindGroup=t.createBindGroup({label:"observatory-birth-render-bind",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:s}},{binding:2,resource:{buffer:this.particleBuffer}}]})}createHaloPipeline(t){const i=t.createShaderModule({label:"observatory-birth-halo",code:`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Camera {
view_proj: mat4x4<f32>,
right: vec4<f32>,
up: vec4<f32>,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<uniform> camera: Camera;
@group(0) @binding(2) var<storage, read> nodes: array<Node>;
struct VSOut {
@builtin(position) clip: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn vs_main(
@builtin(vertex_index) vi: u32,
@builtin(instance_index) ii: u32
) -> VSOut {
var out: VSOut;
if (ii >= u32(params.node_count)) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
return out;
}
let node = nodes[ii];
let flags = u32(node.color_flags.w);
let is_target = (flags & 4u) != 0u; // flag 2: is birth target
if (!is_target) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
return out;
}
// Flash halo: only visible during ignition (frames 330359).
let frame = params.frame;
if (frame < 330.0 || frame > 359.0) {
out.clip = vec4<f32>(0.0, 0.0, 2.0, 1.0);
return out;
}
// Halo ring: expands during flash, fades by frame 359.
let flashT = (frame - 330.0) / 29.0; // 0..1
let ringRadius = 0.3 + flashT * 0.5; // expands 0.3 → 0.8
// Quad centered on target position.
let pos = node.pos_radius.xyz;
let cornerX = (f32(vi) / 3.0 - 1.0); // -1, 0, 1 (3 unique x)
let cornerY = (f32(vi % 3) / 1.5 - 1.0); // -1, 0, 1
// We use 4 vertices for a simple quad (vi 0..3).
let cx = cornerX * ringRadius;
let cy = cornerY * ringRadius;
let world = pos
+ camera.right.xyz * cx
+ camera.up.xyz * cy;
out.clip = camera.view_proj * vec4<f32>(world, 1.0);
// UV for radial fade.
out.uv = vec2<f32>(cx / ringRadius, cy / ringRadius);
return out;
}
@fragment
fn fs_main(in: VSOut) -> @location(0) vec4<f32> {
let d = length(in.uv);
if (d > 0.7) {
discard;
}
// Flash: white-hot core, violet rim.
let flashIntensity = 1.0 - smoothstep(0.0, 0.7, d);
let color = vec3<f32>(0.7, 0.4, 1.0) * flashIntensity * 2.0;
// Fade out as flash ends.
let frame = params.frame;
let fadeOut = 1.0 - smoothstep(345.0, 359.0, frame);
return vec4<f32>(color * params.brightness * fadeOut, 1.0);
}
`});this.haloPipeline=t.createRenderPipeline({label:"observatory-birth-halo",layout:"auto",vertex:{module:i,entryPoint:"vs_main"},fragment:{module:i,entryPoint:"fs_main",targets:[{format:this.engine.sceneFormat,blend:{color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"}});const s=this.nodeRenderer.cameraUniformBuffer;this.haloBindGroup=t.createBindGroup({label:"observatory-birth-halo-bind",layout:this.haloPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:s}},{binding:2,resource:{buffer:this.nodeRenderer.nodeStateBuffer}}]})}createEngravePipeline(t){if(this.engraveStepCount===0||!this.engraveBuffer)return;const e=t.createShaderModule({label:"observatory-birth-engrave",code:ll});this.engravePipeline=t.createRenderPipeline({label:"observatory-birth-engrave-pipeline",layout:"auto",vertex:{module:e,entryPoint:"vs_main"},fragment:{module:e,entryPoint:"fs_main",targets:[{format:this.engine.sceneFormat,blend:{color:{srcFactor:"one",dstFactor:"one",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one",operation:"add"}}}]},primitive:{topology:"triangle-list"}}),this.engraveBindGroup=t.createBindGroup({label:"observatory-birth-engrave-bind",layout:this.engravePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.nodeRenderer.cameraUniformBuffer}},{binding:2,resource:{buffer:this.nodeRenderer.nodeStateBuffer}},{binding:3,resource:{buffer:this.engraveBuffer}}]})}compute(t,e){const i=this.engine.params[9];if(this.active=i===1,!this.active||!this.computePipeline||!this.computeBindGroup)return;const s=t.beginComputePass({label:"observatory-birth-compute"});s.setPipeline(this.computePipeline),s.setBindGroup(0,this.computeBindGroup),s.dispatchWorkgroups(Math.ceil(this.particleCount/64)),s.end()}render(t,e){this.active&&(this.renderPipeline&&this.renderBindGroup&&this.particleCount>0&&(t.setPipeline(this.renderPipeline),t.setBindGroup(0,this.renderBindGroup),t.draw(pp,this.particleCount)),this.haloPipeline&&this.haloBindGroup&&e>=mp&&e<=gp&&(t.setPipeline(this.haloPipeline),t.setBindGroup(0,this.haloBindGroup),t.draw(4,this.nodeRenderer.nodeCountValue)),this.engravePipeline&&this.engraveBindGroup&&this.engraveStepCount>0&&e>=yp&&(t.setPipeline(this.engravePipeline),t.setBindGroup(0,this.engraveBindGroup),t.draw(6,this.engraveStepCount)))}dispose(){var t,e,i,s,n,r,a,o,h,c,u;(t=this.particleBuffer)==null||t.destroy(),this.particleBuffer=null,(i=(e=this.computePipeline)==null?void 0:e.destroy)==null||i.call(e),this.computePipeline=null,this.computeBindGroup=null,(n=(s=this.renderPipeline)==null?void 0:s.destroy)==null||n.call(s),this.renderPipeline=null,this.renderBindGroup=null,(a=(r=this.haloPipeline)==null?void 0:r.destroy)==null||a.call(r),this.haloPipeline=null,this.haloBindGroup=null,(o=this.haloIndexBuffer)==null||o.destroy(),this.haloIndexBuffer=null,(c=(h=this.engravePipeline)==null?void 0:h.destroy)==null||c.call(h),this.engravePipeline=null,this.engraveBindGroup=null,(u=this.engraveBuffer)==null||u.destroy(),this.engraveBuffer=null}}function bp(l){const t=l.hopSlot.toFixed(1),e=l.causeDepth.toFixed(1);return`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read_write> nodes: array<Node>;
// 1 u32/node: bits 0-15 hopDepth (0xffff unreached), 16 failure, 17 cause,
// 18 lookalike, 19-21 lookalike k (rescue-plan.ts packing).
@group(0) @binding(2) var<storage, read> wave: array<u32>;
const HOP_SLOT: f32 = ${t};
const CAUSE_DEPTH: f32 = ${e};
const TAU: f32 = 6.28318530717958647;
fn env(f: f32, a0: f32, a1: f32, r0: f32, r1: f32) -> f32 {
return smoothstep(a0, a1, f) * (1.0 - smoothstep(r0, r1, f));
}
fn arrival(d: f32) -> f32 {
return min(260.0 + HOP_SLOT * d, 514.0);
}
@compute @workgroup_size(64)
fn rescue_choreo(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i >= u32(params.node_count)) {
return;
}
if (i >= arrayLength(&wave)) {
return;
}
// Belt-and-braces atop the TS gate: salience-rescue is demo index 2.
if (params.demo_id != 2.0) {
return;
}
let packed = wave[i];
let depth_u = packed & 0xffffu;
let d = f32(depth_u);
let is_failure = (packed & 0x10000u) != 0u;
let is_cause = (packed & 0x20000u) != 0u;
let is_look = (packed & 0x40000u) != 0u;
let look_k = f32((packed >> 19u) & 0x7u);
let f = params.frame;
var dx = 0.0;
var dy = 0.0;
var dz = 0.0;
var dw = 0.0;
if (is_failure) {
// Detonation spike, wound simmer, recognition flare as the arc lands.
dw = dw + env(f, 90.0, 96.0, 120.0, 168.0);
dw = dw + 0.35 * env(f, 100.0, 130.0, 600.0, 656.0);
dw = dw + 0.35 * env(f, 552.0, 562.0, 580.0, 640.0);
// Symptom backlight while the cause burns.
dx = dx + 0.4 * env(f, 556.0, 566.0, 620.0, 668.0);
}
if (!is_failure && depth_u >= 1u && depth_u <= 12u) {
// Shockwave blink: crimson concussion, 3 frames/hop of REAL graph distance.
dw = dw + 0.75 * exp(-0.3 * d)
* env(f, 92.0 + 3.0 * d, 96.0 + 3.0 * d, 96.0 + 3.0 * d, 122.0 + 3.0 * d);
}
if (is_look) {
let fk = 138.0 + 28.0 * look_k;
// Searchlight flare — cold pop, sequential, on camera.
dy = dy + env(f, fk - 6.0, fk, fk + 10.0, fk + 26.0);
// Ash residue — the struck-through lookalike stays in frame until the verdict.
dy = dy + 0.15 * smoothstep(fk + 10.0, fk + 26.0, f) * (1.0 - smoothstep(600.0, 656.0, f));
}
if (!is_failure && depth_u >= 1u && d <= CAUSE_DEPTH) {
let wd = arrival(d);
// Interrogation flicker: 24 integer sine cycles per loop, per-depth phase.
let flicker = 0.75 + 0.25 * sin(TAU * 24.0 * params.loop_phase + 1.7 * d);
dz = dz + env(f, wd - 10.0, wd, wd + 28.0, wd + 64.0) * flicker;
// Scanned ember.
dz = dz + 0.08 * smoothstep(wd + 28.0, wd + 64.0, f) * (1.0 - smoothstep(580.0, 640.0, f));
}
if (is_cause) {
// Cause ignition rides the EXISTING recall response (render-nodes.wgsl):
// spectral() thin-film band + white-hot core + sprite swell at full intensity.
dx = dx + env(f, 520.0, 546.0, 640.0, 700.0);
}
// WGSL forbids swizzle stores — reconstruct the FULL vec4; pos/vel/color
// lanes pass through untouched (the force sim owns them).
var node = nodes[i];
node.demo = vec4<f32>(dx, dy, dz, dw);
nodes[i] = node;
}
`}const vp=2;class wp{constructor(t){T(this,"engine");T(this,"nodeRenderer");T(this,"plan");T(this,"pipeline",null);T(this,"bindGroup",null);T(this,"waveBuffer",null);this.engine=t.engine,this.nodeRenderer=t.nodeRenderer,this.plan=t.plan,this.engine.addPass(this)}upload(){var i;const t=this.engine.gpuDevice;if(!t||!this.engine.paramsBuffer||!this.plan.viable||!this.nodeRenderer.nodeStateBuffer||this.nodeRenderer.nodeCountValue===0)return;(i=this.waveBuffer)==null||i.destroy(),this.waveBuffer=t.createBuffer({label:"observatory-rescue-wave",size:Math.max(4,this.plan.waveData.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),t.queue.writeBuffer(this.waveBuffer,0,this.plan.waveData.buffer);const e=t.createShaderModule({label:"observatory-rescue-choreo",code:bp(this.plan.consts)});this.pipeline=t.createComputePipeline({label:"observatory-rescue-choreo",layout:"auto",compute:{module:e,entryPoint:"rescue_choreo"}}),this.bindGroup=t.createBindGroup({label:"observatory-rescue-bind",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.nodeRenderer.nodeStateBuffer}},{binding:2,resource:{buffer:this.waveBuffer}}]})}compute(t){if(this.engine.params[9]!==vp||!this.pipeline||!this.bindGroup)return;const e=this.nodeRenderer.nodeCountValue;if(e===0)return;const i=t.beginComputePass({label:"observatory-rescue-choreo"});i.setPipeline(this.pipeline),i.setBindGroup(0,this.bindGroup),i.dispatchWorkgroups(Math.ceil(e/64)),i.end()}dispose(){var t;(t=this.waveBuffer)==null||t.destroy(),this.waveBuffer=null,this.pipeline=null,this.bindGroup=null}}const _p=4,Mp=90,Sp=138,Ap=28,Tp=260,Ip=514,uh=560,Cp=600,si=65535,zp=48,Bp={causal:0,temporal:1,shared_concepts:2,complementary:3,semantic:4};function cl(l,t){const e=new Hn({seed:t});return hl(l,e.state.rng).data}function Fp(l){const t=new Uint32Array(l.nodes.length);for(const e of l.edges)t[e.sourceIndex]++,t[e.targetIndex]++;return t}function Pp(l,t){const e=l.nodes.length;if(e===0)return-1;const i=Fp(l),s=r=>{const a=l.nodes[r],o=new Set(a.tags.map(f=>f.toLowerCase()));let h=0;(o.has("failure")||o.has("guardrail"))&&(h+=3),(o.has("confusion")||o.has("weak-spot"))&&(h+=2),h+=Math.min(i[r],8)/8;const c=t[r*vt+0],u=t[r*vt+1],d=t[r*vt+2];return Math.sqrt(c*c+u*u+d*d)>=54&&(h+=.5),h},n=[r=>r!==l.centerIndex&&!l.nodes[r].suppressed&&i[r]>=2,r=>r!==l.centerIndex&&!l.nodes[r].suppressed,r=>r!==l.centerIndex,()=>!0];for(const r of n){let a=-1,o=-1/0;for(let h=0;h<e;h++){if(!r(h))continue;const c=s(h);c>o&&(o=c,a=h)}if(a>=0)return a}return-1}function kp(l,t){const e=l.nodes.length,i=new Uint16Array(e).fill(si),s=new Int32Array(e).fill(-1);if(t<0||t>=e)return{depths:i,parents:s};const n=Array.from({length:e},()=>[]);for(const a of l.edges){const o=Bp[a.type]??5;n[a.sourceIndex].push({nbr:a.targetIndex,rank:o}),n[a.targetIndex].push({nbr:a.sourceIndex,rank:o})}for(const a of n)a.sort((o,h)=>o.rank-h.rank||o.nbr-h.nbr);i[t]=0;const r=[t];for(let a=0;a<r.length;a++){const o=r[a];for(const{nbr:h}of n[o])i[h]===si&&(i[h]=i[o]+1,r.push(h))}for(let a=0;a<e;a++)if(!(i[a]===si||i[a]===0)){for(const{nbr:o}of n[a])if(i[o]===i[a]-1){s[a]=o;break}}return{depths:i,parents:s}}function Ep(l,t,e,i){const s=new Map;for(const n of l.nodes)s.set(n.id,n.createdAt);for(const n of[3,2,1]){const r=[];for(let f=0;f<t.nodes.length;f++){if(f===t.centerIndex||f===i)continue;const p=e[f];p===si||p<n||r.push(f)}if(r.length===0)continue;let a=r.filter(f=>t.nodes[f].retention<=.45);a.length===0&&(a=r);const o=new Map;let h=1/0,c=-1/0;for(const f of a){const p=s.get(t.nodes[f].id),m=p?Date.parse(p):NaN;Number.isFinite(m)&&(o.set(f,m),m<h&&(h=m),m>c&&(c=m))}const u=f=>{const p=o.get(f);return p===void 0?0:c===h?1:(c-p)/(c-h)},d=f=>2*(1-t.nodes[f].retention)+.5*Math.min(e[f],6)/6+.5*u(f);return a.sort((f,p)=>{const m=d(f),g=d(p);return g!==m?g-m:e[p]!==e[f]?e[p]-e[f]:f-p}),{index:a[0],depth:e[a[0]]}}return{index:-1,depth:0}}function Rp(l,t,e,i,s){const n=l[e*vt+0],r=l[e*vt+1],a=l[e*vt+2],o=[];for(let h=0;h<t;h++){if(h===e||h===i||h===s)continue;const c=l[h*vt+0]-n,u=l[h*vt+1]-r,d=l[h*vt+2]-a;o.push({i:h,d2:c*c+u*u+d*d})}return o.sort((h,c)=>h.d2-c.d2||h.i-c.i),o.slice(0,_p).map(h=>h.i)}function Hr(l){const t=Math.max(1,l);return Math.min(84,Math.max(14,Math.floor(252/t)))}function Lp(l,t){return Math.min(Tp+t*l,Ip)}function dh(l){return Sp+Ap*l}function de(l){return l.length>64?l.slice(0,64)+"…":l}const as=4;function Pr(l){const t=new Uint32Array(l);return t.fill(si),{viable:!1,failureIndex:-1,causeIndex:-1,lookalikeIndices:[],hopDepths:new Uint16Array(l).fill(si),causeDepth:0,hopSlot:Hr(3),waveData:t,pathData:new Uint32Array(4),pathMetas:[],spineBeats:[],verdict:{headline:"root cause found",causeLabel:"",failureLabel:"",causeDate:"",hops:0,k:0,receipt:""},consts:{hopSlot:Hr(3),causeDepth:3}}}function Op(l,t,e){var R;const i=t.nodes.length;if(i===0)return Pr(0);const s=cl(t,e),n=Pp(t,s);if(n<0)return Pr(i);const{depths:r,parents:a}=kp(t,n),o=Ep(l,t,r,n);if(o.index<0){const I=Pr(i);return I.failureIndex=n,I.hopDepths=r,I}const h=o.index,c=Math.max(1,o.depth),u=Hr(c),d=I=>Lp(I,u),f=Rp(s,i,n,h,t.centerIndex),p=f.length,m=new Uint32Array(i);for(let I=0;I<i;I++){let N=r[I]&65535;I===n&&(N|=65536),I===h&&(N|=1<<17),m[I]=N}f.forEach((I,N)=>{m[I]|=1<<18|N<<19});const g=[];f.forEach((I,N)=>{g.push({src:n,dst:I,bf:dh(N),kind:Be.probe,beatKind:"probe"})});const x=[];{let I=h;for(;I!==n&&I>=0&&a[I]>=0;)x.push(I),I=a[I]}const y=new Set(x),b=[];for(let I=0;I<i;I++){if(I===n||y.has(I))continue;const N=r[I];N===si||N<1||N>c||a[I]<0||b.push(I)}b.sort((I,N)=>r[I]-r[N]||I-N);const v=[...x.slice().reverse(),...b].slice(0,zp);v.sort((I,N)=>r[I]-r[N]||I-N);for(const I of v)g.push({src:a[I],dst:I,bf:d(r[I]),kind:Be.backwardCause,beatKind:"wave"});g.push({src:h,dst:n,bf:uh,kind:Be.backwardCause,beatKind:"arc"});const _=new Uint32Array(Math.max(1,g.length)*as),M=[];g.forEach((I,N)=>{_[N*as+0]=I.src,_[N*as+1]=I.dst,_[N*as+2]=I.bf,_[N*as+3]=I.kind,M.push({sourceIndex:I.src,targetIndex:I.dst,beatFrame:I.bf,kind:I.kind,beatKind:I.beatKind,nodeId:t.nodes[I.dst].id,label:de(t.nodes[I.dst].label)})});const A=de(t.nodes[n].label),S=de(t.nodes[h].label),C=[],z=(I,N,wt,Bt)=>{C.push({sourceIndex:n,targetIndex:n,beatFrame:I,kind:N,beatKind:"rescue",nodeId:Bt,label:wt})};z(Mp,1,`failure: ${A}`,t.nodes[n].id),f.forEach((I,N)=>{z(dh(N),0,`lookalike ✗ · ${de(t.nodes[I].label)}`,t.nodes[I].id)}),z(d(1),1,"reaching backward through time","rescue-wave-start"),c>=2&&d(c)!==d(1)&&z(d(c),1,`scrubbing past · ${c} hops`,"rescue-wave-deep"),z(uh,1,`causal arc · ${S}`,t.nodes[h].id),z(Cp,1,"root cause found","rescue-verdict");const k=((R=l.nodes.find(I=>I.id===t.nodes[h].id))==null?void 0:R.createdAt)??"",U=k?k.slice(0,10):"",W={headline:"root cause found",causeLabel:S,failureLabel:A,causeDate:U,hops:c,k:p,receipt:`${c} hops back · ${U} · vector search: 0 for ${p}`};return{viable:!0,failureIndex:n,causeIndex:h,lookalikeIndices:f,hopDepths:r,causeDepth:c,hopSlot:u,waveData:m,pathData:_,pathMetas:M,spineBeats:C,verdict:W,consts:{hopSlot:u,causeDepth:c}}}const Np=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read_write> nodes: array<Node>;
// 1 u32/node: bits 0-7 rank, 8 isDrifting, 9 isRescued, 10-11 rescue slot k
// (forgetting-plan.ts packing). Non-drifting nodes are exactly 0.
@group(0) @binding(2) var<storage, read> horizon: array<u32>;
fn env(f: f32, a0: f32, a1: f32, r0: f32, r1: f32) -> f32 {
return smoothstep(a0, a1, f) * (1.0 - smoothstep(r0, r1, f));
}
@compute @workgroup_size(64)
fn forgetting_choreo(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i >= u32(params.node_count)) {
return;
}
if (i >= arrayLength(&horizon)) {
return;
}
// Belt-and-braces atop the TS gate: forgetting-horizon is demo index 3.
if (params.demo_id != 3.0) {
return;
}
let packed = horizon[i];
let is_drifting = (packed & 0x100u) != 0u;
let is_rescued = (packed & 0x200u) != 0u;
let rank01 = f32(packed & 0xffu) / 255.0;
let k = f32((packed >> 10u) & 0x3u);
let f = params.frame;
// Master release: every lane is exactly 0.0 by frame 712 — the seam wall.
let master = 1.0 - smoothstep(660.0, 712.0, f);
var dx = 0.0;
var dz = 0.0;
if (is_drifting) {
let onset = 90.0 + 42.0 * rank01;
// Phase 1 — the drift: dim + fall to the 0.55 plateau, retention-staggered.
let phase1 = 0.55 * smoothstep(onset, onset + 210.0, f);
if (is_rescued) {
let rk = 318.0 + 60.0 * k;
// Snap-back begins 22 frames before the recall ribbon lands at rk.
dz = master * phase1 * (1.0 - smoothstep(rk - 22.0, rk + 6.0, f));
// Ignition rides the EXISTING recall response (render-nodes.wgsl):
// spectral() thin-film band + white-hot core + sprite swell for free.
dx = master * env(f, rk - 26.0, rk, rk + 60.0, rk + 130.0);
} else {
// Phase 2 — the sink: to exactly 1.0 over 640..660 (the ~6% floor era).
let phase2 = 0.45 * smoothstep(480.0 + 24.0 * rank01, 640.0, f);
dz = master * (phase1 + phase2);
}
}
// WGSL forbids swizzle stores — reconstruct the FULL vec4; pos/vel/color
// lanes pass through untouched (the force sim owns them). demo.y and
// demo.w are hard 0.0: the rescue/firewall grammars can never fire here.
var node = nodes[i];
node.demo = vec4<f32>(dx, 0.0, dz, 0.0);
nodes[i] = node;
}
`,Dp=3;class Up{constructor(t){T(this,"engine");T(this,"nodeRenderer");T(this,"plan");T(this,"pipeline",null);T(this,"bindGroup",null);T(this,"horizonBuffer",null);this.engine=t.engine,this.nodeRenderer=t.nodeRenderer,this.plan=t.plan,this.engine.addPass(this)}upload(){var i;const t=this.engine.gpuDevice;if(!t||!this.engine.paramsBuffer||!this.plan.viable||!this.nodeRenderer.nodeStateBuffer||this.nodeRenderer.nodeCountValue===0)return;(i=this.horizonBuffer)==null||i.destroy(),this.horizonBuffer=t.createBuffer({label:"observatory-forgetting-horizon",size:Math.max(4,this.plan.horizonData.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),t.queue.writeBuffer(this.horizonBuffer,0,this.plan.horizonData.buffer);const e=t.createShaderModule({label:"observatory-forgetting-choreo",code:Np});this.pipeline=t.createComputePipeline({label:"observatory-forgetting-choreo",layout:"auto",compute:{module:e,entryPoint:"forgetting_choreo"}}),this.bindGroup=t.createBindGroup({label:"observatory-forgetting-bind",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.nodeRenderer.nodeStateBuffer}},{binding:2,resource:{buffer:this.horizonBuffer}}]})}compute(t){if(this.engine.params[9]!==Dp||!this.pipeline||!this.bindGroup)return;const e=this.nodeRenderer.nodeCountValue;if(e===0)return;const i=t.beginComputePass({label:"observatory-forgetting-choreo"});i.setPipeline(this.pipeline),i.setBindGroup(0,this.bindGroup),i.dispatchWorkgroups(Math.ceil(e/64)),i.end()}dispose(){var t;(t=this.horizonBuffer)==null||t.destroy(),this.horizonBuffer=null,this.pipeline=null,this.bindGroup=null}}const Vp=318,Gp=60,ul=3,Wp=132,Hp=60,qp=540,Xp=660;function Yp(l){const t=[];for(let s=0;s<l.nodes.length;s++)s!==l.centerIndex&&t.push(s);t.sort((s,n)=>l.nodes[s].retention-l.nodes[n].retention||s-n);const e=t.length;if(e===0)return[];const i=Math.min(e,Math.max(Math.min(ul,e),Math.round(.25*e)));return t.slice(0,i)}function Jp(l,t){const e=new Uint32Array(l.nodes.length);for(const n of l.edges)e[n.sourceIndex]++,e[n.targetIndex]++;const i=n=>2*l.nodes[n].retention+Math.min(e[n],8)/8;return t.slice().sort((n,r)=>i(r)-i(n)||n-r).slice(0,Math.min(ul,t.length))}function fh(l){return Vp+Gp*l}const os=4;function Zp(l){return{viable:!1,driftingIndices:[],rescuedIndices:[],horizonData:new Uint32Array(l),pathData:new Uint32Array(4),pathMetas:[],spineBeats:[]}}function Kp(l){const t=l.nodes.length,e=Yp(l);if(t<2||e.length<1)return Zp(t);const i=Jp(l,e),s=e.length,n=new Uint32Array(t);e.forEach((d,f)=>{const p=Math.round(255*f/Math.max(1,s-1));n[d]=p&255|256}),i.forEach((d,f)=>{n[d]|=512|f<<10});const r=new Uint32Array(Math.max(1,i.length)*os),a=[];i.forEach((d,f)=>{const p=fh(f);r[f*os+0]=l.centerIndex,r[f*os+1]=d,r[f*os+2]=p,r[f*os+3]=Be.recall,a.push({sourceIndex:l.centerIndex,targetIndex:d,beatFrame:p,kind:Be.recall,beatKind:"recall",nodeId:l.nodes[d].id,label:de(l.nodes[d].label)})});const o=[],h=(d,f,p,m)=>{o.push({sourceIndex:l.centerIndex,targetIndex:l.centerIndex,beatFrame:d,kind:f,beatKind:"horizon",nodeId:m,label:p})},c=new Set(i),u=e.filter(d=>!c.has(d)).slice(0,3);return u.forEach((d,f)=>{const p=Math.round(l.nodes[d].retention*100);h(Wp+Hp*f,1,`fading: ${de(l.nodes[d].label)} · retention ${p}%`,l.nodes[d].id)}),i.forEach((d,f)=>{h(fh(f),0,`recalled: ${de(l.nodes[d].label)}`,l.nodes[d].id)}),u.length>0&&h(qp,1,"the unrecalled sink · nothing is deleted","horizon-sink"),h(Xp,0,"every memory still retrievable","horizon-retrievable"),{viable:!0,driftingIndices:e,rescuedIndices:i,horizonData:n,pathData:r,pathMetas:a,spineBeats:o}}const jp=`
struct Params {
frame: f32,
loop_phase: f32,
node_count: f32,
edge_count: f32,
path_count: f32,
pulse: f32,
viewport_w: f32,
viewport_h: f32,
brightness: f32,
demo_id: f32,
time: f32,
_pad: f32,
};
struct Node {
pos_radius: vec4<f32>,
vel_retention: vec4<f32>,
color_flags: vec4<f32>,
demo: vec4<f32>,
};
@group(0) @binding(0) var<uniform> params: Params;
@group(0) @binding(1) var<storage, read_write> nodes: array<Node>;
// 1 u32/node: bits 0-7 shockDelay, 8 isIntruder, 9 isSeverNeighbor,
// 10-13 sever slot k (firewall-plan.ts packing). Every node carries a delay.
@group(0) @binding(2) var<storage, read> fire: array<u32>;
const TAU: f32 = 6.28318530717958647;
fn env(f: f32, a0: f32, a1: f32, r0: f32, r1: f32) -> f32 {
return smoothstep(a0, a1, f) * (1.0 - smoothstep(r0, r1, f));
}
@compute @workgroup_size(64)
fn firewall_choreo(@builtin(global_invocation_id) id: vec3<u32>) {
let i = id.x;
if (i >= u32(params.node_count)) {
return;
}
if (i >= arrayLength(&fire)) {
return;
}
// Belt-and-braces atop the TS gate: firewall is demo index 4.
if (params.demo_id != 4.0) {
return;
}
let packed = fire[i];
let delay = f32(packed & 0xffu);
let is_intruder = (packed & 0x100u) != 0u;
let is_sever = (packed & 0x200u) != 0u;
let k = f32((packed >> 10u) & 0xfu);
let f = params.frame;
var fy = 0.0;
var fw = 0.0;
if (is_intruder) {
// Intrusion flare: sickly strobe, band (0..1], 36 integer cycles/loop.
// C¹ handoff into the membrane over 330-332 (the rise sweeps the flare
// band exactly once — the condensation read is intentional).
fy = env(f, 90.0, 96.0, 310.0, 332.0)
* (0.55 + 0.45 * sin(TAU * 36.0 * params.loop_phase));
// Membrane: sustained ring band [2.60..2.90], 12 integer cycles/loop.
fy = fy + env(f, 330.0, 352.0, 620.0, 680.0)
* (2.75 + 0.15 * sin(TAU * 12.0 * params.loop_phase));
// Source detonation as the front leaves.
fw = env(f, 148.0, 153.0, 162.0, 196.0);
} else {
// Crimson rim as the radial front passes: arrival A = 150 + delay,
// amplitude fades with distance; A ∈ [150, 294] ⇒ all rims dead by 320.
let a = 150.0 + delay;
let amp = 0.9 - 0.45 * (delay / 144.0);
fw = amp * env(f, a - 2.0, a + 3.0, a + 8.0, a + 26.0);
if (is_sever) {
// Node-side receipt of the severed edge; last release 474.
let sk = 345.0 + 21.0 * k;
fw = fw + 0.6 * env(f, sk - 4.0, sk, sk + 6.0, sk + 24.0);
}
}
// WGSL forbids swizzle stores — reconstruct the FULL vec4; pos/vel/color
// lanes pass through untouched (the force sim owns them). demo.x and
// demo.z are hard 0.0: the recall and horizon grammars can never fire here.
var node = nodes[i];
node.demo = vec4<f32>(0.0, fy, 0.0, fw);
nodes[i] = node;
}
`,Qp=4;class $p{constructor(t){T(this,"engine");T(this,"nodeRenderer");T(this,"plan");T(this,"pipeline",null);T(this,"bindGroup",null);T(this,"fireBuffer",null);this.engine=t.engine,this.nodeRenderer=t.nodeRenderer,this.plan=t.plan,this.engine.addPass(this)}upload(){var i;const t=this.engine.gpuDevice;if(!t||!this.engine.paramsBuffer||!this.plan.viable||!this.nodeRenderer.nodeStateBuffer||this.nodeRenderer.nodeCountValue===0)return;(i=this.fireBuffer)==null||i.destroy(),this.fireBuffer=t.createBuffer({label:"observatory-firewall-fire",size:Math.max(4,this.plan.fireData.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),t.queue.writeBuffer(this.fireBuffer,0,this.plan.fireData.buffer);const e=t.createShaderModule({label:"observatory-firewall-choreo",code:jp});this.pipeline=t.createComputePipeline({label:"observatory-firewall-choreo",layout:"auto",compute:{module:e,entryPoint:"firewall_choreo"}}),this.bindGroup=t.createBindGroup({label:"observatory-firewall-bind",layout:this.pipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.engine.paramsBuffer}},{binding:1,resource:{buffer:this.nodeRenderer.nodeStateBuffer}},{binding:2,resource:{buffer:this.fireBuffer}}]})}compute(t){if(this.engine.params[9]!==Qp||!this.pipeline||!this.bindGroup)return;const e=this.nodeRenderer.nodeCountValue;if(e===0)return;const i=t.beginComputePass({label:"observatory-firewall-choreo"});i.setPipeline(this.pipeline),i.setBindGroup(0,this.bindGroup),i.dispatchWorkgroups(Math.ceil(e/64)),i.end()}dispose(){var t;(t=this.fireBuffer)==null||t.destroy(),this.fireBuffer=null,this.pipeline=null,this.bindGroup=null}}const tm=90,em=150,im=144,sm=330,nm=345,rm=21,am=6,om=480,hm=["failure","guardrail","confusion"];function lm(l){const t=l.nodes.length;if(t===0)return-1;const e=new Uint32Array(t);for(const n of l.edges)e[n.sourceIndex]++,e[n.targetIndex]++;const i=n=>l.nodes[n].tags.some(r=>hm.includes(r.toLowerCase())),s=[n=>n!==l.centerIndex&&!l.nodes[n].suppressed&&i(n),n=>n!==l.centerIndex&&!l.nodes[n].suppressed&&e[n]<=1,n=>n!==l.centerIndex&&!l.nodes[n].suppressed,n=>n!==l.centerIndex];for(const n of s){let r=-1;for(let a=0;a<t;a++)n(a)&&(r<0||l.nodes[a].retention<l.nodes[r].retention)&&(r=a);if(r>=0)return r}return-1}function cm(l,t,e){const i=l[e*vt+0],s=l[e*vt+1],n=l[e*vt+2],r=new Array(t);let a=0;for(let h=0;h<t;h++){const c=l[h*vt+0]-i,u=l[h*vt+1]-s,d=l[h*vt+2]-n,f=Math.sqrt(c*c+u*u+d*d);r[h]=f,f>a&&(a=f)}a<1e-6&&(a=1);const o=new Array(t);for(let h=0;h<t;h++)o[h]=Math.min(255,Math.max(0,Math.round(im*r[h]/a)));return o[e]=0,o}function um(l,t){const e=new Set;for(const i of l.edges)i.sourceIndex===t&&i.targetIndex!==t&&e.add(i.targetIndex),i.targetIndex===t&&i.sourceIndex!==t&&e.add(i.sourceIndex);return Array.from(e).sort((i,s)=>i-s).slice(0,am)}function ph(l){return nm+rm*l}const hs=4;function dm(l){return{viable:!1,intruderIndex:-1,severedNeighborIndices:[],shockDelays:[],fireData:new Uint32Array(l),pathData:new Uint32Array(4),pathMetas:[],spineBeats:[],verdict:{headline:"threat quarantined",intruderLabel:"",receipt:"memory held in review · Memory PR opened"}}}function fm(l,t){const e=l.nodes.length,i=lm(l);if(e===0||i<0)return dm(e);const s=cl(l,t),n=cm(s,e,i),r=um(l,i),a=new Uint32Array(e);for(let p=0;p<e;p++)a[p]=n[p]&255;a[i]=256,r.forEach((p,m)=>{a[p]|=512|m<<10});const o=new Uint32Array(Math.max(1,r.length)*hs),h=[];r.forEach((p,m)=>{const g=ph(m);o[m*hs+0]=i,o[m*hs+1]=p,o[m*hs+2]=g,o[m*hs+3]=Be.probe,h.push({sourceIndex:i,targetIndex:p,beatFrame:g,kind:Be.probe,beatKind:"sever",nodeId:l.nodes[p].id,label:de(l.nodes[p].label)})});const c=de(l.nodes[i].label),u=[],d=(p,m,g)=>{u.push({sourceIndex:i,targetIndex:i,beatFrame:p,kind:1,beatKind:"firewall",nodeId:g,label:m})};return d(tm,`intrusion · ${c}`,l.nodes[i].id),d(em,"immune response · shockwave","firewall-shock"),d(sm,"membrane forming","firewall-membrane"),r.forEach((p,m)=>{d(ph(m),`edge severed ✗ · ${de(l.nodes[p].label)}`,l.nodes[p].id)}),d(om,"threat quarantined","firewall-verdict"),{viable:!0,intruderIndex:i,severedNeighborIndices:r,shockDelays:n,fireData:a,pathData:o,pathMetas:h,spineBeats:u,verdict:{headline:"threat quarantined",intruderLabel:c,receipt:"memory held in review · Memory PR opened"}}}var pm=At(`<button class="absolute top-10 right-4 pointer-events-auto font-mono text-xs tracking-widest
text-[#5dcaa5]/70 hover:text-[#5dcaa5] border border-[#5dcaa5]/25 hover:border-[#5dcaa5]/60
bg-[#05060a]/70 rounded px-3 py-1.5 transition-colors" title="Exit Observatory (Esc)">× EXIT</button>`),mm=At("<button> </button>"),gm=At('<div class="absolute top-10 left-4 pointer-events-auto flex flex-col gap-1.5"></div>'),ym=At('<div class="absolute inset-0 flex items-center justify-center pointer-events-auto"><div class="text-[#5dcaa5] font-mono text-sm tracking-widest animate-pulse">LOADING MEMORY FIELD...</div></div>'),xm=At('<div class="absolute inset-0 flex items-center justify-center pointer-events-auto"><div class="text-red-400 font-mono text-sm border border-red-900/50 bg-red-950/30 px-4 py-2 rounded"> </div></div>'),bm=At('<div class="absolute inset-0 flex items-center justify-center pointer-events-auto"><div class="text-[#5dcaa5] font-mono text-sm tracking-widest">NO MEMORIES IN FIELD</div></div>'),vm=At('<div class="absolute inset-0 z-10 pointer-events-none"><!> <!> <!> <!> <!> <!> <!> <!> <!></div>'),wm=At("<div><div><!></div> <!></div>");function Ey(l,t){Ms(t,!0);let e=lt(t,"seed",3,"vestige-observatory-v1"),i=lt(t,"freezeFrame",3,null),s=lt(t,"capture",3,!1),n=lt(t,"showSwitcher",3,!0),r=lt(t,"embedded",3,!1),a=lt(t,"chrome",3,"full"),o=Pt(null);async function h(K){if(!t.onpick||!M||!D(o))return;const it=D(o).getBoundingClientRect();if(it.width===0||it.height===0)return;const jt=(K.clientX-it.left)/it.width*2-1,Pe=-((K.clientY-it.top)/it.height*2-1),q=await M.pickAt(jt,Pe);q&&t.onpick(q.id)}const c={"recall-path":"RECALL","engram-birth":"BIRTH","salience-rescue":"RESCUE","forgetting-horizon":"HORIZON",firewall:"FIREWALL"};let u=Pt(!s());function d(K){(K.key==="h"||K.key==="H")&&mt(u,!D(u)),K.key==="Escape"&&t.onexit&&t.onexit()}let f=Pt(null),p=Pt(!0),m=Pt(""),g=Pt(0),x=Pt(0),y=Pt(0),b=Pt(0),v=Pt(""),_=Pt(null),M=null,A=null,S=null,C=Pt(null),z=null,k=null,U=Pt(null),W=!1,R=Pt(yh([]));async function I(){mt(p,!0),mt(m,"");try{const K=await bl.graph({max_nodes:200,depth:3,sort:"connected"});mt(f,K,!0),mt(y,K.nodeCount,!0),mt(b,K.edgeCount,!0),mt(v,K.center_id,!0)}catch(K){mt(m,K instanceof Error?K.message:"Failed to load graph data",!0)}finally{mt(p,!1)}}function N(K,it){mt(g,K,!0),mt(x,it,!0)}function wt(K){W=!1,mt(_,K,!0),M=new ip(K)}function Bt(K){var it;(K.state==="unsupported"||K.state==="error")&&((it=t.onfallback)==null||it.call(t,K.reason))}gl(()=>{if(D(_)&&M&&D(f)&&!W){W=!0;const K=t.demo==="engram-birth",it=t.demo==="salience-rescue",jt=t.demo==="forgetting-horizon",Pe=t.demo==="firewall";if(M.upload(D(f),e(),{recallPath:!K&&!it&&!jt&&!Pe}),K){A=new xp({engine:D(_),nodeRenderer:M,seed:e()}),A.upload(e());const q=A.engraveSteps,Ot=[];for(let F=0;F<q.length/4;F++)Ot.push({sourceIndex:q[F*4],targetIndex:q[F*4+1],beatFrame:q[F*4+2],kind:q[F*4+3],beatKind:"engrave",nodeId:`engrave-${F}`,label:"edge engraved"});M.setPathSteps(q,Ot),mt(R,A.timeline.map((F,P)=>({sourceIndex:0,targetIndex:0,beatFrame:F.startFrame,kind:0,beatKind:"birth",nodeId:`birth-${P}`,label:F.label})),!0)}else if(it){const q=Op(D(f),M.graph,e());mt(C,q,!0),q.viable&&(S=new wp({engine:D(_),nodeRenderer:M,plan:q}),S.upload(),M.setPathSteps(q.pathData,q.pathMetas)),mt(R,q.spineBeats,!0)}else if(jt){const q=Kp(M.graph);q.viable&&(z=new Up({engine:D(_),nodeRenderer:M,plan:q}),z.upload(),M.setPathSteps(q.pathData,q.pathMetas)),mt(R,q.spineBeats,!0)}else if(Pe){const q=fm(M.graph,e());mt(U,q,!0),q.viable&&(k=new $p({engine:D(_),nodeRenderer:M,plan:q}),k.upload(),M.setPathSteps(q.pathData,q.pathMetas)),mt(R,q.spineBeats,!0)}else mt(R,M.pathSteps,!0);D(_).demoClock.reset()}}),mh(()=>{I()});var nt=wm();xl("keydown",yl,d);let ht;var et=rt(nt);let Lt;var ye=rt(et);Hf(ye,{get demo(){return t.demo},get seed(){return e()},get freezeFrame(){return i()},onframe:N,onready:wt,onstatus:Bt}),st(et),vh(et,K=>mt(o,K),()=>D(o));var Gi=ct(et,2);{var hi=K=>{var it=vm(),jt=rt(it);{var Pe=J=>{Sf(J,{get demoMode(){return t.demo},get seed(){return e()},get nodeCount(){return D(y)},get edgeCount(){return D(b)},get centerId(){return D(v)},get frameCount(){return D(g)},get fpsEstimate(){return D(x)},get freezeFrame(){return i()},get loading(){return D(p)},get error(){return D(m)}})};zt(jt,J=>{a()==="full"&&J(Pe)})}var q=ct(jt,2);{var Ot=J=>{var at=pm();wn("click",at,function(...le){var se;(se=t.onexit)==null||se.apply(this,le)}),xt(J,at)};zt(q,J=>{a()==="full"&&t.onexit&&J(Ot)})}var F=ct(q,2);{var P=J=>{var at=gm();bh(at,20,()=>Fa,le=>le,(le,se)=>{var xe=mm(),zs=rt(xe,!0);st(xe),oe(()=>{us(xe,1,`font-mono text-[11px] tracking-widest text-left rounded px-3 py-1.5 border transition-colors
${se===t.demo?"text-[#05060a] bg-[#5dcaa5] border-[#5dcaa5]":"text-[#5dcaa5]/60 hover:text-[#5dcaa5] bg-[#05060a]/70 border-[#5dcaa5]/20 hover:border-[#5dcaa5]/50"}`),Yr(xe,"title",`Play the ${c[se]??""} moment`),Xt(zs,c[se])}),wn("click",xe,()=>{var Pa;return(Pa=t.ondemochange)==null?void 0:Pa.call(t,se)}),xt(le,xe)}),st(at),xt(J,at)};zt(F,J=>{a()==="full"&&n()&&J(P)})}var E=ct(F,2);{var G=J=>{var at=ym();xt(J,at)};zt(E,J=>{D(p)&&J(G)})}var L=ct(E,2);{var j=J=>{var at=xm(),le=rt(at),se=rt(le,!0);st(le),st(at),oe(()=>Xt(se,D(m))),xt(J,at)};zt(L,J=>{D(m)&&!D(p)&&J(j)})}var Q=ct(L,2);{var ot=J=>{Cf(J,{get steps(){return D(R)},get frame(){return D(g)}})};zt(Q,J=>{a()==="full"&&J(ot)})}var _t=ct(Q,2);{var bt=J=>{ih(J,{get frame(){return D(g)},get verdict(){return D(C).verdict}})};zt(_t,J=>{var at;a()==="full"&&t.demo==="salience-rescue"&&((at=D(C))!=null&&at.viable)&&J(bt)})}var ke=ct(_t,2);{var Wi=J=>{{let at=Xr(()=>({headline:D(U).verdict.headline,causeLabel:D(U).verdict.intruderLabel,receipt:D(U).verdict.receipt}));ih(J,{get frame(){return D(g)},tone:"quarantine",fadeWindow:[480,495,605,620],get verdict(){return D(at)}})}};zt(ke,J=>{var at;a()==="full"&&t.demo==="firewall"&&((at=D(U))!=null&&at.viable)&&J(Wi)})}var ie=ct(ke,2);{var Cs=J=>{var at=bm();xt(J,at)};zt(ie,J=>{!D(p)&&D(f)&&D(f).nodeCount===0&&J(Cs)})}st(it),xt(K,it)};zt(Gi,K=>{D(u)&&K(hi)})}st(nt),oe(()=>{ht=us(nt,1,`${r()?"absolute":"fixed"} inset-0 overflow-hidden bg-[#05060a]`,null,ht,{"cursor-none":s()}),Lt=us(et,1,"absolute inset-0 z-0",null,Lt,{"cursor-crosshair":!!t.onpick&&!s()})}),wn("click",et,h),xt(l,nt),Ss()}xh(["click"]);export{Ni as $,wl as A,Mh as B,V as C,lg as D,We as E,St as F,Oh as G,El as H,vu as I,kl as J,kg as K,_d as L,bg as M,vl as N,_h as O,xa as P,Kt as Q,ta as R,An as S,Ge as T,jr as U,w as V,Tn as W,Rt as X,Ea as Y,Ca as Z,Jg as _,pe as a,ue as a$,U0 as a0,Vt as a1,Qh as a2,te as a3,On as a4,gt as a5,Vg as a6,w0 as a7,Va as a8,Y as a9,Gm as aA,Rh as aB,Er as aC,qm as aD,wg as aE,Ld as aF,Nd as aG,Ud as aH,Dd as aI,Pd as aJ,Gd as aK,_0 as aL,M0 as aM,S0 as aN,A0 as aO,I0 as aP,C0 as aQ,Vm as aR,Sl as aS,Al as aT,Is as aU,Ua as aV,qn as aW,Ol as aX,Sh as aY,vg as aZ,Lr as a_,Ch as aa,Zr as ab,fe as ac,ig as ad,Hm as ae,Wl as af,dd as ag,fs as ah,dt as ai,Ng as aj,v0 as ak,b0 as al,Jr as am,zh as an,Li as ao,Lg as ap,pu as aq,fu as ar,Tl as as,Z as at,ys as au,O as av,tt as aw,P0 as ax,Ii as ay,$t as az,B as b,sc as b$,Rr as b0,Il as b1,he as b2,ag as b3,rg as b4,og as b5,sg as b6,ng as b7,hg as b8,eg as b9,f0 as bA,d0 as bB,Rl as bC,Ll as bD,Nl as bE,Bl as bF,Fl as bG,Pl as bH,Dl as bI,Ul as bJ,Vl as bK,Gl as bL,Ah as bM,Th as bN,Hl as bO,ql as bP,Xl as bQ,Yl as bR,Jl as bS,Zl as bT,Kl as bU,jl as bV,Ql as bW,$l as bX,tc as bY,ec as bZ,ic as b_,Km as ba,Zm as bb,Ra as bc,n0 as bd,a0 as be,Oa as bf,i0 as bg,s0 as bh,r0 as bi,o0 as bj,La as bk,e0 as bl,t0 as bm,$m as bn,Om as bo,Nm as bp,Dm as bq,Jm as br,Ym as bs,Xm as bt,x0 as bu,y0 as bv,g0 as bw,m0 as bx,Na as by,p0 as bz,oa as c,Ut as c$,nc as c0,rc as c1,ac as c2,oc as c3,hc as c4,lc as c5,cc as c6,uc as c7,dc as c8,fc as c9,li as cA,Qm as cB,jm as cC,na as cD,k0 as cE,Ih as cF,of as cG,En as cH,Wg as cI,sy as cJ,iy as cK,Gg as cL,Pu as cM,Qg as cN,Ay as cO,Da as cP,Jd as cQ,ey as cR,$h as cS,$g as cT,Kg as cU,Ty as cV,Ic as cW,zu as cX,Eh as cY,Ui as cZ,dy as c_,pc as ca,mc as cb,gc as cc,yc as cd,vc as ce,wc as cf,_c as cg,Mc as ch,Ce as ci,au as cj,ru as ck,$0 as cl,Q0 as cm,tg as cn,K0 as co,j0 as cp,Z0 as cq,Wa as cr,J0 as cs,X0 as ct,q0 as cu,H0 as cv,W0 as cw,Y0 as cx,G0 as cy,V0 as cz,Oi as d,ge as d$,My as d0,_y as d1,Hd as d2,Ve as d3,sa as d4,wy as d5,Nh as d6,da as d7,ku as d8,fa as d9,vy as dA,Td as dB,ma as dC,mg as dD,dg as dE,Hu as dF,ca as dG,ga as dH,aa as dI,ra as dJ,hy as dK,yg as dL,xg as dM,xy as dN,yy as dO,ya as dP,Zg as dQ,Rn as dR,Yc as dS,Wd as dT,Fg as dU,Pg as dV,Cg as dW,Gn as dX,Mn as dY,Or as dZ,Xn as d_,Xd as da,Kh as db,Dg as dc,Ug as dd,la as de,Hg as df,pa as dg,c0 as dh,h0 as di,Cy as dj,qg as dk,Dh as dl,Vu as dm,Ad as dn,Um as dp,me as dq,Wu as dr,T0 as ds,Ts as dt,uy as du,Bh as dv,Xg as dw,Ig as dx,Bd as dy,_l as dz,qt as e,Pi as e$,mu as e0,Dn as e1,Fh as e2,oi as e3,ni as e4,fy as e5,Uh as e6,Gu as e7,Bu as e8,Fe as e9,ty as eA,$ as eB,Kd as eC,Vh as eD,Gh as eE,Zt as eF,Wn as eG,Id as eH,O0 as eI,N0 as eJ,xc as eK,bc as eL,D0 as eM,fd as eN,As as eO,ly as eP,ny as eQ,ry as eR,ba as eS,ia as eT,Ri as eU,va as eV,Iy as eW,ze as eX,ha as eY,my as eZ,yu as e_,Zh as ea,F0 as eb,Ga as ec,Lo as ed,jh as ee,Sc as ef,Tc as eg,Ac as eh,Rm as ei,el as ej,bd as ek,vd as el,B0 as em,z0 as en,Qr as eo,Pn as ep,Vn as eq,u0 as er,l0 as es,Wm as et,Fn as eu,Sy as ev,gy as ew,Fu as ex,by as ey,ai as ez,Yn as f,Et as f0,cy as f1,Vd as f2,Wh as f3,py as f4,cs as f5,pg as f6,ug as f7,jg as f8,gg as f9,Bi as fA,ky as fB,Ey as fC,Mg as fD,Sg as fE,_g as fF,xs as fG,Rg as fH,Eg as fI,Nn as fJ,pf as fK,Hc as fL,lu as fM,In as fN,gf as fO,Py as fP,By as fQ,nl as fR,xf as fS,bn as fT,Br as fU,bf as fV,Fy as fW,zr as fX,cg as fa,fg as fb,Vi as fc,Lm as fd,wa as fe,Yg as ff,zy as fg,_a as fh,Ma as fi,Yt as fj,L0 as fk,R0 as fl,E0 as fm,Sa as fn,zg as fo,Bg as fp,tl as fq,ay as fr,kn as fs,Og as ft,Tg as fu,Ag as fv,ea as fw,ud as fx,Sn as fy,zi as fz,Kr as g,Ml as h,Te as i,Ed as j,oy as k,bs as l,Lh as m,Gt as n,Di as o,xd as p,wd as q,yd as r,md as s,pd as t,Aa as u,gd as v,ee as w,zl as x,Cl as y,Ln as z};