atome 0.5.7.5.4 → 0.5.7.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/deep learning/basic_infos.txt +5 -0
- data/lib/atome/genesis/atomes.rb +12 -0
- data/lib/atome/genesis/particles/event.rb +141 -97
- data/lib/atome/genesis/particles/identity.rb +2 -1
- data/lib/atome/genesis/particles/spatial.rb +25 -0
- data/lib/atome/genesis/particles/utility.rb +13 -5
- data/lib/atome/utilities/essentials.rb +5 -2
- data/lib/atome/version.rb +1 -1
- data/lib/molecules/intuition/tools.rb +1 -1
- data/lib/molecules/intuition/utilities.rb +3 -0
- data/lib/platform_specific/opal/extensions/object.rb +3 -1
- data/lib/platform_specific/wasm/atome_wasm_extensions.rb +2 -1
- data/lib/renderers/html/event.rb +20 -6
- data/lib/renderers/html/html.rb +753 -446
- data/lib/renderers/html/identity.rb +33 -6
- data/lib/renderers/html/spatial.rb +27 -0
- data/lib/renderers/html/utility.rb +4 -0
- data/vendor/assets/application/examples/audio.rb +25 -9
- data/vendor/assets/application/examples/calendar.rb +186 -0
- data/vendor/assets/application/examples/drop.rb +1 -0
- data/vendor/assets/application/examples/editor.rb +139 -0
- data/vendor/assets/application/examples/inspector.rb +129 -0
- data/vendor/assets/application/examples/keyboard.rb +20 -10
- data/vendor/assets/application/examples/map.rb +42 -0
- data/vendor/assets/application/examples/meteo.rb +8 -0
- data/vendor/assets/application/examples/midi.rb +4 -0
- data/vendor/assets/application/examples/on_resize.rb +14 -0
- data/vendor/assets/application/examples/over.rb +0 -1
- data/vendor/assets/application/examples/overflow.rb +20 -5
- data/vendor/assets/application/examples/particles.rb +1 -1
- data/vendor/assets/application/examples/preset.rb +1 -1
- data/vendor/assets/application/examples/resize.rb +11 -0
- data/vendor/assets/application/examples/tick.rb +10 -0
- data/vendor/assets/application/examples/tools.rb +6 -1
- data/vendor/assets/application/examples/touch.rb +2 -14
- data/vendor/assets/application/examples/trigger_abstraction.rb +165 -0
- data/vendor/assets/application/examples/vr.rb +3 -0
- data/vendor/assets/src/css/codemirror.min.css +472 -0
- data/vendor/assets/src/css/fonts/tui/icon.eot +0 -0
- data/vendor/assets/src/css/fonts/tui/icon.svg +17 -0
- data/vendor/assets/src/css/fonts/tui/icon.ttf +0 -0
- data/vendor/assets/src/css/fonts/tui/icon.woff +0 -0
- data/vendor/assets/src/css/fonts/tui/noto.woff +72 -0
- data/vendor/assets/src/css/images/leaflet/layers-2x.png +0 -0
- data/vendor/assets/src/css/images/leaflet/layers.png +0 -0
- data/vendor/assets/src/css/images/leaflet/marker-icon-2x.png +0 -0
- data/vendor/assets/src/css/images/leaflet/marker-icon.png +0 -0
- data/vendor/assets/src/css/images/leaflet/marker-shadow.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-left.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-left@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-left@3x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-right.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-right@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-arrow-line-right@3x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-traveltime-w.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-day.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-day@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-day@3x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-month.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-month@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-month@3x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-week.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-week@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/ic-view-week@3x.png +0 -0
- data/vendor/assets/src/css/images/tui/icon.png +0 -0
- data/vendor/assets/src/css/images/tui/img-bi.png +0 -0
- data/vendor/assets/src/css/images/tui/img-bi@2x.png +0 -0
- data/vendor/assets/src/css/images/tui/img-bi@3x.png +0 -0
- data/vendor/assets/src/css/leaflet.css +664 -0
- data/vendor/assets/src/css/monokai.min.css +127 -0
- data/vendor/assets/src/css/style.css +1 -1
- data/vendor/assets/src/css/toastui-calendar.min.css +6 -0
- data/vendor/assets/src/index.html +12 -1
- data/vendor/assets/src/index_opal.html +16 -1
- data/vendor/assets/src/index_server.html +11 -1
- data/vendor/assets/src/index_server_wasm.html +10 -1
- data/vendor/assets/src/index_wasm.html +12 -1
- data/vendor/assets/src/js/atome/specific/tauri.js +32 -0
- data/vendor/assets/src/js/atome/utilities/importmap.js +9 -0
- data/vendor/assets/src/js/atome/utilities/three_module.js +88 -0
- data/vendor/assets/src/js/test.js +42 -0
- data/vendor/assets/src/js/third_parties/Three/build/three.cjs +54216 -0
- data/vendor/assets/src/js/third_parties/Three/build/three.module.min.js +6 -0
- data/vendor/assets/src/js/third_parties/Three/build/three.webgpu.min.js +6 -0
- data/vendor/assets/src/js/third_parties/Three/jsm/controls/OrbitControls.js +1532 -0
- data/vendor/assets/src/js/third_parties/codemirror.min.js +1 -0
- data/vendor/assets/src/js/third_parties/leaflet.js +6 -0
- data/vendor/assets/src/js/third_parties/leaflet.js.map +1 -0
- data/vendor/assets/src/js/third_parties/ruby.min.js +1 -0
- data/vendor/assets/src/js/third_parties/toastui-calendar.min.js +9 -0
- data/vendor/assets/src/medias/images/puydesancy.jpg +0 -0
- data/vendor/assets/src-tauri/Cargo.toml +6 -5
- data/vendor/assets/src-tauri/Info.plist +12 -0
- data/vendor/assets/src-tauri/src/main.rs +32 -3
- data/vendor/assets/src-tauri/src/midi.rs +25 -0
- data/vendor/assets/src-tauri/tauri.conf.json +4 -4
- metadata +60 -3
- data/vendor/assets/src/js/third_parties/three.min.js +0 -6
@@ -0,0 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* Copyright 2010-2024 Three.js Authors
|
4
|
+
* SPDX-License-Identifier: MIT
|
5
|
+
*/
|
6
|
+
const t="167",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},s={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,n=2,o=3,a=0,h=1,u=2,l=3,c=0,d=1,p=2,m=0,g=1,f=2,y=3,x=4,b=5,v=100,T=101,_=102,w=103,S=104,M=200,A=201,N=202,R=203,C=204,E=205,B=206,I=207,P=208,F=209,U=210,z=211,O=212,L=213,V=214,D=0,k=1,G=2,W=3,j=4,H=5,q=6,$=7,X=0,Y=1,J=2,Z=0,Q=1,K=2,tt=3,et=4,st=5,it=6,rt=7,nt="attached",ot="detached",at=300,ht=301,ut=302,lt=303,ct=304,dt=306,pt=1e3,mt=1001,gt=1002,ft=1003,yt=1004,xt=1004,bt=1005,vt=1005,Tt=1006,_t=1007,wt=1007,St=1008,Mt=1008,At=1009,Nt=1010,Rt=1011,Ct=1012,Et=1013,Bt=1014,It=1015,Pt=1016,Ft=1017,Ut=1018,zt=1020,Ot=35902,Lt=1021,Vt=1022,Dt=1023,kt=1024,Gt=1025,Wt=1026,jt=1027,Ht=1028,qt=1029,$t=1030,Xt=1031,Yt=1032,Jt=1033,Zt=33776,Qt=33777,Kt=33778,te=33779,ee=35840,se=35841,ie=35842,re=35843,ne=36196,oe=37492,ae=37496,he=37808,ue=37809,le=37810,ce=37811,de=37812,pe=37813,me=37814,ge=37815,fe=37816,ye=37817,xe=37818,be=37819,ve=37820,Te=37821,_e=36492,we=36494,Se=36495,Me=36283,Ae=36284,Ne=36285,Re=36286,Ce=2200,Ee=2201,Be=2202,Ie=2300,Pe=2301,Fe=2302,Ue=2400,ze=2401,Oe=2402,Le=2500,Ve=2501,De=0,ke=1,Ge=2,We=3200,je=3201,He=3202,qe=3203,$e=0,Xe=1,Ye="",Je="srgb",Ze="srgb-linear",Qe="display-p3",Ke="display-p3-linear",ts="linear",es="srgb",ss="rec709",is="p3",rs=0,ns=7680,os=7681,as=7682,hs=7683,us=34055,ls=34056,cs=5386,ds=512,ps=513,ms=514,gs=515,fs=516,ys=517,xs=518,bs=519,vs=512,Ts=513,_s=514,ws=515,Ss=516,Ms=517,As=518,Ns=519,Rs=35044,Cs=35048,Es=35040,Bs=35045,Is=35049,Ps=35041,Fs=35046,Us=35050,zs=35042,Os="100",Ls="300 es",Vs=2e3,Ds=2001;class ks{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const s=this._listeners;void 0===s[t]&&(s[t]=[]),-1===s[t].indexOf(e)&&s[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const s=this._listeners;return void 0!==s[t]&&-1!==s[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const s=this._listeners[t];if(void 0!==s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const s=e.slice(0);for(let e=0,i=s.length;e<i;e++)s[e].call(this,t);t.target=null}}}const Gs=["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 Ws=1234567;const js=Math.PI/180,Hs=180/Math.PI;function qs(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,s=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(Gs[255&t]+Gs[t>>8&255]+Gs[t>>16&255]+Gs[t>>24&255]+"-"+Gs[255&e]+Gs[e>>8&255]+"-"+Gs[e>>16&15|64]+Gs[e>>24&255]+"-"+Gs[63&s|128]+Gs[s>>8&255]+"-"+Gs[s>>16&255]+Gs[s>>24&255]+Gs[255&i]+Gs[i>>8&255]+Gs[i>>16&255]+Gs[i>>24&255]).toLowerCase()}function $s(t,e,s){return Math.max(e,Math.min(s,t))}function Xs(t,e){return(t%e+e)%e}function Ys(t,e,s){return(1-s)*t+s*e}function Js(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Zs(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Qs={DEG2RAD:js,RAD2DEG:Hs,generateUUID:qs,clamp:$s,euclideanModulo:Xs,mapLinear:function(t,e,s,i,r){return i+(t-e)*(r-i)/(s-e)},inverseLerp:function(t,e,s){return t!==e?(s-t)/(e-t):0},lerp:Ys,damp:function(t,e,s,i){return Ys(t,e,1-Math.exp(-s*i))},pingpong:function(t,e=1){return e-Math.abs(Xs(t,2*e)-e)},smoothstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*(3-2*t)},smootherstep:function(t,e,s){return t<=e?0:t>=s?1:(t=(t-e)/(s-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){void 0!==t&&(Ws=t);let e=Ws+=1831565813;return e=Math.imul(e^e>>>15,1|e),e^=e+Math.imul(e^e>>>7,61|e),((e^e>>>14)>>>0)/4294967296},degToRad:function(t){return t*js},radToDeg:function(t){return t*Hs},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,s,i,r){const n=Math.cos,o=Math.sin,a=n(s/2),h=o(s/2),u=n((e+i)/2),l=o((e+i)/2),c=n((e-i)/2),d=o((e-i)/2),p=n((i-e)/2),m=o((i-e)/2);switch(r){case"XYX":t.set(a*l,h*c,h*d,a*u);break;case"YZY":t.set(h*d,a*l,h*c,a*u);break;case"ZXZ":t.set(h*c,h*d,a*l,a*u);break;case"XZX":t.set(a*l,h*m,h*p,a*u);break;case"YXY":t.set(h*p,a*l,h*m,a*u);break;case"ZYZ":t.set(h*m,h*p,a*l,a*u);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:Zs,denormalize:Js};class Ks{constructor(t=0,e=0){Ks.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,s=this.y,i=t.elements;return this.x=i[0]*e+i[3]*s+i[6],this.y=i[1]*e+i[4]*s+i[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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}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(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,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 s=Math.cos(e),i=Math.sin(e),r=this.x-t.x,n=this.y-t.y;return this.x=r*s-n*i+t.x,this.y=r*i+n*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ti{constructor(t,e,s,i,r,n,o,a,h){ti.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h)}set(t,e,s,i,r,n,o,a,h){const u=this.elements;return u[0]=t,u[1]=i,u[2]=o,u[3]=e,u[4]=r,u[5]=a,u[6]=s,u[7]=n,u[8]=h,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],this}extractBasis(t,e,s){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),s.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 s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[3],a=s[6],h=s[1],u=s[4],l=s[7],c=s[2],d=s[5],p=s[8],m=i[0],g=i[3],f=i[6],y=i[1],x=i[4],b=i[7],v=i[2],T=i[5],_=i[8];return r[0]=n*m+o*y+a*v,r[3]=n*g+o*x+a*T,r[6]=n*f+o*b+a*_,r[1]=h*m+u*y+l*v,r[4]=h*g+u*x+l*T,r[7]=h*f+u*b+l*_,r[2]=c*m+d*y+p*v,r[5]=c*g+d*x+p*T,r[8]=c*f+d*b+p*_,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],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8];return e*n*u-e*o*h-s*r*u+s*o*a+i*r*h-i*n*a}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=u*n-o*h,c=o*a-u*r,d=h*r-n*a,p=e*l+s*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const m=1/p;return t[0]=l*m,t[1]=(i*h-u*s)*m,t[2]=(o*s-i*n)*m,t[3]=c*m,t[4]=(u*e-i*a)*m,t[5]=(i*r-o*e)*m,t[6]=d*m,t[7]=(s*a-h*e)*m,t[8]=(n*e-s*r)*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,s,i,r,n,o){const a=Math.cos(r),h=Math.sin(r);return this.set(s*a,s*h,-s*(a*n+h*o)+n+t,-i*h,i*a,-i*(-h*n+a*o)+o+e,0,0,1),this}scale(t,e){return this.premultiply(ei.makeScale(t,e)),this}rotate(t){return this.premultiply(ei.makeRotation(-t)),this}translate(t,e){return this.premultiply(ei.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),s=Math.sin(t);return this.set(e,-s,0,s,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,s=t.elements;for(let t=0;t<9;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<9;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const ei=new ti;const si={Int8Array:Int8Array,Uint8Array:Uint8Array,Uint8ClampedArray:Uint8ClampedArray,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};function ii(t,e){return new si[t](e)}function ri(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ni(){const t=ri("canvas");return t.style.display="block",t}const oi={};function ai(t){t in oi||(oi[t]=!0,console.warn(t))}const hi=(new ti).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ui=(new ti).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),li={[Ze]:{transfer:ts,primaries:ss,luminanceCoefficients:[.2126,.7152,.0722],toReference:t=>t,fromReference:t=>t},[Je]:{transfer:es,primaries:ss,luminanceCoefficients:[.2126,.7152,.0722],toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[Ke]:{transfer:ts,primaries:is,luminanceCoefficients:[.2289,.6917,.0793],toReference:t=>t.applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi)},[Qe]:{transfer:es,primaries:is,luminanceCoefficients:[.2289,.6917,.0793],toReference:t=>t.convertSRGBToLinear().applyMatrix3(ui),fromReference:t=>t.applyMatrix3(hi).convertLinearToSRGB()}},ci=new Set([Ze,Ke]),di={enabled:!0,_workingColorSpace:Ze,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!ci.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,s){if(!1===this.enabled||e===s||!e||!s)return t;const i=li[e].toReference;return(0,li[s].fromReference)(i(t))},fromWorkingColorSpace:function(t,e){return this.convert(t,this._workingColorSpace,e)},toWorkingColorSpace:function(t,e){return this.convert(t,e,this._workingColorSpace)},getPrimaries:function(t){return li[t].primaries},getTransfer:function(t){return t===Ye?ts:li[t].transfer},getLuminanceCoefficients:function(t,e=this._workingColorSpace){return t.fromArray(li[e].luminanceCoefficients)}};function pi(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function mi(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let gi;class fi{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===gi&&(gi=ri("canvas")),gi.width=t.width,gi.height=t.height;const s=gi.getContext("2d");t instanceof ImageData?s.putImageData(t,0,0):s.drawImage(t,0,0,t.width,t.height),e=gi}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("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ri("canvas");e.width=t.width,e.height=t.height;const s=e.getContext("2d");s.drawImage(t,0,0,t.width,t.height);const i=s.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*pi(r[t]/255);return s.putImageData(i,0,0),e}if(t.data){const e=t.data.slice(0);for(let t=0;t<e.length;t++)e instanceof Uint8Array||e instanceof Uint8ClampedArray?e[t]=Math.floor(255*pi(e[t]/255)):e[t]=pi(e[t]);return{data:e,width:t.width,height:t.height}}return console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."),t}}let yi=0;class xi{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:yi++}),this.uuid=qs(),this.data=t,this.dataReady=!0,this.version=0}set needsUpdate(t){!0===t&&this.version++}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.images[this.uuid])return t.images[this.uuid];const s={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,s=i.length;e<s;e++)i[e].isDataTexture?t.push(bi(i[e].image)):t.push(bi(i[e]))}else t=bi(i);s.url=t}return e||(t.images[this.uuid]=s),s}}function bi(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?fi.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:(console.warn("THREE.Texture: Unable to serialize Texture."),{})}let vi=0;class Ti extends ks{constructor(t=Ti.DEFAULT_IMAGE,e=Ti.DEFAULT_MAPPING,s=1001,i=1001,r=1006,n=1008,o=1023,a=1009,h=Ti.DEFAULT_ANISOTROPY,u=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:vi++}),this.uuid=qs(),this.name="",this.source=new xi(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=s,this.wrapT=i,this.magFilter=r,this.minFilter=n,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=a,this.offset=new Ks(0,0),this.repeat=new Ks(1,1),this.center=new Ks(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new ti,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=u,this.userData={},this.version=0,this.onUpdate=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.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const s={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&&(s.userData=this.userData),e||(t.textures[this.uuid]=s),s}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(this.mapping!==at)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case pt:t.x=t.x-Math.floor(t.x);break;case mt:t.x=t.x<0?0:1;break;case gt:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case pt:t.y=t.y-Math.floor(t.y);break;case mt:t.y=t.y<0?0:1;break;case gt:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}Ti.DEFAULT_IMAGE=null,Ti.DEFAULT_MAPPING=at,Ti.DEFAULT_ANISOTROPY=1;class _i{constructor(t=0,e=0,s=0,i=1){_i.prototype.isVector4=!0,this.x=t,this.y=e,this.z=s,this.w=i}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,s,i){return this.x=t,this.y=e,this.z=s,this.w=i,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=void 0!==t.w?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,s=this.y,i=this.z,r=this.w,n=t.elements;return this.x=n[0]*e+n[4]*s+n[8]*i+n[12]*r,this.y=n[1]*e+n[5]*s+n[9]*i+n[13]*r,this.z=n[2]*e+n[6]*s+n[10]*i+n[14]*r,this.w=n[3]*e+n[7]*s+n[11]*i+n[15]*r,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,s,i,r;const n=.01,o=.1,a=t.elements,h=a[0],u=a[4],l=a[8],c=a[1],d=a[5],p=a[9],m=a[2],g=a[6],f=a[10];if(Math.abs(u-c)<n&&Math.abs(l-m)<n&&Math.abs(p-g)<n){if(Math.abs(u+c)<o&&Math.abs(l+m)<o&&Math.abs(p+g)<o&&Math.abs(h+d+f-3)<o)return this.set(1,0,0,0),this;e=Math.PI;const t=(h+1)/2,a=(d+1)/2,y=(f+1)/2,x=(u+c)/4,b=(l+m)/4,v=(p+g)/4;return t>a&&t>y?t<n?(s=0,i=.707106781,r=.707106781):(s=Math.sqrt(t),i=x/s,r=b/s):a>y?a<n?(s=.707106781,i=0,r=.707106781):(i=Math.sqrt(a),s=x/i,r=v/i):y<n?(s=.707106781,i=.707106781,r=0):(r=Math.sqrt(y),s=b/r,i=v/r),this.set(s,i,r,e),this}let y=Math.sqrt((g-p)*(g-p)+(l-m)*(l-m)+(c-u)*(c-u));return Math.abs(y)<.001&&(y=1),this.x=(g-p)/y,this.y=(l-m)/y,this.z=(c-u)/y,this.w=Math.acos((h+d+f-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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this.w=t.w+(e.w-t.w)*s,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 wi extends ks{constructor(t=1,e=1,s={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new _i(0,0,t,e),this.scissorTest=!1,this.viewport=new _i(0,0,t,e);const i={width:t,height:e,depth:1};s=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Tt,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},s);const r=new Ti(i,s.mapping,s.wrapS,s.wrapT,s.magFilter,s.minFilter,s.format,s.type,s.anisotropy,s.colorSpace);r.flipY=!1,r.generateMipmaps=s.generateMipmaps,r.internalFormat=s.internalFormat,this.textures=[];const n=s.count;for(let t=0;t<n;t++)this.textures[t]=r.clone(),this.textures[t].isRenderTargetTexture=!0;this.depthBuffer=s.depthBuffer,this.stencilBuffer=s.stencilBuffer,this.resolveDepthBuffer=s.resolveDepthBuffer,this.resolveStencilBuffer=s.resolveStencilBuffer,this.depthTexture=s.depthTexture,this.samples=s.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,s=1){if(this.width!==t||this.height!==e||this.depth!==s){this.width=t,this.height=e,this.depth=s;for(let i=0,r=this.textures.length;i<r;i++)this.textures[i].image.width=t,this.textures[i].image.height=e,this.textures[i].image.depth=s;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 e=0,s=t.textures.length;e<s;e++)this.textures[e]=t.textures[e].clone(),this.textures[e].isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new xi(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.resolveDepthBuffer=t.resolveDepthBuffer,this.resolveStencilBuffer=t.resolveStencilBuffer,null!==t.depthTexture&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class Si extends wi{constructor(t=1,e=1,s={}){super(t,e,s),this.isWebGLRenderTarget=!0}}class Mi extends Ti{constructor(t=null,e=1,s=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:s,depth:i},this.magFilter=ft,this.minFilter=ft,this.wrapR=mt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Ai extends Si{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGLArrayRenderTarget=!0,this.depth=s,this.texture=new Mi(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class Ni extends Ti{constructor(t=null,e=1,s=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:s,depth:i},this.magFilter=ft,this.minFilter=ft,this.wrapR=mt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Ri extends Si{constructor(t=1,e=1,s=1,i={}){super(t,e,i),this.isWebGL3DRenderTarget=!0,this.depth=s,this.texture=new Ni(null,t,e,s),this.texture.isRenderTargetTexture=!0}}class Ci{constructor(t=0,e=0,s=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=i}static slerpFlat(t,e,s,i,r,n,o){let a=s[i+0],h=s[i+1],u=s[i+2],l=s[i+3];const c=r[n+0],d=r[n+1],p=r[n+2],m=r[n+3];if(0===o)return t[e+0]=a,t[e+1]=h,t[e+2]=u,void(t[e+3]=l);if(1===o)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=m);if(l!==m||a!==c||h!==d||u!==p){let t=1-o;const e=a*c+h*d+u*p+l*m,s=e>=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),n=Math.atan2(r,e*s);t=Math.sin(t*n)/r,o=Math.sin(o*n)/r}const r=o*s;if(a=a*t+c*r,h=h*t+d*r,u=u*t+p*r,l=l*t+m*r,t===1-o){const t=1/Math.sqrt(a*a+h*h+u*u+l*l);a*=t,h*=t,u*=t,l*=t}}t[e]=a,t[e+1]=h,t[e+2]=u,t[e+3]=l}static multiplyQuaternionsFlat(t,e,s,i,r,n){const o=s[i],a=s[i+1],h=s[i+2],u=s[i+3],l=r[n],c=r[n+1],d=r[n+2],p=r[n+3];return t[e]=o*p+u*l+a*d-h*c,t[e+1]=a*p+u*c+h*l-o*d,t[e+2]=h*p+u*d+o*c-a*l,t[e+3]=u*p-o*l-a*c-h*d,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,s,i){return this._x=t,this._y=e,this._z=s,this._w=i,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 s=t._x,i=t._y,r=t._z,n=t._order,o=Math.cos,a=Math.sin,h=o(s/2),u=o(i/2),l=o(r/2),c=a(s/2),d=a(i/2),p=a(r/2);switch(n){case"XYZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"YXZ":this._x=c*u*l+h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"ZXY":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l-c*d*p;break;case"ZYX":this._x=c*u*l-h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l+c*d*p;break;case"YZX":this._x=c*u*l+h*d*p,this._y=h*d*l+c*u*p,this._z=h*u*p-c*d*l,this._w=h*u*l-c*d*p;break;case"XZY":this._x=c*u*l-h*d*p,this._y=h*d*l-c*u*p,this._z=h*u*p+c*d*l,this._w=h*u*l+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+n)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,i=Math.sin(s);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],i=e[4],r=e[8],n=e[1],o=e[5],a=e[9],h=e[2],u=e[6],l=e[10],c=s+o+l;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(u-a)*t,this._y=(r-h)*t,this._z=(n-i)*t}else if(s>o&&s>l){const t=2*Math.sqrt(1+s-o-l);this._w=(u-a)/t,this._x=.25*t,this._y=(i+n)/t,this._z=(r+h)/t}else if(o>l){const t=2*Math.sqrt(1+o-s-l);this._w=(r-h)/t,this._x=(i+n)/t,this._y=.25*t,this._z=(a+u)/t}else{const t=2*Math.sqrt(1+l-s-o);this._w=(n-i)/t,this._x=(r+h)/t,this._y=(a+u)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(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=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs($s(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(0===s)return this;const i=Math.min(1,e/s);return this.slerp(t,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(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 0===t?(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 s=t._x,i=t._y,r=t._z,n=t._w,o=e._x,a=e._y,h=e._z,u=e._w;return this._x=s*u+n*o+i*h-r*a,this._y=i*u+n*a+r*o-s*h,this._z=r*u+n*h+s*a-i*o,this._w=n*u-s*o-i*a-r*h,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const s=this._x,i=this._y,r=this._z,n=this._w;let o=n*t._w+s*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=n,this._x=s,this._y=i,this._z=r,this;const a=1-o*o;if(a<=Number.EPSILON){const t=1-e;return this._w=t*n+e*this._w,this._x=t*s+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const h=Math.sqrt(a),u=Math.atan2(h,o),l=Math.sin((1-e)*u)/h,c=Math.sin(e*u)/h;return this._w=n*l+this._w*c,this._x=s*l+this._x*c,this._y=i*l+this._y*c,this._z=r*l+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),s=Math.random(),i=Math.sqrt(1-s),r=Math.sqrt(s);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*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 Ei{constructor(t=0,e=0,s=0){Ei.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return void 0===s&&(s=this.z),this.x=t,this.y=e,this.z=s,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(Ii.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ii.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*i,this.y=r[1]*e+r[4]*s+r[7]*i,this.z=r[2]*e+r[5]*s+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,i=this.z,r=t.elements,n=1/(r[3]*e+r[7]*s+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*i+r[12])*n,this.y=(r[1]*e+r[5]*s+r[9]*i+r[13])*n,this.z=(r[2]*e+r[6]*s+r[10]*i+r[14])*n,this}applyQuaternion(t){const e=this.x,s=this.y,i=this.z,r=t.x,n=t.y,o=t.z,a=t.w,h=2*(n*i-o*s),u=2*(o*e-r*i),l=2*(r*s-n*e);return this.x=e+a*h+n*l-o*u,this.y=s+a*u+o*h-r*l,this.z=i+a*l+r*u-n*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,s=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*i,this.y=r[1]*e+r[5]*s+r[9]*i,this.z=r[2]*e+r[6]*s+r[10]*i,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=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}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,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,i=t.y,r=t.z,n=e.x,o=e.y,a=e.z;return this.x=i*a-r*o,this.y=r*n-s*a,this.z=s*o-i*n,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return Bi.copy(this).projectOnVector(t),this.sub(Bi)}reflect(t){return this.sub(Bi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const s=this.dot(t)/e;return Math.acos($s(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,i=this.z-t.z;return e*e+s*s+i*i}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,s){const i=Math.sin(e)*t;return this.x=i*Math.sin(s),this.y=Math.cos(e)*t,this.z=i*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,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(),s=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}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=2*Math.random()-1,s=Math.sqrt(1-e*e);return this.x=s*Math.cos(t),this.y=e,this.z=s*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Bi=new Ei,Ii=new Ci;class Pi{constructor(t=new Ei(1/0,1/0,1/0),e=new Ei(-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,s=t.length;e<s;e+=3)this.expandByPoint(Ui.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,s=t.count;e<s;e++)this.expandByPoint(Ui.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=Ui.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),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 s=t.geometry;if(void 0!==s){const i=s.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,s=i.count;e<s;e++)!0===t.isMesh?t.getVertexPosition(e,Ui):Ui.fromBufferAttribute(i,e),Ui.applyMatrix4(t.matrixWorld),this.expandByPoint(Ui);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),zi.copy(t.boundingBox)):(null===s.boundingBox&&s.computeBoundingBox(),zi.copy(s.boundingBox)),zi.applyMatrix4(t.matrixWorld),this.union(zi)}const i=t.children;for(let t=0,s=i.length;t<s;t++)this.expandByObject(i[t],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,Ui),Ui.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,s;return t.normal.x>0?(e=t.normal.x*this.min.x,s=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,s=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,s+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,s+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,s+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,s+=t.normal.z*this.min.z),e<=-t.constant&&s>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Wi),ji.subVectors(this.max,Wi),Oi.subVectors(t.a,Wi),Li.subVectors(t.b,Wi),Vi.subVectors(t.c,Wi),Di.subVectors(Li,Oi),ki.subVectors(Vi,Li),Gi.subVectors(Oi,Vi);let e=[0,-Di.z,Di.y,0,-ki.z,ki.y,0,-Gi.z,Gi.y,Di.z,0,-Di.x,ki.z,0,-ki.x,Gi.z,0,-Gi.x,-Di.y,Di.x,0,-ki.y,ki.x,0,-Gi.y,Gi.x,0];return!!$i(e,Oi,Li,Vi,ji)&&(e=[1,0,0,0,1,0,0,0,1],!!$i(e,Oi,Li,Vi,ji)&&(Hi.crossVectors(Di,ki),e=[Hi.x,Hi.y,Hi.z],$i(e,Oi,Li,Vi,ji)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,Ui).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(Ui).length()),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()||(Fi[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Fi[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Fi[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Fi[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Fi[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Fi[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Fi[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Fi[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Fi)),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 Fi=[new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei,new Ei],Ui=new Ei,zi=new Pi,Oi=new Ei,Li=new Ei,Vi=new Ei,Di=new Ei,ki=new Ei,Gi=new Ei,Wi=new Ei,ji=new Ei,Hi=new Ei,qi=new Ei;function $i(t,e,s,i,r){for(let n=0,o=t.length-3;n<=o;n+=3){qi.fromArray(t,n);const o=r.x*Math.abs(qi.x)+r.y*Math.abs(qi.y)+r.z*Math.abs(qi.z),a=e.dot(qi),h=s.dot(qi),u=i.dot(qi);if(Math.max(-Math.max(a,h,u),Math.min(a,h,u))>o)return!1}return!0}const Xi=new Pi,Yi=new Ei,Ji=new Ei;class Zi{constructor(t=new Ei,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 s=this.center;void 0!==e?s.copy(e):Xi.setFromPoints(t).getCenter(s);let i=0;for(let e=0,r=t.length;e<r;e++)i=Math.max(i,s.distanceToSquared(t[e]));return this.radius=Math.sqrt(i),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 s=this.center.distanceToSquared(t);return e.copy(t),s>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;Yi.subVectors(t,this.center);const e=Yi.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),s=.5*(t-this.radius);this.center.addScaledVector(Yi,s/t),this.radius+=s}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(Ji.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(Yi.copy(t.center).add(Ji)),this.expandByPoint(Yi.copy(t.center).sub(Ji))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Qi=new Ei,Ki=new Ei,tr=new Ei,er=new Ei,sr=new Ei,ir=new Ei,rr=new Ei;class nr{constructor(t=new Ei,e=new Ei(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,Qi)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const s=e.dot(this.direction);return s<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,s)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=Qi.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Qi.copy(this.origin).addScaledVector(this.direction,e),Qi.distanceToSquared(t))}distanceSqToSegment(t,e,s,i){Ki.copy(t).add(e).multiplyScalar(.5),tr.copy(e).sub(t).normalize(),er.copy(this.origin).sub(Ki);const r=.5*t.distanceTo(e),n=-this.direction.dot(tr),o=er.dot(this.direction),a=-er.dot(tr),h=er.lengthSq(),u=Math.abs(1-n*n);let l,c,d,p;if(u>0)if(l=n*a-o,c=n*o-a,p=r*u,l>=0)if(c>=-p)if(c<=p){const t=1/u;l*=t,c*=t,d=l*(l+n*c+2*o)+c*(n*l+c+2*a)+h}else c=r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c=-r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;else c<=-p?(l=Math.max(0,-(-n*r+o)),c=l>0?-r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h):c<=p?(l=0,c=Math.min(Math.max(-r,-a),r),d=c*(c+2*a)+h):(l=Math.max(0,-(n*r+o)),c=l>0?r:Math.min(Math.max(-r,-a),r),d=-l*l+c*(c+2*a)+h);else c=n>0?-r:r,l=Math.max(0,-(n*c+o)),d=-l*l+c*(c+2*a)+h;return s&&s.copy(this.origin).addScaledVector(this.direction,l),i&&i.copy(Ki).addScaledVector(tr,c),d}intersectSphere(t,e){Qi.subVectors(t.center,this.origin);const s=Qi.dot(this.direction),i=Qi.dot(Qi)-s*s,r=t.radius*t.radius;if(i>r)return null;const n=Math.sqrt(r-i),o=s-n,a=s+n;return a<0?null:o<0?this.at(a,e):this.at(o,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const s=-(this.origin.dot(t.normal)+t.constant)/e;return s>=0?s:null}intersectPlane(t,e){const s=this.distanceToPlane(t);return null===s?null:this.at(s,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);if(0===e)return!0;return t.normal.dot(this.direction)*e<0}intersectBox(t,e){let s,i,r,n,o,a;const h=1/this.direction.x,u=1/this.direction.y,l=1/this.direction.z,c=this.origin;return h>=0?(s=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(s=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),u>=0?(r=(t.min.y-c.y)*u,n=(t.max.y-c.y)*u):(r=(t.max.y-c.y)*u,n=(t.min.y-c.y)*u),s>n||r>i?null:((r>s||isNaN(s))&&(s=r),(n<i||isNaN(i))&&(i=n),l>=0?(o=(t.min.z-c.z)*l,a=(t.max.z-c.z)*l):(o=(t.max.z-c.z)*l,a=(t.min.z-c.z)*l),s>a||o>i?null:((o>s||s!=s)&&(s=o),(a<i||i!=i)&&(i=a),i<0?null:this.at(s>=0?s:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,Qi)}intersectTriangle(t,e,s,i,r){sr.subVectors(e,t),ir.subVectors(s,t),rr.crossVectors(sr,ir);let n,o=this.direction.dot(rr);if(o>0){if(i)return null;n=1}else{if(!(o<0))return null;n=-1,o=-o}er.subVectors(this.origin,t);const a=n*this.direction.dot(ir.crossVectors(er,ir));if(a<0)return null;const h=n*this.direction.dot(sr.cross(er));if(h<0)return null;if(a+h>o)return null;const u=-n*er.dot(rr);return u<0?null:this.at(u/o,r)}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 or{constructor(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){or.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g)}set(t,e,s,i,r,n,o,a,h,u,l,c,d,p,m,g){const f=this.elements;return f[0]=t,f[4]=e,f[8]=s,f[12]=i,f[1]=r,f[5]=n,f[9]=o,f[13]=a,f[2]=h,f[6]=u,f[10]=l,f[14]=c,f[3]=d,f[7]=p,f[11]=m,f[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 or).fromArray(this.elements)}copy(t){const e=this.elements,s=t.elements;return e[0]=s[0],e[1]=s[1],e[2]=s[2],e[3]=s[3],e[4]=s[4],e[5]=s[5],e[6]=s[6],e[7]=s[7],e[8]=s[8],e[9]=s[9],e[10]=s[10],e[11]=s[11],e[12]=s[12],e[13]=s[13],e[14]=s[14],e[15]=s[15],this}copyPosition(t){const e=this.elements,s=t.elements;return e[12]=s[12],e[13]=s[13],e[14]=s[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,s){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),s.setFromMatrixColumn(this,2),this}makeBasis(t,e,s){return this.set(t.x,e.x,s.x,0,t.y,e.y,s.y,0,t.z,e.z,s.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,s=t.elements,i=1/ar.setFromMatrixColumn(t,0).length(),r=1/ar.setFromMatrixColumn(t,1).length(),n=1/ar.setFromMatrixColumn(t,2).length();return e[0]=s[0]*i,e[1]=s[1]*i,e[2]=s[2]*i,e[3]=0,e[4]=s[4]*r,e[5]=s[5]*r,e[6]=s[6]*r,e[7]=0,e[8]=s[8]*n,e[9]=s[9]*n,e[10]=s[10]*n,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,s=t.x,i=t.y,r=t.z,n=Math.cos(s),o=Math.sin(s),a=Math.cos(i),h=Math.sin(i),u=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=-a*l,e[8]=h,e[1]=s+i*h,e[5]=t-r*h,e[9]=-o*a,e[2]=r-t*h,e[6]=i+s*h,e[10]=n*a}else if("YXZ"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t+r*o,e[4]=i*o-s,e[8]=n*h,e[1]=n*l,e[5]=n*u,e[9]=-o,e[2]=s*o-i,e[6]=r+t*o,e[10]=n*a}else if("ZXY"===t.order){const t=a*u,s=a*l,i=h*u,r=h*l;e[0]=t-r*o,e[4]=-n*l,e[8]=i+s*o,e[1]=s+i*o,e[5]=n*u,e[9]=r-t*o,e[2]=-n*h,e[6]=o,e[10]=n*a}else if("ZYX"===t.order){const t=n*u,s=n*l,i=o*u,r=o*l;e[0]=a*u,e[4]=i*h-s,e[8]=t*h+r,e[1]=a*l,e[5]=r*h+t,e[9]=s*h-i,e[2]=-h,e[6]=o*a,e[10]=n*a}else if("YZX"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=r-t*l,e[8]=i*l+s,e[1]=l,e[5]=n*u,e[9]=-o*u,e[2]=-h*u,e[6]=s*l+i,e[10]=t-r*l}else if("XZY"===t.order){const t=n*a,s=n*h,i=o*a,r=o*h;e[0]=a*u,e[4]=-l,e[8]=h*u,e[1]=t*l+r,e[5]=n*u,e[9]=s*l-i,e[2]=i*l-s,e[6]=o*u,e[10]=r*l+t}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(ur,t,lr)}lookAt(t,e,s){const i=this.elements;return pr.subVectors(t,e),0===pr.lengthSq()&&(pr.z=1),pr.normalize(),cr.crossVectors(s,pr),0===cr.lengthSq()&&(1===Math.abs(s.z)?pr.x+=1e-4:pr.z+=1e-4,pr.normalize(),cr.crossVectors(s,pr)),cr.normalize(),dr.crossVectors(pr,cr),i[0]=cr.x,i[4]=dr.x,i[8]=pr.x,i[1]=cr.y,i[5]=dr.y,i[9]=pr.y,i[2]=cr.z,i[6]=dr.z,i[10]=pr.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const s=t.elements,i=e.elements,r=this.elements,n=s[0],o=s[4],a=s[8],h=s[12],u=s[1],l=s[5],c=s[9],d=s[13],p=s[2],m=s[6],g=s[10],f=s[14],y=s[3],x=s[7],b=s[11],v=s[15],T=i[0],_=i[4],w=i[8],S=i[12],M=i[1],A=i[5],N=i[9],R=i[13],C=i[2],E=i[6],B=i[10],I=i[14],P=i[3],F=i[7],U=i[11],z=i[15];return r[0]=n*T+o*M+a*C+h*P,r[4]=n*_+o*A+a*E+h*F,r[8]=n*w+o*N+a*B+h*U,r[12]=n*S+o*R+a*I+h*z,r[1]=u*T+l*M+c*C+d*P,r[5]=u*_+l*A+c*E+d*F,r[9]=u*w+l*N+c*B+d*U,r[13]=u*S+l*R+c*I+d*z,r[2]=p*T+m*M+g*C+f*P,r[6]=p*_+m*A+g*E+f*F,r[10]=p*w+m*N+g*B+f*U,r[14]=p*S+m*R+g*I+f*z,r[3]=y*T+x*M+b*C+v*P,r[7]=y*_+x*A+b*E+v*F,r[11]=y*w+x*N+b*B+v*U,r[15]=y*S+x*R+b*I+v*z,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],s=t[4],i=t[8],r=t[12],n=t[1],o=t[5],a=t[9],h=t[13],u=t[2],l=t[6],c=t[10],d=t[14];return t[3]*(+r*a*l-i*h*l-r*o*c+s*h*c+i*o*d-s*a*d)+t[7]*(+e*a*d-e*h*c+r*n*c-i*n*d+i*h*u-r*a*u)+t[11]*(+e*h*l-e*o*d-r*n*l+s*n*d+r*o*u-s*h*u)+t[15]*(-i*o*u-e*a*l+e*o*c+i*n*l-s*n*c+s*a*u)}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,s){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=s),this}invert(){const t=this.elements,e=t[0],s=t[1],i=t[2],r=t[3],n=t[4],o=t[5],a=t[6],h=t[7],u=t[8],l=t[9],c=t[10],d=t[11],p=t[12],m=t[13],g=t[14],f=t[15],y=l*g*h-m*c*h+m*a*d-o*g*d-l*a*f+o*c*f,x=p*c*h-u*g*h-p*a*d+n*g*d+u*a*f-n*c*f,b=u*m*h-p*l*h+p*o*d-n*m*d-u*o*f+n*l*f,v=p*l*a-u*m*a-p*o*c+n*m*c+u*o*g-n*l*g,T=e*y+s*x+i*b+r*v;if(0===T)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const _=1/T;return t[0]=y*_,t[1]=(m*c*r-l*g*r-m*i*d+s*g*d+l*i*f-s*c*f)*_,t[2]=(o*g*r-m*a*r+m*i*h-s*g*h-o*i*f+s*a*f)*_,t[3]=(l*a*r-o*c*r-l*i*h+s*c*h+o*i*d-s*a*d)*_,t[4]=x*_,t[5]=(u*g*r-p*c*r+p*i*d-e*g*d-u*i*f+e*c*f)*_,t[6]=(p*a*r-n*g*r-p*i*h+e*g*h+n*i*f-e*a*f)*_,t[7]=(n*c*r-u*a*r+u*i*h-e*c*h-n*i*d+e*a*d)*_,t[8]=b*_,t[9]=(p*l*r-u*m*r-p*s*d+e*m*d+u*s*f-e*l*f)*_,t[10]=(n*m*r-p*o*r+p*s*h-e*m*h-n*s*f+e*o*f)*_,t[11]=(u*o*r-n*l*r-u*s*h+e*l*h+n*s*d-e*o*d)*_,t[12]=v*_,t[13]=(u*m*i-p*l*i+p*s*c-e*m*c-u*s*g+e*l*g)*_,t[14]=(p*o*i-n*m*i-p*s*a+e*m*a+n*s*g-e*o*g)*_,t[15]=(n*l*i-u*o*i+u*s*a-e*l*a-n*s*c+e*o*c)*_,this}scale(t){const e=this.elements,s=t.x,i=t.y,r=t.z;return e[0]*=s,e[4]*=i,e[8]*=r,e[1]*=s,e[5]*=i,e[9]*=r,e[2]*=s,e[6]*=i,e[10]*=r,e[3]*=s,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],s=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,s,i))}makeTranslation(t,e,s){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,s,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),s=Math.sin(t);return this.set(1,0,0,0,0,e,-s,0,0,s,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,0,s,0,0,1,0,0,-s,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),s=Math.sin(t);return this.set(e,-s,0,0,s,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const s=Math.cos(e),i=Math.sin(e),r=1-s,n=t.x,o=t.y,a=t.z,h=r*n,u=r*o;return this.set(h*n+s,h*o-i*a,h*a+i*o,0,h*o+i*a,u*o+s,u*a-i*n,0,h*a-i*o,u*a+i*n,r*a*a+s,0,0,0,0,1),this}makeScale(t,e,s){return this.set(t,0,0,0,0,e,0,0,0,0,s,0,0,0,0,1),this}makeShear(t,e,s,i,r,n){return this.set(1,s,r,0,t,1,n,0,e,i,1,0,0,0,0,1),this}compose(t,e,s){const i=this.elements,r=e._x,n=e._y,o=e._z,a=e._w,h=r+r,u=n+n,l=o+o,c=r*h,d=r*u,p=r*l,m=n*u,g=n*l,f=o*l,y=a*h,x=a*u,b=a*l,v=s.x,T=s.y,_=s.z;return i[0]=(1-(m+f))*v,i[1]=(d+b)*v,i[2]=(p-x)*v,i[3]=0,i[4]=(d-b)*T,i[5]=(1-(c+f))*T,i[6]=(g+y)*T,i[7]=0,i[8]=(p+x)*_,i[9]=(g-y)*_,i[10]=(1-(c+m))*_,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,s){const i=this.elements;let r=ar.set(i[0],i[1],i[2]).length();const n=ar.set(i[4],i[5],i[6]).length(),o=ar.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],hr.copy(this);const a=1/r,h=1/n,u=1/o;return hr.elements[0]*=a,hr.elements[1]*=a,hr.elements[2]*=a,hr.elements[4]*=h,hr.elements[5]*=h,hr.elements[6]*=h,hr.elements[8]*=u,hr.elements[9]*=u,hr.elements[10]*=u,e.setFromRotationMatrix(hr),s.x=r,s.y=n,s.z=o,this}makePerspective(t,e,s,i,r,n,o=2e3){const a=this.elements,h=2*r/(e-t),u=2*r/(s-i),l=(e+t)/(e-t),c=(s+i)/(s-i);let d,p;if(o===Vs)d=-(n+r)/(n-r),p=-2*n*r/(n-r);else{if(o!==Ds)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+o);d=-n/(n-r),p=-n*r/(n-r)}return a[0]=h,a[4]=0,a[8]=l,a[12]=0,a[1]=0,a[5]=u,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=d,a[14]=p,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,s,i,r,n,o=2e3){const a=this.elements,h=1/(e-t),u=1/(s-i),l=1/(n-r),c=(e+t)*h,d=(s+i)*u;let p,m;if(o===Vs)p=(n+r)*l,m=-2*l;else{if(o!==Ds)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);p=r*l,m=-1*l}return a[0]=2*h,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*u,a[9]=0,a[13]=-d,a[2]=0,a[6]=0,a[10]=m,a[14]=-p,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,s=t.elements;for(let t=0;t<16;t++)if(e[t]!==s[t])return!1;return!0}fromArray(t,e=0){for(let s=0;s<16;s++)this.elements[s]=t[s+e];return this}toArray(t=[],e=0){const s=this.elements;return t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3],t[e+4]=s[4],t[e+5]=s[5],t[e+6]=s[6],t[e+7]=s[7],t[e+8]=s[8],t[e+9]=s[9],t[e+10]=s[10],t[e+11]=s[11],t[e+12]=s[12],t[e+13]=s[13],t[e+14]=s[14],t[e+15]=s[15],t}}const ar=new Ei,hr=new or,ur=new Ei(0,0,0),lr=new Ei(1,1,1),cr=new Ei,dr=new Ei,pr=new Ei,mr=new or,gr=new Ci;class fr{constructor(t=0,e=0,s=0,i=fr.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=s,this._order=i}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,s,i=this._order){return this._x=t,this._y=e,this._z=s,this._order=i,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,s=!0){const i=t.elements,r=i[0],n=i[4],o=i[8],a=i[1],h=i[5],u=i[9],l=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin($s(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-n,r)):(this._x=Math.atan2(c,h),this._z=0);break;case"YXZ":this._x=Math.asin(-$s(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(a,h)):(this._y=Math.atan2(-l,r),this._z=0);break;case"ZXY":this._x=Math.asin($s(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-l,d),this._z=Math.atan2(-n,h)):(this._y=0,this._z=Math.atan2(a,r));break;case"ZYX":this._y=Math.asin(-$s(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(a,r)):(this._x=0,this._z=Math.atan2(-n,h));break;case"YZX":this._z=Math.asin($s(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-u,h),this._y=Math.atan2(-l,r)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-$s(n,-1,1)),Math.abs(n)<.9999999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,r)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===s&&this._onChangeCallback(),this}setFromQuaternion(t,e,s){return mr.makeRotationFromQuaternion(t),this.setFromRotationMatrix(mr,e,s)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return gr.setFromEuler(this),this.setFromQuaternion(gr,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],void 0!==t[3]&&(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}}fr.DEFAULT_ORDER="XYZ";class yr{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 0!=(this.mask&t.mask)}isEnabled(t){return 0!=(this.mask&(1<<t|0))}}let xr=0;const br=new Ei,vr=new Ci,Tr=new or,_r=new Ei,wr=new Ei,Sr=new Ei,Mr=new Ci,Ar=new Ei(1,0,0),Nr=new Ei(0,1,0),Rr=new Ei(0,0,1),Cr={type:"added"},Er={type:"removed"},Br={type:"childadded",child:null},Ir={type:"childremoved",child:null};class Pr extends ks{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:xr++}),this.uuid=qs(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Pr.DEFAULT_UP.clone();const t=new Ei,e=new fr,s=new Ci,i=new Ei(1,1,1);e._onChange((function(){s.setFromEuler(e,!1)})),s._onChange((function(){e.setFromQuaternion(s,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:s},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new or},normalMatrix:{value:new ti}}),this.matrix=new or,this.matrixWorld=new or,this.matrixAutoUpdate=Pr.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Pr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new yr,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 vr.setFromAxisAngle(t,e),this.quaternion.multiply(vr),this}rotateOnWorldAxis(t,e){return vr.setFromAxisAngle(t,e),this.quaternion.premultiply(vr),this}rotateX(t){return this.rotateOnAxis(Ar,t)}rotateY(t){return this.rotateOnAxis(Nr,t)}rotateZ(t){return this.rotateOnAxis(Rr,t)}translateOnAxis(t,e){return br.copy(t).applyQuaternion(this.quaternion),this.position.add(br.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Ar,t)}translateY(t){return this.translateOnAxis(Nr,t)}translateZ(t){return this.translateOnAxis(Rr,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Tr.copy(this.matrixWorld).invert())}lookAt(t,e,s){t.isVector3?_r.copy(t):_r.set(t,e,s);const i=this.parent;this.updateWorldMatrix(!0,!1),wr.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Tr.lookAt(wr,_r,this.up):Tr.lookAt(_r,wr,this.up),this.quaternion.setFromRotationMatrix(Tr),i&&(Tr.extractRotation(i.matrixWorld),vr.setFromRotationMatrix(Tr),this.quaternion.premultiply(vr.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);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(Cr),Br.child=t,this.dispatchEvent(Br),Br.child=null):console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",t),this)}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Er),Ir.child=t,this.dispatchEvent(Ir),Ir.child=null),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){return this.remove(...this.children)}attach(t){return this.updateWorldMatrix(!0,!1),Tr.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),Tr.multiply(t.parent.matrixWorld)),t.applyMatrix4(Tr),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Cr),Br.child=t,this.dispatchEvent(Br),Br.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 s=0,i=this.children.length;s<i;s++){const i=this.children[s].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,s=[]){this[t]===e&&s.push(this);const i=this.children;for(let r=0,n=i.length;r<n;r++)i[r].getObjectsByProperty(t,e,s);return s}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(wr,t,Sr),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(wr,Mr,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 s=0,i=e.length;s<i;s++)e[s].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let s=0,i=e.length;s<i;s++)e[s].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(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)&&(!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let s=0,i=e.length;s<i;s++){e[s].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const s=this.parent;if(!0===t&&null!==s&&s.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),!0===this.matrixWorldAutoUpdate&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),!0===e){const t=this.children;for(let e=0,s=t.length;e<s;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,s={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},s.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,s){return void 0===e[s.uuid]&&(e[s.uuid]=s.toJSON(t)),s.uuid}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),!0===this.castShadow&&(i.castShadow=!0),!0===this.receiveShadow&&(i.receiveShadow=!0),!1===this.visible&&(i.visible=!1),!1===this.frustumCulled&&(i.frustumCulled=!1),0!==this.renderOrder&&(i.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.visibility=this._visibility,i.active=this._active,i.bounds=this._bounds.map((t=>({boxInitialized:t.boxInitialized,boxMin:t.box.min.toArray(),boxMax:t.box.max.toArray(),sphereInitialized:t.sphereInitialized,sphereRadius:t.sphere.radius,sphereCenter:t.sphere.center.toArray()}))),i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.geometryCount=this._geometryCount,i.matricesTexture=this._matricesTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere={center:i.boundingSphere.center.toArray(),radius:i.boundingSphere.radius}),null!==this.boundingBox&&(i.boundingBox={min:i.boundingBox.min.toArray(),max:i.boundingBox.max.toArray()})),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const s=e.shapes;if(Array.isArray(s))for(let e=0,i=s.length;e<i;e++){const i=s[e];r(t.shapes,i)}else r(t.shapes,s)}}if(this.isSkinnedMesh&&(i.bindMode=this.bindMode,i.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(r(t.skeletons,this.skeleton),i.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let s=0,i=this.material.length;s<i;s++)e.push(r(t.materials,this.material[s]));i.material=e}else i.material=r(t.materials,this.material);if(this.children.length>0){i.children=[];for(let e=0;e<this.children.length;e++)i.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){i.animations=[];for(let e=0;e<this.animations.length;e++){const s=this.animations[e];i.animations.push(r(t.animations,s))}}if(e){const e=n(t.geometries),i=n(t.materials),r=n(t.textures),o=n(t.images),a=n(t.shapes),h=n(t.skeletons),u=n(t.animations),l=n(t.nodes);e.length>0&&(s.geometries=e),i.length>0&&(s.materials=i),r.length>0&&(s.textures=r),o.length>0&&(s.images=o),a.length>0&&(s.shapes=a),h.length>0&&(s.skeletons=h),u.length>0&&(s.animations=u),l.length>0&&(s.nodes=l)}return s.object=i,s;function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}}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)),!0===e)for(let e=0;e<t.children.length;e++){const s=t.children[e];this.add(s.clone())}return this}}Pr.DEFAULT_UP=new Ei(0,1,0),Pr.DEFAULT_MATRIX_AUTO_UPDATE=!0,Pr.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Fr=new Ei,Ur=new Ei,zr=new Ei,Or=new Ei,Lr=new Ei,Vr=new Ei,Dr=new Ei,kr=new Ei,Gr=new Ei,Wr=new Ei;class jr{constructor(t=new Ei,e=new Ei,s=new Ei){this.a=t,this.b=e,this.c=s}static getNormal(t,e,s,i){i.subVectors(s,e),Fr.subVectors(t,e),i.cross(Fr);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,s,i,r){Fr.subVectors(i,e),Ur.subVectors(s,e),zr.subVectors(t,e);const n=Fr.dot(Fr),o=Fr.dot(Ur),a=Fr.dot(zr),h=Ur.dot(Ur),u=Ur.dot(zr),l=n*h-o*o;if(0===l)return r.set(0,0,0),null;const c=1/l,d=(h*a-o*u)*c,p=(n*u-o*a)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,s,i){return null!==this.getBarycoord(t,e,s,i,Or)&&(Or.x>=0&&Or.y>=0&&Or.x+Or.y<=1)}static getInterpolation(t,e,s,i,r,n,o,a){return null===this.getBarycoord(t,e,s,i,Or)?(a.x=0,a.y=0,"z"in a&&(a.z=0),"w"in a&&(a.w=0),null):(a.setScalar(0),a.addScaledVector(r,Or.x),a.addScaledVector(n,Or.y),a.addScaledVector(o,Or.z),a)}static isFrontFacing(t,e,s,i){return Fr.subVectors(s,e),Ur.subVectors(t,e),Fr.cross(Ur).dot(i)<0}set(t,e,s){return this.a.copy(t),this.b.copy(e),this.c.copy(s),this}setFromPointsAndIndices(t,e,s,i){return this.a.copy(t[e]),this.b.copy(t[s]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,s,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,s),this.c.fromBufferAttribute(t,i),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 Fr.subVectors(this.c,this.b),Ur.subVectors(this.a,this.b),.5*Fr.cross(Ur).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return jr.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return jr.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,s,i,r){return jr.getInterpolation(t,this.a,this.b,this.c,e,s,i,r)}containsPoint(t){return jr.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return jr.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const s=this.a,i=this.b,r=this.c;let n,o;Lr.subVectors(i,s),Vr.subVectors(r,s),kr.subVectors(t,s);const a=Lr.dot(kr),h=Vr.dot(kr);if(a<=0&&h<=0)return e.copy(s);Gr.subVectors(t,i);const u=Lr.dot(Gr),l=Vr.dot(Gr);if(u>=0&&l<=u)return e.copy(i);const c=a*l-u*h;if(c<=0&&a>=0&&u<=0)return n=a/(a-u),e.copy(s).addScaledVector(Lr,n);Wr.subVectors(t,r);const d=Lr.dot(Wr),p=Vr.dot(Wr);if(p>=0&&d<=p)return e.copy(r);const m=d*h-a*p;if(m<=0&&h>=0&&p<=0)return o=h/(h-p),e.copy(s).addScaledVector(Vr,o);const g=u*p-d*l;if(g<=0&&l-u>=0&&d-p>=0)return Dr.subVectors(r,i),o=(l-u)/(l-u+(d-p)),e.copy(i).addScaledVector(Dr,o);const f=1/(g+m+c);return n=m*f,o=c*f,e.copy(s).addScaledVector(Lr,n).addScaledVector(Vr,o)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const Hr={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},qr={h:0,s:0,l:0},$r={h:0,s:0,l:0};function Xr(t,e,s){return s<0&&(s+=1),s>1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+6*(e-t)*(2/3-s):t}class Yr{constructor(t,e,s){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,s)}set(t,e,s){if(void 0===e&&void 0===s){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,s);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Je){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,di.toWorkingColorSpace(this,e),this}setRGB(t,e,s,i=di.workingColorSpace){return this.r=t,this.g=e,this.b=s,di.toWorkingColorSpace(this,i),this}setHSL(t,e,s,i=di.workingColorSpace){if(t=Xs(t,1),e=$s(e,0,1),s=$s(s,0,1),0===e)this.r=this.g=this.b=s;else{const i=s<=.5?s*(1+e):s+e-s*e,r=2*s-i;this.r=Xr(r,i,t+1/3),this.g=Xr(r,i,t),this.b=Xr(r,i,t-1/3)}return di.toWorkingColorSpace(this,i),this}setStyle(t,e=Je){function s(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const n=i[1],o=i[2];switch(n){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return s(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:console.warn("THREE.Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const s=i[1],r=s.length;if(3===r)return this.setRGB(parseInt(s.charAt(0),16)/15,parseInt(s.charAt(1),16)/15,parseInt(s.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(s,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=Je){const s=Hr[t.toLowerCase()];return void 0!==s?this.setHex(s,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=pi(t.r),this.g=pi(t.g),this.b=pi(t.b),this}copyLinearToSRGB(t){return this.r=mi(t.r),this.g=mi(t.g),this.b=mi(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Je){return di.fromWorkingColorSpace(Jr.copy(this),t),65536*Math.round($s(255*Jr.r,0,255))+256*Math.round($s(255*Jr.g,0,255))+Math.round($s(255*Jr.b,0,255))}getHexString(t=Je){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=di.workingColorSpace){di.fromWorkingColorSpace(Jr.copy(this),e);const s=Jr.r,i=Jr.g,r=Jr.b,n=Math.max(s,i,r),o=Math.min(s,i,r);let a,h;const u=(o+n)/2;if(o===n)a=0,h=0;else{const t=n-o;switch(h=u<=.5?t/(n+o):t/(2-n-o),n){case s:a=(i-r)/t+(i<r?6:0);break;case i:a=(r-s)/t+2;break;case r:a=(s-i)/t+4}a/=6}return t.h=a,t.s=h,t.l=u,t}getRGB(t,e=di.workingColorSpace){return di.fromWorkingColorSpace(Jr.copy(this),e),t.r=Jr.r,t.g=Jr.g,t.b=Jr.b,t}getStyle(t=Je){di.fromWorkingColorSpace(Jr.copy(this),t);const e=Jr.r,s=Jr.g,i=Jr.b;return t!==Je?`color(${t} ${e.toFixed(3)} ${s.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*s)},${Math.round(255*i)})`}offsetHSL(t,e,s){return this.getHSL(qr),this.setHSL(qr.h+t,qr.s+e,qr.l+s)}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,s){return this.r=t.r+(e.r-t.r)*s,this.g=t.g+(e.g-t.g)*s,this.b=t.b+(e.b-t.b)*s,this}lerpHSL(t,e){this.getHSL(qr),t.getHSL($r);const s=Ys(qr.h,$r.h,e),i=Ys(qr.s,$r.s,e),r=Ys(qr.l,$r.l,e);return this.setHSL(s,i,r),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,s=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*s+r[6]*i,this.g=r[1]*e+r[4]*s+r[7]*i,this.b=r[2]*e+r[5]*s+r[8]*i,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 Jr=new Yr;Yr.NAMES=Hr;let Zr=0;class Qr extends ks{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Zr++}),this.uuid=qs(),this.name="",this.type="Material",this.blending=1,this.side=c,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=C,this.blendDst=E,this.blendEquation=v,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Yr(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=bs,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=ns,this.stencilZFail=ns,this.stencilZPass=ns,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}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const s=t[e];if(void 0===s){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(s):i&&i.isVector3&&s&&s.isVector3?i.copy(s):this[e]=s:console.warn(`THREE.Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const s={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),this.color&&this.color.isColor&&(s.color=this.color.getHex()),void 0!==this.roughness&&(s.roughness=this.roughness),void 0!==this.metalness&&(s.metalness=this.metalness),void 0!==this.sheen&&(s.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(s.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(s.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(s.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(s.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(s.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(s.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(s.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(s.shininess=this.shininess),void 0!==this.clearcoat&&(s.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(s.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(s.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(s.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(s.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,s.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(s.dispersion=this.dispersion),void 0!==this.iridescence&&(s.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(s.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(s.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(s.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(s.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(s.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(s.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(s.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(s.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(s.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(s.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(s.lightMap=this.lightMap.toJSON(t).uuid,s.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(s.aoMap=this.aoMap.toJSON(t).uuid,s.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(s.bumpMap=this.bumpMap.toJSON(t).uuid,s.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(s.normalMap=this.normalMap.toJSON(t).uuid,s.normalMapType=this.normalMapType,s.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(s.displacementMap=this.displacementMap.toJSON(t).uuid,s.displacementScale=this.displacementScale,s.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(s.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(s.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(s.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(s.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(s.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(s.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(s.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(s.combine=this.combine)),void 0!==this.envMapRotation&&(s.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(s.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(s.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(s.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(s.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(s.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(s.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(s.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(s.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(s.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(s.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(s.size=this.size),null!==this.shadowSide&&(s.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(s.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(s.blending=this.blending),this.side!==c&&(s.side=this.side),!0===this.vertexColors&&(s.vertexColors=!0),this.opacity<1&&(s.opacity=this.opacity),!0===this.transparent&&(s.transparent=!0),this.blendSrc!==C&&(s.blendSrc=this.blendSrc),this.blendDst!==E&&(s.blendDst=this.blendDst),this.blendEquation!==v&&(s.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(s.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(s.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(s.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(s.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(s.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(s.depthFunc=this.depthFunc),!1===this.depthTest&&(s.depthTest=this.depthTest),!1===this.depthWrite&&(s.depthWrite=this.depthWrite),!1===this.colorWrite&&(s.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(s.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==bs&&(s.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(s.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(s.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==ns&&(s.stencilFail=this.stencilFail),this.stencilZFail!==ns&&(s.stencilZFail=this.stencilZFail),this.stencilZPass!==ns&&(s.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(s.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(s.rotation=this.rotation),!0===this.polygonOffset&&(s.polygonOffset=!0),0!==this.polygonOffsetFactor&&(s.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(s.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(s.linewidth=this.linewidth),void 0!==this.dashSize&&(s.dashSize=this.dashSize),void 0!==this.gapSize&&(s.gapSize=this.gapSize),void 0!==this.scale&&(s.scale=this.scale),!0===this.dithering&&(s.dithering=!0),this.alphaTest>0&&(s.alphaTest=this.alphaTest),!0===this.alphaHash&&(s.alphaHash=!0),!0===this.alphaToCoverage&&(s.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(s.premultipliedAlpha=!0),!0===this.forceSinglePass&&(s.forceSinglePass=!0),!0===this.wireframe&&(s.wireframe=!0),this.wireframeLinewidth>1&&(s.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(s.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(s.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(s.flatShading=!0),!1===this.visible&&(s.visible=!1),!1===this.toneMapped&&(s.toneMapped=!1),!1===this.fog&&(s.fog=!1),Object.keys(this.userData).length>0&&(s.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(s.textures=e),r.length>0&&(s.images=r)}return s}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 s=null;if(null!==e){const t=e.length;s=new Array(t);for(let i=0;i!==t;++i)s[i]=e[i].clone()}return this.clippingPlanes=s,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){!0===t&&this.version++}onBuild(){console.warn("Material: onBuild() has been removed.")}onBeforeRender(){console.warn("Material: onBeforeRender() has been removed.")}}class Kr extends Qr{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Yr(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 fr,this.combine=0,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 tn=en();function en(){const t=new ArrayBuffer(4),e=new Float32Array(t),s=new Uint32Array(t),i=new Uint32Array(512),r=new Uint32Array(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(i[t]=0,i[256|t]=32768,r[t]=24,r[256|t]=24):e<-14?(i[t]=1024>>-e-14,i[256|t]=1024>>-e-14|32768,r[t]=-e-1,r[256|t]=-e-1):e<=15?(i[t]=e+15<<10,i[256|t]=e+15<<10|32768,r[t]=13,r[256|t]=13):e<128?(i[t]=31744,i[256|t]=64512,r[t]=24,r[256|t]=24):(i[t]=31744,i[256|t]=64512,r[t]=13,r[256|t]=13)}const n=new Uint32Array(2048),o=new Uint32Array(64),a=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,s=0;for(;0==(8388608&e);)e<<=1,s-=8388608;e&=-8388609,s+=947912704,n[t]=e|s}for(let t=1024;t<2048;++t)n[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)o[t]=t<<23;o[31]=1199570944,o[32]=2147483648;for(let t=33;t<63;++t)o[t]=2147483648+(t-32<<23);o[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(a[t]=1024);return{floatView:e,uint32View:s,baseTable:i,shiftTable:r,mantissaTable:n,exponentTable:o,offsetTable:a}}function sn(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=$s(t,-65504,65504),tn.floatView[0]=t;const e=tn.uint32View[0],s=e>>23&511;return tn.baseTable[s]+((8388607&e)>>tn.shiftTable[s])}function rn(t){const e=t>>10;return tn.uint32View[0]=tn.mantissaTable[tn.offsetTable[e]+(1023&t)]+tn.exponentTable[e],tn.floatView[0]}const nn={toHalfFloat:sn,fromHalfFloat:rn},on=new Ei,an=new Ks;class hn{constructor(t,e,s=!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=void 0!==t?t.length/e:0,this.normalized=s,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=It,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}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,s){t*=this.itemSize,s*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[s+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,s=this.count;e<s;e++)an.fromBufferAttribute(this,e),an.applyMatrix3(t),this.setXY(e,an.x,an.y);else if(3===this.itemSize)for(let e=0,s=this.count;e<s;e++)on.fromBufferAttribute(this,e),on.applyMatrix3(t),this.setXYZ(e,on.x,on.y,on.z);return this}applyMatrix4(t){for(let e=0,s=this.count;e<s;e++)on.fromBufferAttribute(this,e),on.applyMatrix4(t),this.setXYZ(e,on.x,on.y,on.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)on.fromBufferAttribute(this,e),on.applyNormalMatrix(t),this.setXYZ(e,on.x,on.y,on.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)on.fromBufferAttribute(this,e),on.transformDirection(t),this.setXYZ(e,on.x,on.y,on.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let s=this.array[t*this.itemSize+e];return this.normalized&&(s=Js(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=Zs(s,this.array)),this.array[t*this.itemSize+e]=s,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=Js(e,this.array)),e}setX(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=Js(e,this.array)),e}setY(t,e){return this.normalized&&(e=Zs(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=Js(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Zs(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=Js(e,this.array)),e}setW(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array)),this.array[t+0]=e,this.array[t+1]=s,this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array),r=Zs(r,this.array)),this.array[t+0]=e,this.array[t+1]=s,this.array[t+2]=i,this.array[t+3]=r,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!==Rs&&(t.usage=this.usage),t}}class un extends hn{constructor(t,e,s){super(new Int8Array(t),e,s)}}class ln extends hn{constructor(t,e,s){super(new Uint8Array(t),e,s)}}class cn extends hn{constructor(t,e,s){super(new Uint8ClampedArray(t),e,s)}}class dn extends hn{constructor(t,e,s){super(new Int16Array(t),e,s)}}class pn extends hn{constructor(t,e,s){super(new Uint16Array(t),e,s)}}class mn extends hn{constructor(t,e,s){super(new Int32Array(t),e,s)}}class gn extends hn{constructor(t,e,s){super(new Uint32Array(t),e,s)}}class fn extends hn{constructor(t,e,s){super(new Uint16Array(t),e,s),this.isFloat16BufferAttribute=!0}getX(t){let e=rn(this.array[t*this.itemSize]);return this.normalized&&(e=Js(e,this.array)),e}setX(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize]=sn(e),this}getY(t){let e=rn(this.array[t*this.itemSize+1]);return this.normalized&&(e=Js(e,this.array)),e}setY(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize+1]=sn(e),this}getZ(t){let e=rn(this.array[t*this.itemSize+2]);return this.normalized&&(e=Js(e,this.array)),e}setZ(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize+2]=sn(e),this}getW(t){let e=rn(this.array[t*this.itemSize+3]);return this.normalized&&(e=Js(e,this.array)),e}setW(t,e){return this.normalized&&(e=Zs(e,this.array)),this.array[t*this.itemSize+3]=sn(e),this}setXY(t,e,s){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array)),this.array[t+0]=sn(e),this.array[t+1]=sn(s),this}setXYZ(t,e,s,i){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array)),this.array[t+0]=sn(e),this.array[t+1]=sn(s),this.array[t+2]=sn(i),this}setXYZW(t,e,s,i,r){return t*=this.itemSize,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array),r=Zs(r,this.array)),this.array[t+0]=sn(e),this.array[t+1]=sn(s),this.array[t+2]=sn(i),this.array[t+3]=sn(r),this}}class yn extends hn{constructor(t,e,s){super(new Float32Array(t),e,s)}}let xn=0;const bn=new or,vn=new Pr,Tn=new Ei,_n=new Pi,wn=new Pi,Sn=new Ei;class Mn extends ks{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:xn++}),this.uuid=qs(),this.name="",this.type="BufferGeometry",this.index=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(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(t)?gn:pn)(t,1):this.index=t,this}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 void 0!==this.attributes[t]}addGroup(t,e,s=0){this.groups.push({start:t,count:e,materialIndex:s})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const s=this.attributes.normal;if(void 0!==s){const e=(new ti).getNormalMatrix(t);s.applyNormalMatrix(e),s.needsUpdate=!0}const i=this.attributes.tangent;return void 0!==i&&(i.transformDirection(t),i.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return bn.makeRotationFromQuaternion(t),this.applyMatrix4(bn),this}rotateX(t){return bn.makeRotationX(t),this.applyMatrix4(bn),this}rotateY(t){return bn.makeRotationY(t),this.applyMatrix4(bn),this}rotateZ(t){return bn.makeRotationZ(t),this.applyMatrix4(bn),this}translate(t,e,s){return bn.makeTranslation(t,e,s),this.applyMatrix4(bn),this}scale(t,e,s){return bn.makeScale(t,e,s),this.applyMatrix4(bn),this}lookAt(t){return vn.lookAt(t),vn.updateMatrix(),this.applyMatrix4(vn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Tn).negate(),this.translate(Tn.x,Tn.y,Tn.z),this}setFromPoints(t){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s];e.push(i.x,i.y,i.z||0)}return this.setAttribute("position",new yn(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Ei(-1/0,-1/0,-1/0),new Ei(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];_n.setFromBufferAttribute(s),this.morphTargetsRelative?(Sn.addVectors(this.boundingBox.min,_n.min),this.boundingBox.expandByPoint(Sn),Sn.addVectors(this.boundingBox.max,_n.max),this.boundingBox.expandByPoint(Sn)):(this.boundingBox.expandByPoint(_n.min),this.boundingBox.expandByPoint(_n.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(){null===this.boundingSphere&&(this.boundingSphere=new Zi);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return console.error("THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.",this),void this.boundingSphere.set(new Ei,1/0);if(t){const s=this.boundingSphere.center;if(_n.setFromBufferAttribute(t),e)for(let t=0,s=e.length;t<s;t++){const s=e[t];wn.setFromBufferAttribute(s),this.morphTargetsRelative?(Sn.addVectors(_n.min,wn.min),_n.expandByPoint(Sn),Sn.addVectors(_n.max,wn.max),_n.expandByPoint(Sn)):(_n.expandByPoint(wn.min),_n.expandByPoint(wn.max))}_n.getCenter(s);let i=0;for(let e=0,r=t.count;e<r;e++)Sn.fromBufferAttribute(t,e),i=Math.max(i,s.distanceToSquared(Sn));if(e)for(let r=0,n=e.length;r<n;r++){const n=e[r],o=this.morphTargetsRelative;for(let e=0,r=n.count;e<r;e++)Sn.fromBufferAttribute(n,e),o&&(Tn.fromBufferAttribute(t,e),Sn.add(Tn)),i=Math.max(i,s.distanceToSquared(Sn))}this.boundingSphere.radius=Math.sqrt(i),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(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return void console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)");const s=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new hn(new Float32Array(4*s.count),4));const n=this.getAttribute("tangent"),o=[],a=[];for(let t=0;t<s.count;t++)o[t]=new Ei,a[t]=new Ei;const h=new Ei,u=new Ei,l=new Ei,c=new Ks,d=new Ks,p=new Ks,m=new Ei,g=new Ei;function f(t,e,i){h.fromBufferAttribute(s,t),u.fromBufferAttribute(s,e),l.fromBufferAttribute(s,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),u.sub(h),l.sub(h),d.sub(c),p.sub(c);const n=1/(d.x*p.y-p.x*d.y);isFinite(n)&&(m.copy(u).multiplyScalar(p.y).addScaledVector(l,-d.y).multiplyScalar(n),g.copy(l).multiplyScalar(d.x).addScaledVector(u,-p.x).multiplyScalar(n),o[t].add(m),o[e].add(m),o[i].add(m),a[t].add(g),a[e].add(g),a[i].add(g))}let y=this.groups;0===y.length&&(y=[{start:0,count:t.count}]);for(let e=0,s=y.length;e<s;++e){const s=y[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)f(t.getX(e+0),t.getX(e+1),t.getX(e+2))}const x=new Ei,b=new Ei,v=new Ei,T=new Ei;function _(t){v.fromBufferAttribute(i,t),T.copy(v);const e=o[t];x.copy(e),x.sub(v.multiplyScalar(v.dot(e))).normalize(),b.crossVectors(T,e);const s=b.dot(a[t])<0?-1:1;n.setXYZW(t,x.x,x.y,x.z,s)}for(let e=0,s=y.length;e<s;++e){const s=y[e],i=s.start;for(let e=i,r=i+s.count;e<r;e+=3)_(t.getX(e+0)),_(t.getX(e+1)),_(t.getX(e+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let s=this.getAttribute("normal");if(void 0===s)s=new hn(new Float32Array(3*e.count),3),this.setAttribute("normal",s);else for(let t=0,e=s.count;t<e;t++)s.setXYZ(t,0,0,0);const i=new Ei,r=new Ei,n=new Ei,o=new Ei,a=new Ei,h=new Ei,u=new Ei,l=new Ei;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),m=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),n.fromBufferAttribute(e,m),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),o.fromBufferAttribute(s,d),a.fromBufferAttribute(s,p),h.fromBufferAttribute(s,m),o.add(u),a.add(u),h.add(u),s.setXYZ(d,o.x,o.y,o.z),s.setXYZ(p,a.x,a.y,a.z),s.setXYZ(m,h.x,h.y,h.z)}else for(let t=0,o=e.count;t<o;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),n.fromBufferAttribute(e,t+2),u.subVectors(n,r),l.subVectors(i,r),u.cross(l),s.setXYZ(t+0,u.x,u.y,u.z),s.setXYZ(t+1,u.x,u.y,u.z),s.setXYZ(t+2,u.x,u.y,u.z);this.normalizeNormals(),s.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,s=t.count;e<s;e++)Sn.fromBufferAttribute(t,e),Sn.normalize(),t.setXYZ(e,Sn.x,Sn.y,Sn.z)}toNonIndexed(){function t(t,e){const s=t.array,i=t.itemSize,r=t.normalized,n=new s.constructor(e.length*i);let o=0,a=0;for(let r=0,h=e.length;r<h;r++){o=t.isInterleavedBufferAttribute?e[r]*t.data.stride+t.offset:e[r]*i;for(let t=0;t<i;t++)n[a++]=s[o++]}return new hn(n,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Mn,s=this.index.array,i=this.attributes;for(const r in i){const n=t(i[r],s);e.setAttribute(r,n)}const r=this.morphAttributes;for(const i in r){const n=[],o=r[i];for(let e=0,i=o.length;e<i;e++){const i=t(o[e],s);n.push(i)}e.morphAttributes[i]=n}e.morphTargetsRelative=this.morphTargetsRelative;const n=this.groups;for(let t=0,s=n.length;t<s;t++){const s=n[t];e.addGroup(s.start,s.count,s.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),void 0!==this.parameters){const e=this.parameters;for(const s in e)void 0!==e[s]&&(t[s]=e[s]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const s=this.attributes;for(const e in s){const i=s[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const s=this.morphAttributes[e],n=[];for(let e=0,i=s.length;e<i;e++){const i=s[e];n.push(i.toJSON(t.data))}n.length>0&&(i[e]=n,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const n=this.groups;n.length>0&&(t.data.groups=JSON.parse(JSON.stringify(n)));const o=this.boundingSphere;return null!==o&&(t.data.boundingSphere={center:o.center.toArray(),radius:o.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 s=t.index;null!==s&&this.setIndex(s.clone(e));const i=t.attributes;for(const t in i){const s=i[t];this.setAttribute(t,s.clone(e))}const r=t.morphAttributes;for(const t in r){const s=[],i=r[t];for(let t=0,r=i.length;t<r;t++)s.push(i[t].clone(e));this.morphAttributes[t]=s}this.morphTargetsRelative=t.morphTargetsRelative;const n=t.groups;for(let t=0,e=n.length;t<e;t++){const e=n[t];this.addGroup(e.start,e.count,e.materialIndex)}const o=t.boundingBox;null!==o&&(this.boundingBox=o.clone());const a=t.boundingSphere;return null!==a&&(this.boundingSphere=a.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const An=new or,Nn=new nr,Rn=new Zi,Cn=new Ei,En=new Ei,Bn=new Ei,In=new Ei,Pn=new Ei,Fn=new Ei,Un=new Ks,zn=new Ks,On=new Ks,Ln=new Ei,Vn=new Ei,Dn=new Ei,kn=new Ei,Gn=new Ei;class Wn extends Pr{constructor(t=new Mn,e=new Kr){super(),this.isMesh=!0,this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const s=this.geometry,i=s.attributes.position,r=s.morphAttributes.position,n=s.morphTargetsRelative;e.fromBufferAttribute(i,t);const o=this.morphTargetInfluences;if(r&&o){Fn.set(0,0,0);for(let s=0,i=r.length;s<i;s++){const i=o[s],a=r[s];0!==i&&(Pn.fromBufferAttribute(a,t),n?Fn.addScaledVector(Pn,i):Fn.addScaledVector(Pn.sub(e),i))}e.add(Fn)}return e}raycast(t,e){const s=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===s.boundingSphere&&s.computeBoundingSphere(),Rn.copy(s.boundingSphere),Rn.applyMatrix4(r),Nn.copy(t.ray).recast(t.near),!1===Rn.containsPoint(Nn.origin)){if(null===Nn.intersectSphere(Rn,Cn))return;if(Nn.origin.distanceToSquared(Cn)>(t.far-t.near)**2)return}An.copy(r).invert(),Nn.copy(t.ray).applyMatrix4(An),null!==s.boundingBox&&!1===Nn.intersectsBox(s.boundingBox)||this._computeIntersections(t,e,Nn)}}_computeIntersections(t,e,s){let i;const r=this.geometry,n=this.material,o=r.index,a=r.attributes.position,h=r.attributes.uv,u=r.attributes.uv1,l=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==o)if(Array.isArray(n))for(let r=0,a=c.length;r<a;r++){const a=c[r],p=n[a.materialIndex];for(let r=Math.max(a.start,d.start),n=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<n;r+=3){i=jn(this,p,t,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=a.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),a=Math.min(o.count,d.start+d.count);r<a;r+=3){i=jn(this,n,t,s,h,u,l,o.getX(r),o.getX(r+1),o.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==a)if(Array.isArray(n))for(let r=0,o=c.length;r<o;r++){const o=c[r],p=n[o.materialIndex];for(let r=Math.max(o.start,d.start),n=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<n;r+=3){i=jn(this,p,t,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),i.face.materialIndex=o.materialIndex,e.push(i))}}else{for(let r=Math.max(0,d.start),o=Math.min(a.count,d.start+d.count);r<o;r+=3){i=jn(this,n,t,s,h,u,l,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function jn(t,e,s,i,r,n,o,a,h,u){t.getVertexPosition(a,En),t.getVertexPosition(h,Bn),t.getVertexPosition(u,In);const l=function(t,e,s,i,r,n,o,a){let h;if(h=e.side===d?i.intersectTriangle(o,n,r,!0,a):i.intersectTriangle(r,n,o,e.side===c,a),null===h)return null;Gn.copy(a),Gn.applyMatrix4(t.matrixWorld);const u=s.ray.origin.distanceTo(Gn);return u<s.near||u>s.far?null:{distance:u,point:Gn.clone(),object:t}}(t,e,s,i,En,Bn,In,kn);if(l){r&&(Un.fromBufferAttribute(r,a),zn.fromBufferAttribute(r,h),On.fromBufferAttribute(r,u),l.uv=jr.getInterpolation(kn,En,Bn,In,Un,zn,On,new Ks)),n&&(Un.fromBufferAttribute(n,a),zn.fromBufferAttribute(n,h),On.fromBufferAttribute(n,u),l.uv1=jr.getInterpolation(kn,En,Bn,In,Un,zn,On,new Ks)),o&&(Ln.fromBufferAttribute(o,a),Vn.fromBufferAttribute(o,h),Dn.fromBufferAttribute(o,u),l.normal=jr.getInterpolation(kn,En,Bn,In,Ln,Vn,Dn,new Ei),l.normal.dot(i.direction)>0&&l.normal.multiplyScalar(-1));const t={a:a,b:h,c:u,normal:new Ei,materialIndex:0};jr.getNormal(En,Bn,In,t.normal),l.face=t}return l}class Hn extends Mn{constructor(t=1,e=1,s=1,i=1,r=1,n=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:s,widthSegments:i,heightSegments:r,depthSegments:n};const o=this;i=Math.floor(i),r=Math.floor(r),n=Math.floor(n);const a=[],h=[],u=[],l=[];let c=0,d=0;function p(t,e,s,i,r,n,p,m,g,f,y){const x=n/g,b=p/f,v=n/2,T=p/2,_=m/2,w=g+1,S=f+1;let M=0,A=0;const N=new Ei;for(let n=0;n<S;n++){const o=n*b-T;for(let a=0;a<w;a++){const c=a*x-v;N[t]=c*i,N[e]=o*r,N[s]=_,h.push(N.x,N.y,N.z),N[t]=0,N[e]=0,N[s]=m>0?1:-1,u.push(N.x,N.y,N.z),l.push(a/g),l.push(1-n/f),M+=1}}for(let t=0;t<f;t++)for(let e=0;e<g;e++){const s=c+e+w*t,i=c+e+w*(t+1),r=c+(e+1)+w*(t+1),n=c+(e+1)+w*t;a.push(s,i,n),a.push(i,r,n),A+=6}o.addGroup(d,A,y),d+=A,c+=M}p("z","y","x",-1,-1,s,e,t,n,r,0),p("z","y","x",1,-1,s,e,-t,n,r,1),p("x","z","y",1,1,t,s,e,i,n,2),p("x","z","y",1,-1,t,s,-e,i,n,3),p("x","y","z",1,-1,t,e,s,i,r,4),p("x","y","z",-1,-1,t,e,-s,i,r,5),this.setIndex(a),this.setAttribute("position",new yn(h,3)),this.setAttribute("normal",new yn(u,3)),this.setAttribute("uv",new yn(l,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Hn(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function qn(t){const e={};for(const s in t){e[s]={};for(const i in t[s]){const r=t[s][i];r&&(r.isColor||r.isMatrix3||r.isMatrix4||r.isVector2||r.isVector3||r.isVector4||r.isTexture||r.isQuaternion)?r.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),e[s][i]=null):e[s][i]=r.clone():Array.isArray(r)?e[s][i]=r.slice():e[s][i]=r}}return e}class $n extends Qr{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader="\nvoid main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n",this.fragmentShader="\nvoid main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}\n",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,void 0!==t&&this.setValues(t)}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=qn(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let s=0;s<t.length;s++)e.push(t[s].clone());return e}(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 i=this.uniforms[s].value;i&&i.isTexture?e.uniforms[s]={type:"t",value:i.toJSON(t).uuid}:i&&i.isColor?e.uniforms[s]={type:"c",value:i.getHex()}:i&&i.isVector2?e.uniforms[s]={type:"v2",value:i.toArray()}:i&&i.isVector3?e.uniforms[s]={type:"v3",value:i.toArray()}:i&&i.isVector4?e.uniforms[s]={type:"v4",value:i.toArray()}:i&&i.isMatrix3?e.uniforms[s]={type:"m3",value:i.toArray()}:i&&i.isMatrix4?e.uniforms[s]={type:"m4",value:i.toArray()}:e.uniforms[s]={value:i}}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 s={};for(const t in this.extensions)!0===this.extensions[t]&&(s[t]=!0);return Object.keys(s).length>0&&(e.extensions=s),e}}class Xn extends Pr{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new or,this.projectionMatrix=new or,this.projectionMatrixInverse=new or,this.coordinateSystem=Vs}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 Yn=new Ei,Jn=new Ks,Zn=new Ks;class Qn extends Xn{constructor(t=50,e=1,s=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=s,this.far=i,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=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Hs*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*js*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Hs*Math.atan(Math.tan(.5*js*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,s){Yn.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z),Yn.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),s.set(Yn.x,Yn.y).multiplyScalar(-t/Yn.z)}getViewSize(t,e){return this.getViewBounds(t,Jn,Zn),e.subVectors(Zn,Jn)}setViewOffset(t,e,s,i,r,n){this.aspect=t/e,null===this.view&&(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=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*js*this.fov)/this.zoom,s=2*e,i=this.aspect*s,r=-.5*i;const n=this.view;if(null!==this.view&&this.view.enabled){const t=n.fullWidth,o=n.fullHeight;r+=n.offsetX*i/t,e-=n.offsetY*s/o,i*=n.width/t,s*=n.height/o}const o=this.filmOffset;0!==o&&(r+=t*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-s,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,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const Kn=-90;class to extends Pr{constructor(t,e,s){super(),this.type="CubeCamera",this.renderTarget=s,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Qn(Kn,1,t,e);i.layers=this.layers,this.add(i);const r=new Qn(Kn,1,t,e);r.layers=this.layers,this.add(r);const n=new Qn(Kn,1,t,e);n.layers=this.layers,this.add(n);const o=new Qn(Kn,1,t,e);o.layers=this.layers,this.add(o);const a=new Qn(Kn,1,t,e);a.layers=this.layers,this.add(a);const h=new Qn(Kn,1,t,e);h.layers=this.layers,this.add(h)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[s,i,r,n,o,a]=e;for(const t of e)this.remove(t);if(t===Vs)s.up.set(0,1,0),s.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),n.up.set(0,0,1),n.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),a.up.set(0,1,0),a.lookAt(0,0,-1);else{if(t!==Ds)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);s.up.set(0,-1,0),s.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),n.up.set(0,0,-1),n.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),a.up.set(0,-1,0),a.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:s,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,n,o,a,h,u]=this.children,l=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const m=s.texture.generateMipmaps;s.texture.generateMipmaps=!1,t.setRenderTarget(s,0,i),t.render(e,r),t.setRenderTarget(s,1,i),t.render(e,n),t.setRenderTarget(s,2,i),t.render(e,o),t.setRenderTarget(s,3,i),t.render(e,a),t.setRenderTarget(s,4,i),t.render(e,h),s.texture.generateMipmaps=m,t.setRenderTarget(s,5,i),t.render(e,u),t.setRenderTarget(l,c,d),t.xr.enabled=p,s.texture.needsPMREMUpdate=!0}}class eo extends Ti{constructor(t,e,s,i,r,n,o,a,h,u){super(t=void 0!==t?t:[],e=void 0!==e?e:ht,s,i,r,n,o,a,h,u),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class so extends Si{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const s={width:t,height:t,depth:1},i=[s,s,s,s,s,s];this.texture=new eo(i,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=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Tt}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 s={uniforms:{tEquirect:{value:null}},vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t"},i=new Hn(5,5,5),r=new $n({name:"CubemapFromEquirect",uniforms:qn(s.uniforms),vertexShader:s.vertexShader,fragmentShader:s.fragmentShader,side:d,blending:m});r.uniforms.tEquirect.value=e;const n=new Wn(i,r),o=e.minFilter;e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,n),e.minFilter=o,n.geometry.dispose(),n.material.dispose(),this}clear(t,e,s,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,s,i);t.setRenderTarget(r)}}class io{constructor(t,e=25e-5){this.isFogExp2=!0,this.name="",this.color=new Yr(t),this.density=e}clone(){return new io(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class ro{constructor(t,e=1,s=1e3){this.isFog=!0,this.name="",this.color=new Yr(t),this.near=e,this.far=s}clone(){return new ro(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class no extends Pr{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 fr,this.environmentIntensity=1,this.environmentRotation=new fr,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(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),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class oo{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Rs,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.version=0,this.uuid=qs()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}get updateRange(){return ai("THREE.InterleavedBuffer: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}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,s){t*=this.stride,s*=e.stride;for(let i=0,r=this.stride;i<r;i++)this.array[t+i]=e.array[s+i];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=qs()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),s=new this.constructor(e,this.stride);return s.setUsage(this.usage),s}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=qs()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(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 ao=new Ei;class ho{constructor(t,e,s,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=s,this.normalized=i}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,s=this.data.count;e<s;e++)ao.fromBufferAttribute(this,e),ao.applyMatrix4(t),this.setXYZ(e,ao.x,ao.y,ao.z);return this}applyNormalMatrix(t){for(let e=0,s=this.count;e<s;e++)ao.fromBufferAttribute(this,e),ao.applyNormalMatrix(t),this.setXYZ(e,ao.x,ao.y,ao.z);return this}transformDirection(t){for(let e=0,s=this.count;e<s;e++)ao.fromBufferAttribute(this,e),ao.transformDirection(t),this.setXYZ(e,ao.x,ao.y,ao.z);return this}getComponent(t,e){let s=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(s=Js(s,this.array)),s}setComponent(t,e,s){return this.normalized&&(s=Zs(s,this.array)),this.data.array[t*this.data.stride+this.offset+e]=s,this}setX(t,e){return this.normalized&&(e=Zs(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=Zs(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=Zs(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=Zs(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=Js(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=Js(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=Js(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=Js(e,this.array)),e}setXY(t,e,s){return t=t*this.data.stride+this.offset,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this}setXYZ(t,e,s,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=i,this}setXYZW(t,e,s,i,r){return t=t*this.data.stride+this.offset,this.normalized&&(e=Zs(e,this.array),s=Zs(s,this.array),i=Zs(i,this.array),r=Zs(r,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=s,this.data.array[t+2]=i,this.data.array[t+3]=r,this}clone(t){if(void 0===t){console.log("THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let e=0;e<this.count;e++){const s=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[s+e])}return new hn(new this.array.constructor(t),this.itemSize,this.normalized)}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new ho(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(void 0===t){console.log("THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.");const t=[];for(let e=0;e<this.count;e++){const s=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[s+e])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(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 uo extends Qr{constructor(t){super(),this.isSpriteMaterial=!0,this.type="SpriteMaterial",this.color=new Yr(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 lo;const co=new Ei,po=new Ei,mo=new Ei,go=new Ks,fo=new Ks,yo=new or,xo=new Ei,bo=new Ei,vo=new Ei,To=new Ks,_o=new Ks,wo=new Ks;class So extends Pr{constructor(t=new uo){if(super(),this.isSprite=!0,this.type="Sprite",void 0===lo){lo=new Mn;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),e=new oo(t,5);lo.setIndex([0,1,2,0,2,3]),lo.setAttribute("position",new ho(e,3,0,!1)),lo.setAttribute("uv",new ho(e,2,3,!1))}this.geometry=lo,this.material=t,this.center=new Ks(.5,.5)}raycast(t,e){null===t.camera&&console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.'),po.setFromMatrixScale(this.matrixWorld),yo.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),mo.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&po.multiplyScalar(-mo.z);const s=this.material.rotation;let i,r;0!==s&&(r=Math.cos(s),i=Math.sin(s));const n=this.center;Mo(xo.set(-.5,-.5,0),mo,n,po,i,r),Mo(bo.set(.5,-.5,0),mo,n,po,i,r),Mo(vo.set(.5,.5,0),mo,n,po,i,r),To.set(0,0),_o.set(1,0),wo.set(1,1);let o=t.ray.intersectTriangle(xo,bo,vo,!1,co);if(null===o&&(Mo(bo.set(-.5,.5,0),mo,n,po,i,r),_o.set(0,1),o=t.ray.intersectTriangle(xo,vo,bo,!1,co),null===o))return;const a=t.ray.origin.distanceTo(co);a<t.near||a>t.far||e.push({distance:a,point:co.clone(),uv:jr.getInterpolation(co,xo,bo,vo,To,_o,wo,new Ks),face:null,object:this})}copy(t,e){return super.copy(t,e),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}function Mo(t,e,s,i,r,n){go.subVectors(t,s).addScalar(.5).multiply(i),void 0!==r?(fo.x=n*go.x-r*go.y,fo.y=r*go.x+n*go.y):fo.copy(go),t.copy(e),t.x+=fo.x,t.y+=fo.y,t.applyMatrix4(yo)}const Ao=new Ei,No=new Ei;class Ro extends Pr{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 t=0,s=e.length;t<s;t++){const s=e[t];this.addLevel(s.object.clone(),s.distance,s.hysteresis)}return this.autoUpdate=t.autoUpdate,this}addLevel(t,e=0,s=0){e=Math.abs(e);const i=this.levels;let r;for(r=0;r<i.length&&!(e<i[r].distance);r++);return i.splice(r,0,{distance:e,hysteresis:s,object:t}),this.add(t),this}getCurrentLevel(){return this._currentLevel}getObjectForDistance(t){const e=this.levels;if(e.length>0){let s,i;for(s=1,i=e.length;s<i;s++){let i=e[s].distance;if(e[s].object.visible&&(i-=i*e[s].hysteresis),t<i)break}return e[s-1].object}return null}raycast(t,e){if(this.levels.length>0){Ao.setFromMatrixPosition(this.matrixWorld);const s=t.ray.origin.distanceTo(Ao);this.getObjectForDistance(s).raycast(t,e)}}update(t){const e=this.levels;if(e.length>1){Ao.setFromMatrixPosition(t.matrixWorld),No.setFromMatrixPosition(this.matrixWorld);const s=Ao.distanceTo(No)/t.zoom;let i,r;for(e[0].object.visible=!0,i=1,r=e.length;i<r;i++){let t=e[i].distance;if(e[i].object.visible&&(t-=t*e[i].hysteresis),!(s>=t))break;e[i-1].object.visible=!1,e[i].object.visible=!0}for(this._currentLevel=i-1;i<r;i++)e[i].object.visible=!1}}toJSON(t){const e=super.toJSON(t);!1===this.autoUpdate&&(e.object.autoUpdate=!1),e.object.levels=[];const s=this.levels;for(let t=0,i=s.length;t<i;t++){const i=s[t];e.object.levels.push({object:i.object.uuid,distance:i.distance,hysteresis:i.hysteresis})}return e}}const Co=new Ei,Eo=new _i,Bo=new _i,Io=new Ei,Po=new or,Fo=new Ei,Uo=new Zi,zo=new or,Oo=new nr;class Lo extends Wn{constructor(t,e){super(t,e),this.isSkinnedMesh=!0,this.type="SkinnedMesh",this.bindMode=nt,this.bindMatrix=new or,this.bindMatrixInverse=new or,this.boundingBox=null,this.boundingSphere=null}computeBoundingBox(){const t=this.geometry;null===this.boundingBox&&(this.boundingBox=new Pi),this.boundingBox.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,Fo),this.boundingBox.expandByPoint(Fo)}computeBoundingSphere(){const t=this.geometry;null===this.boundingSphere&&(this.boundingSphere=new Zi),this.boundingSphere.makeEmpty();const e=t.getAttribute("position");for(let t=0;t<e.count;t++)this.getVertexPosition(t,Fo),this.boundingSphere.expandByPoint(Fo)}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,null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this}raycast(t,e){const s=this.material,i=this.matrixWorld;void 0!==s&&(null===this.boundingSphere&&this.computeBoundingSphere(),Uo.copy(this.boundingSphere),Uo.applyMatrix4(i),!1!==t.ray.intersectsSphere(Uo)&&(zo.copy(i).invert(),Oo.copy(t.ray).applyMatrix4(zo),null!==this.boundingBox&&!1===Oo.intersectsBox(this.boundingBox)||this._computeIntersections(t,e,Oo)))}getVertexPosition(t,e){return super.getVertexPosition(t,e),this.applyBoneTransform(t,e),e}bind(t,e){this.skeleton=t,void 0===e&&(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 _i,e=this.geometry.attributes.skinWeight;for(let s=0,i=e.count;s<i;s++){t.fromBufferAttribute(e,s);const i=1/t.manhattanLength();i!==1/0?t.multiplyScalar(i):t.set(1,0,0,0),e.setXYZW(s,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),this.bindMode===nt?this.bindMatrixInverse.copy(this.matrixWorld).invert():this.bindMode===ot?this.bindMatrixInverse.copy(this.bindMatrix).invert():console.warn("THREE.SkinnedMesh: Unrecognized bindMode: "+this.bindMode)}applyBoneTransform(t,e){const s=this.skeleton,i=this.geometry;Eo.fromBufferAttribute(i.attributes.skinIndex,t),Bo.fromBufferAttribute(i.attributes.skinWeight,t),Co.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const i=Bo.getComponent(t);if(0!==i){const r=Eo.getComponent(t);Po.multiplyMatrices(s.bones[r].matrixWorld,s.boneInverses[r]),e.addScaledVector(Io.copy(Co).applyMatrix4(Po),i)}}return e.applyMatrix4(this.bindMatrixInverse)}}class Vo extends Pr{constructor(){super(),this.isBone=!0,this.type="Bone"}}class Do extends Ti{constructor(t=null,e=1,s=1,i,r,n,o,a,h=1003,u=1003,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isDataTexture=!0,this.image={data:t,width:e,height:s},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const ko=new or,Go=new or;class Wo{constructor(t=[],e=[]){this.uuid=qs(),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(16*t.length),0===e.length)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 t=0,e=this.bones.length;t<e;t++)this.boneInverses.push(new or)}}calculateInverses(){this.boneInverses.length=0;for(let t=0,e=this.bones.length;t<e;t++){const e=new or;this.bones[t]&&e.copy(this.bones[t].matrixWorld).invert(),this.boneInverses.push(e)}}pose(){for(let t=0,e=this.bones.length;t<e;t++){const e=this.bones[t];e&&e.matrixWorld.copy(this.boneInverses[t]).invert()}for(let t=0,e=this.bones.length;t<e;t++){const e=this.bones[t];e&&(e.parent&&e.parent.isBone?(e.matrix.copy(e.parent.matrixWorld).invert(),e.matrix.multiply(e.matrixWorld)):e.matrix.copy(e.matrixWorld),e.matrix.decompose(e.position,e.quaternion,e.scale))}}update(){const t=this.bones,e=this.boneInverses,s=this.boneMatrices,i=this.boneTexture;for(let i=0,r=t.length;i<r;i++){const r=t[i]?t[i].matrixWorld:Go;ko.multiplyMatrices(r,e[i]),ko.toArray(s,16*i)}null!==i&&(i.needsUpdate=!0)}clone(){return new Wo(this.bones,this.boneInverses)}computeBoneTexture(){let t=Math.sqrt(4*this.bones.length);t=4*Math.ceil(t/4),t=Math.max(t,4);const e=new Float32Array(t*t*4);e.set(this.boneMatrices);const s=new Do(e,t,t,Dt,It);return s.needsUpdate=!0,this.boneMatrices=e,this.boneTexture=s,this}getBoneByName(t){for(let e=0,s=this.bones.length;e<s;e++){const s=this.bones[e];if(s.name===t)return s}}dispose(){null!==this.boneTexture&&(this.boneTexture.dispose(),this.boneTexture=null)}fromJSON(t,e){this.uuid=t.uuid;for(let s=0,i=t.bones.length;s<i;s++){const i=t.bones[s];let r=e[i];void 0===r&&(console.warn("THREE.Skeleton: No bone found with UUID:",i),r=new Vo),this.bones.push(r),this.boneInverses.push((new or).fromArray(t.boneInverses[s]))}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,s=this.boneInverses;for(let i=0,r=e.length;i<r;i++){const r=e[i];t.bones.push(r.uuid);const n=s[i];t.boneInverses.push(n.toArray())}return t}}class jo extends hn{constructor(t,e,s,i=1){super(t,e,s),this.isInstancedBufferAttribute=!0,this.meshPerAttribute=i}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 Ho=new or,qo=new or,$o=[],Xo=new Pi,Yo=new or,Jo=new Wn,Zo=new Zi;class Qo extends Wn{constructor(t,e,s){super(t,e),this.isInstancedMesh=!0,this.instanceMatrix=new jo(new Float32Array(16*s),16),this.instanceColor=null,this.morphTexture=null,this.count=s,this.boundingBox=null,this.boundingSphere=null;for(let t=0;t<s;t++)this.setMatrixAt(t,Yo)}computeBoundingBox(){const t=this.geometry,e=this.count;null===this.boundingBox&&(this.boundingBox=new Pi),null===t.boundingBox&&t.computeBoundingBox(),this.boundingBox.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Ho),Xo.copy(t.boundingBox).applyMatrix4(Ho),this.boundingBox.union(Xo)}computeBoundingSphere(){const t=this.geometry,e=this.count;null===this.boundingSphere&&(this.boundingSphere=new Zi),null===t.boundingSphere&&t.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let s=0;s<e;s++)this.getMatrixAt(s,Ho),Zo.copy(t.boundingSphere).applyMatrix4(Ho),this.boundingSphere.union(Zo)}copy(t,e){return super.copy(t,e),this.instanceMatrix.copy(t.instanceMatrix),null!==t.morphTexture&&(this.morphTexture=t.morphTexture.clone()),null!==t.instanceColor&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this}getColorAt(t,e){e.fromArray(this.instanceColor.array,3*t)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,16*t)}getMorphAt(t,e){const s=e.morphTargetInfluences,i=this.morphTexture.source.data.data,r=t*(s.length+1)+1;for(let t=0;t<s.length;t++)s[t]=i[r+t]}raycast(t,e){const s=this.matrixWorld,i=this.count;if(Jo.geometry=this.geometry,Jo.material=this.material,void 0!==Jo.material&&(null===this.boundingSphere&&this.computeBoundingSphere(),Zo.copy(this.boundingSphere),Zo.applyMatrix4(s),!1!==t.ray.intersectsSphere(Zo)))for(let r=0;r<i;r++){this.getMatrixAt(r,Ho),qo.multiplyMatrices(s,Ho),Jo.matrixWorld=qo,Jo.raycast(t,$o);for(let t=0,s=$o.length;t<s;t++){const s=$o[t];s.instanceId=r,s.object=this,e.push(s)}$o.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new jo(new Float32Array(3*this.instanceMatrix.count).fill(1),3)),e.toArray(this.instanceColor.array,3*t)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,16*t)}setMorphAt(t,e){const s=e.morphTargetInfluences,i=s.length+1;null===this.morphTexture&&(this.morphTexture=new Do(new Float32Array(i*this.count),i,this.count,Ht,It));const r=this.morphTexture.source.data.data;let n=0;for(let t=0;t<s.length;t++)n+=s[t];const o=this.geometry.morphTargetsRelative?1:1-n,a=i*t;r[a]=o,r.set(s,a+1)}updateMorphTargets(){}dispose(){return this.dispatchEvent({type:"dispose"}),null!==this.morphTexture&&(this.morphTexture.dispose(),this.morphTexture=null),this}}const Ko=new Ei,ta=new Ei,ea=new ti;class sa{constructor(t=new Ei(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,s,i){return this.normal.set(t,e,s),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,s){const i=Ko.subVectors(s,e).cross(ta.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,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 s=t.delta(Ko),i=this.normal.dot(s);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(s,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),s=this.distanceToPoint(t.end);return e<0&&s>0||s<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 s=e||ea.getNormalMatrix(t),i=this.coplanarPoint(Ko).applyMatrix4(t),r=this.normal.applyMatrix3(s).normalize();return this.constant=-i.dot(r),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 ia=new Zi,ra=new Ei;class na{constructor(t=new sa,e=new sa,s=new sa,i=new sa,r=new sa,n=new sa){this.planes=[t,e,s,i,r,n]}set(t,e,s,i,r,n){const o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(s),o[3].copy(i),o[4].copy(r),o[5].copy(n),this}copy(t){const e=this.planes;for(let s=0;s<6;s++)e[s].copy(t.planes[s]);return this}setFromProjectionMatrix(t,e=2e3){const s=this.planes,i=t.elements,r=i[0],n=i[1],o=i[2],a=i[3],h=i[4],u=i[5],l=i[6],c=i[7],d=i[8],p=i[9],m=i[10],g=i[11],f=i[12],y=i[13],x=i[14],b=i[15];if(s[0].setComponents(a-r,c-h,g-d,b-f).normalize(),s[1].setComponents(a+r,c+h,g+d,b+f).normalize(),s[2].setComponents(a+n,c+u,g+p,b+y).normalize(),s[3].setComponents(a-n,c-u,g-p,b-y).normalize(),s[4].setComponents(a-o,c-l,g-m,b-x).normalize(),e===Vs)s[5].setComponents(a+o,c+l,g+m,b+x).normalize();else{if(e!==Ds)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);s[5].setComponents(o,l,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),ia.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),ia.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(ia)}intersectsSprite(t){return ia.center.set(0,0,0),ia.radius=.7071067811865476,ia.applyMatrix4(t.matrixWorld),this.intersectsSphere(ia)}intersectsSphere(t){const e=this.planes,s=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(s)<i)return!1}return!0}intersectsBox(t){const e=this.planes;for(let s=0;s<6;s++){const i=e[s];if(ra.x=i.normal.x>0?t.max.x:t.min.x,ra.y=i.normal.y>0?t.max.y:t.min.y,ra.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(ra)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let s=0;s<6;s++)if(e[s].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function oa(t,e){return t.z-e.z}function aa(t,e){return e.z-t.z}class ha{constructor(){this.index=0,this.pool=[],this.list=[]}push(t,e,s){const i=this.pool,r=this.list;this.index>=i.length&&i.push({start:-1,count:-1,z:-1,index:-1});const n=i[this.index];r.push(n),this.index++,n.start=t.start,n.count=t.count,n.z=e,n.index=s}reset(){this.list.length=0,this.index=0}}const ua=new or,la=new or,ca=new or,da=new Yr(1,1,1),pa=new or,ma=new na,ga=new Pi,fa=new Zi,ya=new Ei,xa=new Ei,ba=new Ei,va=new ha,Ta=new Wn,_a=[];function wa(t,e,s=0){const i=e.itemSize;if(t.isInterleavedBufferAttribute||t.array.constructor!==e.array.constructor){const r=t.count;for(let n=0;n<r;n++)for(let r=0;r<i;r++)e.setComponent(n+s,r,t.getComponent(n,r))}else e.array.set(t.array,s*i);e.needsUpdate=!0}class Sa extends Wn{get maxInstanceCount(){return this._maxInstanceCount}constructor(t,e,s=2*e,i){super(new Mn,i),this.isBatchedMesh=!0,this.perObjectFrustumCulled=!0,this.sortObjects=!0,this.boundingBox=null,this.boundingSphere=null,this.customSort=null,this._drawInfo=[],this._drawRanges=[],this._reservedRanges=[],this._bounds=[],this._maxInstanceCount=t,this._maxVertexCount=e,this._maxIndexCount=s,this._geometryInitialized=!1,this._geometryCount=0,this._multiDrawCounts=new Int32Array(t),this._multiDrawStarts=new Int32Array(t),this._multiDrawCount=0,this._multiDrawInstances=null,this._visibilityChanged=!0,this._matricesTexture=null,this._indirectTexture=null,this._colorsTexture=null,this._initMatricesTexture(),this._initIndirectTexture()}_initMatricesTexture(){let t=Math.sqrt(4*this._maxInstanceCount);t=4*Math.ceil(t/4),t=Math.max(t,4);const e=new Float32Array(t*t*4),s=new Do(e,t,t,Dt,It);this._matricesTexture=s}_initIndirectTexture(){let t=Math.sqrt(this._maxInstanceCount);t=Math.ceil(t);const e=new Uint32Array(t*t),s=new Do(e,t,t,qt,Bt);this._indirectTexture=s}_initColorsTexture(){let t=Math.sqrt(this._maxIndexCount);t=Math.ceil(t);const e=new Float32Array(t*t*4).fill(1),s=new Do(e,t,t,Dt,It);s.colorSpace=di.workingColorSpace,this._colorsTexture=s}_initializeGeometry(t){const e=this.geometry,s=this._maxVertexCount,i=this._maxIndexCount;if(!1===this._geometryInitialized){for(const i in t.attributes){const r=t.getAttribute(i),{array:n,itemSize:o,normalized:a}=r,h=new n.constructor(s*o),u=new hn(h,o,a);e.setAttribute(i,u)}if(null!==t.getIndex()){const t=s>65535?new Uint32Array(i):new Uint16Array(i);e.setIndex(new hn(t,1))}this._geometryInitialized=!0}}_validateGeometry(t){const e=this.geometry;if(Boolean(t.getIndex())!==Boolean(e.getIndex()))throw new Error('BatchedMesh: All geometries must consistently have "index".');for(const s in e.attributes){if(!t.hasAttribute(s))throw new Error(`BatchedMesh: Added geometry missing "${s}". All geometries must have consistent attributes.`);const i=t.getAttribute(s),r=e.getAttribute(s);if(i.itemSize!==r.itemSize||i.normalized!==r.normalized)throw new Error("BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}setCustomSort(t){return this.customSort=t,this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Pi);const t=this._geometryCount,e=this.boundingBox,s=this._drawInfo;e.makeEmpty();for(let i=0;i<t;i++){if(!1===s[i].active)continue;const t=s[i].geometryIndex;this.getMatrixAt(i,ua),this.getBoundingBoxAt(t,ga).applyMatrix4(ua),e.union(ga)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new Zi);const t=this.boundingSphere,e=this._drawInfo;t.makeEmpty();for(let s=0,i=e.length;s<i;s++){if(!1===e[s].active)continue;const i=e[s].geometryIndex;this.getMatrixAt(s,ua),this.getBoundingSphereAt(i,fa).applyMatrix4(ua),t.union(fa)}}addInstance(t){if(this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");this._drawInfo.push({visible:!0,active:!0,geometryIndex:t});const e=this._drawInfo.length-1,s=this._matricesTexture,i=s.image.data;ca.toArray(i,16*e),s.needsUpdate=!0;const r=this._colorsTexture;return r&&(da.toArray(r.image.data,4*e),r.needsUpdate=!0),e}addGeometry(t,e=-1,s=-1){if(this._initializeGeometry(t),this._validateGeometry(t),this._drawInfo.length>=this._maxInstanceCount)throw new Error("BatchedMesh: Maximum item count reached.");const i={vertexStart:-1,vertexCount:-1,indexStart:-1,indexCount:-1};let r=null;const n=this._reservedRanges,o=this._drawRanges,a=this._bounds;0!==this._geometryCount&&(r=n[n.length-1]),i.vertexCount=-1===e?t.getAttribute("position").count:e,i.vertexStart=null===r?0:r.vertexStart+r.vertexCount;const h=t.getIndex(),u=null!==h;if(u&&(i.indexCount=-1===s?h.count:s,i.indexStart=null===r?0:r.indexStart+r.indexCount),-1!==i.indexStart&&i.indexStart+i.indexCount>this._maxIndexCount||i.vertexStart+i.vertexCount>this._maxVertexCount)throw new Error("BatchedMesh: Reserved space request exceeds the maximum buffer size.");const l=this._geometryCount;return this._geometryCount++,n.push(i),o.push({start:u?i.indexStart:i.vertexStart,count:-1}),a.push({boxInitialized:!1,box:new Pi,sphereInitialized:!1,sphere:new Zi}),this.setGeometryAt(l,t),l}setGeometryAt(t,e){if(t>=this._geometryCount)throw new Error("BatchedMesh: Maximum geometry count reached.");this._validateGeometry(e);const s=this.geometry,i=null!==s.getIndex(),r=s.getIndex(),n=e.getIndex(),o=this._reservedRanges[t];if(i&&n.count>o.indexCount||e.attributes.position.count>o.vertexCount)throw new Error("BatchedMesh: Reserved space not large enough for provided geometry.");const a=o.vertexStart,h=o.vertexCount;for(const t in s.attributes){const i=e.getAttribute(t),r=s.getAttribute(t);wa(i,r,a);const n=i.itemSize;for(let t=i.count,e=h;t<e;t++){const e=a+t;for(let t=0;t<n;t++)r.setComponent(e,t,0)}r.needsUpdate=!0,r.addUpdateRange(a*n,h*n)}if(i){const t=o.indexStart;for(let e=0;e<n.count;e++)r.setX(t+e,a+n.getX(e));for(let e=n.count,s=o.indexCount;e<s;e++)r.setX(t+e,a);r.needsUpdate=!0,r.addUpdateRange(t,o.indexCount)}const u=this._bounds[t];null!==e.boundingBox?(u.box.copy(e.boundingBox),u.boxInitialized=!0):u.boxInitialized=!1,null!==e.boundingSphere?(u.sphere.copy(e.boundingSphere),u.sphereInitialized=!0):u.sphereInitialized=!1;const l=this._drawRanges[t],c=e.getAttribute("position");return l.count=i?n.count:c.count,this._visibilityChanged=!0,t}getBoundingBoxAt(t,e){if(t>=this._geometryCount)return null;const s=this._bounds[t],i=s.box,r=this.geometry;if(!1===s.boxInitialized){i.makeEmpty();const e=r.index,n=r.attributes.position,o=this._drawRanges[t];for(let t=o.start,s=o.start+o.count;t<s;t++){let s=t;e&&(s=e.getX(s)),i.expandByPoint(ya.fromBufferAttribute(n,s))}s.boxInitialized=!0}return e.copy(i),e}getBoundingSphereAt(t,e){if(t>=this._geometryCount)return null;const s=this._bounds[t],i=s.sphere,r=this.geometry;if(!1===s.sphereInitialized){i.makeEmpty(),this.getBoundingBoxAt(t,ga),ga.getCenter(i.center);const e=r.index,n=r.attributes.position,o=this._drawRanges[t];let a=0;for(let t=o.start,s=o.start+o.count;t<s;t++){let s=t;e&&(s=e.getX(s)),ya.fromBufferAttribute(n,s),a=Math.max(a,i.center.distanceToSquared(ya))}i.radius=Math.sqrt(a),s.sphereInitialized=!0}return e.copy(i),e}setMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture,r=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active||(e.toArray(r,16*t),i.needsUpdate=!0),this}getMatrixAt(t,e){const s=this._drawInfo,i=this._matricesTexture.image.data;return t>=s.length||!1===s[t].active?null:e.fromArray(i,16*t)}setColorAt(t,e){null===this._colorsTexture&&this._initColorsTexture();const s=this._colorsTexture,i=this._colorsTexture.image.data,r=this._drawInfo;return t>=r.length||!1===r[t].active||(e.toArray(i,4*t),s.needsUpdate=!0),this}getColorAt(t,e){const s=this._colorsTexture.image.data,i=this._drawInfo;return t>=i.length||!1===i[t].active?null:e.fromArray(s,4*t)}setVisibleAt(t,e){const s=this._drawInfo;return t>=s.length||!1===s[t].active||s[t].visible===e||(s[t].visible=e,this._visibilityChanged=!0),this}getVisibleAt(t){const e=this._drawInfo;return!(t>=e.length||!1===e[t].active)&&e[t].visible}raycast(t,e){const s=this._drawInfo,i=this._drawRanges,r=this.matrixWorld,n=this.geometry;Ta.material=this.material,Ta.geometry.index=n.index,Ta.geometry.attributes=n.attributes,null===Ta.geometry.boundingBox&&(Ta.geometry.boundingBox=new Pi),null===Ta.geometry.boundingSphere&&(Ta.geometry.boundingSphere=new Zi);for(let n=0,o=s.length;n<o;n++){if(!s[n].visible||!s[n].active)continue;const o=s[n].geometryIndex,a=i[o];Ta.geometry.setDrawRange(a.start,a.count),this.getMatrixAt(n,Ta.matrixWorld).premultiply(r),this.getBoundingBoxAt(o,Ta.geometry.boundingBox),this.getBoundingSphereAt(o,Ta.geometry.boundingSphere),Ta.raycast(t,_a);for(let t=0,s=_a.length;t<s;t++){const s=_a[t];s.object=this,s.batchId=n,e.push(s)}_a.length=0}Ta.material=null,Ta.geometry.index=null,Ta.geometry.attributes={},Ta.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=null!==t.boundingBox?t.boundingBox.clone():null,this.boundingSphere=null!==t.boundingSphere?t.boundingSphere.clone():null,this._drawRanges=t._drawRanges.map((t=>({...t}))),this._reservedRanges=t._reservedRanges.map((t=>({...t}))),this._drawInfo=t._drawInfo.map((t=>({...t}))),this._bounds=t._bounds.map((t=>({boxInitialized:t.boxInitialized,box:t.box.clone(),sphereInitialized:t.sphereInitialized,sphere:t.sphere.clone()}))),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(),null!==this._colorsTexture&&(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,null!==this._colorsTexture&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(t,e,s,i,r){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const n=i.getIndex(),o=null===n?1:n.array.BYTES_PER_ELEMENT,a=this._drawInfo,h=this._multiDrawStarts,u=this._multiDrawCounts,l=this._drawRanges,c=this.perObjectFrustumCulled,d=this._indirectTexture,p=d.image.data;c&&(pa.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse).multiply(this.matrixWorld),ma.setFromProjectionMatrix(pa,t.coordinateSystem));let m=0;if(this.sortObjects){la.copy(this.matrixWorld).invert(),ya.setFromMatrixPosition(s.matrixWorld).applyMatrix4(la),xa.set(0,0,-1).transformDirection(s.matrixWorld).transformDirection(la);for(let t=0,e=a.length;t<e;t++)if(a[t].visible&&a[t].active){const e=a[t].geometryIndex;this.getMatrixAt(t,ua),this.getBoundingSphereAt(e,fa).applyMatrix4(ua);let s=!1;if(c&&(s=!ma.intersectsSphere(fa)),!s){const s=ba.subVectors(fa.center,ya).dot(xa);va.push(l[e],s,t)}}const t=va.list,e=this.customSort;null===e?t.sort(r.transparent?aa:oa):e.call(this,t,s);for(let e=0,s=t.length;e<s;e++){const s=t[e];h[m]=s.start*o,u[m]=s.count,p[m]=s.index,m++}va.reset()}else for(let t=0,e=a.length;t<e;t++)if(a[t].visible&&a[t].active){const e=a[t].geometryIndex;let s=!1;if(c&&(this.getMatrixAt(t,ua),this.getBoundingSphereAt(e,fa).applyMatrix4(ua),s=!ma.intersectsSphere(fa)),!s){const s=l[e];h[m]=s.start*o,u[m]=s.count,p[m]=t,m++}}d.needsUpdate=!0,this._multiDrawCount=m,this._visibilityChanged=!1}onBeforeShadow(t,e,s,i,r,n){this.onBeforeRender(t,null,i,r,n)}}class Ma extends Qr{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new Yr(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 Aa=new Ei,Na=new Ei,Ra=new or,Ca=new nr,Ea=new Zi,Ba=new Ei,Ia=new Ei;class Pa extends Pr{constructor(t=new Mn,e=new Ma){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(null===t.index){const e=t.attributes.position,s=[0];for(let t=1,i=e.count;t<i;t++)Aa.fromBufferAttribute(e,t-1),Na.fromBufferAttribute(e,t),s[t]=s[t-1],s[t]+=Aa.distanceTo(Na);t.setAttribute("lineDistance",new yn(s,1))}else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const s=this.geometry,i=this.matrixWorld,r=t.params.Line.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),Ea.copy(s.boundingSphere),Ea.applyMatrix4(i),Ea.radius+=r,!1===t.ray.intersectsSphere(Ea))return;Ra.copy(i).invert(),Ca.copy(t.ray).applyMatrix4(Ra);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=this.isLineSegments?2:1,u=s.index,l=s.attributes.position;if(null!==u){const s=Math.max(0,n.start),i=Math.min(u.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=u.getX(r),i=u.getX(r+1),n=Fa(this,t,Ca,a,s,i);n&&e.push(n)}if(this.isLineLoop){const r=u.getX(i-1),n=u.getX(s),o=Fa(this,t,Ca,a,r,n);o&&e.push(o)}}else{const s=Math.max(0,n.start),i=Math.min(l.count,n.start+n.count);for(let r=s,n=i-1;r<n;r+=h){const s=Fa(this,t,Ca,a,r,r+1);s&&e.push(s)}if(this.isLineLoop){const r=Fa(this,t,Ca,a,i-1,s);r&&e.push(r)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}}function Fa(t,e,s,i,r,n){const o=t.geometry.attributes.position;Aa.fromBufferAttribute(o,r),Na.fromBufferAttribute(o,n);if(s.distanceSqToSegment(Aa,Na,Ba,Ia)>i)return;Ba.applyMatrix4(t.matrixWorld);const a=e.ray.origin.distanceTo(Ba);return a<e.near||a>e.far?void 0:{distance:a,point:Ia.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,object:t}}const Ua=new Ei,za=new Ei;class Oa extends Pa{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,s=[];for(let t=0,i=e.count;t<i;t+=2)Ua.fromBufferAttribute(e,t),za.fromBufferAttribute(e,t+1),s[t]=0===t?0:s[t-1],s[t+1]=s[t]+Ua.distanceTo(za);t.setAttribute("lineDistance",new yn(s,1))}else console.warn("THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}}class La extends Pa{constructor(t,e){super(t,e),this.isLineLoop=!0,this.type="LineLoop"}}class Va extends Qr{constructor(t){super(),this.isPointsMaterial=!0,this.type="PointsMaterial",this.color=new Yr(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 Da=new or,ka=new nr,Ga=new Zi,Wa=new Ei;class ja extends Pr{constructor(t=new Mn,e=new Va){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 s=this.geometry,i=this.matrixWorld,r=t.params.Points.threshold,n=s.drawRange;if(null===s.boundingSphere&&s.computeBoundingSphere(),Ga.copy(s.boundingSphere),Ga.applyMatrix4(i),Ga.radius+=r,!1===t.ray.intersectsSphere(Ga))return;Da.copy(i).invert(),ka.copy(t.ray).applyMatrix4(Da);const o=r/((this.scale.x+this.scale.y+this.scale.z)/3),a=o*o,h=s.index,u=s.attributes.position;if(null!==h){for(let s=Math.max(0,n.start),r=Math.min(h.count,n.start+n.count);s<r;s++){const r=h.getX(s);Wa.fromBufferAttribute(u,r),Ha(Wa,r,a,i,t,e,this)}}else{for(let s=Math.max(0,n.start),r=Math.min(u.count,n.start+n.count);s<r;s++)Wa.fromBufferAttribute(u,s),Ha(Wa,s,a,i,t,e,this)}}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const s=t[e[0]];if(void 0!==s){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=s.length;t<e;t++){const e=s[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}}function Ha(t,e,s,i,r,n,o){const a=ka.distanceSqToPoint(t);if(a<s){const s=new Ei;ka.closestPointToPoint(t,s),s.applyMatrix4(i);const h=r.ray.origin.distanceTo(s);if(h<r.near||h>r.far)return;n.push({distance:h,distanceToRay:Math.sqrt(a),point:s,index:e,face:null,object:o})}}class qa extends Pr{constructor(){super(),this.isGroup=!0,this.type="Group"}}class $a extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isVideoTexture=!0,this.minFilter=void 0!==n?n:Tt,this.magFilter=void 0!==r?r:Tt,this.generateMipmaps=!1;const u=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){u.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class Xa extends Ti{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=ft,this.minFilter=ft,this.generateMipmaps=!1,this.needsUpdate=!0}}class Ya extends Ti{constructor(t,e,s,i,r,n,o,a,h,u,l,c){super(null,n,o,a,h,u,i,r,l,c),this.isCompressedTexture=!0,this.image={width:e,height:s},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}class Ja extends Ya{constructor(t,e,s,i,r,n){super(t,e,s,r,n),this.isCompressedArrayTexture=!0,this.image.depth=i,this.wrapR=mt,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Za extends Ya{constructor(t,e,s){super(void 0,t[0].width,t[0].height,e,s,ht),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=t}}class Qa extends Ti{constructor(t,e,s,i,r,n,o,a,h){super(t,e,s,i,r,n,o,a,h),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Ka extends Ti{constructor(t,e,s,i,r,n,o,a,h,u=1026){if(u!==Wt&&u!==jt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===s&&u===Wt&&(s=Bt),void 0===s&&u===jt&&(s=zt),super(null,i,r,n,o,a,u,s,h),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==o?o:ft,this.minFilter=void 0!==a?a:ft,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 null!==this.compareFunction&&(e.compareFunction=this.compareFunction),e}}class th{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const s=this.getUtoTmapping(t);return this.getPoint(s,e)}getPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return e}getSpacedPoints(t=5){const e=[];for(let s=0;s<=t;s++)e.push(this.getPointAt(s/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 s,i=this.getPoint(0),r=0;e.push(0);for(let n=1;n<=t;n++)s=this.getPoint(n/t),r+=s.distanceTo(i),e.push(r),i=s;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const s=this.getLengths();let i=0;const r=s.length;let n;n=e||t*s[r-1];let o,a=0,h=r-1;for(;a<=h;)if(i=Math.floor(a+(h-a)/2),o=s[i]-n,o<0)a=i+1;else{if(!(o>0)){h=i;break}h=i-1}if(i=h,s[i]===n)return i/(r-1);const u=s[i];return(i+(n-u)/(s[i+1]-u))/(r-1)}getTangent(t,e){const s=1e-4;let i=t-s,r=t+s;i<0&&(i=0),r>1&&(r=1);const n=this.getPoint(i),o=this.getPoint(r),a=e||(n.isVector2?new Ks:new Ei);return a.copy(o).sub(n).normalize(),a}getTangentAt(t,e){const s=this.getUtoTmapping(t);return this.getTangent(s,e)}computeFrenetFrames(t,e){const s=new Ei,i=[],r=[],n=[],o=new Ei,a=new or;for(let e=0;e<=t;e++){const s=e/t;i[e]=this.getTangentAt(s,new Ei)}r[0]=new Ei,n[0]=new Ei;let h=Number.MAX_VALUE;const u=Math.abs(i[0].x),l=Math.abs(i[0].y),c=Math.abs(i[0].z);u<=h&&(h=u,s.set(1,0,0)),l<=h&&(h=l,s.set(0,1,0)),c<=h&&s.set(0,0,1),o.crossVectors(i[0],s).normalize(),r[0].crossVectors(i[0],o),n[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),n[e]=n[e-1].clone(),o.crossVectors(i[e-1],i[e]),o.length()>Number.EPSILON){o.normalize();const t=Math.acos($s(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(a.makeRotationAxis(o,t))}n[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos($s(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(e=-e);for(let s=1;s<=t;s++)r[s].applyMatrix4(a.makeRotationAxis(i[s],e*s)),n[s].crossVectors(i[s],r[s])}return{tangents:i,normals:r,binormals:n}}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 eh extends th{constructor(t=0,e=0,s=1,i=1,r=0,n=2*Math.PI,o=!1,a=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=s,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=n,this.aClockwise=o,this.aRotation=a}getPoint(t,e=new Ks){const s=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const n=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=n?0:i),!0!==this.aClockwise||n||(r===i?r=-i:r-=i);const o=this.aStartAngle+t*r;let a=this.aX+this.xRadius*Math.cos(o),h=this.aY+this.yRadius*Math.sin(o);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),s=a-this.aX,i=h-this.aY;a=s*t-i*e+this.aX,h=s*e+i*t+this.aY}return s.set(a,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 sh extends eh{constructor(t,e,s,i,r,n){super(t,e,s,s,i,r,n),this.isArcCurve=!0,this.type="ArcCurve"}}function ih(){let t=0,e=0,s=0,i=0;function r(r,n,o,a){t=r,e=o,s=-3*r+3*n-2*o-a,i=2*r-2*n+o+a}return{initCatmullRom:function(t,e,s,i,n){r(e,s,n*(s-t),n*(i-e))},initNonuniformCatmullRom:function(t,e,s,i,n,o,a){let h=(e-t)/n-(s-t)/(n+o)+(s-e)/o,u=(s-e)/o-(i-e)/(o+a)+(i-s)/a;h*=o,u*=o,r(e,s,h,u)},calc:function(r){const n=r*r;return t+e*r+s*n+i*(n*r)}}}const rh=new Ei,nh=new ih,oh=new ih,ah=new ih;class hh extends th{constructor(t=[],e=!1,s="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=s,this.tension=i}getPoint(t,e=new Ei){const s=e,i=this.points,r=i.length,n=(r-(this.closed?0:1))*t;let o,a,h=Math.floor(n),u=n-h;this.closed?h+=h>0?0:(Math.floor(Math.abs(h)/r)+1)*r:0===u&&h===r-1&&(h=r-2,u=1),this.closed||h>0?o=i[(h-1)%r]:(rh.subVectors(i[0],i[1]).add(i[0]),o=rh);const l=i[h%r],c=i[(h+1)%r];if(this.closed||h+2<r?a=i[(h+2)%r]:(rh.subVectors(i[r-1],i[r-2]).add(i[r-1]),a=rh),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(o.distanceToSquared(l),t),s=Math.pow(l.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(a),t);s<1e-4&&(s=1),e<1e-4&&(e=s),i<1e-4&&(i=s),nh.initNonuniformCatmullRom(o.x,l.x,c.x,a.x,e,s,i),oh.initNonuniformCatmullRom(o.y,l.y,c.y,a.y,e,s,i),ah.initNonuniformCatmullRom(o.z,l.z,c.z,a.z,e,s,i)}else"catmullrom"===this.curveType&&(nh.initCatmullRom(o.x,l.x,c.x,a.x,this.tension),oh.initCatmullRom(o.y,l.y,c.y,a.y,this.tension),ah.initCatmullRom(o.z,l.z,c.z,a.z,this.tension));return s.set(nh.calc(u),oh.calc(u),ah.calc(u)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e<s;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,s=this.points.length;e<s;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,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push((new Ei).fromArray(s))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function uh(t,e,s,i,r){const n=.5*(i-e),o=.5*(r-s),a=t*t;return(2*s-2*i+n+o)*(t*a)+(-3*s+3*i-2*n-o)*a+n*t+s}function lh(t,e,s,i){return function(t,e){const s=1-t;return s*s*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,s)+function(t,e){return t*t*e}(t,i)}function ch(t,e,s,i,r){return function(t,e){const s=1-t;return s*s*s*e}(t,e)+function(t,e){const s=1-t;return 3*s*s*t*e}(t,s)+function(t,e){return 3*(1-t)*t*t*e}(t,i)+function(t,e){return t*t*t*e}(t,r)}class dh extends th{constructor(t=new Ks,e=new Ks,s=new Ks,i=new Ks){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Ks){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(ch(t,i.x,r.x,n.x,o.x),ch(t,i.y,r.y,n.y,o.y)),s}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 ph extends th{constructor(t=new Ei,e=new Ei,s=new Ei,i=new Ei){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=s,this.v3=i}getPoint(t,e=new Ei){const s=e,i=this.v0,r=this.v1,n=this.v2,o=this.v3;return s.set(ch(t,i.x,r.x,n.x,o.x),ch(t,i.y,r.y,n.y,o.y),ch(t,i.z,r.z,n.z,o.z)),s}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 mh extends th{constructor(t=new Ks,e=new Ks){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Ks){const s=e;return 1===t?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(t).add(this.v1)),s}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Ks){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 gh extends th{constructor(t=new Ei,e=new Ei){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new Ei){const s=e;return 1===t?s.copy(this.v2):(s.copy(this.v2).sub(this.v1),s.multiplyScalar(t).add(this.v1)),s}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Ei){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 fh extends th{constructor(t=new Ks,e=new Ks,s=new Ks){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Ks){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(lh(t,i.x,r.x,n.x),lh(t,i.y,r.y,n.y)),s}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 yh extends th{constructor(t=new Ei,e=new Ei,s=new Ei){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=s}getPoint(t,e=new Ei){const s=e,i=this.v0,r=this.v1,n=this.v2;return s.set(lh(t,i.x,r.x,n.x),lh(t,i.y,r.y,n.y),lh(t,i.z,r.z,n.z)),s}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 xh extends th{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new Ks){const s=e,i=this.points,r=(i.length-1)*t,n=Math.floor(r),o=r-n,a=i[0===n?n:n-1],h=i[n],u=i[n>i.length-2?i.length-1:n+1],l=i[n>i.length-3?i.length-1:n+2];return s.set(uh(o,a.x,h.x,u.x,l.x),uh(o,a.y,h.y,u.y,l.y)),s}copy(t){super.copy(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push(s.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,s=this.points.length;e<s;e++){const s=this.points[e];t.points.push(s.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,s=t.points.length;e<s;e++){const s=t.points[e];this.points.push((new Ks).fromArray(s))}return this}}var bh=Object.freeze({__proto__:null,ArcCurve:sh,CatmullRomCurve3:hh,CubicBezierCurve:dh,CubicBezierCurve3:ph,EllipseCurve:eh,LineCurve:mh,LineCurve3:gh,QuadraticBezierCurve:fh,QuadraticBezierCurve3:yh,SplineCurve:xh});class vh extends th{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 s=!0===t.isVector2?"LineCurve":"LineCurve3";this.curves.push(new bh[s](e,t))}return this}getPoint(t,e){const s=t*this.getLength(),i=this.getCurveLengths();let r=0;for(;r<i.length;){if(i[r]>=s){const t=i[r]-s,n=this.curves[r],o=n.getLength(),a=0===o?0:1-t/o;return n.getPointAt(a,e)}r++}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 s=0,i=this.curves.length;s<i;s++)e+=this.curves[s].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let s=0;s<=t;s++)e.push(this.getPoint(s/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let s;for(let i=0,r=this.curves;i<r.length;i++){const n=r[i],o=n.isEllipseCurve?2*t:n.isLineCurve||n.isLineCurve3?1:n.isSplineCurve?t*n.points.length:t,a=n.getPoints(o);for(let t=0;t<a.length;t++){const i=a[t];s&&s.equals(i)||(e.push(i),s=i)}}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,s=t.curves.length;e<s;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,s=this.curves.length;e<s;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,s=t.curves.length;e<s;e++){const s=t.curves[e];this.curves.push((new bh[s.type]).fromJSON(s))}return this}}class Th extends vh{constructor(t){super(),this.type="Path",this.currentPoint=new Ks,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,s=t.length;e<s;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 s=new mh(this.currentPoint.clone(),new Ks(t,e));return this.curves.push(s),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,s,i){const r=new fh(this.currentPoint.clone(),new Ks(t,e),new Ks(s,i));return this.curves.push(r),this.currentPoint.set(s,i),this}bezierCurveTo(t,e,s,i,r,n){const o=new dh(this.currentPoint.clone(),new Ks(t,e),new Ks(s,i),new Ks(r,n));return this.curves.push(o),this.currentPoint.set(r,n),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),s=new xh(e);return this.curves.push(s),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,s,i,r,n){const o=this.currentPoint.x,a=this.currentPoint.y;return this.absarc(t+o,e+a,s,i,r,n),this}absarc(t,e,s,i,r,n){return this.absellipse(t,e,s,s,i,r,n),this}ellipse(t,e,s,i,r,n,o,a){const h=this.currentPoint.x,u=this.currentPoint.y;return this.absellipse(t+h,e+u,s,i,r,n,o,a),this}absellipse(t,e,s,i,r,n,o,a){const h=new eh(t,e,s,i,r,n,o,a);if(this.curves.length>0){const t=h.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(h);const u=h.getPoint(1);return this.currentPoint.copy(u),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 _h extends Mn{constructor(t=[new Ks(0,-.5),new Ks(.5,0),new Ks(0,.5)],e=12,s=0,i=2*Math.PI){super(),this.type="LatheGeometry",this.parameters={points:t,segments:e,phiStart:s,phiLength:i},e=Math.floor(e),i=$s(i,0,2*Math.PI);const r=[],n=[],o=[],a=[],h=[],u=1/e,l=new Ei,c=new Ks,d=new Ei,p=new Ei,m=new Ei;let g=0,f=0;for(let e=0;e<=t.length-1;e++)switch(e){case 0:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,m.copy(d),d.normalize(),a.push(d.x,d.y,d.z);break;case t.length-1:a.push(m.x,m.y,m.z);break;default:g=t[e+1].x-t[e].x,f=t[e+1].y-t[e].y,d.x=1*f,d.y=-g,d.z=0*f,p.copy(d),d.x+=m.x,d.y+=m.y,d.z+=m.z,d.normalize(),a.push(d.x,d.y,d.z),m.copy(p)}for(let r=0;r<=e;r++){const d=s+r*u*i,p=Math.sin(d),m=Math.cos(d);for(let s=0;s<=t.length-1;s++){l.x=t[s].x*p,l.y=t[s].y,l.z=t[s].x*m,n.push(l.x,l.y,l.z),c.x=r/e,c.y=s/(t.length-1),o.push(c.x,c.y);const i=a[3*s+0]*p,u=a[3*s+1],d=a[3*s+0]*m;h.push(i,u,d)}}for(let s=0;s<e;s++)for(let e=0;e<t.length-1;e++){const i=e+s*t.length,n=i,o=i+t.length,a=i+t.length+1,h=i+1;r.push(n,o,h),r.push(a,h,o)}this.setIndex(r),this.setAttribute("position",new yn(n,3)),this.setAttribute("uv",new yn(o,2)),this.setAttribute("normal",new yn(h,3))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new _h(t.points,t.segments,t.phiStart,t.phiLength)}}class wh extends _h{constructor(t=1,e=1,s=4,i=8){const r=new Th;r.absarc(0,-e/2,t,1.5*Math.PI,0),r.absarc(0,e/2,t,0,.5*Math.PI),super(r.getPoints(s),i),this.type="CapsuleGeometry",this.parameters={radius:t,length:e,capSegments:s,radialSegments:i}}static fromJSON(t){return new wh(t.radius,t.length,t.capSegments,t.radialSegments)}}class Sh extends Mn{constructor(t=1,e=32,s=0,i=2*Math.PI){super(),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:s,thetaLength:i},e=Math.max(3,e);const r=[],n=[],o=[],a=[],h=new Ei,u=new Ks;n.push(0,0,0),o.push(0,0,1),a.push(.5,.5);for(let r=0,l=3;r<=e;r++,l+=3){const c=s+r/e*i;h.x=t*Math.cos(c),h.y=t*Math.sin(c),n.push(h.x,h.y,h.z),o.push(0,0,1),u.x=(n[l]/t+1)/2,u.y=(n[l+1]/t+1)/2,a.push(u.x,u.y)}for(let t=1;t<=e;t++)r.push(t,t+1,0);this.setIndex(r),this.setAttribute("position",new yn(n,3)),this.setAttribute("normal",new yn(o,3)),this.setAttribute("uv",new yn(a,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Sh(t.radius,t.segments,t.thetaStart,t.thetaLength)}}class Mh extends Mn{constructor(t=1,e=1,s=1,i=32,r=1,n=!1,o=0,a=2*Math.PI){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:s,radialSegments:i,heightSegments:r,openEnded:n,thetaStart:o,thetaLength:a};const h=this;i=Math.floor(i),r=Math.floor(r);const u=[],l=[],c=[],d=[];let p=0;const m=[],g=s/2;let f=0;function y(s){const r=p,n=new Ks,m=new Ei;let y=0;const x=!0===s?t:e,b=!0===s?1:-1;for(let t=1;t<=i;t++)l.push(0,g*b,0),c.push(0,b,0),d.push(.5,.5),p++;const v=p;for(let t=0;t<=i;t++){const e=t/i*a+o,s=Math.cos(e),r=Math.sin(e);m.x=x*r,m.y=g*b,m.z=x*s,l.push(m.x,m.y,m.z),c.push(0,b,0),n.x=.5*s+.5,n.y=.5*r*b+.5,d.push(n.x,n.y),p++}for(let t=0;t<i;t++){const e=r+t,i=v+t;!0===s?u.push(i,i+1,e):u.push(i+1,i,e),y+=3}h.addGroup(f,y,!0===s?1:2),f+=y}!function(){const n=new Ei,y=new Ei;let x=0;const b=(e-t)/s;for(let h=0;h<=r;h++){const u=[],f=h/r,x=f*(e-t)+t;for(let t=0;t<=i;t++){const e=t/i,r=e*a+o,h=Math.sin(r),m=Math.cos(r);y.x=x*h,y.y=-f*s+g,y.z=x*m,l.push(y.x,y.y,y.z),n.set(h,b,m).normalize(),c.push(n.x,n.y,n.z),d.push(e,1-f),u.push(p++)}m.push(u)}for(let t=0;t<i;t++)for(let e=0;e<r;e++){const s=m[e][t],i=m[e+1][t],r=m[e+1][t+1],n=m[e][t+1];u.push(s,i,n),u.push(i,r,n),x+=6}h.addGroup(f,x,0),f+=x}(),!1===n&&(t>0&&y(!0),e>0&&y(!1)),this.setIndex(u),this.setAttribute("position",new yn(l,3)),this.setAttribute("normal",new yn(c,3)),this.setAttribute("uv",new yn(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Mh(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Ah extends Mh{constructor(t=1,e=1,s=32,i=1,r=!1,n=0,o=2*Math.PI){super(0,t,e,s,i,r,n,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:s,heightSegments:i,openEnded:r,thetaStart:n,thetaLength:o}}static fromJSON(t){return new Ah(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Nh extends Mn{constructor(t=[],e=[],s=1,i=0){super(),this.type="PolyhedronGeometry",this.parameters={vertices:t,indices:e,radius:s,detail:i};const r=[],n=[];function o(t,e,s,i){const r=i+1,n=[];for(let i=0;i<=r;i++){n[i]=[];const o=t.clone().lerp(s,i/r),a=e.clone().lerp(s,i/r),h=r-i;for(let t=0;t<=h;t++)n[i][t]=0===t&&i===r?o:o.clone().lerp(a,t/h)}for(let t=0;t<r;t++)for(let e=0;e<2*(r-t)-1;e++){const s=Math.floor(e/2);e%2==0?(a(n[t][s+1]),a(n[t+1][s]),a(n[t][s])):(a(n[t][s+1]),a(n[t+1][s+1]),a(n[t+1][s]))}}function a(t){r.push(t.x,t.y,t.z)}function h(e,s){const i=3*e;s.x=t[i+0],s.y=t[i+1],s.z=t[i+2]}function u(t,e,s,i){i<0&&1===t.x&&(n[e]=t.x-1),0===s.x&&0===s.z&&(n[e]=i/2/Math.PI+.5)}function l(t){return Math.atan2(t.z,-t.x)}!function(t){const s=new Ei,i=new Ei,r=new Ei;for(let n=0;n<e.length;n+=3)h(e[n+0],s),h(e[n+1],i),h(e[n+2],r),o(s,i,r,t)}(i),function(t){const e=new Ei;for(let s=0;s<r.length;s+=3)e.x=r[s+0],e.y=r[s+1],e.z=r[s+2],e.normalize().multiplyScalar(t),r[s+0]=e.x,r[s+1]=e.y,r[s+2]=e.z}(s),function(){const t=new Ei;for(let s=0;s<r.length;s+=3){t.x=r[s+0],t.y=r[s+1],t.z=r[s+2];const i=l(t)/2/Math.PI+.5,o=(e=t,Math.atan2(-e.y,Math.sqrt(e.x*e.x+e.z*e.z))/Math.PI+.5);n.push(i,1-o)}var e;(function(){const t=new Ei,e=new Ei,s=new Ei,i=new Ei,o=new Ks,a=new Ks,h=new Ks;for(let c=0,d=0;c<r.length;c+=9,d+=6){t.set(r[c+0],r[c+1],r[c+2]),e.set(r[c+3],r[c+4],r[c+5]),s.set(r[c+6],r[c+7],r[c+8]),o.set(n[d+0],n[d+1]),a.set(n[d+2],n[d+3]),h.set(n[d+4],n[d+5]),i.copy(t).add(e).add(s).divideScalar(3);const p=l(i);u(o,d+0,t,p),u(a,d+2,e,p),u(h,d+4,s,p)}})(),function(){for(let t=0;t<n.length;t+=6){const e=n[t+0],s=n[t+2],i=n[t+4],r=Math.max(e,s,i),o=Math.min(e,s,i);r>.9&&o<.1&&(e<.2&&(n[t+0]+=1),s<.2&&(n[t+2]+=1),i<.2&&(n[t+4]+=1))}}()}(),this.setAttribute("position",new yn(r,3)),this.setAttribute("normal",new yn(r.slice(),3)),this.setAttribute("uv",new yn(n,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Nh(t.vertices,t.indices,t.radius,t.details)}}class Rh extends Nh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2,i=1/s;super([-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-i,-s,0,-i,s,0,i,-s,0,i,s,-i,-s,0,-i,s,0,i,-s,0,i,s,0,-s,0,-i,s,0,-i,-s,0,i,s,0,i],[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],t,e),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new Rh(t.radius,t.detail)}}const Ch=new Ei,Eh=new Ei,Bh=new Ei,Ih=new jr;class Ph extends Mn{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const s=4,i=Math.pow(10,s),r=Math.cos(js*e),n=t.getIndex(),o=t.getAttribute("position"),a=n?n.count:o.count,h=[0,0,0],u=["a","b","c"],l=new Array(3),c={},d=[];for(let t=0;t<a;t+=3){n?(h[0]=n.getX(t),h[1]=n.getX(t+1),h[2]=n.getX(t+2)):(h[0]=t,h[1]=t+1,h[2]=t+2);const{a:e,b:s,c:a}=Ih;if(e.fromBufferAttribute(o,h[0]),s.fromBufferAttribute(o,h[1]),a.fromBufferAttribute(o,h[2]),Ih.getNormal(Bh),l[0]=`${Math.round(e.x*i)},${Math.round(e.y*i)},${Math.round(e.z*i)}`,l[1]=`${Math.round(s.x*i)},${Math.round(s.y*i)},${Math.round(s.z*i)}`,l[2]=`${Math.round(a.x*i)},${Math.round(a.y*i)},${Math.round(a.z*i)}`,l[0]!==l[1]&&l[1]!==l[2]&&l[2]!==l[0])for(let t=0;t<3;t++){const e=(t+1)%3,s=l[t],i=l[e],n=Ih[u[t]],o=Ih[u[e]],a=`${s}_${i}`,p=`${i}_${s}`;p in c&&c[p]?(Bh.dot(c[p].normal)<=r&&(d.push(n.x,n.y,n.z),d.push(o.x,o.y,o.z)),c[p]=null):a in c||(c[a]={index0:h[t],index1:h[e],normal:Bh.clone()})}}for(const t in c)if(c[t]){const{index0:e,index1:s}=c[t];Ch.fromBufferAttribute(o,e),Eh.fromBufferAttribute(o,s),d.push(Ch.x,Ch.y,Ch.z),d.push(Eh.x,Eh.y,Eh.z)}this.setAttribute("position",new yn(d,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}class Fh extends Th{constructor(t){super(t),this.uuid=qs(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let s=0,i=this.holes.length;s<i;s++)e[s]=this.holes[s].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,s=t.holes.length;e<s;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,s=this.holes.length;e<s;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,s=t.holes.length;e<s;e++){const s=t.holes[e];this.holes.push((new Th).fromJSON(s))}return this}}const Uh=function(t,e,s=2){const i=e&&e.length,r=i?e[0]*s:t.length;let n=zh(t,0,r,s,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,u,l,c,d,p;if(i&&(n=function(t,e,s,i){const r=[];let n,o,a,h,u;for(n=0,o=e.length;n<o;n++)a=e[n]*i,h=n<o-1?e[n+1]*i:t.length,u=zh(t,a,h,i,!1),u===u.next&&(u.steiner=!0),r.push($h(u));for(r.sort(Wh),n=0;n<r.length;n++)s=jh(r[n],s);return s}(t,e,n,s)),t.length>80*s){a=u=t[0],h=l=t[1];for(let e=s;e<r;e+=s)c=t[e],d=t[e+1],c<a&&(a=c),d<h&&(h=d),c>u&&(u=c),d>l&&(l=d);p=Math.max(u-a,l-h),p=0!==p?32767/p:0}return Lh(n,o,s,a,h,p,0),o};function zh(t,e,s,i,r){let n,o;if(r===function(t,e,s,i){let r=0;for(let n=e,o=s-i;n<s;n+=i)r+=(t[o]-t[n])*(t[n+1]+t[o+1]),o=n;return r}(t,e,s,i)>0)for(n=e;n<s;n+=i)o=iu(n,t[n],t[n+1],o);else for(n=s-i;n>=e;n-=i)o=iu(n,t[n],t[n+1],o);return o&&Zh(o,o.next)&&(ru(o),o=o.next),o}function Oh(t,e){if(!t)return t;e||(e=t);let s,i=t;do{if(s=!1,i.steiner||!Zh(i,i.next)&&0!==Jh(i.prev,i,i.next))i=i.next;else{if(ru(i),i=e=i.prev,i===i.next)break;s=!0}}while(s||i!==e);return e}function Lh(t,e,s,i,r,n,o){if(!t)return;!o&&n&&function(t,e,s,i){let r=t;do{0===r.z&&(r.z=qh(r.x,r.y,e,s,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){let e,s,i,r,n,o,a,h,u=1;do{for(s=t,t=null,n=null,o=0;s;){for(o++,i=s,a=0,e=0;e<u&&(a++,i=i.nextZ,i);e++);for(h=u;a>0||h>0&&i;)0!==a&&(0===h||!i||s.z<=i.z)?(r=s,s=s.nextZ,a--):(r=i,i=i.nextZ,h--),n?n.nextZ=r:t=r,r.prevZ=n,n=r;s=i}n.nextZ=null,u*=2}while(o>1)}(r)}(t,i,r,n);let a,h,u=t;for(;t.prev!==t.next;)if(a=t.prev,h=t.next,n?Dh(t,i,r,n):Vh(t))e.push(a.i/s|0),e.push(t.i/s|0),e.push(h.i/s|0),ru(t),t=h.next,u=h.next;else if((t=h)===u){o?1===o?Lh(t=kh(Oh(t),e,s),e,s,i,r,n,2):2===o&&Gh(t,e,s,i,r,n):Lh(Oh(t),e,s,i,r,n,1);break}}function Vh(t){const e=t.prev,s=t,i=t.next;if(Jh(e,s,i)>=0)return!1;const r=e.x,n=s.x,o=i.x,a=e.y,h=s.y,u=i.y,l=r<n?r<o?r:o:n<o?n:o,c=a<h?a<u?a:u:h<u?h:u,d=r>n?r>o?r:o:n>o?n:o,p=a>h?a>u?a:u:h>u?h:u;let m=i.next;for(;m!==e;){if(m.x>=l&&m.x<=d&&m.y>=c&&m.y<=p&&Xh(r,a,n,h,o,u,m.x,m.y)&&Jh(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function Dh(t,e,s,i){const r=t.prev,n=t,o=t.next;if(Jh(r,n,o)>=0)return!1;const a=r.x,h=n.x,u=o.x,l=r.y,c=n.y,d=o.y,p=a<h?a<u?a:u:h<u?h:u,m=l<c?l<d?l:d:c<d?c:d,g=a>h?a>u?a:u:h>u?h:u,f=l>c?l>d?l:d:c>d?c:d,y=qh(p,m,e,s,i),x=qh(g,f,e,s,i);let b=t.prevZ,v=t.nextZ;for(;b&&b.z>=y&&v&&v.z<=x;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;if(b=b.prevZ,v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;b&&b.z>=y;){if(b.x>=p&&b.x<=g&&b.y>=m&&b.y<=f&&b!==r&&b!==o&&Xh(a,l,h,c,u,d,b.x,b.y)&&Jh(b.prev,b,b.next)>=0)return!1;b=b.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=g&&v.y>=m&&v.y<=f&&v!==r&&v!==o&&Xh(a,l,h,c,u,d,v.x,v.y)&&Jh(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function kh(t,e,s){let i=t;do{const r=i.prev,n=i.next.next;!Zh(r,n)&&Qh(r,i,i.next,n)&&eu(r,n)&&eu(n,r)&&(e.push(r.i/s|0),e.push(i.i/s|0),e.push(n.i/s|0),ru(i),ru(i.next),i=t=n),i=i.next}while(i!==t);return Oh(i)}function Gh(t,e,s,i,r,n){let o=t;do{let t=o.next.next;for(;t!==o.prev;){if(o.i!==t.i&&Yh(o,t)){let a=su(o,t);return o=Oh(o,o.next),a=Oh(a,a.next),Lh(o,e,s,i,r,n,0),void Lh(a,e,s,i,r,n,0)}t=t.next}o=o.next}while(o!==t)}function Wh(t,e){return t.x-e.x}function jh(t,e){const s=function(t,e){let s,i=e,r=-1/0;const n=t.x,o=t.y;do{if(o<=i.y&&o>=i.next.y&&i.next.y!==i.y){const t=i.x+(o-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>r&&(r=t,s=i.x<i.next.x?i:i.next,t===n))return s}i=i.next}while(i!==e);if(!s)return null;const a=s,h=s.x,u=s.y;let l,c=1/0;i=s;do{n>=i.x&&i.x>=h&&n!==i.x&&Xh(o<u?n:r,o,h,u,o<u?r:n,o,i.x,i.y)&&(l=Math.abs(o-i.y)/(n-i.x),eu(i,t)&&(l<c||l===c&&(i.x>s.x||i.x===s.x&&Hh(s,i)))&&(s=i,c=l)),i=i.next}while(i!==a);return s}(t,e);if(!s)return e;const i=su(s,t);return Oh(i,i.next),Oh(s,s.next)}function Hh(t,e){return Jh(t.prev,t,e.prev)<0&&Jh(e.next,t,t.next)<0}function qh(t,e,s,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=(t-s)*r|0)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=(e-i)*r|0)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function $h(t){let e=t,s=t;do{(e.x<s.x||e.x===s.x&&e.y<s.y)&&(s=e),e=e.next}while(e!==t);return s}function Xh(t,e,s,i,r,n,o,a){return(r-o)*(e-a)>=(t-o)*(n-a)&&(t-o)*(i-a)>=(s-o)*(e-a)&&(s-o)*(n-a)>=(r-o)*(i-a)}function Yh(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let s=t;do{if(s.i!==t.i&&s.next.i!==t.i&&s.i!==e.i&&s.next.i!==e.i&&Qh(s,s.next,t,e))return!0;s=s.next}while(s!==t);return!1}(t,e)&&(eu(t,e)&&eu(e,t)&&function(t,e){let s=t,i=!1;const r=(t.x+e.x)/2,n=(t.y+e.y)/2;do{s.y>n!=s.next.y>n&&s.next.y!==s.y&&r<(s.next.x-s.x)*(n-s.y)/(s.next.y-s.y)+s.x&&(i=!i),s=s.next}while(s!==t);return i}(t,e)&&(Jh(t.prev,t,e.prev)||Jh(t,e.prev,e))||Zh(t,e)&&Jh(t.prev,t,t.next)>0&&Jh(e.prev,e,e.next)>0)}function Jh(t,e,s){return(e.y-t.y)*(s.x-e.x)-(e.x-t.x)*(s.y-e.y)}function Zh(t,e){return t.x===e.x&&t.y===e.y}function Qh(t,e,s,i){const r=tu(Jh(t,e,s)),n=tu(Jh(t,e,i)),o=tu(Jh(s,i,t)),a=tu(Jh(s,i,e));return r!==n&&o!==a||(!(0!==r||!Kh(t,s,e))||(!(0!==n||!Kh(t,i,e))||(!(0!==o||!Kh(s,t,i))||!(0!==a||!Kh(s,e,i)))))}function Kh(t,e,s){return e.x<=Math.max(t.x,s.x)&&e.x>=Math.min(t.x,s.x)&&e.y<=Math.max(t.y,s.y)&&e.y>=Math.min(t.y,s.y)}function tu(t){return t>0?1:t<0?-1:0}function eu(t,e){return Jh(t.prev,t,t.next)<0?Jh(t,e,t.next)>=0&&Jh(t,t.prev,e)>=0:Jh(t,e,t.prev)<0||Jh(t,t.next,e)<0}function su(t,e){const s=new nu(t.i,t.x,t.y),i=new nu(e.i,e.x,e.y),r=t.next,n=e.prev;return t.next=e,e.prev=t,s.next=r,r.prev=s,i.next=s,s.prev=i,n.next=i,i.prev=n,i}function iu(t,e,s,i){const r=new nu(t,e,s);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function ru(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function nu(t,e,s){this.i=t,this.x=e,this.y=s,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}class ou{static area(t){const e=t.length;let s=0;for(let i=e-1,r=0;r<e;i=r++)s+=t[i].x*t[r].y-t[r].x*t[i].y;return.5*s}static isClockWise(t){return ou.area(t)<0}static triangulateShape(t,e){const s=[],i=[],r=[];au(t),hu(s,t);let n=t.length;e.forEach(au);for(let t=0;t<e.length;t++)i.push(n),n+=e[t].length,hu(s,e[t]);const o=Uh(s,i);for(let t=0;t<o.length;t+=3)r.push(o.slice(t,t+3));return r}}function au(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function hu(t,e){for(let s=0;s<e.length;s++)t.push(e[s].x),t.push(e[s].y)}class uu extends Mn{constructor(t=new Fh([new Ks(.5,.5),new Ks(-.5,.5),new Ks(-.5,-.5),new Ks(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],r=[];for(let e=0,s=t.length;e<s;e++){n(t[e])}function n(t){const n=[],o=void 0!==e.curveSegments?e.curveSegments:12,a=void 0!==e.steps?e.steps:1,h=void 0!==e.depth?e.depth:1;let u=void 0===e.bevelEnabled||e.bevelEnabled,l=void 0!==e.bevelThickness?e.bevelThickness:.2,c=void 0!==e.bevelSize?e.bevelSize:l-.1,d=void 0!==e.bevelOffset?e.bevelOffset:0,p=void 0!==e.bevelSegments?e.bevelSegments:3;const m=e.extrudePath,g=void 0!==e.UVGenerator?e.UVGenerator:lu;let f,y,x,b,v,T=!1;m&&(f=m.getSpacedPoints(a),T=!0,u=!1,y=m.computeFrenetFrames(a,!1),x=new Ei,b=new Ei,v=new Ei),u||(p=0,l=0,c=0,d=0);const _=t.extractPoints(o);let w=_.shape;const S=_.holes;if(!ou.isClockWise(w)){w=w.reverse();for(let t=0,e=S.length;t<e;t++){const e=S[t];ou.isClockWise(e)&&(S[t]=e.reverse())}}const M=ou.triangulateShape(w,S),A=w;for(let t=0,e=S.length;t<e;t++){const e=S[t];w=w.concat(e)}function N(t,e,s){return e||console.error("THREE.ExtrudeGeometry: vec does not exist"),t.clone().addScaledVector(e,s)}const R=w.length,C=M.length;function E(t,e,s){let i,r,n;const o=t.x-e.x,a=t.y-e.y,h=s.x-t.x,u=s.y-t.y,l=o*o+a*a,c=o*u-a*h;if(Math.abs(c)>Number.EPSILON){const c=Math.sqrt(l),d=Math.sqrt(h*h+u*u),p=e.x-a/c,m=e.y+o/c,g=((s.x-u/d-p)*u-(s.y+h/d-m)*h)/(o*u-a*h);i=p+o*g-t.x,r=m+a*g-t.y;const f=i*i+r*r;if(f<=2)return new Ks(i,r);n=Math.sqrt(f/2)}else{let t=!1;o>Number.EPSILON?h>Number.EPSILON&&(t=!0):o<-Number.EPSILON?h<-Number.EPSILON&&(t=!0):Math.sign(a)===Math.sign(u)&&(t=!0),t?(i=-a,r=o,n=Math.sqrt(l)):(i=o,r=a,n=Math.sqrt(l/2))}return new Ks(i/n,r/n)}const B=[];for(let t=0,e=A.length,s=e-1,i=t+1;t<e;t++,s++,i++)s===e&&(s=0),i===e&&(i=0),B[t]=E(A[t],A[s],A[i]);const I=[];let P,F=B.concat();for(let t=0,e=S.length;t<e;t++){const e=S[t];P=[];for(let t=0,s=e.length,i=s-1,r=t+1;t<s;t++,i++,r++)i===s&&(i=0),r===s&&(r=0),P[t]=E(e[t],e[i],e[r]);I.push(P),F=F.concat(P)}for(let t=0;t<p;t++){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=N(A[t],B[t],i);O(e.x,e.y,-s)}for(let t=0,e=S.length;t<e;t++){const e=S[t];P=I[t];for(let t=0,r=e.length;t<r;t++){const r=N(e[t],P[t],i);O(r.x,r.y,-s)}}}const U=c+d;for(let t=0;t<R;t++){const e=u?N(w[t],F[t],U):w[t];T?(b.copy(y.normals[0]).multiplyScalar(e.x),x.copy(y.binormals[0]).multiplyScalar(e.y),v.copy(f[0]).add(b).add(x),O(v.x,v.y,v.z)):O(e.x,e.y,0)}for(let t=1;t<=a;t++)for(let e=0;e<R;e++){const s=u?N(w[e],F[e],U):w[e];T?(b.copy(y.normals[t]).multiplyScalar(s.x),x.copy(y.binormals[t]).multiplyScalar(s.y),v.copy(f[t]).add(b).add(x),O(v.x,v.y,v.z)):O(s.x,s.y,h/a*t)}for(let t=p-1;t>=0;t--){const e=t/p,s=l*Math.cos(e*Math.PI/2),i=c*Math.sin(e*Math.PI/2)+d;for(let t=0,e=A.length;t<e;t++){const e=N(A[t],B[t],i);O(e.x,e.y,h+s)}for(let t=0,e=S.length;t<e;t++){const e=S[t];P=I[t];for(let t=0,r=e.length;t<r;t++){const r=N(e[t],P[t],i);T?O(r.x,r.y+f[a-1].y,f[a-1].x+s):O(r.x,r.y,h+s)}}}function z(t,e){let s=t.length;for(;--s>=0;){const i=s;let r=s-1;r<0&&(r=t.length-1);for(let t=0,s=a+2*p;t<s;t++){const s=R*t,n=R*(t+1);V(e+i+s,e+r+s,e+r+n,e+i+n)}}}function O(t,e,s){n.push(t),n.push(e),n.push(s)}function L(t,e,r){D(t),D(e),D(r);const n=i.length/3,o=g.generateTopUV(s,i,n-3,n-2,n-1);k(o[0]),k(o[1]),k(o[2])}function V(t,e,r,n){D(t),D(e),D(n),D(e),D(r),D(n);const o=i.length/3,a=g.generateSideWallUV(s,i,o-6,o-3,o-2,o-1);k(a[0]),k(a[1]),k(a[3]),k(a[1]),k(a[2]),k(a[3])}function D(t){i.push(n[3*t+0]),i.push(n[3*t+1]),i.push(n[3*t+2])}function k(t){r.push(t.x),r.push(t.y)}!function(){const t=i.length/3;if(u){let t=0,e=R*t;for(let t=0;t<C;t++){const s=M[t];L(s[2]+e,s[1]+e,s[0]+e)}t=a+2*p,e=R*t;for(let t=0;t<C;t++){const s=M[t];L(s[0]+e,s[1]+e,s[2]+e)}}else{for(let t=0;t<C;t++){const e=M[t];L(e[2],e[1],e[0])}for(let t=0;t<C;t++){const e=M[t];L(e[0]+R*a,e[1]+R*a,e[2]+R*a)}}s.addGroup(t,i.length/3-t,0)}(),function(){const t=i.length/3;let e=0;z(A,e),e+=A.length;for(let t=0,s=S.length;t<s;t++){const s=S[t];z(s,e),e+=s.length}s.addGroup(t,i.length/3-t,1)}()}this.setAttribute("position",new yn(i,3)),this.setAttribute("uv",new yn(r,2)),this.computeVertexNormals()}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e,s){if(s.shapes=[],Array.isArray(t))for(let e=0,i=t.length;e<i;e++){const i=t[e];s.shapes.push(i.uuid)}else s.shapes.push(t.uuid);s.options=Object.assign({},e),void 0!==e.extrudePath&&(s.options.extrudePath=e.extrudePath.toJSON());return s}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const s=[];for(let i=0,r=t.shapes.length;i<r;i++){const r=e[t.shapes[i]];s.push(r)}const i=t.options.extrudePath;return void 0!==i&&(t.options.extrudePath=(new bh[i.type]).fromJSON(i)),new uu(s,t.options)}}const lu={generateTopUV:function(t,e,s,i,r){const n=e[3*s],o=e[3*s+1],a=e[3*i],h=e[3*i+1],u=e[3*r],l=e[3*r+1];return[new Ks(n,o),new Ks(a,h),new Ks(u,l)]},generateSideWallUV:function(t,e,s,i,r,n){const o=e[3*s],a=e[3*s+1],h=e[3*s+2],u=e[3*i],l=e[3*i+1],c=e[3*i+2],d=e[3*r],p=e[3*r+1],m=e[3*r+2],g=e[3*n],f=e[3*n+1],y=e[3*n+2];return Math.abs(a-l)<Math.abs(o-u)?[new Ks(o,1-h),new Ks(u,1-c),new Ks(d,1-m),new Ks(g,1-y)]:[new Ks(a,1-h),new Ks(l,1-c),new Ks(p,1-m),new Ks(f,1-y)]}};class cu extends Nh{constructor(t=1,e=0){const s=(1+Math.sqrt(5))/2;super([-1,s,0,1,s,0,-1,-s,0,1,-s,0,0,-1,s,0,1,s,0,-1,-s,0,1,-s,s,0,-1,s,0,1,-s,0,-1,-s,0,1],[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],t,e),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new cu(t.radius,t.detail)}}class du extends Nh{constructor(t=1,e=0){super([1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],t,e),this.type="OctahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new du(t.radius,t.detail)}}class pu extends Mn{constructor(t=1,e=1,s=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:s,heightSegments:i};const r=t/2,n=e/2,o=Math.floor(s),a=Math.floor(i),h=o+1,u=a+1,l=t/o,c=e/a,d=[],p=[],m=[],g=[];for(let t=0;t<u;t++){const e=t*c-n;for(let s=0;s<h;s++){const i=s*l-r;p.push(i,-e,0),m.push(0,0,1),g.push(s/o),g.push(1-t/a)}}for(let t=0;t<a;t++)for(let e=0;e<o;e++){const s=e+h*t,i=e+h*(t+1),r=e+1+h*(t+1),n=e+1+h*t;d.push(s,i,n),d.push(i,r,n)}this.setIndex(d),this.setAttribute("position",new yn(p,3)),this.setAttribute("normal",new yn(m,3)),this.setAttribute("uv",new yn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new pu(t.width,t.height,t.widthSegments,t.heightSegments)}}class mu extends Mn{constructor(t=.5,e=1,s=32,i=1,r=0,n=2*Math.PI){super(),this.type="RingGeometry",this.parameters={innerRadius:t,outerRadius:e,thetaSegments:s,phiSegments:i,thetaStart:r,thetaLength:n},s=Math.max(3,s);const o=[],a=[],h=[],u=[];let l=t;const c=(e-t)/(i=Math.max(1,i)),d=new Ei,p=new Ks;for(let t=0;t<=i;t++){for(let t=0;t<=s;t++){const i=r+t/s*n;d.x=l*Math.cos(i),d.y=l*Math.sin(i),a.push(d.x,d.y,d.z),h.push(0,0,1),p.x=(d.x/e+1)/2,p.y=(d.y/e+1)/2,u.push(p.x,p.y)}l+=c}for(let t=0;t<i;t++){const e=t*(s+1);for(let t=0;t<s;t++){const i=t+e,r=i,n=i+s+1,a=i+s+2,h=i+1;o.push(r,n,h),o.push(n,a,h)}}this.setIndex(o),this.setAttribute("position",new yn(a,3)),this.setAttribute("normal",new yn(h,3)),this.setAttribute("uv",new yn(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new mu(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}}class gu extends Mn{constructor(t=new Fh([new Ks(0,.5),new Ks(-.5,-.5),new Ks(.5,-.5)]),e=12){super(),this.type="ShapeGeometry",this.parameters={shapes:t,curveSegments:e};const s=[],i=[],r=[],n=[];let o=0,a=0;if(!1===Array.isArray(t))h(t);else for(let e=0;e<t.length;e++)h(t[e]),this.addGroup(o,a,e),o+=a,a=0;function h(t){const o=i.length/3,h=t.extractPoints(e);let u=h.shape;const l=h.holes;!1===ou.isClockWise(u)&&(u=u.reverse());for(let t=0,e=l.length;t<e;t++){const e=l[t];!0===ou.isClockWise(e)&&(l[t]=e.reverse())}const c=ou.triangulateShape(u,l);for(let t=0,e=l.length;t<e;t++){const e=l[t];u=u.concat(e)}for(let t=0,e=u.length;t<e;t++){const e=u[t];i.push(e.x,e.y,0),r.push(0,0,1),n.push(e.x,e.y)}for(let t=0,e=c.length;t<e;t++){const e=c[t],i=e[0]+o,r=e[1]+o,n=e[2]+o;s.push(i,r,n),a+=3}}this.setIndex(s),this.setAttribute("position",new yn(i,3)),this.setAttribute("normal",new yn(r,3)),this.setAttribute("uv",new yn(n,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON();return function(t,e){if(e.shapes=[],Array.isArray(t))for(let s=0,i=t.length;s<i;s++){const i=t[s];e.shapes.push(i.uuid)}else e.shapes.push(t.uuid);return e}(this.parameters.shapes,t)}static fromJSON(t,e){const s=[];for(let i=0,r=t.shapes.length;i<r;i++){const r=e[t.shapes[i]];s.push(r)}return new gu(s,t.curveSegments)}}class fu extends Mn{constructor(t=1,e=32,s=16,i=0,r=2*Math.PI,n=0,o=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:s,phiStart:i,phiLength:r,thetaStart:n,thetaLength:o},e=Math.max(3,Math.floor(e)),s=Math.max(2,Math.floor(s));const a=Math.min(n+o,Math.PI);let h=0;const u=[],l=new Ei,c=new Ei,d=[],p=[],m=[],g=[];for(let d=0;d<=s;d++){const f=[],y=d/s;let x=0;0===d&&0===n?x=.5/e:d===s&&a===Math.PI&&(x=-.5/e);for(let s=0;s<=e;s++){const a=s/e;l.x=-t*Math.cos(i+a*r)*Math.sin(n+y*o),l.y=t*Math.cos(n+y*o),l.z=t*Math.sin(i+a*r)*Math.sin(n+y*o),p.push(l.x,l.y,l.z),c.copy(l).normalize(),m.push(c.x,c.y,c.z),g.push(a+x,1-y),f.push(h++)}u.push(f)}for(let t=0;t<s;t++)for(let i=0;i<e;i++){const e=u[t][i+1],r=u[t][i],o=u[t+1][i],h=u[t+1][i+1];(0!==t||n>0)&&d.push(e,r,h),(t!==s-1||a<Math.PI)&&d.push(r,o,h)}this.setIndex(d),this.setAttribute("position",new yn(p,3)),this.setAttribute("normal",new yn(m,3)),this.setAttribute("uv",new yn(g,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new fu(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class yu extends Nh{constructor(t=1,e=0){super([1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e),this.type="TetrahedronGeometry",this.parameters={radius:t,detail:e}}static fromJSON(t){return new yu(t.radius,t.detail)}}class xu extends Mn{constructor(t=1,e=.4,s=12,i=48,r=2*Math.PI){super(),this.type="TorusGeometry",this.parameters={radius:t,tube:e,radialSegments:s,tubularSegments:i,arc:r},s=Math.floor(s),i=Math.floor(i);const n=[],o=[],a=[],h=[],u=new Ei,l=new Ei,c=new Ei;for(let n=0;n<=s;n++)for(let d=0;d<=i;d++){const p=d/i*r,m=n/s*Math.PI*2;l.x=(t+e*Math.cos(m))*Math.cos(p),l.y=(t+e*Math.cos(m))*Math.sin(p),l.z=e*Math.sin(m),o.push(l.x,l.y,l.z),u.x=t*Math.cos(p),u.y=t*Math.sin(p),c.subVectors(l,u).normalize(),a.push(c.x,c.y,c.z),h.push(d/i),h.push(n/s)}for(let t=1;t<=s;t++)for(let e=1;e<=i;e++){const s=(i+1)*t+e-1,r=(i+1)*(t-1)+e-1,o=(i+1)*(t-1)+e,a=(i+1)*t+e;n.push(s,r,a),n.push(r,o,a)}this.setIndex(n),this.setAttribute("position",new yn(o,3)),this.setAttribute("normal",new yn(a,3)),this.setAttribute("uv",new yn(h,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new xu(t.radius,t.tube,t.radialSegments,t.tubularSegments,t.arc)}}class bu extends Mn{constructor(t=1,e=.4,s=64,i=8,r=2,n=3){super(),this.type="TorusKnotGeometry",this.parameters={radius:t,tube:e,tubularSegments:s,radialSegments:i,p:r,q:n},s=Math.floor(s),i=Math.floor(i);const o=[],a=[],h=[],u=[],l=new Ei,c=new Ei,d=new Ei,p=new Ei,m=new Ei,g=new Ei,f=new Ei;for(let o=0;o<=s;++o){const x=o/s*r*Math.PI*2;y(x,r,n,t,d),y(x+.01,r,n,t,p),g.subVectors(p,d),f.addVectors(p,d),m.crossVectors(g,f),f.crossVectors(m,g),m.normalize(),f.normalize();for(let t=0;t<=i;++t){const r=t/i*Math.PI*2,n=-e*Math.cos(r),p=e*Math.sin(r);l.x=d.x+(n*f.x+p*m.x),l.y=d.y+(n*f.y+p*m.y),l.z=d.z+(n*f.z+p*m.z),a.push(l.x,l.y,l.z),c.subVectors(l,d).normalize(),h.push(c.x,c.y,c.z),u.push(o/s),u.push(t/i)}}for(let t=1;t<=s;t++)for(let e=1;e<=i;e++){const s=(i+1)*(t-1)+(e-1),r=(i+1)*t+(e-1),n=(i+1)*t+e,a=(i+1)*(t-1)+e;o.push(s,r,a),o.push(r,n,a)}function y(t,e,s,i,r){const n=Math.cos(t),o=Math.sin(t),a=s/e*t,h=Math.cos(a);r.x=i*(2+h)*.5*n,r.y=i*(2+h)*o*.5,r.z=i*Math.sin(a)*.5}this.setIndex(o),this.setAttribute("position",new yn(a,3)),this.setAttribute("normal",new yn(h,3)),this.setAttribute("uv",new yn(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new bu(t.radius,t.tube,t.tubularSegments,t.radialSegments,t.p,t.q)}}class vu extends Mn{constructor(t=new yh(new Ei(-1,-1,0),new Ei(-1,1,0),new Ei(1,1,0)),e=64,s=1,i=8,r=!1){super(),this.type="TubeGeometry",this.parameters={path:t,tubularSegments:e,radius:s,radialSegments:i,closed:r};const n=t.computeFrenetFrames(e,r);this.tangents=n.tangents,this.normals=n.normals,this.binormals=n.binormals;const o=new Ei,a=new Ei,h=new Ks;let u=new Ei;const l=[],c=[],d=[],p=[];function m(r){u=t.getPointAt(r/e,u);const h=n.normals[r],d=n.binormals[r];for(let t=0;t<=i;t++){const e=t/i*Math.PI*2,r=Math.sin(e),n=-Math.cos(e);a.x=n*h.x+r*d.x,a.y=n*h.y+r*d.y,a.z=n*h.z+r*d.z,a.normalize(),c.push(a.x,a.y,a.z),o.x=u.x+s*a.x,o.y=u.y+s*a.y,o.z=u.z+s*a.z,l.push(o.x,o.y,o.z)}}!function(){for(let t=0;t<e;t++)m(t);m(!1===r?e:0),function(){for(let t=0;t<=e;t++)for(let s=0;s<=i;s++)h.x=t/e,h.y=s/i,d.push(h.x,h.y)}(),function(){for(let t=1;t<=e;t++)for(let e=1;e<=i;e++){const s=(i+1)*(t-1)+(e-1),r=(i+1)*t+(e-1),n=(i+1)*t+e,o=(i+1)*(t-1)+e;p.push(s,r,o),p.push(r,n,o)}}()}(),this.setIndex(p),this.setAttribute("position",new yn(l,3)),this.setAttribute("normal",new yn(c,3)),this.setAttribute("uv",new yn(d,2))}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 vu((new bh[t.path.type]).fromJSON(t.path),t.tubularSegments,t.radius,t.radialSegments,t.closed)}}class Tu extends Mn{constructor(t=null){if(super(),this.type="WireframeGeometry",this.parameters={geometry:t},null!==t){const e=[],s=new Set,i=new Ei,r=new Ei;if(null!==t.index){const n=t.attributes.position,o=t.index;let a=t.groups;0===a.length&&(a=[{start:0,count:o.count,materialIndex:0}]);for(let t=0,h=a.length;t<h;++t){const h=a[t],u=h.start;for(let t=u,a=u+h.count;t<a;t+=3)for(let a=0;a<3;a++){const h=o.getX(t+a),u=o.getX(t+(a+1)%3);i.fromBufferAttribute(n,h),r.fromBufferAttribute(n,u),!0===_u(i,r,s)&&(e.push(i.x,i.y,i.z),e.push(r.x,r.y,r.z))}}}else{const n=t.attributes.position;for(let t=0,o=n.count/3;t<o;t++)for(let o=0;o<3;o++){const a=3*t+o,h=3*t+(o+1)%3;i.fromBufferAttribute(n,a),r.fromBufferAttribute(n,h),!0===_u(i,r,s)&&(e.push(i.x,i.y,i.z),e.push(r.x,r.y,r.z))}}this.setAttribute("position",new yn(e,3))}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}}function _u(t,e,s){const i=`${t.x},${t.y},${t.z}-${e.x},${e.y},${e.z}`,r=`${e.x},${e.y},${e.z}-${t.x},${t.y},${t.z}`;return!0!==s.has(i)&&!0!==s.has(r)&&(s.add(i),s.add(r),!0)}var wu=Object.freeze({__proto__:null,BoxGeometry:Hn,CapsuleGeometry:wh,CircleGeometry:Sh,ConeGeometry:Ah,CylinderGeometry:Mh,DodecahedronGeometry:Rh,EdgesGeometry:Ph,ExtrudeGeometry:uu,IcosahedronGeometry:cu,LatheGeometry:_h,OctahedronGeometry:du,PlaneGeometry:pu,PolyhedronGeometry:Nh,RingGeometry:mu,ShapeGeometry:gu,SphereGeometry:fu,TetrahedronGeometry:yu,TorusGeometry:xu,TorusKnotGeometry:bu,TubeGeometry:vu,WireframeGeometry:Tu});class Su extends Qr{constructor(t){super(),this.isShadowMaterial=!0,this.type="ShadowMaterial",this.color=new Yr(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 Mu extends $n{constructor(t){super(t),this.isRawShaderMaterial=!0,this.type="RawShaderMaterial"}}class Au extends Qr{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new Yr(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 Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(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 fr,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 Nu extends Au{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 Ks(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return $s(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.iridescenceMap=null,this.iridescenceIOR=1.3,this.iridescenceThicknessRange=[100,400],this.iridescenceThicknessMap=null,this.sheenColor=new Yr(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 Yr(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new Yr(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 Ru extends Qr{constructor(t){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new Yr(16777215),this.specular=new Yr(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,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 Cu extends Qr{constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new Yr(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(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 Eu extends Qr{constructor(t){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(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 Bu extends Qr{constructor(t){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new Yr(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Yr(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new fr,this.combine=0,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 Iu extends Qr{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,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 Pu extends Qr{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 Fu extends Qr{constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new Yr(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Ks(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 Uu extends Ma{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 zu(t,e,s){return!t||!s&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)}function Ou(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function Lu(t){const e=t.length,s=new Array(e);for(let t=0;t!==e;++t)s[t]=t;return s.sort((function(e,s){return t[e]-t[s]})),s}function Vu(t,e,s){const i=t.length,r=new t.constructor(i);for(let n=0,o=0;o!==i;++n){const i=s[n]*e;for(let s=0;s!==e;++s)r[o++]=t[i+s]}return r}function Du(t,e,s,i){let r=1,n=t[0];for(;void 0!==n&&void 0===n[i];)n=t[r++];if(void 0===n)return;let o=n[i];if(void 0!==o)if(Array.isArray(o))do{o=n[i],void 0!==o&&(e.push(n.time),s.push.apply(s,o)),n=t[r++]}while(void 0!==n);else if(void 0!==o.toArray)do{o=n[i],void 0!==o&&(e.push(n.time),o.toArray(s,s.length)),n=t[r++]}while(void 0!==n);else do{o=n[i],void 0!==o&&(e.push(n.time),s.push(o)),n=t[r++]}while(void 0!==n)}const ku={convertArray:zu,isTypedArray:Ou,getKeyframeOrder:Lu,sortedArray:Vu,flattenJSON:Du,subclip:function(t,e,s,i,r=30){const n=t.clone();n.name=e;const o=[];for(let t=0;t<n.tracks.length;++t){const e=n.tracks[t],a=e.getValueSize(),h=[],u=[];for(let t=0;t<e.times.length;++t){const n=e.times[t]*r;if(!(n<s||n>=i)){h.push(e.times[t]);for(let s=0;s<a;++s)u.push(e.values[t*a+s])}}0!==h.length&&(e.times=zu(h,e.times.constructor),e.values=zu(u,e.values.constructor),o.push(e))}n.tracks=o;let a=1/0;for(let t=0;t<n.tracks.length;++t)a>n.tracks[t].times[0]&&(a=n.tracks[t].times[0]);for(let t=0;t<n.tracks.length;++t)n.tracks[t].shift(-1*a);return n.resetDuration(),n},makeClipAdditive:function(t,e=0,s=t,i=30){i<=0&&(i=30);const r=s.tracks.length,n=e/i;for(let e=0;e<r;++e){const i=s.tracks[e],r=i.ValueTypeName;if("bool"===r||"string"===r)continue;const o=t.tracks.find((function(t){return t.name===i.name&&t.ValueTypeName===r}));if(void 0===o)continue;let a=0;const h=i.getValueSize();i.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(a=h/3);let u=0;const l=o.getValueSize();o.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(u=l/3);const c=i.times.length-1;let d;if(n<=i.times[0]){const t=a,e=h-a;d=i.values.slice(t,e)}else if(n>=i.times[c]){const t=c*h+a,e=t+h-a;d=i.values.slice(t,e)}else{const t=i.createInterpolant(),e=a,s=h-a;t.evaluate(n),d=t.resultBuffer.slice(e,s)}if("quaternion"===r){(new Ci).fromArray(d).normalize().conjugate().toArray(d)}const p=o.times.length;for(let t=0;t<p;++t){const e=t*l+u;if("quaternion"===r)Ci.multiplyQuaternionsFlat(o.values,e,d,0,o.values,e);else{const t=l-2*u;for(let s=0;s<t;++s)o.values[e+s]-=d[s]}}}return t.blendMode=Ve,t}};class Gu{constructor(t,e,s,i){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=void 0!==i?i:new e.constructor(s),this.sampleValues=e,this.valueSize=s,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let s=this._cachedIndex,i=e[s],r=e[s-1];t:{e:{let n;s:{i:if(!(t<i)){for(let n=s+2;;){if(void 0===i){if(t<r)break i;return s=e.length,this._cachedIndex=s,this.copySampleValue_(s-1)}if(s===n)break;if(r=i,i=e[++s],t<i)break e}n=e.length;break s}if(t>=r)break t;{const o=e[1];t<o&&(s=2,r=o);for(let n=s-2;;){if(void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(s===n)break;if(i=r,r=e[--s-1],t>=r)break e}n=s,s=0}}for(;s<n;){const i=s+n>>>1;t<e[i]?n=i:s=i+1}if(i=e[s],r=e[s-1],void 0===r)return this._cachedIndex=0,this.copySampleValue_(0);if(void 0===i)return s=e.length,this._cachedIndex=s,this.copySampleValue_(s-1)}this._cachedIndex=s,this.intervalChanged_(s,r,i)}return this.interpolate_(s,r,t,i)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,s=this.sampleValues,i=this.valueSize,r=t*i;for(let t=0;t!==i;++t)e[t]=s[r+t];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}class Wu extends Gu{constructor(t,e,s,i){super(t,e,s,i),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Ue,endingEnd:Ue}}intervalChanged_(t,e,s){const i=this.parameterPositions;let r=t-2,n=t+1,o=i[r],a=i[n];if(void 0===o)switch(this.getSettings_().endingStart){case ze:r=t,o=2*e-s;break;case Oe:r=i.length-2,o=e+i[r]-i[r+1];break;default:r=t,o=s}if(void 0===a)switch(this.getSettings_().endingEnd){case ze:n=t,a=2*s-e;break;case Oe:n=1,a=s+i[1]-i[0];break;default:n=t-1,a=e}const h=.5*(s-e),u=this.valueSize;this._weightPrev=h/(e-o),this._weightNext=h/(a-s),this._offsetPrev=r*u,this._offsetNext=n*u}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=t*o,h=a-o,u=this._offsetPrev,l=this._offsetNext,c=this._weightPrev,d=this._weightNext,p=(s-e)/(i-e),m=p*p,g=m*p,f=-c*g+2*c*m-c*p,y=(1+c)*g+(-1.5-2*c)*m+(-.5+c)*p+1,x=(-1-d)*g+(1.5+d)*m+.5*p,b=d*g-d*m;for(let t=0;t!==o;++t)r[t]=f*n[u+t]+y*n[h+t]+x*n[a+t]+b*n[l+t];return r}}class ju extends Gu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=t*o,h=a-o,u=(s-e)/(i-e),l=1-u;for(let t=0;t!==o;++t)r[t]=n[h+t]*l+n[a+t]*u;return r}}class Hu extends Gu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t){return this.copySampleValue_(t-1)}}class qu{constructor(t,e,s,i){if(void 0===t)throw new Error("THREE.KeyframeTrack: track name is undefined");if(void 0===e||0===e.length)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=zu(e,this.TimeBufferType),this.values=zu(s,this.ValueBufferType),this.setInterpolation(i||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let s;if(e.toJSON!==this.toJSON)s=e.toJSON(t);else{s={name:t.name,times:zu(t.times,Array),values:zu(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(s.interpolation=e)}return s.type=t.ValueTypeName,s}InterpolantFactoryMethodDiscrete(t){return new Hu(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new ju(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Wu(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case Ie:e=this.InterpolantFactoryMethodDiscrete;break;case Pe:e=this.InterpolantFactoryMethodLinear;break;case Fe:e=this.InterpolantFactoryMethodSmooth}if(void 0===e){const e="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(void 0===this.createInterpolant){if(t===this.DefaultInterpolation)throw new Error(e);this.setInterpolation(this.DefaultInterpolation)}return console.warn("THREE.KeyframeTrack:",e),this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return Ie;case this.InterpolantFactoryMethodLinear:return Pe;case this.InterpolantFactoryMethodSmooth:return Fe}}getValueSize(){return this.values.length/this.times.length}shift(t){if(0!==t){const e=this.times;for(let s=0,i=e.length;s!==i;++s)e[s]+=t}return this}scale(t){if(1!==t){const e=this.times;for(let s=0,i=e.length;s!==i;++s)e[s]*=t}return this}trim(t,e){const s=this.times,i=s.length;let r=0,n=i-1;for(;r!==i&&s[r]<t;)++r;for(;-1!==n&&s[n]>e;)--n;if(++n,0!==r||n!==i){r>=n&&(n=Math.max(n,1),r=n-1);const t=this.getValueSize();this.times=s.slice(r,n),this.values=this.values.slice(r*t,n*t)}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 s=this.times,i=this.values,r=s.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);let n=null;for(let e=0;e!==r;e++){const i=s[e];if("number"==typeof i&&isNaN(i)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==n&&n>i){console.error("THREE.KeyframeTrack: Out of order keys.",this,e,i,n),t=!1;break}n=i}if(void 0!==i&&Ou(i))for(let e=0,s=i.length;e!==s;++e){const s=i[e];if(isNaN(s)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,e,s),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),s=this.getValueSize(),i=this.getInterpolation()===Fe,r=t.length-1;let n=1;for(let o=1;o<r;++o){let r=!1;const a=t[o];if(a!==t[o+1]&&(1!==o||a!==t[0]))if(i)r=!0;else{const t=o*s,i=t-s,n=t+s;for(let o=0;o!==s;++o){const s=e[t+o];if(s!==e[i+o]||s!==e[n+o]){r=!0;break}}}if(r){if(o!==n){t[n]=t[o];const i=o*s,r=n*s;for(let t=0;t!==s;++t)e[r+t]=e[i+t]}++n}}if(r>0){t[n]=t[r];for(let t=r*s,i=n*s,o=0;o!==s;++o)e[i+o]=e[t+o];++n}return n!==t.length?(this.times=t.slice(0,n),this.values=e.slice(0,n*s)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),s=new(0,this.constructor)(this.name,t,e);return s.createInterpolant=this.createInterpolant,s}}qu.prototype.TimeBufferType=Float32Array,qu.prototype.ValueBufferType=Float32Array,qu.prototype.DefaultInterpolation=Pe;class $u extends qu{constructor(t,e,s){super(t,e,s)}}$u.prototype.ValueTypeName="bool",$u.prototype.ValueBufferType=Array,$u.prototype.DefaultInterpolation=Ie,$u.prototype.InterpolantFactoryMethodLinear=void 0,$u.prototype.InterpolantFactoryMethodSmooth=void 0;class Xu extends qu{}Xu.prototype.ValueTypeName="color";class Yu extends qu{}Yu.prototype.ValueTypeName="number";class Ju extends Gu{constructor(t,e,s,i){super(t,e,s,i)}interpolate_(t,e,s,i){const r=this.resultBuffer,n=this.sampleValues,o=this.valueSize,a=(s-e)/(i-e);let h=t*o;for(let t=h+o;h!==t;h+=4)Ci.slerpFlat(r,0,n,h-o,n,h,a);return r}}class Zu extends qu{InterpolantFactoryMethodLinear(t){return new Ju(this.times,this.values,this.getValueSize(),t)}}Zu.prototype.ValueTypeName="quaternion",Zu.prototype.InterpolantFactoryMethodSmooth=void 0;class Qu extends qu{constructor(t,e,s){super(t,e,s)}}Qu.prototype.ValueTypeName="string",Qu.prototype.ValueBufferType=Array,Qu.prototype.DefaultInterpolation=Ie,Qu.prototype.InterpolantFactoryMethodLinear=void 0,Qu.prototype.InterpolantFactoryMethodSmooth=void 0;class Ku extends qu{}Ku.prototype.ValueTypeName="vector";class tl{constructor(t="",e=-1,s=[],i=2500){this.name=t,this.tracks=s,this.duration=e,this.blendMode=i,this.uuid=qs(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],s=t.tracks,i=1/(t.fps||1);for(let t=0,r=s.length;t!==r;++t)e.push(el(s[t]).scale(i));const r=new this(t.name,t.duration,e,t.blendMode);return r.uuid=t.uuid,r}static toJSON(t){const e=[],s=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,i=s.length;t!==i;++t)e.push(qu.toJSON(s[t]));return i}static CreateFromMorphTargetSequence(t,e,s,i){const r=e.length,n=[];for(let t=0;t<r;t++){let o=[],a=[];o.push((t+r-1)%r,t,(t+1)%r),a.push(0,1,0);const h=Lu(o);o=Vu(o,1,h),a=Vu(a,1,h),i||0!==o[0]||(o.push(r),a.push(a[0])),n.push(new Yu(".morphTargetInfluences["+e[t].name+"]",o,a).scale(1/s))}return new this(t,-1,n)}static findByName(t,e){let s=t;if(!Array.isArray(t)){const e=t;s=e.geometry&&e.geometry.animations||e.animations}for(let t=0;t<s.length;t++)if(s[t].name===e)return s[t];return null}static CreateClipsFromMorphTargetSequences(t,e,s){const i={},r=/^([\w-]*?)([\d]+)$/;for(let e=0,s=t.length;e<s;e++){const s=t[e],n=s.name.match(r);if(n&&n.length>1){const t=n[1];let e=i[t];e||(i[t]=e=[]),e.push(s)}}const n=[];for(const t in i)n.push(this.CreateFromMorphTargetSequence(t,i[t],e,s));return n}static parseAnimation(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const s=function(t,e,s,i,r){if(0!==s.length){const n=[],o=[];Du(s,n,o,i),0!==n.length&&r.push(new t(e,n,o))}},i=[],r=t.name||"default",n=t.fps||30,o=t.blendMode;let a=t.length||-1;const h=t.hierarchy||[];for(let t=0;t<h.length;t++){const r=h[t].keys;if(r&&0!==r.length)if(r[0].morphTargets){const t={};let e;for(e=0;e<r.length;e++)if(r[e].morphTargets)for(let s=0;s<r[e].morphTargets.length;s++)t[r[e].morphTargets[s]]=-1;for(const s in t){const t=[],n=[];for(let i=0;i!==r[e].morphTargets.length;++i){const i=r[e];t.push(i.time),n.push(i.morphTarget===s?1:0)}i.push(new Yu(".morphTargetInfluence["+s+"]",t,n))}a=t.length*n}else{const n=".bones["+e[t].name+"]";s(Ku,n+".position",r,"pos",i),s(Zu,n+".quaternion",r,"rot",i),s(Ku,n+".scale",r,"scl",i)}}if(0===i.length)return null;return new this(r,a,i,o)}resetDuration(){let t=0;for(let e=0,s=this.tracks.length;e!==s;++e){const s=this.tracks[e];t=Math.max(t,s.times[s.times.length-1])}return this.duration=t,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 el(t){if(void 0===t.type)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=function(t){switch(t.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Yu;case"vector":case"vector2":case"vector3":case"vector4":return Ku;case"color":return Xu;case"quaternion":return Zu;case"bool":case"boolean":return $u;case"string":return Qu}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],s=[];Du(t.keys,e,s,"value"),t.times=e,t.values=s}return void 0!==e.parse?e.parse(t):new e(t.name,t.times,t.values,t.interpolation)}const sl={enabled:!1,files:{},add:function(t,e){!1!==this.enabled&&(this.files[t]=e)},get:function(t){if(!1!==this.enabled)return this.files[t]},remove:function(t){delete this.files[t]},clear:function(){this.files={}}};class il{constructor(t,e,s){const i=this;let r,n=!1,o=0,a=0;const h=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=s,this.itemStart=function(t){a++,!1===n&&void 0!==i.onStart&&i.onStart(t,o,a),n=!0},this.itemEnd=function(t){o++,void 0!==i.onProgress&&i.onProgress(t,o,a),o===a&&(n=!1,void 0!==i.onLoad&&i.onLoad())},this.itemError=function(t){void 0!==i.onError&&i.onError(t)},this.resolveURL=function(t){return r?r(t):t},this.setURLModifier=function(t){return r=t,this},this.addHandler=function(t,e){return h.push(t,e),this},this.removeHandler=function(t){const e=h.indexOf(t);return-1!==e&&h.splice(e,2),this},this.getHandler=function(t){for(let e=0,s=h.length;e<s;e+=2){const s=h[e],i=h[e+1];if(s.global&&(s.lastIndex=0),s.test(t))return i}return null}}}const rl=new il;class nl{constructor(t){this.manager=void 0!==t?t:rl,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const s=this;return new Promise((function(i,r){s.load(t,i,e,r)}))}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}}nl.DEFAULT_MATERIAL_NAME="__DEFAULT";const ol={};class al extends Error{constructor(t,e){super(t),this.response=e}}class hl extends nl{constructor(t){super(t)}load(t,e,s,i){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=sl.get(t);if(void 0!==r)return this.manager.itemStart(t),setTimeout((()=>{e&&e(r),this.manager.itemEnd(t)}),0),r;if(void 0!==ol[t])return void ol[t].push({onLoad:e,onProgress:s,onError:i});ol[t]=[],ol[t].push({onLoad:e,onProgress:s,onError:i});const n=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),o=this.mimeType,a=this.responseType;fetch(n).then((e=>{if(200===e.status||0===e.status){if(0===e.status&&console.warn("THREE.FileLoader: HTTP Status 0 received."),"undefined"==typeof ReadableStream||void 0===e.body||void 0===e.body.getReader)return e;const s=ol[t],i=e.body.getReader(),r=e.headers.get("X-File-Size")||e.headers.get("Content-Length"),n=r?parseInt(r):0,o=0!==n;let a=0;const h=new ReadableStream({start(t){!function e(){i.read().then((({done:i,value:r})=>{if(i)t.close();else{a+=r.byteLength;const i=new ProgressEvent("progress",{lengthComputable:o,loaded:a,total:n});for(let t=0,e=s.length;t<e;t++){const e=s[t];e.onProgress&&e.onProgress(i)}t.enqueue(r),e()}}),(e=>{t.error(e)}))}()}});return new Response(h)}throw new al(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`,e)})).then((t=>{switch(a){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,o)));case"json":return t.json();default:if(void 0===o)return t.text();{const e=/charset="?([^;"\s]*)"?/i.exec(o),s=e&&e[1]?e[1].toLowerCase():void 0,i=new TextDecoder(s);return t.arrayBuffer().then((t=>i.decode(t)))}}})).then((e=>{sl.add(t,e);const s=ol[t];delete ol[t];for(let t=0,i=s.length;t<i;t++){const i=s[t];i.onLoad&&i.onLoad(e)}})).catch((e=>{const s=ol[t];if(void 0===s)throw this.manager.itemError(t),e;delete ol[t];for(let t=0,i=s.length;t<i;t++){const i=s[t];i.onError&&i.onError(e)}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 ul extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=[];for(let s=0;s<t.length;s++){const i=tl.parse(t[s]);e.push(i)}return e}}class ll extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=[],o=new Ya,a=new hl(this.manager);a.setPath(this.path),a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setWithCredentials(r.withCredentials);let h=0;function u(u){a.load(t[u],(function(t){const s=r.parse(t,!0);n[u]={width:s.width,height:s.height,format:s.format,mipmaps:s.mipmaps},h+=1,6===h&&(1===s.mipmapCount&&(o.minFilter=Tt),o.image=n,o.format=s.format,o.needsUpdate=!0,e&&e(o))}),s,i)}if(Array.isArray(t))for(let e=0,s=t.length;e<s;++e)u(e);else a.load(t,(function(t){const s=r.parse(t,!0);if(s.isCubemap){const t=s.mipmaps.length/s.mipmapCount;for(let e=0;e<t;e++){n[e]={mipmaps:[]};for(let t=0;t<s.mipmapCount;t++)n[e].mipmaps.push(s.mipmaps[e*s.mipmapCount+t]),n[e].format=s.format,n[e].width=s.width,n[e].height=s.height}o.image=n}else o.image.width=s.width,o.image.height=s.height,o.mipmaps=s.mipmaps;1===s.mipmapCount&&(o.minFilter=Tt),o.format=s.format,o.needsUpdate=!0,e&&e(o)}),s,i);return o}}class cl extends nl{constructor(t){super(t)}load(t,e,s,i){void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,n=sl.get(t);if(void 0!==n)return r.manager.itemStart(t),setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n;const o=ri("img");function a(){u(),sl.add(t,this),e&&e(this),r.manager.itemEnd(t)}function h(e){u(),i&&i(e),r.manager.itemError(t),r.manager.itemEnd(t)}function u(){o.removeEventListener("load",a,!1),o.removeEventListener("error",h,!1)}return o.addEventListener("load",a,!1),o.addEventListener("error",h,!1),"data:"!==t.slice(0,5)&&void 0!==this.crossOrigin&&(o.crossOrigin=this.crossOrigin),r.manager.itemStart(t),o.src=t,o}}class dl extends nl{constructor(t){super(t)}load(t,e,s,i){const r=new eo;r.colorSpace=Je;const n=new cl(this.manager);n.setCrossOrigin(this.crossOrigin),n.setPath(this.path);let o=0;function a(s){n.load(t[s],(function(t){r.images[s]=t,o++,6===o&&(r.needsUpdate=!0,e&&e(r))}),void 0,i)}for(let e=0;e<t.length;++e)a(e);return r}}class pl extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new Do,o=new hl(this.manager);return o.setResponseType("arraybuffer"),o.setRequestHeader(this.requestHeader),o.setPath(this.path),o.setWithCredentials(r.withCredentials),o.load(t,(function(t){let s;try{s=r.parse(t)}catch(t){if(void 0===i)return void console.error(t);i(t)}void 0!==s.image?n.image=s.image:void 0!==s.data&&(n.image.width=s.width,n.image.height=s.height,n.image.data=s.data),n.wrapS=void 0!==s.wrapS?s.wrapS:mt,n.wrapT=void 0!==s.wrapT?s.wrapT:mt,n.magFilter=void 0!==s.magFilter?s.magFilter:Tt,n.minFilter=void 0!==s.minFilter?s.minFilter:Tt,n.anisotropy=void 0!==s.anisotropy?s.anisotropy:1,void 0!==s.colorSpace&&(n.colorSpace=s.colorSpace),void 0!==s.flipY&&(n.flipY=s.flipY),void 0!==s.format&&(n.format=s.format),void 0!==s.type&&(n.type=s.type),void 0!==s.mipmaps&&(n.mipmaps=s.mipmaps,n.minFilter=St),1===s.mipmapCount&&(n.minFilter=Tt),void 0!==s.generateMipmaps&&(n.generateMipmaps=s.generateMipmaps),n.needsUpdate=!0,e&&e(n,s)}),s,i),n}}class ml extends nl{constructor(t){super(t)}load(t,e,s,i){const r=new Ti,n=new cl(this.manager);return n.setCrossOrigin(this.crossOrigin),n.setPath(this.path),n.load(t,(function(t){r.image=t,r.needsUpdate=!0,void 0!==e&&e(r)}),s,i),r}}class gl extends Pr{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Yr(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,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),void 0!==this.target&&(e.object.target=this.target.uuid),e}}class fl extends gl{constructor(t,e,s){super(t,s),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Yr(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const yl=new or,xl=new Ei,bl=new Ei;class vl{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Ks(512,512),this.map=null,this.mapPass=null,this.matrix=new or,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new na,this._frameExtents=new Ks(1,1),this._viewportCount=1,this._viewports=[new _i(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,s=this.matrix;xl.setFromMatrixPosition(t.matrixWorld),e.position.copy(xl),bl.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(bl),e.updateMatrixWorld(),yl.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(yl),s.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),s.multiply(yl)}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 1!==this.intensity&&(t.intensity=this.intensity),0!==this.bias&&(t.bias=this.bias),0!==this.normalBias&&(t.normalBias=this.normalBias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class Tl extends vl{constructor(){super(new Qn(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,s=2*Hs*t.angle*this.focus,i=this.mapSize.width/this.mapSize.height,r=t.distance||e.far;s===e.fov&&i===e.aspect&&r===e.far||(e.fov=s,e.aspect=i,e.far=r,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class _l extends gl{constructor(t,e,s=0,i=Math.PI/3,r=0,n=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.target=new Pr,this.distance=s,this.angle=i,this.penumbra=r,this.decay=n,this.map=null,this.shadow=new Tl}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 wl=new or,Sl=new Ei,Ml=new Ei;class Al extends vl{constructor(){super(new Qn(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new Ks(4,2),this._viewportCount=6,this._viewports=[new _i(2,1,1,1),new _i(0,1,1,1),new _i(3,1,1,1),new _i(1,1,1,1),new _i(3,0,1,1),new _i(1,0,1,1)],this._cubeDirections=[new Ei(1,0,0),new Ei(-1,0,0),new Ei(0,0,1),new Ei(0,0,-1),new Ei(0,1,0),new Ei(0,-1,0)],this._cubeUps=[new Ei(0,1,0),new Ei(0,1,0),new Ei(0,1,0),new Ei(0,1,0),new Ei(0,0,1),new Ei(0,0,-1)]}updateMatrices(t,e=0){const s=this.camera,i=this.matrix,r=t.distance||s.far;r!==s.far&&(s.far=r,s.updateProjectionMatrix()),Sl.setFromMatrixPosition(t.matrixWorld),s.position.copy(Sl),Ml.copy(s.position),Ml.add(this._cubeDirections[e]),s.up.copy(this._cubeUps[e]),s.lookAt(Ml),s.updateMatrixWorld(),i.makeTranslation(-Sl.x,-Sl.y,-Sl.z),wl.multiplyMatrices(s.projectionMatrix,s.matrixWorldInverse),this._frustum.setFromProjectionMatrix(wl)}}class Nl extends gl{constructor(t,e,s=0,i=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=s,this.decay=i,this.shadow=new Al}get power(){return 4*this.intensity*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 Rl extends Xn{constructor(t=-1,e=1,s=1,i=-1,r=.1,n=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=s,this.bottom=i,this.near=r,this.far=n,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=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,s,i,r,n){null===this.view&&(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=s,this.view.offsetY=i,this.view.width=r,this.view.height=n,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),s=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=s-t,n=s+t,o=i+e,a=i-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=t*this.view.offsetX,n=r+t*this.view.width,o-=e*this.view.offsetY,a=o-e*this.view.height}this.projectionMatrix.makeOrthographic(r,n,o,a,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,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}class Cl extends vl{constructor(){super(new Rl(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class El extends gl{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Pr.DEFAULT_UP),this.updateMatrix(),this.target=new Pr,this.shadow=new Cl}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Bl extends gl{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class Il extends gl{constructor(t,e,s=10,i=10){super(t,e),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=s,this.height=i}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 Pl{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Ei)}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 s=t.x,i=t.y,r=t.z,n=this.coefficients;return e.copy(n[0]).multiplyScalar(.282095),e.addScaledVector(n[1],.488603*i),e.addScaledVector(n[2],.488603*r),e.addScaledVector(n[3],.488603*s),e.addScaledVector(n[4],s*i*1.092548),e.addScaledVector(n[5],i*r*1.092548),e.addScaledVector(n[6],.315392*(3*r*r-1)),e.addScaledVector(n[7],s*r*1.092548),e.addScaledVector(n[8],.546274*(s*s-i*i)),e}getIrradianceAt(t,e){const s=t.x,i=t.y,r=t.z,n=this.coefficients;return e.copy(n[0]).multiplyScalar(.886227),e.addScaledVector(n[1],1.023328*i),e.addScaledVector(n[2],1.023328*r),e.addScaledVector(n[3],1.023328*s),e.addScaledVector(n[4],.858086*s*i),e.addScaledVector(n[5],.858086*i*r),e.addScaledVector(n[6],.743125*r*r-.247708),e.addScaledVector(n[7],.858086*s*r),e.addScaledVector(n[8],.429043*(s*s-i*i)),e}add(t){for(let e=0;e<9;e++)this.coefficients[e].add(t.coefficients[e]);return this}addScaledSH(t,e){for(let s=0;s<9;s++)this.coefficients[s].addScaledVector(t.coefficients[s],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let s=0;s<9;s++)this.coefficients[s].lerp(t.coefficients[s],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 s=this.coefficients;for(let i=0;i<9;i++)s[i].fromArray(t,e+3*i);return this}toArray(t=[],e=0){const s=this.coefficients;for(let i=0;i<9;i++)s[i].toArray(t,e+3*i);return t}static getBasisAt(t,e){const s=t.x,i=t.y,r=t.z;e[0]=.282095,e[1]=.488603*i,e[2]=.488603*r,e[3]=.488603*s,e[4]=1.092548*s*i,e[5]=1.092548*i*r,e[6]=.315392*(3*r*r-1),e[7]=1.092548*s*r,e[8]=.546274*(s*s-i*i)}}class Fl extends gl{constructor(t=new Pl,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 Ul extends nl{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=this,n=new hl(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e=this.textures;function s(t){return void 0===e[t]&&console.warn("THREE.MaterialLoader: Undefined texture",t),e[t]}const i=Ul.createMaterialFromType(t.type);if(void 0!==t.uuid&&(i.uuid=t.uuid),void 0!==t.name&&(i.name=t.name),void 0!==t.color&&void 0!==i.color&&i.color.setHex(t.color),void 0!==t.roughness&&(i.roughness=t.roughness),void 0!==t.metalness&&(i.metalness=t.metalness),void 0!==t.sheen&&(i.sheen=t.sheen),void 0!==t.sheenColor&&(i.sheenColor=(new Yr).setHex(t.sheenColor)),void 0!==t.sheenRoughness&&(i.sheenRoughness=t.sheenRoughness),void 0!==t.emissive&&void 0!==i.emissive&&i.emissive.setHex(t.emissive),void 0!==t.specular&&void 0!==i.specular&&i.specular.setHex(t.specular),void 0!==t.specularIntensity&&(i.specularIntensity=t.specularIntensity),void 0!==t.specularColor&&void 0!==i.specularColor&&i.specularColor.setHex(t.specularColor),void 0!==t.shininess&&(i.shininess=t.shininess),void 0!==t.clearcoat&&(i.clearcoat=t.clearcoat),void 0!==t.clearcoatRoughness&&(i.clearcoatRoughness=t.clearcoatRoughness),void 0!==t.dispersion&&(i.dispersion=t.dispersion),void 0!==t.iridescence&&(i.iridescence=t.iridescence),void 0!==t.iridescenceIOR&&(i.iridescenceIOR=t.iridescenceIOR),void 0!==t.iridescenceThicknessRange&&(i.iridescenceThicknessRange=t.iridescenceThicknessRange),void 0!==t.transmission&&(i.transmission=t.transmission),void 0!==t.thickness&&(i.thickness=t.thickness),void 0!==t.attenuationDistance&&(i.attenuationDistance=t.attenuationDistance),void 0!==t.attenuationColor&&void 0!==i.attenuationColor&&i.attenuationColor.setHex(t.attenuationColor),void 0!==t.anisotropy&&(i.anisotropy=t.anisotropy),void 0!==t.anisotropyRotation&&(i.anisotropyRotation=t.anisotropyRotation),void 0!==t.fog&&(i.fog=t.fog),void 0!==t.flatShading&&(i.flatShading=t.flatShading),void 0!==t.blending&&(i.blending=t.blending),void 0!==t.combine&&(i.combine=t.combine),void 0!==t.side&&(i.side=t.side),void 0!==t.shadowSide&&(i.shadowSide=t.shadowSide),void 0!==t.opacity&&(i.opacity=t.opacity),void 0!==t.transparent&&(i.transparent=t.transparent),void 0!==t.alphaTest&&(i.alphaTest=t.alphaTest),void 0!==t.alphaHash&&(i.alphaHash=t.alphaHash),void 0!==t.depthFunc&&(i.depthFunc=t.depthFunc),void 0!==t.depthTest&&(i.depthTest=t.depthTest),void 0!==t.depthWrite&&(i.depthWrite=t.depthWrite),void 0!==t.colorWrite&&(i.colorWrite=t.colorWrite),void 0!==t.blendSrc&&(i.blendSrc=t.blendSrc),void 0!==t.blendDst&&(i.blendDst=t.blendDst),void 0!==t.blendEquation&&(i.blendEquation=t.blendEquation),void 0!==t.blendSrcAlpha&&(i.blendSrcAlpha=t.blendSrcAlpha),void 0!==t.blendDstAlpha&&(i.blendDstAlpha=t.blendDstAlpha),void 0!==t.blendEquationAlpha&&(i.blendEquationAlpha=t.blendEquationAlpha),void 0!==t.blendColor&&void 0!==i.blendColor&&i.blendColor.setHex(t.blendColor),void 0!==t.blendAlpha&&(i.blendAlpha=t.blendAlpha),void 0!==t.stencilWriteMask&&(i.stencilWriteMask=t.stencilWriteMask),void 0!==t.stencilFunc&&(i.stencilFunc=t.stencilFunc),void 0!==t.stencilRef&&(i.stencilRef=t.stencilRef),void 0!==t.stencilFuncMask&&(i.stencilFuncMask=t.stencilFuncMask),void 0!==t.stencilFail&&(i.stencilFail=t.stencilFail),void 0!==t.stencilZFail&&(i.stencilZFail=t.stencilZFail),void 0!==t.stencilZPass&&(i.stencilZPass=t.stencilZPass),void 0!==t.stencilWrite&&(i.stencilWrite=t.stencilWrite),void 0!==t.wireframe&&(i.wireframe=t.wireframe),void 0!==t.wireframeLinewidth&&(i.wireframeLinewidth=t.wireframeLinewidth),void 0!==t.wireframeLinecap&&(i.wireframeLinecap=t.wireframeLinecap),void 0!==t.wireframeLinejoin&&(i.wireframeLinejoin=t.wireframeLinejoin),void 0!==t.rotation&&(i.rotation=t.rotation),void 0!==t.linewidth&&(i.linewidth=t.linewidth),void 0!==t.dashSize&&(i.dashSize=t.dashSize),void 0!==t.gapSize&&(i.gapSize=t.gapSize),void 0!==t.scale&&(i.scale=t.scale),void 0!==t.polygonOffset&&(i.polygonOffset=t.polygonOffset),void 0!==t.polygonOffsetFactor&&(i.polygonOffsetFactor=t.polygonOffsetFactor),void 0!==t.polygonOffsetUnits&&(i.polygonOffsetUnits=t.polygonOffsetUnits),void 0!==t.dithering&&(i.dithering=t.dithering),void 0!==t.alphaToCoverage&&(i.alphaToCoverage=t.alphaToCoverage),void 0!==t.premultipliedAlpha&&(i.premultipliedAlpha=t.premultipliedAlpha),void 0!==t.forceSinglePass&&(i.forceSinglePass=t.forceSinglePass),void 0!==t.visible&&(i.visible=t.visible),void 0!==t.toneMapped&&(i.toneMapped=t.toneMapped),void 0!==t.userData&&(i.userData=t.userData),void 0!==t.vertexColors&&("number"==typeof t.vertexColors?i.vertexColors=t.vertexColors>0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(const e in t.uniforms){const r=t.uniforms[e];switch(i.uniforms[e]={},r.type){case"t":i.uniforms[e].value=s(r.value);break;case"c":i.uniforms[e].value=(new Yr).setHex(r.value);break;case"v2":i.uniforms[e].value=(new Ks).fromArray(r.value);break;case"v3":i.uniforms[e].value=(new Ei).fromArray(r.value);break;case"v4":i.uniforms[e].value=(new _i).fromArray(r.value);break;case"m3":i.uniforms[e].value=(new ti).fromArray(r.value);break;case"m4":i.uniforms[e].value=(new or).fromArray(r.value);break;default:i.uniforms[e].value=r.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.glslVersion&&(i.glslVersion=t.glslVersion),void 0!==t.extensions)for(const e in t.extensions)i.extensions[e]=t.extensions[e];if(void 0!==t.lights&&(i.lights=t.lights),void 0!==t.clipping&&(i.clipping=t.clipping),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=s(t.map)),void 0!==t.matcap&&(i.matcap=s(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=s(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=s(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=s(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){let e=t.normalScale;!1===Array.isArray(e)&&(e=[e,e]),i.normalScale=(new Ks).fromArray(e)}return void 0!==t.displacementMap&&(i.displacementMap=s(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=s(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=s(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=s(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=s(t.specularMap)),void 0!==t.specularIntensityMap&&(i.specularIntensityMap=s(t.specularIntensityMap)),void 0!==t.specularColorMap&&(i.specularColorMap=s(t.specularColorMap)),void 0!==t.envMap&&(i.envMap=s(t.envMap)),void 0!==t.envMapRotation&&i.envMapRotation.fromArray(t.envMapRotation),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=s(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=s(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=s(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=s(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=s(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=s(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new Ks).fromArray(t.clearcoatNormalScale)),void 0!==t.iridescenceMap&&(i.iridescenceMap=s(t.iridescenceMap)),void 0!==t.iridescenceThicknessMap&&(i.iridescenceThicknessMap=s(t.iridescenceThicknessMap)),void 0!==t.transmissionMap&&(i.transmissionMap=s(t.transmissionMap)),void 0!==t.thicknessMap&&(i.thicknessMap=s(t.thicknessMap)),void 0!==t.anisotropyMap&&(i.anisotropyMap=s(t.anisotropyMap)),void 0!==t.sheenColorMap&&(i.sheenColorMap=s(t.sheenColorMap)),void 0!==t.sheenRoughnessMap&&(i.sheenRoughnessMap=s(t.sheenRoughnessMap)),i}setTextures(t){return this.textures=t,this}static createMaterialFromType(t){return new{ShadowMaterial:Su,SpriteMaterial:uo,RawShaderMaterial:Mu,ShaderMaterial:$n,PointsMaterial:Va,MeshPhysicalMaterial:Nu,MeshStandardMaterial:Au,MeshPhongMaterial:Ru,MeshToonMaterial:Cu,MeshNormalMaterial:Eu,MeshLambertMaterial:Bu,MeshDepthMaterial:Iu,MeshDistanceMaterial:Pu,MeshBasicMaterial:Kr,MeshMatcapMaterial:Fu,LineDashedMaterial:Uu,LineBasicMaterial:Ma,Material:Qr}[t]}}class zl{static decodeText(t){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let s=0,i=t.length;s<i;s++)e+=String.fromCharCode(t[s]);try{return decodeURIComponent(escape(e))}catch(t){return e}}static extractUrlBase(t){const e=t.lastIndexOf("/");return-1===e?"./":t.slice(0,e+1)}static resolveURL(t,e){return"string"!=typeof t||""===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 Ol extends Mn{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 Ll extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(r.manager);n.setPath(r.path),n.setRequestHeader(r.requestHeader),n.setWithCredentials(r.withCredentials),n.load(t,(function(s){try{e(r.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),s,i)}parse(t){const e={},s={};function i(t,i){if(void 0!==e[i])return e[i];const r=t.interleavedBuffers[i],n=function(t,e){if(void 0!==s[e])return s[e];const i=t.arrayBuffers,r=i[e],n=new Uint32Array(r).buffer;return s[e]=n,n}(t,r.buffer),o=ii(r.type,n),a=new oo(o,r.stride);return a.uuid=r.uuid,e[i]=a,a}const r=t.isInstancedBufferGeometry?new Ol:new Mn,n=t.data.index;if(void 0!==n){const t=ii(n.type,n.array);r.setIndex(new hn(t,1))}const o=t.data.attributes;for(const e in o){const s=o[e];let n;if(s.isInterleavedBufferAttribute){const e=i(t.data,s.data);n=new ho(e,s.itemSize,s.offset,s.normalized)}else{const t=ii(s.type,s.array);n=new(s.isInstancedBufferAttribute?jo:hn)(t,s.itemSize,s.normalized)}void 0!==s.name&&(n.name=s.name),void 0!==s.usage&&n.setUsage(s.usage),r.setAttribute(e,n)}const a=t.data.morphAttributes;if(a)for(const e in a){const s=a[e],n=[];for(let e=0,r=s.length;e<r;e++){const r=s[e];let o;if(r.isInterleavedBufferAttribute){const e=i(t.data,r.data);o=new ho(e,r.itemSize,r.offset,r.normalized)}else{const t=ii(r.type,r.array);o=new hn(t,r.itemSize,r.normalized)}void 0!==r.name&&(o.name=r.name),n.push(o)}r.morphAttributes[e]=n}t.data.morphTargetsRelative&&(r.morphTargetsRelative=!0);const h=t.data.groups||t.data.drawcalls||t.data.offsets;if(void 0!==h)for(let t=0,e=h.length;t!==e;++t){const e=h[t];r.addGroup(e.start,e.count,e.materialIndex)}const u=t.data.boundingSphere;if(void 0!==u){const t=new Ei;void 0!==u.center&&t.fromArray(u.center),r.boundingSphere=new Zi(t,u.radius)}return t.name&&(r.name=t.name),t.userData&&(r.userData=t.userData),r}}class Vl extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=""===this.path?zl.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||n;const o=new hl(this.manager);o.setPath(this.path),o.setRequestHeader(this.requestHeader),o.setWithCredentials(this.withCredentials),o.load(t,(function(s){let n=null;try{n=JSON.parse(s)}catch(e){return void 0!==i&&i(e),void console.error("THREE:ObjectLoader: Can't parse "+t+".",e.message)}const o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())return void 0!==i&&i(new Error("THREE.ObjectLoader: Can't load "+t)),void console.error("THREE.ObjectLoader: Can't load "+t);r.parse(n,e)}),s,i)}async loadAsync(t,e){const s=""===this.path?zl.extractUrlBase(t):this.path;this.resourcePath=this.resourcePath||s;const i=new hl(this.manager);i.setPath(this.path),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials);const r=await i.loadAsync(t,e),n=JSON.parse(r),o=n.metadata;if(void 0===o||void 0===o.type||"geometry"===o.type.toLowerCase())throw new Error("THREE.ObjectLoader: Can't load "+t);return await this.parseAsync(n)}parse(t,e){const s=this.parseAnimations(t.animations),i=this.parseShapes(t.shapes),r=this.parseGeometries(t.geometries,i),n=this.parseImages(t.images,(function(){void 0!==e&&e(h)})),o=this.parseTextures(t.textures,n),a=this.parseMaterials(t.materials,o),h=this.parseObject(t.object,r,a,o,s),u=this.parseSkeletons(t.skeletons,h);if(this.bindSkeletons(h,u),this.bindLightTargets(h),void 0!==e){let t=!1;for(const e in n)if(n[e].data instanceof HTMLImageElement){t=!0;break}!1===t&&e(h)}return h}async parseAsync(t){const e=this.parseAnimations(t.animations),s=this.parseShapes(t.shapes),i=this.parseGeometries(t.geometries,s),r=await this.parseImagesAsync(t.images),n=this.parseTextures(t.textures,r),o=this.parseMaterials(t.materials,n),a=this.parseObject(t.object,i,o,n,e),h=this.parseSkeletons(t.skeletons,a);return this.bindSkeletons(a,h),this.bindLightTargets(a),a}parseShapes(t){const e={};if(void 0!==t)for(let s=0,i=t.length;s<i;s++){const i=(new Fh).fromJSON(t[s]);e[i.uuid]=i}return e}parseSkeletons(t,e){const s={},i={};if(e.traverse((function(t){t.isBone&&(i[t.uuid]=t)})),void 0!==t)for(let e=0,r=t.length;e<r;e++){const r=(new Wo).fromJSON(t[e],i);s[r.uuid]=r}return s}parseGeometries(t,e){const s={};if(void 0!==t){const i=new Ll;for(let r=0,n=t.length;r<n;r++){let n;const o=t[r];switch(o.type){case"BufferGeometry":case"InstancedBufferGeometry":n=i.parse(o);break;default:o.type in wu?n=wu[o.type].fromJSON(o,e):console.warn(`THREE.ObjectLoader: Unsupported geometry type "${o.type}"`)}n.uuid=o.uuid,void 0!==o.name&&(n.name=o.name),void 0!==o.userData&&(n.userData=o.userData),s[o.uuid]=n}}return s}parseMaterials(t,e){const s={},i={};if(void 0!==t){const r=new Ul;r.setTextures(e);for(let e=0,n=t.length;e<n;e++){const n=t[e];void 0===s[n.uuid]&&(s[n.uuid]=r.parse(n)),i[n.uuid]=s[n.uuid]}}return i}parseAnimations(t){const e={};if(void 0!==t)for(let s=0;s<t.length;s++){const i=t[s],r=tl.parse(i);e[r.uuid]=r}return e}parseImages(t,e){const s=this,i={};let r;function n(t){if("string"==typeof t){const e=t;return function(t){return s.manager.itemStart(t),r.load(t,(function(){s.manager.itemEnd(t)}),void 0,(function(){s.manager.itemError(t),s.manager.itemEnd(t)}))}(/^(\/\/)|([a-z]+:(\/\/)?)/i.test(e)?e:s.resourcePath+e)}return t.data?{data:ii(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){const s=new il(e);r=new cl(s),r.setCrossOrigin(this.crossOrigin);for(let e=0,s=t.length;e<s;e++){const s=t[e],r=s.url;if(Array.isArray(r)){const t=[];for(let e=0,s=r.length;e<s;e++){const s=n(r[e]);null!==s&&(s instanceof HTMLImageElement?t.push(s):t.push(new Do(s.data,s.width,s.height)))}i[s.uuid]=new xi(t)}else{const t=n(s.url);i[s.uuid]=new xi(t)}}}return i}async parseImagesAsync(t){const e=this,s={};let i;async function r(t){if("string"==typeof t){const s=t,r=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(s)?s:e.resourcePath+s;return await i.loadAsync(r)}return t.data?{data:ii(t.type,t.data),width:t.width,height:t.height}:null}if(void 0!==t&&t.length>0){i=new cl(this.manager),i.setCrossOrigin(this.crossOrigin);for(let e=0,i=t.length;e<i;e++){const i=t[e],n=i.url;if(Array.isArray(n)){const t=[];for(let e=0,s=n.length;e<s;e++){const s=n[e],i=await r(s);null!==i&&(i instanceof HTMLImageElement?t.push(i):t.push(new Do(i.data,i.width,i.height)))}s[i.uuid]=new xi(t)}else{const t=await r(i.url);s[i.uuid]=new xi(t)}}}return s}parseTextures(t,e){function s(t,e){return"number"==typeof t?t:(console.warn("THREE.ObjectLoader.parseTexture: Constant should be in numeric form.",t),e[t])}const i={};if(void 0!==t)for(let r=0,n=t.length;r<n;r++){const n=t[r];void 0===n.image&&console.warn('THREE.ObjectLoader: No "image" specified for',n.uuid),void 0===e[n.image]&&console.warn("THREE.ObjectLoader: Undefined image",n.image);const o=e[n.image],a=o.data;let h;Array.isArray(a)?(h=new eo,6===a.length&&(h.needsUpdate=!0)):(h=a&&a.data?new Do:new Ti,a&&(h.needsUpdate=!0)),h.source=o,h.uuid=n.uuid,void 0!==n.name&&(h.name=n.name),void 0!==n.mapping&&(h.mapping=s(n.mapping,Dl)),void 0!==n.channel&&(h.channel=n.channel),void 0!==n.offset&&h.offset.fromArray(n.offset),void 0!==n.repeat&&h.repeat.fromArray(n.repeat),void 0!==n.center&&h.center.fromArray(n.center),void 0!==n.rotation&&(h.rotation=n.rotation),void 0!==n.wrap&&(h.wrapS=s(n.wrap[0],kl),h.wrapT=s(n.wrap[1],kl)),void 0!==n.format&&(h.format=n.format),void 0!==n.internalFormat&&(h.internalFormat=n.internalFormat),void 0!==n.type&&(h.type=n.type),void 0!==n.colorSpace&&(h.colorSpace=n.colorSpace),void 0!==n.minFilter&&(h.minFilter=s(n.minFilter,Gl)),void 0!==n.magFilter&&(h.magFilter=s(n.magFilter,Gl)),void 0!==n.anisotropy&&(h.anisotropy=n.anisotropy),void 0!==n.flipY&&(h.flipY=n.flipY),void 0!==n.generateMipmaps&&(h.generateMipmaps=n.generateMipmaps),void 0!==n.premultiplyAlpha&&(h.premultiplyAlpha=n.premultiplyAlpha),void 0!==n.unpackAlignment&&(h.unpackAlignment=n.unpackAlignment),void 0!==n.compareFunction&&(h.compareFunction=n.compareFunction),void 0!==n.userData&&(h.userData=n.userData),i[n.uuid]=h}return i}parseObject(t,e,s,i,r){let n,o,a;function h(t){return void 0===e[t]&&console.warn("THREE.ObjectLoader: Undefined geometry",t),e[t]}function u(t){if(void 0!==t){if(Array.isArray(t)){const e=[];for(let i=0,r=t.length;i<r;i++){const r=t[i];void 0===s[r]&&console.warn("THREE.ObjectLoader: Undefined material",r),e.push(s[r])}return e}return void 0===s[t]&&console.warn("THREE.ObjectLoader: Undefined material",t),s[t]}}function l(t){return void 0===i[t]&&console.warn("THREE.ObjectLoader: Undefined texture",t),i[t]}switch(t.type){case"Scene":n=new no,void 0!==t.background&&(Number.isInteger(t.background)?n.background=new Yr(t.background):n.background=l(t.background)),void 0!==t.environment&&(n.environment=l(t.environment)),void 0!==t.fog&&("Fog"===t.fog.type?n.fog=new ro(t.fog.color,t.fog.near,t.fog.far):"FogExp2"===t.fog.type&&(n.fog=new io(t.fog.color,t.fog.density)),""!==t.fog.name&&(n.fog.name=t.fog.name)),void 0!==t.backgroundBlurriness&&(n.backgroundBlurriness=t.backgroundBlurriness),void 0!==t.backgroundIntensity&&(n.backgroundIntensity=t.backgroundIntensity),void 0!==t.backgroundRotation&&n.backgroundRotation.fromArray(t.backgroundRotation),void 0!==t.environmentIntensity&&(n.environmentIntensity=t.environmentIntensity),void 0!==t.environmentRotation&&n.environmentRotation.fromArray(t.environmentRotation);break;case"PerspectiveCamera":n=new Qn(t.fov,t.aspect,t.near,t.far),void 0!==t.focus&&(n.focus=t.focus),void 0!==t.zoom&&(n.zoom=t.zoom),void 0!==t.filmGauge&&(n.filmGauge=t.filmGauge),void 0!==t.filmOffset&&(n.filmOffset=t.filmOffset),void 0!==t.view&&(n.view=Object.assign({},t.view));break;case"OrthographicCamera":n=new Rl(t.left,t.right,t.top,t.bottom,t.near,t.far),void 0!==t.zoom&&(n.zoom=t.zoom),void 0!==t.view&&(n.view=Object.assign({},t.view));break;case"AmbientLight":n=new Bl(t.color,t.intensity);break;case"DirectionalLight":n=new El(t.color,t.intensity),n.target=t.target||"";break;case"PointLight":n=new Nl(t.color,t.intensity,t.distance,t.decay);break;case"RectAreaLight":n=new Il(t.color,t.intensity,t.width,t.height);break;case"SpotLight":n=new _l(t.color,t.intensity,t.distance,t.angle,t.penumbra,t.decay),n.target=t.target||"";break;case"HemisphereLight":n=new fl(t.color,t.groundColor,t.intensity);break;case"LightProbe":n=(new Fl).fromJSON(t);break;case"SkinnedMesh":o=h(t.geometry),a=u(t.material),n=new Lo(o,a),void 0!==t.bindMode&&(n.bindMode=t.bindMode),void 0!==t.bindMatrix&&n.bindMatrix.fromArray(t.bindMatrix),void 0!==t.skeleton&&(n.skeleton=t.skeleton);break;case"Mesh":o=h(t.geometry),a=u(t.material),n=new Wn(o,a);break;case"InstancedMesh":o=h(t.geometry),a=u(t.material);const e=t.count,s=t.instanceMatrix,i=t.instanceColor;n=new Qo(o,a,e),n.instanceMatrix=new jo(new Float32Array(s.array),16),void 0!==i&&(n.instanceColor=new jo(new Float32Array(i.array),i.itemSize));break;case"BatchedMesh":o=h(t.geometry),a=u(t.material),n=new Sa(t.maxInstanceCount,t.maxVertexCount,t.maxIndexCount,a),n.geometry=o,n.perObjectFrustumCulled=t.perObjectFrustumCulled,n.sortObjects=t.sortObjects,n._drawRanges=t.drawRanges,n._reservedRanges=t.reservedRanges,n._visibility=t.visibility,n._active=t.active,n._bounds=t.bounds.map((t=>{const e=new Pi;e.min.fromArray(t.boxMin),e.max.fromArray(t.boxMax);const s=new Zi;return s.radius=t.sphereRadius,s.center.fromArray(t.sphereCenter),{boxInitialized:t.boxInitialized,box:e,sphereInitialized:t.sphereInitialized,sphere:s}})),n._maxInstanceCount=t.maxInstanceCount,n._maxVertexCount=t.maxVertexCount,n._maxIndexCount=t.maxIndexCount,n._geometryInitialized=t.geometryInitialized,n._geometryCount=t.geometryCount,n._matricesTexture=l(t.matricesTexture.uuid),void 0!==t.colorsTexture&&(n._colorsTexture=l(t.colorsTexture.uuid));break;case"LOD":n=new Ro;break;case"Line":n=new Pa(h(t.geometry),u(t.material));break;case"LineLoop":n=new La(h(t.geometry),u(t.material));break;case"LineSegments":n=new Oa(h(t.geometry),u(t.material));break;case"PointCloud":case"Points":n=new ja(h(t.geometry),u(t.material));break;case"Sprite":n=new So(u(t.material));break;case"Group":n=new qa;break;case"Bone":n=new Vo;break;default:n=new Pr}if(n.uuid=t.uuid,void 0!==t.name&&(n.name=t.name),void 0!==t.matrix?(n.matrix.fromArray(t.matrix),void 0!==t.matrixAutoUpdate&&(n.matrixAutoUpdate=t.matrixAutoUpdate),n.matrixAutoUpdate&&n.matrix.decompose(n.position,n.quaternion,n.scale)):(void 0!==t.position&&n.position.fromArray(t.position),void 0!==t.rotation&&n.rotation.fromArray(t.rotation),void 0!==t.quaternion&&n.quaternion.fromArray(t.quaternion),void 0!==t.scale&&n.scale.fromArray(t.scale)),void 0!==t.up&&n.up.fromArray(t.up),void 0!==t.castShadow&&(n.castShadow=t.castShadow),void 0!==t.receiveShadow&&(n.receiveShadow=t.receiveShadow),t.shadow&&(void 0!==t.shadow.intensity&&(n.shadow.intensity=t.shadow.intensity),void 0!==t.shadow.bias&&(n.shadow.bias=t.shadow.bias),void 0!==t.shadow.normalBias&&(n.shadow.normalBias=t.shadow.normalBias),void 0!==t.shadow.radius&&(n.shadow.radius=t.shadow.radius),void 0!==t.shadow.mapSize&&n.shadow.mapSize.fromArray(t.shadow.mapSize),void 0!==t.shadow.camera&&(n.shadow.camera=this.parseObject(t.shadow.camera))),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.frustumCulled&&(n.frustumCulled=t.frustumCulled),void 0!==t.renderOrder&&(n.renderOrder=t.renderOrder),void 0!==t.userData&&(n.userData=t.userData),void 0!==t.layers&&(n.layers.mask=t.layers),void 0!==t.children){const o=t.children;for(let t=0;t<o.length;t++)n.add(this.parseObject(o[t],e,s,i,r))}if(void 0!==t.animations){const e=t.animations;for(let t=0;t<e.length;t++){const s=e[t];n.animations.push(r[s])}}if("LOD"===t.type){void 0!==t.autoUpdate&&(n.autoUpdate=t.autoUpdate);const e=t.levels;for(let t=0;t<e.length;t++){const s=e[t],i=n.getObjectByProperty("uuid",s.object);void 0!==i&&n.addLevel(i,s.distance,s.hysteresis)}}return n}bindSkeletons(t,e){0!==Object.keys(e).length&&t.traverse((function(t){if(!0===t.isSkinnedMesh&&void 0!==t.skeleton){const s=e[t.skeleton];void 0===s?console.warn("THREE.ObjectLoader: No skeleton found with UUID:",t.skeleton):t.bind(s,t.bindMatrix)}}))}bindLightTargets(t){t.traverse((function(e){if(e.isDirectionalLight||e.isSpotLight){const s=e.target,i=t.getObjectByProperty("uuid",s);e.target=void 0!==i?i:new Pr}}))}}const Dl={UVMapping:at,CubeReflectionMapping:ht,CubeRefractionMapping:ut,EquirectangularReflectionMapping:lt,EquirectangularRefractionMapping:ct,CubeUVReflectionMapping:306},kl={RepeatWrapping:pt,ClampToEdgeWrapping:mt,MirroredRepeatWrapping:gt},Gl={NearestFilter:ft,NearestMipmapNearestFilter:yt,NearestMipmapLinearFilter:bt,LinearFilter:Tt,LinearMipmapNearestFilter:_t,LinearMipmapLinearFilter:St};class Wl extends nl{constructor(t){super(t),this.isImageBitmapLoader=!0,"undefined"==typeof createImageBitmap&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),"undefined"==typeof fetch&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,s,i){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,n=sl.get(t);if(void 0!==n)return r.manager.itemStart(t),n.then?void n.then((s=>{e&&e(s),r.manager.itemEnd(t)})).catch((t=>{i&&i(t)})):(setTimeout((function(){e&&e(n),r.manager.itemEnd(t)}),0),n);const o={};o.credentials="anonymous"===this.crossOrigin?"same-origin":"include",o.headers=this.requestHeader;const a=fetch(t,o).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(r.options,{colorSpaceConversion:"none"}))})).then((function(s){return sl.add(t,s),e&&e(s),r.manager.itemEnd(t),s})).catch((function(e){i&&i(e),sl.remove(t),r.manager.itemError(t),r.manager.itemEnd(t)}));sl.add(t,a),r.manager.itemStart(t)}}let jl;class Hl{static getContext(){return void 0===jl&&(jl=new(window.AudioContext||window.webkitAudioContext)),jl}static setContext(t){jl=t}}class ql extends nl{constructor(t){super(t)}load(t,e,s,i){const r=this,n=new hl(this.manager);function o(e){i?i(e):console.error(e),r.manager.itemError(t)}n.setResponseType("arraybuffer"),n.setPath(this.path),n.setRequestHeader(this.requestHeader),n.setWithCredentials(this.withCredentials),n.load(t,(function(t){try{const s=t.slice(0);Hl.getContext().decodeAudioData(s,(function(t){e(t)})).catch(o)}catch(t){o(t)}}),s,i)}}const $l=new or,Xl=new or,Yl=new or;class Jl{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Qn,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Qn,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,Yl.copy(t.projectionMatrix);const s=e.eyeSep/2,i=s*e.near/e.focus,r=e.near*Math.tan(js*e.fov*.5)/e.zoom;let n,o;Xl.elements[12]=-s,$l.elements[12]=s,n=-r*e.aspect+i,o=r*e.aspect+i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraL.projectionMatrix.copy(Yl),n=-r*e.aspect-i,o=r*e.aspect-i,Yl.elements[0]=2*e.near/(o-n),Yl.elements[8]=(o+n)/(o-n),this.cameraR.projectionMatrix.copy(Yl)}this.cameraL.matrixWorld.copy(t.matrixWorld).multiply(Xl),this.cameraR.matrixWorld.copy(t.matrixWorld).multiply($l)}}class Zl extends Qn{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class Ql{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Kl(),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=Kl();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Kl(){return("undefined"==typeof performance?Date:performance).now()}const tc=new Ei,ec=new Ci,sc=new Ei,ic=new Ei;class rc extends Pr{constructor(){super(),this.type="AudioListener",this.context=Hl.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new Ql}getInput(){return this.gain}removeFilter(){return null!==this.filter&&(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 null!==this.filter?(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,s=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(tc,ec,sc),ic.set(0,0,-1).applyQuaternion(ec),e.positionX){const t=this.context.currentTime+this.timeDelta;e.positionX.linearRampToValueAtTime(tc.x,t),e.positionY.linearRampToValueAtTime(tc.y,t),e.positionZ.linearRampToValueAtTime(tc.z,t),e.forwardX.linearRampToValueAtTime(ic.x,t),e.forwardY.linearRampToValueAtTime(ic.y,t),e.forwardZ.linearRampToValueAtTime(ic.z,t),e.upX.linearRampToValueAtTime(s.x,t),e.upY.linearRampToValueAtTime(s.y,t),e.upZ.linearRampToValueAtTime(s.z,t)}else e.setPosition(tc.x,tc.y,tc.z),e.setOrientation(ic.x,ic.y,ic.z,s.x,s.y,s.z)}}class nc extends Pr{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(!0===this.isPlaying)return void console.warn("THREE.Audio: Audio is already playing.");if(!1===this.hasPlaybackControl)return void console.warn("THREE.Audio: this Audio has no playback control.");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(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this;console.warn("THREE.Audio: this Audio has no playback control.")}stop(){if(!1!==this.hasPlaybackControl)return this._progress=0,null!==this.source&&(this.source.stop(),this.source.onended=null),this.isPlaying=!1,this;console.warn("THREE.Audio: this Audio has no playback control.")}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(!1!==this._connected){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=[]),!0===this._connected?(this.disconnect(),this.filters=t.slice(),this.connect()):this.filters=t.slice(),this}setDetune(t){return this.detune=t,!0===this.isPlaying&&void 0!==this.source.detune&&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(!1!==this.hasPlaybackControl)return this.playbackRate=t,!0===this.isPlaying&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this;console.warn("THREE.Audio: this Audio has no playback control.")}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1}getLoop(){return!1===this.hasPlaybackControl?(console.warn("THREE.Audio: this Audio has no playback control."),!1):this.loop}setLoop(t){if(!1!==this.hasPlaybackControl)return this.loop=t,!0===this.isPlaying&&(this.source.loop=this.loop),this;console.warn("THREE.Audio: this Audio has no playback control.")}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}}const oc=new Ei,ac=new Ci,hc=new Ei,uc=new Ei;class lc extends nc{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,s){return this.panner.coneInnerAngle=t,this.panner.coneOuterAngle=e,this.panner.coneOuterGain=s,this}updateMatrixWorld(t){if(super.updateMatrixWorld(t),!0===this.hasPlaybackControl&&!1===this.isPlaying)return;this.matrixWorld.decompose(oc,ac,hc),uc.set(0,0,1).applyQuaternion(ac);const e=this.panner;if(e.positionX){const t=this.context.currentTime+this.listener.timeDelta;e.positionX.linearRampToValueAtTime(oc.x,t),e.positionY.linearRampToValueAtTime(oc.y,t),e.positionZ.linearRampToValueAtTime(oc.z,t),e.orientationX.linearRampToValueAtTime(uc.x,t),e.orientationY.linearRampToValueAtTime(uc.y,t),e.orientationZ.linearRampToValueAtTime(uc.z,t)}else e.setPosition(oc.x,oc.y,oc.z),e.setOrientation(uc.x,uc.y,uc.z)}}class cc{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 s=0;s<e.length;s++)t+=e[s];return t/e.length}}class dc{constructor(t,e,s){let i,r,n;switch(this.binding=t,this.valueSize=s,e){case"quaternion":i=this._slerp,r=this._slerpAdditive,n=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(6*s),this._workIndex=5;break;case"string":case"bool":i=this._select,r=this._select,n=this._setAdditiveIdentityOther,this.buffer=new Array(5*s);break;default:i=this._lerp,r=this._lerpAdditive,n=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(5*s)}this._mixBufferRegion=i,this._mixBufferRegionAdditive=r,this._setIdentity=n,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const s=this.buffer,i=this.valueSize,r=t*i+i;let n=this.cumulativeWeight;if(0===n){for(let t=0;t!==i;++t)s[r+t]=s[t];n=e}else{n+=e;const t=e/n;this._mixBufferRegion(s,r,0,t,i)}this.cumulativeWeight=n}accumulateAdditive(t){const e=this.buffer,s=this.valueSize,i=s*this._addIndex;0===this.cumulativeWeightAdditive&&this._setIdentity(),this._mixBufferRegionAdditive(e,i,0,t,s),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,s=this.buffer,i=t*e+e,r=this.cumulativeWeight,n=this.cumulativeWeightAdditive,o=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,r<1){const t=e*this._origIndex;this._mixBufferRegion(s,i,t,1-r,e)}n>0&&this._mixBufferRegionAdditive(s,i,this._addIndex*e,1,e);for(let t=e,r=e+e;t!==r;++t)if(s[t]!==s[t+e]){o.setValue(s,i);break}}saveOriginalState(){const t=this.binding,e=this.buffer,s=this.valueSize,i=s*this._origIndex;t.getValue(e,i);for(let t=s,r=i;t!==r;++t)e[t]=e[i+t%s];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let s=t;s<e;s++)this.buffer[s]=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 s=0;s<this.valueSize;s++)this.buffer[e+s]=this.buffer[t+s]}_select(t,e,s,i,r){if(i>=.5)for(let i=0;i!==r;++i)t[e+i]=t[s+i]}_slerp(t,e,s,i){Ci.slerpFlat(t,e,t,e,t,s,i)}_slerpAdditive(t,e,s,i,r){const n=this._workIndex*r;Ci.multiplyQuaternionsFlat(t,n,t,e,t,s),Ci.slerpFlat(t,e,t,e,t,n,i)}_lerp(t,e,s,i,r){const n=1-i;for(let o=0;o!==r;++o){const r=e+o;t[r]=t[r]*n+t[s+o]*i}}_lerpAdditive(t,e,s,i,r){for(let n=0;n!==r;++n){const r=e+n;t[r]=t[r]+t[s+n]*i}}}const pc="\\[\\]\\.:\\/",mc=new RegExp("["+pc+"]","g"),gc="[^"+pc+"]",fc="[^"+pc.replace("\\.","")+"]",yc=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",gc)+/(WCOD+)?/.source.replace("WCOD",fc)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",gc)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",gc)+"$"),xc=["material","materials","bones","map"];class bc{constructor(t,e,s){this.path=e,this.parsedPath=s||bc.parseTrackName(e),this.node=bc.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,s){return t&&t.isAnimationObjectGroup?new bc.Composite(t,e,s):new bc(t,e,s)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(mc,"")}static parseTrackName(t){const e=yc.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const s={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=s.nodeName&&s.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=s.nodeName.substring(i+1);-1!==xc.indexOf(t)&&(s.nodeName=s.nodeName.substring(0,i),s.objectName=t)}if(null===s.propertyName||0===s.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return s}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const s=t.skeleton.getBoneByName(e);if(void 0!==s)return s}if(t.children){const s=function(t){for(let i=0;i<t.length;i++){const r=t[i];if(r.name===e||r.uuid===e)return r;const n=s(r.children);if(n)return n}return null},i=s(t.children);if(i)return i}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)t[e++]=s[i]}_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 s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const s=this.resolvedProperty;for(let i=0,r=s.length;i!==r;++i)s[i]=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,s=e.objectName,i=e.propertyName;let r=e.propertyIndex;if(t||(t=bc.findNode(this.rootNode,e.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t)return void console.warn("THREE.PropertyBinding: No target node found for track: "+this.path+".");if(s){let i=e.objectIndex;switch(s){case"materials":if(!t.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!t.material.materials)return void console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.",this);t=t.material.materials;break;case"bones":if(!t.skeleton)return void console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.",this);t=t.skeleton.bones;for(let e=0;e<t.length;e++)if(t[e].name===i){i=e;break}break;case"map":if("map"in t){t=t.map;break}if(!t.material)return void console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.",this);if(!t.material.map)return void console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.",this);t=t.material.map;break;default:if(void 0===t[s])return void console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.",this);t=t[s]}if(void 0!==i){if(void 0===t[i])return void console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.",this,t);t=t[i]}}const n=t[i];if(void 0===n){const s=e.nodeName;return void console.error("THREE.PropertyBinding: Trying to update property for track: "+s+"."+i+" but it wasn't found.",t)}let o=this.Versioning.None;this.targetObject=t,void 0!==t.needsUpdate?o=this.Versioning.NeedsUpdate:void 0!==t.matrixWorldNeedsUpdate&&(o=this.Versioning.MatrixWorldNeedsUpdate);let a=this.BindingType.Direct;if(void 0!==r){if("morphTargetInfluences"===i){if(!t.geometry)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.",this);if(!t.geometry.morphAttributes)return void console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.",this);void 0!==t.morphTargetDictionary[r]&&(r=t.morphTargetDictionary[r])}a=this.BindingType.ArrayElement,this.resolvedProperty=n,this.propertyIndex=r}else void 0!==n.fromArray&&void 0!==n.toArray?(a=this.BindingType.HasFromToArray,this.resolvedProperty=n):Array.isArray(n)?(a=this.BindingType.EntireArray,this.resolvedProperty=n):this.propertyName=i;this.getValue=this.GetterByBindingType[a],this.setValue=this.SetterByBindingTypeAndVersioning[a][o]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}bc.Composite=class{constructor(t,e,s){const i=s||bc.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}getValue(t,e){this.bind();const s=this._targetGroup.nCachedObjects_,i=this._bindings[s];void 0!==i&&i.getValue(t,e)}setValue(t,e){const s=this._bindings;for(let i=this._targetGroup.nCachedObjects_,r=s.length;i!==r;++i)s[i].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,s=t.length;e!==s;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,s=t.length;e!==s;++e)t[e].unbind()}},bc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},bc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},bc.prototype.GetterByBindingType=[bc.prototype._getValue_direct,bc.prototype._getValue_array,bc.prototype._getValue_arrayElement,bc.prototype._getValue_toArray],bc.prototype.SetterByBindingTypeAndVersioning=[[bc.prototype._setValue_direct,bc.prototype._setValue_direct_setNeedsUpdate,bc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_array,bc.prototype._setValue_array_setNeedsUpdate,bc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_arrayElement,bc.prototype._setValue_arrayElement_setNeedsUpdate,bc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[bc.prototype._setValue_fromArray,bc.prototype._setValue_fromArray_setNeedsUpdate,bc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class vc{constructor(){this.isAnimationObjectGroup=!0,this.uuid=qs(),this._objects=Array.prototype.slice.call(arguments),this.nCachedObjects_=0;const t={};this._indicesByUUID=t;for(let e=0,s=arguments.length;e!==s;++e)t[arguments[e].uuid]=e;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,s=this._paths,i=this._parsedPaths,r=this._bindings,n=r.length;let o,a=t.length,h=this.nCachedObjects_;for(let u=0,l=arguments.length;u!==l;++u){const l=arguments[u],c=l.uuid;let d=e[c];if(void 0===d){d=a++,e[c]=d,t.push(l);for(let t=0,e=n;t!==e;++t)r[t].push(new bc(l,s[t],i[t]))}else if(d<h){o=t[d];const a=--h,u=t[a];e[u.uuid]=d,t[d]=u,e[c]=a,t[a]=l;for(let t=0,e=n;t!==e;++t){const e=r[t],n=e[a];let o=e[d];e[d]=n,void 0===o&&(o=new bc(l,s[t],i[t])),e[a]=o}}else t[d]!==o&&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,s=this._bindings,i=s.length;let r=this.nCachedObjects_;for(let n=0,o=arguments.length;n!==o;++n){const o=arguments[n],a=o.uuid,h=e[a];if(void 0!==h&&h>=r){const n=r++,u=t[n];e[u.uuid]=h,t[h]=u,e[a]=n,t[n]=o;for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[n],r=e[h];e[h]=i,e[n]=r}}}this.nCachedObjects_=r}uncache(){const t=this._objects,e=this._indicesByUUID,s=this._bindings,i=s.length;let r=this.nCachedObjects_,n=t.length;for(let o=0,a=arguments.length;o!==a;++o){const a=arguments[o].uuid,h=e[a];if(void 0!==h)if(delete e[a],h<r){const o=--r,a=t[o],u=--n,l=t[u];e[a.uuid]=h,t[h]=a,e[l.uuid]=o,t[o]=l,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t],i=e[o],r=e[u];e[h]=i,e[o]=r,e.pop()}}else{const r=--n,o=t[r];r>0&&(e[o.uuid]=h),t[h]=o,t.pop();for(let t=0,e=i;t!==e;++t){const e=s[t];e[h]=e[r],e.pop()}}}this.nCachedObjects_=r}subscribe_(t,e){const s=this._bindingsIndicesByPath;let i=s[t];const r=this._bindings;if(void 0!==i)return r[i];const n=this._paths,o=this._parsedPaths,a=this._objects,h=a.length,u=this.nCachedObjects_,l=new Array(h);i=r.length,s[t]=i,n.push(t),o.push(e),r.push(l);for(let s=u,i=a.length;s!==i;++s){const i=a[s];l[s]=new bc(i,t,e)}return l}unsubscribe_(t){const e=this._bindingsIndicesByPath,s=e[t];if(void 0!==s){const i=this._paths,r=this._parsedPaths,n=this._bindings,o=n.length-1,a=n[o];e[t[o]]=s,n[s]=a,n.pop(),r[s]=r[o],r.pop(),i[s]=i[o],i.pop()}}}class Tc{constructor(t,e,s=null,i=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=s,this.blendMode=i;const r=e.tracks,n=r.length,o=new Array(n),a={endingStart:Ue,endingEnd:Ue};for(let t=0;t!==n;++t){const e=r[t].createInterpolant(null);o[t]=e,e.settings=a}this._interpolantSettings=a,this._interpolants=o,this._propertyBindings=new Array(n),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,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&&0!==this.timeScale&&null===this._startTime&&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,s){if(t.fadeOut(e),this.fadeIn(e),s){const s=this._clip.duration,i=t._clip.duration,r=i/s,n=s/i;t.warp(1,r,e),this.warp(n,1,e)}return this}crossFadeTo(t,e,s){return t.crossFadeFrom(this,e,s)}stopFading(){const t=this._weightInterpolant;return null!==t&&(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,s){const i=this._mixer,r=i.time,n=this.timeScale;let o=this._timeScaleInterpolant;null===o&&(o=i._lendControlInterpolant(),this._timeScaleInterpolant=o);const a=o.parameterPositions,h=o.sampleValues;return a[0]=r,a[1]=r+s,h[0]=t/n,h[1]=e/n,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(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,s,i){if(!this.enabled)return void this._updateWeight(t);const r=this._startTime;if(null!==r){const i=(t-r)*s;i<0||0===s?e=0:(this._startTime=null,e=s*i)}e*=this._updateTimeScale(t);const n=this._updateTime(e),o=this._updateWeight(t);if(o>0){const t=this._interpolants,e=this._propertyBindings;if(this.blendMode===Ve)for(let s=0,i=t.length;s!==i;++s)t[s].evaluate(n),e[s].accumulateAdditive(o);else for(let s=0,r=t.length;s!==r;++s)t[s].evaluate(n),e[s].accumulate(i,o)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const s=this._weightInterpolant;if(null!==s){const i=s.evaluate(t)[0];e*=i,t>s.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const s=this._timeScaleInterpolant;if(null!==s){e*=s.evaluate(t)[0],t>s.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,s=this.loop;let i=this.time+t,r=this._loopCount;const n=2202===s;if(0===t)return-1===r?i:n&&1==(1&r)?e-i:i;if(2200===s){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,n)):this._setEndings(0===this.repetitions,!0,n)),i>=e||i<0){const s=Math.floor(i/e);i-=e*s,r+=Math.abs(s);const o=this.repetitions-r;if(o<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===o){const e=t<0;this._setEndings(e,!e,n)}else this._setEndings(!1,!1,n);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:s})}}else this.time=i;if(n&&1==(1&r))return e-i}return i}_setEndings(t,e,s){const i=this._interpolantSettings;s?(i.endingStart=ze,i.endingEnd=ze):(i.endingStart=t?this.zeroSlopeAtStart?ze:Ue:Oe,i.endingEnd=e?this.zeroSlopeAtEnd?ze:Ue:Oe)}_scheduleFading(t,e,s){const i=this._mixer,r=i.time;let n=this._weightInterpolant;null===n&&(n=i._lendControlInterpolant(),this._weightInterpolant=n);const o=n.parameterPositions,a=n.sampleValues;return o[0]=r,a[0]=e,o[1]=r+t,a[1]=s,this}}const _c=new Float32Array(1);class wc extends ks{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const s=t._localRoot||this._root,i=t._clip.tracks,r=i.length,n=t._propertyBindings,o=t._interpolants,a=s.uuid,h=this._bindingsByRootAndName;let u=h[a];void 0===u&&(u={},h[a]=u);for(let t=0;t!==r;++t){const r=i[t],h=r.name;let l=u[h];if(void 0!==l)++l.referenceCount,n[t]=l;else{if(l=n[t],void 0!==l){null===l._cacheIndex&&(++l.referenceCount,this._addInactiveBinding(l,a,h));continue}const i=e&&e._propertyBindings[t].binding.parsedPath;l=new dc(bc.create(s,h,i),r.ValueTypeName,r.getValueSize()),++l.referenceCount,this._addInactiveBinding(l,a,h),n[t]=l}o[t].resultBuffer=l.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,s=t._clip.uuid,i=this._actionsByClip[s];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,s,e)}const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.useCount&&(s.restoreOriginalState(),this._takeBackBinding(s))}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 null!==e&&e<this._nActiveActions}_addInactiveAction(t,e,s){const i=this._actions,r=this._actionsByClip;let n=r[e];if(void 0===n)n={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,r[e]=n;else{const e=n.knownActions;t._byClipCacheIndex=e.length,e.push(t)}t._cacheIndex=i.length,i.push(t),n.actionByRoot[s]=t}_removeInactiveAction(t){const e=this._actions,s=e[e.length-1],i=t._cacheIndex;s._cacheIndex=i,e[i]=s,e.pop(),t._cacheIndex=null;const r=t._clip.uuid,n=this._actionsByClip,o=n[r],a=o.knownActions,h=a[a.length-1],u=t._byClipCacheIndex;h._byClipCacheIndex=u,a[u]=h,a.pop(),t._byClipCacheIndex=null;delete o.actionByRoot[(t._localRoot||this._root).uuid],0===a.length&&delete n[r],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let t=0,s=e.length;t!==s;++t){const s=e[t];0==--s.referenceCount&&this._removeInactiveBinding(s)}}_lendAction(t){const e=this._actions,s=t._cacheIndex,i=this._nActiveActions++,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_takeBackAction(t){const e=this._actions,s=t._cacheIndex,i=--this._nActiveActions,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_addInactiveBinding(t,e,s){const i=this._bindingsByRootAndName,r=this._bindings;let n=i[e];void 0===n&&(n={},i[e]=n),n[s]=t,t._cacheIndex=r.length,r.push(t)}_removeInactiveBinding(t){const e=this._bindings,s=t.binding,i=s.rootNode.uuid,r=s.path,n=this._bindingsByRootAndName,o=n[i],a=e[e.length-1],h=t._cacheIndex;a._cacheIndex=h,e[h]=a,e.pop(),delete o[r],0===Object.keys(o).length&&delete n[i]}_lendBinding(t){const e=this._bindings,s=t._cacheIndex,i=this._nActiveBindings++,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_takeBackBinding(t){const e=this._bindings,s=t._cacheIndex,i=--this._nActiveBindings,r=e[i];t._cacheIndex=i,e[i]=t,r._cacheIndex=s,e[s]=r}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let s=t[e];return void 0===s&&(s=new ju(new Float32Array(2),new Float32Array(2),1,_c),s.__cacheIndex=e,t[e]=s),s}_takeBackControlInterpolant(t){const e=this._controlInterpolants,s=t.__cacheIndex,i=--this._nActiveControlInterpolants,r=e[i];t.__cacheIndex=i,e[i]=t,r.__cacheIndex=s,e[s]=r}clipAction(t,e,s){const i=e||this._root,r=i.uuid;let n="string"==typeof t?tl.findByName(i,t):t;const o=null!==n?n.uuid:t,a=this._actionsByClip[o];let h=null;if(void 0===s&&(s=null!==n?n.blendMode:Le),void 0!==a){const t=a.actionByRoot[r];if(void 0!==t&&t.blendMode===s)return t;h=a.knownActions[0],null===n&&(n=h._clip)}if(null===n)return null;const u=new Tc(this,n,e,s);return this._bindAction(u,h),this._addInactiveAction(u,o,r),u}existingAction(t,e){const s=e||this._root,i=s.uuid,r="string"==typeof t?tl.findByName(s,t):t,n=r?r.uuid:t,o=this._actionsByClip[n];return void 0!==o&&o.actionByRoot[i]||null}stopAllAction(){const t=this._actions;for(let e=this._nActiveActions-1;e>=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,s=this._nActiveActions,i=this.time+=t,r=Math.sign(t),n=this._accuIndex^=1;for(let o=0;o!==s;++o){e[o]._update(i,t,r,n)}const o=this._bindings,a=this._nActiveBindings;for(let t=0;t!==a;++t)o[t].apply(n);return this}setTime(t){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,s=t.uuid,i=this._actionsByClip,r=i[s];if(void 0!==r){const t=r.knownActions;for(let s=0,i=t.length;s!==i;++s){const i=t[s];this._deactivateAction(i);const r=i._cacheIndex,n=e[e.length-1];i._cacheIndex=null,i._byClipCacheIndex=null,n._cacheIndex=r,e[r]=n,e.pop(),this._removeInactiveBindingsForAction(i)}delete i[s]}}uncacheRoot(t){const e=t.uuid,s=this._actionsByClip;for(const t in s){const i=s[t].actionByRoot[e];void 0!==i&&(this._deactivateAction(i),this._removeInactiveAction(i))}const i=this._bindingsByRootAndName[e];if(void 0!==i)for(const t in i){const e=i[t];e.restoreOriginalState(),this._removeInactiveBinding(e)}}uncacheAction(t,e){const s=this.existingAction(t,e);null!==s&&(this._deactivateAction(s),this._removeInactiveAction(s))}}let Sc=class t{constructor(t){this.value=t}clone(){return new t(void 0===this.value.clone?this.value:this.value.clone())}},Mc=0,Ac=class extends ks{constructor(){super(),this.isUniformsGroup=!0,Object.defineProperty(this,"id",{value:Mc++}),this.name="",this.usage=Rs,this.uniforms=[]}add(t){return this.uniforms.push(t),this}remove(t){const e=this.uniforms.indexOf(t);return-1!==e&&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 t=0,s=e.length;t<s;t++){const s=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0;t<s.length;t++)this.uniforms.push(s[t].clone())}return this}clone(){return(new this.constructor).copy(this)}};class Nc extends oo{constructor(t,e,s=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=s}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 Rc{constructor(t,e,s,i,r){this.isGLBufferAttribute=!0,this.name="",this.buffer=t,this.type=e,this.itemSize=s,this.elementSize=i,this.count=r,this.version=0}set needsUpdate(t){!0===t&&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 Cc=new or;class Ec{constructor(t,e,s=0,i=1/0){this.ray=new nr(t,e),this.near=s,this.far=i,this.camera=null,this.layers=new yr,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 Cc.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Cc),this}intersectObject(t,e=!0,s=[]){return Ic(t,this,s,e),s.sort(Bc),s}intersectObjects(t,e=!0,s=[]){for(let i=0,r=t.length;i<r;i++)Ic(t[i],this,s,e);return s.sort(Bc),s}}function Bc(t,e){return t.distance-e.distance}function Ic(t,e,s,i){let r=!0;if(t.layers.test(e.layers)){!1===t.raycast(e,s)&&(r=!1)}if(!0===r&&!0===i){const i=t.children;for(let t=0,r=i.length;t<r;t++)Ic(i[t],e,s,!0)}}class Pc{constructor(t=1,e=0,s=0){return this.radius=t,this.phi=e,this.theta=s,this}set(t,e,s){return this.radius=t,this.phi=e,this.theta=s,this}copy(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}makeSafe(){const t=1e-6;return this.phi=Math.max(t,Math.min(Math.PI-t,this.phi)),this}setFromVector3(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}setFromCartesianCoords(t,e,s){return this.radius=Math.sqrt(t*t+e*e+s*s),0===this.radius?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,s),this.phi=Math.acos($s(e/this.radius,-1,1))),this}clone(){return(new this.constructor).copy(this)}}class Fc{constructor(t=1,e=0,s=0){return this.radius=t,this.theta=e,this.y=s,this}set(t,e,s){return this.radius=t,this.theta=e,this.y=s,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,s){return this.radius=Math.sqrt(t*t+s*s),this.theta=Math.atan2(t,s),this.y=e,this}clone(){return(new this.constructor).copy(this)}}class Uc{constructor(t,e,s,i){Uc.prototype.isMatrix2=!0,this.elements=[1,0,0,1],void 0!==t&&this.set(t,e,s,i)}identity(){return this.set(1,0,0,1),this}fromArray(t,e=0){for(let s=0;s<4;s++)this.elements[s]=t[s+e];return this}set(t,e,s,i){const r=this.elements;return r[0]=t,r[2]=e,r[1]=s,r[3]=i,this}}const zc=new Ks;class Oc{constructor(t=new Ks(1/0,1/0),e=new Ks(-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,s=t.length;e<s;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const s=zc.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(s),this.max.copy(t).add(s),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,zc).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 Lc=new Ei,Vc=new Ei;class Dc{constructor(t=new Ei,e=new Ei){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){Lc.subVectors(t,this.start),Vc.subVectors(this.end,this.start);const s=Vc.dot(Vc);let i=Vc.dot(Lc)/s;return e&&(i=$s(i,0,1)),i}closestPointToPoint(t,e,s){const i=this.closestPointToPointParameter(t,e);return this.delta(s).multiplyScalar(i).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 kc=new Ei;class Gc extends Pr{constructor(t,e){super(),this.light=t,this.matrixAutoUpdate=!1,this.color=e,this.type="SpotLightHelper";const s=new Mn,i=[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 t=0,e=1,s=32;t<s;t++,e++){const r=t/s*Math.PI*2,n=e/s*Math.PI*2;i.push(Math.cos(r),Math.sin(r),1,Math.cos(n),Math.sin(n),1)}s.setAttribute("position",new yn(i,3));const r=new Ma({fog:!1,toneMapped:!1});this.cone=new Oa(s,r),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),kc.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(kc),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)}}const Wc=new Ei,jc=new or,Hc=new or;class qc extends Oa{constructor(t){const e=$c(t),s=new Mn,i=[],r=[],n=new Yr(0,0,1),o=new Yr(0,1,0);for(let t=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(i.push(0,0,0),i.push(0,0,0),r.push(n.r,n.g,n.b),r.push(o.r,o.g,o.b))}s.setAttribute("position",new yn(i,3)),s.setAttribute("color",new yn(r,3));super(s,new Ma({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),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,s=this.geometry,i=s.getAttribute("position");Hc.copy(this.root.matrixWorld).invert();for(let t=0,s=0;t<e.length;t++){const r=e[t];r.parent&&r.parent.isBone&&(jc.multiplyMatrices(Hc,r.matrixWorld),Wc.setFromMatrixPosition(jc),i.setXYZ(s,Wc.x,Wc.y,Wc.z),jc.multiplyMatrices(Hc,r.parent.matrixWorld),Wc.setFromMatrixPosition(jc),i.setXYZ(s+1,Wc.x,Wc.y,Wc.z),s+=2)}s.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}dispose(){this.geometry.dispose(),this.material.dispose()}}function $c(t){const e=[];!0===t.isBone&&e.push(t);for(let s=0;s<t.children.length;s++)e.push.apply(e,$c(t.children[s]));return e}class Xc extends Wn{constructor(t,e,s){super(new fu(e,4,2),new Kr({wireframe:!0,fog:!1,toneMapped:!1})),this.light=t,this.color=s,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),void 0!==this.color?this.material.color.set(this.color):this.material.color.copy(this.light.color)}}const Yc=new Ei,Jc=new Yr,Zc=new Yr;class Qc extends Pr{constructor(t,e,s){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="HemisphereLightHelper";const i=new du(e);i.rotateY(.5*Math.PI),this.material=new Kr({wireframe:!0,fog:!1,toneMapped:!1}),void 0===this.color&&(this.material.vertexColors=!0);const r=i.getAttribute("position"),n=new Float32Array(3*r.count);i.setAttribute("color",new hn(n,3)),this.add(new Wn(i,this.material)),this.update()}dispose(){this.children[0].geometry.dispose(),this.children[0].material.dispose()}update(){const t=this.children[0];if(void 0!==this.color)this.material.color.set(this.color);else{const e=t.geometry.getAttribute("color");Jc.copy(this.light.color),Zc.copy(this.light.groundColor);for(let t=0,s=e.count;t<s;t++){const i=t<s/2?Jc:Zc;e.setXYZ(t,i.r,i.g,i.b)}e.needsUpdate=!0}this.light.updateWorldMatrix(!0,!1),t.lookAt(Yc.setFromMatrixPosition(this.light.matrixWorld).negate())}}class Kc extends Oa{constructor(t=10,e=10,s=4473924,i=8947848){s=new Yr(s),i=new Yr(i);const r=e/2,n=t/e,o=t/2,a=[],h=[];for(let t=0,u=0,l=-o;t<=e;t++,l+=n){a.push(-o,0,l,o,0,l),a.push(l,0,-o,l,0,o);const e=t===r?s:i;e.toArray(h,u),u+=3,e.toArray(h,u),u+=3,e.toArray(h,u),u+=3,e.toArray(h,u),u+=3}const u=new Mn;u.setAttribute("position",new yn(a,3)),u.setAttribute("color",new yn(h,3));super(u,new Ma({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}class td extends Oa{constructor(t=10,e=16,s=8,i=64,r=4473924,n=8947848){r=new Yr(r),n=new Yr(n);const o=[],a=[];if(e>1)for(let s=0;s<e;s++){const i=s/e*(2*Math.PI),h=Math.sin(i)*t,u=Math.cos(i)*t;o.push(0,0,0),o.push(h,0,u);const l=1&s?r:n;a.push(l.r,l.g,l.b),a.push(l.r,l.g,l.b)}for(let e=0;e<s;e++){const h=1&e?r:n,u=t-t/s*e;for(let t=0;t<i;t++){let e=t/i*(2*Math.PI),s=Math.sin(e)*u,r=Math.cos(e)*u;o.push(s,0,r),a.push(h.r,h.g,h.b),e=(t+1)/i*(2*Math.PI),s=Math.sin(e)*u,r=Math.cos(e)*u,o.push(s,0,r),a.push(h.r,h.g,h.b)}}const h=new Mn;h.setAttribute("position",new yn(o,3)),h.setAttribute("color",new yn(a,3));super(h,new Ma({vertexColors:!0,toneMapped:!1})),this.type="PolarGridHelper"}dispose(){this.geometry.dispose(),this.material.dispose()}}const ed=new Ei,sd=new Ei,id=new Ei;class rd extends Pr{constructor(t,e,s){super(),this.light=t,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=s,this.type="DirectionalLightHelper",void 0===e&&(e=1);let i=new Mn;i.setAttribute("position",new yn([-e,e,0,e,e,0,e,-e,0,-e,-e,0,-e,e,0],3));const r=new Ma({fog:!1,toneMapped:!1});this.lightPlane=new Pa(i,r),this.add(this.lightPlane),i=new Mn,i.setAttribute("position",new yn([0,0,0,0,0,1],3)),this.targetLine=new Pa(i,r),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),ed.setFromMatrixPosition(this.light.matrixWorld),sd.setFromMatrixPosition(this.light.target.matrixWorld),id.subVectors(sd,ed),this.lightPlane.lookAt(sd),void 0!==this.color?(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(sd),this.targetLine.scale.z=id.length()}}const nd=new Ei,od=new Xn;class ad extends Oa{constructor(t){const e=new Mn,s=new Ma({color:16777215,vertexColors:!0,toneMapped:!1}),i=[],r=[],n={};function o(t,e){a(t),a(e)}function a(t){i.push(0,0,0),r.push(0,0,0),void 0===n[t]&&(n[t]=[]),n[t].push(i.length/3-1)}o("n1","n2"),o("n2","n4"),o("n4","n3"),o("n3","n1"),o("f1","f2"),o("f2","f4"),o("f4","f3"),o("f3","f1"),o("n1","f1"),o("n2","f2"),o("n3","f3"),o("n4","f4"),o("p","n1"),o("p","n2"),o("p","n3"),o("p","n4"),o("u1","u2"),o("u2","u3"),o("u3","u1"),o("c","t"),o("p","c"),o("cn1","cn2"),o("cn3","cn4"),o("cf1","cf2"),o("cf3","cf4"),e.setAttribute("position",new yn(i,3)),e.setAttribute("color",new yn(r,3)),super(e,s),this.type="CameraHelper",this.camera=t,this.camera.updateProjectionMatrix&&this.camera.updateProjectionMatrix(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.pointMap=n,this.update();const h=new Yr(16755200),u=new Yr(16711680),l=new Yr(43775),c=new Yr(16777215),d=new Yr(3355443);this.setColors(h,u,l,c,d)}setColors(t,e,s,i,r){const n=this.geometry.getAttribute("color");n.setXYZ(0,t.r,t.g,t.b),n.setXYZ(1,t.r,t.g,t.b),n.setXYZ(2,t.r,t.g,t.b),n.setXYZ(3,t.r,t.g,t.b),n.setXYZ(4,t.r,t.g,t.b),n.setXYZ(5,t.r,t.g,t.b),n.setXYZ(6,t.r,t.g,t.b),n.setXYZ(7,t.r,t.g,t.b),n.setXYZ(8,t.r,t.g,t.b),n.setXYZ(9,t.r,t.g,t.b),n.setXYZ(10,t.r,t.g,t.b),n.setXYZ(11,t.r,t.g,t.b),n.setXYZ(12,t.r,t.g,t.b),n.setXYZ(13,t.r,t.g,t.b),n.setXYZ(14,t.r,t.g,t.b),n.setXYZ(15,t.r,t.g,t.b),n.setXYZ(16,t.r,t.g,t.b),n.setXYZ(17,t.r,t.g,t.b),n.setXYZ(18,t.r,t.g,t.b),n.setXYZ(19,t.r,t.g,t.b),n.setXYZ(20,t.r,t.g,t.b),n.setXYZ(21,t.r,t.g,t.b),n.setXYZ(22,t.r,t.g,t.b),n.setXYZ(23,t.r,t.g,t.b),n.setXYZ(24,e.r,e.g,e.b),n.setXYZ(25,e.r,e.g,e.b),n.setXYZ(26,e.r,e.g,e.b),n.setXYZ(27,e.r,e.g,e.b),n.setXYZ(28,e.r,e.g,e.b),n.setXYZ(29,e.r,e.g,e.b),n.setXYZ(30,e.r,e.g,e.b),n.setXYZ(31,e.r,e.g,e.b),n.setXYZ(32,s.r,s.g,s.b),n.setXYZ(33,s.r,s.g,s.b),n.setXYZ(34,s.r,s.g,s.b),n.setXYZ(35,s.r,s.g,s.b),n.setXYZ(36,s.r,s.g,s.b),n.setXYZ(37,s.r,s.g,s.b),n.setXYZ(38,i.r,i.g,i.b),n.setXYZ(39,i.r,i.g,i.b),n.setXYZ(40,r.r,r.g,r.b),n.setXYZ(41,r.r,r.g,r.b),n.setXYZ(42,r.r,r.g,r.b),n.setXYZ(43,r.r,r.g,r.b),n.setXYZ(44,r.r,r.g,r.b),n.setXYZ(45,r.r,r.g,r.b),n.setXYZ(46,r.r,r.g,r.b),n.setXYZ(47,r.r,r.g,r.b),n.setXYZ(48,r.r,r.g,r.b),n.setXYZ(49,r.r,r.g,r.b),n.needsUpdate=!0}update(){const t=this.geometry,e=this.pointMap;od.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse),hd("c",e,t,od,0,0,-1),hd("t",e,t,od,0,0,1),hd("n1",e,t,od,-1,-1,-1),hd("n2",e,t,od,1,-1,-1),hd("n3",e,t,od,-1,1,-1),hd("n4",e,t,od,1,1,-1),hd("f1",e,t,od,-1,-1,1),hd("f2",e,t,od,1,-1,1),hd("f3",e,t,od,-1,1,1),hd("f4",e,t,od,1,1,1),hd("u1",e,t,od,.7,1.1,-1),hd("u2",e,t,od,-.7,1.1,-1),hd("u3",e,t,od,0,2,-1),hd("cf1",e,t,od,-1,0,1),hd("cf2",e,t,od,1,0,1),hd("cf3",e,t,od,0,-1,1),hd("cf4",e,t,od,0,1,1),hd("cn1",e,t,od,-1,0,-1),hd("cn2",e,t,od,1,0,-1),hd("cn3",e,t,od,0,-1,-1),hd("cn4",e,t,od,0,1,-1),t.getAttribute("position").needsUpdate=!0}dispose(){this.geometry.dispose(),this.material.dispose()}}function hd(t,e,s,i,r,n,o){nd.set(r,n,o).unproject(i);const a=e[t];if(void 0!==a){const t=s.getAttribute("position");for(let e=0,s=a.length;e<s;e++)t.setXYZ(a[e],nd.x,nd.y,nd.z)}}const ud=new Pi;class ld extends Oa{constructor(t,e=16776960){const s=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]),i=new Float32Array(24),r=new Mn;r.setIndex(new hn(s,1)),r.setAttribute("position",new hn(i,3)),super(r,new Ma({color:e,toneMapped:!1})),this.object=t,this.type="BoxHelper",this.matrixAutoUpdate=!1,this.update()}update(t){if(void 0!==t&&console.warn("THREE.BoxHelper: .update() has no longer arguments."),void 0!==this.object&&ud.setFromObject(this.object),ud.isEmpty())return;const e=ud.min,s=ud.max,i=this.geometry.attributes.position,r=i.array;r[0]=s.x,r[1]=s.y,r[2]=s.z,r[3]=e.x,r[4]=s.y,r[5]=s.z,r[6]=e.x,r[7]=e.y,r[8]=s.z,r[9]=s.x,r[10]=e.y,r[11]=s.z,r[12]=s.x,r[13]=s.y,r[14]=e.z,r[15]=e.x,r[16]=s.y,r[17]=e.z,r[18]=e.x,r[19]=e.y,r[20]=e.z,r[21]=s.x,r[22]=e.y,r[23]=e.z,i.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 cd extends Oa{constructor(t,e=16776960){const s=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]),i=new Mn;i.setIndex(new hn(s,1)),i.setAttribute("position",new yn([1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1],3)),super(i,new Ma({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 dd extends Pa{constructor(t,e=1,s=16776960){const i=s,r=new Mn;r.setAttribute("position",new yn([1,-1,0,-1,1,0,-1,-1,0,1,1,0,-1,1,0,-1,-1,0,1,-1,0,1,1,0],3)),r.computeBoundingSphere(),super(r,new Ma({color:i,toneMapped:!1})),this.type="PlaneHelper",this.plane=t,this.size=e;const n=new Mn;n.setAttribute("position",new yn([1,1,0,-1,1,0,-1,-1,0,1,1,0,-1,-1,0,1,-1,0],3)),n.computeBoundingSphere(),this.add(new Wn(n,new Kr({color:i,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 pd=new Ei;let md,gd;class fd extends Pr{constructor(t=new Ei(0,0,1),e=new Ei(0,0,0),s=1,i=16776960,r=.2*s,n=.2*r){super(),this.type="ArrowHelper",void 0===md&&(md=new Mn,md.setAttribute("position",new yn([0,0,0,0,1,0],3)),gd=new Mh(0,.5,1,5,1),gd.translate(0,-.5,0)),this.position.copy(e),this.line=new Pa(md,new Ma({color:i,toneMapped:!1})),this.line.matrixAutoUpdate=!1,this.add(this.line),this.cone=new Wn(gd,new Kr({color:i,toneMapped:!1})),this.cone.matrixAutoUpdate=!1,this.add(this.cone),this.setDirection(t),this.setLength(s,r,n)}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{pd.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(pd,e)}}setLength(t,e=.2*t,s=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(s,e,s),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 yd extends Oa{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],s=new Mn;s.setAttribute("position",new yn(e,3)),s.setAttribute("color",new yn([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3));super(s,new Ma({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,s){const i=new Yr,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(s),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class xd{constructor(){this.type="ShapePath",this.color=new Yr,this.subPaths=[],this.currentPath=null}moveTo(t,e){return this.currentPath=new Th,this.subPaths.push(this.currentPath),this.currentPath.moveTo(t,e),this}lineTo(t,e){return this.currentPath.lineTo(t,e),this}quadraticCurveTo(t,e,s,i){return this.currentPath.quadraticCurveTo(t,e,s,i),this}bezierCurveTo(t,e,s,i,r,n){return this.currentPath.bezierCurveTo(t,e,s,i,r,n),this}splineThru(t){return this.currentPath.splineThru(t),this}toShapes(t){function e(t,e){const s=e.length;let i=!1;for(let r=s-1,n=0;n<s;r=n++){let s=e[r],o=e[n],a=o.x-s.x,h=o.y-s.y;if(Math.abs(h)>Number.EPSILON){if(h<0&&(s=e[n],a=-a,o=e[r],h=-h),t.y<s.y||t.y>o.y)continue;if(t.y===s.y){if(t.x===s.x)return!0}else{const e=h*(t.x-s.x)-a*(t.y-s.y);if(0===e)return!0;if(e<0)continue;i=!i}}else{if(t.y!==s.y)continue;if(o.x<=t.x&&t.x<=s.x||s.x<=t.x&&t.x<=o.x)return!0}}return i}const s=ou.isClockWise,i=this.subPaths;if(0===i.length)return[];let r,n,o;const a=[];if(1===i.length)return n=i[0],o=new Fh,o.curves=n.curves,a.push(o),a;let h=!s(i[0].getPoints());h=t?!h:h;const u=[],l=[];let c,d,p=[],m=0;l[m]=void 0,p[m]=[];for(let e=0,o=i.length;e<o;e++)n=i[e],c=n.getPoints(),r=s(c),r=t?!r:r,r?(!h&&l[m]&&m++,l[m]={s:new Fh,p:c},l[m].s.curves=n.curves,h&&m++,p[m]=[]):p[m].push({h:n,p:c[0]});if(!l[0])return function(t){const e=[];for(let s=0,i=t.length;s<i;s++){const i=t[s],r=new Fh;r.curves=i.curves,e.push(r)}return e}(i);if(l.length>1){let t=!1,s=0;for(let t=0,e=l.length;t<e;t++)u[t]=[];for(let i=0,r=l.length;i<r;i++){const r=p[i];for(let n=0;n<r.length;n++){const o=r[n];let a=!0;for(let r=0;r<l.length;r++)e(o.p,l[r].p)&&(i!==r&&s++,a?(a=!1,u[r].push(o)):t=!0);a&&u[i].push(o)}}s>0&&!1===t&&(p=u)}for(let t=0,e=l.length;t<e;t++){o=l[t].s,a.push(o),d=p[t];for(let t=0,e=d.length;t<e;t++)o.holes.push(d[t].h)}return a}}class bd extends Si{constructor(t=1,e=1,s=1,i={}){console.warn('THREE.WebGLMultipleRenderTargets has been deprecated and will be removed in r172. Use THREE.WebGLRenderTarget and set the "count" parameter to enable MRT.'),super(t,e,{...i,count:s}),this.isWebGLMultipleRenderTargets=!0}get texture(){return this.textures}}void 0===self.GPUShaderStage&&(self.GPUShaderStage={VERTEX:1,FRAGMENT:2,COMPUTE:4});let vd=void 0!==navigator.gpu;"undefined"!=typeof window&&vd&&(vd=await navigator.gpu.requestAdapter());class Td{static isAvailable(){return Boolean(vd)}static getStaticAdapter(){return vd}static getErrorMessage(){const t=document.createElement("div");return t.id="webgpumessage",t.style.fontFamily="monospace",t.style.fontSize="13px",t.style.fontWeight="normal",t.style.textAlign="center",t.style.background="#fff",t.style.color="#000",t.style.padding="1.5em",t.style.maxWidth="400px",t.style.margin="5em auto 0",t.innerHTML='Your browser does not support <a href="https://gpuweb.github.io/gpuweb/" style="color:blue">WebGPU</a> yet',t}}class _d{constructor(t,e){this.nodes=t,this.info=e,this.animationLoop=null,this.requestId=null,this._init()}_init(){const t=(e,s)=>{this.requestId=self.requestAnimationFrame(t),!0===this.info.autoReset&&this.info.reset(),this.nodes.nodeFrame.update(),this.info.frame=this.nodes.nodeFrame.frameId,null!==this.animationLoop&&this.animationLoop(e,s)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class wd{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let s=0;s<t.length;s++)if(e=e.get(t[s]),void 0===e)return;return e.get(t[t.length-1])}set(t,e){let s=this.weakMap;for(let e=0;e<t.length;e++){const i=t[e];!1===s.has(i)&&s.set(i,new WeakMap),s=s.get(i)}return s.set(t[t.length-1],e)}delete(t){let e=this.weakMap;for(let s=0;s<t.length;s++)if(e=e.get(t[s]),void 0===e)return!1;return e.delete(t[t.length-1])}}const Sd=new sa;let Md=0;class Ad{constructor(){this.version=++Md,this.globalClippingCount=0,this.localClippingCount=0,this.localClippingEnabled=!1,this.localClipIntersection=!1,this.planes=[],this.parentVersion=0,this.viewNormalMatrix=new ti}projectPlanes(t,e){const s=t.length,i=this.planes;for(let r=0;r<s;r++){Sd.copy(t[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const s=i[e+r],n=Sd.normal;s.x=-n.x,s.y=-n.y,s.z=-n.z,s.w=Sd.constant}}updateGlobal(t,e){const s=t.clippingPlanes;this.viewMatrix=e.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix);let i=!1;if(Array.isArray(s)&&0!==s.length){const t=s.length;if(t!==this.globalClippingCount){const e=[];for(let s=0;s<t;s++)e.push(new _i);this.globalClippingCount=t,this.planes=e,i=!0}this.projectPlanes(s,0)}else 0!==this.globalClippingCount&&(this.globalClippingCount=0,this.planes=[],i=!0);t.localClippingEnabled!==this.localClippingEnabled&&(this.localClippingEnabled=t.localClippingEnabled,i=!0),i&&(this.version=Md++)}update(t,e){let s=!1;if(this!==t&&t.version!==this.parentVersion&&(this.globalClippingCount=e.isShadowNodeMaterial?0:t.globalClippingCount,this.localClippingEnabled=t.localClippingEnabled,this.planes=Array.from(t.planes),this.parentVersion=t.version,this.viewMatrix=t.viewMatrix,this.viewNormalMatrix=t.viewNormalMatrix,s=!0),this.localClippingEnabled){const t=e.clippingPlanes;if(Array.isArray(t)&&0!==t.length){const e=t.length,i=this.planes,r=this.globalClippingCount;if(s||e!==this.localClippingCount){i.length=r+e;for(let t=0;t<e;t++)i[r+t]=new _i;this.localClippingCount=e,s=!0}this.projectPlanes(t,r)}else 0!==this.localClippingCount&&(this.localClippingCount=0,s=!0);this.localClipIntersection!==e.clipIntersection&&(this.localClipIntersection=e.clipIntersection,s=!0)}s&&(this.version=Md++)}}let Nd=0;class Rd{constructor(t,e,s,i,r,n,o,a,h){this._nodes=t,this._geometries=e,this.id=Nd++,this.renderer=s,this.object=i,this.material=r,this.scene=n,this.camera=o,this.lightsNode=a,this.context=h,this.geometry=i.geometry,this.version=r.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.updateClipping(h.clippingContext),this.clippingContextVersion=this.clippingContext.version,this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let s=this.clippingContext;Array.isArray(e.clippingPlanes)?(s!==t&&s||(s=new Ad,this.clippingContext=s),s.update(t,e)):this.clippingContext!==t&&(this.clippingContext=t)}get clippingNeedsUpdate(){return this.clippingContext.version!==this.clippingContextVersion&&(this.clippingContextVersion=this.clippingContext.version,!0)}getNodeBuilderState(){return this._nodeBuilderState||(this._nodeBuilderState=this._nodes.getForRender(this))}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getChainArray(){return[this.object,this.material,this.context,this.lightsNode]}getAttributes(){if(null!==this.attributes)return this.attributes;const t=this.getNodeBuilderState().nodeAttributes,e=this.geometry,s=[],i=new Set;for(const r of t){const t=r.node&&r.node.attribute?r.node.attribute:e.getAttribute(r.name);if(void 0===t)continue;s.push(t);const n=t.isInterleavedBufferAttribute?t.data:t;i.add(n)}return this.attributes=s,this.vertexBuffers=Array.from(i.values()),s}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getMaterialCacheKey(){const{object:t,material:e}=this;let s=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let s=Object.getPrototypeOf(t);for(;s;){const t=Object.getOwnPropertyDescriptors(s);for(const s in t)if(void 0!==t[s]){const i=t[s];i&&"function"==typeof i.get&&e.push(s)}s=Object.getPrototypeOf(s)}return e}(e)){if(/^(is[A-Z]|_)|^(visible|version|uuid|name|opacity|userData)$/.test(t))continue;const i=e[t];let r;if(null!==i){const t=typeof i;"number"===t?r=0!==i?"1":"0":"object"===t?(r="{",i.isTexture&&(r+=i.mapping),r+="}"):r=String(i)}else r=String(i);s+=r+","}return s+=this.clippingContextVersion+",",t.skeleton&&(s+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(s+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(s+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(s+=t._colorsTexture.uuid+",")),t.count>1&&(s+=t.count+","),s}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){return this.object.receiveShadow+","+this._nodes.getCacheKey(this.scene,this.lightsNode)}getCacheKey(){return this.getMaterialCacheKey()+","+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}class Cd{constructor(t,e,s,i,r,n){this.renderer=t,this.nodes=e,this.geometries=s,this.pipelines=i,this.bindings=r,this.info=n,this.chainMaps={}}get(t,e,s,i,r,n,o){const a=this.getChainMap(o),h=[t,e,n,r];let u=a.get(h);return void 0===u?(u=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,s,i,r,n,o),a.set(h,u)):(u.updateClipping(n.clippingContext),(u.version!==e.version||u.needsUpdate)&&(u.initialCacheKey!==u.getCacheKey()?(u.dispose(),u=this.get(t,e,s,i,r,n,o)):u.version=e.version)),u}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new wd)}dispose(){this.chainMaps={}}createRenderObject(t,e,s,i,r,n,o,a,h,u){const l=this.getChainMap(u),c=new Rd(t,e,s,i,r,n,o,a,h);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),l.delete(c.getChainArray())},c}}class Ed{constructor(){this.data=new WeakMap}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}delete(t){let e;return this.data.has(t)&&(e=this.data.get(t),this.data.delete(t)),e}has(t){return this.data.has(t)}dispose(){this.data=new WeakMap}}const Bd=1,Id=2,Pd=4,Fd=16;class Ud extends Ed{constructor(t){super(),this.backend=t}delete(t){const e=super.delete(t);return void 0!==e&&this.backend.destroyAttribute(t),e}update(t,e){const s=this.get(t);if(void 0===s.version)e===Bd?this.backend.createAttribute(t):e===Id?this.backend.createIndexAttribute(t):e===Pd&&this.backend.createStorageAttribute(t),s.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(s.version<e.version||e.usage===Cs)&&(this.backend.updateAttribute(t),s.version=e.version)}}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}function zd(t){return null!==t.index?t.index.version:t.attributes.position.version}function Od(t){const e=[],s=t.index,i=t.attributes.position;if(null!==s){const t=s.array;for(let s=0,i=t.length;s<i;s+=3){const i=t[s+0],r=t[s+1],n=t[s+2];e.push(i,r,r,n,n,i)}}else{for(let t=0,s=i.array.length/3-1;t<s;t+=3){const s=t+0,i=t+1,r=t+2;e.push(s,i,i,r,r,s)}}const r=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(e)?gn:pn)(e,1);return r.version=zd(t),r}class Ld extends Ed{constructor(t,e){super(),this.attributes=t,this.info=e,this.wireframes=new WeakMap,this.attributeCall=new WeakMap}has(t){const e=t.geometry;return super.has(e)&&!0===this.get(e).initialized}updateForRender(t){!1===this.has(t)&&this.initGeometry(t),this.updateAttributes(t)}initGeometry(t){const e=t.geometry;this.get(e).initialized=!0,this.info.memory.geometries++;const s=()=>{this.info.memory.geometries--;const i=e.index,r=t.getAttributes();null!==i&&this.attributes.delete(i);for(const t of r)this.attributes.delete(t);const n=this.wireframes.get(e);void 0!==n&&this.attributes.delete(n),e.removeEventListener("dispose",s)};e.addEventListener("dispose",s)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,Pd):this.updateAttribute(t,Bd);const s=this.getIndex(t);null!==s&&this.updateAttribute(s,Id)}updateAttribute(t,e){const s=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,s)):this.attributeCall.get(t.data)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t.data,s),this.attributeCall.set(t,s)):this.attributeCall.get(t)!==s&&(this.attributes.update(t,e),this.attributeCall.set(t,s))}getIndex(t){const{geometry:e,material:s}=t;let i=e.index;if(!0===s.wireframe){const t=this.wireframes;let s=t.get(e);void 0===s?(s=Od(e),t.set(e,s)):s.version!==zd(e)&&(this.attributes.delete(s),s=Od(e),t.set(e,s)),i=s}return i}}class Vd{constructor(){this.autoReset=!0,this.frame=0,this.calls=0,this.render={calls:0,frameCalls:0,drawCalls:0,triangles:0,points:0,lines:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.compute={calls:0,frameCalls:0,timestamp:0,previousFrameCalls:0,timestampCalls:0},this.memory={geometries:0,textures:0}}update(t,e,s){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=s*(e/3):t.isPoints?this.render.points+=s*e:t.isLineSegments?this.render.lines+=s*(e/2):t.isLine?this.render.lines+=s*(e-1):console.error("THREE.WebGPUInfo: Unknown object type.")}updateTimestamp(t,e){0===this[t].timestampCalls&&(this[t].timestamp=0),this[t].timestamp+=e,this[t].timestampCalls++,this[t].timestampCalls>=this[t].previousFrameCalls&&(this[t].timestampCalls=0)}reset(){const t=this.render.frameCalls;this.render.previousFrameCalls=t;const e=this.compute.frameCalls;this.compute.previousFrameCalls=e,this.render.drawCalls=0,this.render.frameCalls=0,this.compute.frameCalls=0,this.render.triangles=0,this.render.points=0,this.render.lines=0}dispose(){this.reset(),this.calls=0,this.render.calls=0,this.compute.calls=0,this.render.timestamp=0,this.compute.timestamp=0,this.memory.geometries=0,this.memory.textures=0}}class Dd{constructor(t){this.cacheKey=t,this.usedTimes=0}}class kd extends Dd{constructor(t,e,s){super(t),this.vertexProgram=e,this.fragmentProgram=s}}class Gd extends Dd{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let Wd=0;class jd{constructor(t,e,s=null,i=null){this.id=Wd++,this.code=t,this.stage=e,this.transforms=s,this.attributes=i,this.usedTimes=0}}class Hd extends Ed{constructor(t,e){super(),this.backend=t,this.nodes=e,this.bindings=null,this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}getForCompute(t,e){const{backend:s}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const n=this.nodes.getForCompute(t);let o=this.programs.compute.get(n.computeShader);void 0===o&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),o=new jd(n.computeShader,"compute",n.transforms,n.nodeAttributes),this.programs.compute.set(n.computeShader,o),s.createProgram(o));const a=this._getComputeCacheKey(t,o);let h=this.caches.get(a);void 0===h&&(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getComputePipeline(t,o,a,e)),h.usedTimes++,o.usedTimes++,i.version=t.version,i.pipeline=h}return i.pipeline}getForRender(t,e=null){const{backend:s}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const n=t.getNodeBuilderState();let o=this.programs.vertex.get(n.vertexShader);void 0===o&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),o=new jd(n.vertexShader,"vertex"),this.programs.vertex.set(n.vertexShader,o),s.createProgram(o));let a=this.programs.fragment.get(n.fragmentShader);void 0===a&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),a=new jd(n.fragmentShader,"fragment"),this.programs.fragment.set(n.fragmentShader,a),s.createProgram(a));const h=this._getRenderCacheKey(t,o,a);let u=this.caches.get(h);void 0===u?(r&&0===r.usedTimes&&this._releasePipeline(r),u=this._getRenderPipeline(t,o,a,h,e)):t.pipeline=u,u.usedTimes++,o.usedTimes++,a.usedTimes++,i.pipeline=u}return i.pipeline}delete(t){const e=this.get(t).pipeline;return e&&(e.usedTimes--,0===e.usedTimes&&this._releasePipeline(e),e.isComputePipeline?(e.computeProgram.usedTimes--,0===e.computeProgram.usedTimes&&this._releaseProgram(e.computeProgram)):(e.fragmentProgram.usedTimes--,e.vertexProgram.usedTimes--,0===e.vertexProgram.usedTimes&&this._releaseProgram(e.vertexProgram),0===e.fragmentProgram.usedTimes&&this._releaseProgram(e.fragmentProgram))),super.delete(t)}dispose(){super.dispose(),this.caches=new Map,this.programs={vertex:new Map,fragment:new Map,compute:new Map}}updateForRender(t){this.getForRender(t)}_getComputePipeline(t,e,s,i){s=s||this._getComputeCacheKey(t,e);let r=this.caches.get(s);return void 0===r&&(r=new Gd(s,e),this.caches.set(s,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,s,i,r){i=i||this._getRenderCacheKey(t,e,s);let n=this.caches.get(i);return void 0===n&&(n=new kd(i,e,s),this.caches.set(i,n),t.pipeline=n,this.backend.createRenderPipeline(t,r)),n}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,s){return e.id+","+s.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,s=t.stage;this.programs[s].delete(e)}_needsComputeUpdate(t){const e=this.get(t);return void 0===e.pipeline||e.version!==t.version}_needsRenderUpdate(t){return void 0===this.get(t).pipeline||this.backend.needsRenderUpdate(t)}}class qd extends Ed{constructor(t,e,s,i,r,n){super(),this.backend=t,this.textures=s,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=n,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const s=this.get(t);void 0===s.bindGroup&&(this._init(t),this.backend.createBindings(t,e),s.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(t,this.getForCompute(t))}updateForRender(t){this._updateBindings(t,this.getForRender(t))}_updateBindings(t,e){for(const s of e)this._update(t,s,e)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute;this.attributes.update(t,Pd)}}_update(t,e,s){const{backend:i}=this;let r=!1;for(const t of e.bindings){if(t.isNodeUniformsGroup){if(!this.nodes.updateGroup(t))continue}if(t.isUniformBuffer){t.update()&&i.updateBinding(t)}else if(t.isSampler)t.update();else if(t.isSampledTexture){const e=t.texture;t.needsBindingsUpdate&&(r=!0);const s=t.update();s&&this.textures.updateTexture(t.texture);const n=i.get(t.texture);if(!0===i.isWebGPUBackend&&void 0===n.texture&&void 0===n.externalTexture&&(console.error("Bindings._update: binding should be available:",t,s,t.texture,t.textureNode.value),this.textures.updateTexture(t.texture),r=!0),!0===e.isStorageTexture){const s=this.get(e);!0===t.store?s.needsMipmap=!0:!0===e.generateMipmaps&&this.textures.needsMipmaps(e)&&!0===s.needsMipmap&&(this.backend.generateMipmaps(e),s.needsMipmap=!1)}}}if(!0===r){const i=this.pipelines.getForRender(t);this.backend.updateBindings(e,s,i)}}}const $d={VERTEX:"vertex",FRAGMENT:"fragment"},Xd={NONE:"none",FRAME:"frame",RENDER:"render",OBJECT:"object"},Yd={BOOLEAN:"bool",INTEGER:"int",FLOAT:"float",VECTOR2:"vec2",VECTOR3:"vec3",VECTOR4:"vec4",MATRIX2:"mat2",MATRIX3:"mat3",MATRIX4:"mat4"},Jd=["fragment","vertex"],Zd=["setup","analyze","generate"],Qd=[...Jd,"compute"],Kd=["x","y","z","w"];function tp(t,e=!1){let s="{";!0===t.isNode&&(s+=t.id);for(const{property:i,childNode:r}of ep(t))s+=","+i.slice(0,-4)+":"+r.getCacheKey(e);return s+="}",s}function*ep(t,e=!1){for(const s in t){if(!0===s.startsWith("_"))continue;const i=t[s];if(!0===Array.isArray(i))for(let t=0;t<i.length;t++){const r=i[t];r&&(!0===r.isNode||e&&"function"==typeof r.toJSON)&&(yield{property:s,index:t,childNode:r})}else if(i&&!0===i.isNode)yield{property:s,childNode:i};else if("object"==typeof i)for(const t in i){const r=i[t];r&&(!0===r.isNode||e&&"function"==typeof r.toJSON)&&(yield{property:s,index:t,childNode:r})}}}function sp(t){if(null==t)return null;const e=typeof t;return!0===t.isNode?"node":"number"===e?"float":"boolean"===e?"bool":"string"===e?"string":"function"===e?"shader":!0===t.isVector2?"vec2":!0===t.isVector3?"vec3":!0===t.isVector4?"vec4":!0===t.isMatrix3?"mat3":!0===t.isMatrix4?"mat4":!0===t.isColor?"color":t instanceof ArrayBuffer?"ArrayBuffer":null}function ip(t,...e){const s=t?t.slice(-4):void 0;return 1===e.length&&("vec2"===s?e=[e[0],e[0]]:"vec3"===s?e=[e[0],e[0],e[0]]:"vec4"===s&&(e=[e[0],e[0],e[0],e[0]])),"color"===t?new Yr(...e):"vec2"===s?new Ks(...e):"vec3"===s?new Ei(...e):"vec4"===s?new _i(...e):"mat3"===s?new ti(...e):"mat4"===s?new or(...e):"bool"===t?e[0]||!1:"float"===t||"int"===t||"uint"===t?e[0]||0:"string"===t?e[0]||"":"ArrayBuffer"===t?np(e[0]):null}function rp(t){let e="";const s=new Uint8Array(t);for(let t=0;t<s.length;t++)e+=String.fromCharCode(s[t]);return btoa(e)}function np(t){return Uint8Array.from(atob(t),(t=>t.charCodeAt(0))).buffer}var op=Object.freeze({__proto__:null,arrayBufferToBase64:rp,base64ToArrayBuffer:np,getCacheKey:tp,getNodeChildren:ep,getValueFromType:ip,getValueType:sp});const ap=new Map;let hp=0;class up extends ks{constructor(t=null){super(),this.nodeType=t,this.updateType=Xd.NONE,this.updateBeforeType=Xd.NONE,this.updateAfterType=Xd.NONE,this.uuid=Qs.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:hp++})}set needsUpdate(t){!0===t&&this.version++}get type(){return this.constructor.type}onUpdate(t,e){return this.updateType=e,this.update=t.bind(this.getSelf()),this}onFrameUpdate(t){return this.onUpdate(t,Xd.FRAME)}onRenderUpdate(t){return this.onUpdate(t,Xd.RENDER)}onObjectUpdate(t){return this.onUpdate(t,Xd.OBJECT)}onReference(t){return this.updateReference=t.bind(this.getSelf()),this}getSelf(){return this.self||this}updateReference(){return this}isGlobal(){return this.global}*getChildren(){for(const{childNode:t}of ep(this))yield t}dispose(){this.dispatchEvent({type:"dispose"})}traverse(t){t(this);for(const e of this.getChildren())e.traverse(t)}getCacheKey(t=!1){return!0!==(t=t||this.version!==this._cacheKeyVersion)&&null!==this._cacheKey||(this._cacheKey=tp(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getHash(){return this.uuid}getUpdateType(){return this.updateType}getUpdateBeforeType(){return this.updateBeforeType}getUpdateAfterType(){return this.updateAfterType}getElementType(t){const e=this.getNodeType(t);return t.getElementType(e)}getNodeType(t){const e=t.getNodeProperties(this);return e.outputNode?e.outputNode.getNodeType(t):this.nodeType}getShared(t){const e=this.getHash(t);return t.getNodeFromHash(e)||this}setup(t){const e=t.getNodeProperties(this);let s=0;for(const t of this.getChildren())e["node"+s++]=t;return null}increaseUsage(t){const e=t.getDataFromNode(this);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}analyze(t){if(1===this.increaseUsage(t)){const e=t.getNodeProperties(this);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);if(s&&!0===s.isNode)return s.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const s=this.getShared(t);if(this!==s)return s.build(t,e);t.addNode(this),t.addChain(this);let i=null;const r=t.getBuildStage();if("setup"===r){this.updateReference(t);const e=t.getNodeProperties(this);if(!0!==e.initialized){const s=t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length!==s&&(e.outputNode=t.stack);for(const s of Object.values(e))s&&!0===s.isNode&&s.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const s=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i&&(i=this.generate(t)||"",r.snippet=i),i=t.format(i,s,e)}else i=this.generate(t,e)||""}return t.removeChain(this),i}getSerializeChildren(){return ep(this)}serialize(t){const e=this.getSerializeChildren(),s={};for(const{property:i,index:r,childNode:n}of e)void 0!==r?(void 0===s[i]&&(s[i]=Number.isInteger(r)?[]:{}),s[i][r]=n.toJSON(t.meta).uuid):s[i]=n.toJSON(t.meta).uuid;Object.keys(s).length>0&&(t.inputNodes=s)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const s in t.inputNodes)if(Array.isArray(t.inputNodes[s])){const i=[];for(const r of t.inputNodes[s])i.push(e[r]);this[s]=i}else if("object"==typeof t.inputNodes[s]){const i={};for(const r in t.inputNodes[s]){const n=t.inputNodes[s][r];i[r]=e[n]}this[s]=i}else{const i=t.inputNodes[s];this[s]=e[i]}}}toJSON(t){const{uuid:e,type:s}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function n(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:s,meta:t,metadata:{version:4.6,type:"Node",generator:"Node.toJSON"}},!0!==i&&(t.nodes[r.uuid]=r),this.serialize(r),delete r.meta),i){const e=n(t.textures),s=n(t.images),i=n(t.nodes);e.length>0&&(r.textures=e),s.length>0&&(r.images=s),i.length>0&&(r.nodes=i)}return r}}function lp(t,e){if("function"!=typeof e||!t)throw new Error(`Node class ${t} is not a class`);ap.has(t)?console.warn(`Redefinition of node class ${t}`):(ap.set(t,e),e.type=t)}function cp(t){const e=ap.get(t);if(void 0!==e)return new e}class dp extends up{constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const s=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,s,e);if("void"!==s&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,s),n=t.getVarFromNode(this,null,s),o=t.getPropertyName(n);return t.addLineFlowCode(`${o} = ${r}`),i.snippet=r,i.propertyName=o,t.format(i.propertyName,s,e)}}return super.build(t,e)}}lp("TempNode",dp);class pp extends up{constructor(t,e){super(),this.node=t,this.indexNode=e,this.isArrayElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){return`${this.node.build(t)}[ ${this.indexNode.build(t,"uint")} ]`}}lp("ArrayElementNode",pp);class mp extends up{constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let s=null;for(const i of this.convertTo.split("|"))null!==s&&t.getTypeLength(e)!==t.getTypeLength(i)||(s=i);return s}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const s=this.node,i=this.getNodeType(t),r=s.build(t,i);return t.format(r,i,e)}}lp("ConvertNode",mp);class gp extends dp{constructor(t=[],e=null){super(e),this.nodes=t}getNodeType(t){return null!==this.nodeType?t.getVectorType(this.nodeType):t.getTypeFromLength(this.nodes.reduce(((e,s)=>e+t.getTypeLength(s.getNodeType(t))),0))}generate(t,e){const s=this.getNodeType(t),i=this.nodes,r=t.getComponentType(s),n=[];for(const e of i){let s=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(s=t.format(s,i,r)),n.push(s)}const o=`${t.getType(s)}( ${n.join(", ")} )`;return t.format(o,s,e)}}lp("JoinNode",gp);const fp=Kd.join("");class yp extends up{constructor(t,e="x"){super(),this.node=t,this.components=e,this.isSplitNode=!0}getVectorLength(){let t=this.components.length;for(const e of this.components)t=Math.max(Kd.indexOf(e)+1,t);return t}getComponentType(t){return t.getComponentType(this.node.getNodeType(t))}getNodeType(t){return t.getTypeFromLength(this.components.length,this.getComponentType(t))}generate(t,e){const s=this.node,i=t.getTypeLength(s.getNodeType(t));let r=null;if(i>1){let n=null;this.getVectorLength()>=i&&(n=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const o=s.build(t,n);r=this.components.length===i&&this.components===fp.slice(0,this.components.length)?t.format(o,n,e):t.format(`${o}.${this.components}`,this.getNodeType(t),e)}else r=s.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}lp("SplitNode",yp);class xp extends dp{constructor(t,e,s){super(),this.sourceNode=t,this.components=e,this.targetNode=s}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:s,targetNode:i}=this,r=this.getNodeType(t),n=t.getTypeFromLength(s.length),o=i.build(t,n),a=e.build(t,r),h=t.getTypeLength(r),u=[];for(let t=0;t<h;t++){const e=Kd[t];e===s[0]?(u.push(o),t+=s.length-1):u.push(a+"."+e)}return`${t.getType(r)}( ${u.join(", ")} )`}}lp("SetNode",xp);class bp extends up{constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return null===this.nodeType?sp(this.value):this.nodeType}getInputType(t){return this.getNodeType(t)}setPrecision(t){return this.precision=t,this}serialize(t){super.serialize(t),t.value=this.value,this.value&&this.value.toArray&&(t.value=this.value.toArray()),t.valueType=sp(this.value),t.nodeType=this.nodeType,"ArrayBuffer"===t.valueType&&(t.value=rp(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?ip(t.valueType,...t.value):t.value,this.precision=t.precision||null,this.value&&this.value.fromArray&&(this.value=this.value.fromArray(t.value))}generate(){console.warn("Abstract function.")}}lp("InputNode",bp);class vp extends bp{constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const s=this.getNodeType(t);return t.format(this.generateConst(t),s,e)}}lp("ConstNode",vp);let Tp=null;const _p=new Map;function wp(t,e){if(_p.has(t))console.warn(`Redefinition of node element ${t}`);else{if("function"!=typeof e)throw new Error(`Node element ${t} is not a function`);_p.set(t,e)}}const Sp=t=>t.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Mp={setup(t,e){const s=e.shift();return t(Jp(s),...e)},get(t,e,s){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>(Tp.assign(s,...t),s);if(_p.has(e)){const i=_p.get(e);return t.isStackNode?(...t)=>s.add(i(...t)):(...t)=>i(s,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&_p.has(e.slice(0,e.length-6))){const i=_p.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>s.assign(t[0],i(...t)):(...t)=>s.assign(i(s,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=Sp(e),Yp(new yp(s,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=(e=Sp(e.slice(3).toLowerCase())).split("").sort().join(""),s=>Yp(new xp(t,e,s));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),Yp(new yp(t,e));if(!0===/^\d+$/.test(e))return Yp(new pp(s,new vp(Number(e),"uint")))}return Reflect.get(t,e,s)},set:(t,e,s,i)=>"string"!=typeof e||void 0!==t[e]||!0!==/^[xyzwrgbastpq]{1,4}$/.test(e)&&"width"!==e&&"height"!==e&&"depth"!==e&&!0!==/^\d+$/.test(e)?Reflect.set(t,e,s,i):(i[e].assign(s),!0)},Ap=new WeakMap,Np=new WeakMap,Rp=function(t,e=null){for(const s in t)t[s]=Yp(t[s],e);return t},Cp=function(t,e=null){const s=t.length;for(let i=0;i<s;i++)t[i]=Yp(t[i],e);return t},Ep=function(t,e=null,s=null,i=null){const r=t=>Yp(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...Zp(e))):null!==s?(s=Yp(s),(...i)=>r(new t(e,...Zp(i),s))):(...s)=>r(new t(e,...Zp(s)))},Bp=function(t,...e){return Yp(new t(...Zp(e)))};class Ip extends up{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode.getNodeType(t)}call(t){const{shaderNode:e,inputNodes:s}=this;if(e.layout){let i=Np.get(t.constructor);void 0===i&&(i=new WeakMap,Np.set(t.constructor,i));let r=i.get(e);return void 0===r&&(r=Yp(t.buildFunctionNode(e)),i.set(e,r)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(r),Yp(r.call(s))}const i=e.jsFunc,r=null!==s?i(s,t.stack,t):i(t.stack,t);return Yp(r)}setup(t){const{outputNode:e}=t.getNodeProperties(this);return e||this.setupOutput(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){const{outputNode:s}=t.getNodeProperties(this);return null===s?this.call(t).build(t,e):super.generate(t,e)}}class Pp extends up{constructor(t){super(),this.jsFunc=t,this.layout=null,this.global=!0}get isArrayInput(){return/^\((\s+)?\[/.test(this.jsFunc.toString())}setLayout(t){return this.layout=t,this}call(t=null){return Jp(t),Yp(new Ip(this,t))}setup(){return this.call()}}const Fp=[!1,!0],Up=[0,1,2,3],zp=[-1,-2],Op=[.5,1.5,1/3,1e-6,1e6,Math.PI,2*Math.PI,1/Math.PI,2/Math.PI,1/(2*Math.PI),Math.PI/2],Lp=new Map;for(const t of Fp)Lp.set(t,new vp(t));const Vp=new Map;for(const t of Up)Vp.set(t,new vp(t,"uint"));const Dp=new Map([...Vp].map((t=>new vp(t.value,"int"))));for(const t of zp)Dp.set(t,new vp(t,"int"));const kp=new Map([...Dp].map((t=>new vp(t.value))));for(const t of Op)kp.set(t,new vp(t));for(const t of Op)kp.set(-t,new vp(-t));const Gp={bool:Lp,uint:Vp,ints:Dp,float:kp},Wp=new Map([...Lp,...kp]),jp=(t,e)=>Wp.has(t)?Wp.get(t):!0===t.isNode?t:new vp(t,e),Hp=function(t,e=null){return(...s)=>{if((0===s.length||!["bool","float","int","uint"].includes(t)&&s.every((t=>"object"!=typeof t)))&&(s=[ip(t,...s)]),1===s.length&&null!==e&&e.has(s[0]))return Yp(e.get(s[0]));if(1===s.length){const e=jp(s[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?Yp(e):Yp(new mp(e,t))}const i=s.map((t=>jp(t)));return Yp(new gp(i,t))}},qp=t=>t&&t.value,$p=t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null;function Xp(t){return new Proxy(new Pp(t),Mp)}const Yp=(t,e=null)=>function(t,e=null){const s=sp(t);if("node"===s){let e=Ap.get(t);return void 0===e&&(e=new Proxy(t,Mp),Ap.set(t,e),Ap.set(e,e)),e}return null===e&&("float"===s||"boolean"===s)||s&&"shader"!==s&&"string"!==s?Yp(jp(t,e)):"shader"===s?tm(t):t}(t,e),Jp=(t,e=null)=>new Rp(t,e),Zp=(t,e=null)=>new Cp(t,e),Qp=(...t)=>new Ep(...t),Kp=(...t)=>new Bp(...t),tm=t=>{const e=new Xp(t),s=(...t)=>{let s;return Jp(t),s=t[0]&&t[0].isNode?[...t]:t[0],e.call(s)};return s.shaderNode=e,s.setLayout=t=>(e.setLayout(t),s),s};lp("ShaderNode",Xp),wp("toGlobal",(t=>(t.global=!0,t)));const em=t=>{Tp=t},sm=()=>Tp,im=(...t)=>Tp.if(...t);function rm(t){return Tp&&Tp.add(t),t}wp("append",rm);const nm=new Hp("color"),om=new Hp("float",Gp.float),am=new Hp("int",Gp.ints),hm=new Hp("uint",Gp.uint),um=new Hp("bool",Gp.bool),lm=new Hp("vec2"),cm=new Hp("ivec2"),dm=new Hp("uvec2"),pm=new Hp("bvec2"),mm=new Hp("vec3"),gm=new Hp("ivec3"),fm=new Hp("uvec3"),ym=new Hp("bvec3"),xm=new Hp("vec4"),bm=new Hp("ivec4"),vm=new Hp("uvec4"),Tm=new Hp("bvec4"),_m=new Hp("mat2"),wm=new Hp("imat2"),Sm=new Hp("umat2"),Mm=new Hp("bmat2"),Am=new Hp("mat3"),Nm=new Hp("imat3"),Rm=new Hp("umat3"),Cm=new Hp("bmat3"),Em=new Hp("mat4"),Bm=new Hp("imat4"),Im=new Hp("umat4"),Pm=new Hp("bmat4"),Fm=(t="")=>Yp(new vp(t,"string")),Um=t=>Yp(new vp(t,"ArrayBuffer"));wp("toColor",nm),wp("toFloat",om),wp("toInt",am),wp("toUint",hm),wp("toBool",um),wp("toVec2",lm),wp("toIvec2",cm),wp("toUvec2",dm),wp("toBvec2",pm),wp("toVec3",mm),wp("toIvec3",gm),wp("toUvec3",fm),wp("toBvec3",ym),wp("toVec4",xm),wp("toIvec4",bm),wp("toUvec4",vm),wp("toBvec4",Tm),wp("toMat2",_m),wp("toImat2",wm),wp("toUmat2",Sm),wp("toBmat2",Mm),wp("toMat3",Am),wp("toImat3",Nm),wp("toUmat3",Rm),wp("toBmat3",Cm),wp("toMat4",Em),wp("toImat4",Bm),wp("toUmat4",Im),wp("toBmat4",Pm);const zm=Qp(pp),Om=(t,e)=>Yp(new mp(Yp(t),e)),Lm=(t,e)=>Yp(new yp(Yp(t),e));wp("element",zm),wp("convert",Om);class Vm extends dp{constructor(t,e){super(),this.targetNode=t,this.sourceNode=e}hasDependencies(){return!1}getNodeType(t,e){return"void"!==e?this.targetNode.getNodeType(t):"void"}needsSplitAssign(t){const{targetNode:e}=this;if(!1===t.isAvailable("swizzleAssign")&&e.isSplitNode&&e.components.length>1){const s=t.getTypeLength(e.node.getNodeType(t));return Kd.join("").slice(0,s)!==e.components}return!1}generate(t,e){const{targetNode:s,sourceNode:i}=this,r=this.needsSplitAssign(t),n=s.getNodeType(t),o=s.context({assign:!0}).build(t),a=i.build(t,n),h=i.getNodeType(t),u=t.getDataFromNode(this);let l;if(!0===u.initialized)"void"!==e&&(l=o);else if(r){const i=t.getVarFromNode(this,null,n),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${a}`);const h=s.node.context({assign:!0}).build(t);for(let e=0;e<s.components.length;e++){const i=s.components[e];t.addLineFlowCode(`${h}.${i} = ${r}[ ${e} ]`)}"void"!==e&&(l=o)}else l=`${o} = ${a}`,"void"!==e&&"void"!==h||(t.addLineFlowCode(l),"void"!==e&&(l=o));return u.initialized=!0,t.format(l,n,e)}}const Dm=Qp(Vm);lp("AssignNode",Vm),wp("assign",Dm);class km extends up{constructor(t,e=null){super(),this.node=t,this.name=e,this.isVaryingNode=!0}isGlobal(){return!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}setupVarying(t){const e=t.getNodeProperties(this);let s=e.varying;if(void 0===s){const i=this.name,r=this.getNodeType(t);e.varying=s=t.getVaryingFromNode(this,i,r),e.node=this.node}return s.needsInterpolation||(s.needsInterpolation="fragment"===t.shaderStage),s}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),s=this.setupVarying(t);if(void 0===e.propertyName){const i=this.getNodeType(t),r=t.getPropertyName(s,$d.VERTEX);t.flowNodeFromShaderStage($d.VERTEX,this.node,i,r),e.propertyName=r}return t.getPropertyName(s)}}const Gm=Qp(km);wp("varying",Gm),lp("VaryingNode",km);class Wm extends up{constructor(t,e=null,s=null){super(e),this.defaultNode=s,this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=super.getNodeType(t);if(null===e){const s=this.getAttributeName(t);if(t.hasGeometryAttribute(s)){const i=t.geometry.getAttribute(s);e=t.getTypeFromAttribute(i)}else e="float"}return e}setAttributeName(t){return this._attributeName=t,this}getAttributeName(){return this._attributeName}generate(t){const e=this.getAttributeName(t),s=this.getNodeType(t);if(!0===t.hasGeometryAttribute(e)){const i=t.geometry.getAttribute(e),r=t.getTypeFromAttribute(i),n=t.getAttribute(e,r);if("vertex"===t.shaderStage)return t.format(n.name,r,s);return Gm(this).build(t,s)}{console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`);const{defaultNode:i}=this;return null!==i?i.build(t,s):t.generateConst(s)}}serialize(t){super.serialize(t),t.global=this.global,t._attributeName=this._attributeName}deserialize(t){super.deserialize(t),this.global=t.global,this._attributeName=t._attributeName}}const jm=(t,e,s)=>Yp(new Wm(t,e,Yp(s)));lp("AttributeNode",Wm);class Hm extends up{constructor(t,e){super(),this.isBypassNode=!0,this.outputNode=t,this.callNode=e}getNodeType(t){return this.outputNode.getNodeType(t)}generate(t){const e=this.callNode.build(t,"void");return""!==e&&t.addLineFlowCode(e),this.outputNode.build(t)}}const qm=Qp(Hm);wp("bypass",qm),lp("BypassNode",Hm);class $m extends up{constructor(t,e=!0){super(),this.node=t,this.parent=e,this.isCacheNode=!0}getNodeType(t){return this.node.getNodeType(t)}build(t,...e){const s=t.getCache(),i=t.getCacheFromNode(this,parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(s),r}}const Xm=(t,...e)=>Yp(new $m(Yp(t),...e));wp("cache",Xm),lp("CacheNode",$m);class Ym extends up{constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.context=e}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.context});const s=this.node.build(t);return t.setContext(e),s}generate(t,e){const s=t.getContext();t.setContext({...t.context,...this.context});const i=this.node.build(t,e);return t.setContext(s),i}}const Jm=Qp(Ym),Zm=(t,e)=>Jm(t,{label:e});wp("context",Jm),wp("label",Zm),lp("ContextNode",Ym);class Qm extends up{constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),s=this.scope;let i,r;if(s===Qm.VERTEX)i=t.getVertexIndex();else if(s===Qm.INSTANCE)i=t.getInstanceIndex();else{if(s!==Qm.DRAW)throw new Error("THREE.IndexNode: Unknown scope: "+s);i=t.getDrawIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=Gm(this).build(t,e)}return r}}Qm.VERTEX="vertex",Qm.INSTANCE="instance",Qm.DRAW="draw";const Km=Kp(Qm,Qm.VERTEX),tg=Kp(Qm,Qm.INSTANCE),eg=Kp(Qm,Qm.DRAW);lp("IndexNode",Qm);class sg{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class ig extends up{constructor(t,e=null){super(),this.node=t,this.name=e,this.global=!0,this.isVarNode=!0}getHash(t){return this.name||super.getHash(t)}getNodeType(t){return this.node.getNodeType(t)}generate(t){const{node:e,name:s}=this,i=t.getVarFromNode(this,s,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),n=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${n}`),r}}const rg=Qp(ig);wp("temp",rg),wp("toVar",((...t)=>rg(...t).append())),lp("VarNode",ig);class ng{constructor(t,e,s=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=s}}class og{constructor(t,e,s){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=s.getSelf()}get value(){return this.node.value}set value(t){this.node.value=t}get id(){return this.node.id}get groupNode(){return this.node.groupNode}}class ag{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class hg extends ag{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class ug{constructor(t,e,s=""){this.name=t,this.type=e,this.code=s,Object.defineProperty(this,"isNodeCode",{value:!0})}}class lg{constructor(){this.keywords=[],this.nodes={},this.keywordsCallback={}}getNode(t){let e=this.nodes[t];return void 0===e&&void 0!==this.keywordsCallback[t]&&(e=this.keywordsCallback[t](t),this.nodes[t]=e),e}addKeyword(t,e){return this.keywords.push(t),this.keywordsCallback[t]=e,this}parse(t){const e=this.keywords,s=new RegExp(`\\b${e.join("\\b|\\b")}\\b`,"g"),i=t.match(s),r=[];if(null!==i)for(const t of i){const e=this.getNode(t);void 0!==e&&-1===r.indexOf(e)&&r.push(e)}return r}include(t,e){const s=this.parse(e);for(const e of s)e.build(t)}}let cg=0;class dg{constructor(t=null){this.id=cg++,this.nodesData=new WeakMap,this.parent=t}getData(t){let e=this.nodesData.get(t);return void 0===e&&null!==this.parent&&(e=this.parent.getData(t)),e}setData(t,e){this.nodesData.set(t,e)}}class pg extends up{constructor(t,e=null,s=!1){super(t),this.name=e,this.varying=s,this.isPropertyNode=!0}getHash(t){return this.name||super.getHash(t)}isGlobal(){return!0}generate(t){let e;return!0===this.varying?(e=t.getVaryingFromNode(this,this.name),e.needsInterpolation=!0):e=t.getVarFromNode(this,this.name),t.getPropertyName(e)}}const mg=(t,e)=>Yp(new pg(t,e)),gg=(t,e)=>Yp(new pg(t,e,!0)),fg=Kp(pg,"vec4","DiffuseColor"),yg=Kp(pg,"vec3","EmissiveColor"),xg=Kp(pg,"float","Roughness"),bg=Kp(pg,"float","Metalness"),vg=Kp(pg,"float","Clearcoat"),Tg=Kp(pg,"float","ClearcoatRoughness"),_g=Kp(pg,"vec3","Sheen"),wg=Kp(pg,"float","SheenRoughness"),Sg=Kp(pg,"float","Iridescence"),Mg=Kp(pg,"float","IridescenceIOR"),Ag=Kp(pg,"float","IridescenceThickness"),Ng=Kp(pg,"float","AlphaT"),Rg=Kp(pg,"float","Anisotropy"),Cg=Kp(pg,"vec3","AnisotropyT"),Eg=Kp(pg,"vec3","AnisotropyB"),Bg=Kp(pg,"color","SpecularColor"),Ig=Kp(pg,"float","SpecularF90"),Pg=Kp(pg,"float","Shininess"),Fg=Kp(pg,"vec4","Output"),Ug=Kp(pg,"float","dashSize"),zg=Kp(pg,"float","gapSize"),Og=Kp(pg,"float","pointWidth"),Lg=Kp(pg,"float","IOR"),Vg=Kp(pg,"float","Transmission"),Dg=Kp(pg,"float","Thickness"),kg=Kp(pg,"float","AttenuationDistance"),Gg=Kp(pg,"color","AttenuationColor"),Wg=Kp(pg,"float","Dispersion");lp("PropertyNode",pg);class jg extends pg{constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}const Hg=(t,e)=>Yp(new jg(t,e));lp("ParameterNode",jg);class qg extends up{constructor(t="",e=[],s=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=s,this.includes=e}isGlobal(){return!0}setIncludes(t){return this.includes=t,this}getIncludes(){return this.includes}generate(t){const e=this.getIncludes(t);for(const s of e)s.build(t);const s=t.getCodeFromNode(this,this.getNodeType(t));return s.code=this.code,s.code}serialize(t){super.serialize(t),t.code=this.code,t.language=this.language}deserialize(t){super.deserialize(t),this.code=t.code,this.language=t.language}}const $g=Qp(qg),Xg=(t,e)=>$g(t,e,"js"),Yg=(t,e)=>$g(t,e,"wgsl"),Jg=(t,e)=>$g(t,e,"glsl");lp("CodeNode",qg);class Zg extends qg{constructor(t="",e=[],s=""){super(t,e,s),this.keywords={}}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let s=e.nodeFunction;return void 0===s&&(s=t.parser.parseFunction(this.code),e.nodeFunction=s),s}generate(t,e){super.generate(t);const s=this.getNodeFunction(t),i=s.name,r=s.type,n=t.getCodeFromNode(this,r);""!==i&&(n.name=i);const o=t.getPropertyName(n);let a=this.getNodeFunction(t).getCode(o);const h=this.keywords,u=Object.keys(h);if(u.length>0)for(const e of u){const s=new RegExp(`\\b${e}\\b`,"g"),i=h[e].build(t,"property");a=a.replace(s,i)}return n.code=a+"\n","property"===e?o:t.format(`${o}()`,r,e)}}const Qg=(t,e=[],s="")=>{for(let t=0;t<e.length;t++){const s=e[t];"function"==typeof s&&(e[t]=s.functionNode)}const i=Yp(new Zg(t,e,s)),r=(...t)=>i.call(...t);return r.functionNode=i,r},Kg=(t,e)=>Qg(t,e,"glsl"),tf=(t,e)=>Qg(t,e,"wgsl");lp("FunctionNode",Zg);class ef extends up{constructor(t,e=!1){super("string"),this.name=t,this.version=0,this.shared=e,this.isUniformGroup=!0}set needsUpdate(t){!0===t&&this.version++}serialize(t){super.serialize(t),t.name=this.name,t.version=this.version,t.shared=this.shared}deserialize(t){super.deserialize(t),this.name=t.name,this.version=t.version,this.shared=t.shared}}const sf=t=>new ef(t),rf=t=>new ef(t,!0),nf=rf("frame"),of=rf("render"),af=sf("object");lp("UniformGroupNode",ef);class hf extends bp{constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=af}label(t){return this.name=t,this}setGroup(t){return this.groupNode=t,this}getGroup(){return this.groupNode}getUniformHash(t){return this.getHash(t)}onUpdate(t,e){const s=this.getSelf();return t=t.bind(s),super.onUpdate((e=>{const i=t(e,s);void 0!==i&&(this.value=i)}),e)}generate(t,e){const s=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const n=r.getInputType(t),o=t.getUniformFromNode(r,n,t.shaderStage,this.name||t.context.label),a=t.getPropertyName(o);return void 0!==t.context.label&&delete t.context.label,t.format(a,s,e)}}const uf=(t,e)=>{const s=$p(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return Yp(new hf(i,s))};lp("UniformNode",hf);const lf=t=>jm("uv"+(t>0?t:""),"vec2");class cf extends up{constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const s=this.textureNode.build(t,"property"),i=this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${s}, ${i} )`,this.getNodeType(t),e)}}const df=Qp(cf);wp("textureSize",df),lp("TextureSizeNode",cf);class pf extends dp{constructor(t,e,s,...i){if(super(),i.length>0){let r=new pf(t,e,s);for(let e=0;e<i.length-1;e++)r=new pf(t,r,i[e]);e=r,s=i[i.length-1]}this.op=t,this.aNode=e,this.bNode=s}getNodeType(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=i.getNodeType(t),o=void 0!==r?r.getNodeType(t):null;if("void"===n||"void"===o)return"void";if("%"===s)return n;if("~"===s||"&"===s||"|"===s||"^"===s||">>"===s||"<<"===s)return t.getIntegerType(n);if("!"===s||"=="===s||"&&"===s||"||"===s||"^^"===s)return"bool";if("<"===s||">"===s||"<="===s||">="===s){const s=e?t.getTypeLength(e):Math.max(t.getTypeLength(n),t.getTypeLength(o));return s>1?`bvec${s}`:"bool"}return"float"===n&&t.isMatrix(o)?o:t.isMatrix(n)&&t.isVector(o)?t.getVectorFromMatrix(n):t.isVector(n)&&t.isMatrix(o)?t.getVectorFromMatrix(o):t.getTypeLength(o)>t.getTypeLength(n)?o:n}generate(t,e){const s=this.op,i=this.aNode,r=this.bNode,n=this.getNodeType(t,e);let o=null,a=null;"void"!==n?(o=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null,"<"===s||">"===s||"<="===s||">="===s||"=="===s?t.isVector(o)?a=o:o=a="float":">>"===s||"<<"===s?(o=n,a=t.changeComponentType(a,"uint")):t.isMatrix(o)&&t.isVector(a)?a=t.getVectorFromMatrix(o):o=t.isVector(o)&&t.isMatrix(a)?t.getVectorFromMatrix(a):a=n):o=a=n;const h=i.build(t,o),u=void 0!==r?r.build(t,a):null,l=t.getTypeLength(e),c=t.getFunctionOperator(s);return"void"!==e?"<"===s&&l>1?t.format(`${t.getMethod("lessThan")}( ${h}, ${u} )`,n,e):"<="===s&&l>1?t.format(`${t.getMethod("lessThanEqual")}( ${h}, ${u} )`,n,e):">"===s&&l>1?t.format(`${t.getMethod("greaterThan")}( ${h}, ${u} )`,n,e):">="===s&&l>1?t.format(`${t.getMethod("greaterThanEqual")}( ${h}, ${u} )`,n,e):"!"===s||"~"===s?t.format(`(${s}${h})`,o,e):c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`( ${h} ${s} ${u} )`,n,e):"void"!==o?c?t.format(`${c}( ${h}, ${u} )`,n,e):t.format(`${h} ${s} ${u}`,n,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const mf=Qp(pf,"+"),gf=Qp(pf,"-"),ff=Qp(pf,"*"),yf=Qp(pf,"/"),xf=Qp(pf,"%"),bf=Qp(pf,"=="),vf=Qp(pf,"!="),Tf=Qp(pf,"<"),_f=Qp(pf,">"),wf=Qp(pf,"<="),Sf=Qp(pf,">="),Mf=Qp(pf,"&&"),Af=Qp(pf,"||"),Nf=Qp(pf,"!"),Rf=Qp(pf,"^^"),Cf=Qp(pf,"&"),Ef=Qp(pf,"~"),Bf=Qp(pf,"|"),If=Qp(pf,"^"),Pf=Qp(pf,"<<"),Ff=Qp(pf,">>");wp("add",mf),wp("sub",gf),wp("mul",ff),wp("div",yf),wp("remainder",xf),wp("equal",bf),wp("notEqual",vf),wp("lessThan",Tf),wp("greaterThan",_f),wp("lessThanEqual",wf),wp("greaterThanEqual",Sf),wp("and",Mf),wp("or",Af),wp("not",Nf),wp("xor",Rf),wp("bitAnd",Cf),wp("bitNot",Ef),wp("bitOr",Bf),wp("bitXor",If),wp("shiftLeft",Pf),wp("shiftRight",Ff),lp("OperatorNode",pf);class Uf extends dp{constructor(t,e,s=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=s,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),s=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),n=t.isMatrix(s)?0:t.getTypeLength(s),o=t.isMatrix(i)?0:t.getTypeLength(i);return r>n&&r>o?e:n>o?s:o>r?i:e}getNodeType(t){const e=this.method;return e===Uf.LENGTH||e===Uf.DISTANCE||e===Uf.DOT?"float":e===Uf.CROSS?"vec3":e===Uf.ALL?"bool":e===Uf.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===Uf.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const s=this.method,i=this.getNodeType(t),r=this.getInputType(t),n=this.aNode,o=this.bNode,a=this.cNode,h=!0===t.renderer.isWebGLRenderer;if(s===Uf.TRANSFORM_DIRECTION){let s=n,i=o;t.isMatrix(s.getNodeType(t))?i=xm(mm(i),0):s=xm(mm(s),0);const r=ff(s,i).xyz;return Kf(r).build(t,e)}if(s===Uf.NEGATE)return t.format("( - "+n.build(t,r)+" )",i,e);if(s===Uf.ONE_MINUS)return gf(1,n).build(t,e);if(s===Uf.RECIPROCAL)return yf(1,n).build(t,e);if(s===Uf.DIFFERENCE)return ay(gf(n,o)).build(t,e);{const u=[];return s===Uf.CROSS||s===Uf.MOD?u.push(n.build(t,i),o.build(t,i)):s===Uf.STEP?u.push(n.build(t,1===t.getTypeLength(n.getNodeType(t))?"float":r),o.build(t,r)):h&&(s===Uf.MIN||s===Uf.MAX)||s===Uf.MOD?u.push(n.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):s===Uf.REFRACT?u.push(n.build(t,r),o.build(t,r),a.build(t,"float")):s===Uf.MIX?u.push(n.build(t,r),o.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):(u.push(n.build(t,r)),null!==o&&u.push(o.build(t,r)),null!==a&&u.push(a.build(t,r))),t.format(`${t.getMethod(s,i)}( ${u.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}Uf.ALL="all",Uf.ANY="any",Uf.EQUALS="equals",Uf.RADIANS="radians",Uf.DEGREES="degrees",Uf.EXP="exp",Uf.EXP2="exp2",Uf.LOG="log",Uf.LOG2="log2",Uf.SQRT="sqrt",Uf.INVERSE_SQRT="inversesqrt",Uf.FLOOR="floor",Uf.CEIL="ceil",Uf.NORMALIZE="normalize",Uf.FRACT="fract",Uf.SIN="sin",Uf.COS="cos",Uf.TAN="tan",Uf.ASIN="asin",Uf.ACOS="acos",Uf.ATAN="atan",Uf.ABS="abs",Uf.SIGN="sign",Uf.LENGTH="length",Uf.NEGATE="negate",Uf.ONE_MINUS="oneMinus",Uf.DFDX="dFdx",Uf.DFDY="dFdy",Uf.ROUND="round",Uf.RECIPROCAL="reciprocal",Uf.TRUNC="trunc",Uf.FWIDTH="fwidth",Uf.BITCAST="bitcast",Uf.TRANSPOSE="transpose",Uf.ATAN2="atan2",Uf.MIN="min",Uf.MAX="max",Uf.MOD="mod",Uf.STEP="step",Uf.REFLECT="reflect",Uf.DISTANCE="distance",Uf.DIFFERENCE="difference",Uf.DOT="dot",Uf.CROSS="cross",Uf.POW="pow",Uf.TRANSFORM_DIRECTION="transformDirection",Uf.MIX="mix",Uf.CLAMP="clamp",Uf.REFRACT="refract",Uf.SMOOTHSTEP="smoothstep",Uf.FACEFORWARD="faceforward";const zf=om(1e-6),Of=om(1e6),Lf=om(Math.PI),Vf=om(2*Math.PI),Df=Qp(Uf,Uf.ALL),kf=Qp(Uf,Uf.ANY),Gf=Qp(Uf,Uf.EQUALS),Wf=Qp(Uf,Uf.RADIANS),jf=Qp(Uf,Uf.DEGREES),Hf=Qp(Uf,Uf.EXP),qf=Qp(Uf,Uf.EXP2),$f=Qp(Uf,Uf.LOG),Xf=Qp(Uf,Uf.LOG2),Yf=Qp(Uf,Uf.SQRT),Jf=Qp(Uf,Uf.INVERSE_SQRT),Zf=Qp(Uf,Uf.FLOOR),Qf=Qp(Uf,Uf.CEIL),Kf=Qp(Uf,Uf.NORMALIZE),ty=Qp(Uf,Uf.FRACT),ey=Qp(Uf,Uf.SIN),sy=Qp(Uf,Uf.COS),iy=Qp(Uf,Uf.TAN),ry=Qp(Uf,Uf.ASIN),ny=Qp(Uf,Uf.ACOS),oy=Qp(Uf,Uf.ATAN),ay=Qp(Uf,Uf.ABS),hy=Qp(Uf,Uf.SIGN),uy=Qp(Uf,Uf.LENGTH),ly=Qp(Uf,Uf.NEGATE),cy=Qp(Uf,Uf.ONE_MINUS),dy=Qp(Uf,Uf.DFDX),py=Qp(Uf,Uf.DFDY),my=Qp(Uf,Uf.ROUND),gy=Qp(Uf,Uf.RECIPROCAL),fy=Qp(Uf,Uf.TRUNC),yy=Qp(Uf,Uf.FWIDTH),xy=Qp(Uf,Uf.BITCAST),by=Qp(Uf,Uf.TRANSPOSE),vy=Qp(Uf,Uf.ATAN2),Ty=Qp(Uf,Uf.MIN),_y=Qp(Uf,Uf.MAX),wy=Qp(Uf,Uf.MOD),Sy=Qp(Uf,Uf.STEP),My=Qp(Uf,Uf.REFLECT),Ay=Qp(Uf,Uf.DISTANCE),Ny=Qp(Uf,Uf.DIFFERENCE),Ry=Qp(Uf,Uf.DOT),Cy=Qp(Uf,Uf.CROSS),Ey=Qp(Uf,Uf.POW),By=Qp(Uf,Uf.POW,2),Iy=Qp(Uf,Uf.POW,3),Py=Qp(Uf,Uf.POW,4),Fy=Qp(Uf,Uf.TRANSFORM_DIRECTION),Uy=t=>ff(hy(t),Ey(ay(t),1/3)),zy=t=>Ry(t,t),Oy=Qp(Uf,Uf.MIX),Ly=(t,e=0,s=1)=>Yp(new Uf(Uf.CLAMP,Yp(t),Yp(e),Yp(s))),Vy=t=>Ly(t),Dy=Qp(Uf,Uf.REFRACT),ky=Qp(Uf,Uf.SMOOTHSTEP),Gy=Qp(Uf,Uf.FACEFORWARD),Wy=tm((([t])=>{const e=Ry(t.xy,lm(12.9898,78.233)),s=wy(e,Lf);return ty(ey(s).mul(43758.5453))}));wp("all",Df),wp("any",kf),wp("equals",Gf),wp("radians",Wf),wp("degrees",jf),wp("exp",Hf),wp("exp2",qf),wp("log",$f),wp("log2",Xf),wp("sqrt",Yf),wp("inverseSqrt",Jf),wp("floor",Zf),wp("ceil",Qf),wp("normalize",Kf),wp("fract",ty),wp("sin",ey),wp("cos",sy),wp("tan",iy),wp("asin",ry),wp("acos",ny),wp("atan",oy),wp("abs",ay),wp("sign",hy),wp("length",uy),wp("lengthSq",zy),wp("negate",ly),wp("oneMinus",cy),wp("dFdx",dy),wp("dFdy",py),wp("round",my),wp("reciprocal",gy),wp("trunc",fy),wp("fwidth",yy),wp("atan2",vy),wp("min",Ty),wp("max",_y),wp("mod",wy),wp("step",Sy),wp("reflect",My),wp("distance",Ay),wp("dot",Ry),wp("cross",Cy),wp("pow",Ey),wp("pow2",By),wp("pow3",Iy),wp("pow4",Py),wp("transformDirection",Fy),wp("mix",((t,e,s)=>Oy(e,s,t))),wp("clamp",Ly),wp("refract",Dy),wp("smoothstep",((t,e,s)=>ky(e,s,t))),wp("faceForward",Gy),wp("difference",Ny),wp("saturate",Vy),wp("cbrt",Uy),wp("transpose",by),wp("rand",Wy),lp("MathNode",Uf);const jy=tm((t=>{const{value:e}=t,{rgb:s}=e,i=s.mul(.9478672986).add(.0521327014).pow(2.4),r=s.mul(.0773993808),n=s.lessThanEqual(.04045),o=Oy(i,r,n);return xm(o,e.a)})),Hy=tm((t=>{const{value:e}=t,{rgb:s}=e,i=s.pow(.41666).mul(1.055).sub(.055),r=s.mul(12.92),n=s.lessThanEqual(.0031308),o=Oy(i,r,n);return xm(o,e.a)})),qy=t=>{let e=null;return t===Ze?e="Linear":t===Je&&(e="sRGB"),e},$y=(t,e)=>qy(t)+"To"+qy(e);class Xy extends dp{constructor(t,e){super("vec4"),this.method=t,this.node=e}setup(){const{method:t,node:e}=this;return t===Xy.LINEAR_TO_LINEAR?e:Yy[t]({value:e})}}Xy.LINEAR_TO_LINEAR="LinearToLinear",Xy.LINEAR_TO_sRGB="LinearTosRGB",Xy.sRGB_TO_LINEAR="sRGBToLinear";const Yy={[Xy.LINEAR_TO_sRGB]:Hy,[Xy.sRGB_TO_LINEAR]:jy},Jy=(t,e)=>Yp(new Xy($y(Ze,e),Yp(t))),Zy=(t,e)=>Yp(new Xy($y(e,Ze),Yp(t))),Qy=Qp(Xy,Xy.LINEAR_TO_sRGB),Ky=Qp(Xy,Xy.sRGB_TO_LINEAR);wp("linearTosRGB",Qy),wp("sRGBToLinear",Ky),wp("linearToColorSpace",Jy),wp("colorSpaceToLinear",Zy),lp("ColorSpaceNode",Xy);class tx extends up{constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const s=this.getNodeType(t),i=this.snippet;if("void"!==s)return t.format(`( ${i} )`,s,e);t.addLineFlowCode(i)}}const ex=Qp(tx);lp("ExpressionNode",tx);class sx extends hf{constructor(t){super(0),this._textureNode=t,this.updateType=Xd.FRAME}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,s=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(s&&void 0!==s.width){const{width:t,height:e}=s;this.value=Math.log2(Math.max(t,e))}}}const ix=Qp(sx);lp("MaxMipLevelNode",sx);class rx extends hf{constructor(t,e=null,s=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=s,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=Xd.NONE,this.referenceNode=null,this._value=t,this._matrixUniform=null,this.setUpdateMatrix(null===e)}set value(t){this.referenceNode?this.referenceNode.value=t:this._value=t}get value(){return this.referenceNode?this.referenceNode.value:this._value}getUniformHash(){return this.value.uuid}getNodeType(){return!0===this.value.isDepthTexture?"float":this.value.type===Bt?"uvec4":this.value.type===Et?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return lf(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=uf(this.value.matrix)),this._matrixUniform.mul(mm(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?Xd.FRAME:Xd.NONE,this}setupUV(t,e){const s=this.value;return!t.isFlipY()||!0!==s.isRenderTargetTexture&&!0!==s.isFramebufferTexture&&!0!==s.isDepthTexture||(e=e.setY(e.y.oneMinus())),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let s=this.uvNode;null!==s&&!0!==t.context.forceUVContext||!t.context.getUV||(s=t.context.getUV(this)),s||(s=this.getDefaultUV()),!0===this.updateMatrix&&(s=this.getTransformedUV(s)),s=this.setupUV(t,s);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=s,e.levelNode=i,e.biasNode=this.biasNode,e.compareNode=this.compareNode,e.gradNode=this.gradNode,e.depthNode=this.depthNode}generateUV(t,e){return e.build(t,!0===this.sampler?"vec2":"ivec2")}generateSnippet(t,e,s,i,r,n,o,a){const h=this.value;let u;return u=i?t.generateTextureLevel(h,e,s,i,n):r?t.generateTextureBias(h,e,s,r,n):a?t.generateTextureGrad(h,e,s,a,n):o?t.generateTextureCompare(h,e,s,o,n):!1===this.sampler?t.generateTextureLoad(h,e,s,n):t.generateTexture(h,e,s,n),u}generate(t,e){const s=t.getNodeProperties(this),i=this.value;if(!i||!0!==i.isTexture)throw new Error("TextureNode: Need a three.js texture.");const r=super.generate(t,"property");if("sampler"===e)return r+"_sampler";if(t.isReference(e))return r;{const n=t.getDataFromNode(this);let o=n.propertyName;if(void 0===o){const{uvNode:e,levelNode:i,biasNode:a,compareNode:h,depthNode:u,gradNode:l}=s,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=a?a.build(t,"float"):null,m=u?u.build(t,"int"):null,g=h?h.build(t,"float"):null,f=l?[l[0].build(t,"vec2"),l[1].build(t,"vec2")]:null,y=t.getVarFromNode(this);o=t.getPropertyName(y);const x=this.generateSnippet(t,r,c,d,p,m,g,f);t.addLineFlowCode(`${o} = ${x}`),n.snippet=x,n.propertyName=o}let a=o;const h=this.getNodeType(t);return t.needsColorSpaceToLinear(i)&&(a=Zy(ex(a,h),i.colorSpace).setup(t).build(t,h)),t.format(a,h,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=Yp(t),e.referenceNode=this,Yp(e)}blur(t){const e=this.clone();return e.biasNode=Yp(t).mul(ix(e)),e.referenceNode=this,Yp(e)}level(t){const e=this.clone();return e.levelNode=Yp(t),e.referenceNode=this,Yp(e)}size(t){return df(this,t)}bias(t){const e=this.clone();return e.biasNode=Yp(t),e.referenceNode=this,Yp(e)}compare(t){const e=this.clone();return e.compareNode=Yp(t),e.referenceNode=this,Yp(e)}grad(t,e){const s=this.clone();return s.gradNode=[Yp(t),Yp(e)],s.referenceNode=this,Yp(s)}depth(t){const e=this.clone();return e.depthNode=Yp(t),e.referenceNode=this,Yp(e)}serialize(t){super.serialize(t),t.value=this.value.toJSON(t.meta).uuid,t.sampler=this.sampler,t.updateMatrix=this.updateMatrix,t.updateType=this.updateType}deserialize(t){super.deserialize(t),this.value=t.meta.textures[t.value],this.sampler=t.sampler,this.updateMatrix=t.updateMatrix,this.updateType=t.updateType}update(){const t=this.value,e=this._matrixUniform;null!==e&&(e.value=t.matrix),!0===t.matrixAutoUpdate&&t.updateMatrix()}clone(){const t=new this.constructor(this.value,this.uvNode,this.levelNode,this.biasNode);return t.sampler=this.sampler,t}}const nx=Qp(rx),ox=(...t)=>nx(...t).setSampler(!1),ax=t=>(!0===t.isNode?t:nx(t)).convert("sampler");wp("texture",nx),lp("TextureNode",rx);class hx extends hf{constructor(t,e,s=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=s}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const ux=(t,e,s)=>Yp(new hx(t,e,s));lp("BufferNode",hx);class lx extends pp{constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}getNodeType(t){return this.node.getElementType(t)}generate(t){const e=super.generate(t),s=this.getNodeType();return t.format(e,"vec4",s)}}class cx extends hx{constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=Xd.RENDER,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,s=this.getElementLength(),i=this.getElementType();if(1===s)for(let s=0;s<t.length;s++){e[4*s]=t[s]}else if("color"===i)for(let s=0;s<t.length;s++){const i=4*s,r=t[s];e[i]=r.r,e[i+1]=r.g,e[i+2]=r.b||0}else for(let s=0;s<t.length;s++){const i=4*s,r=t[s];e[i]=r.x,e[i+1]=r.y,e[i+2]=r.z||0,e[i+3]=r.w||0}}setup(t){const e=this.array.length;this._elementType=null===this.elementType?sp(this.array[0]):this.elementType,this._elementLength=t.getTypeLength(this._elementType);let s=Float32Array;return"i"===this._elementType.charAt(0)?s=Int32Array:"u"===this._elementType.charAt(0)&&(s=Uint32Array),this.value=new s(4*e),this.bufferCount=e,this.bufferType=t.changeComponentType("vec4",t.getComponentType(this._elementType)),super.setup(t)}element(t){return Yp(new lx(this,Yp(t)))}}const dx=(t,e)=>Yp(new cx(t,e));lp("UniformsNode",cx);class px extends pp{constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),s=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,s,i)}}class mx extends up{constructor(t,e,s=null,i=null){super(),this.property=t,this.uniformType=e,this.object=s,this.count=i,this.properties=t.split("."),this.reference=s,this.node=null,this.updateType=Xd.OBJECT}element(t){return Yp(new px(this,Yp(t)))}setNodeType(t){let e=null;e=null!==this.count?ux(null,t,this.count):Array.isArray(this.getValueFromReference())?dx(null,t):"texture"===t?nx(null):uf(null,t),this.node=e}getNodeType(t){return null===this.node&&this.updateValue(),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let s=t[e[0]];for(let t=1;t<e.length;t++)s=s[e[t]];return s}updateReference(t){return this.reference=null!==this.object?this.object:t.object,this.reference}setup(){return this.updateValue(),this.node}update(){this.updateValue()}updateValue(){null===this.node&&this.setNodeType(this.uniformType);const t=this.getValueFromReference();Array.isArray(t)?this.node.array=t:this.node.value=t}}const gx=(t,e,s)=>Yp(new mx(t,e,s)),fx=(t,e,s,i)=>Yp(new mx(t,e,i,s));lp("ReferenceNode",mx);class yx extends mx{constructor(t,e,s=null){super(t,e,s),this.material=s}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const xx=(t,e,s)=>Yp(new yx(t,e,s));lp("MaterialReferenceNode",yx);const bx=rf("camera").onRenderUpdate((()=>{bx.needsUpdate=!0})),vx=uf("float").label("cameraNear").setGroup(bx).onRenderUpdate((({camera:t})=>t.near)),Tx=uf("float").label("cameraFar").setGroup(bx).onRenderUpdate((({camera:t})=>t.far)),_x=uf("float").label("cameraLogDepth").setGroup(bx).onRenderUpdate((({camera:t})=>2/(Math.log(t.far+1)/Math.LN2))),wx=uf("mat4").label("cameraProjectionMatrix").setGroup(bx).onRenderUpdate((({camera:t})=>t.projectionMatrix)),Sx=uf("mat4").label("cameraProjectionMatrixInverse").setGroup(bx).onRenderUpdate((({camera:t})=>t.projectionMatrixInverse)),Mx=uf("mat4").label("cameraViewMatrix").setGroup(bx).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),Ax=uf("mat4").label("cameraWorldMatrix").setGroup(bx).onRenderUpdate((({camera:t})=>t.matrixWorld)),Nx=uf("mat3").label("cameraNormalMatrix").setGroup(bx).onRenderUpdate((({camera:t})=>t.normalMatrix)),Rx=uf(new Ei).label("cameraPosition").setGroup(bx).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class Cx extends up{constructor(t=Cx.VIEW_MATRIX,e=null){super(),this.scope=t,this.object3d=e,this.updateType=Xd.OBJECT,this._uniformNode=new hf(null)}getNodeType(){const t=this.scope;return t===Cx.WORLD_MATRIX||t===Cx.VIEW_MATRIX?"mat4":t===Cx.NORMAL_MATRIX?"mat3":t===Cx.POSITION||t===Cx.VIEW_POSITION||t===Cx.DIRECTION||t===Cx.SCALE?"vec3":void 0}update(t){const e=this.object3d,s=this._uniformNode,i=this.scope;if(i===Cx.VIEW_MATRIX)s.value=e.modelViewMatrix;else if(i===Cx.NORMAL_MATRIX)s.value=e.normalMatrix;else if(i===Cx.WORLD_MATRIX)s.value=e.matrixWorld;else if(i===Cx.POSITION)s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld);else if(i===Cx.SCALE)s.value=s.value||new Ei,s.value.setFromMatrixScale(e.matrixWorld);else if(i===Cx.DIRECTION)s.value=s.value||new Ei,e.getWorldDirection(s.value);else if(i===Cx.VIEW_POSITION){const i=t.camera;s.value=s.value||new Ei,s.value.setFromMatrixPosition(e.matrixWorld),s.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===Cx.WORLD_MATRIX||e===Cx.VIEW_MATRIX?this._uniformNode.nodeType="mat4":e===Cx.NORMAL_MATRIX?this._uniformNode.nodeType="mat3":e!==Cx.POSITION&&e!==Cx.VIEW_POSITION&&e!==Cx.DIRECTION&&e!==Cx.SCALE||(this._uniformNode.nodeType="vec3"),this._uniformNode.build(t)}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}Cx.VIEW_MATRIX="viewMatrix",Cx.NORMAL_MATRIX="normalMatrix",Cx.WORLD_MATRIX="worldMatrix",Cx.POSITION="position",Cx.SCALE="scale",Cx.VIEW_POSITION="viewPosition",Cx.DIRECTION="direction";const Ex=Qp(Cx,Cx.DIRECTION),Bx=Qp(Cx,Cx.VIEW_MATRIX),Ix=Qp(Cx,Cx.NORMAL_MATRIX),Px=Qp(Cx,Cx.WORLD_MATRIX),Fx=Qp(Cx,Cx.POSITION),Ux=Qp(Cx,Cx.SCALE),zx=Qp(Cx,Cx.VIEW_POSITION);lp("Object3DNode",Cx);class Ox extends Cx{constructor(t=Ox.VIEW_MATRIX){super(t)}update(t){this.object3d=t.object,super.update(t)}}const Lx=Kp(Ox,Ox.DIRECTION),Vx=Kp(Ox,Ox.VIEW_MATRIX).label("modelViewMatrix").temp("ModelViewMatrix"),Dx=Kp(Ox,Ox.NORMAL_MATRIX),kx=Kp(Ox,Ox.WORLD_MATRIX),Gx=Kp(Ox,Ox.POSITION),Wx=Kp(Ox,Ox.SCALE),jx=Kp(Ox,Ox.VIEW_POSITION),Hx=uf(new or).onObjectUpdate((({object:t},e)=>e.value.copy(t.matrixWorld).invert()));lp("ModelNode",Ox);const qx=jm("normal","vec3",mm(0,1,0)),$x=qx.toVar("normalLocal"),Xx=Gm(Dx.mul($x),"v_normalView").normalize().toVar("normalView"),Yx=Gm(Xx.transformDirection(Mx),"v_normalWorld").normalize().toVar("normalWorld"),Jx=mg("vec3","transformedNormalView"),Zx=Jx.transformDirection(Mx).normalize().toVar("transformedNormalWorld"),Qx=mg("vec3","transformedClearcoatNormalView"),Kx=new Map;class tb extends up{constructor(t){super(),this.scope=t}getCache(t,e){let s=Kx.get(t);return void 0===s&&(s=xx(t,e),Kx.set(t,s)),s}getFloat(t){return this.getCache(t,"float")}getColor(t){return this.getCache(t,"color")}getTexture(t){return this.getCache("map"===t?"map":t+"Map","texture")}setup(t){const e=t.context.material,s=this.scope;let i=null;if(s===tb.COLOR){const t=this.getColor(s);i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(s===tb.OPACITY){const t=this.getFloat(s);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(s===tb.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:om(1);else if(s===tb.SPECULAR_INTENSITY){const t=this.getFloat(s);i=e.specularMap?t.mul(this.getTexture(s).a):t}else if(s===tb.SPECULAR_COLOR){const t=this.getColor(s);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(s).rgb):t}else if(s===tb.ROUGHNESS){const t=this.getFloat(s);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(s).g):t}else if(s===tb.METALNESS){const t=this.getFloat(s);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(s).b):t}else if(s===tb.EMISSIVE){const t=this.getFloat("emissiveIntensity"),r=this.getColor(s).mul(t);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?r.mul(this.getTexture(s)):r}else if(s===tb.NORMAL)i=e.normalMap?this.getTexture("normal").normalMap(this.getCache("normalScale","vec2")):e.bumpMap?this.getTexture("bump").r.bumpMap(this.getFloat("bumpScale")):Xx;else if(s===tb.CLEARCOAT){const t=this.getFloat(s);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===tb.CLEARCOAT_ROUGHNESS){const t=this.getFloat(s);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(s).r):t}else if(s===tb.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?this.getTexture(s).normalMap(this.getCache(s+"Scale","vec2")):Xx;else if(s===tb.SHEEN){const t=this.getColor("sheenColor").mul(this.getFloat("sheen"));i=e.sheenColorMap&&!0===e.sheenColorMap.isTexture?t.mul(this.getTexture("sheenColor").rgb):t}else if(s===tb.SHEEN_ROUGHNESS){const t=this.getFloat(s);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(s).a):t,i=i.clamp(.07,1)}else if(s===tb.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(s);i=_m(Vb.x,Vb.y,Vb.y.negate(),Vb.x).mul(t.rg.mul(2).sub(lm(1)).normalize().mul(t.b))}else i=Vb;else if(s===tb.IRIDESCENCE_THICKNESS){const t=gx("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=gx("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(s).g).add(r)}else i=t}else if(s===tb.TRANSMISSION){const t=this.getFloat(s);i=e.transmissionMap?t.mul(this.getTexture(s).r):t}else if(s===tb.THICKNESS){const t=this.getFloat(s);i=e.thicknessMap?t.mul(this.getTexture(s).g):t}else if(s===tb.IOR)i=this.getFloat(s);else if(s===tb.REFRACTION_RATIO)i=this.getFloat(s);else if(s===tb.LIGHT_MAP)i=this.getTexture(s).rgb.mul(this.getFloat("lightMapIntensity"));else if(s===tb.AO_MAP)i=this.getTexture(s).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(s,e)}return i}}tb.ALPHA_TEST="alphaTest",tb.COLOR="color",tb.OPACITY="opacity",tb.SHININESS="shininess",tb.SPECULAR="specular",tb.SPECULAR_STRENGTH="specularStrength",tb.SPECULAR_INTENSITY="specularIntensity",tb.SPECULAR_COLOR="specularColor",tb.REFLECTIVITY="reflectivity",tb.ROUGHNESS="roughness",tb.METALNESS="metalness",tb.NORMAL="normal",tb.CLEARCOAT="clearcoat",tb.CLEARCOAT_ROUGHNESS="clearcoatRoughness",tb.CLEARCOAT_NORMAL="clearcoatNormal",tb.EMISSIVE="emissive",tb.ROTATION="rotation",tb.SHEEN="sheen",tb.SHEEN_ROUGHNESS="sheenRoughness",tb.ANISOTROPY="anisotropy",tb.IRIDESCENCE="iridescence",tb.IRIDESCENCE_IOR="iridescenceIOR",tb.IRIDESCENCE_THICKNESS="iridescenceThickness",tb.IOR="ior",tb.TRANSMISSION="transmission",tb.THICKNESS="thickness",tb.ATTENUATION_DISTANCE="attenuationDistance",tb.ATTENUATION_COLOR="attenuationColor",tb.LINE_SCALE="scale",tb.LINE_DASH_SIZE="dashSize",tb.LINE_GAP_SIZE="gapSize",tb.LINE_WIDTH="linewidth",tb.LINE_DASH_OFFSET="dashOffset",tb.POINT_WIDTH="pointWidth",tb.DISPERSION="dispersion",tb.LIGHT_MAP="light",tb.AO_MAP="ao",tb.REFRACTION_RATIO="refractionRatio";const eb=Kp(tb,tb.ALPHA_TEST),sb=Kp(tb,tb.COLOR),ib=Kp(tb,tb.SHININESS),rb=Kp(tb,tb.EMISSIVE),nb=Kp(tb,tb.OPACITY),ob=Kp(tb,tb.SPECULAR),ab=Kp(tb,tb.SPECULAR_INTENSITY),hb=Kp(tb,tb.SPECULAR_COLOR),ub=Kp(tb,tb.SPECULAR_STRENGTH),lb=Kp(tb,tb.REFLECTIVITY),cb=Kp(tb,tb.ROUGHNESS),db=Kp(tb,tb.METALNESS),pb=Kp(tb,tb.NORMAL),mb=Kp(tb,tb.CLEARCOAT),gb=Kp(tb,tb.CLEARCOAT_ROUGHNESS),fb=Kp(tb,tb.CLEARCOAT_NORMAL),yb=Kp(tb,tb.ROTATION),xb=Kp(tb,tb.SHEEN),bb=Kp(tb,tb.SHEEN_ROUGHNESS),vb=Kp(tb,tb.ANISOTROPY),Tb=Kp(tb,tb.IRIDESCENCE),_b=Kp(tb,tb.IRIDESCENCE_IOR),wb=Kp(tb,tb.IRIDESCENCE_THICKNESS),Sb=Kp(tb,tb.TRANSMISSION),Mb=Kp(tb,tb.THICKNESS),Ab=Kp(tb,tb.IOR),Nb=Kp(tb,tb.ATTENUATION_DISTANCE),Rb=Kp(tb,tb.ATTENUATION_COLOR),Cb=Kp(tb,tb.LINE_SCALE),Eb=Kp(tb,tb.LINE_DASH_SIZE),Bb=Kp(tb,tb.LINE_GAP_SIZE),Ib=Kp(tb,tb.LINE_WIDTH),Pb=Kp(tb,tb.LINE_DASH_OFFSET),Fb=Kp(tb,tb.POINT_WIDTH),Ub=Kp(tb,tb.DISPERSION),zb=Kp(tb,tb.LIGHT_MAP),Ob=Kp(tb,tb.AO_MAP),Lb=Kp(tb,tb.REFRACTION_RATIO),Vb=uf(new Ks).onReference((function(t){return t.material})).onRenderUpdate((function({material:t}){this.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation))}));lp("MaterialNode",tb);const Db=jm("position","vec3"),kb=Db.toVar("positionLocal"),Gb=Gm(kx.mul(kb).xyz,"v_positionWorld"),Wb=Gm(kb.transformDirection(kx),"v_positionWorldDirection").normalize().toVar("positionWorldDirection"),jb=Gm(Vx.mul(kb).xyz,"v_positionView"),Hb=Gm(jb.negate(),"v_positionViewDirection").normalize().toVar("positionViewDirection");class qb extends dp{constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return Gm(t.context.mvp);const e=this.positionNode||kb;return wx.mul(Vx).mul(e)}}const $b=Qp(qb);lp("ModelViewProjectionNode",qb);class Xb extends bp{constructor(t,e=null,s=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=s,this.bufferOffset=i,this.usage=Rs,this.instanced=!1,this.attribute=null,this.global=!0,t&&!0===t.isBufferAttribute&&(this.attribute=t,this.usage=t.usage,this.instanced=t.isInstancedBufferAttribute)}getHash(t){if(0===this.bufferStride&&0===this.bufferOffset){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getNodeType(t){return null===this.bufferType&&(this.bufferType=t.getTypeFromAttribute(this.attribute)),this.bufferType}setup(t){if(null!==this.attribute)return;const e=this.getNodeType(t),s=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,n=this.bufferOffset,o=!0===s.isInterleavedBuffer?s:new oo(s,r),a=new ho(o,i,n);o.setUsage(this.usage),this.attribute=a,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),s=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(s);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=Gm(this).build(t,e)}return r}getInputType(){return"bufferAttribute"}setUsage(t){return this.usage=t,this.attribute&&!0===this.attribute.isBufferAttribute&&(this.attribute.usage=t),this}setInstanced(t){return this.instanced=t,this}}const Yb=(t,e,s,i)=>Yp(new Xb(t,e,s,i)),Jb=(t,e,s,i)=>Yb(t,e,s,i).setUsage(Cs),Zb=(t,e,s,i)=>Yb(t,e,s,i).setInstanced(!0),Qb=(t,e,s,i)=>Jb(t,e,s,i).setInstanced(!0);wp("toAttribute",(t=>Yb(t.value))),lp("BufferAttributeNode",Xb);class Kb extends up{constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=Xd.FRAME,this.buffer=null,this.bufferColor=null}setup(){let t=this.instanceMatrixNode,e=this.instanceColorNode;const s=this.instanceMesh;if(null===t){const e=s.instanceMatrix;if(s.count<=1e3)t=ux(e.array,"mat4",s.count).element(tg);else{const s=new Nc(e.array,16,1);this.buffer=s;const i=e.usage===Cs?Qb:Zb,r=[i(s,"vec4",16,0),i(s,"vec4",16,4),i(s,"vec4",16,8),i(s,"vec4",16,12)];t=Em(...r)}this.instanceMatrixNode=t}const i=s.instanceColor;if(i&&null===e){const t=new jo(i.array,3),s=i.usage===Cs?Qb:Zb;this.bufferColor=t,e=mm(s(t,"vec3",3,0)),this.instanceColorNode=e}const r=t.mul(kb).xyz,n=Am(t),o=$x.div(mm(n[0].dot(n[0]),n[1].dot(n[1]),n[2].dot(n[2]))),a=n.mul(o).xyz;kb.assign(r),$x.assign(a),null!==this.instanceColorNode&&gg("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Cs&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Cs&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const tv=Qp(Kb);lp("InstanceNode",Kb);const ev=tm(((t,e)=>(!1===e.geometry.hasAttribute("tangent")&&e.geometry.computeTangents(),jm("tangent","vec4"))))(),sv=ev.xyz.toVar("tangentLocal"),iv=Gm(Vx.mul(xm(sv,0)).xyz,"v_tangentView").normalize().toVar("tangentView"),rv=Gm(iv.transformDirection(Mx),"v_tangentWorld").normalize().toVar("tangentWorld"),nv=iv.toVar("transformedTangentView"),ov=nv.transformDirection(Mx).normalize().toVar("transformedTangentWorld");class av extends up{constructor(t){super("void"),this.batchMesh=t,this.instanceColorNode=null,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=tg:this.batchingIdNode=eg);const e=tm((([t])=>{const e=df(ox(this.batchMesh._indirectTexture),0),s=am(t).remainder(am(e)),i=am(t).div(am(e));return ox(this.batchMesh._indirectTexture,cm(s,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),s=this.batchMesh._matricesTexture,i=df(ox(s),0),r=om(e(am(this.batchingIdNode))).mul(4).toVar(),n=am(r.mod(i)),o=am(r).div(am(i)),a=Em(ox(s,cm(n,o)),ox(s,cm(n.add(1),o)),ox(s,cm(n.add(2),o)),ox(s,cm(n.add(3),o))),h=Am(a);kb.assign(a.mul(kb));const u=$x.div(mm(h[0].dot(h[0]),h[1].dot(h[1]),h[2].dot(h[2]))),l=h.mul(u).xyz;$x.assign(l),t.hasGeometryAttribute("tangent")&&sv.mulAssign(h)}}const hv=Qp(av);lp("batch",av);class uv extends up{constructor(t,e=!1){let s,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=Xd.OBJECT,this.skinIndexNode=jm("skinIndex","uvec4"),this.skinWeightNode=jm("skinWeight","vec4"),e?(s=gx("bindMatrix","mat4"),i=gx("bindMatrixInverse","mat4"),r=fx("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(s=uf(t.bindMatrix,"mat4"),i=uf(t.bindMatrixInverse,"mat4"),r=ux(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=s,this.bindMatrixInverseNode=i,this.boneMatricesNode=r}setup(t){const{skinIndexNode:e,skinWeightNode:s,bindMatrixNode:i,bindMatrixInverseNode:r,boneMatricesNode:n}=this,o=n.element(e.x),a=n.element(e.y),h=n.element(e.z),u=n.element(e.w),l=i.mul(kb),c=mf(o.mul(s.x).mul(l),a.mul(s.y).mul(l),h.mul(s.z).mul(l),u.mul(s.w).mul(l)),d=r.mul(c).xyz;let p=mf(s.x.mul(o),s.y.mul(a),s.z.mul(h),s.w.mul(u));p=r.mul(p).mul(i);const m=p.transformDirection($x).xyz;kb.assign(d),$x.assign(m),t.hasGeometryAttribute("tangent")&&sv.assign(m)}generate(t,e){if("void"!==e)return kb.build(t,e)}update(t){(this.useReference?t.object:this.skinnedMesh).skeleton.update()}}const lv=t=>Yp(new uv(t)),cv=t=>Yp(new uv(t,!0));lp("SkinningNode",uv);class dv extends up{constructor(t=[]){super(),this.params=t}getVarName(t){return String.fromCharCode("i".charCodeAt()+t)}getProperties(t){const e=t.getNodeProperties(this);if(void 0!==e.stackNode)return e;const s={};for(let t=0,e=this.params.length-1;t<e;t++){const e=this.params[t],i=!0!==e.isNode&&e.name||this.getVarName(t),r=!0!==e.isNode&&e.type||"int";s[i]=ex(i,r)}const i=t.addStack();return e.returnsNode=this.params[this.params.length-1](s,i,t),e.stackNode=i,t.removeStack(),e}getNodeType(t){const{returnsNode:e}=this.getProperties(t);return e?e.getNodeType(t):"void"}setup(t){this.getProperties(t)}generate(t){const e=this.getProperties(t),s=this.params,i=e.stackNode;for(let e=0,i=s.length-1;e<i;e++){const i=s[e];let r=null,n=null,o=null,a=null,h=null,u=null;i.isNode?(a="int",o=this.getVarName(e),r="0",n=i.build(t,a),h="<"):(a=i.type||"int",o=i.name||this.getVarName(e),r=i.start,n=i.end,h=i.condition,u=i.update,"number"==typeof r?r=r.toString():r&&r.isNode&&(r=r.build(t,a)),"number"==typeof n?n=n.toString():n&&n.isNode&&(n=n.build(t,a)),void 0!==r&&void 0===n?(r+=" - 1",n="0",h=">="):void 0!==n&&void 0===r&&(r="0",h="<"),void 0===h&&(h=Number(r)>Number(n)?">=":"<"));const l={start:r,end:n,condition:h},c=l.start,d=l.end;let p="",m="",g="";u||(u="int"===a||"uint"===a?h.includes("<")?"++":"--":h.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(a,o)+" = "+c,m+=o+" "+h+" "+d,g+=o+" "+u;const f=`for ( ${p}; ${m}; ${g} )`;t.addFlowCode((0===e?"\n":"")+t.tab+f+" {\n\n").addFlowTab()}const r=i.build(t,"void"),n=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,s=this.params.length-1;e<s;e++)t.addFlowCode((0===e?"":t.tab)+"}\n\n").removeFlowTab();return t.addFlowTab(),n}}const pv=(...t)=>Yp(new dv(Zp(t,"int"))).append(),mv=()=>ex("continue").append(),gv=()=>ex("break").append();wp("loop",((t,...e)=>qm(t,pv(...e)))),lp("LoopNode",dv);const fv=new WeakMap,yv=new _i,xv=tm((({bufferMap:t,influence:e,stride:s,width:i,depth:r,offset:n})=>{const o=am(Km).mul(s).add(n),a=o.div(i),h=o.sub(a.mul(i));return ox(t,cm(h,a)).depth(r).mul(e)}));class bv extends up{constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=uf(1),this.updateType=Xd.OBJECT}setup(t){const{geometry:e}=t,s=void 0!==e.morphAttributes.position,i=void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,n=void 0!==r?r.length:0,{texture:o,stride:a,size:h}=function(t){const e=void 0!==t.morphAttributes.position,s=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,n=void 0!==r?r.length:0;let o=fv.get(t);if(void 0===o||o.count!==n){void 0!==o&&o.texture.dispose();const a=t.morphAttributes.position||[],h=t.morphAttributes.normal||[],u=t.morphAttributes.color||[];let l=0;!0===e&&(l=1),!0===s&&(l=2),!0===i&&(l=3);let c=t.attributes.position.count*l,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const m=new Float32Array(c*d*4*n),g=new Mi(m,c,d,n);g.type=It,g.needsUpdate=!0;const f=4*l;for(let x=0;x<n;x++){const b=a[x],v=h[x],T=u[x],_=c*d*4*x;for(let w=0;w<b.count;w++){const S=w*f;!0===e&&(yv.fromBufferAttribute(b,w),m[_+S+0]=yv.x,m[_+S+1]=yv.y,m[_+S+2]=yv.z,m[_+S+3]=0),!0===s&&(yv.fromBufferAttribute(v,w),m[_+S+4]=yv.x,m[_+S+5]=yv.y,m[_+S+6]=yv.z,m[_+S+7]=0),!0===i&&(yv.fromBufferAttribute(T,w),m[_+S+8]=yv.x,m[_+S+9]=yv.y,m[_+S+10]=yv.z,m[_+S+11]=4===T.itemSize?yv.w:1)}}function y(){g.dispose(),fv.delete(t),t.removeEventListener("dispose",y)}o={count:n,texture:g,stride:l,size:new Ks(c,d)},fv.set(t,o),t.addEventListener("dispose",y)}return o}(e);!0===s&&kb.mulAssign(this.morphBaseInfluence),!0===i&&$x.mulAssign(this.morphBaseInfluence);const u=am(h.width);pv(n,(({i:t})=>{const e=om(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(ox(this.mesh.morphTexture,cm(am(t).add(1),am(tg))).r):e.assign(gx("morphTargetInfluences","float").element(t).toVar()),!0===s&&kb.addAssign(xv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:am(0)})),!0===i&&$x.addAssign(xv({bufferMap:o,influence:e,stride:a,width:u,depth:t,offset:am(1)}))}))}update(){const t=this.morphBaseInfluence;this.mesh.geometry.morphTargetsRelative?t.value=1:t.value=1-this.mesh.morphTargetInfluences.reduce(((t,e)=>t+e),0)}}const vv=Qp(bv);lp("MorphNode",bv);const Tv=Hb.negate().reflect(Jx),_v=Hb.negate().refract(Jx,Lb),wv=Tv.transformDirection(Mx).toVar("reflectVector"),Sv=_v.transformDirection(Mx).toVar("reflectVector");class Mv extends rx{constructor(t,e=null,s=null,i=null){super(t,e,s,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===ht?wv:t.mapping===ut?Sv:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),mm(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const s=this.value;return t.renderer.coordinateSystem!==Ds&&s.isRenderTargetTexture?e:mm(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const Av=Qp(Mv);wp("cubeTexture",Av),lp("CubeTextureNode",Mv);class Nv extends up{constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}lp("LightingNode",Nv);const Rv=tm((({depthTexture:t,shadowCoord:e})=>nx(t,e.xy).compare(e.z))),Cv=tm((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>nx(t,e).compare(s),r=gx("mapSize","vec2",s),n=gx("radius","float",s),o=lm(1).div(r),a=o.x.negate().mul(n),h=o.y.negate().mul(n),u=o.x.mul(n),l=o.y.mul(n),c=a.div(2),d=h.div(2),p=u.div(2),m=l.div(2);return mf(i(e.xy.add(lm(a,h)),e.z),i(e.xy.add(lm(0,h)),e.z),i(e.xy.add(lm(u,h)),e.z),i(e.xy.add(lm(c,d)),e.z),i(e.xy.add(lm(0,d)),e.z),i(e.xy.add(lm(p,d)),e.z),i(e.xy.add(lm(a,0)),e.z),i(e.xy.add(lm(c,0)),e.z),i(e.xy,e.z),i(e.xy.add(lm(p,0)),e.z),i(e.xy.add(lm(u,0)),e.z),i(e.xy.add(lm(c,m)),e.z),i(e.xy.add(lm(0,m)),e.z),i(e.xy.add(lm(p,m)),e.z),i(e.xy.add(lm(a,l)),e.z),i(e.xy.add(lm(0,l)),e.z),i(e.xy.add(lm(u,l)),e.z)).mul(1/17)})),Ev=tm((({depthTexture:t,shadowCoord:e,shadow:s})=>{const i=(e,s)=>nx(t,e).compare(s),r=gx("mapSize","vec2",s),n=lm(1).div(r),o=n.x,a=n.y,h=e.xy,u=ty(h.mul(r).add(.5));return h.subAssign(u.mul(n)),mf(i(h,e.z),i(h.add(lm(o,0)),e.z),i(h.add(lm(0,a)),e.z),i(h.add(n),e.z),Oy(i(h.add(lm(o.negate(),0)),e.z),i(h.add(lm(o.mul(2),0)),e.z),u.x),Oy(i(h.add(lm(o.negate(),a)),e.z),i(h.add(lm(o.mul(2),a)),e.z),u.x),Oy(i(h.add(lm(0,a.negate())),e.z),i(h.add(lm(0,a.mul(2))),e.z),u.y),Oy(i(h.add(lm(o,a.negate())),e.z),i(h.add(lm(o,a.mul(2))),e.z),u.y),Oy(Oy(i(h.add(lm(o.negate(),a.negate())),e.z),i(h.add(lm(o.mul(2),a.negate())),e.z),u.x),Oy(i(h.add(lm(o.negate(),a.mul(2))),e.z),i(h.add(lm(o.mul(2),a.mul(2))),e.z),u.x),u.y)).mul(1/9)})),Bv=[Rv,Cv,Ev];let Iv=null;class Pv extends Nv{constructor(t=null){super(),this.updateType=Xd.FRAME,this.light=t,this.color=new Yr,this.colorNode=uf(this.color),this.baseColorNode=null,this.shadowMap=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return super.getCacheKey()+"-"+this.light.id+"-"+(this.light.castShadow?"1":"0")}getHash(){return this.light.uuid}setupShadow(t){const{object:e,renderer:s}=t;let i=this.shadowColorNode;if(null===i){null===Iv&&(Iv=t.createNodeMaterial(),Iv.fragmentNode=xm(0,0,0,1),Iv.isShadowNodeMaterial=!0);const r=new Ka;r.compareFunction=Ts;const n=this.light.shadow,o=t.createRenderTarget(n.mapSize.width,n.mapSize.height);o.depthTexture=r,n.camera.updateProjectionMatrix();const a=gx("intensity","float",n),h=gx("bias","float",n),u=gx("normalBias","float",n),l=e.material.shadowPositionNode||Gb;let c=uf(n.matrix).mul(l.add(Yx.mul(u)));c=c.xyz.div(c.w);let d=c.z.add(h);s.coordinateSystem===Ds&&(d=d.mul(2).sub(1)),c=mm(c.x,c.y.oneMinus(),d);const p=c.x.greaterThanEqual(0).and(c.x.lessThanEqual(1)).and(c.y.greaterThanEqual(0)).and(c.y.lessThanEqual(1)).and(c.z.lessThanEqual(1)),m=n.filterNode||Bv[s.shadowMap.type]||null;if(null===m)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const g=p.cond(m({depthTexture:r,shadowCoord:c,shadow:n}),om(1));this.shadowMap=o,this.shadowNode=g,this.shadowColorNode=i=this.colorNode.mul(Oy(1,g,a)),this.baseColorNode=this.colorNode}this.colorNode=i,this.updateBeforeType=Xd.RENDER}setup(t){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?t.object.receiveShadow&&this.setupShadow(t):null!==this.shadowNode&&this.disposeShadow()}updateShadow(t){const{shadowMap:e,light:s}=this,{renderer:i,scene:r,camera:n}=t,o=r.overrideMaterial;r.overrideMaterial=Iv,e.setSize(s.shadow.mapSize.width,s.shadow.mapSize.height),s.shadow.updateMatrices(s),s.shadow.camera.layers.mask=n.layers.mask;const a=i.getRenderTarget(),h=i.getRenderObjectFunction();i.setRenderObjectFunction(((t,...e)=>{!0===t.castShadow&&i.renderObject(t,...e)})),i.setRenderTarget(e),i.render(r,s.shadow.camera),i.setRenderTarget(a),i.setRenderObjectFunction(h),r.overrideMaterial=o}disposeShadow(){this.shadowMap.dispose(),this.shadowMap=null,this.shadowNode=null,this.shadowColorNode=null,this.baseColorNode=null,this.updateBeforeType=Xd.NONE}updateBefore(t){this.updateShadow(t)}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}lp("AnalyticLightNode",Pv);const Fv=new WeakMap;class Uv extends up{constructor(t=[]){super("vec3"),this.totalDiffuseNode=mm().temp("totalDiffuse"),this.totalSpecularNode=mm().temp("totalSpecular"),this.outgoingLightNode=mm().temp("outgoingLight"),this.lightNodes=t,this._hash=null}get hasLight(){return this.lightNodes.length>0}getHash(){if(null===this._hash){const t=[];for(const e of this.lightNodes)t.push(e.getHash());this._hash="lights-"+t.join(",")}return this._hash}analyze(t){const e=t.getDataFromNode(this);for(const s of e.nodes)s.build(t)}setup(t){const e=t.context,s=e.lightingModel;let i=this.outgoingLightNode;if(s){const{lightNodes:r,totalDiffuseNode:n,totalSpecularNode:o}=this;e.outgoingLight=i;const a=t.addStack();t.getDataFromNode(this).nodes=a.nodes,s.start(e,a,t);for(const e of r)e.build(t);s.indirect(e,a,t);const{backdrop:h,backdropAlpha:u}=e,{directDiffuse:l,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let m=l.add(d);null!==h&&(m=mm(null!==u?u.mix(m,h):h),e.material.transparent=!0),n.assign(m),o.assign(c.add(p)),i.assign(n.add(o)),s.finish(e,a,t),i=i.bypass(t.removeStack())}return i}_getLightNodeById(t){for(const e of this.lightNodes)if(e.isAnalyticLightNode&&e.light.id===t)return e;return null}fromLights(t=[]){const e=[];t=(t=>t.sort(((t,e)=>t.id-e.id)))(t);for(const s of t){let t=this._getLightNodeById(s.id);if(null===t){const e=s.constructor,i=Fv.has(e)?Fv.get(e):Pv;t=Yp(new i(s))}e.push(t)}return this.lightNodes=e,this._hash=null,this}}const zv=t=>Yp((new Uv).fromLights(t)),Ov=Qp(Uv);function Lv(t,e){if(Fv.has(t))console.warn(`Redefinition of light node ${e.type}`);else{if("function"!=typeof t)throw new Error(`Light ${t.name} is not a class`);if("function"!=typeof e||!e.type)throw new Error(`Light node ${e.type} is not a class`);Fv.set(t,e)}}class Vv extends Nv{constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}lp("AONode",Vv);class Dv extends Ym{constructor(t,e=null,s=null,i=null){super(t),this.lightingModel=e,this.backdropNode=s,this.backdropAlphaNode=i,this._context=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,s={directDiffuse:mm().temp("directDiffuse"),directSpecular:mm().temp("directSpecular"),indirectDiffuse:mm().temp("indirectDiffuse"),indirectSpecular:mm().temp("indirectSpecular")};return{radiance:mm().temp("radiance"),irradiance:mm().temp("irradiance"),iblIrradiance:mm().temp("iblIrradiance"),ambientOcclusion:om(1).temp("ambientOcclusion"),reflectedLight:s,backdrop:t,backdropAlpha:e}}setup(t){return this.context=this._context||(this._context=this.getContext()),this.context.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const kv=Qp(Dv);wp("lightingContext",kv),lp("LightingContextNode",Dv);class Gv extends Nv{constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let Wv,jv;lp("IrradianceNode",Gv);class Hv extends up{constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===Hv.VIEWPORT?"vec4":this.scope===Hv.COORDINATE?"vec3":"vec2"}getUpdateType(){let t=Xd.NONE;return this.scope!==Hv.RESOLUTION&&this.scope!==Hv.VIEWPORT||(t=Xd.RENDER),this.updateType=t,t}update({renderer:t}){this.scope===Hv.VIEWPORT?t.getViewport(jv):t.getDrawingBufferSize(Wv)}setup(){const t=this.scope;let e=null;if(t===Hv.RESOLUTION)e=uf(Wv||(Wv=new Ks));else if(t===Hv.VIEWPORT)e=uf(jv||(jv=new _i));else{e=qv.div($v);let s=e.x,i=e.y;/bottom/i.test(t)&&(i=i.oneMinus()),/right/i.test(t)&&(s=s.oneMinus()),e=lm(s,i)}return e}generate(t){if(this.scope===Hv.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const s=t.getNodeProperties($v).outputNode.build(t);e=`${t.getType("vec3")}( ${e}.x, ${s}.y - ${e}.y, ${e}.z )`}return e}return super.generate(t)}}Hv.COORDINATE="coordinate",Hv.RESOLUTION="resolution",Hv.VIEWPORT="viewport",Hv.TOP_LEFT="topLeft",Hv.BOTTOM_LEFT="bottomLeft",Hv.TOP_RIGHT="topRight",Hv.BOTTOM_RIGHT="bottomRight";const qv=Kp(Hv,Hv.COORDINATE),$v=Kp(Hv,Hv.RESOLUTION),Xv=Kp(Hv,Hv.VIEWPORT),Yv=Kp(Hv,Hv.TOP_LEFT),Jv=Kp(Hv,Hv.BOTTOM_LEFT),Zv=Kp(Hv,Hv.TOP_RIGHT),Qv=Kp(Hv,Hv.BOTTOM_RIGHT);lp("ViewportNode",Hv);const Kv=new Ks;class tT extends rx{constructor(t=Yv,e=null,s=null){null===s&&((s=new Xa).minFilter=St),super(s,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=Xd.FRAME}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(Kv);const s=this.value;s.image.width===Kv.width&&s.image.height===Kv.height||(s.image.width=Kv.width,s.image.height=Kv.height,s.needsUpdate=!0);const i=s.generateMipmaps;s.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(s),s.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const eT=Qp(tT),sT=Qp(tT,null,null,{generateMipmaps:!0});wp("viewportTexture",eT),wp("viewportMipTexture",sT),lp("ViewportTextureNode",tT);let iT=null;class rT extends tT{constructor(t=Yv,e=null){null===iT&&(iT=new Ka),super(t,e,iT)}}const nT=Qp(rT);wp("viewportDepthTexture",nT),lp("ViewportDepthTextureNode",rT);class oT extends up{constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===oT.DEPTH?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,s=this.valueNode;let i=null;if(e===oT.DEPTH)i=null!==s?cT().assign(s):t.isPerspectiveCamera?uT(jb.z,vx,Tx):aT(jb.z,vx,Tx);else if(e===oT.LINEAR_DEPTH)if(null!==s)if(t.isPerspectiveCamera){const t=lT(s,vx,Tx);i=aT(t,vx,Tx)}else i=s;else i=aT(jb.z,vx,Tx);return i}}const aT=(t,e,s)=>t.add(e).div(e.sub(s)),hT=(t,e,s)=>e.sub(s).mul(t).sub(e),uT=(t,e,s)=>e.add(t).mul(s).div(s.sub(e).mul(t)),lT=(t,e,s)=>e.mul(s).div(s.sub(e).mul(t).sub(s));oT.DEPTH="depth",oT.LINEAR_DEPTH="linearDepth";const cT=Qp(oT,oT.DEPTH),dT=Kp(oT,oT.DEPTH),pT=Qp(oT,oT.LINEAR_DEPTH),mT=pT(nT());dT.assign=t=>cT(t),lp("ViewportDepthNode",oT);class gT extends up{constructor(t=gT.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:s,localClippingCount:i,globalClippingCount:r}=e,n=r+i,o=s?n-i:n;return this.scope===gT.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,n,o):this.setupDefault(e.planes,n,o)}setupAlphaToCoverage(t,e,s){return tm((()=>{const i=dx(t),r=mg("float","distanceToPlane"),n=mg("float","distanceToGradient"),o=mg("float","clipOpacity");let a;if(o.assign(1),pv(s,(({i:t})=>{a=i.element(t),r.assign(jb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),o.mulAssign(ky(n.negate(),n,r)),o.equal(0).discard()})),s<e){const t=mg("float","unionclipOpacity");t.assign(1),pv({start:s,end:e},(({i:e})=>{a=i.element(e),r.assign(jb.dot(a.xyz).negate().add(a.w)),n.assign(r.fwidth().div(2)),t.mulAssign(ky(n.negate(),n,r).oneMinus())})),o.mulAssign(t.oneMinus())}fg.a.mulAssign(o),fg.a.equal(0).discard()}))()}setupDefault(t,e,s){return tm((()=>{const i=dx(t);let r;if(pv(s,(({i:t})=>{r=i.element(t),jb.dot(r.xyz).greaterThan(r.w).discard()})),s<e){const t=mg("bool","clipped");t.assign(!0),pv({start:s,end:e},(({i:e})=>{r=i.element(e),t.assign(jb.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}gT.ALPHA_TO_COVERAGE="alphaToCoverage",gT.DEFAULT="default";class fT extends up{constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:s}=t;return e.coordinateSystem===Vs&&s.side===d?"false":t.getFrontFacing()}}const yT=Kp(fT),xT=om(yT).mul(2).sub(1);lp("FrontFacingNode",fT);const bT=new Map;class vT extends Qr{constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,this.normals=!0,this.lightsNode=null,this.envNode=null,this.aoNode=null,this.colorNode=null,this.normalNode=null,this.opacityNode=null,this.backdropNode=null,this.backdropAlphaNode=null,this.alphaTestNode=null,this.positionNode=null,this.depthNode=null,this.shadowNode=null,this.shadowPositionNode=null,this.outputNode=null,this.mrtNode=null,this.fragmentNode=null,this.vertexNode=null}customProgramCacheKey(){return this.type+tp(this)}build(t){this.setup(t)}setup(t){let e;t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),t.addFlow("vertex",t.removeStack()),t.addStack();const s=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){!0===this.normals&&this.setupNormal(t),this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==s&&t.stack.add(s);const r=xm(i,fg.a).max(0);e=this.setupOutput(t,r),Fg.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const s=t.renderer.getMRT(),i=this.mrtNode;null!==s?(e=s,null!==i&&(e=s.merge(i))):null!==i&&(e=i)}}else{let s=this.fragmentNode;!0!==s.isOutputStructNode&&(s=xm(s)),e=this.setupOutput(t,s)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack())}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:s}=t.clippingContext;let i=null;return(e||s)&&(this.alphaToCoverage?i=Yp(new gT(gT.ALPHA_TO_COVERAGE)):t.stack.add(Yp(new gT))),i}setupDepth(t){const{renderer:e}=t;let s=this.depthNode;if(null===s&&!0===e.logarithmicDepthBuffer){s=$b().w.add(1).log2().mul(_x).mul(.5)}null!==s&&dT.assign(s).append()}setupPosition(t){const{object:e}=t,s=e.geometry;if(t.addStack(),(s.morphAttributes.position||s.morphAttributes.normal||s.morphAttributes.color)&&vv(e).append(),!0===e.isSkinnedMesh&&cv(e).append(),this.displacementMap){const t=xx("displacementMap","texture"),e=xx("displacementScale","float"),s=xx("displacementBias","float");kb.addAssign($x.normalize().mul(t.x.mul(e).add(s)))}e.isBatchedMesh&&hv(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&tv(e).append(),null!==this.positionNode&&kb.assign(this.positionNode);const i=$b();return t.context.vertex=t.removeStack(),t.context.mvp=i,i}setupDiffuseColor({object:t,geometry:e}){let s=this.colorNode?xm(this.colorNode):sb;if(!0===this.vertexColors&&e.hasAttribute("color")&&(s=xm(s.xyz.mul(jm("color","vec3")),s.a)),t.instanceColor){s=gg("vec3","vInstanceColor").mul(s)}fg.assign(s);const i=this.opacityNode?om(this.opacityNode):nb;if(fg.a.assign(fg.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?om(this.alphaTestNode):eb;fg.a.lessThanEqual(t).discard()}!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&fg.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?mm(0):fg.rgb}setupNormal(){if(!0===this.flatShading){const t=jb.dFdx().cross(jb.dFdy()).normalize();Jx.assign(t.mul(xT))}else{const t=this.normalNode?mm(this.normalNode):pb;Jx.assign(t.mul(xT))}}setupEnvironment(t){let e=null;return this.envNode?e=this.envNode:this.envMap?e=this.envMap.isCubeTexture?Av(this.envMap):nx(this.envMap):t.environmentNode&&(e=t.environmentNode),e}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new Gv(zb)),e}setupLights(t){const e=[],s=this.setupEnvironment(t);s&&s.isLightingNode&&e.push(s);const i=this.setupLightMap(t);if(i&&i.isLightingNode&&e.push(i),null!==this.aoNode||t.material.aoMap){const t=null!==this.aoNode?this.aoNode:Ob;e.push(new Vv(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=Ov([...r.lightNodes,...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:s,backdropAlphaNode:i,emissiveNode:r}=this,n=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let o=this.setupOutgoingLight(t);if(n&&!1!==n.hasLight){const e=this.setupLightingModel(t);o=kv(n,e,s,i)}else null!==s&&(o=mm(null!==i?Oy(o,s,i):s));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(yg.assign(mm(r||rb)),o=o.add(yg)),o}setupOutput(t,e){if(!0===this.fog){const s=t.fogNode;s&&(e=xm(s.mix(e.rgb,s.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const s=t[e];void 0===this[e]&&(this[e]=s,s&&s.clone&&(this[e]=s.clone()))}const e=Object.getOwnPropertyDescriptors(t.constructor.prototype);for(const t in e)void 0===Object.getOwnPropertyDescriptor(this.constructor.prototype,t)&&void 0!==e[t].get&&Object.defineProperty(this.constructor.prototype,t,e[t])}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{},nodes:{}});const s=Qr.prototype.toJSON.call(this,t),i=ep(this);s.inputNodes={};for(const{property:e,childNode:r}of i)s.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const s in t){const i=t[s];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),n=r(t.nodes);e.length>0&&(s.textures=e),i.length>0&&(s.images=i),n.length>0&&(s.nodes=n)}return s}copy(t){return this.lightsNode=t.lightsNode,this.envNode=t.envNode,this.colorNode=t.colorNode,this.normalNode=t.normalNode,this.opacityNode=t.opacityNode,this.backdropNode=t.backdropNode,this.backdropAlphaNode=t.backdropAlphaNode,this.alphaTestNode=t.alphaTestNode,this.positionNode=t.positionNode,this.depthNode=t.depthNode,this.shadowNode=t.shadowNode,this.shadowPositionNode=t.shadowPositionNode,this.outputNode=t.outputNode,this.mrtNode=t.mrtNode,this.fragmentNode=t.fragmentNode,this.vertexNode=t.vertexNode,super.copy(t)}static fromMaterial(t){if(!0===t.isNodeMaterial)return t;const e=_T(t.type.replace("Material","NodeMaterial"));if(void 0===e)throw new Error(`NodeMaterial: Material "${t.type}" is not compatible.`);for(const s in t)e[s]=t[s];return e}}function TT(t,e){if("function"!=typeof e||!t)throw new Error(`Node material ${t} is not a class`);bT.has(t)?console.warn(`Redefinition of node material ${t}`):(bT.set(t,e),e.type=t)}function _T(t){const e=bT.get(t);if(void 0!==e)return new e}TT("NodeMaterial",vT);class wT{constructor(t,e){this.name=t,this.value=e,this.boundary=0,this.itemSize=0,this.offset=0}setValue(t){this.value=t}getValue(){return this.value}}class ST extends wT{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class MT extends wT{constructor(t,e=new Ks){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class AT extends wT{constructor(t,e=new Ei){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class NT extends wT{constructor(t,e=new _i){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class RT extends wT{constructor(t,e=new Yr){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class CT extends wT{constructor(t,e=new ti){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class ET extends wT{constructor(t,e=new or){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class BT extends ST{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class IT extends MT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class PT extends AT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class FT extends NT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class UT extends RT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class zT extends CT{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class OT extends ET{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class LT extends up{constructor(t,e,s=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=s}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const s=this.elseNode.getNodeType(t);if(t.getTypeLength(s)>t.getTypeLength(e))return s}return e}setup(t){const e=t.getNodeProperties(this);e.condNode=this.condNode.cache(),e.ifNode=this.ifNode.cache(),e.elseNode=this.elseNode?this.elseNode.cache():null}generate(t,e){const s=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:n,elseNode:o}=t.getNodeProperties(this),a="void"!==e,h=a?mg(s).build(t):"";i.nodeProperty=h;const u=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${u} ) {\n\n`).addFlowTab();let l=n.build(t,s);if(l&&(l=a?h+" = "+l+";":"return "+l+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+l+"\n\n"+t.tab+"}"),null!==o){t.addFlowCode(" else {\n\n").addFlowTab();let e=o.build(t,s);e&&(e=a?h+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(h,s,e)}}const VT=Qp(LT);wp("cond",VT),lp("CondNode",LT);class DT extends up{constructor(t=null){super(),this.nodes=[],this.outputNode=null,this.parent=t,this._currentCond=null,this.isStackNode=!0}getNodeType(t){return this.outputNode?this.outputNode.getNodeType(t):"void"}add(t){return this.nodes.push(t),this}if(t,e){const s=new Xp(e);return this._currentCond=VT(t,s),this.add(this._currentCond)}elseif(t,e){const s=new Xp(e),i=VT(t,s);return this._currentCond.elseNode=i,this._currentCond=i,this}else(t){return this._currentCond.elseNode=new Xp(t),this}build(t,...e){const s=sm();em(this);for(const e of this.nodes)e.build(t,"void");return em(s),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}}const kT=Qp(DT);lp("StackNode",DT);class GT extends dp{constructor(t=Wb){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),s=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return lm(e,s)}}const WT=Qp(GT);lp("EquirectUVNode",GT);class jT extends so{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const s=e.minFilter,i=e.generateMipmaps;e.generateMipmaps=!0,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 r=new Hn(5,5,5),n=WT(Wb),o=_T("MeshBasicNodeMaterial");o.colorNode=nx(e,n,0),o.side=d,o.blending=m;const a=new Wn(r,o),h=new no;h.add(a),e.minFilter===St&&(e.minFilter=Tt);return new to(1,10,this).update(t,h),e.minFilter=s,e.currentGenerateMipmaps=i,a.geometry.dispose(),a.material.dispose(),this}}const HT=om(1),qT=om(-2),$T=om(.8),XT=om(-1),YT=om(.4),JT=om(2),ZT=om(.305),QT=om(3),KT=om(.21),t_=om(4),e_=om(4),s_=om(16),i_=tm((([t])=>{const e=mm(ay(t)).toVar(),s=om(-1).toVar();return im(e.x.greaterThan(e.z),(()=>{im(e.x.greaterThan(e.y),(()=>{s.assign(VT(t.x.greaterThan(0),0,3))})).else((()=>{s.assign(VT(t.y.greaterThan(0),1,4))}))})).else((()=>{im(e.z.greaterThan(e.y),(()=>{s.assign(VT(t.z.greaterThan(0),2,5))})).else((()=>{s.assign(VT(t.y.greaterThan(0),1,4))}))})),s})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),r_=tm((([t,e])=>{const s=lm().toVar();return im(e.equal(0),(()=>{s.assign(lm(t.z,t.y).div(ay(t.x)))})).elseif(e.equal(1),(()=>{s.assign(lm(t.x.negate(),t.z.negate()).div(ay(t.y)))})).elseif(e.equal(2),(()=>{s.assign(lm(t.x.negate(),t.y).div(ay(t.z)))})).elseif(e.equal(3),(()=>{s.assign(lm(t.z.negate(),t.y).div(ay(t.x)))})).elseif(e.equal(4),(()=>{s.assign(lm(t.x.negate(),t.z).div(ay(t.y)))})).else((()=>{s.assign(lm(t.x,t.y).div(ay(t.z)))})),ff(.5,s.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),n_=tm((([t])=>{const e=om(0).toVar();return im(t.greaterThanEqual($T),(()=>{e.assign(HT.sub(t).mul(XT.sub(qT)).div(HT.sub($T)).add(qT))})).elseif(t.greaterThanEqual(YT),(()=>{e.assign($T.sub(t).mul(JT.sub(XT)).div($T.sub(YT)).add(XT))})).elseif(t.greaterThanEqual(ZT),(()=>{e.assign(YT.sub(t).mul(QT.sub(JT)).div(YT.sub(ZT)).add(JT))})).elseif(t.greaterThanEqual(KT),(()=>{e.assign(ZT.sub(t).mul(t_.sub(QT)).div(ZT.sub(KT)).add(QT))})).else((()=>{e.assign(om(-2).mul(Xf(ff(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),o_=tm((([t,e])=>{const s=t.toVar();s.assign(ff(2,s).sub(1));const i=mm(s,1).toVar();return im(e.equal(0),(()=>{i.assign(i.zyx)})).elseif(e.equal(1),(()=>{i.assign(i.xzy),i.xz.mulAssign(-1)})).elseif(e.equal(2),(()=>{i.x.mulAssign(-1)})).elseif(e.equal(3),(()=>{i.assign(i.zyx),i.xz.mulAssign(-1)})).elseif(e.equal(4),(()=>{i.assign(i.xzy),i.xy.mulAssign(-1)})).elseif(e.equal(5),(()=>{i.z.mulAssign(-1)})),i})).setLayout({name:"getDirection",type:"vec3",inputs:[{name:"uv",type:"vec2"},{name:"face",type:"float"}]}),a_=tm((([t,e,s,i,r,n])=>{const o=om(s),a=mm(e),h=Ly(n_(o),qT,n),u=ty(h),l=Zf(h),c=mm(h_(t,a,l,i,r,n)).toVar();return im(u.notEqual(0),(()=>{const e=mm(h_(t,a,l.add(1),i,r,n)).toVar();c.assign(Oy(c,e,u))})),c})),h_=tm((([t,e,s,i,r,n])=>{const o=om(s).toVar(),a=mm(e),h=om(i_(a)).toVar(),u=om(_y(e_.sub(o),0)).toVar();o.assign(_y(o,e_));const l=om(qf(o)).toVar(),c=lm(r_(a,h).mul(l.sub(2)).add(1)).toVar();return im(h.greaterThan(2),(()=>{c.y.addAssign(l),h.subAssign(3)})),c.x.addAssign(h.mul(l)),c.x.addAssign(u.mul(ff(3,s_))),c.y.addAssign(ff(4,qf(n).sub(l))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(lm(),lm())})),u_=tm((({envMap:t,mipInt:e,outputDirection:s,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:n,CUBEUV_TEXEL_HEIGHT:o,CUBEUV_MAX_MIP:a})=>{const h=sy(i),u=s.mul(h).add(r.cross(s).mul(ey(i))).add(r.mul(r.dot(s).mul(h.oneMinus())));return h_(t,u,e,n,o,a)})),l_=tm((({n:t,latitudinal:e,poleAxis:s,outputDirection:i,weights:r,samples:n,dTheta:o,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})=>{const d=mm(VT(e,s,Cy(s,i))).toVar();im(Df(d.equals(mm(0))),(()=>{d.assign(mm(i.z,0,i.x.negate()))})),d.assign(Kf(d));const p=mm().toVar();return p.addAssign(r.element(am(0)).mul(u_({theta:0,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),pv({start:am(1),end:t},(({i:t})=>{im(t.greaterThanEqual(n),(()=>{gv()}));const e=om(o.mul(om(t))).toVar();p.addAssign(r.element(t).mul(u_({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(u_({theta:e,axis:d,outputDirection:i,mipInt:a,envMap:h,CUBEUV_TEXEL_WIDTH:u,CUBEUV_TEXEL_HEIGHT:l,CUBEUV_MAX_MIP:c})))})),xm(p,1)})),c_=[.125,.215,.35,.446,.526,.582],d_=20,p_=new Rl(-1,1,1,-1,0,1),m_=new Qn(90,1),g_=new Yr;let f_=null,y_=0,x_=0;const b_=(1+Math.sqrt(5))/2,v_=1/b_,T_=[new Ei(-b_,v_,0),new Ei(b_,v_,0),new Ei(-v_,0,b_),new Ei(v_,0,b_),new Ei(0,b_,-v_),new Ei(0,b_,v_),new Ei(-1,1,-1),new Ei(1,1,-1),new Ei(-1,1,1),new Ei(1,1,1)],__=[3,1,5,0,4,2],w_=o_(lf(),jm("faceIndex")).normalize(),S_=mm(w_.x,w_.y.negate(),w_.z);class M_{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._backgroundBox=null}fromScene(t,e=0,s=.1,i=100){f_=this._renderer.getRenderTarget(),y_=this._renderer.getActiveCubeFace(),x_=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,s,i,r),e>0&&this._blur(r,0,0,e),this._applyPMREM(r),this._cleanup(r),r}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=C_(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=E_(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;t<this._lodPlanes.length;t++)this._lodPlanes[t].dispose()}_cleanup(t){this._renderer.setRenderTarget(f_,y_,x_),t.scissorTest=!1,N_(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===ht||t.mapping===ut?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),f_=this._renderer.getRenderTarget(),y_=this._renderer.getActiveCubeFace(),x_=this._renderer.getActiveMipmapLevel();const s=e||this._allocateTargets();return this._textureToCubeUV(t,s),this._applyPMREM(s),this._cleanup(s),s}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,s={magFilter:Tt,minFilter:Tt,generateMipmaps:!1,type:Pt,format:Dt,colorSpace:Ze},i=A_(t,e,s);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=A_(t,e,s);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=function(t){const e=[],s=[],i=[],r=[];let n=t;const o=t-4+1+c_.length;for(let a=0;a<o;a++){const o=Math.pow(2,n);s.push(o);let h=1/o;a>t-4?h=c_[a-t+4-1]:0===a&&(h=0),i.push(h);const u=1/(o-2),l=-u,c=1+u,d=[l,l,c,l,c,c,l,l,c,c,l,c],p=6,m=6,g=3,f=2,y=1,x=new Float32Array(g*m*p),b=new Float32Array(f*m*p),v=new Float32Array(y*m*p);for(let t=0;t<p;t++){const e=t%3*2/3-1,s=t>2?0:-1,i=[e,s,0,e+2/3,s,0,e+2/3,s+1,0,e,s,0,e+2/3,s+1,0,e,s+1,0],r=__[t];x.set(i,g*m*r),b.set(d,f*m*r);const n=[r,r,r,r,r,r];v.set(n,y*m*r)}const T=new Mn;T.setAttribute("position",new hn(x,g)),T.setAttribute("uv",new hn(b,f)),T.setAttribute("faceIndex",new hn(v,y)),e.push(T),r.push(new Wn(T,null)),n>4&&n--}return{lodPlanes:e,sizeLods:s,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,s){const i=dx(new Array(d_).fill(0)),r=uf(new Ei(0,1,0)),n=uf(0),o=om(d_),a=uf(0),h=uf(1),u=nx(null),l=uf(0),c=om(1/e),d=om(1/s),p=om(t),m={n:o,latitudinal:a,weights:i,poleAxis:r,outputDirection:S_,dTheta:n,samples:h,envMap:u,mipInt:l,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},g=R_();return g.uniforms=m,g.fragmentNode=l_({...m,latitudinal:a.equal(1)}),g}(i,t,e)}return i}_compileMaterial(t){const e=this._lodMeshes[0];e.material=t,this._renderer.compile(e,p_)}_sceneToCubeUV(t,e,s,i){const r=m_;r.near=e,r.far=s;const n=[-1,1,-1,-1,-1,-1],o=[1,1,1,-1,-1,-1],a=this._renderer,h=a.autoClear;a.getClearColor(g_),a.autoClear=!1;let u=this._backgroundBox;if(null===u){const t=new Kr({name:"PMREM.Background",side:d,depthWrite:!1,depthTest:!1});u=new Wn(new Hn,t)}let l=!1;const c=t.background;c?c.isColor&&(u.material.color.copy(c),t.background=null,l=!0):(u.material.color.copy(g_),l=!0),a.setRenderTarget(i),a.clear(),l&&a.render(u,r);for(let e=0;e<6;e++){const s=e%3;0===s?(r.up.set(0,n[e],0),r.lookAt(o[e],0,0)):1===s?(r.up.set(0,0,n[e]),r.lookAt(0,o[e],0)):(r.up.set(0,n[e],0),r.lookAt(0,0,o[e]));const h=this._cubeSize;N_(i,s*h,e>2?h:0,h,h),a.render(t,r)}a.autoClear=h,t.background=c}_textureToCubeUV(t,e){const s=this._renderer,i=t.mapping===ht||t.mapping===ut;i?null===this._cubemapMaterial&&(this._cubemapMaterial=C_(t)):null===this._equirectMaterial&&(this._equirectMaterial=E_(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const n=this._lodMeshes[0];n.material=r;const o=this._cubeSize;N_(e,0,0,3*o,2*o),s.setRenderTarget(e),s.render(n,p_)}_applyPMREM(t){const e=this._renderer,s=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;e<i;e++){const s=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),r=T_[(i-e-1)%T_.length];this._blur(t,e-1,e,s,r)}e.autoClear=s}_blur(t,e,s,i,r){const n=this._pingPongRenderTarget;this._halfBlur(t,n,e,s,i,"latitudinal",r),this._halfBlur(n,t,s,s,i,"longitudinal",r)}_halfBlur(t,e,s,i,r,n,o){const a=this._renderer,h=this._blurMaterial;"latitudinal"!==n&&"longitudinal"!==n&&console.error("blur direction must be either latitudinal or longitudinal!");const u=this._lodMeshes[i];u.material=h;const l=h.uniforms,c=this._sizeLods[s]-1,d=isFinite(r)?Math.PI/(2*c):2*Math.PI/39,p=r/d,m=isFinite(r)?1+Math.floor(3*p):d_;m>d_&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${m} samples when the maximum is set to 20`);const g=[];let f=0;for(let t=0;t<d_;++t){const e=t/p,s=Math.exp(-e*e/2);g.push(s),0===t?f+=s:t<m&&(f+=2*s)}for(let t=0;t<g.length;t++)g[t]=g[t]/f;t.texture.frame=(t.texture.frame||0)+1,l.envMap.value=t.texture,l.samples.value=m,l.weights.array=g,l.latitudinal.value="latitudinal"===n?1:0,o&&(l.poleAxis.value=o);const{_lodMax:y}=this;l.dTheta.value=d,l.mipInt.value=y-s;const x=this._sizeLods[i];N_(e,3*x*(i>y-4?i-y+4:0),4*(this._cubeSize-x),3*x,2*x),a.setRenderTarget(e),a.render(u,p_)}}function A_(t,e,s){const i=new wi(t,e,s);return i.texture.mapping=306,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function N_(t,e,s,i,r){const n=t.height-r-s;t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function R_(){const t=new vT;return t.depthTest=!1,t.depthWrite=!1,t.blending=m,t}function C_(t){const e=R_();return e.fragmentNode=Av(t,S_),e}function E_(t){const e=R_();return e.fragmentNode=nx(t,WT(S_),0),e}let B_=0;class I_{constructor(t="",e=[]){this.name=t,this.bindings=e,this.id=B_++}}const P_=new WeakMap,F_=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),U_=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),z_=t=>(t=Number(t))+(t%1?"":".0");class O_{constructor(t,e,s){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=s,this.scene=null,this.camera=null,this.nodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.lightsNode=null,this.environmentNode=null,this.fogNode=null,this.clippingContext=null,this.vertexShader=null,this.fragmentShader=null,this.computeShader=null,this.flowNodes={vertex:[],fragment:[],compute:[]},this.flowCode={vertex:"",fragment:"",compute:""},this.uniforms={vertex:[],fragment:[],compute:[],index:0},this.structs={vertex:[],fragment:[],compute:[],index:0},this.bindings={vertex:{},fragment:{},compute:{}},this.bindingsIndexes={},this.bindGroups=null,this.attributes=[],this.bufferAttributes=[],this.varyings=[],this.codes={},this.vars={},this.flow={code:""},this.chaining=[],this.stack=kT(),this.stacks=[],this.tab="\t",this.instanceBindGroups=!0,this.currentFunctionNode=null,this.context={keywords:new lg,material:this.material},this.cache=new dg,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null}getBingGroupsCache(){let t=P_.get(this.renderer);return void 0===t&&(t=new wd,P_.set(this.renderer,t)),t}createRenderTarget(t,e,s){return new wi(t,e,s)}createCubeRenderTarget(t,e){return new jT(t,e)}createPMREMGenerator(){return new M_(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const s=this.getBingGroupsCache(),i=[];let r,n=!0;for(const t of e)i.push(t),n=n&&!0!==t.groupNode.shared;return n?(r=s.get(i),void 0===r&&(r=new I_(t,i),s.set(i,r))):r=new I_(t,i),r}getBindGroupArray(t,e){const s=this.bindings[e];let i=s[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),s[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},s=this.bindings;for(const t of Qd)for(const i in s[t]){const r=s[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const s in e){const i=e[s],r=this._getBindGroup(s,i);t.push(r)}this.bindGroups=t}return t}setHashNode(t,e){this.hashNodes[e]=t}addNode(t){!1===this.nodes.includes(t)&&(this.nodes.push(t),this.setHashNode(t,t.getHash(this)))}buildUpdateNodes(){for(const t of this.nodes){const e=t.getUpdateType(),s=t.getUpdateBeforeType(),i=t.getUpdateAfterType();e!==Xd.NONE&&this.updateNodes.push(t.getSelf()),s!==Xd.NONE&&this.updateBeforeNodes.push(t),i!==Xd.NONE&&this.updateAfterNodes.push(t)}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(t){return t.magFilter===Tt||t.magFilter===_t||t.magFilter===bt||t.magFilter===St||t.minFilter===Tt||t.minFilter===_t||t.minFilter===bt||t.minFilter===St}addChain(t){this.chaining.push(t)}removeChain(t){if(this.chaining.pop()!==t)throw new Error("NodeBuilder: Invalid node chaining!")}getMethod(t){return t}getNodeFromHash(t){return this.hashNodes[t]}addFlow(t,e){return this.flowNodes[t].push(e),e}setContext(t){this.context=t}getContext(){return this.context}getSharedContext(){return this.context,this.context}setCache(t){this.cache=t}getCache(){return this.cache}getCacheFromNode(t,e=!0){const s=this.getDataFromNode(t);return void 0===s.cache&&(s.cache=new dg(e?this.getCache():null)),s.cache}isAvailable(){return!1}getVertexIndex(){console.warn("Abstract function.")}getInstanceIndex(){console.warn("Abstract function.")}getDrawIndex(){console.warn("Abstract function.")}getFrontFacing(){console.warn("Abstract function.")}getFragCoord(){console.warn("Abstract function.")}isFlipY(){return!1}generateTexture(){console.warn("Abstract function.")}generateTextureLod(){console.warn("Abstract function.")}generateConst(t,e=null){if(null===e&&("float"===t||"int"===t||"uint"===t?e=0:"bool"===t?e=!1:"color"===t?e=new Yr:"vec2"===t?e=new Ks:"vec3"===t?e=new Ei:"vec4"===t&&(e=new _i)),"float"===t)return z_(e);if("int"===t)return`${Math.round(e)}`;if("uint"===t)return e>=0?`${Math.round(e)}u`:"0u";if("bool"===t)return e?"true":"false";if("color"===t)return`${this.getType("vec3")}( ${z_(e.r)}, ${z_(e.g)}, ${z_(e.b)} )`;const s=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===s)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(s>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(s>4)return`${this.getType(t)}()`;throw new Error(`NodeBuilder: Type '${t}' not found in generate constant attempt.`)}getType(t){return"color"===t?"vec3":t}hasGeometryAttribute(t){return this.geometry&&void 0!==this.geometry.getAttribute(t)}getAttribute(t,e){const s=this.attributes;for(const e of s)if(e.name===t)return e;const i=new ng(t,e);return s.push(i),i}getPropertyName(t){return t.name}isVector(t){return/vec\d/.test(t)}isMatrix(t){return/mat\d/.test(t)}isReference(t){return"void"===t||"property"===t||"sampler"===t||"texture"===t||"cubeTexture"===t||"storageTexture"===t||"depthTexture"===t||"texture3D"===t}needsColorSpaceToLinear(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===Et)return"int";if(e===Bt)return"uint"}return"float"}getElementType(t){return"mat2"===t?"vec2":"mat3"===t?"vec3":"mat4"===t?"vec4":this.getComponentType(t)}getComponentType(t){if("float"===(t=this.getVectorType(t))||"bool"===t||"int"===t||"uint"===t)return t;const e=/(b|i|u|)(vec|mat)([2-4])/.exec(t);return null===e?null:"b"===e[1]?"bool":"i"===e[1]?"int":"u"===e[1]?"uint":"float"}getVectorType(t){return"color"===t?"vec3":"texture"===t||"cubeTexture"===t||"storageTexture"===t||"texture3D"===t?"vec4":t}getTypeFromLength(t,e="float"){if(1===t)return e;const s=F_.get(t);return("float"===e?"":e[0])+s}getTypeFromArray(t){return U_.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const s=e.array,i=t.itemSize,r=t.normalized;let n;return t instanceof fn||!0===r||(n=this.getTypeFromArray(s)),this.getTypeFromLength(i,n)}getTypeLength(t){const e=this.getVectorType(t),s=/vec([2-4])/.exec(e);return null!==s?Number(s[1]):"float"===e||"bool"===e||"int"===e||"uint"===e?1:!0===/mat2/.test(t)?4:!0===/mat3/.test(t)?9:!0===/mat4/.test(t)?16:0}getVectorFromMatrix(t){return t.replace("mat","vec")}changeComponentType(t,e){return this.getTypeFromLength(this.getTypeLength(t),e)}getIntegerType(t){const e=this.getComponentType(t);return"int"===e||"uint"===e?t:this.changeComponentType(t,"int")}addStack(){return this.stack=kT(this.stack),this.stacks.push(sm()||this.stack),em(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,em(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,s=null){let i=(s=null===s?t.isGlobal(this)?this.globalCache:this.cache:s).getData(t);return void 0===i&&(i={},s.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const s=this.getDataFromNode(t,e);return s.properties||(s.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const s=this.getDataFromNode(t);let i=s.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new ng("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),s.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const s=this.getDataFromNode(t,e);if(void 0===s.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),s.structType=t}return t}getUniformFromNode(t,e,s=this.shaderStage,i=null){const r=this.getDataFromNode(t,s,this.globalCache);let n=r.uniform;if(void 0===n){const o=this.uniforms.index++;n=new og(i||"nodeUniform"+o,e,t),this.uniforms[s].push(n),r.uniform=n}return n}getVarFromNode(t,e=null,s=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let n=r.variable;if(void 0===n){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),n=new ag(e,s),t.push(n),r.variable=n}return n}getVaryingFromNode(t,e=null,s=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,n=t.length;null===e&&(e="nodeVarying"+n),r=new hg(e,s),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,s=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[s]||(this.codes[s]=[]),n=t.length;r=new ug("nodeCode"+n,e),t.push(r),i.code=r}return r}addLineFlowCode(t){return""===t||(t=this.tab+t,/;\s*$/.test(t)||(t+=";\n"),this.flow.code+=t),this}addFlowCode(t){return this.flow.code+=t,this}addFlowTab(){return this.tab+="\t",this}removeFlowTab(){return this.tab=this.tab.slice(0,-1),this}getFlowData(t){return this.flowsData.get(t)}flowNode(t){const e=t.getNodeType(this),s=this.flowChildNode(t,e);return this.flowsData.set(t,s),s}buildFunctionNode(t){const e=new Zg,s=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=s,e}flowShaderNode(t){const e=t.layout;let s;if(t.isArrayInput){s=[];for(const t of e.inputs)s.push(new jg(t.type,t.name))}else{s={};for(const t of e.inputs)s[t.name]=new jg(t.type,t.name)}t.layout=null;const i=t.call(s),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const s=this.flow,i=this.vars,r=this.cache,n=this.buildStage,o=this.stack,a={code:""};this.flow=a,this.vars={},this.cache=new dg,this.stack=kT();for(const s of Zd)this.setBuildStage(s),a.result=t.build(this,e);return a.vars=this.getVars(this.shaderStage),this.flow=s,this.vars=i,this.cache=r,this.stack=o,this.setBuildStage(n),a}getFunctionOperator(){return null}flowChildNode(t,e=null){const s=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=s,i}flowNodeFromShaderStage(t,e,s=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const n=this.flowChildNode(e,s);return null!==i&&(n.code+=`${this.tab+i} = ${n.result};\n`),this.flowCode[t]=this.flowCode[t]+n.code,this.setShaderStage(r),n}getAttributesArray(){return this.attributes.concat(this.bufferAttributes)}getAttributes(){console.warn("Abstract function.")}getVaryings(){console.warn("Abstract function.")}getVar(t,e){return`${this.getType(t)} ${e}`}getVars(t){let e="";const s=this.vars[t];if(void 0!==s)for(const t of s)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let s="";if(void 0!==e)for(const t of e)s+=t.code+"\n";return s}getHash(){return this.vertexShader+this.fragmentShader+this.computeShader}setShaderStage(t){this.shaderStage=t}getShaderStage(){return this.shaderStage}setBuildStage(t){this.buildStage=t}getBuildStage(){return this.buildStage}buildCode(){console.warn("Abstract function.")}build(){const{object:t,material:e}=this;null!==e?vT.fromMaterial(e).build(this):this.addFlow("compute",t);for(const t of Zd){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of Qd){this.setShaderStage(e);const s=this.flowNodes[e];for(const e of s)"generate"===t?this.flowNode(e):e.build(this)}}return this.setBuildStage(null),this.setShaderStage(null),this.buildCode(),this.buildUpdateNodes(),this}getNodeUniform(t,e){if("float"===e||"int"===e||"uint"===e)return new BT(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new IT(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new PT(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new FT(t);if("color"===e)return new UT(t);if("mat3"===e)return new zT(t);if("mat4"===e)return new OT(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){return _T(t)}format(t,e,s){if((e=this.getVectorType(e))===(s=this.getVectorType(s))||null===s||this.isReference(s))return t;const i=this.getTypeLength(e),r=this.getTypeLength(s);return 16===i&&9===r?`${this.getType(s)}(${t}[0].xyz, ${t}[1].xyz, ${t}[2].xyz)`:9===i&&4===r?`${this.getType(s)}(${t}[0].xy, ${t}[1].xy)`:i>4||r>4||0===r?t:i===r?`${this.getType(s)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),s):4===r&&i>1?`${this.getType(s)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(s)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(s)&&(t=`${this.getType(this.getComponentType(s))}( ${t} )`),`${this.getType(s)}( ${t} )`)}getSignature(){return`// Three.js r${t} - Node System\n`}}class L_{constructor(){this.time=0,this.deltaTime=0,this.frameId=0,this.renderId=0,this.startTime=null,this.updateMap=new WeakMap,this.updateBeforeMap=new WeakMap,this.updateAfterMap=new WeakMap,this.renderer=null,this.material=null,this.camera=null,this.object=null,this.scene=null}_getMaps(t,e){let s=t.get(e);return void 0===s&&(s={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,s)),s}updateBeforeNode(t){const e=t.getUpdateBeforeType(),s=t.updateReference(this);if(e===Xd.FRAME){const{frameMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(s,this.frameId)}else if(e===Xd.RENDER){const{renderMap:e}=this._getMaps(this.updateBeforeMap,s);e.get(s)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(s,this.renderId)}else e===Xd.OBJECT&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),s=t.updateReference(this);if(e===Xd.FRAME){const{frameMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(s,this.frameId)}else if(e===Xd.RENDER){const{renderMap:e}=this._getMaps(this.updateAfterMap,s);e.get(s)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(s,this.renderId)}else e===Xd.OBJECT&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),s=t.updateReference(this);if(e===Xd.FRAME){const{frameMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.frameId&&!1!==t.update(this)&&e.set(s,this.frameId)}else if(e===Xd.RENDER){const{renderMap:e}=this._getMaps(this.updateMap,s);e.get(s)!==this.renderId&&!1!==t.update(this)&&e.set(s,this.renderId)}else e===Xd.OBJECT&&t.update(this)}update(){this.frameId++,void 0===this.lastTime&&(this.lastTime=performance.now()),this.deltaTime=(performance.now()-this.lastTime)/1e3,this.lastTime=performance.now(),this.time+=this.deltaTime}}class V_{constructor(t,e,s=null,i="",r=!1){this.type=t,this.name=e,this.count=s,this.qualifier=i,this.isConst=r}}V_.isNodeFunctionInput=!0;class D_ extends up{constructor(t){super(),this.types=t,this.isStructTypeNode=!0}getMemberTypes(){return this.types}}lp("StructTypeNode",D_);class k_ extends up{constructor(...t){super(),this.members=t,this.isOutputStructNode=!0}setup(t){super.setup(t);const e=this.members,s=[];for(let i=0;i<e.length;i++)s.push(e[i].getNodeType(t));this.nodeType=t.getStructTypeFromNode(new D_(s)).name}generate(t,e){const s=t.getOutputStructName(),i=this.members,r=""!==s?s+".":"";for(let s=0;s<i.length;s++){const n=i[s].build(t,e);t.addLineFlowCode(`${r}m${s} = ${n}`)}return s}}const G_=Qp(k_);function W_(t,e){for(let s=0;s<t.length;s++)if(t[s].name===e)return s;return-1}lp("OutputStructNode",k_);class j_ extends k_{constructor(t){super(),this.outputNodes=t,this.isMRTNode=!0}getNode(t){return this.outputNodes[t]}merge(t){const e={...this.outputNodes,...t.outputNodes};return H_(e)}setup(t){const e=this.outputNodes,s=[],i=t.renderer.getRenderTarget().textures;for(const t in e){s[W_(i,t)]=xm(e[t])}return this.members=s,super.setup(t)}}const H_=Qp(j_);lp("MRTNode",j_);class q_ extends up{constructor(t){super(),this.seedNode=t}setup(){const t=this.seedNode.toUint().mul(747796405).add(2891336453),e=t.shiftRight(t.shiftRight(28).add(4)).bitXor(t).mul(277803737);return e.shiftRight(22).bitXor(e).toFloat().mul(1/2**32)}}const $_=Qp(q_);wp("hash",$_),lp("HashNode",q_);const X_=(t,e)=>Ey(ff(4,t.mul(gf(1,t))),e),Y_=(t,e)=>t.lessThan(.5)?X_(t.mul(2),e).div(2):gf(1,X_(ff(gf(1,t),2),e).div(2)),J_=(t,e,s)=>Ey(yf(Ey(t,e),mf(Ey(t,e),Ey(gf(1,t),s))),1/e),Z_=(t,e)=>ey(Lf.mul(e.mul(t).sub(1))).div(Lf.mul(e.mul(t).sub(1)));wp("parabola",X_),wp("gain",Y_),wp("pcurve",J_),wp("sinc",Z_);const Q_=tm((([t])=>t.fract().sub(.5).abs())),K_=tm((([t])=>mm(Q_(t.z.add(Q_(t.y.mul(1)))),Q_(t.z.add(Q_(t.x.mul(1)))),Q_(t.y.add(Q_(t.x.mul(1))))))),tw=tm((([t,e,s])=>{const i=mm(t).toVar(),r=om(1.4).toVar(),n=om(0).toVar(),o=mm(i).toVar();return pv({start:om(0),end:om(3),type:"float",condition:"<="},(()=>{const t=mm(K_(o.mul(2))).toVar();i.addAssign(t.add(s.mul(om(.1).mul(e)))),o.mulAssign(1.8),r.mulAssign(1.5),i.mulAssign(1.2);const a=om(Q_(i.z.add(Q_(i.x.add(Q_(i.y)))))).toVar();n.addAssign(a.div(r)),o.addAssign(.14)})),n}));let ew;Q_.setLayout({name:"tri",type:"float",inputs:[{name:"x",type:"float"}]}),K_.setLayout({name:"tri3",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),tw.setLayout({name:"triNoise3D",type:"float",inputs:[{name:"p",type:"vec3"},{name:"spd",type:"float"},{name:"time",type:"float"}]});class sw extends LT{constructor(t){ew=ew||ex("discard"),super(t,ew)}}const iw=Qp(sw),rw=t=>iw(t).append(),nw=()=>ex("return").append();wp("discard",rw),lp("DiscardNode",sw);class ow extends up{constructor(t=[],...e){super(),this.functionNodes=t,this.parametersNodes=e,this._candidateFnCall=null,this.global=!0}getNodeType(){return this.functionNodes[0].shaderNode.layout.type}setup(t){const e=this.parametersNodes;let s=this._candidateFnCall;if(null===s){let i=null,r=-1;for(const s of this.functionNodes){const n=s.shaderNode.layout;if(null===n)throw new Error("FunctionOverloadingNode: FunctionNode must be a layout.");const o=n.inputs;if(e.length===o.length){let n=0;for(let s=0;s<e.length;s++){const i=e[s],r=o[s];i.getNodeType(t)===r.type?n++:n=0}n>r&&(i=s,r=n)}}this._candidateFnCall=s=i(...e)}return s}}const aw=Qp(ow),hw=t=>(...e)=>aw(t,...e);lp("FunctionOverloadingNode",ow);class uw extends dp{constructor(){super("vec2")}setup(){const t=mm(Hb.z,0,Hb.x.negate()).normalize(),e=Hb.cross(t);return lm(t.dot(Jx),e.dot(Jx)).mul(.495).add(.5)}}const lw=Kp(uw);lp("MatcapUVNode",uw);class cw extends hf{constructor(t=cw.LOCAL,e=1,s=0){super(s),this.scope=t,this.scale=e,this.updateType=Xd.FRAME}update(t){const e=this.scope,s=this.scale;e===cw.LOCAL?this.value+=t.deltaTime*s:e===cw.DELTA?this.value=t.deltaTime*s:e===cw.FRAME?this.value=t.frameId:this.value=t.time*s}serialize(t){super.serialize(t),t.scope=this.scope,t.scale=this.scale}deserialize(t){super.deserialize(t),this.scope=t.scope,this.scale=t.scale}}cw.LOCAL="local",cw.GLOBAL="global",cw.DELTA="delta",cw.FRAME="frame";const dw=(t,e=0)=>Yp(new cw(cw.LOCAL,t,e)),pw=(t,e=0)=>Yp(new cw(cw.GLOBAL,t,e)),mw=(t,e=0)=>Yp(new cw(cw.DELTA,t,e)),gw=Kp(cw,cw.FRAME).toUint();lp("TimerNode",cw);class fw extends up{constructor(t=fw.SINE,e=dw()){super(),this.method=t,this.timeNode=e}getNodeType(t){return this.timeNode.getNodeType(t)}setup(){const t=this.method,e=Yp(this.timeNode);let s=null;return t===fw.SINE?s=e.add(.75).mul(2*Math.PI).sin().mul(.5).add(.5):t===fw.SQUARE?s=e.fract().round():t===fw.TRIANGLE?s=e.add(.5).fract().mul(2).sub(1).abs():t===fw.SAWTOOTH&&(s=e.fract()),s}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}fw.SINE="sine",fw.SQUARE="square",fw.TRIANGLE="triangle",fw.SAWTOOTH="sawtooth";const yw=Qp(fw,fw.SINE),xw=Qp(fw,fw.SQUARE),bw=Qp(fw,fw.TRIANGLE),vw=Qp(fw,fw.SAWTOOTH);lp("OscNode",fw);class Tw extends dp{constructor(t,e){super(),this.scope=t,this.node=e}getNodeType(t){return this.node.getNodeType(t)}setup(){const{scope:t,node:e}=this;let s=null;return t===Tw.DIRECTION_TO_COLOR?s=e.mul(.5).add(.5):t===Tw.COLOR_TO_DIRECTION&&(s=e.mul(2).sub(1)),s}}Tw.DIRECTION_TO_COLOR="directionToColor",Tw.COLOR_TO_DIRECTION="colorToDirection";const _w=Qp(Tw,Tw.DIRECTION_TO_COLOR),ww=Qp(Tw,Tw.COLOR_TO_DIRECTION);wp("directionToColor",_w),wp("colorToDirection",ww),lp("PackingNode",Tw);class Sw extends up{constructor(t,e,s,i=om(0),r=om(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=s,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:s,outLowNode:i,outHighNode:r,doClamp:n}=this;let o=t.sub(e).div(s.sub(e));return!0===n&&(o=o.clamp()),o.mul(r.sub(i)).add(i)}}const Mw=Qp(Sw,null,null,{doClamp:!1}),Aw=Qp(Sw);wp("remap",Mw),wp("remapClamp",Aw),lp("RemapNode",Sw);class Nw extends dp{constructor(t,e,s=lm(.5)){super("vec2"),this.uvNode=t,this.rotationNode=e,this.centerNode=s}setup(){const{uvNode:t,rotationNode:e,centerNode:s}=this;return t.sub(s).rotate(e).add(s)}}const Rw=Qp(Nw);wp("rotateUV",Rw),lp("RotateUVNode",Nw);class Cw extends dp{constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:s}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return _m(t,i,i.negate(),t).mul(s)}{const t=e,i=Em(xm(1,0,0,0),xm(0,sy(t.x),ey(t.x).negate(),0),xm(0,ey(t.x),sy(t.x),0),xm(0,0,0,1)),r=Em(xm(sy(t.y),0,ey(t.y),0),xm(0,1,0,0),xm(ey(t.y).negate(),0,sy(t.y),0),xm(0,0,0,1)),n=Em(xm(sy(t.z),ey(t.z).negate(),0,0),xm(ey(t.z),sy(t.z),0,0),xm(0,0,1,0),xm(0,0,0,1));return i.mul(r).mul(n).mul(xm(s,1)).xyz}}}const Ew=Qp(Cw);wp("rotate",Ew),lp("RotateNode",Cw);class Bw extends up{constructor(t,e=lf(),s=om(0)){super("vec2"),this.countNode=t,this.uvNode=e,this.frameNode=s}setup(){const{frameNode:t,uvNode:e,countNode:s}=this,{width:i,height:r}=s,n=t.mod(i.mul(r)).floor(),o=n.mod(i),a=r.sub(n.add(1).div(i).ceil()),h=s.reciprocal(),u=lm(o,a);return e.add(u).mul(h)}}const Iw=Qp(Bw);lp("SpriteSheetUVNode",Bw);class Pw extends pp{constructor(t,e){super(t,e),this.isStorageArrayElementNode=!0}set storageBufferNode(t){this.node=t}get storageBufferNode(){return this.node}setup(t){return!1===t.isAvailable("storageBuffer")&&(this.node.instanceIndex||!0!==this.node.bufferObject||t.setupPBO(this.node)),super.setup(t)}generate(t,e){let s;const i=t.context.assign;if(!1===t.isAvailable("storageBuffer")){const{node:e}=this;s=e.instanceIndex||!0!==this.node.bufferObject||!0===i?e.build(t):t.generatePBO(this)}else s=super.generate(t);if(!0!==i){const i=this.getNodeType(t);s=t.format(s,i,e)}return s}}const Fw=Qp(Pw);wp("storageElement",Fw),lp("StorageArrayElementNode",Pw);class Uw extends up{constructor(t,e=null,s=null,i=om(1),r=kb,n=$x){super("vec4"),this.textureXNode=t,this.textureYNode=e,this.textureZNode=s,this.scaleNode=i,this.positionNode=r,this.normalNode=n}setup(){const{textureXNode:t,textureYNode:e,textureZNode:s,scaleNode:i,positionNode:r,normalNode:n}=this;let o=n.abs().normalize();o=o.div(o.dot(mm(1)));const a=r.yz.mul(i),h=r.zx.mul(i),u=r.xy.mul(i),l=t.value,c=null!==e?e.value:l,d=null!==s?s.value:l,p=nx(l,a).mul(o.x),m=nx(c,h).mul(o.y),g=nx(d,u).mul(o.z);return mf(p,m,g)}}const zw=Qp(Uw),Ow=(...t)=>zw(...t);wp("triplanarTexture",Ow),lp("TriplanarTexturesNode",Uw);const Lw=new sa,Vw=new Ei,Dw=new Ei,kw=new Ei,Gw=new or,Ww=new Ei(0,0,-1),jw=new _i,Hw=new Ei,qw=new Ei,$w=new _i,Xw=new Ks,Yw=new wi,Jw=lm(Yv.x.oneMinus(),Yv.y);let Zw=!1;class Qw extends rx{constructor(t={}){super(Yw.texture,Jw);const{target:e=new Pr,resolution:s=1,generateMipmaps:i=!1,bounces:r=!0}=t;this.target=e,this.resolution=s,this.generateMipmaps=i,this.bounces=r,this.updateBeforeType=r?Xd.RENDER:Xd.FRAME,this.virtualCameras=new WeakMap,this.renderTargets=new WeakMap}_updateResolution(t,e){const s=this.resolution;e.getDrawingBufferSize(Xw),t.setSize(Math.round(Xw.width*s),Math.round(Xw.height*s))}setup(t){return this._updateResolution(Yw,t.renderer),super.setup(t)}getTextureNode(){return this.textureNode}getVirtualCamera(t){let e=this.virtualCameras.get(t);return void 0===e&&(e=t.clone(),this.virtualCameras.set(t,e)),e}getRenderTarget(t){let e=this.renderTargets.get(t);return void 0===e&&(e=new wi(0,0,{type:Pt}),!0===this.generateMipmaps&&(e.texture.minFilter=1008,e.texture.generateMipmaps=!0),this.renderTargets.set(t,e)),e}updateBefore(t){if(!1===this.bounces&&Zw)return!1;Zw=!0;const{scene:e,camera:s,renderer:i,material:r}=t,{target:n}=this,o=this.getVirtualCamera(s),a=this.getRenderTarget(o);if(i.getDrawingBufferSize(Xw),this._updateResolution(a,i),Dw.setFromMatrixPosition(n.matrixWorld),kw.setFromMatrixPosition(s.matrixWorld),Gw.extractRotation(n.matrixWorld),Vw.set(0,0,1),Vw.applyMatrix4(Gw),Hw.subVectors(Dw,kw),Hw.dot(Vw)>0)return;Hw.reflect(Vw).negate(),Hw.add(Dw),Gw.extractRotation(s.matrixWorld),Ww.set(0,0,-1),Ww.applyMatrix4(Gw),Ww.add(kw),qw.subVectors(Dw,Ww),qw.reflect(Vw).negate(),qw.add(Dw),o.coordinateSystem=s.coordinateSystem,o.position.copy(Hw),o.up.set(0,1,0),o.up.applyMatrix4(Gw),o.up.reflect(Vw),o.lookAt(qw),o.near=s.near,o.far=s.far,o.updateMatrixWorld(),o.projectionMatrix.copy(s.projectionMatrix),Lw.setFromNormalAndCoplanarPoint(Vw,Dw),Lw.applyMatrix4(o.matrixWorldInverse),jw.set(Lw.normal.x,Lw.normal.y,Lw.normal.z,Lw.constant);const h=o.projectionMatrix;$w.x=(Math.sign(jw.x)+h.elements[8])/h.elements[0],$w.y=(Math.sign(jw.y)+h.elements[9])/h.elements[5],$w.z=-1,$w.w=(1+h.elements[10])/h.elements[14],jw.multiplyScalar(1/jw.dot($w));h.elements[2]=jw.x,h.elements[6]=jw.y,h.elements[10]=jw.z-0,h.elements[14]=jw.w,this.value=a.texture,r.visible=!1;const u=i.getRenderTarget();i.setRenderTarget(a),i.render(e,o),i.setRenderTarget(u),r.visible=!0,Zw=!1}}const Kw=t=>Yp(new Qw(t)),tS=new Rl(-1,1,1,-1,0,1);class eS extends Mn{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new yn([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new yn(e,2))}}const sS=new eS;class iS extends Wn{constructor(t=null){super(sS,t),this.camera=tS}renderAsync(t){return t.renderAsync(this,tS)}render(t){t.render(this,tS)}}const rS=new Ks;class nS extends rx{constructor(t,e=null,s=null,i={type:Pt}){const r=new wi(e,s,i);super(r.texture,lf()),this.node=t,this.width=e,this.height=s,this.renderTarget=r,this.textureNeedsUpdate=!0,this.autoUpdate=!0,this.updateMap=new WeakMap,this._rttNode=null,this._quadMesh=new iS(new vT),this.updateBeforeType=Xd.RENDER}get autoSize(){return null===this.width}setup(t){return this._rttNode=this.node.context(t.getSharedContext()),this._quadMesh.material.needsUpdate=!0,super.setup(t)}setSize(t,e){this.width=t,this.height=e;const s=t*this.pixelRatio,i=e*this.pixelRatio;this.renderTarget.setSize(s,i),this.textureNeedsUpdate=!0}setPixelRatio(t){this.pixelRatio=t,this.setSize(this.width,this.height)}updateBefore({renderer:t}){if(!1===this.textureNeedsUpdate&&!1===this.autoUpdate)return;if(this.textureNeedsUpdate=!1,!0===this.autoSize){this.pixelRatio=t.getPixelRatio();const e=t.getSize(rS);this.setSize(e.width,e.height)}this._quadMesh.material.fragmentNode=this._rttNode;const e=t.getRenderTarget();t.setRenderTarget(this.renderTarget),this._quadMesh.render(t),t.setRenderTarget(e)}clone(){const t=new rx(this.value,this.uvNode,this.levelNode);return t.sampler=this.sampler,t.referenceNode=this,t}}const oS=(t,...e)=>Yp(new nS(Yp(t),...e));wp("toTexture",((t,...e)=>t.isTextureNode?t:oS(t,...e))),lp("RTTNode",nS);const aS=t=>t.mul(ev.w).xyz,hS=Gm(aS(qx.cross(ev)),"v_bitangentGeometry").normalize().toVar("bitangentGeometry"),uS=Gm(aS($x.cross(sv)),"v_bitangentLocal").normalize().toVar("bitangentLocal"),lS=Gm(aS(Xx.cross(iv)),"v_bitangentView").normalize().toVar("bitangentView"),cS=Gm(aS(Yx.cross(rv)),"v_bitangentWorld").normalize().toVar("bitangentWorld"),dS=aS(Jx.cross(nv)).normalize().toVar("transformedBitangentView"),pS=dS.transformDirection(Mx).normalize().toVar("transformedBitangentWorld"),mS=Am(iv,lS,Xx),gS=Hb.mul(mS),fS=(t,e)=>t.sub(gS.mul(e)),yS=(()=>{let t=Eg.cross(Hb);return t=t.cross(Eg).normalize(),t=Oy(t,Jx,Rg.mul(xg.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})();class xS extends Wm{constructor(t=0){super(null,"vec4"),this.isVertexColorNode=!0,this.index=t}getAttributeName(){const t=this.index;return"color"+(t>0?t:"")}generate(t){const e=this.getAttributeName(t);let s;return s=!0===t.hasGeometryAttribute(e)?super.generate(t):t.generateConst(this.nodeType,new _i(1,1,1,1)),s}serialize(t){super.serialize(t),t.index=this.index}deserialize(t){super.deserialize(t),this.index=t.index}}const bS=(...t)=>Yp(new xS(...t));lp("VertexColorNode",xS);class vS extends mx{constructor(t,e,s=null){super(t,e,s),this.renderer=s}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const TS=(t,e,s)=>Yp(new vS(t,e,s));lp("RendererReferenceNode",vS);const _S=1/6,wS=t=>ff(_S,ff(t,ff(t,t.negate().add(3)).sub(3)).add(1)),SS=t=>ff(_S,ff(t,ff(t,ff(3,t).sub(6))).add(4)),MS=t=>ff(_S,ff(t,ff(t,ff(-3,t).add(3)).add(3)).add(1)),AS=t=>ff(_S,Ey(t,3)),NS=t=>wS(t).add(SS(t)),RS=t=>MS(t).add(AS(t)),CS=t=>mf(-1,SS(t).div(wS(t).add(SS(t)))),ES=t=>mf(1,AS(t).div(MS(t).add(AS(t)))),BS=(t,e,s)=>{const i=t.uvNode,r=ff(i,e.zw).add(.5),n=Zf(r),o=ty(r),a=NS(o.x),h=RS(o.x),u=CS(o.x),l=ES(o.x),c=CS(o.y),d=ES(o.y),p=lm(n.x.add(u),n.y.add(c)).sub(.5).mul(e.xy),m=lm(n.x.add(l),n.y.add(c)).sub(.5).mul(e.xy),g=lm(n.x.add(u),n.y.add(d)).sub(.5).mul(e.xy),f=lm(n.x.add(l),n.y.add(d)).sub(.5).mul(e.xy),y=NS(o.y).mul(mf(a.mul(t.uv(p).level(s)),h.mul(t.uv(m).level(s)))),x=RS(o.y).mul(mf(a.mul(t.uv(g).level(s)),h.mul(t.uv(f).level(s))));return y.add(x)};class IS extends dp{constructor(t,e=om(3)){super("vec4"),this.textureNode=t,this.blurNode=e}setup(){return((t,e)=>{const s=lm(t.size(am(e))),i=lm(t.size(am(e.add(1)))),r=yf(1,s),n=yf(1,i),o=BS(t,xm(r,s),Zf(e)),a=BS(t,xm(n,i),Qf(e));return ty(e).mix(o,a)})(this.textureNode,this.blurNode)}}const PS=Qp(IS);wp("bicubic",PS),lp("TextureBicubicNode",IS);class FS extends up{constructor(){super("vec2"),this.isPointUVNode=!0}generate(){return"vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y )"}}const US=Kp(FS);lp("PointUVNode",FS);class zS extends up{constructor(t=zS.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,s=null!==this.scene?this.scene:t.scene;let i;return e===zS.BACKGROUND_BLURRINESS?i=gx("backgroundBlurriness","float",s):e===zS.BACKGROUND_INTENSITY?i=gx("backgroundIntensity","float",s):console.error("THREE.SceneNode: Unknown scope:",e),i}}zS.BACKGROUND_BLURRINESS="backgroundBlurriness",zS.BACKGROUND_INTENSITY="backgroundIntensity";const OS=Kp(zS,zS.BACKGROUND_BLURRINESS),LS=Kp(zS,zS.BACKGROUND_INTENSITY);lp("SceneNode",zS);const VS="point-list",DS="line-list",kS="line-strip",GS="triangle-list",WS="triangle-strip",jS="never",HS="less",qS="equal",$S="less-equal",XS="greater",YS="not-equal",JS="greater-equal",ZS="always",QS="store",KS="load",tM="clear",eM="ccw",sM="none",iM="front",rM="back",nM="uint16",oM="uint32",aM={R8Unorm:"r8unorm",R8Snorm:"r8snorm",R8Uint:"r8uint",R8Sint:"r8sint",R16Uint:"r16uint",R16Sint:"r16sint",R16Float:"r16float",RG8Unorm:"rg8unorm",RG8Snorm:"rg8snorm",RG8Uint:"rg8uint",RG8Sint:"rg8sint",R32Uint:"r32uint",R32Sint:"r32sint",R32Float:"r32float",RG16Uint:"rg16uint",RG16Sint:"rg16sint",RG16Float:"rg16float",RGBA8Unorm:"rgba8unorm",RGBA8UnormSRGB:"rgba8unorm-srgb",RGBA8Snorm:"rgba8snorm",RGBA8Uint:"rgba8uint",RGBA8Sint:"rgba8sint",BGRA8Unorm:"bgra8unorm",BGRA8UnormSRGB:"bgra8unorm-srgb",RGB9E5UFloat:"rgb9e5ufloat",RGB10A2Unorm:"rgb10a2unorm",RG11B10uFloat:"rgb10a2unorm",RG32Uint:"rg32uint",RG32Sint:"rg32sint",RG32Float:"rg32float",RGBA16Uint:"rgba16uint",RGBA16Sint:"rgba16sint",RGBA16Float:"rgba16float",RGBA32Uint:"rgba32uint",RGBA32Sint:"rgba32sint",RGBA32Float:"rgba32float",Stencil8:"stencil8",Depth16Unorm:"depth16unorm",Depth24Plus:"depth24plus",Depth24PlusStencil8:"depth24plus-stencil8",Depth32Float:"depth32float",Depth32FloatStencil8:"depth32float-stencil8",BC1RGBAUnorm:"bc1-rgba-unorm",BC1RGBAUnormSRGB:"bc1-rgba-unorm-srgb",BC2RGBAUnorm:"bc2-rgba-unorm",BC2RGBAUnormSRGB:"bc2-rgba-unorm-srgb",BC3RGBAUnorm:"bc3-rgba-unorm",BC3RGBAUnormSRGB:"bc3-rgba-unorm-srgb",BC4RUnorm:"bc4-r-unorm",BC4RSnorm:"bc4-r-snorm",BC5RGUnorm:"bc5-rg-unorm",BC5RGSnorm:"bc5-rg-snorm",BC6HRGBUFloat:"bc6h-rgb-ufloat",BC6HRGBFloat:"bc6h-rgb-float",BC7RGBAUnorm:"bc7-rgba-unorm",BC7RGBAUnormSRGB:"bc7-rgba-srgb",ETC2RGB8Unorm:"etc2-rgb8unorm",ETC2RGB8UnormSRGB:"etc2-rgb8unorm-srgb",ETC2RGB8A1Unorm:"etc2-rgb8a1unorm",ETC2RGB8A1UnormSRGB:"etc2-rgb8a1unorm-srgb",ETC2RGBA8Unorm:"etc2-rgba8unorm",ETC2RGBA8UnormSRGB:"etc2-rgba8unorm-srgb",EACR11Unorm:"eac-r11unorm",EACR11Snorm:"eac-r11snorm",EACRG11Unorm:"eac-rg11unorm",EACRG11Snorm:"eac-rg11snorm",ASTC4x4Unorm:"astc-4x4-unorm",ASTC4x4UnormSRGB:"astc-4x4-unorm-srgb",ASTC5x4Unorm:"astc-5x4-unorm",ASTC5x4UnormSRGB:"astc-5x4-unorm-srgb",ASTC5x5Unorm:"astc-5x5-unorm",ASTC5x5UnormSRGB:"astc-5x5-unorm-srgb",ASTC6x5Unorm:"astc-6x5-unorm",ASTC6x5UnormSRGB:"astc-6x5-unorm-srgb",ASTC6x6Unorm:"astc-6x6-unorm",ASTC6x6UnormSRGB:"astc-6x6-unorm-srgb",ASTC8x5Unorm:"astc-8x5-unorm",ASTC8x5UnormSRGB:"astc-8x5-unorm-srgb",ASTC8x6Unorm:"astc-8x6-unorm",ASTC8x6UnormSRGB:"astc-8x6-unorm-srgb",ASTC8x8Unorm:"astc-8x8-unorm",ASTC8x8UnormSRGB:"astc-8x8-unorm-srgb",ASTC10x5Unorm:"astc-10x5-unorm",ASTC10x5UnormSRGB:"astc-10x5-unorm-srgb",ASTC10x6Unorm:"astc-10x6-unorm",ASTC10x6UnormSRGB:"astc-10x6-unorm-srgb",ASTC10x8Unorm:"astc-10x8-unorm",ASTC10x8UnormSRGB:"astc-10x8-unorm-srgb",ASTC10x10Unorm:"astc-10x10-unorm",ASTC10x10UnormSRGB:"astc-10x10-unorm-srgb",ASTC12x10Unorm:"astc-12x10-unorm",ASTC12x10UnormSRGB:"astc-12x10-unorm-srgb",ASTC12x12Unorm:"astc-12x12-unorm",ASTC12x12UnormSRGB:"astc-12x12-unorm-srgb"},hM="clamp-to-edge",uM="repeat",lM="mirror-repeat",cM="linear",dM="nearest",pM="zero",mM="one",gM="src",fM="one-minus-src",yM="src-alpha",xM="one-minus-src-alpha",bM="dst",vM="one-minus-dst",TM="dst-alpha",_M="one-minus-dst-alpha",wM="src-alpha-saturated",SM="constant",MM="one-minus-constant",AM="add",NM="subtract",RM="reverse-subtract",CM="min",EM="max",BM=0,IM=15,PM="keep",FM="zero",UM="replace",zM="invert",OM="increment-clamp",LM="decrement-clamp",VM="increment-wrap",DM="decrement-wrap",kM="storage",GM="read-only-storage",WM="write-only",jM="read-only",HM="unfilterable-float",qM="depth",$M="sint",XM="uint",YM="2d",JM="3d",ZM="2d",QM="2d-array",KM="cube",tA="3d",eA="all",sA="vertex",iA="instance",rA={DepthClipControl:"depth-clip-control",Depth32FloatStencil8:"depth32float-stencil8",TextureCompressionBC:"texture-compression-bc",TextureCompressionETC2:"texture-compression-etc2",TextureCompressionASTC:"texture-compression-astc",TimestampQuery:"timestamp-query",IndirectFirstInstance:"indirect-first-instance",ShaderF16:"shader-f16",RG11B10UFloat:"rg11b10ufloat-renderable",BGRA8UNormStorage:"bgra8unorm-storage",Float32Filterable:"float32-filterable",ClipDistances:"clip-distances",DualSourceBlending:"dual-source-blending"};class nA extends hx{constructor(t,e,s=0){super(t,e,s),this.isStorageBufferNode=!0,this.access=kM,this.bufferObject=!1,this.bufferCount=s,this._attribute=null,this._varying=null,this.global=!0,!0!==t.isStorageBufferAttribute&&!0!==t.isStorageInstancedBufferAttribute&&(t.isInstancedBufferAttribute?t.isStorageInstancedBufferAttribute=!0:t.isStorageBufferAttribute=!0)}getHash(t){if(0===this.bufferCount){let e=t.globalCache.getData(this.value);return void 0===e&&(e={node:this},t.globalCache.setData(this.value,e)),e.node.uuid}return this.uuid}getInputType(){return"storageBuffer"}element(t){return Fw(this,t)}setBufferObject(t){return this.bufferObject=t,this}setAccess(t){return this.access=t,this}toReadOnly(){return this.setAccess(GM)}generate(t){if(t.isAvailable("storageBuffer"))return super.generate(t);const e=this.getNodeType(t);null===this._attribute&&(this._attribute=Yb(this.value),this._varying=Gm(this._attribute));const s=this._varying.build(t,e);return t.registerTransform(s,this._attribute),s}}const oA=(t,e,s)=>Yp(new nA(t,e,s)),aA=(t,e,s)=>Yp(new nA(t,e,s).setBufferObject(!0));lp("StorageBufferNode",nA);class hA extends rx{constructor(t,e,s=null){super(t,e),this.storeNode=s,this.isStorageTextureNode=!0,this.access=WM}getInputType(){return"storageTexture"}setup(t){super.setup(t);t.getNodeProperties(this).storeNode=this.storeNode}setAccess(t){return this.access=t,this}generate(t,e){let s;return s=null!==this.storeNode?this.generateStore(t):super.generate(t,e),s}toReadOnly(){return this.setAccess(jM)}toWriteOnly(){return this.setAccess(WM)}generateStore(t){const e=t.getNodeProperties(this),{uvNode:s,storeNode:i}=e,r=super.generate(t,"property"),n=s.build(t,"uvec2"),o=i.build(t,"vec4"),a=t.generateTextureStore(t,r,n,o);t.addLineFlowCode(a)}}const uA=Qp(hA),lA=(t,e,s)=>{const i=uA(t,e,s);return null!==s&&i.append(),i};lp("StorageTextureNode",hA);const cA=tm((({texture:t,uv:e})=>{const s=1e-4,i=mm().temp();return im(e.x.lessThan(s),(()=>{i.assign(mm(1,0,0))})).elseif(e.y.lessThan(s),(()=>{i.assign(mm(0,1,0))})).elseif(e.z.lessThan(s),(()=>{i.assign(mm(0,0,1))})).elseif(e.x.greaterThan(.9999),(()=>{i.assign(mm(-1,0,0))})).elseif(e.y.greaterThan(.9999),(()=>{i.assign(mm(0,-1,0))})).elseif(e.z.greaterThan(.9999),(()=>{i.assign(mm(0,0,-1))})).else((()=>{const s=.01,r=t.uv(e.add(mm(-.01,0,0))).r.sub(t.uv(e.add(mm(s,0,0))).r),n=t.uv(e.add(mm(0,-.01,0))).r.sub(t.uv(e.add(mm(0,s,0))).r),o=t.uv(e.add(mm(0,0,-.01))).r.sub(t.uv(e.add(mm(0,0,s))).r);i.assign(mm(r,n,o))})),i.normalize()}));class dA extends rx{constructor(t,e=null,s=null){super(t,e,s),this.isTexture3DNode=!0}getInputType(){return"texture3D"}getDefaultUV(){return mm(.5,.5,.5)}setUpdateMatrix(){}setupUV(t,e){return e}generateUV(t,e){return e.build(t,"vec3")}normal(t){return cA({texture:this,uv:t})}}const pA=Qp(dA);lp("Texture3DNode",dA);class mA extends mx{constructor(t,e,s=null){super(t,e,s),this.userData=s}update(t){this.reference=null!==this.userData?this.userData:t.object.userData,super.update(t)}}const gA=(t,e,s)=>Yp(new mA(t,e,s));lp("UserDataNode",mA);const fA=tm((({base:t,blend:e})=>{const s=s=>e[s].lessThan(zf).cond(e[s],t[s].oneMinus().div(e[s]).oneMinus().max(0));return mm(s("x"),s("y"),s("z"))})).setLayout({name:"burnColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),yA=tm((({base:t,blend:e})=>{const s=s=>e[s].equal(1).cond(e[s],t[s].div(e[s].oneMinus()).max(0));return mm(s("x"),s("y"),s("z"))})).setLayout({name:"dodgeColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),xA=tm((({base:t,blend:e})=>{const s=s=>t[s].oneMinus().mul(e[s].oneMinus()).oneMinus();return mm(s("x"),s("y"),s("z"))})).setLayout({name:"screenColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]}),bA=tm((({base:t,blend:e})=>{const s=s=>t[s].lessThan(.5).cond(t[s].mul(e[s],2),t[s].oneMinus().mul(e[s].oneMinus()).oneMinus());return mm(s("x"),s("y"),s("z"))})).setLayout({name:"overlayColor",type:"vec3",inputs:[{name:"base",type:"vec3"},{name:"blend",type:"vec3"}]});class vA extends dp{constructor(t,e,s){super(),this.blendMode=t,this.baseNode=e,this.blendNode=s}setup(){const{blendMode:t,baseNode:e,blendNode:s}=this,i={base:e,blend:s};let r=null;return t===vA.BURN?r=fA(i):t===vA.DODGE?r=yA(i):t===vA.SCREEN?r=xA(i):t===vA.OVERLAY&&(r=bA(i)),r}}vA.BURN="burn",vA.DODGE="dodge",vA.SCREEN="screen",vA.OVERLAY="overlay";const TA=Qp(vA,vA.BURN),_A=Qp(vA,vA.DODGE),wA=Qp(vA,vA.OVERLAY),SA=Qp(vA,vA.SCREEN);wp("burn",TA),wp("dodge",_A),wp("overlay",wA),wp("screen",SA),lp("BlendModeNode",vA);const MA=tm((({textureNode:t,bumpScale:e})=>{const s=e=>t.cache().context({getUV:t=>e(t.uvNode||lf()),forceUVContext:!0}),i=om(s((t=>t)));return lm(om(s((t=>t.add(t.dFdx())))).sub(i),om(s((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),AA=tm((t=>{const{surf_pos:e,surf_norm:s,dHdxy:i}=t,r=e.dFdx().normalize(),n=s,o=e.dFdy().normalize().cross(n),a=n.cross(r),h=r.dot(o).mul(xT),u=h.sign().mul(i.x.mul(o).add(i.y.mul(a)));return h.abs().mul(s).sub(u).normalize()}));class NA extends dp{constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=MA({textureNode:this.textureNode,bumpScale:t});return AA({surf_pos:jb,surf_norm:Xx,dHdxy:e})}}const RA=Qp(NA);wp("bumpMap",RA),lp("BumpMapNode",NA);const CA=tm((({color:t,adjustment:e})=>e.mix(OA(t.rgb),t.rgb))),EA=tm((({color:t,adjustment:e})=>{const s=mf(t.r,t.g,t.b).div(3),i=t.r.max(t.g.max(t.b)),r=i.sub(s).mul(e).mul(-3);return Oy(t.rgb,i,r)})),BA=tm((({color:t,adjustment:e})=>{const s=mm(.57735,.57735,.57735),i=e.cos();return mm(t.rgb.mul(i).add(s.cross(t.rgb).mul(e.sin()).add(s.mul(Ry(s,t.rgb).mul(i.oneMinus())))))}));class IA extends dp{constructor(t,e,s=om(1)){super("vec3"),this.method=t,this.colorNode=e,this.adjustmentNode=s}setup(){const{method:t,colorNode:e,adjustmentNode:s}=this,i={color:e,adjustment:s};let r=null;return t===IA.SATURATION?r=CA(i):t===IA.VIBRANCE?r=EA(i):t===IA.HUE?r=BA(i):console.error(`${this.type}: Method "${this.method}" not supported!`),r}}IA.SATURATION="saturation",IA.VIBRANCE="vibrance",IA.HUE="hue";const PA=Qp(IA,IA.SATURATION),FA=Qp(IA,IA.VIBRANCE),UA=Qp(IA,IA.HUE),zA=new Ei,OA=(t,e=mm(...di.getLuminanceCoefficients(zA)))=>Ry(t,e),LA=(t,e)=>Oy(mm(0),t,OA(t).sub(e).max(0));wp("saturation",PA),wp("vibrance",FA),wp("hue",UA),wp("threshold",LA),lp("ColorAdjustmentNode",IA);const VA=tm((t=>{const{eye_pos:e,surf_norm:s,mapN:i,uv:r}=t,n=e.dFdx(),o=e.dFdy(),a=r.dFdx(),h=r.dFdy(),u=s,l=o.cross(u),c=u.cross(n),d=l.mul(a.x).add(c.mul(h.x)),p=l.mul(a.y).add(c.mul(h.y)),m=d.dot(d).max(p.dot(p)),g=xT.mul(m.inverseSqrt());return mf(d.mul(i.x,g),p.mul(i.y,g),u.mul(i.z)).normalize()}));class DA extends dp{constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:s}=this;let i=this.node.mul(2).sub(1);null!==s&&(i=mm(i.xy.mul(s),i.z));let r=null;if(1===e)r=Dx.mul(i).normalize();else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?mS.mul(i).normalize():VA({eye_pos:jb,surf_norm:Xx,mapN:i,uv:lf()})}return r}}const kA=Qp(DA);wp("normalMap",kA),lp("NormalMapNode",DA);class GA extends dp{constructor(t,e){super(),this.sourceNode=t,this.stepsNode=e}setup(){const{sourceNode:t,stepsNode:e}=this;return t.mul(e).floor().div(e)}}const WA=Qp(GA);wp("posterize",WA),lp("PosterizeNode",GA);const jA=tm((({color:t,exposure:e})=>t.mul(e).clamp())),HA=tm((({color:t,exposure:e})=>(t=t.mul(e)).div(t.add(1)).clamp())),qA=tm((({color:t,exposure:e})=>{const s=(t=(t=t.mul(e)).sub(.004).max(0)).mul(t.mul(6.2).add(.5)),i=t.mul(t.mul(6.2).add(1.7)).add(.06);return s.div(i).pow(2.2)})),$A=tm((({color:t})=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),s=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(s)})),XA=tm((({color:t,exposure:e})=>{const s=Am(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Am(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=s.mul(t),t=$A({color:t}),(t=i.mul(t)).clamp()})),YA=Am(mm(1.6605,-.1246,-.0182),mm(-.5876,1.1329,-.1006),mm(-.0728,-.0083,1.1187)),JA=Am(mm(.6274,.0691,.0164),mm(.3293,.9195,.088),mm(.0433,.0113,.8956)),ZA=tm((([t])=>{const e=mm(t).toVar(),s=mm(e.mul(e)).toVar(),i=mm(s.mul(s)).toVar();return om(15.5).mul(i.mul(s)).sub(ff(40.14,i.mul(e))).add(ff(31.96,i).sub(ff(6.868,s.mul(e))).add(ff(.4298,s).add(ff(.1191,e).sub(.00232))))})),QA=tm((({color:t,exposure:e})=>{const s=mm(t).toVar(),i=Am(mm(.856627153315983,.137318972929847,.11189821299995),mm(.0951212405381588,.761241990602591,.0767994186031903),mm(.0482516061458583,.101439036467562,.811302368396859)),r=Am(mm(1.1271005818144368,-.1413297634984383,-.14132976349843826),mm(-.11060664309660323,1.157823702216272,-.11060664309660294),mm(-.016493938717834573,-.016493938717834257,1.2519364065950405)),n=om(-12.47393),o=om(4.026069);return s.mulAssign(e),s.assign(JA.mul(s)),s.assign(i.mul(s)),s.assign(_y(s,1e-10)),s.assign(Xf(s)),s.assign(s.sub(n).div(o.sub(n))),s.assign(Ly(s,0,1)),s.assign(ZA(s)),s.assign(r.mul(s)),s.assign(Ey(_y(mm(0),s),mm(2.2))),s.assign(YA.mul(s)),s.assign(Ly(s,0,1)),s})),KA=tm((({color:t,exposure:e})=>{const s=om(.76),i=om(.15);t=t.mul(e);const r=Ty(t.r,Ty(t.g,t.b)),n=VT(r.lessThan(.08),r.sub(ff(6.25,r.mul(r))),.04);t.subAssign(n);const o=_y(t.r,_y(t.g,t.b));im(o.lessThan(s),(()=>t));const a=gf(1,s),h=gf(1,a.mul(a).div(o.add(a.sub(s))));t.mulAssign(h.div(o));const u=gf(1,yf(1,i.mul(o.sub(h)).add(1)));return Oy(t,mm(h),u)})).setLayout({name:"NeutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tN={1:jA,2:HA,3:qA,4:XA,6:QA,7:KA};class eN extends dp{constructor(t=0,e=iN,s=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=s}getCacheKey(){let t=super.getCacheKey();return t="{toneMapping:"+this.toneMapping+",nodes:"+t+"}",t}setup(t){const e=this.colorNode||t.context.color,s=this.toneMapping;if(0===s)return e;const i={exposure:this.exposureNode,color:e},r=tN[s];let n=null;return r?n=r(i):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",s),n=e),n}}const sN=(t,e,s)=>Yp(new eN(t,Yp(e),Yp(s))),iN=TS("toneMappingExposure","float");wp("toneMapping",((t,e,s)=>sN(e,s,t))),lp("ToneMappingNode",eN);let rN=null;class nN extends tT{constructor(t=Yv,e=null){null===rN&&(rN=new Xa),super(t,e,rN)}updateReference(){return this}}const oN=Qp(nN);wp("viewportSharedTexture",oN),lp("ViewportSharedTextureNode",nN);const aN=new Ks;class hN extends rx{constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class uN extends hN{constructor(t,e){super(t,null),this.textureName=e}setup(t){return this.value=this.passNode.getTexture(this.textureName),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName)}}class lN extends dp{constructor(t,e,s,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=s,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new Ka;r.isRenderTargetTexture=!0,r.name="depth";const n=new wi(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Pt,...i});n.texture.name="output",n.depthTexture=r,this.renderTarget=n,this.updateBeforeType=Xd.FRAME,this._textures={output:n.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._cameraNear=uf(0),this._cameraFar=uf(0),this._mrt=null,this.isPassNode=!0}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}isGlobal(){return!0}getTexture(t){let e=this._textures[t];if(void 0===e){e=this.renderTarget.texture.clone(),e.isRenderTargetTexture=!0,e.name=t,this._textures[t]=e,this.renderTarget.textures.push(e)}return e}getTextureNode(t="output"){let e=this._textureNodes[t];return void 0===e&&(this._textureNodes[t]=e=Yp(new uN(this,t))),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=lT(this.getTextureNode(t),s,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(void 0===e){const s=this._cameraNear,i=this._cameraFar,r=this.getViewZNode(t);this._linearDepthNodes[t]=e=aT(r,s,i)}return e}setup({renderer:t}){return this.renderTarget.samples=void 0===this.options.samples?t.samples:this.options.samples,!0===t.backend.isWebGLBackend&&(this.renderTarget.samples=0),this.renderTarget.depthTexture.isMultisampleRenderTargetTexture=this.renderTarget.samples>1,this.scope===lN.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:s,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize(aN);this.setSize(r.width,r.height);const n=e.getRenderTarget(),o=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far,e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(s,i),e.setRenderTarget(n),e.setMRT(o)}setSize(t,e){this._width=t,this._height=e;const s=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(s,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}lN.COLOR="color",lN.DEPTH="depth";const cN=(t,e,s)=>Yp(new lN(lN.COLOR,t,e,s)),dN=(t,e)=>Yp(new hN(t,e)),pN=(t,e)=>Yp(new lN(lN.DEPTH,t,e));lp("PassNode",lN);const mN=new iS,gN=new iS;class fN extends dp{constructor(t,e=null,s=2){super("vec4"),this.textureNode=t,this.directionNode=e,this.sigma=s,this._invSize=uf(new Ks),this._passDirection=uf(new Ks),this._horizontalRT=new wi,this._horizontalRT.texture.name="GaussianBlurNode.horizontal",this._verticalRT=new wi,this._verticalRT.texture.name="GaussianBlurNode.vertical",this._textureNode=dN(this,this._verticalRT.texture),this.updateBeforeType=Xd.RENDER,this.resolution=new Ks(1,1)}setSize(t,e){t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._invSize.value.set(1/t,1/e),this._horizontalRT.setSize(t,e),this._verticalRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value,r=e.getRenderTarget(),n=e.getMRT(),o=s.value;mN.material=this._material,gN.material=this._material,this.setSize(i.image.width,i.image.height);const a=i.type;this._horizontalRT.texture.type=a,this._verticalRT.texture.type=a,e.setMRT(null),e.setRenderTarget(this._horizontalRT),this._passDirection.value.set(1,0),mN.render(e),s.value=this._horizontalRT.texture,e.setRenderTarget(this._verticalRT),this._passDirection.value.set(0,1),gN.render(e),e.setRenderTarget(r),e.setMRT(n),s.value=o}getTextureNode(){return this._textureNode}setup(t){const e=this.textureNode;if(!0!==e.isTextureNode)return console.error("GaussianBlurNode requires a TextureNode."),xm();const s=e.uvNode||lf(),i=lm(this.directionNode||1),r=t=>e.uv(t),n=tm((()=>{const t=3+2*this.sigma,e=this._getCoefficients(t),n=this._invSize,o=i.mul(this._passDirection),a=om(e[0]).toVar(),h=xm(r(s).mul(a)).toVar();for(let i=1;i<t;i++){const t=om(i),u=om(e[i]),l=lm(o.mul(n.mul(t))).toVar(),c=xm(r(s.add(l))),d=xm(r(s.sub(l)));h.addAssign(c.add(d).mul(u)),a.addAssign(ff(2,u))}return h.div(a)})),o=this._material||(this._material=t.createNodeMaterial());o.fragmentNode=n().context(t.getSharedContext()),o.needsUpdate=!0;return t.getNodeProperties(this).textureNode=e,this._textureNode}dispose(){this._horizontalRT.dispose(),this._verticalRT.dispose()}_getCoefficients(t){const e=[];for(let s=0;s<t;s++)e.push(.39894*Math.exp(-.5*s*s/(t*t))/t);return e}}const yN=(t,e,s)=>Yp(new fN(Yp(t).toTexture(),e,s));wp("gaussianBlur",yN);const xN=new Ks,bN=new iS;class vN extends dp{constructor(t,e=.96){super(t),this.textureNode=t,this.textureNodeOld=nx(),this.damp=uf(e),this._compRT=new wi,this._compRT.texture.name="AfterImageNode.comp",this._oldRT=new wi,this._oldRT.texture.name="AfterImageNode.old",this._textureNode=dN(this,this._compRT.texture),this.updateBeforeType=Xd.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._compRT.setSize(t,e),this._oldRT.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value.type;this._compRT.texture.type=i,this._oldRT.texture.type=i,e.getDrawingBufferSize(xN),this.setSize(xN.x,xN.y);const r=e.getRenderTarget(),n=s.value;this.textureNodeOld.value=this._oldRT.texture,e.setRenderTarget(this._compRT),bN.render(e);const o=this._oldRT;this._oldRT=this._compRT,this._compRT=o,e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=this.textureNodeOld,i=e.uvNode||lf();s.uvNode=i;const r=tm((([t,e])=>{const s=om(e).toVar(),i=xm(t).toVar();return _y(hy(i.sub(s)),0)})),n=tm((()=>{const t=xm(s),n=xm((t=>e.uv(t))(i));return t.mulAssign(this.damp.mul(r(t,.1))),_y(n,t)})),o=this._materialComposed||(this._materialComposed=t.createNodeMaterial());o.fragmentNode=n(),bN.material=o;return t.getNodeProperties(this).textureNode=e,this._textureNode}dispose(){this._compRT.dispose(),this._oldRT.dispose()}}const TN=(t,e)=>Yp(new vN(Yp(t).toTexture(),e));wp("afterImage",TN);const _N=new iS;class wN extends dp{constructor(t,e,s,i){super("vec4"),this.textureNode=t,this.tresholdNode=e,this.scaleNode=s,this.colorNode=mm(.1,0,1),this.samples=i,this.resolution=new Ks(1,1),this._renderTarget=new wi,this._renderTarget.texture.name="anamorphic",this._invSize=uf(new Ks),this._textureNode=dN(this,this._renderTarget.texture),this.updateBeforeType=Xd.RENDER}getTextureNode(){return this._textureNode}setSize(t,e){this._invSize.value.set(1/t,1/e),t=Math.max(Math.round(t*this.resolution.x),1),e=Math.max(Math.round(e*this.resolution.y),1),this._renderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=this.textureNode,i=s.value;this._renderTarget.texture.type=i.type;const r=e.getRenderTarget(),n=s.value;_N.material=this._material,this.setSize(i.image.width,i.image.height),e.setRenderTarget(this._renderTarget),_N.render(e),e.setRenderTarget(r),s.value=n}setup(t){const e=this.textureNode,s=e.uvNode||lf(),i=tm((()=>{const t=this.samples,i=Math.floor(t/2),r=mm(0).toVar();return pv({start:-i,end:i},(({i:t})=>{const n=om(t).abs().div(i).oneMinus(),o=(t=>e.uv(t))(lm(s.x.add(this._invSize.x.mul(t).mul(this.scaleNode)),s.y)),a=LA(o,this.tresholdNode).mul(n);r.addAssign(a)})),r.mul(this.colorNode)}));(this._material||(this._material=t.createNodeMaterial())).fragmentNode=i();return t.getNodeProperties(this).textureNode=e,this._textureNode}dispose(){this._renderTarget.dispose()}}const SN=(t,e=.9,s=3,i=32)=>Yp(new wN(Yp(t).toTexture(),Yp(e),Yp(s),i));wp("anamorphic",SN);class MN extends dp{constructor(t){super(),this.textureNode=t,this.updateBeforeType=Xd.RENDER,this._invSize=uf(new Ks)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const{textureNode:t}=this,e=t.uvNode||lf(),s=e=>t.uv(e);return tm((()=>{const t=this._invSize,i=Am(-1,-2,-1,0,0,0,1,2,1),r=Am(-1,0,1,-2,0,2,-1,0,1),n=OA(s(e.add(t.mul(lm(-1,-1)))).xyz),o=OA(s(e.add(t.mul(lm(-1,0)))).xyz),a=OA(s(e.add(t.mul(lm(-1,1)))).xyz),h=OA(s(e.add(t.mul(lm(0,-1)))).xyz),u=OA(s(e.add(t.mul(lm(0,0)))).xyz),l=OA(s(e.add(t.mul(lm(0,1)))).xyz),c=OA(s(e.add(t.mul(lm(1,-1)))).xyz),d=OA(s(e.add(t.mul(lm(1,0)))).xyz),p=OA(s(e.add(t.mul(lm(1,1)))).xyz),m=mf(i[0][0].mul(n),i[1][0].mul(h),i[2][0].mul(c),i[0][1].mul(o),i[1][1].mul(u),i[2][1].mul(d),i[0][2].mul(a),i[1][2].mul(l),i[2][2].mul(p)),g=mf(r[0][0].mul(n),r[1][0].mul(h),r[2][0].mul(c),r[0][1].mul(o),r[1][1].mul(u),r[2][1].mul(d),r[0][2].mul(a),r[1][2].mul(l),r[2][2].mul(p)),f=m.mul(m).add(g.mul(g)).sqrt();return xm(mm(f),1)}))()}}const AN=t=>Yp(new MN(Yp(t).toTexture()));wp("sobel",AN);class NN extends dp{constructor(t,e,s,i,r){super(),this.textureNode=t,this.viewZNode=e,this.focusNode=s,this.apertureNode=i,this.maxblurNode=r,this._aspect=uf(0),this.updateBeforeType=Xd.RENDER}updateBefore(){const t=this.textureNode.value;this._aspect.value=t.image.width/t.image.height}setup(){const t=this.textureNode,e=t.uvNode||lf(),s=e=>t.uv(e);return tm((()=>{const t=lm(1,this._aspect),i=this.focusNode.add(this.viewZNode),r=lm(Ly(i.mul(this.apertureNode),this.maxblurNode.negate(),this.maxblurNode)),n=r.mul(.9),o=r.mul(.7),a=r.mul(.4);let h=xm(0);return h=h.add(s(e)),h=h.add(s(e.add(lm(0,.4).mul(t).mul(r)))),h=h.add(s(e.add(lm(.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(lm(.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(lm(.4,0).mul(t).mul(r)))),h=h.add(s(e.add(lm(.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(lm(.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(lm(0,-.4).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.15,.37).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.29,.29).mul(t).mul(r)))),h=h.add(s(e.add(lm(.37,.15).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.4,0).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.37,-.15).mul(t).mul(r)))),h=h.add(s(e.add(lm(-.29,-.29).mul(t).mul(r)))),h=h.add(s(e.add(lm(.15,-.37).mul(t).mul(r)))),h=h.add(s(e.add(lm(.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(lm(-.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(lm(.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(lm(-.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(lm(-.15,.37).mul(t).mul(n)))),h=h.add(s(e.add(lm(.37,.15).mul(t).mul(n)))),h=h.add(s(e.add(lm(-.37,-.15).mul(t).mul(n)))),h=h.add(s(e.add(lm(.15,-.37).mul(t).mul(n)))),h=h.add(s(e.add(lm(.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(lm(.4,0).mul(t).mul(o)))),h=h.add(s(e.add(lm(.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(lm(0,-.4).mul(t).mul(o)))),h=h.add(s(e.add(lm(-.29,.29).mul(t).mul(o)))),h=h.add(s(e.add(lm(-.4,0).mul(t).mul(o)))),h=h.add(s(e.add(lm(-.29,-.29).mul(t).mul(o)))),h=h.add(s(e.add(lm(0,.4).mul(t).mul(o)))),h=h.add(s(e.add(lm(.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(lm(.4,0).mul(t).mul(a)))),h=h.add(s(e.add(lm(.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(lm(0,-.4).mul(t).mul(a)))),h=h.add(s(e.add(lm(-.29,.29).mul(t).mul(a)))),h=h.add(s(e.add(lm(-.4,0).mul(t).mul(a)))),h=h.add(s(e.add(lm(-.29,-.29).mul(t).mul(a)))),h=h.add(s(e.add(lm(0,.4).mul(t).mul(a)))),h=h.div(41),h.a=1,xm(h)}))()}}const RN=(t,e,s=1,i=.025,r=1)=>Yp(new NN(Yp(t).toTexture(),Yp(e),Yp(s),Yp(i),Yp(r)));wp("dof",RN);class CN extends dp{constructor(t,e=new Ks(.5,.5),s=1.57,i=1){super("vec4"),this.inputNode=t,this.center=uf(e),this.angle=uf(s),this.scale=uf(i),this._size=uf(new Ks),this.updateBeforeType=Xd.RENDER}updateBefore(t){const{renderer:e}=t;e.getDrawingBufferSize(this._size.value)}setup(){const t=this.inputNode,e=tm((()=>{const t=ey(this.angle),e=sy(this.angle),s=lf().mul(this._size).sub(this.center),i=lm(e.mul(s.x).sub(t.mul(s.y)),t.mul(s.x).add(e.mul(s.y))).mul(this.scale);return ey(i.x).mul(ey(i.y)).mul(4)})),s=tm((()=>{const s=t,i=mf(s.r,s.g,s.b).div(3);return xm(mm(i.mul(10).sub(5).add(e())),s.a)}));return s()}}const EN=(t,e,s,i)=>Yp(new CN(Yp(t),e,s,i));wp("dotScreen",EN);class BN extends dp{constructor(t,e=.005,s=0){super("vec4"),this.textureNode=t,this.amount=uf(e),this.angle=uf(s)}setup(){const{textureNode:t}=this,e=t.uvNode||lf(),s=e=>t.uv(e);return tm((()=>{const t=lm(sy(this.angle),ey(this.angle)).mul(this.amount),i=s(e.add(t)),r=s(e),n=s(e.sub(t));return xm(i.r,r.g,n.b,r.a)}))()}}const IN=(t,e,s)=>Yp(new BN(Yp(t).toTexture(),e,s));wp("rgbShift",IN);class PN extends dp{constructor(t,e=null,s=null){super(),this.inputNode=t,this.intensityNode=e,this.uvNode=s}setup(){const t=this.uvNode||lf(),e=tm((()=>{const e=this.inputNode.rgb,s=Wy(ty(t.add(dw())));let i=e.add(e.mul(Ly(s.add(.1),0,1)));return null!==this.intensityNode&&(i=Oy(e,i,this.intensityNode)),xm(i,this.inputNode.a)}));return e()}}const FN=Qp(PN);wp("film",FN);class UN extends dp{constructor(t,e,s,i){super(),this.inputNode=t,this.lutNode=e,this.size=uf(s),this.intensityNode=i}setup(){const{inputNode:t,lutNode:e}=this,s=tm((()=>{const s=t,i=om(1).div(this.size),r=om(.5).div(this.size),n=mm(r).add(s.rgb.mul(om(1).sub(i))),o=xm((t=>e.uv(t))(n).rgb,s.a);return xm(Oy(s,o,this.intensityNode))}));return s()}}const zN=(t,e,s,i)=>Yp(new UN(Yp(t),Yp(e),s,Yp(i)));wp("lut3D",zN);const ON=new iS,LN=new Yr,VN=new Ks;class DN extends dp{constructor(t,e,s){super(),this.depthNode=t,this.normalNode=e,this.radius=uf(.25),this.resolution=uf(new Ks),this.thickness=uf(1),this.distanceExponent=uf(1),this.distanceFallOff=uf(1),this.scale=uf(1),this.noiseNode=nx(function(t=5){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),s=function(t){const e=Math.floor(t)%2==0?Math.floor(t)+1:Math.floor(t),s=e*e,i=Array(s).fill(0);let r=Math.floor(e/2),n=e-1;for(let t=1;t<=s;)-1===r&&n===e?(n=e-2,r=0):(n===e&&(n=0),r<0&&(r=e-1)),0===i[r*e+n]?(i[r*e+n]=t++,n++,r--):(n-=2,r++);return i}(e),i=s.length,r=new Uint8Array(4*i);for(let t=0;t<i;++t){const e=s[t],n=2*Math.PI*e/i,o=new Ei(Math.cos(n),Math.sin(n),0).normalize();r[4*t]=255*(.5*o.x+.5),r[4*t+1]=255*(.5*o.y+.5),r[4*t+2]=127,r[4*t+3]=255}const n=new Do(r,e,e);return n.wrapS=pt,n.wrapT=pt,n.needsUpdate=!0,n}()),this.cameraProjectionMatrix=uf(s.projectionMatrix),this.cameraProjectionMatrixInverse=uf(s.projectionMatrixInverse),this.SAMPLES=uf(16),this._aoRenderTarget=new wi,this._aoRenderTarget.texture.name="GTAONode.AO",this._material=null,this._textureNode=dN(this,this._aoRenderTarget.texture),this.updateBeforeType=Xd.FRAME}getTextureNode(){return this._textureNode}setSize(t,e){this.resolution.value.set(t,e),this._aoRenderTarget.setSize(t,e)}updateBefore(t){const{renderer:e}=t,s=e.getDrawingBufferSize(VN),i=e.getRenderTarget(),r=e.getMRT();e.getClearColor(LN);const n=e.getClearAlpha();ON.material=this._material,this.setSize(s.width,s.height),e.setMRT(null),e.setClearColor(16777215,1),e.setRenderTarget(this._aoRenderTarget),ON.render(e),e.setRenderTarget(i),e.setMRT(r),e.setClearColor(LN,n)}setup(t){const e=lf(),s=t=>this.depthNode.uv(t).x,i=t=>this.noiseNode.uv(t),r=tm((([t])=>{const e=this.cameraProjectionMatrix.mul(xm(t,1));let i=e.xy.div(e.w).mul(.5).add(.5).toVar();i=lm(i.x,i.y.oneMinus());const r=s(i);return mm(i,r)})),n=tm((([t,e])=>{t=lm(t.x,t.y.oneMinus()).mul(2).sub(1);const s=xm(mm(t,e),1),i=xm(this.cameraProjectionMatrixInverse.mul(s));return i.xyz.div(i.w)})),o=tm((()=>{const t=s(e);t.greaterThanEqual(1).discard();const o=n(e,t),a=this.normalNode.rgb.normalize(),h=this.radius,u=df(this.noiseNode,0);let l=lm(e.x,e.y.oneMinus());l=l.mul(this.resolution.div(u));const c=i(l),d=c.xyz.mul(2).sub(1),p=mm(d.xy,0).normalize(),m=mm(p.y.mul(-1),p.x,0),g=Am(p,m,mm(0,0,1)),f=this.SAMPLES.lessThan(30).cond(3,5),y=mf(this.SAMPLES,f.sub(1)).div(f),x=om(0).toVar();return pv({start:am(0),end:f,type:"int",condition:"<"},(({i:t})=>{const e=om(t).div(om(f)).mul(Lf),s=xm(sy(e),ey(e),0,mf(.5,ff(.5,c.w)));s.xyz=Kf(g.mul(s.xyz));const i=Kf(o.xyz.negate()),u=Kf(Cy(s.xyz,i)),l=Cy(u,i),d=Kf(a.sub(u.mul(Ry(a,u)))),p=Cy(d,u),m=lm(Ry(i,p),Ry(i,p.negate())).toVar();pv({end:y,type:"int",name:"j",condition:"<"},(({j:t})=>{const e=s.xyz.mul(h).mul(s.w).mul(Ey(yf(om(t).add(1),om(y)),this.distanceExponent)),a=r(o.add(e)),u=n(a.xy,a.z).sub(o);im(ay(u.z).lessThan(this.thickness),(()=>{const e=Ry(i,Kf(u));m.x.addAssign(_y(0,ff(e.sub(m.x),Oy(1,om(2).div(om(t).add(2)),this.distanceFallOff))))}));const l=r(o.sub(e)),c=n(l.xy,l.z).sub(o);im(ay(c.z).lessThan(this.thickness),(()=>{const e=Ry(i,Kf(c));m.y.addAssign(_y(0,ff(e.sub(m.y),Oy(1,om(2).div(om(t).add(2)),this.distanceFallOff))))}))}));const b=Yf(gf(1,m.mul(m))),v=Ry(d,l),T=Ry(d,i),_=ff(.5,ny(m.y).sub(ny(m.x)).add(b.x.mul(m.x).sub(b.y.mul(m.y)))),w=ff(.5,gf(2,m.x.mul(m.x)).sub(m.y.mul(m.y))),S=v.mul(_).add(T.mul(w));x.addAssign(S)})),x.assign(Ly(x.div(f),0,1)),x.assign(Ey(x,this.scale)),xm(mm(x),1)})),a=this._material||(this._material=t.createNodeMaterial());return a.fragmentNode=o().context(t.getSharedContext()),a.needsUpdate=!0,this._textureNode}dispose(){this._aoRenderTarget.dispose()}}const kN=(t,e,s)=>Yp(new DN(Yp(t),Yp(e),s));wp("ao",kN);class GN extends dp{constructor(t,e,s,i,r){super(),this.textureNode=t,this.depthNode=e,this.normalNode=s,this.noiseNode=i,this.cameraProjectionMatrixInverse=uf(r.projectionMatrixInverse),this.lumaPhi=uf(5),this.depthPhi=uf(5),this.normalPhi=uf(5),this.radius=uf(5),this.index=uf(0),this._resolution=uf(new Ks),this._sampleVectors=dx(function(t,e,s){const i=function(t,e,s){const i=[];for(let r=0;r<t;r++){const n=2*Math.PI*e*r/t,o=Math.pow(r/(t-1),s);i.push(new Ei(Math.cos(n),Math.sin(n),o))}return i}(t,e,s),r=[];for(let e=0;e<t;e++){const t=i[e];r.push(t)}return r}(16,2,1)),this.updateBeforeType=Xd.RENDER}updateBefore(){const t=this.textureNode.value;this._resolution.value.set(t.image.width,t.image.height)}setup(){const t=lf(),e=t=>this.textureNode.uv(t),s=t=>this.depthNode.uv(t).x,i=t=>this.normalNode.uv(t),r=t=>this.noiseNode.uv(t),n=tm((([t,e])=>{t=lm(t.x,t.y.oneMinus()).mul(2).sub(1);const s=xm(mm(t,e),1),i=xm(this.cameraProjectionMatrixInverse.mul(s));return i.xyz.div(i.w)})),o=tm((([t,r,o,a])=>{const h=e(a),u=s(a),l=i(a).rgb.normalize(),c=h.rgb,d=n(a,u),p=Ry(r,l).toVar(),m=Ey(_y(p,0),this.normalPhi).toVar(),g=ay(OA(c).sub(OA(t))).toVar(),f=_y(om(1).sub(g.div(this.lumaPhi)),0).toVar(),y=ay(Ry(o.sub(d),r)).toVar(),x=_y(om(1).sub(y.div(this.depthPhi)),0),b=f.mul(x).mul(m);return xm(c.mul(b),b)})),a=tm((([t])=>{const a=s(t),h=i(t).rgb.normalize(),u=e(t);im(a.greaterThanEqual(1).or(Ry(h,h).equal(0)),(()=>u));const l=mm(u.rgb),c=n(t,a),d=df(this.noiseNode,0);let p=lm(t.x,t.y.oneMinus());p=p.mul(this._resolution.div(d));const m=r(p),g=ey(m.element(this.index.mod(4).mul(2).mul(Lf))),f=sy(m.element(this.index.mod(4).mul(2).mul(Lf))),y=lm(g,f),x=_m(y.x,y.y.negate(),y.x,y.y),b=om(1).toVar(),v=mm(u.rgb).toVar();return pv({start:am(0),end:am(16),type:"int",condition:"<"},(({i:e})=>{const s=this._sampleVectors.element(e).toVar(),i=x.mul(s.xy.mul(om(1).add(s.z.mul(this.radius.sub(1))))).div(this._resolution).toVar(),r=t.add(i).toVar(),n=o(l,h,c,r);v.addAssign(n.xyz),b.addAssign(n.w)})),im(b.greaterThan(om(0)),(()=>{v.divAssign(b)})),xm(v,u.a)})).setLayout({name:"denoise",type:"vec4",inputs:[{name:"uv",type:"vec2"}]});return tm((()=>a(t)))()}}const WN=(t,e,s,i,r)=>Yp(new GN(Yp(t).toTexture(),Yp(e),Yp(s),Yp(i),r));wp("denoise",WN);class jN extends dp{constructor(t){super(),this.textureNode=t,this.updateBeforeType=Xd.RENDER,this._invSize=uf(new Ks)}updateBefore(){const t=this.textureNode.value;this._invSize.value.set(1/t.image.width,1/t.image.height)}setup(){const t=this.textureNode.bias(-100),e=t.uvNode||lf(),s=e=>t.uv(e),i=(e,s,i)=>t.uv(e.add(s.mul(i))),r=am(5),n=tm((([t,e])=>{const s=xm(e).toVar(),i=xm(t).toVar(),r=xm(ay(i.sub(s))).toVar();return _y(_y(_y(r.r,r.g),r.b),r.a)})),o=tm((([t,e,o,a])=>{const h=s(t).toVar(),u=i(t,lm(0,-1),e.xy).toVar(),l=i(t,lm(1,0),e.xy).toVar(),c=i(t,lm(0,1),e.xy).toVar(),d=i(t,lm(-1,0),e.xy).toVar(),p=n(h,c).toVar(),m=n(h,u).toVar(),g=n(h,l).toVar(),f=n(h,d).toVar(),y=_y(p,_y(m,_y(g,f))).toVar();im(y.lessThan(o),(()=>h));const x=gf(p.add(m),g.add(f)).toVar();x.mulAssign(a),im(ay(x).lessThan(.3),(()=>{const s=g.greaterThan(f).cond(1,-1).toVar(),r=m.greaterThan(p).cond(1,-1).toVar(),o=lm(s,r).toVar(),y=i(t,lm(o.x,o.y),e.xy),b=n(h,y).toVar(),v=i(t,lm(o.x.negate(),o.y.negate()),e.xy),T=n(h,v).toVar();x.assign(T.sub(b)),x.mulAssign(a),im(ay(x).lessThan(.3),(()=>{const t=c.add(u).add(l).add(d);return Oy(h,t.mul(.25),.4)}))}));const b=lm().toVar();im(x.lessThanEqual(0),(()=>{c.assign(d),u.assign(l),b.x.assign(0),b.y.assign(e.y)})).else((()=>{b.x.assign(e.x),b.y.assign(0)}));const v=n(h,c).toVar(),T=n(h,u).toVar();im(v.lessThanEqual(T),(()=>{c.assign(u)}));const _=am(0).toVar(),w=am(0).toVar(),S=om(0).toVar(),M=om(0).toVar(),A=lm(t).toVar(),N=lm(t).toVar(),R=am(0).toVar(),C=am(0).toVar();pv(r,(({i:e})=>{const i=e.add(1).toVar();im(_.equal(0),(()=>{S.addAssign(i),A.assign(t.add(b.mul(S)));const r=s(A.xy),o=n(r,h).toVar(),a=n(r,c).toVar();im(o.greaterThan(a),(()=>{_.assign(1)})),R.assign(e)})),im(w.equal(0),(()=>{M.addAssign(i),N.assign(t.sub(b.mul(M)));const r=s(N.xy),o=n(r,h).toVar(),a=n(r,c).toVar();im(o.greaterThan(a),(()=>{w.assign(1)})),C.assign(e)})),im(_.equal(1).or(w.equal(1)),(()=>{gv()}))})),im(_.equal(0).and(w.equal(0)),(()=>h));const E=om(1).toVar(),B=om(1).toVar();im(_.equal(1),(()=>{E.assign(om(R).div(om(r.sub(1))))})),im(w.equal(1),(()=>{B.assign(om(C).div(om(r.sub(1))))}));const I=Ty(E,B);return I.assign(Ey(I,.5)),I.assign(om(1).sub(I)),Oy(h,c,I.mul(.5))})).setLayout({name:"FxaaPixelShader",type:"vec4",inputs:[{name:"uv",type:"vec2"},{name:"fxaaQualityRcpFrame",type:"vec2"},{name:"fxaaQualityEdgeThreshold",type:"float"},{name:"fxaaQualityinvEdgeThreshold",type:"float"}]});return tm((()=>{const t=om(.2),s=om(1).div(t);return o(e,this._invSize,t,s)}))()}}const HN=t=>Yp(new jN(Yp(t).toTexture()));wp("fxaa",HN);const qN=new iS,$N=new Yr(0,0,0),XN=new Yr,YN=new Ks,JN=new Ks(1,0),ZN=new Ks(0,1);class QN extends dp{constructor(t,e=1,s=0,i=0){super(),this.inputNode=t,this.strength=uf(e),this.radius=uf(s),this.threshold=uf(i),this.smoothWidth=uf(.01),this._renderTargetsHorizontal=[],this._renderTargetsVertical=[],this._nMips=5,this._renderTargetBright=new wi(1,1,{type:Pt}),this._renderTargetBright.texture.name="UnrealBloomPass.bright",this._renderTargetBright.texture.generateMipmaps=!1;for(let t=0;t<this._nMips;t++){const e=new wi(1,1,{type:Pt});e.texture.name="UnrealBloomPass.h"+t,e.texture.generateMipmaps=!1,this._renderTargetsHorizontal.push(e);const s=new wi(1,1,{type:Pt});s.texture.name="UnrealBloomPass.v"+t,s.texture.generateMipmaps=!1,this._renderTargetsVertical.push(s)}this._compositeMaterial=null,this._highPassFilterMaterial=null,this._separableBlurMaterials=[],this._textureNodeBright=nx(this._renderTargetBright.texture),this._textureNodeBlur0=nx(this._renderTargetsVertical[0].texture),this._textureNodeBlur1=nx(this._renderTargetsVertical[1].texture),this._textureNodeBlur2=nx(this._renderTargetsVertical[2].texture),this._textureNodeBlur3=nx(this._renderTargetsVertical[3].texture),this._textureNodeBlur4=nx(this._renderTargetsVertical[4].texture),this._textureOutput=dN(this,this._renderTargetsHorizontal[0].texture),this.updateBeforeType=Xd.FRAME}getTextureNode(){return this._textureOutput}setSize(t,e){let s=Math.round(t/2),i=Math.round(e/2);this._renderTargetBright.setSize(s,i);for(let t=0;t<this._nMips;t++)this._renderTargetsHorizontal[t].setSize(s,i),this._renderTargetsVertical[t].setSize(s,i),this._separableBlurMaterials[t].invSize.value.set(1/s,1/i),s=Math.round(s/2),i=Math.round(i/2)}updateBefore(t){const{renderer:e}=t,s=e.getDrawingBufferSize(YN);this.setSize(s.width,s.height);const i=e.getRenderTarget(),r=e.getMRT();e.getClearColor(XN);const n=e.getClearAlpha();this.setSize(s.width,s.height),e.setMRT(null),e.setClearColor($N,0),e.setRenderTarget(this._renderTargetBright),qN.material=this._highPassFilterMaterial,qN.render(e);let o=this._renderTargetBright;for(let t=0;t<this._nMips;t++)qN.material=this._separableBlurMaterials[t],this._separableBlurMaterials[t].colorTexture.value=o.texture,this._separableBlurMaterials[t].direction.value=JN,e.setRenderTarget(this._renderTargetsHorizontal[t]),e.clear(),qN.render(e),this._separableBlurMaterials[t].colorTexture.value=this._renderTargetsHorizontal[t].texture,this._separableBlurMaterials[t].direction.value=ZN,e.setRenderTarget(this._renderTargetsVertical[t]),e.clear(),qN.render(e),o=this._renderTargetsVertical[t];e.setRenderTarget(this._renderTargetsHorizontal[0]),e.clear(),qN.material=this._compositeMaterial,qN.render(e),e.setRenderTarget(i),e.setMRT(r),e.setClearColor(XN,n)}setup(t){const e=tm((()=>{const t=this.inputNode,e=OA(t.rgb),s=ky(this.threshold,this.threshold.add(this.smoothWidth),e);return Oy(xm(0),t,s)}));this._highPassFilterMaterial=this._highPassFilterMaterial||t.createNodeMaterial(),this._highPassFilterMaterial.fragmentNode=e().context(t.getSharedContext()),this._highPassFilterMaterial.needsUpdate=!0;const s=[3,5,7,9,11];for(let e=0;e<this._nMips;e++)this._separableBlurMaterials.push(this._getSeperableBlurMaterial(t,s[e]));const i=dx([1,.8,.6,.4,.2]),r=dx([new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1),new Ei(1,1,1)]),n=tm((([t,e])=>{const s=om(1.2).sub(t);return Oy(t,s,e)})).setLayout({name:"lerpBloomFactor",type:"float",inputs:[{name:"factor",type:"float"},{name:"radius",type:"float"}]}),o=tm((()=>{const t=n(i.element(0),this.radius).mul(xm(r.element(0),1)).mul(this._textureNodeBlur0),e=n(i.element(1),this.radius).mul(xm(r.element(1),1)).mul(this._textureNodeBlur1),s=n(i.element(2),this.radius).mul(xm(r.element(2),1)).mul(this._textureNodeBlur2),o=n(i.element(3),this.radius).mul(xm(r.element(3),1)).mul(this._textureNodeBlur3),a=n(i.element(4),this.radius).mul(xm(r.element(4),1)).mul(this._textureNodeBlur4);return t.add(e).add(s).add(o).add(a).mul(this.strength)}));return this._compositeMaterial=this._compositeMaterial||t.createNodeMaterial(),this._compositeMaterial.fragmentNode=o().context(t.getSharedContext()),this._compositeMaterial.needsUpdate=!0,this._textureOutput}dispose(){for(let t=0;t<this._renderTargetsHorizontal.length;t++)this._renderTargetsHorizontal[t].dispose();for(let t=0;t<this._renderTargetsVertical.length;t++)this._renderTargetsVertical[t].dispose();this._renderTargetBright.dispose()}_getSeperableBlurMaterial(t,e){const s=[];for(let t=0;t<e;t++)s.push(.39894*Math.exp(-.5*t*t/(e*e))/e);const i=nx(),r=dx(s),n=uf(new Ks),o=uf(new Ks(.5,.5)),a=lf(),h=t=>i.uv(t),u=tm((()=>{const t=r.element(0).toVar(),s=h(a).rgb.mul(t).toVar();return pv({start:am(1),end:am(e),type:"int",condition:"<"},(({i:e})=>{const i=om(e),u=r.element(e),l=o.mul(n).mul(i),c=h(a.add(l)).rgb,d=h(a.sub(l)).rgb;s.addAssign(mf(c,d).mul(u)),t.addAssign(om(2).mul(u))})),xm(s.div(t),1)})),l=t.createNodeMaterial();return l.fragmentNode=u().context(t.getSharedContext()),l.needsUpdate=!0,l.colorTexture=i,l.direction=o,l.invSize=n,l}}const KN=(t,e,s,i)=>Yp(new QN(Yp(t),e,s,i));wp("bloom",KN);class tR extends dp{constructor(t,e,s,i,r,n){super(),this.textureNodeA=t,this.textureNodeB=e,this.mixTextureNode=s,this.mixRatioNode=i,this.thresholdNode=r,this.useTextureNode=n}setup(){const{textureNodeA:t,textureNodeB:e,mixTextureNode:s,mixRatioNode:i,thresholdNode:r,useTextureNode:n}=this,o=t=>{const e=t.uvNode||lf();return t.uv(e)},a=tm((()=>{const a=o(t),h=o(e),u=xm().toVar();return im(n.equal(am(1)),(()=>{const t=o(s),e=i.mul(r.mul(2).add(1)).sub(r),n=Ly(gf(t.r,e).mul(om(1).div(r)),0,1);u.assign(Oy(a,h,n))})).else((()=>{u.assign(Oy(h,a,i))})),u}));return a()}}const eR=(t,e,s,i=0,r=.1,n=0)=>Yp(new tR(Yp(t).toTexture(),Yp(e).toTexture(),Yp(s).toTexture(),Yp(i),Yp(r),Yp(n)));wp("transition",eR);class sR extends dp{constructor(t,e,s){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=s,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const s=null!==this.toneMapping?this.toneMapping:t.toneMapping,i=null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace;return 0!==s&&(e=e.toneMapping(s)),i===Je&&(e=e.linearToColorSpace(i)),e}}const iR=(t,e=null,s=null)=>Yp(new sR(Yp(t),e,s));wp("renderOutput",iR),lp("RenderOutputNode",sR);class rR extends dp{constructor(t,e,s,i,r,n){super(),this.textureNode=t,this.depthNode=e,this.normalNode=s,this.pixelSize=i,this.normalEdgeStrength=r,this.depthEdgeStrength=n,this._resolution=uf(new _i),this.updateBeforeType=Xd.RENDER}updateBefore(){const t=this.textureNode.value,e=t.image.width,s=t.image.height;this._resolution.value.set(e,s,1/e,1/s)}setup(){const{textureNode:t,depthNode:e,normalNode:s}=this,i=t.uvNode||lf(),r=e.uvNode||lf(),n=s.uvNode||lf(),o=(t,s)=>e.uv(r.add(lm(t,s).mul(this._resolution.zw))).r,a=(t,e)=>s.uv(n.add(lm(t,e).mul(this._resolution.zw))).rgb.normalize(),h=(t,e,s,i)=>{const r=o(t,e).sub(s),n=a(t,e),h=mm(1,1,1),u=Ry(i.sub(n),h),l=Ly(ky(-.01,.01,u),0,1),c=Ly(hy(r.mul(.25).add(.0025)),0,1);return om(1).sub(Ry(i,n)).mul(c).mul(l)},u=tm((()=>{const e=t.uv(i),s=mg("float","depth"),r=mg("vec3","normal");im(this.depthEdgeStrength.greaterThan(0).or(this.normalEdgeStrength.greaterThan(0)),(()=>{s.assign(o(0,0)),r.assign(a(0,0))}));const n=mg("float","dei");im(this.depthEdgeStrength.greaterThan(0),(()=>{n.assign((t=>{const e=mg("float","diff");return e.addAssign(Ly(o(1,0).sub(t))),e.addAssign(Ly(o(-1,0).sub(t))),e.addAssign(Ly(o(0,1).sub(t))),e.addAssign(Ly(o(0,-1).sub(t))),Zf(ky(.01,.02,e).mul(2)).div(2)})(s))}));const u=mg("float","nei");im(this.normalEdgeStrength.greaterThan(0),(()=>{u.assign(((t,e)=>{const s=mg("float","indicator");return s.addAssign(h(0,-1,t,e)),s.addAssign(h(0,1,t,e)),s.addAssign(h(-1,0,t,e)),s.addAssign(h(1,0,t,e)),Sy(.1,s)})(s,r))}));const l=n.greaterThan(0).cond(om(1).sub(n.mul(this.depthEdgeStrength)),u.mul(this.normalEdgeStrength).add(1));return e.mul(l)}));return u()}}const nR=(t,e,s,i=6,r=.3,n=.4)=>Yp(new rR(Yp(t).toTexture(),Yp(e).toTexture(),Yp(s).toTexture(),Yp(i),Yp(r),Yp(n)));wp("pixelation",nR);class oR extends lN{constructor(t,e,s=6,i=.3,r=.4){super("color",t,e,{minFilter:ft,magFilter:ft}),this.pixelSize=s,this.normalEdgeStrength=i,this.depthEdgeStrength=r,this.isPixelationPassNode=!0,this._mrt=H_({output:Fg,normal:Xx})}setSize(t,e){const s=this.pixelSize.value?this.pixelSize.value:this.pixelSize,i=Math.floor(t/s),r=Math.floor(e/s);super.setSize(i,r)}setup(){const t=super.getTextureNode("output"),e=super.getTextureNode("depth"),s=super.getTextureNode("normal");return nR(t,e,s,this.pixelSize,this.normalEdgeStrength,this.depthEdgeStrength)}}const aR=(t,e,s,i,r)=>Yp(new oR(t,e,s,i,r));class hR extends dp{constructor(t=null,e={}){super(),this.functionNode=t,this.parameters=e}setParameters(t){return this.parameters=t,this}getParameters(){return this.parameters}getNodeType(t){return this.functionNode.getNodeType(t)}generate(t){const e=[],s=this.functionNode,i=s.getInputs(t),r=this.parameters;if(Array.isArray(r))for(let s=0;s<r.length;s++){const n=i[s],o=r[s];e.push(o.build(t,n.type))}else for(const s of i){const i=r[s.name];if(void 0===i)throw new Error(`FunctionCallNode: Input '${s.name}' not found in FunctionNode.`);e.push(i.build(t,s.type))}return`${s.build(t,"property")}( ${e.join(", ")} )`}}const uR=(t,...e)=>(e=e.length>1||e[0]&&!0===e[0].isNode?Zp(e):Jp(e[0]),Yp(new hR(Yp(t),e)));wp("call",uR),lp("FunctionCallNode",hR);class lR extends up{constructor(t=null){super(),this._value=t,this._cache=null,this.inputType=null,this.outpuType=null,this.events=new ks,this.isScriptableValueNode=!0}get isScriptableOutputNode(){return null!==this.outputType}set value(t){this._value!==t&&(this._cache&&"URL"===this.inputType&&this.value.value instanceof ArrayBuffer&&(URL.revokeObjectURL(this._cache),this._cache=null),this._value=t,this.events.dispatchEvent({type:"change"}),this.refresh())}get value(){return this._value}refresh(){this.events.dispatchEvent({type:"refresh"})}getValue(){const t=this.value;if(t&&null===this._cache&&"URL"===this.inputType&&t.value instanceof ArrayBuffer)this._cache=URL.createObjectURL(new Blob([t.value]));else if(t&&null!==t.value&&void 0!==t.value&&(("URL"===this.inputType||"String"===this.inputType)&&"string"==typeof t.value||"Number"===this.inputType&&"number"==typeof t.value||"Vector2"===this.inputType&&t.value.isVector2||"Vector3"===this.inputType&&t.value.isVector3||"Vector4"===this.inputType&&t.value.isVector4||"Color"===this.inputType&&t.value.isColor||"Matrix3"===this.inputType&&t.value.isMatrix3||"Matrix4"===this.inputType&&t.value.isMatrix4))return t.value;return this._cache||t}getNodeType(t){return this.value&&this.value.isNode?this.value.getNodeType(t):"float"}setup(){return this.value&&this.value.isNode?this.value:om()}serialize(t){super.serialize(t),null!==this.value?"ArrayBuffer"===this.inputType?t.value=rp(this.value):t.value=this.value?this.value.toJSON(t.meta).uuid:null:t.value=null,t.inputType=this.inputType,t.outputType=this.outputType}deserialize(t){super.deserialize(t);let e=null;null!==t.value&&(e="ArrayBuffer"===t.inputType?np(t.value):"Texture"===t.inputType?t.meta.textures[t.value]:t.meta.nodes[t.value]||null),this.value=e,this.inputType=t.inputType,this.outputType=t.outputType}}const cR=Qp(lR);wp("scriptableValue",cR),lp("ScriptableValueNode",lR);class dR extends Map{get(t,e=null,...s){if(this.has(t))return super.get(t);if(null!==e){const i=e(...s);return this.set(t,i),i}}}class pR{constructor(t){this.scriptableNode=t}get parameters(){return this.scriptableNode.parameters}get layout(){return this.scriptableNode.getLayout()}getInputLayout(t){return this.scriptableNode.getInputLayout(t)}get(t){const e=this.parameters[t];return e?e.getValue():null}}const mR=new dR;class gR extends up{constructor(t=null,e={}){super(),this.codeNode=t,this.parameters=e,this._local=new dR,this._output=cR(),this._outputs={},this._source=this.source,this._method=null,this._object=null,this._value=null,this._needsOutputUpdate=!0,this.onRefresh=this.onRefresh.bind(this),this.isScriptableNode=!0}get source(){return this.codeNode?this.codeNode.code:""}setLocal(t,e){return this._local.set(t,e)}getLocal(t){return this._local.get(t)}onRefresh(){this._refresh()}getInputLayout(t){for(const e of this.getLayout())if(e.inputType&&(e.id===t||e.name===t))return e}getOutputLayout(t){for(const e of this.getLayout())if(e.outputType&&(e.id===t||e.name===t))return e}setOutput(t,e){const s=this._outputs;return void 0===s[t]?s[t]=cR(e):s[t].value=e,this}getOutput(t){return this._outputs[t]}getParameter(t){return this.parameters[t]}setParameter(t,e){const s=this.parameters;return e&&e.isScriptableNode?(this.deleteParameter(t),s[t]=e,s[t].getDefaultOutput().events.addEventListener("refresh",this.onRefresh)):e&&e.isScriptableValueNode?(this.deleteParameter(t),s[t]=e,s[t].events.addEventListener("refresh",this.onRefresh)):void 0===s[t]?(s[t]=cR(e),s[t].events.addEventListener("refresh",this.onRefresh)):s[t].value=e,this}getValue(){return this.getDefaultOutput().getValue()}deleteParameter(t){let e=this.parameters[t];return e&&(e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.removeEventListener("refresh",this.onRefresh)),this}clearParameters(){for(const t of Object.keys(this.parameters))this.deleteParameter(t);return this.needsUpdate=!0,this}call(t,...e){const s=this.getObject()[t];if("function"==typeof s)return s(...e)}async callAsync(t,...e){const s=this.getObject()[t];if("function"==typeof s)return"AsyncFunction"===s.constructor.name?await s(...e):s(...e)}getNodeType(t){return this.getDefaultOutputNode().getNodeType(t)}refresh(t=null){null!==t?this.getOutput(t).refresh():this._refresh()}getObject(){if(this.needsUpdate&&this.dispose(),null!==this._object)return this._object;const t=new pR(this),e=mR.get("THREE"),s=mR.get("TSL"),i=this.getMethod(this.codeNode),r=[t,this._local,mR,()=>this.refresh(),(t,e)=>this.setOutput(t,e),e,s];this._object=i(...r);const n=this._object.layout;if(n&&(!1===n.cache&&this._local.clear(),this._output.outputType=n.outputType||null,Array.isArray(n.elements)))for(const t of n.elements){const e=t.id||t.name;t.inputType&&(void 0===this.getParameter(e)&&this.setParameter(e,null),this.getParameter(e).inputType=t.inputType),t.outputType&&(void 0===this.getOutput(e)&&this.setOutput(e,null),this.getOutput(e).outputType=t.outputType)}return this._object}deserialize(t){super.deserialize(t);for(const t in this.parameters){let e=this.parameters[t];e.isScriptableNode&&(e=e.getDefaultOutput()),e.events.addEventListener("refresh",this.onRefresh)}}getLayout(){return this.getObject().layout}getDefaultOutputNode(){const t=this.getDefaultOutput().value;return t&&t.isNode?t:om()}getDefaultOutput(){return this._exec()._output}getMethod(){if(this.needsUpdate&&this.dispose(),null!==this._method)return this._method;const t=["layout","init","main","dispose"].join(", "),e="\nreturn { ...output, "+t+" };",s="var "+t+"; var output = {};\n"+this.codeNode.code+e;return this._method=new Function(...["parameters","local","global","refresh","setOutput","THREE","TSL"],s),this._method}dispose(){null!==this._method&&(this._object&&"function"==typeof this._object.dispose&&this._object.dispose(),this._method=null,this._object=null,this._source=null,this._value=null,this._needsOutputUpdate=!0,this._output.value=null,this._outputs={})}setup(){return this.getDefaultOutputNode()}getCacheKey(t){const e=[this.source,this.getDefaultOutputNode().getCacheKey(t)];for(const s in this.parameters)e.push(this.parameters[s].getCacheKey(t));return e.join(",")}set needsUpdate(t){!0===t&&this.dispose()}get needsUpdate(){return this.source!==this._source}_exec(){return null===this.codeNode||(!0===this._needsOutputUpdate&&(this._value=this.call("main"),this._needsOutputUpdate=!1),this._output.value=this._value),this}_refresh(){this.needsUpdate=!0,this._exec(),this._output.refresh()}}const fR=Qp(gR);wp("scriptable",fR),lp("ScriptableNode",gR);class yR extends up{constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const s=t.context.getViewZ;return void 0!==s&&(e=s(this)),(e||jb.z).negate()}setup(){return this.factorNode}}const xR=Qp(yR);wp("fog",xR),lp("FogNode",yR);class bR extends yR{constructor(t,e,s){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=s}setup(t){const e=this.getViewZNode(t);return ky(this.nearNode,this.farNode,e)}}const vR=Qp(bR);wp("rangeFog",vR),lp("FogRangeNode",bR);class TR extends yR{constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),s=this.densityNode;return s.mul(s,e,e).negate().exp().oneMinus()}}const _R=Qp(TR);wp("densityFog",_R),lp("FogExp2Node",TR);let wR=null,SR=null;class MR extends up{constructor(t=om(),e=om()){super(),this.minNode=t,this.maxNode=e}getVectorLength(t){const e=t.getTypeLength(sp(this.minNode.value)),s=t.getTypeLength(sp(this.maxNode.value));return e>s?e:s}getNodeType(t){return t.object.count>1?t.getTypeFromLength(this.getVectorLength(t)):"float"}setup(t){const e=t.object;let s=null;if(e.count>1){const i=this.minNode.value,r=this.maxNode.value,n=t.getTypeLength(sp(i)),o=t.getTypeLength(sp(r));wR=wR||new _i,SR=SR||new _i,wR.setScalar(0),SR.setScalar(0),1===n?wR.setScalar(i):i.isColor?wR.set(i.r,i.g,i.b):wR.set(i.x,i.y,i.z||0,i.w||0),1===o?SR.setScalar(r):r.isColor?SR.set(r.r,r.g,r.b):SR.set(r.x,r.y,r.z||0,r.w||0);const a=4,h=a*e.count,u=new Float32Array(h);for(let t=0;t<h;t++){const e=t%a,s=wR.getComponent(e),i=SR.getComponent(e);u[t]=Qs.lerp(s,i,Math.random())}const l=this.getNodeType(t);if(e.count<=4096)s=ux(u,"vec4",e.count).element(tg).convert(l);else{const e=new jo(u,4);t.geometry.setAttribute("__range"+this.id,e),s=Zb(e).convert(l)}}else s=om(0);return s}}const AR=Qp(MR);lp("RangeNode",MR);class NR extends up{constructor(t,e,s=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=s,this.dispatchCount=0,this.version=1,this.updateBeforeType=Xd.OBJECT,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let s=e[0];for(let t=1;t<e.length;t++)s*=e[t];this.dispatchCount=Math.ceil(t/s)}onInit(){}updateBefore({renderer:t}){t.compute(this)}generate(t){const{shaderStage:e}=t;if("compute"===e){const e=this.computeNode.build(t,"void");""!==e&&t.addLineFlowCode(e)}}}const RR=(t,e,s)=>Yp(new NR(Yp(t),e,s));wp("compute",RR),lp("ComputeNode",NR);class CR extends up{constructor(t=CR.TARGET_DIRECTION,e=null){super(),this.scope=t,this.light=e}setup(){const{scope:t,light:e}=this;let s=null;return t===CR.TARGET_DIRECTION&&(s=Mx.transformDirection(Fx(e).sub(Fx(e.target)))),s}serialize(t){super.serialize(t),t.scope=this.scope}deserialize(t){super.deserialize(t),this.scope=t.scope}}CR.TARGET_DIRECTION="targetDirection";const ER=Qp(CR,CR.TARGET_DIRECTION);lp("LightNode",CR);const BR=tm((t=>{const{lightDistance:e,cutoffDistance:s,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return s.greaterThan(0).cond(r.mul(e.div(s).pow4().oneMinus().clamp().pow2()),r)}));class IR extends Pv{constructor(t=null){super(t),this.cutoffDistanceNode=uf(0),this.decayExponentNode=uf(0)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(t){const{colorNode:e,cutoffDistanceNode:s,decayExponentNode:i,light:r}=this,n=t.context.lightingModel,o=zx(r).sub(jb),a=o.normalize(),h=o.length(),u=BR({lightDistance:h,cutoffDistance:s,decayExponent:i}),l=e.mul(u),c=t.context.reflectedLight;n.direct({lightDirection:a,lightColor:l,reflectedLight:c},t.stack,t)}}lp("PointLightNode",IR),Lv(Nl,IR);class PR extends Pv{constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,s=this.colorNode,i=ER(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:s,reflectedLight:r},t.stack,t)}}lp("DirectionalLightNode",PR),Lv(El,PR);const FR=new or,UR=new or;let zR=null;class OR extends Pv{constructor(t=null){super(t),this.halfHeight=uf(new Ei),this.halfWidth=uf(new Ei)}update(t){super.update(t);const{light:e}=this,s=t.camera.matrixWorldInverse;UR.identity(),FR.copy(e.matrixWorld),FR.premultiply(s),UR.extractRotation(FR),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(UR),this.halfHeight.value.applyMatrix4(UR)}setup(t){let e,s;super.setup(t),t.isAvailable("float32Filterable")?(e=nx(zR.LTC_FLOAT_1),s=nx(zR.LTC_FLOAT_2)):(e=nx(zR.LTC_HALF_1),s=nx(zR.LTC_HALF_2));const{colorNode:i,light:r}=this,n=t.context.lightingModel,o=zx(r),a=t.context.reflectedLight;n.directRectArea({lightColor:i,lightPosition:o,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:a,ltc_1:e,ltc_2:s},t.stack,t)}static setLTC(t){zR=t}}lp("RectAreaLightNode",OR),Lv(Il,OR);class LR extends Pv{constructor(t=null){super(t),this.coneCosNode=uf(0),this.penumbraCosNode=uf(0),this.cutoffDistanceNode=uf(0),this.decayExponentNode=uf(0)}update(t){super.update(t);const{light:e}=this;this.coneCosNode.value=Math.cos(e.angle),this.penumbraCosNode.value=Math.cos(e.angle*(1-e.penumbra)),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}getSpotAttenuation(t){const{coneCosNode:e,penumbraCosNode:s}=this;return ky(e,s,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:s,cutoffDistanceNode:i,decayExponentNode:r,light:n}=this,o=zx(n).sub(jb),a=o.normalize(),h=a.dot(ER(n)),u=this.getSpotAttenuation(h),l=o.length(),c=BR({lightDistance:l,cutoffDistance:i,decayExponent:r}),d=s.mul(u).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:a,lightColor:d,reflectedLight:p},t.stack,t)}}lp("SpotLightNode",LR),Lv(_l,LR);class VR extends _l{constructor(t,e,s,i,r,n){super(t,e,s,i,r,n),this.iesMap=null}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this}}class DR extends LR{getSpotAttenuation(t){const e=this.light.iesMap;let s=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);s=nx(e,lm(i,0),0).r}else s=super.getSpotAttenuation(t);return s}}lp("IESSpotLightNode",DR),Lv(VR,DR);class kR extends Pv{constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}lp("AmbientLightNode",kR),Lv(Bl,kR);class GR extends Pv{constructor(t=null){super(t),this.lightPositionNode=Fx(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=uf(new Yr)}update(t){const{light:e}=this;super.update(t),this.lightPositionNode.object3d=e,this.groundColorNode.value.copy(e.groundColor).multiplyScalar(e.intensity)}setup(t){const{colorNode:e,groundColorNode:s,lightDirectionNode:i}=this,r=Xx.dot(i).mul(.5).add(.5),n=Oy(s,e,r);t.context.irradiance.addAssign(n)}}lp("HemisphereLightNode",GR),Lv(fl,GR);let WR=null;const jR=new WeakMap;class HR extends dp{constructor(t,e=null,s=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=s,this._generator=null,this._texture=nx(null),this._width=uf(0),this._height=uf(0),this._maxMip=uf(0),this.updateBeforeType=Xd.RENDER}set value(t){this._value=t,this._pmrem=null}get value(){return this._value}updateFromTexture(t){const e=function(t){const e=Math.log2(t)-2,s=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:s,maxMip:e}}(t.image.height);this._texture.value=t,this._width.value=e.texelWidth,this._height.value=e.texelHeight,this._maxMip.value=e.maxMip}updateBefore(){let t=this._pmrem;const e=t?t.pmremVersion:-1,s=this._value;e!==s.pmremVersion&&(t=!0===s.isPMREMTexture?s:function(t){let e=jR.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){if(t.isCubeTexture){if(t.source.data.some((t=>void 0===t)))throw new Error("PMREMNode: Undefined texture in CubeTexture. Use onLoad callback or async loader");e=WR.fromCubemap(t,e)}else{if(void 0===t.image)throw new Error("PMREMNode: Undefined image in Texture. Use onLoad callback or async loader");e=WR.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,jR.set(t,e)}return e.texture}(s),this._pmrem=t,this.updateFromTexture(t))}setup(t){null===WR&&(WR=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const s=this.value;t.renderer.coordinateSystem===Vs&&!0!==s.isPMREMTexture&&!0===s.isRenderTargetTexture&&(e=mm(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),a_(this._texture,e,i,this._width,this._height,this._maxMip)}}const qR=Qp(HR);lp("PMREMNode",HR);const $R=new WeakMap;class XR extends Nv{constructor(t=null){super(),this.envNode=t}setup(t){let e=this.envNode;if(e.isTextureNode){let t=$R.get(e.value);void 0===t&&(t=qR(e.value),$R.set(e.value,t)),e=t}const{material:s}=t,i=s.envMap?gx("envMapIntensity","float",t.material):gx("environmentIntensity","float",t.scene),r=!0===s.useAnisotropy||s.anisotropy>0,n=Jm(e,YR(xg,r?yS:Jx)).mul(i),o=Jm(e,JR(Zx)).mul(Math.PI).mul(i),a=Xm(n),h=Xm(o);t.context.radiance.addAssign(a),t.context.iblIrradiance.addAssign(h);const u=t.context.lightingModel.clearcoatRadiance;if(u){const t=Jm(e,YR(Tg,Qx)).mul(i),s=Xm(t);u.addAssign(s)}}}const YR=(t,e)=>{let s=null;return{getUV:()=>(null===s&&(s=Hb.negate().reflect(e),s=t.mul(t).mix(s,e).normalize(),s=s.transformDirection(Mx)),s),getTextureLevel:()=>t}},JR=t=>({getUV:()=>t,getTextureLevel:()=>om(1)});lp("EnvironmentNode",XR);class ZR extends Nv{constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=this.envNode}}lp("BasicEnvironmentNode",ZR);const QR=tm((t=>{const e=t.uv.mul(2),s=e.x.floor(),i=e.y.floor();return s.add(i).mod(2).sign()}));class KR extends dp{constructor(t=lf()){super("float"),this.uvNode=t}setup(){return QR({uv:this.uvNode})}}const tC=Qp(KR);wp("checker",tC),lp("CheckerNode",KR);class eC extends nl{constructor(t){super(t),this.textures={}}load(t,e,s,i){const r=new hl(this.manager);r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(s=>{try{e(this.parse(JSON.parse(s)))}catch(e){i?i(e):console.error(e),this.manager.itemError(t)}}),s,i)}parseNodes(t){const e={};if(void 0!==t){for(const s of t){const{uuid:t,type:i}=s;e[t]=Yp(cp(i)),e[t].uuid=t}const s={nodes:e,textures:this.textures};for(const i of t){i.meta=s;e[i.uuid].deserialize(i),delete i.meta}}return e}parse(t){const e=Yp(cp(t.type));e.uuid=t.uuid;const s={nodes:this.parseNodes(t.nodes),textures:this.textures};return t.meta=s,e.deserialize(t),delete t.meta,e}setTextures(t){return this.textures=t,this}}const sC=new Va;class iC extends vT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.pointWidth=1,this.pointColorNode=null,this.setDefaultValues(sC),this.setupShaders(),this.setValues(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor;this.vertexNode=tm((()=>{Gm(lm(),"vUv").assign(lf());const t=jm("instancePosition"),e=mg("vec4","mvPos");e.assign(Vx.mul(xm(t,1)));const s=Xv.z.div(Xv.w),i=wx.mul(e),r=mg("vec2","offset");return r.assign(Db.xy),r.assign(r.mul(Fb)),r.assign(r.div(Xv.z)),r.y.assign(r.y.mul(s)),r.assign(r.mul(i.w)),i.assign(i.add(xm(r,0,0))),i}))(),this.fragmentNode=tm((()=>{const s=Gm(lm(),"vUv"),i=mg("float","alpha");i.assign(1);const r=s.x,n=s.y,o=r.mul(r).add(n.mul(n));if(t){const t=mg("float","dlen");t.assign(o.fwidth()),i.assign(ky(t.oneMinus(),t.add(1),o).oneMinus())}else o.greaterThan(1).discard();let a;if(this.pointColorNode)a=this.pointColorNode;else if(e){a=jm("instanceColor").mul(sb)}else a=sb;return xm(a,i)}))(),this.needsUpdate=!0}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.setupShaders())}}TT("InstancedPointsNodeMaterial",iC);const rC=new Ma;class nC extends vT{constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(rC),this.setValues(t)}}TT("LineBasicNodeMaterial",nC);const oC=new Uu;class aC extends vT{constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.normals=!1,this.setDefaultValues(oC),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?om(this.dashScaleNode):Cb,s=this.dashSizeNode?om(this.dashSizeNode):Eb,i=this.dashSizeNode?om(this.dashGapNode):Bb;Ug.assign(s),zg.assign(i);const r=Gm(jm("lineDistance").mul(e));(t?r.add(t):r).mod(Ug.add(zg)).greaterThan(Ug).discard()}}TT("LineDashedNodeMaterial",aC);const hC=new Uu;class uC extends vT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.setDefaultValues(hC),this.useAlphaToCoverage=!0,this.useColor=t.vertexColors,this.useDash=t.dashed,this.useWorldUnits=!1,this.dashOffset=0,this.lineWidth=1,this.lineColorNode=null,this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setup(t){this.setupShaders(),super.setup(t)}setupShaders(){const t=this.alphaToCoverage,e=this.useColor,s=this.dashed,i=this.worldUnits,r=tm((({start:t,end:e})=>{const s=wx.element(2).element(2),i=wx.element(3).element(2).mul(-.5).div(s).sub(t.z).div(e.z.sub(t.z));return xm(Oy(t.xyz,e.xyz,i),e.w)}));this.vertexNode=tm((()=>{gg("vec2","vUv").assign(lf());const t=jm("instanceStart"),e=jm("instanceEnd"),n=mg("vec4","start"),o=mg("vec4","end");n.assign(Vx.mul(xm(t,1))),o.assign(Vx.mul(xm(e,1))),i&&(gg("vec3","worldStart").assign(n.xyz),gg("vec3","worldEnd").assign(o.xyz));const a=Xv.z.div(Xv.w),h=wx.element(2).element(3).equal(-1);im(h,(()=>{im(n.z.lessThan(0).and(o.z.greaterThan(0)),(()=>{o.assign(r({start:n,end:o}))})).elseif(o.z.lessThan(0).and(n.z.greaterThanEqual(0)),(()=>{n.assign(r({start:o,end:n}))}))}));const u=wx.mul(n),l=wx.mul(o),c=u.xyz.div(u.w),d=l.xyz.div(l.w),p=d.xy.sub(c.xy).temp();p.x.assign(p.x.mul(a)),p.assign(p.normalize());const m=rg(xm());if(i){const t=o.xyz.sub(n.xyz).normalize(),e=Oy(n.xyz,o.xyz,.5).normalize(),i=t.cross(e).normalize(),r=t.cross(i),a=gg("vec4","worldPos");a.assign(Db.y.lessThan(.5).cond(n,o));const h=Ib.mul(.5);a.addAssign(xm(Db.x.lessThan(0).cond(i.mul(h),i.mul(h).negate()),0)),s||(a.addAssign(xm(Db.y.lessThan(.5).cond(t.mul(h).negate(),t.mul(h)),0)),a.addAssign(xm(r.mul(h),0)),im(Db.y.greaterThan(1).or(Db.y.lessThan(0)),(()=>{a.subAssign(xm(r.mul(2).mul(h),0))}))),m.assign(wx.mul(a));const u=rg(mm());u.assign(Db.y.lessThan(.5).cond(c,d)),m.z.assign(u.z.mul(m.w))}else{const t=mg("vec2","offset");t.assign(lm(p.y,p.x.negate())),p.x.assign(p.x.div(a)),t.x.assign(t.x.div(a)),t.assign(Db.x.lessThan(0).cond(t.negate(),t)),im(Db.y.lessThan(0),(()=>{t.assign(t.sub(p))})).elseif(Db.y.greaterThan(1),(()=>{t.assign(t.add(p))})),t.assign(t.mul(Ib)),t.assign(t.div(Xv.w)),m.assign(Db.y.lessThan(.5).cond(u,l)),t.assign(t.mul(m.w)),m.assign(m.add(xm(t,0,0)))}return m}))();const n=tm((({p1:t,p2:e,p3:s,p4:i})=>{const r=t.sub(s),n=i.sub(s),o=e.sub(t),a=r.dot(n),h=n.dot(o),u=r.dot(o),l=n.dot(n),c=o.dot(o).mul(l).sub(h.mul(h)),d=a.mul(h).sub(u.mul(l)).div(c).clamp(),p=a.add(h.mul(d)).div(l).clamp();return lm(d,p)}));this.fragmentNode=tm((()=>{const r=gg("vec2","vUv");if(s){const t=this.offsetNode?om(this.offsetNodeNode):Pb,e=this.dashScaleNode?om(this.dashScaleNode):Cb,s=this.dashSizeNode?om(this.dashSizeNode):Eb,i=this.dashSizeNode?om(this.dashGapNode):Bb;Ug.assign(s),zg.assign(i);const n=jm("instanceDistanceStart"),o=jm("instanceDistanceEnd"),a=Db.y.lessThan(.5).cond(e.mul(n),Cb.mul(o)),h=Gm(a.add(Pb)),u=t?h.add(t):h;r.y.lessThan(-1).or(r.y.greaterThan(1)).discard(),u.mod(Ug.add(zg)).greaterThan(Ug).discard()}const o=mg("float","alpha");if(o.assign(1),i){const e=gg("vec3","worldStart"),i=gg("vec3","worldEnd"),r=gg("vec4","worldPos").xyz.normalize().mul(1e5),a=i.sub(e),h=n({p1:e,p2:i,p3:mm(0,0,0),p4:r}),u=e.add(a.mul(h.x)),l=r.mul(h.y),c=u.sub(l).length().div(Ib);if(!s)if(t){const t=c.fwidth();o.assign(ky(t.negate().add(.5),t.add(.5),c).oneMinus())}else c.greaterThan(.5).discard()}else if(t){const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1)),s=t.mul(t).add(e.mul(e)),i=mg("float","dlen");i.assign(s.fwidth()),im(r.y.abs().greaterThan(1),(()=>{o.assign(ky(i.oneMinus(),i.add(1),s).oneMinus())}))}else im(r.y.abs().greaterThan(1),(()=>{const t=r.x,e=r.y.greaterThan(0).cond(r.y.sub(1),r.y.add(1));t.mul(t).add(e.mul(e)).greaterThan(1).discard()}));let a;if(this.lineColorNode)a=this.lineColorNode;else if(e){const t=jm("instanceColorStart"),e=jm("instanceColorEnd");a=Db.y.lessThan(.5).cond(t,e).mul(sb)}else a=sb;return xm(a,o)}))()}get worldUnits(){return this.useWorldUnits}set worldUnits(t){this.useWorldUnits!==t&&(this.useWorldUnits=t,this.needsUpdate=!0)}get dashed(){return this.useDash}set dashed(t){this.useDash!==t&&(this.useDash=t,this.needsUpdate=!0)}get alphaToCoverage(){return this.useAlphaToCoverage}set alphaToCoverage(t){this.useAlphaToCoverage!==t&&(this.useAlphaToCoverage=t,this.needsUpdate=!0)}}TT("Line2NodeMaterial",uC);const lC=new Eu;class cC extends vT{constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(lC),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?om(this.opacityNode):nb;fg.assign(xm(_w(Jx),t))}}TT("MeshNormalNodeMaterial",cC);class dC extends Nv{constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=om(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}lp("BasicLightMapNode",dC);class pC extends sg{constructor(){super()}indirect(t,e,s){const i=t.ambientOcclusion,r=t.reflectedLight,n=s.context.irradianceLightMap;r.indirectDiffuse.assign(xm(0)),n?r.indirectDiffuse.addAssign(n):r.indirectDiffuse.addAssign(xm(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(fg.rgb)}finish(t,e,s){const i=s.material,r=t.outgoingLight,n=s.context.environment;if(n)switch(i.combine){case 0:r.rgb.assign(Oy(r.rgb,r.rgb.mul(n.rgb),ub.mul(lb)));break;case 1:r.rgb.assign(Oy(r.rgb,n.rgb,ub.mul(lb)));break;case 2:r.rgb.addAssign(n.rgb.mul(ub.mul(lb)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const mC=new Kr;class gC extends vT{constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(mC),this.setValues(t)}setupNormal(){Jx.assign(Xx)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new ZR(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new dC(zb)),e}setupOutgoingLight(){return fg.rgb}setupLightingModel(){return new pC}}TT("MeshBasicNodeMaterial",gC);const fC=tm((({f0:t,f90:e,dotVH:s})=>{const i=s.mul(-5.55473).sub(6.98316).mul(s).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),yC=tm((t=>t.diffuseColor.mul(1/Math.PI))),xC=tm((({dotNH:t})=>Pg.mul(om(.5)).add(1).mul(om(1/Math.PI)).mul(t.pow(Pg)))),bC=tm((({lightDirection:t})=>{const e=t.add(Hb).normalize(),s=Jx.dot(e).clamp(),i=Hb.dot(e).clamp(),r=fC({f0:Bg,f90:1,dotVH:i}),n=om(.25),o=xC({dotNH:s});return r.mul(n).mul(o)}));class vC extends pC{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Jx.dot(t).clamp().mul(e);s.directDiffuse.addAssign(i.mul(yC({diffuseColor:fg.rgb}))),!0===this.specular&&s.directSpecular.addAssign(i.mul(bC({lightDirection:t})).mul(ub))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(yC({diffuseColor:fg}))),s.indirectDiffuse.mulAssign(t)}}const TC=new Bu;class _C extends vT{constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(TC),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new ZR(e):null}setupLightingModel(){return new vC(!1)}}TT("MeshLambertNodeMaterial",_C);const wC=new Ru;class SC extends vT{constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(wC),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new ZR(e):null}setupLightingModel(){return new vC}setupVariants(){const t=(this.shininessNode?om(this.shininessNode):ib).max(1e-4);Pg.assign(t);const e=this.specularNode||ob;Bg.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}TT("MeshPhongNodeMaterial",SC);const MC=tm((()=>{const t=qx.dFdx().abs().max(qx.dFdy().abs());return t.x.max(t.y).max(t.z)})),AC=tm((t=>{const{roughness:e}=t,s=MC();let i=e.max(.0525);return i=i.add(s),i=i.min(1),i})),NC=tm((({alpha:t,dotNL:e,dotNV:s})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(s.pow2())).sqrt()),n=s.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return yf(.5,r.add(n).max(zf))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),RC=tm((({alphaT:t,alphaB:e,dotTV:s,dotBV:i,dotTL:r,dotBL:n,dotNV:o,dotNL:a})=>{const h=a.mul(mm(t.mul(s),e.mul(i),o).length()),u=o.mul(mm(t.mul(r),e.mul(n),a).length());return yf(.5,h.add(u)).saturate()})).setLayout({name:"V_GGX_SmithCorrelated_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotTV",type:"float",qualifier:"in"},{name:"dotBV",type:"float",qualifier:"in"},{name:"dotTL",type:"float",qualifier:"in"},{name:"dotBL",type:"float",qualifier:"in"},{name:"dotNV",type:"float",qualifier:"in"},{name:"dotNL",type:"float",qualifier:"in"}]}),CC=tm((({alpha:t,dotNH:e})=>{const s=t.pow2(),i=e.pow2().mul(s.oneMinus()).oneMinus();return s.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),EC=om(1/Math.PI),BC=tm((({alphaT:t,alphaB:e,dotNH:s,dotTH:i,dotBH:r})=>{const n=t.mul(e),o=mm(e.mul(i),t.mul(r),n.mul(s)),a=o.dot(o),h=n.div(a);return EC.mul(n.mul(h.pow2()))})).setLayout({name:"D_GGX_Anisotropic",type:"float",inputs:[{name:"alphaT",type:"float",qualifier:"in"},{name:"alphaB",type:"float",qualifier:"in"},{name:"dotNH",type:"float",qualifier:"in"},{name:"dotTH",type:"float",qualifier:"in"},{name:"dotBH",type:"float",qualifier:"in"}]}),IC=tm((t=>{const{lightDirection:e,f0:s,f90:i,roughness:r,f:n,USE_IRIDESCENCE:o,USE_ANISOTROPY:a}=t,h=t.normalView||Jx,u=r.pow2(),l=e.add(Hb).normalize(),c=h.dot(e).clamp(),d=h.dot(Hb).clamp(),p=h.dot(l).clamp(),m=Hb.dot(l).clamp();let g,f,y=fC({f0:s,f90:i,dotVH:m});if(qp(o)&&(y=Sg.mix(y,n)),qp(a)){const t=Cg.dot(e),s=Cg.dot(Hb),i=Cg.dot(l),r=Eg.dot(e),n=Eg.dot(Hb),o=Eg.dot(l);g=RC({alphaT:Ng,alphaB:u,dotTV:s,dotBV:n,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),f=BC({alphaT:Ng,alphaB:u,dotNH:p,dotTH:i,dotBH:o})}else g=NC({alpha:u,dotNL:c,dotNV:d}),f=CC({alpha:u,dotNH:p});return y.mul(g).mul(f)})),PC=tm((({roughness:t,dotNV:e})=>{const s=xm(-1,-.0275,-.572,.022),i=xm(1,.0425,1.04,-.04),r=t.mul(s).add(i),n=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return lm(-1.04,1.04).mul(n).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),FC=tm((t=>{const{dotNV:e,specularColor:s,specularF90:i,roughness:r}=t,n=PC({dotNV:e,roughness:r});return s.mul(n.x).add(i.mul(n.y))})),UC=tm((({f:t,f90:e,dotVH:s})=>{const i=s.oneMinus().saturate(),r=i.mul(i),n=i.mul(r,r).clamp(0,.9999);return t.sub(mm(e).mul(n)).div(n.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),zC=tm((({roughness:t,dotNH:e})=>{const s=t.pow2(),i=om(1).div(s),r=e.pow2().oneMinus().max(.0078125);return om(2).add(i).mul(r.pow(i.mul(.5))).div(2*Math.PI)})).setLayout({name:"D_Charlie",type:"float",inputs:[{name:"roughness",type:"float"},{name:"dotNH",type:"float"}]}),OC=tm((({dotNV:t,dotNL:e})=>om(1).div(om(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),LC=tm((({lightDirection:t})=>{const e=t.add(Hb).normalize(),s=Jx.dot(t).clamp(),i=Jx.dot(Hb).clamp(),r=Jx.dot(e).clamp(),n=zC({roughness:wg,dotNH:r}),o=OC({dotNV:i,dotNL:s});return _g.mul(n).mul(o)})),VC=tm((({N:t,V:e,roughness:s})=>{const i=t.dot(e).saturate(),r=lm(s,i.oneMinus().sqrt());return r.assign(r.mul(.984375).add(.0078125)),r})).setLayout({name:"LTC_Uv",type:"vec2",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"roughness",type:"float"}]}),DC=tm((({f:t})=>{const e=t.length();return _y(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),kC=tm((({v1:t,v2:e})=>{const s=t.dot(e),i=s.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),n=i.add(4.1616724).mul(i).add(3.417594).toVar(),o=r.div(n),a=s.greaterThan(0).cond(o,_y(s.mul(s).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(o));return t.cross(e).mul(a)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),GC=tm((({N:t,V:e,P:s,mInv:i,p0:r,p1:n,p2:o,p3:a})=>{const h=n.sub(r).toVar(),u=a.sub(r).toVar(),l=h.cross(u),c=mm().toVar();return im(l.dot(s.sub(r)).greaterThanEqual(0),(()=>{const h=e.sub(t.mul(e.dot(t))).normalize(),u=t.cross(h).negate(),l=i.mul(Am(h,u,t).transpose()).toVar(),d=l.mul(r.sub(s)).normalize().toVar(),p=l.mul(n.sub(s)).normalize().toVar(),m=l.mul(o.sub(s)).normalize().toVar(),g=l.mul(a.sub(s)).normalize().toVar(),f=mm(0).toVar();f.addAssign(kC({v1:d,v2:p})),f.addAssign(kC({v1:p,v2:m})),f.addAssign(kC({v1:m,v2:g})),f.addAssign(kC({v1:g,v2:d})),c.assign(mm(DC({f:f})))})),c})).setLayout({name:"LTC_Evaluate",type:"vec3",inputs:[{name:"N",type:"vec3"},{name:"V",type:"vec3"},{name:"P",type:"vec3"},{name:"mInv",type:"mat3"},{name:"p0",type:"vec3"},{name:"p1",type:"vec3"},{name:"p2",type:"vec3"},{name:"p3",type:"vec3"}]}),WC=tm((([t,e,s,i,r])=>{const n=mm(Dy(e.negate(),Kf(t),yf(1,i))),o=mm(uy(r[0].xyz),uy(r[1].xyz),uy(r[2].xyz));return Kf(n).mul(s.mul(o))})).setLayout({name:"getVolumeTransmissionRay",type:"vec3",inputs:[{name:"n",type:"vec3"},{name:"v",type:"vec3"},{name:"thickness",type:"float"},{name:"ior",type:"float"},{name:"modelMatrix",type:"mat4"}]}),jC=tm((([t,e])=>t.mul(Ly(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),HC=sT(),qC=tm((([t,e,s])=>{const i=HC.uv(t),r=Xf(om($v.x)).mul(jC(e,s));return i.bicubic(r)})),$C=tm((([t,e,s])=>(im(s.notEqual(0),(()=>{const i=$f(e).negate().div(s);return Hf(i.negate().mul(t))})),mm(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),XC=tm((([t,e,s,i,r,n,o,a,h,u,l,c,d,p,m])=>{let g,f;if(m){g=xm().toVar(),f=mm().toVar();const r=l.sub(1).mul(m.mul(.025)),n=mm(l.sub(r),l,l.add(r));pv({start:0,end:3},(({i:r})=>{const l=n.element(r),m=WC(t,e,c,l,a),y=o.add(m),x=u.mul(h.mul(xm(y,1))),b=lm(x.xy.div(x.w)).toVar();b.addAssign(1),b.divAssign(2),b.assign(lm(b.x,b.y.oneMinus()));const v=qC(b,s,l);g.element(r).assign(v.element(r)),g.a.addAssign(v.a),f.element(r).assign(i.element(r).mul($C(uy(m),d,p).element(r)))})),g.a.divAssign(3)}else{const r=WC(t,e,c,l,a),n=o.add(r),m=u.mul(h.mul(xm(n,1))),y=lm(m.xy.div(m.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(lm(y.x,y.y.oneMinus())),g=qC(y,s,l),f=i.mul($C(uy(r),d,p))}const y=f.rgb.mul(g.rgb),x=t.dot(e).clamp(),b=mm(FC({dotNV:x,specularColor:r,specularF90:n,roughness:s})),v=f.r.add(f.g,f.b).div(3);return xm(b.oneMinus().mul(y),g.a.oneMinus().mul(v).oneMinus())})),YC=Am(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),JC=(t,e)=>t.sub(e).div(t.add(e)).pow2(),ZC=(t,e)=>{const s=t.mul(2*Math.PI*1e-9),i=mm(54856e-17,44201e-17,52481e-17),r=mm(1681e3,1795300,2208400),n=mm(43278e5,93046e5,66121e5),o=om(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(s.mul(2239900).add(e.x).cos()).mul(s.pow2().mul(-45282e5).exp());let a=i.mul(n.mul(2*Math.PI).sqrt()).mul(r.mul(s).add(e).cos()).mul(s.pow2().negate().mul(n).exp());a=mm(a.x.add(o),a.y,a.z).div(1.0685e-7);return YC.mul(a)},QC=tm((({outsideIOR:t,eta2:e,cosTheta1:s,thinFilmThickness:i,baseF0:r})=>{const n=Oy(t,e,ky(0,.03,i)),o=t.div(n).pow2().mul(om(1).sub(s.pow2())),a=om(1).sub(o).sqrt(),h=JC(n,t),u=fC({f0:h,f90:1,dotVH:s}),l=u.oneMinus(),c=n.lessThan(t).cond(Math.PI,0),d=om(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return mm(1).add(e).div(mm(1).sub(e))})(r.clamp(0,.9999)),m=JC(p,n.toVec3()),g=fC({f0:m,f90:1,dotVH:a}),f=mm(p.x.lessThan(n).cond(Math.PI,0),p.y.lessThan(n).cond(Math.PI,0),p.z.lessThan(n).cond(Math.PI,0)),y=n.mul(i,a,2),x=mm(d).add(f),b=u.mul(g).clamp(1e-5,.9999),v=b.sqrt(),T=l.pow2().mul(g).div(mm(1).sub(b));let _=u.add(T),w=T.sub(l);for(let t=1;t<=2;++t){w=w.mul(v);const e=ZC(om(t).mul(y),om(t).mul(x)).mul(2);_=_.add(w.mul(e))}return _.max(mm(0))})).setLayout({name:"evalIridescence",type:"vec3",inputs:[{name:"outsideIOR",type:"float"},{name:"eta2",type:"float"},{name:"cosTheta1",type:"float"},{name:"thinFilmThickness",type:"float"},{name:"baseF0",type:"vec3"}]}),KC=tm((({normal:t,viewDir:e,roughness:s})=>{const i=t.dot(e).saturate(),r=s.pow2(),n=VT(s.lessThan(.25),om(-339.2).mul(r).add(om(161.4).mul(s)).sub(25.9),om(-8.48).mul(r).add(om(14.3).mul(s)).sub(9.95)),o=VT(s.lessThan(.25),om(44).mul(r).sub(om(23.7).mul(s)).add(3.26),om(1.97).mul(r).sub(om(3.27).mul(s)).add(.72));return VT(s.lessThan(.25),0,om(.1).mul(s).sub(.025)).add(n.mul(i).add(o).exp()).mul(1/Math.PI).saturate()})),tE=mm(.04),eE=om(1);class sE extends sg{constructor(t=!1,e=!1,s=!1,i=!1,r=!1,n=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=s,this.anisotropy=i,this.transmission=r,this.dispersion=n,this.clearcoatRadiance=null,this.clearcoatSpecularDirect=null,this.clearcoatSpecularIndirect=null,this.sheenSpecularDirect=null,this.sheenSpecularIndirect=null,this.iridescenceFresnel=null,this.iridescenceF0=null}start(t){if(!0===this.clearcoat&&(this.clearcoatRadiance=mm().temp("clearcoatRadiance"),this.clearcoatSpecularDirect=mm().temp("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=mm().temp("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=mm().temp("sheenSpecularDirect"),this.sheenSpecularIndirect=mm().temp("sheenSpecularIndirect")),!0===this.iridescence){const t=Jx.dot(Hb).clamp();this.iridescenceFresnel=QC({outsideIOR:om(1),eta2:Mg,cosTheta1:t,thinFilmThickness:Ag,baseF0:Bg}),this.iridescenceF0=UC({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=Gb,s=Rx.sub(Gb).normalize(),i=Zx;t.backdrop=XC(i,s,xg,fg,Bg,Ig,e,kx,Mx,wx,Lg,Dg,Gg,kg,this.dispersion?Wg:null),t.backdropAlpha=Vg,fg.a.mulAssign(Oy(1,t.backdrop.a,Vg))}}computeMultiscattering(t,e,s){const i=Jx.dot(Hb).clamp(),r=PC({roughness:xg,dotNV:i}),n=(this.iridescenceF0?Sg.mix(Bg,this.iridescenceF0):Bg).mul(r.x).add(s.mul(r.y)),o=r.x.add(r.y).oneMinus(),a=Bg.add(Bg.oneMinus().mul(.047619)),h=n.mul(a).div(o.mul(a).oneMinus());t.addAssign(n),e.addAssign(h.mul(o))}direct({lightDirection:t,lightColor:e,reflectedLight:s}){const i=Jx.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(LC({lightDirection:t}))),!0===this.clearcoat){const s=Qx.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(s.mul(IC({lightDirection:t,f0:tE,f90:eE,roughness:Tg,normalView:Qx})))}s.directDiffuse.addAssign(i.mul(yC({diffuseColor:fg.rgb}))),s.directSpecular.addAssign(i.mul(IC({lightDirection:t,f0:Bg,f90:1,roughness:xg,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:s,halfHeight:i,reflectedLight:r,ltc_1:n,ltc_2:o}){const a=e.add(s).sub(i),h=e.sub(s).sub(i),u=e.sub(s).add(i),l=e.add(s).add(i),c=Jx,d=Hb,p=jb.toVar(),m=VC({N:c,V:d,roughness:xg}),g=n.uv(m).toVar(),f=o.uv(m).toVar(),y=Am(mm(g.x,0,g.y),mm(0,1,0),mm(g.z,0,g.w)).toVar(),x=Bg.mul(f.x).add(Bg.oneMinus().mul(f.y)).toVar();r.directSpecular.addAssign(t.mul(x).mul(GC({N:c,V:d,P:p,mInv:y,p0:a,p1:h,p2:u,p3:l}))),r.directDiffuse.addAssign(t.mul(fg).mul(GC({N:c,V:d,P:p,mInv:Am(1,0,0,0,1,0,0,0,1),p0:a,p1:h,p2:u,p3:l})))}indirect(t,e,s){this.indirectDiffuse(t,e,s),this.indirectSpecular(t,e,s),this.ambientOcclusion(t,e,s)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(yC({diffuseColor:fg})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:s}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(_g,KC({normal:Jx,viewDir:Hb,roughness:wg}))),!0===this.clearcoat){const t=Qx.dot(Hb).clamp(),e=FC({dotNV:t,specularColor:tE,specularF90:eE,roughness:Tg});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=mm().temp("singleScattering"),r=mm().temp("multiScattering"),n=e.mul(1/Math.PI);this.computeMultiscattering(i,r,Ig);const o=i.add(r),a=fg.mul(o.r.max(o.g).max(o.b).oneMinus());s.indirectSpecular.addAssign(t.mul(i)),s.indirectSpecular.addAssign(r.mul(n)),s.indirectDiffuse.addAssign(a.mul(n))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const s=Jx.dot(Hb).clamp().add(t),i=xg.mul(-16).oneMinus().negate().exp2(),r=t.sub(s.pow(i).oneMinus()).clamp();!0===this.clearcoat&&this.clearcoatSpecularIndirect.mulAssign(t),!0===this.sheen&&this.sheenSpecularIndirect.mulAssign(t),e.indirectDiffuse.mulAssign(t),e.indirectSpecular.mulAssign(r)}finish(t){const{outgoingLight:e}=t;if(!0===this.clearcoat){const t=Qx.dot(Hb).clamp(),s=fC({dotVH:t,f0:tE,f90:eE}),i=e.mul(vg.mul(s).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(vg));e.assign(i)}if(!0===this.sheen){const t=_g.r.max(_g.g).max(_g.b).mul(.157).oneMinus(),s=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(s)}}}const iE=new Au;class rE extends vT{constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(iE),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new XR(e):null}setupLightingModel(){return new sE}setupSpecular(){const t=Oy(mm(.04),fg.rgb,bg);Bg.assign(t),Ig.assign(1)}setupVariants(){const t=this.metalnessNode?om(this.metalnessNode):db;bg.assign(t);let e=this.roughnessNode?om(this.roughnessNode):cb;e=AC({roughness:e}),xg.assign(e),this.setupSpecular(),fg.assign(xm(fg.rgb.mul(t.oneMinus()),fg.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}TT("MeshStandardNodeMaterial",rE);const nE=new Nu;class oE extends rE{constructor(t){super(),this.isMeshPhysicalNodeMaterial=!0,this.clearcoatNode=null,this.clearcoatRoughnessNode=null,this.clearcoatNormalNode=null,this.sheenNode=null,this.sheenRoughnessNode=null,this.iridescenceNode=null,this.iridescenceIORNode=null,this.iridescenceThicknessNode=null,this.specularIntensityNode=null,this.specularColorNode=null,this.iorNode=null,this.transmissionNode=null,this.thicknessNode=null,this.attenuationDistanceNode=null,this.attenuationColorNode=null,this.dispersionNode=null,this.anisotropyNode=null,this.setDefaultValues(nE),this.setValues(t)}get useClearcoat(){return this.clearcoat>0||null!==this.clearcoatNode}get useIridescence(){return this.iridescence>0||null!==this.iridescenceNode}get useSheen(){return this.sheen>0||null!==this.sheenNode}get useAnisotropy(){return this.anisotropy>0||null!==this.anisotropyNode}get useTransmission(){return this.transmission>0||null!==this.transmissionNode}get useDispersion(){return this.dispersion>0||null!==this.dispersionNode}setupSpecular(){const t=this.iorNode?om(this.iorNode):Ab;Lg.assign(t),Bg.assign(Oy(Ty(By(Lg.sub(1).div(Lg.add(1))).mul(hb),mm(1)).mul(ab),fg.rgb,bg)),Ig.assign(Oy(ab,1,bg))}setupLightingModel(){return new sE(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?om(this.clearcoatNode):mb,e=this.clearcoatRoughnessNode?om(this.clearcoatRoughnessNode):gb;vg.assign(t),Tg.assign(AC({roughness:e}))}if(this.useSheen){const t=this.sheenNode?mm(this.sheenNode):xb,e=this.sheenRoughnessNode?om(this.sheenRoughnessNode):bb;_g.assign(t),wg.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?om(this.iridescenceNode):Tb,e=this.iridescenceIORNode?om(this.iridescenceIORNode):_b,s=this.iridescenceThicknessNode?om(this.iridescenceThicknessNode):wb;Sg.assign(t),Mg.assign(e),Ag.assign(s)}if(this.useAnisotropy){const t=(this.anisotropyNode?lm(this.anisotropyNode):vb).toVar();Rg.assign(t.length()),im(Rg.equal(0),(()=>{t.assign(lm(1,0))})).else((()=>{t.divAssign(lm(Rg)),Rg.assign(Rg.saturate())})),Ng.assign(Rg.pow2().mix(xg.pow2(),1)),Cg.assign(mS[0].mul(t.x).add(mS[1].mul(t.y))),Eg.assign(mS[1].mul(t.x).sub(mS[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?om(this.transmissionNode):Sb,e=this.thicknessNode?om(this.thicknessNode):Mb,s=this.attenuationDistanceNode?om(this.attenuationDistanceNode):Nb,i=this.attenuationColorNode?mm(this.attenuationColorNode):Rb;if(Vg.assign(t),Dg.assign(e),kg.assign(s),Gg.assign(i),this.useDispersion){const t=this.dispersionNode?om(this.dispersionNode):Ub;Wg.assign(t)}}}setupNormal(t){super.setupNormal(t);const e=this.clearcoatNormalNode?mm(this.clearcoatNormalNode):fb;Qx.assign(e)}copy(t){return this.clearcoatNode=t.clearcoatNode,this.clearcoatRoughnessNode=t.clearcoatRoughnessNode,this.clearcoatNormalNode=t.clearcoatNormalNode,this.sheenNode=t.sheenNode,this.sheenRoughnessNode=t.sheenRoughnessNode,this.iridescenceNode=t.iridescenceNode,this.iridescenceIORNode=t.iridescenceIORNode,this.iridescenceThicknessNode=t.iridescenceThicknessNode,this.specularIntensityNode=t.specularIntensityNode,this.specularColorNode=t.specularColorNode,this.transmissionNode=t.transmissionNode,this.thicknessNode=t.thicknessNode,this.attenuationDistanceNode=t.attenuationDistanceNode,this.attenuationColorNode=t.attenuationColorNode,this.dispersionNode=t.dispersionNode,this.anisotropyNode=t.anisotropyNode,super.copy(t)}}TT("MeshPhysicalNodeMaterial",oE);class aE extends sE{constructor(t,e,s,i){super(t,e,s),this.useSSS=i}direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){if(!0===this.useSSS){const i=r.material,{thicknessColorNode:n,thicknessDistortionNode:o,thicknessAmbientNode:a,thicknessAttenuationNode:h,thicknessPowerNode:u,thicknessScaleNode:l}=i,c=t.add(Jx.mul(o)).normalize(),d=om(Hb.dot(c.negate()).saturate().pow(u).mul(l)),p=mm(d.add(a).mul(n));s.directDiffuse.addAssign(p.mul(h.mul(e)))}super.direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r)}}class hE extends oE{constructor(t){super(t),this.thicknessColorNode=null,this.thicknessDistortionNode=om(.1),this.thicknessAmbientNode=om(0),this.thicknessAttenuationNode=om(.1),this.thicknessPowerNode=om(2),this.thicknessScaleNode=om(10)}get useSSS(){return null!==this.thicknessColorNode}setupLightingModel(){return new aE(this.useClearcoat,this.useSheen,this.useIridescence,this.useSSS)}copy(t){return this.thicknessColorNode=t.thicknessColorNode,this.thicknessDistortionNode=t.thicknessDistortionNode,this.thicknessAmbientNode=t.thicknessAmbientNode,this.thicknessAttenuationNode=t.thicknessAttenuationNode,this.thicknessPowerNode=t.thicknessPowerNode,this.thicknessScaleNode=t.thicknessScaleNode,super.copy(t)}}TT("MeshSSSNodeMaterial",hE);const uE=tm((({normal:t,lightDirection:e,builder:s})=>{const i=t.dot(e),r=lm(i.mul(.5).add(.5),0);if(s.material.gradientMap){const t=xx("gradientMap","texture").context({getUV:()=>r});return mm(t.r)}{const t=r.fwidth().mul(.5);return Oy(mm(.7),mm(1),ky(om(.7).sub(t.x),om(.7).add(t.x),r.x))}}));class lE extends sg{direct({lightDirection:t,lightColor:e,reflectedLight:s},i,r){const n=uE({normal:qx,lightDirection:t,builder:r}).mul(e);s.directDiffuse.addAssign(n.mul(yC({diffuseColor:fg.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:s}){s.indirectDiffuse.addAssign(e.mul(yC({diffuseColor:fg}))),s.indirectDiffuse.mulAssign(t)}}const cE=new Cu;class dE extends vT{constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(cE),this.setValues(t)}setupLightingModel(){return new lE}}TT("MeshToonNodeMaterial",dE);const pE=new Fu;class mE extends vT{constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(pE),this.setValues(t)}setupVariants(t){const e=lw;let s;s=t.material.matcap?xx("matcap","texture").context({getUV:()=>e}):mm(Oy(.2,.8,e.y)),fg.rgb.mulAssign(s.rgb)}}TT("MeshMatcapNodeMaterial",mE);const gE=new Va;class fE extends vT{constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.normals=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(gE),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}TT("PointsNodeMaterial",fE);const yE=new uo;class xE extends vT{constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this.normals=!1,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(yE),this.setValues(t)}setupPosition({object:t,context:e}){const{positionNode:s,rotationNode:i,scaleNode:r}=this,n=kb;let o=Vx.mul(mm(s||0)),a=lm(kx[0].xyz.length(),kx[1].xyz.length());null!==r&&(a=a.mul(r));let h=n.xy;t.center&&!0===t.center.isVector2&&(h=h.sub(uf(t.center).sub(.5))),h=h.mul(a);const u=om(i||yb),l=h.rotate(u);o=xm(o.xy.add(l),o.zw);const c=wx.mul(o);return e.vertex=n,c}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}}TT("SpriteNodeMaterial",xE);class bE extends sg{constructor(){super(),this.shadowNode=om(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){fg.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(fg.rgb)}}const vE=new Su;class TE extends vT{constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(vE),this.setValues(t)}setupLightingModel(){return new bE}}TT("ShadowNodeMaterial",TE);class _E extends vT{constructor(t={}){super(),this.normals=!1,this.lights=!1,this.isVolumeNodeMaterial=!0,this.testNode=null,this.setValues(t)}setup(t){const e=pA(this.map,null,0),s=tm((({orig:t,dir:e})=>{const s=mm(-.5),i=mm(.5),r=e.reciprocal(),n=s.sub(t).mul(r),o=i.sub(t).mul(r),a=Ty(n,o),h=_y(n,o),u=_y(a.x,_y(a.y,a.z)),l=Ty(h.x,Ty(h.y,h.z));return lm(u,l)}));this.fragmentNode=tm((()=>{const t=Gm(mm(Hx.mul(xm(Rx,1)))),i=Gm(Db.sub(t)).normalize(),r=mg("vec2","bounds").assign(s({orig:t,dir:i}));r.x.greaterThan(r.y).discard(),r.assign(lm(_y(r.x,0),r.y));const n=mg("vec3","p").assign(t.add(r.x.mul(i))),o=mg("vec3","inc").assign(mm(i.abs().reciprocal())),a=mg("float","delta").assign(Ty(o.x,Ty(o.y,o.z)));a.divAssign(xx("steps","float"));const h=mg("vec4","ac").assign(xm(xx("base","color"),0));return pv({type:"float",start:r.x,end:r.y,update:"+= delta"},(()=>{const t=mg("float","d").assign(e.uv(n.add(.5)).r);null!==this.testNode?this.testNode({map:e,mapValue:t,probe:n,finalColor:h}).append():(h.a.assign(1),gv()),n.addAssign(i.mul(a))})),h.a.equal(0).discard(),xm(h)}))(),super.setup(t)}}TT("VolumeNodeMaterial",_E);const wE=Ul.createMaterialFromType;Ul.createMaterialFromType=function(t){const e=_T(t);return void 0!==e?e:wE.call(this,t)};class SE extends Ul{constructor(t){super(t),this.nodes={}}parse(t){const e=super.parse(t),s=this.nodes,i=t.inputNodes;for(const t in i){const r=i[t];e[t]=s[r]}return e}setNodes(t){return this.nodes=t,this}}class ME extends Vl{constructor(t){super(t),this._nodesJSON=null}parse(t,e){this._nodesJSON=t.nodes;const s=super.parse(t,e);return this._nodesJSON=null,s}parseNodes(t,e){if(void 0!==t){const s=new eC;return s.setTextures(e),s.parseNodes(t)}return{}}parseMaterials(t,e){const s={};if(void 0!==t){const i=this.parseNodes(this._nodesJSON,e),r=new SE;r.setTextures(e),r.setNodes(i);for(let e=0,i=t.length;e<i;e++){const i=t[e];s[i.uuid]=r.parse(i)}}return s}}class AE{parseFunction(){console.warn("Abstract function.")}}class NE{constructor(t,e,s="",i=""){this.type=t,this.inputs=e,this.name=s,this.precision=i}getCode(){console.warn("Abstract function.")}}NE.isNodeFunction=!0;const RE=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,CE=/[a-z_0-9]+/gi,EE="#pragma main";class BE extends NE{constructor(t){const{type:e,inputs:s,name:i,precision:r,inputsCode:n,blockCode:o,headerCode:a}=(t=>{const e=(t=t.trim()).indexOf(EE),s=-1!==e?t.slice(e+12):t,i=s.match(RE);if(null!==i&&5===i.length){const r=i[4],n=[];let o=null;for(;null!==(o=CE.exec(r));)n.push(o);const a=[];let h=0;for(;h<n.length;){const t="const"===n[h][0];!0===t&&h++;let e=n[h][0];"in"===e||"out"===e||"inout"===e?h++:e="";const s=n[h++][0];let i=Number.parseInt(n[h][0]);!1===Number.isNaN(i)?h++:i=null;const r=n[h++][0];a.push(new V_(s,r,i,e,t))}const u=s.substring(i[0].length),l=void 0!==i[3]?i[3]:"";return{type:i[2],inputs:a,name:l,precision:void 0!==i[1]?i[1]:"",inputsCode:r,blockCode:u,headerCode:-1!==e?t.slice(0,e):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(t);super(e,s,i,r),this.inputsCode=n,this.blockCode=o,this.headerCode=a}getCode(t=this.name){let e;const s=this.blockCode;if(""!==s){const{type:i,inputsCode:r,headerCode:n,precision:o}=this;let a=`${i} ${t} ( ${r.trim()} )`;""!==o&&(a=`${o} ${a}`),e=n+a+s}else e="";return e}}class IE extends AE{parseFunction(t){return new BE(t)}}const PE=tm((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=um(t).toVar();return VT(n,r,i)})).setLayout({name:"mx_select",type:"float",inputs:[{name:"b",type:"bool"},{name:"t",type:"float"},{name:"f",type:"float"}]}),FE=tm((([t,e])=>{const s=um(e).toVar(),i=om(t).toVar();return VT(s,i.negate(),i)})).setLayout({name:"mx_negate_if",type:"float",inputs:[{name:"val",type:"float"},{name:"b",type:"bool"}]}),UE=tm((([t])=>{const e=om(t).toVar();return am(Zf(e))})).setLayout({name:"mx_floor",type:"int",inputs:[{name:"x",type:"float"}]}),zE=tm((([t,e])=>{const s=om(t).toVar();return e.assign(UE(s)),s.sub(om(e))})),OE=hw([tm((([t,e,s,i,r,n])=>{const o=om(n).toVar(),a=om(r).toVar(),h=om(i).toVar(),u=om(s).toVar(),l=om(e).toVar(),c=om(t).toVar(),d=om(gf(1,a)).toVar();return gf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"}]}),tm((([t,e,s,i,r,n])=>{const o=om(n).toVar(),a=om(r).toVar(),h=mm(i).toVar(),u=mm(s).toVar(),l=mm(e).toVar(),c=mm(t).toVar(),d=om(gf(1,a)).toVar();return gf(1,o).mul(c.mul(d).add(l.mul(a))).add(o.mul(u.mul(d).add(h.mul(a))))})).setLayout({name:"mx_bilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"}]})]),LE=hw([tm((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=om(l).toVar(),d=om(u).toVar(),p=om(h).toVar(),m=om(a).toVar(),g=om(o).toVar(),f=om(n).toVar(),y=om(r).toVar(),x=om(i).toVar(),b=om(s).toVar(),v=om(e).toVar(),T=om(t).toVar(),_=om(gf(1,p)).toVar(),w=om(gf(1,d)).toVar();return om(gf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_0",type:"float",inputs:[{name:"v0",type:"float"},{name:"v1",type:"float"},{name:"v2",type:"float"},{name:"v3",type:"float"},{name:"v4",type:"float"},{name:"v5",type:"float"},{name:"v6",type:"float"},{name:"v7",type:"float"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]}),tm((([t,e,s,i,r,n,o,a,h,u,l])=>{const c=om(l).toVar(),d=om(u).toVar(),p=om(h).toVar(),m=mm(a).toVar(),g=mm(o).toVar(),f=mm(n).toVar(),y=mm(r).toVar(),x=mm(i).toVar(),b=mm(s).toVar(),v=mm(e).toVar(),T=mm(t).toVar(),_=om(gf(1,p)).toVar(),w=om(gf(1,d)).toVar();return om(gf(1,c)).toVar().mul(w.mul(T.mul(_).add(v.mul(p))).add(d.mul(b.mul(_).add(x.mul(p))))).add(c.mul(w.mul(y.mul(_).add(f.mul(p))).add(d.mul(g.mul(_).add(m.mul(p))))))})).setLayout({name:"mx_trilerp_1",type:"vec3",inputs:[{name:"v0",type:"vec3"},{name:"v1",type:"vec3"},{name:"v2",type:"vec3"},{name:"v3",type:"vec3"},{name:"v4",type:"vec3"},{name:"v5",type:"vec3"},{name:"v6",type:"vec3"},{name:"v7",type:"vec3"},{name:"s",type:"float"},{name:"t",type:"float"},{name:"r",type:"float"}]})]),VE=tm((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=hm(t).toVar(),o=hm(n.bitAnd(hm(7))).toVar(),a=om(PE(o.lessThan(hm(4)),r,i)).toVar(),h=om(ff(2,PE(o.lessThan(hm(4)),i,r))).toVar();return FE(a,um(o.bitAnd(hm(1)))).add(FE(h,um(o.bitAnd(hm(2)))))})).setLayout({name:"mx_gradient_float_0",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"}]}),DE=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=om(e).toVar(),a=hm(t).toVar(),h=hm(a.bitAnd(hm(15))).toVar(),u=om(PE(h.lessThan(hm(8)),o,n)).toVar(),l=om(PE(h.lessThan(hm(4)),n,PE(h.equal(hm(12)).or(h.equal(hm(14))),o,r))).toVar();return FE(u,um(h.bitAnd(hm(1)))).add(FE(l,um(h.bitAnd(hm(2)))))})).setLayout({name:"mx_gradient_float_1",type:"float",inputs:[{name:"hash",type:"uint"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),kE=hw([VE,DE]),GE=tm((([t,e,s])=>{const i=om(s).toVar(),r=om(e).toVar(),n=fm(t).toVar();return mm(kE(n.x,r,i),kE(n.y,r,i),kE(n.z,r,i))})).setLayout({name:"mx_gradient_vec3_0",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"}]}),WE=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=om(e).toVar(),a=fm(t).toVar();return mm(kE(a.x,o,n,r),kE(a.y,o,n,r),kE(a.z,o,n,r))})).setLayout({name:"mx_gradient_vec3_1",type:"vec3",inputs:[{name:"hash",type:"uvec3"},{name:"x",type:"float"},{name:"y",type:"float"},{name:"z",type:"float"}]}),jE=hw([GE,WE]),HE=tm((([t])=>{const e=om(t).toVar();return ff(.6616,e)})).setLayout({name:"mx_gradient_scale2d_0",type:"float",inputs:[{name:"v",type:"float"}]}),qE=tm((([t])=>{const e=om(t).toVar();return ff(.982,e)})).setLayout({name:"mx_gradient_scale3d_0",type:"float",inputs:[{name:"v",type:"float"}]}),$E=hw([HE,tm((([t])=>{const e=mm(t).toVar();return ff(.6616,e)})).setLayout({name:"mx_gradient_scale2d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),XE=hw([qE,tm((([t])=>{const e=mm(t).toVar();return ff(.982,e)})).setLayout({name:"mx_gradient_scale3d_1",type:"vec3",inputs:[{name:"v",type:"vec3"}]})]),YE=tm((([t,e])=>{const s=am(e).toVar(),i=hm(t).toVar();return i.shiftLeft(s).bitOr(i.shiftRight(am(32).sub(s)))})).setLayout({name:"mx_rotl32",type:"uint",inputs:[{name:"x",type:"uint"},{name:"k",type:"int"}]}),JE=tm((([t,e,s])=>{t.subAssign(s),t.bitXorAssign(YE(s,am(4))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(YE(t,am(6))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(YE(e,am(8))),e.addAssign(t),t.subAssign(s),t.bitXorAssign(YE(s,am(16))),s.addAssign(e),e.subAssign(t),e.bitXorAssign(YE(t,am(19))),t.addAssign(s),s.subAssign(e),s.bitXorAssign(YE(e,am(4))),e.addAssign(t)})),ZE=tm((([t,e,s])=>{const i=hm(s).toVar(),r=hm(e).toVar(),n=hm(t).toVar();return i.bitXorAssign(r),i.subAssign(YE(r,am(14))),n.bitXorAssign(i),n.subAssign(YE(i,am(11))),r.bitXorAssign(n),r.subAssign(YE(n,am(25))),i.bitXorAssign(r),i.subAssign(YE(r,am(16))),n.bitXorAssign(i),n.subAssign(YE(i,am(4))),r.bitXorAssign(n),r.subAssign(YE(n,am(14))),i.bitXorAssign(r),i.subAssign(YE(r,am(24))),i})).setLayout({name:"mx_bjfinal",type:"uint",inputs:[{name:"a",type:"uint"},{name:"b",type:"uint"},{name:"c",type:"uint"}]}),QE=tm((([t])=>{const e=hm(t).toVar();return om(e).div(om(hm(am(4294967295))))})).setLayout({name:"mx_bits_to_01",type:"float",inputs:[{name:"bits",type:"uint"}]}),KE=tm((([t])=>{const e=om(t).toVar();return e.mul(e).mul(e).mul(e.mul(e.mul(6).sub(15)).add(10))})).setLayout({name:"mx_fade",type:"float",inputs:[{name:"t",type:"float"}]}),tB=hw([tm((([t])=>{const e=am(t).toVar(),s=hm(hm(1)).toVar(),i=hm(hm(am(3735928559)).add(s.shiftLeft(hm(2))).add(hm(13))).toVar();return ZE(i.add(hm(e)),i,i)})).setLayout({name:"mx_hash_int_0",type:"uint",inputs:[{name:"x",type:"int"}]}),tm((([t,e])=>{const s=am(e).toVar(),i=am(t).toVar(),r=hm(hm(2)).toVar(),n=hm().toVar(),o=hm().toVar(),a=hm().toVar();return n.assign(o.assign(a.assign(hm(am(3735928559)).add(r.shiftLeft(hm(2))).add(hm(13))))),n.addAssign(hm(i)),o.addAssign(hm(s)),ZE(n,o,a)})).setLayout({name:"mx_hash_int_1",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),tm((([t,e,s])=>{const i=am(s).toVar(),r=am(e).toVar(),n=am(t).toVar(),o=hm(hm(3)).toVar(),a=hm().toVar(),h=hm().toVar(),u=hm().toVar();return a.assign(h.assign(u.assign(hm(am(3735928559)).add(o.shiftLeft(hm(2))).add(hm(13))))),a.addAssign(hm(n)),h.addAssign(hm(r)),u.addAssign(hm(i)),ZE(a,h,u)})).setLayout({name:"mx_hash_int_2",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]}),tm((([t,e,s,i])=>{const r=am(i).toVar(),n=am(s).toVar(),o=am(e).toVar(),a=am(t).toVar(),h=hm(hm(4)).toVar(),u=hm().toVar(),l=hm().toVar(),c=hm().toVar();return u.assign(l.assign(c.assign(hm(am(3735928559)).add(h.shiftLeft(hm(2))).add(hm(13))))),u.addAssign(hm(a)),l.addAssign(hm(o)),c.addAssign(hm(n)),JE(u,l,c),u.addAssign(hm(r)),ZE(u,l,c)})).setLayout({name:"mx_hash_int_3",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"}]}),tm((([t,e,s,i,r])=>{const n=am(r).toVar(),o=am(i).toVar(),a=am(s).toVar(),h=am(e).toVar(),u=am(t).toVar(),l=hm(hm(5)).toVar(),c=hm().toVar(),d=hm().toVar(),p=hm().toVar();return c.assign(d.assign(p.assign(hm(am(3735928559)).add(l.shiftLeft(hm(2))).add(hm(13))))),c.addAssign(hm(u)),d.addAssign(hm(h)),p.addAssign(hm(a)),JE(c,d,p),c.addAssign(hm(o)),d.addAssign(hm(n)),ZE(c,d,p)})).setLayout({name:"mx_hash_int_4",type:"uint",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xx",type:"int"},{name:"yy",type:"int"}]})]),eB=hw([tm((([t,e])=>{const s=am(e).toVar(),i=am(t).toVar(),r=hm(tB(i,s)).toVar(),n=fm().toVar();return n.x.assign(r.bitAnd(am(255))),n.y.assign(r.shiftRight(am(8)).bitAnd(am(255))),n.z.assign(r.shiftRight(am(16)).bitAnd(am(255))),n})).setLayout({name:"mx_hash_vec3_0",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"}]}),tm((([t,e,s])=>{const i=am(s).toVar(),r=am(e).toVar(),n=am(t).toVar(),o=hm(tB(n,r,i)).toVar(),a=fm().toVar();return a.x.assign(o.bitAnd(am(255))),a.y.assign(o.shiftRight(am(8)).bitAnd(am(255))),a.z.assign(o.shiftRight(am(16)).bitAnd(am(255))),a})).setLayout({name:"mx_hash_vec3_1",type:"uvec3",inputs:[{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"}]})]),sB=hw([tm((([t])=>{const e=lm(t).toVar(),s=am().toVar(),i=am().toVar(),r=om(zE(e.x,s)).toVar(),n=om(zE(e.y,i)).toVar(),o=om(KE(r)).toVar(),a=om(KE(n)).toVar(),h=om(OE(kE(tB(s,i),r,n),kE(tB(s.add(am(1)),i),r.sub(1),n),kE(tB(s,i.add(am(1))),r,n.sub(1)),kE(tB(s.add(am(1)),i.add(am(1))),r.sub(1),n.sub(1)),o,a)).toVar();return $E(h)})).setLayout({name:"mx_perlin_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"}]}),tm((([t])=>{const e=mm(t).toVar(),s=am().toVar(),i=am().toVar(),r=am().toVar(),n=om(zE(e.x,s)).toVar(),o=om(zE(e.y,i)).toVar(),a=om(zE(e.z,r)).toVar(),h=om(KE(n)).toVar(),u=om(KE(o)).toVar(),l=om(KE(a)).toVar(),c=om(LE(kE(tB(s,i,r),n,o,a),kE(tB(s.add(am(1)),i,r),n.sub(1),o,a),kE(tB(s,i.add(am(1)),r),n,o.sub(1),a),kE(tB(s.add(am(1)),i.add(am(1)),r),n.sub(1),o.sub(1),a),kE(tB(s,i,r.add(am(1))),n,o,a.sub(1)),kE(tB(s.add(am(1)),i,r.add(am(1))),n.sub(1),o,a.sub(1)),kE(tB(s,i.add(am(1)),r.add(am(1))),n,o.sub(1),a.sub(1)),kE(tB(s.add(am(1)),i.add(am(1)),r.add(am(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return XE(c)})).setLayout({name:"mx_perlin_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"}]})]),iB=hw([tm((([t])=>{const e=lm(t).toVar(),s=am().toVar(),i=am().toVar(),r=om(zE(e.x,s)).toVar(),n=om(zE(e.y,i)).toVar(),o=om(KE(r)).toVar(),a=om(KE(n)).toVar(),h=mm(OE(jE(eB(s,i),r,n),jE(eB(s.add(am(1)),i),r.sub(1),n),jE(eB(s,i.add(am(1))),r,n.sub(1)),jE(eB(s.add(am(1)),i.add(am(1))),r.sub(1),n.sub(1)),o,a)).toVar();return $E(h)})).setLayout({name:"mx_perlin_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),tm((([t])=>{const e=mm(t).toVar(),s=am().toVar(),i=am().toVar(),r=am().toVar(),n=om(zE(e.x,s)).toVar(),o=om(zE(e.y,i)).toVar(),a=om(zE(e.z,r)).toVar(),h=om(KE(n)).toVar(),u=om(KE(o)).toVar(),l=om(KE(a)).toVar(),c=mm(LE(jE(eB(s,i,r),n,o,a),jE(eB(s.add(am(1)),i,r),n.sub(1),o,a),jE(eB(s,i.add(am(1)),r),n,o.sub(1),a),jE(eB(s.add(am(1)),i.add(am(1)),r),n.sub(1),o.sub(1),a),jE(eB(s,i,r.add(am(1))),n,o,a.sub(1)),jE(eB(s.add(am(1)),i,r.add(am(1))),n.sub(1),o,a.sub(1)),jE(eB(s,i.add(am(1)),r.add(am(1))),n,o.sub(1),a.sub(1)),jE(eB(s.add(am(1)),i.add(am(1)),r.add(am(1))),n.sub(1),o.sub(1),a.sub(1)),h,u,l)).toVar();return XE(c)})).setLayout({name:"mx_perlin_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"}]})]),rB=hw([tm((([t])=>{const e=om(t).toVar(),s=am(UE(e)).toVar();return QE(tB(s))})).setLayout({name:"mx_cell_noise_float_0",type:"float",inputs:[{name:"p",type:"float"}]}),tm((([t])=>{const e=lm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar();return QE(tB(s,i))})).setLayout({name:"mx_cell_noise_float_1",type:"float",inputs:[{name:"p",type:"vec2"}]}),tm((([t])=>{const e=mm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar(),r=am(UE(e.z)).toVar();return QE(tB(s,i,r))})).setLayout({name:"mx_cell_noise_float_2",type:"float",inputs:[{name:"p",type:"vec3"}]}),tm((([t])=>{const e=xm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar(),r=am(UE(e.z)).toVar(),n=am(UE(e.w)).toVar();return QE(tB(s,i,r,n))})).setLayout({name:"mx_cell_noise_float_3",type:"float",inputs:[{name:"p",type:"vec4"}]})]),nB=hw([tm((([t])=>{const e=om(t).toVar(),s=am(UE(e)).toVar();return mm(QE(tB(s,am(0))),QE(tB(s,am(1))),QE(tB(s,am(2))))})).setLayout({name:"mx_cell_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"float"}]}),tm((([t])=>{const e=lm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar();return mm(QE(tB(s,i,am(0))),QE(tB(s,i,am(1))),QE(tB(s,i,am(2))))})).setLayout({name:"mx_cell_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec2"}]}),tm((([t])=>{const e=mm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar(),r=am(UE(e.z)).toVar();return mm(QE(tB(s,i,r,am(0))),QE(tB(s,i,r,am(1))),QE(tB(s,i,r,am(2))))})).setLayout({name:"mx_cell_noise_vec3_2",type:"vec3",inputs:[{name:"p",type:"vec3"}]}),tm((([t])=>{const e=xm(t).toVar(),s=am(UE(e.x)).toVar(),i=am(UE(e.y)).toVar(),r=am(UE(e.z)).toVar(),n=am(UE(e.w)).toVar();return mm(QE(tB(s,i,r,n,am(0))),QE(tB(s,i,r,n,am(1))),QE(tB(s,i,r,n,am(2))))})).setLayout({name:"mx_cell_noise_vec3_3",type:"vec3",inputs:[{name:"p",type:"vec4"}]})]),oB=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=am(e).toVar(),a=mm(t).toVar(),h=om(0).toVar(),u=om(1).toVar();return pv(o,(()=>{h.addAssign(u.mul(sB(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_float",type:"float",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),aB=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=am(e).toVar(),a=mm(t).toVar(),h=mm(0).toVar(),u=om(1).toVar();return pv(o,(()=>{h.addAssign(u.mul(iB(a))),u.mulAssign(r),a.mulAssign(n)})),h})).setLayout({name:"mx_fractal_noise_vec3",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),hB=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=am(e).toVar(),a=mm(t).toVar();return lm(oB(a,o,n,r),oB(a.add(mm(am(19),am(193),am(17))),o,n,r))})).setLayout({name:"mx_fractal_noise_vec2",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),uB=tm((([t,e,s,i])=>{const r=om(i).toVar(),n=om(s).toVar(),o=am(e).toVar(),a=mm(t).toVar(),h=mm(aB(a,o,n,r)).toVar(),u=om(oB(a.add(mm(am(19),am(193),am(17))),o,n,r)).toVar();return xm(h,u)})).setLayout({name:"mx_fractal_noise_vec4",type:"vec4",inputs:[{name:"p",type:"vec3"},{name:"octaves",type:"int"},{name:"lacunarity",type:"float"},{name:"diminish",type:"float"}]}),lB=tm((([t,e,s,i,r,n,o])=>{const a=am(o).toVar(),h=om(n).toVar(),u=am(r).toVar(),l=am(i).toVar(),c=am(s).toVar(),d=am(e).toVar(),p=lm(t).toVar(),m=mm(nB(lm(d.add(l),c.add(u)))).toVar(),g=lm(m.x,m.y).toVar();g.subAssign(.5),g.mulAssign(h),g.addAssign(.5);const f=lm(lm(om(d),om(c)).add(g)).toVar(),y=lm(f.sub(p)).toVar();return im(a.equal(am(2)),(()=>ay(y.x).add(ay(y.y)))),im(a.equal(am(3)),(()=>_y(ay(y.x),ay(y.y)))),Ry(y,y)})).setLayout({name:"mx_worley_distance_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),cB=hw([lB,tm((([t,e,s,i,r,n,o,a,h])=>{const u=am(h).toVar(),l=om(a).toVar(),c=am(o).toVar(),d=am(n).toVar(),p=am(r).toVar(),m=am(i).toVar(),g=am(s).toVar(),f=am(e).toVar(),y=mm(t).toVar(),x=mm(nB(mm(f.add(p),g.add(d),m.add(c)))).toVar();x.subAssign(.5),x.mulAssign(l),x.addAssign(.5);const b=mm(mm(om(f),om(g),om(m)).add(x)).toVar(),v=mm(b.sub(y)).toVar();return im(u.equal(am(2)),(()=>ay(v.x).add(ay(v.y)).add(ay(v.z)))),im(u.equal(am(3)),(()=>_y(_y(ay(v.x),ay(v.y)),ay(v.z)))),Ry(v,v)})).setLayout({name:"mx_worley_distance_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"x",type:"int"},{name:"y",type:"int"},{name:"z",type:"int"},{name:"xoff",type:"int"},{name:"yoff",type:"int"},{name:"zoff",type:"int"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),dB=tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=lm(t).toVar(),o=am().toVar(),a=am().toVar(),h=lm(zE(n.x,o),zE(n.y,a)).toVar(),u=om(1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{const s=om(cB(h,t,e,o,a,r,i)).toVar();u.assign(Ty(u,s))}))})),im(i.equal(am(0)),(()=>{u.assign(Yf(u))})),u})).setLayout({name:"mx_worley_noise_float_0",type:"float",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),pB=tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=lm(t).toVar(),o=am().toVar(),a=am().toVar(),h=lm(zE(n.x,o),zE(n.y,a)).toVar(),u=lm(1e6,1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{const s=om(cB(h,t,e,o,a,r,i)).toVar();im(s.lessThan(u.x),(()=>{u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.y.assign(s)}))}))})),im(i.equal(am(0)),(()=>{u.assign(Yf(u))})),u})).setLayout({name:"mx_worley_noise_vec2_0",type:"vec2",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),mB=tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=lm(t).toVar(),o=am().toVar(),a=am().toVar(),h=lm(zE(n.x,o),zE(n.y,a)).toVar(),u=mm(1e6,1e6,1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{const s=om(cB(h,t,e,o,a,r,i)).toVar();im(s.lessThan(u.x),(()=>{u.z.assign(u.y),u.y.assign(u.x),u.x.assign(s)})).elseif(s.lessThan(u.y),(()=>{u.z.assign(u.y),u.y.assign(s)})).elseif(s.lessThan(u.z),(()=>{u.z.assign(s)}))}))})),im(i.equal(am(0)),(()=>{u.assign(Yf(u))})),u})).setLayout({name:"mx_worley_noise_vec3_0",type:"vec3",inputs:[{name:"p",type:"vec2"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]}),gB=hw([dB,tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=mm(t).toVar(),o=am().toVar(),a=am().toVar(),h=am().toVar(),u=mm(zE(n.x,o),zE(n.y,a),zE(n.z,h)).toVar(),l=om(1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{pv({start:-1,end:am(1),name:"z",condition:"<="},(({z:s})=>{const n=om(cB(u,t,e,s,o,a,h,r,i)).toVar();l.assign(Ty(l,n))}))}))})),im(i.equal(am(0)),(()=>{l.assign(Yf(l))})),l})).setLayout({name:"mx_worley_noise_float_1",type:"float",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),fB=hw([pB,tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=mm(t).toVar(),o=am().toVar(),a=am().toVar(),h=am().toVar(),u=mm(zE(n.x,o),zE(n.y,a),zE(n.z,h)).toVar(),l=lm(1e6,1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{pv({start:-1,end:am(1),name:"z",condition:"<="},(({z:s})=>{const n=om(cB(u,t,e,s,o,a,h,r,i)).toVar();im(n.lessThan(l.x),(()=>{l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.y.assign(n)}))}))}))})),im(i.equal(am(0)),(()=>{l.assign(Yf(l))})),l})).setLayout({name:"mx_worley_noise_vec2_1",type:"vec2",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),yB=hw([mB,tm((([t,e,s])=>{const i=am(s).toVar(),r=om(e).toVar(),n=mm(t).toVar(),o=am().toVar(),a=am().toVar(),h=am().toVar(),u=mm(zE(n.x,o),zE(n.y,a),zE(n.z,h)).toVar(),l=mm(1e6,1e6,1e6).toVar();return pv({start:-1,end:am(1),name:"x",condition:"<="},(({x:t})=>{pv({start:-1,end:am(1),name:"y",condition:"<="},(({y:e})=>{pv({start:-1,end:am(1),name:"z",condition:"<="},(({z:s})=>{const n=om(cB(u,t,e,s,o,a,h,r,i)).toVar();im(n.lessThan(l.x),(()=>{l.z.assign(l.y),l.y.assign(l.x),l.x.assign(n)})).elseif(n.lessThan(l.y),(()=>{l.z.assign(l.y),l.y.assign(n)})).elseif(n.lessThan(l.z),(()=>{l.z.assign(n)}))}))}))})),im(i.equal(am(0)),(()=>{l.assign(Yf(l))})),l})).setLayout({name:"mx_worley_noise_vec3_1",type:"vec3",inputs:[{name:"p",type:"vec3"},{name:"jitter",type:"float"},{name:"metric",type:"int"}]})]),xB=tm((([t])=>{const e=mm(t).toVar(),s=om(e.x).toVar(),i=om(e.y).toVar(),r=om(e.z).toVar();im(i.lessThan(1e-4),(()=>mm(r,r,r))).else((()=>{s.assign(ff(6,s.sub(Zf(s))));const t=am(fy(s)).toVar(),e=om(s.sub(om(t))).toVar(),n=om(r.mul(gf(1,i))).toVar(),o=om(r.mul(gf(1,i.mul(e)))).toVar(),a=om(r.mul(gf(1,i.mul(gf(1,e))))).toVar();return im(t.equal(am(0)),(()=>mm(r,a,n))).elseif(t.equal(am(1)),(()=>mm(o,r,n))).elseif(t.equal(am(2)),(()=>mm(n,r,a))).elseif(t.equal(am(3)),(()=>mm(n,o,r))).elseif(t.equal(am(4)),(()=>mm(a,n,r))),mm(r,n,o)}))})).setLayout({name:"mx_hsvtorgb",type:"vec3",inputs:[{name:"hsv",type:"vec3"}]}),bB=tm((([t])=>{const e=mm(t).toVar(),s=om(e.x).toVar(),i=om(e.y).toVar(),r=om(e.z).toVar(),n=om(Ty(s,Ty(i,r))).toVar(),o=om(_y(s,_y(i,r))).toVar(),a=om(o.sub(n)).toVar(),h=om().toVar(),u=om().toVar(),l=om().toVar();return l.assign(o),im(o.greaterThan(0),(()=>{u.assign(a.div(o))})).else((()=>{u.assign(0)})),im(u.lessThanEqual(0),(()=>{h.assign(0)})).else((()=>{im(s.greaterThanEqual(o),(()=>{h.assign(i.sub(r).div(a))})).elseif(i.greaterThanEqual(o),(()=>{h.assign(mf(2,r.sub(s).div(a)))})).else((()=>{h.assign(mf(4,s.sub(i).div(a)))})),h.mulAssign(1/6),im(h.lessThan(0),(()=>{h.addAssign(1)}))})),mm(h,u,l)})).setLayout({name:"mx_rgbtohsv",type:"vec3",inputs:[{name:"c",type:"vec3"}]}),vB=tm((([t])=>{const e=mm(t).toVar(),s=ym(_f(e,mm(.04045))).toVar(),i=mm(e.div(12.92)).toVar(),r=mm(Ey(_y(e.add(mm(.055)),mm(0)).div(1.055),mm(2.4))).toVar();return Oy(i,r,s)})).setLayout({name:"mx_srgb_texture_to_lin_rec709",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),TB=(t,e)=>{t=om(t),e=om(e);const s=lm(e.dFdx(),e.dFdy()).length().mul(.7071067811865476);return ky(t.sub(s),t.add(s),e)},_B=(t,e,s,i)=>Oy(t,e,s[i].clamp()),wB=(t,e,s=lf())=>_B(t,e,s,"x"),SB=(t,e,s=lf())=>_B(t,e,s,"y"),MB=(t,e,s,i,r)=>Oy(t,e,TB(s,i[r])),AB=(t,e,s,i=lf())=>MB(t,e,s,i,"x"),NB=(t,e,s,i=lf())=>MB(t,e,s,i,"y"),RB=(t=1,e=0,s=lf())=>s.mul(t).add(e),CB=(t,e=1)=>(t=om(t)).abs().pow(e).mul(t.sign()),EB=(t,e=1,s=.5)=>om(t).sub(s).mul(e).add(s),BB=(t=lf(),e=1,s=0)=>sB(t.convert("vec2|vec3")).mul(e).add(s),IB=(t=lf(),e=1,s=0)=>iB(t.convert("vec2|vec3")).mul(e).add(s),PB=(t=lf(),e=1,s=0)=>{t=t.convert("vec2|vec3");return xm(iB(t),sB(t.add(lm(19,73)))).mul(e).add(s)},FB=(t=lf(),e=1)=>gB(t.convert("vec2|vec3"),e,am(1)),UB=(t=lf(),e=1)=>fB(t.convert("vec2|vec3"),e,am(1)),zB=(t=lf(),e=1)=>yB(t.convert("vec2|vec3"),e,am(1)),OB=(t=lf())=>rB(t.convert("vec2|vec3")),LB=(t=lf(),e=3,s=2,i=.5,r=1)=>oB(t,am(e),s,i).mul(r),VB=(t=lf(),e=3,s=2,i=.5,r=1)=>hB(t,am(e),s,i).mul(r),DB=(t=lf(),e=3,s=2,i=.5,r=1)=>aB(t,am(e),s,i).mul(r),kB=(t=lf(),e=3,s=2,i=.5,r=1)=>uB(t,am(e),s,i).mul(r);function GB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function WB(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}class jB{constructor(){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparent=[],this.bundles=[],this.lightsNode=new Uv([]),this.lightsArray=[],this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(t,e,s,i,r,n){let o=this.renderItems[this.renderItemsIndex];return void 0===o?(o={id:t.id,object:t,geometry:e,material:s,groupOrder:i,renderOrder:t.renderOrder,z:r,group:n},this.renderItems[this.renderItemsIndex]=o):(o.id=t.id,o.object=t,o.geometry=e,o.material=s,o.groupOrder=i,o.renderOrder=t.renderOrder,o.z=r,o.group=n),this.renderItemsIndex++,o}push(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);!0===t.occlusionTest&&this.occlusionQueryCount++,(!0===s.transparent||s.transmission>0?this.transparent:this.opaque).push(o)}unshift(t,e,s,i,r,n){const o=this.getNextRenderItem(t,e,s,i,r,n);(!0===s.transparent?this.transparent:this.opaque).unshift(o)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}getLightsNode(){return this.lightsNode.fromLights(this.lightsArray)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||GB),this.transparent.length>1&&this.transparent.sort(e||WB)}finish(){this.lightsNode.fromLights(this.lightsArray);for(let t=this.renderItemsIndex,e=this.renderItems.length;t<e;t++){const e=this.renderItems[t];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.groupOrder=null,e.renderOrder=null,e.z=null,e.group=null}}}class HB{constructor(){this.lists=new wd}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new jB,s.set(i,r)),r}dispose(){this.lists=new wd}}let qB=0;class $B{constructor(){this.id=qB++,this.color=!0,this.clearColor=!0,this.clearColorValue={r:0,g:0,b:0,a:1},this.depth=!0,this.clearDepth=!0,this.clearDepthValue=1,this.stencil=!1,this.clearStencil=!0,this.clearStencilValue=1,this.viewport=!1,this.viewportValue=new _i,this.scissor=!1,this.scissorValue=new _i,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}}class XB{constructor(){this.chainMaps={}}get(t,e,s=null){const i=[t,e];let r;if(null===s)r="default";else{const t=s.texture.format;r=`${s.textures.length}:${t}:${s.samples}:${s.depthBuffer}:${s.stencilBuffer}`}const n=this.getChainMap(r);let o=n.get(i);return void 0===o&&(o=new $B,n.set(i,o)),null!==s&&(o.sampleCount=0===s.samples?1:s.samples),o}getChainMap(t){return this.chainMaps[t]||(this.chainMaps[t]=new wd)}dispose(){this.chainMaps={}}}const YB=new Ei;class JB extends Ed{constructor(t,e,s){super(),this.renderer=t,this.backend=e,this.info=s}updateRenderTarget(t,e=0){const s=this.get(t),i=0===t.samples?1:t.samples,r=s.depthTextureMips||(s.depthTextureMips={}),n=t.texture,o=t.textures,a=this.getSize(n),h=a.width>>e,u=a.height>>e;let l=t.depthTexture||r[e],c=!1;void 0===l&&(l=new Ka,l.format=t.stencilBuffer?jt:Wt,l.type=t.stencilBuffer?zt:Bt,l.image.width=h,l.image.height=u,r[e]=l),s.width===a.width&&a.height===s.height||(c=!0,l.needsUpdate=!0,l.image.width=h,l.image.height=u),s.width=a.width,s.height=a.height,s.textures=o,s.depthTexture=l,s.depth=t.depthBuffer,s.stencil=t.stencilBuffer,s.renderTarget=t,s.sampleCount!==i&&(c=!0,l.needsUpdate=!0,s.sampleCount=i);const d={sampleCount:i};for(let t=0;t<o.length;t++){const e=o[t];c&&(e.needsUpdate=!0),this.updateTexture(e,d)}if(this.updateTexture(l,d),!0!==s.initialized){s.initialized=!0;const e=()=>{if(t.removeEventListener("dispose",e),void 0!==o)for(let t=0;t<o.length;t++)this._destroyTexture(o[t]);else this._destroyTexture(n);this._destroyTexture(l),this.delete(t)};t.addEventListener("dispose",e)}}updateTexture(t,e={}){const s=this.get(t);if(!0===s.initialized&&s.version===t.version)return;const i=t.isRenderTargetTexture||t.isDepthTexture||t.isFramebufferTexture,r=this.backend;if(i&&!0===s.initialized&&(r.destroySampler(t),r.destroyTexture(t)),t.isFramebufferTexture){const e=this.renderer.getRenderTarget();t.type=e?e.texture.type:At}const{width:n,height:o,depth:a}=this.getSize(t);if(e.width=n,e.height=o,e.depth=a,e.needsMipmaps=this.needsMipmaps(t),e.levels=e.needsMipmaps?this.getMipLevels(t,n,o):1,i||!0===t.isStorageTexture)r.createSampler(t),r.createTexture(t,e);else{if(!0!==s.initialized&&r.createSampler(t),t.version>0){const i=t.image;if(void 0===i)console.warn("THREE.Renderer: Texture marked for update but image is undefined.");else if(!1===i.complete)console.warn("THREE.Renderer: Texture marked for update but image is incomplete.");else{if(t.images){const s=[];for(const e of t.images)s.push(e);e.images=s}else e.image=i;void 0!==s.isDefaultTexture&&!0!==s.isDefaultTexture||(r.createTexture(t,e),s.isDefaultTexture=!1),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),s.isDefaultTexture=!0}if(!0!==s.initialized){s.initialized=!0,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}s.version=t.version}getSize(t,e=YB){let s=t.images?t.images[0]:t.image;return s?(void 0!==s.image&&(s=s.image),e.width=s.width,e.height=s.height,e.depth=t.isCubeTexture?6:s.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,s){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,s)))+1,i}needsMipmaps(t){return!!this.isEnvironmentTexture(t)||(!0===t.isCompressedTexture||t.minFilter!==ft&&t.minFilter!==Tt)}isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class ZB extends Yr{constructor(t,e,s,i=1){super(t,e,s),this.a=i}set(t,e,s,i=1){return this.a=i,super.set(t,e,s)}copy(t){return void 0!==t.a&&(this.a=t.a),super.copy(t)}clone(){return new this.constructor(this.r,this.g,this.b,this.a)}}const QB=new ZB;class KB extends Ed{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,s){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let n=!1;if(null===r)i._clearColor.getRGB(QB,Ze),QB.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(QB,Ze),QB.a=1,n=!0;else if(!0===r.isNode){const s=this.get(t),n=r;QB.copy(i._clearColor);let o=s.backgroundMesh;if(void 0===o){const t=Jm(xm(n).mul(LS),{getUV:()=>Yx,getTextureLevel:()=>OS});let e=$b();e=e.setZ(e.w);const i=new vT;i.name="Background.material",i.side=d,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,s.backgroundMeshNode=t,s.backgroundMesh=o=new Wn(new fu(1,32,32),i),o.frustumCulled=!1,o.name="Background.mesh",o.onBeforeRender=function(t,e,s){this.matrixWorld.copyPosition(s.matrixWorld)}}const a=n.getCacheKey();s.backgroundCacheKey!==a&&(s.backgroundMeshNode.node=xm(n).mul(LS),o.material.needsUpdate=!0,s.backgroundCacheKey=a),e.unshift(o,o.geometry,o.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===n){QB.multiplyScalar(QB.a);const t=s.clearColorValue;t.r=QB.r,t.g=QB.g,t.b=QB.b,t.a=QB.a,s.depthClearValue=i._clearDepth,s.stencilClearValue=i._clearStencil,s.clearColor=!0===i.autoClearColor,s.clearDepth=!0===i.autoClearDepth,s.clearStencil=!0===i.autoClearStencil}else s.clearColor=!1,s.clearDepth=!1,s.clearStencil=!1}}class tI{constructor(t,e,s,i,r,n,o,a,h=!0,u=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=s,this.transforms=u,this.nodeAttributes=i,this.bindings=r,this.updateNodes=n,this.updateBeforeNodes=o,this.updateAfterNodes=a,this.instanceBindGroups=h,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==(this.instanceBindGroups&&e.bindings[0].groupNode.shared)){const s=new I_(e.name);t.push(s);for(const t of e.bindings)s.bindings.push(t.clone())}else t.push(e)}return t}}const eI=new WeakMap;class sI extends Ed{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new L_,this.nodeBuilderCache=new Map,this.callHashCache=new wd,this.groupsData=new wd}updateGroup(t){const e=t.groupNode,s=e.name;if(s===af.name)return!0;if(s===of.name){const e=this.get(t),s=this.nodeFrame.renderId;return e.renderId!==s&&(e.renderId=s,!0)}if(s===nf.name){const e=this.get(t),s=this.nodeFrame.frameId;return e.frameId!==s&&(e.frameId=s,!0)}const i=[e,t];let r=this.groupsData.get(i);return void 0===r&&this.groupsData.set(i,r={}),r.version!==e.version&&(r.version=e.version,!0)}getForRenderCacheKey(t){return t.initialCacheKey}getForRender(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(s=i.get(r),void 0===s){const e=this.backend.createNodeBuilder(t.object,this.renderer);e.scene=t.scene,e.material=t.material,e.camera=t.camera,e.context.material=t.material,e.lightsNode=t.lightsNode,e.environmentNode=this.getEnvironmentNode(t.scene),e.fogNode=this.getFogNode(t.scene),e.clippingContext=t.clippingContext,e.build(),s=this._createNodeBuilderState(e),i.set(r,s)}s.usedTimes++,e.nodeBuilderState=s}return s}delete(t){if(t.isRenderObject){const e=this.get(t).nodeBuilderState;e.usedTimes--,0===e.usedTimes&&this.nodeBuilderCache.delete(this.getForRenderCacheKey(t))}return super.delete(t)}getForCompute(t){const e=this.get(t);let s=e.nodeBuilderState;if(void 0===s){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),s=this._createNodeBuilderState(i),e.nodeBuilderState=s}return s}_createNodeBuilderState(t){return new tI(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.instanceBindGroups,t.transforms)}getEnvironmentNode(t){return t.environmentNode||this.get(t).environmentNode||null}getBackgroundNode(t){return t.backgroundNode||this.get(t).backgroundNode||null}getFogNode(t){return t.fogNode||this.get(t).fogNode||null}getCacheKey(t,e){const s=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(s);if(void 0===r||r.callId!==i){const n=this.getEnvironmentNode(t),o=this.getFogNode(t),a=[];e&&a.push(e.getCacheKey(!0)),n&&a.push(n.getCacheKey()),o&&a.push(o.getCacheKey()),r={callId:i,cacheKey:a.join(",")},this.callHashCache.set(s,r)}return r.cacheKey}updateScene(t){this.updateEnvironment(t),this.updateFog(t),this.updateBackground(t)}get isToneMappingState(){return!this.renderer.getRenderTarget()}updateBackground(t){const e=this.get(t),s=t.background;if(s){if(e.background!==s){let t=null;!0===s.isCubeTexture||s.mapping===lt||s.mapping===ct?t=qR(s,Yx):!0===s.isTexture?t=nx(s,Jv).setUpdateMatrix(!0):!0!==s.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",s),e.backgroundNode=t,e.background=s}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),s=t.fog;if(s){if(e.fog!==s){let t=null;s.isFogExp2?t=_R(gx("color","color",s),gx("density","float",s)):s.isFog?t=vR(gx("color","color",s),gx("near","float",s),gx("far","float",s)):console.error("WebGPUNodes: Unsupported fog configuration.",s),e.fogNode=t,e.fog=s}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),s=t.environment;if(s){if(e.environment!==s){let t=null;!0===s.isCubeTexture?t=Av(s):!0===s.isTexture?t=nx(s):console.error("Nodes: Unsupported environment configuration.",s),e.environmentNode=t,e.environment=s}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,s=null,i=null,r=null){const n=this.nodeFrame;return n.renderer=t,n.scene=e,n.object=s,n.camera=i,n.material=r,n}getNodeFrameForRender(t){return this.getNodeFrame(t.renderer,t.scene,t.object,t.camera,t.material)}getOutputCacheKey(){const t=this.renderer;return t.toneMapping+","+t.currentColorSpace}hasOutputChange(t){return eI.get(t)!==this.getOutputCacheKey()}getOutputNode(t){const e=this.renderer,s=this.getOutputCacheKey(),i=nx(t,Yv).renderOutput(e.toneMapping,e.currentColorSpace);return eI.set(t,s),i}updateBefore(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateBeforeNodes)e.updateBeforeNode(t)}updateAfter(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateAfterNodes)e.updateAfterNode(t)}updateForCompute(t){const e=this.getNodeFrame(),s=this.getForCompute(t);for(const t of s.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),s=t.getNodeBuilderState();for(const t of s.updateNodes)e.updateNode(t)}dispose(){super.dispose(),this.nodeFrame=new L_,this.nodeBuilderCache=new Map}}class iI{constructor(t,e){this.scene=t,this.camera=e}clone(){return Object.assign(new this.constructor,this)}}class rI{constructor(){this.lists=new wd}get(t,e){const s=this.lists,i=[t,e];let r=s.get(i);return void 0===r&&(r=new iI(t,e),s.set(i,r)),r}dispose(){this.lists=new wd}}const nI=new no,oI=new Ks,aI=new _i,hI=new na,uI=new or,lI=new Ei;class cI{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:s=!1,alpha:i=!0,antialias:r=!1,samples:n=0}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=n||!0===r?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=s,this.outputColorSpace=Je,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=!0,this.stencil=!1,this.clippingPlanes=[],this.info=new Vd,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new _i(0,0,this._width,this._height),this._scissor=new _i(0,0,this._width,this._height),this._scissorTest=!1,this._attributes=null,this._geometries=null,this._nodes=null,this._animation=null,this._bindings=null,this._objects=null,this._pipelines=null,this._bundles=null,this._renderLists=null,this._renderContexts=null,this._textures=null,this._background=null,this._quad=new iS(new vT),this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const o=!0===this.alpha?0:1;this._clearColor=new ZB(0,0,0,o),this._clearDepth=1,this._clearStencil=0,this._renderTarget=null,this._activeCubeFace=0,this._activeMipmapLevel=0,this._mrt=null,this._renderObjectFunction=null,this._currentRenderObjectFunction=null,this._currentRenderBundle=null,this._handleObjectFunction=this._renderObjectDirect,this._initialized=!1,this._initPromise=null,this._compilationPromises=null,this.transparent=!0,this.opaque=!0,this.shadowMap={enabled:!1,type:1},this.xr={enabled:!1},this.debug={checkShaderErrors:!0,onShaderError:null}}async init(){if(this._initialized)throw new Error("Renderer: Backend has already been initialized.");return null!==this._initPromise||(this._initPromise=new Promise((async(t,e)=>{const s=this.backend;try{await s.init(this)}catch(t){return void e(t)}this._nodes=new sI(this,s),this._animation=new _d(this._nodes,this.info),this._attributes=new Ud(s),this._background=new KB(this,this._nodes),this._geometries=new Ld(this._attributes,this.info),this._textures=new JB(this,s,this.info),this._pipelines=new Hd(s,this._nodes),this._bindings=new qd(s,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new Cd(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new HB,this._bundles=new rI,this._renderContexts=new XB,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,s=null){!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,n=this._currentRenderContext,o=this._currentRenderObjectFunction,a=this._compilationPromises,h=!0===t.isScene?t:nI;null===s&&(s=t);const u=this._renderTarget,l=this._renderContexts.get(s,e,u),c=this._activeMipmapLevel,d=[];this._currentRenderContext=l,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),l.depth=this.depth,l.stencil=this.stencil,l.clippingContext||(l.clippingContext=new Ad),l.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,u);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),s!==t&&s.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==u){this._textures.updateRenderTarget(u,c);const t=this._textures.get(u);l.textures=t.textures,l.depthTexture=t.depthTexture}else l.textures=null,l.depthTexture=null;this._nodes.updateScene(h),this._background.update(h,p,l);const m=p.opaque,g=p.transparent,f=p.lightsNode;!0===this.opaque&&m.length>0&&this._renderObjects(m,e,h,f),!0===this.transparent&&g.length>0&&this._renderObjects(g,e,h,f),i.renderId=r,this._currentRenderContext=n,this._currentRenderObjectFunction=o,this._compilationPromises=a,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const s=this._renderScene(t,e);await this.backend.resolveTimestampAsync(s,"render")}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_renderBundle(t,e,s){const{object:i,camera:r,renderList:n}=t,o=this._currentRenderContext,a=this.backend.get(o),h=this._bundles.get(i,r),u=this.backend.get(h);void 0===u.renderContexts&&(u.renderContexts=new Set);const l=!1===u.renderContexts.has(o)||!0===i.needsUpdate;if(u.renderContexts.add(o),l){if(void 0===a.renderObjects||!0===i.needsUpdate){const t=this._nodes.nodeFrame;a.renderObjects=[],a.renderBundles=[],a.scene=e,a.camera=r,a.renderId=t.renderId,a.registerBundlesPhase=!0}this._currentRenderBundle=h;const t=n.opaque;t.length>0&&this._renderObjects(t,r,e,s),this._currentRenderBundle=null,i.needsUpdate=!1}else{const t=this._currentRenderContext,e=this.backend.get(t);for(let t=0,s=e.renderObjects.length;t<s;t++){const s=e.renderObjects[t];this._nodes.updateBefore(s),s.object.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,s.object.matrixWorld),s.object.normalMatrix.getNormalMatrix(s.object.modelViewMatrix),this._nodes.updateForRender(s),this._bindings.updateForRender(s),this.backend.draw(s,this.info),this._nodes.updateAfter(s)}}}render(t,e){if(!1===this._initialized)return console.warn("THREE.Renderer: .render() called before the backend is initialized. Try using .renderAsync() instead."),this.renderAsync(t,e);this._renderScene(t,e)}_getFrameBufferTarget(){const{currentColorSpace:t}=this,e=null===this._renderTarget&&0!==this.toneMapping,s=null===this._renderTarget&&t!==Ze&&t!==Ye;if(!1===e&&!1===s)return null;const{width:i,height:r}=this.getDrawingBufferSize(oI),{depth:n,stencil:o}=this;let a=this._frameBufferTarget;return null===a&&(a=new wi(i,r,{depthBuffer:n,stencilBuffer:o,type:Pt,format:Dt,colorSpace:Ze,generateMipmaps:!1,minFilter:Tt,magFilter:Tt,samples:this.samples}),a.isPostProcessingRenderTarget=!0,this._frameBufferTarget=a),a.depthBuffer=n,a.stencilBuffer=o,a.setSize(i,r),a.viewport.copy(this._viewport),a.scissor.copy(this._scissor),a.viewport.multiplyScalar(this._pixelRatio),a.scissor.multiplyScalar(this._pixelRatio),a.scissorTest=this._scissorTest,a}_renderScene(t,e,s=!0){const i=s?this._getFrameBufferTarget():null,r=this._nodes.nodeFrame,n=r.renderId,o=this._currentRenderContext,a=this._currentRenderObjectFunction,h=!0===t.isScene?t:nI,u=this._renderTarget,l=this._activeCubeFace,c=this._activeMipmapLevel;let d;null!==i?(d=i,this.setRenderTarget(d)):d=u;const p=this._renderContexts.get(t,e,d);this._currentRenderContext=p,this._currentRenderObjectFunction=this._renderObjectFunction||this.renderObject,this.info.calls++,this.info.render.calls++,this.info.render.frameCalls++,r.renderId=this.info.calls;const m=this.coordinateSystem;e.coordinateSystem!==m&&(e.coordinateSystem=m,e.updateProjectionMatrix()),!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld();let g=this._viewport,f=this._scissor,y=this._pixelRatio;null!==d&&(g=d.viewport,f=d.scissor,y=1),this.getDrawingBufferSize(oI),aI.set(0,0,oI.width,oI.height);const x=void 0===g.minDepth?0:g.minDepth,b=void 0===g.maxDepth?1:g.maxDepth;p.viewportValue.copy(g).multiplyScalar(y).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=x,p.viewportValue.maxDepth=b,p.viewport=!1===p.viewportValue.equals(aI),p.scissorValue.copy(f).multiplyScalar(y).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(aI),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new Ad),p.clippingContext.updateGlobal(this,e),h.onBeforeRender(this,t,e,d),uI.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),hI.setFromProjectionMatrix(uI,m);const v=this._renderLists.get(t,e);if(v.begin(),this._projectObject(t,e,0,v),v.finish(),!0===this.sortObjects&&v.sort(this._opaqueSort,this._transparentSort),null!==d){this._textures.updateRenderTarget(d,c);const t=this._textures.get(d);p.textures=t.textures,p.depthTexture=t.depthTexture,p.width=t.width,p.height=t.height,p.renderTarget=d,p.depth=d.depthBuffer,p.stencil=d.stencilBuffer}else p.textures=null,p.depthTexture=null,p.width=this.domElement.width,p.height=this.domElement.height,p.depth=this.depth,p.stencil=this.stencil;p.width>>=c,p.height>>=c,p.activeCubeFace=l,p.activeMipmapLevel=c,p.occlusionQueryCount=v.occlusionQueryCount,this._nodes.updateScene(h),this._background.update(h,v,p),this.backend.beginRender(p);const T=v.opaque,_=v.transparent,w=v.bundles,S=v.lightsNode;if(w.length>0&&this._renderBundles(w,h,S),!0===this.opaque&&T.length>0&&this._renderObjects(T,e,h,S),!0===this.transparent&&_.length>0&&this._renderObjects(_,e,h,S),this.backend.finishRender(p),r.renderId=n,this._currentRenderContext=o,this._currentRenderObjectFunction=a,null!==i){this.setRenderTarget(u,l,c);const t=this._quad;this._nodes.hasOutputChange(d.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(d.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}return h.onAfterRender(this,t,e,d),p}getMaxAnisotropy(){return this.backend.getMaxAnisotropy()}getActiveCubeFace(){return this._activeCubeFace}getActiveMipmapLevel(){return this._activeMipmapLevel}async setAnimationLoop(t){!1===this._initialized&&await this.init(),this._animation.setAnimationLoop(t)}async getArrayBufferAsync(t){return await this.backend.getArrayBufferAsync(t)}getContext(){return this.backend.getContext()}getPixelRatio(){return this._pixelRatio}getDrawingBufferSize(t){return t.set(this._width*this._pixelRatio,this._height*this._pixelRatio).floor()}getSize(t){return t.set(this._width,this._height)}setPixelRatio(t=1){this._pixelRatio=t,this.setSize(this._width,this._height,!1)}setDrawingBufferSize(t,e,s){this._width=t,this._height=e,this._pixelRatio=s,this.domElement.width=Math.floor(t*s),this.domElement.height=Math.floor(e*s),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,s=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===s&&(this.domElement.style.width=t+"px",this.domElement.style.height=e+"px"),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setOpaqueSort(t){this._opaqueSort=t}setTransparentSort(t){this._transparentSort=t}getScissor(t){const e=this._scissor;return t.x=e.x,t.y=e.y,t.width=e.width,t.height=e.height,t}setScissor(t,e,s,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,s,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,s,i,r=0,n=1){const o=this._viewport;t.isVector4?o.copy(t):o.set(t,e,s,i),o.minDepth=r,o.maxDepth=n}getClearColor(t){return t.copy(this._clearColor)}setClearColor(t,e=1){this._clearColor.set(t),this._clearColor.a=e}getClearAlpha(){return this._clearColor.a}setClearAlpha(t){this._clearColor.a=t}getClearDepth(){return this._clearDepth}setClearDepth(t){this._clearDepth=t}getClearStencil(){return this._clearStencil}setClearStencil(t){this._clearStencil=t}isOccluded(t){const e=this._currentRenderContext;return e&&this.backend.isOccluded(e,t)}clear(t=!0,e=!0,s=!0){if(!1===this._initialized)return console.warn("THREE.Renderer: .clear() called before the backend is initialized. Try using .clearAsync() instead."),this.clearAsync(t,e,s);const i=this._renderTarget||this._getFrameBufferTarget();let r=null;if(null!==i&&(this._textures.updateRenderTarget(i),r=this._textures.get(i)),this.backend.clear(t,e,s,r),null!==i&&null===this._renderTarget){const t=this._quad;this._nodes.hasOutputChange(i.texture)&&(t.material.fragmentNode=this._nodes.getOutputNode(i.texture),t.material.needsUpdate=!0),this._renderScene(t,t.camera,!1)}}clearColor(){return this.clear(!0,!1,!1)}clearDepth(){return this.clear(!1,!0,!1)}clearStencil(){return this.clear(!1,!1,!0)}async clearAsync(t=!0,e=!0,s=!0){!1===this._initialized&&await this.init(),this.clear(t,e,s)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentColorSpace(){const t=this._renderTarget;if(null!==t){const e=t.texture;return(Array.isArray(e)?e[0]:e).colorSpace}return this.outputColorSpace}dispose(){this.info.dispose(),this._animation.dispose(),this._objects.dispose(),this._pipelines.dispose(),this._nodes.dispose(),this._bindings.dispose(),this._renderLists.dispose(),this._renderContexts.dispose(),this._textures.dispose(),this.setRenderTarget(null),this.setAnimationLoop(null)}setRenderTarget(t,e=0,s=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=s}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}async computeAsync(t){!1===this._initialized&&await this.init();const e=this._nodes.nodeFrame,s=e.renderId;this.info.calls++,this.info.compute.calls++,this.info.compute.frameCalls++,e.renderId=this.info.calls;const i=this.backend,r=this._pipelines,n=this._bindings,o=this._nodes,a=Array.isArray(t)?t:[t];if(void 0===a[0]||!0!==a[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of a){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),n.delete(e),o.delete(e)};e.addEventListener("dispose",t),e.onInit({renderer:this})}o.updateForCompute(e),n.updateForCompute(e);const s=n.getForCompute(e),a=r.getForCompute(e,s);i.compute(t,e,s,a)}i.finishCompute(t),await this.backend.resolveTimestampAsync(t,"compute"),e.renderId=s}async hasFeatureAsync(t){return!1===this._initialized&&await this.init(),this.backend.hasFeature(t)}hasFeature(t){return!1===this._initialized?(console.warn("THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead."),!1):this.backend.hasFeature(t)}copyFramebufferToTexture(t){const e=this._currentRenderContext;this._textures.updateTexture(t),this.backend.copyFramebufferToTexture(t,e)}copyTextureToTexture(t,e,s=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,s,i,r)}readRenderTargetPixelsAsync(t,e,s,i,r,n=0){return this.backend.copyTextureToBuffer(t.textures[n],e,s,i,r)}_projectObject(t,e,s,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)s=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)i.pushLight(t);else if(t.isSprite){if(!t.frustumCulled||hI.intersectsSprite(t)){!0===this.sortObjects&&lI.setFromMatrixPosition(t.matrixWorld).applyMatrix4(uI);const e=t.geometry,r=t.material;r.visible&&i.push(t,e,r,s,lI.z,null)}}else if(t.isLineLoop)console.error("THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.");else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||hI.intersectsObject(t))){const e=t.geometry,r=t.material;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),lI.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(uI)),Array.isArray(r)){const n=e.groups;for(let o=0,a=n.length;o<a;o++){const a=n[o],h=r[a.materialIndex];h&&h.visible&&i.push(t,e,h,s,lI.z,a)}}else r.visible&&i.push(t,e,r,s,lI.z,null)}if(!0===t.static){const s=i;(i=this._renderLists.get(t,e)).begin(),s.pushBundle({object:t,camera:e,renderList:i}),i.finish()}const r=t.children;for(let t=0,n=r.length;t<n;t++)this._projectObject(r[t],e,s,i)}_renderBundles(t,e,s){for(const i of t)this._renderBundle(i,e,s)}_renderObjects(t,e,s,i){for(let r=0,n=t.length;r<n;r++){const n=t[r],{object:o,geometry:a,material:h,group:u}=n;if(e.isArrayCamera){const t=e.cameras;for(let e=0,r=t.length;e<r;e++){const r=t[e];if(o.layers.test(r.layers)){const t=r.viewport,e=void 0===t.minDepth?0:t.minDepth,n=void 0===t.maxDepth?1:t.maxDepth,l=this._currentRenderContext.viewportValue;l.copy(t).multiplyScalar(this._pixelRatio).floor(),l.minDepth=e,l.maxDepth=n,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(o,s,r,a,h,u,i)}}}else this._currentRenderObjectFunction(o,s,e,a,h,u,i)}}renderObject(t,e,s,i,r,n,o){let a,h,u;if(t.onBeforeRender(this,e,s,i,r,n),null!==e.overrideMaterial){const t=e.overrideMaterial;r.positionNode&&r.positionNode.isNode&&(a=t.positionNode,t.positionNode=r.positionNode),t.isShadowNodeMaterial&&(t.side=null===r.shadowSide?r.side:r.shadowSide,r.depthNode&&r.depthNode.isNode&&(u=t.depthNode,t.depthNode=r.depthNode),r.shadowNode&&r.shadowNode.isNode&&(h=t.fragmentNode,t.fragmentNode=r.shadowNode),this.localClippingEnabled&&(r.clipShadows?(t.clippingPlanes!==r.clippingPlanes&&(t.clippingPlanes=r.clippingPlanes,t.needsUpdate=!0),t.clipIntersection!==r.clipIntersection&&(t.clipIntersection=r.clipIntersection)):Array.isArray(t.clippingPlanes)&&(t.clippingPlanes=null,t.needsUpdate=!0))),r=t}!0===r.transparent&&2===r.side&&!1===r.forceSinglePass?(r.side=d,this._handleObjectFunction(t,r,e,s,o,n,"backSide"),r.side=c,this._handleObjectFunction(t,r,e,s,o,n),r.side=2):this._handleObjectFunction(t,r,e,s,o,n),void 0!==a&&(e.overrideMaterial.positionNode=a),void 0!==u&&(e.overrideMaterial.depthNode=u),void 0!==h&&(e.overrideMaterial.fragmentNode=h),t.onAfterRender(this,e,s,i,r,n)}_renderObjectDirect(t,e,s,i,r,n,o){const a=this._objects.get(t,e,s,i,r,this._currentRenderContext,o);if(a.drawRange=n||t.geometry.drawRange,this._nodes.updateBefore(a),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),this._nodes.updateForRender(a),this._geometries.updateForRender(a),this._bindings.updateForRender(a),this._pipelines.updateForRender(a),null!==this._currentRenderBundle&&!0===this._currentRenderBundle.needsUpdate){const t=this.backend.get(a);t.bundleEncoder=void 0,t.lastPipelineGPU=void 0}if(this.backend.draw(a,this.info),null!==this._currentRenderBundle){this.backend.get(this._currentRenderContext).renderObjects.push(a)}this._nodes.updateAfter(a)}_createObjectPipeline(t,e,s,i,r,n){const o=this._objects.get(t,e,s,i,r,this._currentRenderContext,n);this._nodes.updateBefore(o),this._nodes.updateForRender(o),this._geometries.updateForRender(o),this._bindings.updateForRender(o),this._pipelines.getForRender(o,this._compilationPromises),this._nodes.updateAfter(o)}get compute(){return this.computeAsync}get compile(){return this.compileAsync}}class dI{constructor(t=""){this.name=t,this.visibility=0}setVisibility(t){this.visibility|=t}clone(){return Object.assign(new this.constructor,this)}}class pI extends dI{constructor(t,e=null){super(t),this.isBuffer=!0,this.bytesPerElement=Float32Array.BYTES_PER_ELEMENT,this._buffer=e}get byteLength(){return(t=this._buffer.byteLength)+(Fd-t%Fd)%Fd;var t}get buffer(){return this._buffer}update(){return!0}}class mI extends pI{constructor(t,e=null){super(t,e),this.isUniformBuffer=!0}}let gI=0;class fI extends mI{constructor(t,e){super("UniformBuffer_"+gI++,t?t.value:null),this.nodeUniform=t,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class yI extends mI{constructor(t){super(t),this.isUniformsGroup=!0,this._values=null,this.uniforms=[]}addUniform(t){return this.uniforms.push(t),this}removeUniform(t){const e=this.uniforms.indexOf(t);return-1!==e&&this.uniforms.splice(e,1),this}get values(){return null===this._values&&(this._values=Array.from(this.buffer)),this._values}get buffer(){let t=this._buffer;if(null===t){const e=this.byteLength;t=new Float32Array(new ArrayBuffer(e)),this._buffer=t}return t}get byteLength(){let t=0;for(let e=0,s=this.uniforms.length;e<s;e++){const s=this.uniforms[e],{boundary:i,itemSize:r}=s,n=t%Fd;0!==n&&Fd-n-i<0?t+=Fd-n:n%i!=0&&(t+=n%i),s.offset=t/this.bytesPerElement,t+=r*this.bytesPerElement}return Math.ceil(t/Fd)*Fd}update(){let t=!1;for(const e of this.uniforms)!0===this.updateByType(e)&&(t=!0);return t}updateByType(t){return t.isNumberUniform?this.updateNumber(t):t.isVector2Uniform?this.updateVector2(t):t.isVector3Uniform?this.updateVector3(t):t.isVector4Uniform?this.updateVector4(t):t.isColorUniform?this.updateColor(t):t.isMatrix3Uniform?this.updateMatrix3(t):t.isMatrix4Uniform?this.updateMatrix4(t):void console.error("THREE.WebGPUUniformsGroup: Unsupported uniform type.",t)}updateNumber(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r]!==i){this.buffer[r]=s[r]=i,e=!0}return e}updateVector2(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,e=!0}return e}updateVector3(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,t[r+2]=s[r+2]=i.z,e=!0}return e}updateVector4(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.x||s[r+1]!==i.y||s[r+2]!==i.z||s[r+4]!==i.w){const t=this.buffer;t[r+0]=s[r+0]=i.x,t[r+1]=s[r+1]=i.y,t[r+2]=s[r+2]=i.z,t[r+3]=s[r+3]=i.w,e=!0}return e}updateColor(t){let e=!1;const s=this.values,i=t.getValue(),r=t.offset;if(s[r+0]!==i.r||s[r+1]!==i.g||s[r+2]!==i.b){const t=this.buffer;t[r+0]=s[r+0]=i.r,t[r+1]=s[r+1]=i.g,t[r+2]=s[r+2]=i.b,e=!0}return e}updateMatrix3(t){let e=!1;const s=this.values,i=t.getValue().elements,r=t.offset;if(s[r+0]!==i[0]||s[r+1]!==i[1]||s[r+2]!==i[2]||s[r+4]!==i[3]||s[r+5]!==i[4]||s[r+6]!==i[5]||s[r+8]!==i[6]||s[r+9]!==i[7]||s[r+10]!==i[8]){const t=this.buffer;t[r+0]=s[r+0]=i[0],t[r+1]=s[r+1]=i[1],t[r+2]=s[r+2]=i[2],t[r+4]=s[r+4]=i[3],t[r+5]=s[r+5]=i[4],t[r+6]=s[r+6]=i[5],t[r+8]=s[r+8]=i[6],t[r+9]=s[r+9]=i[7],t[r+10]=s[r+10]=i[8],e=!0}return e}updateMatrix4(t){let e=!1;const s=this.values,i=t.getValue().elements,r=t.offset;if(!1===function(t,e,s){for(let i=0,r=e.length;i<r;i++)if(t[s+i]!==e[i])return!1;return!0}(s,i,r)){this.buffer.set(i,r),function(t,e,s){for(let i=0,r=e.length;i<r;i++)t[s+i]=e[i]}(s,i,r),e=!0}return e}}let xI=0;class bI extends yI{constructor(t,e){super(t),this.id=xI++,this.groupNode=e,this.isNodeUniformsGroup=!0}getNodes(){const t=[];for(const e of this.uniforms){const s=e.nodeUniform.node;if(!s)throw new Error("NodeUniformsGroup: Uniform has no node.");t.push(s)}return t}}let vI=0;class TI extends dI{constructor(t,e){super(t),this.id=vI++,this.texture=e,this.version=e?e.version:0,this.store=!1,this.isSampledTexture=!0}get needsBindingsUpdate(){const{texture:t,version:e}=this;return!!t.isVideoTexture||e!==t.version}update(){const{texture:t,version:e}=this;return e!==t.version&&(this.version=t.version,!0)}}class _I extends TI{constructor(t,e,s,i=null){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s,this.access=i}get needsBindingsUpdate(){return this.textureNode.value!==this.texture||super.needsBindingsUpdate}update(){const{textureNode:t}=this;return this.texture!==t.value?(this.texture=t.value,!0):super.update()}}class wI extends _I{constructor(t,e,s,i){super(t,e,s,i),this.isSampledCubeTexture=!0}}class SI extends _I{constructor(t,e,s,i){super(t,e,s,i),this.isSampledTexture3D=!0}}const MI={[Uf.ATAN2]:"atan",textureDimensions:"textureSize",equals:"equal"},AI={low:"lowp",medium:"mediump",high:"highp"},NI={swizzleAssign:!0,storageBuffer:!1},RI="\nprecision highp float;\nprecision highp int;\nprecision highp sampler2D;\nprecision highp sampler3D;\nprecision highp samplerCube;\nprecision highp sampler2DArray;\n\nprecision highp usampler2D;\nprecision highp usampler3D;\nprecision highp usamplerCube;\nprecision highp usampler2DArray;\n\nprecision highp isampler2D;\nprecision highp isampler3D;\nprecision highp isamplerCube;\nprecision highp isampler2DArray;\n\nprecision lowp sampler2DShadow;\n";class CI extends O_{constructor(t,e){super(t,e,new IE),this.uniformGroups={},this.transforms=[],this.instanceBindGroups=!1}getMethod(t){return MI[t]||t}getOutputStructName(){return""}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(this.getType(t.type)+" "+t.name);return`${this.getType(e.type)} ${e.name}( ${i.join(", ")} ) {\n\n\t${s.vars}\n\n${s.code}\n\treturn ${s.result};\n\n}`}setupPBO(t){const e=t.value;if(void 0===e.pbo){const t=e.array,s=e.count*e.itemSize,{itemSize:i}=e,r=e.array.constructor.name.toLowerCase().includes("int");let n=r?qt:Ht;2===i?n=r?Xt:$t:3===i?n=r?1032:Vt:4===i&&(n=r?Jt:Dt);const o={Float32Array:It,Uint8Array:At,Uint16Array:Ct,Uint32Array:Bt,Int8Array:Nt,Int16Array:Rt,Int32Array:Et,Uint8ClampedArray:At},a=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(s/i))));let h=Math.ceil(s/i/a);a*h*i<s&&h++;const u=a*h*i,l=new t.constructor(u);l.set(t,0),e.array=l;const c=new Do(e.array,a,h,n,o[e.array.constructor.name]||It);c.needsUpdate=!0,c.isPBOTexture=!0;const d=new rx(c,null,null);d.setPrecision("high"),e.pboNode=d,e.pbo=d.value,this.getUniformFromNode(e.pboNode,"texture",this.shaderStage,this.context.label)}}getPropertyName(t,e=this.shaderStage){return t.isNodeUniform&&!0!==t.node.isTextureNode&&!0!==t.node.isBufferNode?e.charAt(0)+"_"+t.name:super.getPropertyName(t,e)}generatePBO(t){const{node:e,indexNode:s}=t,i=e.value;if(this.renderer.backend.has(i)){this.renderer.backend.get(i).pbo=i.pbo}const r=this.getUniformFromNode(i.pboNode,"texture",this.shaderStage,this.context.label),n=this.getPropertyName(r);s.increaseUsage(this);const o=s.build(this,"uint"),a=this.getDataFromNode(t);let h=a.propertyName;if(void 0===h){const s=this.getVarFromNode(t);h=this.getPropertyName(s);const r=this.getDataFromNode(e);let u=r.propertySizeName;void 0===u&&(u=h+"Size",this.getVarFromNode(e,u,"uint"),this.addLineFlowCode(`${u} = uint( textureSize( ${n}, 0 ).x )`),r.propertySizeName=u);const{itemSize:l}=i,c="."+Kd.join("").slice(0,l),d=`ivec2(${o} % ${u}, ${o} / ${u})`,p=this.generateTextureLoad(null,n,d,null,"0");let m="vec4";i.pbo.type===Bt?m="uvec4":i.pbo.type===Et&&(m="ivec4"),this.addLineFlowCode(`${h} = ${m}(${p})${c}`),a.propertyName=h}return h}generateTextureLoad(t,e,s,i,r="0"){return i?`texelFetch( ${e}, ivec3( ${s}, ${i} ), ${r} )`:`texelFetch( ${e}, ${s}, ${r} )`}generateTexture(t,e,s,i){return t.isDepthTexture?`texture( ${e}, ${s} ).x`:(i&&(s=`vec3( ${s}, ${i} )`),`texture( ${e}, ${s} )`)}generateTextureLevel(t,e,s,i){return`textureLod( ${e}, ${s}, ${i} )`}generateTextureBias(t,e,s,i){return`texture( ${e}, ${s}, ${i} )`}generateTextureGrad(t,e,s,i){return`textureGrad( ${e}, ${s}, ${i[0]}, ${i[1]} )`}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`texture( ${e}, vec3( ${s}, ${i} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`${this.getVar(t.type,t.name)};`);return e.join("\n\t")}getUniforms(t){const e=this.uniforms[t],s=[],i={};for(const r of e){let e=null,n=!1;if("texture"===r.type){const t=r.node.value;let s="";!0===t.isDataTexture&&(t.type===Bt?s="u":t.type===Et&&(s="i")),e=t.compareFunction?`sampler2DShadow ${r.name};`:!0===t.isDataArrayTexture?`${s}sampler2DArray ${r.name};`:`${s}sampler2D ${r.name};`}else if("cubeTexture"===r.type)e=`samplerCube ${r.name};`;else if("texture3D"===r.type)e=`sampler3D ${r.name};`;else if("buffer"===r.type){const t=r.node,s=this.getType(t.bufferType),i=t.bufferCount,n=i>0?i:"";e=`${t.name} {\n\t${s} ${r.name}[${n}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,n=!0}const o=r.node.precision;if(null!==o&&(e=AI[o]+" "+e),n){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,s.push(e)}let r="";for(const e in i){const s=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,s.join("\n"))+"\n"}return r+=s.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==Et){let s=t;t.isInterleavedBufferAttribute&&(s=t.data);const i=s.array;!1==(i instanceof Uint32Array||i instanceof Int32Array)&&(e=e.slice(1))}return e}getAttributes(t){let e="";if("vertex"===t||"compute"===t){const t=this.getAttributesArray();let s=0;for(const i of t)e+=`layout( location = ${s++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t<s.length;t++){const i=s[t];e.push(`layout( location = ${t} ) out ${i} m${t};`)}return e.join("\n")}getStructs(t){const e=[],s=this.structs[t];if(0===s.length)return"layout( location = 0 ) out vec4 fragColor;\n";for(let t=0,i=s.length;t<i;t++){const i=s[t];let r="\n";r+=this.getStructMembers(i),r+="\n",e.push(r)}return e.join("\n\n")}getVaryings(t){let e="";const s=this.varyings;if("vertex"===t||"compute"===t)for(const i of s){"compute"===t&&(i.needsInterpolation=!0);const s=i.type;e+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}${i.needsInterpolation?"out":"/*out*/"} ${s} ${i.name};\n`}else if("fragment"===t)for(const t of s)if(t.needsInterpolation){const s=t.type;e+=`${s.includes("int")||s.includes("uv")||s.includes("iv")?"flat ":""}in ${s} ${t.name};\n`}return e}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord"}getFragDepth(){return"gl_FragDepth"}getExtensions(t){let e="";if("vertex"===t){const t=this.renderer.backend.extensions;this.object.isBatchedMesh&&t.has("WEBGL_multi_draw")&&(e+="#extension GL_ANGLE_multi_draw : require\n")}return e}isAvailable(t){let e=NI[t];if(void 0===e){if("float32Filterable"===t){const t=this.renderer.backend.extensions;t.has("OES_texture_float_linear")?(t.get("OES_texture_float_linear"),e=!0):e=!1}NI[t]=e}return e}isFlipY(){return!0}registerTransform(t,e){this.transforms.push({varyingName:t,attributeNode:e})}getTransforms(){const t=this.transforms;let e="";for(let s=0;s<t.length;s++){const i=t[s],r=this.getPropertyName(i.attributeNode);e+=`${i.varyingName} = ${r};\n\t`}return e}_getGLSLUniformStruct(t,e){return`\nlayout( std140 ) uniform ${t} {\n${e}\n};`}_getGLSLVertexCode(t){return`#version 300 es\n\n// extensions \n${t.extensions}\n\n// precision\n${RI}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\n\n// attributes\n${t.attributes}\n\n// codes\n${t.codes}\n\nvoid main() {\n\n\t// vars\n\t${t.vars}\n\n\t// transforms\n\t${t.transforms}\n\n\t// flow\n\t${t.flow}\n\n\tgl_PointSize = 1.0;\n\n}\n`}_getGLSLFragmentCode(t){return`#version 300 es\n\n${this.getSignature()}\n\n// precision\n${RI}\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\n\n// codes\n${t.codes}\n\n${t.structs}\n\nvoid main() {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(const e in t){let s="// code\n\n";s+=this.flowCode[e];const i=this.flowNodes[e],r=i[i.length-1];for(const t of i){const i=this.getFlowData(t),n=t.name;n&&(s.length>0&&(s+="\n"),s+=`\t// flow -> ${n}\n\t`),s+=`${i.code}\n\t`,t===r&&"compute"!==e&&(s+="// result\n\t","vertex"===e?(s+="gl_Position = ",s+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(s+="fragColor = ",s+=`${i.result};`)))}const n=t[e];n.extensions=this.getExtensions(e),n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.vars=this.getVars(e),n.structs=this.getStructs(e),n.codes=this.getCodes(e),n.transforms=this.getTransforms(e),n.flow=s}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);let o=n.uniformGPU;if(void 0===o){const i=t.groupNode,a=i.name,h=this.getBindGroupArray(a,s);if("texture"===e)o=new _I(r.name,r.node,i),h.push(o);else if("cubeTexture"===e)o=new wI(r.name,r.node,i),h.push(o);else if("texture3D"===e)o=new SI(r.name,r.node,i),h.push(o);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new fI(t,i);e.name=t.name,h.push(e),o=e}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new bI(s+"_"+a,i),t[a]=n,h.push(n)),o=this.getNodeUniform(r,e),n.addUniform(o)}n.uniformGPU=o}return r}}let EI=null,BI=null,II=null;class PI{constructor(t={}){this.parameters=Object.assign({},t),this.data=new WeakMap,this.renderer=null,this.domElement=null}async init(t){this.renderer=t}begin(){}finish(){}draw(){}createProgram(){}destroyProgram(){}createBindings(){}updateBindings(){}createRenderPipeline(){}createComputePipeline(){}destroyPipeline(){}needsRenderUpdate(){}getRenderCacheKey(){}createNodeBuilder(){}createSampler(){}createDefaultTexture(){}createTexture(){}copyTextureToBuffer(){}createAttribute(){}createIndexAttribute(){}updateAttribute(){}destroyAttribute(){}getContext(){}updateSize(){}resolveTimestampAsync(){}hasFeatureAsync(){}hasFeature(){}getInstanceCount(t){const{object:e,geometry:s}=t;return s.isInstancedBufferGeometry?s.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return EI=EI||new Ks,this.renderer.getDrawingBufferSize(EI)}getScissor(){return BI=BI||new _i,this.renderer.getScissor(BI)}setScissorTest(){}getClearColor(){const t=this.renderer;return II=II||new ZB,t.getClearColor(II),II.getRGB(II,this.renderer.currentColorSpace),II}getDomElement(){let e=this.domElement;return null===e&&(e=void 0!==this.parameters.canvas?this.parameters.canvas:ni(),"setAttribute"in e&&e.setAttribute("data-engine",`three.js r${t} webgpu`),this.domElement=e),e}set(t,e){this.data.set(t,e)}get(t){let e=this.data.get(t);return void 0===e&&(e={},this.data.set(t,e)),e}has(t){return this.data.has(t)}delete(t){this.data.delete(t)}}let FI=0;class UI{constructor(t,e){this.buffers=[t.bufferGPU,e],this.type=t.type,this.bufferType=t.bufferType,this.pbo=t.pbo,this.byteLength=t.byteLength,this.bytesPerElement=t.BYTES_PER_ELEMENT,this.version=t.version,this.isInteger=t.isInteger,this.activeBufferIndex=0,this.baseId=t.id}get id(){return`${this.baseId}|${this.activeBufferIndex}`}get bufferGPU(){return this.buffers[this.activeBufferIndex]}get transformBuffer(){return this.buffers[1^this.activeBufferIndex]}switchBuffers(){this.activeBufferIndex^=1}}class zI{constructor(t){this.backend=t}createAttribute(t,e){const s=this.backend,{gl:i}=s,r=t.array,n=t.usage||i.STATIC_DRAW,o=t.isInterleavedBufferAttribute?t.data:t,a=s.get(o);let h,u=a.bufferGPU;if(void 0===u&&(u=this._createBuffer(i,e,r,n),a.bufferGPU=u,a.bufferType=e,a.version=o.version),r instanceof Float32Array)h=i.FLOAT;else if(r instanceof Uint16Array)h=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)h=i.SHORT;else if(r instanceof Uint32Array)h=i.UNSIGNED_INT;else if(r instanceof Int32Array)h=i.INT;else if(r instanceof Int8Array)h=i.BYTE;else if(r instanceof Uint8Array)h=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);h=i.UNSIGNED_BYTE}let l={bufferGPU:u,bufferType:e,type:h,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:h===i.INT||h===i.UNSIGNED_INT||t.gpuType===Et,id:FI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,n);l=new UI(l,t)}s.set(t,l)}updateAttribute(t){const e=this.backend,{gl:s}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,n=e.get(r),o=n.bufferType,a=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(s.bindBuffer(o,n.bufferGPU),0===a.length)s.bufferSubData(o,0,i);else{for(let t=0,e=a.length;t<e;t++){const e=a[t];s.bufferSubData(o,e.start*i.BYTES_PER_ELEMENT,i,e.start,e.count)}r.clearUpdateRanges()}s.bindBuffer(o,null),n.version=r.version}destroyAttribute(t){const e=this.backend,{gl:s}=e;t.isInterleavedBufferAttribute&&e.delete(t.data);const i=e.get(t);s.deleteBuffer(i.bufferGPU),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,{gl:s}=e,i=t.isInterleavedBufferAttribute?t.data:t,{bufferGPU:r}=e.get(i),n=t.array,o=n.byteLength;s.bindBuffer(s.COPY_READ_BUFFER,r);const a=s.createBuffer();s.bindBuffer(s.COPY_WRITE_BUFFER,a),s.bufferData(s.COPY_WRITE_BUFFER,o,s.STREAM_READ),s.copyBufferSubData(s.COPY_READ_BUFFER,s.COPY_WRITE_BUFFER,0,0,o),await e.utils._clientWaitAsync();const h=new t.array.constructor(n.length);return s.getBufferSubData(s.COPY_WRITE_BUFFER,0,h),s.deleteBuffer(a),h.buffer}_createBuffer(t,e,s,i){const r=t.createBuffer();return t.bindBuffer(e,r),t.bufferData(e,s,i),t.bindBuffer(e,null),r}}let OI,LI,VI=!1;class DI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.enabled={},this.currentFlipSided=null,this.currentCullFace=null,this.currentProgram=null,this.currentBlendingEnabled=!1,this.currentBlending=null,this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentPremultipledAlpha=null,this.currentPolygonOffsetFactor=null,this.currentPolygonOffsetUnits=null,this.currentColorMask=null,this.currentDepthFunc=null,this.currentDepthMask=null,this.currentStencilFunc=null,this.currentStencilRef=null,this.currentStencilFuncMask=null,this.currentStencilFail=null,this.currentStencilZFail=null,this.currentStencilZPass=null,this.currentStencilMask=null,this.currentLineWidth=null,this.currentBoundFramebuffers={},this.currentDrawbuffers=new WeakMap,this.maxTextures=this.gl.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.currentTextureSlot=null,this.currentBoundTextures={},!1===VI&&(this._init(this.gl),VI=!0)}_init(t){OI={[v]:t.FUNC_ADD,101:t.FUNC_SUBTRACT,102:t.FUNC_REVERSE_SUBTRACT},LI={200:t.ZERO,201:t.ONE,202:t.SRC_COLOR,[C]:t.SRC_ALPHA,210:t.SRC_ALPHA_SATURATE,208:t.DST_COLOR,206:t.DST_ALPHA,203:t.ONE_MINUS_SRC_COLOR,[E]:t.ONE_MINUS_SRC_ALPHA,209:t.ONE_MINUS_DST_COLOR,207:t.ONE_MINUS_DST_ALPHA}}enable(t){const{enabled:e}=this;!0!==e[t]&&(this.gl.enable(t),e[t]=!0)}disable(t){const{enabled:e}=this;!1!==e[t]&&(this.gl.disable(t),e[t]=!1)}setFlipSided(t){if(this.currentFlipSided!==t){const{gl:e}=this;t?e.frontFace(e.CW):e.frontFace(e.CCW),this.currentFlipSided=t}}setCullFace(t){const{gl:e}=this;0!==t?(this.enable(e.CULL_FACE),t!==this.currentCullFace&&(1===t?e.cullFace(e.BACK):2===t?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK))):this.disable(e.CULL_FACE),this.currentCullFace=t}setLineWidth(t){const{currentLineWidth:e,gl:s}=this;t!==e&&(s.lineWidth(t),this.currentLineWidth=t)}setBlending(t,e,s,i,r,n,o,a){const{gl:h}=this;if(t!==m){if(!1===this.currentBlendingEnabled&&(this.enable(h.BLEND),this.currentBlendingEnabled=!0),5===t)r=r||e,n=n||s,o=o||i,e===this.currentBlendEquation&&r===this.currentBlendEquationAlpha||(h.blendEquationSeparate(OI[e],OI[r]),this.currentBlendEquation=e,this.currentBlendEquationAlpha=r),s===this.currentBlendSrc&&i===this.currentBlendDst&&n===this.currentBlendSrcAlpha&&o===this.currentBlendDstAlpha||(h.blendFuncSeparate(LI[s],LI[i],LI[n],LI[o]),this.currentBlendSrc=s,this.currentBlendDst=i,this.currentBlendSrcAlpha=n,this.currentBlendDstAlpha=o),this.currentBlending=t,this.currentPremultipledAlpha=!1;else if(t!==this.currentBlending||a!==this.currentPremultipledAlpha){if(this.currentBlendEquation===v&&this.currentBlendEquationAlpha===v||(h.blendEquation(h.FUNC_ADD),this.currentBlendEquation=v,this.currentBlendEquationAlpha=v),a)switch(t){case 1:h.blendFuncSeparate(h.ONE,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.ONE,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFuncSeparate(h.ZERO,h.SRC_COLOR,h.ZERO,h.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",t)}else switch(t){case 1:h.blendFuncSeparate(h.SRC_ALPHA,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA);break;case 2:h.blendFunc(h.SRC_ALPHA,h.ONE);break;case 3:h.blendFuncSeparate(h.ZERO,h.ONE_MINUS_SRC_COLOR,h.ZERO,h.ONE);break;case 4:h.blendFunc(h.ZERO,h.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",t)}this.currentBlendSrc=null,this.currentBlendDst=null,this.currentBlendSrcAlpha=null,this.currentBlendDstAlpha=null,this.currentBlending=t,this.currentPremultipledAlpha=a}}else!0===this.currentBlendingEnabled&&(this.disable(h.BLEND),this.currentBlendingEnabled=!1)}setColorMask(t){this.currentColorMask!==t&&(this.gl.colorMask(t,t,t,t),this.currentColorMask=t)}setDepthTest(t){const{gl:e}=this;t?this.enable(e.DEPTH_TEST):this.disable(e.DEPTH_TEST)}setDepthMask(t){this.currentDepthMask!==t&&(this.gl.depthMask(t),this.currentDepthMask=t)}setDepthFunc(t){if(this.currentDepthFunc!==t){const{gl:e}=this;switch(t){case 0:e.depthFunc(e.NEVER);break;case 1:e.depthFunc(e.ALWAYS);break;case 2:e.depthFunc(e.LESS);break;case 3:default:e.depthFunc(e.LEQUAL);break;case 4:e.depthFunc(e.EQUAL);break;case 5:e.depthFunc(e.GEQUAL);break;case 6:e.depthFunc(e.GREATER);break;case 7:e.depthFunc(e.NOTEQUAL)}this.currentDepthFunc=t}}setStencilTest(t){const{gl:e}=this;t?this.enable(e.STENCIL_TEST):this.disable(e.STENCIL_TEST)}setStencilMask(t){this.currentStencilMask!==t&&(this.gl.stencilMask(t),this.currentStencilMask=t)}setStencilFunc(t,e,s){this.currentStencilFunc===t&&this.currentStencilRef===e&&this.currentStencilFuncMask===s||(this.gl.stencilFunc(t,e,s),this.currentStencilFunc=t,this.currentStencilRef=e,this.currentStencilFuncMask=s)}setStencilOp(t,e,s){this.currentStencilFail===t&&this.currentStencilZFail===e&&this.currentStencilZPass===s||(this.gl.stencilOp(t,e,s),this.currentStencilFail=t,this.currentStencilZFail=e,this.currentStencilZPass=s)}setMaterial(t,e){const{gl:s}=this;2===t.side?this.disable(s.CULL_FACE):this.enable(s.CULL_FACE);let i=t.side===d;e&&(i=!i),this.setFlipSided(i),1===t.blending&&!1===t.transparent?this.setBlending(m):this.setBlending(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.premultipliedAlpha),this.setDepthFunc(t.depthFunc),this.setDepthTest(t.depthTest),this.setDepthMask(t.depthWrite),this.setColorMask(t.colorWrite);const r=t.stencilWrite;this.setStencilTest(r),r&&(this.setStencilMask(t.stencilWriteMask),this.setStencilFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),this.setStencilOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),this.setPolygonOffset(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),!0===t.alphaToCoverage?this.enable(s.SAMPLE_ALPHA_TO_COVERAGE):this.disable(s.SAMPLE_ALPHA_TO_COVERAGE)}setPolygonOffset(t,e,s){const{gl:i}=this;t?(this.enable(i.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===e&&this.currentPolygonOffsetUnits===s||(i.polygonOffset(e,s),this.currentPolygonOffsetFactor=e,this.currentPolygonOffsetUnits=s)):this.disable(i.POLYGON_OFFSET_FILL)}useProgram(t){return this.currentProgram!==t&&(this.gl.useProgram(t),this.currentProgram=t,!0)}bindFramebuffer(t,e){const{gl:s,currentBoundFramebuffers:i}=this;return i[t]!==e&&(s.bindFramebuffer(t,e),i[t]=e,t===s.DRAW_FRAMEBUFFER&&(i[s.FRAMEBUFFER]=e),t===s.FRAMEBUFFER&&(i[s.DRAW_FRAMEBUFFER]=e),!0)}drawBuffers(t,e){const{gl:s}=this;let i=[],r=!1;if(null!==t.textures){i=this.currentDrawbuffers.get(e),void 0===i&&(i=[],this.currentDrawbuffers.set(e,i));const n=t.textures;if(i.length!==n.length||i[0]!==s.COLOR_ATTACHMENT0){for(let t=0,e=n.length;t<e;t++)i[t]=s.COLOR_ATTACHMENT0+t;i.length=n.length,r=!0}}else i[0]!==s.BACK&&(i[0]=s.BACK,r=!0);r&&s.drawBuffers(i)}activeTexture(t){const{gl:e,currentTextureSlot:s,maxTextures:i}=this;void 0===t&&(t=e.TEXTURE0+i-1),s!==t&&(e.activeTexture(t),this.currentTextureSlot=t)}bindTexture(t,e,s){const{gl:i,currentTextureSlot:r,currentBoundTextures:n,maxTextures:o}=this;void 0===s&&(s=null===r?i.TEXTURE0+o-1:r);let a=n[s];void 0===a&&(a={type:void 0,texture:void 0},n[s]=a),a.type===t&&a.texture===e||(r!==s&&(i.activeTexture(s),this.currentTextureSlot=s),i.bindTexture(t,e),a.type=t,a.texture=e)}unbindTexture(){const{gl:t,currentTextureSlot:e,currentBoundTextures:s}=this,i=s[e];void 0!==i&&void 0!==i.type&&(t.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}}class kI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.extensions=t.extensions}convert(t,e=""){const{gl:s,extensions:i}=this;let r;if(t===At)return s.UNSIGNED_BYTE;if(1017===t)return s.UNSIGNED_SHORT_4_4_4_4;if(1018===t)return s.UNSIGNED_SHORT_5_5_5_1;if(t===Ot)return s.UNSIGNED_INT_5_9_9_9_REV;if(t===Nt)return s.BYTE;if(t===Rt)return s.SHORT;if(t===Ct)return s.UNSIGNED_SHORT;if(t===Et)return s.INT;if(t===Bt)return s.UNSIGNED_INT;if(t===It)return s.FLOAT;if(t===Pt)return s.HALF_FLOAT;if(1021===t)return s.ALPHA;if(t===Vt)return s.RGB;if(t===Dt)return s.RGBA;if(1024===t)return s.LUMINANCE;if(1025===t)return s.LUMINANCE_ALPHA;if(t===Wt)return s.DEPTH_COMPONENT;if(t===jt)return s.DEPTH_STENCIL;if(t===Ht)return s.RED;if(t===qt)return s.RED_INTEGER;if(t===$t)return s.RG;if(t===Xt)return s.RG_INTEGER;if(t===Jt)return s.RGBA_INTEGER;if(t===Zt||t===Qt||t===Kt||t===te)if(e===Je){if(r=i.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(t===Zt)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(t===Kt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(t===te)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=i.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(t===Zt)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Qt)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===Kt)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===te)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(t===ee||t===se||t===ie||t===re){if(r=i.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(t===ee)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===se)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===ie)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===re)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===ne||t===oe||t===ae){if(r=i.get("WEBGL_compressed_texture_etc"),null===r)return null;if(t===ne||t===oe)return e===Je?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(t===ae)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(t===he||t===ue||t===le||t===ce||t===de||t===pe||t===me||t===ge||t===fe||t===ye||t===xe||t===be||t===ve||t===Te){if(r=i.get("WEBGL_compressed_texture_astc"),null===r)return null;if(t===he)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(t===ue)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(t===le)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(t===ce)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(t===de)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(t===pe)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(t===me)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(t===ge)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(t===fe)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(t===ye)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(t===xe)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(t===be)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(t===ve)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(t===Te)return e===Je?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(t===_e){if(r=i.get("EXT_texture_compression_bptc"),null===r)return null;if(t===_e)return e===Je?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(36283===t||t===Ae||t===Ne||t===Re){if(r=i.get("EXT_texture_compression_rgtc"),null===r)return null;if(t===_e)return r.COMPRESSED_RED_RGTC1_EXT;if(t===Ae)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(t===Ne)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(t===Re)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return t===zt?s.UNSIGNED_INT_24_8:void 0!==s[t]?s[t]:null}_clientWaitAsync(){const{gl:t}=this,e=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return t.flush(),new Promise(((s,i)=>{!function r(){const n=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(n===t.WAIT_FAILED)return t.deleteSync(e),void i();n!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),s()):requestAnimationFrame(r)}()}))}}let GI,WI,jI,HI=!1;class qI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===HI&&(this._init(this.gl),HI=!0)}_init(t){GI={[pt]:t.REPEAT,[mt]:t.CLAMP_TO_EDGE,[gt]:t.MIRRORED_REPEAT},WI={[ft]:t.NEAREST,[yt]:t.NEAREST_MIPMAP_NEAREST,[bt]:t.NEAREST_MIPMAP_LINEAR,[Tt]:t.LINEAR,[_t]:t.LINEAR_MIPMAP_NEAREST,[St]:t.LINEAR_MIPMAP_LINEAR},jI={512:t.NEVER,519:t.ALWAYS,[Ts]:t.LESS,515:t.LEQUAL,514:t.EQUAL,518:t.GEQUAL,516:t.GREATER,517:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===ft||t===yt||t===bt?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let s;return s=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,s}getInternalFormat(t,e,s,i,r=!1){const{gl:n,extensions:o}=this;if(null!==t){if(void 0!==n[t])return n[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let a=e;return e===n.RED&&(s===n.FLOAT&&(a=n.R32F),s===n.HALF_FLOAT&&(a=n.R16F),s===n.UNSIGNED_BYTE&&(a=n.R8),s===n.UNSIGNED_SHORT&&(a=n.R16),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RED_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.R8UI),s===n.UNSIGNED_SHORT&&(a=n.R16UI),s===n.UNSIGNED_INT&&(a=n.R32UI),s===n.BYTE&&(a=n.R8I),s===n.SHORT&&(a=n.R16I),s===n.INT&&(a=n.R32I)),e===n.RG&&(s===n.FLOAT&&(a=n.RG32F),s===n.HALF_FLOAT&&(a=n.RG16F),s===n.UNSIGNED_BYTE&&(a=n.RG8),s===n.UNSIGNED_SHORT&&(a=n.RG16),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RG_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RG8UI),s===n.UNSIGNED_SHORT&&(a=n.RG16UI),s===n.UNSIGNED_INT&&(a=n.RG32UI),s===n.BYTE&&(a=n.RG8I),s===n.SHORT&&(a=n.RG16I),s===n.INT&&(a=n.RG32I)),e===n.RGB&&(s===n.FLOAT&&(a=n.RGB32F),s===n.HALF_FLOAT&&(a=n.RGB16F),s===n.UNSIGNED_BYTE&&(a=n.RGB8),s===n.UNSIGNED_SHORT&&(a=n.RGB16),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8:n.RGB8),s===n.UNSIGNED_SHORT_5_6_5&&(a=n.RGB565),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGB4),s===n.UNSIGNED_INT_5_9_9_9_REV&&(a=n.RGB9_E5)),e===n.RGB_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGB8UI),s===n.UNSIGNED_SHORT&&(a=n.RGB16UI),s===n.UNSIGNED_INT&&(a=n.RGB32UI),s===n.BYTE&&(a=n.RGB8I),s===n.SHORT&&(a=n.RGB16I),s===n.INT&&(a=n.RGB32I)),e===n.RGBA&&(s===n.FLOAT&&(a=n.RGBA32F),s===n.HALF_FLOAT&&(a=n.RGBA16F),s===n.UNSIGNED_BYTE&&(a=n.RGBA8),s===n.UNSIGNED_SHORT&&(a=n.RGBA16),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I),s===n.UNSIGNED_BYTE&&(a=i===Je&&!1===r?n.SRGB8_ALPHA8:n.RGBA8),s===n.UNSIGNED_SHORT_4_4_4_4&&(a=n.RGBA4),s===n.UNSIGNED_SHORT_5_5_5_1&&(a=n.RGB5_A1)),e===n.RGBA_INTEGER&&(s===n.UNSIGNED_BYTE&&(a=n.RGBA8UI),s===n.UNSIGNED_SHORT&&(a=n.RGBA16UI),s===n.UNSIGNED_INT&&(a=n.RGBA32UI),s===n.BYTE&&(a=n.RGBA8I),s===n.SHORT&&(a=n.RGBA16I),s===n.INT&&(a=n.RGBA32I)),e===n.DEPTH_COMPONENT&&(s===n.UNSIGNED_INT&&(a=n.DEPTH24_STENCIL8),s===n.FLOAT&&(a=n.DEPTH_COMPONENT32F)),e===n.DEPTH_STENCIL&&s===n.UNSIGNED_INT_24_8&&(a=n.DEPTH24_STENCIL8),a!==n.R16F&&a!==n.R32F&&a!==n.RG16F&&a!==n.RG32F&&a!==n.RGBA16F&&a!==n.RGBA32F||o.get("EXT_color_buffer_float"),a}setTextureParameters(t,e){const{gl:s,extensions:i,backend:r}=this,{currentAnisotropy:n}=r.get(e);s.texParameteri(t,s.TEXTURE_WRAP_S,GI[e.wrapS]),s.texParameteri(t,s.TEXTURE_WRAP_T,GI[e.wrapT]),t!==s.TEXTURE_3D&&t!==s.TEXTURE_2D_ARRAY||s.texParameteri(t,s.TEXTURE_WRAP_R,GI[e.wrapR]),s.texParameteri(t,s.TEXTURE_MAG_FILTER,WI[e.magFilter]);const o=e.isVideoTexture||e.minFilter!==Tt?e.minFilter:St;if(s.texParameteri(t,s.TEXTURE_MIN_FILTER,WI[o]),e.compareFunction&&(s.texParameteri(t,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(t,s.TEXTURE_COMPARE_FUNC,jI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===ft)return;if(e.minFilter!==bt&&e.minFilter!==St)return;if(e.type===It&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1||n!==e.anisotropy){const n=i.get("EXT_texture_filter_anisotropic");s.texParameterf(t,n.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy())),r.get(e).currentAnisotropy=e.anisotropy}}}createDefaultTexture(t){const{gl:e,backend:s,defaultTextures:i}=this,r=this.getGLTextureType(t);let n=i[r];void 0===n&&(n=e.createTexture(),s.state.bindTexture(r,n),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=n),s.set(t,{textureGPU:n,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:s,backend:i}=this,{levels:r,width:n,height:o,depth:a}=e,h=i.utils.convert(t.format,t.colorSpace),u=i.utils.convert(t.type),l=this.getInternalFormat(t.internalFormat,h,u,t.colorSpace,t.isVideoTexture),c=s.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,t.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,t.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,s.NONE),this.setTextureParameters(d,t),t.isDataArrayTexture?s.texStorage3D(s.TEXTURE_2D_ARRAY,r,l,n,o,a):t.isData3DTexture?s.texStorage3D(s.TEXTURE_3D,r,l,n,o,a):t.isVideoTexture||s.texStorage2D(d,r,l,n,o),i.set(t,{textureGPU:c,glTextureType:d,glFormat:h,glType:u,glInternalFormat:l})}copyBufferToTexture(t,e){const{gl:s,backend:i}=this,{textureGPU:r,glTextureType:n,glFormat:o,glType:a}=i.get(e),{width:h,height:u}=e.source.data;s.bindBuffer(s.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(n,r),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,!1),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),s.texSubImage2D(n,0,0,0,h,u,o,a,0),s.bindBuffer(s.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:s}=this,{width:i,height:r}=e,{textureGPU:n,glTextureType:o,glFormat:a,glType:h,glInternalFormat:u}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===n)return;const l=t=>t.isDataTexture?t.image.data:t instanceof ImageBitmap||t instanceof OffscreenCanvas||t instanceof HTMLImageElement||t instanceof HTMLCanvasElement?t:t.data;if(this.backend.state.bindTexture(o,n),t.isCompressedTexture){const i=t.mipmaps;for(let r=0;r<i.length;r++){const n=i[r];if(t.isCompressedArrayTexture){const i=e.image;t.format!==s.RGBA?null!==a?s.compressedTexSubImage3D(s.TEXTURE_2D_ARRAY,r,0,0,0,n.width,n.height,i.depth,a,n.data,0,0):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):s.texSubImage3D(s.TEXTURE_2D_ARRAY,r,0,0,0,n.width,n.height,i.depth,a,h,n.data)}else null!==a?s.compressedTexSubImage2D(s.TEXTURE_2D,r,0,0,n.width,n.height,a,n.data):console.warn("Unsupported compressed texture format")}}else if(t.isCubeTexture){const t=e.images;for(let e=0;e<6;e++){const n=l(t[e]);s.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,i,r,a,h,n)}}else if(t.isDataArrayTexture){const t=e.image;s.texSubImage3D(s.TEXTURE_2D_ARRAY,0,0,0,0,t.width,t.height,t.depth,a,h,t.data)}else if(t.isData3DTexture){const t=e.image;s.texSubImage3D(s.TEXTURE_3D,0,0,0,0,t.width,t.height,t.depth,a,h,t.data)}else if(t.isVideoTexture)t.update(),s.texImage2D(o,0,u,a,h,e.image);else{const t=l(e.image);s.texSubImage2D(o,0,0,0,i,r,a,h,t)}}generateMipmaps(t){const{gl:e,backend:s}=this,{textureGPU:i,glTextureType:r}=s.get(t);s.state.bindTexture(r,i),e.generateMipmap(r)}deallocateRenderBuffers(t){const{gl:e,backend:s}=this;if(t){const i=s.get(t);if(i.renderBufferStorageSetup=void 0,i.framebuffer&&(e.deleteFramebuffer(i.framebuffer),i.framebuffer=void 0),i.depthRenderbuffer&&(e.deleteRenderbuffer(i.depthRenderbuffer),i.depthRenderbuffer=void 0),i.stencilRenderbuffer&&(e.deleteRenderbuffer(i.stencilRenderbuffer),i.stencilRenderbuffer=void 0),i.msaaFrameBuffer&&(e.deleteFramebuffer(i.msaaFrameBuffer),i.msaaFrameBuffer=void 0),i.msaaRenderbuffers){for(let t=0;t<i.msaaRenderbuffers.length;t++)e.deleteRenderbuffer(i.msaaRenderbuffers[t]);i.msaaRenderbuffers=void 0}}}destroyTexture(t){const{gl:e,backend:s}=this,{textureGPU:i,renderTarget:r}=s.get(t);this.deallocateRenderBuffers(r),e.deleteTexture(i),s.delete(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){const{gl:n,backend:o}=this,{state:a}=this.backend,{textureGPU:h,glTextureType:u,glType:l,glFormat:c}=o.get(e);let d,p,m,g,f,y;null!==s?(d=s.max.x-s.min.x,p=s.max.y-s.min.y,m=s.min.x,g=s.min.y):(d=t.image.width,p=t.image.height,m=0,g=0),null!==i?(f=i.x,y=i.y):(f=0,y=0),a.bindTexture(u,h),n.pixelStorei(n.UNPACK_ALIGNMENT,e.unpackAlignment),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,e.flipY),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),n.pixelStorei(n.UNPACK_ALIGNMENT,e.unpackAlignment);const x=n.getParameter(n.UNPACK_ROW_LENGTH),b=n.getParameter(n.UNPACK_IMAGE_HEIGHT),v=n.getParameter(n.UNPACK_SKIP_PIXELS),T=n.getParameter(n.UNPACK_SKIP_ROWS),_=n.getParameter(n.UNPACK_SKIP_IMAGES),w=t.isCompressedTexture?t.mipmaps[r]:t.image;n.pixelStorei(n.UNPACK_ROW_LENGTH,w.width),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,w.height),n.pixelStorei(n.UNPACK_SKIP_PIXELS,m),n.pixelStorei(n.UNPACK_SKIP_ROWS,g),t.isDataTexture?n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w.data):t.isCompressedTexture?n.compressedTexSubImage2D(n.TEXTURE_2D,r,f,y,w.width,w.height,c,w.data):n.texSubImage2D(n.TEXTURE_2D,r,f,y,d,p,c,l,w),n.pixelStorei(n.UNPACK_ROW_LENGTH,x),n.pixelStorei(n.UNPACK_IMAGE_HEIGHT,b),n.pixelStorei(n.UNPACK_SKIP_PIXELS,v),n.pixelStorei(n.UNPACK_SKIP_ROWS,T),n.pixelStorei(n.UNPACK_SKIP_IMAGES,_),0===r&&e.generateMipmaps&&n.generateMipmap(n.TEXTURE_2D),a.unbindTexture()}copyFramebufferToTexture(t,e){const{gl:s}=this,{state:i}=this.backend,{textureGPU:r}=this.backend.get(t),n=t.image.width,o=t.image.height;if(!0===t.isDepthTexture||e.renderTarget&&e.renderTarget.samples>0){let a,h;!0===t.isDepthTexture?(a=s.DEPTH_BUFFER_BIT,h=s.DEPTH_ATTACHMENT,e.stencil&&(a|=s.STENCIL_BUFFER_BIT)):(a=s.COLOR_BUFFER_BIT,h=s.COLOR_ATTACHMENT0);const u=s.createFramebuffer();i.bindFramebuffer(s.DRAW_FRAMEBUFFER,u),s.framebufferTexture2D(s.DRAW_FRAMEBUFFER,h,s.TEXTURE_2D,r,0),s.blitFramebuffer(0,0,n,o,0,0,n,o,a,s.NEAREST),s.deleteFramebuffer(u)}else i.bindTexture(s.TEXTURE_2D,r),s.copyTexSubImage2D(s.TEXTURE_2D,0,0,0,0,0,n,o),i.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:s}=this,i=e.renderTarget,{samples:r,depthTexture:n,depthBuffer:o,stencilBuffer:a,width:h,height:u}=i;if(s.bindRenderbuffer(s.RENDERBUFFER,t),o&&!a){let e=s.DEPTH_COMPONENT24;r>0?(n&&n.isDepthTexture&&n.type===s.FLOAT&&(e=s.DEPTH_COMPONENT32F),s.renderbufferStorageMultisample(s.RENDERBUFFER,r,e,h,u)):s.renderbufferStorage(s.RENDERBUFFER,e,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,t)}else o&&a&&(r>0?s.renderbufferStorageMultisample(s.RENDERBUFFER,r,s.DEPTH24_STENCIL8,h,u):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,h,u),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,s,i,r){const{backend:n,gl:o}=this,{textureGPU:a,glFormat:h,glType:u}=this.backend.get(t),l=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,l),o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,a,0);const c=this._getTypedArrayType(u),d=i*r*this._getBytesPerTexel(h),p=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.bufferData(o.PIXEL_PACK_BUFFER,d,o.STREAM_READ),o.readPixels(e,s,i,r,h,u,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await n.utils._clientWaitAsync();const m=new c(d/c.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,p),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,m),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(l),m}_getTypedArrayType(t){const{gl:e}=this;if(t===e.UNSIGNED_BYTE)return Uint8Array;if(t===e.UNSIGNED_SHORT_4_4_4_4)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_5_5_1)return Uint16Array;if(t===e.UNSIGNED_SHORT_5_6_5)return Uint16Array;if(t===e.UNSIGNED_SHORT)return Uint16Array;if(t===e.UNSIGNED_INT)return Uint32Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t){const{gl:e}=this;return t===e.RGBA?4:t===e.RGB?3:t===e.ALPHA?1:void 0}}class $I{constructor(t){this.backend=t,this.gl=this.backend.gl,this.availableExtensions=this.gl.getSupportedExtensions(),this.extensions={}}get(t){let e=this.extensions[t];return void 0===e&&(e=this.gl.getExtension(t),this.extensions[t]=e),e}has(t){return this.availableExtensions.includes(t)}}class XI{constructor(t){this.backend=t,this.maxAnisotropy=null}getMaxAnisotropy(){if(null!==this.maxAnisotropy)return this.maxAnisotropy;const t=this.backend.gl,e=this.backend.extensions;if(!0===e.has("EXT_texture_filter_anisotropic")){const s=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const YI={WEBGL_multi_draw:"WEBGL_multi_draw",WEBGL_compressed_texture_astc:"texture-compression-astc",WEBGL_compressed_texture_etc:"texture-compression-etc2",WEBGL_compressed_texture_etc1:"texture-compression-etc1",WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBKIT_WEBGL_compressed_texture_pvrtc:"texture-compression-pvrtc",WEBGL_compressed_texture_s3tc:"texture-compression-bc",EXT_texture_compression_bptc:"texture-compression-bptc",EXT_disjoint_timer_query_webgl2:"timestamp-query"};class JI{constructor(t){this.gl=t.gl,this.extensions=t.extensions,this.info=t.renderer.info,this.mode=null,this.index=0,this.type=null,this.object=null}render(t,e){const{gl:s,mode:i,object:r,type:n,info:o,index:a}=this;0!==a?s.drawElements(i,e,n,t):s.drawArrays(i,t,e),o.update(r,e,i,1)}renderInstances(t,e,s){const{gl:i,mode:r,type:n,index:o,object:a,info:h}=this;0!==s&&(0!==o?i.drawElementsInstanced(r,e,n,t,s):i.drawArraysInstanced(r,t,e,s),h.update(a,e,r,s))}renderMultiDraw(t,e,s){const{extensions:i,mode:r,object:n,info:o}=this;if(0===s)return;const a=i.get("WEBGL_multi_draw");if(null===a)for(let i=0;i<s;i++)this.render(t[i],e[i]);else{0!==this.index?a.multiDrawElementsWEBGL(r,e,0,this.type,t,0,s):a.multiDrawArraysWEBGL(r,t,0,e,0,s);let i=0;for(let t=0;t<s;t++)i+=e[t];o.update(n,i,r,1)}}renderMultiDrawInstances(t,e,s,i){const{extensions:r,mode:n,object:o,info:a}=this;if(0===s)return;const h=r.get("WEBGL_multi_draw");if(null===h)for(let r=0;r<s;r++)this.renderInstances(t[r],e[r],i[r]);else{0!==this.index?h.multiDrawElementsInstancedWEBGL(n,e,0,this.type,t,0,i,0,s):h.multiDrawArraysInstancedWEBGL(n,t,0,e,0,i,0,s);let r=0;for(let t=0;t<s;t++)r+=e[t];for(let t=0;t<i.length;t++)a.update(o,r,n,i[t])}}}class ZI extends PI{constructor(t={}){super(t),this.isWebGLBackend=!0}init(t){super.init(t);const e=this.parameters,s=void 0!==e.context?e.context:t.domElement.getContext("webgl2");this.gl=s,this.extensions=new $I(this),this.capabilities=new XI(this),this.attributeUtils=new zI(this),this.textureUtils=new qI(this),this.bufferRenderer=new JI(this),this.state=new DI(this),this.utils=new kI(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===e.trackTimestamp,this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_multi_draw"),this.disjoint=this.extensions.get("EXT_disjoint_timer_query_webgl2"),this.parallel=this.extensions.get("KHR_parallel_shader_compile"),this._currentContext=null}get coordinateSystem(){return Vs}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}initTimestampQuery(t){if(!this.disjoint||!this.trackTimestamp)return;const e=this.get(t);if(this.queryRunning)return e.queryQueue||(e.queryQueue=[]),void e.queryQueue.push(t);e.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),e.activeQuery=null),e.activeQuery=this.gl.createQuery(),null!==e.activeQuery&&(this.gl.beginQuery(this.disjoint.TIME_ELAPSED_EXT,e.activeQuery),this.queryRunning=!0)}prepareTimestampBuffer(t){if(!this.disjoint||!this.trackTimestamp)return;const e=this.get(t);if(e.activeQuery&&(this.gl.endQuery(this.disjoint.TIME_ELAPSED_EXT),e.gpuQueries||(e.gpuQueries=[]),e.gpuQueries.push({query:e.activeQuery}),e.activeQuery=null,this.queryRunning=!1,e.queryQueue&&e.queryQueue.length>0)){const t=e.queryQueue.shift();this.initTimestampQuery(t)}}async resolveTimestampAsync(t,e="render"){if(!this.disjoint||!this.trackTimestamp)return;const s=this.get(t);s.gpuQueries||(s.gpuQueries=[]);for(let t=0;t<s.gpuQueries.length;t++){const i=s.gpuQueries[t],r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT_AVAILABLE),n=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(r&&!n){const r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT),n=Number(r)/1e6;this.gl.deleteQuery(i.query),s.gpuQueries.splice(t,1),t--,this.renderer.info.updateTimestamp(e,n)}}}getContext(){return this.gl}beginRender(t){const{gl:e}=this,s=this.get(t);if(this.initTimestampQuery(t),s.previousContext=this._currentContext,this._currentContext=t,this._setFramebuffer(t),this.clear(t.clearColor,t.clearDepth,t.clearStencil,t,!1),t.viewport?this.updateViewport(t):e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),t.scissor){const{x:s,y:i,width:r,height:n}=t.scissorValue;e.scissor(s,i,r,n)}const i=t.occlusionQueryCount;i>0&&(s.currentOcclusionQueries=s.occlusionQueries,s.currentOcclusionQueryObjects=s.occlusionQueryObjects,s.lastOcclusionObject=null,s.occlusionQueries=new Array(i),s.occlusionQueryObjects=new Array(i),s.occlusionQueryIndex=0)}finishRender(t){const{gl:e,state:s}=this,i=this.get(t).previousContext,r=t.textures;if(null!==r)for(let t=0;t<r.length;t++){const e=r[t];e.generateMipmaps&&this.generateMipmaps(e)}if(this._currentContext=i,null!==t.textures&&t.renderTarget){const i=this.get(t.renderTarget),{samples:r}=t.renderTarget,n=i.framebuffer,o=e.COLOR_BUFFER_BIT;if(r>0){const r=i.msaaFrameBuffer,a=t.textures;s.bindFramebuffer(e.READ_FRAMEBUFFER,r),s.bindFramebuffer(e.DRAW_FRAMEBUFFER,n);for(let s=0;s<a.length;s++)e.blitFramebuffer(0,0,t.width,t.height,0,0,t.width,t.height,o,e.NEAREST),e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray)}}if(null!==i)if(this._setFramebuffer(i),i.viewport)this.updateViewport(i);else{const t=this.gl;t.viewport(0,0,t.drawingBufferWidth,t.drawingBufferHeight)}const n=t.occlusionQueryCount;if(n>0){if(n>this.get(t).occlusionQueryIndex){const{gl:t}=this;t.endQuery(t.ANY_SAMPLES_PASSED)}this.resolveOccludedAsync(t)}this.prepareTimestampBuffer(t)}resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueries:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet,{gl:r}=this;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueries=null;const n=()=>{let o=0;for(let e=0;e<s.length;e++){const n=s[e];null!==n&&(r.getQueryParameter(n,r.QUERY_RESULT_AVAILABLE)&&(r.getQueryParameter(n,r.QUERY_RESULT)>0&&t.add(i[e]),s[e]=null,r.deleteQuery(n),o++))}o<s.length?requestAnimationFrame(n):e.occluded=t};n()}}isOccluded(t,e){const s=this.get(t);return s.occluded&&s.occluded.has(e)}updateViewport(t){const e=this.gl,{x:s,y:i,width:r,height:n}=t.viewportValue;e.viewport(s,i,r,n)}setScissorTest(t){const e=this.gl;t?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)}clear(t,e,s,i=null,r=!0){const{gl:n}=this;null===i&&(i={textures:null,clearColorValue:this.getClearColor()});let o=0;if(t&&(o|=n.COLOR_BUFFER_BIT),e&&(o|=n.DEPTH_BUFFER_BIT),s&&(o|=n.STENCIL_BUFFER_BIT),0!==o){const a=i.clearColorValue||this.getClearColor();if(e&&this.state.setDepthMask(!0),null===i.textures)n.clearColor(a.r,a.g,a.b,a.a),n.clear(o);else{if(r&&this._setFramebuffer(i),t)for(let t=0;t<i.textures.length;t++)n.clearBufferfv(n.COLOR,t,[a.r,a.g,a.b,a.a]);e&&s?n.clearBufferfi(n.DEPTH_STENCIL,0,1,0):e?n.clearBufferfv(n.DEPTH,0,[1]):s&&n.clearBufferiv(n.STENCIL,0,[0])}}}beginCompute(t){const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),this.initTimestampQuery(t)}compute(t,e,s,i){const r=this.gl;this.discard||(r.enable(r.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:n,transformBuffers:o,attributes:a}=this.get(i),h=this._getVaoKey(null,a),u=this.vaoCache[h];void 0===u?this._createVao(null,a):r.bindVertexArray(u),r.useProgram(n),this._bindUniforms(s);const l=this._getTransformFeedback(o);r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,l),r.beginTransformFeedback(r.POINTS),a[0].isStorageInstancedBufferAttribute?r.drawArraysInstanced(r.POINTS,0,1,e.count):r.drawArrays(r.POINTS,0,e.count),r.endTransformFeedback(),r.bindTransformFeedback(r.TRANSFORM_FEEDBACK,null);for(let t=0;t<o.length;t++){const e=o[t];e.pbo&&this.textureUtils.copyBufferToTexture(e.transformBuffer,e.pbo),e.switchBuffers()}}finishCompute(t){const e=this.gl;this.discard=!1,e.disable(e.RASTERIZER_DISCARD),this.prepareTimestampBuffer(t)}draw(t){const{object:e,pipeline:s,material:i,context:r}=t,{programGPU:n}=this.get(s),{gl:o,state:a}=this,h=this.get(r);this._bindUniforms(t.getBindings());const u=e.isMesh&&e.matrixWorld.determinant()<0;a.setMaterial(i,u),o.useProgram(n);let l=t.staticVao;if(void 0===l){const e=this._getVaoKey(t.getIndex(),t.getAttributes());if(l=this.vaoCache[e],void 0===l){let e;({vaoGPU:l,staticVao:e}=this._createVao(t.getIndex(),t.getAttributes())),e&&(t.staticVao=l)}}o.bindVertexArray(l);const c=t.getIndex(),d=t.geometry,p=t.drawRange,m=p.start,g=h.lastOcclusionObject;if(g!==e&&void 0!==g){if(null!==g&&!0===g.occlusionTest&&(o.endQuery(o.ANY_SAMPLES_PASSED),h.occlusionQueryIndex++),!0===e.occlusionTest){const t=o.createQuery();o.beginQuery(o.ANY_SAMPLES_PASSED,t),h.occlusionQueries[h.occlusionQueryIndex]=t,h.occlusionQueryObjects[h.occlusionQueryIndex]=e}h.lastOcclusionObject=e}const f=this.bufferRenderer;let y;if(e.isPoints?f.mode=o.POINTS:e.isLineSegments?f.mode=o.LINES:e.isLine?f.mode=o.LINE_STRIP:e.isLineLoop?f.mode=o.LINE_LOOP:!0===i.wireframe?(a.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),f.mode=o.LINES):f.mode=o.TRIANGLES,f.object=e,null!==c){const t=this.get(c),e=p.count!==1/0?p.count:c.count;f.index=c.count,f.type=t.type,y=e}else{f.index=0;y=p.count!==1/0?p.count:d.attributes.position.count}const x=this.getInstanceCount(t);e.isBatchedMesh?null!==e._multiDrawInstances?f.renderMultiDrawInstances(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount,e._multiDrawInstances):this.hasFeature("WEBGL_multi_draw")?f.renderMultiDraw(e._multiDrawStarts,e._multiDrawCounts,e._multiDrawCount):ai("THREE.WebGLRenderer: WEBGL_multi_draw not supported."):x>1?f.renderInstances(m,y,x):f.render(m,y),o.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(t){return t.id}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new CI(t,e)}createProgram(t){const e=this.gl,{stage:s,code:i}=t,r="fragment"===s?e.createShader(e.FRAGMENT_SHADER):e.createShader(e.VERTEX_SHADER);e.shaderSource(r,i),e.compileShader(r),this.set(t,{shaderGPU:r})}destroyProgram(){console.warn("Abstract class.")}createRenderPipeline(t,e){const s=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:n}=i,o=s.createProgram(),a=this.get(r).shaderGPU,h=this.get(n).shaderGPU;if(s.attachShader(o,a),s.attachShader(o,h),s.linkProgram(o),this.set(i,{programGPU:o,fragmentShader:a,vertexShader:h}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,n=()=>{s.getProgramParameter(o,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(n)};n()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const s=t.split("\n"),i=[],r=Math.max(e-6,0),n=Math.min(e+6,s.length);for(let t=r;t<n;t++){const r=t+1;i.push(`${r===e?">":" "} ${r}: ${s[t]}`)}return i.join("\n")}_getShaderErrors(t,e,s){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const n=/ERROR: 0:(\d+)/.exec(r);if(n){const i=parseInt(n[1]);return s.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,s){if(this.renderer.debug.checkShaderErrors){const i=this.gl,r=i.getProgramInfoLog(t).trim();if(!1===i.getProgramParameter(t,i.LINK_STATUS))if("function"==typeof this.renderer.debug.onShaderError)this.renderer.debug.onShaderError(i,t,s,e);else{const n=this._getShaderErrors(i,s,"vertex"),o=this._getShaderErrors(i,e,"fragment");console.error("THREE.WebGLProgram: Shader Error "+i.getError()+" - VALIDATE_STATUS "+i.getProgramParameter(t,i.VALIDATE_STATUS)+"\n\nProgram Info Log: "+r+"\n"+n+"\n"+o)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const s=this.gl,i=this.get(e),{programGPU:r,fragmentShader:n,vertexShader:o}=i;!1===s.getProgramParameter(r,s.LINK_STATUS)&&this._logProgramError(r,n,o),s.useProgram(r);const a=t.getBindings();this._setupBindings(a,r),this.set(e,{programGPU:r})}createComputePipeline(t,e){const s=this.gl,i={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(i);const{computeProgram:r}=t,n=s.createProgram(),o=this.get(i).shaderGPU,a=this.get(r).shaderGPU,h=r.transforms,u=[],l=[];for(let t=0;t<h.length;t++){const e=h[t];u.push(e.varyingName),l.push(e.attributeNode)}s.attachShader(n,o),s.attachShader(n,a),s.transformFeedbackVaryings(n,u,s.SEPARATE_ATTRIBS),s.linkProgram(n),!1===s.getProgramParameter(n,s.LINK_STATUS)&&this._logProgramError(n,o,a),s.useProgram(n),this.createBindings(null,e),this._setupBindings(e,n);const c=r.attributes,d=[],p=[];for(let t=0;t<c.length;t++){const e=c[t].node.attribute;d.push(e),this.has(e)||this.attributeUtils.createAttribute(e,s.ARRAY_BUFFER)}for(let t=0;t<l.length;t++){const e=l[t].attribute;this.has(e)||this.attributeUtils.createAttribute(e,s.ARRAY_BUFFER);const i=this.get(e);p.push(i)}this.set(t,{programGPU:n,transformBuffers:p,attributes:d})}createBindings(t,e){this.updateBindings(t,e)}updateBindings(t,e){const{gl:s}=this;let i=0,r=0;for(const t of e)for(const e of t.bindings)if(e.isUniformsGroup||e.isUniformBuffer){const t=s.createBuffer(),r=e.buffer;s.bindBuffer(s.UNIFORM_BUFFER,t),s.bufferData(s.UNIFORM_BUFFER,r,s.DYNAMIC_DRAW),s.bindBufferBase(s.UNIFORM_BUFFER,i,t),this.set(e,{index:i++,bufferGPU:t})}else if(e.isSampledTexture){const{textureGPU:t,glTextureType:s}=this.get(e.texture);this.set(e,{index:r++,textureGPU:t,glTextureType:s})}}updateBinding(t){const e=this.gl;if(t.isUniformsGroup||t.isUniformBuffer){const s=this.get(t).bufferGPU,i=t.buffer;e.bindBuffer(e.UNIFORM_BUFFER,s),e.bufferData(e.UNIFORM_BUFFER,i,e.DYNAMIC_DRAW)}}createIndexAttribute(t){const e=this.gl;this.attributeUtils.createAttribute(t,e.ELEMENT_ARRAY_BUFFER)}createAttribute(t){if(this.has(t))return;const e=this.gl;this.attributeUtils.createAttribute(t,e.ARRAY_BUFFER)}createStorageAttribute(t){if(this.has(t))return;const e=this.gl;this.attributeUtils.createAttribute(t,e.ARRAY_BUFFER)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){}hasFeature(t){const e=Object.keys(YI).filter((e=>YI[e]===t)),s=this.extensions;for(let t=0;t<e.length;t++)if(s.has(e[t]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(t,e,s,i){this.textureUtils.copyTextureToTexture(t,e,s,i)}copyFramebufferToTexture(t,e){this.textureUtils.copyFramebufferToTexture(t,e)}_setFramebuffer(t){const{gl:e,state:s}=this;let i=null;if(null!==t.textures){const r=t.renderTarget,n=this.get(r),{samples:o,depthBuffer:a,stencilBuffer:h}=r,u=this.renderer._activeCubeFace,l=!0===r.isWebGLCubeRenderTarget;let c,d=n.msaaFrameBuffer,p=n.depthRenderbuffer;if(l?(void 0===n.cubeFramebuffers&&(n.cubeFramebuffers=[]),c=n.cubeFramebuffers[u]):c=n.framebuffer,void 0===c){c=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,c);const i=t.textures;if(l){n.cubeFramebuffers[u]=c;const{textureGPU:t}=this.get(i[0]);e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+u,t,0)}else{for(let s=0;s<i.length;s++){const r=i[s],n=this.get(r);n.renderTarget=t.renderTarget;const o=e.COLOR_ATTACHMENT0+s;e.framebufferTexture2D(e.FRAMEBUFFER,o,e.TEXTURE_2D,n.textureGPU,0)}n.framebuffer=c,s.drawBuffers(t,c)}if(null!==t.depthTexture){const s=this.get(t.depthTexture),i=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;e.framebufferTexture2D(e.FRAMEBUFFER,i,e.TEXTURE_2D,s.textureGPU,0)}}if(o>0){if(void 0===d){const i=[];d=e.createFramebuffer(),s.bindFramebuffer(e.FRAMEBUFFER,d);const r=[],u=t.textures;for(let s=0;s<u.length;s++){if(r[s]=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,r[s]),i.push(e.COLOR_ATTACHMENT0+s),a){const t=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(t)}const n=t.textures[s],u=this.get(n);e.renderbufferStorageMultisample(e.RENDERBUFFER,o,u.glInternalFormat,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+s,e.RENDERBUFFER,r[s])}if(n.msaaFrameBuffer=d,n.msaaRenderbuffers=r,void 0===p){p=e.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(p,t),n.depthRenderbuffer=p;const s=h?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(s)}n.invalidationArray=i}i=n.msaaFrameBuffer}else i=c}s.bindFramebuffer(e.FRAMEBUFFER,i)}_getVaoKey(t,e){let s=[];if(null!==t){s+=":"+this.get(t).id}for(let t=0;t<e.length;t++){s+=":"+this.get(e[t]).id}return s}_createVao(t,e){const{gl:s}=this,i=s.createVertexArray();let r="",n=!0;if(s.bindVertexArray(i),null!==t){const e=this.get(t);s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,e.bufferGPU),r+=":"+e.id}for(let t=0;t<e.length;t++){const i=e[t],o=this.get(i);let a,h;r+=":"+o.id,s.bindBuffer(s.ARRAY_BUFFER,o.bufferGPU),s.enableVertexAttribArray(t),(i.isStorageBufferAttribute||i.isStorageInstancedBufferAttribute)&&(n=!1),!0===i.isInterleavedBufferAttribute?(a=i.data.stride*o.bytesPerElement,h=i.offset*o.bytesPerElement):(a=0,h=0),o.isInteger?s.vertexAttribIPointer(t,i.itemSize,o.type,a,h):s.vertexAttribPointer(t,i.itemSize,o.type,i.normalized,a,h),i.isInstancedBufferAttribute&&!i.isInterleavedBufferAttribute?s.vertexAttribDivisor(t,i.meshPerAttribute):i.isInterleavedBufferAttribute&&i.data.isInstancedInterleavedBuffer&&s.vertexAttribDivisor(t,i.data.meshPerAttribute)}return s.bindBuffer(s.ARRAY_BUFFER,null),this.vaoCache[r]=i,{vaoGPU:i,staticVao:n}}_getTransformFeedback(t){let e="";for(let s=0;s<t.length;s++)e+=":"+t[s].id;let s=this.transformFeedbackCache[e];if(void 0!==s)return s;const i=this.gl;s=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,s);for(let e=0;e<t.length;e++){const s=t[e];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,e,s.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[e]=s,s}_setupBindings(t,e){const s=this.gl;for(const i of t)for(const t of i.bindings){const i=this.get(t).index;if(t.isUniformsGroup||t.isUniformBuffer){const r=s.getUniformBlockIndex(e,t.name);s.uniformBlockBinding(e,r,i)}else if(t.isSampledTexture){const r=s.getUniformLocation(e,t.name);s.uniform1i(r,i)}}}_bindUniforms(t){const{gl:e,state:s}=this;for(const i of t)for(const t of i.bindings){const i=this.get(t),r=i.index;t.isUniformsGroup||t.isUniformBuffer?e.bindBufferBase(e.UNIFORM_BUFFER,r,i.bufferGPU):t.isSampledTexture&&s.bindTexture(i.glTextureType,i.textureGPU,e.TEXTURE0+r)}}}class QI extends dI{constructor(t,e){super(t),this.texture=e,this.version=e?e.version:0,this.isSampler=!0}}class KI extends QI{constructor(t,e,s){super(t,e?e.value:null),this.textureNode=e,this.groupNode=s}update(){this.texture=this.textureNode.value}}class tP extends pI{constructor(t,e){super(t,e?e.array:null),this.attribute=e,this.isStorageBuffer=!0}}let eP=0;class sP extends tP{constructor(t,e){super("StorageBuffer_"+eP++,t?t.value:null),this.nodeUniform=t,this.access=t?t.access:kM,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class iP{constructor(t){this.device=t;this.mipmapSampler=t.createSampler({minFilter:cM}),this.flipYSampler=t.createSampler({minFilter:dM}),this.transferPipelines={},this.flipYPipelines={},this.mipmapVertexShaderModule=t.createShaderModule({label:"mipmapVertex",code:"\nstruct VarysStruct {\n\t@builtin( position ) Position: vec4<f32>,\n\t@location( 0 ) vTex : vec2<f32>\n};\n\n@vertex\nfn main( @builtin( vertex_index ) vertexIndex : u32 ) -> VarysStruct {\n\n\tvar Varys : VarysStruct;\n\n\tvar pos = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( -1.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 ),\n\t\tvec2<f32>( -1.0, -1.0 ),\n\t\tvec2<f32>( 1.0, -1.0 )\n\t);\n\n\tvar tex = array< vec2<f32>, 4 >(\n\t\tvec2<f32>( 0.0, 0.0 ),\n\t\tvec2<f32>( 1.0, 0.0 ),\n\t\tvec2<f32>( 0.0, 1.0 ),\n\t\tvec2<f32>( 1.0, 1.0 )\n\t);\n\n\tVarys.vTex = tex[ vertexIndex ];\n\tVarys.Position = vec4<f32>( pos[ vertexIndex ], 0.0, 1.0 );\n\n\treturn Varys;\n\n}\n"}),this.mipmapFragmentShaderModule=t.createShaderModule({label:"mipmapFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vTex );\n\n}\n"}),this.flipYFragmentShaderModule=t.createShaderModule({label:"flipYFragment",code:"\n@group( 0 ) @binding( 0 )\nvar imgSampler : sampler;\n\n@group( 0 ) @binding( 1 )\nvar img : texture_2d<f32>;\n\n@fragment\nfn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {\n\n\treturn textureSample( img, imgSampler, vec2( vTex.x, 1.0 - vTex.y ) );\n\n}\n"})}getTransferPipeline(t){let e=this.transferPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:WS,stripIndexFormat:oM},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:WS,stripIndexFormat:oM},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,s=0){const i=e.format,{width:r,height:n}=e.size,o=this.getTransferPipeline(i),a=this.getFlipYPipeline(i),h=this.device.createTexture({size:{width:r,height:n,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:ZM,baseArrayLayer:s}),l=h.createView({baseMipLevel:0,mipLevelCount:1,dimension:ZM,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,s)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),n=c.beginRenderPass({colorAttachments:[{view:s,loadOp:tM,storeOp:QS,clearValue:[0,0,0,0]}]});n.setPipeline(t),n.setBindGroup(0,r),n.draw(4,1,0,0),n.end()};d(o,u,l),d(a,l,u),this.device.queue.submit([c.finish()]),h.destroy()}generateMipmaps(t,e,s=0){const i=this.getTransferPipeline(e.format),r=this.device.createCommandEncoder({}),n=i.getBindGroupLayout(0);let o=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:ZM,baseArrayLayer:s});for(let a=1;a<e.mipLevelCount;a++){const e=this.device.createBindGroup({layout:n,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:o}]}),h=t.createView({baseMipLevel:a,mipLevelCount:1,dimension:ZM,baseArrayLayer:s}),u=r.beginRenderPass({colorAttachments:[{view:h,loadOp:tM,storeOp:QS,clearValue:[0,0,0,0]}]});u.setPipeline(i),u.setBindGroup(0,e),u.draw(4,1,0,0),u.end(),o=h}this.device.queue.submit([r.finish()])}}const rP={512:"never",[Ts]:"less",514:"equal",515:"less-equal",516:"greater",518:"greater-equal",519:"always",517:"not-equal"},nP=[0,1,3,2,4,5];class oP{constructor(t){this.backend=t,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new Ka,this.depthTexture.name="depthBuffer"}createSampler(t){const e=this.backend,s=e.device,i=e.get(t),r={addressModeU:this._convertAddressMode(t.wrapS),addressModeV:this._convertAddressMode(t.wrapT),addressModeW:this._convertAddressMode(t.wrapR),magFilter:this._convertFilterMode(t.magFilter),minFilter:this._convertFilterMode(t.minFilter),mipmapFilter:this._convertFilterMode(t.minFilter),maxAnisotropy:t.anisotropy};t.isDepthTexture&&null!==t.compareFunction&&(r.compare=rP[t.compareFunction]),i.sampler=s.createSampler(r)}createDefaultTexture(t){let e;const s=aP(t);t.isCubeTexture?e=this._getDefaultCubeTextureGPU(s):t.isVideoTexture?this.backend.get(t).externalTexture=this._getDefaultVideoFrame():e=this._getDefaultTextureGPU(s),this.backend.get(t).texture=e}createTexture(t,e={}){const s=this.backend,i=s.get(t);if(i.initialized)throw new Error("WebGPUTextureUtils: Texture already initialized.");void 0===e.needsMipmaps&&(e.needsMipmaps=!1),void 0===e.levels&&(e.levels=1),void 0===e.depth&&(e.depth=1);const{width:r,height:n,depth:o,levels:a}=e,h=this._getDimension(t),u=t.internalFormat||e.format||aP(t,s.device);let l=void 0!==e.sampleCount?e.sampleCount:1;l=s.utils.getSampleCount(l);const c=t.isRenderTargetTexture&&!t.isMultisampleRenderTargetTexture?1:l;let d=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===t.isStorageTexture&&(d|=GPUTextureUsage.STORAGE_BINDING),!0!==t.isCompressedTexture&&(d|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:t.name,size:{width:r,height:n,depthOrArrayLayers:o},mipLevelCount:a,sampleCount:c,dimension:h,format:u,usage:d};if(t.isVideoTexture){const e=t.source.data,s=new VideoFrame(e);p.size.width=s.displayWidth,p.size.height=s.displayHeight,s.close(),i.externalTexture=e}else{if(void 0===u)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(t);i.texture=s.device.createTexture(p)}if(t.isRenderTargetTexture&&l>1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=l,i.msaaTexture=s.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,s=e.get(t);s.texture.destroy(),void 0!==s.msaaTexture&&s.msaaTexture.destroy(),e.delete(t)}destroySampler(t){delete this.backend.get(t).sampler}generateMipmaps(t){const e=this.backend.get(t);if(t.isCubeTexture)for(let t=0;t<6;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t);else this._generateMipmaps(e.texture,e.textureDescriptorGPU)}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const t=this.backend,{width:e,height:s}=t.getDrawingBufferSize();return this.colorBuffer=t.device.createTexture({label:"colorBuffer",size:{width:e,height:s,depthOrArrayLayers:1},sampleCount:t.utils.getSampleCount(t.renderer.samples),format:aM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(t=!0,e=!1){const s=this.backend,{width:i,height:r}=s.getDrawingBufferSize(),n=this.depthTexture,o=s.get(n).texture;let a,h;if(e?(a=jt,h=zt):t&&(a=Wt,h=Bt),void 0!==o){if(n.image.width===i&&n.image.height===r&&n.format===a&&n.type===h)return o;this.destroyTexture(n)}return n.name="depthBuffer",n.format=a,n.type=h,n.image.width=i,n.image.height=r,this.createTexture(n,{sampleCount:s.utils.getSampleCount(s.renderer.samples),width:i,height:r}),s.get(n).texture}updateTexture(t,e){const s=this.backend.get(t),{textureDescriptorGPU:i}=s;if(!t.isRenderTargetTexture&&void 0!==i){if(t.isDataTexture)this._copyBufferToTexture(e.image,s.texture,i,0,t.flipY);else if(t.isDataArrayTexture||t.isData3DTexture)for(let r=0;r<e.image.depth;r++)this._copyBufferToTexture(e.image,s.texture,i,r,t.flipY,r);else if(t.isCompressedTexture)this._copyCompressedBufferToTexture(t.mipmaps,s.texture,i);else if(t.isCubeTexture)this._copyCubeMapToTexture(e.images,s.texture,i,t.flipY);else if(t.isVideoTexture){const e=t.source.data;s.externalTexture=e}else this._copyImageToTexture(e.image,s.texture,i,0,t.flipY);s.version=t.version,t.onUpdate&&t.onUpdate(t)}}async copyTextureToBuffer(t,e,s,i,r){const n=this.backend.device,o=this.backend.get(t),a=o.texture,h=o.textureDescriptorGPU.format,u=this._getBytesPerTexel(h);let l=i*u;l=256*Math.ceil(l/256);const c=n.createBuffer({size:i*r*u,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),d=n.createCommandEncoder();d.copyTextureToBuffer({texture:a,origin:{x:e,y:s}},{buffer:c,bytesPerRow:l},{width:i,height:r});const p=this._getTypedArrayType(h);n.queue.submit([d.finish()]),await c.mapAsync(GPUMapMode.READ);return new p(c.getMappedRange())}_isEnvironmentTexture(t){const e=t.mapping;return e===lt||e===ct||e===ht||e===ut}_getDefaultTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const s=new Ti;s.minFilter=ft,s.magFilter=ft,this.createTexture(s,{width:1,height:1,format:t}),this.defaultTexture[t]=e=s}return this.backend.get(e).texture}_getDefaultCubeTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const s=new eo;s.minFilter=ft,s.magFilter=ft,this.createTexture(s,{width:1,height:1,depth:6}),this.defaultCubeTexture[t]=e=s}return this.backend.get(e).texture}_getDefaultVideoFrame(){let t=this.defaultVideoFrame;if(null===t){const e={timestamp:0,codedWidth:1,codedHeight:1,format:"RGBA"};this.defaultVideoFrame=t=new VideoFrame(new Uint8Array([0,0,0,255]),e)}return t}_copyCubeMapToTexture(t,e,s,i){for(let r=0;r<6;r++){const n=t[r],o=!0===i?nP[r]:r;n.isDataTexture?this._copyBufferToTexture(n.image,e,s,o,i):this._copyImageToTexture(n,e,s,o,i)}}_copyImageToTexture(t,e,s,i,r){this.backend.device.queue.copyExternalImageToTexture({source:t},{texture:e,mipLevel:0,origin:{x:0,y:0,z:i}},{width:t.width,height:t.height,depthOrArrayLayers:1}),!0===r&&this._flipY(e,s,i)}_getPassUtils(){let t=this._passUtils;return null===t&&(this._passUtils=t=new iP(this.backend.device)),t}_generateMipmaps(t,e,s=0){this._getPassUtils().generateMipmaps(t,e,s)}_flipY(t,e,s=0){this._getPassUtils().flipY(t,e,s)}_copyBufferToTexture(t,e,s,i,r,n=0){const o=this.backend.device,a=t.data,h=this._getBytesPerTexel(s.format),u=t.width*h;o.queue.writeTexture({texture:e,mipLevel:0,origin:{x:0,y:0,z:i}},a,{offset:t.width*t.height*h*n,bytesPerRow:u},{width:t.width,height:t.height,depthOrArrayLayers:1}),!0===r&&this._flipY(e,s,i)}_copyCompressedBufferToTexture(t,e,s){const i=this.backend.device,r=this._getBlockData(s.format);for(let s=0;s<t.length;s++){const n=t[s],o=n.width,a=n.height,h=Math.ceil(o/r.width)*r.byteLength;i.queue.writeTexture({texture:e,mipLevel:s},n.data,{offset:0,bytesPerRow:h},{width:Math.ceil(o/r.width)*r.width,height:Math.ceil(a/r.width)*r.width,depthOrArrayLayers:1})}}_getBlockData(t){return t===aM.BC1RGBAUnorm||t===aM.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:t===aM.BC2RGBAUnorm||t===aM.BC2RGBAUnormSRGB||t===aM.BC3RGBAUnorm||t===aM.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===aM.BC4RUnorm||t===aM.BC4RSNorm?{byteLength:8,width:4,height:4}:t===aM.BC5RGUnorm||t===aM.BC5RGSnorm||t===aM.BC6HRGBUFloat||t===aM.BC6HRGBFloat||t===aM.BC7RGBAUnorm||t===aM.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===aM.ETC2RGB8Unorm||t===aM.ETC2RGB8UnormSRGB||t===aM.ETC2RGB8A1Unorm||t===aM.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:t===aM.ETC2RGBA8Unorm||t===aM.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:t===aM.EACR11Unorm||t===aM.EACR11Snorm?{byteLength:8,width:4,height:4}:t===aM.EACRG11Unorm||t===aM.EACRG11Snorm||t===aM.ASTC4x4Unorm||t===aM.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:t===aM.ASTC5x4Unorm||t===aM.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:t===aM.ASTC5x5Unorm||t===aM.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:t===aM.ASTC6x5Unorm||t===aM.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:t===aM.ASTC6x6Unorm||t===aM.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:t===aM.ASTC8x5Unorm||t===aM.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:t===aM.ASTC8x6Unorm||t===aM.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:t===aM.ASTC8x8Unorm||t===aM.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:t===aM.ASTC10x5Unorm||t===aM.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:t===aM.ASTC10x6Unorm||t===aM.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:t===aM.ASTC10x8Unorm||t===aM.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:t===aM.ASTC10x10Unorm||t===aM.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:t===aM.ASTC12x10Unorm||t===aM.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:t===aM.ASTC12x12Unorm||t===aM.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(t){let e=hM;return t===pt?e=uM:t===gt&&(e=lM),e}_convertFilterMode(t){let e=cM;return t!==ft&&t!==yt&&t!==bt||(e=dM),e}_getBytesPerTexel(t){return t===aM.R8Unorm||t===aM.R8Snorm||t===aM.R8Uint||t===aM.R8Sint?1:t===aM.R16Uint||t===aM.R16Sint||t===aM.R16Float||t===aM.RG8Unorm||t===aM.RG8Snorm||t===aM.RG8Uint||t===aM.RG8Sint?2:t===aM.R32Uint||t===aM.R32Sint||t===aM.R32Float||t===aM.RG16Uint||t===aM.RG16Sint||t===aM.RG16Float||t===aM.RGBA8Unorm||t===aM.RGBA8UnormSRGB||t===aM.RGBA8Snorm||t===aM.RGBA8Uint||t===aM.RGBA8Sint||t===aM.BGRA8Unorm||t===aM.BGRA8UnormSRGB||t===aM.RGB9E5UFloat||t===aM.RGB10A2Unorm||t===aM.RG11B10UFloat||t===aM.Depth32Float||t===aM.Depth24Plus||t===aM.Depth24PlusStencil8||t===aM.Depth32FloatStencil8?4:t===aM.RG32Uint||t===aM.RG32Sint||t===aM.RG32Float||t===aM.RGBA16Uint||t===aM.RGBA16Sint||t===aM.RGBA16Float?8:t===aM.RGBA32Uint||t===aM.RGBA32Sint||t===aM.RGBA32Float?16:void 0}_getTypedArrayType(t){return t===aM.R8Uint?Uint8Array:t===aM.R8Sint?Int8Array:t===aM.R8Unorm?Uint8Array:t===aM.R8Snorm?Int8Array:t===aM.RG8Uint?Uint8Array:t===aM.RG8Sint?Int8Array:t===aM.RG8Unorm?Uint8Array:t===aM.RG8Snorm?Int8Array:t===aM.RGBA8Uint?Uint8Array:t===aM.RGBA8Sint?Int8Array:t===aM.RGBA8Unorm?Uint8Array:t===aM.RGBA8Snorm?Int8Array:t===aM.R16Uint?Uint16Array:t===aM.R16Sint?Int16Array:t===aM.RG16Uint?Uint16Array:t===aM.RG16Sint?Int16Array:t===aM.RGBA16Uint?Uint16Array:t===aM.RGBA16Sint?Int16Array:t===aM.R16Float||t===aM.RG16Float||t===aM.RGBA16Float?Float32Array:t===aM.R32Uint?Uint32Array:t===aM.R32Sint?Int32Array:t===aM.R32Float?Float32Array:t===aM.RG32Uint?Uint32Array:t===aM.RG32Sint?Int32Array:t===aM.RG32Float?Float32Array:t===aM.RGBA32Uint?Uint32Array:t===aM.RGBA32Sint?Int32Array:t===aM.RGBA32Float?Float32Array:t===aM.BGRA8Unorm||t===aM.BGRA8UnormSRGB?Uint8Array:t===aM.RGB10A2Unorm||t===aM.RGB9E5UFloat||t===aM.RG11B10UFloat?Uint32Array:t===aM.Depth32Float?Float32Array:t===aM.Depth24Plus||t===aM.Depth24PlusStencil8?Uint32Array:t===aM.Depth32FloatStencil8?Float32Array:void 0}_getDimension(t){let e;return e=t.isData3DTexture?JM:YM,e}}function aP(t,e=null){const s=t.format,i=t.type,r=t.colorSpace;let n;if(!0===t.isFramebufferTexture&&t.type===At)n=aM.BGRA8Unorm;else if(!0===t.isCompressedTexture)switch(s){case Qt:n=r===Je?aM.BC1RGBAUnormSRGB:aM.BC1RGBAUnorm;break;case Kt:n=r===Je?aM.BC2RGBAUnormSRGB:aM.BC2RGBAUnorm;break;case te:n=r===Je?aM.BC3RGBAUnormSRGB:aM.BC3RGBAUnorm;break;case oe:n=r===Je?aM.ETC2RGB8UnormSRGB:aM.ETC2RGB8Unorm;break;case ae:n=r===Je?aM.ETC2RGBA8UnormSRGB:aM.ETC2RGBA8Unorm;break;case he:n=r===Je?aM.ASTC4x4UnormSRGB:aM.ASTC4x4Unorm;break;case ue:n=r===Je?aM.ASTC5x4UnormSRGB:aM.ASTC5x4Unorm;break;case le:n=r===Je?aM.ASTC5x5UnormSRGB:aM.ASTC5x5Unorm;break;case ce:n=r===Je?aM.ASTC6x5UnormSRGB:aM.ASTC6x5Unorm;break;case de:n=r===Je?aM.ASTC6x6UnormSRGB:aM.ASTC6x6Unorm;break;case pe:n=r===Je?aM.ASTC8x5UnormSRGB:aM.ASTC8x5Unorm;break;case me:n=r===Je?aM.ASTC8x6UnormSRGB:aM.ASTC8x6Unorm;break;case ge:n=r===Je?aM.ASTC8x8UnormSRGB:aM.ASTC8x8Unorm;break;case fe:n=r===Je?aM.ASTC10x5UnormSRGB:aM.ASTC10x5Unorm;break;case ye:n=r===Je?aM.ASTC10x6UnormSRGB:aM.ASTC10x6Unorm;break;case xe:n=r===Je?aM.ASTC10x8UnormSRGB:aM.ASTC10x8Unorm;break;case be:n=r===Je?aM.ASTC10x10UnormSRGB:aM.ASTC10x10Unorm;break;case ve:n=r===Je?aM.ASTC12x10UnormSRGB:aM.ASTC12x10Unorm;break;case Te:n=r===Je?aM.ASTC12x12UnormSRGB:aM.ASTC12x12Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}else switch(s){case Dt:switch(i){case Nt:n=aM.RGBA8Snorm;break;case Rt:n=aM.RGBA16Sint;break;case Ct:n=aM.RGBA16Uint;break;case Bt:n=aM.RGBA32Uint;break;case Et:n=aM.RGBA32Sint;break;case At:n=r===Je?aM.RGBA8UnormSRGB:aM.RGBA8Unorm;break;case Pt:n=aM.RGBA16Float;break;case It:n=aM.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",i)}break;case Vt:if(i===Ot)n=aM.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",i);break;case Ht:switch(i){case Nt:n=aM.R8Snorm;break;case Rt:n=aM.R16Sint;break;case Ct:n=aM.R16Uint;break;case Bt:n=aM.R32Uint;break;case Et:n=aM.R32Sint;break;case At:n=aM.R8Unorm;break;case Pt:n=aM.R16Float;break;case It:n=aM.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",i)}break;case $t:switch(i){case Nt:n=aM.RG8Snorm;break;case Rt:n=aM.RG16Sint;break;case Ct:n=aM.RG16Uint;break;case Bt:n=aM.RG32Uint;break;case Et:n=aM.RG32Sint;break;case At:n=aM.RG8Unorm;break;case Pt:n=aM.RG16Float;break;case It:n=aM.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",i)}break;case Wt:switch(i){case Ct:n=aM.Depth16Unorm;break;case Bt:n=aM.Depth24Plus;break;case It:n=aM.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",i)}break;case jt:switch(i){case zt:n=aM.Depth24PlusStencil8;break;case It:e&&!1===e.features.has(rA.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),n=aM.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",i)}break;case qt:switch(i){case Et:n=aM.R32Sint;break;case Bt:n=aM.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",i)}break;case Xt:switch(i){case Et:n=aM.RG32Sint;break;case Bt:n=aM.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",i)}break;case Jt:switch(i){case Et:n=aM.RGBA32Sint;break;case Bt:n=aM.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",i)}break;default:console.error("WebGPURenderer: Unsupported texture format.",s)}return n}const hP=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,uP=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,lP={f32:"float",i32:"int",u32:"uint",bool:"bool","vec2<f32>":"vec2","vec2<i32>":"ivec2","vec2<u32>":"uvec2","vec2<bool>":"bvec2",vec2f:"vec2",vec2i:"ivec2",vec2u:"uvec2",vec2b:"bvec2","vec3<f32>":"vec3","vec3<i32>":"ivec3","vec3<u32>":"uvec3","vec3<bool>":"bvec3",vec3f:"vec3",vec3i:"ivec3",vec3u:"uvec3",vec3b:"bvec3","vec4<f32>":"vec4","vec4<i32>":"ivec4","vec4<u32>":"uvec4","vec4<bool>":"bvec4",vec4f:"vec4",vec4i:"ivec4",vec4u:"uvec4",vec4b:"bvec4","mat2x2<f32>":"mat2",mat2x2f:"mat2","mat3x3<f32>":"mat3",mat3x3f:"mat3","mat4x4<f32>":"mat4",mat4x4f:"mat4",sampler:"sampler",texture_1d:"texture",texture_2d:"texture",texture_2d_array:"texture",texture_multisampled_2d:"cubeTexture",texture_depth_2d:"depthTexture",texture_3d:"texture3D",texture_cube:"cubeTexture",texture_cube_array:"cubeTexture",texture_storage_1d:"storageTexture",texture_storage_2d:"storageTexture",texture_storage_2d_array:"storageTexture",texture_storage_3d:"storageTexture"};class cP extends NE{constructor(t){const{type:e,inputs:s,name:i,inputsCode:r,blockCode:n,outputType:o}=(t=>{const e=(t=t.trim()).match(hP);if(null!==e&&4===e.length){const s=e[2],i=[];let r=null;for(;null!==(r=uP.exec(s));)i.push({name:r[1],type:r[2]});const n=[];for(let t=0;t<i.length;t++){const{name:e,type:s}=i[t];let r=s;r.startsWith("texture")&&(r=s.split("<")[0]),r=lP[r]||r,n.push(new V_(r,e))}const o=t.substring(e[0].length),a=e[3]||"void",h=void 0!==e[1]?e[1]:"";return{type:lP[a]||a,inputs:n,name:h,inputsCode:s,blockCode:o,outputType:a}}throw new Error("FunctionNode: Function is not a WGSL code.")})(t);super(e,s,i),this.inputsCode=r,this.blockCode=n,this.outputType=o}getCode(t=this.name){const e="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class dP extends AE{parseFunction(t){return new cP(t)}}const pP=self.GPUShaderStage,mP={vertex:pP?pP.VERTEX:1,fragment:pP?pP.FRAGMENT:2,compute:pP?pP.COMPUTE:4},gP={instance:!0,swizzleAssign:!1,storageBuffer:!0},fP={"^^":"threejs_xor"},yP={float:"f32",int:"i32",uint:"u32",bool:"bool",color:"vec3<f32>",vec2:"vec2<f32>",ivec2:"vec2<i32>",uvec2:"vec2<u32>",bvec2:"vec2<bool>",vec3:"vec3<f32>",ivec3:"vec3<i32>",uvec3:"vec3<u32>",bvec3:"vec3<bool>",vec4:"vec4<f32>",ivec4:"vec4<i32>",uvec4:"vec4<u32>",bvec4:"vec4<bool>",mat2:"mat2x2<f32>",imat2:"mat2x2<i32>",umat2:"mat2x2<u32>",bmat2:"mat2x2<bool>",mat3:"mat3x3<f32>",imat3:"mat3x3<i32>",umat3:"mat3x3<u32>",bmat3:"mat3x3<bool>",mat4:"mat4x4<f32>",imat4:"mat4x4<i32>",umat4:"mat4x4<u32>",bmat4:"mat4x4<bool>"},xP={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"threejs_mod_float",mod_vec2:"threejs_mod_vec2",mod_vec3:"threejs_mod_vec3",mod_vec4:"threejs_mod_vec4",equals_bool:"threejs_equals_bool",equals_bvec2:"threejs_equals_bvec2",equals_bvec3:"threejs_equals_bvec3",equals_bvec4:"threejs_equals_bvec4",lessThanEqual:"threejs_lessThanEqual",greaterThan:"threejs_greaterThan",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"},bP={threejs_xor:new qg("\nfn threejs_xor( a : bool, b : bool ) -> bool {\n\n\treturn ( a || b ) && !( a && b );\n\n}\n"),lessThanEqual:new qg("\nfn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {\n\n\treturn vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );\n\n}\n"),greaterThan:new qg("\nfn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {\n\n\treturn vec3<bool>( a.x > b.x, a.y > b.y, a.z > b.z );\n\n}\n"),mod_float:new qg("fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new qg("fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new qg("fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new qg("fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new qg("fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new qg("fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new qg("fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }"),equals_bvec4:new qg("fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }"),repeatWrapping:new qg("\nfn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {\n\n\tlet uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );\n\n\treturn ( ( uvScaled % dimension ) + dimension ) % dimension;\n\n}\n"),biquadraticTexture:new qg("\nfn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet res = vec2f( textureDimensions( map, level ) );\n\n\tlet uvScaled = coord * res;\n\tlet uvWrapping = ( ( uvScaled % res ) + res ) % res;\n\n\t// https://www.shadertoy.com/view/WtyXRy\n\n\tlet uv = uvWrapping - 0.5;\n\tlet iuv = floor( uv );\n\tlet f = fract( uv );\n\n\tlet rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")};class vP extends O_{constructor(t,e){super(t,e,new dP),this.uniformGroups={},this.builtins={},this.directives={}}needsColorSpaceToLinear(t){return!0===t.isVideoTexture&&t.colorSpace!==Ye}_generateTextureSample(t,e,s,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${s}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${s} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s):this.generateTextureLod(t,e,s,"0")}_generateVideoSample(t,e,s=this.shaderStage){if("fragment"===s)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2<f32>( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${s} shader.`)}_generateTextureSampleLevel(t,e,s,i,r,n=this.shaderStage){return"fragment"===n&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${s}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,s,i):this.generateTextureLod(t,e,s,i)}generateFilteredTexture(t,e,s,i="0"){return this._include("biquadraticTexture"),`threejs_biquadraticTexture( ${e}, ${s}, i32( ${i} ) )`}generateTextureLod(t,e,s,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, threejs_repeatWrapping( ${s}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,s,i,r="0u"){return i?`textureLoad( ${e}, ${s}, ${i}, ${r} )`:`textureLoad( ${e}, ${s}, ${r} )`}generateTextureStore(t,e,s,i){return`textureStore( ${e}, ${s}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!0===t.isDataTexture&&t.type===It||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,s,i,r=this.shaderStage){let n=null;return n=!0===t.isVideoTexture?this._generateVideoSample(e,s,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,s,"0",i,r):this._generateTextureSample(t,e,s,i,r),n}generateTextureGrad(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleGrad( ${e}, ${e}_sampler, ${s}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${n} shader.`)}generateTextureCompare(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleCompare( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${n} shader.`)}generateTextureLevel(t,e,s,i,r,n=this.shaderStage){let o=null;return o=!0===t.isVideoTexture?this._generateVideoSample(e,s,n):this._generateTextureSampleLevel(t,e,s,i,r,n),o}generateTextureBias(t,e,s,i,r,n=this.shaderStage){if("fragment"===n)return`textureSampleBias( ${e}, ${e}_sampler, ${s}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${n} shader.`)}getPropertyName(t,e=this.shaderStage){if(!0===t.isNodeVarying&&!0===t.needsInterpolation){if("vertex"===e)return`varyings.${t.name}`}else if(!0===t.isNodeUniform){const e=t.name,s=t.type;return"texture"===s||"cubeTexture"===s||"storageTexture"===s||"texture3D"===s?e:"buffer"===s||"storageBuffer"===s?`NodeBuffer_${t.id}.${e}`:t.groupNode.name+"."+e}return super.getPropertyName(t)}getOutputStructName(){return"output"}_getUniformGroupCount(t){return Object.keys(this.uniforms[t]).length}getFunctionOperator(t){const e=fP[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case jM:return"read";case WM:return"write";default:return"read_write"}else switch(t.access){case kM:return"read_write";case GM:return"read";default:return"write"}}getUniformFromNode(t,e,s,i=null){const r=super.getUniformFromNode(t,e,s,i),n=this.getDataFromNode(t,s,this.globalCache);if(void 0===n.uniformGPU){let i;const o=t.groupNode,a=o.name,h=this.getBindGroupArray(a,s);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let n=null;if("texture"===e||"storageTexture"===e?n=new _I(r.name,r.node,o,t.access?t.access:null):"cubeTexture"===e?n=new wI(r.name,r.node,o,t.access?t.access:null):"texture3D"===e&&(n=new SI(r.name,r.node,o,t.access?t.access:null)),n.store=!0===t.isStorageTextureNode,n.setVisibility(mP[s]),"fragment"===s&&!1===this.isUnfilterable(t.value)&&!1===n.store){const t=new KI(`${r.name}_sampler`,r.node,o);t.setVisibility(mP[s]),h.push(t,n),i=[t,n]}else h.push(n),i=[n]}else if("buffer"===e||"storageBuffer"===e){const r=new("storageBuffer"===e?sP:fI)(t,o);r.setVisibility(mP[s]),h.push(r),i=r}else{const t=this.uniformGroups[s]||(this.uniformGroups[s]={});let n=t[a];void 0===n&&(n=new bI(a,o),n.setVisibility(mP[s]),t[a]=n,h.push(n)),i=this.getNodeUniform(r,e),n.addUniform(i)}n.uniformGPU=i}return r}getBuiltin(t,e,s,i=this.shaderStage){const r=this.builtins[i]||(this.builtins[i]=new Map);return!1===r.has(t)&&r.set(t,{name:t,property:e,type:s}),e}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,s=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));return`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${s.vars}\n${s.code}\n\treturn ${s.result};\n\n}`}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xyz"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}enableDirective(t,e=this.shaderStage){(this.directives[e]||(this.directives[e]=[])).push(t)}getDirectives(t){const e=[],s=this.directives[t];if(void 0!==s)for(const t of s)e.push(`enable ${t}`);return e.join("\n")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}getBuiltins(t){const e=[],s=this.builtins[t];if(void 0!==s)for(const{name:t,property:i,type:r}of s.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getAttributes(t){const e=[];if("compute"===t&&(this.getBuiltin("global_invocation_id","id","vec3<u32>","attribute"),this.getBuiltin("workgroup_id","workgroupId","vec3<u32>","attribute"),this.getBuiltin("local_invocation_id","localId","vec3<u32>","attribute"),this.getBuiltin("num_workgroups","numWorkgroups","vec3<u32>","attribute")),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const s=this.getAttributesArray();for(let t=0,i=s.length;t<i;t++){const i=s[t],r=i.name,n=this.getType(i.type);e.push(`@location( ${t} ) ${r} : ${n}`)}}return e.join(",\n\t")}getStructMembers(t){const e=[],s=t.getMemberTypes();for(let t=0;t<s.length;t++){const i=s[t];e.push(`\t@location( ${t} ) m${t} : ${i}<f32>`)}const i=this.getBuiltins("output");return i&&e.push(i),e.join(",\n")}getStructs(t){const e=[],s=this.structs[t];for(let t=0,i=s.length;t<i;t++){const i=s[t],r=i.name;let n=`struct ${r} {\n`;n+=this.getStructMembers(i),n+="\n}",e.push(n),e.push(`\nvar<private> output : ${r};\n\n`)}return e.join("\n\n")}getVar(t,e){return`var ${e} : ${this.getType(t)}`}getVars(t){const e=[],s=this.vars[t];if(void 0!==s)for(const t of s)e.push(`\t${this.getVar(t.type,t.name)};`);return`\n${e.join("\n")}\n`}getVaryings(t){const e=[];if("vertex"===t&&this.getBuiltin("position","Vertex","vec4<f32>","vertex"),"vertex"===t||"fragment"===t){const s=this.varyings,i=this.vars[t];for(let r=0;r<s.length;r++){const n=s[r];if(n.needsInterpolation){let t=`@location( ${r} )`;/^(int|uint|ivec|uvec)/.test(n.type)&&(t+=" @interpolate( flat )"),e.push(`${t} ${n.name} : ${this.getType(n.type)}`)}else"vertex"===t&&!1===i.includes(n)&&i.push(n)}}const s=this.getBuiltins(t);s&&e.push(s);const i=e.join(",\n\t");return"vertex"===t?this._getWGSLStruct("VaryingsStruct","\t"+i):i}getUniforms(t){const e=this.uniforms[t],s=[],i=[],r=[],n={};for(const r of e){const e=r.groupNode.name,o=this.bindingsIndexes[e];if("texture"===r.type||"cubeTexture"===r.type||"storageTexture"===r.type||"texture3D"===r.type){const e=r.node.value;let i;"fragment"===t&&!1===this.isUnfilterable(e)&&!0!==r.node.isStorageTextureNode&&(!0===e.isDepthTexture&&null!==e.compareFunction?s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler_comparison;`):s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name}_sampler : sampler;`));let n="";if(!0===e.isMultisampleRenderTargetTexture&&(n="_multisampled"),!0===e.isCubeTexture)i="texture_cube<f32>";else if(!0===e.isDataArrayTexture)i="texture_2d_array<f32>";else if(!0===e.isDepthTexture)i=`texture_depth${n}_2d`;else if(!0===e.isVideoTexture)i="texture_external";else if(!0===e.isData3DTexture)i="texture_3d<f32>";else if(!0===r.node.isStorageTextureNode){i=`texture_storage_2d<${aP(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${n}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}s.push(`@binding( ${o.binding++} ) @group( ${o.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),s=t.bufferCount,n=s>0?", "+s:"",a=`\t${r.name} : array< ${e}${n} >\n`,h=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,a,h,o.binding++,o.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(n[e]||(n[e]={index:o.binding++,id:o.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in n){const e=n[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let o=s.join("\n");return o+=i.join("\n"),o+=r.join("\n"),o}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};for(const e in t){const s=t[e];s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.structs=this.getStructs(e),s.vars=this.getVars(e),s.codes=this.getCodes(e),s.directives=this.getDirectives(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],n=r[r.length-1],o=n.outputNode,a=void 0!==o&&!0===o.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),h=t.name;if(h&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${h}\n\t`),i+=`${r.code}\n\t`,t===n&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(a)s.returnType=o.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4<f32>";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),s.returnType="OutputStruct",s.structs+=this._getWGSLStruct("OutputStruct",t),s.structs+="\nvar<private> output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}s.flow=i}null!==this.material?(this.vertexShader=this._getWGSLVertexCode(t.vertex),this.fragmentShader=this._getWGSLFragmentCode(t.fragment)):this.computeShader=this._getWGSLComputeCode(t.compute,(this.object.workgroupSize||[64]).join(", "))}getMethod(t,e=null){let s;return null!==e&&(s=this._getWGSLMethod(t+"_"+e)),void 0===s&&(s=this._getWGSLMethod(t)),s||t}getType(t){return yP[t]||t}isAvailable(t){let e=gP[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),gP[t]=e),e}_getWGSLMethod(t){return void 0!==bP[t]&&this._include(t),xP[t]}_include(t){const e=bP[t];return e.build(this),null!==this.currentFunctionNode&&this.currentFunctionNode.includes.push(e),e}_getWGSLVertexCode(t){return`${this.getSignature()}\n// directives\n${t.directives};\n\n// uniforms\n${t.uniforms}\n\n// varyings\n${t.varyings}\nvar<private> varyings : VaryingsStruct;\n\n// codes\n${t.codes}\n\n@vertex\nfn main( ${t.attributes} ) -> VaryingsStruct {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n\treturn varyings;\n\n}\n`}_getWGSLFragmentCode(t){return`${this.getSignature()}\n\ndiagnostic( off, derivative_uniformity );\n\n// uniforms\n${t.uniforms}\n\n// structs\n${t.structs}\n\n// codes\n${t.codes}\n\n@fragment\nfn main( ${t.varyings} ) -> ${t.returnType} {\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLComputeCode(t,e){return`${this.getSignature()}\n// directives\n${t.directives}\n\n// system\nvar<private> instanceIndex : u32;\n\n// uniforms\n${t.uniforms}\n\n// codes\n${t.codes}\n\n@compute @workgroup_size( ${e} )\nfn main( ${t.attributes} ) {\n\n\t// system\n\tinstanceIndex = id.x + id.y * numWorkgroups.x * u32(${e}) + id.z * numWorkgroups.x * numWorkgroups.y * u32(${e});\n\n\t// vars\n\t${t.vars}\n\n\t// flow\n\t${t.flow}\n\n}\n`}_getWGSLStruct(t,e){return`\nstruct ${t} {\n${e}\n};`}_getWGSLStructBinding(t,e,s,i=0,r=0){const n=t+"Struct";return`${this._getWGSLStruct(n,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${s}> ${t} : ${n};`}}class TP{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=aM.Depth24PlusStencil8:t.depth&&(e=aM.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).texture.format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):aM.BGRA8Unorm,e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?VS:t.isLineSegments||t.isMesh&&!0===e.wireframe?DS:t.isLine?kS:t.isMesh?GS:void 0}getSampleCount(t){let e=1;return t>1&&(e=Math.pow(2,Math.floor(Math.log2(t))),2===e&&(e=4)),e}getSampleCountRenderContext(t){return null!==t.textures?this.getSampleCount(t.sampleCount):this.getSampleCount(this.backend.renderer.samples)}}const _P=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),wP=new Map([[fn,["float16"]]]),SP=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class MP{constructor(t){this.backend=t}createAttribute(t,e){const s=this._getBufferAttribute(t),i=this.backend,r=i.get(s);let n=r.buffer;if(void 0===n){const o=i.device;let a=s.array;if(!1===t.normalized&&(a.constructor===Int16Array||a.constructor===Uint16Array)){const t=new Uint32Array(a.length);for(let e=0;e<a.length;e++)t[e]=a[e];a=t}if(s.array=a,(s.isStorageBufferAttribute||s.isStorageInstancedBufferAttribute)&&3===s.itemSize){a=new a.constructor(4*s.count);for(let t=0;t<s.count;t++)a.set(s.array.subarray(3*t,3*t+3),4*t);s.itemSize=4,s.array=a}const h=a.byteLength+(4-a.byteLength%4)%4;n=o.createBuffer({label:s.name,size:h,usage:e,mappedAtCreation:!0}),new a.constructor(n.getMappedRange()).set(a),n.unmap(),r.buffer=n}}updateAttribute(t){const e=this._getBufferAttribute(t),s=this.backend,i=s.device,r=s.get(e).buffer,n=e.array,o=e.updateRanges;if(0===o.length)i.queue.writeBuffer(r,0,n,0);else{for(let t=0,e=o.length;t<e;t++){const e=o[t];i.queue.writeBuffer(r,0,n,e.start*n.BYTES_PER_ELEMENT,e.count*n.BYTES_PER_ELEMENT)}e.clearUpdateRanges()}}createShaderVertexBuffers(t){const e=t.getAttributes(),s=new Map;for(let t=0;t<e.length;t++){const i=e[t],r=i.array.BYTES_PER_ELEMENT,n=this._getBufferAttribute(i);let o=s.get(n);if(void 0===o){let t,e;!0===i.isInterleavedBufferAttribute?(t=i.data.stride*r,e=i.data.isInstancedInterleavedBuffer?iA:sA):(t=i.itemSize*r,e=i.isInstancedBufferAttribute?iA:sA),!1!==i.normalized||i.array.constructor!==Int16Array&&i.array.constructor!==Uint16Array||(t=4),o={arrayStride:t,attributes:[],stepMode:e},s.set(n,o)}const a=this._getVertexFormat(i),h=!0===i.isInterleavedBufferAttribute?i.offset*r:0;o.attributes.push({shaderLocation:t,offset:h,format:a})}return Array.from(s.values())}destroyAttribute(t){const e=this.backend;e.get(this._getBufferAttribute(t)).buffer.destroy(),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,s=e.device,i=e.get(this._getBufferAttribute(t)),r=i.buffer,n=r.size;let o=i.readBuffer,a=!0;void 0===o&&(o=s.createBuffer({label:t.name,size:n,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=!1,i.readBuffer=o);const h=s.createCommandEncoder({});h.copyBufferToBuffer(r,0,o,0,n),a&&o.unmap();const u=h.finish();s.queue.submit([u]),await o.mapAsync(GPUMapMode.READ);return o.getMappedRange()}_getVertexFormat(t){const{itemSize:e,normalized:s}=t,i=t.array.constructor,r=t.constructor;let n;if(1==e)n=SP.get(i);else{const t=(wP.get(r)||_P.get(i))[s?1:0];if(t){const s=i.BYTES_PER_ELEMENT*e,r=4*Math.floor((s+3)/4)/i.BYTES_PER_ELEMENT;if(r%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");n=`${t}x${r}`}}return n||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),n}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}class AP{constructor(t){this.backend=t}createBindingsLayout(t){const e=this.backend.device,s=[];let i=0;for(const e of t.bindings){const t={binding:i++,visibility:e.visibility};if(e.isUniformBuffer||e.isStorageBuffer){const s={};e.isStorageBuffer&&(s.type=e.access),t.buffer=s}else if(e.isSampler){const s={};e.texture.isDepthTexture&&null!==e.texture.compareFunction&&(s.type="comparison"),t.sampler=s}else if(e.isSampledTexture&&e.texture.isVideoTexture)t.externalTexture={};else if(e.isSampledTexture&&e.store){const s=this.backend.get(e.texture).texture.format,i=e.access;t.storageTexture={format:s,access:i}}else if(e.isSampledTexture){const s={};if(!0===e.texture.isMultisampleRenderTargetTexture&&(s.multisampled=!0),e.texture.isDepthTexture)s.sampleType=qM;else if(e.texture.isDataTexture||e.texture.isDataArrayTexture||e.texture.isData3DTexture){const t=e.texture.type;t===Et?s.sampleType=$M:t===Bt?s.sampleType=XM:t===It&&(s.sampleType=HM)}e.isSampledCubeTexture?s.viewDimension=KM:e.texture.isDataArrayTexture?s.viewDimension=QM:e.isSampledTexture3D&&(s.viewDimension=tA),t.texture=s}else console.error(`WebGPUBindingUtils: Unsupported binding "${e}".`);s.push(t)}return e.createBindGroupLayout({entries:s})}createBindings(t){const e=this.backend.get(t),s=this.createBindingsLayout(t),i=this.createBindGroup(t,s);e.layout=s,e.group=i}updateBinding(t){const e=this.backend,s=e.device,i=t.buffer,r=e.get(t).buffer;s.queue.writeBuffer(r,0,i,0)}createBindGroup(t,e){const s=this.backend,i=s.device;let r=0;const n=[];for(const e of t.bindings){if(e.isUniformBuffer){const t=s.get(e);if(void 0===t.buffer){const s=e.byteLength,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,n=i.createBuffer({label:"bindingBuffer_"+e.name,size:s,usage:r});t.buffer=n}n.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isStorageBuffer){const t=s.get(e);if(void 0===t.buffer){const i=e.attribute;t.buffer=s.get(i).buffer}n.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isSampler){const t=s.get(e.texture);n.push({binding:r,resource:t.sampler})}else if(e.isSampledTexture){const t=s.get(e.texture);let o,a;if(o=e.isSampledCubeTexture?KM:e.isSampledTexture3D?tA:e.texture.isDataArrayTexture?QM:ZM,void 0!==t.externalTexture)a=i.importExternalTexture({source:t.externalTexture});else{const s=eA;a=t.texture.createView({aspect:s,dimension:o,mipLevelCount:e.store?1:t.mipLevelCount})}n.push({binding:r,resource:a})}r++}return i.createBindGroup({label:"bindGroup_"+t.name,layout:e,entries:n})}}class NP{constructor(t){this.backend=t}_getSampleCount(t){return this.backend.utils.getSampleCountRenderContext(t)}createRenderPipeline(t,e){const{object:s,material:i,geometry:r,pipeline:n}=t,{vertexProgram:o,fragmentProgram:a}=n,h=this.backend,u=h.device,l=h.utils,c=h.get(n),d=[];for(const e of t.getBindings()){const t=h.get(e);d.push(t.layout)}const p=h.attributeUtils.createShaderVertexBuffers(t);let g;!0===i.transparent&&i.blending!==m&&(g=this._getBlending(i));let f={};!0===i.stencilWrite&&(f={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const y=this._getColorWriteMask(i),x=[];if(null!==t.context.textures){const e=t.context.textures;for(let t=0;t<e.length;t++){const s=l.getTextureFormatGPU(e[t]);x.push({format:s,blend:g,writeMask:y})}}else{const e=l.getCurrentColorFormat(t.context);x.push({format:e,blend:g,writeMask:y})}const b=h.get(o).module,v=h.get(a).module,T=this._getPrimitiveState(s,r,i),_=this._getDepthCompare(i),w=l.getCurrentDepthStencilFormat(t.context),S=this._getSampleCount(t.context),M={label:"renderPipeline",vertex:Object.assign({},b,{buffers:p}),fragment:Object.assign({},v,{targets:x}),primitive:T,depthStencil:{format:w,depthWriteEnabled:i.depthWrite,depthCompare:_,stencilFront:f,stencilBack:{},stencilReadMask:i.stencilFuncMask,stencilWriteMask:i.stencilWriteMask},multisample:{count:S,alphaToCoverageEnabled:i.alphaToCoverage},layout:u.createPipelineLayout({bindGroupLayouts:d})};if(null===e)c.pipeline=u.createRenderPipeline(M);else{const t=new Promise((t=>{u.createRenderPipelineAsync(M).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t,e){const s=this.backend,{utils:i,device:r}=s,n=s.get(t),o=s.get(e),a=i.getCurrentDepthStencilFormat(t),h={label:"renderBundleEncoder",colorFormats:[i.getCurrentColorFormat(t)],depthStencilFormat:a,sampleCount:this._getSampleCount(e.context)},u=r.createRenderBundleEncoder(h);return o.bundleEncoder=u,n.currentSets={attributes:{}},n._renderBundleViewport=t.width+"_"+t.height,u}createComputePipeline(t,e){const s=this.backend,i=s.device,r=s.get(t.computeProgram).module,n=s.get(t),o=[];for(const t of e){const e=s.get(t);o.push(e.layout)}n.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:o})})}_getBlending(t){let e,s;const i=t.blending,r=t.blendSrc,n=t.blendDst,o=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,a=null!==t.blendDstAlpha?t.blendDstAlpha:n,h=null!==t.blendEquationAlpha?t.blendEquationAlpha:o;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(n),operation:this._getBlendOperation(o)},s={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(a),operation:this._getBlendOperation(h)}}else{const r=(t,i,r,n)=>{e={srcFactor:t,dstFactor:i,operation:AM},s={srcFactor:r,dstFactor:n,operation:AM}};if(t.premultipliedAlpha)switch(i){case 1:r(yM,xM,mM,xM);break;case 2:r(yM,mM,mM,mM);break;case 3:r(pM,fM,pM,mM);break;case 4:r(pM,gM,pM,yM)}else switch(i){case 1:r(yM,xM,mM,xM);break;case 2:r(yM,mM,yM,mM);break;case 3:r(pM,fM,pM,mM);break;case 4:r(pM,gM,pM,gM)}}if(void 0!==e&&void 0!==s)return{color:e,alpha:s};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=pM;break;case 201:e=mM;break;case 202:e=gM;break;case 203:e=fM;break;case C:e=yM;break;case E:e=xM;break;case 208:e=bM;break;case 209:e=vM;break;case 206:e=TM;break;case 207:e=_M;break;case 210:e=wM;break;case 211:e=SM;break;case 212:e=MM;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const s=t.stencilFunc;switch(s){case 512:e=jS;break;case bs:e=ZS;break;case 513:e=HS;break;case 515:e=$S;break;case 514:e=qS;break;case 518:e=JS;break;case 516:e=XS;break;case 517:e=YS;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",s)}return e}_getStencilOperation(t){let e;switch(t){case ns:e=PM;break;case 0:e=FM;break;case 7681:e=UM;break;case 5386:e=zM;break;case 7682:e=OM;break;case 7683:e=LM;break;case 34055:e=VM;break;case 34056:e=DM;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case v:e=AM;break;case 101:e=NM;break;case 102:e=RM;break;case 103:e=CM;break;case 104:e=EM;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,s){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,s),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?nM:oM),s.side){case c:i.frontFace=eM,i.cullMode=rM;break;case d:i.frontFace=eM,i.cullMode=iM;break;case 2:i.frontFace=eM,i.cullMode=sM;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",s.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?IM:BM}_getDepthCompare(t){let e;if(!1===t.depthTest)e=ZS;else{const s=t.depthFunc;switch(s){case 0:e=jS;break;case 1:e=ZS;break;case 2:e=HS;break;case 3:e=$S;break;case 4:e=qS;break;case 5:e=JS;break;case 6:e=XS;break;case 7:e=YS;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",s)}}return e}}class RP extends PI{constructor(t={}){super(t),this.isWebGPUBackend=!0,this.parameters.alpha=void 0===t.alpha||t.alpha,this.parameters.requiredLimits=void 0===t.requiredLimits?{}:t.requiredLimits,this.trackTimestamp=!0===t.trackTimestamp,this.device=null,this.context=null,this.colorBuffer=null,this.defaultRenderPassdescriptor=null,this.utils=new TP(this),this.attributeUtils=new MP(this),this.bindingUtils=new AP(this),this.pipelineUtils=new NP(this),this.textureUtils=new oP(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let s;if(void 0===e.device){const t={powerPreference:e.powerPreference},i=await navigator.gpu.requestAdapter(t);if(null===i)throw new Error("WebGPUBackend: Unable to create WebGPU adapter.");const r=Object.values(rA),n=[];for(const t of r)i.features.has(t)&&n.push(t);const o={requiredFeatures:n,requiredLimits:e.requiredLimits};s=await i.requestDevice(o)}else s=e.device;const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=s,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.context.configure({device:this.device,format:aM.BGRA8Unorm,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return Ds}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}getContext(){return this.context}_getDefaultRenderPassDescriptor(){let t=this.defaultRenderPassdescriptor;if(null===t){const e=this.renderer;t={colorAttachments:[{view:null}],depthStencilAttachment:{view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()}};const s=t.colorAttachments[0];this.renderer.samples>0?s.view=this.colorBuffer.createView():s.resolveTarget=void 0,this.defaultRenderPassdescriptor=t}const e=t.colorAttachments[0];return this.renderer.samples>0?e.resolveTarget=this.context.getCurrentTexture().createView():e.view=this.context.getCurrentTexture().createView(),t}_getRenderPassDescriptor(t){const e=t.renderTarget,s=this.get(e);let i=s.descriptors;if(void 0===i&&(i=[],s.descriptors=i),s.width!==e.width||s.height!==e.height||s.activeMipmapLevel!==e.activeMipmapLevel||s.samples!==e.samples||i.length!==e.textures.length){i.length=0;const t=()=>{e.removeEventListener("dispose",t),this.delete(e)};e.addEventListener("dispose",t)}let r=i[t.activeCubeFace];if(void 0===r){const n=t.textures,o=[];for(let e=0;e<n.length;e++){const s=this.get(n[e]),i=s.texture.createView({baseMipLevel:t.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:t.activeCubeFace,dimension:ZM});let r,a;void 0!==s.msaaTexture?(r=s.msaaTexture.createView(),a=i):(r=i,a=void 0),o.push({view:r,resolveTarget:a,loadOp:KS,storeOp:QS})}r={colorAttachments:o,depthStencilAttachment:{view:this.get(t.depthTexture).texture.createView()}},i[t.activeCubeFace]=r,s.width=e.width,s.height=e.height,s.samples=e.samples,s.activeMipmapLevel=e.activeMipmapLevel}return r}beginRender(t){const e=this.get(t),s=this.device,i=t.occlusionQueryCount;let r,n;i>0&&(e.currentOcclusionQuerySet&&e.currentOcclusionQuerySet.destroy(),e.currentOcclusionQueryBuffer&&e.currentOcclusionQueryBuffer.destroy(),e.currentOcclusionQuerySet=e.occlusionQuerySet,e.currentOcclusionQueryBuffer=e.occlusionQueryBuffer,e.currentOcclusionQueryObjects=e.occlusionQueryObjects,r=s.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),n=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,n),n.occlusionQuerySet=r;const o=n.depthStencilAttachment;if(null!==t.textures){const e=n.colorAttachments;for(let s=0;s<e.length;s++){const i=e[s];t.clearColor?(i.clearValue=t.clearColorValue,i.loadOp=tM,i.storeOp=QS):(i.loadOp=KS,i.storeOp=QS)}}else{const e=n.colorAttachments[0];t.clearColor?(e.clearValue=t.clearColorValue,e.loadOp=tM,e.storeOp=QS):(e.loadOp=KS,e.storeOp=QS)}t.depth&&(t.clearDepth?(o.depthClearValue=t.clearDepthValue,o.depthLoadOp=tM,o.depthStoreOp=QS):(o.depthLoadOp=KS,o.depthStoreOp=QS)),t.stencil&&(t.clearStencil?(o.stencilClearValue=t.clearStencilValue,o.stencilLoadOp=tM,o.stencilStoreOp=QS):(o.stencilLoadOp=KS,o.stencilStoreOp=QS));const a=s.createCommandEncoder({label:"renderContext_"+t.id}),h=a.beginRenderPass(n);if(e.descriptor=n,e.encoder=a,e.currentPass=h,e.currentSets={attributes:{}},t.viewport&&this.updateViewport(t),t.scissor){const{x:e,y:s,width:i,height:r}=t.scissorValue;h.setScissorRect(e,t.height-r-s,i,r)}}finishRender(t){const e=this.get(t),s=t.occlusionQueryCount;if(void 0!==e.renderBundles&&e.renderBundles.length>0&&(e.registerBundlesPhase=!1,e.currentPass.executeBundles(e.renderBundles)),s>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),s>0){const i=8*s;let r=this.occludedResolveCache.get(i);void 0===r&&(r=this.device.createBuffer({size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),this.occludedResolveCache.set(i,r));const n=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,s,r,0),e.encoder.copyBufferToBuffer(r,0,n,0,i),e.occlusionQueryBuffer=n,this.resolveOccludedAsync(t)}if(this.prepareTimestampBuffer(t,e.encoder),this.device.queue.submit([e.encoder.finish()]),null!==t.textures){const e=t.textures;for(let t=0;t<e.length;t++){const s=e[t];!0===s.generateMipmaps&&this.textureUtils.generateMipmaps(s)}}}isOccluded(t,e){const s=this.get(t);return s.occluded&&s.occluded.has(e)}async resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueryBuffer:s,currentOcclusionQueryObjects:i}=e;if(s&&i){const t=new WeakSet;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueryBuffer=null,await s.mapAsync(GPUMapMode.READ);const r=s.getMappedRange(),n=new BigUint64Array(r);for(let e=0;e<i.length;e++)n[e]!==BigInt(0)&&t.add(i[e]);s.destroy(),e.occluded=t}}updateViewport(t){const{currentPass:e}=this.get(t),{x:s,y:i,width:r,height:n,minDepth:o,maxDepth:a}=t.viewportValue;e.setViewport(s,t.height-n-i,r,n,o,a)}clear(t,e,s,i=null){const r=this.device,n=this.renderer;let o,a,h,u,l=[];if(t){const t=this.getClearColor();a={r:t.r,g:t.g,b:t.b,a:t.a}}if(null===i){h=n.depth,u=n.stencil;const e=this._getDefaultRenderPassDescriptor();if(t){l=e.colorAttachments;const t=l[0];t.clearValue=a,t.loadOp=tM,t.storeOp=QS}(h||u)&&(o=e.depthStencilAttachment)}else{if(h=i.depth,u=i.stencil,t)for(const t of i.textures){const e=this.get(t),s=e.texture.createView();let i,r;void 0!==e.msaaTexture?(i=e.msaaTexture.createView(),r=s):(i=s,r=void 0),l.push({view:i,resolveTarget:r,clearValue:a,loadOp:tM,storeOp:QS})}if(h||u){o={view:this.get(i.depthTexture).texture.createView()}}}h&&(e?(o.depthLoadOp=tM,o.depthClearValue=n.getClearDepth(),o.depthStoreOp=QS):(o.depthLoadOp=KS,o.depthStoreOp=QS)),u&&(s?(o.stencilLoadOp=tM,o.stencilClearValue=n.getClearStencil(),o.stencilStoreOp=QS):(o.stencilLoadOp=KS,o.stencilStoreOp=QS));const c=r.createCommandEncoder({});c.beginRenderPass({colorAttachments:l,depthStencilAttachment:o}).end(),r.queue.submit([c.finish()])}beginCompute(t){const e=this.get(t),s={};this.initTimestampQuery(t,s),e.cmdEncoderGPU=this.device.createCommandEncoder(),e.passEncoderGPU=e.cmdEncoderGPU.beginComputePass(s)}compute(t,e,s,i){const{passEncoderGPU:r}=this.get(t),n=this.get(i).pipeline;r.setPipeline(n);for(let t=0,e=s.length;t<e;t++){const e=s[t],i=this.get(e);r.setBindGroup(t,i.group)}const o=this.device.limits.maxComputeWorkgroupsPerDimension,a=this.get(e);void 0===a.dispatchSize&&(a.dispatchSize={x:0,y:1,z:1});const{dispatchSize:h}=a;e.dispatchCount>o?(h.x=Math.min(e.dispatchCount,o),h.y=Math.ceil(e.dispatchCount/o)):h.x=e.dispatchCount,r.dispatchWorkgroups(h.x,h.y,h.z)}finishCompute(t){const e=this.get(t);e.passEncoderGPU.end(),this.prepareTimestampBuffer(t,e.cmdEncoderGPU),this.device.queue.submit([e.cmdEncoderGPU.finish()])}draw(t,e){const{object:s,geometry:i,context:r,pipeline:n}=t,o=t.getBindings(),a=this.get(r),h=this.get(n).pipeline,u=a.currentSets,l=this.get(t),{bundleEncoder:c,renderBundle:d,lastPipelineGPU:p}=l,m=this.get(r);if(!0===m.registerBundlesPhase&&void 0!==c&&p===h)return void m.renderBundles.push(d);const g=this.renderer._currentRenderBundle?this.createBundleEncoder(r,t):a.currentPass;u.pipeline!==h&&(g.setPipeline(h),u.pipeline=h);for(let t=0,e=o.length;t<e;t++){const e=o[t],s=this.get(e);g.setBindGroup(t,s.group)}const f=t.getIndex(),y=null!==f;if(!0===y&&u.index!==f){const t=this.get(f).buffer,e=f.array instanceof Uint16Array?nM:oM;g.setIndexBuffer(t,e),u.index=f}const x=t.getVertexBuffers();for(let t=0,e=x.length;t<e;t++){const e=x[t];if(u.attributes[t]!==e){const s=this.get(e).buffer;g.setVertexBuffer(t,s),u.attributes[t]=e}}if(void 0!==a.occlusionQuerySet){const t=a.lastOcclusionObject;t!==s&&(null!==t&&!0===t.occlusionTest&&(g.endOcclusionQuery(),a.occlusionQueryIndex++),!0===s.occlusionTest&&(g.beginOcclusionQuery(a.occlusionQueryIndex),a.occlusionQueryObjects[a.occlusionQueryIndex]=s),a.lastOcclusionObject=s)}const b=t.drawRange,v=b.start,T=this.getInstanceCount(t);if(0!==T){if(!0===s.isBatchedMesh){const t=s._multiDrawStarts,e=s._multiDrawCounts,i=s._multiDrawCount,r=s._multiDrawInstances,n=f.bytesPerElement||1;for(let s=0;s<i;s++){const i=r?r[s]:1,o=i>1?0:s;g.drawIndexed(e[s]/n,i,t[s]/4,0,o)}}else if(!0===y){const t=b.count!==1/0?b.count:f.count;g.drawIndexed(t,T,v,0,0),e.update(s,t,T)}else{const t=i.attributes.position,r=b.count!==1/0?b.count:t.count;g.draw(r,T,v,0),e.update(s,r,T)}if(this.renderer._currentRenderBundle){const t=g.finish();l.lastPipelineGPU=h,l.renderBundle=t,l.bundleEncoder=g}}}needsRenderUpdate(t){const e=this.get(t),{object:s,material:i}=t,r=this.utils,n=r.getSampleCountRenderContext(t.context),o=r.getCurrentColorSpace(t.context),a=r.getCurrentColorFormat(t.context),h=r.getCurrentDepthStencilFormat(t.context),u=r.getPrimitiveTopology(s,i);let l=!1;return e.material===i&&e.materialVersion===i.version&&e.transparent===i.transparent&&e.blending===i.blending&&e.premultipliedAlpha===i.premultipliedAlpha&&e.blendSrc===i.blendSrc&&e.blendDst===i.blendDst&&e.blendEquation===i.blendEquation&&e.blendSrcAlpha===i.blendSrcAlpha&&e.blendDstAlpha===i.blendDstAlpha&&e.blendEquationAlpha===i.blendEquationAlpha&&e.colorWrite===i.colorWrite&&e.depthWrite===i.depthWrite&&e.depthTest===i.depthTest&&e.depthFunc===i.depthFunc&&e.stencilWrite===i.stencilWrite&&e.stencilFunc===i.stencilFunc&&e.stencilFail===i.stencilFail&&e.stencilZFail===i.stencilZFail&&e.stencilZPass===i.stencilZPass&&e.stencilFuncMask===i.stencilFuncMask&&e.stencilWriteMask===i.stencilWriteMask&&e.side===i.side&&e.alphaToCoverage===i.alphaToCoverage&&e.sampleCount===n&&e.colorSpace===o&&e.colorFormat===a&&e.depthStencilFormat===h&&e.primitiveTopology===u&&e.clippingContextVersion===t.clippingContextVersion||(e.material=i,e.materialVersion=i.version,e.transparent=i.transparent,e.blending=i.blending,e.premultipliedAlpha=i.premultipliedAlpha,e.blendSrc=i.blendSrc,e.blendDst=i.blendDst,e.blendEquation=i.blendEquation,e.blendSrcAlpha=i.blendSrcAlpha,e.blendDstAlpha=i.blendDstAlpha,e.blendEquationAlpha=i.blendEquationAlpha,e.colorWrite=i.colorWrite,e.depthWrite=i.depthWrite,e.depthTest=i.depthTest,e.depthFunc=i.depthFunc,e.stencilWrite=i.stencilWrite,e.stencilFunc=i.stencilFunc,e.stencilFail=i.stencilFail,e.stencilZFail=i.stencilZFail,e.stencilZPass=i.stencilZPass,e.stencilFuncMask=i.stencilFuncMask,e.stencilWriteMask=i.stencilWriteMask,e.side=i.side,e.alphaToCoverage=i.alphaToCoverage,e.sampleCount=n,e.colorSpace=o,e.colorFormat=a,e.depthStencilFormat=h,e.primitiveTopology=u,e.clippingContextVersion=t.clippingContextVersion,l=!0),l}getRenderCacheKey(t){const{object:e,material:s}=t,i=this.utils,r=t.context;return[s.transparent,s.blending,s.premultipliedAlpha,s.blendSrc,s.blendDst,s.blendEquation,s.blendSrcAlpha,s.blendDstAlpha,s.blendEquationAlpha,s.colorWrite,s.depthWrite,s.depthTest,s.depthFunc,s.stencilWrite,s.stencilFunc,s.stencilFail,s.stencilZFail,s.stencilZPass,s.stencilFuncMask,s.stencilWriteMask,s.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,s),t.clippingContextVersion].join()}createSampler(t){this.textureUtils.createSampler(t)}destroySampler(t){this.textureUtils.destroySampler(t)}createDefaultTexture(t){this.textureUtils.createDefaultTexture(t)}createTexture(t,e){this.textureUtils.createTexture(t,e)}updateTexture(t,e){this.textureUtils.updateTexture(t,e)}generateMipmaps(t){this.textureUtils.generateMipmaps(t)}destroyTexture(t){this.textureUtils.destroyTexture(t)}copyTextureToBuffer(t,e,s,i,r){return this.textureUtils.copyTextureToBuffer(t,e,s,i,r)}initTimestampQuery(t,e){if(!this.hasFeature(rA.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(!s.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),s.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.hasFeature(rA.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===s.currentTimestampQueryBuffers&&(s.currentTimestampQueryBuffers={resolveBuffer:this.device.createBuffer({label:"timestamp resolve buffer",size:i,usage:GPUBufferUsage.QUERY_RESOLVE|GPUBufferUsage.COPY_SRC}),resultBuffer:this.device.createBuffer({label:"timestamp result buffer",size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),isMappingPending:!1});const{resolveBuffer:r,resultBuffer:n,isMappingPending:o}=s.currentTimestampQueryBuffers;!0!==o&&(e.resolveQuerySet(s.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,n,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.hasFeature(rA.TimestampQuery)||!this.trackTimestamp)return;const s=this.get(t);if(void 0===s.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=s.currentTimestampQueryBuffers;!0!==r&&(s.currentTimestampQueryBuffers.isMappingPending=!0,i.mapAsync(GPUMapMode.READ).then((()=>{const t=new BigUint64Array(i.getMappedRange()),r=Number(t[1]-t[0])/1e6;this.renderer.info.updateTimestamp(e,r),i.unmap(),s.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new vP(t,e)}createProgram(t){this.get(t).module={module:this.device.createShaderModule({code:t.code,label:t.stage}),entryPoint:"main"}}destroyProgram(t){this.delete(t)}createRenderPipeline(t,e){this.pipelineUtils.createRenderPipeline(t,e)}createComputePipeline(t,e){this.pipelineUtils.createComputePipeline(t,e)}createBundleEncoder(t,e){return this.pipelineUtils.createBundleEncoder(t,e)}createBindings(t){this.bindingUtils.createBindings(t)}updateBindings(t){this.bindingUtils.createBindings(t)}updateBinding(t){this.bindingUtils.updateBinding(t)}createIndexAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.INDEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}createStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_SRC|GPUBufferUsage.COPY_DST)}updateAttribute(t){this.attributeUtils.updateAttribute(t)}destroyAttribute(t){this.attributeUtils.destroyAttribute(t)}updateSize(){this.colorBuffer=this.textureUtils.getColorBuffer(),this.defaultRenderPassdescriptor=null}getMaxAnisotropy(){return 16}hasFeature(t){return this.device.features.has(t)}copyTextureToTexture(t,e,s=null,i=null,r=0){let n=0,o=0,a=0,h=0,u=t.image.width,l=t.image.height;null!==s&&(a=s.x,h=s.y,u=s.width,l=s.height),null!==i&&(n=i.x,o=i.y);const c=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),d=this.get(t).texture,p=this.get(e).texture;c.copyTextureToTexture({texture:d,mipLevel:r,origin:{x:a,y:h,z:0}},{texture:p,mipLevel:r,origin:{x:n,y:o,z:0}},[u,l]),this.device.queue.submit([c.finish()])}copyFramebufferToTexture(t,e){const s=this.get(e),{encoder:i,descriptor:r}=s;let n=null;n=e.renderTarget?t.isDepthTexture?this.get(e.depthTexture).texture:this.get(e.textures[0]).texture:t.isDepthTexture?this.textureUtils.getDepthBuffer(e.depth,e.stencil):this.context.getCurrentTexture();const o=this.get(t).texture;if(n.format===o.format){s.currentPass.end(),i.copyTextureToTexture({texture:n,origin:{x:0,y:0,z:0}},{texture:o},[t.image.width,t.image.height]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t);for(let t=0;t<r.colorAttachments.length;t++)r.colorAttachments[t].loadOp=KS;e.depth&&(r.depthStencilAttachment.depthLoadOp=KS),e.stencil&&(r.depthStencilAttachment.stencilLoadOp=KS),s.currentPass=i.beginRenderPass(r),s.currentSets={attributes:{}}}else console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",n.format,o.format)}}class CP extends cI{constructor(t={}){let e;t.forceWebGL?e=ZI:Td.isAvailable()?e=RP:(e=ZI,console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."));super(new e(t),t),this.isWebGPURenderer=!0}}const EP=new iS(new vT);class BP{constructor(t,e=xm(0,0,1,1)){this.renderer=t,this.outputNode=e,this.outputColorTransform=!0,this.needsUpdate=!0}render(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Ze,EP.render(t),t.toneMapping=e,t.outputColorSpace=s}update(){if(!0===this.needsUpdate){const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;EP.material.fragmentNode=!0===this.outputColorTransform?iR(this.outputNode,e,s):this.outputNode.context({toneMapping:e,outputColorSpace:s}),EP.material.needsUpdate=!0,this.needsUpdate=!1}}async renderAsync(){this.update();const t=this.renderer,e=t.toneMapping,s=t.outputColorSpace;t.toneMapping=0,t.outputColorSpace=Ze,await EP.renderAsync(t),t.toneMapping=e,t.outputColorSpace=s}}class IP extends Ti{constructor(t=1,e=1){super(),this.image={width:t,height:e},this.magFilter=Tt,this.minFilter=Tt,this.isStorageTexture=!0}}class PP extends hn{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageBufferAttribute=!0}}class FP extends jo{constructor(t,e,s=Float32Array){!1===ArrayBuffer.isView(t)&&(t=new s(t*e)),super(t,e),this.isStorageInstancedBufferAttribute=!0}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:t}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=t);export{et as ACESFilmicToneMapping,Vv as AONode,v as AddEquation,J as AddOperation,Ve as AdditiveAnimationBlendMode,f as AdditiveBlending,vN as AfterImageNode,it as AgXToneMapping,Lt as AlphaFormat,Ns as AlwaysCompare,k as AlwaysDepth,bs as AlwaysStencilFunc,Bl as AmbientLight,kR as AmbientLightNode,Pv as AnalyticLightNode,wN as AnamorphicNode,Tc as AnimationAction,tl as AnimationClip,ul as AnimationLoader,wc as AnimationMixer,vc as AnimationObjectGroup,ku as AnimationUtils,sh as ArcCurve,Zl as ArrayCamera,pp as ArrayElementNode,fd as ArrowHelper,Vm as AssignNode,nt as AttachedBindMode,Wm as AttributeNode,nc as Audio,cc as AudioAnalyser,Hl as AudioContext,rc as AudioListener,ql as AudioLoader,yd as AxesHelper,IC as BRDF_GGX,yC as BRDF_Lambert,d as BackSide,We as BasicDepthPacking,ZR as BasicEnvironmentNode,a as BasicShadowMap,av as BatchNode,Sa as BatchedMesh,vA as BlendModeNode,QN as BloomNode,Vo as Bone,$u as BooleanKeyframeTrack,Oc as Box2,Pi as Box3,cd as Box3Helper,Hn as BoxGeometry,ld as BoxHelper,gv as Break,hn as BufferAttribute,Xb as BufferAttributeNode,Mn as BufferGeometry,Ll as BufferGeometryLoader,hx as BufferNode,NA as BumpMapNode,Hm as BypassNode,Nt as ByteType,sl as Cache,$m as CacheNode,Xn as Camera,ad as CameraHelper,Qa as CanvasTexture,wh as CapsuleGeometry,hh as CatmullRomCurve3,KR as CheckerNode,tt as CineonToneMapping,Sh as CircleGeometry,mt as ClampToEdgeWrapping,Ql as Clock,qg as CodeNode,Yr as Color,IA as ColorAdjustmentNode,Xu as ColorKeyframeTrack,di as ColorManagement,Xy as ColorSpaceNode,Ja as CompressedArrayTexture,Za as CompressedCubeTexture,Ya as CompressedTexture,ll as CompressedTextureLoader,NR as ComputeNode,LT as CondNode,Ah as ConeGeometry,vp as ConstNode,L as ConstantAlphaFactor,z as ConstantColorFactor,Ym as ContextNode,mv as Continue,mp as ConvertNode,to as CubeCamera,ht as CubeReflectionMapping,ut as CubeRefractionMapping,eo as CubeTexture,dl as CubeTextureLoader,Mv as CubeTextureNode,dt as CubeUVReflectionMapping,dh as CubicBezierCurve,ph as CubicBezierCurve3,Wu as CubicInterpolant,r as CullFaceBack,n as CullFaceFront,o as CullFaceFrontBack,i as CullFaceNone,th as Curve,vh as CurvePath,b as CustomBlending,st as CustomToneMapping,Mh as CylinderGeometry,Fc as Cylindrical,PC as DFGApprox,CC as D_GGX,Ni as Data3DTexture,Mi as DataArrayTexture,Do as DataTexture,pl as DataTextureLoader,nn as DataUtils,hs as DecrementStencilOp,ls as DecrementWrapStencilOp,rl as DefaultLoadingManager,GN as DenoiseNode,Wt as DepthFormat,NN as DepthOfFieldNode,jt as DepthStencilFormat,Ka as DepthTexture,ot as DetachedBindMode,El as DirectionalLight,rd as DirectionalLightHelper,PR as DirectionalLightNode,sw as DiscardNode,Hu as DiscreteInterpolant,Qe as DisplayP3ColorSpace,Rh as DodecahedronGeometry,CN as DotScreenNode,p as DoubleSide,B as DstAlphaFactor,P as DstColorFactor,Us as DynamicCopyUsage,Cs as DynamicDrawUsage,Is as DynamicReadUsage,zf as EPSILON,Ph as EdgesGeometry,eh as EllipseCurve,XR as EnvironmentNode,_s as EqualCompare,j as EqualDepth,ms as EqualStencilFunc,GT as EquirectUVNode,lt as EquirectangularReflectionMapping,ct as EquirectangularRefractionMapping,fr as Euler,ks as EventDispatcher,tx as ExpressionNode,uu as ExtrudeGeometry,jN as FXAANode,fC as F_Schlick,hl as FileLoader,PN as FilmNode,fn as Float16BufferAttribute,yn as Float32BufferAttribute,It as FloatType,ro as Fog,io as FogExp2,TR as FogExp2Node,yR as FogNode,bR as FogRangeNode,Xa as FramebufferTexture,fT as FrontFacingNode,c as FrontSide,na as Frustum,hR as FunctionCallNode,Zg as FunctionNode,ow as FunctionOverloadingNode,Rc as GLBufferAttribute,Os as GLSL1,Ls as GLSL3,IE as GLSLNodeParser,DN as GTAONode,fN as GaussianBlurNode,Ss as GreaterCompare,q as GreaterDepth,As as GreaterEqualCompare,H as GreaterEqualDepth,xs as GreaterEqualStencilFunc,fs as GreaterStencilFunc,Kc as GridHelper,qa as Group,Pt as HalfFloatType,q_ as HashNode,fl as HemisphereLight,Qc as HemisphereLightHelper,GR as HemisphereLightNode,VR as IESSpotLight,DR as IESSpotLightNode,Of as INFINITY,cu as IcosahedronGeometry,im as If,Wl as ImageBitmapLoader,cl as ImageLoader,fi as ImageUtils,as as IncrementStencilOp,us as IncrementWrapStencilOp,Qm as IndexNode,Kb as InstanceNode,jo as InstancedBufferAttribute,Ol as InstancedBufferGeometry,Nc as InstancedInterleavedBuffer,Qo as InstancedMesh,iC as InstancedPointsNodeMaterial,dn as Int16BufferAttribute,mn as Int32BufferAttribute,un as Int8BufferAttribute,Et as IntType,oo as InterleavedBuffer,ho as InterleavedBufferAttribute,Gu as Interpolant,Ie as InterpolateDiscrete,Pe as InterpolateLinear,Fe as InterpolateSmooth,cs as InvertStencilOp,Gv as IrradianceNode,gp as JoinNode,ns as KeepStencilOp,qu as KeyframeTrack,Ro as LOD,_h as LatheGeometry,yr as Layers,Ts as LessCompare,G as LessDepth,ws as LessEqualCompare,W as LessEqualDepth,gs as LessEqualStencilFunc,ps as LessStencilFunc,gl as Light,CR as LightNode,Fl as LightProbe,Dv as LightingContextNode,sg as LightingModel,Nv as LightingNode,Uv as LightsNode,Pa as Line,uC as Line2NodeMaterial,Dc as Line3,Ma as LineBasicMaterial,nC as LineBasicNodeMaterial,mh as LineCurve,gh as LineCurve3,Uu as LineDashedMaterial,aC as LineDashedNodeMaterial,La as LineLoop,Oa as LineSegments,Ke as LinearDisplayP3ColorSpace,Tt as LinearFilter,ju as LinearInterpolant,Mt as LinearMipMapLinearFilter,wt as LinearMipMapNearestFilter,St as LinearMipmapLinearFilter,_t as LinearMipmapNearestFilter,Ze as LinearSRGBColorSpace,Q as LinearToneMapping,ts as LinearTransfer,nl as Loader,zl as LoaderUtils,il as LoadingManager,dv as LoopNode,Ce as LoopOnce,Be as LoopPingPong,Ee as LoopRepeat,Gt as LuminanceAlphaFormat,kt as LuminanceFormat,UN as Lut3DNode,e as MOUSE,j_ as MRTNode,uw as MatcapUVNode,Qr as Material,Ul as MaterialLoader,tb as MaterialNode,yx as MaterialReferenceNode,Uf as MathNode,Qs as MathUtils,Uc as Matrix2,ti as Matrix3,or as Matrix4,S as MaxEquation,sx as MaxMipLevelNode,Wn as Mesh,Kr as MeshBasicMaterial,gC as MeshBasicNodeMaterial,Iu as MeshDepthMaterial,Pu as MeshDistanceMaterial,Bu as MeshLambertMaterial,_C as MeshLambertNodeMaterial,Fu as MeshMatcapMaterial,mE as MeshMatcapNodeMaterial,Eu as MeshNormalMaterial,cC as MeshNormalNodeMaterial,Ru as MeshPhongMaterial,SC as MeshPhongNodeMaterial,Nu as MeshPhysicalMaterial,oE as MeshPhysicalNodeMaterial,hE as MeshSSSNodeMaterial,Au as MeshStandardMaterial,rE as MeshStandardNodeMaterial,Cu as MeshToonMaterial,dE as MeshToonNodeMaterial,w as MinEquation,gt as MirroredRepeatWrapping,Y as MixOperation,Ox as ModelNode,qb as ModelViewProjectionNode,bv as MorphNode,x as MultiplyBlending,X as MultiplyOperation,ft as NearestFilter,vt as NearestMipMapLinearFilter,xt as NearestMipMapNearestFilter,bt as NearestMipmapLinearFilter,yt as NearestMipmapNearestFilter,rt as NeutralToneMapping,vs as NeverCompare,D as NeverDepth,ds as NeverStencilFunc,m as NoBlending,Ye as NoColorSpace,Z as NoToneMapping,up as Node,ng as NodeAttribute,O_ as NodeBuilder,dg as NodeCache,ug as NodeCode,L_ as NodeFrame,V_ as NodeFunctionInput,lg as NodeKeywords,eC as NodeLoader,vT as NodeMaterial,SE as NodeMaterialLoader,ME as NodeObjectLoader,$d as NodeShaderStage,Yd as NodeType,og as NodeUniform,Xd as NodeUpdateType,op as NodeUtils,ag as NodeVar,hg as NodeVarying,Le as NormalAnimationBlendMode,g as NormalBlending,DA as NormalMapNode,Ms as NotEqualCompare,$ as NotEqualDepth,ys as NotEqualStencilFunc,Yu as NumberKeyframeTrack,Pr as Object3D,Cx as Object3DNode,Vl as ObjectLoader,Xe as ObjectSpaceNormalMap,du as OctahedronGeometry,A as OneFactor,V as OneMinusConstantAlphaFactor,O as OneMinusConstantColorFactor,I as OneMinusDstAlphaFactor,F as OneMinusDstColorFactor,E as OneMinusSrcAlphaFactor,R as OneMinusSrcColorFactor,pf as OperatorNode,Rl as OrthographicCamera,fw as OscNode,k_ as OutputStructNode,is as P3Primaries,h as PCFShadowMap,u as PCFSoftShadowMap,Lf as PI,Vf as PI2,M_ as PMREMGenerator,HR as PMREMNode,Tw as PackingNode,jg as ParameterNode,lN as PassNode,Th as Path,Qn as PerspectiveCamera,vC as PhongLightingModel,sE as PhysicalLightingModel,oR as PixelationPassNode,sa as Plane,pu as PlaneGeometry,dd as PlaneHelper,Nl as PointLight,Xc as PointLightHelper,IR as PointLightNode,FS as PointUVNode,ja as Points,Va as PointsMaterial,fE as PointsNodeMaterial,td as PolarGridHelper,Nh as PolyhedronGeometry,lc as PositionalAudio,BP as PostProcessing,GA as PosterizeNode,bc as PropertyBinding,dc as PropertyMixer,pg as PropertyNode,iS as QuadMesh,fh as QuadraticBezierCurve,yh as QuadraticBezierCurve3,Ci as Quaternion,Zu as QuaternionKeyframeTrack,Ju as QuaternionLinearInterpolant,Ne as RED_GREEN_RGTC2_Format,Me as RED_RGTC1_Format,t as REVISION,je as RGBADepthPacking,Dt as RGBAFormat,Jt as RGBAIntegerFormat,be as RGBA_ASTC_10x10_Format,fe as RGBA_ASTC_10x5_Format,ye as RGBA_ASTC_10x6_Format,xe as RGBA_ASTC_10x8_Format,ve as RGBA_ASTC_12x10_Format,Te as RGBA_ASTC_12x12_Format,he as RGBA_ASTC_4x4_Format,ue as RGBA_ASTC_5x4_Format,le as RGBA_ASTC_5x5_Format,ce as RGBA_ASTC_6x5_Format,de as RGBA_ASTC_6x6_Format,pe as RGBA_ASTC_8x5_Format,me as RGBA_ASTC_8x6_Format,ge as RGBA_ASTC_8x8_Format,_e as RGBA_BPTC_Format,ae as RGBA_ETC2_EAC_Format,re as RGBA_PVRTC_2BPPV1_Format,ie as RGBA_PVRTC_4BPPV1_Format,Qt as RGBA_S3TC_DXT1_Format,Kt as RGBA_S3TC_DXT3_Format,te as RGBA_S3TC_DXT5_Format,He as RGBDepthPacking,Vt as RGBFormat,Yt as RGBIntegerFormat,BN as RGBShiftNode,we as RGB_BPTC_SIGNED_Format,Se as RGB_BPTC_UNSIGNED_Format,ne as RGB_ETC1_Format,oe as RGB_ETC2_Format,se as RGB_PVRTC_2BPPV1_Format,ee as RGB_PVRTC_4BPPV1_Format,Zt as RGB_S3TC_DXT1_Format,qe as RGDepthPacking,$t as RGFormat,Xt as RGIntegerFormat,nS as RTTNode,MR as RangeNode,Mu as RawShaderMaterial,nr as Ray,Ec as Raycaster,ss as Rec709Primaries,Il as RectAreaLight,OR as RectAreaLightNode,Ht as RedFormat,qt as RedIntegerFormat,mx as ReferenceNode,Qw as ReflectorNode,K as ReinhardToneMapping,Sw as RemapNode,sR as RenderOutputNode,wi as RenderTarget,vS as RendererReferenceNode,pt as RepeatWrapping,os as ReplaceStencilOp,nw as Return,_ as ReverseSubtractEquation,mu as RingGeometry,Cw as RotateNode,Nw as RotateUVNode,Re as SIGNED_RED_GREEN_RGTC2_Format,Ae as SIGNED_RED_RGTC1_Format,Je as SRGBColorSpace,es as SRGBTransfer,no as Scene,zS as SceneNode,UC as Schlick_to_F0,gR as ScriptableNode,lR as ScriptableValueNode,xp as SetNode,$n as ShaderMaterial,Xp as ShaderNode,Su as ShadowMaterial,TE as ShadowNodeMaterial,Fh as Shape,gu as ShapeGeometry,xd as ShapePath,ou as ShapeUtils,Rt as ShortType,Wo as Skeleton,qc as SkeletonHelper,Lo as SkinnedMesh,uv as SkinningNode,MN as SobelOperatorNode,xi as Source,Zi as Sphere,fu as SphereGeometry,Pc as Spherical,Pl as SphericalHarmonics3,xh as SplineCurve,yp as SplitNode,_l as SpotLight,Gc as SpotLightHelper,LR as SpotLightNode,So as Sprite,uo as SpriteMaterial,xE as SpriteNodeMaterial,Bw as SpriteSheetUVNode,C as SrcAlphaFactor,U as SrcAlphaSaturateFactor,N as SrcColorFactor,DT as StackNode,Fs as StaticCopyUsage,Rs as StaticDrawUsage,Bs as StaticReadUsage,Jl as StereoCamera,Pw as StorageArrayElementNode,PP as StorageBufferAttribute,nA as StorageBufferNode,FP as StorageInstancedBufferAttribute,IP as StorageTexture,hA as StorageTextureNode,zs as StreamCopyUsage,Es as StreamDrawUsage,Ps as StreamReadUsage,Qu as StringKeyframeTrack,T as SubtractEquation,y as SubtractiveBlending,mS as TBNViewMatrix,s as TOUCH,$e as TangentSpaceNormalMap,dp as TempNode,yu as TetrahedronGeometry,Ti as Texture,dA as Texture3DNode,IS as TextureBicubicNode,ml as TextureLoader,rx as TextureNode,cf as TextureSizeNode,cw as TimerNode,eN as ToneMappingNode,xu as TorusGeometry,bu as TorusKnotGeometry,tR as TransitionNode,jr as Triangle,Ge as TriangleFanDrawMode,ke as TriangleStripDrawMode,De as TrianglesDrawMode,Uw as TriplanarTexturesNode,vu as TubeGeometry,at as UVMapping,pn as Uint16BufferAttribute,gn as Uint32BufferAttribute,ln as Uint8BufferAttribute,cn as Uint8ClampedBufferAttribute,Sc as Uniform,ef as UniformGroupNode,hf as UniformNode,Ac as UniformsGroup,cx as UniformsNode,At as UnsignedByteType,zt as UnsignedInt248Type,Ot as UnsignedInt5999Type,Bt as UnsignedIntType,Ft as UnsignedShort4444Type,Ut as UnsignedShort5551Type,Ct as UnsignedShortType,mA as UserDataNode,l as VSMShadowMap,NC as V_GGX_SmithCorrelated,ig as VarNode,km as VaryingNode,Ks as Vector2,Ei as Vector3,_i as Vector4,Ku as VectorKeyframeTrack,xS as VertexColorNode,$a as VideoTexture,oT as ViewportDepthNode,rT as ViewportDepthTextureNode,Hv as ViewportNode,nN as ViewportSharedTextureNode,tT as ViewportTextureNode,_E as VolumeNodeMaterial,Ri as WebGL3DRenderTarget,Ai as WebGLArrayRenderTarget,Vs as WebGLCoordinateSystem,so as WebGLCubeRenderTarget,bd as WebGLMultipleRenderTargets,Si as WebGLRenderTarget,Ds as WebGPUCoordinateSystem,CP as WebGPURenderer,Tu as WireframeGeometry,Oe as WrapAroundEnding,Ue as ZeroCurvatureEnding,M as ZeroFactor,ze as ZeroSlopeEnding,rs as ZeroStencilOp,ay as abs,ny as acos,mf as add,Lv as addLightNode,lp as addNodeClass,wp as addNodeElement,TT as addNodeMaterial,TN as afterImage,Df as all,Ng as alphaT,SN as anamorphic,Mf as and,Rg as anisotropy,Eg as anisotropyB,Cg as anisotropyT,kf as any,kN as ao,rm as append,Um as arrayBuffer,ry as asin,Dm as assign,oy as atan,vy as atan2,jm as attribute,OS as backgroundBlurriness,LS as backgroundIntensity,hv as batch,Cf as bitAnd,Ef as bitNot,Bf as bitOr,If as bitXor,hS as bitangentGeometry,uS as bitangentLocal,lS as bitangentView,cS as bitangentWorld,xy as bitcast,KN as bloom,l_ as blur,Mm as bmat2,Cm as bmat3,Pm as bmat4,um as bool,ux as buffer,Yb as bufferAttribute,RA as bumpMap,TA as burn,pm as bvec2,ym as bvec3,Tm as bvec4,qm as bypass,Xm as cache,uR as call,Tx as cameraFar,_x as cameraLogDepth,vx as cameraNear,Nx as cameraNormalMatrix,Rx as cameraPosition,wx as cameraProjectionMatrix,Sx as cameraProjectionMatrixInverse,Mx as cameraViewMatrix,Ax as cameraWorldMatrix,Uy as cbrt,Qf as ceil,tC as checker,Ly as clamp,vg as clearcoat,Tg as clearcoatRoughness,$g as code,nm as color,Zy as colorSpaceToLinear,ww as colorToDirection,RR as compute,VT as cond,Jm as context,Om as convert,sy as cos,ni as createCanvasElement,cp as createNodeFromType,_T as createNodeMaterialFromType,Cy as cross,Av as cubeTexture,dy as dFdx,py as dFdy,Ug as dashSize,Zd as defaultBuildStages,Jd as defaultShaderStages,qp as defined,jf as degrees,WN as denoise,_R as densityFog,dT as depth,pN as depthPass,Ny as difference,fg as diffuseColor,_w as directionToColor,rw as discard,Ay as distance,yf as div,_A as dodge,RN as dof,Ry as dot,EN as dotScreen,eg as drawIndex,Jb as dynamicBufferAttribute,zm as element,yg as emissive,bf as equal,Gf as equals,WT as equirectUV,Hf as exp,qf as exp2,ex as expression,xT as faceDirection,Gy as faceForward,FN as film,om as float,Zf as floor,xR as fog,ty as fract,nf as frameGroup,gw as frameId,yT as frontFacing,yy as fwidth,HN as fxaa,Y_ as gain,zg as gapSize,yN as gaussianBlur,$p as getConstNodeType,sm as getCurrentStack,o_ as getDirection,BR as getDistanceAttenuation,MC as getGeometryRoughness,AC as getRoughness,mR as global,Jg as glsl,Kg as glslFn,_f as greaterThan,Sf as greaterThanEqual,$_ as hash,UA as hue,wm as imat2,Nm as imat3,Bm as imat4,tv as instance,tg as instanceIndex,Zb as instancedBufferAttribute,Qb as instancedDynamicBufferAttribute,am as int,Jf as inverseSqrt,Sg as iridescence,Mg as iridescenceIOR,Ag as iridescenceThickness,cm as ivec2,gm as ivec3,bm as ivec4,Xg as js,Zm as label,uy as length,zy as lengthSq,Tf as lessThan,wf as lessThanEqual,ER as lightTargetDirection,kv as lightingContext,zv as lights,Ov as lightsNode,pT as linearDepth,Jy as linearToColorSpace,Qy as linearTosRGB,$f as log,Xf as log2,pv as loop,OA as luminance,zN as lut3D,_m as mat2,Am as mat3,Em as mat4,lw as matcapUV,Ob as materialAOMap,eb as materialAlphaTest,vb as materialAnisotropy,Vb as materialAnisotropyVector,mb as materialClearcoat,fb as materialClearcoatNormal,gb as materialClearcoatRoughness,sb as materialColor,Ub as materialDispersion,rb as materialEmissive,Tb as materialIridescence,_b as materialIridescenceIOR,wb as materialIridescenceThickness,zb as materialLightMap,Pb as materialLineDashOffset,Eb as materialLineDashSize,Bb as materialLineGapSize,Cb as materialLineScale,Ib as materialLineWidth,db as materialMetalness,pb as materialNormal,nb as materialOpacity,Fb as materialPointWidth,xx as materialReference,lb as materialReflectivity,yb as materialRotation,cb as materialRoughness,xb as materialSheen,bb as materialSheenRoughness,ib as materialShininess,ob as materialSpecular,ub as materialSpecularStrength,_y as max,ix as maxMipLevel,bg as metalness,Ty as min,Oy as mix,wy as mod,Lx as modelDirection,Dx as modelNormalMatrix,Gx as modelPosition,Wx as modelScale,Vx as modelViewMatrix,jx as modelViewPosition,$b as modelViewProjection,kx as modelWorldMatrix,Hx as modelWorldMatrixInverse,vv as morphReference,H_ as mrt,ff as mul,TB as mx_aastep,OB as mx_cell_noise_float,EB as mx_contrast,LB as mx_fractal_noise_float,VB as mx_fractal_noise_vec2,DB as mx_fractal_noise_vec3,kB as mx_fractal_noise_vec4,xB as mx_hsvtorgb,BB as mx_noise_float,IB as mx_noise_vec3,PB as mx_noise_vec4,wB as mx_ramplr,SB as mx_ramptb,bB as mx_rgbtohsv,CB as mx_safepower,AB as mx_splitlr,NB as mx_splittb,vB as mx_srgb_texture_to_lin_rec709,RB as mx_transform_uv,FB as mx_worley_noise_float,UB as mx_worley_noise_vec2,zB as mx_worley_noise_vec3,ly as negate,Zp as nodeArray,Kp as nodeImmutable,Yp as nodeObject,Jp as nodeObjects,Qp as nodeProxy,qx as normalGeometry,$x as normalLocal,kA as normalMap,Xx as normalView,Yx as normalWorld,Kf as normalize,Nf as not,Ex as objectDirection,af as objectGroup,Ix as objectNormalMatrix,Fx as objectPosition,Ux as objectScale,Bx as objectViewMatrix,zx as objectViewPosition,Px as objectWorldMatrix,cy as oneMinus,Af as or,hT as orthographicDepthToViewZ,vw as oscSawtooth,yw as oscSine,xw as oscSquare,bw as oscTriangle,Fg as output,G_ as outputStruct,wA as overlay,hw as overloadingFn,X_ as parabola,gS as parallaxDirection,fS as parallaxUV,Hg as parameter,cN as pass,dN as passTexture,J_ as pcurve,lT as perspectiveDepthToViewZ,aR as pixelationPass,qR as pmremTexture,US as pointUV,Og as pointWidth,Db as positionGeometry,kb as positionLocal,jb as positionView,Hb as positionViewDirection,Gb as positionWorld,Wb as positionWorldDirection,WA as posterize,Ey as pow,By as pow2,Iy as pow3,Py as pow4,mg as property,Wf as radians,Wy as rand,AR as range,vR as rangeFog,gy as reciprocal,gx as reference,fx as referenceBuffer,My as reflect,wv as reflectVector,Tv as reflectView,Kw as reflector,Dy as refract,Sv as refractVector,_v as refractView,xf as remainder,Mw as remap,Aw as remapClamp,of as renderGroup,iR as renderOutput,TS as rendererReference,IN as rgbShift,Ew as rotate,Rw as rotateUV,xg as roughness,my as round,oS as rtt,Ky as sRGBToLinear,ax as sampler,Vy as saturate,PA as saturation,SA as screen,fR as scriptable,cR as scriptableValue,em as setCurrentStack,Qd as shaderStages,_g as sheen,wg as sheenRoughness,Pf as shiftLeft,Ff as shiftRight,Pg as shininess,hy as sign,ey as sin,Z_ as sinc,lv as skinning,cv as skinningReference,ky as smoothstep,AN as sobel,Bg as specularColor,Lm as split,Iw as spritesheetUV,Yf as sqrt,kT as stack,Sy as step,oA as storage,aA as storageObject,uA as storageTexture,Fm as string,gf as sub,iy as tan,ev as tangentGeometry,sv as tangentLocal,iv as tangentView,rv as tangentWorld,rg as temp,nx as texture,pA as texture3D,PS as textureBicubic,a_ as textureCubeUV,ox as textureLoad,df as textureSize,lA as textureStore,LA as threshold,mw as timerDelta,pw as timerGlobal,dw as timerLocal,sN as toneMapping,Fy as transformDirection,yS as transformedBentNormalView,dS as transformedBitangentView,pS as transformedBitangentWorld,Qx as transformedClearcoatNormalView,Jx as transformedNormalView,Zx as transformedNormalWorld,nv as transformedTangentView,ov as transformedTangentWorld,eR as transition,by as transpose,tw as triNoise3D,Ow as triplanarTexture,zw as triplanarTextures,fy as trunc,tm as tslFn,hm as uint,Sm as umat2,Rm as umat3,Im as umat4,uf as uniform,sf as uniformGroup,dx as uniforms,gA as userData,lf as uv,dm as uvec2,fm as uvec3,vm as uvec4,Gm as varying,gg as varyingProperty,lm as vec2,mm as vec3,xm as vec4,Kd as vectorComponents,bS as vertexColor,Km as vertexIndex,FA as vibrance,aT as viewZToOrthographicDepth,uT as viewZToPerspectiveDepth,Xv as viewport,Jv as viewportBottomLeft,Qv as viewportBottomRight,qv as viewportCoordinate,nT as viewportDepthTexture,mT as viewportLinearDepth,sT as viewportMipTexture,$v as viewportResolution,oN as viewportSharedTexture,eT as viewportTexture,Yv as viewportTopLeft,Zv as viewportTopRight,Yg as wgsl,tf as wgslFn,Rf as xor};
|