UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

1 lines • 1.11 MB
const un="169.19",Dx={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},zx={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Ox=0,Cm=1,Ux=2,dN=3,pN=0,Rm=1,Im=2,hs=3,Sr=0,ai=1,er=2,Ds=0,Vr=1,Al=2,Lm=3,Pm=4,Dm=5,dn=100,Fx=101,Vx=102,Bx=103,zm=104,kx=200,Gx=201,Hx=202,Wx=203,Cc=204,Rc=205,Xx=206,jx=207,qx=208,Yx=209,Jx=210,$x=211,Zx=212,Kx=213,Qx=214,El=0,Nl=1,Cl=2,pn=3,Rl=4,Il=5,Ll=6,Pl=7,Qa=0,Om=1,Um=2,vs=0,Ic=1,Lc=2,Fm=3,Pc=4,ev=5,Dc=6,zc=7,Vm="attached",tv="detached",Oc=300,_s=301,zs=302,mn=303,fn=304,gn=306,yn=1e3,Ms=1001,eo=1002,$t=1003,Uc=1004,iv=1004,Br=1005,mN=1005,Dt=1006,xn=1007,fN=1007,Ki=1008,Bm=1008,tr=1009,km=1010,Gm=1011,to=1012,io=1013,Os=1014,Bi=1015,Ci=1016,Fc=1017,Vc=1018,vn=1020,Hm=35902,Wm=35899,Xm=1021,jm=1022,Ri=1023,qm=1024,Ym=1025,_n=1026,Mn=1027,Dl=1028,zl=1029,so=1030,Bc=1031,gN=1032,kc=1033,Ol=33776,Ul=33777,Fl=33778,Vl=33779,Gc=35840,Hc=35841,Wc=35842,Xc=35843,jc=36196,qc=37492,Yc=37496,Jc=37808,$c=37809,Zc=37810,Kc=37811,Qc=37812,eu=37813,tu=37814,iu=37815,su=37816,ru=37817,nu=37818,au=37819,ou=37820,lu=37821,Bl=36492,hu=36494,cu=36495,Jm=36283,uu=36284,du=36285,pu=36286,$m=2200,Zm=2201,sv=2202,ro=2300,kl=2301,mu=2302,ea=2400,ta=2401,Gl=2402,fu=2500,Km=2501,rv=0,nv=1,av=2,Qm=3200,ef=3201,yN=3202,xN=3203,Tr=0,tf=1,Us="",ki="srgb",cs="srgb-linear",gu="display-p3",Hl="display-p3-linear",Wl="linear",Ft="srgb",Xl="rec709",jl="p3",ov=0,bn=7680,lv=7681,hv=7682,cv=7683,uv=34055,dv=34056,pv=5386,mv=512,fv=513,gv=514,yv=515,xv=516,vv=517,_v=518,yu=519,Mv=512,sf=513,bv=514,rf=515,Sv=516,Tv=517,wv=518,Av=519,no=35044,ia=35048,vN=35040,_N=35045,MN=35049,bN=35041,SN=35046,TN=35050,wN=35042,AN="100",xu="300 es",Fs=2e3,sa=2001;let bs=class{addEventListener(r,e){this._listeners===void 0&&(this._listeners={});const t=this._listeners;t[r]===void 0&&(t[r]=[]),t[r].indexOf(e)===-1&&t[r].push(e)}hasEventListener(r,e){if(this._listeners===void 0)return!1;const t=this._listeners;return t[r]!==void 0&&t[r].indexOf(e)!==-1}removeEventListener(r,e){if(this._listeners===void 0)return;const t=this._listeners[r];if(t!==void 0){const i=t.indexOf(e);i!==-1&&t.splice(i,1)}}dispatchEvent(r){if(this._listeners===void 0)return;const e=this._listeners[r.type];if(e!==void 0){r.target=this;const t=e.slice(0);for(let i=0,s=t.length;i<s;i++)t[i].call(this,r);r.target=null}}};const Gi=["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 Ev=1234567;const ra=Math.PI/180,ao=180/Math.PI;function Ss(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(Gi[r&255]+Gi[r>>8&255]+Gi[r>>16&255]+Gi[r>>24&255]+"-"+Gi[e&255]+Gi[e>>8&255]+"-"+Gi[e>>16&15|64]+Gi[e>>24&255]+"-"+Gi[t&63|128]+Gi[t>>8&255]+"-"+Gi[t>>16&255]+Gi[t>>24&255]+Gi[i&255]+Gi[i>>8&255]+Gi[i>>16&255]+Gi[i>>24&255]).toLowerCase()}function Zt(r,e,t){return Math.max(e,Math.min(t,r))}function nf(r,e){return(r%e+e)%e}function EN(r,e,t,i,s){return i+(r-e)*(s-i)/(t-e)}function NN(r,e,t){return r!==e?(t-r)/(e-r):0}function ql(r,e,t){return(1-t)*r+t*e}function CN(r,e,t,i){return ql(r,e,1-Math.exp(-t*i))}function RN(r,e=1){return e-Math.abs(nf(r,e*2)-e)}function IN(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function LN(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function PN(r,e){return r+Math.floor(Math.random()*(e-r+1))}function DN(r,e){return r+Math.random()*(e-r)}function zN(r){return r*(.5-Math.random())}function ON(r){r!==void 0&&(Ev=r);let e=Ev+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function UN(r){return r*ra}function FN(r){return r*ao}function VN(r){return(r&r-1)===0&&r!==0}function BN(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function kN(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function GN(r,e,t,i,s){const n=Math.cos,a=Math.sin,o=n(t/2),l=a(t/2),h=n((e+i)/2),c=a((e+i)/2),u=n((e-i)/2),d=a((e-i)/2),p=n((i-e)/2),m=a((i-e)/2);switch(s){case"XYX":r.set(o*c,l*u,l*d,o*h);break;case"YZY":r.set(l*d,o*c,l*u,o*h);break;case"ZXZ":r.set(l*u,l*d,o*c,o*h);break;case"XZX":r.set(o*c,l*m,l*p,o*h);break;case"YXY":r.set(l*p,o*c,l*m,o*h);break;case"ZYZ":r.set(l*m,l*p,o*c,o*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+s)}}function Qi(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function ut(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const vu={DEG2RAD:ra,RAD2DEG:ao,generateUUID:Ss,clamp:Zt,euclideanModulo:nf,mapLinear:EN,inverseLerp:NN,lerp:ql,damp:CN,pingpong:RN,smoothstep:IN,smootherstep:LN,randInt:PN,randFloat:DN,randFloatSpread:zN,seededRandom:ON,degToRad:UN,radToDeg:FN,isPowerOfTwo:VN,ceilPowerOfTwo:BN,floorPowerOfTwo:kN,setQuaternionFromProperEuler:GN,normalize:ut,denormalize:Qi};let K=class eN{constructor(e=0,t=0){eN.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,i=this.y,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6],this.y=s[1]*t+s[4]*i+s[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.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(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Zt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const i=Math.cos(t),s=Math.sin(t),n=this.x-e.x,a=this.y-e.y;return this.x=n*i-a*s+e.x,this.y=n*s+a*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},et=class tN{constructor(e,t,i,s,n,a,o,l,h){tN.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,s,n,a,o,l,h)}set(e,t,i,s,n,a,o,l,h){const c=this.elements;return c[0]=e,c[1]=s,c[2]=o,c[3]=t,c[4]=n,c[5]=l,c[6]=i,c[7]=a,c[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,s=t.elements,n=this.elements,a=i[0],o=i[3],l=i[6],h=i[1],c=i[4],u=i[7],d=i[2],p=i[5],m=i[8],g=s[0],f=s[3],y=s[6],v=s[1],x=s[4],_=s[7],R=s[2],b=s[5],S=s[8];return n[0]=a*g+o*v+l*R,n[3]=a*f+o*x+l*b,n[6]=a*y+o*_+l*S,n[1]=h*g+c*v+u*R,n[4]=h*f+c*x+u*b,n[7]=h*y+c*_+u*S,n[2]=d*g+p*v+m*R,n[5]=d*f+p*x+m*b,n[8]=d*y+p*_+m*S,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],i=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],h=e[7],c=e[8];return t*a*c-t*o*h-i*n*c+i*o*l+s*n*h-s*a*l}invert(){const e=this.elements,t=e[0],i=e[1],s=e[2],n=e[3],a=e[4],o=e[5],l=e[6],h=e[7],c=e[8],u=c*a-o*h,d=o*l-c*n,p=h*n-a*l,m=t*u+i*d+s*p;if(m===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/m;return e[0]=u*g,e[1]=(s*h-c*i)*g,e[2]=(o*i-s*a)*g,e[3]=d*g,e[4]=(c*t-s*l)*g,e[5]=(s*n-o*t)*g,e[6]=p*g,e[7]=(i*l-h*t)*g,e[8]=(a*t-i*n)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,s,n,a,o){const l=Math.cos(n),h=Math.sin(n);return this.set(i*l,i*h,-i*(l*a+h*o)+a+e,-s*h,s*l,-s*(-h*a+l*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(af.makeScale(e,t)),this}rotate(e){return this.premultiply(af.makeRotation(-e)),this}translate(e,t){return this.premultiply(af.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,i,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,i=e.elements;for(let s=0;s<9;s++)if(t[s]!==i[s])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new this.constructor().fromArray(this.elements)}};const af=new et;function Nv(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}const HN={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array};function oo(r,e){return new HN[r](e)}function Yl(r){return document.createElementNS("http://www.w3.org/1999/xhtml",r)}function Cv(){const r=Yl("canvas");return r.style.display="block",r}const Rv={};function _u(r){r in Rv||(Rv[r]=!0,console.warn(r))}function WN(r,e,t){return new Promise(function(i,s){function n(){switch(r.clientWaitSync(e,r.SYNC_FLUSH_COMMANDS_BIT,0)){case r.WAIT_FAILED:s();break;case r.TIMEOUT_EXPIRED:setTimeout(n,t);break;default:i()}}setTimeout(n,t)})}function XN(r){const e=r.elements;e[2]=.5*e[2]+.5*e[3],e[6]=.5*e[6]+.5*e[7],e[10]=.5*e[10]+.5*e[11],e[14]=.5*e[14]+.5*e[15]}function jN(r){const e=r.elements;e[11]===-1?(e[10]=-e[10]-1,e[14]=-e[14]):(e[10]=-e[10],e[14]=-e[14]+1)}const Iv=new et().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),Lv=new et().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Jl={[cs]:{transfer:Wl,primaries:Xl,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r,fromReference:r=>r},[ki]:{transfer:Ft,primaries:Xl,luminanceCoefficients:[.2126,.7152,.0722],toReference:r=>r.convertSRGBToLinear(),fromReference:r=>r.convertLinearToSRGB()},[Hl]:{transfer:Wl,primaries:jl,luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.applyMatrix3(Lv),fromReference:r=>r.applyMatrix3(Iv)},[gu]:{transfer:Ft,primaries:jl,luminanceCoefficients:[.2289,.6917,.0793],toReference:r=>r.convertSRGBToLinear().applyMatrix3(Lv),fromReference:r=>r.applyMatrix3(Iv).convertLinearToSRGB()}},qN=new Set([cs,Hl]),xt={enabled:!0,_workingColorSpace:cs,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(r){if(!qN.has(r))throw new Error(`Unsupported working color space, "${r}".`);this._workingColorSpace=r},convert:function(r,e,t){if(this.enabled===!1||e===t||!e||!t)return r;const i=Jl[e].toReference,s=Jl[t].fromReference;return s(i(r))},fromWorkingColorSpace:function(r,e){return this.convert(r,this._workingColorSpace,e)},toWorkingColorSpace:function(r,e){return this.convert(r,e,this._workingColorSpace)},getPrimaries:function(r){return Jl[r].primaries},getTransfer:function(r){return r===Us?Wl:Jl[r].transfer},getLuminanceCoefficients:function(r,e=this._workingColorSpace){return r.fromArray(Jl[e].luminanceCoefficients)}};function lo(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function of(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}let ho,Pv=class{static getDataURL(r){if(/^data:/i.test(r.src)||typeof HTMLCanvasElement>"u")return r.src;let e;if(r instanceof HTMLCanvasElement)e=r;else{ho===void 0&&(ho=Yl("canvas")),ho.width=r.width,ho.height=r.height;const t=ho.getContext("2d");r instanceof ImageData?t.putImageData(r,0,0):t.drawImage(r,0,0,r.width,r.height),e=ho}return e.width>2048||e.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",r),e.toDataURL("image/jpeg",.6)):e.toDataURL("image/png")}static sRGBToLinear(r){if(typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap){const e=Yl("canvas");e.width=r.width,e.height=r.height;const t=e.getContext("2d");t.drawImage(r,0,0,r.width,r.height);const i=t.getImageData(0,0,r.width,r.height),s=i.data;for(let n=0;n<s.length;n++)s[n]=lo(s[n]/255)*255;return t.putImageData(i,0,0),e}else if(r.data){const e=r.data.slice(0);for(let t=0;t<e.length;t++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[t]=Math.floor(lo(e[t]/255)*255):e[t]=lo(e[t]);return{data:e,width:r.width,height:r.height}}else return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),r}},YN=0,Sn=class{constructor(r=null){this.isSource=!0,Object.defineProperty(this,"id",{value:YN++}),this.uuid=Ss(),this.data=r,this.dataReady=!0,this.version=0}set needsUpdate(r){r===!0&&this.version++}toJSON(r){const e=r===void 0||typeof r=="string";if(!e&&r.images[this.uuid]!==void 0)return r.images[this.uuid];const t={uuid:this.uuid,url:""},i=this.data;if(i!==null){let s;if(Array.isArray(i)){s=[];for(let n=0,a=i.length;n<a;n++)i[n].isDataTexture?s.push(lf(i[n].image)):s.push(lf(i[n]))}else s=lf(i);t.url=s}return e||(r.images[this.uuid]=t),t}};function lf(r){return typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&r instanceof ImageBitmap?Pv.getDataURL(r):r.data?{data:Array.from(r.data),width:r.width,height:r.height,type:r.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let JN=0,oi=class pm extends bs{constructor(e=pm.DEFAULT_IMAGE,t=pm.DEFAULT_MAPPING,i=Ms,s=Ms,n=Dt,a=Ki,o=Ri,l=tr,h=pm.DEFAULT_ANISOTROPY,c=Us){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:JN++}),this.uuid=Ss(),this.name="",this.source=new Sn(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=a,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=l,this.offset=new K(0,0),this.repeat=new K(1,1),this.center=new K(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new et,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=c,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.pmremVersion=0}get image(){return this.source.data}set image(e=null){this.source.data=e}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(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}toJSON(e){const t=e===void 0||typeof e=="string";if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];const i={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).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),t||(e.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==Oc)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case yn:e.x=e.x-Math.floor(e.x);break;case Ms:e.x=e.x<0?0:1;break;case eo:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case yn:e.y=e.y-Math.floor(e.y);break;case Ms:e.y=e.y<0?0:1;break;case eo:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};oi.DEFAULT_IMAGE=null,oi.DEFAULT_MAPPING=Oc,oi.DEFAULT_ANISOTROPY=4;let lt=class iN{constructor(e=0,t=0,i=0,s=1){iN.prototype.isVector4=!0,this.x=e,this.y=t,this.z=i,this.w=s}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){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: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,n=this.w,a=e.elements;return this.x=a[0]*t+a[4]*i+a[8]*s+a[12]*n,this.y=a[1]*t+a[5]*i+a[9]*s+a[13]*n,this.z=a[2]*t+a[6]*i+a[10]*s+a[14]*n,this.w=a[3]*t+a[7]*i+a[11]*s+a[15]*n,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,i,s,n;const a=e.elements,o=a[0],l=a[4],h=a[8],c=a[1],u=a[5],d=a[9],p=a[2],m=a[6],g=a[10];if(Math.abs(l-c)<.01&&Math.abs(h-p)<.01&&Math.abs(d-m)<.01){if(Math.abs(l+c)<.1&&Math.abs(h+p)<.1&&Math.abs(d+m)<.1&&Math.abs(o+u+g-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const y=(o+1)/2,v=(u+1)/2,x=(g+1)/2,_=(l+c)/4,R=(h+p)/4,b=(d+m)/4;return y>v&&y>x?y<.01?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(y),s=_/i,n=R/i):v>x?v<.01?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(v),i=_/s,n=b/s):x<.01?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(x),i=R/n,s=b/n),this.set(i,s,n,t),this}let f=Math.sqrt((m-d)*(m-d)+(h-p)*(h-p)+(c-l)*(c-l));return Math.abs(f)<.001&&(f=1),this.x=(m-d)/f,this.y=(h-p)/f,this.z=(c-l)/f,this.w=Math.acos((o+u+g-1)/2),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),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 pi extends bs{constructor(e=1,t=1,i={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new lt(0,0,e,t),this.scissorTest=!1,this.viewport=new lt(0,0,e,t);const s={width:e,height:t,depth:1};i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Dt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},i);const n=new oi(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 a=i.count;for(let o=0;o<a;o++)this.textures[o]=n.clone(),this.textures[o].isRenderTargetTexture=!0;this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this.depthTexture=i.depthTexture,this.samples=i.samples}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}setSize(e,t,i=1){if(this.width!==e||this.height!==t||this.depth!==i){this.width=e,this.height=t,this.depth=i;for(let s=0,n=this.textures.length;s<n;s++)this.textures[s].image.width=e,this.textures[s].image.height=t,this.textures[s].image.depth=i;this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let i=0,s=e.textures.length;i<s;i++)this.textures[i]=e.textures[i].clone(),this.textures[i].isRenderTargetTexture=!0;const t=Object.assign({},e.texture.image);return this.texture.source=new Sn(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Vs extends pi{constructor(e=1,t=1,i={}){super(e,t,i),this.isWebGLRenderTarget=!0}}class $l extends oi{constructor(e=null,t=1,i=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:i,depth:s},this.magFilter=$t,this.minFilter=$t,this.wrapR=Ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(e){this.layerUpdates.add(e)}clearLayerUpdates(){this.layerUpdates.clear()}}class $N extends Vs{constructor(e=1,t=1,i=1,s={}){super(e,t,s),this.isWebGLArrayRenderTarget=!0,this.depth=i,this.texture=new $l(null,e,t,i),this.texture.isRenderTargetTexture=!0}}class Mu extends oi{constructor(e=null,t=1,i=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:i,depth:s},this.magFilter=$t,this.minFilter=$t,this.wrapR=Ms,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class ZN extends Vs{constructor(e=1,t=1,i=1,s={}){super(e,t,s),this.isWebGL3DRenderTarget=!0,this.depth=i,this.texture=new Mu(null,e,t,i),this.texture.isRenderTargetTexture=!0}}let Hi=class{constructor(r=0,e=0,t=0,i=1){this.isQuaternion=!0,this._x=r,this._y=e,this._z=t,this._w=i}static slerpFlat(r,e,t,i,s,n,a){let o=t[i+0],l=t[i+1],h=t[i+2],c=t[i+3];const u=s[n+0],d=s[n+1],p=s[n+2],m=s[n+3];if(a===0){r[e+0]=o,r[e+1]=l,r[e+2]=h,r[e+3]=c;return}if(a===1){r[e+0]=u,r[e+1]=d,r[e+2]=p,r[e+3]=m;return}if(c!==m||o!==u||l!==d||h!==p){let g=1-a;const f=o*u+l*d+h*p+c*m,y=f>=0?1:-1,v=1-f*f;if(v>Number.EPSILON){const _=Math.sqrt(v),R=Math.atan2(_,f*y);g=Math.sin(g*R)/_,a=Math.sin(a*R)/_}const x=a*y;if(o=o*g+u*x,l=l*g+d*x,h=h*g+p*x,c=c*g+m*x,g===1-a){const _=1/Math.sqrt(o*o+l*l+h*h+c*c);o*=_,l*=_,h*=_,c*=_}}r[e]=o,r[e+1]=l,r[e+2]=h,r[e+3]=c}static multiplyQuaternionsFlat(r,e,t,i,s,n){const a=t[i],o=t[i+1],l=t[i+2],h=t[i+3],c=s[n],u=s[n+1],d=s[n+2],p=s[n+3];return r[e]=a*p+h*c+o*d-l*u,r[e+1]=o*p+h*u+l*c-a*d,r[e+2]=l*p+h*d+a*u-o*c,r[e+3]=h*p-a*c-o*u-l*d,r}get x(){return this._x}set x(r){this._x=r,this._onChangeCallback()}get y(){return this._y}set y(r){this._y=r,this._onChangeCallback()}get z(){return this._z}set z(r){this._z=r,this._onChangeCallback()}get w(){return this._w}set w(r){this._w=r,this._onChangeCallback()}set(r,e,t,i){return this._x=r,this._y=e,this._z=t,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(r){return this._x=r.x,this._y=r.y,this._z=r.z,this._w=r.w,this._onChangeCallback(),this}setFromEuler(r,e=!0){const t=r._x,i=r._y,s=r._z,n=r._order,a=Math.cos,o=Math.sin,l=a(t/2),h=a(i/2),c=a(s/2),u=o(t/2),d=o(i/2),p=o(s/2);switch(n){case"XYZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"YXZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"ZXY":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"ZYX":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"YZX":this._x=u*h*c+l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c-u*d*p;break;case"XZY":this._x=u*h*c-l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c+u*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return e===!0&&this._onChangeCallback(),this}setFromAxisAngle(r,e){const t=e/2,i=Math.sin(t);return this._x=r.x*i,this._y=r.y*i,this._z=r.z*i,this._w=Math.cos(t),this._onChangeCallback(),this}setFromRotationMatrix(r){const e=r.elements,t=e[0],i=e[4],s=e[8],n=e[1],a=e[5],o=e[9],l=e[2],h=e[6],c=e[10],u=t+a+c;if(u>0){const d=.5/Math.sqrt(u+1);this._w=.25/d,this._x=(h-o)*d,this._y=(s-l)*d,this._z=(n-i)*d}else if(t>a&&t>c){const d=2*Math.sqrt(1+t-a-c);this._w=(h-o)/d,this._x=.25*d,this._y=(i+n)/d,this._z=(s+l)/d}else if(a>c){const d=2*Math.sqrt(1+a-t-c);this._w=(s-l)/d,this._x=(i+n)/d,this._y=.25*d,this._z=(o+h)/d}else{const d=2*Math.sqrt(1+c-t-a);this._w=(n-i)/d,this._x=(s+l)/d,this._y=(o+h)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(r,e){let t=r.dot(e)+1;return t<Number.EPSILON?(t=0,Math.abs(r.x)>Math.abs(r.z)?(this._x=-r.y,this._y=r.x,this._z=0,this._w=t):(this._x=0,this._y=-r.z,this._z=r.y,this._w=t)):(this._x=r.y*e.z-r.z*e.y,this._y=r.z*e.x-r.x*e.z,this._z=r.x*e.y-r.y*e.x,this._w=t),this.normalize()}angleTo(r){return 2*Math.acos(Math.abs(Zt(this.dot(r),-1,1)))}rotateTowards(r,e){const t=this.angleTo(r);if(t===0)return this;const i=Math.min(1,e/t);return this.slerp(r,i),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(r){return this._x*r._x+this._y*r._y+this._z*r._z+this._w*r._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 r=this.length();return r===0?(this._x=0,this._y=0,this._z=0,this._w=1):(r=1/r,this._x=this._x*r,this._y=this._y*r,this._z=this._z*r,this._w=this._w*r),this._onChangeCallback(),this}multiply(r){return this.multiplyQuaternions(this,r)}premultiply(r){return this.multiplyQuaternions(r,this)}multiplyQuaternions(r,e){const t=r._x,i=r._y,s=r._z,n=r._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=t*h+n*a+i*l-s*o,this._y=i*h+n*o+s*a-t*l,this._z=s*h+n*l+t*o-i*a,this._w=n*h-t*a-i*o-s*l,this._onChangeCallback(),this}slerp(r,e){if(e===0)return this;if(e===1)return this.copy(r);const t=this._x,i=this._y,s=this._z,n=this._w;let a=n*r._w+t*r._x+i*r._y+s*r._z;if(a<0?(this._w=-r._w,this._x=-r._x,this._y=-r._y,this._z=-r._z,a=-a):this.copy(r),a>=1)return this._w=n,this._x=t,this._y=i,this._z=s,this;const o=1-a*a;if(o<=Number.EPSILON){const d=1-e;return this._w=d*n+e*this._w,this._x=d*t+e*this._x,this._y=d*i+e*this._y,this._z=d*s+e*this._z,this.normalize(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),c=Math.sin((1-e)*h)/l,u=Math.sin(e*h)/l;return this._w=n*c+this._w*u,this._x=t*c+this._x*u,this._y=i*c+this._y*u,this._z=s*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(r,e,t){return this.copy(r).slerp(e,t)}random(){const r=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),t=Math.random(),i=Math.sqrt(1-t),s=Math.sqrt(t);return this.set(i*Math.sin(r),i*Math.cos(r),s*Math.sin(e),s*Math.cos(e))}equals(r){return r._x===this._x&&r._y===this._y&&r._z===this._z&&r._w===this._w}fromArray(r,e=0){return this._x=r[e],this._y=r[e+1],this._z=r[e+2],this._w=r[e+3],this._onChangeCallback(),this}toArray(r=[],e=0){return r[e]=this._x,r[e+1]=this._y,r[e+2]=this._z,r[e+3]=this._w,r}fromBufferAttribute(r,e){return this._x=r.getX(e),this._y=r.getY(e),this._z=r.getZ(e),this._w=r.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(r){return this._onChangeCallback=r,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},C=class sN{constructor(e=0,t=0,i=0){sN.prototype.isVector3=!0,this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Dv.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Dv.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,s=this.z,n=e.elements;return this.x=n[0]*t+n[3]*i+n[6]*s,this.y=n[1]*t+n[4]*i+n[7]*s,this.z=n[2]*t+n[5]*i+n[8]*s,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,s=this.z,n=e.elements,a=1/(n[3]*t+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*t+n[4]*i+n[8]*s+n[12])*a,this.y=(n[1]*t+n[5]*i+n[9]*s+n[13])*a,this.z=(n[2]*t+n[6]*i+n[10]*s+n[14])*a,this}applyQuaternion(e){const t=this.x,i=this.y,s=this.z,n=e.x,a=e.y,o=e.z,l=e.w,h=2*(a*s-o*i),c=2*(o*t-n*s),u=2*(n*i-a*t);return this.x=t+l*h+a*u-o*c,this.y=i+l*c+o*h-n*u,this.z=s+l*u+n*c-a*h,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,i=this.y,s=this.z,n=e.elements;return this.x=n[0]*t+n[4]*i+n[8]*s,this.y=n[1]*t+n[5]*i+n[9]*s,this.z=n[2]*t+n[6]*i+n[10]*s,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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(e){return this.x*e.x+this.y*e.y+this.z*e.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(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,s=e.y,n=e.z,a=t.x,o=t.y,l=t.z;return this.x=s*l-n*o,this.y=n*a-i*l,this.z=i*o-s*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}projectOnPlane(e){return hf.copy(this).projectOnVector(e),this.sub(hf)}reflect(e){return this.sub(hf.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const i=this.dot(e)/t;return Math.acos(Zt(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,i){const s=Math.sin(t)*e;return this.x=s*Math.sin(i),this.y=Math.cos(t)*e,this.z=s*Math.cos(i),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),s=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=s,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};const hf=new C,Dv=new Hi;let Wi=class{constructor(r=new C(1/0,1/0,1/0),e=new C(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=r,this.max=e}set(r,e){return this.min.copy(r),this.max.copy(e),this}setFromArray(r){this.makeEmpty();for(let e=0,t=r.length;e<t;e+=3)this.expandByPoint(ir.fromArray(r,e));return this}setFromBufferAttribute(r){this.makeEmpty();for(let e=0,t=r.count;e<t;e++)this.expandByPoint(ir.fromBufferAttribute(r,e));return this}setFromPoints(r){this.makeEmpty();for(let e=0,t=r.length;e<t;e++)this.expandByPoint(r[e]);return this}setFromCenterAndSize(r,e){const t=ir.copy(e).multiplyScalar(.5);return this.min.copy(r).sub(t),this.max.copy(r).add(t),this}setFromObject(r,e=!1){return this.makeEmpty(),this.expandByObject(r,e)}clone(){return new this.constructor().copy(this)}copy(r){return this.min.copy(r.min),this.max.copy(r.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(r){return this.isEmpty()?r.set(0,0,0):r.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(r){return this.isEmpty()?r.set(0,0,0):r.subVectors(this.max,this.min)}expandByPoint(r){return this.min.min(r),this.max.max(r),this}expandByVector(r){return this.min.sub(r),this.max.add(r),this}expandByScalar(r){return this.min.addScalar(-r),this.max.addScalar(r),this}expandByObject(r,e=!1){r.updateWorldMatrix(!1,!1);const t=r.geometry;if(t!==void 0){const s=t.getAttribute("position");if(e===!0&&s!==void 0&&r.isInstancedMesh!==!0)for(let n=0,a=s.count;n<a;n++)r.isMesh===!0?r.getVertexPosition(n,ir):ir.fromBufferAttribute(s,n),ir.applyMatrix4(r.matrixWorld),this.expandByPoint(ir);else r.boundingBox!==void 0?(r.boundingBox===null&&r.computeBoundingBox(),bu.copy(r.boundingBox)):(t.boundingBox===null&&t.computeBoundingBox(),bu.copy(t.boundingBox)),bu.applyMatrix4(r.matrixWorld),this.union(bu)}const i=r.children;for(let s=0,n=i.length;s<n;s++)this.expandByObject(i[s],e);return this}containsPoint(r){return r.x>=this.min.x&&r.x<=this.max.x&&r.y>=this.min.y&&r.y<=this.max.y&&r.z>=this.min.z&&r.z<=this.max.z}containsBox(r){return this.min.x<=r.min.x&&r.max.x<=this.max.x&&this.min.y<=r.min.y&&r.max.y<=this.max.y&&this.min.z<=r.min.z&&r.max.z<=this.max.z}getParameter(r,e){return e.set((r.x-this.min.x)/(this.max.x-this.min.x),(r.y-this.min.y)/(this.max.y-this.min.y),(r.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(r){return r.max.x>=this.min.x&&r.min.x<=this.max.x&&r.max.y>=this.min.y&&r.min.y<=this.max.y&&r.max.z>=this.min.z&&r.min.z<=this.max.z}intersectsSphere(r){return this.clampPoint(r.center,ir),ir.distanceToSquared(r.center)<=r.radius*r.radius}intersectsPlane(r){let e,t;return r.normal.x>0?(e=r.normal.x*this.min.x,t=r.normal.x*this.max.x):(e=r.normal.x*this.max.x,t=r.normal.x*this.min.x),r.normal.y>0?(e+=r.normal.y*this.min.y,t+=r.normal.y*this.max.y):(e+=r.normal.y*this.max.y,t+=r.normal.y*this.min.y),r.normal.z>0?(e+=r.normal.z*this.min.z,t+=r.normal.z*this.max.z):(e+=r.normal.z*this.max.z,t+=r.normal.z*this.min.z),e<=-r.constant&&t>=-r.constant}intersectsTriangle(r){if(this.isEmpty())return!1;this.getCenter(Zl),Su.subVectors(this.max,Zl),co.subVectors(r.a,Zl),uo.subVectors(r.b,Zl),po.subVectors(r.c,Zl),Tn.subVectors(uo,co),wn.subVectors(po,uo),na.subVectors(co,po);let e=[0,-Tn.z,Tn.y,0,-wn.z,wn.y,0,-na.z,na.y,Tn.z,0,-Tn.x,wn.z,0,-wn.x,na.z,0,-na.x,-Tn.y,Tn.x,0,-wn.y,wn.x,0,-na.y,na.x,0];return!cf(e,co,uo,po,Su)||(e=[1,0,0,0,1,0,0,0,1],!cf(e,co,uo,po,Su))?!1:(Tu.crossVectors(Tn,wn),e=[Tu.x,Tu.y,Tu.z],cf(e,co,uo,po,Su))}clampPoint(r,e){return e.copy(r).clamp(this.min,this.max)}distanceToPoint(r){return this.clampPoint(r,ir).distanceTo(r)}getBoundingSphere(r){return this.isEmpty()?r.makeEmpty():(this.getCenter(r.center),r.radius=this.getSize(ir).length()*.5),r}intersect(r){return this.min.max(r.min),this.max.min(r.max),this.isEmpty()&&this.makeEmpty(),this}union(r){return this.min.min(r.min),this.max.max(r.max),this}applyMatrix4(r){return this.isEmpty()?this:(kr[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(r),kr[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(r),kr[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(r),kr[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(r),kr[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(r),kr[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(r),kr[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(r),kr[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(r),this.setFromPoints(kr),this)}translate(r){return this.min.add(r),this.max.add(r),this}equals(r){return r.min.equals(this.min)&&r.max.equals(this.max)}};const kr=[new C,new C,new C,new C,new C,new C,new C,new C],ir=new C,bu=new Wi,co=new C,uo=new C,po=new C,Tn=new C,wn=new C,na=new C,Zl=new C,Su=new C,Tu=new C,aa=new C;function cf(r,e,t,i,s){for(let n=0,a=r.length-3;n<=a;n+=3){aa.fromArray(r,n);const o=s.x*Math.abs(aa.x)+s.y*Math.abs(aa.y)+s.z*Math.abs(aa.z),l=e.dot(aa),h=t.dot(aa),c=i.dot(aa);if(Math.max(-Math.max(l,h,c),Math.min(l,h,c))>o)return!1}return!0}const KN=new Wi,Kl=new C,uf=new C;let Ii=class{constructor(r=new C,e=-1){this.isSphere=!0,this.center=r,this.radius=e}set(r,e){return this.center.copy(r),this.radius=e,this}setFromPoints(r,e){const t=this.center;e!==void 0?t.copy(e):KN.setFromPoints(r).getCenter(t);let i=0;for(let s=0,n=r.length;s<n;s++)i=Math.max(i,t.distanceToSquared(r[s]));return this.radius=Math.sqrt(i),this}copy(r){return this.center.copy(r.center),this.radius=r.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(r){return r.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(r){return r.distanceTo(this.center)-this.radius}intersectsSphere(r){const e=this.radius+r.radius;return r.center.distanceToSquared(this.center)<=e*e}intersectsBox(r){return r.intersectsSphere(this)}intersectsPlane(r){return Math.abs(r.distanceToPoint(this.center))<=this.radius}clampPoint(r,e){const t=this.center.distanceToSquared(r);return e.copy(r),t>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(r){return this.isEmpty()?(r.makeEmpty(),r):(r.set(this.center,this.center),r.expandByScalar(this.radius),r)}applyMatrix4(r){return this.center.applyMatrix4(r),this.radius=this.radius*r.getMaxScaleOnAxis(),this}translate(r){return this.center.add(r),this}expandByPoint(r){if(this.isEmpty())return this.center.copy(r),this.radius=0,this;Kl.subVectors(r,this.center);const e=Kl.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=(t-this.radius)*.5;this.center.addScaledVector(Kl,i/t),this.radius+=i}return this}union(r){return r.isEmpty()?this:this.isEmpty()?(this.copy(r),this):(this.center.equals(r.center)===!0?this.radius=Math.max(this.radius,r.radius):(uf.subVectors(r.center,this.center).setLength(r.radius),this.expandByPoint(Kl.copy(r.center).add(uf)),this.expandByPoint(Kl.copy(r.center).sub(uf))),this)}equals(r){return r.center.equals(this.center)&&r.radius===this.radius}clone(){return new this.constructor().copy(this)}};const Gr=new C,df=new C,wu=new C,An=new C,pf=new C,Au=new C,mf=new C;let oa=class{constructor(r=new C,e=new C(0,0,-1)){this.origin=r,this.direction=e}set(r,e){return this.origin.copy(r),this.direction.copy(e),this}copy(r){return this.origin.copy(r.origin),this.direction.copy(r.direction),this}at(r,e){return e.copy(this.origin).addScaledVector(this.direction,r)}lookAt(r){return this.direction.copy(r).sub(this.origin).normalize(),this}recast(r){return this.origin.copy(this.at(r,Gr)),this}closestPointToPoint(r,e){e.subVectors(r,this.origin);const t=e.dot(this